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