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