1 //===-- SBTarget.cpp ------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "lldb/API/SBTarget.h"
10 #include "SBReproducerPrivate.h"
11 
12 #include "lldb/lldb-public.h"
13 
14 #include "lldb/API/SBBreakpoint.h"
15 #include "lldb/API/SBDebugger.h"
16 #include "lldb/API/SBEnvironment.h"
17 #include "lldb/API/SBEvent.h"
18 #include "lldb/API/SBExpressionOptions.h"
19 #include "lldb/API/SBFileSpec.h"
20 #include "lldb/API/SBListener.h"
21 #include "lldb/API/SBModule.h"
22 #include "lldb/API/SBModuleSpec.h"
23 #include "lldb/API/SBProcess.h"
24 #include "lldb/API/SBSourceManager.h"
25 #include "lldb/API/SBStream.h"
26 #include "lldb/API/SBStringList.h"
27 #include "lldb/API/SBStructuredData.h"
28 #include "lldb/API/SBSymbolContextList.h"
29 #include "lldb/Breakpoint/BreakpointID.h"
30 #include "lldb/Breakpoint/BreakpointIDList.h"
31 #include "lldb/Breakpoint/BreakpointList.h"
32 #include "lldb/Breakpoint/BreakpointLocation.h"
33 #include "lldb/Core/Address.h"
34 #include "lldb/Core/AddressResolver.h"
35 #include "lldb/Core/AddressResolverName.h"
36 #include "lldb/Core/Debugger.h"
37 #include "lldb/Core/Disassembler.h"
38 #include "lldb/Core/Module.h"
39 #include "lldb/Core/ModuleSpec.h"
40 #include "lldb/Core/SearchFilter.h"
41 #include "lldb/Core/Section.h"
42 #include "lldb/Core/StructuredDataImpl.h"
43 #include "lldb/Core/ValueObjectConstResult.h"
44 #include "lldb/Core/ValueObjectList.h"
45 #include "lldb/Core/ValueObjectVariable.h"
46 #include "lldb/Host/Host.h"
47 #include "lldb/Symbol/DeclVendor.h"
48 #include "lldb/Symbol/ObjectFile.h"
49 #include "lldb/Symbol/SymbolFile.h"
50 #include "lldb/Symbol/SymbolVendor.h"
51 #include "lldb/Symbol/TypeSystem.h"
52 #include "lldb/Symbol/VariableList.h"
53 #include "lldb/Target/ABI.h"
54 #include "lldb/Target/Language.h"
55 #include "lldb/Target/LanguageRuntime.h"
56 #include "lldb/Target/Process.h"
57 #include "lldb/Target/StackFrame.h"
58 #include "lldb/Target/Target.h"
59 #include "lldb/Target/TargetList.h"
60 #include "lldb/Utility/ArchSpec.h"
61 #include "lldb/Utility/Args.h"
62 #include "lldb/Utility/FileSpec.h"
63 #include "lldb/Utility/ProcessInfo.h"
64 #include "lldb/Utility/RegularExpression.h"
65 
66 #include "Commands/CommandObjectBreakpoint.h"
67 #include "lldb/Interpreter/CommandReturnObject.h"
68 #include "llvm/Support/PrettyStackTrace.h"
69 #include "llvm/Support/Regex.h"
70 
71 using namespace lldb;
72 using namespace lldb_private;
73 
74 #define DEFAULT_DISASM_BYTE_SIZE 32
75 
76 namespace {
77 
AttachToProcess(ProcessAttachInfo & attach_info,Target & target)78 Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target) {
79   std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
80 
81   auto process_sp = target.GetProcessSP();
82   if (process_sp) {
83     const auto state = process_sp->GetState();
84     if (process_sp->IsAlive() && state == eStateConnected) {
85       // If we are already connected, then we have already specified the
86       // listener, so if a valid listener is supplied, we need to error out to
87       // let the client know.
88       if (attach_info.GetListener())
89         return Status("process is connected and already has a listener, pass "
90                       "empty listener");
91     }
92   }
93 
94   return target.Attach(attach_info, nullptr);
95 }
96 
97 } // namespace
98 
99 // SBTarget constructor
SBTarget()100 SBTarget::SBTarget() : m_opaque_sp() {
101   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTarget);
102 }
103 
SBTarget(const SBTarget & rhs)104 SBTarget::SBTarget(const SBTarget &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
105   LLDB_RECORD_CONSTRUCTOR(SBTarget, (const lldb::SBTarget &), rhs);
106 }
107 
SBTarget(const TargetSP & target_sp)108 SBTarget::SBTarget(const TargetSP &target_sp) : m_opaque_sp(target_sp) {
109   LLDB_RECORD_CONSTRUCTOR(SBTarget, (const lldb::TargetSP &), target_sp);
110 }
111 
operator =(const SBTarget & rhs)112 const SBTarget &SBTarget::operator=(const SBTarget &rhs) {
113   LLDB_RECORD_METHOD(const lldb::SBTarget &,
114                      SBTarget, operator=,(const lldb::SBTarget &), rhs);
115 
116   if (this != &rhs)
117     m_opaque_sp = rhs.m_opaque_sp;
118   return LLDB_RECORD_RESULT(*this);
119 }
120 
121 // Destructor
122 SBTarget::~SBTarget() = default;
123 
EventIsTargetEvent(const SBEvent & event)124 bool SBTarget::EventIsTargetEvent(const SBEvent &event) {
125   LLDB_RECORD_STATIC_METHOD(bool, SBTarget, EventIsTargetEvent,
126                             (const lldb::SBEvent &), event);
127 
128   return Target::TargetEventData::GetEventDataFromEvent(event.get()) != nullptr;
129 }
130 
GetTargetFromEvent(const SBEvent & event)131 SBTarget SBTarget::GetTargetFromEvent(const SBEvent &event) {
132   LLDB_RECORD_STATIC_METHOD(lldb::SBTarget, SBTarget, GetTargetFromEvent,
133                             (const lldb::SBEvent &), event);
134 
135   return LLDB_RECORD_RESULT(
136       Target::TargetEventData::GetTargetFromEvent(event.get()));
137 }
138 
GetNumModulesFromEvent(const SBEvent & event)139 uint32_t SBTarget::GetNumModulesFromEvent(const SBEvent &event) {
140   LLDB_RECORD_STATIC_METHOD(uint32_t, SBTarget, GetNumModulesFromEvent,
141                             (const lldb::SBEvent &), event);
142 
143   const ModuleList module_list =
144       Target::TargetEventData::GetModuleListFromEvent(event.get());
145   return module_list.GetSize();
146 }
147 
GetModuleAtIndexFromEvent(const uint32_t idx,const SBEvent & event)148 SBModule SBTarget::GetModuleAtIndexFromEvent(const uint32_t idx,
149                                              const SBEvent &event) {
150   LLDB_RECORD_STATIC_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndexFromEvent,
151                             (const uint32_t, const lldb::SBEvent &), idx,
152                             event);
153 
154   const ModuleList module_list =
155       Target::TargetEventData::GetModuleListFromEvent(event.get());
156   return LLDB_RECORD_RESULT(SBModule(module_list.GetModuleAtIndex(idx)));
157 }
158 
GetBroadcasterClassName()159 const char *SBTarget::GetBroadcasterClassName() {
160   LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBTarget,
161                                     GetBroadcasterClassName);
162 
163   return Target::GetStaticBroadcasterClass().AsCString();
164 }
165 
IsValid() const166 bool SBTarget::IsValid() const {
167   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTarget, IsValid);
168   return this->operator bool();
169 }
operator bool() const170 SBTarget::operator bool() const {
171   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTarget, operator bool);
172 
173   return m_opaque_sp.get() != nullptr && m_opaque_sp->IsValid();
174 }
175 
GetProcess()176 SBProcess SBTarget::GetProcess() {
177   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBProcess, SBTarget, GetProcess);
178 
179   SBProcess sb_process;
180   ProcessSP process_sp;
181   TargetSP target_sp(GetSP());
182   if (target_sp) {
183     process_sp = target_sp->GetProcessSP();
184     sb_process.SetSP(process_sp);
185   }
186 
187   return LLDB_RECORD_RESULT(sb_process);
188 }
189 
GetPlatform()190 SBPlatform SBTarget::GetPlatform() {
191   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBPlatform, SBTarget, GetPlatform);
192 
193   TargetSP target_sp(GetSP());
194   if (!target_sp)
195     return LLDB_RECORD_RESULT(SBPlatform());
196 
197   SBPlatform platform;
198   platform.m_opaque_sp = target_sp->GetPlatform();
199 
200   return LLDB_RECORD_RESULT(platform);
201 }
202 
GetDebugger() const203 SBDebugger SBTarget::GetDebugger() const {
204   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBDebugger, SBTarget, GetDebugger);
205 
206   SBDebugger debugger;
207   TargetSP target_sp(GetSP());
208   if (target_sp)
209     debugger.reset(target_sp->GetDebugger().shared_from_this());
210   return LLDB_RECORD_RESULT(debugger);
211 }
212 
GetStatistics()213 SBStructuredData SBTarget::GetStatistics() {
214   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBStructuredData, SBTarget, GetStatistics);
215 
216   SBStructuredData data;
217   TargetSP target_sp(GetSP());
218   if (!target_sp)
219     return LLDB_RECORD_RESULT(data);
220 
221   auto stats_up = std::make_unique<StructuredData::Dictionary>();
222   int i = 0;
223   for (auto &Entry : target_sp->GetStatistics()) {
224     std::string Desc = lldb_private::GetStatDescription(
225         static_cast<lldb_private::StatisticKind>(i));
226     stats_up->AddIntegerItem(Desc, Entry);
227     i += 1;
228   }
229 
230   data.m_impl_up->SetObjectSP(std::move(stats_up));
231   return LLDB_RECORD_RESULT(data);
232 }
233 
SetCollectingStats(bool v)234 void SBTarget::SetCollectingStats(bool v) {
235   LLDB_RECORD_METHOD(void, SBTarget, SetCollectingStats, (bool), v);
236 
237   TargetSP target_sp(GetSP());
238   if (!target_sp)
239     return;
240   return target_sp->SetCollectingStats(v);
241 }
242 
GetCollectingStats()243 bool SBTarget::GetCollectingStats() {
244   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, GetCollectingStats);
245 
246   TargetSP target_sp(GetSP());
247   if (!target_sp)
248     return false;
249   return target_sp->GetCollectingStats();
250 }
251 
LoadCore(const char * core_file)252 SBProcess SBTarget::LoadCore(const char *core_file) {
253   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, LoadCore, (const char *),
254                      core_file);
255 
256   lldb::SBError error; // Ignored
257   return LLDB_RECORD_RESULT(LoadCore(core_file, error));
258 }
259 
LoadCore(const char * core_file,lldb::SBError & error)260 SBProcess SBTarget::LoadCore(const char *core_file, lldb::SBError &error) {
261   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, LoadCore,
262                      (const char *, lldb::SBError &), core_file, error);
263 
264   SBProcess sb_process;
265   TargetSP target_sp(GetSP());
266   if (target_sp) {
267     FileSpec filespec(core_file);
268     FileSystem::Instance().Resolve(filespec);
269     ProcessSP process_sp(target_sp->CreateProcess(
270         target_sp->GetDebugger().GetListener(), "", &filespec, false));
271     if (process_sp) {
272       error.SetError(process_sp->LoadCore());
273       if (error.Success())
274         sb_process.SetSP(process_sp);
275     } else {
276       error.SetErrorString("Failed to create the process");
277     }
278   } else {
279     error.SetErrorString("SBTarget is invalid");
280   }
281   return LLDB_RECORD_RESULT(sb_process);
282 }
283 
LaunchSimple(char const ** argv,char const ** envp,const char * working_directory)284 SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp,
285                                  const char *working_directory) {
286   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, LaunchSimple,
287                      (const char **, const char **, const char *), argv, envp,
288                      working_directory);
289 
290   TargetSP target_sp = GetSP();
291   if (!target_sp)
292     return LLDB_RECORD_RESULT(SBProcess());
293 
294   SBLaunchInfo launch_info = GetLaunchInfo();
295 
296   if (Module *exe_module = target_sp->GetExecutableModulePointer())
297     launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(),
298                                   /*add_as_first_arg*/ true);
299   if (argv)
300     launch_info.SetArguments(argv, /*append*/ true);
301   if (envp)
302     launch_info.SetEnvironmentEntries(envp, /*append*/ false);
303   if (working_directory)
304     launch_info.SetWorkingDirectory(working_directory);
305 
306   SBError error;
307   return LLDB_RECORD_RESULT(Launch(launch_info, error));
308 }
309 
Install()310 SBError SBTarget::Install() {
311   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBError, SBTarget, Install);
312 
313   SBError sb_error;
314   TargetSP target_sp(GetSP());
315   if (target_sp) {
316     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
317     sb_error.ref() = target_sp->Install(nullptr);
318   }
319   return LLDB_RECORD_RESULT(sb_error);
320 }
321 
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)322 SBProcess SBTarget::Launch(SBListener &listener, char const **argv,
323                            char const **envp, const char *stdin_path,
324                            const char *stdout_path, const char *stderr_path,
325                            const char *working_directory,
326                            uint32_t launch_flags, // See LaunchFlags
327                            bool stop_at_entry, lldb::SBError &error) {
328   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, Launch,
329                      (lldb::SBListener &, const char **, const char **,
330                       const char *, const char *, const char *, const char *,
331                       uint32_t, bool, lldb::SBError &),
332                      listener, argv, envp, stdin_path, stdout_path, stderr_path,
333                      working_directory, launch_flags, stop_at_entry, error);
334 
335   SBProcess sb_process;
336   ProcessSP process_sp;
337   TargetSP target_sp(GetSP());
338 
339   if (target_sp) {
340     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
341 
342     if (stop_at_entry)
343       launch_flags |= eLaunchFlagStopAtEntry;
344 
345     if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR"))
346       launch_flags |= eLaunchFlagDisableASLR;
347 
348     StateType state = eStateInvalid;
349     process_sp = target_sp->GetProcessSP();
350     if (process_sp) {
351       state = process_sp->GetState();
352 
353       if (process_sp->IsAlive() && state != eStateConnected) {
354         if (state == eStateAttaching)
355           error.SetErrorString("process attach is in progress");
356         else
357           error.SetErrorString("a process is already being debugged");
358         return LLDB_RECORD_RESULT(sb_process);
359       }
360     }
361 
362     if (state == eStateConnected) {
363       // If we are already connected, then we have already specified the
364       // listener, so if a valid listener is supplied, we need to error out to
365       // let the client know.
366       if (listener.IsValid()) {
367         error.SetErrorString("process is connected and already has a listener, "
368                              "pass empty listener");
369         return LLDB_RECORD_RESULT(sb_process);
370       }
371     }
372 
373     if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO"))
374       launch_flags |= eLaunchFlagDisableSTDIO;
375 
376     ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
377                                   FileSpec(stderr_path),
378                                   FileSpec(working_directory), launch_flags);
379 
380     Module *exe_module = target_sp->GetExecutableModulePointer();
381     if (exe_module)
382       launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
383     if (argv) {
384       launch_info.GetArguments().AppendArguments(argv);
385     } else {
386       auto default_launch_info = target_sp->GetProcessLaunchInfo();
387       launch_info.GetArguments().AppendArguments(
388           default_launch_info.GetArguments());
389     }
390     if (envp) {
391       launch_info.GetEnvironment() = Environment(envp);
392     } else {
393       auto default_launch_info = target_sp->GetProcessLaunchInfo();
394       launch_info.GetEnvironment() = default_launch_info.GetEnvironment();
395     }
396 
397     if (listener.IsValid())
398       launch_info.SetListener(listener.GetSP());
399 
400     error.SetError(target_sp->Launch(launch_info, nullptr));
401 
402     sb_process.SetSP(target_sp->GetProcessSP());
403   } else {
404     error.SetErrorString("SBTarget is invalid");
405   }
406 
407   return LLDB_RECORD_RESULT(sb_process);
408 }
409 
Launch(SBLaunchInfo & sb_launch_info,SBError & error)410 SBProcess SBTarget::Launch(SBLaunchInfo &sb_launch_info, SBError &error) {
411   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, Launch,
412                      (lldb::SBLaunchInfo &, lldb::SBError &), sb_launch_info,
413                      error);
414 
415 
416   SBProcess sb_process;
417   TargetSP target_sp(GetSP());
418 
419   if (target_sp) {
420     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
421     StateType state = eStateInvalid;
422     {
423       ProcessSP process_sp = target_sp->GetProcessSP();
424       if (process_sp) {
425         state = process_sp->GetState();
426 
427         if (process_sp->IsAlive() && state != eStateConnected) {
428           if (state == eStateAttaching)
429             error.SetErrorString("process attach is in progress");
430           else
431             error.SetErrorString("a process is already being debugged");
432           return LLDB_RECORD_RESULT(sb_process);
433         }
434       }
435     }
436 
437     lldb_private::ProcessLaunchInfo launch_info = sb_launch_info.ref();
438 
439     if (!launch_info.GetExecutableFile()) {
440       Module *exe_module = target_sp->GetExecutableModulePointer();
441       if (exe_module)
442         launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
443     }
444 
445     const ArchSpec &arch_spec = target_sp->GetArchitecture();
446     if (arch_spec.IsValid())
447       launch_info.GetArchitecture() = arch_spec;
448 
449     error.SetError(target_sp->Launch(launch_info, nullptr));
450     sb_launch_info.set_ref(launch_info);
451     sb_process.SetSP(target_sp->GetProcessSP());
452   } else {
453     error.SetErrorString("SBTarget is invalid");
454   }
455 
456   return LLDB_RECORD_RESULT(sb_process);
457 }
458 
Attach(SBAttachInfo & sb_attach_info,SBError & error)459 lldb::SBProcess SBTarget::Attach(SBAttachInfo &sb_attach_info, SBError &error) {
460   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, Attach,
461                      (lldb::SBAttachInfo &, lldb::SBError &), sb_attach_info,
462                      error);
463 
464   SBProcess sb_process;
465   TargetSP target_sp(GetSP());
466 
467   if (target_sp) {
468     ProcessAttachInfo &attach_info = sb_attach_info.ref();
469     if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid()) {
470       PlatformSP platform_sp = target_sp->GetPlatform();
471       // See if we can pre-verify if a process exists or not
472       if (platform_sp && platform_sp->IsConnected()) {
473         lldb::pid_t attach_pid = attach_info.GetProcessID();
474         ProcessInstanceInfo instance_info;
475         if (platform_sp->GetProcessInfo(attach_pid, instance_info)) {
476           attach_info.SetUserID(instance_info.GetEffectiveUserID());
477         } else {
478           error.ref().SetErrorStringWithFormat(
479               "no process found with process ID %" PRIu64, attach_pid);
480           return LLDB_RECORD_RESULT(sb_process);
481         }
482       }
483     }
484     error.SetError(AttachToProcess(attach_info, *target_sp));
485     if (error.Success())
486       sb_process.SetSP(target_sp->GetProcessSP());
487   } else {
488     error.SetErrorString("SBTarget is invalid");
489   }
490 
491   return LLDB_RECORD_RESULT(sb_process);
492 }
493 
AttachToProcessWithID(SBListener & listener,lldb::pid_t pid,SBError & error)494 lldb::SBProcess SBTarget::AttachToProcessWithID(
495     SBListener &listener,
496     lldb::pid_t pid, // The process ID to attach to
497     SBError &error   // An error explaining what went wrong if attach fails
498 ) {
499   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, AttachToProcessWithID,
500                      (lldb::SBListener &, lldb::pid_t, lldb::SBError &),
501                      listener, pid, error);
502 
503   SBProcess sb_process;
504   TargetSP target_sp(GetSP());
505 
506   if (target_sp) {
507     ProcessAttachInfo attach_info;
508     attach_info.SetProcessID(pid);
509     if (listener.IsValid())
510       attach_info.SetListener(listener.GetSP());
511 
512     ProcessInstanceInfo instance_info;
513     if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info))
514       attach_info.SetUserID(instance_info.GetEffectiveUserID());
515 
516     error.SetError(AttachToProcess(attach_info, *target_sp));
517     if (error.Success())
518       sb_process.SetSP(target_sp->GetProcessSP());
519   } else
520     error.SetErrorString("SBTarget is invalid");
521 
522   return LLDB_RECORD_RESULT(sb_process);
523 }
524 
AttachToProcessWithName(SBListener & listener,const char * name,bool wait_for,SBError & error)525 lldb::SBProcess SBTarget::AttachToProcessWithName(
526     SBListener &listener,
527     const char *name, // basename of process to attach to
528     bool wait_for, // if true wait for a new instance of "name" to be launched
529     SBError &error // An error explaining what went wrong if attach fails
530 ) {
531   LLDB_RECORD_METHOD(lldb::SBProcess, SBTarget, AttachToProcessWithName,
532                      (lldb::SBListener &, const char *, bool, lldb::SBError &),
533                      listener, name, wait_for, error);
534 
535   SBProcess sb_process;
536   TargetSP target_sp(GetSP());
537 
538   if (name && target_sp) {
539     ProcessAttachInfo attach_info;
540     attach_info.GetExecutableFile().SetFile(name, FileSpec::Style::native);
541     attach_info.SetWaitForLaunch(wait_for);
542     if (listener.IsValid())
543       attach_info.SetListener(listener.GetSP());
544 
545     error.SetError(AttachToProcess(attach_info, *target_sp));
546     if (error.Success())
547       sb_process.SetSP(target_sp->GetProcessSP());
548   } else
549     error.SetErrorString("SBTarget is invalid");
550 
551   return LLDB_RECORD_RESULT(sb_process);
552 }
553 
ConnectRemote(SBListener & listener,const char * url,const char * plugin_name,SBError & error)554 lldb::SBProcess SBTarget::ConnectRemote(SBListener &listener, const char *url,
555                                         const char *plugin_name,
556                                         SBError &error) {
557   LLDB_RECORD_METHOD(
558       lldb::SBProcess, SBTarget, ConnectRemote,
559       (lldb::SBListener &, const char *, const char *, lldb::SBError &),
560       listener, url, plugin_name, error);
561 
562   SBProcess sb_process;
563   ProcessSP process_sp;
564   TargetSP target_sp(GetSP());
565 
566   if (target_sp) {
567     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
568     if (listener.IsValid())
569       process_sp =
570           target_sp->CreateProcess(listener.m_opaque_sp, plugin_name, nullptr,
571                                    true);
572     else
573       process_sp = target_sp->CreateProcess(
574           target_sp->GetDebugger().GetListener(), plugin_name, nullptr, true);
575 
576     if (process_sp) {
577       sb_process.SetSP(process_sp);
578       error.SetError(process_sp->ConnectRemote(url));
579     } else {
580       error.SetErrorString("unable to create lldb_private::Process");
581     }
582   } else {
583     error.SetErrorString("SBTarget is invalid");
584   }
585 
586   return LLDB_RECORD_RESULT(sb_process);
587 }
588 
GetExecutable()589 SBFileSpec SBTarget::GetExecutable() {
590   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBTarget, GetExecutable);
591 
592   SBFileSpec exe_file_spec;
593   TargetSP target_sp(GetSP());
594   if (target_sp) {
595     Module *exe_module = target_sp->GetExecutableModulePointer();
596     if (exe_module)
597       exe_file_spec.SetFileSpec(exe_module->GetFileSpec());
598   }
599 
600   return LLDB_RECORD_RESULT(exe_file_spec);
601 }
602 
operator ==(const SBTarget & rhs) const603 bool SBTarget::operator==(const SBTarget &rhs) const {
604   LLDB_RECORD_METHOD_CONST(bool, SBTarget, operator==,(const lldb::SBTarget &),
605                            rhs);
606 
607   return m_opaque_sp.get() == rhs.m_opaque_sp.get();
608 }
609 
operator !=(const SBTarget & rhs) const610 bool SBTarget::operator!=(const SBTarget &rhs) const {
611   LLDB_RECORD_METHOD_CONST(bool, SBTarget, operator!=,(const lldb::SBTarget &),
612                            rhs);
613 
614   return m_opaque_sp.get() != rhs.m_opaque_sp.get();
615 }
616 
GetSP() const617 lldb::TargetSP SBTarget::GetSP() const { return m_opaque_sp; }
618 
SetSP(const lldb::TargetSP & target_sp)619 void SBTarget::SetSP(const lldb::TargetSP &target_sp) {
620   m_opaque_sp = target_sp;
621 }
622 
ResolveLoadAddress(lldb::addr_t vm_addr)623 lldb::SBAddress SBTarget::ResolveLoadAddress(lldb::addr_t vm_addr) {
624   LLDB_RECORD_METHOD(lldb::SBAddress, SBTarget, ResolveLoadAddress,
625                      (lldb::addr_t), vm_addr);
626 
627   lldb::SBAddress sb_addr;
628   Address &addr = sb_addr.ref();
629   TargetSP target_sp(GetSP());
630   if (target_sp) {
631     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
632     if (target_sp->ResolveLoadAddress(vm_addr, addr))
633       return LLDB_RECORD_RESULT(sb_addr);
634   }
635 
636   // We have a load address that isn't in a section, just return an address
637   // with the offset filled in (the address) and the section set to NULL
638   addr.SetRawAddress(vm_addr);
639   return LLDB_RECORD_RESULT(sb_addr);
640 }
641 
ResolveFileAddress(lldb::addr_t file_addr)642 lldb::SBAddress SBTarget::ResolveFileAddress(lldb::addr_t file_addr) {
643   LLDB_RECORD_METHOD(lldb::SBAddress, SBTarget, ResolveFileAddress,
644                      (lldb::addr_t), file_addr);
645 
646   lldb::SBAddress sb_addr;
647   Address &addr = sb_addr.ref();
648   TargetSP target_sp(GetSP());
649   if (target_sp) {
650     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
651     if (target_sp->ResolveFileAddress(file_addr, addr))
652       return LLDB_RECORD_RESULT(sb_addr);
653   }
654 
655   addr.SetRawAddress(file_addr);
656   return LLDB_RECORD_RESULT(sb_addr);
657 }
658 
ResolvePastLoadAddress(uint32_t stop_id,lldb::addr_t vm_addr)659 lldb::SBAddress SBTarget::ResolvePastLoadAddress(uint32_t stop_id,
660                                                  lldb::addr_t vm_addr) {
661   LLDB_RECORD_METHOD(lldb::SBAddress, SBTarget, ResolvePastLoadAddress,
662                      (uint32_t, lldb::addr_t), stop_id, vm_addr);
663 
664   lldb::SBAddress sb_addr;
665   Address &addr = sb_addr.ref();
666   TargetSP target_sp(GetSP());
667   if (target_sp) {
668     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
669     if (target_sp->ResolveLoadAddress(vm_addr, addr))
670       return LLDB_RECORD_RESULT(sb_addr);
671   }
672 
673   // We have a load address that isn't in a section, just return an address
674   // with the offset filled in (the address) and the section set to NULL
675   addr.SetRawAddress(vm_addr);
676   return LLDB_RECORD_RESULT(sb_addr);
677 }
678 
679 SBSymbolContext
ResolveSymbolContextForAddress(const SBAddress & addr,uint32_t resolve_scope)680 SBTarget::ResolveSymbolContextForAddress(const SBAddress &addr,
681                                          uint32_t resolve_scope) {
682   LLDB_RECORD_METHOD(lldb::SBSymbolContext, SBTarget,
683                      ResolveSymbolContextForAddress,
684                      (const lldb::SBAddress &, uint32_t), addr, resolve_scope);
685 
686   SBSymbolContext sc;
687   SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
688   if (addr.IsValid()) {
689     TargetSP target_sp(GetSP());
690     if (target_sp)
691       target_sp->GetImages().ResolveSymbolContextForAddress(addr.ref(), scope,
692                                                             sc.ref());
693   }
694   return LLDB_RECORD_RESULT(sc);
695 }
696 
ReadMemory(const SBAddress addr,void * buf,size_t size,lldb::SBError & error)697 size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size,
698                             lldb::SBError &error) {
699   LLDB_RECORD_METHOD(size_t, SBTarget, ReadMemory,
700                      (const lldb::SBAddress, void *, size_t, lldb::SBError &),
701                      addr, buf, size, error);
702 
703   SBError sb_error;
704   size_t bytes_read = 0;
705   TargetSP target_sp(GetSP());
706   if (target_sp) {
707     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
708     bytes_read =
709         target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref());
710   } else {
711     sb_error.SetErrorString("invalid target");
712   }
713 
714   return bytes_read;
715 }
716 
BreakpointCreateByLocation(const char * file,uint32_t line)717 SBBreakpoint SBTarget::BreakpointCreateByLocation(const char *file,
718                                                   uint32_t line) {
719   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
720                      (const char *, uint32_t), file, line);
721 
722   return LLDB_RECORD_RESULT(
723       SBBreakpoint(BreakpointCreateByLocation(SBFileSpec(file, false), line)));
724 }
725 
726 SBBreakpoint
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line)727 SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
728                                      uint32_t line) {
729   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
730                      (const lldb::SBFileSpec &, uint32_t), sb_file_spec, line);
731 
732   return LLDB_RECORD_RESULT(BreakpointCreateByLocation(sb_file_spec, line, 0));
733 }
734 
735 SBBreakpoint
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,lldb::addr_t offset)736 SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
737                                      uint32_t line, lldb::addr_t offset) {
738   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
739                      (const lldb::SBFileSpec &, uint32_t, lldb::addr_t),
740                      sb_file_spec, line, offset);
741 
742   SBFileSpecList empty_list;
743   return LLDB_RECORD_RESULT(
744       BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list));
745 }
746 
747 SBBreakpoint
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,lldb::addr_t offset,SBFileSpecList & sb_module_list)748 SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec,
749                                      uint32_t line, lldb::addr_t offset,
750                                      SBFileSpecList &sb_module_list) {
751   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
752                      (const lldb::SBFileSpec &, uint32_t, lldb::addr_t,
753                       lldb::SBFileSpecList &),
754                      sb_file_spec, line, offset, sb_module_list);
755 
756   return LLDB_RECORD_RESULT(BreakpointCreateByLocation(sb_file_spec, line, 0,
757                                                        offset, sb_module_list));
758 }
759 
BreakpointCreateByLocation(const SBFileSpec & sb_file_spec,uint32_t line,uint32_t column,lldb::addr_t offset,SBFileSpecList & sb_module_list)760 SBBreakpoint SBTarget::BreakpointCreateByLocation(
761     const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
762     lldb::addr_t offset, SBFileSpecList &sb_module_list) {
763   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
764                      (const lldb::SBFileSpec &, uint32_t, uint32_t,
765                       lldb::addr_t, lldb::SBFileSpecList &),
766                      sb_file_spec, line, column, offset, sb_module_list);
767 
768   SBBreakpoint sb_bp;
769   TargetSP target_sp(GetSP());
770   if (target_sp && line != 0) {
771     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
772 
773     const LazyBool check_inlines = eLazyBoolCalculate;
774     const LazyBool skip_prologue = eLazyBoolCalculate;
775     const bool internal = false;
776     const bool hardware = false;
777     const LazyBool move_to_nearest_code = eLazyBoolCalculate;
778     const FileSpecList *module_list = nullptr;
779     if (sb_module_list.GetSize() > 0) {
780       module_list = sb_module_list.get();
781     }
782     sb_bp = target_sp->CreateBreakpoint(
783         module_list, *sb_file_spec, line, column, offset, check_inlines,
784         skip_prologue, internal, hardware, move_to_nearest_code);
785   }
786 
787   return LLDB_RECORD_RESULT(sb_bp);
788 }
789 
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)790 SBBreakpoint SBTarget::BreakpointCreateByLocation(
791     const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column,
792     lldb::addr_t offset, SBFileSpecList &sb_module_list,
793     bool move_to_nearest_code) {
794   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
795                      (const lldb::SBFileSpec &, uint32_t, uint32_t,
796                       lldb::addr_t, lldb::SBFileSpecList &, bool),
797                      sb_file_spec, line, column, offset, sb_module_list,
798                      move_to_nearest_code);
799 
800   SBBreakpoint sb_bp;
801   TargetSP target_sp(GetSP());
802   if (target_sp && line != 0) {
803     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
804 
805     const LazyBool check_inlines = eLazyBoolCalculate;
806     const LazyBool skip_prologue = eLazyBoolCalculate;
807     const bool internal = false;
808     const bool hardware = false;
809     const FileSpecList *module_list = nullptr;
810     if (sb_module_list.GetSize() > 0) {
811       module_list = sb_module_list.get();
812     }
813     sb_bp = target_sp->CreateBreakpoint(
814         module_list, *sb_file_spec, line, column, offset, check_inlines,
815         skip_prologue, internal, hardware,
816         move_to_nearest_code ? eLazyBoolYes : eLazyBoolNo);
817   }
818 
819   return LLDB_RECORD_RESULT(sb_bp);
820 }
821 
BreakpointCreateByName(const char * symbol_name,const char * module_name)822 SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name,
823                                               const char *module_name) {
824   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
825                      (const char *, const char *), symbol_name, module_name);
826 
827   SBBreakpoint sb_bp;
828   TargetSP target_sp(GetSP());
829   if (target_sp.get()) {
830     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
831 
832     const bool internal = false;
833     const bool hardware = false;
834     const LazyBool skip_prologue = eLazyBoolCalculate;
835     const lldb::addr_t offset = 0;
836     if (module_name && module_name[0]) {
837       FileSpecList module_spec_list;
838       module_spec_list.Append(FileSpec(module_name));
839       sb_bp = target_sp->CreateBreakpoint(
840           &module_spec_list, nullptr, symbol_name, eFunctionNameTypeAuto,
841           eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
842     } else {
843       sb_bp = target_sp->CreateBreakpoint(
844           nullptr, nullptr, symbol_name, eFunctionNameTypeAuto,
845           eLanguageTypeUnknown, offset, skip_prologue, internal, hardware);
846     }
847   }
848 
849   return LLDB_RECORD_RESULT(sb_bp);
850 }
851 
852 lldb::SBBreakpoint
BreakpointCreateByName(const char * symbol_name,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)853 SBTarget::BreakpointCreateByName(const char *symbol_name,
854                                  const SBFileSpecList &module_list,
855                                  const SBFileSpecList &comp_unit_list) {
856   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
857                      (const char *, const lldb::SBFileSpecList &,
858                       const lldb::SBFileSpecList &),
859                      symbol_name, module_list, comp_unit_list);
860 
861   lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto;
862   return LLDB_RECORD_RESULT(
863       BreakpointCreateByName(symbol_name, name_type_mask, eLanguageTypeUnknown,
864                              module_list, comp_unit_list));
865 }
866 
BreakpointCreateByName(const char * symbol_name,uint32_t name_type_mask,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)867 lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
868     const char *symbol_name, uint32_t name_type_mask,
869     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
870   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
871                      (const char *, uint32_t, const lldb::SBFileSpecList &,
872                       const lldb::SBFileSpecList &),
873                      symbol_name, name_type_mask, module_list, comp_unit_list);
874 
875   return LLDB_RECORD_RESULT(
876       BreakpointCreateByName(symbol_name, name_type_mask, eLanguageTypeUnknown,
877                              module_list, comp_unit_list));
878 }
879 
BreakpointCreateByName(const char * symbol_name,uint32_t name_type_mask,LanguageType symbol_language,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)880 lldb::SBBreakpoint SBTarget::BreakpointCreateByName(
881     const char *symbol_name, uint32_t name_type_mask,
882     LanguageType symbol_language, const SBFileSpecList &module_list,
883     const SBFileSpecList &comp_unit_list) {
884   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
885                      (const char *, uint32_t, lldb::LanguageType,
886                       const lldb::SBFileSpecList &,
887                       const lldb::SBFileSpecList &),
888                      symbol_name, name_type_mask, symbol_language, module_list,
889                      comp_unit_list);
890 
891   SBBreakpoint sb_bp;
892   TargetSP target_sp(GetSP());
893   if (target_sp && symbol_name && symbol_name[0]) {
894     const bool internal = false;
895     const bool hardware = false;
896     const LazyBool skip_prologue = eLazyBoolCalculate;
897     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
898     FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
899     sb_bp = target_sp->CreateBreakpoint(module_list.get(), comp_unit_list.get(),
900                                         symbol_name, mask, symbol_language, 0,
901                                         skip_prologue, internal, hardware);
902   }
903 
904   return LLDB_RECORD_RESULT(sb_bp);
905 }
906 
BreakpointCreateByNames(const char * symbol_names[],uint32_t num_names,uint32_t name_type_mask,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)907 lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
908     const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
909     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
910   LLDB_RECORD_METHOD(
911       lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
912       (const char **, uint32_t, uint32_t, const lldb::SBFileSpecList &,
913        const lldb::SBFileSpecList &),
914       symbol_names, num_names, name_type_mask, module_list, comp_unit_list);
915 
916   return LLDB_RECORD_RESULT(BreakpointCreateByNames(
917       symbol_names, num_names, name_type_mask, eLanguageTypeUnknown,
918       module_list, comp_unit_list));
919 }
920 
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)921 lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
922     const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
923     LanguageType symbol_language, const SBFileSpecList &module_list,
924     const SBFileSpecList &comp_unit_list) {
925   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
926                      (const char **, uint32_t, uint32_t, lldb::LanguageType,
927                       const lldb::SBFileSpecList &,
928                       const lldb::SBFileSpecList &),
929                      symbol_names, num_names, name_type_mask, symbol_language,
930                      module_list, comp_unit_list);
931 
932   return LLDB_RECORD_RESULT(BreakpointCreateByNames(
933       symbol_names, num_names, name_type_mask, eLanguageTypeUnknown, 0,
934       module_list, comp_unit_list));
935 }
936 
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)937 lldb::SBBreakpoint SBTarget::BreakpointCreateByNames(
938     const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask,
939     LanguageType symbol_language, lldb::addr_t offset,
940     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
941   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
942                      (const char **, uint32_t, uint32_t, lldb::LanguageType,
943                       lldb::addr_t, const lldb::SBFileSpecList &,
944                       const lldb::SBFileSpecList &),
945                      symbol_names, num_names, name_type_mask, symbol_language,
946                      offset, module_list, comp_unit_list);
947 
948   SBBreakpoint sb_bp;
949   TargetSP target_sp(GetSP());
950   if (target_sp && num_names > 0) {
951     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
952     const bool internal = false;
953     const bool hardware = false;
954     FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
955     const LazyBool skip_prologue = eLazyBoolCalculate;
956     sb_bp = target_sp->CreateBreakpoint(
957         module_list.get(), comp_unit_list.get(), symbol_names, num_names, mask,
958         symbol_language, offset, skip_prologue, internal, hardware);
959   }
960 
961   return LLDB_RECORD_RESULT(sb_bp);
962 }
963 
BreakpointCreateByRegex(const char * symbol_name_regex,const char * module_name)964 SBBreakpoint SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
965                                                const char *module_name) {
966   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
967                      (const char *, const char *), symbol_name_regex,
968                      module_name);
969 
970   SBFileSpecList module_spec_list;
971   SBFileSpecList comp_unit_list;
972   if (module_name && module_name[0]) {
973     module_spec_list.Append(FileSpec(module_name));
974   }
975   return LLDB_RECORD_RESULT(
976       BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown,
977                               module_spec_list, comp_unit_list));
978 }
979 
980 lldb::SBBreakpoint
BreakpointCreateByRegex(const char * symbol_name_regex,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)981 SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex,
982                                   const SBFileSpecList &module_list,
983                                   const SBFileSpecList &comp_unit_list) {
984   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
985                      (const char *, const lldb::SBFileSpecList &,
986                       const lldb::SBFileSpecList &),
987                      symbol_name_regex, module_list, comp_unit_list);
988 
989   return LLDB_RECORD_RESULT(BreakpointCreateByRegex(
990       symbol_name_regex, eLanguageTypeUnknown, module_list, comp_unit_list));
991 }
992 
BreakpointCreateByRegex(const char * symbol_name_regex,LanguageType symbol_language,const SBFileSpecList & module_list,const SBFileSpecList & comp_unit_list)993 lldb::SBBreakpoint SBTarget::BreakpointCreateByRegex(
994     const char *symbol_name_regex, LanguageType symbol_language,
995     const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) {
996   LLDB_RECORD_METHOD(
997       lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
998       (const char *, lldb::LanguageType, const lldb::SBFileSpecList &,
999        const lldb::SBFileSpecList &),
1000       symbol_name_regex, symbol_language, module_list, comp_unit_list);
1001 
1002 
1003   SBBreakpoint sb_bp;
1004   TargetSP target_sp(GetSP());
1005   if (target_sp && symbol_name_regex && symbol_name_regex[0]) {
1006     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1007     RegularExpression regexp((llvm::StringRef(symbol_name_regex)));
1008     const bool internal = false;
1009     const bool hardware = false;
1010     const LazyBool skip_prologue = eLazyBoolCalculate;
1011 
1012     sb_bp = target_sp->CreateFuncRegexBreakpoint(
1013         module_list.get(), comp_unit_list.get(), std::move(regexp),
1014         symbol_language, skip_prologue, internal, hardware);
1015   }
1016 
1017   return LLDB_RECORD_RESULT(sb_bp);
1018 }
1019 
BreakpointCreateByAddress(addr_t address)1020 SBBreakpoint SBTarget::BreakpointCreateByAddress(addr_t address) {
1021   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByAddress,
1022                      (lldb::addr_t), address);
1023 
1024   SBBreakpoint sb_bp;
1025   TargetSP target_sp(GetSP());
1026   if (target_sp) {
1027     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1028     const bool hardware = false;
1029     sb_bp = target_sp->CreateBreakpoint(address, false, hardware);
1030   }
1031 
1032   return LLDB_RECORD_RESULT(sb_bp);
1033 }
1034 
BreakpointCreateBySBAddress(SBAddress & sb_address)1035 SBBreakpoint SBTarget::BreakpointCreateBySBAddress(SBAddress &sb_address) {
1036   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateBySBAddress,
1037                      (lldb::SBAddress &), sb_address);
1038 
1039   SBBreakpoint sb_bp;
1040   TargetSP target_sp(GetSP());
1041   if (!sb_address.IsValid()) {
1042     return LLDB_RECORD_RESULT(sb_bp);
1043   }
1044 
1045   if (target_sp) {
1046     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1047     const bool hardware = false;
1048     sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware);
1049   }
1050 
1051   return LLDB_RECORD_RESULT(sb_bp);
1052 }
1053 
1054 lldb::SBBreakpoint
BreakpointCreateBySourceRegex(const char * source_regex,const lldb::SBFileSpec & source_file,const char * module_name)1055 SBTarget::BreakpointCreateBySourceRegex(const char *source_regex,
1056                                         const lldb::SBFileSpec &source_file,
1057                                         const char *module_name) {
1058   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget,
1059                      BreakpointCreateBySourceRegex,
1060                      (const char *, const lldb::SBFileSpec &, const char *),
1061                      source_regex, source_file, module_name);
1062 
1063   SBFileSpecList module_spec_list;
1064 
1065   if (module_name && module_name[0]) {
1066     module_spec_list.Append(FileSpec(module_name));
1067   }
1068 
1069   SBFileSpecList source_file_list;
1070   if (source_file.IsValid()) {
1071     source_file_list.Append(source_file);
1072   }
1073 
1074   return LLDB_RECORD_RESULT(BreakpointCreateBySourceRegex(
1075       source_regex, module_spec_list, source_file_list));
1076 }
1077 
BreakpointCreateBySourceRegex(const char * source_regex,const SBFileSpecList & module_list,const lldb::SBFileSpecList & source_file_list)1078 lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
1079     const char *source_regex, const SBFileSpecList &module_list,
1080     const lldb::SBFileSpecList &source_file_list) {
1081   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget,
1082                      BreakpointCreateBySourceRegex,
1083                      (const char *, const lldb::SBFileSpecList &,
1084                       const lldb::SBFileSpecList &),
1085                      source_regex, module_list, source_file_list);
1086 
1087   return LLDB_RECORD_RESULT(BreakpointCreateBySourceRegex(
1088       source_regex, module_list, source_file_list, SBStringList()));
1089 }
1090 
BreakpointCreateBySourceRegex(const char * source_regex,const SBFileSpecList & module_list,const lldb::SBFileSpecList & source_file_list,const SBStringList & func_names)1091 lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex(
1092     const char *source_regex, const SBFileSpecList &module_list,
1093     const lldb::SBFileSpecList &source_file_list,
1094     const SBStringList &func_names) {
1095   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget,
1096                      BreakpointCreateBySourceRegex,
1097                      (const char *, const lldb::SBFileSpecList &,
1098                       const lldb::SBFileSpecList &, const lldb::SBStringList &),
1099                      source_regex, module_list, source_file_list, func_names);
1100 
1101   SBBreakpoint sb_bp;
1102   TargetSP target_sp(GetSP());
1103   if (target_sp && source_regex && source_regex[0]) {
1104     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1105     const bool hardware = false;
1106     const LazyBool move_to_nearest_code = eLazyBoolCalculate;
1107     RegularExpression regexp((llvm::StringRef(source_regex)));
1108     std::unordered_set<std::string> func_names_set;
1109     for (size_t i = 0; i < func_names.GetSize(); i++) {
1110       func_names_set.insert(func_names.GetStringAtIndex(i));
1111     }
1112 
1113     sb_bp = target_sp->CreateSourceRegexBreakpoint(
1114         module_list.get(), source_file_list.get(), func_names_set,
1115         std::move(regexp), false, hardware, move_to_nearest_code);
1116   }
1117 
1118   return LLDB_RECORD_RESULT(sb_bp);
1119 }
1120 
1121 lldb::SBBreakpoint
BreakpointCreateForException(lldb::LanguageType language,bool catch_bp,bool throw_bp)1122 SBTarget::BreakpointCreateForException(lldb::LanguageType language,
1123                                        bool catch_bp, bool throw_bp) {
1124   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateForException,
1125                      (lldb::LanguageType, bool, bool), language, catch_bp,
1126                      throw_bp);
1127 
1128   SBBreakpoint sb_bp;
1129   TargetSP target_sp(GetSP());
1130   if (target_sp) {
1131     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1132     const bool hardware = false;
1133     sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp,
1134                                                   hardware);
1135   }
1136 
1137   return LLDB_RECORD_RESULT(sb_bp);
1138 }
1139 
BreakpointCreateFromScript(const char * class_name,SBStructuredData & extra_args,const SBFileSpecList & module_list,const SBFileSpecList & file_list,bool request_hardware)1140 lldb::SBBreakpoint SBTarget::BreakpointCreateFromScript(
1141     const char *class_name, SBStructuredData &extra_args,
1142     const SBFileSpecList &module_list, const SBFileSpecList &file_list,
1143     bool request_hardware) {
1144   LLDB_RECORD_METHOD(
1145       lldb::SBBreakpoint, SBTarget, BreakpointCreateFromScript,
1146       (const char *, lldb::SBStructuredData &, const lldb::SBFileSpecList &,
1147        const lldb::SBFileSpecList &, bool),
1148       class_name, extra_args, module_list, file_list, request_hardware);
1149 
1150   SBBreakpoint sb_bp;
1151   TargetSP target_sp(GetSP());
1152   if (target_sp) {
1153     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1154     Status error;
1155 
1156     StructuredData::ObjectSP obj_sp = extra_args.m_impl_up->GetObjectSP();
1157     sb_bp =
1158         target_sp->CreateScriptedBreakpoint(class_name,
1159                                             module_list.get(),
1160                                             file_list.get(),
1161                                             false, /* internal */
1162                                             request_hardware,
1163                                             obj_sp,
1164                                             &error);
1165   }
1166 
1167   return LLDB_RECORD_RESULT(sb_bp);
1168 }
1169 
GetNumBreakpoints() const1170 uint32_t SBTarget::GetNumBreakpoints() const {
1171   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumBreakpoints);
1172 
1173   TargetSP target_sp(GetSP());
1174   if (target_sp) {
1175     // The breakpoint list is thread safe, no need to lock
1176     return target_sp->GetBreakpointList().GetSize();
1177   }
1178   return 0;
1179 }
1180 
GetBreakpointAtIndex(uint32_t idx) const1181 SBBreakpoint SBTarget::GetBreakpointAtIndex(uint32_t idx) const {
1182   LLDB_RECORD_METHOD_CONST(lldb::SBBreakpoint, SBTarget, GetBreakpointAtIndex,
1183                            (uint32_t), idx);
1184 
1185   SBBreakpoint sb_breakpoint;
1186   TargetSP target_sp(GetSP());
1187   if (target_sp) {
1188     // The breakpoint list is thread safe, no need to lock
1189     sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx);
1190   }
1191   return LLDB_RECORD_RESULT(sb_breakpoint);
1192 }
1193 
BreakpointDelete(break_id_t bp_id)1194 bool SBTarget::BreakpointDelete(break_id_t bp_id) {
1195   LLDB_RECORD_METHOD(bool, SBTarget, BreakpointDelete, (lldb::break_id_t),
1196                      bp_id);
1197 
1198   bool result = false;
1199   TargetSP target_sp(GetSP());
1200   if (target_sp) {
1201     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1202     result = target_sp->RemoveBreakpointByID(bp_id);
1203   }
1204 
1205   return result;
1206 }
1207 
FindBreakpointByID(break_id_t bp_id)1208 SBBreakpoint SBTarget::FindBreakpointByID(break_id_t bp_id) {
1209   LLDB_RECORD_METHOD(lldb::SBBreakpoint, SBTarget, FindBreakpointByID,
1210                      (lldb::break_id_t), bp_id);
1211 
1212   SBBreakpoint sb_breakpoint;
1213   TargetSP target_sp(GetSP());
1214   if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) {
1215     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1216     sb_breakpoint = target_sp->GetBreakpointByID(bp_id);
1217   }
1218 
1219   return LLDB_RECORD_RESULT(sb_breakpoint);
1220 }
1221 
FindBreakpointsByName(const char * name,SBBreakpointList & bkpts)1222 bool SBTarget::FindBreakpointsByName(const char *name,
1223                                      SBBreakpointList &bkpts) {
1224   LLDB_RECORD_METHOD(bool, SBTarget, FindBreakpointsByName,
1225                      (const char *, lldb::SBBreakpointList &), name, bkpts);
1226 
1227   TargetSP target_sp(GetSP());
1228   if (target_sp) {
1229     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1230     llvm::Expected<std::vector<BreakpointSP>> expected_vector =
1231         target_sp->GetBreakpointList().FindBreakpointsByName(name);
1232     if (!expected_vector) {
1233       LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS),
1234                "invalid breakpoint name: {}",
1235                llvm::toString(expected_vector.takeError()));
1236       return false;
1237     }
1238     for (BreakpointSP bkpt_sp : *expected_vector) {
1239       bkpts.AppendByID(bkpt_sp->GetID());
1240     }
1241   }
1242   return true;
1243 }
1244 
GetBreakpointNames(SBStringList & names)1245 void SBTarget::GetBreakpointNames(SBStringList &names) {
1246   LLDB_RECORD_METHOD(void, SBTarget, GetBreakpointNames, (lldb::SBStringList &),
1247                      names);
1248 
1249   names.Clear();
1250 
1251   TargetSP target_sp(GetSP());
1252   if (target_sp) {
1253     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1254 
1255     std::vector<std::string> name_vec;
1256     target_sp->GetBreakpointNames(name_vec);
1257     for (auto name : name_vec)
1258       names.AppendString(name.c_str());
1259   }
1260 }
1261 
DeleteBreakpointName(const char * name)1262 void SBTarget::DeleteBreakpointName(const char *name) {
1263   LLDB_RECORD_METHOD(void, SBTarget, DeleteBreakpointName, (const char *),
1264                      name);
1265 
1266   TargetSP target_sp(GetSP());
1267   if (target_sp) {
1268     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1269     target_sp->DeleteBreakpointName(ConstString(name));
1270   }
1271 }
1272 
EnableAllBreakpoints()1273 bool SBTarget::EnableAllBreakpoints() {
1274   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, EnableAllBreakpoints);
1275 
1276   TargetSP target_sp(GetSP());
1277   if (target_sp) {
1278     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1279     target_sp->EnableAllowedBreakpoints();
1280     return true;
1281   }
1282   return false;
1283 }
1284 
DisableAllBreakpoints()1285 bool SBTarget::DisableAllBreakpoints() {
1286   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DisableAllBreakpoints);
1287 
1288   TargetSP target_sp(GetSP());
1289   if (target_sp) {
1290     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1291     target_sp->DisableAllowedBreakpoints();
1292     return true;
1293   }
1294   return false;
1295 }
1296 
DeleteAllBreakpoints()1297 bool SBTarget::DeleteAllBreakpoints() {
1298   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DeleteAllBreakpoints);
1299 
1300   TargetSP target_sp(GetSP());
1301   if (target_sp) {
1302     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1303     target_sp->RemoveAllowedBreakpoints();
1304     return true;
1305   }
1306   return false;
1307 }
1308 
BreakpointsCreateFromFile(SBFileSpec & source_file,SBBreakpointList & new_bps)1309 lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
1310                                                   SBBreakpointList &new_bps) {
1311   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsCreateFromFile,
1312                      (lldb::SBFileSpec &, lldb::SBBreakpointList &),
1313                      source_file, new_bps);
1314 
1315   SBStringList empty_name_list;
1316   return LLDB_RECORD_RESULT(
1317       BreakpointsCreateFromFile(source_file, empty_name_list, new_bps));
1318 }
1319 
BreakpointsCreateFromFile(SBFileSpec & source_file,SBStringList & matching_names,SBBreakpointList & new_bps)1320 lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file,
1321                                                   SBStringList &matching_names,
1322                                                   SBBreakpointList &new_bps) {
1323   LLDB_RECORD_METHOD(
1324       lldb::SBError, SBTarget, BreakpointsCreateFromFile,
1325       (lldb::SBFileSpec &, lldb::SBStringList &, lldb::SBBreakpointList &),
1326       source_file, matching_names, new_bps);
1327 
1328   SBError sberr;
1329   TargetSP target_sp(GetSP());
1330   if (!target_sp) {
1331     sberr.SetErrorString(
1332         "BreakpointCreateFromFile called with invalid target.");
1333     return LLDB_RECORD_RESULT(sberr);
1334   }
1335   std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1336 
1337   BreakpointIDList bp_ids;
1338 
1339   std::vector<std::string> name_vector;
1340   size_t num_names = matching_names.GetSize();
1341   for (size_t i = 0; i < num_names; i++)
1342     name_vector.push_back(matching_names.GetStringAtIndex(i));
1343 
1344   sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(),
1345                                                      name_vector, bp_ids);
1346   if (sberr.Fail())
1347     return LLDB_RECORD_RESULT(sberr);
1348 
1349   size_t num_bkpts = bp_ids.GetSize();
1350   for (size_t i = 0; i < num_bkpts; i++) {
1351     BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i);
1352     new_bps.AppendByID(bp_id.GetBreakpointID());
1353   }
1354   return LLDB_RECORD_RESULT(sberr);
1355 }
1356 
BreakpointsWriteToFile(SBFileSpec & dest_file)1357 lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file) {
1358   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
1359                      (lldb::SBFileSpec &), dest_file);
1360 
1361   SBError sberr;
1362   TargetSP target_sp(GetSP());
1363   if (!target_sp) {
1364     sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1365     return LLDB_RECORD_RESULT(sberr);
1366   }
1367   SBBreakpointList bkpt_list(*this);
1368   return LLDB_RECORD_RESULT(BreakpointsWriteToFile(dest_file, bkpt_list));
1369 }
1370 
BreakpointsWriteToFile(SBFileSpec & dest_file,SBBreakpointList & bkpt_list,bool append)1371 lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file,
1372                                                SBBreakpointList &bkpt_list,
1373                                                bool append) {
1374   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
1375                      (lldb::SBFileSpec &, lldb::SBBreakpointList &, bool),
1376                      dest_file, bkpt_list, append);
1377 
1378   SBError sberr;
1379   TargetSP target_sp(GetSP());
1380   if (!target_sp) {
1381     sberr.SetErrorString("BreakpointWriteToFile called with invalid target.");
1382     return LLDB_RECORD_RESULT(sberr);
1383   }
1384 
1385   std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1386   BreakpointIDList bp_id_list;
1387   bkpt_list.CopyToBreakpointIDList(bp_id_list);
1388   sberr.ref() = target_sp->SerializeBreakpointsToFile(dest_file.ref(),
1389                                                       bp_id_list, append);
1390   return LLDB_RECORD_RESULT(sberr);
1391 }
1392 
GetNumWatchpoints() const1393 uint32_t SBTarget::GetNumWatchpoints() const {
1394   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumWatchpoints);
1395 
1396   TargetSP target_sp(GetSP());
1397   if (target_sp) {
1398     // The watchpoint list is thread safe, no need to lock
1399     return target_sp->GetWatchpointList().GetSize();
1400   }
1401   return 0;
1402 }
1403 
GetWatchpointAtIndex(uint32_t idx) const1404 SBWatchpoint SBTarget::GetWatchpointAtIndex(uint32_t idx) const {
1405   LLDB_RECORD_METHOD_CONST(lldb::SBWatchpoint, SBTarget, GetWatchpointAtIndex,
1406                            (uint32_t), idx);
1407 
1408   SBWatchpoint sb_watchpoint;
1409   TargetSP target_sp(GetSP());
1410   if (target_sp) {
1411     // The watchpoint list is thread safe, no need to lock
1412     sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx));
1413   }
1414   return LLDB_RECORD_RESULT(sb_watchpoint);
1415 }
1416 
DeleteWatchpoint(watch_id_t wp_id)1417 bool SBTarget::DeleteWatchpoint(watch_id_t wp_id) {
1418   LLDB_RECORD_METHOD(bool, SBTarget, DeleteWatchpoint, (lldb::watch_id_t),
1419                      wp_id);
1420 
1421 
1422   bool result = false;
1423   TargetSP target_sp(GetSP());
1424   if (target_sp) {
1425     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1426     std::unique_lock<std::recursive_mutex> lock;
1427     target_sp->GetWatchpointList().GetListMutex(lock);
1428     result = target_sp->RemoveWatchpointByID(wp_id);
1429   }
1430 
1431   return result;
1432 }
1433 
FindWatchpointByID(lldb::watch_id_t wp_id)1434 SBWatchpoint SBTarget::FindWatchpointByID(lldb::watch_id_t wp_id) {
1435   LLDB_RECORD_METHOD(lldb::SBWatchpoint, SBTarget, FindWatchpointByID,
1436                      (lldb::watch_id_t), wp_id);
1437 
1438 
1439   SBWatchpoint sb_watchpoint;
1440   lldb::WatchpointSP watchpoint_sp;
1441   TargetSP target_sp(GetSP());
1442   if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) {
1443     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1444     std::unique_lock<std::recursive_mutex> lock;
1445     target_sp->GetWatchpointList().GetListMutex(lock);
1446     watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id);
1447     sb_watchpoint.SetSP(watchpoint_sp);
1448   }
1449 
1450   return LLDB_RECORD_RESULT(sb_watchpoint);
1451 }
1452 
WatchAddress(lldb::addr_t addr,size_t size,bool read,bool write,SBError & error)1453 lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size,
1454                                           bool read, bool write,
1455                                           SBError &error) {
1456   LLDB_RECORD_METHOD(lldb::SBWatchpoint, SBTarget, WatchAddress,
1457                      (lldb::addr_t, size_t, bool, bool, lldb::SBError &), addr,
1458                      size, read, write, error);
1459 
1460   SBWatchpoint sb_watchpoint;
1461   lldb::WatchpointSP watchpoint_sp;
1462   TargetSP target_sp(GetSP());
1463   if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS &&
1464       size > 0) {
1465     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1466     uint32_t watch_type = 0;
1467     if (read)
1468       watch_type |= LLDB_WATCH_TYPE_READ;
1469     if (write)
1470       watch_type |= LLDB_WATCH_TYPE_WRITE;
1471     if (watch_type == 0) {
1472       error.SetErrorString(
1473           "Can't create a watchpoint that is neither read nor write.");
1474       return LLDB_RECORD_RESULT(sb_watchpoint);
1475     }
1476 
1477     // Target::CreateWatchpoint() is thread safe.
1478     Status cw_error;
1479     // This API doesn't take in a type, so we can't figure out what it is.
1480     CompilerType *type = nullptr;
1481     watchpoint_sp =
1482         target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error);
1483     error.SetError(cw_error);
1484     sb_watchpoint.SetSP(watchpoint_sp);
1485   }
1486 
1487   return LLDB_RECORD_RESULT(sb_watchpoint);
1488 }
1489 
EnableAllWatchpoints()1490 bool SBTarget::EnableAllWatchpoints() {
1491   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, EnableAllWatchpoints);
1492 
1493   TargetSP target_sp(GetSP());
1494   if (target_sp) {
1495     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1496     std::unique_lock<std::recursive_mutex> lock;
1497     target_sp->GetWatchpointList().GetListMutex(lock);
1498     target_sp->EnableAllWatchpoints();
1499     return true;
1500   }
1501   return false;
1502 }
1503 
DisableAllWatchpoints()1504 bool SBTarget::DisableAllWatchpoints() {
1505   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DisableAllWatchpoints);
1506 
1507   TargetSP target_sp(GetSP());
1508   if (target_sp) {
1509     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1510     std::unique_lock<std::recursive_mutex> lock;
1511     target_sp->GetWatchpointList().GetListMutex(lock);
1512     target_sp->DisableAllWatchpoints();
1513     return true;
1514   }
1515   return false;
1516 }
1517 
CreateValueFromAddress(const char * name,SBAddress addr,SBType type)1518 SBValue SBTarget::CreateValueFromAddress(const char *name, SBAddress addr,
1519                                          SBType type) {
1520   LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromAddress,
1521                      (const char *, lldb::SBAddress, lldb::SBType), name, addr,
1522                      type);
1523 
1524   SBValue sb_value;
1525   lldb::ValueObjectSP new_value_sp;
1526   if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) {
1527     lldb::addr_t load_addr(addr.GetLoadAddress(*this));
1528     ExecutionContext exe_ctx(
1529         ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1530     CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1531     new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr,
1532                                                              exe_ctx, ast_type);
1533   }
1534   sb_value.SetSP(new_value_sp);
1535   return LLDB_RECORD_RESULT(sb_value);
1536 }
1537 
CreateValueFromData(const char * name,lldb::SBData data,lldb::SBType type)1538 lldb::SBValue SBTarget::CreateValueFromData(const char *name, lldb::SBData data,
1539                                             lldb::SBType type) {
1540   LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromData,
1541                      (const char *, lldb::SBData, lldb::SBType), name, data,
1542                      type);
1543 
1544   SBValue sb_value;
1545   lldb::ValueObjectSP new_value_sp;
1546   if (IsValid() && name && *name && data.IsValid() && type.IsValid()) {
1547     DataExtractorSP extractor(*data);
1548     ExecutionContext exe_ctx(
1549         ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1550     CompilerType ast_type(type.GetSP()->GetCompilerType(true));
1551     new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor,
1552                                                           exe_ctx, ast_type);
1553   }
1554   sb_value.SetSP(new_value_sp);
1555   return LLDB_RECORD_RESULT(sb_value);
1556 }
1557 
CreateValueFromExpression(const char * name,const char * expr)1558 lldb::SBValue SBTarget::CreateValueFromExpression(const char *name,
1559                                                   const char *expr) {
1560   LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, CreateValueFromExpression,
1561                      (const char *, const char *), name, expr);
1562 
1563   SBValue sb_value;
1564   lldb::ValueObjectSP new_value_sp;
1565   if (IsValid() && name && *name && expr && *expr) {
1566     ExecutionContext exe_ctx(
1567         ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false)));
1568     new_value_sp =
1569         ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
1570   }
1571   sb_value.SetSP(new_value_sp);
1572   return LLDB_RECORD_RESULT(sb_value);
1573 }
1574 
DeleteAllWatchpoints()1575 bool SBTarget::DeleteAllWatchpoints() {
1576   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTarget, DeleteAllWatchpoints);
1577 
1578   TargetSP target_sp(GetSP());
1579   if (target_sp) {
1580     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
1581     std::unique_lock<std::recursive_mutex> lock;
1582     target_sp->GetWatchpointList().GetListMutex(lock);
1583     target_sp->RemoveAllWatchpoints();
1584     return true;
1585   }
1586   return false;
1587 }
1588 
AppendImageSearchPath(const char * from,const char * to,lldb::SBError & error)1589 void SBTarget::AppendImageSearchPath(const char *from, const char *to,
1590                                      lldb::SBError &error) {
1591   LLDB_RECORD_METHOD(void, SBTarget, AppendImageSearchPath,
1592                      (const char *, const char *, lldb::SBError &), from, to,
1593                      error);
1594 
1595   TargetSP target_sp(GetSP());
1596   if (!target_sp)
1597     return error.SetErrorString("invalid target");
1598 
1599   const ConstString csFrom(from), csTo(to);
1600   if (!csFrom)
1601     return error.SetErrorString("<from> path can't be empty");
1602   if (!csTo)
1603     return error.SetErrorString("<to> path can't be empty");
1604 
1605   target_sp->GetImageSearchPathList().Append(csFrom, csTo, true);
1606 }
1607 
AddModule(const char * path,const char * triple,const char * uuid_cstr)1608 lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1609                                    const char *uuid_cstr) {
1610   LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule,
1611                      (const char *, const char *, const char *), path, triple,
1612                      uuid_cstr);
1613 
1614   return LLDB_RECORD_RESULT(AddModule(path, triple, uuid_cstr, nullptr));
1615 }
1616 
AddModule(const char * path,const char * triple,const char * uuid_cstr,const char * symfile)1617 lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,
1618                                    const char *uuid_cstr, const char *symfile) {
1619   LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule,
1620                      (const char *, const char *, const char *, const char *),
1621                      path, triple, uuid_cstr, symfile);
1622 
1623   lldb::SBModule sb_module;
1624   TargetSP target_sp(GetSP());
1625   if (target_sp) {
1626     ModuleSpec module_spec;
1627     if (path)
1628       module_spec.GetFileSpec().SetFile(path, FileSpec::Style::native);
1629 
1630     if (uuid_cstr)
1631       module_spec.GetUUID().SetFromStringRef(uuid_cstr);
1632 
1633     if (triple)
1634       module_spec.GetArchitecture() = Platform::GetAugmentedArchSpec(
1635           target_sp->GetPlatform().get(), triple);
1636     else
1637       module_spec.GetArchitecture() = target_sp->GetArchitecture();
1638 
1639     if (symfile)
1640       module_spec.GetSymbolFileSpec().SetFile(symfile, FileSpec::Style::native);
1641 
1642     sb_module.SetSP(target_sp->GetOrCreateModule(module_spec, true /* notify */));
1643   }
1644   return LLDB_RECORD_RESULT(sb_module);
1645 }
1646 
AddModule(const SBModuleSpec & module_spec)1647 lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) {
1648   LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, AddModule,
1649                      (const lldb::SBModuleSpec &), module_spec);
1650 
1651   lldb::SBModule sb_module;
1652   TargetSP target_sp(GetSP());
1653   if (target_sp)
1654     sb_module.SetSP(target_sp->GetOrCreateModule(*module_spec.m_opaque_up,
1655                                                  true /* notify */));
1656   return LLDB_RECORD_RESULT(sb_module);
1657 }
1658 
AddModule(lldb::SBModule & module)1659 bool SBTarget::AddModule(lldb::SBModule &module) {
1660   LLDB_RECORD_METHOD(bool, SBTarget, AddModule, (lldb::SBModule &), module);
1661 
1662   TargetSP target_sp(GetSP());
1663   if (target_sp) {
1664     target_sp->GetImages().AppendIfNeeded(module.GetSP());
1665     return true;
1666   }
1667   return false;
1668 }
1669 
GetNumModules() const1670 uint32_t SBTarget::GetNumModules() const {
1671   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBTarget, GetNumModules);
1672 
1673   uint32_t num = 0;
1674   TargetSP target_sp(GetSP());
1675   if (target_sp) {
1676     // The module list is thread safe, no need to lock
1677     num = target_sp->GetImages().GetSize();
1678   }
1679 
1680   return num;
1681 }
1682 
Clear()1683 void SBTarget::Clear() {
1684   LLDB_RECORD_METHOD_NO_ARGS(void, SBTarget, Clear);
1685 
1686   m_opaque_sp.reset();
1687 }
1688 
FindModule(const SBFileSpec & sb_file_spec)1689 SBModule SBTarget::FindModule(const SBFileSpec &sb_file_spec) {
1690   LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, FindModule,
1691                      (const lldb::SBFileSpec &), sb_file_spec);
1692 
1693   SBModule sb_module;
1694   TargetSP target_sp(GetSP());
1695   if (target_sp && sb_file_spec.IsValid()) {
1696     ModuleSpec module_spec(*sb_file_spec);
1697     // The module list is thread safe, no need to lock
1698     sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec));
1699   }
1700   return LLDB_RECORD_RESULT(sb_module);
1701 }
1702 
FindCompileUnits(const SBFileSpec & sb_file_spec)1703 SBSymbolContextList SBTarget::FindCompileUnits(const SBFileSpec &sb_file_spec) {
1704   LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindCompileUnits,
1705                      (const lldb::SBFileSpec &), sb_file_spec);
1706 
1707   SBSymbolContextList sb_sc_list;
1708   const TargetSP target_sp(GetSP());
1709   if (target_sp && sb_file_spec.IsValid())
1710     target_sp->GetImages().FindCompileUnits(*sb_file_spec, *sb_sc_list);
1711   return LLDB_RECORD_RESULT(sb_sc_list);
1712 }
1713 
GetByteOrder()1714 lldb::ByteOrder SBTarget::GetByteOrder() {
1715   LLDB_RECORD_METHOD_NO_ARGS(lldb::ByteOrder, SBTarget, GetByteOrder);
1716 
1717   TargetSP target_sp(GetSP());
1718   if (target_sp)
1719     return target_sp->GetArchitecture().GetByteOrder();
1720   return eByteOrderInvalid;
1721 }
1722 
GetTriple()1723 const char *SBTarget::GetTriple() {
1724   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTarget, GetTriple);
1725 
1726   TargetSP target_sp(GetSP());
1727   if (target_sp) {
1728     std::string triple(target_sp->GetArchitecture().GetTriple().str());
1729     // Unique the string so we don't run into ownership issues since the const
1730     // strings put the string into the string pool once and the strings never
1731     // comes out
1732     ConstString const_triple(triple.c_str());
1733     return const_triple.GetCString();
1734   }
1735   return nullptr;
1736 }
1737 
GetDataByteSize()1738 uint32_t SBTarget::GetDataByteSize() {
1739   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetDataByteSize);
1740 
1741   TargetSP target_sp(GetSP());
1742   if (target_sp) {
1743     return target_sp->GetArchitecture().GetDataByteSize();
1744   }
1745   return 0;
1746 }
1747 
GetCodeByteSize()1748 uint32_t SBTarget::GetCodeByteSize() {
1749   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetCodeByteSize);
1750 
1751   TargetSP target_sp(GetSP());
1752   if (target_sp) {
1753     return target_sp->GetArchitecture().GetCodeByteSize();
1754   }
1755   return 0;
1756 }
1757 
GetAddressByteSize()1758 uint32_t SBTarget::GetAddressByteSize() {
1759   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTarget, GetAddressByteSize);
1760 
1761   TargetSP target_sp(GetSP());
1762   if (target_sp)
1763     return target_sp->GetArchitecture().GetAddressByteSize();
1764   return sizeof(void *);
1765 }
1766 
GetModuleAtIndex(uint32_t idx)1767 SBModule SBTarget::GetModuleAtIndex(uint32_t idx) {
1768   LLDB_RECORD_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndex, (uint32_t),
1769                      idx);
1770 
1771   SBModule sb_module;
1772   ModuleSP module_sp;
1773   TargetSP target_sp(GetSP());
1774   if (target_sp) {
1775     // The module list is thread safe, no need to lock
1776     module_sp = target_sp->GetImages().GetModuleAtIndex(idx);
1777     sb_module.SetSP(module_sp);
1778   }
1779 
1780   return LLDB_RECORD_RESULT(sb_module);
1781 }
1782 
RemoveModule(lldb::SBModule module)1783 bool SBTarget::RemoveModule(lldb::SBModule module) {
1784   LLDB_RECORD_METHOD(bool, SBTarget, RemoveModule, (lldb::SBModule), module);
1785 
1786   TargetSP target_sp(GetSP());
1787   if (target_sp)
1788     return target_sp->GetImages().Remove(module.GetSP());
1789   return false;
1790 }
1791 
GetBroadcaster() const1792 SBBroadcaster SBTarget::GetBroadcaster() const {
1793   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBBroadcaster, SBTarget,
1794                                    GetBroadcaster);
1795 
1796 
1797   TargetSP target_sp(GetSP());
1798   SBBroadcaster broadcaster(target_sp.get(), false);
1799 
1800 
1801   return LLDB_RECORD_RESULT(broadcaster);
1802 }
1803 
GetDescription(SBStream & description,lldb::DescriptionLevel description_level)1804 bool SBTarget::GetDescription(SBStream &description,
1805                               lldb::DescriptionLevel description_level) {
1806   LLDB_RECORD_METHOD(bool, SBTarget, GetDescription,
1807                      (lldb::SBStream &, lldb::DescriptionLevel), description,
1808                      description_level);
1809 
1810   Stream &strm = description.ref();
1811 
1812   TargetSP target_sp(GetSP());
1813   if (target_sp) {
1814     target_sp->Dump(&strm, description_level);
1815   } else
1816     strm.PutCString("No value");
1817 
1818   return true;
1819 }
1820 
FindFunctions(const char * name,uint32_t name_type_mask)1821 lldb::SBSymbolContextList SBTarget::FindFunctions(const char *name,
1822                                                   uint32_t name_type_mask) {
1823   LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindFunctions,
1824                      (const char *, uint32_t), name, name_type_mask);
1825 
1826   lldb::SBSymbolContextList sb_sc_list;
1827   if (!name || !name[0])
1828     return LLDB_RECORD_RESULT(sb_sc_list);
1829 
1830   TargetSP target_sp(GetSP());
1831   if (!target_sp)
1832     return LLDB_RECORD_RESULT(sb_sc_list);
1833 
1834   const bool symbols_ok = true;
1835   const bool inlines_ok = true;
1836   FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask);
1837   target_sp->GetImages().FindFunctions(ConstString(name), mask, symbols_ok,
1838                                        inlines_ok, *sb_sc_list);
1839   return LLDB_RECORD_RESULT(sb_sc_list);
1840 }
1841 
FindGlobalFunctions(const char * name,uint32_t max_matches,MatchType matchtype)1842 lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name,
1843                                                         uint32_t max_matches,
1844                                                         MatchType matchtype) {
1845   LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindGlobalFunctions,
1846                      (const char *, uint32_t, lldb::MatchType), name,
1847                      max_matches, matchtype);
1848 
1849   lldb::SBSymbolContextList sb_sc_list;
1850   if (name && name[0]) {
1851     llvm::StringRef name_ref(name);
1852     TargetSP target_sp(GetSP());
1853     if (target_sp) {
1854       std::string regexstr;
1855       switch (matchtype) {
1856       case eMatchTypeRegex:
1857         target_sp->GetImages().FindFunctions(RegularExpression(name_ref), true,
1858                                              true, *sb_sc_list);
1859         break;
1860       case eMatchTypeStartsWith:
1861         regexstr = llvm::Regex::escape(name) + ".*";
1862         target_sp->GetImages().FindFunctions(RegularExpression(regexstr), true,
1863                                              true, *sb_sc_list);
1864         break;
1865       default:
1866         target_sp->GetImages().FindFunctions(
1867             ConstString(name), eFunctionNameTypeAny, true, true, *sb_sc_list);
1868         break;
1869       }
1870     }
1871   }
1872   return LLDB_RECORD_RESULT(sb_sc_list);
1873 }
1874 
FindFirstType(const char * typename_cstr)1875 lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) {
1876   LLDB_RECORD_METHOD(lldb::SBType, SBTarget, FindFirstType, (const char *),
1877                      typename_cstr);
1878 
1879   TargetSP target_sp(GetSP());
1880   if (typename_cstr && typename_cstr[0] && target_sp) {
1881     ConstString const_typename(typename_cstr);
1882     SymbolContext sc;
1883     const bool exact_match = false;
1884 
1885     const ModuleList &module_list = target_sp->GetImages();
1886     size_t count = module_list.GetSize();
1887     for (size_t idx = 0; idx < count; idx++) {
1888       ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
1889       if (module_sp) {
1890         TypeSP type_sp(
1891             module_sp->FindFirstType(sc, const_typename, exact_match));
1892         if (type_sp)
1893           return LLDB_RECORD_RESULT(SBType(type_sp));
1894       }
1895     }
1896 
1897     // Didn't find the type in the symbols; Try the loaded language runtimes
1898     if (auto process_sp = target_sp->GetProcessSP()) {
1899       for (auto *runtime : process_sp->GetLanguageRuntimes()) {
1900         if (auto vendor = runtime->GetDeclVendor()) {
1901           auto types = vendor->FindTypes(const_typename, /*max_matches*/ 1);
1902           if (!types.empty())
1903             return LLDB_RECORD_RESULT(SBType(types.front()));
1904         }
1905       }
1906     }
1907 
1908     // No matches, search for basic typename matches
1909     for (auto *type_system : target_sp->GetScratchTypeSystems())
1910       if (auto type = type_system->GetBuiltinTypeByName(const_typename))
1911         return LLDB_RECORD_RESULT(SBType(type));
1912   }
1913 
1914   return LLDB_RECORD_RESULT(SBType());
1915 }
1916 
GetBasicType(lldb::BasicType type)1917 SBType SBTarget::GetBasicType(lldb::BasicType type) {
1918   LLDB_RECORD_METHOD(lldb::SBType, SBTarget, GetBasicType, (lldb::BasicType),
1919                      type);
1920 
1921   TargetSP target_sp(GetSP());
1922   if (target_sp) {
1923     for (auto *type_system : target_sp->GetScratchTypeSystems())
1924       if (auto compiler_type = type_system->GetBasicTypeFromAST(type))
1925         return LLDB_RECORD_RESULT(SBType(compiler_type));
1926   }
1927   return LLDB_RECORD_RESULT(SBType());
1928 }
1929 
FindTypes(const char * typename_cstr)1930 lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) {
1931   LLDB_RECORD_METHOD(lldb::SBTypeList, SBTarget, FindTypes, (const char *),
1932                      typename_cstr);
1933 
1934   SBTypeList sb_type_list;
1935   TargetSP target_sp(GetSP());
1936   if (typename_cstr && typename_cstr[0] && target_sp) {
1937     ModuleList &images = target_sp->GetImages();
1938     ConstString const_typename(typename_cstr);
1939     bool exact_match = false;
1940     TypeList type_list;
1941     llvm::DenseSet<SymbolFile *> searched_symbol_files;
1942     images.FindTypes(nullptr, const_typename, exact_match, UINT32_MAX,
1943                      searched_symbol_files, type_list);
1944 
1945     for (size_t idx = 0; idx < type_list.GetSize(); idx++) {
1946       TypeSP type_sp(type_list.GetTypeAtIndex(idx));
1947       if (type_sp)
1948         sb_type_list.Append(SBType(type_sp));
1949     }
1950 
1951     // Try the loaded language runtimes
1952     if (auto process_sp = target_sp->GetProcessSP()) {
1953       for (auto *runtime : process_sp->GetLanguageRuntimes()) {
1954         if (auto *vendor = runtime->GetDeclVendor()) {
1955           auto types =
1956               vendor->FindTypes(const_typename, /*max_matches*/ UINT32_MAX);
1957           for (auto type : types)
1958             sb_type_list.Append(SBType(type));
1959         }
1960       }
1961     }
1962 
1963     if (sb_type_list.GetSize() == 0) {
1964       // No matches, search for basic typename matches
1965       for (auto *type_system : target_sp->GetScratchTypeSystems())
1966         if (auto compiler_type =
1967                 type_system->GetBuiltinTypeByName(const_typename))
1968           sb_type_list.Append(SBType(compiler_type));
1969     }
1970   }
1971   return LLDB_RECORD_RESULT(sb_type_list);
1972 }
1973 
FindGlobalVariables(const char * name,uint32_t max_matches)1974 SBValueList SBTarget::FindGlobalVariables(const char *name,
1975                                           uint32_t max_matches) {
1976   LLDB_RECORD_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
1977                      (const char *, uint32_t), name, max_matches);
1978 
1979   SBValueList sb_value_list;
1980 
1981   TargetSP target_sp(GetSP());
1982   if (name && target_sp) {
1983     VariableList variable_list;
1984     target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
1985                                                variable_list);
1986     if (!variable_list.Empty()) {
1987       ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
1988       if (exe_scope == nullptr)
1989         exe_scope = target_sp.get();
1990       for (const VariableSP &var_sp : variable_list) {
1991         lldb::ValueObjectSP valobj_sp(
1992             ValueObjectVariable::Create(exe_scope, var_sp));
1993         if (valobj_sp)
1994           sb_value_list.Append(SBValue(valobj_sp));
1995       }
1996     }
1997   }
1998 
1999   return LLDB_RECORD_RESULT(sb_value_list);
2000 }
2001 
FindGlobalVariables(const char * name,uint32_t max_matches,MatchType matchtype)2002 SBValueList SBTarget::FindGlobalVariables(const char *name,
2003                                           uint32_t max_matches,
2004                                           MatchType matchtype) {
2005   LLDB_RECORD_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
2006                      (const char *, uint32_t, lldb::MatchType), name,
2007                      max_matches, matchtype);
2008 
2009   SBValueList sb_value_list;
2010 
2011   TargetSP target_sp(GetSP());
2012   if (name && target_sp) {
2013     llvm::StringRef name_ref(name);
2014     VariableList variable_list;
2015 
2016     std::string regexstr;
2017     switch (matchtype) {
2018     case eMatchTypeNormal:
2019       target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches,
2020                                                  variable_list);
2021       break;
2022     case eMatchTypeRegex:
2023       target_sp->GetImages().FindGlobalVariables(RegularExpression(name_ref),
2024                                                  max_matches, variable_list);
2025       break;
2026     case eMatchTypeStartsWith:
2027       regexstr = llvm::Regex::escape(name) + ".*";
2028       target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr),
2029                                                  max_matches, variable_list);
2030       break;
2031     }
2032     if (!variable_list.Empty()) {
2033       ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get();
2034       if (exe_scope == nullptr)
2035         exe_scope = target_sp.get();
2036       for (const VariableSP &var_sp : variable_list) {
2037         lldb::ValueObjectSP valobj_sp(
2038             ValueObjectVariable::Create(exe_scope, var_sp));
2039         if (valobj_sp)
2040           sb_value_list.Append(SBValue(valobj_sp));
2041       }
2042     }
2043   }
2044 
2045   return LLDB_RECORD_RESULT(sb_value_list);
2046 }
2047 
FindFirstGlobalVariable(const char * name)2048 lldb::SBValue SBTarget::FindFirstGlobalVariable(const char *name) {
2049   LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, FindFirstGlobalVariable,
2050                      (const char *), name);
2051 
2052   SBValueList sb_value_list(FindGlobalVariables(name, 1));
2053   if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
2054     return LLDB_RECORD_RESULT(sb_value_list.GetValueAtIndex(0));
2055   return LLDB_RECORD_RESULT(SBValue());
2056 }
2057 
GetSourceManager()2058 SBSourceManager SBTarget::GetSourceManager() {
2059   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBSourceManager, SBTarget, GetSourceManager);
2060 
2061   SBSourceManager source_manager(*this);
2062   return LLDB_RECORD_RESULT(source_manager);
2063 }
2064 
ReadInstructions(lldb::SBAddress base_addr,uint32_t count)2065 lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
2066                                                    uint32_t count) {
2067   LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
2068                      (lldb::SBAddress, uint32_t), base_addr, count);
2069 
2070   return LLDB_RECORD_RESULT(ReadInstructions(base_addr, count, nullptr));
2071 }
2072 
ReadInstructions(lldb::SBAddress base_addr,uint32_t count,const char * flavor_string)2073 lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr,
2074                                                    uint32_t count,
2075                                                    const char *flavor_string) {
2076   LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
2077                      (lldb::SBAddress, uint32_t, const char *), base_addr,
2078                      count, flavor_string);
2079 
2080   SBInstructionList sb_instructions;
2081 
2082   TargetSP target_sp(GetSP());
2083   if (target_sp) {
2084     Address *addr_ptr = base_addr.get();
2085 
2086     if (addr_ptr) {
2087       DataBufferHeap data(
2088           target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0);
2089       bool prefer_file_cache = false;
2090       lldb_private::Status error;
2091       lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
2092       const size_t bytes_read =
2093           target_sp->ReadMemory(*addr_ptr, prefer_file_cache, data.GetBytes(),
2094                                 data.GetByteSize(), error, &load_addr);
2095       const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS;
2096       sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
2097           target_sp->GetArchitecture(), nullptr, flavor_string, *addr_ptr,
2098           data.GetBytes(), bytes_read, count, data_from_file));
2099     }
2100   }
2101 
2102   return LLDB_RECORD_RESULT(sb_instructions);
2103 }
2104 
GetInstructions(lldb::SBAddress base_addr,const void * buf,size_t size)2105 lldb::SBInstructionList SBTarget::GetInstructions(lldb::SBAddress base_addr,
2106                                                   const void *buf,
2107                                                   size_t size) {
2108   LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions,
2109                      (lldb::SBAddress, const void *, size_t), base_addr, buf,
2110                      size);
2111 
2112   return LLDB_RECORD_RESULT(
2113       GetInstructionsWithFlavor(base_addr, nullptr, buf, size));
2114 }
2115 
2116 lldb::SBInstructionList
GetInstructionsWithFlavor(lldb::SBAddress base_addr,const char * flavor_string,const void * buf,size_t size)2117 SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr,
2118                                     const char *flavor_string, const void *buf,
2119                                     size_t size) {
2120   LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget,
2121                      GetInstructionsWithFlavor,
2122                      (lldb::SBAddress, const char *, const void *, size_t),
2123                      base_addr, flavor_string, buf, size);
2124 
2125   SBInstructionList sb_instructions;
2126 
2127   TargetSP target_sp(GetSP());
2128   if (target_sp) {
2129     Address addr;
2130 
2131     if (base_addr.get())
2132       addr = *base_addr.get();
2133 
2134     const bool data_from_file = true;
2135 
2136     sb_instructions.SetDisassembler(Disassembler::DisassembleBytes(
2137         target_sp->GetArchitecture(), nullptr, flavor_string, addr, buf, size,
2138         UINT32_MAX, data_from_file));
2139   }
2140 
2141   return LLDB_RECORD_RESULT(sb_instructions);
2142 }
2143 
GetInstructions(lldb::addr_t base_addr,const void * buf,size_t size)2144 lldb::SBInstructionList SBTarget::GetInstructions(lldb::addr_t base_addr,
2145                                                   const void *buf,
2146                                                   size_t size) {
2147   LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions,
2148                      (lldb::addr_t, const void *, size_t), base_addr, buf,
2149                      size);
2150 
2151   return LLDB_RECORD_RESULT(GetInstructionsWithFlavor(
2152       ResolveLoadAddress(base_addr), nullptr, buf, size));
2153 }
2154 
2155 lldb::SBInstructionList
GetInstructionsWithFlavor(lldb::addr_t base_addr,const char * flavor_string,const void * buf,size_t size)2156 SBTarget::GetInstructionsWithFlavor(lldb::addr_t base_addr,
2157                                     const char *flavor_string, const void *buf,
2158                                     size_t size) {
2159   LLDB_RECORD_METHOD(lldb::SBInstructionList, SBTarget,
2160                      GetInstructionsWithFlavor,
2161                      (lldb::addr_t, const char *, const void *, size_t),
2162                      base_addr, flavor_string, buf, size);
2163 
2164   return LLDB_RECORD_RESULT(GetInstructionsWithFlavor(
2165       ResolveLoadAddress(base_addr), flavor_string, buf, size));
2166 }
2167 
SetSectionLoadAddress(lldb::SBSection section,lldb::addr_t section_base_addr)2168 SBError SBTarget::SetSectionLoadAddress(lldb::SBSection section,
2169                                         lldb::addr_t section_base_addr) {
2170   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, SetSectionLoadAddress,
2171                      (lldb::SBSection, lldb::addr_t), section,
2172                      section_base_addr);
2173 
2174   SBError sb_error;
2175   TargetSP target_sp(GetSP());
2176   if (target_sp) {
2177     if (!section.IsValid()) {
2178       sb_error.SetErrorStringWithFormat("invalid section");
2179     } else {
2180       SectionSP section_sp(section.GetSP());
2181       if (section_sp) {
2182         if (section_sp->IsThreadSpecific()) {
2183           sb_error.SetErrorString(
2184               "thread specific sections are not yet supported");
2185         } else {
2186           ProcessSP process_sp(target_sp->GetProcessSP());
2187           if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) {
2188             ModuleSP module_sp(section_sp->GetModule());
2189             if (module_sp) {
2190               ModuleList module_list;
2191               module_list.Append(module_sp);
2192               target_sp->ModulesDidLoad(module_list);
2193             }
2194             // Flush info in the process (stack frames, etc)
2195             if (process_sp)
2196               process_sp->Flush();
2197           }
2198         }
2199       }
2200     }
2201   } else {
2202     sb_error.SetErrorString("invalid target");
2203   }
2204   return LLDB_RECORD_RESULT(sb_error);
2205 }
2206 
ClearSectionLoadAddress(lldb::SBSection section)2207 SBError SBTarget::ClearSectionLoadAddress(lldb::SBSection section) {
2208   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, ClearSectionLoadAddress,
2209                      (lldb::SBSection), section);
2210 
2211   SBError sb_error;
2212 
2213   TargetSP target_sp(GetSP());
2214   if (target_sp) {
2215     if (!section.IsValid()) {
2216       sb_error.SetErrorStringWithFormat("invalid section");
2217     } else {
2218       SectionSP section_sp(section.GetSP());
2219       if (section_sp) {
2220         ProcessSP process_sp(target_sp->GetProcessSP());
2221         if (target_sp->SetSectionUnloaded(section_sp)) {
2222           ModuleSP module_sp(section_sp->GetModule());
2223           if (module_sp) {
2224             ModuleList module_list;
2225             module_list.Append(module_sp);
2226             target_sp->ModulesDidUnload(module_list, false);
2227           }
2228           // Flush info in the process (stack frames, etc)
2229           if (process_sp)
2230             process_sp->Flush();
2231         }
2232       } else {
2233         sb_error.SetErrorStringWithFormat("invalid section");
2234       }
2235     }
2236   } else {
2237     sb_error.SetErrorStringWithFormat("invalid target");
2238   }
2239   return LLDB_RECORD_RESULT(sb_error);
2240 }
2241 
SetModuleLoadAddress(lldb::SBModule module,int64_t slide_offset)2242 SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module,
2243                                        int64_t slide_offset) {
2244   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, SetModuleLoadAddress,
2245                      (lldb::SBModule, int64_t), module, slide_offset);
2246 
2247   SBError sb_error;
2248 
2249   TargetSP target_sp(GetSP());
2250   if (target_sp) {
2251     ModuleSP module_sp(module.GetSP());
2252     if (module_sp) {
2253       bool changed = false;
2254       if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) {
2255         // The load was successful, make sure that at least some sections
2256         // changed before we notify that our module was loaded.
2257         if (changed) {
2258           ModuleList module_list;
2259           module_list.Append(module_sp);
2260           target_sp->ModulesDidLoad(module_list);
2261           // Flush info in the process (stack frames, etc)
2262           ProcessSP process_sp(target_sp->GetProcessSP());
2263           if (process_sp)
2264             process_sp->Flush();
2265         }
2266       }
2267     } else {
2268       sb_error.SetErrorStringWithFormat("invalid module");
2269     }
2270 
2271   } else {
2272     sb_error.SetErrorStringWithFormat("invalid target");
2273   }
2274   return LLDB_RECORD_RESULT(sb_error);
2275 }
2276 
ClearModuleLoadAddress(lldb::SBModule module)2277 SBError SBTarget::ClearModuleLoadAddress(lldb::SBModule module) {
2278   LLDB_RECORD_METHOD(lldb::SBError, SBTarget, ClearModuleLoadAddress,
2279                      (lldb::SBModule), module);
2280 
2281   SBError sb_error;
2282 
2283   char path[PATH_MAX];
2284   TargetSP target_sp(GetSP());
2285   if (target_sp) {
2286     ModuleSP module_sp(module.GetSP());
2287     if (module_sp) {
2288       ObjectFile *objfile = module_sp->GetObjectFile();
2289       if (objfile) {
2290         SectionList *section_list = objfile->GetSectionList();
2291         if (section_list) {
2292           ProcessSP process_sp(target_sp->GetProcessSP());
2293 
2294           bool changed = false;
2295           const size_t num_sections = section_list->GetSize();
2296           for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
2297             SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
2298             if (section_sp)
2299               changed |= target_sp->SetSectionUnloaded(section_sp);
2300           }
2301           if (changed) {
2302             ModuleList module_list;
2303             module_list.Append(module_sp);
2304             target_sp->ModulesDidUnload(module_list, false);
2305             // Flush info in the process (stack frames, etc)
2306             ProcessSP process_sp(target_sp->GetProcessSP());
2307             if (process_sp)
2308               process_sp->Flush();
2309           }
2310         } else {
2311           module_sp->GetFileSpec().GetPath(path, sizeof(path));
2312           sb_error.SetErrorStringWithFormat("no sections in object file '%s'",
2313                                             path);
2314         }
2315       } else {
2316         module_sp->GetFileSpec().GetPath(path, sizeof(path));
2317         sb_error.SetErrorStringWithFormat("no object file for module '%s'",
2318                                           path);
2319       }
2320     } else {
2321       sb_error.SetErrorStringWithFormat("invalid module");
2322     }
2323   } else {
2324     sb_error.SetErrorStringWithFormat("invalid target");
2325   }
2326   return LLDB_RECORD_RESULT(sb_error);
2327 }
2328 
FindSymbols(const char * name,lldb::SymbolType symbol_type)2329 lldb::SBSymbolContextList SBTarget::FindSymbols(const char *name,
2330                                                 lldb::SymbolType symbol_type) {
2331   LLDB_RECORD_METHOD(lldb::SBSymbolContextList, SBTarget, FindSymbols,
2332                      (const char *, lldb::SymbolType), name, symbol_type);
2333 
2334   SBSymbolContextList sb_sc_list;
2335   if (name && name[0]) {
2336     TargetSP target_sp(GetSP());
2337     if (target_sp)
2338       target_sp->GetImages().FindSymbolsWithNameAndType(
2339           ConstString(name), symbol_type, *sb_sc_list);
2340   }
2341   return LLDB_RECORD_RESULT(sb_sc_list);
2342 }
2343 
EvaluateExpression(const char * expr)2344 lldb::SBValue SBTarget::EvaluateExpression(const char *expr) {
2345   LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
2346                      (const char *), expr);
2347 
2348   TargetSP target_sp(GetSP());
2349   if (!target_sp)
2350     return LLDB_RECORD_RESULT(SBValue());
2351 
2352   SBExpressionOptions options;
2353   lldb::DynamicValueType fetch_dynamic_value =
2354       target_sp->GetPreferDynamicValue();
2355   options.SetFetchDynamicValue(fetch_dynamic_value);
2356   options.SetUnwindOnError(true);
2357   return LLDB_RECORD_RESULT(EvaluateExpression(expr, options));
2358 }
2359 
EvaluateExpression(const char * expr,const SBExpressionOptions & options)2360 lldb::SBValue SBTarget::EvaluateExpression(const char *expr,
2361                                            const SBExpressionOptions &options) {
2362   LLDB_RECORD_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
2363                      (const char *, const lldb::SBExpressionOptions &), expr,
2364                      options);
2365 
2366   Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
2367   SBValue expr_result;
2368   ValueObjectSP expr_value_sp;
2369   TargetSP target_sp(GetSP());
2370   StackFrame *frame = nullptr;
2371   if (target_sp) {
2372     if (expr == nullptr || expr[0] == '\0') {
2373       return LLDB_RECORD_RESULT(expr_result);
2374     }
2375 
2376     std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
2377     ExecutionContext exe_ctx(m_opaque_sp.get());
2378 
2379 
2380     frame = exe_ctx.GetFramePtr();
2381     Target *target = exe_ctx.GetTargetPtr();
2382 
2383     if (target) {
2384       target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
2385 
2386       expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
2387     }
2388   }
2389   LLDB_LOGF(expr_log,
2390             "** [SBTarget::EvaluateExpression] Expression result is "
2391             "%s, summary %s **",
2392             expr_result.GetValue(), expr_result.GetSummary());
2393   return LLDB_RECORD_RESULT(expr_result);
2394 }
2395 
GetStackRedZoneSize()2396 lldb::addr_t SBTarget::GetStackRedZoneSize() {
2397   LLDB_RECORD_METHOD_NO_ARGS(lldb::addr_t, SBTarget, GetStackRedZoneSize);
2398 
2399   TargetSP target_sp(GetSP());
2400   if (target_sp) {
2401     ABISP abi_sp;
2402     ProcessSP process_sp(target_sp->GetProcessSP());
2403     if (process_sp)
2404       abi_sp = process_sp->GetABI();
2405     else
2406       abi_sp = ABI::FindPlugin(ProcessSP(), target_sp->GetArchitecture());
2407     if (abi_sp)
2408       return abi_sp->GetRedZoneSize();
2409   }
2410   return 0;
2411 }
2412 
GetLaunchInfo() const2413 lldb::SBLaunchInfo SBTarget::GetLaunchInfo() const {
2414   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo);
2415 
2416   lldb::SBLaunchInfo launch_info(nullptr);
2417   TargetSP target_sp(GetSP());
2418   if (target_sp)
2419     launch_info.set_ref(m_opaque_sp->GetProcessLaunchInfo());
2420   return LLDB_RECORD_RESULT(launch_info);
2421 }
2422 
SetLaunchInfo(const lldb::SBLaunchInfo & launch_info)2423 void SBTarget::SetLaunchInfo(const lldb::SBLaunchInfo &launch_info) {
2424   LLDB_RECORD_METHOD(void, SBTarget, SetLaunchInfo,
2425                      (const lldb::SBLaunchInfo &), launch_info);
2426 
2427   TargetSP target_sp(GetSP());
2428   if (target_sp)
2429     m_opaque_sp->SetProcessLaunchInfo(launch_info.ref());
2430 }
2431 
GetEnvironment()2432 SBEnvironment SBTarget::GetEnvironment() {
2433   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBEnvironment, SBTarget, GetEnvironment);
2434   TargetSP target_sp(GetSP());
2435 
2436   if (target_sp) {
2437     return LLDB_RECORD_RESULT(SBEnvironment(target_sp->GetEnvironment()));
2438   }
2439 
2440   return LLDB_RECORD_RESULT(SBEnvironment());
2441 }
2442 
2443 namespace lldb_private {
2444 namespace repro {
2445 
2446 template <>
RegisterMethods(Registry & R)2447 void RegisterMethods<SBTarget>(Registry &R) {
2448   LLDB_REGISTER_CONSTRUCTOR(SBTarget, ());
2449   LLDB_REGISTER_CONSTRUCTOR(SBTarget, (const lldb::SBTarget &));
2450   LLDB_REGISTER_CONSTRUCTOR(SBTarget, (const lldb::TargetSP &));
2451   LLDB_REGISTER_METHOD(const lldb::SBTarget &,
2452                        SBTarget, operator=,(const lldb::SBTarget &));
2453   LLDB_REGISTER_STATIC_METHOD(bool, SBTarget, EventIsTargetEvent,
2454                               (const lldb::SBEvent &));
2455   LLDB_REGISTER_STATIC_METHOD(lldb::SBTarget, SBTarget, GetTargetFromEvent,
2456                               (const lldb::SBEvent &));
2457   LLDB_REGISTER_STATIC_METHOD(uint32_t, SBTarget, GetNumModulesFromEvent,
2458                               (const lldb::SBEvent &));
2459   LLDB_REGISTER_STATIC_METHOD(lldb::SBModule, SBTarget,
2460                               GetModuleAtIndexFromEvent,
2461                               (const uint32_t, const lldb::SBEvent &));
2462   LLDB_REGISTER_STATIC_METHOD(const char *, SBTarget, GetBroadcasterClassName,
2463                               ());
2464   LLDB_REGISTER_METHOD_CONST(bool, SBTarget, IsValid, ());
2465   LLDB_REGISTER_METHOD_CONST(bool, SBTarget, operator bool, ());
2466   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, GetProcess, ());
2467   LLDB_REGISTER_METHOD(lldb::SBPlatform, SBTarget, GetPlatform, ());
2468   LLDB_REGISTER_METHOD_CONST(lldb::SBDebugger, SBTarget, GetDebugger, ());
2469   LLDB_REGISTER_METHOD(lldb::SBStructuredData, SBTarget, GetStatistics, ());
2470   LLDB_REGISTER_METHOD(void, SBTarget, SetCollectingStats, (bool));
2471   LLDB_REGISTER_METHOD(bool, SBTarget, GetCollectingStats, ());
2472   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, LoadCore, (const char *));
2473   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, LoadCore,
2474                        (const char *, lldb::SBError &));
2475   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, LaunchSimple,
2476                        (const char **, const char **, const char *));
2477   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, Install, ());
2478   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, Launch,
2479                        (lldb::SBListener &, const char **, const char **,
2480                         const char *, const char *, const char *,
2481                         const char *, uint32_t, bool, lldb::SBError &));
2482   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, Launch,
2483                        (lldb::SBLaunchInfo &, lldb::SBError &));
2484   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, Attach,
2485                        (lldb::SBAttachInfo &, lldb::SBError &));
2486   LLDB_REGISTER_METHOD(lldb::SBProcess, SBTarget, AttachToProcessWithID,
2487                        (lldb::SBListener &, lldb::pid_t, lldb::SBError &));
2488   LLDB_REGISTER_METHOD(
2489       lldb::SBProcess, SBTarget, AttachToProcessWithName,
2490       (lldb::SBListener &, const char *, bool, lldb::SBError &));
2491   LLDB_REGISTER_METHOD(
2492       lldb::SBProcess, SBTarget, ConnectRemote,
2493       (lldb::SBListener &, const char *, const char *, lldb::SBError &));
2494   LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBTarget, GetExecutable, ());
2495   LLDB_REGISTER_METHOD_CONST(bool,
2496                              SBTarget, operator==,(const lldb::SBTarget &));
2497   LLDB_REGISTER_METHOD_CONST(bool,
2498                              SBTarget, operator!=,(const lldb::SBTarget &));
2499   LLDB_REGISTER_METHOD(lldb::SBAddress, SBTarget, ResolveLoadAddress,
2500                        (lldb::addr_t));
2501   LLDB_REGISTER_METHOD(lldb::SBAddress, SBTarget, ResolveFileAddress,
2502                        (lldb::addr_t));
2503   LLDB_REGISTER_METHOD(lldb::SBAddress, SBTarget, ResolvePastLoadAddress,
2504                        (uint32_t, lldb::addr_t));
2505   LLDB_REGISTER_METHOD(lldb::SBSymbolContext, SBTarget,
2506                        ResolveSymbolContextForAddress,
2507                        (const lldb::SBAddress &, uint32_t));
2508   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2509                        BreakpointCreateByLocation, (const char *, uint32_t));
2510   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2511                        BreakpointCreateByLocation,
2512                        (const lldb::SBFileSpec &, uint32_t));
2513   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2514                        BreakpointCreateByLocation,
2515                        (const lldb::SBFileSpec &, uint32_t, lldb::addr_t));
2516   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2517                        BreakpointCreateByLocation,
2518                        (const lldb::SBFileSpec &, uint32_t, lldb::addr_t,
2519                         lldb::SBFileSpecList &));
2520   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2521                        BreakpointCreateByLocation,
2522                        (const lldb::SBFileSpec &, uint32_t, uint32_t,
2523                         lldb::addr_t, lldb::SBFileSpecList &));
2524   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByLocation,
2525                        (const lldb::SBFileSpec &, uint32_t, uint32_t,
2526                         lldb::addr_t, lldb::SBFileSpecList &, bool));
2527   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
2528                        (const char *, const char *));
2529   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
2530                        (const char *, const lldb::SBFileSpecList &,
2531                         const lldb::SBFileSpecList &));
2532   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
2533                        (const char *, uint32_t, const lldb::SBFileSpecList &,
2534                         const lldb::SBFileSpecList &));
2535   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByName,
2536                        (const char *, uint32_t, lldb::LanguageType,
2537                         const lldb::SBFileSpecList &,
2538                         const lldb::SBFileSpecList &));
2539   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
2540                        (const char **, uint32_t, uint32_t,
2541                         const lldb::SBFileSpecList &,
2542                         const lldb::SBFileSpecList &));
2543   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
2544                        (const char **, uint32_t, uint32_t, lldb::LanguageType,
2545                         const lldb::SBFileSpecList &,
2546                         const lldb::SBFileSpecList &));
2547   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByNames,
2548                        (const char **, uint32_t, uint32_t, lldb::LanguageType,
2549                         lldb::addr_t, const lldb::SBFileSpecList &,
2550                         const lldb::SBFileSpecList &));
2551   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
2552                        (const char *, const char *));
2553   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
2554                        (const char *, const lldb::SBFileSpecList &,
2555                         const lldb::SBFileSpecList &));
2556   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, BreakpointCreateByRegex,
2557                        (const char *, lldb::LanguageType,
2558                         const lldb::SBFileSpecList &,
2559                         const lldb::SBFileSpecList &));
2560   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2561                        BreakpointCreateByAddress, (lldb::addr_t));
2562   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2563                        BreakpointCreateBySBAddress, (lldb::SBAddress &));
2564   LLDB_REGISTER_METHOD(
2565       lldb::SBBreakpoint, SBTarget, BreakpointCreateBySourceRegex,
2566       (const char *, const lldb::SBFileSpec &, const char *));
2567   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2568                        BreakpointCreateBySourceRegex,
2569                        (const char *, const lldb::SBFileSpecList &,
2570                         const lldb::SBFileSpecList &));
2571   LLDB_REGISTER_METHOD(
2572       lldb::SBBreakpoint, SBTarget, BreakpointCreateBySourceRegex,
2573       (const char *, const lldb::SBFileSpecList &,
2574        const lldb::SBFileSpecList &, const lldb::SBStringList &));
2575   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget,
2576                        BreakpointCreateForException,
2577                        (lldb::LanguageType, bool, bool));
2578   LLDB_REGISTER_METHOD(
2579       lldb::SBBreakpoint, SBTarget, BreakpointCreateFromScript,
2580       (const char *, lldb::SBStructuredData &, const lldb::SBFileSpecList &,
2581        const lldb::SBFileSpecList &, bool));
2582   LLDB_REGISTER_METHOD_CONST(uint32_t, SBTarget, GetNumBreakpoints, ());
2583   LLDB_REGISTER_METHOD_CONST(lldb::SBBreakpoint, SBTarget,
2584                              GetBreakpointAtIndex, (uint32_t));
2585   LLDB_REGISTER_METHOD(bool, SBTarget, BreakpointDelete, (lldb::break_id_t));
2586   LLDB_REGISTER_METHOD(lldb::SBBreakpoint, SBTarget, FindBreakpointByID,
2587                        (lldb::break_id_t));
2588   LLDB_REGISTER_METHOD(bool, SBTarget, FindBreakpointsByName,
2589                        (const char *, lldb::SBBreakpointList &));
2590   LLDB_REGISTER_METHOD(void, SBTarget, GetBreakpointNames,
2591                        (lldb::SBStringList &));
2592   LLDB_REGISTER_METHOD(void, SBTarget, DeleteBreakpointName, (const char *));
2593   LLDB_REGISTER_METHOD(bool, SBTarget, EnableAllBreakpoints, ());
2594   LLDB_REGISTER_METHOD(bool, SBTarget, DisableAllBreakpoints, ());
2595   LLDB_REGISTER_METHOD(bool, SBTarget, DeleteAllBreakpoints, ());
2596   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, BreakpointsCreateFromFile,
2597                        (lldb::SBFileSpec &, lldb::SBBreakpointList &));
2598   LLDB_REGISTER_METHOD(
2599       lldb::SBError, SBTarget, BreakpointsCreateFromFile,
2600       (lldb::SBFileSpec &, lldb::SBStringList &, lldb::SBBreakpointList &));
2601   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
2602                        (lldb::SBFileSpec &));
2603   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, BreakpointsWriteToFile,
2604                        (lldb::SBFileSpec &, lldb::SBBreakpointList &, bool));
2605   LLDB_REGISTER_METHOD_CONST(uint32_t, SBTarget, GetNumWatchpoints, ());
2606   LLDB_REGISTER_METHOD_CONST(lldb::SBWatchpoint, SBTarget,
2607                              GetWatchpointAtIndex, (uint32_t));
2608   LLDB_REGISTER_METHOD(bool, SBTarget, DeleteWatchpoint, (lldb::watch_id_t));
2609   LLDB_REGISTER_METHOD(lldb::SBWatchpoint, SBTarget, FindWatchpointByID,
2610                        (lldb::watch_id_t));
2611   LLDB_REGISTER_METHOD(lldb::SBWatchpoint, SBTarget, WatchAddress,
2612                        (lldb::addr_t, size_t, bool, bool, lldb::SBError &));
2613   LLDB_REGISTER_METHOD(bool, SBTarget, EnableAllWatchpoints, ());
2614   LLDB_REGISTER_METHOD(bool, SBTarget, DisableAllWatchpoints, ());
2615   LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromAddress,
2616                        (const char *, lldb::SBAddress, lldb::SBType));
2617   LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromData,
2618                        (const char *, lldb::SBData, lldb::SBType));
2619   LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, CreateValueFromExpression,
2620                        (const char *, const char *));
2621   LLDB_REGISTER_METHOD(bool, SBTarget, DeleteAllWatchpoints, ());
2622   LLDB_REGISTER_METHOD(void, SBTarget, AppendImageSearchPath,
2623                        (const char *, const char *, lldb::SBError &));
2624   LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, AddModule,
2625                        (const char *, const char *, const char *));
2626   LLDB_REGISTER_METHOD(
2627       lldb::SBModule, SBTarget, AddModule,
2628       (const char *, const char *, const char *, const char *));
2629   LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, AddModule,
2630                        (const lldb::SBModuleSpec &));
2631   LLDB_REGISTER_METHOD(bool, SBTarget, AddModule, (lldb::SBModule &));
2632   LLDB_REGISTER_METHOD_CONST(uint32_t, SBTarget, GetNumModules, ());
2633   LLDB_REGISTER_METHOD(void, SBTarget, Clear, ());
2634   LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, FindModule,
2635                        (const lldb::SBFileSpec &));
2636   LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget, FindCompileUnits,
2637                        (const lldb::SBFileSpec &));
2638   LLDB_REGISTER_METHOD(lldb::ByteOrder, SBTarget, GetByteOrder, ());
2639   LLDB_REGISTER_METHOD(const char *, SBTarget, GetTriple, ());
2640   LLDB_REGISTER_METHOD(uint32_t, SBTarget, GetDataByteSize, ());
2641   LLDB_REGISTER_METHOD(uint32_t, SBTarget, GetCodeByteSize, ());
2642   LLDB_REGISTER_METHOD(uint32_t, SBTarget, GetAddressByteSize, ());
2643   LLDB_REGISTER_METHOD(lldb::SBModule, SBTarget, GetModuleAtIndex,
2644                        (uint32_t));
2645   LLDB_REGISTER_METHOD(bool, SBTarget, RemoveModule, (lldb::SBModule));
2646   LLDB_REGISTER_METHOD_CONST(lldb::SBBroadcaster, SBTarget, GetBroadcaster,
2647                              ());
2648   LLDB_REGISTER_METHOD(bool, SBTarget, GetDescription,
2649                        (lldb::SBStream &, lldb::DescriptionLevel));
2650   LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget, FindFunctions,
2651                        (const char *, uint32_t));
2652   LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget,
2653                        FindGlobalFunctions,
2654                        (const char *, uint32_t, lldb::MatchType));
2655   LLDB_REGISTER_METHOD(lldb::SBType, SBTarget, FindFirstType, (const char *));
2656   LLDB_REGISTER_METHOD(lldb::SBType, SBTarget, GetBasicType,
2657                        (lldb::BasicType));
2658   LLDB_REGISTER_METHOD(lldb::SBTypeList, SBTarget, FindTypes, (const char *));
2659   LLDB_REGISTER_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
2660                        (const char *, uint32_t));
2661   LLDB_REGISTER_METHOD(lldb::SBValueList, SBTarget, FindGlobalVariables,
2662                        (const char *, uint32_t, lldb::MatchType));
2663   LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, FindFirstGlobalVariable,
2664                        (const char *));
2665   LLDB_REGISTER_METHOD(lldb::SBSourceManager, SBTarget, GetSourceManager, ());
2666   LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
2667                        (lldb::SBAddress, uint32_t));
2668   LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, ReadInstructions,
2669                        (lldb::SBAddress, uint32_t, const char *));
2670   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, SetSectionLoadAddress,
2671                        (lldb::SBSection, lldb::addr_t));
2672   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, ClearSectionLoadAddress,
2673                        (lldb::SBSection));
2674   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, SetModuleLoadAddress,
2675                        (lldb::SBModule, int64_t));
2676   LLDB_REGISTER_METHOD(lldb::SBError, SBTarget, ClearModuleLoadAddress,
2677                        (lldb::SBModule));
2678   LLDB_REGISTER_METHOD(lldb::SBSymbolContextList, SBTarget, FindSymbols,
2679                        (const char *, lldb::SymbolType));
2680   LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
2681                        (const char *));
2682   LLDB_REGISTER_METHOD(lldb::SBValue, SBTarget, EvaluateExpression,
2683                        (const char *, const lldb::SBExpressionOptions &));
2684   LLDB_REGISTER_METHOD(lldb::addr_t, SBTarget, GetStackRedZoneSize, ());
2685   LLDB_REGISTER_METHOD_CONST(lldb::SBLaunchInfo, SBTarget, GetLaunchInfo, ());
2686   LLDB_REGISTER_METHOD(void, SBTarget, SetLaunchInfo,
2687                        (const lldb::SBLaunchInfo &));
2688   LLDB_REGISTER_METHOD(
2689       size_t, SBTarget, ReadMemory,
2690       (const lldb::SBAddress, void *, size_t, lldb::SBError &));
2691   LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions,
2692                        (lldb::SBAddress, const void *, size_t));
2693   LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget,
2694                        GetInstructionsWithFlavor,
2695                        (lldb::SBAddress, const char *, const void *, size_t));
2696   LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget, GetInstructions,
2697                        (lldb::addr_t, const void *, size_t));
2698   LLDB_REGISTER_METHOD(lldb::SBInstructionList, SBTarget,
2699                        GetInstructionsWithFlavor,
2700                        (lldb::addr_t, const char *, const void *, size_t));
2701   LLDB_REGISTER_METHOD(lldb::SBEnvironment, SBTarget, GetEnvironment, ());
2702 }
2703 
2704 }
2705 }
2706