1 //===-- SBTarget.cpp --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBTarget.h"
12 #include "lldb/lldb-public.h"
14 #include "lldb/API/SBBreakpoint.h"
15 #include "lldb/API/SBDebugger.h"
16 #include "lldb/API/SBEvent.h"
17 #include "lldb/API/SBExpressionOptions.h"
18 #include "lldb/API/SBFileSpec.h"
19 #include "lldb/API/SBListener.h"
20 #include "lldb/API/SBModule.h"
21 #include "lldb/API/SBModuleSpec.h"
22 #include "lldb/API/SBProcess.h"
23 #include "lldb/API/SBSourceManager.h"
24 #include "lldb/API/SBStream.h"
25 #include "lldb/API/SBStringList.h"
26 #include "lldb/API/SBStructuredData.h"
27 #include "lldb/API/SBSymbolContextList.h"
28 #include "lldb/Breakpoint/BreakpointID.h"
29 #include "lldb/Breakpoint/BreakpointIDList.h"
30 #include "lldb/Breakpoint/BreakpointList.h"
31 #include "lldb/Breakpoint/BreakpointLocation.h"
32 #include "lldb/Core/Address.h"
33 #include "lldb/Core/AddressResolver.h"
34 #include "lldb/Core/AddressResolverName.h"
35 #include "lldb/Core/Debugger.h"
36 #include "lldb/Core/Disassembler.h"
37 #include "lldb/Core/Module.h"
38 #include "lldb/Core/ModuleSpec.h"
39 #include "lldb/Core/STLUtils.h"
40 #include "lldb/Core/SearchFilter.h"
41 #include "lldb/Core/Section.h"
42 #include "lldb/Core/StructuredDataImpl.h"
43 #include "lldb/Core/ValueObjectConstResult.h"
44 #include "lldb/Core/ValueObjectList.h"
45 #include "lldb/Core/ValueObjectVariable.h"
46 #include "lldb/Host/Host.h"
47 #include "lldb/Symbol/ClangASTContext.h"
48 #include "lldb/Symbol/DeclVendor.h"
49 #include "lldb/Symbol/ObjectFile.h"
50 #include "lldb/Symbol/SymbolFile.h"
51 #include "lldb/Symbol/SymbolVendor.h"
52 #include "lldb/Symbol/VariableList.h"
53 #include "lldb/Target/ABI.h"
54 #include "lldb/Target/Language.h"
55 #include "lldb/Target/LanguageRuntime.h"
56 #include "lldb/Target/ObjCLanguageRuntime.h"
57 #include "lldb/Target/Process.h"
58 #include "lldb/Target/StackFrame.h"
59 #include "lldb/Target/Target.h"
60 #include "lldb/Target/TargetList.h"
61 #include "lldb/Utility/ArchSpec.h"
62 #include "lldb/Utility/Args.h"
63 #include "lldb/Utility/FileSpec.h"
64 #include "lldb/Utility/Log.h"
65 #include "lldb/Utility/RegularExpression.h"
67 #include "Commands/CommandObjectBreakpoint.h"
68 #include "lldb/Interpreter/CommandReturnObject.h"
69 #include "llvm/Support/PrettyStackTrace.h"
70 #include "llvm/Support/Regex.h"
73 using namespace lldb_private;
75 #define DEFAULT_DISASM_BYTE_SIZE 32
79 Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target) {
80 std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
82 auto process_sp = target.GetProcessSP();
84 const auto state = process_sp->GetState();
85 if (process_sp->IsAlive() && state == eStateConnected) {
86 // If we are already connected, then we have already specified the
87 // listener, so if a valid listener is supplied, we need to error out to
88 // let the client know.
89 if (attach_info.GetListener())
90 return Status("process is connected and already has a listener, pass "
95 return target.Attach(attach_info, nullptr);
100 //----------------------------------------------------------------------
101 // SBTarget constructor
102 //----------------------------------------------------------------------
103 SBTarget::SBTarget() : m_opaque_sp() {}
105 SBTarget::SBTarget(const SBTarget &rhs) : m_opaque_sp(rhs.m_opaque_sp) {}
107 SBTarget::SBTarget(const TargetSP &target_sp) : m_opaque_sp(target_sp) {}
109 const SBTarget &SBTarget::operator=(const SBTarget &rhs) {
111 m_opaque_sp = rhs.m_opaque_sp;
115 //----------------------------------------------------------------------
117 //----------------------------------------------------------------------
118 SBTarget::~SBTarget() {}
120 bool SBTarget::EventIsTargetEvent(const SBEvent &event) {
121 return Target::TargetEventData::GetEventDataFromEvent(event.get()) != NULL;
124 SBTarget SBTarget::GetTargetFromEvent(const SBEvent &event) {
125 return Target::TargetEventData::GetTargetFromEvent(event.get());
128 uint32_t SBTarget::GetNumModulesFromEvent(const SBEvent &event) {
129 const ModuleList module_list =
130 Target::TargetEventData::GetModuleListFromEvent(event.get());
131 return module_list.GetSize();
134 SBModule SBTarget::GetModuleAtIndexFromEvent(const uint32_t idx,
135 const SBEvent &event) {
136 const ModuleList module_list =
137 Target::TargetEventData::GetModuleListFromEvent(event.get());
138 return SBModule(module_list.GetModuleAtIndex(idx));
141 const char *SBTarget::GetBroadcasterClassName() {
142 return Target::GetStaticBroadcasterClass().AsCString();
145 bool SBTarget::IsValid() const {
146 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
149 SBProcess SBTarget::GetProcess() {
150 SBProcess sb_process;
151 ProcessSP process_sp;
152 TargetSP target_sp(GetSP());
154 process_sp = target_sp->GetProcessSP();
155 sb_process.SetSP(process_sp);
158 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
160 log->Printf("SBTarget(%p)::GetProcess () => SBProcess(%p)",
161 static_cast<void *>(target_sp.get()),
162 static_cast<void *>(process_sp.get()));
167 SBPlatform SBTarget::GetPlatform() {
168 TargetSP target_sp(GetSP());
173 platform.m_opaque_sp = target_sp->GetPlatform();
178 SBDebugger SBTarget::GetDebugger() const {
180 TargetSP target_sp(GetSP());
182 debugger.reset(target_sp->GetDebugger().shared_from_this());
186 SBStructuredData SBTarget::GetStatistics() {
187 SBStructuredData data;
188 TargetSP target_sp(GetSP());
192 auto stats_up = llvm::make_unique<StructuredData::Dictionary>();
194 for (auto &Entry : target_sp->GetStatistics()) {
195 std::string Desc = lldb_private::GetStatDescription(
196 static_cast<lldb_private::StatisticKind>(i));
197 stats_up->AddIntegerItem(Desc, Entry);
201 data.m_impl_up->SetObjectSP(std::move(stats_up));
205 SBProcess SBTarget::LoadCore(const char *core_file) {
206 lldb::SBError error; // Ignored
207 return LoadCore(core_file, error);
210 SBProcess SBTarget::LoadCore(const char *core_file, lldb::SBError &error) {
211 SBProcess sb_process;
212 TargetSP target_sp(GetSP());
214 FileSpec filespec(core_file, true);
215 ProcessSP process_sp(target_sp->CreateProcess(
216 target_sp->GetDebugger().GetListener(), "", &filespec));
218 error.SetError(process_sp->LoadCore());
220 sb_process.SetSP(process_sp);
222 error.SetErrorString("Failed to create the process");
225 error.SetErrorString("SBTarget is invalid");
230 SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp,
231 const char *working_directory) {
232 char *stdin_path = NULL;
233 char *stdout_path = NULL;
234 char *stderr_path = NULL;
235 uint32_t launch_flags = 0;
236 bool stop_at_entry = false;
238 SBListener listener = GetDebugger().GetListener();
239 return Launch(listener, argv, envp, stdin_path, stdout_path, stderr_path,
240 working_directory, launch_flags, stop_at_entry, error);
243 SBError SBTarget::Install() {
245 TargetSP target_sp(GetSP());
247 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
248 sb_error.ref() = target_sp->Install(NULL);
253 SBProcess SBTarget::Launch(SBListener &listener, char const **argv,
254 char const **envp, const char *stdin_path,
255 const char *stdout_path, const char *stderr_path,
256 const char *working_directory,
257 uint32_t launch_flags, // See LaunchFlags
258 bool stop_at_entry, lldb::SBError &error) {
259 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
261 SBProcess sb_process;
262 ProcessSP process_sp;
263 TargetSP target_sp(GetSP());
266 log->Printf("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, "
267 "stderr=%s, working-dir=%s, launch_flags=0x%x, "
268 "stop_at_entry=%i, &error (%p))...",
269 static_cast<void *>(target_sp.get()), static_cast<void *>(argv),
270 static_cast<void *>(envp), stdin_path ? stdin_path : "NULL",
271 stdout_path ? stdout_path : "NULL",
272 stderr_path ? stderr_path : "NULL",
273 working_directory ? working_directory : "NULL", launch_flags,
274 stop_at_entry, static_cast<void *>(error.get()));
277 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
280 launch_flags |= eLaunchFlagStopAtEntry;
282 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
283 launch_flags |= eLaunchFlagDisableASLR;
285 StateType state = eStateInvalid;
286 process_sp = target_sp->GetProcessSP();
288 state = process_sp->GetState();
290 if (process_sp->IsAlive() && state != eStateConnected) {
291 if (state == eStateAttaching)
292 error.SetErrorString("process attach is in progress");
294 error.SetErrorString("a process is already being debugged");
299 if (state == eStateConnected) {
300 // If we are already connected, then we have already specified the
301 // listener, so if a valid listener is supplied, we need to error out to
302 // let the client know.
303 if (listener.IsValid()) {
304 error.SetErrorString("process is connected and already has a listener, "
305 "pass empty listener");
310 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
311 launch_flags |= eLaunchFlagDisableSTDIO;
313 ProcessLaunchInfo launch_info(
314 FileSpec{stdin_path, false}, FileSpec{stdout_path, false},
315 FileSpec{stderr_path, false}, FileSpec{working_directory, false},
318 Module *exe_module = target_sp->GetExecutableModulePointer();
320 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
322 launch_info.GetArguments().AppendArguments(argv);
324 launch_info.GetEnvironment() = Environment(envp);
326 if (listener.IsValid())
327 launch_info.SetListener(listener.GetSP());
329 error.SetError(target_sp->Launch(launch_info, NULL));
331 sb_process.SetSP(target_sp->GetProcessSP());
333 error.SetErrorString("SBTarget is invalid");
336 log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API);
338 log->Printf("SBTarget(%p)::Launch (...) => SBProcess(%p), SBError(%s)",
339 static_cast<void *>(target_sp.get()),
340 static_cast<void *>(sb_process.GetSP().get()),
346 SBProcess SBTarget::Launch(SBLaunchInfo &sb_launch_info, SBError &error) {
347 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
349 SBProcess sb_process;
350 TargetSP target_sp(GetSP());
353 log->Printf("SBTarget(%p)::Launch (launch_info, error)...",
354 static_cast<void *>(target_sp.get()));
357 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
358 StateType state = eStateInvalid;
360 ProcessSP process_sp = target_sp->GetProcessSP();
362 state = process_sp->GetState();
364 if (process_sp->IsAlive() && state != eStateConnected) {
365 if (state == eStateAttaching)
366 error.SetErrorString("process attach is in progress");
368 error.SetErrorString("a process is already being debugged");
374 lldb_private::ProcessLaunchInfo launch_info = sb_launch_info.ref();
376 if (!launch_info.GetExecutableFile()) {
377 Module *exe_module = target_sp->GetExecutableModulePointer();
379 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
382 const ArchSpec &arch_spec = target_sp->GetArchitecture();
383 if (arch_spec.IsValid())
384 launch_info.GetArchitecture() = arch_spec;
386 error.SetError(target_sp->Launch(launch_info, NULL));
387 sb_launch_info.set_ref(launch_info);
388 sb_process.SetSP(target_sp->GetProcessSP());
390 error.SetErrorString("SBTarget is invalid");
393 log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API);
395 log->Printf("SBTarget(%p)::Launch (...) => SBProcess(%p)",
396 static_cast<void *>(target_sp.get()),
397 static_cast<void *>(sb_process.GetSP().get()));
402 lldb::SBProcess SBTarget::Attach(SBAttachInfo &sb_attach_info, SBError &error) {
403 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
405 SBProcess sb_process;
406 TargetSP target_sp(GetSP());
409 log->Printf("SBTarget(%p)::Attach (sb_attach_info, error)...",
410 static_cast<void *>(target_sp.get()));
413 ProcessAttachInfo &attach_info = sb_attach_info.ref();
414 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid()) {
415 PlatformSP platform_sp = target_sp->GetPlatform();
416 // See if we can pre-verify if a process exists or not
417 if (platform_sp && platform_sp->IsConnected()) {
418 lldb::pid_t attach_pid = attach_info.GetProcessID();
419 ProcessInstanceInfo instance_info;
420 if (platform_sp->GetProcessInfo(attach_pid, instance_info)) {
421 attach_info.SetUserID(instance_info.GetEffectiveUserID());
423 error.ref().SetErrorStringWithFormat(
424 "no process found with process ID %" PRIu64, attach_pid);
426 log->Printf("SBTarget(%p)::Attach (...) => error %s",
427 static_cast<void *>(target_sp.get()),
434 error.SetError(AttachToProcess(attach_info, *target_sp));
436 sb_process.SetSP(target_sp->GetProcessSP());
438 error.SetErrorString("SBTarget is invalid");
442 log->Printf("SBTarget(%p)::Attach (...) => SBProcess(%p)",
443 static_cast<void *>(target_sp.get()),
444 static_cast<void *>(sb_process.GetSP().get()));
449 lldb::SBProcess SBTarget::AttachToProcessWithID(
450 SBListener &listener,
451 lldb::pid_t pid, // The process ID to attach to
452 SBError &error // An error explaining what went wrong if attach fails
454 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
456 SBProcess sb_process;
457 TargetSP target_sp(GetSP());
460 log->Printf("SBTarget(%p)::%s (listener, pid=%" PRId64 ", error)...",
461 static_cast<void *>(target_sp.get()), __FUNCTION__, pid);
464 ProcessAttachInfo attach_info;
465 attach_info.SetProcessID(pid);
466 if (listener.IsValid())
467 attach_info.SetListener(listener.GetSP());
469 ProcessInstanceInfo instance_info;
470 if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info))
471 attach_info.SetUserID(instance_info.GetEffectiveUserID());
473 error.SetError(AttachToProcess(attach_info, *target_sp));
475 sb_process.SetSP(target_sp->GetProcessSP());
477 error.SetErrorString("SBTarget is invalid");
480 log->Printf("SBTarget(%p)::%s (...) => SBProcess(%p)",
481 static_cast<void *>(target_sp.get()), __FUNCTION__,
482 static_cast<void *>(sb_process.GetSP().get()));
486 lldb::SBProcess SBTarget::AttachToProcessWithName(
487 SBListener &listener,
488 const char *name, // basename of process to attach to
489 bool wait_for, // if true wait for a new instance of "name" to be launched
490 SBError &error // An error explaining what went wrong if attach fails
492 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
494 SBProcess sb_process;
495 TargetSP target_sp(GetSP());
498 log->Printf("SBTarget(%p)::%s (listener, name=%s, wait_for=%s, error)...",
499 static_cast<void *>(target_sp.get()), __FUNCTION__, name,
500 wait_for ? "true" : "false");
502 if (name && target_sp) {
503 ProcessAttachInfo attach_info;
504 attach_info.GetExecutableFile().SetFile(name, false,
505 FileSpec::Style::native);
506 attach_info.SetWaitForLaunch(wait_for);
507 if (listener.IsValid())
508 attach_info.SetListener(listener.GetSP());
510 error.SetError(AttachToProcess(attach_info, *target_sp));
512 sb_process.SetSP(target_sp->GetProcessSP());
514 error.SetErrorString("SBTarget is invalid");
517 log->Printf("SBTarget(%p)::%s (...) => SBProcess(%p)",
518 static_cast<void *>(target_sp.get()), __FUNCTION__,
519 static_cast<void *>(sb_process.GetSP().get()));
523 lldb::SBProcess SBTarget::ConnectRemote(SBListener &listener, const char *url,
524 const char *plugin_name,
526 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
528 SBProcess sb_process;
529 ProcessSP process_sp;
530 TargetSP target_sp(GetSP());
533 log->Printf("SBTarget(%p)::ConnectRemote (listener, url=%s, "
534 "plugin_name=%s, error)...",
535 static_cast<void *>(target_sp.get()), url, plugin_name);
538 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
539 if (listener.IsValid())
541 target_sp->CreateProcess(listener.m_opaque_sp, plugin_name, NULL);
543 process_sp = target_sp->CreateProcess(
544 target_sp->GetDebugger().GetListener(), plugin_name, NULL);
547 sb_process.SetSP(process_sp);
548 error.SetError(process_sp->ConnectRemote(NULL, url));
550 error.SetErrorString("unable to create lldb_private::Process");
553 error.SetErrorString("SBTarget is invalid");
557 log->Printf("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
558 static_cast<void *>(target_sp.get()),
559 static_cast<void *>(process_sp.get()));
563 SBFileSpec SBTarget::GetExecutable() {
565 SBFileSpec exe_file_spec;
566 TargetSP target_sp(GetSP());
568 Module *exe_module = target_sp->GetExecutableModulePointer();
570 exe_file_spec.SetFileSpec(exe_module->GetFileSpec());
573 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
575 log->Printf("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
576 static_cast<void *>(target_sp.get()),
577 static_cast<const void *>(exe_file_spec.get()));
580 return exe_file_spec;
583 bool SBTarget::operator==(const SBTarget &rhs) const {
584 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
587 bool SBTarget::operator!=(const SBTarget &rhs) const {
588 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
591 lldb::TargetSP SBTarget::GetSP() const { return m_opaque_sp; }
593 void SBTarget::SetSP(const lldb::TargetSP &target_sp) {
594 m_opaque_sp = target_sp;
597 lldb::SBAddress SBTarget::ResolveLoadAddress(lldb::addr_t vm_addr) {
598 lldb::SBAddress sb_addr;
599 Address &addr = sb_addr.ref();
600 TargetSP target_sp(GetSP());
602 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
603 if (target_sp->ResolveLoadAddress(vm_addr, addr))
607 // We have a load address that isn't in a section, just return an address
608 // with the offset filled in (the address) and the section set to NULL
609 addr.SetRawAddress(vm_addr);
613 lldb::SBAddress SBTarget::ResolveFileAddress(lldb::addr_t file_addr) {
614 lldb::SBAddress sb_addr;
615 Address &addr = sb_addr.ref();
616 TargetSP target_sp(GetSP());
618 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
619 if (target_sp->ResolveFileAddress(file_addr, addr))
623 addr.SetRawAddress(file_addr);
627 lldb::SBAddress SBTarget::ResolvePastLoadAddress(uint32_t stop_id,
628 lldb::addr_t vm_addr) {
629 lldb::SBAddress sb_addr;
630 Address &addr = sb_addr.ref();
631 TargetSP target_sp(GetSP());
633 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
634 if (target_sp->ResolveLoadAddress(vm_addr, addr))
638 // We have a load address that isn't in a section, just return an address
639 // with the offset filled in (the address) and the section set to NULL
640 addr.SetRawAddress(vm_addr);
645 SBTarget::ResolveSymbolContextForAddress(const SBAddress &addr,
646 uint32_t resolve_scope) {
648 if (addr.IsValid()) {
649 TargetSP target_sp(GetSP());
651 target_sp->GetImages().ResolveSymbolContextForAddress(
652 addr.ref(), resolve_scope, sc.ref());
657 size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size,
658 lldb::SBError &error) {
660 size_t bytes_read = 0;
661 TargetSP target_sp(GetSP());
663 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
665 target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref());
667 sb_error.SetErrorString("invalid target");
673 SBBreakpoint SBTarget::BreakpointCreateByLocation(const char *file,
676 BreakpointCreateByLocation(SBFileSpec(file, false), line));
680 SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
682 return BreakpointCreateByLocation(sb_file_spec, line, 0);
686 SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
687 uint32_t line, lldb::addr_t offset) {
688 SBFileSpecList empty_list;
689 return BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list);
693 SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
694 uint32_t line, lldb::addr_t offset,
695 SBFileSpecList &sb_module_list) {
696 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
699 TargetSP target_sp(GetSP());
700 if (target_sp && line != 0) {
701 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
703 const LazyBool check_inlines = eLazyBoolCalculate;
704 const LazyBool skip_prologue = eLazyBoolCalculate;
705 const bool internal = false;
706 const bool hardware = false;
707 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
708 const FileSpecList *module_list = nullptr;
709 if (sb_module_list.GetSize() > 0) {
710 module_list = sb_module_list.get();
712 sb_bp = target_sp->CreateBreakpoint(
713 module_list, *sb_file_spec, line, offset, check_inlines, skip_prologue,
714 internal, hardware, move_to_nearest_code);
719 sb_bp.GetDescription(sstr);
721 sb_file_spec->GetPath(path, sizeof(path));
722 log->Printf("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => "
723 "SBBreakpoint(%p): %s",
724 static_cast<void *>(target_sp.get()), path, line,
725 static_cast<void *>(sb_bp.GetSP().get()), sstr.GetData());
731 SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name,
732 const char *module_name) {
733 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
736 TargetSP target_sp(GetSP());
737 if (target_sp.get()) {
738 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
740 const bool internal = false;
741 const bool hardware = false;
742 const LazyBool skip_prologue = eLazyBoolCalculate;
743 const lldb::addr_t offset = 0;
744 if (module_name && module_name[0]) {
745 FileSpecList module_spec_list;
746 module_spec_list.Append(FileSpec(module_name, false));
747 sb_bp = target_sp->CreateBreakpoint(
748 &module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto,
749 eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
751 sb_bp = target_sp->CreateBreakpoint(
752 NULL, NULL, symbol_name, eFunctionNameTypeAuto, eLanguageTypeUnknown,
753 offset, skip_prologue, internal, hardware);
758 log->Printf("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", "
759 "module=\"%s\") => SBBreakpoint(%p)",
760 static_cast<void *>(target_sp.get()), symbol_name, module_name,
761 static_cast<void *>(sb_bp.GetSP().get()));
767 SBTarget::BreakpointCreateByName(const char *symbol_name,
768 const SBFileSpecList &module_list,
769 const SBFileSpecList &comp_unit_list) {
770 uint32_t name_type_mask = eFunctionNameTypeAuto;
771 return BreakpointCreateByName(symbol_name, name_type_mask,
772 eLanguageTypeUnknown, module_list,
776 lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
777 const char *symbol_name, uint32_t name_type_mask,
778 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
779 return BreakpointCreateByName(symbol_name, name_type_mask,
780 eLanguageTypeUnknown, module_list,
784 lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
785 const char *symbol_name, uint32_t name_type_mask,
786 LanguageType symbol_language, const SBFileSpecList &module_list,
787 const SBFileSpecList &comp_unit_list) {
788 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
791 TargetSP target_sp(GetSP());
792 if (target_sp && symbol_name && symbol_name[0]) {
793 const bool internal = false;
794 const bool hardware = false;
795 const LazyBool skip_prologue = eLazyBoolCalculate;
796 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
797 sb_bp = target_sp->CreateBreakpoint(
798 module_list.get(), comp_unit_list.get(), symbol_name, name_type_mask,
799 symbol_language, 0, skip_prologue, internal, hardware);
803 log->Printf("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", "
804 "name_type: %d) => SBBreakpoint(%p)",
805 static_cast<void *>(target_sp.get()), symbol_name,
806 name_type_mask, static_cast<void *>(sb_bp.GetSP().get()));
811 lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
812 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
813 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
814 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
815 eLanguageTypeUnknown, module_list,
819 lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
820 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
821 LanguageType symbol_language, const SBFileSpecList &module_list,
822 const SBFileSpecList &comp_unit_list) {
823 return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
824 eLanguageTypeUnknown, 0, module_list,
828 lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
829 const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
830 LanguageType symbol_language, lldb::addr_t offset,
831 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
832 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
835 TargetSP target_sp(GetSP());
836 if (target_sp && num_names > 0) {
837 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
838 const bool internal = false;
839 const bool hardware = false;
840 const LazyBool skip_prologue = eLazyBoolCalculate;
841 sb_bp = target_sp->CreateBreakpoint(
842 module_list.get(), comp_unit_list.get(), symbol_names, num_names,
843 name_type_mask, symbol_language, offset, skip_prologue, internal,
848 log->Printf("SBTarget(%p)::BreakpointCreateByName (symbols={",
849 static_cast<void *>(target_sp.get()));
850 for (uint32_t i = 0; i < num_names; i++) {
852 if (i < num_names - 1)
856 if (symbol_names[i] != NULL)
857 log->Printf("\"%s\"%c ", symbol_names[i], sep);
859 log->Printf("\"<NULL>\"%c ", sep);
861 log->Printf("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
862 static_cast<void *>(sb_bp.GetSP().get()));
868 SBBreakpoint SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
869 const char *module_name) {
870 SBFileSpecList module_spec_list;
871 SBFileSpecList comp_unit_list;
872 if (module_name && module_name[0]) {
873 module_spec_list.Append(FileSpec(module_name, false));
875 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
876 module_spec_list, comp_unit_list);
880 SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
881 const SBFileSpecList &module_list,
882 const SBFileSpecList &comp_unit_list) {
883 return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
884 module_list, comp_unit_list);
887 lldb::SBBreakpoint SBTarget::BreakpointCreateByRegex(
888 const char *symbol_name_regex, LanguageType symbol_language,
889 const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
890 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
893 TargetSP target_sp(GetSP());
894 if (target_sp && symbol_name_regex && symbol_name_regex[0]) {
895 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
896 RegularExpression regexp((llvm::StringRef(symbol_name_regex)));
897 const bool internal = false;
898 const bool hardware = false;
899 const LazyBool skip_prologue = eLazyBoolCalculate;
901 sb_bp = target_sp->CreateFuncRegexBreakpoint(
902 module_list.get(), comp_unit_list.get(), regexp, symbol_language,
903 skip_prologue, internal, hardware);
907 log->Printf("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") "
908 "=> SBBreakpoint(%p)",
909 static_cast<void *>(target_sp.get()), symbol_name_regex,
910 static_cast<void *>(sb_bp.GetSP().get()));
915 SBBreakpoint SBTarget::BreakpointCreateByAddress(addr_t address) {
916 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
919 TargetSP target_sp(GetSP());
921 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
922 const bool hardware = false;
923 sb_bp = target_sp->CreateBreakpoint(address, false, hardware);
927 log->Printf("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64
928 ") => SBBreakpoint(%p)",
929 static_cast<void *>(target_sp.get()),
930 static_cast<uint64_t>(address),
931 static_cast<void *>(sb_bp.GetSP().get()));
936 SBBreakpoint SBTarget::BreakpointCreateBySBAddress(SBAddress &sb_address) {
937 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
940 TargetSP target_sp(GetSP());
941 if (!sb_address.IsValid()) {
943 log->Printf("SBTarget(%p)::BreakpointCreateBySBAddress called with "
945 static_cast<void *>(target_sp.get()));
950 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
951 const bool hardware = false;
952 sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware);
957 sb_address.GetDescription(s);
958 log->Printf("SBTarget(%p)::BreakpointCreateBySBAddress (address=%s) => "
960 static_cast<void *>(target_sp.get()), s.GetData(),
961 static_cast<void *>(sb_bp.GetSP().get()));
968 SBTarget::BreakpointCreateBySourceRegex(const char *source_regex,
969 const lldb::SBFileSpec &source_file,
970 const char *module_name) {
971 SBFileSpecList module_spec_list;
973 if (module_name && module_name[0]) {
974 module_spec_list.Append(FileSpec(module_name, false));
977 SBFileSpecList source_file_list;
978 if (source_file.IsValid()) {
979 source_file_list.Append(source_file);
982 return BreakpointCreateBySourceRegex(source_regex, module_spec_list,
986 lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
987 const char *source_regex, const SBFileSpecList &module_list,
988 const lldb::SBFileSpecList &source_file_list) {
989 return BreakpointCreateBySourceRegex(source_regex, module_list,
990 source_file_list, SBStringList());
993 lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
994 const char *source_regex, const SBFileSpecList &module_list,
995 const lldb::SBFileSpecList &source_file_list,
996 const SBStringList &func_names) {
997 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1000 TargetSP target_sp(GetSP());
1001 if (target_sp && source_regex && source_regex[0]) {
1002 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1003 const bool hardware = false;
1004 const LazyBool move_to_nearest_code = eLazyBoolCalculate;
1005 RegularExpression regexp((llvm::StringRef(source_regex)));
1006 std::unordered_set<std::string> func_names_set;
1007 for (size_t i = 0; i < func_names.GetSize(); i++) {
1008 func_names_set.insert(func_names.GetStringAtIndex(i));
1011 sb_bp = target_sp->CreateSourceRegexBreakpoint(
1012 module_list.get(), source_file_list.get(), func_names_set, regexp,
1013 false, hardware, move_to_nearest_code);
1017 log->Printf("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") "
1018 "=> SBBreakpoint(%p)",
1019 static_cast<void *>(target_sp.get()), source_regex,
1020 static_cast<void *>(sb_bp.GetSP().get()));
1026 SBTarget::BreakpointCreateForException(lldb::LanguageType language,
1027 bool catch_bp, bool throw_bp) {
1028 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1031 TargetSP target_sp(GetSP());
1033 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1034 const bool hardware = false;
1035 sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
1040 log->Printf("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: "
1041 "%s throw: %s) => SBBreakpoint(%p)",
1042 static_cast<void *>(target_sp.get()),
1043 Language::GetNameForLanguageType(language),
1044 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1045 static_cast<void *>(sb_bp.GetSP().get()));
1050 uint32_t SBTarget::GetNumBreakpoints() const {
1051 TargetSP target_sp(GetSP());
1053 // The breakpoint list is thread safe, no need to lock
1054 return target_sp->GetBreakpointList().GetSize();
1059 SBBreakpoint SBTarget::GetBreakpointAtIndex(uint32_t idx) const {
1060 SBBreakpoint sb_breakpoint;
1061 TargetSP target_sp(GetSP());
1063 // The breakpoint list is thread safe, no need to lock
1064 sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1066 return sb_breakpoint;
1069 bool SBTarget::BreakpointDelete(break_id_t bp_id) {
1070 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1072 bool result = false;
1073 TargetSP target_sp(GetSP());
1075 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1076 result = target_sp->RemoveBreakpointByID(bp_id);
1080 log->Printf("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
1081 static_cast<void *>(target_sp.get()),
1082 static_cast<uint32_t>(bp_id), result);
1087 SBBreakpoint SBTarget::FindBreakpointByID(break_id_t bp_id) {
1088 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1090 SBBreakpoint sb_breakpoint;
1091 TargetSP target_sp(GetSP());
1092 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) {
1093 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1094 sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
1099 "SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1100 static_cast<void *>(target_sp.get()), static_cast<uint32_t>(bp_id),
1101 static_cast<void *>(sb_breakpoint.GetSP().get()));
1103 return sb_breakpoint;
1106 bool SBTarget::FindBreakpointsByName(const char *name,
1107 SBBreakpointList &bkpts) {
1108 TargetSP target_sp(GetSP());
1110 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1111 BreakpointList bkpt_list(false);
1113 target_sp->GetBreakpointList().FindBreakpointsByName(name, bkpt_list);
1116 for (BreakpointSP bkpt_sp : bkpt_list.Breakpoints()) {
1117 bkpts.AppendByID(bkpt_sp->GetID());
1123 void SBTarget::GetBreakpointNames(SBStringList &names)
1127 TargetSP target_sp(GetSP());
1129 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1131 std::vector<std::string> name_vec;
1132 target_sp->GetBreakpointNames(name_vec);
1133 for (auto name : name_vec)
1134 names.AppendString(name.c_str());
1138 void SBTarget::DeleteBreakpointName(const char *name)
1140 TargetSP target_sp(GetSP());
1142 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1143 target_sp->DeleteBreakpointName(ConstString(name));
1147 bool SBTarget::EnableAllBreakpoints() {
1148 TargetSP target_sp(GetSP());
1150 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1151 target_sp->EnableAllowedBreakpoints();
1157 bool SBTarget::DisableAllBreakpoints() {
1158 TargetSP target_sp(GetSP());
1160 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1161 target_sp->DisableAllowedBreakpoints();
1167 bool SBTarget::DeleteAllBreakpoints() {
1168 TargetSP target_sp(GetSP());
1170 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1171 target_sp->RemoveAllowedBreakpoints();
1177 lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
1178 SBBreakpointList &new_bps) {
1179 SBStringList empty_name_list;
1180 return BreakpointsCreateFromFile(source_file, empty_name_list, new_bps);
1183 lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
1184 SBStringList &matching_names,
1185 SBBreakpointList &new_bps) {
1187 TargetSP target_sp(GetSP());
1189 sberr.SetErrorString(
1190 "BreakpointCreateFromFile called with invalid target.");
1193 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1195 BreakpointIDList bp_ids;
1197 std::vector<std::string> name_vector;
1198 size_t num_names = matching_names.GetSize();
1199 for (size_t i = 0; i < num_names; i++)
1200 name_vector.push_back(matching_names.GetStringAtIndex(i));
1202 sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(),
1203 name_vector, bp_ids);
1207 size_t num_bkpts = bp_ids.GetSize();
1208 for (size_t i = 0; i < num_bkpts; i++) {
1209 BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
1210 new_bps.AppendByID(bp_id.GetBreakpointID());
1215 lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file) {
1217 TargetSP target_sp(GetSP());
1219 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1222 SBBreakpointList bkpt_list(*this);
1223 return BreakpointsWriteToFile(dest_file, bkpt_list);
1226 lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file,
1227 SBBreakpointList &bkpt_list,
1230 TargetSP target_sp(GetSP());
1232 sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1236 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1237 BreakpointIDList bp_id_list;
1238 bkpt_list.CopyToBreakpointIDList(bp_id_list);
1239 sberr.ref() = target_sp->SerializeBreakpointsToFile(dest_file.ref(),
1240 bp_id_list, append);
1244 uint32_t SBTarget::GetNumWatchpoints() const {
1245 TargetSP target_sp(GetSP());
1247 // The watchpoint list is thread safe, no need to lock
1248 return target_sp->GetWatchpointList().GetSize();
1253 SBWatchpoint SBTarget::GetWatchpointAtIndex(uint32_t idx) const {
1254 SBWatchpoint sb_watchpoint;
1255 TargetSP target_sp(GetSP());
1257 // The watchpoint list is thread safe, no need to lock
1258 sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1260 return sb_watchpoint;
1263 bool SBTarget::DeleteWatchpoint(watch_id_t wp_id) {
1264 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1266 bool result = false;
1267 TargetSP target_sp(GetSP());
1269 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1270 std::unique_lock<std::recursive_mutex> lock;
1271 target_sp->GetWatchpointList().GetListMutex(lock);
1272 result = target_sp->RemoveWatchpointByID(wp_id);
1276 log->Printf("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
1277 static_cast<void *>(target_sp.get()),
1278 static_cast<uint32_t>(wp_id), result);
1283 SBWatchpoint SBTarget::FindWatchpointByID(lldb::watch_id_t wp_id) {
1284 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1286 SBWatchpoint sb_watchpoint;
1287 lldb::WatchpointSP watchpoint_sp;
1288 TargetSP target_sp(GetSP());
1289 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) {
1290 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1291 std::unique_lock<std::recursive_mutex> lock;
1292 target_sp->GetWatchpointList().GetListMutex(lock);
1293 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1294 sb_watchpoint.SetSP(watchpoint_sp);
1299 "SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1300 static_cast<void *>(target_sp.get()), static_cast<uint32_t>(wp_id),
1301 static_cast<void *>(watchpoint_sp.get()));
1303 return sb_watchpoint;
1306 lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size,
1307 bool read, bool write,
1309 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1311 SBWatchpoint sb_watchpoint;
1312 lldb::WatchpointSP watchpoint_sp;
1313 TargetSP target_sp(GetSP());
1314 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS &&
1316 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1317 uint32_t watch_type = 0;
1319 watch_type |= LLDB_WATCH_TYPE_READ;
1321 watch_type |= LLDB_WATCH_TYPE_WRITE;
1322 if (watch_type == 0) {
1323 error.SetErrorString(
1324 "Can't create a watchpoint that is neither read nor write.");
1325 return sb_watchpoint;
1328 // Target::CreateWatchpoint() is thread safe.
1330 // This API doesn't take in a type, so we can't figure out what it is.
1331 CompilerType *type = NULL;
1333 target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1334 error.SetError(cw_error);
1335 sb_watchpoint.SetSP(watchpoint_sp);
1339 log->Printf("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64
1340 ", 0x%u) => SBWatchpoint(%p)",
1341 static_cast<void *>(target_sp.get()), addr,
1342 static_cast<uint32_t>(size),
1343 static_cast<void *>(watchpoint_sp.get()));
1345 return sb_watchpoint;
1348 bool SBTarget::EnableAllWatchpoints() {
1349 TargetSP target_sp(GetSP());
1351 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1352 std::unique_lock<std::recursive_mutex> lock;
1353 target_sp->GetWatchpointList().GetListMutex(lock);
1354 target_sp->EnableAllWatchpoints();
1360 bool SBTarget::DisableAllWatchpoints() {
1361 TargetSP target_sp(GetSP());
1363 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1364 std::unique_lock<std::recursive_mutex> lock;
1365 target_sp->GetWatchpointList().GetListMutex(lock);
1366 target_sp->DisableAllWatchpoints();
1372 SBValue SBTarget::CreateValueFromAddress(const char *name, SBAddress addr,
1375 lldb::ValueObjectSP new_value_sp;
1376 if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) {
1377 lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1378 ExecutionContext exe_ctx(
1379 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1380 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1381 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr,
1384 sb_value.SetSP(new_value_sp);
1385 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1388 log->Printf("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
1389 static_cast<void *>(m_opaque_sp.get()),
1390 new_value_sp->GetName().AsCString());
1392 log->Printf("SBTarget(%p)::CreateValueFromAddress => NULL",
1393 static_cast<void *>(m_opaque_sp.get()));
1398 lldb::SBValue SBTarget::CreateValueFromData(const char *name, lldb::SBData data,
1399 lldb::SBType type) {
1401 lldb::ValueObjectSP new_value_sp;
1402 if (IsValid() && name && *name && data.IsValid() && type.IsValid()) {
1403 DataExtractorSP extractor(*data);
1404 ExecutionContext exe_ctx(
1405 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1406 CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1407 new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor,
1410 sb_value.SetSP(new_value_sp);
1411 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1414 log->Printf("SBTarget(%p)::CreateValueFromData => \"%s\"",
1415 static_cast<void *>(m_opaque_sp.get()),
1416 new_value_sp->GetName().AsCString());
1418 log->Printf("SBTarget(%p)::CreateValueFromData => NULL",
1419 static_cast<void *>(m_opaque_sp.get()));
1424 lldb::SBValue SBTarget::CreateValueFromExpression(const char *name,
1427 lldb::ValueObjectSP new_value_sp;
1428 if (IsValid() && name && *name && expr && *expr) {
1429 ExecutionContext exe_ctx(
1430 ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1432 ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
1434 sb_value.SetSP(new_value_sp);
1435 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1438 log->Printf("SBTarget(%p)::CreateValueFromExpression => \"%s\"",
1439 static_cast<void *>(m_opaque_sp.get()),
1440 new_value_sp->GetName().AsCString());
1442 log->Printf("SBTarget(%p)::CreateValueFromExpression => NULL",
1443 static_cast<void *>(m_opaque_sp.get()));
1448 bool SBTarget::DeleteAllWatchpoints() {
1449 TargetSP target_sp(GetSP());
1451 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1452 std::unique_lock<std::recursive_mutex> lock;
1453 target_sp->GetWatchpointList().GetListMutex(lock);
1454 target_sp->RemoveAllWatchpoints();
1460 lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1461 const char *uuid_cstr) {
1462 return AddModule(path, triple, uuid_cstr, NULL);
1465 lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1466 const char *uuid_cstr, const char *symfile) {
1467 lldb::SBModule sb_module;
1468 TargetSP target_sp(GetSP());
1470 ModuleSpec module_spec;
1472 module_spec.GetFileSpec().SetFile(path, false, FileSpec::Style::native);
1475 module_spec.GetUUID().SetFromStringRef(uuid_cstr);
1478 module_spec.GetArchitecture() = Platform::GetAugmentedArchSpec(
1479 target_sp->GetPlatform().get(), triple);
1481 module_spec.GetArchitecture() = target_sp->GetArchitecture();
1484 module_spec.GetSymbolFileSpec().SetFile(symfile, false,
1485 FileSpec::Style::native);
1487 sb_module.SetSP(target_sp->GetSharedModule(module_spec));
1492 lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) {
1493 lldb::SBModule sb_module;
1494 TargetSP target_sp(GetSP());
1496 sb_module.SetSP(target_sp->GetSharedModule(*module_spec.m_opaque_ap));
1500 bool SBTarget::AddModule(lldb::SBModule &module) {
1501 TargetSP target_sp(GetSP());
1503 target_sp->GetImages().AppendIfNeeded(module.GetSP());
1509 uint32_t SBTarget::GetNumModules() const {
1510 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1513 TargetSP target_sp(GetSP());
1515 // The module list is thread safe, no need to lock
1516 num = target_sp->GetImages().GetSize();
1520 log->Printf("SBTarget(%p)::GetNumModules () => %d",
1521 static_cast<void *>(target_sp.get()), num);
1526 void SBTarget::Clear() {
1527 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1530 log->Printf("SBTarget(%p)::Clear ()",
1531 static_cast<void *>(m_opaque_sp.get()));
1533 m_opaque_sp.reset();
1536 SBModule SBTarget::FindModule(const SBFileSpec &sb_file_spec) {
1538 TargetSP target_sp(GetSP());
1539 if (target_sp && sb_file_spec.IsValid()) {
1540 ModuleSpec module_spec(*sb_file_spec);
1541 // The module list is thread safe, no need to lock
1542 sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1548 SBTarget::FindCompileUnits(const SBFileSpec &sb_file_spec) {
1549 SBSymbolContextList sb_sc_list;
1550 const TargetSP target_sp(GetSP());
1551 if (target_sp && sb_file_spec.IsValid()) {
1552 const bool append = true;
1553 target_sp->GetImages().FindCompileUnits(*sb_file_spec,
1554 append, *sb_sc_list);
1559 lldb::ByteOrder SBTarget::GetByteOrder() {
1560 TargetSP target_sp(GetSP());
1562 return target_sp->GetArchitecture().GetByteOrder();
1563 return eByteOrderInvalid;
1566 const char *SBTarget::GetTriple() {
1567 TargetSP target_sp(GetSP());
1569 std::string triple(target_sp->GetArchitecture().GetTriple().str());
1570 // Unique the string so we don't run into ownership issues since the const
1571 // strings put the string into the string pool once and the strings never
1573 ConstString const_triple(triple.c_str());
1574 return const_triple.GetCString();
1579 uint32_t SBTarget::GetDataByteSize() {
1580 TargetSP target_sp(GetSP());
1582 return target_sp->GetArchitecture().GetDataByteSize();
1587 uint32_t SBTarget::GetCodeByteSize() {
1588 TargetSP target_sp(GetSP());
1590 return target_sp->GetArchitecture().GetCodeByteSize();
1595 uint32_t SBTarget::GetAddressByteSize() {
1596 TargetSP target_sp(GetSP());
1598 return target_sp->GetArchitecture().GetAddressByteSize();
1599 return sizeof(void *);
1602 SBModule SBTarget::GetModuleAtIndex(uint32_t idx) {
1603 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1607 TargetSP target_sp(GetSP());
1609 // The module list is thread safe, no need to lock
1610 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1611 sb_module.SetSP(module_sp);
1615 log->Printf("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
1616 static_cast<void *>(target_sp.get()), idx,
1617 static_cast<void *>(module_sp.get()));
1622 bool SBTarget::RemoveModule(lldb::SBModule module) {
1623 TargetSP target_sp(GetSP());
1625 return target_sp->GetImages().Remove(module.GetSP());
1629 SBBroadcaster SBTarget::GetBroadcaster() const {
1630 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1632 TargetSP target_sp(GetSP());
1633 SBBroadcaster broadcaster(target_sp.get(), false);
1636 log->Printf("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
1637 static_cast<void *>(target_sp.get()),
1638 static_cast<void *>(broadcaster.get()));
1643 bool SBTarget::GetDescription(SBStream &description,
1644 lldb::DescriptionLevel description_level) {
1645 Stream &strm = description.ref();
1647 TargetSP target_sp(GetSP());
1649 target_sp->Dump(&strm, description_level);
1651 strm.PutCString("No value");
1656 lldb::SBSymbolContextList SBTarget::FindFunctions(const char *name,
1657 uint32_t name_type_mask) {
1658 lldb::SBSymbolContextList sb_sc_list;
1659 if (name && name[0]) {
1660 TargetSP target_sp(GetSP());
1662 const bool symbols_ok = true;
1663 const bool inlines_ok = true;
1664 const bool append = true;
1665 target_sp->GetImages().FindFunctions(ConstString(name), name_type_mask,
1666 symbols_ok, inlines_ok, append,
1673 lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name,
1674 uint32_t max_matches,
1675 MatchType matchtype) {
1676 lldb::SBSymbolContextList sb_sc_list;
1677 if (name && name[0]) {
1678 llvm::StringRef name_ref(name);
1679 TargetSP target_sp(GetSP());
1681 std::string regexstr;
1682 switch (matchtype) {
1683 case eMatchTypeRegex:
1684 target_sp->GetImages().FindFunctions(RegularExpression(name_ref), true,
1685 true, true, *sb_sc_list);
1687 case eMatchTypeStartsWith:
1688 regexstr = llvm::Regex::escape(name) + ".*";
1689 target_sp->GetImages().FindFunctions(RegularExpression(regexstr), true,
1690 true, true, *sb_sc_list);
1693 target_sp->GetImages().FindFunctions(ConstString(name),
1694 eFunctionNameTypeAny, true, true,
1703 lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
1704 TargetSP target_sp(GetSP());
1705 if (typename_cstr && typename_cstr[0] && target_sp) {
1706 ConstString const_typename(typename_cstr);
1708 const bool exact_match = false;
1710 const ModuleList &module_list = target_sp->GetImages();
1711 size_t count = module_list.GetSize();
1712 for (size_t idx = 0; idx < count; idx++) {
1713 ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
1716 module_sp->FindFirstType(sc, const_typename, exact_match));
1718 return SBType(type_sp);
1722 // Didn't find the type in the symbols; try the Objective-C runtime if one
1725 ProcessSP process_sp(target_sp->GetProcessSP());
1728 ObjCLanguageRuntime *objc_language_runtime =
1729 process_sp->GetObjCLanguageRuntime();
1731 if (objc_language_runtime) {
1732 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
1734 if (objc_decl_vendor) {
1735 std::vector<clang::NamedDecl *> decls;
1737 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) {
1738 if (CompilerType type = ClangASTContext::GetTypeForDecl(decls[0])) {
1739 return SBType(type);
1746 // No matches, search for basic typename matches
1747 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1749 return SBType(ClangASTContext::GetBasicType(clang_ast->getASTContext(),
1755 SBType SBTarget::GetBasicType(lldb::BasicType type) {
1756 TargetSP target_sp(GetSP());
1758 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1761 ClangASTContext::GetBasicType(clang_ast->getASTContext(), type));
1766 lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
1767 SBTypeList sb_type_list;
1768 TargetSP target_sp(GetSP());
1769 if (typename_cstr && typename_cstr[0] && target_sp) {
1770 ModuleList &images = target_sp->GetImages();
1771 ConstString const_typename(typename_cstr);
1772 bool exact_match = false;
1775 llvm::DenseSet<SymbolFile *> searched_symbol_files;
1776 uint32_t num_matches =
1777 images.FindTypes(sc, const_typename, exact_match, UINT32_MAX,
1778 searched_symbol_files, type_list);
1780 if (num_matches > 0) {
1781 for (size_t idx = 0; idx < num_matches; idx++) {
1782 TypeSP type_sp(type_list.GetTypeAtIndex(idx));
1784 sb_type_list.Append(SBType(type_sp));
1788 // Try the Objective-C runtime if one is installed
1790 ProcessSP process_sp(target_sp->GetProcessSP());
1793 ObjCLanguageRuntime *objc_language_runtime =
1794 process_sp->GetObjCLanguageRuntime();
1796 if (objc_language_runtime) {
1797 DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
1799 if (objc_decl_vendor) {
1800 std::vector<clang::NamedDecl *> decls;
1802 if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) {
1803 for (clang::NamedDecl *decl : decls) {
1804 if (CompilerType type = ClangASTContext::GetTypeForDecl(decl)) {
1805 sb_type_list.Append(SBType(type));
1813 if (sb_type_list.GetSize() == 0) {
1814 // No matches, search for basic typename matches
1815 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1817 sb_type_list.Append(SBType(ClangASTContext::GetBasicType(
1818 clang_ast->getASTContext(), const_typename)));
1821 return sb_type_list;
1824 SBValueList SBTarget::FindGlobalVariables(const char *name,
1825 uint32_t max_matches) {
1826 SBValueList sb_value_list;
1828 TargetSP target_sp(GetSP());
1829 if (name && target_sp) {
1830 VariableList variable_list;
1831 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables(
1832 ConstString(name), max_matches, variable_list);
1834 if (match_count > 0) {
1835 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1836 if (exe_scope == NULL)
1837 exe_scope = target_sp.get();
1838 for (uint32_t i = 0; i < match_count; ++i) {
1839 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(
1840 exe_scope, variable_list.GetVariableAtIndex(i)));
1842 sb_value_list.Append(SBValue(valobj_sp));
1847 return sb_value_list;
1850 SBValueList SBTarget::FindGlobalVariables(const char *name,
1851 uint32_t max_matches,
1852 MatchType matchtype) {
1853 SBValueList sb_value_list;
1855 TargetSP target_sp(GetSP());
1856 if (name && target_sp) {
1857 llvm::StringRef name_ref(name);
1858 VariableList variable_list;
1860 std::string regexstr;
1861 uint32_t match_count;
1862 switch (matchtype) {
1863 case eMatchTypeNormal:
1864 match_count = target_sp->GetImages().FindGlobalVariables(
1865 ConstString(name), max_matches, variable_list);
1867 case eMatchTypeRegex:
1868 match_count = target_sp->GetImages().FindGlobalVariables(
1869 RegularExpression(name_ref), max_matches, variable_list);
1871 case eMatchTypeStartsWith:
1872 regexstr = llvm::Regex::escape(name) + ".*";
1873 match_count = target_sp->GetImages().FindGlobalVariables(
1874 RegularExpression(regexstr), max_matches, variable_list);
1878 if (match_count > 0) {
1879 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1880 if (exe_scope == NULL)
1881 exe_scope = target_sp.get();
1882 for (uint32_t i = 0; i < match_count; ++i) {
1883 lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(
1884 exe_scope, variable_list.GetVariableAtIndex(i)));
1886 sb_value_list.Append(SBValue(valobj_sp));
1891 return sb_value_list;
1894 lldb::SBValue SBTarget::FindFirstGlobalVariable(const char *name) {
1895 SBValueList sb_value_list(FindGlobalVariables(name, 1));
1896 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
1897 return sb_value_list.GetValueAtIndex(0);
1901 SBSourceManager SBTarget::GetSourceManager() {
1902 SBSourceManager source_manager(*this);
1903 return source_manager;
1906 lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
1908 return ReadInstructions(base_addr, count, NULL);
1911 lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
1913 const char *flavor_string) {
1914 SBInstructionList sb_instructions;
1916 TargetSP target_sp(GetSP());
1918 Address *addr_ptr = base_addr.get();
1921 DataBufferHeap data(
1922 target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
1923 bool prefer_file_cache = false;
1924 lldb_private::Status error;
1925 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
1926 const size_t bytes_read =
1927 target_sp->ReadMemory(*addr_ptr, prefer_file_cache, data.GetBytes(),
1928 data.GetByteSize(), error, &load_addr);
1929 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
1930 sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
1931 target_sp->GetArchitecture(), NULL, flavor_string, *addr_ptr,
1932 data.GetBytes(), bytes_read, count, data_from_file));
1936 return sb_instructions;
1939 lldb::SBInstructionList SBTarget::GetInstructions(lldb::SBAddress base_addr,
1942 return GetInstructionsWithFlavor(base_addr, NULL, buf, size);
1945 lldb::SBInstructionList
1946 SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
1947 const char *flavor_string, const void *buf,
1949 SBInstructionList sb_instructions;
1951 TargetSP target_sp(GetSP());
1955 if (base_addr.get())
1956 addr = *base_addr.get();
1958 const bool data_from_file = true;
1960 sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
1961 target_sp->GetArchitecture(), NULL, flavor_string, addr, buf, size,
1962 UINT32_MAX, data_from_file));
1965 return sb_instructions;
1968 lldb::SBInstructionList SBTarget::GetInstructions(lldb::addr_t base_addr,
1971 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), NULL, buf,
1975 lldb::SBInstructionList
1976 SBTarget::GetInstructionsWithFlavor(lldb::addr_t base_addr,
1977 const char *flavor_string, const void *buf,
1979 return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string,
1983 SBError SBTarget::SetSectionLoadAddress(lldb::SBSection section,
1984 lldb::addr_t section_base_addr) {
1986 TargetSP target_sp(GetSP());
1988 if (!section.IsValid()) {
1989 sb_error.SetErrorStringWithFormat("invalid section");
1991 SectionSP section_sp(section.GetSP());
1993 if (section_sp->IsThreadSpecific()) {
1994 sb_error.SetErrorString(
1995 "thread specific sections are not yet supported");
1997 ProcessSP process_sp(target_sp->GetProcessSP());
1998 if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
1999 ModuleSP module_sp(section_sp->GetModule());
2001 ModuleList module_list;
2002 module_list.Append(module_sp);
2003 target_sp->ModulesDidLoad(module_list);
2005 // Flush info in the process (stack frames, etc)
2007 process_sp->Flush();
2013 sb_error.SetErrorString("invalid target");
2018 SBError SBTarget::ClearSectionLoadAddress(lldb::SBSection section) {
2021 TargetSP target_sp(GetSP());
2023 if (!section.IsValid()) {
2024 sb_error.SetErrorStringWithFormat("invalid section");
2026 SectionSP section_sp(section.GetSP());
2028 ProcessSP process_sp(target_sp->GetProcessSP());
2029 if (target_sp->SetSectionUnloaded(section_sp)) {
2030 ModuleSP module_sp(section_sp->GetModule());
2032 ModuleList module_list;
2033 module_list.Append(module_sp);
2034 target_sp->ModulesDidUnload(module_list, false);
2036 // Flush info in the process (stack frames, etc)
2038 process_sp->Flush();
2041 sb_error.SetErrorStringWithFormat("invalid section");
2045 sb_error.SetErrorStringWithFormat("invalid target");
2050 SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
2051 int64_t slide_offset) {
2054 TargetSP target_sp(GetSP());
2056 ModuleSP module_sp(module.GetSP());
2058 bool changed = false;
2059 if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) {
2060 // The load was successful, make sure that at least some sections
2061 // changed before we notify that our module was loaded.
2063 ModuleList module_list;
2064 module_list.Append(module_sp);
2065 target_sp->ModulesDidLoad(module_list);
2066 // Flush info in the process (stack frames, etc)
2067 ProcessSP process_sp(target_sp->GetProcessSP());
2069 process_sp->Flush();
2073 sb_error.SetErrorStringWithFormat("invalid module");
2077 sb_error.SetErrorStringWithFormat("invalid target");
2082 SBError SBTarget::ClearModuleLoadAddress(lldb::SBModule module) {
2085 char path[PATH_MAX];
2086 TargetSP target_sp(GetSP());
2088 ModuleSP module_sp(module.GetSP());
2090 ObjectFile *objfile = module_sp->GetObjectFile();
2092 SectionList *section_list = objfile->GetSectionList();
2094 ProcessSP process_sp(target_sp->GetProcessSP());
2096 bool changed = false;
2097 const size_t num_sections = section_list->GetSize();
2098 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
2099 SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
2101 changed |= target_sp->SetSectionUnloaded(section_sp);
2104 ModuleList module_list;
2105 module_list.Append(module_sp);
2106 target_sp->ModulesDidUnload(module_list, false);
2107 // Flush info in the process (stack frames, etc)
2108 ProcessSP process_sp(target_sp->GetProcessSP());
2110 process_sp->Flush();
2113 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2114 sb_error.SetErrorStringWithFormat("no sections in object file '%s'",
2118 module_sp->GetFileSpec().GetPath(path, sizeof(path));
2119 sb_error.SetErrorStringWithFormat("no object file for module '%s'",
2123 sb_error.SetErrorStringWithFormat("invalid module");
2126 sb_error.SetErrorStringWithFormat("invalid target");
2131 lldb::SBSymbolContextList SBTarget::FindSymbols(const char *name,
2132 lldb::SymbolType symbol_type) {
2133 SBSymbolContextList sb_sc_list;
2134 if (name && name[0]) {
2135 TargetSP target_sp(GetSP());
2138 target_sp->GetImages().FindSymbolsWithNameAndType(
2139 ConstString(name), symbol_type, *sb_sc_list, append);
2145 lldb::SBValue SBTarget::EvaluateExpression(const char *expr) {
2146 TargetSP target_sp(GetSP());
2150 SBExpressionOptions options;
2151 lldb::DynamicValueType fetch_dynamic_value =
2152 target_sp->GetPreferDynamicValue();
2153 options.SetFetchDynamicValue(fetch_dynamic_value);
2154 options.SetUnwindOnError(true);
2155 return EvaluateExpression(expr, options);
2158 lldb::SBValue SBTarget::EvaluateExpression(const char *expr,
2159 const SBExpressionOptions &options) {
2160 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
2161 #if !defined(LLDB_DISABLE_PYTHON)
2162 Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
2164 SBValue expr_result;
2165 ExpressionResults exe_results = eExpressionSetupError;
2166 ValueObjectSP expr_value_sp;
2167 TargetSP target_sp(GetSP());
2168 StackFrame *frame = NULL;
2170 if (expr == NULL || expr[0] == '\0') {
2173 "SBTarget::EvaluateExpression called with an empty expression");
2177 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2178 ExecutionContext exe_ctx(m_opaque_sp.get());
2181 log->Printf("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
2183 frame = exe_ctx.GetFramePtr();
2184 Target *target = exe_ctx.GetTargetPtr();
2187 #ifdef LLDB_CONFIGURATION_DEBUG
2188 StreamString frame_description;
2190 frame->DumpUsingSettingsFormat(&frame_description);
2191 llvm::PrettyStackTraceFormat stack_trace(
2192 "SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = "
2194 expr, options.GetFetchDynamicValue(),
2195 frame_description.GetString().str().c_str());
2198 target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2200 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2203 log->Printf("SBTarget::EvaluateExpression () => error: could not "
2204 "reconstruct frame object for this SBTarget.");
2207 #ifndef LLDB_DISABLE_PYTHON
2209 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is "
2210 "%s, summary %s **",
2211 expr_result.GetValue(), expr_result.GetSummary());
2214 log->Printf("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) "
2215 "(execution result=%d)",
2216 static_cast<void *>(frame), expr,
2217 static_cast<void *>(expr_value_sp.get()), exe_results);
2223 lldb::addr_t SBTarget::GetStackRedZoneSize() {
2224 TargetSP target_sp(GetSP());
2227 ProcessSP process_sp(target_sp->GetProcessSP());
2229 abi_sp = process_sp->GetABI();
2231 abi_sp = ABI::FindPlugin(ProcessSP(), target_sp->GetArchitecture());
2233 return abi_sp->GetRedZoneSize();
2238 lldb::SBLaunchInfo SBTarget::GetLaunchInfo() const {
2239 lldb::SBLaunchInfo launch_info(NULL);
2240 TargetSP target_sp(GetSP());
2242 launch_info.set_ref(m_opaque_sp->GetProcessLaunchInfo());
2246 void SBTarget::SetLaunchInfo(const lldb::SBLaunchInfo &launch_info) {
2247 TargetSP target_sp(GetSP());
2249 m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());