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