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