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