1ac7ddfbfSEd Maste //===-- SBTarget.cpp --------------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
10ac7ddfbfSEd Maste #include "lldb/API/SBTarget.h"
11ac7ddfbfSEd Maste 
12ac7ddfbfSEd Maste #include "lldb/lldb-public.h"
13ac7ddfbfSEd Maste 
14ac7ddfbfSEd Maste #include "lldb/API/SBBreakpoint.h"
151c3bbb01SEd Maste #include "lldb/API/SBDebugger.h"
161c3bbb01SEd Maste #include "lldb/API/SBEvent.h"
17ac7ddfbfSEd Maste #include "lldb/API/SBExpressionOptions.h"
18ac7ddfbfSEd Maste #include "lldb/API/SBFileSpec.h"
19ac7ddfbfSEd Maste #include "lldb/API/SBListener.h"
20ac7ddfbfSEd Maste #include "lldb/API/SBModule.h"
21ac7ddfbfSEd Maste #include "lldb/API/SBModuleSpec.h"
22ac7ddfbfSEd Maste #include "lldb/API/SBProcess.h"
23435933ddSDimitry Andric #include "lldb/API/SBSourceManager.h"
24ac7ddfbfSEd Maste #include "lldb/API/SBStream.h"
254bb0738eSEd Maste #include "lldb/API/SBStringList.h"
264ba319b5SDimitry Andric #include "lldb/API/SBStructuredData.h"
27ac7ddfbfSEd Maste #include "lldb/API/SBSymbolContextList.h"
28ac7ddfbfSEd Maste #include "lldb/Breakpoint/BreakpointID.h"
29ac7ddfbfSEd Maste #include "lldb/Breakpoint/BreakpointIDList.h"
30ac7ddfbfSEd Maste #include "lldb/Breakpoint/BreakpointList.h"
31ac7ddfbfSEd Maste #include "lldb/Breakpoint/BreakpointLocation.h"
32ac7ddfbfSEd Maste #include "lldb/Core/Address.h"
33ac7ddfbfSEd Maste #include "lldb/Core/AddressResolver.h"
34ac7ddfbfSEd Maste #include "lldb/Core/AddressResolverName.h"
35ac7ddfbfSEd Maste #include "lldb/Core/Debugger.h"
36ac7ddfbfSEd Maste #include "lldb/Core/Disassembler.h"
37ac7ddfbfSEd Maste #include "lldb/Core/Module.h"
38ac7ddfbfSEd Maste #include "lldb/Core/ModuleSpec.h"
39435933ddSDimitry Andric #include "lldb/Core/STLUtils.h"
40ac7ddfbfSEd Maste #include "lldb/Core/SearchFilter.h"
41ac7ddfbfSEd Maste #include "lldb/Core/Section.h"
424ba319b5SDimitry Andric #include "lldb/Core/StructuredDataImpl.h"
4335617911SEd Maste #include "lldb/Core/ValueObjectConstResult.h"
44ac7ddfbfSEd Maste #include "lldb/Core/ValueObjectList.h"
45ac7ddfbfSEd Maste #include "lldb/Core/ValueObjectVariable.h"
46ac7ddfbfSEd Maste #include "lldb/Host/Host.h"
471c3bbb01SEd Maste #include "lldb/Symbol/ClangASTContext.h"
481c3bbb01SEd Maste #include "lldb/Symbol/DeclVendor.h"
49ac7ddfbfSEd Maste #include "lldb/Symbol/ObjectFile.h"
504bb0738eSEd Maste #include "lldb/Symbol/SymbolFile.h"
51ac7ddfbfSEd Maste #include "lldb/Symbol/SymbolVendor.h"
52ac7ddfbfSEd Maste #include "lldb/Symbol/VariableList.h"
531c3bbb01SEd Maste #include "lldb/Target/ABI.h"
549f2f44ceSEd Maste #include "lldb/Target/Language.h"
55ac7ddfbfSEd Maste #include "lldb/Target/LanguageRuntime.h"
561c3bbb01SEd Maste #include "lldb/Target/ObjCLanguageRuntime.h"
57ac7ddfbfSEd Maste #include "lldb/Target/Process.h"
581c3bbb01SEd Maste #include "lldb/Target/StackFrame.h"
59ac7ddfbfSEd Maste #include "lldb/Target/Target.h"
60ac7ddfbfSEd Maste #include "lldb/Target/TargetList.h"
61acac075bSDimitry Andric #include "lldb/Utility/ArchSpec.h"
624ba319b5SDimitry Andric #include "lldb/Utility/Args.h"
63f678e45dSDimitry Andric #include "lldb/Utility/FileSpec.h"
64f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
65f678e45dSDimitry Andric #include "lldb/Utility/RegularExpression.h"
66ac7ddfbfSEd Maste 
674ba319b5SDimitry Andric #include "Commands/CommandObjectBreakpoint.h"
68435933ddSDimitry Andric #include "lldb/Interpreter/CommandReturnObject.h"
69435933ddSDimitry Andric #include "llvm/Support/PrettyStackTrace.h"
707aa51b79SEd Maste #include "llvm/Support/Regex.h"
71ac7ddfbfSEd Maste 
72ac7ddfbfSEd Maste using namespace lldb;
73ac7ddfbfSEd Maste using namespace lldb_private;
74ac7ddfbfSEd Maste 
75ac7ddfbfSEd Maste #define DEFAULT_DISASM_BYTE_SIZE 32
76ac7ddfbfSEd Maste 
771c3bbb01SEd Maste namespace {
78ac7ddfbfSEd Maste 
AttachToProcess(ProcessAttachInfo & attach_info,Target & target)795517e702SDimitry Andric Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target) {
804bb0738eSEd Maste   std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
81ac7ddfbfSEd Maste 
821c3bbb01SEd Maste   auto process_sp = target.GetProcessSP();
83435933ddSDimitry Andric   if (process_sp) {
841c3bbb01SEd Maste     const auto state = process_sp->GetState();
85435933ddSDimitry Andric     if (process_sp->IsAlive() && state == eStateConnected) {
861c3bbb01SEd Maste       // If we are already connected, then we have already specified the
874ba319b5SDimitry Andric       // listener, so if a valid listener is supplied, we need to error out to
884ba319b5SDimitry Andric       // let the client know.
891c3bbb01SEd Maste       if (attach_info.GetListener())
905517e702SDimitry Andric         return Status("process is connected and already has a listener, pass "
91435933ddSDimitry Andric                       "empty listener");
92ac7ddfbfSEd Maste     }
93ac7ddfbfSEd Maste   }
94ac7ddfbfSEd Maste 
951c3bbb01SEd Maste   return target.Attach(attach_info, nullptr);
96ac7ddfbfSEd Maste }
97ac7ddfbfSEd Maste 
981c3bbb01SEd Maste } // namespace
99ac7ddfbfSEd Maste 
100ac7ddfbfSEd Maste //----------------------------------------------------------------------
101ac7ddfbfSEd Maste // SBTarget constructor
102ac7ddfbfSEd Maste //----------------------------------------------------------------------
SBTarget()103435933ddSDimitry Andric SBTarget::SBTarget() : m_opaque_sp() {}
104ac7ddfbfSEd Maste 
SBTarget(const SBTarget & rhs)105435933ddSDimitry Andric SBTarget::SBTarget(const SBTarget &rhs) : m_opaque_sp(rhs.m_opaque_sp) {}
106ac7ddfbfSEd Maste 
SBTarget(const TargetSP & target_sp)107435933ddSDimitry Andric SBTarget::SBTarget(const TargetSP &target_sp) : m_opaque_sp(target_sp) {}
108ac7ddfbfSEd Maste 
operator =(const SBTarget & rhs)109435933ddSDimitry Andric const SBTarget &SBTarget::operator=(const SBTarget &rhs) {
110ac7ddfbfSEd Maste   if (this != &rhs)
111ac7ddfbfSEd Maste     m_opaque_sp = rhs.m_opaque_sp;
112ac7ddfbfSEd Maste   return *this;
113ac7ddfbfSEd Maste }
114ac7ddfbfSEd Maste 
115ac7ddfbfSEd Maste //----------------------------------------------------------------------
116ac7ddfbfSEd Maste // Destructor
117ac7ddfbfSEd Maste //----------------------------------------------------------------------
~SBTarget()118435933ddSDimitry Andric SBTarget::~SBTarget() {}
119ac7ddfbfSEd Maste 
EventIsTargetEvent(const SBEvent & event)120435933ddSDimitry Andric bool SBTarget::EventIsTargetEvent(const SBEvent &event) {
1211c3bbb01SEd Maste   return Target::TargetEventData::GetEventDataFromEvent(event.get()) != NULL;
1221c3bbb01SEd Maste }
1231c3bbb01SEd Maste 
GetTargetFromEvent(const SBEvent & event)124435933ddSDimitry Andric SBTarget SBTarget::GetTargetFromEvent(const SBEvent &event) {
1251c3bbb01SEd Maste   return Target::TargetEventData::GetTargetFromEvent(event.get());
1261c3bbb01SEd Maste }
1271c3bbb01SEd Maste 
GetNumModulesFromEvent(const SBEvent & event)128435933ddSDimitry Andric uint32_t SBTarget::GetNumModulesFromEvent(const SBEvent &event) {
129435933ddSDimitry Andric   const ModuleList module_list =
130435933ddSDimitry Andric       Target::TargetEventData::GetModuleListFromEvent(event.get());
1311c3bbb01SEd Maste   return module_list.GetSize();
1321c3bbb01SEd Maste }
1331c3bbb01SEd Maste 
GetModuleAtIndexFromEvent(const uint32_t idx,const SBEvent & event)134435933ddSDimitry Andric SBModule SBTarget::GetModuleAtIndexFromEvent(const uint32_t idx,
135435933ddSDimitry Andric                                              const SBEvent &event) {
136435933ddSDimitry Andric   const ModuleList module_list =
137435933ddSDimitry Andric       Target::TargetEventData::GetModuleListFromEvent(event.get());
1381c3bbb01SEd Maste   return SBModule(module_list.GetModuleAtIndex(idx));
1391c3bbb01SEd Maste }
1401c3bbb01SEd Maste 
GetBroadcasterClassName()141435933ddSDimitry Andric const char *SBTarget::GetBroadcasterClassName() {
142ac7ddfbfSEd Maste   return Target::GetStaticBroadcasterClass().AsCString();
143ac7ddfbfSEd Maste }
144ac7ddfbfSEd Maste 
IsValid() const145435933ddSDimitry Andric bool SBTarget::IsValid() const {
146ac7ddfbfSEd Maste   return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid();
147ac7ddfbfSEd Maste }
148ac7ddfbfSEd Maste 
GetProcess()149435933ddSDimitry Andric SBProcess SBTarget::GetProcess() {
150ac7ddfbfSEd Maste   SBProcess sb_process;
151ac7ddfbfSEd Maste   ProcessSP process_sp;
152ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
153435933ddSDimitry Andric   if (target_sp) {
154ac7ddfbfSEd Maste     process_sp = target_sp->GetProcessSP();
155ac7ddfbfSEd Maste     sb_process.SetSP(process_sp);
156ac7ddfbfSEd Maste   }
157ac7ddfbfSEd Maste 
158ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
159ac7ddfbfSEd Maste   if (log)
160ac7ddfbfSEd Maste     log->Printf("SBTarget(%p)::GetProcess () => SBProcess(%p)",
1610127ef0fSEd Maste                 static_cast<void *>(target_sp.get()),
1620127ef0fSEd Maste                 static_cast<void *>(process_sp.get()));
163ac7ddfbfSEd Maste 
164ac7ddfbfSEd Maste   return sb_process;
165ac7ddfbfSEd Maste }
166ac7ddfbfSEd Maste 
GetPlatform()167435933ddSDimitry Andric SBPlatform SBTarget::GetPlatform() {
1687aa51b79SEd Maste   TargetSP target_sp(GetSP());
1697aa51b79SEd Maste   if (!target_sp)
1707aa51b79SEd Maste     return SBPlatform();
1717aa51b79SEd Maste 
1727aa51b79SEd Maste   SBPlatform platform;
1737aa51b79SEd Maste   platform.m_opaque_sp = target_sp->GetPlatform();
1747aa51b79SEd Maste 
1757aa51b79SEd Maste   return platform;
1767aa51b79SEd Maste }
1777aa51b79SEd Maste 
GetDebugger() const178435933ddSDimitry Andric SBDebugger SBTarget::GetDebugger() const {
179ac7ddfbfSEd Maste   SBDebugger debugger;
180ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
181ac7ddfbfSEd Maste   if (target_sp)
182ac7ddfbfSEd Maste     debugger.reset(target_sp->GetDebugger().shared_from_this());
183ac7ddfbfSEd Maste   return debugger;
184ac7ddfbfSEd Maste }
185ac7ddfbfSEd Maste 
GetStatistics()1864ba319b5SDimitry Andric SBStructuredData SBTarget::GetStatistics() {
1874ba319b5SDimitry Andric   SBStructuredData data;
1884ba319b5SDimitry Andric   TargetSP target_sp(GetSP());
1894ba319b5SDimitry Andric   if (!target_sp)
1904ba319b5SDimitry Andric     return data;
1914ba319b5SDimitry Andric 
1924ba319b5SDimitry Andric   auto stats_up = llvm::make_unique<StructuredData::Dictionary>();
1934ba319b5SDimitry Andric   int i = 0;
1944ba319b5SDimitry Andric   for (auto &Entry : target_sp->GetStatistics()) {
1954ba319b5SDimitry Andric     std::string Desc = lldb_private::GetStatDescription(
1964ba319b5SDimitry Andric         static_cast<lldb_private::StatisticKind>(i));
1974ba319b5SDimitry Andric     stats_up->AddIntegerItem(Desc, Entry);
1984ba319b5SDimitry Andric     i += 1;
1994ba319b5SDimitry Andric   }
2004ba319b5SDimitry Andric 
2014ba319b5SDimitry Andric   data.m_impl_up->SetObjectSP(std::move(stats_up));
2024ba319b5SDimitry Andric   return data;
2034ba319b5SDimitry Andric }
2044ba319b5SDimitry Andric 
SetCollectingStats(bool v)205*b5893f02SDimitry Andric void SBTarget::SetCollectingStats(bool v) {
206*b5893f02SDimitry Andric   TargetSP target_sp(GetSP());
207*b5893f02SDimitry Andric   if (!target_sp)
208*b5893f02SDimitry Andric     return;
209*b5893f02SDimitry Andric   return target_sp->SetCollectingStats(v);
210*b5893f02SDimitry Andric }
211*b5893f02SDimitry Andric 
GetCollectingStats()212*b5893f02SDimitry Andric bool SBTarget::GetCollectingStats() {
213*b5893f02SDimitry Andric   TargetSP target_sp(GetSP());
214*b5893f02SDimitry Andric   if (!target_sp)
215*b5893f02SDimitry Andric     return false;
216*b5893f02SDimitry Andric   return target_sp->GetCollectingStats();
217*b5893f02SDimitry Andric }
218*b5893f02SDimitry Andric 
219*b5893f02SDimitry Andric 
LoadCore(const char * core_file)220435933ddSDimitry Andric SBProcess SBTarget::LoadCore(const char *core_file) {
2214ba319b5SDimitry Andric   lldb::SBError error; // Ignored
2224ba319b5SDimitry Andric   return LoadCore(core_file, error);
2234ba319b5SDimitry Andric }
2244ba319b5SDimitry Andric 
LoadCore(const char * core_file,lldb::SBError & error)2254ba319b5SDimitry Andric SBProcess SBTarget::LoadCore(const char *core_file, lldb::SBError &error) {
226ac7ddfbfSEd Maste   SBProcess sb_process;
227ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
228435933ddSDimitry Andric   if (target_sp) {
229*b5893f02SDimitry Andric     FileSpec filespec(core_file);
230*b5893f02SDimitry Andric     FileSystem::Instance().Resolve(filespec);
231435933ddSDimitry Andric     ProcessSP process_sp(target_sp->CreateProcess(
232435933ddSDimitry Andric         target_sp->GetDebugger().GetListener(), "", &filespec));
233435933ddSDimitry Andric     if (process_sp) {
2344ba319b5SDimitry Andric       error.SetError(process_sp->LoadCore());
2354ba319b5SDimitry Andric       if (error.Success())
236ac7ddfbfSEd Maste         sb_process.SetSP(process_sp);
2374ba319b5SDimitry Andric     } else {
2384ba319b5SDimitry Andric       error.SetErrorString("Failed to create the process");
239ac7ddfbfSEd Maste     }
2404ba319b5SDimitry Andric   } else {
2414ba319b5SDimitry Andric     error.SetErrorString("SBTarget is invalid");
242ac7ddfbfSEd Maste   }
243ac7ddfbfSEd Maste   return sb_process;
244ac7ddfbfSEd Maste }
245ac7ddfbfSEd Maste 
LaunchSimple(char const ** argv,char const ** envp,const char * working_directory)246435933ddSDimitry Andric SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp,
247435933ddSDimitry Andric                                  const char *working_directory) {
248ac7ddfbfSEd Maste   char *stdin_path = NULL;
249ac7ddfbfSEd Maste   char *stdout_path = NULL;
250ac7ddfbfSEd Maste   char *stderr_path = NULL;
251ac7ddfbfSEd Maste   uint32_t launch_flags = 0;
252ac7ddfbfSEd Maste   bool stop_at_entry = false;
253ac7ddfbfSEd Maste   SBError error;
254ac7ddfbfSEd Maste   SBListener listener = GetDebugger().GetListener();
255435933ddSDimitry Andric   return Launch(listener, argv, envp, stdin_path, stdout_path, stderr_path,
256435933ddSDimitry Andric                 working_directory, launch_flags, stop_at_entry, error);
257ac7ddfbfSEd Maste }
258ac7ddfbfSEd Maste 
Install()259435933ddSDimitry Andric SBError SBTarget::Install() {
260b952cd58SEd Maste   SBError sb_error;
261b952cd58SEd Maste   TargetSP target_sp(GetSP());
262435933ddSDimitry Andric   if (target_sp) {
2634bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
264b952cd58SEd Maste     sb_error.ref() = target_sp->Install(NULL);
265b952cd58SEd Maste   }
266b952cd58SEd Maste   return sb_error;
267b952cd58SEd Maste }
268b952cd58SEd Maste 
Launch(SBListener & listener,char const ** argv,char const ** envp,const char * stdin_path,const char * stdout_path,const char * stderr_path,const char * working_directory,uint32_t launch_flags,bool stop_at_entry,lldb::SBError & error)269435933ddSDimitry Andric SBProcess SBTarget::Launch(SBListener &listener, char const **argv,
270435933ddSDimitry Andric                            char const **envp, const char *stdin_path,
271435933ddSDimitry Andric                            const char *stdout_path, const char *stderr_path,
272ac7ddfbfSEd Maste                            const char *working_directory,
273ac7ddfbfSEd Maste                            uint32_t launch_flags, // See LaunchFlags
274435933ddSDimitry Andric                            bool stop_at_entry, lldb::SBError &error) {
275ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
276ac7ddfbfSEd Maste 
277ac7ddfbfSEd Maste   SBProcess sb_process;
278ac7ddfbfSEd Maste   ProcessSP process_sp;
279ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
280ac7ddfbfSEd Maste 
281ac7ddfbfSEd Maste   if (log)
282435933ddSDimitry Andric     log->Printf("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, "
283435933ddSDimitry Andric                 "stderr=%s, working-dir=%s, launch_flags=0x%x, "
284435933ddSDimitry Andric                 "stop_at_entry=%i, &error (%p))...",
285435933ddSDimitry Andric                 static_cast<void *>(target_sp.get()), static_cast<void *>(argv),
286435933ddSDimitry Andric                 static_cast<void *>(envp), stdin_path ? stdin_path : "NULL",
287ac7ddfbfSEd Maste                 stdout_path ? stdout_path : "NULL",
288ac7ddfbfSEd Maste                 stderr_path ? stderr_path : "NULL",
289435933ddSDimitry Andric                 working_directory ? working_directory : "NULL", launch_flags,
290435933ddSDimitry Andric                 stop_at_entry, static_cast<void *>(error.get()));
291ac7ddfbfSEd Maste 
292435933ddSDimitry Andric   if (target_sp) {
2934bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
294ac7ddfbfSEd Maste 
2951c3bbb01SEd Maste     if (stop_at_entry)
2961c3bbb01SEd Maste       launch_flags |= eLaunchFlagStopAtEntry;
2971c3bbb01SEd Maste 
298ac7ddfbfSEd Maste     if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
299ac7ddfbfSEd Maste       launch_flags |= eLaunchFlagDisableASLR;
300ac7ddfbfSEd Maste 
301ac7ddfbfSEd Maste     StateType state = eStateInvalid;
302ac7ddfbfSEd Maste     process_sp = target_sp->GetProcessSP();
303435933ddSDimitry Andric     if (process_sp) {
304ac7ddfbfSEd Maste       state = process_sp->GetState();
305ac7ddfbfSEd Maste 
306435933ddSDimitry Andric       if (process_sp->IsAlive() && state != eStateConnected) {
307ac7ddfbfSEd Maste         if (state == eStateAttaching)
308ac7ddfbfSEd Maste           error.SetErrorString("process attach is in progress");
309ac7ddfbfSEd Maste         else
310ac7ddfbfSEd Maste           error.SetErrorString("a process is already being debugged");
311ac7ddfbfSEd Maste         return sb_process;
312ac7ddfbfSEd Maste       }
313ac7ddfbfSEd Maste     }
314ac7ddfbfSEd Maste 
315435933ddSDimitry Andric     if (state == eStateConnected) {
316ac7ddfbfSEd Maste       // If we are already connected, then we have already specified the
3174ba319b5SDimitry Andric       // listener, so if a valid listener is supplied, we need to error out to
3184ba319b5SDimitry Andric       // let the client know.
319435933ddSDimitry Andric       if (listener.IsValid()) {
320435933ddSDimitry Andric         error.SetErrorString("process is connected and already has a listener, "
321435933ddSDimitry Andric                              "pass empty listener");
322ac7ddfbfSEd Maste         return sb_process;
323ac7ddfbfSEd Maste       }
324ac7ddfbfSEd Maste     }
325ac7ddfbfSEd Maste 
326ac7ddfbfSEd Maste     if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
327ac7ddfbfSEd Maste       launch_flags |= eLaunchFlagDisableSTDIO;
328ac7ddfbfSEd Maste 
329*b5893f02SDimitry Andric     ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
330*b5893f02SDimitry Andric                                   FileSpec(stderr_path),
331*b5893f02SDimitry Andric                                   FileSpec(working_directory), launch_flags);
332ac7ddfbfSEd Maste 
333ac7ddfbfSEd Maste     Module *exe_module = target_sp->GetExecutableModulePointer();
334ac7ddfbfSEd Maste     if (exe_module)
335ac7ddfbfSEd Maste       launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
336ac7ddfbfSEd Maste     if (argv)
337ac7ddfbfSEd Maste       launch_info.GetArguments().AppendArguments(argv);
338ac7ddfbfSEd Maste     if (envp)
3394ba319b5SDimitry Andric       launch_info.GetEnvironment() = Environment(envp);
340ac7ddfbfSEd Maste 
34112b93ac6SEd Maste     if (listener.IsValid())
3427aa51b79SEd Maste       launch_info.SetListener(listener.GetSP());
3437aa51b79SEd Maste 
3447aa51b79SEd Maste     error.SetError(target_sp->Launch(launch_info, NULL));
34512b93ac6SEd Maste 
34612b93ac6SEd Maste     sb_process.SetSP(target_sp->GetProcessSP());
347435933ddSDimitry Andric   } else {
348ac7ddfbfSEd Maste     error.SetErrorString("SBTarget is invalid");
349ac7ddfbfSEd Maste   }
350ac7ddfbfSEd Maste 
351ac7ddfbfSEd Maste   log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API);
352ac7ddfbfSEd Maste   if (log)
353435933ddSDimitry Andric     log->Printf("SBTarget(%p)::Launch (...) => SBProcess(%p), SBError(%s)",
354435933ddSDimitry Andric                 static_cast<void *>(target_sp.get()),
355435933ddSDimitry Andric                 static_cast<void *>(sb_process.GetSP().get()),
356435933ddSDimitry Andric                 error.GetCString());
357ac7ddfbfSEd Maste 
358ac7ddfbfSEd Maste   return sb_process;
359ac7ddfbfSEd Maste }
360ac7ddfbfSEd Maste 
Launch(SBLaunchInfo & sb_launch_info,SBError & error)361435933ddSDimitry Andric SBProcess SBTarget::Launch(SBLaunchInfo &sb_launch_info, SBError &error) {
362ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
363ac7ddfbfSEd Maste 
364ac7ddfbfSEd Maste   SBProcess sb_process;
365ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
366ac7ddfbfSEd Maste 
367ac7ddfbfSEd Maste   if (log)
3680127ef0fSEd Maste     log->Printf("SBTarget(%p)::Launch (launch_info, error)...",
3690127ef0fSEd Maste                 static_cast<void *>(target_sp.get()));
370ac7ddfbfSEd Maste 
371435933ddSDimitry Andric   if (target_sp) {
3724bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
373ac7ddfbfSEd Maste     StateType state = eStateInvalid;
37412b93ac6SEd Maste     {
37512b93ac6SEd Maste       ProcessSP process_sp = target_sp->GetProcessSP();
376435933ddSDimitry Andric       if (process_sp) {
377ac7ddfbfSEd Maste         state = process_sp->GetState();
378ac7ddfbfSEd Maste 
379435933ddSDimitry Andric         if (process_sp->IsAlive() && state != eStateConnected) {
380ac7ddfbfSEd Maste           if (state == eStateAttaching)
381ac7ddfbfSEd Maste             error.SetErrorString("process attach is in progress");
382ac7ddfbfSEd Maste           else
383ac7ddfbfSEd Maste             error.SetErrorString("a process is already being debugged");
384ac7ddfbfSEd Maste           return sb_process;
385ac7ddfbfSEd Maste         }
386ac7ddfbfSEd Maste       }
38712b93ac6SEd Maste     }
388ac7ddfbfSEd Maste 
3894ba319b5SDimitry Andric     lldb_private::ProcessLaunchInfo launch_info = sb_launch_info.ref();
390ac7ddfbfSEd Maste 
391435933ddSDimitry Andric     if (!launch_info.GetExecutableFile()) {
392ac7ddfbfSEd Maste       Module *exe_module = target_sp->GetExecutableModulePointer();
393ac7ddfbfSEd Maste       if (exe_module)
394ac7ddfbfSEd Maste         launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
3950127ef0fSEd Maste     }
396ac7ddfbfSEd Maste 
397ac7ddfbfSEd Maste     const ArchSpec &arch_spec = target_sp->GetArchitecture();
398ac7ddfbfSEd Maste     if (arch_spec.IsValid())
399ac7ddfbfSEd Maste       launch_info.GetArchitecture() = arch_spec;
400ac7ddfbfSEd Maste 
4017aa51b79SEd Maste     error.SetError(target_sp->Launch(launch_info, NULL));
4024ba319b5SDimitry Andric     sb_launch_info.set_ref(launch_info);
40312b93ac6SEd Maste     sb_process.SetSP(target_sp->GetProcessSP());
404435933ddSDimitry Andric   } else {
405ac7ddfbfSEd Maste     error.SetErrorString("SBTarget is invalid");
406ac7ddfbfSEd Maste   }
407ac7ddfbfSEd Maste 
408ac7ddfbfSEd Maste   log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API);
409ac7ddfbfSEd Maste   if (log)
410ac7ddfbfSEd Maste     log->Printf("SBTarget(%p)::Launch (...) => SBProcess(%p)",
4110127ef0fSEd Maste                 static_cast<void *>(target_sp.get()),
4120127ef0fSEd Maste                 static_cast<void *>(sb_process.GetSP().get()));
413ac7ddfbfSEd Maste 
414ac7ddfbfSEd Maste   return sb_process;
415ac7ddfbfSEd Maste }
416ac7ddfbfSEd Maste 
Attach(SBAttachInfo & sb_attach_info,SBError & error)417435933ddSDimitry Andric lldb::SBProcess SBTarget::Attach(SBAttachInfo &sb_attach_info, SBError &error) {
418ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
419ac7ddfbfSEd Maste 
420ac7ddfbfSEd Maste   SBProcess sb_process;
421ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
422ac7ddfbfSEd Maste 
423ac7ddfbfSEd Maste   if (log)
4240127ef0fSEd Maste     log->Printf("SBTarget(%p)::Attach (sb_attach_info, error)...",
4250127ef0fSEd Maste                 static_cast<void *>(target_sp.get()));
426ac7ddfbfSEd Maste 
427435933ddSDimitry Andric   if (target_sp) {
428ac7ddfbfSEd Maste     ProcessAttachInfo &attach_info = sb_attach_info.ref();
429435933ddSDimitry Andric     if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid()) {
430ac7ddfbfSEd Maste       PlatformSP platform_sp = target_sp->GetPlatform();
431ac7ddfbfSEd Maste       // See if we can pre-verify if a process exists or not
432435933ddSDimitry Andric       if (platform_sp && platform_sp->IsConnected()) {
433ac7ddfbfSEd Maste         lldb::pid_t attach_pid = attach_info.GetProcessID();
434ac7ddfbfSEd Maste         ProcessInstanceInfo instance_info;
435435933ddSDimitry Andric         if (platform_sp->GetProcessInfo(attach_pid, instance_info)) {
436ac7ddfbfSEd Maste           attach_info.SetUserID(instance_info.GetEffectiveUserID());
437435933ddSDimitry Andric         } else {
438435933ddSDimitry Andric           error.ref().SetErrorStringWithFormat(
439435933ddSDimitry Andric               "no process found with process ID %" PRIu64, attach_pid);
440435933ddSDimitry Andric           if (log) {
441ac7ddfbfSEd Maste             log->Printf("SBTarget(%p)::Attach (...) => error %s",
442435933ddSDimitry Andric                         static_cast<void *>(target_sp.get()),
443435933ddSDimitry Andric                         error.GetCString());
444ac7ddfbfSEd Maste           }
445ac7ddfbfSEd Maste           return sb_process;
446ac7ddfbfSEd Maste         }
447ac7ddfbfSEd Maste       }
448ac7ddfbfSEd Maste     }
4491c3bbb01SEd Maste     error.SetError(AttachToProcess(attach_info, *target_sp));
450ac7ddfbfSEd Maste     if (error.Success())
4511c3bbb01SEd Maste       sb_process.SetSP(target_sp->GetProcessSP());
452435933ddSDimitry Andric   } else {
453ac7ddfbfSEd Maste     error.SetErrorString("SBTarget is invalid");
454ac7ddfbfSEd Maste   }
455ac7ddfbfSEd Maste 
456ac7ddfbfSEd Maste   if (log)
457ac7ddfbfSEd Maste     log->Printf("SBTarget(%p)::Attach (...) => SBProcess(%p)",
4580127ef0fSEd Maste                 static_cast<void *>(target_sp.get()),
4591c3bbb01SEd Maste                 static_cast<void *>(sb_process.GetSP().get()));
460ac7ddfbfSEd Maste 
461ac7ddfbfSEd Maste   return sb_process;
462ac7ddfbfSEd Maste }
463ac7ddfbfSEd Maste 
AttachToProcessWithID(SBListener & listener,lldb::pid_t pid,SBError & error)464435933ddSDimitry Andric lldb::SBProcess SBTarget::AttachToProcessWithID(
465ac7ddfbfSEd Maste     SBListener &listener,
466ac7ddfbfSEd Maste     lldb::pid_t pid, // The process ID to attach to
467ac7ddfbfSEd Maste     SBError &error   // An error explaining what went wrong if attach fails
468435933ddSDimitry Andric     ) {
469ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
470ac7ddfbfSEd Maste 
471ac7ddfbfSEd Maste   SBProcess sb_process;
472ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
473ac7ddfbfSEd Maste 
474ac7ddfbfSEd Maste   if (log)
4751c3bbb01SEd Maste     log->Printf("SBTarget(%p)::%s (listener, pid=%" PRId64 ", error)...",
476435933ddSDimitry Andric                 static_cast<void *>(target_sp.get()), __FUNCTION__, pid);
477ac7ddfbfSEd Maste 
478435933ddSDimitry Andric   if (target_sp) {
479ac7ddfbfSEd Maste     ProcessAttachInfo attach_info;
480ac7ddfbfSEd Maste     attach_info.SetProcessID(pid);
4811c3bbb01SEd Maste     if (listener.IsValid())
4821c3bbb01SEd Maste       attach_info.SetListener(listener.GetSP());
483ac7ddfbfSEd Maste 
484ac7ddfbfSEd Maste     ProcessInstanceInfo instance_info;
4851c3bbb01SEd Maste     if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info))
486ac7ddfbfSEd Maste       attach_info.SetUserID(instance_info.GetEffectiveUserID());
4871c3bbb01SEd Maste 
4881c3bbb01SEd Maste     error.SetError(AttachToProcess(attach_info, *target_sp));
489ac7ddfbfSEd Maste     if (error.Success())
4901c3bbb01SEd Maste       sb_process.SetSP(target_sp->GetProcessSP());
491435933ddSDimitry Andric   } else
492ac7ddfbfSEd Maste     error.SetErrorString("SBTarget is invalid");
493ac7ddfbfSEd Maste 
494ac7ddfbfSEd Maste   if (log)
4951c3bbb01SEd Maste     log->Printf("SBTarget(%p)::%s (...) => SBProcess(%p)",
496435933ddSDimitry Andric                 static_cast<void *>(target_sp.get()), __FUNCTION__,
4971c3bbb01SEd Maste                 static_cast<void *>(sb_process.GetSP().get()));
498ac7ddfbfSEd Maste   return sb_process;
499ac7ddfbfSEd Maste }
500ac7ddfbfSEd Maste 
AttachToProcessWithName(SBListener & listener,const char * name,bool wait_for,SBError & error)501435933ddSDimitry Andric lldb::SBProcess SBTarget::AttachToProcessWithName(
502ac7ddfbfSEd Maste     SBListener &listener,
503ac7ddfbfSEd Maste     const char *name, // basename of process to attach to
504ac7ddfbfSEd Maste     bool wait_for, // if true wait for a new instance of "name" to be launched
505ac7ddfbfSEd Maste     SBError &error // An error explaining what went wrong if attach fails
506435933ddSDimitry Andric     ) {
507ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
508ac7ddfbfSEd Maste 
509ac7ddfbfSEd Maste   SBProcess sb_process;
510ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
511ac7ddfbfSEd Maste 
512ac7ddfbfSEd Maste   if (log)
5131c3bbb01SEd Maste     log->Printf("SBTarget(%p)::%s (listener, name=%s, wait_for=%s, error)...",
514435933ddSDimitry Andric                 static_cast<void *>(target_sp.get()), __FUNCTION__, name,
5150127ef0fSEd Maste                 wait_for ? "true" : "false");
516ac7ddfbfSEd Maste 
517435933ddSDimitry Andric   if (name && target_sp) {
518ac7ddfbfSEd Maste     ProcessAttachInfo attach_info;
519*b5893f02SDimitry Andric     attach_info.GetExecutableFile().SetFile(name, FileSpec::Style::native);
520ac7ddfbfSEd Maste     attach_info.SetWaitForLaunch(wait_for);
5211c3bbb01SEd Maste     if (listener.IsValid())
5221c3bbb01SEd Maste       attach_info.SetListener(listener.GetSP());
5231c3bbb01SEd Maste 
5241c3bbb01SEd Maste     error.SetError(AttachToProcess(attach_info, *target_sp));
525ac7ddfbfSEd Maste     if (error.Success())
5261c3bbb01SEd Maste       sb_process.SetSP(target_sp->GetProcessSP());
527435933ddSDimitry Andric   } else
528ac7ddfbfSEd Maste     error.SetErrorString("SBTarget is invalid");
529ac7ddfbfSEd Maste 
530ac7ddfbfSEd Maste   if (log)
5311c3bbb01SEd Maste     log->Printf("SBTarget(%p)::%s (...) => SBProcess(%p)",
532435933ddSDimitry Andric                 static_cast<void *>(target_sp.get()), __FUNCTION__,
5331c3bbb01SEd Maste                 static_cast<void *>(sb_process.GetSP().get()));
534ac7ddfbfSEd Maste   return sb_process;
535ac7ddfbfSEd Maste }
536ac7ddfbfSEd Maste 
ConnectRemote(SBListener & listener,const char * url,const char * plugin_name,SBError & error)537435933ddSDimitry Andric lldb::SBProcess SBTarget::ConnectRemote(SBListener &listener, const char *url,
538ac7ddfbfSEd Maste                                         const char *plugin_name,
539435933ddSDimitry Andric                                         SBError &error) {
540ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
541ac7ddfbfSEd Maste 
542ac7ddfbfSEd Maste   SBProcess sb_process;
543ac7ddfbfSEd Maste   ProcessSP process_sp;
544ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
545ac7ddfbfSEd Maste 
546ac7ddfbfSEd Maste   if (log)
547435933ddSDimitry Andric     log->Printf("SBTarget(%p)::ConnectRemote (listener, url=%s, "
548435933ddSDimitry Andric                 "plugin_name=%s, error)...",
5490127ef0fSEd Maste                 static_cast<void *>(target_sp.get()), url, plugin_name);
550ac7ddfbfSEd Maste 
551435933ddSDimitry Andric   if (target_sp) {
5524bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
553ac7ddfbfSEd Maste     if (listener.IsValid())
554435933ddSDimitry Andric       process_sp =
555435933ddSDimitry Andric           target_sp->CreateProcess(listener.m_opaque_sp, plugin_name, NULL);
556ac7ddfbfSEd Maste     else
557435933ddSDimitry Andric       process_sp = target_sp->CreateProcess(
558435933ddSDimitry Andric           target_sp->GetDebugger().GetListener(), plugin_name, NULL);
559ac7ddfbfSEd Maste 
560435933ddSDimitry Andric     if (process_sp) {
561ac7ddfbfSEd Maste       sb_process.SetSP(process_sp);
562ac7ddfbfSEd Maste       error.SetError(process_sp->ConnectRemote(NULL, url));
563435933ddSDimitry Andric     } else {
564ac7ddfbfSEd Maste       error.SetErrorString("unable to create lldb_private::Process");
565ac7ddfbfSEd Maste     }
566435933ddSDimitry Andric   } else {
567ac7ddfbfSEd Maste     error.SetErrorString("SBTarget is invalid");
568ac7ddfbfSEd Maste   }
569ac7ddfbfSEd Maste 
570ac7ddfbfSEd Maste   if (log)
571ac7ddfbfSEd Maste     log->Printf("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)",
5720127ef0fSEd Maste                 static_cast<void *>(target_sp.get()),
5730127ef0fSEd Maste                 static_cast<void *>(process_sp.get()));
574ac7ddfbfSEd Maste   return sb_process;
575ac7ddfbfSEd Maste }
576ac7ddfbfSEd Maste 
GetExecutable()577435933ddSDimitry Andric SBFileSpec SBTarget::GetExecutable() {
578ac7ddfbfSEd Maste 
579ac7ddfbfSEd Maste   SBFileSpec exe_file_spec;
580ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
581435933ddSDimitry Andric   if (target_sp) {
582ac7ddfbfSEd Maste     Module *exe_module = target_sp->GetExecutableModulePointer();
583ac7ddfbfSEd Maste     if (exe_module)
584ac7ddfbfSEd Maste       exe_file_spec.SetFileSpec(exe_module->GetFileSpec());
585ac7ddfbfSEd Maste   }
586ac7ddfbfSEd Maste 
587ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
588435933ddSDimitry Andric   if (log) {
589ac7ddfbfSEd Maste     log->Printf("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)",
5900127ef0fSEd Maste                 static_cast<void *>(target_sp.get()),
5910127ef0fSEd Maste                 static_cast<const void *>(exe_file_spec.get()));
592ac7ddfbfSEd Maste   }
593ac7ddfbfSEd Maste 
594ac7ddfbfSEd Maste   return exe_file_spec;
595ac7ddfbfSEd Maste }
596ac7ddfbfSEd Maste 
operator ==(const SBTarget & rhs) const597435933ddSDimitry Andric bool SBTarget::operator==(const SBTarget &rhs) const {
598ac7ddfbfSEd Maste   return m_opaque_sp.get() == rhs.m_opaque_sp.get();
599ac7ddfbfSEd Maste }
600ac7ddfbfSEd Maste 
operator !=(const SBTarget & rhs) const601435933ddSDimitry Andric bool SBTarget::operator!=(const SBTarget &rhs) const {
602ac7ddfbfSEd Maste   return m_opaque_sp.get() != rhs.m_opaque_sp.get();
603ac7ddfbfSEd Maste }
604ac7ddfbfSEd Maste 
GetSP() const605435933ddSDimitry Andric lldb::TargetSP SBTarget::GetSP() const { return m_opaque_sp; }
606ac7ddfbfSEd Maste 
SetSP(const lldb::TargetSP & target_sp)607435933ddSDimitry Andric void SBTarget::SetSP(const lldb::TargetSP &target_sp) {
608ac7ddfbfSEd Maste   m_opaque_sp = target_sp;
609ac7ddfbfSEd Maste }
610ac7ddfbfSEd Maste 
ResolveLoadAddress(lldb::addr_t vm_addr)611435933ddSDimitry Andric lldb::SBAddress SBTarget::ResolveLoadAddress(lldb::addr_t vm_addr) {
612ac7ddfbfSEd Maste   lldb::SBAddress sb_addr;
613ac7ddfbfSEd Maste   Address &addr = sb_addr.ref();
614ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
615435933ddSDimitry Andric   if (target_sp) {
6164bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
61712b93ac6SEd Maste     if (target_sp->ResolveLoadAddress(vm_addr, addr))
61812b93ac6SEd Maste       return sb_addr;
61912b93ac6SEd Maste   }
62012b93ac6SEd Maste 
62112b93ac6SEd Maste   // We have a load address that isn't in a section, just return an address
62212b93ac6SEd Maste   // with the offset filled in (the address) and the section set to NULL
62312b93ac6SEd Maste   addr.SetRawAddress(vm_addr);
62412b93ac6SEd Maste   return sb_addr;
62512b93ac6SEd Maste }
62612b93ac6SEd Maste 
ResolveFileAddress(lldb::addr_t file_addr)627435933ddSDimitry Andric lldb::SBAddress SBTarget::ResolveFileAddress(lldb::addr_t file_addr) {
6287aa51b79SEd Maste   lldb::SBAddress sb_addr;
6297aa51b79SEd Maste   Address &addr = sb_addr.ref();
6307aa51b79SEd Maste   TargetSP target_sp(GetSP());
631435933ddSDimitry Andric   if (target_sp) {
6324bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
6337aa51b79SEd Maste     if (target_sp->ResolveFileAddress(file_addr, addr))
6347aa51b79SEd Maste       return sb_addr;
6357aa51b79SEd Maste   }
6367aa51b79SEd Maste 
6377aa51b79SEd Maste   addr.SetRawAddress(file_addr);
6387aa51b79SEd Maste   return sb_addr;
6397aa51b79SEd Maste }
64012b93ac6SEd Maste 
ResolvePastLoadAddress(uint32_t stop_id,lldb::addr_t vm_addr)641435933ddSDimitry Andric lldb::SBAddress SBTarget::ResolvePastLoadAddress(uint32_t stop_id,
642435933ddSDimitry Andric                                                  lldb::addr_t vm_addr) {
64312b93ac6SEd Maste   lldb::SBAddress sb_addr;
64412b93ac6SEd Maste   Address &addr = sb_addr.ref();
64512b93ac6SEd Maste   TargetSP target_sp(GetSP());
646435933ddSDimitry Andric   if (target_sp) {
6474bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
64812b93ac6SEd Maste     if (target_sp->ResolveLoadAddress(vm_addr, addr))
649ac7ddfbfSEd Maste       return sb_addr;
650ac7ddfbfSEd Maste   }
651ac7ddfbfSEd Maste 
652ac7ddfbfSEd Maste   // We have a load address that isn't in a section, just return an address
653ac7ddfbfSEd Maste   // with the offset filled in (the address) and the section set to NULL
654ac7ddfbfSEd Maste   addr.SetRawAddress(vm_addr);
655ac7ddfbfSEd Maste   return sb_addr;
656ac7ddfbfSEd Maste }
657ac7ddfbfSEd Maste 
658ac7ddfbfSEd Maste SBSymbolContext
ResolveSymbolContextForAddress(const SBAddress & addr,uint32_t resolve_scope)65935617911SEd Maste SBTarget::ResolveSymbolContextForAddress(const SBAddress &addr,
660435933ddSDimitry Andric                                          uint32_t resolve_scope) {
661ac7ddfbfSEd Maste   SBSymbolContext sc;
662*b5893f02SDimitry Andric   SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
663435933ddSDimitry Andric   if (addr.IsValid()) {
664ac7ddfbfSEd Maste     TargetSP target_sp(GetSP());
665ac7ddfbfSEd Maste     if (target_sp)
666*b5893f02SDimitry Andric       target_sp->GetImages().ResolveSymbolContextForAddress(addr.ref(), scope,
667*b5893f02SDimitry Andric                                                             sc.ref());
668ac7ddfbfSEd Maste   }
669ac7ddfbfSEd Maste   return sc;
670ac7ddfbfSEd Maste }
671ac7ddfbfSEd Maste 
ReadMemory(const SBAddress addr,void * buf,size_t size,lldb::SBError & error)672435933ddSDimitry Andric size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size,
673435933ddSDimitry Andric                             lldb::SBError &error) {
6747aa51b79SEd Maste   SBError sb_error;
6757aa51b79SEd Maste   size_t bytes_read = 0;
6767aa51b79SEd Maste   TargetSP target_sp(GetSP());
677435933ddSDimitry Andric   if (target_sp) {
6784bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
679435933ddSDimitry Andric     bytes_read =
680435933ddSDimitry Andric         target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref());
681435933ddSDimitry Andric   } else {
6827aa51b79SEd Maste     sb_error.SetErrorString("invalid target");
6837aa51b79SEd Maste   }
6847aa51b79SEd Maste 
6857aa51b79SEd Maste   return bytes_read;
6867aa51b79SEd Maste }
687ac7ddfbfSEd Maste 
BreakpointCreateByLocation(const char * file,uint32_t line)688435933ddSDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByLocation(const char *file,
689435933ddSDimitry Andric                                                   uint32_t line) {
690435933ddSDimitry Andric   return SBBreakpoint(
691435933ddSDimitry Andric       BreakpointCreateByLocation(SBFileSpec(file, false), line));
692ac7ddfbfSEd Maste }
693ac7ddfbfSEd Maste 
694ac7ddfbfSEd Maste SBBreakpoint
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line)69535617911SEd Maste SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
696435933ddSDimitry Andric                                      uint32_t line) {
6974bb0738eSEd Maste   return BreakpointCreateByLocation(sb_file_spec, line, 0);
6984bb0738eSEd Maste }
6994bb0738eSEd Maste 
7004bb0738eSEd Maste SBBreakpoint
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,lldb::addr_t offset)7014bb0738eSEd Maste SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
702435933ddSDimitry Andric                                      uint32_t line, lldb::addr_t offset) {
703435933ddSDimitry Andric   SBFileSpecList empty_list;
704435933ddSDimitry Andric   return BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list);
705435933ddSDimitry Andric }
706435933ddSDimitry Andric 
707435933ddSDimitry Andric SBBreakpoint
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,lldb::addr_t offset,SBFileSpecList & sb_module_list)708435933ddSDimitry Andric SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
709435933ddSDimitry Andric                                      uint32_t line, lldb::addr_t offset,
710435933ddSDimitry Andric                                      SBFileSpecList &sb_module_list) {
711*b5893f02SDimitry Andric   return BreakpointCreateByLocation(sb_file_spec, line, 0, offset,
712*b5893f02SDimitry Andric                                     sb_module_list);
713*b5893f02SDimitry Andric }
714*b5893f02SDimitry Andric 
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,uint32_t column,lldb::addr_t offset,SBFileSpecList & sb_module_list)715*b5893f02SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByLocation(
716*b5893f02SDimitry Andric     const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
717*b5893f02SDimitry Andric     lldb::addr_t offset, SBFileSpecList &sb_module_list) {
718ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
719ac7ddfbfSEd Maste 
720ac7ddfbfSEd Maste   SBBreakpoint sb_bp;
721ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
722435933ddSDimitry Andric   if (target_sp && line != 0) {
7234bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
724ac7ddfbfSEd Maste 
725ac7ddfbfSEd Maste     const LazyBool check_inlines = eLazyBoolCalculate;
726ac7ddfbfSEd Maste     const LazyBool skip_prologue = eLazyBoolCalculate;
727ac7ddfbfSEd Maste     const bool internal = false;
72835617911SEd Maste     const bool hardware = false;
7291c3bbb01SEd Maste     const LazyBool move_to_nearest_code = eLazyBoolCalculate;
730435933ddSDimitry Andric     const FileSpecList *module_list = nullptr;
731435933ddSDimitry Andric     if (sb_module_list.GetSize() > 0) {
732435933ddSDimitry Andric       module_list = sb_module_list.get();
733435933ddSDimitry Andric     }
734f678e45dSDimitry Andric     sb_bp = target_sp->CreateBreakpoint(
735*b5893f02SDimitry Andric         module_list, *sb_file_spec, line, column, offset, check_inlines,
736*b5893f02SDimitry Andric         skip_prologue, internal, hardware, move_to_nearest_code);
737ac7ddfbfSEd Maste   }
738ac7ddfbfSEd Maste 
739435933ddSDimitry Andric   if (log) {
740ac7ddfbfSEd Maste     SBStream sstr;
741ac7ddfbfSEd Maste     sb_bp.GetDescription(sstr);
742ac7ddfbfSEd Maste     char path[PATH_MAX];
743ac7ddfbfSEd Maste     sb_file_spec->GetPath(path, sizeof(path));
744435933ddSDimitry Andric     log->Printf("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => "
745435933ddSDimitry Andric                 "SBBreakpoint(%p): %s",
7460127ef0fSEd Maste                 static_cast<void *>(target_sp.get()), path, line,
747f678e45dSDimitry Andric                 static_cast<void *>(sb_bp.GetSP().get()), sstr.GetData());
748ac7ddfbfSEd Maste   }
749ac7ddfbfSEd Maste 
750ac7ddfbfSEd Maste   return sb_bp;
751ac7ddfbfSEd Maste }
752ac7ddfbfSEd Maste 
BreakpointCreateByName(const char * symbol_name,const char * module_name)753435933ddSDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name,
754435933ddSDimitry Andric                                               const char *module_name) {
755ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
756ac7ddfbfSEd Maste 
757ac7ddfbfSEd Maste   SBBreakpoint sb_bp;
758ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
759435933ddSDimitry Andric   if (target_sp.get()) {
7604bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
761ac7ddfbfSEd Maste 
762ac7ddfbfSEd Maste     const bool internal = false;
76335617911SEd Maste     const bool hardware = false;
764ac7ddfbfSEd Maste     const LazyBool skip_prologue = eLazyBoolCalculate;
7654bb0738eSEd Maste     const lldb::addr_t offset = 0;
766435933ddSDimitry Andric     if (module_name && module_name[0]) {
767ac7ddfbfSEd Maste       FileSpecList module_spec_list;
768*b5893f02SDimitry Andric       module_spec_list.Append(FileSpec(module_name));
769f678e45dSDimitry Andric       sb_bp = target_sp->CreateBreakpoint(
770435933ddSDimitry Andric           &module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto,
771435933ddSDimitry Andric           eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
772435933ddSDimitry Andric     } else {
773f678e45dSDimitry Andric       sb_bp = target_sp->CreateBreakpoint(
774435933ddSDimitry Andric           NULL, NULL, symbol_name, eFunctionNameTypeAuto, eLanguageTypeUnknown,
775435933ddSDimitry Andric           offset, skip_prologue, internal, hardware);
776ac7ddfbfSEd Maste     }
777ac7ddfbfSEd Maste   }
778ac7ddfbfSEd Maste 
779ac7ddfbfSEd Maste   if (log)
780435933ddSDimitry Andric     log->Printf("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", "
781435933ddSDimitry Andric                 "module=\"%s\") => SBBreakpoint(%p)",
782435933ddSDimitry Andric                 static_cast<void *>(target_sp.get()), symbol_name, module_name,
783f678e45dSDimitry Andric                 static_cast<void *>(sb_bp.GetSP().get()));
784ac7ddfbfSEd Maste 
785ac7ddfbfSEd Maste   return sb_bp;
786ac7ddfbfSEd Maste }
787ac7ddfbfSEd Maste 
788ac7ddfbfSEd Maste lldb::SBBreakpoint
BreakpointCreateByName(const char * symbol_name,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)789ac7ddfbfSEd Maste SBTarget::BreakpointCreateByName(const char *symbol_name,
790ac7ddfbfSEd Maste                                  const SBFileSpecList &module_list,
791435933ddSDimitry Andric                                  const SBFileSpecList &comp_unit_list) {
792*b5893f02SDimitry Andric   lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto;
793435933ddSDimitry Andric   return BreakpointCreateByName(symbol_name, name_type_mask,
794435933ddSDimitry Andric                                 eLanguageTypeUnknown, module_list,
795435933ddSDimitry Andric                                 comp_unit_list);
796ac7ddfbfSEd Maste }
797ac7ddfbfSEd Maste 
BreakpointCreateByName(const char * symbol_name,uint32_t name_type_mask,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)798435933ddSDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
799435933ddSDimitry Andric     const char *symbol_name, uint32_t name_type_mask,
800435933ddSDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
801435933ddSDimitry Andric   return BreakpointCreateByName(symbol_name, name_type_mask,
802435933ddSDimitry Andric                                 eLanguageTypeUnknown, module_list,
803435933ddSDimitry Andric                                 comp_unit_list);
8049f2f44ceSEd Maste }
8059f2f44ceSEd Maste 
BreakpointCreateByName(const char * symbol_name,uint32_t name_type_mask,LanguageType symbol_language,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)806435933ddSDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
807435933ddSDimitry Andric     const char *symbol_name, uint32_t name_type_mask,
808435933ddSDimitry Andric     LanguageType symbol_language, const SBFileSpecList &module_list,
809435933ddSDimitry Andric     const SBFileSpecList &comp_unit_list) {
810ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
811ac7ddfbfSEd Maste 
812ac7ddfbfSEd Maste   SBBreakpoint sb_bp;
813ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
814435933ddSDimitry Andric   if (target_sp && symbol_name && symbol_name[0]) {
815ac7ddfbfSEd Maste     const bool internal = false;
81635617911SEd Maste     const bool hardware = false;
817ac7ddfbfSEd Maste     const LazyBool skip_prologue = eLazyBoolCalculate;
8184bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
819*b5893f02SDimitry Andric     FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
820*b5893f02SDimitry Andric     sb_bp = target_sp->CreateBreakpoint(module_list.get(), comp_unit_list.get(),
821*b5893f02SDimitry Andric                                         symbol_name, mask, symbol_language, 0,
822*b5893f02SDimitry Andric                                         skip_prologue, internal, hardware);
823ac7ddfbfSEd Maste   }
824ac7ddfbfSEd Maste 
825ac7ddfbfSEd Maste   if (log)
826435933ddSDimitry Andric     log->Printf("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", "
827435933ddSDimitry Andric                 "name_type: %d) => SBBreakpoint(%p)",
8280127ef0fSEd Maste                 static_cast<void *>(target_sp.get()), symbol_name,
829f678e45dSDimitry Andric                 name_type_mask, static_cast<void *>(sb_bp.GetSP().get()));
830ac7ddfbfSEd Maste 
831ac7ddfbfSEd Maste   return sb_bp;
832ac7ddfbfSEd Maste }
833ac7ddfbfSEd Maste 
BreakpointCreateByNames(const char * symbol_names[],uint32_t num_names,uint32_t name_type_mask,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)834435933ddSDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
835435933ddSDimitry Andric     const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
836435933ddSDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
837435933ddSDimitry Andric   return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
838435933ddSDimitry Andric                                  eLanguageTypeUnknown, module_list,
839435933ddSDimitry Andric                                  comp_unit_list);
8409f2f44ceSEd Maste }
8419f2f44ceSEd Maste 
BreakpointCreateByNames(const char * symbol_names[],uint32_t num_names,uint32_t name_type_mask,LanguageType symbol_language,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)842435933ddSDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
843435933ddSDimitry Andric     const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
844435933ddSDimitry Andric     LanguageType symbol_language, const SBFileSpecList &module_list,
845435933ddSDimitry Andric     const SBFileSpecList &comp_unit_list) {
846435933ddSDimitry Andric   return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
847435933ddSDimitry Andric                                  eLanguageTypeUnknown, 0, module_list,
848435933ddSDimitry Andric                                  comp_unit_list);
8494bb0738eSEd Maste }
8504bb0738eSEd Maste 
BreakpointCreateByNames(const char * symbol_names[],uint32_t num_names,uint32_t name_type_mask,LanguageType symbol_language,lldb::addr_t offset,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)851435933ddSDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
852435933ddSDimitry Andric     const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
853435933ddSDimitry Andric     LanguageType symbol_language, lldb::addr_t offset,
854435933ddSDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
855ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
856ac7ddfbfSEd Maste 
857ac7ddfbfSEd Maste   SBBreakpoint sb_bp;
858ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
859435933ddSDimitry Andric   if (target_sp && num_names > 0) {
8604bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
861ac7ddfbfSEd Maste     const bool internal = false;
86235617911SEd Maste     const bool hardware = false;
863*b5893f02SDimitry Andric     FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
864ac7ddfbfSEd Maste     const LazyBool skip_prologue = eLazyBoolCalculate;
865f678e45dSDimitry Andric     sb_bp = target_sp->CreateBreakpoint(
866*b5893f02SDimitry Andric         module_list.get(), comp_unit_list.get(), symbol_names, num_names, mask,
867*b5893f02SDimitry Andric         symbol_language, offset, skip_prologue, internal, hardware);
868ac7ddfbfSEd Maste   }
869ac7ddfbfSEd Maste 
870435933ddSDimitry Andric   if (log) {
8710127ef0fSEd Maste     log->Printf("SBTarget(%p)::BreakpointCreateByName (symbols={",
8720127ef0fSEd Maste                 static_cast<void *>(target_sp.get()));
873435933ddSDimitry Andric     for (uint32_t i = 0; i < num_names; i++) {
874ac7ddfbfSEd Maste       char sep;
875ac7ddfbfSEd Maste       if (i < num_names - 1)
876ac7ddfbfSEd Maste         sep = ',';
877ac7ddfbfSEd Maste       else
878ac7ddfbfSEd Maste         sep = '}';
879ac7ddfbfSEd Maste       if (symbol_names[i] != NULL)
880ac7ddfbfSEd Maste         log->Printf("\"%s\"%c ", symbol_names[i], sep);
881ac7ddfbfSEd Maste       else
882ac7ddfbfSEd Maste         log->Printf("\"<NULL>\"%c ", sep);
883ac7ddfbfSEd Maste     }
8840127ef0fSEd Maste     log->Printf("name_type: %d) => SBBreakpoint(%p)", name_type_mask,
885f678e45dSDimitry Andric                 static_cast<void *>(sb_bp.GetSP().get()));
886ac7ddfbfSEd Maste   }
887ac7ddfbfSEd Maste 
888ac7ddfbfSEd Maste   return sb_bp;
889ac7ddfbfSEd Maste }
890ac7ddfbfSEd Maste 
BreakpointCreateByRegex(const char * symbol_name_regex,const char * module_name)891435933ddSDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
892435933ddSDimitry Andric                                                const char *module_name) {
8939f2f44ceSEd Maste   SBFileSpecList module_spec_list;
8949f2f44ceSEd Maste   SBFileSpecList comp_unit_list;
895435933ddSDimitry Andric   if (module_name && module_name[0]) {
896*b5893f02SDimitry Andric     module_spec_list.Append(FileSpec(module_name));
897ac7ddfbfSEd Maste   }
898435933ddSDimitry Andric   return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
899435933ddSDimitry Andric                                  module_spec_list, comp_unit_list);
900ac7ddfbfSEd Maste }
901ac7ddfbfSEd Maste 
902ac7ddfbfSEd Maste lldb::SBBreakpoint
BreakpointCreateByRegex(const char * symbol_name_regex,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)903ac7ddfbfSEd Maste SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
904ac7ddfbfSEd Maste                                   const SBFileSpecList &module_list,
905435933ddSDimitry Andric                                   const SBFileSpecList &comp_unit_list) {
906435933ddSDimitry Andric   return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
907435933ddSDimitry Andric                                  module_list, comp_unit_list);
9089f2f44ceSEd Maste }
9099f2f44ceSEd Maste 
BreakpointCreateByRegex(const char * symbol_name_regex,LanguageType symbol_language,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)910435933ddSDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByRegex(
911435933ddSDimitry Andric     const char *symbol_name_regex, LanguageType symbol_language,
912435933ddSDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
913ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
914ac7ddfbfSEd Maste 
915ac7ddfbfSEd Maste   SBBreakpoint sb_bp;
916ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
917435933ddSDimitry Andric   if (target_sp && symbol_name_regex && symbol_name_regex[0]) {
9184bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
919435933ddSDimitry Andric     RegularExpression regexp((llvm::StringRef(symbol_name_regex)));
920ac7ddfbfSEd Maste     const bool internal = false;
92135617911SEd Maste     const bool hardware = false;
922ac7ddfbfSEd Maste     const LazyBool skip_prologue = eLazyBoolCalculate;
923ac7ddfbfSEd Maste 
924f678e45dSDimitry Andric     sb_bp = target_sp->CreateFuncRegexBreakpoint(
925435933ddSDimitry Andric         module_list.get(), comp_unit_list.get(), regexp, symbol_language,
926435933ddSDimitry Andric         skip_prologue, internal, hardware);
927ac7ddfbfSEd Maste   }
928ac7ddfbfSEd Maste 
929ac7ddfbfSEd Maste   if (log)
930435933ddSDimitry Andric     log->Printf("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") "
931435933ddSDimitry Andric                 "=> SBBreakpoint(%p)",
9320127ef0fSEd Maste                 static_cast<void *>(target_sp.get()), symbol_name_regex,
933f678e45dSDimitry Andric                 static_cast<void *>(sb_bp.GetSP().get()));
934ac7ddfbfSEd Maste 
935ac7ddfbfSEd Maste   return sb_bp;
936ac7ddfbfSEd Maste }
937ac7ddfbfSEd Maste 
BreakpointCreateByAddress(addr_t address)938435933ddSDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByAddress(addr_t address) {
939ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
940ac7ddfbfSEd Maste 
941ac7ddfbfSEd Maste   SBBreakpoint sb_bp;
942ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
943435933ddSDimitry Andric   if (target_sp) {
9444bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
94535617911SEd Maste     const bool hardware = false;
946f678e45dSDimitry Andric     sb_bp = target_sp->CreateBreakpoint(address, false, hardware);
947ac7ddfbfSEd Maste   }
948ac7ddfbfSEd Maste 
949ac7ddfbfSEd Maste   if (log)
950435933ddSDimitry Andric     log->Printf("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64
951435933ddSDimitry Andric                 ") => SBBreakpoint(%p)",
9520127ef0fSEd Maste                 static_cast<void *>(target_sp.get()),
9530127ef0fSEd Maste                 static_cast<uint64_t>(address),
954f678e45dSDimitry Andric                 static_cast<void *>(sb_bp.GetSP().get()));
955ac7ddfbfSEd Maste 
956ac7ddfbfSEd Maste   return sb_bp;
957ac7ddfbfSEd Maste }
958ac7ddfbfSEd Maste 
BreakpointCreateBySBAddress(SBAddress & sb_address)959435933ddSDimitry Andric SBBreakpoint SBTarget::BreakpointCreateBySBAddress(SBAddress &sb_address) {
9609f2f44ceSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
9619f2f44ceSEd Maste 
9629f2f44ceSEd Maste   SBBreakpoint sb_bp;
9639f2f44ceSEd Maste   TargetSP target_sp(GetSP());
964435933ddSDimitry Andric   if (!sb_address.IsValid()) {
9659f2f44ceSEd Maste     if (log)
966435933ddSDimitry Andric       log->Printf("SBTarget(%p)::BreakpointCreateBySBAddress called with "
967435933ddSDimitry Andric                   "invalid address",
9689f2f44ceSEd Maste                   static_cast<void *>(target_sp.get()));
9699f2f44ceSEd Maste     return sb_bp;
9709f2f44ceSEd Maste   }
9719f2f44ceSEd Maste 
972435933ddSDimitry Andric   if (target_sp) {
9734bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
9749f2f44ceSEd Maste     const bool hardware = false;
975f678e45dSDimitry Andric     sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware);
9769f2f44ceSEd Maste   }
9779f2f44ceSEd Maste 
978435933ddSDimitry Andric   if (log) {
9799f2f44ceSEd Maste     SBStream s;
9809f2f44ceSEd Maste     sb_address.GetDescription(s);
981435933ddSDimitry Andric     log->Printf("SBTarget(%p)::BreakpointCreateBySBAddress (address=%s) => "
982435933ddSDimitry Andric                 "SBBreakpoint(%p)",
983435933ddSDimitry Andric                 static_cast<void *>(target_sp.get()), s.GetData(),
984f678e45dSDimitry Andric                 static_cast<void *>(sb_bp.GetSP().get()));
9859f2f44ceSEd Maste   }
9869f2f44ceSEd Maste 
9879f2f44ceSEd Maste   return sb_bp;
9889f2f44ceSEd Maste }
9899f2f44ceSEd Maste 
990ac7ddfbfSEd Maste lldb::SBBreakpoint
BreakpointCreateBySourceRegex(const char * source_regex,const lldb::SBFileSpec & source_file,const char * module_name)99135617911SEd Maste SBTarget::BreakpointCreateBySourceRegex(const char *source_regex,
99235617911SEd Maste                                         const lldb::SBFileSpec &source_file,
993435933ddSDimitry Andric                                         const char *module_name) {
9944bb0738eSEd Maste   SBFileSpecList module_spec_list;
995ac7ddfbfSEd Maste 
996435933ddSDimitry Andric   if (module_name && module_name[0]) {
997*b5893f02SDimitry Andric     module_spec_list.Append(FileSpec(module_name));
998ac7ddfbfSEd Maste   }
9994bb0738eSEd Maste 
10004bb0738eSEd Maste   SBFileSpecList source_file_list;
1001435933ddSDimitry Andric   if (source_file.IsValid()) {
10024bb0738eSEd Maste     source_file_list.Append(source_file);
1003ac7ddfbfSEd Maste   }
1004ac7ddfbfSEd Maste 
1005435933ddSDimitry Andric   return BreakpointCreateBySourceRegex(source_regex, module_spec_list,
1006435933ddSDimitry Andric                                        source_file_list);
1007ac7ddfbfSEd Maste }
1008ac7ddfbfSEd Maste 
BreakpointCreateBySourceRegex(const char * source_regex,const SBFileSpecList & module_list,const lldb::SBFileSpecList & source_file_list)1009435933ddSDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
1010435933ddSDimitry Andric     const char *source_regex, const SBFileSpecList &module_list,
1011435933ddSDimitry Andric     const lldb::SBFileSpecList &source_file_list) {
1012435933ddSDimitry Andric   return BreakpointCreateBySourceRegex(source_regex, module_list,
1013435933ddSDimitry Andric                                        source_file_list, SBStringList());
10144bb0738eSEd Maste }
10154bb0738eSEd Maste 
BreakpointCreateBySourceRegex(const char * source_regex,const SBFileSpecList & module_list,const lldb::SBFileSpecList & source_file_list,const SBStringList & func_names)1016435933ddSDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
1017435933ddSDimitry Andric     const char *source_regex, const SBFileSpecList &module_list,
10184bb0738eSEd Maste     const lldb::SBFileSpecList &source_file_list,
1019435933ddSDimitry Andric     const SBStringList &func_names) {
1020ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1021ac7ddfbfSEd Maste 
1022ac7ddfbfSEd Maste   SBBreakpoint sb_bp;
1023ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1024435933ddSDimitry Andric   if (target_sp && source_regex && source_regex[0]) {
10254bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
102635617911SEd Maste     const bool hardware = false;
10271c3bbb01SEd Maste     const LazyBool move_to_nearest_code = eLazyBoolCalculate;
1028435933ddSDimitry Andric     RegularExpression regexp((llvm::StringRef(source_regex)));
10294bb0738eSEd Maste     std::unordered_set<std::string> func_names_set;
1030435933ddSDimitry Andric     for (size_t i = 0; i < func_names.GetSize(); i++) {
10314bb0738eSEd Maste       func_names_set.insert(func_names.GetStringAtIndex(i));
10324bb0738eSEd Maste     }
10334bb0738eSEd Maste 
1034f678e45dSDimitry Andric     sb_bp = target_sp->CreateSourceRegexBreakpoint(
1035435933ddSDimitry Andric         module_list.get(), source_file_list.get(), func_names_set, regexp,
1036435933ddSDimitry Andric         false, hardware, move_to_nearest_code);
1037ac7ddfbfSEd Maste   }
1038ac7ddfbfSEd Maste 
1039ac7ddfbfSEd Maste   if (log)
1040435933ddSDimitry Andric     log->Printf("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") "
1041435933ddSDimitry Andric                 "=> SBBreakpoint(%p)",
10420127ef0fSEd Maste                 static_cast<void *>(target_sp.get()), source_regex,
1043f678e45dSDimitry Andric                 static_cast<void *>(sb_bp.GetSP().get()));
1044ac7ddfbfSEd Maste 
1045ac7ddfbfSEd Maste   return sb_bp;
1046ac7ddfbfSEd Maste }
1047ac7ddfbfSEd Maste 
1048ac7ddfbfSEd Maste lldb::SBBreakpoint
BreakpointCreateForException(lldb::LanguageType language,bool catch_bp,bool throw_bp)1049ac7ddfbfSEd Maste SBTarget::BreakpointCreateForException(lldb::LanguageType language,
1050435933ddSDimitry Andric                                        bool catch_bp, bool throw_bp) {
1051ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1052ac7ddfbfSEd Maste 
1053ac7ddfbfSEd Maste   SBBreakpoint sb_bp;
1054ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1055435933ddSDimitry Andric   if (target_sp) {
10564bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
105735617911SEd Maste     const bool hardware = false;
1058f678e45dSDimitry Andric     sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
1059435933ddSDimitry Andric                                                   hardware);
1060ac7ddfbfSEd Maste   }
1061ac7ddfbfSEd Maste 
1062ac7ddfbfSEd Maste   if (log)
1063*b5893f02SDimitry Andric     log->Printf("SBTarget(%p)::BreakpointCreateForException (Language: %s, catch: "
1064435933ddSDimitry Andric                 "%s throw: %s) => SBBreakpoint(%p)",
10650127ef0fSEd Maste                 static_cast<void *>(target_sp.get()),
10669f2f44ceSEd Maste                 Language::GetNameForLanguageType(language),
10670127ef0fSEd Maste                 catch_bp ? "on" : "off", throw_bp ? "on" : "off",
1068f678e45dSDimitry Andric                 static_cast<void *>(sb_bp.GetSP().get()));
1069ac7ddfbfSEd Maste 
1070ac7ddfbfSEd Maste   return sb_bp;
1071ac7ddfbfSEd Maste }
1072ac7ddfbfSEd Maste 
1073*b5893f02SDimitry Andric lldb::SBBreakpoint
BreakpointCreateFromScript(const char * class_name,SBStructuredData & extra_args,const SBFileSpecList & module_list,const SBFileSpecList & file_list,bool request_hardware)1074*b5893f02SDimitry Andric SBTarget::BreakpointCreateFromScript(const char *class_name,
1075*b5893f02SDimitry Andric                                      SBStructuredData &extra_args,
1076*b5893f02SDimitry Andric                                      const SBFileSpecList &module_list,
1077*b5893f02SDimitry Andric                                      const SBFileSpecList &file_list,
1078*b5893f02SDimitry Andric                                      bool request_hardware)
1079*b5893f02SDimitry Andric {
1080*b5893f02SDimitry Andric   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1081*b5893f02SDimitry Andric 
1082*b5893f02SDimitry Andric   SBBreakpoint sb_bp;
1083*b5893f02SDimitry Andric   TargetSP target_sp(GetSP());
1084*b5893f02SDimitry Andric   if (target_sp) {
1085*b5893f02SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1086*b5893f02SDimitry Andric     Status error;
1087*b5893f02SDimitry Andric 
1088*b5893f02SDimitry Andric     StructuredData::ObjectSP obj_sp = extra_args.m_impl_up->GetObjectSP();
1089*b5893f02SDimitry Andric     sb_bp =
1090*b5893f02SDimitry Andric         target_sp->CreateScriptedBreakpoint(class_name,
1091*b5893f02SDimitry Andric                                             module_list.get(),
1092*b5893f02SDimitry Andric                                             file_list.get(),
1093*b5893f02SDimitry Andric                                             false, /* internal */
1094*b5893f02SDimitry Andric                                             request_hardware,
1095*b5893f02SDimitry Andric                                             obj_sp,
1096*b5893f02SDimitry Andric                                             &error);
1097*b5893f02SDimitry Andric   }
1098*b5893f02SDimitry Andric   if (log)
1099*b5893f02SDimitry Andric     log->Printf("SBTarget(%p)::BreakpointCreateFromScript (class name: %s) "
1100*b5893f02SDimitry Andric                 " => SBBreakpoint(%p)",
1101*b5893f02SDimitry Andric                 static_cast<void *>(target_sp.get()),
1102*b5893f02SDimitry Andric                 class_name,
1103*b5893f02SDimitry Andric                 static_cast<void *>(sb_bp.GetSP().get()));
1104*b5893f02SDimitry Andric 
1105*b5893f02SDimitry Andric   return sb_bp;
1106*b5893f02SDimitry Andric }
1107*b5893f02SDimitry Andric 
1108*b5893f02SDimitry Andric 
GetNumBreakpoints() const1109435933ddSDimitry Andric uint32_t SBTarget::GetNumBreakpoints() const {
1110ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1111435933ddSDimitry Andric   if (target_sp) {
1112ac7ddfbfSEd Maste     // The breakpoint list is thread safe, no need to lock
1113ac7ddfbfSEd Maste     return target_sp->GetBreakpointList().GetSize();
1114ac7ddfbfSEd Maste   }
1115ac7ddfbfSEd Maste   return 0;
1116ac7ddfbfSEd Maste }
1117ac7ddfbfSEd Maste 
GetBreakpointAtIndex(uint32_t idx) const1118435933ddSDimitry Andric SBBreakpoint SBTarget::GetBreakpointAtIndex(uint32_t idx) const {
1119ac7ddfbfSEd Maste   SBBreakpoint sb_breakpoint;
1120ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1121435933ddSDimitry Andric   if (target_sp) {
1122ac7ddfbfSEd Maste     // The breakpoint list is thread safe, no need to lock
1123f678e45dSDimitry Andric     sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1124ac7ddfbfSEd Maste   }
1125ac7ddfbfSEd Maste   return sb_breakpoint;
1126ac7ddfbfSEd Maste }
1127ac7ddfbfSEd Maste 
BreakpointDelete(break_id_t bp_id)1128435933ddSDimitry Andric bool SBTarget::BreakpointDelete(break_id_t bp_id) {
1129ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1130ac7ddfbfSEd Maste 
1131ac7ddfbfSEd Maste   bool result = false;
1132ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1133435933ddSDimitry Andric   if (target_sp) {
11344bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1135ac7ddfbfSEd Maste     result = target_sp->RemoveBreakpointByID(bp_id);
1136ac7ddfbfSEd Maste   }
1137ac7ddfbfSEd Maste 
1138ac7ddfbfSEd Maste   if (log)
11390127ef0fSEd Maste     log->Printf("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i",
11400127ef0fSEd Maste                 static_cast<void *>(target_sp.get()),
11410127ef0fSEd Maste                 static_cast<uint32_t>(bp_id), result);
1142ac7ddfbfSEd Maste 
1143ac7ddfbfSEd Maste   return result;
1144ac7ddfbfSEd Maste }
1145ac7ddfbfSEd Maste 
FindBreakpointByID(break_id_t bp_id)1146435933ddSDimitry Andric SBBreakpoint SBTarget::FindBreakpointByID(break_id_t bp_id) {
1147ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1148ac7ddfbfSEd Maste 
1149ac7ddfbfSEd Maste   SBBreakpoint sb_breakpoint;
1150ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1151435933ddSDimitry Andric   if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) {
11524bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1153f678e45dSDimitry Andric     sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
1154ac7ddfbfSEd Maste   }
1155ac7ddfbfSEd Maste 
1156ac7ddfbfSEd Maste   if (log)
1157435933ddSDimitry Andric     log->Printf(
1158435933ddSDimitry Andric         "SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)",
1159435933ddSDimitry Andric         static_cast<void *>(target_sp.get()), static_cast<uint32_t>(bp_id),
1160f678e45dSDimitry Andric         static_cast<void *>(sb_breakpoint.GetSP().get()));
1161ac7ddfbfSEd Maste 
1162ac7ddfbfSEd Maste   return sb_breakpoint;
1163ac7ddfbfSEd Maste }
1164ac7ddfbfSEd Maste 
FindBreakpointsByName(const char * name,SBBreakpointList & bkpts)1165435933ddSDimitry Andric bool SBTarget::FindBreakpointsByName(const char *name,
1166435933ddSDimitry Andric                                      SBBreakpointList &bkpts) {
1167ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1168435933ddSDimitry Andric   if (target_sp) {
1169435933ddSDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1170435933ddSDimitry Andric     BreakpointList bkpt_list(false);
1171435933ddSDimitry Andric     bool is_valid =
1172435933ddSDimitry Andric         target_sp->GetBreakpointList().FindBreakpointsByName(name, bkpt_list);
1173435933ddSDimitry Andric     if (!is_valid)
1174435933ddSDimitry Andric       return false;
1175435933ddSDimitry Andric     for (BreakpointSP bkpt_sp : bkpt_list.Breakpoints()) {
1176435933ddSDimitry Andric       bkpts.AppendByID(bkpt_sp->GetID());
1177435933ddSDimitry Andric     }
1178435933ddSDimitry Andric   }
1179435933ddSDimitry Andric   return true;
1180435933ddSDimitry Andric }
1181435933ddSDimitry Andric 
GetBreakpointNames(SBStringList & names)1182acac075bSDimitry Andric void SBTarget::GetBreakpointNames(SBStringList &names)
1183acac075bSDimitry Andric {
1184acac075bSDimitry Andric   names.Clear();
1185acac075bSDimitry Andric 
1186acac075bSDimitry Andric   TargetSP target_sp(GetSP());
1187acac075bSDimitry Andric   if (target_sp) {
1188acac075bSDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1189acac075bSDimitry Andric 
1190acac075bSDimitry Andric     std::vector<std::string> name_vec;
1191acac075bSDimitry Andric     target_sp->GetBreakpointNames(name_vec);
1192acac075bSDimitry Andric     for (auto name : name_vec)
1193acac075bSDimitry Andric       names.AppendString(name.c_str());
1194acac075bSDimitry Andric   }
1195acac075bSDimitry Andric }
1196acac075bSDimitry Andric 
DeleteBreakpointName(const char * name)1197acac075bSDimitry Andric void SBTarget::DeleteBreakpointName(const char *name)
1198acac075bSDimitry Andric {
1199acac075bSDimitry Andric   TargetSP target_sp(GetSP());
1200acac075bSDimitry Andric   if (target_sp) {
1201acac075bSDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1202acac075bSDimitry Andric     target_sp->DeleteBreakpointName(ConstString(name));
1203acac075bSDimitry Andric   }
1204acac075bSDimitry Andric }
1205acac075bSDimitry Andric 
EnableAllBreakpoints()1206435933ddSDimitry Andric bool SBTarget::EnableAllBreakpoints() {
1207435933ddSDimitry Andric   TargetSP target_sp(GetSP());
1208435933ddSDimitry Andric   if (target_sp) {
12094bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1210acac075bSDimitry Andric     target_sp->EnableAllowedBreakpoints();
1211ac7ddfbfSEd Maste     return true;
1212ac7ddfbfSEd Maste   }
1213ac7ddfbfSEd Maste   return false;
1214ac7ddfbfSEd Maste }
1215ac7ddfbfSEd Maste 
DisableAllBreakpoints()1216435933ddSDimitry Andric bool SBTarget::DisableAllBreakpoints() {
1217ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1218435933ddSDimitry Andric   if (target_sp) {
12194bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1220acac075bSDimitry Andric     target_sp->DisableAllowedBreakpoints();
1221ac7ddfbfSEd Maste     return true;
1222ac7ddfbfSEd Maste   }
1223ac7ddfbfSEd Maste   return false;
1224ac7ddfbfSEd Maste }
1225ac7ddfbfSEd Maste 
DeleteAllBreakpoints()1226435933ddSDimitry Andric bool SBTarget::DeleteAllBreakpoints() {
1227ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1228435933ddSDimitry Andric   if (target_sp) {
12294bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1230acac075bSDimitry Andric     target_sp->RemoveAllowedBreakpoints();
1231ac7ddfbfSEd Maste     return true;
1232ac7ddfbfSEd Maste   }
1233ac7ddfbfSEd Maste   return false;
1234ac7ddfbfSEd Maste }
1235ac7ddfbfSEd Maste 
BreakpointsCreateFromFile(SBFileSpec & source_file,SBBreakpointList & new_bps)1236435933ddSDimitry Andric lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
1237435933ddSDimitry Andric                                                   SBBreakpointList &new_bps) {
1238435933ddSDimitry Andric   SBStringList empty_name_list;
1239435933ddSDimitry Andric   return BreakpointsCreateFromFile(source_file, empty_name_list, new_bps);
1240435933ddSDimitry Andric }
1241435933ddSDimitry Andric 
BreakpointsCreateFromFile(SBFileSpec & source_file,SBStringList & matching_names,SBBreakpointList & new_bps)1242435933ddSDimitry Andric lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
1243435933ddSDimitry Andric                                                   SBStringList &matching_names,
1244435933ddSDimitry Andric                                                   SBBreakpointList &new_bps) {
1245435933ddSDimitry Andric   SBError sberr;
1246ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1247435933ddSDimitry Andric   if (!target_sp) {
1248435933ddSDimitry Andric     sberr.SetErrorString(
1249435933ddSDimitry Andric         "BreakpointCreateFromFile called with invalid target.");
1250435933ddSDimitry Andric     return sberr;
1251435933ddSDimitry Andric   }
1252435933ddSDimitry Andric   std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1253435933ddSDimitry Andric 
1254435933ddSDimitry Andric   BreakpointIDList bp_ids;
1255435933ddSDimitry Andric 
1256435933ddSDimitry Andric   std::vector<std::string> name_vector;
1257435933ddSDimitry Andric   size_t num_names = matching_names.GetSize();
1258435933ddSDimitry Andric   for (size_t i = 0; i < num_names; i++)
1259435933ddSDimitry Andric     name_vector.push_back(matching_names.GetStringAtIndex(i));
1260435933ddSDimitry Andric 
1261435933ddSDimitry Andric   sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(),
1262435933ddSDimitry Andric                                                      name_vector, bp_ids);
1263435933ddSDimitry Andric   if (sberr.Fail())
1264435933ddSDimitry Andric     return sberr;
1265435933ddSDimitry Andric 
1266435933ddSDimitry Andric   size_t num_bkpts = bp_ids.GetSize();
1267435933ddSDimitry Andric   for (size_t i = 0; i < num_bkpts; i++) {
1268435933ddSDimitry Andric     BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
1269435933ddSDimitry Andric     new_bps.AppendByID(bp_id.GetBreakpointID());
1270435933ddSDimitry Andric   }
1271435933ddSDimitry Andric   return sberr;
1272435933ddSDimitry Andric }
1273435933ddSDimitry Andric 
BreakpointsWriteToFile(SBFileSpec & dest_file)1274435933ddSDimitry Andric lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file) {
1275435933ddSDimitry Andric   SBError sberr;
1276435933ddSDimitry Andric   TargetSP target_sp(GetSP());
1277435933ddSDimitry Andric   if (!target_sp) {
1278435933ddSDimitry Andric     sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1279435933ddSDimitry Andric     return sberr;
1280435933ddSDimitry Andric   }
1281435933ddSDimitry Andric   SBBreakpointList bkpt_list(*this);
1282435933ddSDimitry Andric   return BreakpointsWriteToFile(dest_file, bkpt_list);
1283435933ddSDimitry Andric }
1284435933ddSDimitry Andric 
BreakpointsWriteToFile(SBFileSpec & dest_file,SBBreakpointList & bkpt_list,bool append)1285435933ddSDimitry Andric lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file,
1286435933ddSDimitry Andric                                                SBBreakpointList &bkpt_list,
1287435933ddSDimitry Andric                                                bool append) {
1288435933ddSDimitry Andric   SBError sberr;
1289435933ddSDimitry Andric   TargetSP target_sp(GetSP());
1290435933ddSDimitry Andric   if (!target_sp) {
1291435933ddSDimitry Andric     sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1292435933ddSDimitry Andric     return sberr;
1293435933ddSDimitry Andric   }
1294435933ddSDimitry Andric 
1295435933ddSDimitry Andric   std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1296435933ddSDimitry Andric   BreakpointIDList bp_id_list;
1297435933ddSDimitry Andric   bkpt_list.CopyToBreakpointIDList(bp_id_list);
1298435933ddSDimitry Andric   sberr.ref() = target_sp->SerializeBreakpointsToFile(dest_file.ref(),
1299435933ddSDimitry Andric                                                       bp_id_list, append);
1300435933ddSDimitry Andric   return sberr;
1301435933ddSDimitry Andric }
1302435933ddSDimitry Andric 
GetNumWatchpoints() const1303435933ddSDimitry Andric uint32_t SBTarget::GetNumWatchpoints() const {
1304435933ddSDimitry Andric   TargetSP target_sp(GetSP());
1305435933ddSDimitry Andric   if (target_sp) {
1306ac7ddfbfSEd Maste     // The watchpoint list is thread safe, no need to lock
1307ac7ddfbfSEd Maste     return target_sp->GetWatchpointList().GetSize();
1308ac7ddfbfSEd Maste   }
1309ac7ddfbfSEd Maste   return 0;
1310ac7ddfbfSEd Maste }
1311ac7ddfbfSEd Maste 
GetWatchpointAtIndex(uint32_t idx) const1312435933ddSDimitry Andric SBWatchpoint SBTarget::GetWatchpointAtIndex(uint32_t idx) const {
1313ac7ddfbfSEd Maste   SBWatchpoint sb_watchpoint;
1314ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1315435933ddSDimitry Andric   if (target_sp) {
1316ac7ddfbfSEd Maste     // The watchpoint list is thread safe, no need to lock
1317ac7ddfbfSEd Maste     sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1318ac7ddfbfSEd Maste   }
1319ac7ddfbfSEd Maste   return sb_watchpoint;
1320ac7ddfbfSEd Maste }
1321ac7ddfbfSEd Maste 
DeleteWatchpoint(watch_id_t wp_id)1322435933ddSDimitry Andric bool SBTarget::DeleteWatchpoint(watch_id_t wp_id) {
1323ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1324ac7ddfbfSEd Maste 
1325ac7ddfbfSEd Maste   bool result = false;
1326ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1327435933ddSDimitry Andric   if (target_sp) {
13284bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
13294bb0738eSEd Maste     std::unique_lock<std::recursive_mutex> lock;
13304bb0738eSEd Maste     target_sp->GetWatchpointList().GetListMutex(lock);
1331ac7ddfbfSEd Maste     result = target_sp->RemoveWatchpointByID(wp_id);
1332ac7ddfbfSEd Maste   }
1333ac7ddfbfSEd Maste 
1334ac7ddfbfSEd Maste   if (log)
13350127ef0fSEd Maste     log->Printf("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i",
13360127ef0fSEd Maste                 static_cast<void *>(target_sp.get()),
13370127ef0fSEd Maste                 static_cast<uint32_t>(wp_id), result);
1338ac7ddfbfSEd Maste 
1339ac7ddfbfSEd Maste   return result;
1340ac7ddfbfSEd Maste }
1341ac7ddfbfSEd Maste 
FindWatchpointByID(lldb::watch_id_t wp_id)1342435933ddSDimitry Andric SBWatchpoint SBTarget::FindWatchpointByID(lldb::watch_id_t wp_id) {
1343ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1344ac7ddfbfSEd Maste 
1345ac7ddfbfSEd Maste   SBWatchpoint sb_watchpoint;
1346ac7ddfbfSEd Maste   lldb::WatchpointSP watchpoint_sp;
1347ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1348435933ddSDimitry Andric   if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) {
13494bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
13504bb0738eSEd Maste     std::unique_lock<std::recursive_mutex> lock;
13514bb0738eSEd Maste     target_sp->GetWatchpointList().GetListMutex(lock);
1352ac7ddfbfSEd Maste     watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1353ac7ddfbfSEd Maste     sb_watchpoint.SetSP(watchpoint_sp);
1354ac7ddfbfSEd Maste   }
1355ac7ddfbfSEd Maste 
1356ac7ddfbfSEd Maste   if (log)
1357435933ddSDimitry Andric     log->Printf(
1358435933ddSDimitry Andric         "SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)",
1359435933ddSDimitry Andric         static_cast<void *>(target_sp.get()), static_cast<uint32_t>(wp_id),
13600127ef0fSEd Maste         static_cast<void *>(watchpoint_sp.get()));
1361ac7ddfbfSEd Maste 
1362ac7ddfbfSEd Maste   return sb_watchpoint;
1363ac7ddfbfSEd Maste }
1364ac7ddfbfSEd Maste 
WatchAddress(lldb::addr_t addr,size_t size,bool read,bool write,SBError & error)1365435933ddSDimitry Andric lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size,
1366435933ddSDimitry Andric                                           bool read, bool write,
1367435933ddSDimitry Andric                                           SBError &error) {
1368ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1369ac7ddfbfSEd Maste 
1370ac7ddfbfSEd Maste   SBWatchpoint sb_watchpoint;
1371ac7ddfbfSEd Maste   lldb::WatchpointSP watchpoint_sp;
1372ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1373435933ddSDimitry Andric   if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS &&
1374435933ddSDimitry Andric       size > 0) {
13754bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1376ac7ddfbfSEd Maste     uint32_t watch_type = 0;
1377ac7ddfbfSEd Maste     if (read)
1378ac7ddfbfSEd Maste       watch_type |= LLDB_WATCH_TYPE_READ;
1379ac7ddfbfSEd Maste     if (write)
1380ac7ddfbfSEd Maste       watch_type |= LLDB_WATCH_TYPE_WRITE;
1381435933ddSDimitry Andric     if (watch_type == 0) {
1382435933ddSDimitry Andric       error.SetErrorString(
1383435933ddSDimitry Andric           "Can't create a watchpoint that is neither read nor write.");
1384ac7ddfbfSEd Maste       return sb_watchpoint;
1385ac7ddfbfSEd Maste     }
1386ac7ddfbfSEd Maste 
1387ac7ddfbfSEd Maste     // Target::CreateWatchpoint() is thread safe.
13885517e702SDimitry Andric     Status cw_error;
1389ac7ddfbfSEd Maste     // This API doesn't take in a type, so we can't figure out what it is.
13909f2f44ceSEd Maste     CompilerType *type = NULL;
1391435933ddSDimitry Andric     watchpoint_sp =
1392435933ddSDimitry Andric         target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1393ac7ddfbfSEd Maste     error.SetError(cw_error);
1394ac7ddfbfSEd Maste     sb_watchpoint.SetSP(watchpoint_sp);
1395ac7ddfbfSEd Maste   }
1396ac7ddfbfSEd Maste 
1397ac7ddfbfSEd Maste   if (log)
1398435933ddSDimitry Andric     log->Printf("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64
1399435933ddSDimitry Andric                 ", 0x%u) => SBWatchpoint(%p)",
14000127ef0fSEd Maste                 static_cast<void *>(target_sp.get()), addr,
14010127ef0fSEd Maste                 static_cast<uint32_t>(size),
14020127ef0fSEd Maste                 static_cast<void *>(watchpoint_sp.get()));
1403ac7ddfbfSEd Maste 
1404ac7ddfbfSEd Maste   return sb_watchpoint;
1405ac7ddfbfSEd Maste }
1406ac7ddfbfSEd Maste 
EnableAllWatchpoints()1407435933ddSDimitry Andric bool SBTarget::EnableAllWatchpoints() {
1408ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1409435933ddSDimitry Andric   if (target_sp) {
14104bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
14114bb0738eSEd Maste     std::unique_lock<std::recursive_mutex> lock;
14124bb0738eSEd Maste     target_sp->GetWatchpointList().GetListMutex(lock);
1413ac7ddfbfSEd Maste     target_sp->EnableAllWatchpoints();
1414ac7ddfbfSEd Maste     return true;
1415ac7ddfbfSEd Maste   }
1416ac7ddfbfSEd Maste   return false;
1417ac7ddfbfSEd Maste }
1418ac7ddfbfSEd Maste 
DisableAllWatchpoints()1419435933ddSDimitry Andric bool SBTarget::DisableAllWatchpoints() {
1420ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1421435933ddSDimitry Andric   if (target_sp) {
14224bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
14234bb0738eSEd Maste     std::unique_lock<std::recursive_mutex> lock;
14244bb0738eSEd Maste     target_sp->GetWatchpointList().GetListMutex(lock);
1425ac7ddfbfSEd Maste     target_sp->DisableAllWatchpoints();
1426ac7ddfbfSEd Maste     return true;
1427ac7ddfbfSEd Maste   }
1428ac7ddfbfSEd Maste   return false;
1429ac7ddfbfSEd Maste }
1430ac7ddfbfSEd Maste 
CreateValueFromAddress(const char * name,SBAddress addr,SBType type)1431435933ddSDimitry Andric SBValue SBTarget::CreateValueFromAddress(const char *name, SBAddress addr,
1432435933ddSDimitry Andric                                          SBType type) {
143335617911SEd Maste   SBValue sb_value;
143435617911SEd Maste   lldb::ValueObjectSP new_value_sp;
1435435933ddSDimitry Andric   if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) {
14367aa51b79SEd Maste     lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1437435933ddSDimitry Andric     ExecutionContext exe_ctx(
1438435933ddSDimitry Andric         ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
14399f2f44ceSEd Maste     CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1440435933ddSDimitry Andric     new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr,
1441435933ddSDimitry Andric                                                              exe_ctx, ast_type);
144235617911SEd Maste   }
144335617911SEd Maste   sb_value.SetSP(new_value_sp);
144435617911SEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1445435933ddSDimitry Andric   if (log) {
144635617911SEd Maste     if (new_value_sp)
14470127ef0fSEd Maste       log->Printf("SBTarget(%p)::CreateValueFromAddress => \"%s\"",
14480127ef0fSEd Maste                   static_cast<void *>(m_opaque_sp.get()),
14490127ef0fSEd Maste                   new_value_sp->GetName().AsCString());
145035617911SEd Maste     else
14510127ef0fSEd Maste       log->Printf("SBTarget(%p)::CreateValueFromAddress => NULL",
14520127ef0fSEd Maste                   static_cast<void *>(m_opaque_sp.get()));
145335617911SEd Maste   }
145435617911SEd Maste   return sb_value;
145535617911SEd Maste }
145635617911SEd Maste 
CreateValueFromData(const char * name,lldb::SBData data,lldb::SBType type)1457435933ddSDimitry Andric lldb::SBValue SBTarget::CreateValueFromData(const char *name, lldb::SBData data,
1458435933ddSDimitry Andric                                             lldb::SBType type) {
14597aa51b79SEd Maste   SBValue sb_value;
14607aa51b79SEd Maste   lldb::ValueObjectSP new_value_sp;
1461435933ddSDimitry Andric   if (IsValid() && name && *name && data.IsValid() && type.IsValid()) {
14627aa51b79SEd Maste     DataExtractorSP extractor(*data);
1463435933ddSDimitry Andric     ExecutionContext exe_ctx(
1464435933ddSDimitry Andric         ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
14659f2f44ceSEd Maste     CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1466435933ddSDimitry Andric     new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor,
1467435933ddSDimitry Andric                                                           exe_ctx, ast_type);
14687aa51b79SEd Maste   }
14697aa51b79SEd Maste   sb_value.SetSP(new_value_sp);
14707aa51b79SEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1471435933ddSDimitry Andric   if (log) {
14727aa51b79SEd Maste     if (new_value_sp)
14737aa51b79SEd Maste       log->Printf("SBTarget(%p)::CreateValueFromData => \"%s\"",
14747aa51b79SEd Maste                   static_cast<void *>(m_opaque_sp.get()),
14757aa51b79SEd Maste                   new_value_sp->GetName().AsCString());
14767aa51b79SEd Maste     else
14777aa51b79SEd Maste       log->Printf("SBTarget(%p)::CreateValueFromData => NULL",
14787aa51b79SEd Maste                   static_cast<void *>(m_opaque_sp.get()));
14797aa51b79SEd Maste   }
14807aa51b79SEd Maste   return sb_value;
14817aa51b79SEd Maste }
14827aa51b79SEd Maste 
CreateValueFromExpression(const char * name,const char * expr)1483435933ddSDimitry Andric lldb::SBValue SBTarget::CreateValueFromExpression(const char *name,
1484435933ddSDimitry Andric                                                   const char *expr) {
14857aa51b79SEd Maste   SBValue sb_value;
14867aa51b79SEd Maste   lldb::ValueObjectSP new_value_sp;
1487435933ddSDimitry Andric   if (IsValid() && name && *name && expr && *expr) {
1488435933ddSDimitry Andric     ExecutionContext exe_ctx(
1489435933ddSDimitry Andric         ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1490435933ddSDimitry Andric     new_value_sp =
1491435933ddSDimitry Andric         ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
14927aa51b79SEd Maste   }
14937aa51b79SEd Maste   sb_value.SetSP(new_value_sp);
14947aa51b79SEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1495435933ddSDimitry Andric   if (log) {
14967aa51b79SEd Maste     if (new_value_sp)
14977aa51b79SEd Maste       log->Printf("SBTarget(%p)::CreateValueFromExpression => \"%s\"",
14987aa51b79SEd Maste                   static_cast<void *>(m_opaque_sp.get()),
14997aa51b79SEd Maste                   new_value_sp->GetName().AsCString());
15007aa51b79SEd Maste     else
15017aa51b79SEd Maste       log->Printf("SBTarget(%p)::CreateValueFromExpression => NULL",
15027aa51b79SEd Maste                   static_cast<void *>(m_opaque_sp.get()));
15037aa51b79SEd Maste   }
15047aa51b79SEd Maste   return sb_value;
15057aa51b79SEd Maste }
15067aa51b79SEd Maste 
DeleteAllWatchpoints()1507435933ddSDimitry Andric bool SBTarget::DeleteAllWatchpoints() {
1508ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1509435933ddSDimitry Andric   if (target_sp) {
15104bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
15114bb0738eSEd Maste     std::unique_lock<std::recursive_mutex> lock;
15124bb0738eSEd Maste     target_sp->GetWatchpointList().GetListMutex(lock);
1513ac7ddfbfSEd Maste     target_sp->RemoveAllWatchpoints();
1514ac7ddfbfSEd Maste     return true;
1515ac7ddfbfSEd Maste   }
1516ac7ddfbfSEd Maste   return false;
1517ac7ddfbfSEd Maste }
1518ac7ddfbfSEd Maste 
AppendImageSearchPath(const char * from,const char * to,lldb::SBError & error)1519*b5893f02SDimitry Andric void SBTarget::AppendImageSearchPath(const char *from, const char *to,
1520*b5893f02SDimitry Andric                                      lldb::SBError &error) {
1521*b5893f02SDimitry Andric   TargetSP target_sp(GetSP());
1522*b5893f02SDimitry Andric   if (!target_sp)
1523*b5893f02SDimitry Andric     return error.SetErrorString("invalid target");
1524*b5893f02SDimitry Andric 
1525*b5893f02SDimitry Andric   const ConstString csFrom(from), csTo(to);
1526*b5893f02SDimitry Andric   if (!csFrom)
1527*b5893f02SDimitry Andric     return error.SetErrorString("<from> path can't be empty");
1528*b5893f02SDimitry Andric   if (!csTo)
1529*b5893f02SDimitry Andric     return error.SetErrorString("<to> path can't be empty");
1530*b5893f02SDimitry Andric 
1531*b5893f02SDimitry Andric   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1532*b5893f02SDimitry Andric   if (log)
1533*b5893f02SDimitry Andric     log->Printf("SBTarget(%p)::%s: '%s' -> '%s'",
1534*b5893f02SDimitry Andric                 static_cast<void *>(target_sp.get()),  __FUNCTION__,
1535*b5893f02SDimitry Andric                 from, to);
1536*b5893f02SDimitry Andric   target_sp->GetImageSearchPathList().Append(csFrom, csTo, true);
1537*b5893f02SDimitry Andric }
1538*b5893f02SDimitry Andric 
AddModule(const char * path,const char * triple,const char * uuid_cstr)1539435933ddSDimitry Andric lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1540435933ddSDimitry Andric                                    const char *uuid_cstr) {
1541ac7ddfbfSEd Maste   return AddModule(path, triple, uuid_cstr, NULL);
1542ac7ddfbfSEd Maste }
1543ac7ddfbfSEd Maste 
AddModule(const char * path,const char * triple,const char * uuid_cstr,const char * symfile)1544435933ddSDimitry Andric lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1545435933ddSDimitry Andric                                    const char *uuid_cstr, const char *symfile) {
1546ac7ddfbfSEd Maste   lldb::SBModule sb_module;
1547ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1548435933ddSDimitry Andric   if (target_sp) {
1549ac7ddfbfSEd Maste     ModuleSpec module_spec;
1550ac7ddfbfSEd Maste     if (path)
1551*b5893f02SDimitry Andric       module_spec.GetFileSpec().SetFile(path, FileSpec::Style::native);
1552ac7ddfbfSEd Maste 
1553ac7ddfbfSEd Maste     if (uuid_cstr)
15544ba319b5SDimitry Andric       module_spec.GetUUID().SetFromStringRef(uuid_cstr);
1555ac7ddfbfSEd Maste 
1556ac7ddfbfSEd Maste     if (triple)
1557acac075bSDimitry Andric       module_spec.GetArchitecture() = Platform::GetAugmentedArchSpec(
1558acac075bSDimitry Andric           target_sp->GetPlatform().get(), triple);
155935617911SEd Maste     else
156035617911SEd Maste       module_spec.GetArchitecture() = target_sp->GetArchitecture();
1561ac7ddfbfSEd Maste 
1562ac7ddfbfSEd Maste     if (symfile)
1563*b5893f02SDimitry Andric       module_spec.GetSymbolFileSpec().SetFile(symfile, FileSpec::Style::native);
1564ac7ddfbfSEd Maste 
1565ac7ddfbfSEd Maste     sb_module.SetSP(target_sp->GetSharedModule(module_spec));
1566ac7ddfbfSEd Maste   }
1567ac7ddfbfSEd Maste   return sb_module;
1568ac7ddfbfSEd Maste }
1569ac7ddfbfSEd Maste 
AddModule(const SBModuleSpec & module_spec)1570435933ddSDimitry Andric lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) {
1571ac7ddfbfSEd Maste   lldb::SBModule sb_module;
1572ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1573ac7ddfbfSEd Maste   if (target_sp)
1574ac7ddfbfSEd Maste     sb_module.SetSP(target_sp->GetSharedModule(*module_spec.m_opaque_ap));
1575ac7ddfbfSEd Maste   return sb_module;
1576ac7ddfbfSEd Maste }
1577ac7ddfbfSEd Maste 
AddModule(lldb::SBModule & module)1578435933ddSDimitry Andric bool SBTarget::AddModule(lldb::SBModule &module) {
1579ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1580435933ddSDimitry Andric   if (target_sp) {
1581ac7ddfbfSEd Maste     target_sp->GetImages().AppendIfNeeded(module.GetSP());
1582ac7ddfbfSEd Maste     return true;
1583ac7ddfbfSEd Maste   }
1584ac7ddfbfSEd Maste   return false;
1585ac7ddfbfSEd Maste }
1586ac7ddfbfSEd Maste 
GetNumModules() const1587435933ddSDimitry Andric uint32_t SBTarget::GetNumModules() const {
1588ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1589ac7ddfbfSEd Maste 
1590ac7ddfbfSEd Maste   uint32_t num = 0;
1591ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1592435933ddSDimitry Andric   if (target_sp) {
1593ac7ddfbfSEd Maste     // The module list is thread safe, no need to lock
1594ac7ddfbfSEd Maste     num = target_sp->GetImages().GetSize();
1595ac7ddfbfSEd Maste   }
1596ac7ddfbfSEd Maste 
1597ac7ddfbfSEd Maste   if (log)
15980127ef0fSEd Maste     log->Printf("SBTarget(%p)::GetNumModules () => %d",
15990127ef0fSEd Maste                 static_cast<void *>(target_sp.get()), num);
1600ac7ddfbfSEd Maste 
1601ac7ddfbfSEd Maste   return num;
1602ac7ddfbfSEd Maste }
1603ac7ddfbfSEd Maste 
Clear()1604435933ddSDimitry Andric void SBTarget::Clear() {
1605ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1606ac7ddfbfSEd Maste 
1607ac7ddfbfSEd Maste   if (log)
16080127ef0fSEd Maste     log->Printf("SBTarget(%p)::Clear ()",
16090127ef0fSEd Maste                 static_cast<void *>(m_opaque_sp.get()));
1610ac7ddfbfSEd Maste 
1611ac7ddfbfSEd Maste   m_opaque_sp.reset();
1612ac7ddfbfSEd Maste }
1613ac7ddfbfSEd Maste 
FindModule(const SBFileSpec & sb_file_spec)1614435933ddSDimitry Andric SBModule SBTarget::FindModule(const SBFileSpec &sb_file_spec) {
1615ac7ddfbfSEd Maste   SBModule sb_module;
1616ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1617435933ddSDimitry Andric   if (target_sp && sb_file_spec.IsValid()) {
1618ac7ddfbfSEd Maste     ModuleSpec module_spec(*sb_file_spec);
1619ac7ddfbfSEd Maste     // The module list is thread safe, no need to lock
1620ac7ddfbfSEd Maste     sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1621ac7ddfbfSEd Maste   }
1622ac7ddfbfSEd Maste   return sb_module;
1623ac7ddfbfSEd Maste }
1624ac7ddfbfSEd Maste 
16254ba319b5SDimitry Andric SBSymbolContextList
FindCompileUnits(const SBFileSpec & sb_file_spec)16264ba319b5SDimitry Andric SBTarget::FindCompileUnits(const SBFileSpec &sb_file_spec) {
16274ba319b5SDimitry Andric   SBSymbolContextList sb_sc_list;
16284ba319b5SDimitry Andric   const TargetSP target_sp(GetSP());
16294ba319b5SDimitry Andric   if (target_sp && sb_file_spec.IsValid()) {
16304ba319b5SDimitry Andric     const bool append = true;
16314ba319b5SDimitry Andric     target_sp->GetImages().FindCompileUnits(*sb_file_spec,
16324ba319b5SDimitry Andric                                             append, *sb_sc_list);
16334ba319b5SDimitry Andric   }
16344ba319b5SDimitry Andric   return sb_sc_list;
16354ba319b5SDimitry Andric }
16364ba319b5SDimitry Andric 
GetByteOrder()1637435933ddSDimitry Andric lldb::ByteOrder SBTarget::GetByteOrder() {
1638ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1639ac7ddfbfSEd Maste   if (target_sp)
1640ac7ddfbfSEd Maste     return target_sp->GetArchitecture().GetByteOrder();
1641ac7ddfbfSEd Maste   return eByteOrderInvalid;
1642ac7ddfbfSEd Maste }
1643ac7ddfbfSEd Maste 
GetTriple()1644435933ddSDimitry Andric const char *SBTarget::GetTriple() {
1645ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1646435933ddSDimitry Andric   if (target_sp) {
1647ac7ddfbfSEd Maste     std::string triple(target_sp->GetArchitecture().GetTriple().str());
16484ba319b5SDimitry Andric     // Unique the string so we don't run into ownership issues since the const
16494ba319b5SDimitry Andric     // strings put the string into the string pool once and the strings never
16504ba319b5SDimitry Andric     // comes out
1651ac7ddfbfSEd Maste     ConstString const_triple(triple.c_str());
1652ac7ddfbfSEd Maste     return const_triple.GetCString();
1653ac7ddfbfSEd Maste   }
1654ac7ddfbfSEd Maste   return NULL;
1655ac7ddfbfSEd Maste }
1656ac7ddfbfSEd Maste 
GetDataByteSize()1657435933ddSDimitry Andric uint32_t SBTarget::GetDataByteSize() {
16587aa51b79SEd Maste   TargetSP target_sp(GetSP());
1659435933ddSDimitry Andric   if (target_sp) {
16607aa51b79SEd Maste     return target_sp->GetArchitecture().GetDataByteSize();
16617aa51b79SEd Maste   }
16627aa51b79SEd Maste   return 0;
16637aa51b79SEd Maste }
16647aa51b79SEd Maste 
GetCodeByteSize()1665435933ddSDimitry Andric uint32_t SBTarget::GetCodeByteSize() {
16667aa51b79SEd Maste   TargetSP target_sp(GetSP());
1667435933ddSDimitry Andric   if (target_sp) {
16687aa51b79SEd Maste     return target_sp->GetArchitecture().GetCodeByteSize();
16697aa51b79SEd Maste   }
16707aa51b79SEd Maste   return 0;
16717aa51b79SEd Maste }
16727aa51b79SEd Maste 
GetAddressByteSize()1673435933ddSDimitry Andric uint32_t SBTarget::GetAddressByteSize() {
1674ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1675ac7ddfbfSEd Maste   if (target_sp)
1676ac7ddfbfSEd Maste     return target_sp->GetArchitecture().GetAddressByteSize();
1677ac7ddfbfSEd Maste   return sizeof(void *);
1678ac7ddfbfSEd Maste }
1679ac7ddfbfSEd Maste 
GetModuleAtIndex(uint32_t idx)1680435933ddSDimitry Andric SBModule SBTarget::GetModuleAtIndex(uint32_t idx) {
1681ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1682ac7ddfbfSEd Maste 
1683ac7ddfbfSEd Maste   SBModule sb_module;
1684ac7ddfbfSEd Maste   ModuleSP module_sp;
1685ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1686435933ddSDimitry Andric   if (target_sp) {
1687ac7ddfbfSEd Maste     // The module list is thread safe, no need to lock
1688ac7ddfbfSEd Maste     module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1689ac7ddfbfSEd Maste     sb_module.SetSP(module_sp);
1690ac7ddfbfSEd Maste   }
1691ac7ddfbfSEd Maste 
1692ac7ddfbfSEd Maste   if (log)
1693ac7ddfbfSEd Maste     log->Printf("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)",
16940127ef0fSEd Maste                 static_cast<void *>(target_sp.get()), idx,
16950127ef0fSEd Maste                 static_cast<void *>(module_sp.get()));
1696ac7ddfbfSEd Maste 
1697ac7ddfbfSEd Maste   return sb_module;
1698ac7ddfbfSEd Maste }
1699ac7ddfbfSEd Maste 
RemoveModule(lldb::SBModule module)1700435933ddSDimitry Andric bool SBTarget::RemoveModule(lldb::SBModule module) {
1701ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1702ac7ddfbfSEd Maste   if (target_sp)
1703ac7ddfbfSEd Maste     return target_sp->GetImages().Remove(module.GetSP());
1704ac7ddfbfSEd Maste   return false;
1705ac7ddfbfSEd Maste }
1706ac7ddfbfSEd Maste 
GetBroadcaster() const1707435933ddSDimitry Andric SBBroadcaster SBTarget::GetBroadcaster() const {
1708ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1709ac7ddfbfSEd Maste 
1710ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1711ac7ddfbfSEd Maste   SBBroadcaster broadcaster(target_sp.get(), false);
1712ac7ddfbfSEd Maste 
1713ac7ddfbfSEd Maste   if (log)
1714ac7ddfbfSEd Maste     log->Printf("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)",
17150127ef0fSEd Maste                 static_cast<void *>(target_sp.get()),
17160127ef0fSEd Maste                 static_cast<void *>(broadcaster.get()));
1717ac7ddfbfSEd Maste 
1718ac7ddfbfSEd Maste   return broadcaster;
1719ac7ddfbfSEd Maste }
1720ac7ddfbfSEd Maste 
GetDescription(SBStream & description,lldb::DescriptionLevel description_level)1721435933ddSDimitry Andric bool SBTarget::GetDescription(SBStream &description,
1722435933ddSDimitry Andric                               lldb::DescriptionLevel description_level) {
1723ac7ddfbfSEd Maste   Stream &strm = description.ref();
1724ac7ddfbfSEd Maste 
1725ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1726435933ddSDimitry Andric   if (target_sp) {
1727ac7ddfbfSEd Maste     target_sp->Dump(&strm, description_level);
1728435933ddSDimitry Andric   } else
1729ac7ddfbfSEd Maste     strm.PutCString("No value");
1730ac7ddfbfSEd Maste 
1731ac7ddfbfSEd Maste   return true;
1732ac7ddfbfSEd Maste }
1733ac7ddfbfSEd Maste 
FindFunctions(const char * name,uint32_t name_type_mask)1734435933ddSDimitry Andric lldb::SBSymbolContextList SBTarget::FindFunctions(const char *name,
1735435933ddSDimitry Andric                                                   uint32_t name_type_mask) {
1736ac7ddfbfSEd Maste   lldb::SBSymbolContextList sb_sc_list;
1737*b5893f02SDimitry Andric   if (!name | !name[0])
1738*b5893f02SDimitry Andric     return sb_sc_list;
1739*b5893f02SDimitry Andric 
1740ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1741*b5893f02SDimitry Andric   if (!target_sp)
1742*b5893f02SDimitry Andric     return sb_sc_list;
1743*b5893f02SDimitry Andric 
1744ac7ddfbfSEd Maste   const bool symbols_ok = true;
1745ac7ddfbfSEd Maste   const bool inlines_ok = true;
1746ac7ddfbfSEd Maste   const bool append = true;
1747*b5893f02SDimitry Andric   FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
1748*b5893f02SDimitry Andric   target_sp->GetImages().FindFunctions(ConstString(name), mask, symbols_ok,
1749*b5893f02SDimitry Andric                                        inlines_ok, append, *sb_sc_list);
1750ac7ddfbfSEd Maste   return sb_sc_list;
1751ac7ddfbfSEd Maste }
1752ac7ddfbfSEd Maste 
FindGlobalFunctions(const char * name,uint32_t max_matches,MatchType matchtype)1753435933ddSDimitry Andric lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name,
1754435933ddSDimitry Andric                                                         uint32_t max_matches,
1755435933ddSDimitry Andric                                                         MatchType matchtype) {
17567aa51b79SEd Maste   lldb::SBSymbolContextList sb_sc_list;
1757435933ddSDimitry Andric   if (name && name[0]) {
1758435933ddSDimitry Andric     llvm::StringRef name_ref(name);
17597aa51b79SEd Maste     TargetSP target_sp(GetSP());
1760435933ddSDimitry Andric     if (target_sp) {
17617aa51b79SEd Maste       std::string regexstr;
1762435933ddSDimitry Andric       switch (matchtype) {
17637aa51b79SEd Maste       case eMatchTypeRegex:
1764435933ddSDimitry Andric         target_sp->GetImages().FindFunctions(RegularExpression(name_ref), true,
1765435933ddSDimitry Andric                                              true, true, *sb_sc_list);
17667aa51b79SEd Maste         break;
17677aa51b79SEd Maste       case eMatchTypeStartsWith:
17687aa51b79SEd Maste         regexstr = llvm::Regex::escape(name) + ".*";
1769435933ddSDimitry Andric         target_sp->GetImages().FindFunctions(RegularExpression(regexstr), true,
1770435933ddSDimitry Andric                                              true, true, *sb_sc_list);
17717aa51b79SEd Maste         break;
17727aa51b79SEd Maste       default:
1773435933ddSDimitry Andric         target_sp->GetImages().FindFunctions(ConstString(name),
1774435933ddSDimitry Andric                                              eFunctionNameTypeAny, true, true,
1775435933ddSDimitry Andric                                              true, *sb_sc_list);
17767aa51b79SEd Maste         break;
17777aa51b79SEd Maste       }
17787aa51b79SEd Maste     }
17797aa51b79SEd Maste   }
17807aa51b79SEd Maste   return sb_sc_list;
17817aa51b79SEd Maste }
17827aa51b79SEd Maste 
FindFirstType(const char * typename_cstr)1783435933ddSDimitry Andric lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
1784ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1785435933ddSDimitry Andric   if (typename_cstr && typename_cstr[0] && target_sp) {
1786ac7ddfbfSEd Maste     ConstString const_typename(typename_cstr);
1787ac7ddfbfSEd Maste     SymbolContext sc;
1788ac7ddfbfSEd Maste     const bool exact_match = false;
1789ac7ddfbfSEd Maste 
1790ac7ddfbfSEd Maste     const ModuleList &module_list = target_sp->GetImages();
1791ac7ddfbfSEd Maste     size_t count = module_list.GetSize();
1792435933ddSDimitry Andric     for (size_t idx = 0; idx < count; idx++) {
1793ac7ddfbfSEd Maste       ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
1794435933ddSDimitry Andric       if (module_sp) {
1795435933ddSDimitry Andric         TypeSP type_sp(
1796435933ddSDimitry Andric             module_sp->FindFirstType(sc, const_typename, exact_match));
1797ac7ddfbfSEd Maste         if (type_sp)
1798ac7ddfbfSEd Maste           return SBType(type_sp);
1799ac7ddfbfSEd Maste       }
1800ac7ddfbfSEd Maste     }
1801ac7ddfbfSEd Maste 
18024ba319b5SDimitry Andric     // Didn't find the type in the symbols; try the Objective-C runtime if one
18034ba319b5SDimitry Andric     // is installed
1804ac7ddfbfSEd Maste 
1805ac7ddfbfSEd Maste     ProcessSP process_sp(target_sp->GetProcessSP());
1806ac7ddfbfSEd Maste 
1807435933ddSDimitry Andric     if (process_sp) {
1808435933ddSDimitry Andric       ObjCLanguageRuntime *objc_language_runtime =
1809435933ddSDimitry Andric           process_sp->GetObjCLanguageRuntime();
1810ac7ddfbfSEd Maste 
1811435933ddSDimitry Andric       if (objc_language_runtime) {
18127aa51b79SEd Maste         DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
1813ac7ddfbfSEd Maste 
1814435933ddSDimitry Andric         if (objc_decl_vendor) {
18157aa51b79SEd Maste           std::vector<clang::NamedDecl *> decls;
1816ac7ddfbfSEd Maste 
1817435933ddSDimitry Andric           if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) {
1818435933ddSDimitry Andric             if (CompilerType type = ClangASTContext::GetTypeForDecl(decls[0])) {
18197aa51b79SEd Maste               return SBType(type);
18207aa51b79SEd Maste             }
18217aa51b79SEd Maste           }
1822ac7ddfbfSEd Maste         }
1823ac7ddfbfSEd Maste       }
1824ac7ddfbfSEd Maste     }
1825ac7ddfbfSEd Maste 
1826ac7ddfbfSEd Maste     // No matches, search for basic typename matches
1827ac7ddfbfSEd Maste     ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1828ac7ddfbfSEd Maste     if (clang_ast)
1829435933ddSDimitry Andric       return SBType(ClangASTContext::GetBasicType(clang_ast->getASTContext(),
1830435933ddSDimitry Andric                                                   const_typename));
1831ac7ddfbfSEd Maste   }
1832ac7ddfbfSEd Maste   return SBType();
1833ac7ddfbfSEd Maste }
1834ac7ddfbfSEd Maste 
GetBasicType(lldb::BasicType type)1835435933ddSDimitry Andric SBType SBTarget::GetBasicType(lldb::BasicType type) {
1836ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1837435933ddSDimitry Andric   if (target_sp) {
1838ac7ddfbfSEd Maste     ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1839ac7ddfbfSEd Maste     if (clang_ast)
1840435933ddSDimitry Andric       return SBType(
1841435933ddSDimitry Andric           ClangASTContext::GetBasicType(clang_ast->getASTContext(), type));
1842ac7ddfbfSEd Maste   }
1843ac7ddfbfSEd Maste   return SBType();
1844ac7ddfbfSEd Maste }
1845ac7ddfbfSEd Maste 
FindTypes(const char * typename_cstr)1846435933ddSDimitry Andric lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
1847ac7ddfbfSEd Maste   SBTypeList sb_type_list;
1848ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1849435933ddSDimitry Andric   if (typename_cstr && typename_cstr[0] && target_sp) {
1850ac7ddfbfSEd Maste     ModuleList &images = target_sp->GetImages();
1851ac7ddfbfSEd Maste     ConstString const_typename(typename_cstr);
1852ac7ddfbfSEd Maste     bool exact_match = false;
1853ac7ddfbfSEd Maste     TypeList type_list;
18544bb0738eSEd Maste     llvm::DenseSet<SymbolFile *> searched_symbol_files;
1855435933ddSDimitry Andric     uint32_t num_matches =
1856*b5893f02SDimitry Andric         images.FindTypes(nullptr, const_typename, exact_match, UINT32_MAX,
1857435933ddSDimitry Andric                          searched_symbol_files, type_list);
1858ac7ddfbfSEd Maste 
1859435933ddSDimitry Andric     if (num_matches > 0) {
1860435933ddSDimitry Andric       for (size_t idx = 0; idx < num_matches; idx++) {
1861ac7ddfbfSEd Maste         TypeSP type_sp(type_list.GetTypeAtIndex(idx));
1862ac7ddfbfSEd Maste         if (type_sp)
1863ac7ddfbfSEd Maste           sb_type_list.Append(SBType(type_sp));
1864ac7ddfbfSEd Maste       }
1865ac7ddfbfSEd Maste     }
1866ac7ddfbfSEd Maste 
1867ac7ddfbfSEd Maste     // Try the Objective-C runtime if one is installed
1868ac7ddfbfSEd Maste 
1869ac7ddfbfSEd Maste     ProcessSP process_sp(target_sp->GetProcessSP());
1870ac7ddfbfSEd Maste 
1871435933ddSDimitry Andric     if (process_sp) {
1872435933ddSDimitry Andric       ObjCLanguageRuntime *objc_language_runtime =
1873435933ddSDimitry Andric           process_sp->GetObjCLanguageRuntime();
1874ac7ddfbfSEd Maste 
1875435933ddSDimitry Andric       if (objc_language_runtime) {
18767aa51b79SEd Maste         DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
1877ac7ddfbfSEd Maste 
1878435933ddSDimitry Andric         if (objc_decl_vendor) {
18797aa51b79SEd Maste           std::vector<clang::NamedDecl *> decls;
1880ac7ddfbfSEd Maste 
1881435933ddSDimitry Andric           if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) {
1882435933ddSDimitry Andric             for (clang::NamedDecl *decl : decls) {
1883435933ddSDimitry Andric               if (CompilerType type = ClangASTContext::GetTypeForDecl(decl)) {
1884ac7ddfbfSEd Maste                 sb_type_list.Append(SBType(type));
1885ac7ddfbfSEd Maste               }
1886ac7ddfbfSEd Maste             }
1887ac7ddfbfSEd Maste           }
1888ac7ddfbfSEd Maste         }
1889ac7ddfbfSEd Maste       }
18907aa51b79SEd Maste     }
1891ac7ddfbfSEd Maste 
1892435933ddSDimitry Andric     if (sb_type_list.GetSize() == 0) {
1893ac7ddfbfSEd Maste       // No matches, search for basic typename matches
1894ac7ddfbfSEd Maste       ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext();
1895ac7ddfbfSEd Maste       if (clang_ast)
1896435933ddSDimitry Andric         sb_type_list.Append(SBType(ClangASTContext::GetBasicType(
1897435933ddSDimitry Andric             clang_ast->getASTContext(), const_typename)));
1898ac7ddfbfSEd Maste     }
1899ac7ddfbfSEd Maste   }
1900ac7ddfbfSEd Maste   return sb_type_list;
1901ac7ddfbfSEd Maste }
1902ac7ddfbfSEd Maste 
FindGlobalVariables(const char * name,uint32_t max_matches)1903435933ddSDimitry Andric SBValueList SBTarget::FindGlobalVariables(const char *name,
1904435933ddSDimitry Andric                                           uint32_t max_matches) {
1905ac7ddfbfSEd Maste   SBValueList sb_value_list;
1906ac7ddfbfSEd Maste 
1907ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1908435933ddSDimitry Andric   if (name && target_sp) {
1909ac7ddfbfSEd Maste     VariableList variable_list;
1910435933ddSDimitry Andric     const uint32_t match_count = target_sp->GetImages().FindGlobalVariables(
19114ba319b5SDimitry Andric         ConstString(name), max_matches, variable_list);
1912ac7ddfbfSEd Maste 
1913435933ddSDimitry Andric     if (match_count > 0) {
1914ac7ddfbfSEd Maste       ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1915ac7ddfbfSEd Maste       if (exe_scope == NULL)
1916ac7ddfbfSEd Maste         exe_scope = target_sp.get();
1917435933ddSDimitry Andric       for (uint32_t i = 0; i < match_count; ++i) {
1918435933ddSDimitry Andric         lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(
1919435933ddSDimitry Andric             exe_scope, variable_list.GetVariableAtIndex(i)));
1920ac7ddfbfSEd Maste         if (valobj_sp)
1921ac7ddfbfSEd Maste           sb_value_list.Append(SBValue(valobj_sp));
1922ac7ddfbfSEd Maste       }
1923ac7ddfbfSEd Maste     }
1924ac7ddfbfSEd Maste   }
1925ac7ddfbfSEd Maste 
1926ac7ddfbfSEd Maste   return sb_value_list;
1927ac7ddfbfSEd Maste }
1928ac7ddfbfSEd Maste 
FindGlobalVariables(const char * name,uint32_t max_matches,MatchType matchtype)1929435933ddSDimitry Andric SBValueList SBTarget::FindGlobalVariables(const char *name,
1930435933ddSDimitry Andric                                           uint32_t max_matches,
1931435933ddSDimitry Andric                                           MatchType matchtype) {
19327aa51b79SEd Maste   SBValueList sb_value_list;
19337aa51b79SEd Maste 
19347aa51b79SEd Maste   TargetSP target_sp(GetSP());
1935435933ddSDimitry Andric   if (name && target_sp) {
1936435933ddSDimitry Andric     llvm::StringRef name_ref(name);
19377aa51b79SEd Maste     VariableList variable_list;
19387aa51b79SEd Maste 
19397aa51b79SEd Maste     std::string regexstr;
19407aa51b79SEd Maste     uint32_t match_count;
1941435933ddSDimitry Andric     switch (matchtype) {
19427aa51b79SEd Maste     case eMatchTypeNormal:
1943435933ddSDimitry Andric       match_count = target_sp->GetImages().FindGlobalVariables(
19444ba319b5SDimitry Andric           ConstString(name), max_matches, variable_list);
19457aa51b79SEd Maste       break;
19467aa51b79SEd Maste     case eMatchTypeRegex:
1947435933ddSDimitry Andric       match_count = target_sp->GetImages().FindGlobalVariables(
19484ba319b5SDimitry Andric           RegularExpression(name_ref), max_matches, variable_list);
19497aa51b79SEd Maste       break;
19507aa51b79SEd Maste     case eMatchTypeStartsWith:
19517aa51b79SEd Maste       regexstr = llvm::Regex::escape(name) + ".*";
1952435933ddSDimitry Andric       match_count = target_sp->GetImages().FindGlobalVariables(
19534ba319b5SDimitry Andric           RegularExpression(regexstr), max_matches, variable_list);
19547aa51b79SEd Maste       break;
19557aa51b79SEd Maste     }
19567aa51b79SEd Maste 
1957435933ddSDimitry Andric     if (match_count > 0) {
19587aa51b79SEd Maste       ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
19597aa51b79SEd Maste       if (exe_scope == NULL)
19607aa51b79SEd Maste         exe_scope = target_sp.get();
1961435933ddSDimitry Andric       for (uint32_t i = 0; i < match_count; ++i) {
1962435933ddSDimitry Andric         lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(
1963435933ddSDimitry Andric             exe_scope, variable_list.GetVariableAtIndex(i)));
19647aa51b79SEd Maste         if (valobj_sp)
19657aa51b79SEd Maste           sb_value_list.Append(SBValue(valobj_sp));
19667aa51b79SEd Maste       }
19677aa51b79SEd Maste     }
19687aa51b79SEd Maste   }
19697aa51b79SEd Maste 
19707aa51b79SEd Maste   return sb_value_list;
19717aa51b79SEd Maste }
19727aa51b79SEd Maste 
FindFirstGlobalVariable(const char * name)1973435933ddSDimitry Andric lldb::SBValue SBTarget::FindFirstGlobalVariable(const char *name) {
1974ac7ddfbfSEd Maste   SBValueList sb_value_list(FindGlobalVariables(name, 1));
1975ac7ddfbfSEd Maste   if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
1976ac7ddfbfSEd Maste     return sb_value_list.GetValueAtIndex(0);
1977ac7ddfbfSEd Maste   return SBValue();
1978ac7ddfbfSEd Maste }
1979ac7ddfbfSEd Maste 
GetSourceManager()1980435933ddSDimitry Andric SBSourceManager SBTarget::GetSourceManager() {
1981ac7ddfbfSEd Maste   SBSourceManager source_manager(*this);
1982ac7ddfbfSEd Maste   return source_manager;
1983ac7ddfbfSEd Maste }
1984ac7ddfbfSEd Maste 
ReadInstructions(lldb::SBAddress base_addr,uint32_t count)1985435933ddSDimitry Andric lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
1986435933ddSDimitry Andric                                                    uint32_t count) {
1987ac7ddfbfSEd Maste   return ReadInstructions(base_addr, count, NULL);
1988ac7ddfbfSEd Maste }
1989ac7ddfbfSEd Maste 
ReadInstructions(lldb::SBAddress base_addr,uint32_t count,const char * flavor_string)1990435933ddSDimitry Andric lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
1991435933ddSDimitry Andric                                                    uint32_t count,
1992435933ddSDimitry Andric                                                    const char *flavor_string) {
1993ac7ddfbfSEd Maste   SBInstructionList sb_instructions;
1994ac7ddfbfSEd Maste 
1995ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
1996435933ddSDimitry Andric   if (target_sp) {
1997ac7ddfbfSEd Maste     Address *addr_ptr = base_addr.get();
1998ac7ddfbfSEd Maste 
1999435933ddSDimitry Andric     if (addr_ptr) {
2000435933ddSDimitry Andric       DataBufferHeap data(
2001435933ddSDimitry Andric           target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2002ac7ddfbfSEd Maste       bool prefer_file_cache = false;
20035517e702SDimitry Andric       lldb_private::Status error;
2004ac7ddfbfSEd Maste       lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2005435933ddSDimitry Andric       const size_t bytes_read =
2006435933ddSDimitry Andric           target_sp->ReadMemory(*addr_ptr, prefer_file_cache, data.GetBytes(),
2007435933ddSDimitry Andric                                 data.GetByteSize(), error, &load_addr);
2008ac7ddfbfSEd Maste       const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
2009435933ddSDimitry Andric       sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
2010435933ddSDimitry Andric           target_sp->GetArchitecture(), NULL, flavor_string, *addr_ptr,
2011435933ddSDimitry Andric           data.GetBytes(), bytes_read, count, data_from_file));
2012ac7ddfbfSEd Maste     }
2013ac7ddfbfSEd Maste   }
2014ac7ddfbfSEd Maste 
2015ac7ddfbfSEd Maste   return sb_instructions;
2016ac7ddfbfSEd Maste }
2017ac7ddfbfSEd Maste 
GetInstructions(lldb::SBAddress base_addr,const void * buf,size_t size)2018435933ddSDimitry Andric lldb::SBInstructionList SBTarget::GetInstructions(lldb::SBAddress base_addr,
2019435933ddSDimitry Andric                                                   const void *buf,
2020435933ddSDimitry Andric                                                   size_t size) {
2021ac7ddfbfSEd Maste   return GetInstructionsWithFlavor(base_addr, NULL, buf, size);
2022ac7ddfbfSEd Maste }
2023ac7ddfbfSEd Maste 
2024ac7ddfbfSEd Maste lldb::SBInstructionList
GetInstructionsWithFlavor(lldb::SBAddress base_addr,const char * flavor_string,const void * buf,size_t size)2025435933ddSDimitry Andric SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
2026435933ddSDimitry Andric                                     const char *flavor_string, const void *buf,
2027435933ddSDimitry Andric                                     size_t size) {
2028ac7ddfbfSEd Maste   SBInstructionList sb_instructions;
2029ac7ddfbfSEd Maste 
2030ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
2031435933ddSDimitry Andric   if (target_sp) {
2032ac7ddfbfSEd Maste     Address addr;
2033ac7ddfbfSEd Maste 
2034ac7ddfbfSEd Maste     if (base_addr.get())
2035ac7ddfbfSEd Maste       addr = *base_addr.get();
2036ac7ddfbfSEd Maste 
2037ac7ddfbfSEd Maste     const bool data_from_file = true;
2038ac7ddfbfSEd Maste 
2039435933ddSDimitry Andric     sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
2040435933ddSDimitry Andric         target_sp->GetArchitecture(), NULL, flavor_string, addr, buf, size,
2041435933ddSDimitry Andric         UINT32_MAX, data_from_file));
2042ac7ddfbfSEd Maste   }
2043ac7ddfbfSEd Maste 
2044ac7ddfbfSEd Maste   return sb_instructions;
2045ac7ddfbfSEd Maste }
2046ac7ddfbfSEd Maste 
GetInstructions(lldb::addr_t base_addr,const void * buf,size_t size)2047435933ddSDimitry Andric lldb::SBInstructionList SBTarget::GetInstructions(lldb::addr_t base_addr,
2048435933ddSDimitry Andric                                                   const void *buf,
2049435933ddSDimitry Andric                                                   size_t size) {
2050435933ddSDimitry Andric   return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), NULL, buf,
2051435933ddSDimitry Andric                                    size);
2052ac7ddfbfSEd Maste }
2053ac7ddfbfSEd Maste 
2054ac7ddfbfSEd Maste lldb::SBInstructionList
GetInstructionsWithFlavor(lldb::addr_t base_addr,const char * flavor_string,const void * buf,size_t size)2055435933ddSDimitry Andric SBTarget::GetInstructionsWithFlavor(lldb::addr_t base_addr,
2056435933ddSDimitry Andric                                     const char *flavor_string, const void *buf,
2057435933ddSDimitry Andric                                     size_t size) {
2058435933ddSDimitry Andric   return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string,
2059435933ddSDimitry Andric                                    buf, size);
2060ac7ddfbfSEd Maste }
2061ac7ddfbfSEd Maste 
SetSectionLoadAddress(lldb::SBSection section,lldb::addr_t section_base_addr)2062435933ddSDimitry Andric SBError SBTarget::SetSectionLoadAddress(lldb::SBSection section,
2063435933ddSDimitry Andric                                         lldb::addr_t section_base_addr) {
2064ac7ddfbfSEd Maste   SBError sb_error;
2065ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
2066435933ddSDimitry Andric   if (target_sp) {
2067435933ddSDimitry Andric     if (!section.IsValid()) {
2068ac7ddfbfSEd Maste       sb_error.SetErrorStringWithFormat("invalid section");
2069435933ddSDimitry Andric     } else {
2070ac7ddfbfSEd Maste       SectionSP section_sp(section.GetSP());
2071435933ddSDimitry Andric       if (section_sp) {
2072435933ddSDimitry Andric         if (section_sp->IsThreadSpecific()) {
2073435933ddSDimitry Andric           sb_error.SetErrorString(
2074435933ddSDimitry Andric               "thread specific sections are not yet supported");
2075435933ddSDimitry Andric         } else {
207612b93ac6SEd Maste           ProcessSP process_sp(target_sp->GetProcessSP());
2077435933ddSDimitry Andric           if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
20784bb0738eSEd Maste             ModuleSP module_sp(section_sp->GetModule());
2079435933ddSDimitry Andric             if (module_sp) {
20804bb0738eSEd Maste               ModuleList module_list;
20814bb0738eSEd Maste               module_list.Append(module_sp);
20824bb0738eSEd Maste               target_sp->ModulesDidLoad(module_list);
20834bb0738eSEd Maste             }
2084ac7ddfbfSEd Maste             // Flush info in the process (stack frames, etc)
2085ac7ddfbfSEd Maste             if (process_sp)
2086ac7ddfbfSEd Maste               process_sp->Flush();
2087ac7ddfbfSEd Maste           }
2088ac7ddfbfSEd Maste         }
2089ac7ddfbfSEd Maste       }
2090ac7ddfbfSEd Maste     }
2091435933ddSDimitry Andric   } else {
2092ac7ddfbfSEd Maste     sb_error.SetErrorString("invalid target");
2093ac7ddfbfSEd Maste   }
2094ac7ddfbfSEd Maste   return sb_error;
2095ac7ddfbfSEd Maste }
2096ac7ddfbfSEd Maste 
ClearSectionLoadAddress(lldb::SBSection section)2097435933ddSDimitry Andric SBError SBTarget::ClearSectionLoadAddress(lldb::SBSection section) {
2098ac7ddfbfSEd Maste   SBError sb_error;
2099ac7ddfbfSEd Maste 
2100ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
2101435933ddSDimitry Andric   if (target_sp) {
2102435933ddSDimitry Andric     if (!section.IsValid()) {
2103ac7ddfbfSEd Maste       sb_error.SetErrorStringWithFormat("invalid section");
2104435933ddSDimitry Andric     } else {
21054bb0738eSEd Maste       SectionSP section_sp(section.GetSP());
2106435933ddSDimitry Andric       if (section_sp) {
21074bb0738eSEd Maste         ProcessSP process_sp(target_sp->GetProcessSP());
2108435933ddSDimitry Andric         if (target_sp->SetSectionUnloaded(section_sp)) {
21094bb0738eSEd Maste           ModuleSP module_sp(section_sp->GetModule());
2110435933ddSDimitry Andric           if (module_sp) {
21114bb0738eSEd Maste             ModuleList module_list;
21124bb0738eSEd Maste             module_list.Append(module_sp);
21134bb0738eSEd Maste             target_sp->ModulesDidUnload(module_list, false);
21144bb0738eSEd Maste           }
2115ac7ddfbfSEd Maste           // Flush info in the process (stack frames, etc)
2116ac7ddfbfSEd Maste           if (process_sp)
2117ac7ddfbfSEd Maste             process_sp->Flush();
2118ac7ddfbfSEd Maste         }
2119435933ddSDimitry Andric       } else {
21204bb0738eSEd Maste         sb_error.SetErrorStringWithFormat("invalid section");
21214bb0738eSEd Maste       }
21224bb0738eSEd Maste     }
2123435933ddSDimitry Andric   } else {
2124ac7ddfbfSEd Maste     sb_error.SetErrorStringWithFormat("invalid target");
2125ac7ddfbfSEd Maste   }
2126ac7ddfbfSEd Maste   return sb_error;
2127ac7ddfbfSEd Maste }
2128ac7ddfbfSEd Maste 
SetModuleLoadAddress(lldb::SBModule module,int64_t slide_offset)2129435933ddSDimitry Andric SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
2130435933ddSDimitry Andric                                        int64_t slide_offset) {
2131ac7ddfbfSEd Maste   SBError sb_error;
2132ac7ddfbfSEd Maste 
2133ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
2134435933ddSDimitry Andric   if (target_sp) {
2135ac7ddfbfSEd Maste     ModuleSP module_sp(module.GetSP());
2136435933ddSDimitry Andric     if (module_sp) {
2137ac7ddfbfSEd Maste       bool changed = false;
2138435933ddSDimitry Andric       if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) {
2139ac7ddfbfSEd Maste         // The load was successful, make sure that at least some sections
2140ac7ddfbfSEd Maste         // changed before we notify that our module was loaded.
2141435933ddSDimitry Andric         if (changed) {
2142ac7ddfbfSEd Maste           ModuleList module_list;
2143ac7ddfbfSEd Maste           module_list.Append(module_sp);
2144ac7ddfbfSEd Maste           target_sp->ModulesDidLoad(module_list);
2145ac7ddfbfSEd Maste           // Flush info in the process (stack frames, etc)
2146ac7ddfbfSEd Maste           ProcessSP process_sp(target_sp->GetProcessSP());
2147ac7ddfbfSEd Maste           if (process_sp)
2148ac7ddfbfSEd Maste             process_sp->Flush();
2149ac7ddfbfSEd Maste         }
2150ac7ddfbfSEd Maste       }
2151435933ddSDimitry Andric     } else {
2152ac7ddfbfSEd Maste       sb_error.SetErrorStringWithFormat("invalid module");
2153ac7ddfbfSEd Maste     }
2154ac7ddfbfSEd Maste 
2155435933ddSDimitry Andric   } else {
2156ac7ddfbfSEd Maste     sb_error.SetErrorStringWithFormat("invalid target");
2157ac7ddfbfSEd Maste   }
2158ac7ddfbfSEd Maste   return sb_error;
2159ac7ddfbfSEd Maste }
2160ac7ddfbfSEd Maste 
ClearModuleLoadAddress(lldb::SBModule module)2161435933ddSDimitry Andric SBError SBTarget::ClearModuleLoadAddress(lldb::SBModule module) {
2162ac7ddfbfSEd Maste   SBError sb_error;
2163ac7ddfbfSEd Maste 
2164ac7ddfbfSEd Maste   char path[PATH_MAX];
2165ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
2166435933ddSDimitry Andric   if (target_sp) {
2167ac7ddfbfSEd Maste     ModuleSP module_sp(module.GetSP());
2168435933ddSDimitry Andric     if (module_sp) {
2169ac7ddfbfSEd Maste       ObjectFile *objfile = module_sp->GetObjectFile();
2170435933ddSDimitry Andric       if (objfile) {
2171ac7ddfbfSEd Maste         SectionList *section_list = objfile->GetSectionList();
2172435933ddSDimitry Andric         if (section_list) {
217312b93ac6SEd Maste           ProcessSP process_sp(target_sp->GetProcessSP());
217412b93ac6SEd Maste 
2175ac7ddfbfSEd Maste           bool changed = false;
2176ac7ddfbfSEd Maste           const size_t num_sections = section_list->GetSize();
2177435933ddSDimitry Andric           for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
2178ac7ddfbfSEd Maste             SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
2179ac7ddfbfSEd Maste             if (section_sp)
21800127ef0fSEd Maste               changed |= target_sp->SetSectionUnloaded(section_sp);
2181ac7ddfbfSEd Maste           }
2182435933ddSDimitry Andric           if (changed) {
21834bb0738eSEd Maste             ModuleList module_list;
21844bb0738eSEd Maste             module_list.Append(module_sp);
21854bb0738eSEd Maste             target_sp->ModulesDidUnload(module_list, false);
2186ac7ddfbfSEd Maste             // Flush info in the process (stack frames, etc)
2187ac7ddfbfSEd Maste             ProcessSP process_sp(target_sp->GetProcessSP());
2188ac7ddfbfSEd Maste             if (process_sp)
2189ac7ddfbfSEd Maste               process_sp->Flush();
2190ac7ddfbfSEd Maste           }
2191435933ddSDimitry Andric         } else {
2192ac7ddfbfSEd Maste           module_sp->GetFileSpec().GetPath(path, sizeof(path));
2193435933ddSDimitry Andric           sb_error.SetErrorStringWithFormat("no sections in object file '%s'",
2194435933ddSDimitry Andric                                             path);
2195ac7ddfbfSEd Maste         }
2196435933ddSDimitry Andric       } else {
2197ac7ddfbfSEd Maste         module_sp->GetFileSpec().GetPath(path, sizeof(path));
2198435933ddSDimitry Andric         sb_error.SetErrorStringWithFormat("no object file for module '%s'",
2199435933ddSDimitry Andric                                           path);
2200ac7ddfbfSEd Maste       }
2201435933ddSDimitry Andric     } else {
2202ac7ddfbfSEd Maste       sb_error.SetErrorStringWithFormat("invalid module");
2203ac7ddfbfSEd Maste     }
2204435933ddSDimitry Andric   } else {
2205ac7ddfbfSEd Maste     sb_error.SetErrorStringWithFormat("invalid target");
2206ac7ddfbfSEd Maste   }
2207ac7ddfbfSEd Maste   return sb_error;
2208ac7ddfbfSEd Maste }
2209ac7ddfbfSEd Maste 
FindSymbols(const char * name,lldb::SymbolType symbol_type)2210435933ddSDimitry Andric lldb::SBSymbolContextList SBTarget::FindSymbols(const char *name,
2211435933ddSDimitry Andric                                                 lldb::SymbolType symbol_type) {
2212ac7ddfbfSEd Maste   SBSymbolContextList sb_sc_list;
2213435933ddSDimitry Andric   if (name && name[0]) {
2214ac7ddfbfSEd Maste     TargetSP target_sp(GetSP());
2215435933ddSDimitry Andric     if (target_sp) {
2216ac7ddfbfSEd Maste       bool append = true;
2217435933ddSDimitry Andric       target_sp->GetImages().FindSymbolsWithNameAndType(
2218435933ddSDimitry Andric           ConstString(name), symbol_type, *sb_sc_list, append);
2219ac7ddfbfSEd Maste     }
2220ac7ddfbfSEd Maste   }
2221ac7ddfbfSEd Maste   return sb_sc_list;
2222ac7ddfbfSEd Maste }
2223ac7ddfbfSEd Maste 
EvaluateExpression(const char * expr)2224435933ddSDimitry Andric lldb::SBValue SBTarget::EvaluateExpression(const char *expr) {
2225b91a7dfcSDimitry Andric   TargetSP target_sp(GetSP());
2226b91a7dfcSDimitry Andric   if (!target_sp)
2227b91a7dfcSDimitry Andric     return SBValue();
2228b91a7dfcSDimitry Andric 
2229b91a7dfcSDimitry Andric   SBExpressionOptions options;
2230435933ddSDimitry Andric   lldb::DynamicValueType fetch_dynamic_value =
2231435933ddSDimitry Andric       target_sp->GetPreferDynamicValue();
2232b91a7dfcSDimitry Andric   options.SetFetchDynamicValue(fetch_dynamic_value);
2233b91a7dfcSDimitry Andric   options.SetUnwindOnError(true);
2234b91a7dfcSDimitry Andric   return EvaluateExpression(expr, options);
2235b91a7dfcSDimitry Andric }
2236ac7ddfbfSEd Maste 
EvaluateExpression(const char * expr,const SBExpressionOptions & options)2237435933ddSDimitry Andric lldb::SBValue SBTarget::EvaluateExpression(const char *expr,
2238435933ddSDimitry Andric                                            const SBExpressionOptions &options) {
2239ac7ddfbfSEd Maste   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
22404bb0738eSEd Maste #if !defined(LLDB_DISABLE_PYTHON)
2241ac7ddfbfSEd Maste   Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
22424bb0738eSEd Maste #endif
2243ac7ddfbfSEd Maste   SBValue expr_result;
22440127ef0fSEd Maste   ExpressionResults exe_results = eExpressionSetupError;
2245ac7ddfbfSEd Maste   ValueObjectSP expr_value_sp;
2246ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
2247ac7ddfbfSEd Maste   StackFrame *frame = NULL;
2248435933ddSDimitry Andric   if (target_sp) {
2249435933ddSDimitry Andric     if (expr == NULL || expr[0] == '\0') {
2250ac7ddfbfSEd Maste       if (log)
2251435933ddSDimitry Andric         log->Printf(
2252435933ddSDimitry Andric             "SBTarget::EvaluateExpression called with an empty expression");
2253ac7ddfbfSEd Maste       return expr_result;
2254ac7ddfbfSEd Maste     }
2255ac7ddfbfSEd Maste 
22564bb0738eSEd Maste     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2257ac7ddfbfSEd Maste     ExecutionContext exe_ctx(m_opaque_sp.get());
2258ac7ddfbfSEd Maste 
2259ac7ddfbfSEd Maste     if (log)
2260ac7ddfbfSEd Maste       log->Printf("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr);
2261ac7ddfbfSEd Maste 
2262ac7ddfbfSEd Maste     frame = exe_ctx.GetFramePtr();
2263ac7ddfbfSEd Maste     Target *target = exe_ctx.GetTargetPtr();
2264ac7ddfbfSEd Maste 
2265435933ddSDimitry Andric     if (target) {
2266ac7ddfbfSEd Maste #ifdef LLDB_CONFIGURATION_DEBUG
2267ac7ddfbfSEd Maste       StreamString frame_description;
2268ac7ddfbfSEd Maste       if (frame)
2269ac7ddfbfSEd Maste         frame->DumpUsingSettingsFormat(&frame_description);
2270435933ddSDimitry Andric       llvm::PrettyStackTraceFormat stack_trace(
2271435933ddSDimitry Andric           "SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = "
2272435933ddSDimitry Andric           "%u) %s",
2273435933ddSDimitry Andric           expr, options.GetFetchDynamicValue(),
2274435933ddSDimitry Andric           frame_description.GetString().str().c_str());
2275ac7ddfbfSEd Maste #endif
2276435933ddSDimitry Andric       exe_results =
2277435933ddSDimitry Andric           target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2278ac7ddfbfSEd Maste 
2279ac7ddfbfSEd Maste       expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2280435933ddSDimitry Andric     } else {
2281ac7ddfbfSEd Maste       if (log)
2282435933ddSDimitry Andric         log->Printf("SBTarget::EvaluateExpression () => error: could not "
2283435933ddSDimitry Andric                     "reconstruct frame object for this SBTarget.");
2284ac7ddfbfSEd Maste     }
2285ac7ddfbfSEd Maste   }
2286ac7ddfbfSEd Maste #ifndef LLDB_DISABLE_PYTHON
2287ac7ddfbfSEd Maste   if (expr_log)
2288435933ddSDimitry Andric     expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is "
2289435933ddSDimitry Andric                      "%s, summary %s **",
22900127ef0fSEd Maste                      expr_result.GetValue(), expr_result.GetSummary());
2291ac7ddfbfSEd Maste 
2292ac7ddfbfSEd Maste   if (log)
2293435933ddSDimitry Andric     log->Printf("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) "
2294435933ddSDimitry Andric                 "(execution result=%d)",
22950127ef0fSEd Maste                 static_cast<void *>(frame), expr,
22960127ef0fSEd Maste                 static_cast<void *>(expr_value_sp.get()), exe_results);
2297ac7ddfbfSEd Maste #endif
2298ac7ddfbfSEd Maste 
2299ac7ddfbfSEd Maste   return expr_result;
2300ac7ddfbfSEd Maste }
2301ac7ddfbfSEd Maste 
GetStackRedZoneSize()2302435933ddSDimitry Andric lldb::addr_t SBTarget::GetStackRedZoneSize() {
2303ac7ddfbfSEd Maste   TargetSP target_sp(GetSP());
2304435933ddSDimitry Andric   if (target_sp) {
2305ac7ddfbfSEd Maste     ABISP abi_sp;
2306ac7ddfbfSEd Maste     ProcessSP process_sp(target_sp->GetProcessSP());
2307ac7ddfbfSEd Maste     if (process_sp)
2308ac7ddfbfSEd Maste       abi_sp = process_sp->GetABI();
2309ac7ddfbfSEd Maste     else
2310a580b014SDimitry Andric       abi_sp = ABI::FindPlugin(ProcessSP(), target_sp->GetArchitecture());
2311ac7ddfbfSEd Maste     if (abi_sp)
2312ac7ddfbfSEd Maste       return abi_sp->GetRedZoneSize();
2313ac7ddfbfSEd Maste   }
2314ac7ddfbfSEd Maste   return 0;
2315ac7ddfbfSEd Maste }
2316ac7ddfbfSEd Maste 
GetLaunchInfo() const2317435933ddSDimitry Andric lldb::SBLaunchInfo SBTarget::GetLaunchInfo() const {
23181c3bbb01SEd Maste   lldb::SBLaunchInfo launch_info(NULL);
23191c3bbb01SEd Maste   TargetSP target_sp(GetSP());
23201c3bbb01SEd Maste   if (target_sp)
23214ba319b5SDimitry Andric     launch_info.set_ref(m_opaque_sp->GetProcessLaunchInfo());
23221c3bbb01SEd Maste   return launch_info;
23231c3bbb01SEd Maste }
23241c3bbb01SEd Maste 
SetLaunchInfo(const lldb::SBLaunchInfo & launch_info)2325435933ddSDimitry Andric void SBTarget::SetLaunchInfo(const lldb::SBLaunchInfo &launch_info) {
23261c3bbb01SEd Maste   TargetSP target_sp(GetSP());
23271c3bbb01SEd Maste   if (target_sp)
23281c3bbb01SEd Maste     m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
23291c3bbb01SEd Maste }
2330