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"
26#include "lldb/API/SBTrace.h"
31#include "lldb/Core/Address.h"
33#include "lldb/Core/Debugger.h"
35#include "lldb/Core/Module.h"
39#include "lldb/Core/Section.h"
41#include "lldb/Host/Host.h"
48#include "lldb/Target/ABI.h"
51#include "lldb/Target/Process.h"
53#include "lldb/Target/Target.h"
56#include "lldb/Utility/Args.h"
65#include "lldb/lldb-public.h"
66
69#include "llvm/Support/PrettyStackTrace.h"
70#include "llvm/Support/Regex.h"
71
72using namespace lldb;
73using namespace lldb_private;
74
75#define DEFAULT_DISASM_BYTE_SIZE 32
76
77static Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target) {
78 std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
79
80 auto process_sp = target.GetProcessSP();
81 if (process_sp) {
82 const auto state = process_sp->GetState();
83 if (process_sp->IsAlive() && state == eStateConnected) {
84 // If we are already connected, then we have already specified the
85 // listener, so if a valid listener is supplied, we need to error out to
86 // let the client know.
87 if (attach_info.GetListener())
89 "process is connected and already has a listener, pass "
90 "empty listener");
91 }
92 }
93
94 return target.Attach(attach_info, nullptr);
95}
96
97// SBTarget constructor
99
101 LLDB_INSTRUMENT_VA(this, rhs);
102}
103
104SBTarget::SBTarget(const TargetSP &target_sp) : m_opaque_sp(target_sp) {
105 LLDB_INSTRUMENT_VA(this, target_sp);
106}
107
109 LLDB_INSTRUMENT_VA(this, rhs);
110
111 if (this != &rhs)
113 return *this;
114}
115
116// Destructor
117SBTarget::~SBTarget() = default;
118
120 LLDB_INSTRUMENT_VA(event);
121
122 return Target::TargetEventData::GetEventDataFromEvent(event.get()) != nullptr;
123}
124
130
132 LLDB_INSTRUMENT_VA(event);
133
134 const ModuleList module_list =
136 return module_list.GetSize();
137}
138
140 const SBEvent &event) {
141 LLDB_INSTRUMENT_VA(idx, event);
142
143 const ModuleList module_list =
145 return SBModule(module_list.GetModuleAtIndex(idx));
146}
147
153
154bool SBTarget::IsValid() const {
155 LLDB_INSTRUMENT_VA(this);
156 return this->operator bool();
157}
158SBTarget::operator bool() const {
159 LLDB_INSTRUMENT_VA(this);
160
161 return m_opaque_sp.get() != nullptr && m_opaque_sp->IsValid();
162}
163
165 LLDB_INSTRUMENT_VA(this);
166
167 SBProcess sb_process;
168 ProcessSP process_sp;
169 if (TargetSP target_sp = GetSP()) {
170 process_sp = target_sp->GetProcessSP();
171 sb_process.SetSP(process_sp);
172 }
173
174 return sb_process;
175}
176
178 LLDB_INSTRUMENT_VA(this);
179
180 if (TargetSP target_sp = GetSP()) {
181 SBPlatform platform;
182 platform.m_opaque_sp = target_sp->GetPlatform();
183 return platform;
184 }
185 return SBPlatform();
186}
187
189 LLDB_INSTRUMENT_VA(this);
190
191 SBDebugger debugger;
192 if (TargetSP target_sp = GetSP())
193 debugger.reset(target_sp->GetDebugger().shared_from_this());
194 return debugger;
195}
196
202
204 LLDB_INSTRUMENT_VA(this);
205
206 SBStructuredData data;
207 if (TargetSP target_sp = GetSP()) {
208 std::string json_str =
209 llvm::formatv("{0:2}", DebuggerStats::ReportStatistics(
210 target_sp->GetDebugger(), target_sp.get(),
211 options.ref()))
212 .str();
213 data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
214 return data;
215 }
216 return data;
217}
218
220 LLDB_INSTRUMENT_VA(this);
221
222 if (TargetSP target_sp = GetSP())
223 DebuggerStats::ResetStatistics(target_sp->GetDebugger(), target_sp.get());
224}
225
227 LLDB_INSTRUMENT_VA(this, v);
228
229 if (TargetSP target_sp = GetSP())
231}
232
234 LLDB_INSTRUMENT_VA(this);
235
236 if (TargetSP target_sp = GetSP())
238 return false;
239}
240
241SBProcess SBTarget::LoadCore(const char *core_file) {
242 LLDB_INSTRUMENT_VA(this, core_file);
243
244 lldb::SBError error; // Ignored
245 return LoadCore(core_file, error);
246}
247
249 LLDB_INSTRUMENT_VA(this, core_file, error);
250
251 SBProcess sb_process;
252 if (TargetSP target_sp = GetSP()) {
253 FileSpec filespec(core_file);
254 FileSystem::Instance().Resolve(filespec);
255 ProcessSP process_sp(target_sp->CreateProcess(
256 target_sp->GetDebugger().GetListener(), "", &filespec, false));
257 if (process_sp) {
258 error.SetError(process_sp->LoadCore());
259 if (error.Success())
260 sb_process.SetSP(process_sp);
261 } else {
262 error.SetErrorString("Failed to create the process");
263 }
264 } else {
265 error.SetErrorString("SBTarget is invalid");
266 }
267 return sb_process;
268}
269
270SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp,
271 const char *working_directory) {
272 LLDB_INSTRUMENT_VA(this, argv, envp, working_directory);
273
274 TargetSP target_sp = GetSP();
275 if (!target_sp)
276 return SBProcess();
277
278 SBLaunchInfo launch_info = GetLaunchInfo();
279
280 if (Module *exe_module = target_sp->GetExecutableModulePointer())
281 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(),
282 /*add_as_first_arg*/ true);
283 if (argv)
284 launch_info.SetArguments(argv, /*append*/ true);
285 if (envp)
286 launch_info.SetEnvironmentEntries(envp, /*append*/ false);
287 if (working_directory)
288 launch_info.SetWorkingDirectory(working_directory);
289
291 return Launch(launch_info, error);
292}
293
295 LLDB_INSTRUMENT_VA(this);
296
297 SBError sb_error;
298 if (TargetSP target_sp = GetSP()) {
299 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
300 sb_error.ref() = target_sp->Install(nullptr);
301 }
302 return sb_error;
303}
304
305SBProcess SBTarget::Launch(SBListener &listener, char const **argv,
306 char const **envp, const char *stdin_path,
307 const char *stdout_path, const char *stderr_path,
308 const char *working_directory,
309 uint32_t launch_flags, // See LaunchFlags
310 bool stop_at_entry, lldb::SBError &error) {
311 LLDB_INSTRUMENT_VA(this, listener, argv, envp, stdin_path, stdout_path,
312 stderr_path, working_directory, launch_flags,
313 stop_at_entry, error);
314
315 SBProcess sb_process;
316 ProcessSP process_sp;
317 if (TargetSP target_sp = GetSP()) {
318 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
319
320 if (stop_at_entry)
321 launch_flags |= eLaunchFlagStopAtEntry;
322
323 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
324 launch_flags |= eLaunchFlagDisableASLR;
325
326 StateType state = eStateInvalid;
327 process_sp = target_sp->GetProcessSP();
328 if (process_sp) {
329 state = process_sp->GetState();
330
331 if (process_sp->IsAlive() && state != eStateConnected) {
332 if (state == eStateAttaching)
333 error.SetErrorString("process attach is in progress");
334 else
335 error.SetErrorString("a process is already being debugged");
336 return sb_process;
337 }
338 }
339
340 if (state == eStateConnected) {
341 // If we are already connected, then we have already specified the
342 // listener, so if a valid listener is supplied, we need to error out to
343 // let the client know.
344 if (listener.IsValid()) {
345 error.SetErrorString("process is connected and already has a listener, "
346 "pass empty listener");
347 return sb_process;
348 }
349 }
350
351 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
352 launch_flags |= eLaunchFlagDisableSTDIO;
353
354 ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
355 FileSpec(stderr_path),
356 FileSpec(working_directory), launch_flags);
357
358 Module *exe_module = target_sp->GetExecutableModulePointer();
359 if (exe_module)
360 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
361 if (argv) {
362 launch_info.GetArguments().AppendArguments(argv);
363 } else {
364 auto default_launch_info = target_sp->GetProcessLaunchInfo();
365 launch_info.GetArguments().AppendArguments(
366 default_launch_info.GetArguments());
367 }
368 if (envp) {
369 launch_info.GetEnvironment() = Environment(envp);
370 } else {
371 auto default_launch_info = target_sp->GetProcessLaunchInfo();
372 launch_info.GetEnvironment() = default_launch_info.GetEnvironment();
373 }
374
375 if (listener.IsValid())
376 launch_info.SetListener(listener.GetSP());
377
378 error.SetError(target_sp->Launch(launch_info, nullptr));
379
380 sb_process.SetSP(target_sp->GetProcessSP());
381 } else {
382 error.SetErrorString("SBTarget is invalid");
383 }
384
385 return sb_process;
386}
387
389 LLDB_INSTRUMENT_VA(this, sb_launch_info, error);
390
391 SBProcess sb_process;
392 if (TargetSP target_sp = GetSP()) {
393 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
394 StateType state = eStateInvalid;
395 {
396 ProcessSP process_sp = target_sp->GetProcessSP();
397 if (process_sp) {
398 state = process_sp->GetState();
399
400 if (process_sp->IsAlive() && state != eStateConnected) {
401 if (state == eStateAttaching)
402 error.SetErrorString("process attach is in progress");
403 else
404 error.SetErrorString("a process is already being debugged");
405 return sb_process;
406 }
407 }
408 }
409
410 lldb_private::ProcessLaunchInfo launch_info = sb_launch_info.ref();
411
412 if (!launch_info.GetExecutableFile()) {
413 Module *exe_module = target_sp->GetExecutableModulePointer();
414 if (exe_module)
415 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
416 }
417
418 const ArchSpec &arch_spec = target_sp->GetArchitecture();
419 if (arch_spec.IsValid())
420 launch_info.GetArchitecture() = arch_spec;
421
422 error.SetError(target_sp->Launch(launch_info, nullptr));
423 sb_launch_info.set_ref(launch_info);
424 sb_process.SetSP(target_sp->GetProcessSP());
425 } else {
426 error.SetErrorString("SBTarget is invalid");
427 }
428
429 return sb_process;
430}
431
433 LLDB_INSTRUMENT_VA(this, sb_attach_info, error);
434
435 SBProcess sb_process;
436 if (TargetSP target_sp = GetSP()) {
437 ProcessAttachInfo &attach_info = sb_attach_info.ref();
438 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid() &&
439 !attach_info.IsScriptedProcess()) {
440 PlatformSP platform_sp = target_sp->GetPlatform();
441 // See if we can pre-verify if a process exists or not
442 if (platform_sp && platform_sp->IsConnected()) {
443 lldb::pid_t attach_pid = attach_info.GetProcessID();
444 ProcessInstanceInfo instance_info;
445 if (platform_sp->GetProcessInfo(attach_pid, instance_info)) {
446 attach_info.SetUserID(instance_info.GetEffectiveUserID());
447 } else {
449 "no process found with process ID %" PRIu64, attach_pid);
450 return sb_process;
451 }
452 }
453 }
454 error.SetError(AttachToProcess(attach_info, *target_sp));
455 if (error.Success())
456 sb_process.SetSP(target_sp->GetProcessSP());
457 } else {
458 error.SetErrorString("SBTarget is invalid");
459 }
460
461 return sb_process;
462}
463
465 SBListener &listener,
466 lldb::pid_t pid, // The process ID to attach to
467 SBError &error // An error explaining what went wrong if attach fails
468) {
469 LLDB_INSTRUMENT_VA(this, listener, pid, error);
470
471 SBProcess sb_process;
472 if (TargetSP target_sp = GetSP()) {
473 ProcessAttachInfo attach_info;
474 attach_info.SetProcessID(pid);
475 if (listener.IsValid())
476 attach_info.SetListener(listener.GetSP());
477
478 ProcessInstanceInfo instance_info;
479 if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info))
480 attach_info.SetUserID(instance_info.GetEffectiveUserID());
481
482 error.SetError(AttachToProcess(attach_info, *target_sp));
483 if (error.Success())
484 sb_process.SetSP(target_sp->GetProcessSP());
485 } else
486 error.SetErrorString("SBTarget is invalid");
487
488 return sb_process;
489}
490
492 SBListener &listener,
493 const char *name, // basename of process to attach to
494 bool wait_for, // if true wait for a new instance of "name" to be launched
495 SBError &error // An error explaining what went wrong if attach fails
496) {
497 LLDB_INSTRUMENT_VA(this, listener, name, wait_for, error);
498
499 SBProcess sb_process;
500
501 if (!name) {
502 error.SetErrorString("invalid name");
503 return sb_process;
504 }
505
506 if (TargetSP target_sp = GetSP()) {
507 ProcessAttachInfo attach_info;
508 attach_info.GetExecutableFile().SetFile(name, FileSpec::Style::native);
509 attach_info.SetWaitForLaunch(wait_for);
510 if (listener.IsValid())
511 attach_info.SetListener(listener.GetSP());
512
513 error.SetError(AttachToProcess(attach_info, *target_sp));
514 if (error.Success())
515 sb_process.SetSP(target_sp->GetProcessSP());
516 } else {
517 error.SetErrorString("SBTarget is invalid");
518 }
519
520 return sb_process;
521}
522
524 const char *plugin_name,
525 SBError &error) {
526 LLDB_INSTRUMENT_VA(this, listener, url, plugin_name, error);
527
528 SBProcess sb_process;
529 ProcessSP process_sp;
530 if (TargetSP target_sp = GetSP()) {
531 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
532 if (listener.IsValid())
533 process_sp =
534 target_sp->CreateProcess(listener.m_opaque_sp, plugin_name, nullptr,
535 true);
536 else
537 process_sp = target_sp->CreateProcess(
538 target_sp->GetDebugger().GetListener(), plugin_name, nullptr, true);
539
540 if (process_sp) {
541 sb_process.SetSP(process_sp);
542 error.SetError(process_sp->ConnectRemote(url));
543 } else {
544 error.SetErrorString("unable to create lldb_private::Process");
545 }
546 } else {
547 error.SetErrorString("SBTarget is invalid");
548 }
549
550 return sb_process;
551}
552
554 LLDB_INSTRUMENT_VA(this);
555
556 SBFileSpec exe_file_spec;
557 if (TargetSP target_sp = GetSP()) {
558 Module *exe_module = target_sp->GetExecutableModulePointer();
559 if (exe_module)
560 exe_file_spec.SetFileSpec(exe_module->GetFileSpec());
561 }
562
563 return exe_file_spec;
564}
565
566bool SBTarget::operator==(const SBTarget &rhs) const {
567 LLDB_INSTRUMENT_VA(this, rhs);
568
569 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
570}
571
572bool SBTarget::operator!=(const SBTarget &rhs) const {
573 LLDB_INSTRUMENT_VA(this, rhs);
574
575 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
576}
577
579
580void SBTarget::SetSP(const lldb::TargetSP &target_sp) {
581 m_opaque_sp = target_sp;
582}
583
585 LLDB_INSTRUMENT_VA(this, vm_addr);
586
587 lldb::SBAddress sb_addr;
588 Address &addr = sb_addr.ref();
589 if (TargetSP target_sp = GetSP()) {
590 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
591 if (target_sp->ResolveLoadAddress(vm_addr, addr))
592 return sb_addr;
593 }
594
595 // We have a load address that isn't in a section, just return an address
596 // with the offset filled in (the address) and the section set to NULL
597 addr.SetRawAddress(vm_addr);
598 return sb_addr;
599}
600
602 LLDB_INSTRUMENT_VA(this, file_addr);
603
604 lldb::SBAddress sb_addr;
605 Address &addr = sb_addr.ref();
606 if (TargetSP target_sp = GetSP()) {
607 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
608 if (target_sp->ResolveFileAddress(file_addr, addr))
609 return sb_addr;
610 }
611
612 addr.SetRawAddress(file_addr);
613 return sb_addr;
614}
615
617 lldb::addr_t vm_addr) {
618 LLDB_INSTRUMENT_VA(this, stop_id, vm_addr);
619
620 lldb::SBAddress sb_addr;
621 Address &addr = sb_addr.ref();
622 if (TargetSP target_sp = GetSP()) {
623 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
624 if (target_sp->ResolveLoadAddress(vm_addr, addr))
625 return sb_addr;
626 }
627
628 // We have a load address that isn't in a section, just return an address
629 // with the offset filled in (the address) and the section set to NULL
630 addr.SetRawAddress(vm_addr);
631 return sb_addr;
632}
633
636 uint32_t resolve_scope) {
637 LLDB_INSTRUMENT_VA(this, addr, resolve_scope);
638
639 SBSymbolContext sb_sc;
640 SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
641 if (addr.IsValid()) {
642 if (TargetSP target_sp = GetSP()) {
643 lldb_private::SymbolContext &sc = sb_sc.ref();
644 sc.target_sp = target_sp;
645 target_sp->GetImages().ResolveSymbolContextForAddress(addr.ref(), scope,
646 sc);
647 }
648 }
649 return sb_sc;
650}
651
652size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size,
654 LLDB_INSTRUMENT_VA(this, addr, buf, size, error);
655
656 size_t bytes_read = 0;
657 if (TargetSP target_sp = GetSP()) {
658 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
659 bytes_read =
660 target_sp->ReadMemory(addr.ref(), buf, size, error.ref(), true);
661 } else {
662 error.SetErrorString("invalid target");
663 }
664
665 return bytes_read;
666}
667
669 uint32_t line) {
670 LLDB_INSTRUMENT_VA(this, file, line);
671
672 return SBBreakpoint(
673 BreakpointCreateByLocation(SBFileSpec(file, false), line));
674}
675
678 uint32_t line) {
679 LLDB_INSTRUMENT_VA(this, sb_file_spec, line);
680
681 return BreakpointCreateByLocation(sb_file_spec, line, 0);
682}
683
686 uint32_t line, lldb::addr_t offset) {
687 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, offset);
688
689 SBFileSpecList empty_list;
690 return BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list);
691}
692
695 uint32_t line, lldb::addr_t offset,
696 SBFileSpecList &sb_module_list) {
697 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, offset, sb_module_list);
698
699 return BreakpointCreateByLocation(sb_file_spec, line, 0, offset,
700 sb_module_list);
701}
702
704 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
705 lldb::addr_t offset, SBFileSpecList &sb_module_list) {
706 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, column, offset, sb_module_list);
707
708 SBBreakpoint sb_bp;
709 if (TargetSP target_sp = GetSP(); target_sp && line != 0) {
710 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
711
712 const LazyBool check_inlines = eLazyBoolCalculate;
713 const LazyBool skip_prologue = eLazyBoolCalculate;
714 const bool internal = false;
715 const bool hardware = false;
716 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
717 const FileSpecList *module_list = nullptr;
718 if (sb_module_list.GetSize() > 0) {
719 module_list = sb_module_list.get();
720 }
721 sb_bp = target_sp->CreateBreakpoint(
722 module_list, *sb_file_spec, line, column, offset, check_inlines,
723 skip_prologue, internal, hardware, move_to_nearest_code);
724 }
725
726 return sb_bp;
727}
728
730 const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
731 lldb::addr_t offset, SBFileSpecList &sb_module_list,
732 bool move_to_nearest_code) {
733 LLDB_INSTRUMENT_VA(this, sb_file_spec, line, column, offset, sb_module_list,
734 move_to_nearest_code);
735
736 SBBreakpoint sb_bp;
737 if (TargetSP target_sp = GetSP(); target_sp && line != 0) {
738 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
739
740 const LazyBool check_inlines = eLazyBoolCalculate;
741 const LazyBool skip_prologue = eLazyBoolCalculate;
742 const bool internal = false;
743 const bool hardware = false;
744 const FileSpecList *module_list = nullptr;
745 if (sb_module_list.GetSize() > 0) {
746 module_list = sb_module_list.get();
747 }
748 sb_bp = target_sp->CreateBreakpoint(
749 module_list, *sb_file_spec, line, column, offset, check_inlines,
750 skip_prologue, internal, hardware,
751 move_to_nearest_code ? eLazyBoolYes : eLazyBoolNo);
752 }
753
754 return sb_bp;
755}
756
758 const char *module_name) {
759 LLDB_INSTRUMENT_VA(this, symbol_name, module_name);
760
761 SBBreakpoint sb_bp;
762 if (TargetSP target_sp = GetSP()) {
763 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
764
765 const bool internal = false;
766 const bool hardware = false;
767 const LazyBool skip_prologue = eLazyBoolCalculate;
768 const lldb::addr_t offset = 0;
769 const bool offset_is_insn_count = false;
770 if (module_name && module_name[0]) {
771 FileSpecList module_spec_list;
772 module_spec_list.Append(FileSpec(module_name));
773 sb_bp = target_sp->CreateBreakpoint(
774 &module_spec_list, nullptr, symbol_name, eFunctionNameTypeAuto,
775 eLanguageTypeUnknown, offset, offset_is_insn_count, skip_prologue,
776 internal, hardware);
777 } else {
778 sb_bp = target_sp->CreateBreakpoint(
779 nullptr, nullptr, symbol_name, eFunctionNameTypeAuto,
780 eLanguageTypeUnknown, offset, offset_is_insn_count, skip_prologue,
781 internal, hardware);
782 }
783 }
784
785 return sb_bp;
786}
787
789SBTarget::BreakpointCreateByName(const char *symbol_name,
790 const SBFileSpecList &module_list,
791 const SBFileSpecList &comp_unit_list) {
792 LLDB_INSTRUMENT_VA(this, symbol_name, module_list, comp_unit_list);
793
794 lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto;
795 return BreakpointCreateByName(symbol_name, name_type_mask,
796 eLanguageTypeUnknown, module_list,
797 comp_unit_list);
798}
799
801 const char *symbol_name, uint32_t name_type_mask,
802 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
803 LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, module_list,
804 comp_unit_list);
805
806 return BreakpointCreateByName(symbol_name, name_type_mask,
807 eLanguageTypeUnknown, module_list,
808 comp_unit_list);
809}
810
812 const char *symbol_name, uint32_t name_type_mask,
813 LanguageType symbol_language, const SBFileSpecList &module_list,
814 const SBFileSpecList &comp_unit_list) {
815 LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, symbol_language,
816 module_list, comp_unit_list);
817 return BreakpointCreateByName(symbol_name, name_type_mask, symbol_language, 0,
818 false, module_list, comp_unit_list);
819}
820
822 const char *symbol_name, uint32_t name_type_mask,
823 LanguageType symbol_language, lldb::addr_t offset,
824 bool offset_is_insn_count, const SBFileSpecList &module_list,
825 const SBFileSpecList &comp_unit_list) {
826 LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, symbol_language, offset,
827 offset_is_insn_count, module_list, comp_unit_list);
828
829 SBBreakpoint sb_bp;
830 if (TargetSP target_sp = GetSP();
831 target_sp && symbol_name && symbol_name[0]) {
832 const bool internal = false;
833 const bool hardware = false;
834 const LazyBool skip_prologue = eLazyBoolCalculate;
835 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
836 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
837 sb_bp = target_sp->CreateBreakpoint(module_list.get(), comp_unit_list.get(),
838 symbol_name, mask, symbol_language,
839 offset, offset_is_insn_count,
840 skip_prologue, internal, hardware);
841 }
842
843 return sb_bp;
844}
845
847 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
848 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
849 LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask, module_list,
850 comp_unit_list);
851
852 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
853 eLanguageTypeUnknown, module_list,
854 comp_unit_list);
855}
856
858 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
859 LanguageType symbol_language, const SBFileSpecList &module_list,
860 const SBFileSpecList &comp_unit_list) {
861 LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask,
862 symbol_language, module_list, comp_unit_list);
863
864 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
865 eLanguageTypeUnknown, 0, module_list,
866 comp_unit_list);
867}
868
870 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
871 LanguageType symbol_language, lldb::addr_t offset,
872 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
873 LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask,
874 symbol_language, offset, module_list, comp_unit_list);
875
876 SBBreakpoint sb_bp;
877 if (TargetSP target_sp = GetSP(); target_sp && num_names > 0) {
878 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
879 const bool internal = false;
880 const bool hardware = false;
881 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
882 const LazyBool skip_prologue = eLazyBoolCalculate;
883 sb_bp = target_sp->CreateBreakpoint(
884 module_list.get(), comp_unit_list.get(), symbol_names, num_names, mask,
885 symbol_language, offset, skip_prologue, internal, hardware);
886 }
887
888 return sb_bp;
889}
890
892 const char *module_name) {
893 LLDB_INSTRUMENT_VA(this, symbol_name_regex, module_name);
894
895 SBFileSpecList module_spec_list;
896 SBFileSpecList comp_unit_list;
897 if (module_name && module_name[0]) {
898 module_spec_list.Append(FileSpec(module_name));
899 }
900 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
901 module_spec_list, comp_unit_list);
902}
903
905SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
906 const SBFileSpecList &module_list,
907 const SBFileSpecList &comp_unit_list) {
908 LLDB_INSTRUMENT_VA(this, symbol_name_regex, module_list, comp_unit_list);
909
910 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
911 module_list, comp_unit_list);
912}
913
915 const char *symbol_name_regex, LanguageType symbol_language,
916 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
917 LLDB_INSTRUMENT_VA(this, symbol_name_regex, symbol_language, module_list,
918 comp_unit_list);
919
920 SBBreakpoint sb_bp;
921 if (TargetSP target_sp = GetSP();
922 target_sp && symbol_name_regex && symbol_name_regex[0]) {
923 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
924 RegularExpression regexp((llvm::StringRef(symbol_name_regex)));
925 const bool internal = false;
926 const bool hardware = false;
927 const LazyBool skip_prologue = eLazyBoolCalculate;
928
929 sb_bp = target_sp->CreateFuncRegexBreakpoint(
930 module_list.get(), comp_unit_list.get(), std::move(regexp),
931 symbol_language, skip_prologue, internal, hardware);
932 }
933
934 return sb_bp;
935}
936
938 LLDB_INSTRUMENT_VA(this, address);
939
940 SBBreakpoint sb_bp;
941 if (TargetSP target_sp = GetSP()) {
942 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
943 const bool hardware = false;
944 sb_bp = target_sp->CreateBreakpoint(address, false, hardware);
945 }
946
947 return sb_bp;
948}
949
951 LLDB_INSTRUMENT_VA(this, sb_address);
952
953 SBBreakpoint sb_bp;
954 if (!sb_address.IsValid()) {
955 return sb_bp;
956 }
957
958 if (TargetSP target_sp = GetSP()) {
959 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
960 const bool hardware = false;
961 sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware);
962 }
963
964 return sb_bp;
965}
966
969 const lldb::SBFileSpec &source_file,
970 const char *module_name) {
971 LLDB_INSTRUMENT_VA(this, source_regex, source_file, module_name);
972
973 SBFileSpecList module_spec_list;
974
975 if (module_name && module_name[0]) {
976 module_spec_list.Append(FileSpec(module_name));
977 }
978
979 SBFileSpecList source_file_list;
980 if (source_file.IsValid()) {
981 source_file_list.Append(source_file);
982 }
983
984 return BreakpointCreateBySourceRegex(source_regex, module_spec_list,
985 source_file_list);
986}
987
989 const char *source_regex, const SBFileSpecList &module_list,
990 const lldb::SBFileSpecList &source_file_list) {
991 LLDB_INSTRUMENT_VA(this, source_regex, module_list, source_file_list);
992
993 return BreakpointCreateBySourceRegex(source_regex, module_list,
994 source_file_list, SBStringList());
995}
996
998 const char *source_regex, const SBFileSpecList &module_list,
999 const lldb::SBFileSpecList &source_file_list,
1000 const SBStringList &func_names) {
1001 LLDB_INSTRUMENT_VA(this, source_regex, module_list, source_file_list,
1002 func_names);
1003
1004 SBBreakpoint sb_bp;
1005 if (TargetSP target_sp = GetSP();
1006 target_sp && source_regex && source_regex[0]) {
1007 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1008 const bool hardware = false;
1009 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
1010 RegularExpression regexp((llvm::StringRef(source_regex)));
1011 std::unordered_set<std::string> func_names_set;
1012 for (size_t i = 0; i < func_names.GetSize(); i++) {
1013 func_names_set.insert(func_names.GetStringAtIndex(i));
1014 }
1015
1016 sb_bp = target_sp->CreateSourceRegexBreakpoint(
1017 module_list.get(), source_file_list.get(), func_names_set,
1018 std::move(regexp), false, hardware, move_to_nearest_code);
1019 }
1020
1021 return sb_bp;
1022}
1023
1026 bool catch_bp, bool throw_bp) {
1027 LLDB_INSTRUMENT_VA(this, language, catch_bp, throw_bp);
1028
1029 SBBreakpoint sb_bp;
1030 if (TargetSP target_sp = GetSP()) {
1031 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1032 const bool hardware = false;
1033 sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
1034 hardware);
1035 }
1036
1037 return sb_bp;
1038}
1039
1041 const char *class_name, SBStructuredData &extra_args,
1042 const SBFileSpecList &module_list, const SBFileSpecList &file_list,
1043 bool request_hardware) {
1044 LLDB_INSTRUMENT_VA(this, class_name, extra_args, module_list, file_list,
1045 request_hardware);
1046
1047 SBBreakpoint sb_bp;
1048 if (TargetSP target_sp = GetSP()) {
1049 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1050 Status error;
1051
1052 StructuredData::ObjectSP obj_sp = extra_args.m_impl_up->GetObjectSP();
1053 sb_bp =
1054 target_sp->CreateScriptedBreakpoint(class_name,
1055 module_list.get(),
1056 file_list.get(),
1057 false, /* internal */
1058 request_hardware,
1059 obj_sp,
1060 &error);
1061 }
1062
1063 return sb_bp;
1064}
1065
1067 LLDB_INSTRUMENT_VA(this);
1068
1069 if (TargetSP target_sp = GetSP()) {
1070 // The breakpoint list is thread safe, no need to lock
1071 return target_sp->GetBreakpointList().GetSize();
1072 }
1073 return 0;
1074}
1075
1077 LLDB_INSTRUMENT_VA(this, idx);
1078
1079 SBBreakpoint sb_breakpoint;
1080 if (TargetSP target_sp = GetSP()) {
1081 // The breakpoint list is thread safe, no need to lock
1082 sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1083 }
1084 return sb_breakpoint;
1085}
1086
1088 LLDB_INSTRUMENT_VA(this, bp_id);
1089
1090 bool result = false;
1091 if (TargetSP target_sp = GetSP()) {
1092 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1093 result = target_sp->RemoveBreakpointByID(bp_id);
1094 }
1095
1096 return result;
1097}
1098
1100 LLDB_INSTRUMENT_VA(this, bp_id);
1101
1102 SBBreakpoint sb_breakpoint;
1103 if (TargetSP target_sp = GetSP();
1104 target_sp && bp_id != LLDB_INVALID_BREAK_ID) {
1105 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1106 sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
1107 }
1108
1109 return sb_breakpoint;
1110}
1111
1113 SBBreakpointList &bkpts) {
1114 LLDB_INSTRUMENT_VA(this, name, bkpts);
1115
1116 if (TargetSP target_sp = GetSP()) {
1117 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1118 llvm::Expected<std::vector<BreakpointSP>> expected_vector =
1119 target_sp->GetBreakpointList().FindBreakpointsByName(name);
1120 if (!expected_vector) {
1121 LLDB_LOG_ERROR(GetLog(LLDBLog::Breakpoints), expected_vector.takeError(),
1122 "invalid breakpoint name: {0}");
1123 return false;
1124 }
1125 for (BreakpointSP bkpt_sp : *expected_vector) {
1126 bkpts.AppendByID(bkpt_sp->GetID());
1127 }
1128 }
1129 return true;
1130}
1131
1133 LLDB_INSTRUMENT_VA(this, names);
1134
1135 names.Clear();
1136
1137 if (TargetSP target_sp = GetSP()) {
1138 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1139
1140 std::vector<std::string> name_vec;
1141 target_sp->GetBreakpointNames(name_vec);
1142 for (const auto &name : name_vec)
1143 names.AppendString(name.c_str());
1144 }
1145}
1146
1147void SBTarget::DeleteBreakpointName(const char *name) {
1148 LLDB_INSTRUMENT_VA(this, name);
1149
1150 if (TargetSP target_sp = GetSP()) {
1151 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1152 target_sp->DeleteBreakpointName(ConstString(name));
1153 }
1154}
1155
1157 LLDB_INSTRUMENT_VA(this);
1158
1159 if (TargetSP target_sp = GetSP()) {
1160 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1161 target_sp->EnableAllowedBreakpoints();
1162 return true;
1163 }
1164 return false;
1165}
1166
1168 LLDB_INSTRUMENT_VA(this);
1169
1170 if (TargetSP target_sp = GetSP()) {
1171 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1172 target_sp->DisableAllowedBreakpoints();
1173 return true;
1174 }
1175 return false;
1176}
1177
1179 LLDB_INSTRUMENT_VA(this);
1180
1181 if (TargetSP target_sp = GetSP()) {
1182 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1183 target_sp->RemoveAllowedBreakpoints();
1184 return true;
1185 }
1186 return false;
1187}
1188
1190 SBBreakpointList &new_bps) {
1191 LLDB_INSTRUMENT_VA(this, source_file, new_bps);
1192
1193 SBStringList empty_name_list;
1194 return BreakpointsCreateFromFile(source_file, empty_name_list, new_bps);
1195}
1196
1198 SBStringList &matching_names,
1199 SBBreakpointList &new_bps) {
1200 LLDB_INSTRUMENT_VA(this, source_file, matching_names, new_bps);
1201
1202 SBError sberr;
1203 if (TargetSP target_sp = GetSP()) {
1204 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1205
1206 BreakpointIDList bp_ids;
1207
1208 std::vector<std::string> name_vector;
1209 size_t num_names = matching_names.GetSize();
1210 for (size_t i = 0; i < num_names; i++)
1211 name_vector.push_back(matching_names.GetStringAtIndex(i));
1212
1213 sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(),
1214 name_vector, bp_ids);
1215 if (sberr.Fail())
1216 return sberr;
1217
1218 size_t num_bkpts = bp_ids.GetSize();
1219 for (size_t i = 0; i < num_bkpts; i++) {
1220 BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
1221 new_bps.AppendByID(bp_id.GetBreakpointID());
1222 }
1223 } else {
1224 sberr.SetErrorString(
1225 "BreakpointCreateFromFile called with invalid target.");
1226 }
1227 return sberr;
1228}
1229
1231 LLDB_INSTRUMENT_VA(this, dest_file);
1232
1233 SBError sberr;
1234 if (TargetSP target_sp = GetSP()) {
1235 SBBreakpointList bkpt_list(*this);
1236 return BreakpointsWriteToFile(dest_file, bkpt_list);
1237 }
1238 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1239 return sberr;
1240}
1241
1243 SBBreakpointList &bkpt_list,
1244 bool append) {
1245 LLDB_INSTRUMENT_VA(this, dest_file, bkpt_list, append);
1246
1247 SBError sberr;
1248 if (TargetSP target_sp = GetSP()) {
1249 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1250 BreakpointIDList bp_id_list;
1251 bkpt_list.CopyToBreakpointIDList(bp_id_list);
1252 sberr.ref() = target_sp->SerializeBreakpointsToFile(dest_file.ref(),
1253 bp_id_list, append);
1254 } else {
1255 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1256 }
1257 return sberr;
1258}
1259
1261 LLDB_INSTRUMENT_VA(this);
1262
1263 if (TargetSP target_sp = GetSP()) {
1264 // The watchpoint list is thread safe, no need to lock
1265 return target_sp->GetWatchpointList().GetSize();
1266 }
1267 return 0;
1268}
1269
1271 LLDB_INSTRUMENT_VA(this, idx);
1272
1273 SBWatchpoint sb_watchpoint;
1274 if (TargetSP target_sp = GetSP()) {
1275 // The watchpoint list is thread safe, no need to lock
1276 sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1277 }
1278 return sb_watchpoint;
1279}
1280
1282 LLDB_INSTRUMENT_VA(this, wp_id);
1283
1284 bool result = false;
1285 if (TargetSP target_sp = GetSP()) {
1286 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1287 std::unique_lock<std::recursive_mutex> lock;
1288 target_sp->GetWatchpointList().GetListMutex(lock);
1289 result = target_sp->RemoveWatchpointByID(wp_id);
1290 }
1291
1292 return result;
1293}
1294
1296 LLDB_INSTRUMENT_VA(this, wp_id);
1297
1298 SBWatchpoint sb_watchpoint;
1299 lldb::WatchpointSP watchpoint_sp;
1300 if (TargetSP target_sp = GetSP();
1301 target_sp && wp_id != LLDB_INVALID_WATCH_ID) {
1302 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1303 std::unique_lock<std::recursive_mutex> lock;
1304 target_sp->GetWatchpointList().GetListMutex(lock);
1305 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1306 sb_watchpoint.SetSP(watchpoint_sp);
1307 }
1308
1309 return sb_watchpoint;
1310}
1311
1313 bool read, bool modify,
1314 SBError &error) {
1315 LLDB_INSTRUMENT_VA(this, addr, size, read, write, error);
1316
1317 SBWatchpointOptions options;
1318 options.SetWatchpointTypeRead(read);
1319 if (modify)
1321 return WatchpointCreateByAddress(addr, size, options, error);
1322}
1323
1326 SBWatchpointOptions options,
1327 SBError &error) {
1328 LLDB_INSTRUMENT_VA(this, addr, size, options, error);
1329
1330 SBWatchpoint sb_watchpoint;
1331 lldb::WatchpointSP watchpoint_sp;
1332 uint32_t watch_type = 0;
1333 if (options.GetWatchpointTypeRead())
1334 watch_type |= LLDB_WATCH_TYPE_READ;
1336 watch_type |= LLDB_WATCH_TYPE_WRITE;
1338 watch_type |= LLDB_WATCH_TYPE_MODIFY;
1339 if (watch_type == 0) {
1340 error.SetErrorString("Can't create a watchpoint that is neither read nor "
1341 "write nor modify.");
1342 return sb_watchpoint;
1343 }
1344
1345 if (TargetSP target_sp = GetSP();
1346 target_sp && addr != LLDB_INVALID_ADDRESS && size > 0) {
1347 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1348 // Target::CreateWatchpoint() is thread safe.
1349 Status cw_error;
1350 // This API doesn't take in a type, so we can't figure out what it is.
1351 CompilerType *type = nullptr;
1352 watchpoint_sp =
1353 target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1354 error.SetError(std::move(cw_error));
1355 sb_watchpoint.SetSP(watchpoint_sp);
1356 }
1357
1358 return sb_watchpoint;
1359}
1360
1362 LLDB_INSTRUMENT_VA(this);
1363
1364 if (TargetSP target_sp = GetSP()) {
1365 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1366 std::unique_lock<std::recursive_mutex> lock;
1367 target_sp->GetWatchpointList().GetListMutex(lock);
1368 target_sp->EnableAllWatchpoints();
1369 return true;
1370 }
1371 return false;
1372}
1373
1375 LLDB_INSTRUMENT_VA(this);
1376
1377 if (TargetSP target_sp = GetSP()) {
1378 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1379 std::unique_lock<std::recursive_mutex> lock;
1380 target_sp->GetWatchpointList().GetListMutex(lock);
1381 target_sp->DisableAllWatchpoints();
1382 return true;
1383 }
1384 return false;
1385}
1386
1388 SBType type) {
1389 LLDB_INSTRUMENT_VA(this, name, addr, type);
1390
1391 SBValue sb_value;
1392 lldb::ValueObjectSP new_value_sp;
1393 if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) {
1394 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1395 ExecutionContext exe_ctx(
1397 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1398 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr,
1399 exe_ctx, ast_type);
1400 }
1401 sb_value.SetSP(new_value_sp);
1402 return sb_value;
1403}
1404
1406 lldb::SBType type) {
1407 LLDB_INSTRUMENT_VA(this, name, data, type);
1408
1409 SBValue sb_value;
1410 lldb::ValueObjectSP new_value_sp;
1411 if (IsValid() && name && *name && data.IsValid() && type.IsValid()) {
1412 DataExtractorSP extractor(*data);
1413 ExecutionContext exe_ctx(
1415 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1416 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor,
1417 exe_ctx, ast_type);
1418 }
1419 sb_value.SetSP(new_value_sp);
1420 return sb_value;
1421}
1422
1424 const char *expr) {
1425 LLDB_INSTRUMENT_VA(this, name, expr);
1426
1427 SBValue sb_value;
1428 lldb::ValueObjectSP new_value_sp;
1429 if (IsValid() && name && *name && expr && *expr) {
1430 ExecutionContext exe_ctx(
1432 new_value_sp =
1434 }
1435 sb_value.SetSP(new_value_sp);
1436 return sb_value;
1437}
1438
1440 LLDB_INSTRUMENT_VA(this);
1441
1442 if (TargetSP target_sp = GetSP()) {
1443 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1444 std::unique_lock<std::recursive_mutex> lock;
1445 target_sp->GetWatchpointList().GetListMutex(lock);
1446 target_sp->RemoveAllWatchpoints();
1447 return true;
1448 }
1449 return false;
1450}
1451
1452void SBTarget::AppendImageSearchPath(const char *from, const char *to,
1454 LLDB_INSTRUMENT_VA(this, from, to, error);
1455
1456 if (TargetSP target_sp = GetSP()) {
1457 llvm::StringRef srFrom = from, srTo = to;
1458 if (srFrom.empty())
1459 return error.SetErrorString("<from> path can't be empty");
1460 if (srTo.empty())
1461 return error.SetErrorString("<to> path can't be empty");
1462
1463 target_sp->GetImageSearchPathList().Append(srFrom, srTo, true);
1464 } else {
1465 error.SetErrorString("invalid target");
1466 }
1467}
1468
1469lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1470 const char *uuid_cstr) {
1471 LLDB_INSTRUMENT_VA(this, path, triple, uuid_cstr);
1472
1473 return AddModule(path, triple, uuid_cstr, nullptr);
1474}
1475
1476lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1477 const char *uuid_cstr, const char *symfile) {
1478 LLDB_INSTRUMENT_VA(this, path, triple, uuid_cstr, symfile);
1479
1480 if (TargetSP target_sp = GetSP()) {
1481 ModuleSpec module_spec;
1482 if (path)
1483 module_spec.GetFileSpec().SetFile(path, FileSpec::Style::native);
1484
1485 if (uuid_cstr)
1486 module_spec.GetUUID().SetFromStringRef(uuid_cstr);
1487
1488 if (triple)
1490 target_sp->GetPlatform().get(), triple);
1491 else
1492 module_spec.GetArchitecture() = target_sp->GetArchitecture();
1493
1494 if (symfile)
1495 module_spec.GetSymbolFileSpec().SetFile(symfile, FileSpec::Style::native);
1496
1497 SBModuleSpec sb_modulespec(module_spec);
1498
1499 return AddModule(sb_modulespec);
1500 }
1501 return SBModule();
1502}
1503
1505 LLDB_INSTRUMENT_VA(this, module_spec);
1506
1507 lldb::SBModule sb_module;
1508 if (TargetSP target_sp = GetSP()) {
1509 sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,
1510 true /* notify */));
1511 if (!sb_module.IsValid() && module_spec.m_opaque_up->GetUUID().IsValid()) {
1512 Status error;
1514 error,
1515 /* force_lookup */ true)) {
1516 if (FileSystem::Instance().Exists(
1517 module_spec.m_opaque_up->GetFileSpec())) {
1518 sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,
1519 true /* notify */));
1520 }
1521 }
1522 }
1523
1524 // If the target hasn't initialized any architecture yet, use the
1525 // binary's architecture.
1526 if (sb_module.IsValid() && !target_sp->GetArchitecture().IsValid() &&
1527 sb_module.GetSP()->GetArchitecture().IsValid())
1528 target_sp->SetArchitecture(sb_module.GetSP()->GetArchitecture());
1529 }
1530 return sb_module;
1531}
1532
1534 LLDB_INSTRUMENT_VA(this, module);
1535
1536 if (TargetSP target_sp = GetSP()) {
1537 target_sp->GetImages().AppendIfNeeded(module.GetSP());
1538 return true;
1539 }
1540 return false;
1541}
1542
1543uint32_t SBTarget::GetNumModules() const {
1544 LLDB_INSTRUMENT_VA(this);
1545
1546 uint32_t num = 0;
1547 if (TargetSP target_sp = GetSP()) {
1548 // The module list is thread safe, no need to lock
1549 num = target_sp->GetImages().GetSize();
1550 }
1551
1552 return num;
1553}
1554
1556 LLDB_INSTRUMENT_VA(this);
1557
1558 m_opaque_sp.reset();
1559}
1560
1562 LLDB_INSTRUMENT_VA(this, sb_file_spec);
1563
1564 SBModule sb_module;
1565 if (TargetSP target_sp = GetSP(); target_sp && sb_file_spec.IsValid()) {
1566 ModuleSpec module_spec(*sb_file_spec);
1567 // The module list is thread safe, no need to lock
1568 sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1569 }
1570 return sb_module;
1571}
1572
1574 LLDB_INSTRUMENT_VA(this, sb_module_spec);
1575
1576 SBModule sb_module;
1577 if (TargetSP target_sp = GetSP(); target_sp && sb_module_spec.IsValid()) {
1578 // The module list is thread safe, no need to lock.
1579 sb_module.SetSP(
1580 target_sp->GetImages().FindFirstModule(*sb_module_spec.m_opaque_up));
1581 }
1582 return sb_module;
1583}
1584
1586 LLDB_INSTRUMENT_VA(this, sb_file_spec);
1587
1588 SBSymbolContextList sb_sc_list;
1589 if (TargetSP target_sp = GetSP(); target_sp && sb_file_spec.IsValid())
1590 target_sp->GetImages().FindCompileUnits(*sb_file_spec, *sb_sc_list);
1591 return sb_sc_list;
1592}
1593
1595 LLDB_INSTRUMENT_VA(this);
1596
1597 if (TargetSP target_sp = GetSP())
1598 return target_sp->GetArchitecture().GetByteOrder();
1599 return eByteOrderInvalid;
1600}
1601
1602const char *SBTarget::GetTriple() {
1603 LLDB_INSTRUMENT_VA(this);
1604
1605 if (TargetSP target_sp = GetSP()) {
1606 std::string triple(target_sp->GetArchitecture().GetTriple().str());
1607 // Unique the string so we don't run into ownership issues since the const
1608 // strings put the string into the string pool once and the strings never
1609 // comes out
1610 ConstString const_triple(triple.c_str());
1611 return const_triple.GetCString();
1612 }
1613 return nullptr;
1614}
1615
1617 LLDB_INSTRUMENT_VA(this);
1618
1619 if (TargetSP target_sp = GetSP()) {
1620 std::string abi_name(target_sp->GetABIName().str());
1621 ConstString const_name(abi_name.c_str());
1622 return const_name.GetCString();
1623 }
1624 return nullptr;
1625}
1626
1627const char *SBTarget::GetLabel() const {
1628 LLDB_INSTRUMENT_VA(this);
1629
1630 if (TargetSP target_sp = GetSP())
1631 return ConstString(target_sp->GetLabel().data()).AsCString();
1632 return nullptr;
1633}
1634
1635SBError SBTarget::SetLabel(const char *label) {
1636 LLDB_INSTRUMENT_VA(this, label);
1637
1638 if (TargetSP target_sp = GetSP())
1639 return Status::FromError(target_sp->SetLabel(label));
1640 return Status::FromErrorString("Couldn't get internal target object.");
1641}
1642
1644 LLDB_INSTRUMENT_VA(this);
1645
1646 if (TargetSP target_sp = GetSP())
1647 return target_sp->GetArchitecture().GetMinimumOpcodeByteSize();
1648 return 0;
1649}
1650
1652 LLDB_INSTRUMENT_VA(this);
1653
1654 TargetSP target_sp(GetSP());
1655 if (target_sp)
1656 return target_sp->GetArchitecture().GetMaximumOpcodeByteSize();
1657
1658 return 0;
1659}
1660
1662 LLDB_INSTRUMENT_VA(this);
1663
1664 if (TargetSP target_sp = GetSP())
1665 return target_sp->GetArchitecture().GetDataByteSize();
1666 return 0;
1667}
1668
1670 LLDB_INSTRUMENT_VA(this);
1671
1672 if (TargetSP target_sp = GetSP())
1673 return target_sp->GetArchitecture().GetCodeByteSize();
1674 return 0;
1675}
1676
1678 LLDB_INSTRUMENT_VA(this);
1679
1680 if (TargetSP target_sp = GetSP())
1681 return target_sp->GetMaximumNumberOfChildrenToDisplay();
1682 return 0;
1683}
1684
1686 LLDB_INSTRUMENT_VA(this);
1687
1688 if (TargetSP target_sp = GetSP())
1689 return target_sp->GetArchitecture().GetAddressByteSize();
1690 return sizeof(void *);
1691}
1692
1694 LLDB_INSTRUMENT_VA(this, idx);
1695
1696 SBModule sb_module;
1697 ModuleSP module_sp;
1698 if (TargetSP target_sp = GetSP()) {
1699 // The module list is thread safe, no need to lock
1700 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1701 sb_module.SetSP(module_sp);
1702 }
1703
1704 return sb_module;
1705}
1706
1708 LLDB_INSTRUMENT_VA(this, module);
1709
1710 if (TargetSP target_sp = GetSP())
1711 return target_sp->GetImages().Remove(module.GetSP());
1712 return false;
1713}
1714
1716 LLDB_INSTRUMENT_VA(this);
1717
1718 if (TargetSP target_sp = GetSP()) {
1719 SBBroadcaster broadcaster(target_sp.get(), false);
1720 return broadcaster;
1721 }
1722 return SBBroadcaster();
1723}
1724
1726 lldb::DescriptionLevel description_level) {
1727 LLDB_INSTRUMENT_VA(this, description, description_level);
1728
1729 Stream &strm = description.ref();
1730
1731 if (TargetSP target_sp = GetSP()) {
1732 target_sp->Dump(&strm, description_level);
1733 } else
1734 strm.PutCString("No value");
1735
1736 return true;
1737}
1738
1740 uint32_t name_type_mask) {
1741 LLDB_INSTRUMENT_VA(this, name, name_type_mask);
1742
1743 lldb::SBSymbolContextList sb_sc_list;
1744 if (!name || !name[0])
1745 return sb_sc_list;
1746
1747 if (TargetSP target_sp = GetSP()) {
1748 ModuleFunctionSearchOptions function_options;
1749 function_options.include_symbols = true;
1750 function_options.include_inlines = true;
1751
1752 FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
1753 target_sp->GetImages().FindFunctions(ConstString(name), mask,
1754 function_options, *sb_sc_list);
1755 }
1756 return sb_sc_list;
1757}
1758
1760 uint32_t max_matches,
1761 MatchType matchtype) {
1762 LLDB_INSTRUMENT_VA(this, name, max_matches, matchtype);
1763
1764 lldb::SBSymbolContextList sb_sc_list;
1765 if (name && name[0]) {
1766 llvm::StringRef name_ref(name);
1767 if (TargetSP target_sp = GetSP()) {
1768 ModuleFunctionSearchOptions function_options;
1769 function_options.include_symbols = true;
1770 function_options.include_inlines = true;
1771
1772 std::string regexstr;
1773 switch (matchtype) {
1774 case eMatchTypeRegex:
1775 target_sp->GetImages().FindFunctions(RegularExpression(name_ref),
1776 function_options, *sb_sc_list);
1777 break;
1779 target_sp->GetImages().FindFunctions(
1780 RegularExpression(name_ref, llvm::Regex::RegexFlags::IgnoreCase),
1781 function_options, *sb_sc_list);
1782 break;
1784 regexstr = llvm::Regex::escape(name) + ".*";
1785 target_sp->GetImages().FindFunctions(RegularExpression(regexstr),
1786 function_options, *sb_sc_list);
1787 break;
1788 default:
1789 target_sp->GetImages().FindFunctions(ConstString(name),
1790 eFunctionNameTypeAny,
1791 function_options, *sb_sc_list);
1792 break;
1793 }
1794 }
1795 }
1796 return sb_sc_list;
1797}
1798
1799lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
1800 LLDB_INSTRUMENT_VA(this, typename_cstr);
1801
1802 if (TargetSP target_sp = GetSP();
1803 target_sp && typename_cstr && typename_cstr[0]) {
1804 ConstString const_typename(typename_cstr);
1805 TypeQuery query(const_typename.GetStringRef(),
1806 TypeQueryOptions::e_find_one);
1807 TypeResults results;
1808 target_sp->GetImages().FindTypes(/*search_first=*/nullptr, query, results);
1809 if (TypeSP type_sp = results.GetFirstType())
1810 return SBType(type_sp);
1811 // Didn't find the type in the symbols; Try the loaded language runtimes.
1812 if (auto process_sp = target_sp->GetProcessSP()) {
1813 for (auto *runtime : process_sp->GetLanguageRuntimes()) {
1814 if (auto vendor = runtime->GetDeclVendor()) {
1815 auto types = vendor->FindTypes(const_typename, /*max_matches*/ 1);
1816 if (!types.empty())
1817 return SBType(types.front());
1818 }
1819 }
1820 }
1821
1822 // No matches, search for basic typename matches.
1823 for (auto type_system_sp : target_sp->GetScratchTypeSystems())
1824 if (auto type = type_system_sp->GetBuiltinTypeByName(const_typename))
1825 return SBType(type);
1826 }
1827
1828 return SBType();
1829}
1830
1832 LLDB_INSTRUMENT_VA(this, type);
1833
1834 if (TargetSP target_sp = GetSP()) {
1835 for (auto type_system_sp : target_sp->GetScratchTypeSystems())
1836 if (auto compiler_type = type_system_sp->GetBasicTypeFromAST(type))
1837 return SBType(compiler_type);
1838 }
1839 return SBType();
1840}
1841
1842lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
1843 LLDB_INSTRUMENT_VA(this, typename_cstr);
1844
1845 SBTypeList sb_type_list;
1846 if (TargetSP target_sp = GetSP();
1847 target_sp && typename_cstr && typename_cstr[0]) {
1848 ModuleList &images = target_sp->GetImages();
1849 ConstString const_typename(typename_cstr);
1850 TypeQuery query(typename_cstr);
1851 TypeResults results;
1852 images.FindTypes(nullptr, query, results);
1853 for (const TypeSP &type_sp : results.GetTypeMap().Types())
1854 sb_type_list.Append(SBType(type_sp));
1855
1856 // Try the loaded language runtimes
1857 if (ProcessSP process_sp = target_sp->GetProcessSP()) {
1858 for (auto *runtime : process_sp->GetLanguageRuntimes()) {
1859 if (auto *vendor = runtime->GetDeclVendor()) {
1860 auto types =
1861 vendor->FindTypes(const_typename, /*max_matches*/ UINT32_MAX);
1862 for (auto type : types)
1863 sb_type_list.Append(SBType(type));
1864 }
1865 }
1866 }
1867
1868 if (sb_type_list.GetSize() == 0) {
1869 // No matches, search for basic typename matches
1870 for (auto type_system_sp : target_sp->GetScratchTypeSystems())
1871 if (auto compiler_type =
1872 type_system_sp->GetBuiltinTypeByName(const_typename))
1873 sb_type_list.Append(SBType(compiler_type));
1874 }
1875 }
1876 return sb_type_list;
1877}
1878
1880 uint32_t max_matches) {
1881 LLDB_INSTRUMENT_VA(this, name, max_matches);
1882
1883 SBValueList sb_value_list;
1884
1885 if (TargetSP target_sp = GetSP(); target_sp && name) {
1886 VariableList variable_list;
1887 target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
1888 variable_list);
1889 if (!variable_list.Empty()) {
1890 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1891 if (exe_scope == nullptr)
1892 exe_scope = target_sp.get();
1893 for (const VariableSP &var_sp : variable_list) {
1894 lldb::ValueObjectSP valobj_sp(
1895 ValueObjectVariable::Create(exe_scope, var_sp));
1896 if (valobj_sp)
1897 sb_value_list.Append(SBValue(valobj_sp));
1898 }
1899 }
1900 }
1901
1902 return sb_value_list;
1903}
1904
1906 uint32_t max_matches,
1907 MatchType matchtype) {
1908 LLDB_INSTRUMENT_VA(this, name, max_matches, matchtype);
1909
1910 SBValueList sb_value_list;
1911
1912 if (TargetSP target_sp = GetSP(); target_sp && name) {
1913 llvm::StringRef name_ref(name);
1914 VariableList variable_list;
1915
1916 std::string regexstr;
1917 switch (matchtype) {
1918 case eMatchTypeNormal:
1919 target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
1920 variable_list);
1921 break;
1922 case eMatchTypeRegex:
1923 target_sp->GetImages().FindGlobalVariables(RegularExpression(name_ref),
1924 max_matches, variable_list);
1925 break;
1927 target_sp->GetImages().FindGlobalVariables(
1928 RegularExpression(name_ref, llvm::Regex::IgnoreCase), max_matches,
1929 variable_list);
1930 break;
1932 regexstr = "^" + llvm::Regex::escape(name) + ".*";
1933 target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr),
1934 max_matches, variable_list);
1935 break;
1936 }
1937 if (!variable_list.Empty()) {
1938 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1939 if (exe_scope == nullptr)
1940 exe_scope = target_sp.get();
1941 for (const VariableSP &var_sp : variable_list) {
1942 lldb::ValueObjectSP valobj_sp(
1943 ValueObjectVariable::Create(exe_scope, var_sp));
1944 if (valobj_sp)
1945 sb_value_list.Append(SBValue(valobj_sp));
1946 }
1947 }
1948 }
1949
1950 return sb_value_list;
1951}
1952
1954 LLDB_INSTRUMENT_VA(this, name);
1955
1956 SBValueList sb_value_list(FindGlobalVariables(name, 1));
1957 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
1958 return sb_value_list.GetValueAtIndex(0);
1959 return SBValue();
1960}
1961
1963 LLDB_INSTRUMENT_VA(this);
1964
1965 SBSourceManager source_manager(*this);
1966 return source_manager;
1967}
1968
1970 uint32_t count) {
1971 LLDB_INSTRUMENT_VA(this, base_addr, count);
1972
1973 return ReadInstructions(base_addr, count, nullptr);
1974}
1975
1977 uint32_t count,
1978 const char *flavor_string) {
1979 LLDB_INSTRUMENT_VA(this, base_addr, count, flavor_string);
1980
1981 SBInstructionList sb_instructions;
1982
1983 if (TargetSP target_sp = GetSP()) {
1984 if (Address *addr_ptr = base_addr.get()) {
1985 if (llvm::Expected<DisassemblerSP> disassembler =
1986 target_sp->ReadInstructions(*addr_ptr, count, flavor_string)) {
1987 sb_instructions.SetDisassembler(*disassembler);
1988 }
1989 }
1990 }
1991
1992 return sb_instructions;
1993}
1994
1996 lldb::SBAddress end_addr,
1997 const char *flavor_string) {
1998 LLDB_INSTRUMENT_VA(this, start_addr, end_addr, flavor_string);
1999
2000 SBInstructionList sb_instructions;
2001
2002 if (TargetSP target_sp = GetSP()) {
2003 lldb::addr_t start_load_addr = start_addr.GetLoadAddress(*this);
2004 lldb::addr_t end_load_addr = end_addr.GetLoadAddress(*this);
2005 if (end_load_addr > start_load_addr) {
2006 lldb::addr_t size = end_load_addr - start_load_addr;
2007
2008 AddressRange range(start_load_addr, size);
2009 const bool force_live_memory = true;
2011 target_sp->GetArchitecture(), nullptr, flavor_string,
2012 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
2013 *target_sp, range, force_live_memory));
2014 }
2015 }
2016 return sb_instructions;
2017}
2018
2020 const void *buf,
2021 size_t size) {
2022 LLDB_INSTRUMENT_VA(this, base_addr, buf, size);
2023
2024 return GetInstructionsWithFlavor(base_addr, nullptr, buf, size);
2025}
2026
2029 const char *flavor_string, const void *buf,
2030 size_t size) {
2031 LLDB_INSTRUMENT_VA(this, base_addr, flavor_string, buf, size);
2032
2033 SBInstructionList sb_instructions;
2034
2035 if (TargetSP target_sp = GetSP()) {
2036 Address addr;
2037
2038 if (base_addr.get())
2039 addr = *base_addr.get();
2040
2041 constexpr bool data_from_file = true;
2042 if (!flavor_string || flavor_string[0] == '\0') {
2043 // FIXME - we don't have the mechanism in place to do per-architecture
2044 // settings. But since we know that for now we only support flavors on
2045 // x86 & x86_64,
2046 const llvm::Triple::ArchType arch =
2047 target_sp->GetArchitecture().GetTriple().getArch();
2048 if (arch == llvm::Triple::x86 || arch == llvm::Triple::x86_64)
2049 flavor_string = target_sp->GetDisassemblyFlavor();
2050 }
2051
2053 target_sp->GetArchitecture(), nullptr, flavor_string,
2054 target_sp->GetDisassemblyCPU(), target_sp->GetDisassemblyFeatures(),
2055 addr, buf, size, UINT32_MAX, data_from_file));
2056 }
2057
2058 return sb_instructions;
2059}
2060
2062 const void *buf,
2063 size_t size) {
2064 LLDB_INSTRUMENT_VA(this, base_addr, buf, size);
2065
2066 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), nullptr, buf,
2067 size);
2068}
2069
2072 const char *flavor_string, const void *buf,
2073 size_t size) {
2074 LLDB_INSTRUMENT_VA(this, base_addr, flavor_string, buf, size);
2075
2076 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string,
2077 buf, size);
2078}
2079
2081 lldb::addr_t section_base_addr) {
2082 LLDB_INSTRUMENT_VA(this, section, section_base_addr);
2083
2084 SBError sb_error;
2085 if (TargetSP target_sp = GetSP()) {
2086 if (!section.IsValid()) {
2087 sb_error.SetErrorStringWithFormat("invalid section");
2088 } else {
2089 SectionSP section_sp(section.GetSP());
2090 if (section_sp) {
2091 if (section_sp->IsThreadSpecific()) {
2092 sb_error.SetErrorString(
2093 "thread specific sections are not yet supported");
2094 } else {
2095 ProcessSP process_sp(target_sp->GetProcessSP());
2096 if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
2097 ModuleSP module_sp(section_sp->GetModule());
2098 if (module_sp) {
2099 ModuleList module_list;
2100 module_list.Append(module_sp);
2101 target_sp->ModulesDidLoad(module_list);
2102 }
2103 // Flush info in the process (stack frames, etc)
2104 if (process_sp)
2105 process_sp->Flush();
2106 }
2107 }
2108 }
2109 }
2110 } else {
2111 sb_error.SetErrorString("invalid target");
2112 }
2113 return sb_error;
2114}
2115
2117 LLDB_INSTRUMENT_VA(this, section);
2118
2119 SBError sb_error;
2120
2121 if (TargetSP target_sp = GetSP()) {
2122 if (!section.IsValid()) {
2123 sb_error.SetErrorStringWithFormat("invalid section");
2124 } else {
2125 SectionSP section_sp(section.GetSP());
2126 if (section_sp) {
2127 ProcessSP process_sp(target_sp->GetProcessSP());
2128 if (target_sp->SetSectionUnloaded(section_sp)) {
2129 ModuleSP module_sp(section_sp->GetModule());
2130 if (module_sp) {
2131 ModuleList module_list;
2132 module_list.Append(module_sp);
2133 target_sp->ModulesDidUnload(module_list, false);
2134 }
2135 // Flush info in the process (stack frames, etc)
2136 if (process_sp)
2137 process_sp->Flush();
2138 }
2139 } else {
2140 sb_error.SetErrorStringWithFormat("invalid section");
2141 }
2142 }
2143 } else {
2144 sb_error.SetErrorStringWithFormat("invalid target");
2145 }
2146 return sb_error;
2147}
2148
2150 int64_t slide_offset) {
2151 LLDB_INSTRUMENT_VA(this, module, slide_offset);
2152
2153 if (slide_offset < 0) {
2154 SBError sb_error;
2155 sb_error.SetErrorStringWithFormat("slide must be positive");
2156 return sb_error;
2157 }
2158
2159 return SetModuleLoadAddress(module, static_cast<uint64_t>(slide_offset));
2160}
2161
2163 uint64_t slide_offset) {
2164
2165 SBError sb_error;
2166
2167 if (TargetSP target_sp = GetSP()) {
2168 ModuleSP module_sp(module.GetSP());
2169 if (module_sp) {
2170 bool changed = false;
2171 if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) {
2172 // The load was successful, make sure that at least some sections
2173 // changed before we notify that our module was loaded.
2174 if (changed) {
2175 ModuleList module_list;
2176 module_list.Append(module_sp);
2177 target_sp->ModulesDidLoad(module_list);
2178 // Flush info in the process (stack frames, etc)
2179 ProcessSP process_sp(target_sp->GetProcessSP());
2180 if (process_sp)
2181 process_sp->Flush();
2182 }
2183 }
2184 } else {
2185 sb_error.SetErrorStringWithFormat("invalid module");
2186 }
2187
2188 } else {
2189 sb_error.SetErrorStringWithFormat("invalid target");
2190 }
2191 return sb_error;
2192}
2193
2195 LLDB_INSTRUMENT_VA(this, module);
2196
2197 SBError sb_error;
2198
2199 char path[PATH_MAX];
2200 if (TargetSP target_sp = GetSP()) {
2201 ModuleSP module_sp(module.GetSP());
2202 if (module_sp) {
2203 ObjectFile *objfile = module_sp->GetObjectFile();
2204 if (objfile) {
2205 SectionList *section_list = objfile->GetSectionList();
2206 if (section_list) {
2207 ProcessSP process_sp(target_sp->GetProcessSP());
2208
2209 bool changed = false;
2210 const size_t num_sections = section_list->GetSize();
2211 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
2212 SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
2213 if (section_sp)
2214 changed |= target_sp->SetSectionUnloaded(section_sp);
2215 }
2216 if (changed) {
2217 ModuleList module_list;
2218 module_list.Append(module_sp);
2219 target_sp->ModulesDidUnload(module_list, false);
2220 // Flush info in the process (stack frames, etc)
2221 ProcessSP process_sp(target_sp->GetProcessSP());
2222 if (process_sp)
2223 process_sp->Flush();
2224 }
2225 } else {
2226 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2227 sb_error.SetErrorStringWithFormat("no sections in object file '%s'",
2228 path);
2229 }
2230 } else {
2231 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2232 sb_error.SetErrorStringWithFormat("no object file for module '%s'",
2233 path);
2234 }
2235 } else {
2236 sb_error.SetErrorStringWithFormat("invalid module");
2237 }
2238 } else {
2239 sb_error.SetErrorStringWithFormat("invalid target");
2240 }
2241 return sb_error;
2242}
2243
2245 lldb::SymbolType symbol_type) {
2246 LLDB_INSTRUMENT_VA(this, name, symbol_type);
2247
2248 SBSymbolContextList sb_sc_list;
2249 if (name && name[0]) {
2250 if (TargetSP target_sp = GetSP()) {
2251 target_sp->GetImages().FindSymbolsWithNameAndType(
2252 ConstString(name), symbol_type, *sb_sc_list);
2253 }
2254 }
2255 return sb_sc_list;
2256}
2257
2259 LLDB_INSTRUMENT_VA(this, expr);
2260
2261 if (TargetSP target_sp = GetSP()) {
2262 SBExpressionOptions options;
2263 lldb::DynamicValueType fetch_dynamic_value =
2264 target_sp->GetPreferDynamicValue();
2265 options.SetFetchDynamicValue(fetch_dynamic_value);
2266 options.SetUnwindOnError(true);
2267 return EvaluateExpression(expr, options);
2268 }
2269 return SBValue();
2270}
2271
2273 const SBExpressionOptions &options) {
2274 LLDB_INSTRUMENT_VA(this, expr, options);
2275
2276 Log *expr_log = GetLog(LLDBLog::Expressions);
2277 SBValue expr_result;
2278 ValueObjectSP expr_value_sp;
2279 if (TargetSP target_sp = GetSP()) {
2280 StackFrame *frame = nullptr;
2281 if (expr == nullptr || expr[0] == '\0')
2282 return expr_result;
2283
2284 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2285 ExecutionContext exe_ctx(m_opaque_sp.get());
2286
2287 frame = exe_ctx.GetFramePtr();
2288 Target *target = exe_ctx.GetTargetPtr();
2289 Process *process = exe_ctx.GetProcessPtr();
2290
2291 if (target) {
2292 // If we have a process, make sure to lock the runlock:
2293 if (process) {
2294 Process::StopLocker stop_locker;
2295 if (stop_locker.TryLock(&process->GetRunLock())) {
2296 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2297 } else {
2298 Status error;
2299 error = Status::FromErrorString("can't evaluate expressions when the "
2300 "process is running.");
2301 expr_value_sp =
2302 ValueObjectConstResult::Create(nullptr, std::move(error));
2303 }
2304 } else {
2305 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2306 }
2307
2308 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2309 }
2310 }
2311 LLDB_LOGF(expr_log,
2312 "** [SBTarget::EvaluateExpression] Expression result is "
2313 "%s, summary %s **",
2314 expr_result.GetValue(), expr_result.GetSummary());
2315 return expr_result;
2316}
2317
2319 LLDB_INSTRUMENT_VA(this);
2320
2321 if (TargetSP target_sp = GetSP()) {
2322 ABISP abi_sp;
2323 ProcessSP process_sp(target_sp->GetProcessSP());
2324 if (process_sp)
2325 abi_sp = process_sp->GetABI();
2326 else
2327 abi_sp = ABI::FindPlugin(ProcessSP(), target_sp->GetArchitecture());
2328 if (abi_sp)
2329 return abi_sp->GetRedZoneSize();
2330 }
2331 return 0;
2332}
2333
2334bool SBTarget::IsLoaded(const SBModule &module) const {
2335 LLDB_INSTRUMENT_VA(this, module);
2336
2337 if (TargetSP target_sp = GetSP()) {
2338 ModuleSP module_sp(module.GetSP());
2339 if (module_sp)
2340 return module_sp->IsLoadedInTarget(target_sp.get());
2341 }
2342 return false;
2343}
2344
2346 LLDB_INSTRUMENT_VA(this);
2347
2348 lldb::SBLaunchInfo launch_info(nullptr);
2349 if (TargetSP target_sp = GetSP())
2350 launch_info.set_ref(m_opaque_sp->GetProcessLaunchInfo());
2351 return launch_info;
2352}
2353
2355 LLDB_INSTRUMENT_VA(this, launch_info);
2356
2357 if (TargetSP target_sp = GetSP())
2358 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
2359}
2360
2362 LLDB_INSTRUMENT_VA(this);
2363
2364 if (TargetSP target_sp = GetSP())
2365 return SBEnvironment(target_sp->GetEnvironment());
2366
2367 return SBEnvironment();
2368}
2369
2371 LLDB_INSTRUMENT_VA(this);
2372
2373 if (TargetSP target_sp = GetSP())
2374 return SBTrace(target_sp->GetTrace());
2375
2376 return SBTrace();
2377}
2378
2381
2382 error.Clear();
2383 if (TargetSP target_sp = GetSP()) {
2384 if (llvm::Expected<lldb::TraceSP> trace_sp = target_sp->CreateTrace()) {
2385 return SBTrace(*trace_sp);
2386 } else {
2387 error.SetErrorString(llvm::toString(trace_sp.takeError()).c_str());
2388 }
2389 } else {
2390 error.SetErrorString("missing target");
2391 }
2392 return SBTrace();
2393}
2394
2396 LLDB_INSTRUMENT_VA(this);
2397
2398 if (TargetSP target_sp = GetSP())
2399 return lldb::SBMutex(target_sp);
2400 return lldb::SBMutex();
2401}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
#define LLDB_LOGF(log,...)
Definition Log.h:376
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
static Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target)
Definition SBTarget.cpp:77
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:211
ModuleSP GetSP() const
Definition SBModule.cpp:209
bool IsValid() const
Definition SBModule.cpp:75
lldb::PlatformSP m_opaque_sp
Definition SBPlatform.h:205
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:177
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()
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:226
bool BreakpointDelete(break_id_t break_id)
void SetSP(const lldb::TargetSP &target_sp)
Definition SBTarget.cpp:580
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:139
bool GetCollectingStats()
Returns whether statistics collection are enabled.
Definition SBTarget.cpp:233
lldb::SBBreakpoint BreakpointCreateByAddress(addr_t address)
Definition SBTarget.cpp:937
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:891
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:108
const char * GetLabel() const
friend class SBProcess
Definition SBTarget.h:995
static bool EventIsTargetEvent(const lldb::SBEvent &event)
Definition SBTarget.cpp:119
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:616
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:294
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:584
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:197
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:553
const char * GetABIName()
friend class SBDebugger
Definition SBTarget.h:988
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:993
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:523
friend class SBBreakpoint
Definition SBTarget.h:985
lldb::SBBreakpoint BreakpointCreateByName(const char *symbol_name, const char *module_name=nullptr)
Definition SBTarget.cpp:757
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:432
bool EnableAllWatchpoints()
lldb::SBBreakpoint BreakpointCreateBySBAddress(SBAddress &address)
Definition SBTarget.cpp:950
friend class SBValue
Definition SBTarget.h:1001
friend class SBAddress
Definition SBTarget.h:982
bool IsValid() const
Definition SBTarget.cpp:154
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:164
SBSymbolContext ResolveSymbolContextForAddress(const SBAddress &addr, uint32_t resolve_scope)
Definition SBTarget.cpp:635
lldb::SBProcess AttachToProcessWithID(SBListener &listener, lldb::pid_t pid, lldb::SBError &error)
Attach to process with pid.
Definition SBTarget.cpp:464
lldb::SBPlatform GetPlatform()
Return the platform object associated with the target.
Definition SBTarget.cpp:177
lldb::SBBreakpoint BreakpointCreateByLocation(const char *file, uint32_t line)
Definition SBTarget.cpp:668
lldb::SBBreakpoint BreakpointCreateForException(lldb::LanguageType language, bool catch_bp, bool throw_bp)
uint32_t GetNumModules() const
lldb::TargetSP GetSP() const
Definition SBTarget.cpp:578
uint32_t GetDataByteSize()
Architecture data byte width accessor.
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)
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:305
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:148
SBEnvironment GetEnvironment()
Return the environment variables that would be used to launch a new process.
lldb::SBTypeList FindTypes(const char *type)
lldb::SBValue CreateValueFromAddress(const char *name, lldb::SBAddress addr, lldb::SBType type)
static lldb::SBTarget GetTargetFromEvent(const lldb::SBEvent &event)
Definition SBTarget.cpp:125
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:566
bool operator!=(const lldb::SBTarget &rhs) const
Definition SBTarget.cpp:572
lldb::TargetSP m_opaque_sp
Definition SBTarget.h:1016
lldb::SBWatchpoint GetWatchpointAtIndex(uint32_t idx) const
lldb::SBLaunchInfo GetLaunchInfo() const
lldb::SBSymbolContextList FindSymbols(const char *name, lldb::SymbolType type=eSymbolTypeAny)
void AppendImageSearchPath(const char *from, const char *to, lldb::SBError &error)
friend class SBBreakpointList
Definition SBTarget.h:986
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:968
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:219
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:652
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:846
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:270
lldb::SBModule FindModule(const lldb::SBFileSpec &file_spec)
friend class SBSourceManager
Definition SBTarget.h:997
lldb::SBBreakpoint FindBreakpointByID(break_id_t break_id)
friend class SBType
Definition SBTarget.h:999
lldb::SBInstructionList ReadInstructions(lldb::SBAddress base_addr, uint32_t count)
void GetBreakpointNames(SBStringList &names)
lldb::SBDebugger GetDebugger() const
Definition SBTarget.cpp:188
friend class SBPlatform
Definition SBTarget.h:994
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:601
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()
Architecture code byte width accessor.
lldb::SBProcess AttachToProcessWithName(SBListener &listener, const char *name, bool wait_for, lldb::SBError &error)
Attach to process with name.
Definition SBTarget.cpp:491
SBProcess LoadCore(const char *core_file)
Definition SBTarget.cpp:241
static uint32_t GetNumModulesFromEvent(const lldb::SBEvent &event)
Definition SBTarget.cpp:131
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:1116
const char * GetValue()
Definition SBValue.cpp:352
const char * GetSummary()
Definition SBValue.cpp:419
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:31
bool IsValid() const
Tests if this ArchSpec is valid.
Definition ArchSpec.h:366
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
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
static void SetCollectingStats(bool enable)
Definition Statistics.h:345
static bool GetCollectingStats()
Definition Statistics.h:346
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)
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
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
static FileSystem & Instance()
A collection class for Module objects.
Definition ModuleList.h:104
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:53
ArchSpec & GetArchitecture()
Definition ModuleSpec.h:89
FileSpec & GetSymbolFileSpec()
Definition ModuleSpec.h:77
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:468
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:454
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:45
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:227
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:357
ProcessRunLock::ProcessRunLocker StopLocker
Definition Process.h:396
ProcessRunLock & GetRunLock()
Definition Process.cpp:5871
size_t GetSize() const
Definition Section.h:75
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition Section.cpp:551
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:137
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:65
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 ModuleList GetModuleListFromEvent(const Event *event_ptr)
Definition Target.cpp:5210
static const TargetEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition Target.cpp:5191
static lldb::TargetSP GetTargetFromEvent(const Event *event_ptr)
Definition Target.cpp:5201
const lldb::ProcessSP & GetProcessSP() const
Definition Target.cpp:306
std::recursive_mutex & GetAPIMutex()
Definition Target.cpp:5218
static llvm::StringRef GetStaticBroadcasterClass()
Definition Target.cpp:168
Status Attach(ProcessAttachInfo &attach_info, Stream *stream)
Definition Target.cpp:3593
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:2842
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_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:332
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:92
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:86
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:87
std::shared_ptr< lldb_private::Variable > VariableSP
class LLDB_API SBTrace
Definition SBDefines.h:118
class LLDB_API SBStringList
Definition SBDefines.h:109
std::shared_ptr< lldb_private::Section > SectionSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
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
#define PATH_MAX