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