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