LLDB mainline
SBTarget.cpp
Go to the documentation of this file.
1//===-- SBTarget.cpp ------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/API/SBTarget.h"
11#include "lldb/API/SBDebugger.h"
13#include "lldb/API/SBEvent.h"
15#include "lldb/API/SBFileSpec.h"
16#include "lldb/API/SBListener.h"
17#include "lldb/API/SBModule.h"
19#include "lldb/API/SBMutex.h"
20#include "lldb/API/SBProcess.h"
22#include "lldb/API/SBStream.h"
27#include "lldb/API/SBTrace.h"
32#include "lldb/Core/Address.h"
34#include "lldb/Core/Debugger.h"
36#include "lldb/Core/Module.h"
40#include "lldb/Core/Section.h"
42#include "lldb/Host/Host.h"
50#include "lldb/Target/ABI.h"
53#include "lldb/Target/Process.h"
56#include "lldb/Target/Target.h"
59#include "lldb/Utility/Args.h"
69#include "lldb/lldb-public.h"
70
73#include "llvm/Support/PrettyStackTrace.h"
74#include "llvm/Support/Regex.h"
75
76using namespace lldb;
77using namespace lldb_private;
78
79#define DEFAULT_DISASM_BYTE_SIZE 32
80
81static Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target) {
82 std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
83
84 auto process_sp = target.GetProcessSP();
85 if (process_sp) {
86 const auto state = process_sp->GetState();
87 if (process_sp->IsAlive() && state == eStateConnected) {
88 // If we are already connected, then we have already specified the
89 // listener, so if a valid listener is supplied, we need to error out to
90 // let the client know.
91 if (attach_info.GetListener())
93 "process is connected and already has a listener, pass "
94 "empty listener");
95 }
96 }
97
98 return target.Attach(attach_info, nullptr);
99}
100
101// SBTarget constructor
103
105 LLDB_INSTRUMENT_VA(this, rhs);
106}
107
108SBTarget::SBTarget(const TargetSP &target_sp) : m_opaque_sp(target_sp) {
109 LLDB_INSTRUMENT_VA(this, target_sp);
110}
111
113 LLDB_INSTRUMENT_VA(this, rhs);
114
115 if (this != &rhs)
117 return *this;
118}
119
120// Destructor
121SBTarget::~SBTarget() = default;
122
124 LLDB_INSTRUMENT_VA(event);
125
126 return Target::TargetEventData::GetEventDataFromEvent(event.get()) != nullptr;
127}
128
134
140
142 LLDB_INSTRUMENT_VA(event);
143
144 const ModuleList module_list =
146 return module_list.GetSize();
147}
148
150 const SBEvent &event) {
151 LLDB_INSTRUMENT_VA(idx, event);
152
153 const ModuleList module_list =
155 return SBModule(module_list.GetModuleAtIndex(idx));
156}
157
163
164bool SBTarget::IsValid() const {
165 LLDB_INSTRUMENT_VA(this);
166 return this->operator bool();
167}
168SBTarget::operator bool() const {
169 LLDB_INSTRUMENT_VA(this);
170
171 return m_opaque_sp.get() != nullptr && m_opaque_sp->IsValid();
172}
173
175 LLDB_INSTRUMENT_VA(this);
176
177 SBProcess sb_process;
178 ProcessSP process_sp;
179 if (TargetSP target_sp = GetSP()) {
180 process_sp = target_sp->GetProcessSP();
181 sb_process.SetSP(process_sp);
182 }
183
184 return sb_process;
185}
186
188 LLDB_INSTRUMENT_VA(this);
189
190 if (TargetSP target_sp = GetSP()) {
191 SBPlatform platform;
192 platform.m_opaque_sp = target_sp->GetPlatform();
193 return platform;
194 }
195 return SBPlatform();
196}
197
199 LLDB_INSTRUMENT_VA(this);
200
201 SBDebugger debugger;
202 if (TargetSP target_sp = GetSP())
203 debugger.reset(target_sp->GetDebugger().shared_from_this());
204 return debugger;
205}
206
212
214 LLDB_INSTRUMENT_VA(this);
215
216 SBStructuredData data;
217 if (TargetSP target_sp = GetSP()) {
218 std::string json_str =
219 llvm::formatv("{0:2}", DebuggerStats::ReportStatistics(
220 target_sp->GetDebugger(), target_sp.get(),
221 options.ref()))
222 .str();
223 data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
224 return data;
225 }
226 return data;
227}
228
230 LLDB_INSTRUMENT_VA(this);
231
232 if (TargetSP target_sp = GetSP())
233 DebuggerStats::ResetStatistics(target_sp->GetDebugger(), target_sp.get());
234}
235
237 LLDB_INSTRUMENT_VA(this, v);
238
239 if (TargetSP target_sp = GetSP())
241}
242
244 LLDB_INSTRUMENT_VA(this);
245
246 if (TargetSP target_sp = GetSP())
248 return false;
249}
250
251SBProcess SBTarget::LoadCore(const char *core_file) {
252 LLDB_INSTRUMENT_VA(this, core_file);
253
254 lldb::SBError error; // Ignored
255 return LoadCore(core_file, error);
256}
257
259 LLDB_INSTRUMENT_VA(this, core_file, error);
260
261 SBProcess sb_process;
262 if (TargetSP target_sp = GetSP()) {
263 FileSpec filespec(core_file);
264 FileSystem::Instance().Resolve(filespec);
265 ProcessSP process_sp(target_sp->CreateProcess(
266 target_sp->GetDebugger().GetListener(), "", &filespec, false));
267 if (process_sp) {
268 ElapsedTime load_core_time(target_sp->GetStatistics().GetLoadCoreTime());
269 error.SetError(process_sp->LoadCore());
270 if (error.Success())
271 sb_process.SetSP(process_sp);
272 } else {
273 error.SetErrorString("Failed to create the process");
274 }
275 } else {
276 error.SetErrorString("SBTarget is invalid");
277 }
278 return sb_process;
279}
280
281SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp,
282 const char *working_directory) {
283 LLDB_INSTRUMENT_VA(this, argv, envp, working_directory);
284
285 TargetSP target_sp = GetSP();
286 if (!target_sp)
287 return SBProcess();
288
289 SBLaunchInfo launch_info = GetLaunchInfo();
290
291 if (Module *exe_module = target_sp->GetExecutableModulePointer())
292 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(),
293 /*add_as_first_arg*/ true);
294 if (argv)
295 launch_info.SetArguments(argv, /*append*/ true);
296 if (envp)
297 launch_info.SetEnvironmentEntries(envp, /*append*/ false);
298 if (working_directory)
299 launch_info.SetWorkingDirectory(working_directory);
300
302 return Launch(launch_info, error);
303}
304
306 LLDB_INSTRUMENT_VA(this);
307
308 SBError sb_error;
309 if (TargetSP target_sp = GetSP()) {
310 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
311 sb_error.ref() = target_sp->Install(nullptr);
312 }
313 return sb_error;
314}
315
316SBProcess SBTarget::Launch(SBListener &listener, char const **argv,
317 char const **envp, const char *stdin_path,
318 const char *stdout_path, const char *stderr_path,
319 const char *working_directory,
320 uint32_t launch_flags, // See LaunchFlags
321 bool stop_at_entry, lldb::SBError &error) {
322 LLDB_INSTRUMENT_VA(this, listener, argv, envp, stdin_path, stdout_path,
323 stderr_path, working_directory, launch_flags,
324 stop_at_entry, error);
325
326 SBProcess sb_process;
327 ProcessSP process_sp;
328 if (TargetSP target_sp = GetSP()) {
329 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
330
331 if (stop_at_entry)
332 launch_flags |= eLaunchFlagStopAtEntry;
333
334 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
335 launch_flags |= eLaunchFlagDisableASLR;
336
337 if (getenv("LLDB_LAUNCH_FLAG_USE_PIPES"))
338 launch_flags |= eLaunchFlagUsePipes;
339
340 StateType state = eStateInvalid;
341 process_sp = target_sp->GetProcessSP();
342 if (process_sp) {
343 state = process_sp->GetState();
344
345 if (process_sp->IsAlive() && state != eStateConnected) {
346 if (state == eStateAttaching)
347 error.SetErrorString("process attach is in progress");
348 else
349 error.SetErrorString("a process is already being debugged");
350 return sb_process;
351 }
352 }
353
354 if (state == eStateConnected) {
355 // If we are already connected, then we have already specified the
356 // listener, so if a valid listener is supplied, we need to error out to
357 // let the client know.
358 if (listener.IsValid()) {
359 error.SetErrorString("process is connected and already has a listener, "
360 "pass empty listener");
361 return sb_process;
362 }
363 }
364
365 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
366 launch_flags |= eLaunchFlagDisableSTDIO;
367
368 ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
369 FileSpec(stderr_path),
370 FileSpec(working_directory), launch_flags);
371
372 Module *exe_module = target_sp->GetExecutableModulePointer();
373 if (exe_module)
374 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
375 if (argv) {
376 launch_info.GetArguments().AppendArguments(argv);
377 } else {
378 auto default_launch_info = target_sp->GetProcessLaunchInfo();
379 launch_info.GetArguments().AppendArguments(
380 default_launch_info.GetArguments());
381 }
382 if (envp) {
383 launch_info.GetEnvironment() = Environment(envp);
384 } else {
385 auto default_launch_info = target_sp->GetProcessLaunchInfo();
386 launch_info.GetEnvironment() = default_launch_info.GetEnvironment();
387 }
388
389 if (listener.IsValid())
390 launch_info.SetListener(listener.GetSP());
391
392 error.SetError(target_sp->Launch(launch_info, nullptr));
393
394 sb_process.SetSP(target_sp->GetProcessSP());
395 } else {
396 error.SetErrorString("SBTarget is invalid");
397 }
398
399 return sb_process;
400}
401
403 LLDB_INSTRUMENT_VA(this, sb_launch_info, error);
404
405 SBProcess sb_process;
406 if (TargetSP target_sp = GetSP()) {
407 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
408 StateType state = eStateInvalid;
409 {
410 ProcessSP process_sp = target_sp->GetProcessSP();
411 if (process_sp) {
412 state = process_sp->GetState();
413
414 if (process_sp->IsAlive() && state != eStateConnected) {
415 if (state == eStateAttaching)
416 error.SetErrorString("process attach is in progress");
417 else
418 error.SetErrorString("a process is already being debugged");
419 return sb_process;
420 }
421 }
422 }
423
424 lldb_private::ProcessLaunchInfo launch_info = sb_launch_info.ref();
425
426 if (!launch_info.GetExecutableFile()) {
427 Module *exe_module = target_sp->GetExecutableModulePointer();
428 if (exe_module)
429 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
430 }
431
432 const ArchSpec &arch_spec = target_sp->GetArchitecture();
433 if (arch_spec.IsValid())
434 launch_info.GetArchitecture() = arch_spec;
435
436 error.SetError(target_sp->Launch(launch_info, nullptr));
437 sb_launch_info.set_ref(launch_info);
438 sb_process.SetSP(target_sp->GetProcessSP());
439 } else {
440 error.SetErrorString("SBTarget is invalid");
441 }
442
443 return sb_process;
444}
445
447 LLDB_INSTRUMENT_VA(this, sb_attach_info, error);
448
449 SBProcess sb_process;
450 if (TargetSP target_sp = GetSP()) {
451 ProcessAttachInfo &attach_info = sb_attach_info.ref();
452 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid() &&
453 !attach_info.IsScriptedProcess()) {
454 PlatformSP platform_sp = target_sp->GetPlatform();
455 // See if we can pre-verify if a process exists or not
456 if (platform_sp && platform_sp->IsConnected()) {
457 lldb::pid_t attach_pid = attach_info.GetProcessID();
458 ProcessInstanceInfo instance_info;
459 if (platform_sp->GetProcessInfo(attach_pid, instance_info)) {
460 attach_info.SetUserID(instance_info.GetEffectiveUserID());
461 } else {
463 "no process found with process ID %" PRIu64, attach_pid);
464 return sb_process;
465 }
466 }
467 }
468 error.SetError(AttachToProcess(attach_info, *target_sp));
469 if (error.Success())
470 sb_process.SetSP(target_sp->GetProcessSP());
471 } else {
472 error.SetErrorString("SBTarget is invalid");
473 }
474
475 return sb_process;
476}
477
479 SBListener &listener,
480 lldb::pid_t pid, // The process ID to attach to
481 SBError &error // An error explaining what went wrong if attach fails
482) {
483 LLDB_INSTRUMENT_VA(this, listener, pid, error);
484
485 SBProcess sb_process;
486 if (TargetSP target_sp = GetSP()) {
487 ProcessAttachInfo attach_info;
488 attach_info.SetProcessID(pid);
489 if (listener.IsValid())
490 attach_info.SetListener(listener.GetSP());
491
492 ProcessInstanceInfo instance_info;
493 if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info))
494 attach_info.SetUserID(instance_info.GetEffectiveUserID());
495
496 error.SetError(AttachToProcess(attach_info, *target_sp));
497 if (error.Success())
498 sb_process.SetSP(target_sp->GetProcessSP());
499 } else
500 error.SetErrorString("SBTarget is invalid");
501
502 return sb_process;
503}
504
506 SBListener &listener,
507 const char *name, // basename of process to attach to
508 bool wait_for, // if true wait for a new instance of "name" to be launched
509 SBError &error // An error explaining what went wrong if attach fails
510) {
511 LLDB_INSTRUMENT_VA(this, listener, name, wait_for, error);
512
513 SBProcess sb_process;
514
515 if (!name) {
516 error.SetErrorString("invalid name");
517 return sb_process;
518 }
519
520 if (TargetSP target_sp = GetSP()) {
521 ProcessAttachInfo attach_info;
522 attach_info.GetExecutableFile().SetFile(name, FileSpec::Style::native);
523 attach_info.SetWaitForLaunch(wait_for);
524 if (listener.IsValid())
525 attach_info.SetListener(listener.GetSP());
526
527 error.SetError(AttachToProcess(attach_info, *target_sp));
528 if (error.Success())
529 sb_process.SetSP(target_sp->GetProcessSP());
530 } else {
531 error.SetErrorString("SBTarget is invalid");
532 }
533
534 return sb_process;
535}
536
538 const char *plugin_name,
539 SBError &error) {
540 LLDB_INSTRUMENT_VA(this, listener, url, plugin_name, error);
541
542 SBProcess sb_process;
543 ProcessSP process_sp;
544 if (TargetSP target_sp = GetSP()) {
545 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
546 if (listener.IsValid())
547 process_sp =
548 target_sp->CreateProcess(listener.m_opaque_sp, plugin_name, nullptr,
549 true);
550 else
551 process_sp = target_sp->CreateProcess(
552 target_sp->GetDebugger().GetListener(), plugin_name, nullptr, true);
553
554 if (process_sp) {
555 sb_process.SetSP(process_sp);
556 error.SetError(process_sp->ConnectRemote(url));
557 } else {
558 error.SetErrorString("unable to create lldb_private::Process");
559 }
560 } else {
561 error.SetErrorString("SBTarget is invalid");
562 }
563
564 return sb_process;
565}
566
568 LLDB_INSTRUMENT_VA(this);
569
570 SBFileSpec exe_file_spec;
571 if (TargetSP target_sp = GetSP()) {
572 Module *exe_module = target_sp->GetExecutableModulePointer();
573 if (exe_module)
574 exe_file_spec.SetFileSpec(exe_module->GetFileSpec());
575 }
576
577 return exe_file_spec;
578}
579
580bool SBTarget::operator==(const SBTarget &rhs) const {
581 LLDB_INSTRUMENT_VA(this, rhs);
582
583 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
584}
585
586bool SBTarget::operator!=(const SBTarget &rhs) const {
587 LLDB_INSTRUMENT_VA(this, rhs);
588
589 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
590}
591
593
594void SBTarget::SetSP(const lldb::TargetSP &target_sp) {
595 m_opaque_sp = target_sp;
596}
597
599 LLDB_INSTRUMENT_VA(this, vm_addr);
600
601 lldb::SBAddress sb_addr;
602 Address &addr = sb_addr.ref();
603 if (TargetSP target_sp = GetSP()) {
604 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
605 if (target_sp->ResolveLoadAddress(vm_addr, addr))
606 return sb_addr;
607 }
608
609 // We have a load address that isn't in a section, just return an address
610 // with the offset filled in (the address) and the section set to NULL
611 addr.SetRawAddress(vm_addr);
612 return sb_addr;
613}
614
616 LLDB_INSTRUMENT_VA(this, file_addr);
617
618 lldb::SBAddress sb_addr;
619 Address &addr = sb_addr.ref();
620 if (TargetSP target_sp = GetSP()) {
621 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
622 if (target_sp->ResolveFileAddress(file_addr, addr))
623 return sb_addr;
624 }
625
626 addr.SetRawAddress(file_addr);
627 return sb_addr;
628}
629
631 lldb::addr_t vm_addr) {
632 LLDB_INSTRUMENT_VA(this, stop_id, vm_addr);
633
634 lldb::SBAddress sb_addr;
635 Address &addr = sb_addr.ref();
636 if (TargetSP target_sp = GetSP()) {
637 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
638 if (target_sp->ResolveLoadAddress(vm_addr, addr))
639 return sb_addr;
640 }
641
642 // We have a load address that isn't in a section, just return an address
643 // with the offset filled in (the address) and the section set to NULL
644 addr.SetRawAddress(vm_addr);
645 return sb_addr;
646}
647
650 uint32_t resolve_scope) {
651 LLDB_INSTRUMENT_VA(this, addr, resolve_scope);
652
653 SBSymbolContext sb_sc;
654 SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
655 if (addr.IsValid()) {
656 if (TargetSP target_sp = GetSP()) {
657 lldb_private::SymbolContext &sc = sb_sc.ref();
658 sc.target_sp = target_sp;
659 target_sp->GetImages().ResolveSymbolContextForAddress(addr.ref(), scope,
660 sc);
661 }
662 }
663 return sb_sc;
664}
665
666size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size,
668 LLDB_INSTRUMENT_VA(this, addr, buf, size, error);
669
670 size_t bytes_read = 0;
671 if (TargetSP target_sp = GetSP()) {
672 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
673 bytes_read =
674 target_sp->ReadMemory(addr.ref(), buf, size, error.ref(), true);
675 } else {
676 error.SetErrorString("invalid target");
677 }
678
679 return bytes_read;
680}
681
683 uint32_t line) {
684 LLDB_INSTRUMENT_VA(this, file, line);
685
686 return SBBreakpoint(
687 BreakpointCreateByLocation(SBFileSpec(file, false), line));
688}
689
692 uint32_t line) {
693 LLDB_INSTRUMENT_VA(this, sb_file_spec, line);
694
695 return BreakpointCreateByLocation(sb_file_spec, line, 0);
696}
697
700 uint32_t line, lldb::addr_t offset) {
701 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, offset);
702
703 SBFileSpecList empty_list;
704 return BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list);
705}
706
709 uint32_t line, lldb::addr_t offset,
710 SBFileSpecList &sb_module_list) {
711 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, offset, sb_module_list);
712
713 return BreakpointCreateByLocation(sb_file_spec, line, 0, offset,
714 sb_module_list);
715}
716
718 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
719 lldb::addr_t offset, SBFileSpecList &sb_module_list) {
720 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, column, offset, sb_module_list);
721
722 SBBreakpoint sb_bp;
723 if (TargetSP target_sp = GetSP(); target_sp && line != 0) {
724 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
725
726 const LazyBool check_inlines = eLazyBoolCalculate;
727 const LazyBool skip_prologue = eLazyBoolCalculate;
728 const bool internal = false;
729 const bool hardware = false;
730 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
731 const FileSpecList *module_list = nullptr;
732 if (sb_module_list.GetSize() > 0) {
733 module_list = sb_module_list.get();
734 }
735 sb_bp = target_sp->CreateBreakpoint(
736 module_list, *sb_file_spec, line, column, offset, check_inlines,
737 skip_prologue, internal, hardware, move_to_nearest_code);
738 }
739
740 return sb_bp;
741}
742
744 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
745 lldb::addr_t offset, SBFileSpecList &sb_module_list,
746 bool move_to_nearest_code) {
747 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, column, offset, sb_module_list,
748 move_to_nearest_code);
749
750 SBBreakpoint sb_bp;
751 if (TargetSP target_sp = GetSP(); target_sp && line != 0) {
752 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
753
754 const LazyBool check_inlines = eLazyBoolCalculate;
755 const LazyBool skip_prologue = eLazyBoolCalculate;
756 const bool internal = false;
757 const bool hardware = false;
758 const FileSpecList *module_list = nullptr;
759 if (sb_module_list.GetSize() > 0) {
760 module_list = sb_module_list.get();
761 }
762 sb_bp = target_sp->CreateBreakpoint(
763 module_list, *sb_file_spec, line, column, offset, check_inlines,
764 skip_prologue, internal, hardware,
765 move_to_nearest_code ? eLazyBoolYes : eLazyBoolNo);
766 }
767
768 return sb_bp;
769}
770
772 const char *module_name) {
773 LLDB_INSTRUMENT_VA(this, symbol_name, module_name);
774
775 SBBreakpoint sb_bp;
776 if (TargetSP target_sp = GetSP()) {
777 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
778
779 const bool internal = false;
780 const bool hardware = false;
781 const LazyBool skip_prologue = eLazyBoolCalculate;
782 const lldb::addr_t offset = 0;
783 const bool offset_is_insn_count = false;
784 if (module_name && module_name[0]) {
785 FileSpecList module_spec_list;
786 module_spec_list.Append(FileSpec(module_name));
787 sb_bp = target_sp->CreateBreakpoint(
788 &module_spec_list, nullptr, symbol_name, eFunctionNameTypeAuto,
789 eLanguageTypeUnknown, offset, offset_is_insn_count, skip_prologue,
790 internal, hardware);
791 } else {
792 sb_bp = target_sp->CreateBreakpoint(
793 nullptr, nullptr, symbol_name, eFunctionNameTypeAuto,
794 eLanguageTypeUnknown, offset, offset_is_insn_count, skip_prologue,
795 internal, hardware);
796 }
797 }
798
799 return sb_bp;
800}
801
803SBTarget::BreakpointCreateByName(const char *symbol_name,
804 const SBFileSpecList &module_list,
805 const SBFileSpecList &comp_unit_list) {
806 LLDB_INSTRUMENT_VA(this, symbol_name, module_list, comp_unit_list);
807
808 lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto;
809 return BreakpointCreateByName(symbol_name, name_type_mask,
810 eLanguageTypeUnknown, module_list,
811 comp_unit_list);
812}
813
815 const char *symbol_name, uint32_t name_type_mask,
816 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
817 LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, module_list,
818 comp_unit_list);
819
820 return BreakpointCreateByName(symbol_name, name_type_mask,
821 eLanguageTypeUnknown, module_list,
822 comp_unit_list);
823}
824
826 const char *symbol_name, uint32_t name_type_mask,
827 LanguageType symbol_language, const SBFileSpecList &module_list,
828 const SBFileSpecList &comp_unit_list) {
829 LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, symbol_language,
830 module_list, comp_unit_list);
831 return BreakpointCreateByName(symbol_name, name_type_mask, symbol_language, 0,
832 false, module_list, comp_unit_list);
833}
834
836 const char *symbol_name, uint32_t name_type_mask,
837 LanguageType symbol_language, lldb::addr_t offset,
838 bool offset_is_insn_count, const SBFileSpecList &module_list,
839 const SBFileSpecList &comp_unit_list) {
840 LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, symbol_language, offset,
841 offset_is_insn_count, module_list, comp_unit_list);
842
843 SBBreakpoint sb_bp;
844 if (TargetSP target_sp = GetSP();
845 target_sp && symbol_name && symbol_name[0]) {
846 const bool internal = false;
847 const bool hardware = false;
848 const LazyBool skip_prologue = eLazyBoolCalculate;
849 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
850 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
851 sb_bp = target_sp->CreateBreakpoint(module_list.get(), comp_unit_list.get(),
852 symbol_name, mask, symbol_language,
853 offset, offset_is_insn_count,
854 skip_prologue, internal, hardware);
855 }
856
857 return sb_bp;
858}
859
861 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
862 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
863 LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask, module_list,
864 comp_unit_list);
865
866 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
867 eLanguageTypeUnknown, module_list,
868 comp_unit_list);
869}
870
872 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
873 LanguageType symbol_language, const SBFileSpecList &module_list,
874 const SBFileSpecList &comp_unit_list) {
875 LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask,
876 symbol_language, module_list, comp_unit_list);
877
878 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
879 eLanguageTypeUnknown, 0, module_list,
880 comp_unit_list);
881}
882
884 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
885 LanguageType symbol_language, lldb::addr_t offset,
886 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
887 LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask,
888 symbol_language, offset, module_list, comp_unit_list);
889
890 SBBreakpoint sb_bp;
891 if (TargetSP target_sp = GetSP(); target_sp && num_names > 0) {
892 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
893 const bool internal = false;
894 const bool hardware = false;
895 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
896 const LazyBool skip_prologue = eLazyBoolCalculate;
897 sb_bp = target_sp->CreateBreakpoint(
898 module_list.get(), comp_unit_list.get(), symbol_names, num_names, mask,
899 symbol_language, offset, skip_prologue, internal, hardware);
900 }
901
902 return sb_bp;
903}
904
906 const char *module_name) {
907 LLDB_INSTRUMENT_VA(this, symbol_name_regex, module_name);
908
909 SBFileSpecList module_spec_list;
910 SBFileSpecList comp_unit_list;
911 if (module_name && module_name[0]) {
912 module_spec_list.Append(FileSpec(module_name));
913 }
914 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
915 module_spec_list, comp_unit_list);
916}
917
919SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
920 const SBFileSpecList &module_list,
921 const SBFileSpecList &comp_unit_list) {
922 LLDB_INSTRUMENT_VA(this, symbol_name_regex, module_list, comp_unit_list);
923
924 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
925 module_list, comp_unit_list);
926}
927
929 const char *symbol_name_regex, LanguageType symbol_language,
930 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
931 LLDB_INSTRUMENT_VA(this, symbol_name_regex, symbol_language, module_list,
932 comp_unit_list);
933
934 SBBreakpoint sb_bp;
935 if (TargetSP target_sp = GetSP();
936 target_sp && symbol_name_regex && symbol_name_regex[0]) {
937 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
938 RegularExpression regexp((llvm::StringRef(symbol_name_regex)));
939 const bool internal = false;
940 const bool hardware = false;
941 const LazyBool skip_prologue = eLazyBoolCalculate;
942
943 sb_bp = target_sp->CreateFuncRegexBreakpoint(
944 module_list.get(), comp_unit_list.get(), std::move(regexp),
945 symbol_language, skip_prologue, internal, hardware);
946 }
947
948 return sb_bp;
949}
950
952 LLDB_INSTRUMENT_VA(this, address);
953
954 SBBreakpoint sb_bp;
955 if (TargetSP target_sp = GetSP()) {
956 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
957 const bool hardware = false;
958 sb_bp = target_sp->CreateBreakpoint(address, false, hardware);
959 }
960
961 return sb_bp;
962}
963
965 LLDB_INSTRUMENT_VA(this, sb_address);
966
967 SBBreakpoint sb_bp;
968 if (!sb_address.IsValid()) {
969 return sb_bp;
970 }
971
972 if (TargetSP target_sp = GetSP()) {
973 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
974 const bool hardware = false;
975 sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware);
976 }
977
978 return sb_bp;
979}
980
983 const lldb::SBFileSpec &source_file,
984 const char *module_name) {
985 LLDB_INSTRUMENT_VA(this, source_regex, source_file, module_name);
986
987 SBFileSpecList module_spec_list;
988
989 if (module_name && module_name[0]) {
990 module_spec_list.Append(FileSpec(module_name));
991 }
992
993 SBFileSpecList source_file_list;
994 if (source_file.IsValid()) {
995 source_file_list.Append(source_file);
996 }
997
998 return BreakpointCreateBySourceRegex(source_regex, module_spec_list,
999 source_file_list);
1000}
1001
1003 const char *source_regex, const SBFileSpecList &module_list,
1004 const lldb::SBFileSpecList &source_file_list) {
1005 LLDB_INSTRUMENT_VA(this, source_regex, module_list, source_file_list);
1006
1007 return BreakpointCreateBySourceRegex(source_regex, module_list,
1008 source_file_list, SBStringList());
1009}
1010
1012 const char *source_regex, const SBFileSpecList &module_list,
1013 const lldb::SBFileSpecList &source_file_list,
1014 const SBStringList &func_names) {
1015 LLDB_INSTRUMENT_VA(this, source_regex, module_list, source_file_list,
1016 func_names);
1017
1018 SBBreakpoint sb_bp;
1019 if (TargetSP target_sp = GetSP();
1020 target_sp && source_regex && source_regex[0]) {
1021 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1022 const bool hardware = false;
1023 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
1024 RegularExpression regexp((llvm::StringRef(source_regex)));
1025 std::unordered_set<std::string> func_names_set;
1026 for (size_t i = 0; i < func_names.GetSize(); i++) {
1027 func_names_set.insert(func_names.GetStringAtIndex(i));
1028 }
1029
1030 sb_bp = target_sp->CreateSourceRegexBreakpoint(
1031 module_list.get(), source_file_list.get(), func_names_set,
1032 std::move(regexp), false, hardware, move_to_nearest_code);
1033 }
1034
1035 return sb_bp;
1036}
1037
1040 bool catch_bp, bool throw_bp) {
1041 LLDB_INSTRUMENT_VA(this, language, catch_bp, throw_bp);
1042
1043 SBBreakpoint sb_bp;
1044 if (TargetSP target_sp = GetSP()) {
1045 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1046 const bool hardware = false;
1047 sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
1048 hardware);
1049 }
1050
1051 return sb_bp;
1052}
1053
1055 const char *class_name, SBStructuredData &extra_args,
1056 const SBFileSpecList &module_list, const SBFileSpecList &file_list,
1057 bool request_hardware) {
1058 LLDB_INSTRUMENT_VA(this, class_name, extra_args, module_list, file_list,
1059 request_hardware);
1060
1061 SBBreakpoint sb_bp;
1062 if (TargetSP target_sp = GetSP()) {
1063 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1064 Status error;
1065
1066 StructuredData::ObjectSP obj_sp = extra_args.m_impl_up->GetObjectSP();
1067 sb_bp =
1068 target_sp->CreateScriptedBreakpoint(class_name,
1069 module_list.get(),
1070 file_list.get(),
1071 false, /* internal */
1072 request_hardware,
1073 obj_sp,
1074 &error);
1075 }
1076
1077 return sb_bp;
1078}
1079
1081 LLDB_INSTRUMENT_VA(this);
1082
1083 if (TargetSP target_sp = GetSP()) {
1084 // The breakpoint list is thread safe, no need to lock
1085 return target_sp->GetBreakpointList().GetSize();
1086 }
1087 return 0;
1088}
1089
1091 LLDB_INSTRUMENT_VA(this, idx);
1092
1093 SBBreakpoint sb_breakpoint;
1094 if (TargetSP target_sp = GetSP()) {
1095 // The breakpoint list is thread safe, no need to lock
1096 sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1097 }
1098 return sb_breakpoint;
1099}
1100
1102 LLDB_INSTRUMENT_VA(this, bp_id);
1103
1104 bool result = false;
1105 if (TargetSP target_sp = GetSP()) {
1106 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1107 result = target_sp->RemoveBreakpointByID(bp_id);
1108 }
1109
1110 return result;
1111}
1112
1114 LLDB_INSTRUMENT_VA(this, bp_id);
1115
1116 SBBreakpoint sb_breakpoint;
1117 if (TargetSP target_sp = GetSP();
1118 target_sp && bp_id != LLDB_INVALID_BREAK_ID) {
1119 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1120 sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
1121 }
1122
1123 return sb_breakpoint;
1124}
1125
1127 SBBreakpointList &bkpts) {
1128 LLDB_INSTRUMENT_VA(this, name, bkpts);
1129
1130 if (TargetSP target_sp = GetSP()) {
1131 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1132 llvm::Expected<std::vector<BreakpointSP>> expected_vector =
1133 target_sp->GetBreakpointList().FindBreakpointsByName(name);
1134 if (!expected_vector) {
1135 LLDB_LOG_ERROR(GetLog(LLDBLog::Breakpoints), expected_vector.takeError(),
1136 "invalid breakpoint name: {0}");
1137 return false;
1138 }
1139 for (BreakpointSP bkpt_sp : *expected_vector) {
1140 bkpts.AppendByID(bkpt_sp->GetID());
1141 }
1142 }
1143 return true;
1144}
1145
1147 LLDB_INSTRUMENT_VA(this, names);
1148
1149 names.Clear();
1150
1151 if (TargetSP target_sp = GetSP()) {
1152 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1153
1154 std::vector<std::string> name_vec;
1155 target_sp->GetBreakpointNames(name_vec);
1156 for (const auto &name : name_vec)
1157 names.AppendString(name.c_str());
1158 }
1159}
1160
1161void SBTarget::DeleteBreakpointName(const char *name) {
1162 LLDB_INSTRUMENT_VA(this, name);
1163
1164 if (TargetSP target_sp = GetSP()) {
1165 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1166 target_sp->DeleteBreakpointName(ConstString(name));
1167 }
1168}
1169
1171 LLDB_INSTRUMENT_VA(this);
1172
1173 if (TargetSP target_sp = GetSP()) {
1174 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1175 target_sp->EnableAllowedBreakpoints();
1176 return true;
1177 }
1178 return false;
1179}
1180
1182 LLDB_INSTRUMENT_VA(this);
1183
1184 if (TargetSP target_sp = GetSP()) {
1185 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1186 target_sp->DisableAllowedBreakpoints();
1187 return true;
1188 }
1189 return false;
1190}
1191
1193 LLDB_INSTRUMENT_VA(this);
1194
1195 if (TargetSP target_sp = GetSP()) {
1196 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1197 target_sp->RemoveAllowedBreakpoints();
1198 return true;
1199 }
1200 return false;
1201}
1202
1204 SBBreakpointList &new_bps) {
1205 LLDB_INSTRUMENT_VA(this, source_file, new_bps);
1206
1207 SBStringList empty_name_list;
1208 return BreakpointsCreateFromFile(source_file, empty_name_list, new_bps);
1209}
1210
1212 SBStringList &matching_names,
1213 SBBreakpointList &new_bps) {
1214 LLDB_INSTRUMENT_VA(this, source_file, matching_names, new_bps);
1215
1216 SBError sberr;
1217 if (TargetSP target_sp = GetSP()) {
1218 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1219
1220 BreakpointIDList bp_ids;
1221
1222 std::vector<std::string> name_vector;
1223 size_t num_names = matching_names.GetSize();
1224 for (size_t i = 0; i < num_names; i++)
1225 name_vector.push_back(matching_names.GetStringAtIndex(i));
1226
1227 sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(),
1228 name_vector, bp_ids);
1229 if (sberr.Fail())
1230 return sberr;
1231
1232 size_t num_bkpts = bp_ids.GetSize();
1233 for (size_t i = 0; i < num_bkpts; i++) {
1234 BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
1235 new_bps.AppendByID(bp_id.GetBreakpointID());
1236 }
1237 } else {
1238 sberr.SetErrorString(
1239 "BreakpointCreateFromFile called with invalid target.");
1240 }
1241 return sberr;
1242}
1243
1245 LLDB_INSTRUMENT_VA(this, dest_file);
1246
1247 SBError sberr;
1248 if (TargetSP target_sp = GetSP()) {
1249 SBBreakpointList bkpt_list(*this);
1250 return BreakpointsWriteToFile(dest_file, bkpt_list);
1251 }
1252 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1253 return sberr;
1254}
1255
1257 SBBreakpointList &bkpt_list,
1258 bool append) {
1259 LLDB_INSTRUMENT_VA(this, dest_file, bkpt_list, append);
1260
1261 SBError sberr;
1262 if (TargetSP target_sp = GetSP()) {
1263 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1264 BreakpointIDList bp_id_list;
1265 bkpt_list.CopyToBreakpointIDList(bp_id_list);
1266 sberr.ref() = target_sp->SerializeBreakpointsToFile(dest_file.ref(),
1267 bp_id_list, append);
1268 } else {
1269 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1270 }
1271 return sberr;
1272}
1273
1275 LLDB_INSTRUMENT_VA(this);
1276
1277 if (TargetSP target_sp = GetSP()) {
1278 // The watchpoint list is thread safe, no need to lock
1279 return target_sp->GetWatchpointList().GetSize();
1280 }
1281 return 0;
1282}
1283
1285 LLDB_INSTRUMENT_VA(this, idx);
1286
1287 SBWatchpoint sb_watchpoint;
1288 if (TargetSP target_sp = GetSP()) {
1289 // The watchpoint list is thread safe, no need to lock
1290 sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1291 }
1292 return sb_watchpoint;
1293}
1294
1296 LLDB_INSTRUMENT_VA(this, wp_id);
1297
1298 bool result = false;
1299 if (TargetSP target_sp = GetSP()) {
1300 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1301 std::unique_lock<std::recursive_mutex> lock;
1302 target_sp->GetWatchpointList().GetListMutex(lock);
1303 result = target_sp->RemoveWatchpointByID(wp_id);
1304 }
1305
1306 return result;
1307}
1308
1310 LLDB_INSTRUMENT_VA(this, wp_id);
1311
1312 SBWatchpoint sb_watchpoint;
1313 lldb::WatchpointSP watchpoint_sp;
1314 if (TargetSP target_sp = GetSP();
1315 target_sp && wp_id != LLDB_INVALID_WATCH_ID) {
1316 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1317 std::unique_lock<std::recursive_mutex> lock;
1318 target_sp->GetWatchpointList().GetListMutex(lock);
1319 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1320 sb_watchpoint.SetSP(watchpoint_sp);
1321 }
1322
1323 return sb_watchpoint;
1324}
1325
1327 bool read, bool modify,
1328 SBError &error) {
1329 LLDB_INSTRUMENT_VA(this, addr, size, read, write, error);
1330
1331 SBWatchpointOptions options;
1332 options.SetWatchpointTypeRead(read);
1333 if (modify)
1335 return WatchpointCreateByAddress(addr, size, options, error);
1336}
1337
1340 SBWatchpointOptions options,
1341 SBError &error) {
1342 LLDB_INSTRUMENT_VA(this, addr, size, options, error);
1343
1344 SBWatchpoint sb_watchpoint;
1345 lldb::WatchpointSP watchpoint_sp;
1346 uint32_t watch_type = 0;
1347 if (options.GetWatchpointTypeRead())
1348 watch_type |= LLDB_WATCH_TYPE_READ;
1350 watch_type |= LLDB_WATCH_TYPE_WRITE;
1352 watch_type |= LLDB_WATCH_TYPE_MODIFY;
1353 if (watch_type == 0) {
1354 error.SetErrorString("Can't create a watchpoint that is neither read nor "
1355 "write nor modify.");
1356 return sb_watchpoint;
1357 }
1358
1359 if (TargetSP target_sp = GetSP();
1360 target_sp && addr != LLDB_INVALID_ADDRESS && size > 0) {
1361 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1362 // Target::CreateWatchpoint() is thread safe.
1363 Status cw_error;
1364 // This API doesn't take in a type, so we can't figure out what it is.
1365 CompilerType *type = nullptr;
1366 watchpoint_sp =
1367 target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1368 error.SetError(std::move(cw_error));
1369 sb_watchpoint.SetSP(watchpoint_sp);
1370 }
1371
1372 return sb_watchpoint;
1373}
1374
1376 LLDB_INSTRUMENT_VA(this);
1377
1378 if (TargetSP target_sp = GetSP()) {
1379 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1380 std::unique_lock<std::recursive_mutex> lock;
1381 target_sp->GetWatchpointList().GetListMutex(lock);
1382 target_sp->EnableAllWatchpoints();
1383 return true;
1384 }
1385 return false;
1386}
1387
1389 LLDB_INSTRUMENT_VA(this);
1390
1391 if (TargetSP target_sp = GetSP()) {
1392 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1393 std::unique_lock<std::recursive_mutex> lock;
1394 target_sp->GetWatchpointList().GetListMutex(lock);
1395 target_sp->DisableAllWatchpoints();
1396 return true;
1397 }
1398 return false;
1399}
1400
1402 SBType type) {
1403 LLDB_INSTRUMENT_VA(this, name, addr, type);
1404
1405 SBValue sb_value;
1406 lldb::ValueObjectSP new_value_sp;
1407 if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) {
1408 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1409 ExecutionContext exe_ctx(
1411 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1412 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr,
1413 exe_ctx, ast_type);
1414 }
1415 sb_value.SetSP(new_value_sp);
1416 return sb_value;
1417}
1418
1420 lldb::SBType type) {
1421 LLDB_INSTRUMENT_VA(this, name, data, type);
1422
1423 SBValue sb_value;
1424 lldb::ValueObjectSP new_value_sp;
1425 if (IsValid() && name && *name && data.IsValid() && type.IsValid()) {
1426 DataExtractorSP extractor(*data);
1427 ExecutionContext exe_ctx(
1429 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1430 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor,
1431 exe_ctx, ast_type);
1432 }
1433 sb_value.SetSP(new_value_sp);
1434 return sb_value;
1435}
1436
1438 const char *expr) {
1439 LLDB_INSTRUMENT_VA(this, name, expr);
1440
1441 SBValue sb_value;
1442 lldb::ValueObjectSP new_value_sp;
1443 if (IsValid() && name && *name && expr && *expr) {
1444 ExecutionContext exe_ctx(
1446 new_value_sp =
1448 }
1449 sb_value.SetSP(new_value_sp);
1450 return sb_value;
1451}
1452
1454 LLDB_INSTRUMENT_VA(this);
1455
1456 if (TargetSP target_sp = GetSP()) {
1457 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1458 std::unique_lock<std::recursive_mutex> lock;
1459 target_sp->GetWatchpointList().GetListMutex(lock);
1460 target_sp->RemoveAllWatchpoints();
1461 return true;
1462 }
1463 return false;
1464}
1465
1466void SBTarget::AppendImageSearchPath(const char *from, const char *to,
1468 LLDB_INSTRUMENT_VA(this, from, to, error);
1469
1470 if (TargetSP target_sp = GetSP()) {
1471 llvm::StringRef srFrom = from, srTo = to;
1472 if (srFrom.empty())
1473 return error.SetErrorString("<from> path can't be empty");
1474 if (srTo.empty())
1475 return error.SetErrorString("<to> path can't be empty");
1476
1477 target_sp->GetImageSearchPathList().Append(srFrom, srTo, true);
1478 } else {
1479 error.SetErrorString("invalid target");
1480 }
1481}
1482
1483lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1484 const char *uuid_cstr) {
1485 LLDB_INSTRUMENT_VA(this, path, triple, uuid_cstr);
1486
1487 return AddModule(path, triple, uuid_cstr, nullptr);
1488}
1489
1490lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1491 const char *uuid_cstr, const char *symfile) {
1492 LLDB_INSTRUMENT_VA(this, path, triple, uuid_cstr, symfile);
1493
1494 if (TargetSP target_sp = GetSP()) {
1495 ModuleSpec module_spec;
1496 if (path)
1497 module_spec.GetFileSpec().SetFile(path, FileSpec::Style::native);
1498
1499 if (uuid_cstr)
1500 module_spec.GetUUID().SetFromStringRef(uuid_cstr);
1501
1502 if (triple)
1504 target_sp->GetPlatform().get(), triple);
1505 else
1506 module_spec.GetArchitecture() = target_sp->GetArchitecture();
1507
1508 if (symfile)
1509 module_spec.GetSymbolFileSpec().SetFile(symfile, FileSpec::Style::native);
1510
1511 SBModuleSpec sb_modulespec(module_spec);
1512
1513 return AddModule(sb_modulespec);
1514 }
1515 return SBModule();
1516}
1517
1519 LLDB_INSTRUMENT_VA(this, module_spec);
1520
1521 lldb::SBModule sb_module;
1522 if (TargetSP target_sp = GetSP()) {
1523 sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,
1524 true /* notify */));
1525 if (!sb_module.IsValid() && module_spec.m_opaque_up->GetUUID().IsValid()) {
1526 Status error;
1528 error,
1529 /* force_lookup */ true)) {
1530 if (FileSystem::Instance().Exists(
1531 module_spec.m_opaque_up->GetFileSpec())) {
1532 sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,
1533 true /* notify */));
1534 }
1535 }
1536 }
1537
1538 // If the target hasn't initialized any architecture yet, use the
1539 // binary's architecture.
1540 if (sb_module.IsValid() && !target_sp->GetArchitecture().IsValid() &&
1541 sb_module.GetSP()->GetArchitecture().IsValid())
1542 target_sp->SetArchitecture(sb_module.GetSP()->GetArchitecture());
1543 }
1544 return sb_module;
1545}
1546
1548 LLDB_INSTRUMENT_VA(this, module);
1549
1550 if (TargetSP target_sp = GetSP()) {
1551 target_sp->GetImages().AppendIfNeeded(module.GetSP());
1552 return true;
1553 }
1554 return false;
1555}
1556
1557uint32_t SBTarget::GetNumModules() const {
1558 LLDB_INSTRUMENT_VA(this);
1559
1560 uint32_t num = 0;
1561 if (TargetSP target_sp = GetSP()) {
1562 // The module list is thread safe, no need to lock
1563 num = target_sp->GetImages().GetSize();
1564 }
1565
1566 return num;
1567}
1568
1570 LLDB_INSTRUMENT_VA(this);
1571
1572 m_opaque_sp.reset();
1573}
1574
1576 LLDB_INSTRUMENT_VA(this, sb_file_spec);
1577
1578 SBModule sb_module;
1579 if (TargetSP target_sp = GetSP(); target_sp && sb_file_spec.IsValid()) {
1580 ModuleSpec module_spec(*sb_file_spec);
1581 // The module list is thread safe, no need to lock
1582 sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1583 }
1584 return sb_module;
1585}
1586
1587SBModule SBTarget::FindModule(const SBModuleSpec &sb_module_spec) const {
1588 LLDB_INSTRUMENT_VA(this, sb_module_spec);
1589
1590 SBModule sb_module;
1591 if (TargetSP target_sp = GetSP(); target_sp && sb_module_spec.IsValid()) {
1592 // The module list is thread safe, no need to lock.
1593 sb_module.SetSP(
1594 target_sp->GetImages().FindFirstModule(*sb_module_spec.m_opaque_up));
1595 }
1596 return sb_module;
1597}
1598
1600 LLDB_INSTRUMENT_VA(this, sb_file_spec);
1601
1602 SBSymbolContextList sb_sc_list;
1603 if (TargetSP target_sp = GetSP(); target_sp && sb_file_spec.IsValid())
1604 target_sp->GetImages().FindCompileUnits(*sb_file_spec, *sb_sc_list);
1605 return sb_sc_list;
1606}
1607
1609 LLDB_INSTRUMENT_VA(this);
1610
1611 if (TargetSP target_sp = GetSP())
1612 return target_sp->GetArchitecture().GetByteOrder();
1613 return eByteOrderInvalid;
1614}
1615
1616const char *SBTarget::GetTriple() {
1617 LLDB_INSTRUMENT_VA(this);
1618
1619 if (TargetSP target_sp = GetSP()) {
1620 std::string triple(target_sp->GetArchitecture().GetTriple().str());
1621 // Unique the string so we don't run into ownership issues since the const
1622 // strings put the string into the string pool once and the strings never
1623 // comes out
1624 ConstString const_triple(triple.c_str());
1625 return const_triple.GetCString();
1626 }
1627 return nullptr;
1628}
1629
1630const char *SBTarget::GetArchName() const {
1631 LLDB_INSTRUMENT_VA(this);
1632
1633 if (TargetSP target_sp = GetSP()) {
1634 llvm::StringRef arch_name =
1635 target_sp->GetArchitecture().GetTriple().getArchName();
1636 ConstString const_arch_name(arch_name);
1637
1638 return const_arch_name.GetCString();
1639 }
1640 return nullptr;
1641}
1642
1644 LLDB_INSTRUMENT_VA(this);
1645
1646 if (TargetSP target_sp = GetSP()) {
1647 std::string abi_name(target_sp->GetABIName().str());
1648 ConstString const_name(abi_name.c_str());
1649 return const_name.GetCString();
1650 }
1651 return nullptr;
1652}
1653
1654const char *SBTarget::GetLabel() const {
1655 LLDB_INSTRUMENT_VA(this);
1656
1657 if (TargetSP target_sp = GetSP())
1658 return ConstString(target_sp->GetLabel().data()).AsCString(nullptr);
1659 return nullptr;
1660}
1661
1663 LLDB_INSTRUMENT_VA(this);
1664
1665 if (TargetSP target_sp = GetSP())
1666 return target_sp->GetGloballyUniqueID();
1668}
1669
1671 LLDB_INSTRUMENT_VA(this);
1672
1673 if (TargetSP target_sp = GetSP())
1674 return ConstString(target_sp->GetTargetSessionName()).AsCString(nullptr);
1675 return nullptr;
1676}
1677
1678SBError SBTarget::SetLabel(const char *label) {
1679 LLDB_INSTRUMENT_VA(this, label);
1680
1681 if (TargetSP target_sp = GetSP())
1682 return Status::FromError(target_sp->SetLabel(label));
1683 return Status::FromErrorString("Couldn't get internal target object.");
1684}
1685
1687 LLDB_INSTRUMENT_VA(this);
1688
1689 if (TargetSP target_sp = GetSP())
1690 return target_sp->GetArchitecture().GetMinimumOpcodeByteSize();
1691 return 0;
1692}
1693
1695 LLDB_INSTRUMENT_VA(this);
1696
1697 TargetSP target_sp(GetSP());
1698 if (target_sp)
1699 return target_sp->GetArchitecture().GetMaximumOpcodeByteSize();
1700
1701 return 0;
1702}
1703
1705 LLDB_INSTRUMENT_VA(this);
1706
1707 return 1;
1708}
1709
1711 LLDB_INSTRUMENT_VA(this);
1712
1713 return 1;
1714}
1715
1717 LLDB_INSTRUMENT_VA(this);
1718
1719 if (TargetSP target_sp = GetSP())
1720 return target_sp->GetMaximumNumberOfChildrenToDisplay();
1721 return 0;
1722}
1723
1725 LLDB_INSTRUMENT_VA(this);
1726
1727 if (TargetSP target_sp = GetSP())
1728 return target_sp->GetArchitecture().GetAddressByteSize();
1729 return sizeof(void *);
1730}
1731
1733 LLDB_INSTRUMENT_VA(this, idx);
1734
1735 SBModule sb_module;
1736 ModuleSP module_sp;
1737 if (TargetSP target_sp = GetSP()) {
1738 // The module list is thread safe, no need to lock
1739 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1740 sb_module.SetSP(module_sp);
1741 }
1742
1743 return sb_module;
1744}
1745
1747 LLDB_INSTRUMENT_VA(this, module);
1748
1749 if (TargetSP target_sp = GetSP())
1750 return target_sp->GetImages().Remove(module.GetSP());
1751 return false;
1752}
1753
1755 LLDB_INSTRUMENT_VA(this);
1756
1757 if (TargetSP target_sp = GetSP()) {
1758 SBBroadcaster broadcaster(target_sp.get(), false);
1759 return broadcaster;
1760 }
1761 return SBBroadcaster();
1762}
1763
1765 lldb::DescriptionLevel description_level) {
1766 LLDB_INSTRUMENT_VA(this, description, description_level);
1767
1768 Stream &strm = description.ref();
1769
1770 if (TargetSP target_sp = GetSP()) {
1771 target_sp->Dump(&strm, description_level);
1772 } else
1773 strm.PutCString("No value");
1774
1775 return true;
1776}
1777
1779 uint32_t name_type_mask) {
1780 LLDB_INSTRUMENT_VA(this, name, name_type_mask);
1781
1782 lldb::SBSymbolContextList sb_sc_list;
1783 if (!name || !name[0])
1784 return sb_sc_list;
1785
1786 if (TargetSP target_sp = GetSP()) {
1787 ModuleFunctionSearchOptions function_options;
1788 function_options.include_symbols = true;
1789 function_options.include_inlines = true;
1790
1791 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
1792 target_sp->GetImages().FindFunctions(ConstString(name), mask,
1793 function_options, *sb_sc_list);
1794 }
1795 return sb_sc_list;
1796}
1797
1799 uint32_t max_matches,
1800 MatchType matchtype) {
1801 LLDB_INSTRUMENT_VA(this, name, max_matches, matchtype);
1802
1803 lldb::SBSymbolContextList sb_sc_list;
1804 if (name && name[0]) {
1805 llvm::StringRef name_ref(name);
1806 if (TargetSP target_sp = GetSP()) {
1807 ModuleFunctionSearchOptions function_options;
1808 function_options.include_symbols = true;
1809 function_options.include_inlines = true;
1810
1811 std::string regexstr;
1812 switch (matchtype) {
1813 case eMatchTypeRegex:
1814 target_sp->GetImages().FindFunctions(RegularExpression(name_ref),
1815 function_options, *sb_sc_list);
1816 break;
1818 target_sp->GetImages().FindFunctions(
1819 RegularExpression(name_ref, llvm::Regex::RegexFlags::IgnoreCase),
1820 function_options, *sb_sc_list);
1821 break;
1823 regexstr = llvm::Regex::escape(name) + ".*";
1824 target_sp->GetImages().FindFunctions(RegularExpression(regexstr),
1825 function_options, *sb_sc_list);
1826 break;
1827 default:
1828 target_sp->GetImages().FindFunctions(ConstString(name),
1829 eFunctionNameTypeAny,
1830 function_options, *sb_sc_list);
1831 break;
1832 }
1833 }
1834 }
1835 return sb_sc_list;
1836}
1837
1838lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
1839 LLDB_INSTRUMENT_VA(this, typename_cstr);
1840
1841 if (TargetSP target_sp = GetSP();
1842 target_sp && typename_cstr && typename_cstr[0]) {
1843 ConstString const_typename(typename_cstr);
1844 TypeQuery query(const_typename.GetStringRef(),
1845 TypeQueryOptions::e_find_one);
1846 TypeResults results;
1847 target_sp->GetImages().FindTypes(/*search_first=*/nullptr, query, results);
1848 if (TypeSP type_sp = results.GetFirstType())
1849 return SBType(type_sp);
1850 // Didn't find the type in the symbols; Try the loaded language runtimes.
1851 if (auto process_sp = target_sp->GetProcessSP()) {
1852 for (auto *runtime : process_sp->GetLanguageRuntimes()) {
1853 if (auto vendor = runtime->GetDeclVendor()) {
1854 auto types = vendor->FindTypes(const_typename, /*max_matches*/ 1);
1855 if (!types.empty())
1856 return SBType(types.front());
1857 }
1858 }
1859 }
1860
1861 // No matches, search for basic typename matches.
1862 for (auto type_system_sp : target_sp->GetScratchTypeSystems())
1863 if (auto type = type_system_sp->GetBuiltinTypeByName(const_typename))
1864 return SBType(type);
1865 }
1866
1867 return SBType();
1868}
1869
1871 LLDB_INSTRUMENT_VA(this, type);
1872
1873 if (TargetSP target_sp = GetSP()) {
1874 for (auto type_system_sp : target_sp->GetScratchTypeSystems())
1875 if (auto compiler_type = type_system_sp->GetBasicTypeFromAST(type))
1876 return SBType(compiler_type);
1877 }
1878 return SBType();
1879}
1880
1881lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
1882 LLDB_INSTRUMENT_VA(this, typename_cstr);
1883
1884 SBTypeList sb_type_list;
1885 if (TargetSP target_sp = GetSP();
1886 target_sp && typename_cstr && typename_cstr[0]) {
1887 ModuleList &images = target_sp->GetImages();
1888 ConstString const_typename(typename_cstr);
1889 TypeQuery query(typename_cstr);
1890 TypeResults results;
1891 images.FindTypes(nullptr, query, results);
1892 for (const TypeSP &type_sp : results.GetTypeMap().Types())
1893 sb_type_list.Append(SBType(type_sp));
1894
1895 // Try the loaded language runtimes
1896 if (ProcessSP process_sp = target_sp->GetProcessSP()) {
1897 for (auto *runtime : process_sp->GetLanguageRuntimes()) {
1898 if (auto *vendor = runtime->GetDeclVendor()) {
1899 auto types =
1900 vendor->FindTypes(const_typename, /*max_matches*/ UINT32_MAX);
1901 for (auto type : types)
1902 sb_type_list.Append(SBType(type));
1903 }
1904 }
1905 }
1906
1907 if (sb_type_list.GetSize() == 0) {
1908 // No matches, search for basic typename matches
1909 for (auto type_system_sp : target_sp->GetScratchTypeSystems())
1910 if (auto compiler_type =
1911 type_system_sp->GetBuiltinTypeByName(const_typename))
1912 sb_type_list.Append(SBType(compiler_type));
1913 }
1914 }
1915 return sb_type_list;
1916}
1917
1919 uint32_t max_matches) {
1920 LLDB_INSTRUMENT_VA(this, name, max_matches);
1921
1922 SBValueList sb_value_list;
1923
1924 if (TargetSP target_sp = GetSP(); target_sp && name) {
1925 VariableList variable_list;
1926 target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
1927 variable_list);
1928 if (!variable_list.Empty()) {
1929 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1930 if (exe_scope == nullptr)
1931 exe_scope = target_sp.get();
1932 for (const VariableSP &var_sp : variable_list) {
1933 lldb::ValueObjectSP valobj_sp(
1934 ValueObjectVariable::Create(exe_scope, var_sp));
1935 if (valobj_sp)
1936 sb_value_list.Append(SBValue(valobj_sp));
1937 }
1938 }
1939 }
1940
1941 return sb_value_list;
1942}
1943
1945 uint32_t max_matches,
1946 MatchType matchtype) {
1947 LLDB_INSTRUMENT_VA(this, name, max_matches, matchtype);
1948
1949 SBValueList sb_value_list;
1950
1951 if (TargetSP target_sp = GetSP(); target_sp && name) {
1952 llvm::StringRef name_ref(name);
1953 VariableList variable_list;
1954
1955 std::string regexstr;
1956 switch (matchtype) {
1957 case eMatchTypeNormal:
1958 target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
1959 variable_list);
1960 break;
1961 case eMatchTypeRegex:
1962 target_sp->GetImages().FindGlobalVariables(RegularExpression(name_ref),
1963 max_matches, variable_list);
1964 break;
1966 target_sp->GetImages().FindGlobalVariables(
1967 RegularExpression(name_ref, llvm::Regex::IgnoreCase), max_matches,
1968 variable_list);
1969 break;
1971 regexstr = "^" + llvm::Regex::escape(name) + ".*";
1972 target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr),
1973 max_matches, variable_list);
1974 break;
1975 }
1976 if (!variable_list.Empty()) {
1977 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1978 if (exe_scope == nullptr)
1979 exe_scope = target_sp.get();
1980 for (const VariableSP &var_sp : variable_list) {
1981 lldb::ValueObjectSP valobj_sp(
1982 ValueObjectVariable::Create(exe_scope, var_sp));
1983 if (valobj_sp)
1984 sb_value_list.Append(SBValue(valobj_sp));
1985 }
1986 }
1987 }
1988
1989 return sb_value_list;
1990}
1991
1993 LLDB_INSTRUMENT_VA(this, name);
1994
1995 SBValueList sb_value_list(FindGlobalVariables(name, 1));
1996 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
1997 return sb_value_list.GetValueAtIndex(0);
1998 return SBValue();
1999}
2000
2002 LLDB_INSTRUMENT_VA(this);
2003
2004 SBSourceManager source_manager(*this);
2005 return source_manager;
2006}
2007
2009 uint32_t count) {
2010 LLDB_INSTRUMENT_VA(this, base_addr, count);
2011
2012 return ReadInstructions(base_addr, count, nullptr);
2013}
2014
2016 uint32_t count,
2017 const char *flavor_string) {
2018 LLDB_INSTRUMENT_VA(this, base_addr, count, flavor_string);
2019
2020 SBInstructionList sb_instructions;
2021
2022 if (TargetSP target_sp = GetSP()) {
2023 if (Address *addr_ptr = base_addr.get()) {
2024 if (llvm::Expected<DisassemblerSP> disassembler =
2025 target_sp->ReadInstructions(*addr_ptr, count, flavor_string)) {
2026 sb_instructions.SetDisassembler(*disassembler);
2027 }
2028 }
2029 }
2030
2031 return sb_instructions;
2032}
2033
2035 lldb::SBAddress end_addr,
2036 const char *flavor_string) {
2037 LLDB_INSTRUMENT_VA(this, start_addr, end_addr, flavor_string);
2038
2039 SBInstructionList sb_instructions;
2040
2041 if (TargetSP target_sp = GetSP()) {
2042 lldb::addr_t start_load_addr = start_addr.GetLoadAddress(*this);
2043 lldb::addr_t end_load_addr = end_addr.GetLoadAddress(*this);
2044 if (end_load_addr > start_load_addr) {
2045 lldb::addr_t size = end_load_addr - start_load_addr;
2046
2047 AddressRange range(start_load_addr, size);
2048 const bool force_live_memory = true;
2050 target_sp->GetArchitecture(), nullptr, flavor_string,
2051 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
2052 *target_sp, range, force_live_memory));
2053 }
2054 }
2055 return sb_instructions;
2056}
2057
2059 const void *buf,
2060 size_t size) {
2061 LLDB_INSTRUMENT_VA(this, base_addr, buf, size);
2062
2063 return GetInstructionsWithFlavor(base_addr, nullptr, buf, size);
2064}
2065
2068 const char *flavor_string, const void *buf,
2069 size_t size) {
2070 LLDB_INSTRUMENT_VA(this, base_addr, flavor_string, buf, size);
2071
2072 SBInstructionList sb_instructions;
2073
2074 if (TargetSP target_sp = GetSP()) {
2075 Address addr;
2076
2077 if (base_addr.get())
2078 addr = *base_addr.get();
2079
2080 constexpr bool data_from_file = true;
2081 if (!flavor_string || flavor_string[0] == '\0') {
2082 // FIXME - we don't have the mechanism in place to do per-architecture
2083 // settings. But since we know that for now we only support flavors on
2084 // x86 & x86_64,
2085 const llvm::Triple::ArchType arch =
2086 target_sp->GetArchitecture().GetTriple().getArch();
2087 if (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64)
2088 flavor_string = target_sp->GetDisassemblyFlavor();
2089 }
2090
2092 target_sp->GetArchitecture(), nullptr, flavor_string,
2093 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
2094 addr, buf, size, UINT32_MAX, data_from_file));
2095 }
2096
2097 return sb_instructions;
2098}
2099
2101 const void *buf,
2102 size_t size) {
2103 LLDB_INSTRUMENT_VA(this, base_addr, buf, size);
2104
2105 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), nullptr, buf,
2106 size);
2107}
2108
2111 const char *flavor_string, const void *buf,
2112 size_t size) {
2113 LLDB_INSTRUMENT_VA(this, base_addr, flavor_string, buf, size);
2114
2115 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string,
2116 buf, size);
2117}
2118
2120 lldb::addr_t section_base_addr) {
2121 LLDB_INSTRUMENT_VA(this, section, section_base_addr);
2122
2123 SBError sb_error;
2124 if (TargetSP target_sp = GetSP()) {
2125 if (!section.IsValid()) {
2126 sb_error.SetErrorStringWithFormat("invalid section");
2127 } else {
2128 SectionSP section_sp(section.GetSP());
2129 if (section_sp) {
2130 if (section_sp->IsThreadSpecific()) {
2131 sb_error.SetErrorString(
2132 "thread specific sections are not yet supported");
2133 } else {
2134 ProcessSP process_sp(target_sp->GetProcessSP());
2135 if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
2136 ModuleSP module_sp(section_sp->GetModule());
2137 if (module_sp) {
2138 ModuleList module_list;
2139 module_list.Append(module_sp);
2140 target_sp->ModulesDidLoad(module_list);
2141 }
2142 // Flush info in the process (stack frames, etc)
2143 if (process_sp)
2144 process_sp->Flush();
2145 }
2146 }
2147 }
2148 }
2149 } else {
2150 sb_error.SetErrorString("invalid target");
2151 }
2152 return sb_error;
2153}
2154
2156 LLDB_INSTRUMENT_VA(this, section);
2157
2158 SBError sb_error;
2159
2160 if (TargetSP target_sp = GetSP()) {
2161 if (!section.IsValid()) {
2162 sb_error.SetErrorStringWithFormat("invalid section");
2163 } else {
2164 SectionSP section_sp(section.GetSP());
2165 if (section_sp) {
2166 ProcessSP process_sp(target_sp->GetProcessSP());
2167 if (target_sp->SetSectionUnloaded(section_sp)) {
2168 ModuleSP module_sp(section_sp->GetModule());
2169 if (module_sp) {
2170 ModuleList module_list;
2171 module_list.Append(module_sp);
2172 target_sp->ModulesDidUnload(module_list, false);
2173 }
2174 // Flush info in the process (stack frames, etc)
2175 if (process_sp)
2176 process_sp->Flush();
2177 }
2178 } else {
2179 sb_error.SetErrorStringWithFormat("invalid section");
2180 }
2181 }
2182 } else {
2183 sb_error.SetErrorStringWithFormat("invalid target");
2184 }
2185 return sb_error;
2186}
2187
2189 int64_t slide_offset) {
2190 LLDB_INSTRUMENT_VA(this, module, slide_offset);
2191
2192 if (slide_offset < 0) {
2193 SBError sb_error;
2194 sb_error.SetErrorStringWithFormat("slide must be positive");
2195 return sb_error;
2196 }
2197
2198 return SetModuleLoadAddress(module, static_cast<uint64_t>(slide_offset));
2199}
2200
2202 uint64_t slide_offset) {
2203
2204 SBError sb_error;
2205
2206 if (TargetSP target_sp = GetSP()) {
2207 ModuleSP module_sp(module.GetSP());
2208 if (module_sp) {
2209 bool changed = false;
2210 if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) {
2211 // The load was successful, make sure that at least some sections
2212 // changed before we notify that our module was loaded.
2213 if (changed) {
2214 ModuleList module_list;
2215 module_list.Append(module_sp);
2216 target_sp->ModulesDidLoad(module_list);
2217 // Flush info in the process (stack frames, etc)
2218 ProcessSP process_sp(target_sp->GetProcessSP());
2219 if (process_sp)
2220 process_sp->Flush();
2221 }
2222 }
2223 } else {
2224 sb_error.SetErrorStringWithFormat("invalid module");
2225 }
2226
2227 } else {
2228 sb_error.SetErrorStringWithFormat("invalid target");
2229 }
2230 return sb_error;
2231}
2232
2234 LLDB_INSTRUMENT_VA(this, module);
2235
2236 SBError sb_error;
2237
2238 char path[PATH_MAX];
2239 if (TargetSP target_sp = GetSP()) {
2240 ModuleSP module_sp(module.GetSP());
2241 if (module_sp) {
2242 ObjectFile *objfile = module_sp->GetObjectFile();
2243 if (objfile) {
2244 SectionList *section_list = objfile->GetSectionList();
2245 if (section_list) {
2246 ProcessSP process_sp(target_sp->GetProcessSP());
2247
2248 bool changed = false;
2249 const size_t num_sections = section_list->GetSize();
2250 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
2251 SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
2252 if (section_sp)
2253 changed |= target_sp->SetSectionUnloaded(section_sp);
2254 }
2255 if (changed) {
2256 ModuleList module_list;
2257 module_list.Append(module_sp);
2258 target_sp->ModulesDidUnload(module_list, false);
2259 // Flush info in the process (stack frames, etc)
2260 ProcessSP process_sp(target_sp->GetProcessSP());
2261 if (process_sp)
2262 process_sp->Flush();
2263 }
2264 } else {
2265 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2266 sb_error.SetErrorStringWithFormat("no sections in object file '%s'",
2267 path);
2268 }
2269 } else {
2270 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2271 sb_error.SetErrorStringWithFormat("no object file for module '%s'",
2272 path);
2273 }
2274 } else {
2275 sb_error.SetErrorStringWithFormat("invalid module");
2276 }
2277 } else {
2278 sb_error.SetErrorStringWithFormat("invalid target");
2279 }
2280 return sb_error;
2281}
2282
2284 lldb::SymbolType symbol_type) {
2285 LLDB_INSTRUMENT_VA(this, name, symbol_type);
2286
2287 SBSymbolContextList sb_sc_list;
2288 if (name && name[0]) {
2289 if (TargetSP target_sp = GetSP()) {
2290 target_sp->GetImages().FindSymbolsWithNameAndType(
2291 ConstString(name), symbol_type, *sb_sc_list);
2292 }
2293 }
2294 return sb_sc_list;
2295}
2296
2298 LLDB_INSTRUMENT_VA(this, expr);
2299
2300 if (TargetSP target_sp = GetSP()) {
2301 SBExpressionOptions options;
2302 lldb::DynamicValueType fetch_dynamic_value =
2303 target_sp->GetPreferDynamicValue();
2304 options.SetFetchDynamicValue(fetch_dynamic_value);
2305 options.SetUnwindOnError(true);
2306 return EvaluateExpression(expr, options);
2307 }
2308 return SBValue();
2309}
2310
2312 const SBExpressionOptions &options) {
2313 LLDB_INSTRUMENT_VA(this, expr, options);
2314
2315 Log *expr_log = GetLog(LLDBLog::Expressions);
2316 SBValue expr_result;
2317 ValueObjectSP expr_value_sp;
2318 if (TargetSP target_sp = GetSP()) {
2319 StackFrame *frame = nullptr;
2320 if (expr == nullptr || expr[0] == '\0')
2321 return expr_result;
2322
2323 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2324 ExecutionContext exe_ctx(m_opaque_sp.get());
2325
2326 frame = exe_ctx.GetFramePtr();
2327 Target *target = exe_ctx.GetTargetPtr();
2328 Process *process = exe_ctx.GetProcessPtr();
2329
2330 if (target) {
2331 // If we have a process, make sure to lock the runlock:
2332 if (process) {
2333 Process::StopLocker stop_locker;
2334 if (stop_locker.TryLock(&process->GetRunLock())) {
2335 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2336 } else {
2337 Status error;
2338 error = Status::FromErrorString("can't evaluate expressions when the "
2339 "process is running.");
2340 expr_value_sp =
2341 ValueObjectConstResult::Create(nullptr, std::move(error));
2342 }
2343 } else {
2344 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2345 }
2346
2347 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2348 }
2349 }
2350 LLDB_LOGF(expr_log,
2351 "** [SBTarget::EvaluateExpression] Expression result is "
2352 "%s, summary %s **",
2353 expr_result.GetValue(), expr_result.GetSummary());
2354 return expr_result;
2355}
2356
2358 LLDB_INSTRUMENT_VA(this);
2359
2360 if (TargetSP target_sp = GetSP()) {
2361 ABISP abi_sp;
2362 ProcessSP process_sp(target_sp->GetProcessSP());
2363 if (process_sp)
2364 abi_sp = process_sp->GetABI();
2365 else
2366 abi_sp = ABI::FindPlugin(ProcessSP(), target_sp->GetArchitecture());
2367 if (abi_sp)
2368 return abi_sp->GetRedZoneSize();
2369 }
2370 return 0;
2371}
2372
2373bool SBTarget::IsLoaded(const SBModule &module) const {
2374 LLDB_INSTRUMENT_VA(this, module);
2375
2376 if (TargetSP target_sp = GetSP()) {
2377 ModuleSP module_sp(module.GetSP());
2378 if (module_sp)
2379 return module_sp->IsLoadedInTarget(target_sp.get());
2380 }
2381 return false;
2382}
2383
2385 LLDB_INSTRUMENT_VA(this);
2386
2387 lldb::SBLaunchInfo launch_info(nullptr);
2388 if (TargetSP target_sp = GetSP())
2389 launch_info.set_ref(m_opaque_sp->GetProcessLaunchInfo());
2390 return launch_info;
2391}
2392
2394 LLDB_INSTRUMENT_VA(this, launch_info);
2395
2396 if (TargetSP target_sp = GetSP())
2397 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
2398}
2399
2401 LLDB_INSTRUMENT_VA(this);
2402
2403 if (TargetSP target_sp = GetSP())
2404 return SBEnvironment(target_sp->GetEnvironment());
2405
2406 return SBEnvironment();
2407}
2408
2410 LLDB_INSTRUMENT_VA(this);
2411
2412 if (TargetSP target_sp = GetSP())
2413 return SBTrace(target_sp->GetTrace());
2414
2415 return SBTrace();
2416}
2417
2420
2421 error.Clear();
2422 if (TargetSP target_sp = GetSP()) {
2423 if (llvm::Expected<lldb::TraceSP> trace_sp = target_sp->CreateTrace()) {
2424 return SBTrace(*trace_sp);
2425 } else {
2426 error.SetErrorString(llvm::toString(trace_sp.takeError()).c_str());
2427 }
2428 } else {
2429 error.SetErrorString("missing target");
2430 }
2431 return SBTrace();
2432}
2433
2435 LLDB_INSTRUMENT_VA(this);
2436
2437 if (TargetSP target_sp = GetSP())
2438 return lldb::SBMutex(target_sp);
2439 return lldb::SBMutex();
2440}
2441
2442uint32_t
2444 lldb::SBStructuredData args_dict,
2446 LLDB_INSTRUMENT_VA(this, class_name, args_dict, error);
2447
2448 TargetSP target_sp = GetSP();
2449 if (!target_sp) {
2450 error.SetErrorString("invalid target");
2451 return 0;
2452 }
2453
2454 if (!class_name || !class_name[0]) {
2455 error.SetErrorString("invalid class name");
2456 return 0;
2457 }
2458
2459 // Extract the dictionary from SBStructuredData.
2461 if (args_dict.IsValid() && args_dict.m_impl_up) {
2462 StructuredData::ObjectSP obj_sp = args_dict.m_impl_up->GetObjectSP();
2463 if (obj_sp && obj_sp->GetType() != lldb::eStructuredDataTypeDictionary) {
2464 error.SetErrorString("SBStructuredData argument isn't a dictionary");
2465 return 0;
2466 }
2467 dict_sp = std::make_shared<StructuredData::Dictionary>(obj_sp);
2468 }
2469
2470 // Create the ScriptedMetadata.
2471 ScriptedMetadataSP metadata_sp =
2472 std::make_shared<ScriptedMetadata>(class_name, dict_sp);
2473
2474 // Create the interface for calling static methods.
2476 target_sp->GetDebugger()
2477 .GetScriptInterpreter()
2478 ->CreateScriptedFrameProviderInterface();
2479
2480 // Create a descriptor (applies to all threads by default).
2481 ScriptedFrameProviderDescriptor descriptor(metadata_sp);
2482 descriptor.interface_sp = interface_sp;
2483
2484 llvm::Expected<uint32_t> descriptor_id_or_err =
2485 target_sp->AddScriptedFrameProviderDescriptor(descriptor);
2486 if (!descriptor_id_or_err) {
2487 error.SetErrorString(
2488 llvm::toString(descriptor_id_or_err.takeError()).c_str());
2489 return 0;
2490 }
2491
2492 // Register the descriptor with the target.
2493 return *descriptor_id_or_err;
2494}
2495
2497 LLDB_INSTRUMENT_VA(this, provider_id);
2498
2499 SBError error;
2500 TargetSP target_sp = GetSP();
2501 if (!target_sp) {
2502 error.SetErrorString("invalid target");
2503 return error;
2504 }
2505
2506 if (!provider_id) {
2507 error.SetErrorString("invalid provider id");
2508 return error;
2509 }
2510
2511 if (!target_sp->RemoveScriptedFrameProviderDescriptor(provider_id)) {
2512 error.SetErrorStringWithFormat("no frame provider named '%u' found",
2513 provider_id);
2514 return error;
2515 }
2516
2517 return {};
2518}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
#define LLDB_LOGF(log,...)
Definition Log.h:378
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:394
static Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target)
Definition SBTarget.cpp:81
lldb_private::Address * get()
addr_t GetLoadAddress(const lldb::SBTarget &target) const
lldb_private::Address & ref()
bool IsValid() const
Definition SBAddress.cpp:72
lldb_private::ProcessAttachInfo & ref()
void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_id_list)
void AppendByID(lldb::break_id_t id)
bool IsValid()
Definition SBData.cpp:59
void reset(const lldb::DebuggerSP &debugger_sp)
void SetErrorString(const char *err_str)
Definition SBError.cpp:150
bool Fail() const
Definition SBError.cpp:70
lldb_private::Status & ref()
Definition SBError.cpp:191
lldb_private::Event * get() const
Definition SBEvent.cpp:134
void SetFetchDynamicValue(lldb::DynamicValueType dynamic=lldb::eDynamicCanRunTarget)
lldb_private::EvaluateExpressionOptions & ref() const
void SetUnwindOnError(bool unwind=true)
lldb::DynamicValueType GetFetchDynamicValue() const
const lldb_private::FileSpecList * get() const
void Append(const SBFileSpec &sb_file)
uint32_t GetSize() const
void SetFileSpec(const lldb_private::FileSpec &fspec)
bool IsValid() const
const lldb_private::FileSpec & ref() const
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
void SetWorkingDirectory(const char *working_dir)
void SetExecutableFile(SBFileSpec exe_file, bool add_as_first_arg)
Set the executable file that will be used to launch the process and optionally set it as the first ar...
void set_ref(const lldb_private::ProcessLaunchInfo &info)
void SetEnvironmentEntries(const char **envp, bool append)
Update this object with the given environment variables.
const lldb_private::ProcessLaunchInfo & ref() const
void SetArguments(const char **argv, bool append)
lldb::ListenerSP GetSP()
lldb::ListenerSP m_opaque_sp
Definition SBListener.h:102
bool IsValid() const
bool IsValid() const
std::unique_ptr< lldb_private::ModuleSpec > m_opaque_up
void SetSP(const ModuleSP &module_sp)
Definition SBModule.cpp:218
ModuleSP GetSP() const
Definition SBModule.cpp:216
bool IsValid() const
Definition SBModule.cpp:82
lldb::PlatformSP m_opaque_sp
Definition SBPlatform.h:208
void SetSP(const lldb::ProcessSP &process_sp)
lldb::SectionSP GetSP() const
bool IsValid() const
Definition SBSection.cpp:45
This class handles the verbosity when dumping statistics.
const lldb_private::StatisticsOptions & ref() const
lldb_private::Stream & ref()
Definition SBStream.cpp:178
uint32_t GetSize() const
void AppendString(const char *str)
const char * GetStringAtIndex(size_t idx)
StructuredDataImplUP m_impl_up
lldb_private::SymbolContext & ref()
SBSourceManager GetSourceManager()
const char * GetTargetSessionName() const
Get the target session name for this target.
bool AddModule(lldb::SBModule &module)
bool DisableAllBreakpoints()
uint32_t GetNumWatchpoints() const
bool GetDescription(lldb::SBStream &description, lldb::DescriptionLevel description_level)
lldb::SBError ClearSectionLoadAddress(lldb::SBSection section)
Clear the base load address for a module section.
bool DeleteWatchpoint(lldb::watch_id_t watch_id)
lldb::ByteOrder GetByteOrder()
uint32_t GetNumBreakpoints() const
lldb::SBInstructionList GetInstructionsWithFlavor(lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
void SetCollectingStats(bool v)
Sets whether we should collect statistics on lldb or not.
Definition SBTarget.cpp:236
bool BreakpointDelete(break_id_t break_id)
void SetSP(const lldb::TargetSP &target_sp)
Definition SBTarget.cpp:594
bool IsLoaded(const lldb::SBModule &module) const
const char * GetTriple()
static lldb::SBModule GetModuleAtIndexFromEvent(const uint32_t idx, const lldb::SBEvent &event)
Definition SBTarget.cpp:149
bool GetCollectingStats()
Returns whether statistics collection are enabled.
Definition SBTarget.cpp:243
lldb::SBBreakpoint BreakpointCreateByAddress(addr_t address)
Definition SBTarget.cpp:951
lldb::SBValue CreateValueFromExpression(const char *name, const char *expr)
lldb::SBSymbolContextList FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype)
Find global functions by their name with pattern matching.
lldb::SBBreakpoint BreakpointCreateByRegex(const char *symbol_name_regex, const char *module_name=nullptr)
Definition SBTarget.cpp:905
lldb::SBTrace GetTrace()
Get a SBTrace object the can manage the processor trace information of this target.
const lldb::SBTarget & operator=(const lldb::SBTarget &rhs)
Definition SBTarget.cpp:112
const char * GetLabel() const
friend class SBProcess
Definition SBTarget.h:1043
static bool EventIsTargetEvent(const lldb::SBEvent &event)
Definition SBTarget.cpp:123
lldb::SBAddress ResolvePastLoadAddress(uint32_t stop_id, lldb::addr_t vm_addr)
Resolve a current load address into a section offset address using the process stop ID to identify a ...
Definition SBTarget.cpp:630
bool DisableAllWatchpoints()
lldb::addr_t GetStackRedZoneSize()
lldb::SBBreakpoint GetBreakpointAtIndex(uint32_t idx) const
SBError Install()
Install any binaries that need to be installed.
Definition SBTarget.cpp:305
lldb::SBSymbolContextList FindCompileUnits(const lldb::SBFileSpec &sb_file_spec)
Find compile units related to *this target and passed source file.
lldb::SBAddress ResolveLoadAddress(lldb::addr_t vm_addr)
Resolve a current load address into a section offset address.
Definition SBTarget.cpp:598
lldb::SBWatchpoint WatchpointCreateByAddress(lldb::addr_t addr, size_t size, lldb::SBWatchpointOptions options, SBError &error)
lldb::SBMutex GetAPIMutex() const
lldb::SBStructuredData GetStatistics()
Returns a dump of the collected statistics.
Definition SBTarget.cpp:207
lldb::SBModule GetModuleAtIndex(uint32_t idx)
SBError SetLabel(const char *label)
lldb::SBValueList FindGlobalVariables(const char *name, uint32_t max_matches)
Find global and static variables by name.
lldb::SBType GetBasicType(lldb::BasicType type)
lldb::SBFileSpec GetExecutable()
Definition SBTarget.cpp:567
const char * GetABIName()
friend class SBDebugger
Definition SBTarget.h:1035
lldb::SBError SetSectionLoadAddress(lldb::SBSection section, lldb::addr_t section_base_addr)
Set the base load address for a module section.
friend class SBModule
Definition SBTarget.h:1040
lldb::SBProcess ConnectRemote(SBListener &listener, const char *url, const char *plugin_name, SBError &error)
Connect to a remote debug server with url.
Definition SBTarget.cpp:537
friend class SBBreakpoint
Definition SBTarget.h:1032
lldb::SBBreakpoint BreakpointCreateByName(const char *symbol_name, const char *module_name=nullptr)
Definition SBTarget.cpp:771
void DeleteBreakpointName(const char *name)
lldb::SBWatchpoint WatchAddress(lldb::addr_t addr, size_t size, bool read, bool modify, SBError &error)
SBProcess Attach(SBAttachInfo &attach_info, SBError &error)
Definition SBTarget.cpp:446
bool EnableAllWatchpoints()
lldb::SBBreakpoint BreakpointCreateBySBAddress(SBAddress &address)
Definition SBTarget.cpp:964
friend class SBValue
Definition SBTarget.h:1049
friend class SBAddress
Definition SBTarget.h:1029
bool IsValid() const
Definition SBTarget.cpp:164
LLDB_DEPRECATED_FIXME("Use SetModuleLoadAddress(lldb::SBModule, uint64_t)", "SetModuleLoadAddress(lldb::SBModule, uint64_t)") lldb lldb::SBError SetModuleLoadAddress(lldb::SBModule module, uint64_t sections_offset)
Slide all file addresses for all module sections so that module appears to loaded at these slide addr...
lldb::SBProcess GetProcess()
Definition SBTarget.cpp:174
uint32_t RegisterScriptedFrameProvider(const char *class_name, lldb::SBStructuredData args_dict, lldb::SBError &error)
Register a scripted frame provider for this target.
SBSymbolContext ResolveSymbolContextForAddress(const SBAddress &addr, uint32_t resolve_scope)
Definition SBTarget.cpp:649
lldb::SBProcess AttachToProcessWithID(SBListener &listener, lldb::pid_t pid, lldb::SBError &error)
Attach to process with pid.
Definition SBTarget.cpp:478
lldb::SBPlatform GetPlatform()
Return the platform object associated with the target.
Definition SBTarget.cpp:187
lldb::SBBreakpoint BreakpointCreateByLocation(const char *file, uint32_t line)
Definition SBTarget.cpp:682
lldb::SBBreakpoint BreakpointCreateForException(lldb::LanguageType language, bool catch_bp, bool throw_bp)
uint32_t GetNumModules() const
lldb::TargetSP GetSP() const
Definition SBTarget.cpp:592
uint32_t GetDataByteSize()
uint32_t GetMaximumNumberOfChildrenToDisplay() const
Gets the target.max-children-count value It should be used to limit the number of children of large d...
bool DeleteAllWatchpoints()
lldb::SBInstructionList GetInstructions(lldb::SBAddress base_addr, const void *buf, size_t size)
friend class SBModuleSpec
Definition SBTarget.h:1041
lldb::SBProcess Launch(SBListener &listener, char const **argv, char const **envp, const char *stdin_path, const char *stdout_path, const char *stderr_path, const char *working_directory, uint32_t launch_flags, bool stop_at_entry, lldb::SBError &error)
Launch a new process.
Definition SBTarget.cpp:316
bool RemoveModule(lldb::SBModule module)
lldb::SBSymbolContextList FindFunctions(const char *name, uint32_t name_type_mask=lldb::eFunctionNameTypeAny)
Find functions by name.
lldb::SBValue FindFirstGlobalVariable(const char *name)
Find the first global (or static) variable by name.
lldb::SBValue EvaluateExpression(const char *expr)
lldb::SBBreakpoint BreakpointCreateFromScript(const char *class_name, SBStructuredData &extra_args, const SBFileSpecList &module_list, const SBFileSpecList &file_list, bool request_hardware=false)
Create a breakpoint using a scripted resolver.
static const char * GetBroadcasterClassName()
Definition SBTarget.cpp:158
SBEnvironment GetEnvironment()
Return the environment variables that would be used to launch a new process.
lldb::SBTypeList FindTypes(const char *type)
static lldb::SBTarget GetCreatedTargetFromEvent(const lldb::SBEvent &event)
For eBroadcastBitNewTargetCreated events, returns the newly created target.
Definition SBTarget.cpp:135
lldb::SBValue CreateValueFromAddress(const char *name, lldb::SBAddress addr, lldb::SBType type)
static lldb::SBTarget GetTargetFromEvent(const lldb::SBEvent &event)
Definition SBTarget.cpp:129
lldb::SBError BreakpointsCreateFromFile(SBFileSpec &source_file, SBBreakpointList &new_bps)
Read breakpoints from source_file and return the newly created breakpoints in bkpt_list.
uint32_t GetAddressByteSize()
bool operator==(const lldb::SBTarget &rhs) const
Definition SBTarget.cpp:580
bool operator!=(const lldb::SBTarget &rhs) const
Definition SBTarget.cpp:586
const char * GetArchName() const
lldb::TargetSP m_opaque_sp
Definition SBTarget.h:1064
lldb::SBWatchpoint GetWatchpointAtIndex(uint32_t idx) const
lldb::SBLaunchInfo GetLaunchInfo() const
lldb::SBSymbolContextList FindSymbols(const char *name, lldb::SymbolType type=eSymbolTypeAny)
lldb::user_id_t GetGloballyUniqueID() const
Get the globally unique ID for this target.
void AppendImageSearchPath(const char *from, const char *to, lldb::SBError &error)
lldb::SBError RemoveScriptedFrameProvider(uint32_t provider_id)
Remove a scripted frame provider from this target by name.
friend class SBBreakpointList
Definition SBTarget.h:1033
lldb::SBTrace CreateTrace(SBError &error)
Create a Trace object for the current target using the using the default supported tracing technology...
lldb::SBBreakpoint BreakpointCreateBySourceRegex(const char *source_regex, const SBFileSpec &source_file, const char *module_name=nullptr)
Definition SBTarget.cpp:982
bool DeleteAllBreakpoints()
lldb::SBValue CreateValueFromData(const char *name, lldb::SBData data, lldb::SBType type)
void ResetStatistics()
Reset the statistics collected for this target.
Definition SBTarget.cpp:229
lldb::SBBroadcaster GetBroadcaster() const
uint32_t GetMinimumOpcodeByteSize() const
Architecture opcode byte size width accessor.
bool FindBreakpointsByName(const char *name, SBBreakpointList &bkpt_list)
size_t ReadMemory(const SBAddress addr, void *buf, size_t size, lldb::SBError &error)
Read target memory.
Definition SBTarget.cpp:666
lldb::SBBreakpoint BreakpointCreateByNames(const char *symbol_name[], uint32_t num_names, uint32_t name_type_mask, const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list)
Definition SBTarget.cpp:860
uint32_t GetMaximumOpcodeByteSize() const
Architecture opcode byte size width accessor.
SBProcess LaunchSimple(const char **argv, const char **envp, const char *working_directory)
Launch a new process with sensible defaults.
Definition SBTarget.cpp:281
lldb::SBModule FindModule(const lldb::SBFileSpec &file_spec)
friend class SBSourceManager
Definition SBTarget.h:1045
lldb::SBBreakpoint FindBreakpointByID(break_id_t break_id)
friend class SBType
Definition SBTarget.h:1047
lldb::SBInstructionList ReadInstructions(lldb::SBAddress base_addr, uint32_t count)
void GetBreakpointNames(SBStringList &names)
lldb::SBDebugger GetDebugger() const
Definition SBTarget.cpp:198
friend class SBPlatform
Definition SBTarget.h:1042
lldb::SBError BreakpointsWriteToFile(SBFileSpec &dest_file)
Write breakpoints to dest_file.
lldb::SBWatchpoint FindWatchpointByID(lldb::watch_id_t watch_id)
lldb::SBAddress ResolveFileAddress(lldb::addr_t file_addr)
Resolve a current file address into a section offset address.
Definition SBTarget.cpp:615
void SetLaunchInfo(const lldb::SBLaunchInfo &launch_info)
lldb::SBError ClearModuleLoadAddress(lldb::SBModule module)
Clear the section base load addresses for all sections in a module.
lldb::SBType FindFirstType(const char *type)
uint32_t GetCodeByteSize()
lldb::SBProcess AttachToProcessWithName(SBListener &listener, const char *name, bool wait_for, lldb::SBError &error)
Attach to process with name.
Definition SBTarget.cpp:505
SBProcess LoadCore(const char *core_file)
Definition SBTarget.cpp:251
static uint32_t GetNumModulesFromEvent(const lldb::SBEvent &event)
Definition SBTarget.cpp:141
bool EnableAllBreakpoints()
uint32_t GetSize()
Definition SBType.cpp:783
void Append(lldb::SBType type)
Definition SBType.cpp:768
lldb::TypeImplSP GetSP()
Definition SBType.cpp:82
bool IsValid() const
Definition SBType.cpp:113
bool IsValid() const
void Append(const lldb::SBValue &val_obj)
lldb::SBValue GetValueAtIndex(uint32_t idx) const
uint32_t GetSize() const
void SetSP(const lldb::ValueObjectSP &sp)
Definition SBValue.cpp:968
const char * GetValue()
Definition SBValue.cpp:187
const char * GetSummary()
Definition SBValue.cpp:254
void SetWatchpointTypeWrite(lldb::WatchpointWriteType write_type)
Stop when the watched memory region is written to/modified.
lldb::WatchpointWriteType GetWatchpointTypeWrite() const
void SetWatchpointTypeRead(bool read)
Stop when the watched memory region is read.
void SetSP(const lldb::WatchpointSP &sp)
static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch)
Definition ABI.cpp:27
A section + offset based address range class.
A section + offset based address class.
Definition Address.h:62
void SetRawAddress(lldb::addr_t addr)
Definition Address.h:447
An architecture specification class.
Definition ArchSpec.h:32
bool IsValid() const
Tests if this ArchSpec is valid.
Definition ArchSpec.h:367
void AppendArguments(const Args &rhs)
Definition Args.cpp:307
BreakpointID GetBreakpointIDAtIndex(size_t index) const
lldb::break_id_t GetBreakpointID() const
Generic representation of a type in a programming language.
A uniqued constant string class.
Definition ConstString.h:40
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
static void SetCollectingStats(bool enable)
Definition Statistics.h:347
static bool GetCollectingStats()
Definition Statistics.h:348
static void ResetStatistics(Debugger &debugger, Target *target)
Reset metrics associated with one or all targets in a debugger.
static llvm::json::Value ReportStatistics(Debugger &debugger, Target *target, const lldb_private::StatisticsOptions &options)
Get metrics associated with one or all targets in a debugger in JSON format.
static lldb::DisassemblerSP DisassembleRange(const ArchSpec &arch, const char *plugin_name, const char *flavor, const char *cpu, const char *features, Target &target, llvm::ArrayRef< AddressRange > disasm_ranges, bool force_live_memory=false)
static lldb::DisassemblerSP DisassembleBytes(const ArchSpec &arch, const char *plugin_name, const char *flavor, const char *cpu, const char *features, const Address &start, const void *bytes, size_t length, uint32_t max_num_instructions, bool data_from_file)
A class that measures elapsed time in an exception safe way.
Definition Statistics.h:76
Execution context objects refer to objects in the execution of the program that is being debugged.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
Target * GetTargetPtr() const
Returns a pointer to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
A file collection class.
void Append(const FileSpec &file)
Append a FileSpec object to the list.
A file utility class.
Definition FileSpec.h:57
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition FileSpec.cpp:174
static FileSystem & Instance()
void Resolve(llvm::SmallVectorImpl< char > &path, bool force_make_absolute=false)
Resolve path to make it canonical.
A collection class for Module objects.
Definition ModuleList.h:125
void FindTypes(Module *search_first, const TypeQuery &query, lldb_private::TypeResults &results) const
Find types using a type-matching object that contains all search parameters.
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
void Append(const lldb::ModuleSP &module_sp, bool notify=true)
Append a module to the module list.
size_t GetSize() const
Gets the size of the module list.
FileSpec & GetFileSpec()
Definition ModuleSpec.h:57
ArchSpec & GetArchitecture()
Definition ModuleSpec.h:93
FileSpec & GetSymbolFileSpec()
Definition ModuleSpec.h:81
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
Definition Module.h:460
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:446
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
static ArchSpec GetAugmentedArchSpec(Platform *platform, llvm::StringRef triple)
Augments the triple either with information from platform or the host system (if platform is null).
Definition Platform.cpp:320
static bool DownloadObjectAndSymbolFile(ModuleSpec &module_spec, Status &error, bool force_lookup=true, bool copy_executable=true)
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
bool ProcessIDIsValid() const
Definition ProcessInfo.h:72
lldb::pid_t GetProcessID() const
Definition ProcessInfo.h:68
void SetProcessID(lldb::pid_t pid)
Definition ProcessInfo.h:70
FileSpec & GetExecutableFile()
Definition ProcessInfo.h:43
void SetListener(const lldb::ListenerSP &listener_sp)
lldb::ListenerSP GetListener() const
Environment & GetEnvironment()
Definition ProcessInfo.h:88
void SetUserID(uint32_t uid)
Definition ProcessInfo.h:58
ArchSpec & GetArchitecture()
Definition ProcessInfo.h:62
A plug-in interface definition class for debugging a process.
Definition Process.h:354
ProcessRunLock::ProcessRunLocker StopLocker
Definition Process.h:393
ProcessRunLock & GetRunLock()
Definition Process.cpp:6063
size_t GetSize() const
Definition Section.h:77
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition Section.cpp:549
This base class provides an interface to stack frames.
Definition StackFrame.h:44
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:136
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
static ObjectSP ParseJSON(llvm::StringRef json_text)
Defines a symbol context baton that can be handed other debug core functions.
lldb::TargetSP target_sp
The Target for a given query.
static lldb::TargetSP GetCreatedTargetFromEvent(const Event *event_ptr)
Definition Target.cpp:5375
static ModuleList GetModuleListFromEvent(const Event *event_ptr)
Definition Target.cpp:5384
static const TargetEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition Target.cpp:5356
static lldb::TargetSP GetTargetFromEvent(const Event *event_ptr)
Definition Target.cpp:5366
const lldb::ProcessSP & GetProcessSP() const
Definition Target.cpp:314
std::recursive_mutex & GetAPIMutex()
Definition Target.cpp:5392
static llvm::StringRef GetStaticBroadcasterClass()
Definition Target.cpp:171
Status Attach(ProcessAttachInfo &attach_info, Stream *stream)
Definition Target.cpp:3627
lldb::ExpressionResults EvaluateExpression(llvm::StringRef expression, ExecutionContextScope *exe_scope, lldb::ValueObjectSP &result_valobj_sp, const EvaluateExpressionOptions &options=EvaluateExpressionOptions(), std::string *fixed_expression=nullptr, ValueObject *ctx_obj=nullptr)
Definition Target.cpp:2836
TypeIterable Types() const
Definition TypeMap.h:50
A class that contains all state required for type lookups.
Definition Type.h:104
This class tracks the state and results of a TypeQuery.
Definition Type.h:344
TypeMap & GetTypeMap()
Definition Type.h:386
lldb::TypeSP GetFirstType() const
Definition Type.h:385
bool SetFromStringRef(llvm::StringRef str)
Definition UUID.cpp:101
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
static lldb::ValueObjectSP CreateValueObjectFromExpression(llvm::StringRef name, llvm::StringRef expression, const ExecutionContext &exe_ctx)
static lldb::ValueObjectSP CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, CompilerType type, bool do_deref=true)
Given an address either create a value object containing the value at that address,...
static lldb::ValueObjectSP CreateValueObjectFromData(llvm::StringRef name, const DataExtractor &data, const ExecutionContext &exe_ctx, CompilerType type)
#define LLDB_INVALID_GLOBALLY_UNIQUE_TARGET_ID
#define LLDB_WATCH_TYPE_WRITE
#define LLDB_INVALID_BREAK_ID
#define LLDB_INVALID_WATCH_ID
#define LLDB_WATCH_TYPE_MODIFY
#define LLDB_WATCH_TYPE_READ
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:327
MatchType
String matching algorithm used by SBTarget.
@ eMatchTypeRegexInsensitive
class LLDB_API SBBroadcaster
Definition SBDefines.h:55
std::shared_ptr< lldb_private::ABI > ABISP
class LLDB_API SBFileSpec
Definition SBDefines.h:75
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
@ eWatchpointWriteTypeOnModify
Stop on a write to the memory region that changes its value.
@ eWatchpointWriteTypeAlways
Stop on any write access to the memory region, even if the value doesn't change.
class LLDB_API SBMutex
Definition SBDefines.h:93
std::shared_ptr< lldb_private::ScriptedMetadata > ScriptedMetadataSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::Platform > PlatformSP
StateType
Process and Thread States.
@ eStateConnected
Process is connected to remote debug services, but not launched or attached to anything yet.
@ eStateAttaching
Process is currently trying to attach.
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::Type > TypeSP
int32_t break_id_t
Definition lldb-types.h:87
std::shared_ptr< lldb_private::Process > ProcessSP
SymbolType
Symbol types.
uint64_t pid_t
Definition lldb-types.h:83
ByteOrder
Byte ordering definitions.
class LLDB_API SBEnvironment
Definition SBDefines.h:68
std::shared_ptr< lldb_private::Watchpoint > WatchpointSP
int32_t watch_id_t
Definition lldb-types.h:88
std::shared_ptr< lldb_private::Variable > VariableSP
std::shared_ptr< lldb_private::ScriptedFrameProviderInterface > ScriptedFrameProviderInterfaceSP
class LLDB_API SBTrace
Definition SBDefines.h:119
uint64_t user_id_t
Definition lldb-types.h:82
class LLDB_API SBStringList
Definition SBDefines.h:110
std::shared_ptr< lldb_private::Section > SectionSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
@ eStructuredDataTypeDictionary
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP
Options used by Module::FindFunctions.
Definition Module.h:66
bool include_inlines
Include inlined functions.
Definition Module.h:70
bool include_symbols
Include the symbol table.
Definition Module.h:68
This struct contains the metadata needed to instantiate a frame provider and optional filters to cont...
lldb::ScriptedFrameProviderInterfaceSP interface_sp
Interface for calling static methods on the provider class.
#define PATH_MAX