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