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/lldb-python.h"
12 #include "lldb/API/SBTarget.h"
14 #include "lldb/lldb-public.h"
16 #include "lldb/API/SBDebugger.h"
17 #include "lldb/API/SBBreakpoint.h"
18 #include "lldb/API/SBExpressionOptions.h"
19 #include "lldb/API/SBFileSpec.h"
20 #include "lldb/API/SBListener.h"
21 #include "lldb/API/SBModule.h"
22 #include "lldb/API/SBModuleSpec.h"
23 #include "lldb/API/SBSourceManager.h"
24 #include "lldb/API/SBProcess.h"
25 #include "lldb/API/SBStream.h"
26 #include "lldb/API/SBSymbolContextList.h"
27 #include "lldb/Breakpoint/BreakpointID.h"
28 #include "lldb/Breakpoint/BreakpointIDList.h"
29 #include "lldb/Breakpoint/BreakpointList.h"
30 #include "lldb/Breakpoint/BreakpointLocation.h"
31 #include "lldb/Core/Address.h"
32 #include "lldb/Core/AddressResolver.h"
33 #include "lldb/Core/AddressResolverName.h"
34 #include "lldb/Core/ArchSpec.h"
35 #include "lldb/Core/Debugger.h"
36 #include "lldb/Core/Disassembler.h"
37 #include "lldb/Core/Log.h"
38 #include "lldb/Core/Module.h"
39 #include "lldb/Core/ModuleSpec.h"
40 #include "lldb/Core/RegularExpression.h"
41 #include "lldb/Core/SearchFilter.h"
42 #include "lldb/Core/Section.h"
43 #include "lldb/Core/STLUtils.h"
44 #include "lldb/Core/ValueObjectConstResult.h"
45 #include "lldb/Core/ValueObjectList.h"
46 #include "lldb/Core/ValueObjectVariable.h"
47 #include "lldb/Host/FileSpec.h"
48 #include "lldb/Host/Host.h"
49 #include "lldb/Interpreter/Args.h"
50 #include "lldb/Symbol/ObjectFile.h"
51 #include "lldb/Symbol/SymbolVendor.h"
52 #include "lldb/Symbol/VariableList.h"
53 #include "lldb/Target/LanguageRuntime.h"
54 #include "lldb/Target/Process.h"
56 #include "lldb/Target/Target.h"
57 #include "lldb/Target/TargetList.h"
59 #include "lldb/Interpreter/CommandReturnObject.h"
60 #include "../source/Commands/CommandObjectBreakpoint.h"
64 using namespace lldb_private;
66 #define DEFAULT_DISASM_BYTE_SIZE 32
68 SBLaunchInfo::SBLaunchInfo (const char **argv) :
69 m_opaque_sp(new ProcessLaunchInfo())
71 m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
73 m_opaque_sp->GetArguments().SetArguments(argv);
76 SBLaunchInfo::~SBLaunchInfo()
80 lldb_private::ProcessLaunchInfo &
88 SBLaunchInfo::GetUserID()
90 return m_opaque_sp->GetUserID();
94 SBLaunchInfo::GetGroupID()
96 return m_opaque_sp->GetGroupID();
100 SBLaunchInfo::UserIDIsValid ()
102 return m_opaque_sp->UserIDIsValid();
106 SBLaunchInfo::GroupIDIsValid ()
108 return m_opaque_sp->GroupIDIsValid();
112 SBLaunchInfo::SetUserID (uint32_t uid)
114 m_opaque_sp->SetUserID (uid);
118 SBLaunchInfo::SetGroupID (uint32_t gid)
120 m_opaque_sp->SetGroupID (gid);
124 SBLaunchInfo::GetNumArguments ()
126 return m_opaque_sp->GetArguments().GetArgumentCount();
130 SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
132 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
136 SBLaunchInfo::SetArguments (const char **argv, bool append)
141 m_opaque_sp->GetArguments().AppendArguments(argv);
146 m_opaque_sp->GetArguments().SetArguments(argv);
148 m_opaque_sp->GetArguments().Clear();
153 SBLaunchInfo::GetNumEnvironmentEntries ()
155 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
159 SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
161 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
165 SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
170 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
175 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
177 m_opaque_sp->GetEnvironmentEntries().Clear();
182 SBLaunchInfo::Clear ()
184 m_opaque_sp->Clear();
188 SBLaunchInfo::GetWorkingDirectory () const
190 return m_opaque_sp->GetWorkingDirectory();
194 SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
196 m_opaque_sp->SetWorkingDirectory(working_dir);
200 SBLaunchInfo::GetLaunchFlags ()
202 return m_opaque_sp->GetFlags().Get();
206 SBLaunchInfo::SetLaunchFlags (uint32_t flags)
208 m_opaque_sp->GetFlags().Reset(flags);
212 SBLaunchInfo::GetProcessPluginName ()
214 return m_opaque_sp->GetProcessPluginName();
218 SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
220 return m_opaque_sp->SetProcessPluginName (plugin_name);
224 SBLaunchInfo::GetShell ()
226 return m_opaque_sp->GetShell();
230 SBLaunchInfo::SetShell (const char * path)
232 m_opaque_sp->SetShell (path);
236 SBLaunchInfo::GetResumeCount ()
238 return m_opaque_sp->GetResumeCount();
242 SBLaunchInfo::SetResumeCount (uint32_t c)
244 m_opaque_sp->SetResumeCount (c);
248 SBLaunchInfo::AddCloseFileAction (int fd)
250 return m_opaque_sp->AppendCloseFileAction(fd);
254 SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
256 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
260 SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
262 return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
266 SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
268 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
272 SBAttachInfo::SBAttachInfo () :
273 m_opaque_sp (new ProcessAttachInfo())
277 SBAttachInfo::SBAttachInfo (lldb::pid_t pid) :
278 m_opaque_sp (new ProcessAttachInfo())
280 m_opaque_sp->SetProcessID (pid);
283 SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) :
284 m_opaque_sp (new ProcessAttachInfo())
287 m_opaque_sp->GetExecutableFile().SetFile(path, false);
288 m_opaque_sp->SetWaitForLaunch (wait_for);
291 SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
292 m_opaque_sp (new ProcessAttachInfo())
294 *m_opaque_sp = *rhs.m_opaque_sp;
297 SBAttachInfo::~SBAttachInfo()
301 lldb_private::ProcessAttachInfo &
308 SBAttachInfo::operator = (const SBAttachInfo &rhs)
311 *m_opaque_sp = *rhs.m_opaque_sp;
316 SBAttachInfo::GetProcessID ()
318 return m_opaque_sp->GetProcessID();
322 SBAttachInfo::SetProcessID (lldb::pid_t pid)
324 m_opaque_sp->SetProcessID (pid);
329 SBAttachInfo::GetResumeCount ()
331 return m_opaque_sp->GetResumeCount();
335 SBAttachInfo::SetResumeCount (uint32_t c)
337 m_opaque_sp->SetResumeCount (c);
341 SBAttachInfo::GetProcessPluginName ()
343 return m_opaque_sp->GetProcessPluginName();
347 SBAttachInfo::SetProcessPluginName (const char *plugin_name)
349 return m_opaque_sp->SetProcessPluginName (plugin_name);
353 SBAttachInfo::SetExecutable (const char *path)
356 m_opaque_sp->GetExecutableFile().SetFile(path, false);
358 m_opaque_sp->GetExecutableFile().Clear();
362 SBAttachInfo::SetExecutable (SBFileSpec exe_file)
364 if (exe_file.IsValid())
365 m_opaque_sp->GetExecutableFile() = exe_file.ref();
367 m_opaque_sp->GetExecutableFile().Clear();
371 SBAttachInfo::GetWaitForLaunch ()
373 return m_opaque_sp->GetWaitForLaunch();
377 SBAttachInfo::SetWaitForLaunch (bool b)
379 m_opaque_sp->SetWaitForLaunch (b);
383 SBAttachInfo::GetIgnoreExisting ()
385 return m_opaque_sp->GetIgnoreExisting();
389 SBAttachInfo::SetIgnoreExisting (bool b)
391 m_opaque_sp->SetIgnoreExisting (b);
395 SBAttachInfo::GetUserID()
397 return m_opaque_sp->GetUserID();
401 SBAttachInfo::GetGroupID()
403 return m_opaque_sp->GetGroupID();
407 SBAttachInfo::UserIDIsValid ()
409 return m_opaque_sp->UserIDIsValid();
413 SBAttachInfo::GroupIDIsValid ()
415 return m_opaque_sp->GroupIDIsValid();
419 SBAttachInfo::SetUserID (uint32_t uid)
421 m_opaque_sp->SetUserID (uid);
425 SBAttachInfo::SetGroupID (uint32_t gid)
427 m_opaque_sp->SetGroupID (gid);
431 SBAttachInfo::GetEffectiveUserID()
433 return m_opaque_sp->GetEffectiveUserID();
437 SBAttachInfo::GetEffectiveGroupID()
439 return m_opaque_sp->GetEffectiveGroupID();
443 SBAttachInfo::EffectiveUserIDIsValid ()
445 return m_opaque_sp->EffectiveUserIDIsValid();
449 SBAttachInfo::EffectiveGroupIDIsValid ()
451 return m_opaque_sp->EffectiveGroupIDIsValid ();
455 SBAttachInfo::SetEffectiveUserID (uint32_t uid)
457 m_opaque_sp->SetEffectiveUserID(uid);
461 SBAttachInfo::SetEffectiveGroupID (uint32_t gid)
463 m_opaque_sp->SetEffectiveGroupID(gid);
467 SBAttachInfo::GetParentProcessID ()
469 return m_opaque_sp->GetParentProcessID();
473 SBAttachInfo::SetParentProcessID (lldb::pid_t pid)
475 m_opaque_sp->SetParentProcessID (pid);
479 SBAttachInfo::ParentProcessIDIsValid()
481 return m_opaque_sp->ParentProcessIDIsValid();
485 //----------------------------------------------------------------------
486 // SBTarget constructor
487 //----------------------------------------------------------------------
488 SBTarget::SBTarget () :
493 SBTarget::SBTarget (const SBTarget& rhs) :
494 m_opaque_sp (rhs.m_opaque_sp)
498 SBTarget::SBTarget(const TargetSP& target_sp) :
499 m_opaque_sp (target_sp)
504 SBTarget::operator = (const SBTarget& rhs)
507 m_opaque_sp = rhs.m_opaque_sp;
511 //----------------------------------------------------------------------
513 //----------------------------------------------------------------------
514 SBTarget::~SBTarget()
519 SBTarget::GetBroadcasterClassName ()
521 return Target::GetStaticBroadcasterClass().AsCString();
525 SBTarget::IsValid () const
527 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
531 SBTarget::GetProcess ()
533 SBProcess sb_process;
534 ProcessSP process_sp;
535 TargetSP target_sp(GetSP());
538 process_sp = target_sp->GetProcessSP();
539 sb_process.SetSP (process_sp);
542 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
545 log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)",
546 target_sp.get(), process_sp.get());
553 SBTarget::GetDebugger () const
556 TargetSP target_sp(GetSP());
558 debugger.reset (target_sp->GetDebugger().shared_from_this());
563 SBTarget::LoadCore (const char *core_file)
565 SBProcess sb_process;
566 TargetSP target_sp(GetSP());
569 FileSpec filespec(core_file, true);
570 ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(),
575 process_sp->LoadCore();
576 sb_process.SetSP (process_sp);
583 SBTarget::LaunchSimple
587 const char *working_directory
590 char *stdin_path = NULL;
591 char *stdout_path = NULL;
592 char *stderr_path = NULL;
593 uint32_t launch_flags = 0;
594 bool stop_at_entry = false;
596 SBListener listener = GetDebugger().GetListener();
597 return Launch (listener,
613 TargetSP target_sp(GetSP());
616 Mutex::Locker api_locker (target_sp->GetAPIMutex());
617 sb_error.ref() = target_sp->Install(NULL);
625 SBListener &listener,
628 const char *stdin_path,
629 const char *stdout_path,
630 const char *stderr_path,
631 const char *working_directory,
632 uint32_t launch_flags, // See LaunchFlags
637 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
639 SBProcess sb_process;
640 ProcessSP process_sp;
641 TargetSP target_sp(GetSP());
645 log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...",
649 stdin_path ? stdin_path : "NULL",
650 stdout_path ? stdout_path : "NULL",
651 stderr_path ? stderr_path : "NULL",
652 working_directory ? working_directory : "NULL",
660 Mutex::Locker api_locker (target_sp->GetAPIMutex());
662 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
663 launch_flags |= eLaunchFlagDisableASLR;
665 StateType state = eStateInvalid;
666 process_sp = target_sp->GetProcessSP();
669 state = process_sp->GetState();
671 if (process_sp->IsAlive() && state != eStateConnected)
673 if (state == eStateAttaching)
674 error.SetErrorString ("process attach is in progress");
676 error.SetErrorString ("a process is already being debugged");
681 if (state == eStateConnected)
683 // If we are already connected, then we have already specified the
684 // listener, so if a valid listener is supplied, we need to error out
685 // to let the client know.
686 if (listener.IsValid())
688 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
693 if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
694 launch_flags |= eLaunchFlagDisableSTDIO;
696 ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags);
698 Module *exe_module = target_sp->GetExecutableModulePointer();
700 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
702 launch_info.GetArguments().AppendArguments (argv);
704 launch_info.GetEnvironmentEntries ().SetArguments (envp);
706 if (listener.IsValid())
707 error.SetError (target_sp->Launch(listener.ref(), launch_info));
709 error.SetError (target_sp->Launch(target_sp->GetDebugger().GetListener(), launch_info));
711 sb_process.SetSP(target_sp->GetProcessSP());
715 error.SetErrorString ("SBTarget is invalid");
718 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
721 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
722 target_sp.get(), sb_process.GetSP().get());
729 SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error)
731 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
733 SBProcess sb_process;
734 TargetSP target_sp(GetSP());
738 log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get());
743 Mutex::Locker api_locker (target_sp->GetAPIMutex());
744 StateType state = eStateInvalid;
746 ProcessSP process_sp = target_sp->GetProcessSP();
749 state = process_sp->GetState();
751 if (process_sp->IsAlive() && state != eStateConnected)
753 if (state == eStateAttaching)
754 error.SetErrorString ("process attach is in progress");
756 error.SetErrorString ("a process is already being debugged");
762 lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref();
764 Module *exe_module = target_sp->GetExecutableModulePointer();
766 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
768 const ArchSpec &arch_spec = target_sp->GetArchitecture();
769 if (arch_spec.IsValid())
770 launch_info.GetArchitecture () = arch_spec;
772 error.SetError (target_sp->Launch (target_sp->GetDebugger().GetListener(), launch_info));
773 sb_process.SetSP(target_sp->GetProcessSP());
777 error.SetErrorString ("SBTarget is invalid");
780 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
783 log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)",
784 target_sp.get(), sb_process.GetSP().get());
791 SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error)
793 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
795 SBProcess sb_process;
796 ProcessSP process_sp;
797 TargetSP target_sp(GetSP());
801 log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...", target_sp.get());
806 Mutex::Locker api_locker (target_sp->GetAPIMutex());
808 StateType state = eStateInvalid;
809 process_sp = target_sp->GetProcessSP();
812 state = process_sp->GetState();
814 if (process_sp->IsAlive() && state != eStateConnected)
816 if (state == eStateAttaching)
817 error.SetErrorString ("process attach is in progress");
819 error.SetErrorString ("a process is already being debugged");
822 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
823 target_sp.get(), error.GetCString());
829 if (state != eStateConnected)
830 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
834 ProcessAttachInfo &attach_info = sb_attach_info.ref();
835 if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid())
837 PlatformSP platform_sp = target_sp->GetPlatform();
838 // See if we can pre-verify if a process exists or not
839 if (platform_sp && platform_sp->IsConnected())
841 lldb::pid_t attach_pid = attach_info.GetProcessID();
842 ProcessInstanceInfo instance_info;
843 if (platform_sp->GetProcessInfo(attach_pid, instance_info))
845 attach_info.SetUserID(instance_info.GetEffectiveUserID());
849 error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid);
852 log->Printf ("SBTarget(%p)::Attach (...) => error %s",
853 target_sp.get(), error.GetCString());
859 error.SetError (process_sp->Attach (attach_info));
862 sb_process.SetSP (process_sp);
863 // If we are doing synchronous mode, then wait for the
865 if (target_sp->GetDebugger().GetAsyncExecution () == false)
866 process_sp->WaitForProcessToStop (NULL);
871 error.SetErrorString ("unable to create lldb_private::Process");
876 error.SetErrorString ("SBTarget is invalid");
881 log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)",
882 target_sp.get(), process_sp.get());
889 #if defined(__APPLE__)
892 SBTarget::AttachToProcessWithID (SBListener &listener,
894 lldb::SBError& error)
896 return AttachToProcessWithID (listener, (lldb::pid_t)pid, error);
899 #endif // #if defined(__APPLE__)
902 SBTarget::AttachToProcessWithID
904 SBListener &listener,
905 lldb::pid_t pid,// The process ID to attach to
906 SBError& error // An error explaining what went wrong if attach fails
909 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
911 SBProcess sb_process;
912 ProcessSP process_sp;
913 TargetSP target_sp(GetSP());
917 log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...", target_sp.get(), pid);
922 Mutex::Locker api_locker (target_sp->GetAPIMutex());
924 StateType state = eStateInvalid;
925 process_sp = target_sp->GetProcessSP();
928 state = process_sp->GetState();
930 if (process_sp->IsAlive() && state != eStateConnected)
932 if (state == eStateAttaching)
933 error.SetErrorString ("process attach is in progress");
935 error.SetErrorString ("a process is already being debugged");
940 if (state == eStateConnected)
942 // If we are already connected, then we have already specified the
943 // listener, so if a valid listener is supplied, we need to error out
944 // to let the client know.
945 if (listener.IsValid())
947 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
953 if (listener.IsValid())
954 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
956 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
960 sb_process.SetSP (process_sp);
962 ProcessAttachInfo attach_info;
963 attach_info.SetProcessID (pid);
965 PlatformSP platform_sp = target_sp->GetPlatform();
966 ProcessInstanceInfo instance_info;
967 if (platform_sp->GetProcessInfo(pid, instance_info))
969 attach_info.SetUserID(instance_info.GetEffectiveUserID());
971 error.SetError (process_sp->Attach (attach_info));
974 // If we are doing synchronous mode, then wait for the
976 if (target_sp->GetDebugger().GetAsyncExecution () == false)
977 process_sp->WaitForProcessToStop (NULL);
982 error.SetErrorString ("unable to create lldb_private::Process");
987 error.SetErrorString ("SBTarget is invalid");
992 log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)",
993 target_sp.get(), process_sp.get());
999 SBTarget::AttachToProcessWithName
1001 SBListener &listener,
1002 const char *name, // basename of process to attach to
1003 bool wait_for, // if true wait for a new instance of "name" to be launched
1004 SBError& error // An error explaining what went wrong if attach fails
1007 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1009 SBProcess sb_process;
1010 ProcessSP process_sp;
1011 TargetSP target_sp(GetSP());
1015 log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...", target_sp.get(), name, wait_for ? "true" : "false");
1018 if (name && target_sp)
1020 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1022 StateType state = eStateInvalid;
1023 process_sp = target_sp->GetProcessSP();
1026 state = process_sp->GetState();
1028 if (process_sp->IsAlive() && state != eStateConnected)
1030 if (state == eStateAttaching)
1031 error.SetErrorString ("process attach is in progress");
1033 error.SetErrorString ("a process is already being debugged");
1038 if (state == eStateConnected)
1040 // If we are already connected, then we have already specified the
1041 // listener, so if a valid listener is supplied, we need to error out
1042 // to let the client know.
1043 if (listener.IsValid())
1045 error.SetErrorString ("process is connected and already has a listener, pass empty listener");
1051 if (listener.IsValid())
1052 process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL);
1054 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL);
1059 sb_process.SetSP (process_sp);
1060 ProcessAttachInfo attach_info;
1061 attach_info.GetExecutableFile().SetFile(name, false);
1062 attach_info.SetWaitForLaunch(wait_for);
1063 error.SetError (process_sp->Attach (attach_info));
1064 if (error.Success())
1066 // If we are doing synchronous mode, then wait for the
1068 if (target_sp->GetDebugger().GetAsyncExecution () == false)
1069 process_sp->WaitForProcessToStop (NULL);
1074 error.SetErrorString ("unable to create lldb_private::Process");
1079 error.SetErrorString ("SBTarget is invalid");
1084 log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)",
1085 target_sp.get(), process_sp.get());
1091 SBTarget::ConnectRemote
1093 SBListener &listener,
1095 const char *plugin_name,
1099 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1101 SBProcess sb_process;
1102 ProcessSP process_sp;
1103 TargetSP target_sp(GetSP());
1107 log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...", target_sp.get(), url, plugin_name);
1112 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1113 if (listener.IsValid())
1114 process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL);
1116 process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL);
1121 sb_process.SetSP (process_sp);
1122 error.SetError (process_sp->ConnectRemote (NULL, url));
1126 error.SetErrorString ("unable to create lldb_private::Process");
1131 error.SetErrorString ("SBTarget is invalid");
1136 log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
1137 target_sp.get(), process_sp.get());
1143 SBTarget::GetExecutable ()
1146 SBFileSpec exe_file_spec;
1147 TargetSP target_sp(GetSP());
1150 Module *exe_module = target_sp->GetExecutableModulePointer();
1152 exe_file_spec.SetFileSpec (exe_module->GetFileSpec());
1155 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1158 log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
1159 target_sp.get(), exe_file_spec.get());
1162 return exe_file_spec;
1166 SBTarget::operator == (const SBTarget &rhs) const
1168 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
1172 SBTarget::operator != (const SBTarget &rhs) const
1174 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
1178 SBTarget::GetSP () const
1184 SBTarget::SetSP (const lldb::TargetSP& target_sp)
1186 m_opaque_sp = target_sp;
1190 SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr)
1192 lldb::SBAddress sb_addr;
1193 Address &addr = sb_addr.ref();
1194 TargetSP target_sp(GetSP());
1197 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1198 if (target_sp->ResolveLoadAddress (vm_addr, addr))
1202 // We have a load address that isn't in a section, just return an address
1203 // with the offset filled in (the address) and the section set to NULL
1204 addr.SetRawAddress(vm_addr);
1210 SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr)
1212 lldb::SBAddress sb_addr;
1213 Address &addr = sb_addr.ref();
1214 TargetSP target_sp(GetSP());
1217 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1218 if (target_sp->ResolveLoadAddress (vm_addr, addr))
1222 // We have a load address that isn't in a section, just return an address
1223 // with the offset filled in (the address) and the section set to NULL
1224 addr.SetRawAddress(vm_addr);
1229 SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr,
1230 uint32_t resolve_scope)
1235 TargetSP target_sp(GetSP());
1237 target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref());
1244 SBTarget::BreakpointCreateByLocation (const char *file,
1247 return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line));
1251 SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec,
1254 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1257 TargetSP target_sp(GetSP());
1258 if (target_sp && line != 0)
1260 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1262 const LazyBool check_inlines = eLazyBoolCalculate;
1263 const LazyBool skip_prologue = eLazyBoolCalculate;
1264 const bool internal = false;
1265 const bool hardware = false;
1266 *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware);
1272 sb_bp.GetDescription (sstr);
1273 char path[PATH_MAX];
1274 sb_file_spec->GetPath (path, sizeof(path));
1275 log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s",
1287 SBTarget::BreakpointCreateByName (const char *symbol_name,
1288 const char *module_name)
1290 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1293 TargetSP target_sp(GetSP());
1294 if (target_sp.get())
1296 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1298 const bool internal = false;
1299 const bool hardware = false;
1300 const LazyBool skip_prologue = eLazyBoolCalculate;
1301 if (module_name && module_name[0])
1303 FileSpecList module_spec_list;
1304 module_spec_list.Append (FileSpec (module_name, false));
1305 *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
1309 *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware);
1315 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)",
1316 target_sp.get(), symbol_name, module_name, sb_bp.get());
1323 SBTarget::BreakpointCreateByName (const char *symbol_name,
1324 const SBFileSpecList &module_list,
1325 const SBFileSpecList &comp_unit_list)
1327 uint32_t name_type_mask = eFunctionNameTypeAuto;
1328 return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list);
1332 SBTarget::BreakpointCreateByName (const char *symbol_name,
1333 uint32_t name_type_mask,
1334 const SBFileSpecList &module_list,
1335 const SBFileSpecList &comp_unit_list)
1337 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1340 TargetSP target_sp(GetSP());
1341 if (target_sp && symbol_name && symbol_name[0])
1343 const bool internal = false;
1344 const bool hardware = false;
1345 const LazyBool skip_prologue = eLazyBoolCalculate;
1346 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1347 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1348 comp_unit_list.get(),
1358 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)",
1359 target_sp.get(), symbol_name, name_type_mask, sb_bp.get());
1366 SBTarget::BreakpointCreateByNames (const char *symbol_names[],
1368 uint32_t name_type_mask,
1369 const SBFileSpecList &module_list,
1370 const SBFileSpecList &comp_unit_list)
1372 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1375 TargetSP target_sp(GetSP());
1376 if (target_sp && num_names > 0)
1378 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1379 const bool internal = false;
1380 const bool hardware = false;
1381 const LazyBool skip_prologue = eLazyBoolCalculate;
1382 *sb_bp = target_sp->CreateBreakpoint (module_list.get(),
1383 comp_unit_list.get(),
1394 log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={", target_sp.get());
1395 for (uint32_t i = 0 ; i < num_names; i++)
1398 if (i < num_names - 1)
1402 if (symbol_names[i] != NULL)
1403 log->Printf ("\"%s\"%c ", symbol_names[i], sep);
1405 log->Printf ("\"<NULL>\"%c ", sep);
1408 log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask, sb_bp.get());
1415 SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1416 const char *module_name)
1418 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1421 TargetSP target_sp(GetSP());
1422 if (target_sp && symbol_name_regex && symbol_name_regex[0])
1424 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1425 RegularExpression regexp(symbol_name_regex);
1426 const bool internal = false;
1427 const bool hardware = false;
1428 const LazyBool skip_prologue = eLazyBoolCalculate;
1430 if (module_name && module_name[0])
1432 FileSpecList module_spec_list;
1433 module_spec_list.Append (FileSpec (module_name, false));
1435 *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware);
1439 *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware);
1445 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1446 target_sp.get(), symbol_name_regex, module_name, sb_bp.get());
1453 SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex,
1454 const SBFileSpecList &module_list,
1455 const SBFileSpecList &comp_unit_list)
1457 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1460 TargetSP target_sp(GetSP());
1461 if (target_sp && symbol_name_regex && symbol_name_regex[0])
1463 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1464 RegularExpression regexp(symbol_name_regex);
1465 const bool internal = false;
1466 const bool hardware = false;
1467 const LazyBool skip_prologue = eLazyBoolCalculate;
1469 *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware);
1474 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)",
1475 target_sp.get(), symbol_name_regex, sb_bp.get());
1482 SBTarget::BreakpointCreateByAddress (addr_t address)
1484 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1487 TargetSP target_sp(GetSP());
1490 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1491 const bool hardware = false;
1492 *sb_bp = target_sp->CreateBreakpoint (address, false, hardware);
1497 log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)", target_sp.get(), (uint64_t) address, sb_bp.get());
1504 SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1505 const lldb::SBFileSpec &source_file,
1506 const char *module_name)
1508 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1511 TargetSP target_sp(GetSP());
1512 if (target_sp && source_regex && source_regex[0])
1514 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1515 RegularExpression regexp(source_regex);
1516 FileSpecList source_file_spec_list;
1517 const bool hardware = false;
1518 source_file_spec_list.Append (source_file.ref());
1520 if (module_name && module_name[0])
1522 FileSpecList module_spec_list;
1523 module_spec_list.Append (FileSpec (module_name, false));
1525 *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware);
1529 *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware);
1535 char path[PATH_MAX];
1536 source_file->GetPath (path, sizeof(path));
1537 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)",
1538 target_sp.get(), source_regex, path, module_name, sb_bp.get());
1545 SBTarget::BreakpointCreateBySourceRegex (const char *source_regex,
1546 const SBFileSpecList &module_list,
1547 const lldb::SBFileSpecList &source_file_list)
1549 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1552 TargetSP target_sp(GetSP());
1553 if (target_sp && source_regex && source_regex[0])
1555 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1556 const bool hardware = false;
1557 RegularExpression regexp(source_regex);
1558 *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware);
1563 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)",
1564 target_sp.get(), source_regex, sb_bp.get());
1571 SBTarget::BreakpointCreateForException (lldb::LanguageType language,
1575 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1578 TargetSP target_sp(GetSP());
1581 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1582 const bool hardware = false;
1583 *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware);
1588 log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)",
1590 LanguageRuntime::GetNameForLanguageType(language),
1591 catch_bp ? "on" : "off",
1592 throw_bp ? "on" : "off",
1600 SBTarget::GetNumBreakpoints () const
1602 TargetSP target_sp(GetSP());
1605 // The breakpoint list is thread safe, no need to lock
1606 return target_sp->GetBreakpointList().GetSize();
1612 SBTarget::GetBreakpointAtIndex (uint32_t idx) const
1614 SBBreakpoint sb_breakpoint;
1615 TargetSP target_sp(GetSP());
1618 // The breakpoint list is thread safe, no need to lock
1619 *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1621 return sb_breakpoint;
1625 SBTarget::BreakpointDelete (break_id_t bp_id)
1627 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1629 bool result = false;
1630 TargetSP target_sp(GetSP());
1633 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1634 result = target_sp->RemoveBreakpointByID (bp_id);
1639 log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result);
1646 SBTarget::FindBreakpointByID (break_id_t bp_id)
1648 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1650 SBBreakpoint sb_breakpoint;
1651 TargetSP target_sp(GetSP());
1652 if (target_sp && bp_id != LLDB_INVALID_BREAK_ID)
1654 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1655 *sb_breakpoint = target_sp->GetBreakpointByID (bp_id);
1660 log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1661 target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get());
1664 return sb_breakpoint;
1668 SBTarget::EnableAllBreakpoints ()
1670 TargetSP target_sp(GetSP());
1673 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1674 target_sp->EnableAllBreakpoints ();
1681 SBTarget::DisableAllBreakpoints ()
1683 TargetSP target_sp(GetSP());
1686 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1687 target_sp->DisableAllBreakpoints ();
1694 SBTarget::DeleteAllBreakpoints ()
1696 TargetSP target_sp(GetSP());
1699 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1700 target_sp->RemoveAllBreakpoints ();
1707 SBTarget::GetNumWatchpoints () const
1709 TargetSP target_sp(GetSP());
1712 // The watchpoint list is thread safe, no need to lock
1713 return target_sp->GetWatchpointList().GetSize();
1719 SBTarget::GetWatchpointAtIndex (uint32_t idx) const
1721 SBWatchpoint sb_watchpoint;
1722 TargetSP target_sp(GetSP());
1725 // The watchpoint list is thread safe, no need to lock
1726 sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx));
1728 return sb_watchpoint;
1732 SBTarget::DeleteWatchpoint (watch_id_t wp_id)
1734 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1736 bool result = false;
1737 TargetSP target_sp(GetSP());
1740 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1741 Mutex::Locker locker;
1742 target_sp->GetWatchpointList().GetListMutex(locker);
1743 result = target_sp->RemoveWatchpointByID (wp_id);
1748 log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result);
1755 SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id)
1757 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1759 SBWatchpoint sb_watchpoint;
1760 lldb::WatchpointSP watchpoint_sp;
1761 TargetSP target_sp(GetSP());
1762 if (target_sp && wp_id != LLDB_INVALID_WATCH_ID)
1764 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1765 Mutex::Locker locker;
1766 target_sp->GetWatchpointList().GetListMutex(locker);
1767 watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1768 sb_watchpoint.SetSP (watchpoint_sp);
1773 log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1774 target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get());
1777 return sb_watchpoint;
1781 SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error)
1783 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1785 SBWatchpoint sb_watchpoint;
1786 lldb::WatchpointSP watchpoint_sp;
1787 TargetSP target_sp(GetSP());
1788 if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0)
1790 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1791 uint32_t watch_type = 0;
1793 watch_type |= LLDB_WATCH_TYPE_READ;
1795 watch_type |= LLDB_WATCH_TYPE_WRITE;
1796 if (watch_type == 0)
1798 error.SetErrorString("Can't create a watchpoint that is neither read nor write.");
1799 return sb_watchpoint;
1802 // Target::CreateWatchpoint() is thread safe.
1804 // This API doesn't take in a type, so we can't figure out what it is.
1805 ClangASTType *type = NULL;
1806 watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1807 error.SetError(cw_error);
1808 sb_watchpoint.SetSP (watchpoint_sp);
1813 log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)",
1814 target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get());
1817 return sb_watchpoint;
1821 SBTarget::EnableAllWatchpoints ()
1823 TargetSP target_sp(GetSP());
1826 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1827 Mutex::Locker locker;
1828 target_sp->GetWatchpointList().GetListMutex(locker);
1829 target_sp->EnableAllWatchpoints ();
1836 SBTarget::DisableAllWatchpoints ()
1838 TargetSP target_sp(GetSP());
1841 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1842 Mutex::Locker locker;
1843 target_sp->GetWatchpointList().GetListMutex(locker);
1844 target_sp->DisableAllWatchpoints ();
1851 SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
1854 lldb::ValueObjectSP new_value_sp;
1855 if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
1857 lldb::addr_t address(addr.GetLoadAddress(*this));
1858 lldb::TypeImplSP type_impl_sp (type.GetSP());
1859 ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(true).GetPointerType ());
1860 if (pointer_ast_type)
1862 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
1864 ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
1865 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
1869 exe_ctx.GetByteOrder(),
1870 exe_ctx.GetAddressByteSize()));
1872 if (ptr_result_valobj_sp)
1874 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
1876 new_value_sp = ptr_result_valobj_sp->Dereference(err);
1878 new_value_sp->SetName(ConstString(name));
1882 sb_value.SetSP(new_value_sp);
1883 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1887 log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"", m_opaque_sp.get(), new_value_sp->GetName().AsCString());
1889 log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL", m_opaque_sp.get());
1895 SBTarget::DeleteAllWatchpoints ()
1897 TargetSP target_sp(GetSP());
1900 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1901 Mutex::Locker locker;
1902 target_sp->GetWatchpointList().GetListMutex(locker);
1903 target_sp->RemoveAllWatchpoints ();
1911 SBTarget::AddModule (const char *path,
1913 const char *uuid_cstr)
1915 return AddModule (path, triple, uuid_cstr, NULL);
1919 SBTarget::AddModule (const char *path,
1921 const char *uuid_cstr,
1922 const char *symfile)
1924 lldb::SBModule sb_module;
1925 TargetSP target_sp(GetSP());
1928 ModuleSpec module_spec;
1930 module_spec.GetFileSpec().SetFile(path, false);
1933 module_spec.GetUUID().SetFromCString(uuid_cstr);
1936 module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get());
1938 module_spec.GetArchitecture() = target_sp->GetArchitecture();
1941 module_spec.GetSymbolFileSpec ().SetFile(symfile, false);
1943 sb_module.SetSP(target_sp->GetSharedModule (module_spec));
1949 SBTarget::AddModule (const SBModuleSpec &module_spec)
1951 lldb::SBModule sb_module;
1952 TargetSP target_sp(GetSP());
1954 sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap));
1959 SBTarget::AddModule (lldb::SBModule &module)
1961 TargetSP target_sp(GetSP());
1964 target_sp->GetImages().AppendIfNeeded (module.GetSP());
1971 SBTarget::GetNumModules () const
1973 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1976 TargetSP target_sp(GetSP());
1979 // The module list is thread safe, no need to lock
1980 num = target_sp->GetImages().GetSize();
1984 log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num);
1992 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1995 log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get());
1997 m_opaque_sp.reset();
2002 SBTarget::FindModule (const SBFileSpec &sb_file_spec)
2005 TargetSP target_sp(GetSP());
2006 if (target_sp && sb_file_spec.IsValid())
2008 ModuleSpec module_spec(*sb_file_spec);
2009 // The module list is thread safe, no need to lock
2010 sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec));
2016 SBTarget::GetByteOrder ()
2018 TargetSP target_sp(GetSP());
2020 return target_sp->GetArchitecture().GetByteOrder();
2021 return eByteOrderInvalid;
2025 SBTarget::GetTriple ()
2027 TargetSP target_sp(GetSP());
2030 std::string triple (target_sp->GetArchitecture().GetTriple().str());
2031 // Unique the string so we don't run into ownership issues since
2032 // the const strings put the string into the string pool once and
2033 // the strings never comes out
2034 ConstString const_triple (triple.c_str());
2035 return const_triple.GetCString();
2041 SBTarget::GetAddressByteSize()
2043 TargetSP target_sp(GetSP());
2045 return target_sp->GetArchitecture().GetAddressByteSize();
2046 return sizeof(void*);
2051 SBTarget::GetModuleAtIndex (uint32_t idx)
2053 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2057 TargetSP target_sp(GetSP());
2060 // The module list is thread safe, no need to lock
2061 module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
2062 sb_module.SetSP (module_sp);
2067 log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
2068 target_sp.get(), idx, module_sp.get());
2075 SBTarget::RemoveModule (lldb::SBModule module)
2077 TargetSP target_sp(GetSP());
2079 return target_sp->GetImages().Remove(module.GetSP());
2085 SBTarget::GetBroadcaster () const
2087 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2089 TargetSP target_sp(GetSP());
2090 SBBroadcaster broadcaster(target_sp.get(), false);
2093 log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
2094 target_sp.get(), broadcaster.get());
2100 SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level)
2102 Stream &strm = description.ref();
2104 TargetSP target_sp(GetSP());
2107 target_sp->Dump (&strm, description_level);
2110 strm.PutCString ("No value");
2115 lldb::SBSymbolContextList
2116 SBTarget::FindFunctions (const char *name, uint32_t name_type_mask)
2118 lldb::SBSymbolContextList sb_sc_list;
2119 if (name && name[0])
2121 TargetSP target_sp(GetSP());
2124 const bool symbols_ok = true;
2125 const bool inlines_ok = true;
2126 const bool append = true;
2127 target_sp->GetImages().FindFunctions (ConstString(name),
2139 SBTarget::FindFirstType (const char* typename_cstr)
2141 TargetSP target_sp(GetSP());
2142 if (typename_cstr && typename_cstr[0] && target_sp)
2144 ConstString const_typename(typename_cstr);
2146 const bool exact_match = false;
2148 const ModuleList &module_list = target_sp->GetImages();
2149 size_t count = module_list.GetSize();
2150 for (size_t idx = 0; idx < count; idx++)
2152 ModuleSP module_sp (module_list.GetModuleAtIndex(idx));
2155 TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match));
2157 return SBType(type_sp);
2161 // Didn't find the type in the symbols; try the Objective-C runtime
2162 // if one is installed
2164 ProcessSP process_sp(target_sp->GetProcessSP());
2168 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2170 if (objc_language_runtime)
2172 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2174 if (objc_type_vendor)
2176 std::vector <ClangASTType> types;
2178 if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0)
2179 return SBType(types[0]);
2184 // No matches, search for basic typename matches
2185 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2187 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename));
2193 SBTarget::GetBasicType(lldb::BasicType type)
2195 TargetSP target_sp(GetSP());
2198 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2200 return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type));
2207 SBTarget::FindTypes (const char* typename_cstr)
2209 SBTypeList sb_type_list;
2210 TargetSP target_sp(GetSP());
2211 if (typename_cstr && typename_cstr[0] && target_sp)
2213 ModuleList& images = target_sp->GetImages();
2214 ConstString const_typename(typename_cstr);
2215 bool exact_match = false;
2219 uint32_t num_matches = images.FindTypes (sc,
2225 if (num_matches > 0)
2227 for (size_t idx = 0; idx < num_matches; idx++)
2229 TypeSP type_sp (type_list.GetTypeAtIndex(idx));
2231 sb_type_list.Append(SBType(type_sp));
2235 // Try the Objective-C runtime if one is installed
2237 ProcessSP process_sp(target_sp->GetProcessSP());
2241 ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime();
2243 if (objc_language_runtime)
2245 TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
2247 if (objc_type_vendor)
2249 std::vector <ClangASTType> types;
2251 if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types))
2253 for (ClangASTType &type : types)
2255 sb_type_list.Append(SBType(type));
2262 if (sb_type_list.GetSize() == 0)
2264 // No matches, search for basic typename matches
2265 ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
2267 sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)));
2270 return sb_type_list;
2274 SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches)
2276 SBValueList sb_value_list;
2278 TargetSP target_sp(GetSP());
2279 if (name && target_sp)
2281 VariableList variable_list;
2282 const bool append = true;
2283 const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name),
2288 if (match_count > 0)
2290 ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2291 if (exe_scope == NULL)
2292 exe_scope = target_sp.get();
2293 for (uint32_t i=0; i<match_count; ++i)
2295 lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i)));
2297 sb_value_list.Append(SBValue(valobj_sp));
2302 return sb_value_list;
2306 SBTarget::FindFirstGlobalVariable (const char* name)
2308 SBValueList sb_value_list(FindGlobalVariables(name, 1));
2309 if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2310 return sb_value_list.GetValueAtIndex(0);
2315 SBTarget::GetSourceManager()
2317 SBSourceManager source_manager (*this);
2318 return source_manager;
2321 lldb::SBInstructionList
2322 SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count)
2324 return ReadInstructions (base_addr, count, NULL);
2327 lldb::SBInstructionList
2328 SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string)
2330 SBInstructionList sb_instructions;
2332 TargetSP target_sp(GetSP());
2335 Address *addr_ptr = base_addr.get();
2339 DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2340 bool prefer_file_cache = false;
2341 lldb_private::Error error;
2342 lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2343 const size_t bytes_read = target_sp->ReadMemory(*addr_ptr,
2349 const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
2350 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2361 return sb_instructions;
2365 lldb::SBInstructionList
2366 SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size)
2368 return GetInstructionsWithFlavor (base_addr, NULL, buf, size);
2371 lldb::SBInstructionList
2372 SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size)
2374 SBInstructionList sb_instructions;
2376 TargetSP target_sp(GetSP());
2381 if (base_addr.get())
2382 addr = *base_addr.get();
2384 const bool data_from_file = true;
2386 sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(),
2396 return sb_instructions;
2399 lldb::SBInstructionList
2400 SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size)
2402 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size);
2405 lldb::SBInstructionList
2406 SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size)
2408 return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size);
2412 SBTarget::SetSectionLoadAddress (lldb::SBSection section,
2413 lldb::addr_t section_base_addr)
2416 TargetSP target_sp(GetSP());
2419 if (!section.IsValid())
2421 sb_error.SetErrorStringWithFormat ("invalid section");
2425 SectionSP section_sp (section.GetSP());
2428 if (section_sp->IsThreadSpecific())
2430 sb_error.SetErrorString ("thread specific sections are not yet supported");
2434 ProcessSP process_sp (target_sp->GetProcessSP());
2435 uint32_t stop_id = 0;
2437 stop_id = process_sp->GetStopID();
2439 if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr))
2441 // Flush info in the process (stack frames, etc)
2443 process_sp->Flush();
2451 sb_error.SetErrorString ("invalid target");
2457 SBTarget::ClearSectionLoadAddress (lldb::SBSection section)
2461 TargetSP target_sp(GetSP());
2464 if (!section.IsValid())
2466 sb_error.SetErrorStringWithFormat ("invalid section");
2470 ProcessSP process_sp (target_sp->GetProcessSP());
2471 uint32_t stop_id = 0;
2473 stop_id = process_sp->GetStopID();
2475 if (target_sp->SetSectionUnloaded (section.GetSP()))
2477 // Flush info in the process (stack frames, etc)
2479 process_sp->Flush();
2485 sb_error.SetErrorStringWithFormat ("invalid target");
2491 SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset)
2495 TargetSP target_sp(GetSP());
2498 ModuleSP module_sp (module.GetSP());
2501 bool changed = false;
2502 if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
2504 // The load was successful, make sure that at least some sections
2505 // changed before we notify that our module was loaded.
2508 ModuleList module_list;
2509 module_list.Append(module_sp);
2510 target_sp->ModulesDidLoad (module_list);
2511 // Flush info in the process (stack frames, etc)
2512 ProcessSP process_sp (target_sp->GetProcessSP());
2514 process_sp->Flush();
2520 sb_error.SetErrorStringWithFormat ("invalid module");
2526 sb_error.SetErrorStringWithFormat ("invalid target");
2532 SBTarget::ClearModuleLoadAddress (lldb::SBModule module)
2536 char path[PATH_MAX];
2537 TargetSP target_sp(GetSP());
2540 ModuleSP module_sp (module.GetSP());
2543 ObjectFile *objfile = module_sp->GetObjectFile();
2546 SectionList *section_list = objfile->GetSectionList();
2549 ProcessSP process_sp (target_sp->GetProcessSP());
2550 uint32_t stop_id = 0;
2552 stop_id = process_sp->GetStopID();
2554 bool changed = false;
2555 const size_t num_sections = section_list->GetSize();
2556 for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
2558 SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
2560 changed |= target_sp->SetSectionUnloaded (section_sp) > 0;
2564 // Flush info in the process (stack frames, etc)
2565 ProcessSP process_sp (target_sp->GetProcessSP());
2567 process_sp->Flush();
2572 module_sp->GetFileSpec().GetPath (path, sizeof(path));
2573 sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
2578 module_sp->GetFileSpec().GetPath (path, sizeof(path));
2579 sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
2584 sb_error.SetErrorStringWithFormat ("invalid module");
2589 sb_error.SetErrorStringWithFormat ("invalid target");
2595 lldb::SBSymbolContextList
2596 SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type)
2598 SBSymbolContextList sb_sc_list;
2599 if (name && name[0])
2601 TargetSP target_sp(GetSP());
2605 target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name),
2617 SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options)
2619 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
2620 Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
2621 SBValue expr_result;
2622 ExecutionResults exe_results = eExecutionSetupError;
2623 ValueObjectSP expr_value_sp;
2624 TargetSP target_sp(GetSP());
2625 StackFrame *frame = NULL;
2628 if (expr == NULL || expr[0] == '\0')
2631 log->Printf ("SBTarget::EvaluateExpression called with an empty expression");
2635 Mutex::Locker api_locker (target_sp->GetAPIMutex());
2636 ExecutionContext exe_ctx (m_opaque_sp.get());
2639 log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
2641 frame = exe_ctx.GetFramePtr();
2642 Target *target = exe_ctx.GetTargetPtr();
2646 #ifdef LLDB_CONFIGURATION_DEBUG
2647 StreamString frame_description;
2649 frame->DumpUsingSettingsFormat (&frame_description);
2650 Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
2651 expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str());
2653 exe_results = target->EvaluateExpression (expr,
2658 expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2659 #ifdef LLDB_CONFIGURATION_DEBUG
2660 Host::SetCrashDescription (NULL);
2666 log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget.");
2669 #ifndef LLDB_DISABLE_PYTHON
2671 expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **",
2672 expr_result.GetValue(),
2673 expr_result.GetSummary());
2676 log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)",
2679 expr_value_sp.get(),
2688 SBTarget::GetStackRedZoneSize()
2690 TargetSP target_sp(GetSP());
2694 ProcessSP process_sp (target_sp->GetProcessSP());
2696 abi_sp = process_sp->GetABI();
2698 abi_sp = ABI::FindPlugin(target_sp->GetArchitecture());
2700 return abi_sp->GetRedZoneSize();