xref: /src/contrib/llvm-project/lldb/source/API/SBTarget.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1cfca06d7SDimitry Andric //===-- SBTarget.cpp ------------------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste 
9f034231aSEd Maste #include "lldb/API/SBTarget.h"
106f8fc217SDimitry Andric #include "lldb/Utility/Instrumentation.h"
11145449b1SDimitry Andric #include "lldb/Utility/LLDBLog.h"
12f034231aSEd Maste #include "lldb/lldb-public.h"
13f034231aSEd Maste 
14f034231aSEd Maste #include "lldb/API/SBBreakpoint.h"
155e95aa85SEd Maste #include "lldb/API/SBDebugger.h"
16cfca06d7SDimitry Andric #include "lldb/API/SBEnvironment.h"
175e95aa85SEd Maste #include "lldb/API/SBEvent.h"
18f034231aSEd Maste #include "lldb/API/SBExpressionOptions.h"
19f034231aSEd Maste #include "lldb/API/SBFileSpec.h"
20f034231aSEd Maste #include "lldb/API/SBListener.h"
21f034231aSEd Maste #include "lldb/API/SBModule.h"
22f034231aSEd Maste #include "lldb/API/SBModuleSpec.h"
23f034231aSEd Maste #include "lldb/API/SBProcess.h"
2414f1b3e8SDimitry Andric #include "lldb/API/SBSourceManager.h"
25f034231aSEd Maste #include "lldb/API/SBStream.h"
26f3fbd1c0SDimitry Andric #include "lldb/API/SBStringList.h"
27f73363f1SDimitry Andric #include "lldb/API/SBStructuredData.h"
28f034231aSEd Maste #include "lldb/API/SBSymbolContextList.h"
29344a3780SDimitry Andric #include "lldb/API/SBTrace.h"
30f034231aSEd Maste #include "lldb/Breakpoint/BreakpointID.h"
31f034231aSEd Maste #include "lldb/Breakpoint/BreakpointIDList.h"
32f034231aSEd Maste #include "lldb/Breakpoint/BreakpointList.h"
33f034231aSEd Maste #include "lldb/Breakpoint/BreakpointLocation.h"
34f034231aSEd Maste #include "lldb/Core/Address.h"
35f034231aSEd Maste #include "lldb/Core/AddressResolver.h"
36f034231aSEd Maste #include "lldb/Core/Debugger.h"
37f034231aSEd Maste #include "lldb/Core/Disassembler.h"
38f034231aSEd Maste #include "lldb/Core/Module.h"
39f034231aSEd Maste #include "lldb/Core/ModuleSpec.h"
40b1c73532SDimitry Andric #include "lldb/Core/PluginManager.h"
41f034231aSEd Maste #include "lldb/Core/SearchFilter.h"
42f034231aSEd Maste #include "lldb/Core/Section.h"
43f73363f1SDimitry Andric #include "lldb/Core/StructuredDataImpl.h"
44f21a844fSEd Maste #include "lldb/Core/ValueObjectConstResult.h"
45f034231aSEd Maste #include "lldb/Core/ValueObjectList.h"
46f034231aSEd Maste #include "lldb/Core/ValueObjectVariable.h"
47f034231aSEd Maste #include "lldb/Host/Host.h"
485e95aa85SEd Maste #include "lldb/Symbol/DeclVendor.h"
49f034231aSEd Maste #include "lldb/Symbol/ObjectFile.h"
50f3fbd1c0SDimitry Andric #include "lldb/Symbol/SymbolFile.h"
51f034231aSEd Maste #include "lldb/Symbol/SymbolVendor.h"
52ead24645SDimitry Andric #include "lldb/Symbol/TypeSystem.h"
53f034231aSEd Maste #include "lldb/Symbol/VariableList.h"
545e95aa85SEd Maste #include "lldb/Target/ABI.h"
55e81d9d49SDimitry Andric #include "lldb/Target/Language.h"
56f034231aSEd Maste #include "lldb/Target/LanguageRuntime.h"
57f034231aSEd Maste #include "lldb/Target/Process.h"
585e95aa85SEd Maste #include "lldb/Target/StackFrame.h"
59f034231aSEd Maste #include "lldb/Target/Target.h"
60f034231aSEd Maste #include "lldb/Target/TargetList.h"
61ef5d0b5eSDimitry Andric #include "lldb/Utility/ArchSpec.h"
62f73363f1SDimitry Andric #include "lldb/Utility/Args.h"
6374a628f7SDimitry Andric #include "lldb/Utility/FileSpec.h"
645f29bb8aSDimitry Andric #include "lldb/Utility/ProcessInfo.h"
6574a628f7SDimitry Andric #include "lldb/Utility/RegularExpression.h"
66f034231aSEd Maste 
67f73363f1SDimitry Andric #include "Commands/CommandObjectBreakpoint.h"
6814f1b3e8SDimitry Andric #include "lldb/Interpreter/CommandReturnObject.h"
6914f1b3e8SDimitry Andric #include "llvm/Support/PrettyStackTrace.h"
70205afe67SEd Maste #include "llvm/Support/Regex.h"
71f034231aSEd Maste 
72f034231aSEd Maste using namespace lldb;
73f034231aSEd Maste using namespace lldb_private;
74f034231aSEd Maste 
75f034231aSEd Maste #define DEFAULT_DISASM_BYTE_SIZE 32
76f034231aSEd Maste 
AttachToProcess(ProcessAttachInfo & attach_info,Target & target)77c0981da4SDimitry Andric static Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target) {
78f3fbd1c0SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
795e95aa85SEd Maste 
805e95aa85SEd Maste   auto process_sp = target.GetProcessSP();
8114f1b3e8SDimitry Andric   if (process_sp) {
825e95aa85SEd Maste     const auto state = process_sp->GetState();
8314f1b3e8SDimitry Andric     if (process_sp->IsAlive() && state == eStateConnected) {
845e95aa85SEd Maste       // If we are already connected, then we have already specified the
85f73363f1SDimitry Andric       // listener, so if a valid listener is supplied, we need to error out to
86f73363f1SDimitry Andric       // let the client know.
875e95aa85SEd Maste       if (attach_info.GetListener())
88b76161e4SDimitry Andric         return Status("process is connected and already has a listener, pass "
8914f1b3e8SDimitry Andric                       "empty listener");
905e95aa85SEd Maste     }
91f034231aSEd Maste   }
92f034231aSEd Maste 
935e95aa85SEd Maste   return target.Attach(attach_info, nullptr);
94f034231aSEd Maste }
95f034231aSEd Maste 
96f034231aSEd Maste // SBTarget constructor
SBTarget()976f8fc217SDimitry Andric SBTarget::SBTarget() { LLDB_INSTRUMENT_VA(this); }
98f034231aSEd Maste 
SBTarget(const SBTarget & rhs)995f29bb8aSDimitry Andric SBTarget::SBTarget(const SBTarget &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
1006f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
1015f29bb8aSDimitry Andric }
1025f29bb8aSDimitry Andric 
SBTarget(const TargetSP & target_sp)1035f29bb8aSDimitry Andric SBTarget::SBTarget(const TargetSP &target_sp) : m_opaque_sp(target_sp) {
1046f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, target_sp);
1055f29bb8aSDimitry Andric }
1065f29bb8aSDimitry Andric 
operator =(const SBTarget & rhs)1075f29bb8aSDimitry Andric const SBTarget &SBTarget::operator=(const SBTarget &rhs) {
1086f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
1095f29bb8aSDimitry Andric 
1105f29bb8aSDimitry Andric   if (this != &rhs)
1115f29bb8aSDimitry Andric     m_opaque_sp = rhs.m_opaque_sp;
1126f8fc217SDimitry Andric   return *this;
1135f29bb8aSDimitry Andric }
1145f29bb8aSDimitry Andric 
115f034231aSEd Maste // Destructor
116cfca06d7SDimitry Andric SBTarget::~SBTarget() = default;
117f034231aSEd Maste 
EventIsTargetEvent(const SBEvent & event)11814f1b3e8SDimitry Andric bool SBTarget::EventIsTargetEvent(const SBEvent &event) {
1196f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(event);
1205f29bb8aSDimitry Andric 
1215f29bb8aSDimitry Andric   return Target::TargetEventData::GetEventDataFromEvent(event.get()) != nullptr;
1225e95aa85SEd Maste }
1235e95aa85SEd Maste 
GetTargetFromEvent(const SBEvent & event)12414f1b3e8SDimitry Andric SBTarget SBTarget::GetTargetFromEvent(const SBEvent &event) {
1256f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(event);
1265f29bb8aSDimitry Andric 
1276f8fc217SDimitry Andric   return Target::TargetEventData::GetTargetFromEvent(event.get());
1285e95aa85SEd Maste }
1295e95aa85SEd Maste 
GetNumModulesFromEvent(const SBEvent & event)13014f1b3e8SDimitry Andric uint32_t SBTarget::GetNumModulesFromEvent(const SBEvent &event) {
1316f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(event);
1325f29bb8aSDimitry Andric 
13314f1b3e8SDimitry Andric   const ModuleList module_list =
13414f1b3e8SDimitry Andric       Target::TargetEventData::GetModuleListFromEvent(event.get());
1355e95aa85SEd Maste   return module_list.GetSize();
1365e95aa85SEd Maste }
1375e95aa85SEd Maste 
GetModuleAtIndexFromEvent(const uint32_t idx,const SBEvent & event)13814f1b3e8SDimitry Andric SBModule SBTarget::GetModuleAtIndexFromEvent(const uint32_t idx,
13914f1b3e8SDimitry Andric                                              const SBEvent &event) {
1406f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(idx, event);
1415f29bb8aSDimitry Andric 
14214f1b3e8SDimitry Andric   const ModuleList module_list =
14314f1b3e8SDimitry Andric       Target::TargetEventData::GetModuleListFromEvent(event.get());
1446f8fc217SDimitry Andric   return SBModule(module_list.GetModuleAtIndex(idx));
1455e95aa85SEd Maste }
1465e95aa85SEd Maste 
GetBroadcasterClassName()14714f1b3e8SDimitry Andric const char *SBTarget::GetBroadcasterClassName() {
1486f8fc217SDimitry Andric   LLDB_INSTRUMENT();
1495f29bb8aSDimitry Andric 
150ac9a064cSDimitry Andric   return ConstString(Target::GetStaticBroadcasterClass()).AsCString();
151f034231aSEd Maste }
152f034231aSEd Maste 
IsValid() const15314f1b3e8SDimitry Andric bool SBTarget::IsValid() const {
1546f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1555f29bb8aSDimitry Andric   return this->operator bool();
1565f29bb8aSDimitry Andric }
operator bool() const1575f29bb8aSDimitry Andric SBTarget::operator bool() const {
1586f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1595f29bb8aSDimitry Andric 
1605f29bb8aSDimitry Andric   return m_opaque_sp.get() != nullptr && m_opaque_sp->IsValid();
161f034231aSEd Maste }
162f034231aSEd Maste 
GetProcess()16314f1b3e8SDimitry Andric SBProcess SBTarget::GetProcess() {
1646f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1655f29bb8aSDimitry Andric 
166f034231aSEd Maste   SBProcess sb_process;
167f034231aSEd Maste   ProcessSP process_sp;
168f034231aSEd Maste   TargetSP target_sp(GetSP());
16914f1b3e8SDimitry Andric   if (target_sp) {
170f034231aSEd Maste     process_sp = target_sp->GetProcessSP();
171f034231aSEd Maste     sb_process.SetSP(process_sp);
172f034231aSEd Maste   }
173f034231aSEd Maste 
1746f8fc217SDimitry Andric   return sb_process;
175f034231aSEd Maste }
176f034231aSEd Maste 
GetPlatform()17714f1b3e8SDimitry Andric SBPlatform SBTarget::GetPlatform() {
1786f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1795f29bb8aSDimitry Andric 
180205afe67SEd Maste   TargetSP target_sp(GetSP());
181205afe67SEd Maste   if (!target_sp)
1826f8fc217SDimitry Andric     return SBPlatform();
183205afe67SEd Maste 
184205afe67SEd Maste   SBPlatform platform;
185205afe67SEd Maste   platform.m_opaque_sp = target_sp->GetPlatform();
186205afe67SEd Maste 
1876f8fc217SDimitry Andric   return platform;
188205afe67SEd Maste }
189205afe67SEd Maste 
GetDebugger() const19014f1b3e8SDimitry Andric SBDebugger SBTarget::GetDebugger() const {
1916f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1925f29bb8aSDimitry Andric 
193f034231aSEd Maste   SBDebugger debugger;
194f034231aSEd Maste   TargetSP target_sp(GetSP());
195f034231aSEd Maste   if (target_sp)
196f034231aSEd Maste     debugger.reset(target_sp->GetDebugger().shared_from_this());
1976f8fc217SDimitry Andric   return debugger;
198f034231aSEd Maste }
199f034231aSEd Maste 
GetStatistics()200f73363f1SDimitry Andric SBStructuredData SBTarget::GetStatistics() {
2016f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
202ac9a064cSDimitry Andric   SBStatisticsOptions options;
203ac9a064cSDimitry Andric   return GetStatistics(options);
204ac9a064cSDimitry Andric }
205ac9a064cSDimitry Andric 
GetStatistics(SBStatisticsOptions options)206ac9a064cSDimitry Andric SBStructuredData SBTarget::GetStatistics(SBStatisticsOptions options) {
207ac9a064cSDimitry Andric   LLDB_INSTRUMENT_VA(this);
2085f29bb8aSDimitry Andric 
209f73363f1SDimitry Andric   SBStructuredData data;
210f73363f1SDimitry Andric   TargetSP target_sp(GetSP());
211f73363f1SDimitry Andric   if (!target_sp)
2126f8fc217SDimitry Andric     return data;
213c0981da4SDimitry Andric   std::string json_str =
214ac9a064cSDimitry Andric       llvm::formatv("{0:2}", DebuggerStats::ReportStatistics(
215ac9a064cSDimitry Andric                                  target_sp->GetDebugger(), target_sp.get(),
216ac9a064cSDimitry Andric                                  options.ref()))
217ac9a064cSDimitry Andric           .str();
218c0981da4SDimitry Andric   data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
2196f8fc217SDimitry Andric   return data;
220f73363f1SDimitry Andric }
221f73363f1SDimitry Andric 
SetCollectingStats(bool v)22294994d37SDimitry Andric void SBTarget::SetCollectingStats(bool v) {
2236f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, v);
2245f29bb8aSDimitry Andric 
22594994d37SDimitry Andric   TargetSP target_sp(GetSP());
22694994d37SDimitry Andric   if (!target_sp)
22794994d37SDimitry Andric     return;
228c0981da4SDimitry Andric   return DebuggerStats::SetCollectingStats(v);
22994994d37SDimitry Andric }
23094994d37SDimitry Andric 
GetCollectingStats()23194994d37SDimitry Andric bool SBTarget::GetCollectingStats() {
2326f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
2335f29bb8aSDimitry Andric 
23494994d37SDimitry Andric   TargetSP target_sp(GetSP());
23594994d37SDimitry Andric   if (!target_sp)
23694994d37SDimitry Andric     return false;
237c0981da4SDimitry Andric   return DebuggerStats::GetCollectingStats();
23894994d37SDimitry Andric }
23994994d37SDimitry Andric 
LoadCore(const char * core_file)24014f1b3e8SDimitry Andric SBProcess SBTarget::LoadCore(const char *core_file) {
2416f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, core_file);
2425f29bb8aSDimitry Andric 
243f73363f1SDimitry Andric   lldb::SBError error; // Ignored
2446f8fc217SDimitry Andric   return LoadCore(core_file, error);
245f73363f1SDimitry Andric }
246f73363f1SDimitry Andric 
LoadCore(const char * core_file,lldb::SBError & error)247f73363f1SDimitry Andric SBProcess SBTarget::LoadCore(const char *core_file, lldb::SBError &error) {
2486f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, core_file, error);
2495f29bb8aSDimitry Andric 
250f034231aSEd Maste   SBProcess sb_process;
251f034231aSEd Maste   TargetSP target_sp(GetSP());
25214f1b3e8SDimitry Andric   if (target_sp) {
25394994d37SDimitry Andric     FileSpec filespec(core_file);
25494994d37SDimitry Andric     FileSystem::Instance().Resolve(filespec);
25514f1b3e8SDimitry Andric     ProcessSP process_sp(target_sp->CreateProcess(
256b60736ecSDimitry Andric         target_sp->GetDebugger().GetListener(), "", &filespec, false));
25714f1b3e8SDimitry Andric     if (process_sp) {
258f73363f1SDimitry Andric       error.SetError(process_sp->LoadCore());
259f73363f1SDimitry Andric       if (error.Success())
260f034231aSEd Maste         sb_process.SetSP(process_sp);
261f73363f1SDimitry Andric     } else {
262f73363f1SDimitry Andric       error.SetErrorString("Failed to create the process");
263f034231aSEd Maste     }
264f73363f1SDimitry Andric   } else {
265f73363f1SDimitry Andric     error.SetErrorString("SBTarget is invalid");
266f034231aSEd Maste   }
2676f8fc217SDimitry Andric   return sb_process;
268f034231aSEd Maste }
269f034231aSEd Maste 
LaunchSimple(char const ** argv,char const ** envp,const char * working_directory)27014f1b3e8SDimitry Andric SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp,
27114f1b3e8SDimitry Andric                                  const char *working_directory) {
2726f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, argv, envp, working_directory);
2735f29bb8aSDimitry Andric 
274b60736ecSDimitry Andric   TargetSP target_sp = GetSP();
275b60736ecSDimitry Andric   if (!target_sp)
2766f8fc217SDimitry Andric     return SBProcess();
277b60736ecSDimitry Andric 
278b60736ecSDimitry Andric   SBLaunchInfo launch_info = GetLaunchInfo();
279b60736ecSDimitry Andric 
280b60736ecSDimitry Andric   if (Module *exe_module = target_sp->GetExecutableModulePointer())
281b60736ecSDimitry Andric     launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(),
282b60736ecSDimitry Andric                                   /*add_as_first_arg*/ true);
283b60736ecSDimitry Andric   if (argv)
284b60736ecSDimitry Andric     launch_info.SetArguments(argv, /*append*/ true);
285b60736ecSDimitry Andric   if (envp)
286b60736ecSDimitry Andric     launch_info.SetEnvironmentEntries(envp, /*append*/ false);
287b60736ecSDimitry Andric   if (working_directory)
288b60736ecSDimitry Andric     launch_info.SetWorkingDirectory(working_directory);
289b60736ecSDimitry Andric 
290f034231aSEd Maste   SBError error;
2916f8fc217SDimitry Andric   return Launch(launch_info, error);
292f034231aSEd Maste }
293f034231aSEd Maste 
Install()29414f1b3e8SDimitry Andric SBError SBTarget::Install() {
2956f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
2965f29bb8aSDimitry Andric 
29786758c71SEd Maste   SBError sb_error;
29886758c71SEd Maste   TargetSP target_sp(GetSP());
29914f1b3e8SDimitry Andric   if (target_sp) {
300f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
3015f29bb8aSDimitry Andric     sb_error.ref() = target_sp->Install(nullptr);
30286758c71SEd Maste   }
3036f8fc217SDimitry Andric   return sb_error;
30486758c71SEd Maste }
30586758c71SEd 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)30614f1b3e8SDimitry Andric SBProcess SBTarget::Launch(SBListener &listener, char const **argv,
30714f1b3e8SDimitry Andric                            char const **envp, const char *stdin_path,
30814f1b3e8SDimitry Andric                            const char *stdout_path, const char *stderr_path,
309f034231aSEd Maste                            const char *working_directory,
310f034231aSEd Maste                            uint32_t launch_flags, // See LaunchFlags
31114f1b3e8SDimitry Andric                            bool stop_at_entry, lldb::SBError &error) {
3126f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, listener, argv, envp, stdin_path, stdout_path,
3136f8fc217SDimitry Andric                      stderr_path, working_directory, launch_flags,
3146f8fc217SDimitry Andric                      stop_at_entry, error);
315f034231aSEd Maste 
316f034231aSEd Maste   SBProcess sb_process;
317f034231aSEd Maste   ProcessSP process_sp;
318f034231aSEd Maste   TargetSP target_sp(GetSP());
319f034231aSEd Maste 
32014f1b3e8SDimitry Andric   if (target_sp) {
321f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
322f034231aSEd Maste 
32312bd4897SEd Maste     if (stop_at_entry)
32412bd4897SEd Maste       launch_flags |= eLaunchFlagStopAtEntry;
32512bd4897SEd Maste 
326f034231aSEd Maste     if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
327f034231aSEd Maste       launch_flags |= eLaunchFlagDisableASLR;
328f034231aSEd Maste 
329f034231aSEd Maste     StateType state = eStateInvalid;
330f034231aSEd Maste     process_sp = target_sp->GetProcessSP();
33114f1b3e8SDimitry Andric     if (process_sp) {
332f034231aSEd Maste       state = process_sp->GetState();
333f034231aSEd Maste 
33414f1b3e8SDimitry Andric       if (process_sp->IsAlive() && state != eStateConnected) {
335f034231aSEd Maste         if (state == eStateAttaching)
336f034231aSEd Maste           error.SetErrorString("process attach is in progress");
337f034231aSEd Maste         else
338f034231aSEd Maste           error.SetErrorString("a process is already being debugged");
3396f8fc217SDimitry Andric         return sb_process;
340f034231aSEd Maste       }
341f034231aSEd Maste     }
342f034231aSEd Maste 
34314f1b3e8SDimitry Andric     if (state == eStateConnected) {
344f034231aSEd Maste       // If we are already connected, then we have already specified the
345f73363f1SDimitry Andric       // listener, so if a valid listener is supplied, we need to error out to
346f73363f1SDimitry Andric       // let the client know.
34714f1b3e8SDimitry Andric       if (listener.IsValid()) {
34814f1b3e8SDimitry Andric         error.SetErrorString("process is connected and already has a listener, "
34914f1b3e8SDimitry Andric                              "pass empty listener");
3506f8fc217SDimitry Andric         return sb_process;
351f034231aSEd Maste       }
352f034231aSEd Maste     }
353f034231aSEd Maste 
354f034231aSEd Maste     if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
355f034231aSEd Maste       launch_flags |= eLaunchFlagDisableSTDIO;
356f034231aSEd Maste 
35794994d37SDimitry Andric     ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
35894994d37SDimitry Andric                                   FileSpec(stderr_path),
35994994d37SDimitry Andric                                   FileSpec(working_directory), launch_flags);
360f034231aSEd Maste 
361f034231aSEd Maste     Module *exe_module = target_sp->GetExecutableModulePointer();
362f034231aSEd Maste     if (exe_module)
363f034231aSEd Maste       launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
364cfca06d7SDimitry Andric     if (argv) {
365f034231aSEd Maste       launch_info.GetArguments().AppendArguments(argv);
366cfca06d7SDimitry Andric     } else {
367cfca06d7SDimitry Andric       auto default_launch_info = target_sp->GetProcessLaunchInfo();
368cfca06d7SDimitry Andric       launch_info.GetArguments().AppendArguments(
369cfca06d7SDimitry Andric           default_launch_info.GetArguments());
370cfca06d7SDimitry Andric     }
371cfca06d7SDimitry Andric     if (envp) {
372f73363f1SDimitry Andric       launch_info.GetEnvironment() = Environment(envp);
373cfca06d7SDimitry Andric     } else {
374cfca06d7SDimitry Andric       auto default_launch_info = target_sp->GetProcessLaunchInfo();
375cfca06d7SDimitry Andric       launch_info.GetEnvironment() = default_launch_info.GetEnvironment();
376cfca06d7SDimitry Andric     }
377f034231aSEd Maste 
378866dcdacSEd Maste     if (listener.IsValid())
379205afe67SEd Maste       launch_info.SetListener(listener.GetSP());
380205afe67SEd Maste 
3815f29bb8aSDimitry Andric     error.SetError(target_sp->Launch(launch_info, nullptr));
382866dcdacSEd Maste 
383866dcdacSEd Maste     sb_process.SetSP(target_sp->GetProcessSP());
38414f1b3e8SDimitry Andric   } else {
385f034231aSEd Maste     error.SetErrorString("SBTarget is invalid");
386f034231aSEd Maste   }
387f034231aSEd Maste 
3886f8fc217SDimitry Andric   return sb_process;
389f034231aSEd Maste }
390f034231aSEd Maste 
Launch(SBLaunchInfo & sb_launch_info,SBError & error)39114f1b3e8SDimitry Andric SBProcess SBTarget::Launch(SBLaunchInfo &sb_launch_info, SBError &error) {
3926f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, sb_launch_info, error);
393f034231aSEd Maste 
394f034231aSEd Maste   SBProcess sb_process;
395f034231aSEd Maste   TargetSP target_sp(GetSP());
396f034231aSEd Maste 
39714f1b3e8SDimitry Andric   if (target_sp) {
398f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
399f034231aSEd Maste     StateType state = eStateInvalid;
400866dcdacSEd Maste     {
401866dcdacSEd Maste       ProcessSP process_sp = target_sp->GetProcessSP();
40214f1b3e8SDimitry Andric       if (process_sp) {
403f034231aSEd Maste         state = process_sp->GetState();
404f034231aSEd Maste 
40514f1b3e8SDimitry Andric         if (process_sp->IsAlive() && state != eStateConnected) {
406f034231aSEd Maste           if (state == eStateAttaching)
407f034231aSEd Maste             error.SetErrorString("process attach is in progress");
408f034231aSEd Maste           else
409f034231aSEd Maste             error.SetErrorString("a process is already being debugged");
4106f8fc217SDimitry Andric           return sb_process;
411f034231aSEd Maste         }
412f034231aSEd Maste       }
413866dcdacSEd Maste     }
414f034231aSEd Maste 
415f73363f1SDimitry Andric     lldb_private::ProcessLaunchInfo launch_info = sb_launch_info.ref();
416f034231aSEd Maste 
41714f1b3e8SDimitry Andric     if (!launch_info.GetExecutableFile()) {
418f034231aSEd Maste       Module *exe_module = target_sp->GetExecutableModulePointer();
419f034231aSEd Maste       if (exe_module)
420f034231aSEd Maste         launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
4210cac4ca3SEd Maste     }
422f034231aSEd Maste 
423f034231aSEd Maste     const ArchSpec &arch_spec = target_sp->GetArchitecture();
424f034231aSEd Maste     if (arch_spec.IsValid())
425f034231aSEd Maste       launch_info.GetArchitecture() = arch_spec;
426f034231aSEd Maste 
4275f29bb8aSDimitry Andric     error.SetError(target_sp->Launch(launch_info, nullptr));
428f73363f1SDimitry Andric     sb_launch_info.set_ref(launch_info);
429866dcdacSEd Maste     sb_process.SetSP(target_sp->GetProcessSP());
43014f1b3e8SDimitry Andric   } else {
431f034231aSEd Maste     error.SetErrorString("SBTarget is invalid");
432f034231aSEd Maste   }
433f034231aSEd Maste 
4346f8fc217SDimitry Andric   return sb_process;
435f034231aSEd Maste }
436f034231aSEd Maste 
Attach(SBAttachInfo & sb_attach_info,SBError & error)43714f1b3e8SDimitry Andric lldb::SBProcess SBTarget::Attach(SBAttachInfo &sb_attach_info, SBError &error) {
4386f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, sb_attach_info, error);
439f034231aSEd Maste 
440f034231aSEd Maste   SBProcess sb_process;
441f034231aSEd Maste   TargetSP target_sp(GetSP());
442f034231aSEd Maste 
44314f1b3e8SDimitry Andric   if (target_sp) {
444f034231aSEd Maste     ProcessAttachInfo &attach_info = sb_attach_info.ref();
4457fa27ce4SDimitry Andric     if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid() &&
4467fa27ce4SDimitry Andric         !attach_info.IsScriptedProcess()) {
447f034231aSEd Maste       PlatformSP platform_sp = target_sp->GetPlatform();
448f034231aSEd Maste       // See if we can pre-verify if a process exists or not
44914f1b3e8SDimitry Andric       if (platform_sp && platform_sp->IsConnected()) {
450f034231aSEd Maste         lldb::pid_t attach_pid = attach_info.GetProcessID();
451f034231aSEd Maste         ProcessInstanceInfo instance_info;
45214f1b3e8SDimitry Andric         if (platform_sp->GetProcessInfo(attach_pid, instance_info)) {
453f034231aSEd Maste           attach_info.SetUserID(instance_info.GetEffectiveUserID());
45414f1b3e8SDimitry Andric         } else {
45514f1b3e8SDimitry Andric           error.ref().SetErrorStringWithFormat(
45614f1b3e8SDimitry Andric               "no process found with process ID %" PRIu64, attach_pid);
4576f8fc217SDimitry Andric           return sb_process;
458f034231aSEd Maste         }
459f034231aSEd Maste       }
460f034231aSEd Maste     }
4615e95aa85SEd Maste     error.SetError(AttachToProcess(attach_info, *target_sp));
462f034231aSEd Maste     if (error.Success())
4635e95aa85SEd Maste       sb_process.SetSP(target_sp->GetProcessSP());
46414f1b3e8SDimitry Andric   } else {
465f034231aSEd Maste     error.SetErrorString("SBTarget is invalid");
466f034231aSEd Maste   }
467f034231aSEd Maste 
4686f8fc217SDimitry Andric   return sb_process;
469f034231aSEd Maste }
470f034231aSEd Maste 
AttachToProcessWithID(SBListener & listener,lldb::pid_t pid,SBError & error)47114f1b3e8SDimitry Andric lldb::SBProcess SBTarget::AttachToProcessWithID(
472f034231aSEd Maste     SBListener &listener,
473f034231aSEd Maste     lldb::pid_t pid, // The process ID to attach to
474f034231aSEd Maste     SBError &error   // An error explaining what went wrong if attach fails
47514f1b3e8SDimitry Andric ) {
4766f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, listener, pid, error);
477f034231aSEd Maste 
478f034231aSEd Maste   SBProcess sb_process;
479f034231aSEd Maste   TargetSP target_sp(GetSP());
480f034231aSEd Maste 
48114f1b3e8SDimitry Andric   if (target_sp) {
482f034231aSEd Maste     ProcessAttachInfo attach_info;
483f034231aSEd Maste     attach_info.SetProcessID(pid);
4845e95aa85SEd Maste     if (listener.IsValid())
4855e95aa85SEd Maste       attach_info.SetListener(listener.GetSP());
486f034231aSEd Maste 
487f034231aSEd Maste     ProcessInstanceInfo instance_info;
4885e95aa85SEd Maste     if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info))
489f034231aSEd Maste       attach_info.SetUserID(instance_info.GetEffectiveUserID());
4905e95aa85SEd Maste 
4915e95aa85SEd Maste     error.SetError(AttachToProcess(attach_info, *target_sp));
492f034231aSEd Maste     if (error.Success())
4935e95aa85SEd Maste       sb_process.SetSP(target_sp->GetProcessSP());
49414f1b3e8SDimitry Andric   } else
495f034231aSEd Maste     error.SetErrorString("SBTarget is invalid");
496f034231aSEd Maste 
4976f8fc217SDimitry Andric   return sb_process;
498f034231aSEd Maste }
499f034231aSEd Maste 
AttachToProcessWithName(SBListener & listener,const char * name,bool wait_for,SBError & error)50014f1b3e8SDimitry Andric lldb::SBProcess SBTarget::AttachToProcessWithName(
501f034231aSEd Maste     SBListener &listener,
502f034231aSEd Maste     const char *name, // basename of process to attach to
503f034231aSEd Maste     bool wait_for, // if true wait for a new instance of "name" to be launched
504f034231aSEd Maste     SBError &error // An error explaining what went wrong if attach fails
50514f1b3e8SDimitry Andric ) {
5066f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, listener, name, wait_for, error);
507f034231aSEd Maste 
508f034231aSEd Maste   SBProcess sb_process;
509f034231aSEd Maste   TargetSP target_sp(GetSP());
510f034231aSEd Maste 
51114f1b3e8SDimitry Andric   if (name && target_sp) {
512f034231aSEd Maste     ProcessAttachInfo attach_info;
51394994d37SDimitry Andric     attach_info.GetExecutableFile().SetFile(name, FileSpec::Style::native);
514f034231aSEd Maste     attach_info.SetWaitForLaunch(wait_for);
5155e95aa85SEd Maste     if (listener.IsValid())
5165e95aa85SEd Maste       attach_info.SetListener(listener.GetSP());
5175e95aa85SEd Maste 
5185e95aa85SEd Maste     error.SetError(AttachToProcess(attach_info, *target_sp));
519f034231aSEd Maste     if (error.Success())
5205e95aa85SEd Maste       sb_process.SetSP(target_sp->GetProcessSP());
52114f1b3e8SDimitry Andric   } else
522f034231aSEd Maste     error.SetErrorString("SBTarget is invalid");
523f034231aSEd Maste 
5246f8fc217SDimitry Andric   return sb_process;
525f034231aSEd Maste }
526f034231aSEd Maste 
ConnectRemote(SBListener & listener,const char * url,const char * plugin_name,SBError & error)52714f1b3e8SDimitry Andric lldb::SBProcess SBTarget::ConnectRemote(SBListener &listener, const char *url,
528f034231aSEd Maste                                         const char *plugin_name,
52914f1b3e8SDimitry Andric                                         SBError &error) {
5306f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, listener, url, plugin_name, error);
531f034231aSEd Maste 
532f034231aSEd Maste   SBProcess sb_process;
533f034231aSEd Maste   ProcessSP process_sp;
534f034231aSEd Maste   TargetSP target_sp(GetSP());
535f034231aSEd Maste 
53614f1b3e8SDimitry Andric   if (target_sp) {
537f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
538f034231aSEd Maste     if (listener.IsValid())
53914f1b3e8SDimitry Andric       process_sp =
540b60736ecSDimitry Andric           target_sp->CreateProcess(listener.m_opaque_sp, plugin_name, nullptr,
541b60736ecSDimitry Andric                                    true);
542f034231aSEd Maste     else
54314f1b3e8SDimitry Andric       process_sp = target_sp->CreateProcess(
544b60736ecSDimitry Andric           target_sp->GetDebugger().GetListener(), plugin_name, nullptr, true);
545f034231aSEd Maste 
54614f1b3e8SDimitry Andric     if (process_sp) {
547f034231aSEd Maste       sb_process.SetSP(process_sp);
548cfca06d7SDimitry Andric       error.SetError(process_sp->ConnectRemote(url));
54914f1b3e8SDimitry Andric     } else {
550f034231aSEd Maste       error.SetErrorString("unable to create lldb_private::Process");
551f034231aSEd Maste     }
55214f1b3e8SDimitry Andric   } else {
553f034231aSEd Maste     error.SetErrorString("SBTarget is invalid");
554f034231aSEd Maste   }
555f034231aSEd Maste 
5566f8fc217SDimitry Andric   return sb_process;
557f034231aSEd Maste }
558f034231aSEd Maste 
GetExecutable()55914f1b3e8SDimitry Andric SBFileSpec SBTarget::GetExecutable() {
5606f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
561f034231aSEd Maste 
562f034231aSEd Maste   SBFileSpec exe_file_spec;
563f034231aSEd Maste   TargetSP target_sp(GetSP());
56414f1b3e8SDimitry Andric   if (target_sp) {
565f034231aSEd Maste     Module *exe_module = target_sp->GetExecutableModulePointer();
566f034231aSEd Maste     if (exe_module)
567f034231aSEd Maste       exe_file_spec.SetFileSpec(exe_module->GetFileSpec());
568f034231aSEd Maste   }
569f034231aSEd Maste 
5706f8fc217SDimitry Andric   return exe_file_spec;
571f034231aSEd Maste }
572f034231aSEd Maste 
operator ==(const SBTarget & rhs) const57314f1b3e8SDimitry Andric bool SBTarget::operator==(const SBTarget &rhs) const {
5746f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
5755f29bb8aSDimitry Andric 
576f034231aSEd Maste   return m_opaque_sp.get() == rhs.m_opaque_sp.get();
577f034231aSEd Maste }
578f034231aSEd Maste 
operator !=(const SBTarget & rhs) const57914f1b3e8SDimitry Andric bool SBTarget::operator!=(const SBTarget &rhs) const {
5806f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, rhs);
5815f29bb8aSDimitry Andric 
582f034231aSEd Maste   return m_opaque_sp.get() != rhs.m_opaque_sp.get();
583f034231aSEd Maste }
584f034231aSEd Maste 
GetSP() const58514f1b3e8SDimitry Andric lldb::TargetSP SBTarget::GetSP() const { return m_opaque_sp; }
586f034231aSEd Maste 
SetSP(const lldb::TargetSP & target_sp)58714f1b3e8SDimitry Andric void SBTarget::SetSP(const lldb::TargetSP &target_sp) {
588f034231aSEd Maste   m_opaque_sp = target_sp;
589f034231aSEd Maste }
590f034231aSEd Maste 
ResolveLoadAddress(lldb::addr_t vm_addr)59114f1b3e8SDimitry Andric lldb::SBAddress SBTarget::ResolveLoadAddress(lldb::addr_t vm_addr) {
5926f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, vm_addr);
5935f29bb8aSDimitry Andric 
594f034231aSEd Maste   lldb::SBAddress sb_addr;
595f034231aSEd Maste   Address &addr = sb_addr.ref();
596f034231aSEd Maste   TargetSP target_sp(GetSP());
59714f1b3e8SDimitry Andric   if (target_sp) {
598f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
599866dcdacSEd Maste     if (target_sp->ResolveLoadAddress(vm_addr, addr))
6006f8fc217SDimitry Andric       return sb_addr;
601866dcdacSEd Maste   }
602866dcdacSEd Maste 
603866dcdacSEd Maste   // We have a load address that isn't in a section, just return an address
604866dcdacSEd Maste   // with the offset filled in (the address) and the section set to NULL
605866dcdacSEd Maste   addr.SetRawAddress(vm_addr);
6066f8fc217SDimitry Andric   return sb_addr;
607866dcdacSEd Maste }
608866dcdacSEd Maste 
ResolveFileAddress(lldb::addr_t file_addr)60914f1b3e8SDimitry Andric lldb::SBAddress SBTarget::ResolveFileAddress(lldb::addr_t file_addr) {
6106f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, file_addr);
6115f29bb8aSDimitry Andric 
612205afe67SEd Maste   lldb::SBAddress sb_addr;
613205afe67SEd Maste   Address &addr = sb_addr.ref();
614205afe67SEd Maste   TargetSP target_sp(GetSP());
61514f1b3e8SDimitry Andric   if (target_sp) {
616f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
617205afe67SEd Maste     if (target_sp->ResolveFileAddress(file_addr, addr))
6186f8fc217SDimitry Andric       return sb_addr;
619205afe67SEd Maste   }
620205afe67SEd Maste 
621205afe67SEd Maste   addr.SetRawAddress(file_addr);
6226f8fc217SDimitry Andric   return sb_addr;
623205afe67SEd Maste }
624866dcdacSEd Maste 
ResolvePastLoadAddress(uint32_t stop_id,lldb::addr_t vm_addr)62514f1b3e8SDimitry Andric lldb::SBAddress SBTarget::ResolvePastLoadAddress(uint32_t stop_id,
62614f1b3e8SDimitry Andric                                                  lldb::addr_t vm_addr) {
6276f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, stop_id, vm_addr);
6285f29bb8aSDimitry Andric 
629866dcdacSEd Maste   lldb::SBAddress sb_addr;
630866dcdacSEd Maste   Address &addr = sb_addr.ref();
631866dcdacSEd Maste   TargetSP target_sp(GetSP());
63214f1b3e8SDimitry Andric   if (target_sp) {
633f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
634866dcdacSEd Maste     if (target_sp->ResolveLoadAddress(vm_addr, addr))
6356f8fc217SDimitry Andric       return sb_addr;
636f034231aSEd Maste   }
637f034231aSEd Maste 
638f034231aSEd Maste   // We have a load address that isn't in a section, just return an address
639f034231aSEd Maste   // with the offset filled in (the address) and the section set to NULL
640f034231aSEd Maste   addr.SetRawAddress(vm_addr);
6416f8fc217SDimitry Andric   return sb_addr;
642f034231aSEd Maste }
643f034231aSEd Maste 
644f034231aSEd Maste SBSymbolContext
ResolveSymbolContextForAddress(const SBAddress & addr,uint32_t resolve_scope)645f21a844fSEd Maste SBTarget::ResolveSymbolContextForAddress(const SBAddress &addr,
64614f1b3e8SDimitry Andric                                          uint32_t resolve_scope) {
6476f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, addr, resolve_scope);
6485f29bb8aSDimitry Andric 
649f034231aSEd Maste   SBSymbolContext sc;
65094994d37SDimitry Andric   SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
65114f1b3e8SDimitry Andric   if (addr.IsValid()) {
652f034231aSEd Maste     TargetSP target_sp(GetSP());
653f034231aSEd Maste     if (target_sp)
65494994d37SDimitry Andric       target_sp->GetImages().ResolveSymbolContextForAddress(addr.ref(), scope,
65594994d37SDimitry Andric                                                             sc.ref());
656f034231aSEd Maste   }
6576f8fc217SDimitry Andric   return sc;
658f034231aSEd Maste }
659f034231aSEd Maste 
ReadMemory(const SBAddress addr,void * buf,size_t size,lldb::SBError & error)66014f1b3e8SDimitry Andric size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size,
66114f1b3e8SDimitry Andric                             lldb::SBError &error) {
6626f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, addr, buf, size, error);
6635f29bb8aSDimitry Andric 
664205afe67SEd Maste   SBError sb_error;
665205afe67SEd Maste   size_t bytes_read = 0;
666205afe67SEd Maste   TargetSP target_sp(GetSP());
66714f1b3e8SDimitry Andric   if (target_sp) {
668f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
66914f1b3e8SDimitry Andric     bytes_read =
670344a3780SDimitry Andric         target_sp->ReadMemory(addr.ref(), buf, size, sb_error.ref(), true);
67114f1b3e8SDimitry Andric   } else {
672205afe67SEd Maste     sb_error.SetErrorString("invalid target");
673205afe67SEd Maste   }
674205afe67SEd Maste 
675205afe67SEd Maste   return bytes_read;
676205afe67SEd Maste }
677f034231aSEd Maste 
BreakpointCreateByLocation(const char * file,uint32_t line)67814f1b3e8SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByLocation(const char *file,
67914f1b3e8SDimitry Andric                                                   uint32_t line) {
6806f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, file, line);
6815f29bb8aSDimitry Andric 
6826f8fc217SDimitry Andric   return SBBreakpoint(
6836f8fc217SDimitry Andric       BreakpointCreateByLocation(SBFileSpec(file, false), line));
684f034231aSEd Maste }
685f034231aSEd Maste 
686f034231aSEd Maste SBBreakpoint
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line)687f21a844fSEd Maste SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
68814f1b3e8SDimitry Andric                                      uint32_t line) {
6896f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, sb_file_spec, line);
6905f29bb8aSDimitry Andric 
6916f8fc217SDimitry Andric   return BreakpointCreateByLocation(sb_file_spec, line, 0);
692f3fbd1c0SDimitry Andric }
693f3fbd1c0SDimitry Andric 
694f3fbd1c0SDimitry Andric SBBreakpoint
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,lldb::addr_t offset)695f3fbd1c0SDimitry Andric SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
69614f1b3e8SDimitry Andric                                      uint32_t line, lldb::addr_t offset) {
6976f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, sb_file_spec, line, offset);
6985f29bb8aSDimitry Andric 
69914f1b3e8SDimitry Andric   SBFileSpecList empty_list;
7006f8fc217SDimitry Andric   return BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list);
70114f1b3e8SDimitry Andric }
70214f1b3e8SDimitry Andric 
70314f1b3e8SDimitry Andric SBBreakpoint
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,lldb::addr_t offset,SBFileSpecList & sb_module_list)70414f1b3e8SDimitry Andric SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
70514f1b3e8SDimitry Andric                                      uint32_t line, lldb::addr_t offset,
70614f1b3e8SDimitry Andric                                      SBFileSpecList &sb_module_list) {
7076f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, sb_file_spec, line, offset, sb_module_list);
7085f29bb8aSDimitry Andric 
7096f8fc217SDimitry Andric   return BreakpointCreateByLocation(sb_file_spec, line, 0, offset,
7106f8fc217SDimitry Andric                                     sb_module_list);
71194994d37SDimitry Andric }
71294994d37SDimitry Andric 
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,uint32_t column,lldb::addr_t offset,SBFileSpecList & sb_module_list)71394994d37SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByLocation(
71494994d37SDimitry Andric     const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
71594994d37SDimitry Andric     lldb::addr_t offset, SBFileSpecList &sb_module_list) {
7166f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, sb_file_spec, line, column, offset, sb_module_list);
717f034231aSEd Maste 
718f034231aSEd Maste   SBBreakpoint sb_bp;
719f034231aSEd Maste   TargetSP target_sp(GetSP());
72014f1b3e8SDimitry Andric   if (target_sp && line != 0) {
721f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
722f034231aSEd Maste 
723f034231aSEd Maste     const LazyBool check_inlines = eLazyBoolCalculate;
724f034231aSEd Maste     const LazyBool skip_prologue = eLazyBoolCalculate;
725f034231aSEd Maste     const bool internal = false;
726f21a844fSEd Maste     const bool hardware = false;
7275e95aa85SEd Maste     const LazyBool move_to_nearest_code = eLazyBoolCalculate;
72814f1b3e8SDimitry Andric     const FileSpecList *module_list = nullptr;
72914f1b3e8SDimitry Andric     if (sb_module_list.GetSize() > 0) {
73014f1b3e8SDimitry Andric       module_list = sb_module_list.get();
73114f1b3e8SDimitry Andric     }
73274a628f7SDimitry Andric     sb_bp = target_sp->CreateBreakpoint(
73394994d37SDimitry Andric         module_list, *sb_file_spec, line, column, offset, check_inlines,
73494994d37SDimitry Andric         skip_prologue, internal, hardware, move_to_nearest_code);
735f034231aSEd Maste   }
736f034231aSEd Maste 
7376f8fc217SDimitry Andric   return sb_bp;
738f034231aSEd Maste }
739f034231aSEd Maste 
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,uint32_t column,lldb::addr_t offset,SBFileSpecList & sb_module_list,bool move_to_nearest_code)740b60736ecSDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByLocation(
741b60736ecSDimitry Andric     const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
742b60736ecSDimitry Andric     lldb::addr_t offset, SBFileSpecList &sb_module_list,
743b60736ecSDimitry Andric     bool move_to_nearest_code) {
7446f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, sb_file_spec, line, column, offset, sb_module_list,
745b60736ecSDimitry Andric                      move_to_nearest_code);
746b60736ecSDimitry Andric 
747b60736ecSDimitry Andric   SBBreakpoint sb_bp;
748b60736ecSDimitry Andric   TargetSP target_sp(GetSP());
749b60736ecSDimitry Andric   if (target_sp && line != 0) {
750b60736ecSDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
751b60736ecSDimitry Andric 
752b60736ecSDimitry Andric     const LazyBool check_inlines = eLazyBoolCalculate;
753b60736ecSDimitry Andric     const LazyBool skip_prologue = eLazyBoolCalculate;
754b60736ecSDimitry Andric     const bool internal = false;
755b60736ecSDimitry Andric     const bool hardware = false;
756b60736ecSDimitry Andric     const FileSpecList *module_list = nullptr;
757b60736ecSDimitry Andric     if (sb_module_list.GetSize() > 0) {
758b60736ecSDimitry Andric       module_list = sb_module_list.get();
759b60736ecSDimitry Andric     }
760b60736ecSDimitry Andric     sb_bp = target_sp->CreateBreakpoint(
761b60736ecSDimitry Andric         module_list, *sb_file_spec, line, column, offset, check_inlines,
762b60736ecSDimitry Andric         skip_prologue, internal, hardware,
763b60736ecSDimitry Andric         move_to_nearest_code ? eLazyBoolYes : eLazyBoolNo);
764b60736ecSDimitry Andric   }
765b60736ecSDimitry Andric 
7666f8fc217SDimitry Andric   return sb_bp;
767b60736ecSDimitry Andric }
768b60736ecSDimitry Andric 
BreakpointCreateByName(const char * symbol_name,const char * module_name)76914f1b3e8SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name,
77014f1b3e8SDimitry Andric                                               const char *module_name) {
7716f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, symbol_name, module_name);
772f034231aSEd Maste 
773f034231aSEd Maste   SBBreakpoint sb_bp;
774f034231aSEd Maste   TargetSP target_sp(GetSP());
77514f1b3e8SDimitry Andric   if (target_sp.get()) {
776f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
777f034231aSEd Maste 
778f034231aSEd Maste     const bool internal = false;
779f21a844fSEd Maste     const bool hardware = false;
780f034231aSEd Maste     const LazyBool skip_prologue = eLazyBoolCalculate;
781f3fbd1c0SDimitry Andric     const lldb::addr_t offset = 0;
78214f1b3e8SDimitry Andric     if (module_name && module_name[0]) {
783f034231aSEd Maste       FileSpecList module_spec_list;
78494994d37SDimitry Andric       module_spec_list.Append(FileSpec(module_name));
78574a628f7SDimitry Andric       sb_bp = target_sp->CreateBreakpoint(
7865f29bb8aSDimitry Andric           &module_spec_list, nullptr, symbol_name, eFunctionNameTypeAuto,
78714f1b3e8SDimitry Andric           eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
78814f1b3e8SDimitry Andric     } else {
78974a628f7SDimitry Andric       sb_bp = target_sp->CreateBreakpoint(
7905f29bb8aSDimitry Andric           nullptr, nullptr, symbol_name, eFunctionNameTypeAuto,
7915f29bb8aSDimitry Andric           eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
792f034231aSEd Maste     }
793f034231aSEd Maste   }
794f034231aSEd Maste 
7956f8fc217SDimitry Andric   return sb_bp;
796f034231aSEd Maste }
797f034231aSEd Maste 
798f034231aSEd Maste lldb::SBBreakpoint
BreakpointCreateByName(const char * symbol_name,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)799f034231aSEd Maste SBTarget::BreakpointCreateByName(const char *symbol_name,
800f034231aSEd Maste                                  const SBFileSpecList &module_list,
80114f1b3e8SDimitry Andric                                  const SBFileSpecList &comp_unit_list) {
8026f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, symbol_name, module_list, comp_unit_list);
8035f29bb8aSDimitry Andric 
80494994d37SDimitry Andric   lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto;
8056f8fc217SDimitry Andric   return BreakpointCreateByName(symbol_name, name_type_mask,
8066f8fc217SDimitry Andric                                 eLanguageTypeUnknown, module_list,
8076f8fc217SDimitry Andric                                 comp_unit_list);
808f034231aSEd Maste }
809f034231aSEd Maste 
BreakpointCreateByName(const char * symbol_name,uint32_t name_type_mask,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)81014f1b3e8SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
81114f1b3e8SDimitry Andric     const char *symbol_name, uint32_t name_type_mask,
81214f1b3e8SDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
8136f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, module_list,
8146f8fc217SDimitry Andric                      comp_unit_list);
8155f29bb8aSDimitry Andric 
8166f8fc217SDimitry Andric   return BreakpointCreateByName(symbol_name, name_type_mask,
8176f8fc217SDimitry Andric                                 eLanguageTypeUnknown, module_list,
8186f8fc217SDimitry Andric                                 comp_unit_list);
819e81d9d49SDimitry Andric }
820e81d9d49SDimitry Andric 
BreakpointCreateByName(const char * symbol_name,uint32_t name_type_mask,LanguageType symbol_language,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)82114f1b3e8SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
82214f1b3e8SDimitry Andric     const char *symbol_name, uint32_t name_type_mask,
82314f1b3e8SDimitry Andric     LanguageType symbol_language, const SBFileSpecList &module_list,
82414f1b3e8SDimitry Andric     const SBFileSpecList &comp_unit_list) {
8256f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, symbol_name, name_type_mask, symbol_language,
8266f8fc217SDimitry Andric                      module_list, comp_unit_list);
827f034231aSEd Maste 
828f034231aSEd Maste   SBBreakpoint sb_bp;
829f034231aSEd Maste   TargetSP target_sp(GetSP());
83014f1b3e8SDimitry Andric   if (target_sp && symbol_name && symbol_name[0]) {
831f034231aSEd Maste     const bool internal = false;
832f21a844fSEd Maste     const bool hardware = false;
833f034231aSEd Maste     const LazyBool skip_prologue = eLazyBoolCalculate;
834f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
83594994d37SDimitry Andric     FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
83694994d37SDimitry Andric     sb_bp = target_sp->CreateBreakpoint(module_list.get(), comp_unit_list.get(),
83794994d37SDimitry Andric                                         symbol_name, mask, symbol_language, 0,
83894994d37SDimitry Andric                                         skip_prologue, internal, hardware);
839f034231aSEd Maste   }
840f034231aSEd Maste 
8416f8fc217SDimitry Andric   return sb_bp;
842f034231aSEd Maste }
843f034231aSEd Maste 
BreakpointCreateByNames(const char * symbol_names[],uint32_t num_names,uint32_t name_type_mask,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)84414f1b3e8SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
84514f1b3e8SDimitry Andric     const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
84614f1b3e8SDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
8476f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask, module_list,
8486f8fc217SDimitry Andric                      comp_unit_list);
8495f29bb8aSDimitry Andric 
8506f8fc217SDimitry Andric   return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
8516f8fc217SDimitry Andric                                  eLanguageTypeUnknown, module_list,
8526f8fc217SDimitry Andric                                  comp_unit_list);
853e81d9d49SDimitry Andric }
854e81d9d49SDimitry Andric 
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)85514f1b3e8SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
85614f1b3e8SDimitry Andric     const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
85714f1b3e8SDimitry Andric     LanguageType symbol_language, const SBFileSpecList &module_list,
85814f1b3e8SDimitry Andric     const SBFileSpecList &comp_unit_list) {
8596f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask,
8606f8fc217SDimitry Andric                      symbol_language, module_list, comp_unit_list);
8615f29bb8aSDimitry Andric 
8626f8fc217SDimitry Andric   return BreakpointCreateByNames(symbol_names, num_names, name_type_mask,
8636f8fc217SDimitry Andric                                  eLanguageTypeUnknown, 0, module_list,
8646f8fc217SDimitry Andric                                  comp_unit_list);
865f3fbd1c0SDimitry Andric }
866f3fbd1c0SDimitry Andric 
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)86714f1b3e8SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
86814f1b3e8SDimitry Andric     const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
86914f1b3e8SDimitry Andric     LanguageType symbol_language, lldb::addr_t offset,
87014f1b3e8SDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
8716f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, symbol_names, num_names, name_type_mask,
8726f8fc217SDimitry Andric                      symbol_language, offset, module_list, comp_unit_list);
873f034231aSEd Maste 
874f034231aSEd Maste   SBBreakpoint sb_bp;
875f034231aSEd Maste   TargetSP target_sp(GetSP());
87614f1b3e8SDimitry Andric   if (target_sp && num_names > 0) {
877f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
878f034231aSEd Maste     const bool internal = false;
879f21a844fSEd Maste     const bool hardware = false;
88094994d37SDimitry Andric     FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
881f034231aSEd Maste     const LazyBool skip_prologue = eLazyBoolCalculate;
88274a628f7SDimitry Andric     sb_bp = target_sp->CreateBreakpoint(
88394994d37SDimitry Andric         module_list.get(), comp_unit_list.get(), symbol_names, num_names, mask,
88494994d37SDimitry Andric         symbol_language, offset, skip_prologue, internal, hardware);
885f034231aSEd Maste   }
886f034231aSEd Maste 
8876f8fc217SDimitry Andric   return sb_bp;
888f034231aSEd Maste }
889f034231aSEd Maste 
BreakpointCreateByRegex(const char * symbol_name_regex,const char * module_name)89014f1b3e8SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
89114f1b3e8SDimitry Andric                                                const char *module_name) {
8926f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, symbol_name_regex, module_name);
8935f29bb8aSDimitry Andric 
894e81d9d49SDimitry Andric   SBFileSpecList module_spec_list;
895e81d9d49SDimitry Andric   SBFileSpecList comp_unit_list;
89614f1b3e8SDimitry Andric   if (module_name && module_name[0]) {
89794994d37SDimitry Andric     module_spec_list.Append(FileSpec(module_name));
898f034231aSEd Maste   }
8996f8fc217SDimitry Andric   return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
9006f8fc217SDimitry Andric                                  module_spec_list, comp_unit_list);
901f034231aSEd Maste }
902f034231aSEd Maste 
903f034231aSEd Maste lldb::SBBreakpoint
BreakpointCreateByRegex(const char * symbol_name_regex,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)904f034231aSEd Maste SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
905f034231aSEd Maste                                   const SBFileSpecList &module_list,
90614f1b3e8SDimitry Andric                                   const SBFileSpecList &comp_unit_list) {
9076f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, symbol_name_regex, module_list, comp_unit_list);
9085f29bb8aSDimitry Andric 
9096f8fc217SDimitry Andric   return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
9106f8fc217SDimitry Andric                                  module_list, comp_unit_list);
911e81d9d49SDimitry Andric }
912e81d9d49SDimitry Andric 
BreakpointCreateByRegex(const char * symbol_name_regex,LanguageType symbol_language,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)91314f1b3e8SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateByRegex(
91414f1b3e8SDimitry Andric     const char *symbol_name_regex, LanguageType symbol_language,
91514f1b3e8SDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
9166f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, symbol_name_regex, symbol_language, module_list,
9176f8fc217SDimitry Andric                      comp_unit_list);
918f034231aSEd Maste 
919f034231aSEd Maste   SBBreakpoint sb_bp;
920f034231aSEd Maste   TargetSP target_sp(GetSP());
92114f1b3e8SDimitry Andric   if (target_sp && symbol_name_regex && symbol_name_regex[0]) {
922f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
92314f1b3e8SDimitry Andric     RegularExpression regexp((llvm::StringRef(symbol_name_regex)));
924f034231aSEd Maste     const bool internal = false;
925f21a844fSEd Maste     const bool hardware = false;
926f034231aSEd Maste     const LazyBool skip_prologue = eLazyBoolCalculate;
927f034231aSEd Maste 
92874a628f7SDimitry Andric     sb_bp = target_sp->CreateFuncRegexBreakpoint(
929ead24645SDimitry Andric         module_list.get(), comp_unit_list.get(), std::move(regexp),
930ead24645SDimitry Andric         symbol_language, skip_prologue, internal, hardware);
931f034231aSEd Maste   }
932f034231aSEd Maste 
9336f8fc217SDimitry Andric   return sb_bp;
934f034231aSEd Maste }
935f034231aSEd Maste 
BreakpointCreateByAddress(addr_t address)93614f1b3e8SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateByAddress(addr_t address) {
9376f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, address);
938f034231aSEd Maste 
939f034231aSEd Maste   SBBreakpoint sb_bp;
940f034231aSEd Maste   TargetSP target_sp(GetSP());
94114f1b3e8SDimitry Andric   if (target_sp) {
942f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
943f21a844fSEd Maste     const bool hardware = false;
94474a628f7SDimitry Andric     sb_bp = target_sp->CreateBreakpoint(address, false, hardware);
945f034231aSEd Maste   }
946f034231aSEd Maste 
9476f8fc217SDimitry Andric   return sb_bp;
948f034231aSEd Maste }
949f034231aSEd Maste 
BreakpointCreateBySBAddress(SBAddress & sb_address)95014f1b3e8SDimitry Andric SBBreakpoint SBTarget::BreakpointCreateBySBAddress(SBAddress &sb_address) {
9516f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, sb_address);
952e81d9d49SDimitry Andric 
953e81d9d49SDimitry Andric   SBBreakpoint sb_bp;
954e81d9d49SDimitry Andric   TargetSP target_sp(GetSP());
95514f1b3e8SDimitry Andric   if (!sb_address.IsValid()) {
9566f8fc217SDimitry Andric     return sb_bp;
957e81d9d49SDimitry Andric   }
958e81d9d49SDimitry Andric 
95914f1b3e8SDimitry Andric   if (target_sp) {
960f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
961e81d9d49SDimitry Andric     const bool hardware = false;
96274a628f7SDimitry Andric     sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware);
963e81d9d49SDimitry Andric   }
964e81d9d49SDimitry Andric 
9656f8fc217SDimitry Andric   return sb_bp;
966e81d9d49SDimitry Andric }
967e81d9d49SDimitry Andric 
968f034231aSEd Maste lldb::SBBreakpoint
BreakpointCreateBySourceRegex(const char * source_regex,const lldb::SBFileSpec & source_file,const char * module_name)969f21a844fSEd Maste SBTarget::BreakpointCreateBySourceRegex(const char *source_regex,
970f21a844fSEd Maste                                         const lldb::SBFileSpec &source_file,
97114f1b3e8SDimitry Andric                                         const char *module_name) {
9726f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, source_regex, source_file, module_name);
9735f29bb8aSDimitry Andric 
974f3fbd1c0SDimitry Andric   SBFileSpecList module_spec_list;
975f034231aSEd Maste 
97614f1b3e8SDimitry Andric   if (module_name && module_name[0]) {
97794994d37SDimitry Andric     module_spec_list.Append(FileSpec(module_name));
978f034231aSEd Maste   }
979f3fbd1c0SDimitry Andric 
980f3fbd1c0SDimitry Andric   SBFileSpecList source_file_list;
98114f1b3e8SDimitry Andric   if (source_file.IsValid()) {
982f3fbd1c0SDimitry Andric     source_file_list.Append(source_file);
983f034231aSEd Maste   }
984f034231aSEd Maste 
9856f8fc217SDimitry Andric   return BreakpointCreateBySourceRegex(source_regex, module_spec_list,
9866f8fc217SDimitry Andric                                        source_file_list);
987f034231aSEd Maste }
988f034231aSEd Maste 
BreakpointCreateBySourceRegex(const char * source_regex,const SBFileSpecList & module_list,const lldb::SBFileSpecList & source_file_list)98914f1b3e8SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
99014f1b3e8SDimitry Andric     const char *source_regex, const SBFileSpecList &module_list,
99114f1b3e8SDimitry Andric     const lldb::SBFileSpecList &source_file_list) {
9926f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, source_regex, module_list, source_file_list);
9935f29bb8aSDimitry Andric 
9946f8fc217SDimitry Andric   return BreakpointCreateBySourceRegex(source_regex, module_list,
9956f8fc217SDimitry Andric                                        source_file_list, SBStringList());
996f3fbd1c0SDimitry Andric }
997f3fbd1c0SDimitry Andric 
BreakpointCreateBySourceRegex(const char * source_regex,const SBFileSpecList & module_list,const lldb::SBFileSpecList & source_file_list,const SBStringList & func_names)99814f1b3e8SDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
99914f1b3e8SDimitry Andric     const char *source_regex, const SBFileSpecList &module_list,
1000f3fbd1c0SDimitry Andric     const lldb::SBFileSpecList &source_file_list,
100114f1b3e8SDimitry Andric     const SBStringList &func_names) {
10026f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, source_regex, module_list, source_file_list,
10036f8fc217SDimitry Andric                      func_names);
1004f034231aSEd Maste 
1005f034231aSEd Maste   SBBreakpoint sb_bp;
1006f034231aSEd Maste   TargetSP target_sp(GetSP());
100714f1b3e8SDimitry Andric   if (target_sp && source_regex && source_regex[0]) {
1008f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1009f21a844fSEd Maste     const bool hardware = false;
10105e95aa85SEd Maste     const LazyBool move_to_nearest_code = eLazyBoolCalculate;
101114f1b3e8SDimitry Andric     RegularExpression regexp((llvm::StringRef(source_regex)));
1012f3fbd1c0SDimitry Andric     std::unordered_set<std::string> func_names_set;
101314f1b3e8SDimitry Andric     for (size_t i = 0; i < func_names.GetSize(); i++) {
1014f3fbd1c0SDimitry Andric       func_names_set.insert(func_names.GetStringAtIndex(i));
1015f3fbd1c0SDimitry Andric     }
1016f3fbd1c0SDimitry Andric 
101774a628f7SDimitry Andric     sb_bp = target_sp->CreateSourceRegexBreakpoint(
1018ead24645SDimitry Andric         module_list.get(), source_file_list.get(), func_names_set,
1019ead24645SDimitry Andric         std::move(regexp), false, hardware, move_to_nearest_code);
1020f034231aSEd Maste   }
1021f034231aSEd Maste 
10226f8fc217SDimitry Andric   return sb_bp;
1023f034231aSEd Maste }
1024f034231aSEd Maste 
1025f034231aSEd Maste lldb::SBBreakpoint
BreakpointCreateForException(lldb::LanguageType language,bool catch_bp,bool throw_bp)1026f034231aSEd Maste SBTarget::BreakpointCreateForException(lldb::LanguageType language,
102714f1b3e8SDimitry Andric                                        bool catch_bp, bool throw_bp) {
10286f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, language, catch_bp, throw_bp);
1029f034231aSEd Maste 
1030f034231aSEd Maste   SBBreakpoint sb_bp;
1031f034231aSEd Maste   TargetSP target_sp(GetSP());
103214f1b3e8SDimitry Andric   if (target_sp) {
1033f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1034f21a844fSEd Maste     const bool hardware = false;
103574a628f7SDimitry Andric     sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
103614f1b3e8SDimitry Andric                                                   hardware);
1037f034231aSEd Maste   }
1038f034231aSEd Maste 
10396f8fc217SDimitry Andric   return sb_bp;
1040f034231aSEd Maste }
1041f034231aSEd Maste 
BreakpointCreateFromScript(const char * class_name,SBStructuredData & extra_args,const SBFileSpecList & module_list,const SBFileSpecList & file_list,bool request_hardware)10425f29bb8aSDimitry Andric lldb::SBBreakpoint SBTarget::BreakpointCreateFromScript(
10435f29bb8aSDimitry Andric     const char *class_name, SBStructuredData &extra_args,
10445f29bb8aSDimitry Andric     const SBFileSpecList &module_list, const SBFileSpecList &file_list,
10455f29bb8aSDimitry Andric     bool request_hardware) {
10466f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, class_name, extra_args, module_list, file_list,
10476f8fc217SDimitry Andric                      request_hardware);
104894994d37SDimitry Andric 
104994994d37SDimitry Andric   SBBreakpoint sb_bp;
105094994d37SDimitry Andric   TargetSP target_sp(GetSP());
105194994d37SDimitry Andric   if (target_sp) {
105294994d37SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
105394994d37SDimitry Andric     Status error;
105494994d37SDimitry Andric 
105594994d37SDimitry Andric     StructuredData::ObjectSP obj_sp = extra_args.m_impl_up->GetObjectSP();
105694994d37SDimitry Andric     sb_bp =
105794994d37SDimitry Andric         target_sp->CreateScriptedBreakpoint(class_name,
105894994d37SDimitry Andric                                             module_list.get(),
105994994d37SDimitry Andric                                             file_list.get(),
106094994d37SDimitry Andric                                             false, /* internal */
106194994d37SDimitry Andric                                             request_hardware,
106294994d37SDimitry Andric                                             obj_sp,
106394994d37SDimitry Andric                                             &error);
106494994d37SDimitry Andric   }
106594994d37SDimitry Andric 
10666f8fc217SDimitry Andric   return sb_bp;
106794994d37SDimitry Andric }
106894994d37SDimitry Andric 
GetNumBreakpoints() const106914f1b3e8SDimitry Andric uint32_t SBTarget::GetNumBreakpoints() const {
10706f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
10715f29bb8aSDimitry Andric 
1072f034231aSEd Maste   TargetSP target_sp(GetSP());
107314f1b3e8SDimitry Andric   if (target_sp) {
1074f034231aSEd Maste     // The breakpoint list is thread safe, no need to lock
1075f034231aSEd Maste     return target_sp->GetBreakpointList().GetSize();
1076f034231aSEd Maste   }
1077f034231aSEd Maste   return 0;
1078f034231aSEd Maste }
1079f034231aSEd Maste 
GetBreakpointAtIndex(uint32_t idx) const108014f1b3e8SDimitry Andric SBBreakpoint SBTarget::GetBreakpointAtIndex(uint32_t idx) const {
10816f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, idx);
10825f29bb8aSDimitry Andric 
1083f034231aSEd Maste   SBBreakpoint sb_breakpoint;
1084f034231aSEd Maste   TargetSP target_sp(GetSP());
108514f1b3e8SDimitry Andric   if (target_sp) {
1086f034231aSEd Maste     // The breakpoint list is thread safe, no need to lock
108774a628f7SDimitry Andric     sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1088f034231aSEd Maste   }
10896f8fc217SDimitry Andric   return sb_breakpoint;
1090f034231aSEd Maste }
1091f034231aSEd Maste 
BreakpointDelete(break_id_t bp_id)109214f1b3e8SDimitry Andric bool SBTarget::BreakpointDelete(break_id_t bp_id) {
10936f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, bp_id);
1094f034231aSEd Maste 
1095f034231aSEd Maste   bool result = false;
1096f034231aSEd Maste   TargetSP target_sp(GetSP());
109714f1b3e8SDimitry Andric   if (target_sp) {
1098f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1099f034231aSEd Maste     result = target_sp->RemoveBreakpointByID(bp_id);
1100f034231aSEd Maste   }
1101f034231aSEd Maste 
1102f034231aSEd Maste   return result;
1103f034231aSEd Maste }
1104f034231aSEd Maste 
FindBreakpointByID(break_id_t bp_id)110514f1b3e8SDimitry Andric SBBreakpoint SBTarget::FindBreakpointByID(break_id_t bp_id) {
11066f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, bp_id);
1107f034231aSEd Maste 
1108f034231aSEd Maste   SBBreakpoint sb_breakpoint;
1109f034231aSEd Maste   TargetSP target_sp(GetSP());
111014f1b3e8SDimitry Andric   if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) {
1111f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
111274a628f7SDimitry Andric     sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
1113f034231aSEd Maste   }
1114f034231aSEd Maste 
11156f8fc217SDimitry Andric   return sb_breakpoint;
1116f034231aSEd Maste }
1117f034231aSEd Maste 
FindBreakpointsByName(const char * name,SBBreakpointList & bkpts)111814f1b3e8SDimitry Andric bool SBTarget::FindBreakpointsByName(const char *name,
111914f1b3e8SDimitry Andric                                      SBBreakpointList &bkpts) {
11206f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, bkpts);
11215f29bb8aSDimitry Andric 
1122f034231aSEd Maste   TargetSP target_sp(GetSP());
112314f1b3e8SDimitry Andric   if (target_sp) {
112414f1b3e8SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1125706b4fc4SDimitry Andric     llvm::Expected<std::vector<BreakpointSP>> expected_vector =
1126706b4fc4SDimitry Andric         target_sp->GetBreakpointList().FindBreakpointsByName(name);
1127706b4fc4SDimitry Andric     if (!expected_vector) {
11287fa27ce4SDimitry Andric       LLDB_LOG_ERROR(GetLog(LLDBLog::Breakpoints), expected_vector.takeError(),
11297fa27ce4SDimitry Andric                      "invalid breakpoint name: {0}");
113014f1b3e8SDimitry Andric       return false;
1131706b4fc4SDimitry Andric     }
1132706b4fc4SDimitry Andric     for (BreakpointSP bkpt_sp : *expected_vector) {
113314f1b3e8SDimitry Andric       bkpts.AppendByID(bkpt_sp->GetID());
113414f1b3e8SDimitry Andric     }
113514f1b3e8SDimitry Andric   }
113614f1b3e8SDimitry Andric   return true;
113714f1b3e8SDimitry Andric }
113814f1b3e8SDimitry Andric 
GetBreakpointNames(SBStringList & names)11395f29bb8aSDimitry Andric void SBTarget::GetBreakpointNames(SBStringList &names) {
11406f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, names);
11415f29bb8aSDimitry Andric 
1142ef5d0b5eSDimitry Andric   names.Clear();
1143ef5d0b5eSDimitry Andric 
1144ef5d0b5eSDimitry Andric   TargetSP target_sp(GetSP());
1145ef5d0b5eSDimitry Andric   if (target_sp) {
1146ef5d0b5eSDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1147ef5d0b5eSDimitry Andric 
1148ef5d0b5eSDimitry Andric     std::vector<std::string> name_vec;
1149ef5d0b5eSDimitry Andric     target_sp->GetBreakpointNames(name_vec);
1150ac9a064cSDimitry Andric     for (const auto &name : name_vec)
1151ef5d0b5eSDimitry Andric       names.AppendString(name.c_str());
1152ef5d0b5eSDimitry Andric   }
1153ef5d0b5eSDimitry Andric }
1154ef5d0b5eSDimitry Andric 
DeleteBreakpointName(const char * name)11555f29bb8aSDimitry Andric void SBTarget::DeleteBreakpointName(const char *name) {
11566f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name);
11575f29bb8aSDimitry Andric 
1158ef5d0b5eSDimitry Andric   TargetSP target_sp(GetSP());
1159ef5d0b5eSDimitry Andric   if (target_sp) {
1160ef5d0b5eSDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1161ef5d0b5eSDimitry Andric     target_sp->DeleteBreakpointName(ConstString(name));
1162ef5d0b5eSDimitry Andric   }
1163ef5d0b5eSDimitry Andric }
1164ef5d0b5eSDimitry Andric 
EnableAllBreakpoints()116514f1b3e8SDimitry Andric bool SBTarget::EnableAllBreakpoints() {
11666f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
11675f29bb8aSDimitry Andric 
116814f1b3e8SDimitry Andric   TargetSP target_sp(GetSP());
116914f1b3e8SDimitry Andric   if (target_sp) {
1170f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1171ef5d0b5eSDimitry Andric     target_sp->EnableAllowedBreakpoints();
1172f034231aSEd Maste     return true;
1173f034231aSEd Maste   }
1174f034231aSEd Maste   return false;
1175f034231aSEd Maste }
1176f034231aSEd Maste 
DisableAllBreakpoints()117714f1b3e8SDimitry Andric bool SBTarget::DisableAllBreakpoints() {
11786f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
11795f29bb8aSDimitry Andric 
1180f034231aSEd Maste   TargetSP target_sp(GetSP());
118114f1b3e8SDimitry Andric   if (target_sp) {
1182f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1183ef5d0b5eSDimitry Andric     target_sp->DisableAllowedBreakpoints();
1184f034231aSEd Maste     return true;
1185f034231aSEd Maste   }
1186f034231aSEd Maste   return false;
1187f034231aSEd Maste }
1188f034231aSEd Maste 
DeleteAllBreakpoints()118914f1b3e8SDimitry Andric bool SBTarget::DeleteAllBreakpoints() {
11906f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
11915f29bb8aSDimitry Andric 
1192f034231aSEd Maste   TargetSP target_sp(GetSP());
119314f1b3e8SDimitry Andric   if (target_sp) {
1194f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1195ef5d0b5eSDimitry Andric     target_sp->RemoveAllowedBreakpoints();
1196f034231aSEd Maste     return true;
1197f034231aSEd Maste   }
1198f034231aSEd Maste   return false;
1199f034231aSEd Maste }
1200f034231aSEd Maste 
BreakpointsCreateFromFile(SBFileSpec & source_file,SBBreakpointList & new_bps)120114f1b3e8SDimitry Andric lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
120214f1b3e8SDimitry Andric                                                   SBBreakpointList &new_bps) {
12036f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, source_file, new_bps);
12045f29bb8aSDimitry Andric 
120514f1b3e8SDimitry Andric   SBStringList empty_name_list;
12066f8fc217SDimitry Andric   return BreakpointsCreateFromFile(source_file, empty_name_list, new_bps);
120714f1b3e8SDimitry Andric }
120814f1b3e8SDimitry Andric 
BreakpointsCreateFromFile(SBFileSpec & source_file,SBStringList & matching_names,SBBreakpointList & new_bps)120914f1b3e8SDimitry Andric lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
121014f1b3e8SDimitry Andric                                                   SBStringList &matching_names,
121114f1b3e8SDimitry Andric                                                   SBBreakpointList &new_bps) {
12126f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, source_file, matching_names, new_bps);
12135f29bb8aSDimitry Andric 
121414f1b3e8SDimitry Andric   SBError sberr;
1215f034231aSEd Maste   TargetSP target_sp(GetSP());
121614f1b3e8SDimitry Andric   if (!target_sp) {
121714f1b3e8SDimitry Andric     sberr.SetErrorString(
121814f1b3e8SDimitry Andric         "BreakpointCreateFromFile called with invalid target.");
12196f8fc217SDimitry Andric     return sberr;
122014f1b3e8SDimitry Andric   }
122114f1b3e8SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
122214f1b3e8SDimitry Andric 
122314f1b3e8SDimitry Andric   BreakpointIDList bp_ids;
122414f1b3e8SDimitry Andric 
122514f1b3e8SDimitry Andric   std::vector<std::string> name_vector;
122614f1b3e8SDimitry Andric   size_t num_names = matching_names.GetSize();
122714f1b3e8SDimitry Andric   for (size_t i = 0; i < num_names; i++)
122814f1b3e8SDimitry Andric     name_vector.push_back(matching_names.GetStringAtIndex(i));
122914f1b3e8SDimitry Andric 
123014f1b3e8SDimitry Andric   sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(),
123114f1b3e8SDimitry Andric                                                      name_vector, bp_ids);
123214f1b3e8SDimitry Andric   if (sberr.Fail())
12336f8fc217SDimitry Andric     return sberr;
123414f1b3e8SDimitry Andric 
123514f1b3e8SDimitry Andric   size_t num_bkpts = bp_ids.GetSize();
123614f1b3e8SDimitry Andric   for (size_t i = 0; i < num_bkpts; i++) {
123714f1b3e8SDimitry Andric     BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
123814f1b3e8SDimitry Andric     new_bps.AppendByID(bp_id.GetBreakpointID());
123914f1b3e8SDimitry Andric   }
12406f8fc217SDimitry Andric   return sberr;
124114f1b3e8SDimitry Andric }
124214f1b3e8SDimitry Andric 
BreakpointsWriteToFile(SBFileSpec & dest_file)124314f1b3e8SDimitry Andric lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file) {
12446f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, dest_file);
12455f29bb8aSDimitry Andric 
124614f1b3e8SDimitry Andric   SBError sberr;
124714f1b3e8SDimitry Andric   TargetSP target_sp(GetSP());
124814f1b3e8SDimitry Andric   if (!target_sp) {
124914f1b3e8SDimitry Andric     sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
12506f8fc217SDimitry Andric     return sberr;
125114f1b3e8SDimitry Andric   }
125214f1b3e8SDimitry Andric   SBBreakpointList bkpt_list(*this);
12536f8fc217SDimitry Andric   return BreakpointsWriteToFile(dest_file, bkpt_list);
125414f1b3e8SDimitry Andric }
125514f1b3e8SDimitry Andric 
BreakpointsWriteToFile(SBFileSpec & dest_file,SBBreakpointList & bkpt_list,bool append)125614f1b3e8SDimitry Andric lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file,
125714f1b3e8SDimitry Andric                                                SBBreakpointList &bkpt_list,
125814f1b3e8SDimitry Andric                                                bool append) {
12596f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, dest_file, bkpt_list, append);
12605f29bb8aSDimitry Andric 
126114f1b3e8SDimitry Andric   SBError sberr;
126214f1b3e8SDimitry Andric   TargetSP target_sp(GetSP());
126314f1b3e8SDimitry Andric   if (!target_sp) {
126414f1b3e8SDimitry Andric     sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
12656f8fc217SDimitry Andric     return sberr;
126614f1b3e8SDimitry Andric   }
126714f1b3e8SDimitry Andric 
126814f1b3e8SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
126914f1b3e8SDimitry Andric   BreakpointIDList bp_id_list;
127014f1b3e8SDimitry Andric   bkpt_list.CopyToBreakpointIDList(bp_id_list);
127114f1b3e8SDimitry Andric   sberr.ref() = target_sp->SerializeBreakpointsToFile(dest_file.ref(),
127214f1b3e8SDimitry Andric                                                       bp_id_list, append);
12736f8fc217SDimitry Andric   return sberr;
127414f1b3e8SDimitry Andric }
127514f1b3e8SDimitry Andric 
GetNumWatchpoints() const127614f1b3e8SDimitry Andric uint32_t SBTarget::GetNumWatchpoints() const {
12776f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
12785f29bb8aSDimitry Andric 
127914f1b3e8SDimitry Andric   TargetSP target_sp(GetSP());
128014f1b3e8SDimitry Andric   if (target_sp) {
1281f034231aSEd Maste     // The watchpoint list is thread safe, no need to lock
1282f034231aSEd Maste     return target_sp->GetWatchpointList().GetSize();
1283f034231aSEd Maste   }
1284f034231aSEd Maste   return 0;
1285f034231aSEd Maste }
1286f034231aSEd Maste 
GetWatchpointAtIndex(uint32_t idx) const128714f1b3e8SDimitry Andric SBWatchpoint SBTarget::GetWatchpointAtIndex(uint32_t idx) const {
12886f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, idx);
12895f29bb8aSDimitry Andric 
1290f034231aSEd Maste   SBWatchpoint sb_watchpoint;
1291f034231aSEd Maste   TargetSP target_sp(GetSP());
129214f1b3e8SDimitry Andric   if (target_sp) {
1293f034231aSEd Maste     // The watchpoint list is thread safe, no need to lock
1294f034231aSEd Maste     sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1295f034231aSEd Maste   }
12966f8fc217SDimitry Andric   return sb_watchpoint;
1297f034231aSEd Maste }
1298f034231aSEd Maste 
DeleteWatchpoint(watch_id_t wp_id)129914f1b3e8SDimitry Andric bool SBTarget::DeleteWatchpoint(watch_id_t wp_id) {
13006f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, wp_id);
1301f034231aSEd Maste 
1302f034231aSEd Maste   bool result = false;
1303f034231aSEd Maste   TargetSP target_sp(GetSP());
130414f1b3e8SDimitry Andric   if (target_sp) {
1305f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1306f3fbd1c0SDimitry Andric     std::unique_lock<std::recursive_mutex> lock;
1307f3fbd1c0SDimitry Andric     target_sp->GetWatchpointList().GetListMutex(lock);
1308f034231aSEd Maste     result = target_sp->RemoveWatchpointByID(wp_id);
1309f034231aSEd Maste   }
1310f034231aSEd Maste 
1311f034231aSEd Maste   return result;
1312f034231aSEd Maste }
1313f034231aSEd Maste 
FindWatchpointByID(lldb::watch_id_t wp_id)131414f1b3e8SDimitry Andric SBWatchpoint SBTarget::FindWatchpointByID(lldb::watch_id_t wp_id) {
13156f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, wp_id);
1316f034231aSEd Maste 
1317f034231aSEd Maste   SBWatchpoint sb_watchpoint;
1318f034231aSEd Maste   lldb::WatchpointSP watchpoint_sp;
1319f034231aSEd Maste   TargetSP target_sp(GetSP());
132014f1b3e8SDimitry Andric   if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) {
1321f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1322f3fbd1c0SDimitry Andric     std::unique_lock<std::recursive_mutex> lock;
1323f3fbd1c0SDimitry Andric     target_sp->GetWatchpointList().GetListMutex(lock);
1324f034231aSEd Maste     watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1325f034231aSEd Maste     sb_watchpoint.SetSP(watchpoint_sp);
1326f034231aSEd Maste   }
1327f034231aSEd Maste 
13286f8fc217SDimitry Andric   return sb_watchpoint;
1329f034231aSEd Maste }
1330f034231aSEd Maste 
WatchAddress(lldb::addr_t addr,size_t size,bool read,bool modify,SBError & error)133114f1b3e8SDimitry Andric lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size,
1332b1c73532SDimitry Andric                                           bool read, bool modify,
133314f1b3e8SDimitry Andric                                           SBError &error) {
13346f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, addr, size, read, write, error);
1335f034231aSEd Maste 
1336b1c73532SDimitry Andric   SBWatchpointOptions options;
1337b1c73532SDimitry Andric   options.SetWatchpointTypeRead(read);
1338b1c73532SDimitry Andric   options.SetWatchpointTypeWrite(eWatchpointWriteTypeOnModify);
1339b1c73532SDimitry Andric   return WatchpointCreateByAddress(addr, size, options, error);
1340b1c73532SDimitry Andric }
1341b1c73532SDimitry Andric 
1342b1c73532SDimitry Andric lldb::SBWatchpoint
WatchpointCreateByAddress(lldb::addr_t addr,size_t size,SBWatchpointOptions options,SBError & error)1343b1c73532SDimitry Andric SBTarget::WatchpointCreateByAddress(lldb::addr_t addr, size_t size,
1344b1c73532SDimitry Andric                                     SBWatchpointOptions options,
1345b1c73532SDimitry Andric                                     SBError &error) {
1346b1c73532SDimitry Andric   LLDB_INSTRUMENT_VA(this, addr, size, options, error);
1347b1c73532SDimitry Andric 
1348f034231aSEd Maste   SBWatchpoint sb_watchpoint;
1349f034231aSEd Maste   lldb::WatchpointSP watchpoint_sp;
1350f034231aSEd Maste   TargetSP target_sp(GetSP());
1351f034231aSEd Maste   uint32_t watch_type = 0;
1352b1c73532SDimitry Andric   if (options.GetWatchpointTypeRead())
1353f034231aSEd Maste     watch_type |= LLDB_WATCH_TYPE_READ;
1354b1c73532SDimitry Andric   if (options.GetWatchpointTypeWrite() == eWatchpointWriteTypeAlways)
1355f034231aSEd Maste     watch_type |= LLDB_WATCH_TYPE_WRITE;
1356b1c73532SDimitry Andric   if (options.GetWatchpointTypeWrite() == eWatchpointWriteTypeOnModify)
1357b1c73532SDimitry Andric     watch_type |= LLDB_WATCH_TYPE_MODIFY;
135814f1b3e8SDimitry Andric   if (watch_type == 0) {
1359b1c73532SDimitry Andric     error.SetErrorString("Can't create a watchpoint that is neither read nor "
1360b1c73532SDimitry Andric                          "write nor modify.");
13616f8fc217SDimitry Andric     return sb_watchpoint;
1362f034231aSEd Maste   }
1363b1c73532SDimitry Andric   if (target_sp && addr != LLDB_INVALID_ADDRESS && size > 0) {
1364b1c73532SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1365f034231aSEd Maste     // Target::CreateWatchpoint() is thread safe.
1366b76161e4SDimitry Andric     Status cw_error;
1367f034231aSEd Maste     // This API doesn't take in a type, so we can't figure out what it is.
13685f29bb8aSDimitry Andric     CompilerType *type = nullptr;
136914f1b3e8SDimitry Andric     watchpoint_sp =
137014f1b3e8SDimitry Andric         target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1371f034231aSEd Maste     error.SetError(cw_error);
1372f034231aSEd Maste     sb_watchpoint.SetSP(watchpoint_sp);
1373f034231aSEd Maste   }
1374f034231aSEd Maste 
13756f8fc217SDimitry Andric   return sb_watchpoint;
1376f034231aSEd Maste }
1377f034231aSEd Maste 
EnableAllWatchpoints()137814f1b3e8SDimitry Andric bool SBTarget::EnableAllWatchpoints() {
13796f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
13805f29bb8aSDimitry Andric 
1381f034231aSEd Maste   TargetSP target_sp(GetSP());
138214f1b3e8SDimitry Andric   if (target_sp) {
1383f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1384f3fbd1c0SDimitry Andric     std::unique_lock<std::recursive_mutex> lock;
1385f3fbd1c0SDimitry Andric     target_sp->GetWatchpointList().GetListMutex(lock);
1386f034231aSEd Maste     target_sp->EnableAllWatchpoints();
1387f034231aSEd Maste     return true;
1388f034231aSEd Maste   }
1389f034231aSEd Maste   return false;
1390f034231aSEd Maste }
1391f034231aSEd Maste 
DisableAllWatchpoints()139214f1b3e8SDimitry Andric bool SBTarget::DisableAllWatchpoints() {
13936f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
13945f29bb8aSDimitry Andric 
1395f034231aSEd Maste   TargetSP target_sp(GetSP());
139614f1b3e8SDimitry Andric   if (target_sp) {
1397f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1398f3fbd1c0SDimitry Andric     std::unique_lock<std::recursive_mutex> lock;
1399f3fbd1c0SDimitry Andric     target_sp->GetWatchpointList().GetListMutex(lock);
1400f034231aSEd Maste     target_sp->DisableAllWatchpoints();
1401f034231aSEd Maste     return true;
1402f034231aSEd Maste   }
1403f034231aSEd Maste   return false;
1404f034231aSEd Maste }
1405f034231aSEd Maste 
CreateValueFromAddress(const char * name,SBAddress addr,SBType type)140614f1b3e8SDimitry Andric SBValue SBTarget::CreateValueFromAddress(const char *name, SBAddress addr,
140714f1b3e8SDimitry Andric                                          SBType type) {
14086f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, addr, type);
14095f29bb8aSDimitry Andric 
1410f21a844fSEd Maste   SBValue sb_value;
1411f21a844fSEd Maste   lldb::ValueObjectSP new_value_sp;
141214f1b3e8SDimitry Andric   if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) {
1413205afe67SEd Maste     lldb::addr_t load_addr(addr.GetLoadAddress(*this));
141414f1b3e8SDimitry Andric     ExecutionContext exe_ctx(
141514f1b3e8SDimitry Andric         ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1416e81d9d49SDimitry Andric     CompilerType ast_type(type.GetSP()->GetCompilerType(true));
141714f1b3e8SDimitry Andric     new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr,
141814f1b3e8SDimitry Andric                                                              exe_ctx, ast_type);
1419f21a844fSEd Maste   }
1420f21a844fSEd Maste   sb_value.SetSP(new_value_sp);
14216f8fc217SDimitry Andric   return sb_value;
1422f21a844fSEd Maste }
1423f21a844fSEd Maste 
CreateValueFromData(const char * name,lldb::SBData data,lldb::SBType type)142414f1b3e8SDimitry Andric lldb::SBValue SBTarget::CreateValueFromData(const char *name, lldb::SBData data,
142514f1b3e8SDimitry Andric                                             lldb::SBType type) {
14266f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, data, type);
14275f29bb8aSDimitry Andric 
1428205afe67SEd Maste   SBValue sb_value;
1429205afe67SEd Maste   lldb::ValueObjectSP new_value_sp;
143014f1b3e8SDimitry Andric   if (IsValid() && name && *name && data.IsValid() && type.IsValid()) {
1431205afe67SEd Maste     DataExtractorSP extractor(*data);
143214f1b3e8SDimitry Andric     ExecutionContext exe_ctx(
143314f1b3e8SDimitry Andric         ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1434e81d9d49SDimitry Andric     CompilerType ast_type(type.GetSP()->GetCompilerType(true));
143514f1b3e8SDimitry Andric     new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor,
143614f1b3e8SDimitry Andric                                                           exe_ctx, ast_type);
1437205afe67SEd Maste   }
1438205afe67SEd Maste   sb_value.SetSP(new_value_sp);
14396f8fc217SDimitry Andric   return sb_value;
1440205afe67SEd Maste }
1441205afe67SEd Maste 
CreateValueFromExpression(const char * name,const char * expr)144214f1b3e8SDimitry Andric lldb::SBValue SBTarget::CreateValueFromExpression(const char *name,
144314f1b3e8SDimitry Andric                                                   const char *expr) {
14446f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, expr);
14455f29bb8aSDimitry Andric 
1446205afe67SEd Maste   SBValue sb_value;
1447205afe67SEd Maste   lldb::ValueObjectSP new_value_sp;
144814f1b3e8SDimitry Andric   if (IsValid() && name && *name && expr && *expr) {
144914f1b3e8SDimitry Andric     ExecutionContext exe_ctx(
145014f1b3e8SDimitry Andric         ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
145114f1b3e8SDimitry Andric     new_value_sp =
145214f1b3e8SDimitry Andric         ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
1453205afe67SEd Maste   }
1454205afe67SEd Maste   sb_value.SetSP(new_value_sp);
14556f8fc217SDimitry Andric   return sb_value;
1456205afe67SEd Maste }
1457205afe67SEd Maste 
DeleteAllWatchpoints()145814f1b3e8SDimitry Andric bool SBTarget::DeleteAllWatchpoints() {
14596f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
14605f29bb8aSDimitry Andric 
1461f034231aSEd Maste   TargetSP target_sp(GetSP());
146214f1b3e8SDimitry Andric   if (target_sp) {
1463f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1464f3fbd1c0SDimitry Andric     std::unique_lock<std::recursive_mutex> lock;
1465f3fbd1c0SDimitry Andric     target_sp->GetWatchpointList().GetListMutex(lock);
1466f034231aSEd Maste     target_sp->RemoveAllWatchpoints();
1467f034231aSEd Maste     return true;
1468f034231aSEd Maste   }
1469f034231aSEd Maste   return false;
1470f034231aSEd Maste }
1471f034231aSEd Maste 
AppendImageSearchPath(const char * from,const char * to,lldb::SBError & error)147294994d37SDimitry Andric void SBTarget::AppendImageSearchPath(const char *from, const char *to,
147394994d37SDimitry Andric                                      lldb::SBError &error) {
14746f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, from, to, error);
14755f29bb8aSDimitry Andric 
147694994d37SDimitry Andric   TargetSP target_sp(GetSP());
147794994d37SDimitry Andric   if (!target_sp)
147894994d37SDimitry Andric     return error.SetErrorString("invalid target");
147994994d37SDimitry Andric 
1480c0981da4SDimitry Andric   llvm::StringRef srFrom = from, srTo = to;
1481c0981da4SDimitry Andric   if (srFrom.empty())
148294994d37SDimitry Andric     return error.SetErrorString("<from> path can't be empty");
1483c0981da4SDimitry Andric   if (srTo.empty())
148494994d37SDimitry Andric     return error.SetErrorString("<to> path can't be empty");
148594994d37SDimitry Andric 
1486c0981da4SDimitry Andric   target_sp->GetImageSearchPathList().Append(srFrom, srTo, true);
148794994d37SDimitry Andric }
148894994d37SDimitry Andric 
AddModule(const char * path,const char * triple,const char * uuid_cstr)148914f1b3e8SDimitry Andric lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
149014f1b3e8SDimitry Andric                                    const char *uuid_cstr) {
14916f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, path, triple, uuid_cstr);
14925f29bb8aSDimitry Andric 
14936f8fc217SDimitry Andric   return AddModule(path, triple, uuid_cstr, nullptr);
1494f034231aSEd Maste }
1495f034231aSEd Maste 
AddModule(const char * path,const char * triple,const char * uuid_cstr,const char * symfile)149614f1b3e8SDimitry Andric lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
149714f1b3e8SDimitry Andric                                    const char *uuid_cstr, const char *symfile) {
14986f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, path, triple, uuid_cstr, symfile);
14995f29bb8aSDimitry Andric 
1500f034231aSEd Maste   TargetSP target_sp(GetSP());
1501b1c73532SDimitry Andric   if (!target_sp)
1502b1c73532SDimitry Andric     return {};
1503b1c73532SDimitry Andric 
1504f034231aSEd Maste   ModuleSpec module_spec;
1505f034231aSEd Maste   if (path)
150694994d37SDimitry Andric     module_spec.GetFileSpec().SetFile(path, FileSpec::Style::native);
1507f034231aSEd Maste 
1508f034231aSEd Maste   if (uuid_cstr)
1509f73363f1SDimitry Andric     module_spec.GetUUID().SetFromStringRef(uuid_cstr);
1510f034231aSEd Maste 
1511f034231aSEd Maste   if (triple)
1512b1c73532SDimitry Andric     module_spec.GetArchitecture() =
1513b1c73532SDimitry Andric         Platform::GetAugmentedArchSpec(target_sp->GetPlatform().get(), triple);
1514f21a844fSEd Maste   else
1515f21a844fSEd Maste     module_spec.GetArchitecture() = target_sp->GetArchitecture();
1516f034231aSEd Maste 
1517f034231aSEd Maste   if (symfile)
151894994d37SDimitry Andric     module_spec.GetSymbolFileSpec().SetFile(symfile, FileSpec::Style::native);
1519f034231aSEd Maste 
1520b1c73532SDimitry Andric   SBModuleSpec sb_modulespec(module_spec);
1521b1c73532SDimitry Andric 
1522b1c73532SDimitry Andric   return AddModule(sb_modulespec);
1523f034231aSEd Maste }
1524f034231aSEd Maste 
AddModule(const SBModuleSpec & module_spec)152514f1b3e8SDimitry Andric lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) {
15266f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, module_spec);
15275f29bb8aSDimitry Andric 
1528f034231aSEd Maste   lldb::SBModule sb_module;
1529f034231aSEd Maste   TargetSP target_sp(GetSP());
1530b1c73532SDimitry Andric   if (target_sp) {
15315f29bb8aSDimitry Andric     sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,
15325f29bb8aSDimitry Andric                                                  true /* notify */));
1533b1c73532SDimitry Andric     if (!sb_module.IsValid() && module_spec.m_opaque_up->GetUUID().IsValid()) {
1534b1c73532SDimitry Andric       Status error;
1535b1c73532SDimitry Andric       if (PluginManager::DownloadObjectAndSymbolFile(*module_spec.m_opaque_up,
1536b1c73532SDimitry Andric                                                      error,
1537b1c73532SDimitry Andric                                                      /* force_lookup */ true)) {
1538b1c73532SDimitry Andric         if (FileSystem::Instance().Exists(
1539b1c73532SDimitry Andric                 module_spec.m_opaque_up->GetFileSpec())) {
1540b1c73532SDimitry Andric           sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,
1541b1c73532SDimitry Andric                                                        true /* notify */));
1542b1c73532SDimitry Andric         }
1543b1c73532SDimitry Andric       }
1544b1c73532SDimitry Andric     }
1545b1c73532SDimitry Andric   }
1546b1c73532SDimitry Andric   // If the target hasn't initialized any architecture yet, use the
1547b1c73532SDimitry Andric   // binary's architecture.
1548b1c73532SDimitry Andric   if (sb_module.IsValid() && !target_sp->GetArchitecture().IsValid() &&
1549b1c73532SDimitry Andric       sb_module.GetSP()->GetArchitecture().IsValid())
1550b1c73532SDimitry Andric     target_sp->SetArchitecture(sb_module.GetSP()->GetArchitecture());
15516f8fc217SDimitry Andric   return sb_module;
1552f034231aSEd Maste }
1553f034231aSEd Maste 
AddModule(lldb::SBModule & module)155414f1b3e8SDimitry Andric bool SBTarget::AddModule(lldb::SBModule &module) {
15556f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, module);
15565f29bb8aSDimitry Andric 
1557f034231aSEd Maste   TargetSP target_sp(GetSP());
155814f1b3e8SDimitry Andric   if (target_sp) {
1559f034231aSEd Maste     target_sp->GetImages().AppendIfNeeded(module.GetSP());
1560f034231aSEd Maste     return true;
1561f034231aSEd Maste   }
1562f034231aSEd Maste   return false;
1563f034231aSEd Maste }
1564f034231aSEd Maste 
GetNumModules() const156514f1b3e8SDimitry Andric uint32_t SBTarget::GetNumModules() const {
15666f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1567f034231aSEd Maste 
1568f034231aSEd Maste   uint32_t num = 0;
1569f034231aSEd Maste   TargetSP target_sp(GetSP());
157014f1b3e8SDimitry Andric   if (target_sp) {
1571f034231aSEd Maste     // The module list is thread safe, no need to lock
1572f034231aSEd Maste     num = target_sp->GetImages().GetSize();
1573f034231aSEd Maste   }
1574f034231aSEd Maste 
1575f034231aSEd Maste   return num;
1576f034231aSEd Maste }
1577f034231aSEd Maste 
Clear()157814f1b3e8SDimitry Andric void SBTarget::Clear() {
15796f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1580f034231aSEd Maste 
1581f034231aSEd Maste   m_opaque_sp.reset();
1582f034231aSEd Maste }
1583f034231aSEd Maste 
FindModule(const SBFileSpec & sb_file_spec)158414f1b3e8SDimitry Andric SBModule SBTarget::FindModule(const SBFileSpec &sb_file_spec) {
15856f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, sb_file_spec);
15865f29bb8aSDimitry Andric 
1587f034231aSEd Maste   SBModule sb_module;
1588f034231aSEd Maste   TargetSP target_sp(GetSP());
158914f1b3e8SDimitry Andric   if (target_sp && sb_file_spec.IsValid()) {
1590f034231aSEd Maste     ModuleSpec module_spec(*sb_file_spec);
1591f034231aSEd Maste     // The module list is thread safe, no need to lock
1592f034231aSEd Maste     sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1593f034231aSEd Maste   }
15946f8fc217SDimitry Andric   return sb_module;
1595f034231aSEd Maste }
1596f034231aSEd Maste 
FindCompileUnits(const SBFileSpec & sb_file_spec)15975f29bb8aSDimitry Andric SBSymbolContextList SBTarget::FindCompileUnits(const SBFileSpec &sb_file_spec) {
15986f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, sb_file_spec);
15995f29bb8aSDimitry Andric 
1600f73363f1SDimitry Andric   SBSymbolContextList sb_sc_list;
1601f73363f1SDimitry Andric   const TargetSP target_sp(GetSP());
1602ead24645SDimitry Andric   if (target_sp && sb_file_spec.IsValid())
1603ead24645SDimitry Andric     target_sp->GetImages().FindCompileUnits(*sb_file_spec, *sb_sc_list);
16046f8fc217SDimitry Andric   return sb_sc_list;
1605f73363f1SDimitry Andric }
1606f73363f1SDimitry Andric 
GetByteOrder()160714f1b3e8SDimitry Andric lldb::ByteOrder SBTarget::GetByteOrder() {
16086f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
16095f29bb8aSDimitry Andric 
1610f034231aSEd Maste   TargetSP target_sp(GetSP());
1611f034231aSEd Maste   if (target_sp)
1612f034231aSEd Maste     return target_sp->GetArchitecture().GetByteOrder();
1613f034231aSEd Maste   return eByteOrderInvalid;
1614f034231aSEd Maste }
1615f034231aSEd Maste 
GetTriple()161614f1b3e8SDimitry Andric const char *SBTarget::GetTriple() {
16176f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
16185f29bb8aSDimitry Andric 
1619f034231aSEd Maste   TargetSP target_sp(GetSP());
16207fa27ce4SDimitry Andric   if (!target_sp)
16217fa27ce4SDimitry Andric     return nullptr;
16227fa27ce4SDimitry Andric 
1623f034231aSEd Maste   std::string triple(target_sp->GetArchitecture().GetTriple().str());
1624f73363f1SDimitry Andric   // Unique the string so we don't run into ownership issues since the const
1625f73363f1SDimitry Andric   // strings put the string into the string pool once and the strings never
1626f73363f1SDimitry Andric   // comes out
1627f034231aSEd Maste   ConstString const_triple(triple.c_str());
1628f034231aSEd Maste   return const_triple.GetCString();
1629f034231aSEd Maste }
1630f034231aSEd Maste 
GetABIName()1631145449b1SDimitry Andric const char *SBTarget::GetABIName() {
1632145449b1SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1633145449b1SDimitry Andric 
1634145449b1SDimitry Andric   TargetSP target_sp(GetSP());
16357fa27ce4SDimitry Andric   if (!target_sp)
16367fa27ce4SDimitry Andric     return nullptr;
16377fa27ce4SDimitry Andric 
1638145449b1SDimitry Andric   std::string abi_name(target_sp->GetABIName().str());
1639145449b1SDimitry Andric   ConstString const_name(abi_name.c_str());
1640145449b1SDimitry Andric   return const_name.GetCString();
1641145449b1SDimitry Andric }
16427fa27ce4SDimitry Andric 
GetLabel() const16437fa27ce4SDimitry Andric const char *SBTarget::GetLabel() const {
16447fa27ce4SDimitry Andric   LLDB_INSTRUMENT_VA(this);
16457fa27ce4SDimitry Andric 
16467fa27ce4SDimitry Andric   TargetSP target_sp(GetSP());
16477fa27ce4SDimitry Andric   if (!target_sp)
1648145449b1SDimitry Andric     return nullptr;
16497fa27ce4SDimitry Andric 
16507fa27ce4SDimitry Andric   return ConstString(target_sp->GetLabel().data()).AsCString();
16517fa27ce4SDimitry Andric }
16527fa27ce4SDimitry Andric 
SetLabel(const char * label)16537fa27ce4SDimitry Andric SBError SBTarget::SetLabel(const char *label) {
16547fa27ce4SDimitry Andric   LLDB_INSTRUMENT_VA(this, label);
16557fa27ce4SDimitry Andric 
16567fa27ce4SDimitry Andric   TargetSP target_sp(GetSP());
16577fa27ce4SDimitry Andric   if (!target_sp)
16587fa27ce4SDimitry Andric     return Status("Couldn't get internal target object.");
16597fa27ce4SDimitry Andric 
16607fa27ce4SDimitry Andric   return Status(target_sp->SetLabel(label));
1661145449b1SDimitry Andric }
1662145449b1SDimitry Andric 
GetDataByteSize()166314f1b3e8SDimitry Andric uint32_t SBTarget::GetDataByteSize() {
16646f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
16655f29bb8aSDimitry Andric 
1666205afe67SEd Maste   TargetSP target_sp(GetSP());
166714f1b3e8SDimitry Andric   if (target_sp) {
1668205afe67SEd Maste     return target_sp->GetArchitecture().GetDataByteSize();
1669205afe67SEd Maste   }
1670205afe67SEd Maste   return 0;
1671205afe67SEd Maste }
1672205afe67SEd Maste 
GetCodeByteSize()167314f1b3e8SDimitry Andric uint32_t SBTarget::GetCodeByteSize() {
16746f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
16755f29bb8aSDimitry Andric 
1676205afe67SEd Maste   TargetSP target_sp(GetSP());
167714f1b3e8SDimitry Andric   if (target_sp) {
1678205afe67SEd Maste     return target_sp->GetArchitecture().GetCodeByteSize();
1679205afe67SEd Maste   }
1680205afe67SEd Maste   return 0;
1681205afe67SEd Maste }
1682205afe67SEd Maste 
GetMaximumNumberOfChildrenToDisplay() const1683f65dcba8SDimitry Andric uint32_t SBTarget::GetMaximumNumberOfChildrenToDisplay() const {
16846f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1685f65dcba8SDimitry Andric 
1686f65dcba8SDimitry Andric   TargetSP target_sp(GetSP());
1687f65dcba8SDimitry Andric   if(target_sp){
1688f65dcba8SDimitry Andric      return target_sp->GetMaximumNumberOfChildrenToDisplay();
1689f65dcba8SDimitry Andric   }
1690f65dcba8SDimitry Andric   return 0;
1691f65dcba8SDimitry Andric }
1692f65dcba8SDimitry Andric 
GetAddressByteSize()169314f1b3e8SDimitry Andric uint32_t SBTarget::GetAddressByteSize() {
16946f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
16955f29bb8aSDimitry Andric 
1696f034231aSEd Maste   TargetSP target_sp(GetSP());
1697f034231aSEd Maste   if (target_sp)
1698f034231aSEd Maste     return target_sp->GetArchitecture().GetAddressByteSize();
1699f034231aSEd Maste   return sizeof(void *);
1700f034231aSEd Maste }
1701f034231aSEd Maste 
GetModuleAtIndex(uint32_t idx)170214f1b3e8SDimitry Andric SBModule SBTarget::GetModuleAtIndex(uint32_t idx) {
17036f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, idx);
1704f034231aSEd Maste 
1705f034231aSEd Maste   SBModule sb_module;
1706f034231aSEd Maste   ModuleSP module_sp;
1707f034231aSEd Maste   TargetSP target_sp(GetSP());
170814f1b3e8SDimitry Andric   if (target_sp) {
1709f034231aSEd Maste     // The module list is thread safe, no need to lock
1710f034231aSEd Maste     module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1711f034231aSEd Maste     sb_module.SetSP(module_sp);
1712f034231aSEd Maste   }
1713f034231aSEd Maste 
17146f8fc217SDimitry Andric   return sb_module;
1715f034231aSEd Maste }
1716f034231aSEd Maste 
RemoveModule(lldb::SBModule module)171714f1b3e8SDimitry Andric bool SBTarget::RemoveModule(lldb::SBModule module) {
17186f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, module);
17195f29bb8aSDimitry Andric 
1720f034231aSEd Maste   TargetSP target_sp(GetSP());
1721f034231aSEd Maste   if (target_sp)
1722f034231aSEd Maste     return target_sp->GetImages().Remove(module.GetSP());
1723f034231aSEd Maste   return false;
1724f034231aSEd Maste }
1725f034231aSEd Maste 
GetBroadcaster() const172614f1b3e8SDimitry Andric SBBroadcaster SBTarget::GetBroadcaster() const {
17276f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
1728f034231aSEd Maste 
1729f034231aSEd Maste   TargetSP target_sp(GetSP());
1730f034231aSEd Maste   SBBroadcaster broadcaster(target_sp.get(), false);
1731f034231aSEd Maste 
17326f8fc217SDimitry Andric   return broadcaster;
1733f034231aSEd Maste }
1734f034231aSEd Maste 
GetDescription(SBStream & description,lldb::DescriptionLevel description_level)173514f1b3e8SDimitry Andric bool SBTarget::GetDescription(SBStream &description,
173614f1b3e8SDimitry Andric                               lldb::DescriptionLevel description_level) {
17376f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, description, description_level);
17385f29bb8aSDimitry Andric 
1739f034231aSEd Maste   Stream &strm = description.ref();
1740f034231aSEd Maste 
1741f034231aSEd Maste   TargetSP target_sp(GetSP());
174214f1b3e8SDimitry Andric   if (target_sp) {
1743f034231aSEd Maste     target_sp->Dump(&strm, description_level);
174414f1b3e8SDimitry Andric   } else
1745f034231aSEd Maste     strm.PutCString("No value");
1746f034231aSEd Maste 
1747f034231aSEd Maste   return true;
1748f034231aSEd Maste }
1749f034231aSEd Maste 
FindFunctions(const char * name,uint32_t name_type_mask)175014f1b3e8SDimitry Andric lldb::SBSymbolContextList SBTarget::FindFunctions(const char *name,
175114f1b3e8SDimitry Andric                                                   uint32_t name_type_mask) {
17526f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, name_type_mask);
17535f29bb8aSDimitry Andric 
1754f034231aSEd Maste   lldb::SBSymbolContextList sb_sc_list;
1755b60736ecSDimitry Andric   if (!name || !name[0])
17566f8fc217SDimitry Andric     return sb_sc_list;
175794994d37SDimitry Andric 
1758f034231aSEd Maste   TargetSP target_sp(GetSP());
175994994d37SDimitry Andric   if (!target_sp)
17606f8fc217SDimitry Andric     return sb_sc_list;
176194994d37SDimitry Andric 
1762c0981da4SDimitry Andric   ModuleFunctionSearchOptions function_options;
1763c0981da4SDimitry Andric   function_options.include_symbols = true;
1764c0981da4SDimitry Andric   function_options.include_inlines = true;
1765c0981da4SDimitry Andric 
176694994d37SDimitry Andric   FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
1767c0981da4SDimitry Andric   target_sp->GetImages().FindFunctions(ConstString(name), mask,
1768c0981da4SDimitry Andric                                        function_options, *sb_sc_list);
17696f8fc217SDimitry Andric   return sb_sc_list;
1770f034231aSEd Maste }
1771f034231aSEd Maste 
FindGlobalFunctions(const char * name,uint32_t max_matches,MatchType matchtype)177214f1b3e8SDimitry Andric lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name,
177314f1b3e8SDimitry Andric                                                         uint32_t max_matches,
177414f1b3e8SDimitry Andric                                                         MatchType matchtype) {
17756f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, max_matches, matchtype);
17765f29bb8aSDimitry Andric 
1777205afe67SEd Maste   lldb::SBSymbolContextList sb_sc_list;
177814f1b3e8SDimitry Andric   if (name && name[0]) {
177914f1b3e8SDimitry Andric     llvm::StringRef name_ref(name);
1780205afe67SEd Maste     TargetSP target_sp(GetSP());
178114f1b3e8SDimitry Andric     if (target_sp) {
1782c0981da4SDimitry Andric       ModuleFunctionSearchOptions function_options;
1783c0981da4SDimitry Andric       function_options.include_symbols = true;
1784c0981da4SDimitry Andric       function_options.include_inlines = true;
1785c0981da4SDimitry Andric 
1786205afe67SEd Maste       std::string regexstr;
178714f1b3e8SDimitry Andric       switch (matchtype) {
1788205afe67SEd Maste       case eMatchTypeRegex:
1789c0981da4SDimitry Andric         target_sp->GetImages().FindFunctions(RegularExpression(name_ref),
1790c0981da4SDimitry Andric                                              function_options, *sb_sc_list);
1791205afe67SEd Maste         break;
1792ac9a064cSDimitry Andric       case eMatchTypeRegexInsensitive:
1793ac9a064cSDimitry Andric         target_sp->GetImages().FindFunctions(
1794ac9a064cSDimitry Andric             RegularExpression(name_ref, llvm::Regex::RegexFlags::IgnoreCase),
1795ac9a064cSDimitry Andric             function_options, *sb_sc_list);
1796ac9a064cSDimitry Andric         break;
1797205afe67SEd Maste       case eMatchTypeStartsWith:
1798205afe67SEd Maste         regexstr = llvm::Regex::escape(name) + ".*";
1799c0981da4SDimitry Andric         target_sp->GetImages().FindFunctions(RegularExpression(regexstr),
1800c0981da4SDimitry Andric                                              function_options, *sb_sc_list);
1801205afe67SEd Maste         break;
1802205afe67SEd Maste       default:
1803c0981da4SDimitry Andric         target_sp->GetImages().FindFunctions(ConstString(name),
1804c0981da4SDimitry Andric                                              eFunctionNameTypeAny,
1805c0981da4SDimitry Andric                                              function_options, *sb_sc_list);
1806205afe67SEd Maste         break;
1807205afe67SEd Maste       }
1808205afe67SEd Maste     }
1809205afe67SEd Maste   }
18106f8fc217SDimitry Andric   return sb_sc_list;
1811205afe67SEd Maste }
1812205afe67SEd Maste 
FindFirstType(const char * typename_cstr)181314f1b3e8SDimitry Andric lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
18146f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, typename_cstr);
18155f29bb8aSDimitry Andric 
1816f034231aSEd Maste   TargetSP target_sp(GetSP());
181714f1b3e8SDimitry Andric   if (typename_cstr && typename_cstr[0] && target_sp) {
1818f034231aSEd Maste     ConstString const_typename(typename_cstr);
1819312c0ed1SDimitry Andric     TypeQuery query(const_typename.GetStringRef(),
1820312c0ed1SDimitry Andric                     TypeQueryOptions::e_find_one);
1821312c0ed1SDimitry Andric     TypeResults results;
1822312c0ed1SDimitry Andric     target_sp->GetImages().FindTypes(/*search_first=*/nullptr, query, results);
1823312c0ed1SDimitry Andric     TypeSP type_sp = results.GetFirstType();
1824f034231aSEd Maste     if (type_sp)
18256f8fc217SDimitry Andric       return SBType(type_sp);
1826e3b55780SDimitry Andric     // Didn't find the type in the symbols; Try the loaded language runtimes.
18275f29bb8aSDimitry Andric     if (auto process_sp = target_sp->GetProcessSP()) {
18285f29bb8aSDimitry Andric       for (auto *runtime : process_sp->GetLanguageRuntimes()) {
18295f29bb8aSDimitry Andric         if (auto vendor = runtime->GetDeclVendor()) {
18305f29bb8aSDimitry Andric           auto types = vendor->FindTypes(const_typename, /*max_matches*/ 1);
18315f29bb8aSDimitry Andric           if (!types.empty())
18326f8fc217SDimitry Andric             return SBType(types.front());
1833f034231aSEd Maste         }
1834f034231aSEd Maste       }
1835f034231aSEd Maste     }
1836f034231aSEd Maste 
1837e3b55780SDimitry Andric     // No matches, search for basic typename matches.
1838e3b55780SDimitry Andric     for (auto type_system_sp : target_sp->GetScratchTypeSystems())
1839e3b55780SDimitry Andric       if (auto type = type_system_sp->GetBuiltinTypeByName(const_typename))
18406f8fc217SDimitry Andric         return SBType(type);
1841f034231aSEd Maste   }
1842ead24645SDimitry Andric 
18436f8fc217SDimitry Andric   return SBType();
1844f034231aSEd Maste }
1845f034231aSEd Maste 
GetBasicType(lldb::BasicType type)184614f1b3e8SDimitry Andric SBType SBTarget::GetBasicType(lldb::BasicType type) {
18476f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, type);
18485f29bb8aSDimitry Andric 
1849f034231aSEd Maste   TargetSP target_sp(GetSP());
185014f1b3e8SDimitry Andric   if (target_sp) {
1851e3b55780SDimitry Andric     for (auto type_system_sp : target_sp->GetScratchTypeSystems())
1852e3b55780SDimitry Andric       if (auto compiler_type = type_system_sp->GetBasicTypeFromAST(type))
18536f8fc217SDimitry Andric         return SBType(compiler_type);
1854f034231aSEd Maste   }
18556f8fc217SDimitry Andric   return SBType();
1856f034231aSEd Maste }
1857f034231aSEd Maste 
FindTypes(const char * typename_cstr)185814f1b3e8SDimitry Andric lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
18596f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, typename_cstr);
18605f29bb8aSDimitry Andric 
1861f034231aSEd Maste   SBTypeList sb_type_list;
1862f034231aSEd Maste   TargetSP target_sp(GetSP());
186314f1b3e8SDimitry Andric   if (typename_cstr && typename_cstr[0] && target_sp) {
1864f034231aSEd Maste     ModuleList &images = target_sp->GetImages();
1865f034231aSEd Maste     ConstString const_typename(typename_cstr);
1866312c0ed1SDimitry Andric     TypeQuery query(typename_cstr);
1867312c0ed1SDimitry Andric     TypeResults results;
1868312c0ed1SDimitry Andric     images.FindTypes(nullptr, query, results);
1869312c0ed1SDimitry Andric     for (const TypeSP &type_sp : results.GetTypeMap().Types())
1870f034231aSEd Maste       sb_type_list.Append(SBType(type_sp));
1871f034231aSEd Maste 
18725f29bb8aSDimitry Andric     // Try the loaded language runtimes
18735f29bb8aSDimitry Andric     if (auto process_sp = target_sp->GetProcessSP()) {
18745f29bb8aSDimitry Andric       for (auto *runtime : process_sp->GetLanguageRuntimes()) {
18755f29bb8aSDimitry Andric         if (auto *vendor = runtime->GetDeclVendor()) {
18765f29bb8aSDimitry Andric           auto types =
18775f29bb8aSDimitry Andric               vendor->FindTypes(const_typename, /*max_matches*/ UINT32_MAX);
18785f29bb8aSDimitry Andric           for (auto type : types)
1879f034231aSEd Maste             sb_type_list.Append(SBType(type));
1880f034231aSEd Maste         }
1881f034231aSEd Maste       }
1882f034231aSEd Maste     }
1883f034231aSEd Maste 
188414f1b3e8SDimitry Andric     if (sb_type_list.GetSize() == 0) {
1885f034231aSEd Maste       // No matches, search for basic typename matches
1886e3b55780SDimitry Andric       for (auto type_system_sp : target_sp->GetScratchTypeSystems())
1887ead24645SDimitry Andric         if (auto compiler_type =
1888e3b55780SDimitry Andric                 type_system_sp->GetBuiltinTypeByName(const_typename))
1889ead24645SDimitry Andric           sb_type_list.Append(SBType(compiler_type));
1890f034231aSEd Maste     }
1891f034231aSEd Maste   }
18926f8fc217SDimitry Andric   return sb_type_list;
1893f034231aSEd Maste }
1894f034231aSEd Maste 
FindGlobalVariables(const char * name,uint32_t max_matches)189514f1b3e8SDimitry Andric SBValueList SBTarget::FindGlobalVariables(const char *name,
189614f1b3e8SDimitry Andric                                           uint32_t max_matches) {
18976f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, max_matches);
18985f29bb8aSDimitry Andric 
1899f034231aSEd Maste   SBValueList sb_value_list;
1900f034231aSEd Maste 
1901f034231aSEd Maste   TargetSP target_sp(GetSP());
190214f1b3e8SDimitry Andric   if (name && target_sp) {
1903f034231aSEd Maste     VariableList variable_list;
1904ead24645SDimitry Andric     target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
1905ead24645SDimitry Andric                                                variable_list);
1906706b4fc4SDimitry Andric     if (!variable_list.Empty()) {
1907f034231aSEd Maste       ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
19085f29bb8aSDimitry Andric       if (exe_scope == nullptr)
1909f034231aSEd Maste         exe_scope = target_sp.get();
1910706b4fc4SDimitry Andric       for (const VariableSP &var_sp : variable_list) {
1911706b4fc4SDimitry Andric         lldb::ValueObjectSP valobj_sp(
1912706b4fc4SDimitry Andric             ValueObjectVariable::Create(exe_scope, var_sp));
1913f034231aSEd Maste         if (valobj_sp)
1914f034231aSEd Maste           sb_value_list.Append(SBValue(valobj_sp));
1915f034231aSEd Maste       }
1916f034231aSEd Maste     }
1917f034231aSEd Maste   }
1918f034231aSEd Maste 
19196f8fc217SDimitry Andric   return sb_value_list;
1920f034231aSEd Maste }
1921f034231aSEd Maste 
FindGlobalVariables(const char * name,uint32_t max_matches,MatchType matchtype)192214f1b3e8SDimitry Andric SBValueList SBTarget::FindGlobalVariables(const char *name,
192314f1b3e8SDimitry Andric                                           uint32_t max_matches,
192414f1b3e8SDimitry Andric                                           MatchType matchtype) {
19256f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, max_matches, matchtype);
19265f29bb8aSDimitry Andric 
1927205afe67SEd Maste   SBValueList sb_value_list;
1928205afe67SEd Maste 
1929205afe67SEd Maste   TargetSP target_sp(GetSP());
193014f1b3e8SDimitry Andric   if (name && target_sp) {
193114f1b3e8SDimitry Andric     llvm::StringRef name_ref(name);
1932205afe67SEd Maste     VariableList variable_list;
1933205afe67SEd Maste 
1934205afe67SEd Maste     std::string regexstr;
193514f1b3e8SDimitry Andric     switch (matchtype) {
1936205afe67SEd Maste     case eMatchTypeNormal:
1937ead24645SDimitry Andric       target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
1938ead24645SDimitry Andric                                                  variable_list);
1939205afe67SEd Maste       break;
1940205afe67SEd Maste     case eMatchTypeRegex:
1941ead24645SDimitry Andric       target_sp->GetImages().FindGlobalVariables(RegularExpression(name_ref),
1942ead24645SDimitry Andric                                                  max_matches, variable_list);
1943205afe67SEd Maste       break;
1944ac9a064cSDimitry Andric     case eMatchTypeRegexInsensitive:
1945ac9a064cSDimitry Andric       target_sp->GetImages().FindGlobalVariables(
1946ac9a064cSDimitry Andric           RegularExpression(name_ref, llvm::Regex::IgnoreCase), max_matches,
1947ac9a064cSDimitry Andric           variable_list);
1948ac9a064cSDimitry Andric       break;
1949205afe67SEd Maste     case eMatchTypeStartsWith:
19507fa27ce4SDimitry Andric       regexstr = "^" + llvm::Regex::escape(name) + ".*";
1951ead24645SDimitry Andric       target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr),
1952ead24645SDimitry Andric                                                  max_matches, variable_list);
1953205afe67SEd Maste       break;
1954205afe67SEd Maste     }
1955706b4fc4SDimitry Andric     if (!variable_list.Empty()) {
1956205afe67SEd Maste       ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
19575f29bb8aSDimitry Andric       if (exe_scope == nullptr)
1958205afe67SEd Maste         exe_scope = target_sp.get();
1959706b4fc4SDimitry Andric       for (const VariableSP &var_sp : variable_list) {
1960706b4fc4SDimitry Andric         lldb::ValueObjectSP valobj_sp(
1961706b4fc4SDimitry Andric             ValueObjectVariable::Create(exe_scope, var_sp));
1962205afe67SEd Maste         if (valobj_sp)
1963205afe67SEd Maste           sb_value_list.Append(SBValue(valobj_sp));
1964205afe67SEd Maste       }
1965205afe67SEd Maste     }
1966205afe67SEd Maste   }
1967205afe67SEd Maste 
19686f8fc217SDimitry Andric   return sb_value_list;
1969205afe67SEd Maste }
1970205afe67SEd Maste 
FindFirstGlobalVariable(const char * name)197114f1b3e8SDimitry Andric lldb::SBValue SBTarget::FindFirstGlobalVariable(const char *name) {
19726f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name);
19735f29bb8aSDimitry Andric 
1974f034231aSEd Maste   SBValueList sb_value_list(FindGlobalVariables(name, 1));
1975f034231aSEd Maste   if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
19766f8fc217SDimitry Andric     return sb_value_list.GetValueAtIndex(0);
19776f8fc217SDimitry Andric   return SBValue();
1978f034231aSEd Maste }
1979f034231aSEd Maste 
GetSourceManager()198014f1b3e8SDimitry Andric SBSourceManager SBTarget::GetSourceManager() {
19816f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
19825f29bb8aSDimitry Andric 
1983f034231aSEd Maste   SBSourceManager source_manager(*this);
19846f8fc217SDimitry Andric   return source_manager;
1985f034231aSEd Maste }
1986f034231aSEd Maste 
ReadInstructions(lldb::SBAddress base_addr,uint32_t count)198714f1b3e8SDimitry Andric lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
198814f1b3e8SDimitry Andric                                                    uint32_t count) {
19896f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, base_addr, count);
19905f29bb8aSDimitry Andric 
19916f8fc217SDimitry Andric   return ReadInstructions(base_addr, count, nullptr);
1992f034231aSEd Maste }
1993f034231aSEd Maste 
ReadInstructions(lldb::SBAddress base_addr,uint32_t count,const char * flavor_string)199414f1b3e8SDimitry Andric lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
199514f1b3e8SDimitry Andric                                                    uint32_t count,
199614f1b3e8SDimitry Andric                                                    const char *flavor_string) {
19976f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, base_addr, count, flavor_string);
19985f29bb8aSDimitry Andric 
1999f034231aSEd Maste   SBInstructionList sb_instructions;
2000f034231aSEd Maste 
2001f034231aSEd Maste   TargetSP target_sp(GetSP());
200214f1b3e8SDimitry Andric   if (target_sp) {
2003f034231aSEd Maste     Address *addr_ptr = base_addr.get();
2004f034231aSEd Maste 
200514f1b3e8SDimitry Andric     if (addr_ptr) {
200614f1b3e8SDimitry Andric       DataBufferHeap data(
200714f1b3e8SDimitry Andric           target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2008344a3780SDimitry Andric       bool force_live_memory = true;
2009b76161e4SDimitry Andric       lldb_private::Status error;
2010f034231aSEd Maste       lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
201114f1b3e8SDimitry Andric       const size_t bytes_read =
2012344a3780SDimitry Andric           target_sp->ReadMemory(*addr_ptr, data.GetBytes(), data.GetByteSize(),
2013344a3780SDimitry Andric                                 error, force_live_memory, &load_addr);
2014f034231aSEd Maste       const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
201514f1b3e8SDimitry Andric       sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
20165f29bb8aSDimitry Andric           target_sp->GetArchitecture(), nullptr, flavor_string, *addr_ptr,
201714f1b3e8SDimitry Andric           data.GetBytes(), bytes_read, count, data_from_file));
2018f034231aSEd Maste     }
2019f034231aSEd Maste   }
2020f034231aSEd Maste 
20216f8fc217SDimitry Andric   return sb_instructions;
2022f034231aSEd Maste }
2023f034231aSEd Maste 
ReadInstructions(lldb::SBAddress start_addr,lldb::SBAddress end_addr,const char * flavor_string)2024ac9a064cSDimitry Andric lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress start_addr,
2025ac9a064cSDimitry Andric                                                    lldb::SBAddress end_addr,
2026ac9a064cSDimitry Andric                                                    const char *flavor_string) {
2027ac9a064cSDimitry Andric   LLDB_INSTRUMENT_VA(this, start_addr, end_addr, flavor_string);
2028ac9a064cSDimitry Andric 
2029ac9a064cSDimitry Andric   SBInstructionList sb_instructions;
2030ac9a064cSDimitry Andric 
2031ac9a064cSDimitry Andric   TargetSP target_sp(GetSP());
2032ac9a064cSDimitry Andric   if (target_sp) {
2033ac9a064cSDimitry Andric     lldb::addr_t start_load_addr = start_addr.GetLoadAddress(*this);
2034ac9a064cSDimitry Andric     lldb::addr_t end_load_addr = end_addr.GetLoadAddress(*this);
2035ac9a064cSDimitry Andric     if (end_load_addr > start_load_addr) {
2036ac9a064cSDimitry Andric       lldb::addr_t size = end_load_addr - start_load_addr;
2037ac9a064cSDimitry Andric 
2038ac9a064cSDimitry Andric       AddressRange range(start_load_addr, size);
2039ac9a064cSDimitry Andric       const bool force_live_memory = true;
2040ac9a064cSDimitry Andric       sb_instructions.SetDisassembler(Disassembler::DisassembleRange(
2041ac9a064cSDimitry Andric           target_sp->GetArchitecture(), nullptr, flavor_string, *target_sp,
2042ac9a064cSDimitry Andric           range, force_live_memory));
2043ac9a064cSDimitry Andric     }
2044ac9a064cSDimitry Andric   }
2045ac9a064cSDimitry Andric   return sb_instructions;
2046ac9a064cSDimitry Andric }
2047ac9a064cSDimitry Andric 
GetInstructions(lldb::SBAddress base_addr,const void * buf,size_t size)204814f1b3e8SDimitry Andric lldb::SBInstructionList SBTarget::GetInstructions(lldb::SBAddress base_addr,
204914f1b3e8SDimitry Andric                                                   const void *buf,
205014f1b3e8SDimitry Andric                                                   size_t size) {
20516f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, base_addr, buf, size);
20525f29bb8aSDimitry Andric 
20536f8fc217SDimitry Andric   return GetInstructionsWithFlavor(base_addr, nullptr, buf, size);
2054f034231aSEd Maste }
2055f034231aSEd Maste 
2056f034231aSEd Maste lldb::SBInstructionList
GetInstructionsWithFlavor(lldb::SBAddress base_addr,const char * flavor_string,const void * buf,size_t size)205714f1b3e8SDimitry Andric SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
205814f1b3e8SDimitry Andric                                     const char *flavor_string, const void *buf,
205914f1b3e8SDimitry Andric                                     size_t size) {
20606f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, base_addr, flavor_string, buf, size);
20615f29bb8aSDimitry Andric 
2062f034231aSEd Maste   SBInstructionList sb_instructions;
2063f034231aSEd Maste 
2064f034231aSEd Maste   TargetSP target_sp(GetSP());
206514f1b3e8SDimitry Andric   if (target_sp) {
2066f034231aSEd Maste     Address addr;
2067f034231aSEd Maste 
2068f034231aSEd Maste     if (base_addr.get())
2069f034231aSEd Maste       addr = *base_addr.get();
2070f034231aSEd Maste 
2071f034231aSEd Maste     const bool data_from_file = true;
2072f034231aSEd Maste 
207314f1b3e8SDimitry Andric     sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
20745f29bb8aSDimitry Andric         target_sp->GetArchitecture(), nullptr, flavor_string, addr, buf, size,
207514f1b3e8SDimitry Andric         UINT32_MAX, data_from_file));
2076f034231aSEd Maste   }
2077f034231aSEd Maste 
20786f8fc217SDimitry Andric   return sb_instructions;
2079f034231aSEd Maste }
2080f034231aSEd Maste 
GetInstructions(lldb::addr_t base_addr,const void * buf,size_t size)208114f1b3e8SDimitry Andric lldb::SBInstructionList SBTarget::GetInstructions(lldb::addr_t base_addr,
208214f1b3e8SDimitry Andric                                                   const void *buf,
208314f1b3e8SDimitry Andric                                                   size_t size) {
20846f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, base_addr, buf, size);
2085cfca06d7SDimitry Andric 
20866f8fc217SDimitry Andric   return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), nullptr, buf,
20876f8fc217SDimitry Andric                                    size);
2088f034231aSEd Maste }
2089f034231aSEd Maste 
2090f034231aSEd Maste lldb::SBInstructionList
GetInstructionsWithFlavor(lldb::addr_t base_addr,const char * flavor_string,const void * buf,size_t size)209114f1b3e8SDimitry Andric SBTarget::GetInstructionsWithFlavor(lldb::addr_t base_addr,
209214f1b3e8SDimitry Andric                                     const char *flavor_string, const void *buf,
209314f1b3e8SDimitry Andric                                     size_t size) {
20946f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, base_addr, flavor_string, buf, size);
20955f29bb8aSDimitry Andric 
20966f8fc217SDimitry Andric   return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string,
20976f8fc217SDimitry Andric                                    buf, size);
2098f034231aSEd Maste }
2099f034231aSEd Maste 
SetSectionLoadAddress(lldb::SBSection section,lldb::addr_t section_base_addr)210014f1b3e8SDimitry Andric SBError SBTarget::SetSectionLoadAddress(lldb::SBSection section,
210114f1b3e8SDimitry Andric                                         lldb::addr_t section_base_addr) {
21026f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, section, section_base_addr);
21035f29bb8aSDimitry Andric 
2104f034231aSEd Maste   SBError sb_error;
2105f034231aSEd Maste   TargetSP target_sp(GetSP());
210614f1b3e8SDimitry Andric   if (target_sp) {
210714f1b3e8SDimitry Andric     if (!section.IsValid()) {
2108f034231aSEd Maste       sb_error.SetErrorStringWithFormat("invalid section");
210914f1b3e8SDimitry Andric     } else {
2110f034231aSEd Maste       SectionSP section_sp(section.GetSP());
211114f1b3e8SDimitry Andric       if (section_sp) {
211214f1b3e8SDimitry Andric         if (section_sp->IsThreadSpecific()) {
211314f1b3e8SDimitry Andric           sb_error.SetErrorString(
211414f1b3e8SDimitry Andric               "thread specific sections are not yet supported");
211514f1b3e8SDimitry Andric         } else {
2116866dcdacSEd Maste           ProcessSP process_sp(target_sp->GetProcessSP());
211714f1b3e8SDimitry Andric           if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
2118f3fbd1c0SDimitry Andric             ModuleSP module_sp(section_sp->GetModule());
211914f1b3e8SDimitry Andric             if (module_sp) {
2120f3fbd1c0SDimitry Andric               ModuleList module_list;
2121f3fbd1c0SDimitry Andric               module_list.Append(module_sp);
2122f3fbd1c0SDimitry Andric               target_sp->ModulesDidLoad(module_list);
2123f3fbd1c0SDimitry Andric             }
2124f034231aSEd Maste             // Flush info in the process (stack frames, etc)
2125f034231aSEd Maste             if (process_sp)
2126f034231aSEd Maste               process_sp->Flush();
2127f034231aSEd Maste           }
2128f034231aSEd Maste         }
2129f034231aSEd Maste       }
2130f034231aSEd Maste     }
213114f1b3e8SDimitry Andric   } else {
2132f034231aSEd Maste     sb_error.SetErrorString("invalid target");
2133f034231aSEd Maste   }
21346f8fc217SDimitry Andric   return sb_error;
2135f034231aSEd Maste }
2136f034231aSEd Maste 
ClearSectionLoadAddress(lldb::SBSection section)213714f1b3e8SDimitry Andric SBError SBTarget::ClearSectionLoadAddress(lldb::SBSection section) {
21386f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, section);
21395f29bb8aSDimitry Andric 
2140f034231aSEd Maste   SBError sb_error;
2141f034231aSEd Maste 
2142f034231aSEd Maste   TargetSP target_sp(GetSP());
214314f1b3e8SDimitry Andric   if (target_sp) {
214414f1b3e8SDimitry Andric     if (!section.IsValid()) {
2145f034231aSEd Maste       sb_error.SetErrorStringWithFormat("invalid section");
214614f1b3e8SDimitry Andric     } else {
2147f3fbd1c0SDimitry Andric       SectionSP section_sp(section.GetSP());
214814f1b3e8SDimitry Andric       if (section_sp) {
2149f3fbd1c0SDimitry Andric         ProcessSP process_sp(target_sp->GetProcessSP());
215014f1b3e8SDimitry Andric         if (target_sp->SetSectionUnloaded(section_sp)) {
2151f3fbd1c0SDimitry Andric           ModuleSP module_sp(section_sp->GetModule());
215214f1b3e8SDimitry Andric           if (module_sp) {
2153f3fbd1c0SDimitry Andric             ModuleList module_list;
2154f3fbd1c0SDimitry Andric             module_list.Append(module_sp);
2155f3fbd1c0SDimitry Andric             target_sp->ModulesDidUnload(module_list, false);
2156f3fbd1c0SDimitry Andric           }
2157f034231aSEd Maste           // Flush info in the process (stack frames, etc)
2158f034231aSEd Maste           if (process_sp)
2159f034231aSEd Maste             process_sp->Flush();
2160f034231aSEd Maste         }
216114f1b3e8SDimitry Andric       } else {
2162f3fbd1c0SDimitry Andric         sb_error.SetErrorStringWithFormat("invalid section");
2163f3fbd1c0SDimitry Andric       }
2164f3fbd1c0SDimitry Andric     }
216514f1b3e8SDimitry Andric   } else {
2166f034231aSEd Maste     sb_error.SetErrorStringWithFormat("invalid target");
2167f034231aSEd Maste   }
21686f8fc217SDimitry Andric   return sb_error;
2169f034231aSEd Maste }
2170f034231aSEd Maste 
SetModuleLoadAddress(lldb::SBModule module,int64_t slide_offset)217114f1b3e8SDimitry Andric SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
217214f1b3e8SDimitry Andric                                        int64_t slide_offset) {
21736f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, module, slide_offset);
21745f29bb8aSDimitry Andric 
21757fa27ce4SDimitry Andric   if (slide_offset < 0) {
21767fa27ce4SDimitry Andric     SBError sb_error;
21777fa27ce4SDimitry Andric     sb_error.SetErrorStringWithFormat("slide must be positive");
21787fa27ce4SDimitry Andric     return sb_error;
21797fa27ce4SDimitry Andric   }
21807fa27ce4SDimitry Andric 
21817fa27ce4SDimitry Andric   return SetModuleLoadAddress(module, static_cast<uint64_t>(slide_offset));
21827fa27ce4SDimitry Andric }
21837fa27ce4SDimitry Andric 
SetModuleLoadAddress(lldb::SBModule module,uint64_t slide_offset)21847fa27ce4SDimitry Andric SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
21857fa27ce4SDimitry Andric                                                uint64_t slide_offset) {
21867fa27ce4SDimitry Andric 
2187f034231aSEd Maste   SBError sb_error;
2188f034231aSEd Maste 
2189f034231aSEd Maste   TargetSP target_sp(GetSP());
219014f1b3e8SDimitry Andric   if (target_sp) {
2191f034231aSEd Maste     ModuleSP module_sp(module.GetSP());
219214f1b3e8SDimitry Andric     if (module_sp) {
2193f034231aSEd Maste       bool changed = false;
219414f1b3e8SDimitry Andric       if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) {
2195f034231aSEd Maste         // The load was successful, make sure that at least some sections
2196f034231aSEd Maste         // changed before we notify that our module was loaded.
219714f1b3e8SDimitry Andric         if (changed) {
2198f034231aSEd Maste           ModuleList module_list;
2199f034231aSEd Maste           module_list.Append(module_sp);
2200f034231aSEd Maste           target_sp->ModulesDidLoad(module_list);
2201f034231aSEd Maste           // Flush info in the process (stack frames, etc)
2202f034231aSEd Maste           ProcessSP process_sp(target_sp->GetProcessSP());
2203f034231aSEd Maste           if (process_sp)
2204f034231aSEd Maste             process_sp->Flush();
2205f034231aSEd Maste         }
2206f034231aSEd Maste       }
220714f1b3e8SDimitry Andric     } else {
2208f034231aSEd Maste       sb_error.SetErrorStringWithFormat("invalid module");
2209f034231aSEd Maste     }
2210f034231aSEd Maste 
221114f1b3e8SDimitry Andric   } else {
2212f034231aSEd Maste     sb_error.SetErrorStringWithFormat("invalid target");
2213f034231aSEd Maste   }
22146f8fc217SDimitry Andric   return sb_error;
2215f034231aSEd Maste }
2216f034231aSEd Maste 
ClearModuleLoadAddress(lldb::SBModule module)221714f1b3e8SDimitry Andric SBError SBTarget::ClearModuleLoadAddress(lldb::SBModule module) {
22186f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, module);
22195f29bb8aSDimitry Andric 
2220f034231aSEd Maste   SBError sb_error;
2221f034231aSEd Maste 
2222f034231aSEd Maste   char path[PATH_MAX];
2223f034231aSEd Maste   TargetSP target_sp(GetSP());
222414f1b3e8SDimitry Andric   if (target_sp) {
2225f034231aSEd Maste     ModuleSP module_sp(module.GetSP());
222614f1b3e8SDimitry Andric     if (module_sp) {
2227f034231aSEd Maste       ObjectFile *objfile = module_sp->GetObjectFile();
222814f1b3e8SDimitry Andric       if (objfile) {
2229f034231aSEd Maste         SectionList *section_list = objfile->GetSectionList();
223014f1b3e8SDimitry Andric         if (section_list) {
2231866dcdacSEd Maste           ProcessSP process_sp(target_sp->GetProcessSP());
2232866dcdacSEd Maste 
2233f034231aSEd Maste           bool changed = false;
2234f034231aSEd Maste           const size_t num_sections = section_list->GetSize();
223514f1b3e8SDimitry Andric           for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
2236f034231aSEd Maste             SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
2237f034231aSEd Maste             if (section_sp)
22380cac4ca3SEd Maste               changed |= target_sp->SetSectionUnloaded(section_sp);
2239f034231aSEd Maste           }
224014f1b3e8SDimitry Andric           if (changed) {
2241f3fbd1c0SDimitry Andric             ModuleList module_list;
2242f3fbd1c0SDimitry Andric             module_list.Append(module_sp);
2243f3fbd1c0SDimitry Andric             target_sp->ModulesDidUnload(module_list, false);
2244f034231aSEd Maste             // Flush info in the process (stack frames, etc)
2245f034231aSEd Maste             ProcessSP process_sp(target_sp->GetProcessSP());
2246f034231aSEd Maste             if (process_sp)
2247f034231aSEd Maste               process_sp->Flush();
2248f034231aSEd Maste           }
224914f1b3e8SDimitry Andric         } else {
2250f034231aSEd Maste           module_sp->GetFileSpec().GetPath(path, sizeof(path));
225114f1b3e8SDimitry Andric           sb_error.SetErrorStringWithFormat("no sections in object file '%s'",
225214f1b3e8SDimitry Andric                                             path);
2253f034231aSEd Maste         }
225414f1b3e8SDimitry Andric       } else {
2255f034231aSEd Maste         module_sp->GetFileSpec().GetPath(path, sizeof(path));
225614f1b3e8SDimitry Andric         sb_error.SetErrorStringWithFormat("no object file for module '%s'",
225714f1b3e8SDimitry Andric                                           path);
2258f034231aSEd Maste       }
225914f1b3e8SDimitry Andric     } else {
2260f034231aSEd Maste       sb_error.SetErrorStringWithFormat("invalid module");
2261f034231aSEd Maste     }
226214f1b3e8SDimitry Andric   } else {
2263f034231aSEd Maste     sb_error.SetErrorStringWithFormat("invalid target");
2264f034231aSEd Maste   }
22656f8fc217SDimitry Andric   return sb_error;
2266f034231aSEd Maste }
2267f034231aSEd Maste 
FindSymbols(const char * name,lldb::SymbolType symbol_type)226814f1b3e8SDimitry Andric lldb::SBSymbolContextList SBTarget::FindSymbols(const char *name,
226914f1b3e8SDimitry Andric                                                 lldb::SymbolType symbol_type) {
22706f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, name, symbol_type);
22715f29bb8aSDimitry Andric 
2272f034231aSEd Maste   SBSymbolContextList sb_sc_list;
227314f1b3e8SDimitry Andric   if (name && name[0]) {
2274f034231aSEd Maste     TargetSP target_sp(GetSP());
2275ead24645SDimitry Andric     if (target_sp)
227614f1b3e8SDimitry Andric       target_sp->GetImages().FindSymbolsWithNameAndType(
2277ead24645SDimitry Andric           ConstString(name), symbol_type, *sb_sc_list);
2278f034231aSEd Maste   }
22796f8fc217SDimitry Andric   return sb_sc_list;
2280f034231aSEd Maste }
2281f034231aSEd Maste 
EvaluateExpression(const char * expr)228214f1b3e8SDimitry Andric lldb::SBValue SBTarget::EvaluateExpression(const char *expr) {
22836f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, expr);
22845f29bb8aSDimitry Andric 
2285027f1c96SDimitry Andric   TargetSP target_sp(GetSP());
2286027f1c96SDimitry Andric   if (!target_sp)
22876f8fc217SDimitry Andric     return SBValue();
2288027f1c96SDimitry Andric 
2289027f1c96SDimitry Andric   SBExpressionOptions options;
229014f1b3e8SDimitry Andric   lldb::DynamicValueType fetch_dynamic_value =
229114f1b3e8SDimitry Andric       target_sp->GetPreferDynamicValue();
2292027f1c96SDimitry Andric   options.SetFetchDynamicValue(fetch_dynamic_value);
2293027f1c96SDimitry Andric   options.SetUnwindOnError(true);
22946f8fc217SDimitry Andric   return EvaluateExpression(expr, options);
2295027f1c96SDimitry Andric }
2296f034231aSEd Maste 
EvaluateExpression(const char * expr,const SBExpressionOptions & options)229714f1b3e8SDimitry Andric lldb::SBValue SBTarget::EvaluateExpression(const char *expr,
229814f1b3e8SDimitry Andric                                            const SBExpressionOptions &options) {
22996f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, expr, options);
23005f29bb8aSDimitry Andric 
2301145449b1SDimitry Andric   Log *expr_log = GetLog(LLDBLog::Expressions);
2302f034231aSEd Maste   SBValue expr_result;
2303f034231aSEd Maste   ValueObjectSP expr_value_sp;
2304f034231aSEd Maste   TargetSP target_sp(GetSP());
23055f29bb8aSDimitry Andric   StackFrame *frame = nullptr;
230614f1b3e8SDimitry Andric   if (target_sp) {
23075f29bb8aSDimitry Andric     if (expr == nullptr || expr[0] == '\0') {
23086f8fc217SDimitry Andric       return expr_result;
2309f034231aSEd Maste     }
2310f034231aSEd Maste 
2311f3fbd1c0SDimitry Andric     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2312f034231aSEd Maste     ExecutionContext exe_ctx(m_opaque_sp.get());
2313f034231aSEd Maste 
2314f034231aSEd Maste     frame = exe_ctx.GetFramePtr();
2315f034231aSEd Maste     Target *target = exe_ctx.GetTargetPtr();
23167fa27ce4SDimitry Andric     Process *process = exe_ctx.GetProcessPtr();
2317f034231aSEd Maste 
231814f1b3e8SDimitry Andric     if (target) {
23197fa27ce4SDimitry Andric       // If we have a process, make sure to lock the runlock:
23207fa27ce4SDimitry Andric       if (process) {
23217fa27ce4SDimitry Andric         Process::StopLocker stop_locker;
23227fa27ce4SDimitry Andric         if (stop_locker.TryLock(&process->GetRunLock())) {
232314f1b3e8SDimitry Andric           target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
23247fa27ce4SDimitry Andric         } else {
23257fa27ce4SDimitry Andric           Status error;
23267fa27ce4SDimitry Andric           error.SetErrorString("can't evaluate expressions when the "
23277fa27ce4SDimitry Andric                                "process is running.");
23287fa27ce4SDimitry Andric           expr_value_sp = ValueObjectConstResult::Create(nullptr, error);
23297fa27ce4SDimitry Andric         }
23307fa27ce4SDimitry Andric       } else {
23317fa27ce4SDimitry Andric         target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
23327fa27ce4SDimitry Andric       }
2333f034231aSEd Maste 
2334f034231aSEd Maste       expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2335f034231aSEd Maste     }
2336f034231aSEd Maste   }
2337ead24645SDimitry Andric   LLDB_LOGF(expr_log,
2338ead24645SDimitry Andric             "** [SBTarget::EvaluateExpression] Expression result is "
233914f1b3e8SDimitry Andric             "%s, summary %s **",
23400cac4ca3SEd Maste             expr_result.GetValue(), expr_result.GetSummary());
23416f8fc217SDimitry Andric   return expr_result;
2342f034231aSEd Maste }
2343f034231aSEd Maste 
GetStackRedZoneSize()234414f1b3e8SDimitry Andric lldb::addr_t SBTarget::GetStackRedZoneSize() {
23456f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
23465f29bb8aSDimitry Andric 
2347f034231aSEd Maste   TargetSP target_sp(GetSP());
234814f1b3e8SDimitry Andric   if (target_sp) {
2349f034231aSEd Maste     ABISP abi_sp;
2350f034231aSEd Maste     ProcessSP process_sp(target_sp->GetProcessSP());
2351f034231aSEd Maste     if (process_sp)
2352f034231aSEd Maste       abi_sp = process_sp->GetABI();
2353f034231aSEd Maste     else
23541b306c26SDimitry Andric       abi_sp = ABI::FindPlugin(ProcessSP(), target_sp->GetArchitecture());
2355f034231aSEd Maste     if (abi_sp)
2356f034231aSEd Maste       return abi_sp->GetRedZoneSize();
2357f034231aSEd Maste   }
2358f034231aSEd Maste   return 0;
2359f034231aSEd Maste }
2360f034231aSEd Maste 
IsLoaded(const SBModule & module) const2361344a3780SDimitry Andric bool SBTarget::IsLoaded(const SBModule &module) const {
23626f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, module);
2363344a3780SDimitry Andric 
2364344a3780SDimitry Andric   TargetSP target_sp(GetSP());
2365344a3780SDimitry Andric   if (!target_sp)
2366344a3780SDimitry Andric     return false;
2367344a3780SDimitry Andric 
2368344a3780SDimitry Andric   ModuleSP module_sp(module.GetSP());
2369344a3780SDimitry Andric   if (!module_sp)
2370344a3780SDimitry Andric     return false;
2371344a3780SDimitry Andric 
2372344a3780SDimitry Andric   return module_sp->IsLoadedInTarget(target_sp.get());
2373344a3780SDimitry Andric }
2374344a3780SDimitry Andric 
GetLaunchInfo() const237514f1b3e8SDimitry Andric lldb::SBLaunchInfo SBTarget::GetLaunchInfo() const {
23766f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
23775f29bb8aSDimitry Andric 
23785f29bb8aSDimitry Andric   lldb::SBLaunchInfo launch_info(nullptr);
23795e95aa85SEd Maste   TargetSP target_sp(GetSP());
23805e95aa85SEd Maste   if (target_sp)
2381f73363f1SDimitry Andric     launch_info.set_ref(m_opaque_sp->GetProcessLaunchInfo());
23826f8fc217SDimitry Andric   return launch_info;
23835e95aa85SEd Maste }
23845e95aa85SEd Maste 
SetLaunchInfo(const lldb::SBLaunchInfo & launch_info)238514f1b3e8SDimitry Andric void SBTarget::SetLaunchInfo(const lldb::SBLaunchInfo &launch_info) {
23866f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, launch_info);
23875f29bb8aSDimitry Andric 
23885e95aa85SEd Maste   TargetSP target_sp(GetSP());
23895e95aa85SEd Maste   if (target_sp)
23905e95aa85SEd Maste     m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
23915e95aa85SEd Maste }
23925f29bb8aSDimitry Andric 
GetEnvironment()2393cfca06d7SDimitry Andric SBEnvironment SBTarget::GetEnvironment() {
23946f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
2395cfca06d7SDimitry Andric   TargetSP target_sp(GetSP());
2396cfca06d7SDimitry Andric 
2397cfca06d7SDimitry Andric   if (target_sp) {
23986f8fc217SDimitry Andric     return SBEnvironment(target_sp->GetEnvironment());
2399cfca06d7SDimitry Andric   }
2400cfca06d7SDimitry Andric 
24016f8fc217SDimitry Andric   return SBEnvironment();
2402cfca06d7SDimitry Andric }
2403cfca06d7SDimitry Andric 
GetTrace()2404344a3780SDimitry Andric lldb::SBTrace SBTarget::GetTrace() {
24056f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this);
2406344a3780SDimitry Andric   TargetSP target_sp(GetSP());
2407344a3780SDimitry Andric 
2408344a3780SDimitry Andric   if (target_sp)
24096f8fc217SDimitry Andric     return SBTrace(target_sp->GetTrace());
2410344a3780SDimitry Andric 
24116f8fc217SDimitry Andric   return SBTrace();
2412344a3780SDimitry Andric }
2413344a3780SDimitry Andric 
CreateTrace(lldb::SBError & error)2414344a3780SDimitry Andric lldb::SBTrace SBTarget::CreateTrace(lldb::SBError &error) {
24156f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(this, error);
2416344a3780SDimitry Andric   TargetSP target_sp(GetSP());
2417344a3780SDimitry Andric   error.Clear();
2418344a3780SDimitry Andric 
2419344a3780SDimitry Andric   if (target_sp) {
2420344a3780SDimitry Andric     if (llvm::Expected<lldb::TraceSP> trace_sp = target_sp->CreateTrace()) {
24216f8fc217SDimitry Andric       return SBTrace(*trace_sp);
2422344a3780SDimitry Andric     } else {
2423344a3780SDimitry Andric       error.SetErrorString(llvm::toString(trace_sp.takeError()).c_str());
2424344a3780SDimitry Andric     }
2425344a3780SDimitry Andric   } else {
2426344a3780SDimitry Andric     error.SetErrorString("missing target");
2427344a3780SDimitry Andric   }
24286f8fc217SDimitry Andric   return SBTrace();
24295f29bb8aSDimitry Andric }
2430