1 //===-- SBDebugger.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 "SBReproducerPrivate.h"
10 #include "SystemInitializerFull.h"
11 
12 #include "lldb/API/SBDebugger.h"
13 
14 #include "lldb/lldb-private.h"
15 
16 #include "lldb/API/SBBroadcaster.h"
17 #include "lldb/API/SBCommandInterpreter.h"
18 #include "lldb/API/SBCommandReturnObject.h"
19 #include "lldb/API/SBError.h"
20 #include "lldb/API/SBEvent.h"
21 #include "lldb/API/SBFrame.h"
22 #include "lldb/API/SBListener.h"
23 #include "lldb/API/SBProcess.h"
24 #include "lldb/API/SBSourceManager.h"
25 #include "lldb/API/SBStream.h"
26 #include "lldb/API/SBStringList.h"
27 #include "lldb/API/SBStructuredData.h"
28 #include "lldb/API/SBTarget.h"
29 #include "lldb/API/SBThread.h"
30 #include "lldb/API/SBTypeCategory.h"
31 #include "lldb/API/SBTypeFilter.h"
32 #include "lldb/API/SBTypeFormat.h"
33 #include "lldb/API/SBTypeNameSpecifier.h"
34 #include "lldb/API/SBTypeSummary.h"
35 #include "lldb/API/SBTypeSynthetic.h"
36 
37 #include "lldb/Core/Debugger.h"
38 #include "lldb/Core/PluginManager.h"
39 #include "lldb/Core/StreamFile.h"
40 #include "lldb/Core/StructuredDataImpl.h"
41 #include "lldb/DataFormatters/DataVisualization.h"
42 #include "lldb/Host/XML.h"
43 #include "lldb/Initialization/SystemLifetimeManager.h"
44 #include "lldb/Interpreter/CommandInterpreter.h"
45 #include "lldb/Interpreter/OptionArgParser.h"
46 #include "lldb/Interpreter/OptionGroupPlatform.h"
47 #include "lldb/Target/Process.h"
48 #include "lldb/Target/TargetList.h"
49 #include "lldb/Utility/Args.h"
50 #include "lldb/Utility/State.h"
51 
52 #include "llvm/ADT/STLExtras.h"
53 #include "llvm/ADT/StringRef.h"
54 #include "llvm/Support/DynamicLibrary.h"
55 #include "llvm/Support/ManagedStatic.h"
56 
57 using namespace lldb;
58 using namespace lldb_private;
59 
60 /// Helper class for replaying commands through the reproducer.
61 class CommandLoader {
62 public:
63   CommandLoader(std::vector<std::string> files) : m_files(files) {}
64 
65   static std::unique_ptr<CommandLoader> Create() {
66     repro::Loader *loader = repro::Reproducer::Instance().GetLoader();
67     if (!loader)
68       return {};
69 
70     FileSpec file = loader->GetFile<repro::CommandProvider::Info>();
71     if (!file)
72       return {};
73 
74     auto error_or_file = llvm::MemoryBuffer::getFile(file.GetPath());
75     if (auto err = error_or_file.getError())
76       return {};
77 
78     std::vector<std::string> files;
79     llvm::yaml::Input yin((*error_or_file)->getBuffer());
80     yin >> files;
81 
82     if (auto err = yin.error())
83       return {};
84 
85     for (auto &file : files) {
86       FileSpec absolute_path =
87           loader->GetRoot().CopyByAppendingPathComponent(file);
88       file = absolute_path.GetPath();
89     }
90 
91     return std::make_unique<CommandLoader>(std::move(files));
92   }
93 
94   FILE *GetNextFile() {
95     if (m_index >= m_files.size())
96       return nullptr;
97     return FileSystem::Instance().Fopen(m_files[m_index++].c_str(), "r");
98   }
99 
100 private:
101   std::vector<std::string> m_files;
102   unsigned m_index = 0;
103 };
104 
105 static llvm::sys::DynamicLibrary LoadPlugin(const lldb::DebuggerSP &debugger_sp,
106                                             const FileSpec &spec,
107                                             Status &error) {
108   llvm::sys::DynamicLibrary dynlib =
109       llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
110   if (dynlib.isValid()) {
111     typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger & debugger);
112 
113     lldb::SBDebugger debugger_sb(debugger_sp);
114     // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger)
115     // function.
116     // TODO: mangle this differently for your system - on OSX, the first
117     // underscore needs to be removed and the second one stays
118     LLDBCommandPluginInit init_func =
119         (LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol(
120             "_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
121     if (init_func) {
122       if (init_func(debugger_sb))
123         return dynlib;
124       else
125         error.SetErrorString("plug-in refused to load "
126                              "(lldb::PluginInitialize(lldb::SBDebugger) "
127                              "returned false)");
128     } else {
129       error.SetErrorString("plug-in is missing the required initialization: "
130                            "lldb::PluginInitialize(lldb::SBDebugger)");
131     }
132   } else {
133     if (FileSystem::Instance().Exists(spec))
134       error.SetErrorString("this file does not represent a loadable dylib");
135     else
136       error.SetErrorString("no such file");
137   }
138   return llvm::sys::DynamicLibrary();
139 }
140 
141 static llvm::ManagedStatic<SystemLifetimeManager> g_debugger_lifetime;
142 
143 SBError SBInputReader::Initialize(
144     lldb::SBDebugger &sb_debugger,
145     unsigned long (*callback)(void *, lldb::SBInputReader *,
146                               lldb::InputReaderAction, char const *,
147                               unsigned long),
148     void *a, lldb::InputReaderGranularity b, char const *c, char const *d,
149     bool e) {
150   LLDB_RECORD_DUMMY(
151       lldb::SBError, SBInputReader, Initialize,
152       (lldb::SBDebugger &,
153        unsigned long (*)(void *, lldb::SBInputReader *, lldb::InputReaderAction,
154                          const char *, unsigned long),
155        void *, lldb::InputReaderGranularity, const char *, const char *, bool),
156       sb_debugger, callback, a, b, c, d, e);
157 
158   return SBError();
159 }
160 
161 void SBInputReader::SetIsDone(bool b) {
162   LLDB_RECORD_METHOD(void, SBInputReader, SetIsDone, (bool), b);
163 }
164 
165 bool SBInputReader::IsActive() const {
166   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBInputReader, IsActive);
167 
168   return false;
169 }
170 
171 SBDebugger::SBDebugger() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBDebugger); }
172 
173 SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp)
174     : m_opaque_sp(debugger_sp) {
175   LLDB_RECORD_CONSTRUCTOR(SBDebugger, (const lldb::DebuggerSP &), debugger_sp);
176 }
177 
178 SBDebugger::SBDebugger(const SBDebugger &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
179   LLDB_RECORD_CONSTRUCTOR(SBDebugger, (const lldb::SBDebugger &), rhs);
180 }
181 
182 SBDebugger::~SBDebugger() = default;
183 
184 SBDebugger &SBDebugger::operator=(const SBDebugger &rhs) {
185   LLDB_RECORD_METHOD(lldb::SBDebugger &,
186                      SBDebugger, operator=,(const lldb::SBDebugger &), rhs);
187 
188   if (this != &rhs) {
189     m_opaque_sp = rhs.m_opaque_sp;
190   }
191   return LLDB_RECORD_RESULT(*this);
192 }
193 
194 void SBDebugger::Initialize() {
195   LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, Initialize);
196   SBError ignored = SBDebugger::InitializeWithErrorHandling();
197 }
198 
199 lldb::SBError SBDebugger::InitializeWithErrorHandling() {
200   LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBError, SBDebugger,
201                                     InitializeWithErrorHandling);
202 
203 
204 
205   SBError error;
206   if (auto e = g_debugger_lifetime->Initialize(
207           std::make_unique<SystemInitializerFull>(), LoadPlugin)) {
208     error.SetError(Status(std::move(e)));
209   }
210   return LLDB_RECORD_RESULT(error);
211 }
212 
213 void SBDebugger::Terminate() {
214   LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, Terminate);
215 
216   g_debugger_lifetime->Terminate();
217 }
218 
219 void SBDebugger::Clear() {
220   LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, Clear);
221 
222 
223   if (m_opaque_sp)
224     m_opaque_sp->ClearIOHandlers();
225 
226   m_opaque_sp.reset();
227 }
228 
229 SBDebugger SBDebugger::Create() {
230   LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBDebugger, SBDebugger, Create);
231 
232   return LLDB_RECORD_RESULT(SBDebugger::Create(false, nullptr, nullptr));
233 }
234 
235 SBDebugger SBDebugger::Create(bool source_init_files) {
236   LLDB_RECORD_STATIC_METHOD(lldb::SBDebugger, SBDebugger, Create, (bool),
237                             source_init_files);
238 
239   return LLDB_RECORD_RESULT(
240       SBDebugger::Create(source_init_files, nullptr, nullptr));
241 }
242 
243 SBDebugger SBDebugger::Create(bool source_init_files,
244                               lldb::LogOutputCallback callback, void *baton)
245 
246 {
247   LLDB_RECORD_DUMMY(lldb::SBDebugger, SBDebugger, Create,
248                     (bool, lldb::LogOutputCallback, void *), source_init_files,
249                     callback, baton);
250 
251   SBDebugger debugger;
252 
253   // Currently we have issues if this function is called simultaneously on two
254   // different threads. The issues mainly revolve around the fact that the
255   // lldb_private::FormatManager uses global collections and having two threads
256   // parsing the .lldbinit files can cause mayhem. So to get around this for
257   // now we need to use a mutex to prevent bad things from happening.
258   static std::recursive_mutex g_mutex;
259   std::lock_guard<std::recursive_mutex> guard(g_mutex);
260 
261   debugger.reset(Debugger::CreateInstance(callback, baton));
262 
263 
264   SBCommandInterpreter interp = debugger.GetCommandInterpreter();
265   if (source_init_files) {
266     interp.get()->SkipLLDBInitFiles(false);
267     interp.get()->SkipAppInitFiles(false);
268     SBCommandReturnObject result;
269     interp.SourceInitFileInHomeDirectory(result);
270   } else {
271     interp.get()->SkipLLDBInitFiles(true);
272     interp.get()->SkipAppInitFiles(true);
273   }
274   return debugger;
275 }
276 
277 void SBDebugger::Destroy(SBDebugger &debugger) {
278   LLDB_RECORD_STATIC_METHOD(void, SBDebugger, Destroy, (lldb::SBDebugger &),
279                             debugger);
280 
281 
282   Debugger::Destroy(debugger.m_opaque_sp);
283 
284   if (debugger.m_opaque_sp.get() != nullptr)
285     debugger.m_opaque_sp.reset();
286 }
287 
288 void SBDebugger::MemoryPressureDetected() {
289   LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, MemoryPressureDetected);
290 
291   // Since this function can be call asynchronously, we allow it to be non-
292   // mandatory. We have seen deadlocks with this function when called so we
293   // need to safeguard against this until we can determine what is causing the
294   // deadlocks.
295 
296   const bool mandatory = false;
297 
298   ModuleList::RemoveOrphanSharedModules(mandatory);
299 }
300 
301 bool SBDebugger::IsValid() const {
302   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, IsValid);
303   return this->operator bool();
304 }
305 SBDebugger::operator bool() const {
306   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, operator bool);
307 
308   return m_opaque_sp.get() != nullptr;
309 }
310 
311 void SBDebugger::SetAsync(bool b) {
312   LLDB_RECORD_METHOD(void, SBDebugger, SetAsync, (bool), b);
313 
314   if (m_opaque_sp)
315     m_opaque_sp->SetAsyncExecution(b);
316 }
317 
318 bool SBDebugger::GetAsync() {
319   LLDB_RECORD_METHOD_NO_ARGS(bool, SBDebugger, GetAsync);
320 
321   return (m_opaque_sp ? m_opaque_sp->GetAsyncExecution() : false);
322 }
323 
324 void SBDebugger::SkipLLDBInitFiles(bool b) {
325   LLDB_RECORD_METHOD(void, SBDebugger, SkipLLDBInitFiles, (bool), b);
326 
327   if (m_opaque_sp)
328     m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles(b);
329 }
330 
331 void SBDebugger::SkipAppInitFiles(bool b) {
332   LLDB_RECORD_METHOD(void, SBDebugger, SkipAppInitFiles, (bool), b);
333 
334   if (m_opaque_sp)
335     m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles(b);
336 }
337 
338 // Shouldn't really be settable after initialization as this could cause lots
339 // of problems; don't want users trying to switch modes in the middle of a
340 // debugging session.
341 void SBDebugger::SetInputFileHandle(FILE *fh, bool transfer_ownership) {
342   LLDB_RECORD_METHOD(void, SBDebugger, SetInputFileHandle, (FILE *, bool), fh,
343                      transfer_ownership);
344 
345   if (!m_opaque_sp)
346     return;
347 
348   repro::DataRecorder *recorder = nullptr;
349   if (repro::Generator *g = repro::Reproducer::Instance().GetGenerator())
350     recorder = g->GetOrCreate<repro::CommandProvider>().GetNewDataRecorder();
351 
352   static std::unique_ptr<CommandLoader> loader = CommandLoader::Create();
353   if (loader)
354     fh = loader->GetNextFile();
355 
356   m_opaque_sp->SetInputFileHandle(fh, transfer_ownership, recorder);
357 }
358 
359 void SBDebugger::SetOutputFileHandle(FILE *fh, bool transfer_ownership) {
360   LLDB_RECORD_METHOD(void, SBDebugger, SetOutputFileHandle, (FILE *, bool), fh,
361                      transfer_ownership);
362 
363   if (m_opaque_sp)
364     m_opaque_sp->SetOutputFileHandle(fh, transfer_ownership);
365 }
366 
367 void SBDebugger::SetErrorFileHandle(FILE *fh, bool transfer_ownership) {
368   LLDB_RECORD_METHOD(void, SBDebugger, SetErrorFileHandle, (FILE *, bool), fh,
369                      transfer_ownership);
370 
371 
372   if (m_opaque_sp)
373     m_opaque_sp->SetErrorFileHandle(fh, transfer_ownership);
374 }
375 
376 FILE *SBDebugger::GetInputFileHandle() {
377   LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetInputFileHandle);
378 
379   if (m_opaque_sp) {
380     StreamFileSP stream_file_sp(m_opaque_sp->GetInputFile());
381     if (stream_file_sp)
382       return LLDB_RECORD_RESULT(stream_file_sp->GetFile().GetStream());
383   }
384   return nullptr;
385 }
386 
387 FILE *SBDebugger::GetOutputFileHandle() {
388   LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetOutputFileHandle);
389 
390   if (m_opaque_sp) {
391     StreamFileSP stream_file_sp(m_opaque_sp->GetOutputFile());
392     if (stream_file_sp)
393       return LLDB_RECORD_RESULT(stream_file_sp->GetFile().GetStream());
394   }
395   return nullptr;
396 }
397 
398 FILE *SBDebugger::GetErrorFileHandle() {
399   LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetErrorFileHandle);
400 
401   if (m_opaque_sp) {
402     StreamFileSP stream_file_sp(m_opaque_sp->GetErrorFile());
403     if (stream_file_sp)
404       return LLDB_RECORD_RESULT(stream_file_sp->GetFile().GetStream());
405   }
406   return nullptr;
407 }
408 
409 void SBDebugger::SaveInputTerminalState() {
410   LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, SaveInputTerminalState);
411 
412   if (m_opaque_sp)
413     m_opaque_sp->SaveInputTerminalState();
414 }
415 
416 void SBDebugger::RestoreInputTerminalState() {
417   LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, RestoreInputTerminalState);
418 
419   if (m_opaque_sp)
420     m_opaque_sp->RestoreInputTerminalState();
421 }
422 SBCommandInterpreter SBDebugger::GetCommandInterpreter() {
423   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBCommandInterpreter, SBDebugger,
424                              GetCommandInterpreter);
425 
426 
427   SBCommandInterpreter sb_interpreter;
428   if (m_opaque_sp)
429     sb_interpreter.reset(&m_opaque_sp->GetCommandInterpreter());
430 
431 
432   return LLDB_RECORD_RESULT(sb_interpreter);
433 }
434 
435 void SBDebugger::HandleCommand(const char *command) {
436   LLDB_RECORD_METHOD(void, SBDebugger, HandleCommand, (const char *), command);
437 
438   if (m_opaque_sp) {
439     TargetSP target_sp(m_opaque_sp->GetSelectedTarget());
440     std::unique_lock<std::recursive_mutex> lock;
441     if (target_sp)
442       lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
443 
444     SBCommandInterpreter sb_interpreter(GetCommandInterpreter());
445     SBCommandReturnObject result;
446 
447     sb_interpreter.HandleCommand(command, result, false);
448 
449     if (GetErrorFileHandle() != nullptr)
450       result.PutError(GetErrorFileHandle());
451     if (GetOutputFileHandle() != nullptr)
452       result.PutOutput(GetOutputFileHandle());
453 
454     if (!m_opaque_sp->GetAsyncExecution()) {
455       SBProcess process(GetCommandInterpreter().GetProcess());
456       ProcessSP process_sp(process.GetSP());
457       if (process_sp) {
458         EventSP event_sp;
459         ListenerSP lldb_listener_sp = m_opaque_sp->GetListener();
460         while (lldb_listener_sp->GetEventForBroadcaster(
461             process_sp.get(), event_sp, std::chrono::seconds(0))) {
462           SBEvent event(event_sp);
463           HandleProcessEvent(process, event, GetOutputFileHandle(),
464                              GetErrorFileHandle());
465         }
466       }
467     }
468   }
469 }
470 
471 SBListener SBDebugger::GetListener() {
472   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBListener, SBDebugger, GetListener);
473 
474 
475   SBListener sb_listener;
476   if (m_opaque_sp)
477     sb_listener.reset(m_opaque_sp->GetListener());
478 
479 
480   return LLDB_RECORD_RESULT(sb_listener);
481 }
482 
483 void SBDebugger::HandleProcessEvent(const SBProcess &process,
484                                     const SBEvent &event, FILE *out,
485                                     FILE *err) {
486   LLDB_RECORD_METHOD(
487       void, SBDebugger, HandleProcessEvent,
488       (const lldb::SBProcess &, const lldb::SBEvent &, FILE *, FILE *), process,
489       event, out, err);
490 
491   if (!process.IsValid())
492     return;
493 
494   TargetSP target_sp(process.GetTarget().GetSP());
495   if (!target_sp)
496     return;
497 
498   const uint32_t event_type = event.GetType();
499   char stdio_buffer[1024];
500   size_t len;
501 
502   std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
503 
504   if (event_type &
505       (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged)) {
506     // Drain stdout when we stop just in case we have any bytes
507     while ((len = process.GetSTDOUT(stdio_buffer, sizeof(stdio_buffer))) > 0)
508       if (out != nullptr)
509         ::fwrite(stdio_buffer, 1, len, out);
510   }
511 
512   if (event_type &
513       (Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged)) {
514     // Drain stderr when we stop just in case we have any bytes
515     while ((len = process.GetSTDERR(stdio_buffer, sizeof(stdio_buffer))) > 0)
516       if (err != nullptr)
517         ::fwrite(stdio_buffer, 1, len, err);
518   }
519 
520   if (event_type & Process::eBroadcastBitStateChanged) {
521     StateType event_state = SBProcess::GetStateFromEvent(event);
522 
523     if (event_state == eStateInvalid)
524       return;
525 
526     bool is_stopped = StateIsStoppedState(event_state);
527     if (!is_stopped)
528       process.ReportEventState(event, out);
529   }
530 }
531 
532 SBSourceManager SBDebugger::GetSourceManager() {
533   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBSourceManager, SBDebugger,
534                              GetSourceManager);
535 
536   SBSourceManager sb_source_manager(*this);
537   return LLDB_RECORD_RESULT(sb_source_manager);
538 }
539 
540 bool SBDebugger::GetDefaultArchitecture(char *arch_name, size_t arch_name_len) {
541   LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, GetDefaultArchitecture,
542                             (char *, size_t), "", arch_name_len);
543 
544   if (arch_name && arch_name_len) {
545     ArchSpec default_arch = Target::GetDefaultArchitecture();
546 
547     if (default_arch.IsValid()) {
548       const std::string &triple_str = default_arch.GetTriple().str();
549       if (!triple_str.empty())
550         ::snprintf(arch_name, arch_name_len, "%s", triple_str.c_str());
551       else
552         ::snprintf(arch_name, arch_name_len, "%s",
553                    default_arch.GetArchitectureName());
554       return true;
555     }
556   }
557   if (arch_name && arch_name_len)
558     arch_name[0] = '\0';
559   return false;
560 }
561 
562 bool SBDebugger::SetDefaultArchitecture(const char *arch_name) {
563   LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, SetDefaultArchitecture,
564                             (const char *), arch_name);
565 
566   if (arch_name) {
567     ArchSpec arch(arch_name);
568     if (arch.IsValid()) {
569       Target::SetDefaultArchitecture(arch);
570       return true;
571     }
572   }
573   return false;
574 }
575 
576 ScriptLanguage
577 SBDebugger::GetScriptingLanguage(const char *script_language_name) {
578   LLDB_RECORD_METHOD(lldb::ScriptLanguage, SBDebugger, GetScriptingLanguage,
579                      (const char *), script_language_name);
580 
581   if (!script_language_name) return eScriptLanguageDefault;
582   return OptionArgParser::ToScriptLanguage(
583       llvm::StringRef(script_language_name), eScriptLanguageDefault, nullptr);
584 }
585 
586 const char *SBDebugger::GetVersionString() {
587   LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBDebugger, GetVersionString);
588 
589   return lldb_private::GetVersion();
590 }
591 
592 const char *SBDebugger::StateAsCString(StateType state) {
593   LLDB_RECORD_STATIC_METHOD(const char *, SBDebugger, StateAsCString,
594                             (lldb::StateType), state);
595 
596   return lldb_private::StateAsCString(state);
597 }
598 
599 static void AddBoolConfigEntry(StructuredData::Dictionary &dict,
600                                llvm::StringRef name, bool value,
601                                llvm::StringRef description) {
602   auto entry_up = std::make_unique<StructuredData::Dictionary>();
603   entry_up->AddBooleanItem("value", value);
604   entry_up->AddStringItem("description", description);
605   dict.AddItem(name, std::move(entry_up));
606 }
607 
608 static void AddLLVMTargets(StructuredData::Dictionary &dict) {
609   auto array_up = std::make_unique<StructuredData::Array>();
610 #define LLVM_TARGET(target)                                                    \
611   array_up->AddItem(std::make_unique<StructuredData::String>(#target));
612 #include "llvm/Config/Targets.def"
613   auto entry_up = std::make_unique<StructuredData::Dictionary>();
614   entry_up->AddItem("value", std::move(array_up));
615   entry_up->AddStringItem("description", "A list of configured LLVM targets.");
616   dict.AddItem("targets", std::move(entry_up));
617 }
618 
619 SBStructuredData SBDebugger::GetBuildConfiguration() {
620   LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBStructuredData, SBDebugger,
621                                     GetBuildConfiguration);
622 
623   auto config_up = std::make_unique<StructuredData::Dictionary>();
624   AddBoolConfigEntry(
625       *config_up, "xml", XMLDocument::XMLEnabled(),
626       "A boolean value that indicates if XML support is enabled in LLDB");
627   bool have_curses = true;
628 #ifdef LLDB_DISABLE_CURSES
629   have_curses = false;
630 #endif
631   AddBoolConfigEntry(
632       *config_up, "curses", have_curses,
633       "A boolean value that indicates if curses support is enabled in LLDB");
634   AddLLVMTargets(*config_up);
635 
636   SBStructuredData data;
637   data.m_impl_up->SetObjectSP(std::move(config_up));
638   return LLDB_RECORD_RESULT(data);
639 }
640 
641 bool SBDebugger::StateIsRunningState(StateType state) {
642   LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, StateIsRunningState,
643                             (lldb::StateType), state);
644 
645 
646   const bool result = lldb_private::StateIsRunningState(state);
647 
648   return result;
649 }
650 
651 bool SBDebugger::StateIsStoppedState(StateType state) {
652   LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, StateIsStoppedState,
653                             (lldb::StateType), state);
654 
655 
656   const bool result = lldb_private::StateIsStoppedState(state, false);
657 
658   return result;
659 }
660 
661 lldb::SBTarget SBDebugger::CreateTarget(const char *filename,
662                                         const char *target_triple,
663                                         const char *platform_name,
664                                         bool add_dependent_modules,
665                                         lldb::SBError &sb_error) {
666   LLDB_RECORD_METHOD(
667       lldb::SBTarget, SBDebugger, CreateTarget,
668       (const char *, const char *, const char *, bool, lldb::SBError &),
669       filename, target_triple, platform_name, add_dependent_modules, sb_error);
670 
671   SBTarget sb_target;
672   TargetSP target_sp;
673   if (m_opaque_sp) {
674     sb_error.Clear();
675     OptionGroupPlatform platform_options(false);
676     platform_options.SetPlatformName(platform_name);
677 
678     sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget(
679         *m_opaque_sp, filename, target_triple,
680         add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo,
681         &platform_options, target_sp);
682 
683     if (sb_error.Success())
684       sb_target.SetSP(target_sp);
685   } else {
686     sb_error.SetErrorString("invalid debugger");
687   }
688 
689   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
690   LLDB_LOGF(log,
691             "SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, "
692             "platform_name=%s, add_dependent_modules=%u, error=%s) => "
693             "SBTarget(%p)",
694             static_cast<void *>(m_opaque_sp.get()), filename, target_triple,
695             platform_name, add_dependent_modules, sb_error.GetCString(),
696             static_cast<void *>(target_sp.get()));
697 
698   return LLDB_RECORD_RESULT(sb_target);
699 }
700 
701 SBTarget
702 SBDebugger::CreateTargetWithFileAndTargetTriple(const char *filename,
703                                                 const char *target_triple) {
704   LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger,
705                      CreateTargetWithFileAndTargetTriple,
706                      (const char *, const char *), filename, target_triple);
707 
708   SBTarget sb_target;
709   TargetSP target_sp;
710   if (m_opaque_sp) {
711     const bool add_dependent_modules = true;
712     Status error(m_opaque_sp->GetTargetList().CreateTarget(
713         *m_opaque_sp, filename, target_triple,
714         add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,
715         target_sp));
716     sb_target.SetSP(target_sp);
717   }
718 
719   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
720   LLDB_LOGF(log,
721             "SBDebugger(%p)::CreateTargetWithFileAndTargetTriple "
722             "(filename=\"%s\", triple=%s) => SBTarget(%p)",
723             static_cast<void *>(m_opaque_sp.get()), filename, target_triple,
724             static_cast<void *>(target_sp.get()));
725 
726   return LLDB_RECORD_RESULT(sb_target);
727 }
728 
729 SBTarget SBDebugger::CreateTargetWithFileAndArch(const char *filename,
730                                                  const char *arch_cstr) {
731   LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, CreateTargetWithFileAndArch,
732                      (const char *, const char *), filename, arch_cstr);
733 
734   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
735 
736   SBTarget sb_target;
737   TargetSP target_sp;
738   if (m_opaque_sp) {
739     Status error;
740     const bool add_dependent_modules = true;
741 
742     error = m_opaque_sp->GetTargetList().CreateTarget(
743         *m_opaque_sp, filename, arch_cstr,
744         add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,
745         target_sp);
746 
747     if (error.Success()) {
748       m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get());
749       sb_target.SetSP(target_sp);
750     }
751   }
752 
753   LLDB_LOGF(log,
754             "SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", "
755             "arch=%s) => SBTarget(%p)",
756             static_cast<void *>(m_opaque_sp.get()), filename, arch_cstr,
757             static_cast<void *>(target_sp.get()));
758 
759   return LLDB_RECORD_RESULT(sb_target);
760 }
761 
762 SBTarget SBDebugger::CreateTarget(const char *filename) {
763   LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, CreateTarget, (const char *),
764                      filename);
765 
766   SBTarget sb_target;
767   TargetSP target_sp;
768   if (m_opaque_sp) {
769     Status error;
770     const bool add_dependent_modules = true;
771     error = m_opaque_sp->GetTargetList().CreateTarget(
772         *m_opaque_sp, filename, "",
773         add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,
774         target_sp);
775 
776     if (error.Success()) {
777       m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get());
778       sb_target.SetSP(target_sp);
779     }
780   }
781   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
782   LLDB_LOGF(log,
783             "SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
784             static_cast<void *>(m_opaque_sp.get()), filename,
785             static_cast<void *>(target_sp.get()));
786   return LLDB_RECORD_RESULT(sb_target);
787 }
788 
789 SBTarget SBDebugger::GetDummyTarget() {
790   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTarget, SBDebugger, GetDummyTarget);
791 
792   SBTarget sb_target;
793   if (m_opaque_sp) {
794       sb_target.SetSP(m_opaque_sp->GetDummyTarget()->shared_from_this());
795   }
796   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
797   LLDB_LOGF(log, "SBDebugger(%p)::GetDummyTarget() => SBTarget(%p)",
798             static_cast<void *>(m_opaque_sp.get()),
799             static_cast<void *>(sb_target.GetSP().get()));
800   return LLDB_RECORD_RESULT(sb_target);
801 }
802 
803 bool SBDebugger::DeleteTarget(lldb::SBTarget &target) {
804   LLDB_RECORD_METHOD(bool, SBDebugger, DeleteTarget, (lldb::SBTarget &),
805                      target);
806 
807   bool result = false;
808   if (m_opaque_sp) {
809     TargetSP target_sp(target.GetSP());
810     if (target_sp) {
811       // No need to lock, the target list is thread safe
812       result = m_opaque_sp->GetTargetList().DeleteTarget(target_sp);
813       target_sp->Destroy();
814       target.Clear();
815       const bool mandatory = true;
816       ModuleList::RemoveOrphanSharedModules(mandatory);
817     }
818   }
819 
820   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
821   LLDB_LOGF(log, "SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i",
822             static_cast<void *>(m_opaque_sp.get()),
823             static_cast<void *>(target.m_opaque_sp.get()), result);
824 
825   return result;
826 }
827 
828 SBTarget SBDebugger::GetTargetAtIndex(uint32_t idx) {
829   LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, GetTargetAtIndex, (uint32_t),
830                      idx);
831 
832   SBTarget sb_target;
833   if (m_opaque_sp) {
834     // No need to lock, the target list is thread safe
835     sb_target.SetSP(m_opaque_sp->GetTargetList().GetTargetAtIndex(idx));
836   }
837   return LLDB_RECORD_RESULT(sb_target);
838 }
839 
840 uint32_t SBDebugger::GetIndexOfTarget(lldb::SBTarget target) {
841   LLDB_RECORD_METHOD(uint32_t, SBDebugger, GetIndexOfTarget, (lldb::SBTarget),
842                      target);
843 
844   lldb::TargetSP target_sp = target.GetSP();
845   if (!target_sp)
846     return UINT32_MAX;
847 
848   if (!m_opaque_sp)
849     return UINT32_MAX;
850 
851   return m_opaque_sp->GetTargetList().GetIndexOfTarget(target.GetSP());
852 }
853 
854 SBTarget SBDebugger::FindTargetWithProcessID(lldb::pid_t pid) {
855   LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithProcessID,
856                      (lldb::pid_t), pid);
857 
858   SBTarget sb_target;
859   if (m_opaque_sp) {
860     // No need to lock, the target list is thread safe
861     sb_target.SetSP(m_opaque_sp->GetTargetList().FindTargetWithProcessID(pid));
862   }
863   return LLDB_RECORD_RESULT(sb_target);
864 }
865 
866 SBTarget SBDebugger::FindTargetWithFileAndArch(const char *filename,
867                                                const char *arch_name) {
868   LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithFileAndArch,
869                      (const char *, const char *), filename, arch_name);
870 
871   SBTarget sb_target;
872   if (m_opaque_sp && filename && filename[0]) {
873     // No need to lock, the target list is thread safe
874     ArchSpec arch = Platform::GetAugmentedArchSpec(
875         m_opaque_sp->GetPlatformList().GetSelectedPlatform().get(), arch_name);
876     TargetSP target_sp(
877         m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture(
878             FileSpec(filename), arch_name ? &arch : nullptr));
879     sb_target.SetSP(target_sp);
880   }
881   return LLDB_RECORD_RESULT(sb_target);
882 }
883 
884 SBTarget SBDebugger::FindTargetWithLLDBProcess(const ProcessSP &process_sp) {
885   SBTarget sb_target;
886   if (m_opaque_sp) {
887     // No need to lock, the target list is thread safe
888     sb_target.SetSP(
889         m_opaque_sp->GetTargetList().FindTargetWithProcess(process_sp.get()));
890   }
891   return sb_target;
892 }
893 
894 uint32_t SBDebugger::GetNumTargets() {
895   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumTargets);
896 
897   if (m_opaque_sp) {
898     // No need to lock, the target list is thread safe
899     return m_opaque_sp->GetTargetList().GetNumTargets();
900   }
901   return 0;
902 }
903 
904 SBTarget SBDebugger::GetSelectedTarget() {
905   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTarget, SBDebugger, GetSelectedTarget);
906 
907   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
908 
909   SBTarget sb_target;
910   TargetSP target_sp;
911   if (m_opaque_sp) {
912     // No need to lock, the target list is thread safe
913     target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget();
914     sb_target.SetSP(target_sp);
915   }
916 
917   if (log) {
918     SBStream sstr;
919     sb_target.GetDescription(sstr, eDescriptionLevelBrief);
920     LLDB_LOGF(log, "SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s",
921               static_cast<void *>(m_opaque_sp.get()),
922               static_cast<void *>(target_sp.get()), sstr.GetData());
923   }
924 
925   return LLDB_RECORD_RESULT(sb_target);
926 }
927 
928 void SBDebugger::SetSelectedTarget(SBTarget &sb_target) {
929   LLDB_RECORD_METHOD(void, SBDebugger, SetSelectedTarget, (lldb::SBTarget &),
930                      sb_target);
931 
932   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
933 
934   TargetSP target_sp(sb_target.GetSP());
935   if (m_opaque_sp) {
936     m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get());
937   }
938   if (log) {
939     SBStream sstr;
940     sb_target.GetDescription(sstr, eDescriptionLevelBrief);
941     LLDB_LOGF(log, "SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s",
942               static_cast<void *>(m_opaque_sp.get()),
943               static_cast<void *>(target_sp.get()), sstr.GetData());
944   }
945 }
946 
947 SBPlatform SBDebugger::GetSelectedPlatform() {
948   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBPlatform, SBDebugger, GetSelectedPlatform);
949 
950   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
951 
952   SBPlatform sb_platform;
953   DebuggerSP debugger_sp(m_opaque_sp);
954   if (debugger_sp) {
955     sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform());
956   }
957   LLDB_LOGF(log, "SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s",
958             static_cast<void *>(m_opaque_sp.get()),
959             static_cast<void *>(sb_platform.GetSP().get()),
960             sb_platform.GetName());
961   return LLDB_RECORD_RESULT(sb_platform);
962 }
963 
964 void SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform) {
965   LLDB_RECORD_METHOD(void, SBDebugger, SetSelectedPlatform,
966                      (lldb::SBPlatform &), sb_platform);
967 
968   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
969 
970   DebuggerSP debugger_sp(m_opaque_sp);
971   if (debugger_sp) {
972     debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP());
973   }
974 
975   LLDB_LOGF(log, "SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)",
976             static_cast<void *>(m_opaque_sp.get()),
977             static_cast<void *>(sb_platform.GetSP().get()),
978             sb_platform.GetName());
979 }
980 
981 uint32_t SBDebugger::GetNumPlatforms() {
982   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumPlatforms);
983 
984   if (m_opaque_sp) {
985     // No need to lock, the platform list is thread safe
986     return m_opaque_sp->GetPlatformList().GetSize();
987   }
988   return 0;
989 }
990 
991 SBPlatform SBDebugger::GetPlatformAtIndex(uint32_t idx) {
992   LLDB_RECORD_METHOD(lldb::SBPlatform, SBDebugger, GetPlatformAtIndex,
993                      (uint32_t), idx);
994 
995   SBPlatform sb_platform;
996   if (m_opaque_sp) {
997     // No need to lock, the platform list is thread safe
998     sb_platform.SetSP(m_opaque_sp->GetPlatformList().GetAtIndex(idx));
999   }
1000   return LLDB_RECORD_RESULT(sb_platform);
1001 }
1002 
1003 uint32_t SBDebugger::GetNumAvailablePlatforms() {
1004   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumAvailablePlatforms);
1005 
1006   uint32_t idx = 0;
1007   while (true) {
1008     if (!PluginManager::GetPlatformPluginNameAtIndex(idx)) {
1009       break;
1010     }
1011     ++idx;
1012   }
1013   // +1 for the host platform, which should always appear first in the list.
1014   return idx + 1;
1015 }
1016 
1017 SBStructuredData SBDebugger::GetAvailablePlatformInfoAtIndex(uint32_t idx) {
1018   LLDB_RECORD_METHOD(lldb::SBStructuredData, SBDebugger,
1019                      GetAvailablePlatformInfoAtIndex, (uint32_t), idx);
1020 
1021   SBStructuredData data;
1022   auto platform_dict = std::make_unique<StructuredData::Dictionary>();
1023   llvm::StringRef name_str("name"), desc_str("description");
1024 
1025   if (idx == 0) {
1026     PlatformSP host_platform_sp(Platform::GetHostPlatform());
1027     platform_dict->AddStringItem(
1028         name_str, host_platform_sp->GetPluginName().GetStringRef());
1029     platform_dict->AddStringItem(
1030         desc_str, llvm::StringRef(host_platform_sp->GetDescription()));
1031   } else if (idx > 0) {
1032     const char *plugin_name =
1033         PluginManager::GetPlatformPluginNameAtIndex(idx - 1);
1034     if (!plugin_name) {
1035       return LLDB_RECORD_RESULT(data);
1036     }
1037     platform_dict->AddStringItem(name_str, llvm::StringRef(plugin_name));
1038 
1039     const char *plugin_desc =
1040         PluginManager::GetPlatformPluginDescriptionAtIndex(idx - 1);
1041     if (!plugin_desc) {
1042       return LLDB_RECORD_RESULT(data);
1043     }
1044     platform_dict->AddStringItem(desc_str, llvm::StringRef(plugin_desc));
1045   }
1046 
1047   data.m_impl_up->SetObjectSP(
1048       StructuredData::ObjectSP(platform_dict.release()));
1049   return LLDB_RECORD_RESULT(data);
1050 }
1051 
1052 void SBDebugger::DispatchInput(void *baton, const void *data, size_t data_len) {
1053   LLDB_RECORD_DUMMY(void, SBDebugger, DispatchInput,
1054                     (void *, const void *, size_t), baton, data, data_len);
1055 
1056   DispatchInput(data, data_len);
1057 }
1058 
1059 void SBDebugger::DispatchInput(const void *data, size_t data_len) {
1060   LLDB_RECORD_DUMMY(void, SBDebugger, DispatchInput, (const void *, size_t),
1061                     data, data_len);
1062 
1063   //    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1064   //
1065   //    if (log)
1066   //        LLDB_LOGF(log, "SBDebugger(%p)::DispatchInput (data=\"%.*s\",
1067   //        size_t=%" PRIu64 ")",
1068   //                     m_opaque_sp.get(),
1069   //                     (int) data_len,
1070   //                     (const char *) data,
1071   //                     (uint64_t)data_len);
1072   //
1073   //    if (m_opaque_sp)
1074   //        m_opaque_sp->DispatchInput ((const char *) data, data_len);
1075 }
1076 
1077 void SBDebugger::DispatchInputInterrupt() {
1078   LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, DispatchInputInterrupt);
1079 
1080   if (m_opaque_sp)
1081     m_opaque_sp->DispatchInputInterrupt();
1082 }
1083 
1084 void SBDebugger::DispatchInputEndOfFile() {
1085   LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, DispatchInputEndOfFile);
1086 
1087   if (m_opaque_sp)
1088     m_opaque_sp->DispatchInputEndOfFile();
1089 }
1090 
1091 void SBDebugger::PushInputReader(SBInputReader &reader) {
1092   LLDB_RECORD_METHOD(void, SBDebugger, PushInputReader, (lldb::SBInputReader &),
1093                      reader);
1094 }
1095 
1096 void SBDebugger::RunCommandInterpreter(bool auto_handle_events,
1097                                        bool spawn_thread) {
1098   LLDB_RECORD_METHOD(void, SBDebugger, RunCommandInterpreter, (bool, bool),
1099                      auto_handle_events, spawn_thread);
1100 
1101   if (m_opaque_sp) {
1102     CommandInterpreterRunOptions options;
1103 
1104     m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(
1105         auto_handle_events, spawn_thread, options);
1106   }
1107 }
1108 
1109 void SBDebugger::RunCommandInterpreter(bool auto_handle_events,
1110                                        bool spawn_thread,
1111                                        SBCommandInterpreterRunOptions &options,
1112                                        int &num_errors, bool &quit_requested,
1113                                        bool &stopped_for_crash)
1114 
1115 {
1116   LLDB_RECORD_METHOD(void, SBDebugger, RunCommandInterpreter,
1117                      (bool, bool, lldb::SBCommandInterpreterRunOptions &, int &,
1118                       bool &, bool &),
1119                      auto_handle_events, spawn_thread, options, num_errors,
1120                      quit_requested, stopped_for_crash);
1121 
1122   if (m_opaque_sp) {
1123     CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();
1124     interp.RunCommandInterpreter(auto_handle_events, spawn_thread,
1125                                  options.ref());
1126     num_errors = interp.GetNumErrors();
1127     quit_requested = interp.GetQuitRequested();
1128     stopped_for_crash = interp.GetStoppedForCrash();
1129   }
1130 }
1131 
1132 SBError SBDebugger::RunREPL(lldb::LanguageType language,
1133                             const char *repl_options) {
1134   LLDB_RECORD_METHOD(lldb::SBError, SBDebugger, RunREPL,
1135                      (lldb::LanguageType, const char *), language,
1136                      repl_options);
1137 
1138   SBError error;
1139   if (m_opaque_sp)
1140     error.ref() = m_opaque_sp->RunREPL(language, repl_options);
1141   else
1142     error.SetErrorString("invalid debugger");
1143   return LLDB_RECORD_RESULT(error);
1144 }
1145 
1146 void SBDebugger::reset(const DebuggerSP &debugger_sp) {
1147   m_opaque_sp = debugger_sp;
1148 }
1149 
1150 Debugger *SBDebugger::get() const { return m_opaque_sp.get(); }
1151 
1152 Debugger &SBDebugger::ref() const {
1153   assert(m_opaque_sp.get());
1154   return *m_opaque_sp;
1155 }
1156 
1157 const lldb::DebuggerSP &SBDebugger::get_sp() const { return m_opaque_sp; }
1158 
1159 SBDebugger SBDebugger::FindDebuggerWithID(int id) {
1160   LLDB_RECORD_STATIC_METHOD(lldb::SBDebugger, SBDebugger, FindDebuggerWithID,
1161                             (int), id);
1162 
1163   // No need to lock, the debugger list is thread safe
1164   SBDebugger sb_debugger;
1165   DebuggerSP debugger_sp = Debugger::FindDebuggerWithID(id);
1166   if (debugger_sp)
1167     sb_debugger.reset(debugger_sp);
1168   return LLDB_RECORD_RESULT(sb_debugger);
1169 }
1170 
1171 const char *SBDebugger::GetInstanceName() {
1172   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBDebugger, GetInstanceName);
1173 
1174   return (m_opaque_sp ? m_opaque_sp->GetInstanceName().AsCString() : nullptr);
1175 }
1176 
1177 SBError SBDebugger::SetInternalVariable(const char *var_name, const char *value,
1178                                         const char *debugger_instance_name) {
1179   LLDB_RECORD_STATIC_METHOD(lldb::SBError, SBDebugger, SetInternalVariable,
1180                             (const char *, const char *, const char *),
1181                             var_name, value, debugger_instance_name);
1182 
1183   SBError sb_error;
1184   DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName(
1185       ConstString(debugger_instance_name)));
1186   Status error;
1187   if (debugger_sp) {
1188     ExecutionContext exe_ctx(
1189         debugger_sp->GetCommandInterpreter().GetExecutionContext());
1190     error = debugger_sp->SetPropertyValue(&exe_ctx, eVarSetOperationAssign,
1191                                           var_name, value);
1192   } else {
1193     error.SetErrorStringWithFormat("invalid debugger instance name '%s'",
1194                                    debugger_instance_name);
1195   }
1196   if (error.Fail())
1197     sb_error.SetError(error);
1198   return LLDB_RECORD_RESULT(sb_error);
1199 }
1200 
1201 SBStringList
1202 SBDebugger::GetInternalVariableValue(const char *var_name,
1203                                      const char *debugger_instance_name) {
1204   LLDB_RECORD_STATIC_METHOD(
1205       lldb::SBStringList, SBDebugger, GetInternalVariableValue,
1206       (const char *, const char *), var_name, debugger_instance_name);
1207 
1208   SBStringList ret_value;
1209   DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName(
1210       ConstString(debugger_instance_name)));
1211   Status error;
1212   if (debugger_sp) {
1213     ExecutionContext exe_ctx(
1214         debugger_sp->GetCommandInterpreter().GetExecutionContext());
1215     lldb::OptionValueSP value_sp(
1216         debugger_sp->GetPropertyValue(&exe_ctx, var_name, false, error));
1217     if (value_sp) {
1218       StreamString value_strm;
1219       value_sp->DumpValue(&exe_ctx, value_strm, OptionValue::eDumpOptionValue);
1220       const std::string &value_str = value_strm.GetString();
1221       if (!value_str.empty()) {
1222         StringList string_list;
1223         string_list.SplitIntoLines(value_str);
1224         return LLDB_RECORD_RESULT(SBStringList(&string_list));
1225       }
1226     }
1227   }
1228   return LLDB_RECORD_RESULT(SBStringList());
1229 }
1230 
1231 uint32_t SBDebugger::GetTerminalWidth() const {
1232   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBDebugger, GetTerminalWidth);
1233 
1234   return (m_opaque_sp ? m_opaque_sp->GetTerminalWidth() : 0);
1235 }
1236 
1237 void SBDebugger::SetTerminalWidth(uint32_t term_width) {
1238   LLDB_RECORD_METHOD(void, SBDebugger, SetTerminalWidth, (uint32_t),
1239                      term_width);
1240 
1241   if (m_opaque_sp)
1242     m_opaque_sp->SetTerminalWidth(term_width);
1243 }
1244 
1245 const char *SBDebugger::GetPrompt() const {
1246   LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBDebugger, GetPrompt);
1247 
1248   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1249 
1250   LLDB_LOGF(log, "SBDebugger(%p)::GetPrompt () => \"%s\"",
1251             static_cast<void *>(m_opaque_sp.get()),
1252             (m_opaque_sp ? m_opaque_sp->GetPrompt().str().c_str() : ""));
1253 
1254   return (m_opaque_sp ? ConstString(m_opaque_sp->GetPrompt()).GetCString()
1255                       : nullptr);
1256 }
1257 
1258 void SBDebugger::SetPrompt(const char *prompt) {
1259   LLDB_RECORD_METHOD(void, SBDebugger, SetPrompt, (const char *), prompt);
1260 
1261   if (m_opaque_sp)
1262     m_opaque_sp->SetPrompt(llvm::StringRef::withNullAsEmpty(prompt));
1263 }
1264 
1265 const char *SBDebugger::GetReproducerPath() const {
1266   LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBDebugger, GetReproducerPath);
1267 
1268   return (m_opaque_sp
1269               ? ConstString(m_opaque_sp->GetReproducerPath()).GetCString()
1270               : nullptr);
1271 }
1272 
1273 ScriptLanguage SBDebugger::GetScriptLanguage() const {
1274   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::ScriptLanguage, SBDebugger,
1275                                    GetScriptLanguage);
1276 
1277   return (m_opaque_sp ? m_opaque_sp->GetScriptLanguage() : eScriptLanguageNone);
1278 }
1279 
1280 void SBDebugger::SetScriptLanguage(ScriptLanguage script_lang) {
1281   LLDB_RECORD_METHOD(void, SBDebugger, SetScriptLanguage,
1282                      (lldb::ScriptLanguage), script_lang);
1283 
1284   if (m_opaque_sp) {
1285     m_opaque_sp->SetScriptLanguage(script_lang);
1286   }
1287 }
1288 
1289 bool SBDebugger::SetUseExternalEditor(bool value) {
1290   LLDB_RECORD_METHOD(bool, SBDebugger, SetUseExternalEditor, (bool), value);
1291 
1292   return (m_opaque_sp ? m_opaque_sp->SetUseExternalEditor(value) : false);
1293 }
1294 
1295 bool SBDebugger::GetUseExternalEditor() {
1296   LLDB_RECORD_METHOD_NO_ARGS(bool, SBDebugger, GetUseExternalEditor);
1297 
1298   return (m_opaque_sp ? m_opaque_sp->GetUseExternalEditor() : false);
1299 }
1300 
1301 bool SBDebugger::SetUseColor(bool value) {
1302   LLDB_RECORD_METHOD(bool, SBDebugger, SetUseColor, (bool), value);
1303 
1304   return (m_opaque_sp ? m_opaque_sp->SetUseColor(value) : false);
1305 }
1306 
1307 bool SBDebugger::GetUseColor() const {
1308   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, GetUseColor);
1309 
1310   return (m_opaque_sp ? m_opaque_sp->GetUseColor() : false);
1311 }
1312 
1313 bool SBDebugger::GetDescription(SBStream &description) {
1314   LLDB_RECORD_METHOD(bool, SBDebugger, GetDescription, (lldb::SBStream &),
1315                      description);
1316 
1317   Stream &strm = description.ref();
1318 
1319   if (m_opaque_sp) {
1320     const char *name = m_opaque_sp->GetInstanceName().AsCString();
1321     user_id_t id = m_opaque_sp->GetID();
1322     strm.Printf("Debugger (instance: \"%s\", id: %" PRIu64 ")", name, id);
1323   } else
1324     strm.PutCString("No value");
1325 
1326   return true;
1327 }
1328 
1329 user_id_t SBDebugger::GetID() {
1330   LLDB_RECORD_METHOD_NO_ARGS(lldb::user_id_t, SBDebugger, GetID);
1331 
1332   return (m_opaque_sp ? m_opaque_sp->GetID() : LLDB_INVALID_UID);
1333 }
1334 
1335 SBError SBDebugger::SetCurrentPlatform(const char *platform_name_cstr) {
1336   LLDB_RECORD_METHOD(lldb::SBError, SBDebugger, SetCurrentPlatform,
1337                      (const char *), platform_name_cstr);
1338 
1339   SBError sb_error;
1340   if (m_opaque_sp) {
1341     if (platform_name_cstr && platform_name_cstr[0]) {
1342       ConstString platform_name(platform_name_cstr);
1343       PlatformSP platform_sp(Platform::Find(platform_name));
1344 
1345       if (platform_sp) {
1346         // Already have a platform with this name, just select it
1347         m_opaque_sp->GetPlatformList().SetSelectedPlatform(platform_sp);
1348       } else {
1349         // We don't have a platform by this name yet, create one
1350         platform_sp = Platform::Create(platform_name, sb_error.ref());
1351         if (platform_sp) {
1352           // We created the platform, now append and select it
1353           bool make_selected = true;
1354           m_opaque_sp->GetPlatformList().Append(platform_sp, make_selected);
1355         }
1356       }
1357     } else {
1358       sb_error.ref().SetErrorString("invalid platform name");
1359     }
1360   } else {
1361     sb_error.ref().SetErrorString("invalid debugger");
1362   }
1363   return LLDB_RECORD_RESULT(sb_error);
1364 }
1365 
1366 bool SBDebugger::SetCurrentPlatformSDKRoot(const char *sysroot) {
1367   LLDB_RECORD_METHOD(bool, SBDebugger, SetCurrentPlatformSDKRoot,
1368                      (const char *), sysroot);
1369 
1370   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1371   if (m_opaque_sp) {
1372     PlatformSP platform_sp(
1373         m_opaque_sp->GetPlatformList().GetSelectedPlatform());
1374 
1375     if (platform_sp) {
1376       if (log && sysroot)
1377         LLDB_LOGF(log, "SBDebugger::SetCurrentPlatformSDKRoot (\"%s\")",
1378                   sysroot);
1379       platform_sp->SetSDKRootDirectory(ConstString(sysroot));
1380       return true;
1381     }
1382   }
1383   return false;
1384 }
1385 
1386 bool SBDebugger::GetCloseInputOnEOF() const {
1387   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, GetCloseInputOnEOF);
1388 
1389   return (m_opaque_sp ? m_opaque_sp->GetCloseInputOnEOF() : false);
1390 }
1391 
1392 void SBDebugger::SetCloseInputOnEOF(bool b) {
1393   LLDB_RECORD_METHOD(void, SBDebugger, SetCloseInputOnEOF, (bool), b);
1394 
1395   if (m_opaque_sp)
1396     m_opaque_sp->SetCloseInputOnEOF(b);
1397 }
1398 
1399 SBTypeCategory SBDebugger::GetCategory(const char *category_name) {
1400   LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory,
1401                      (const char *), category_name);
1402 
1403   if (!category_name || *category_name == 0)
1404     return LLDB_RECORD_RESULT(SBTypeCategory());
1405 
1406   TypeCategoryImplSP category_sp;
1407 
1408   if (DataVisualization::Categories::GetCategory(ConstString(category_name),
1409                                                  category_sp, false)) {
1410     return LLDB_RECORD_RESULT(SBTypeCategory(category_sp));
1411   } else {
1412     return LLDB_RECORD_RESULT(SBTypeCategory());
1413   }
1414 }
1415 
1416 SBTypeCategory SBDebugger::GetCategory(lldb::LanguageType lang_type) {
1417   LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory,
1418                      (lldb::LanguageType), lang_type);
1419 
1420   TypeCategoryImplSP category_sp;
1421   if (DataVisualization::Categories::GetCategory(lang_type, category_sp)) {
1422     return LLDB_RECORD_RESULT(SBTypeCategory(category_sp));
1423   } else {
1424     return LLDB_RECORD_RESULT(SBTypeCategory());
1425   }
1426 }
1427 
1428 SBTypeCategory SBDebugger::CreateCategory(const char *category_name) {
1429   LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, CreateCategory,
1430                      (const char *), category_name);
1431 
1432   if (!category_name || *category_name == 0)
1433     return LLDB_RECORD_RESULT(SBTypeCategory());
1434 
1435   TypeCategoryImplSP category_sp;
1436 
1437   if (DataVisualization::Categories::GetCategory(ConstString(category_name),
1438                                                  category_sp, true)) {
1439     return LLDB_RECORD_RESULT(SBTypeCategory(category_sp));
1440   } else {
1441     return LLDB_RECORD_RESULT(SBTypeCategory());
1442   }
1443 }
1444 
1445 bool SBDebugger::DeleteCategory(const char *category_name) {
1446   LLDB_RECORD_METHOD(bool, SBDebugger, DeleteCategory, (const char *),
1447                      category_name);
1448 
1449   if (!category_name || *category_name == 0)
1450     return false;
1451 
1452   return DataVisualization::Categories::Delete(ConstString(category_name));
1453 }
1454 
1455 uint32_t SBDebugger::GetNumCategories() {
1456   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumCategories);
1457 
1458   return DataVisualization::Categories::GetCount();
1459 }
1460 
1461 SBTypeCategory SBDebugger::GetCategoryAtIndex(uint32_t index) {
1462   LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategoryAtIndex,
1463                      (uint32_t), index);
1464 
1465   return LLDB_RECORD_RESULT(
1466       SBTypeCategory(DataVisualization::Categories::GetCategoryAtIndex(index)));
1467 }
1468 
1469 SBTypeCategory SBDebugger::GetDefaultCategory() {
1470   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTypeCategory, SBDebugger,
1471                              GetDefaultCategory);
1472 
1473   return LLDB_RECORD_RESULT(GetCategory("default"));
1474 }
1475 
1476 SBTypeFormat SBDebugger::GetFormatForType(SBTypeNameSpecifier type_name) {
1477   LLDB_RECORD_METHOD(lldb::SBTypeFormat, SBDebugger, GetFormatForType,
1478                      (lldb::SBTypeNameSpecifier), type_name);
1479 
1480   SBTypeCategory default_category_sb = GetDefaultCategory();
1481   if (default_category_sb.GetEnabled())
1482     return LLDB_RECORD_RESULT(default_category_sb.GetFormatForType(type_name));
1483   return LLDB_RECORD_RESULT(SBTypeFormat());
1484 }
1485 
1486 SBTypeSummary SBDebugger::GetSummaryForType(SBTypeNameSpecifier type_name) {
1487   LLDB_RECORD_METHOD(lldb::SBTypeSummary, SBDebugger, GetSummaryForType,
1488                      (lldb::SBTypeNameSpecifier), type_name);
1489 
1490   if (!type_name.IsValid())
1491     return LLDB_RECORD_RESULT(SBTypeSummary());
1492   return LLDB_RECORD_RESULT(
1493       SBTypeSummary(DataVisualization::GetSummaryForType(type_name.GetSP())));
1494 }
1495 
1496 SBTypeFilter SBDebugger::GetFilterForType(SBTypeNameSpecifier type_name) {
1497   LLDB_RECORD_METHOD(lldb::SBTypeFilter, SBDebugger, GetFilterForType,
1498                      (lldb::SBTypeNameSpecifier), type_name);
1499 
1500   if (!type_name.IsValid())
1501     return LLDB_RECORD_RESULT(SBTypeFilter());
1502   return LLDB_RECORD_RESULT(
1503       SBTypeFilter(DataVisualization::GetFilterForType(type_name.GetSP())));
1504 }
1505 
1506 SBTypeSynthetic SBDebugger::GetSyntheticForType(SBTypeNameSpecifier type_name) {
1507   LLDB_RECORD_METHOD(lldb::SBTypeSynthetic, SBDebugger, GetSyntheticForType,
1508                      (lldb::SBTypeNameSpecifier), type_name);
1509 
1510   if (!type_name.IsValid())
1511     return LLDB_RECORD_RESULT(SBTypeSynthetic());
1512   return LLDB_RECORD_RESULT(SBTypeSynthetic(
1513       DataVisualization::GetSyntheticForType(type_name.GetSP())));
1514 }
1515 
1516 static llvm::ArrayRef<const char *> GetCategoryArray(const char **categories) {
1517   if (categories == nullptr)
1518     return {};
1519   size_t len = 0;
1520   while (categories[len] != nullptr)
1521     ++len;
1522   return llvm::makeArrayRef(categories, len);
1523 }
1524 
1525 bool SBDebugger::EnableLog(const char *channel, const char **categories) {
1526   LLDB_RECORD_METHOD(bool, SBDebugger, EnableLog, (const char *, const char **),
1527                      channel, categories);
1528 
1529   if (m_opaque_sp) {
1530     uint32_t log_options =
1531         LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
1532     std::string error;
1533     llvm::raw_string_ostream error_stream(error);
1534     return m_opaque_sp->EnableLog(channel, GetCategoryArray(categories), "",
1535                                   log_options, error_stream);
1536   } else
1537     return false;
1538 }
1539 
1540 void SBDebugger::SetLoggingCallback(lldb::LogOutputCallback log_callback,
1541                                     void *baton) {
1542   LLDB_RECORD_DUMMY(void, SBDebugger, SetLoggingCallback,
1543                     (lldb::LogOutputCallback, void *), log_callback, baton);
1544 
1545   if (m_opaque_sp) {
1546     return m_opaque_sp->SetLoggingCallback(log_callback, baton);
1547   }
1548 }
1549 
1550 namespace lldb_private {
1551 namespace repro {
1552 
1553 template <>
1554 void RegisterMethods<SBInputReader>(Registry &R) {
1555   LLDB_REGISTER_METHOD(void, SBInputReader, SetIsDone, (bool));
1556   LLDB_REGISTER_METHOD_CONST(bool, SBInputReader, IsActive, ());
1557 }
1558 
1559 static void SetFileHandleRedirect(SBDebugger *, FILE *, bool) {
1560   // Do nothing.
1561 }
1562 
1563 static bool GetDefaultArchitectureRedirect(char *arch_name,
1564                                            size_t arch_name_len) {
1565   // The function is writing to its argument. Without the redirect it would
1566   // write into the replay buffer.
1567   char buffer[1024];
1568   return SBDebugger::GetDefaultArchitecture(buffer, arch_name_len);
1569 }
1570 
1571 template <>
1572 void RegisterMethods<SBDebugger>(Registry &R) {
1573   // Custom implementation.
1574   R.Register(&invoke<void (SBDebugger::*)(
1575                  FILE *, bool)>::method<&SBDebugger::SetErrorFileHandle>::doit,
1576              &SetFileHandleRedirect);
1577   R.Register(&invoke<void (SBDebugger::*)(
1578                  FILE *, bool)>::method<&SBDebugger::SetOutputFileHandle>::doit,
1579              &SetFileHandleRedirect);
1580   R.Register<bool(char *, size_t)>(static_cast<bool (*)(char *, size_t)>(
1581                                        &SBDebugger::GetDefaultArchitecture),
1582                                    &GetDefaultArchitectureRedirect);
1583 
1584   LLDB_REGISTER_CONSTRUCTOR(SBDebugger, ());
1585   LLDB_REGISTER_CONSTRUCTOR(SBDebugger, (const lldb::DebuggerSP &));
1586   LLDB_REGISTER_CONSTRUCTOR(SBDebugger, (const lldb::SBDebugger &));
1587   LLDB_REGISTER_METHOD(lldb::SBDebugger &,
1588                        SBDebugger, operator=,(const lldb::SBDebugger &));
1589   LLDB_REGISTER_STATIC_METHOD(void, SBDebugger, Initialize, ());
1590   LLDB_REGISTER_STATIC_METHOD(lldb::SBError, SBDebugger,
1591                               InitializeWithErrorHandling, ());
1592   LLDB_REGISTER_STATIC_METHOD(void, SBDebugger, Terminate, ());
1593   LLDB_REGISTER_METHOD(void, SBDebugger, Clear, ());
1594   LLDB_REGISTER_STATIC_METHOD(lldb::SBDebugger, SBDebugger, Create, ());
1595   LLDB_REGISTER_STATIC_METHOD(lldb::SBDebugger, SBDebugger, Create, (bool));
1596   LLDB_REGISTER_STATIC_METHOD(void, SBDebugger, Destroy,
1597                               (lldb::SBDebugger &));
1598   LLDB_REGISTER_STATIC_METHOD(void, SBDebugger, MemoryPressureDetected, ());
1599   LLDB_REGISTER_METHOD_CONST(bool, SBDebugger, IsValid, ());
1600   LLDB_REGISTER_METHOD_CONST(bool, SBDebugger, operator bool, ());
1601   LLDB_REGISTER_METHOD(void, SBDebugger, SetAsync, (bool));
1602   LLDB_REGISTER_METHOD(bool, SBDebugger, GetAsync, ());
1603   LLDB_REGISTER_METHOD(void, SBDebugger, SkipLLDBInitFiles, (bool));
1604   LLDB_REGISTER_METHOD(void, SBDebugger, SkipAppInitFiles, (bool));
1605   LLDB_REGISTER_METHOD(void, SBDebugger, SetInputFileHandle, (FILE *, bool));
1606   LLDB_REGISTER_METHOD(FILE *, SBDebugger, GetInputFileHandle, ());
1607   LLDB_REGISTER_METHOD(FILE *, SBDebugger, GetOutputFileHandle, ());
1608   LLDB_REGISTER_METHOD(FILE *, SBDebugger, GetErrorFileHandle, ());
1609   LLDB_REGISTER_METHOD(void, SBDebugger, SaveInputTerminalState, ());
1610   LLDB_REGISTER_METHOD(void, SBDebugger, RestoreInputTerminalState, ());
1611   LLDB_REGISTER_METHOD(lldb::SBCommandInterpreter, SBDebugger,
1612                        GetCommandInterpreter, ());
1613   LLDB_REGISTER_METHOD(void, SBDebugger, HandleCommand, (const char *));
1614   LLDB_REGISTER_METHOD(lldb::SBListener, SBDebugger, GetListener, ());
1615   LLDB_REGISTER_METHOD(
1616       void, SBDebugger, HandleProcessEvent,
1617       (const lldb::SBProcess &, const lldb::SBEvent &, FILE *, FILE *));
1618   LLDB_REGISTER_METHOD(lldb::SBSourceManager, SBDebugger, GetSourceManager,
1619                        ());
1620   LLDB_REGISTER_STATIC_METHOD(bool, SBDebugger, SetDefaultArchitecture,
1621                               (const char *));
1622   LLDB_REGISTER_METHOD(lldb::ScriptLanguage, SBDebugger, GetScriptingLanguage,
1623                        (const char *));
1624   LLDB_REGISTER_STATIC_METHOD(const char *, SBDebugger, GetVersionString, ());
1625   LLDB_REGISTER_STATIC_METHOD(const char *, SBDebugger, StateAsCString,
1626                               (lldb::StateType));
1627   LLDB_REGISTER_STATIC_METHOD(lldb::SBStructuredData, SBDebugger,
1628                               GetBuildConfiguration, ());
1629   LLDB_REGISTER_STATIC_METHOD(bool, SBDebugger, StateIsRunningState,
1630                               (lldb::StateType));
1631   LLDB_REGISTER_STATIC_METHOD(bool, SBDebugger, StateIsStoppedState,
1632                               (lldb::StateType));
1633   LLDB_REGISTER_METHOD(
1634       lldb::SBTarget, SBDebugger, CreateTarget,
1635       (const char *, const char *, const char *, bool, lldb::SBError &));
1636   LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger,
1637                        CreateTargetWithFileAndTargetTriple,
1638                        (const char *, const char *));
1639   LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger,
1640                        CreateTargetWithFileAndArch,
1641                        (const char *, const char *));
1642   LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, CreateTarget,
1643                        (const char *));
1644   LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, GetDummyTarget, ());
1645   LLDB_REGISTER_METHOD(bool, SBDebugger, DeleteTarget, (lldb::SBTarget &));
1646   LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, GetTargetAtIndex,
1647                        (uint32_t));
1648   LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetIndexOfTarget,
1649                        (lldb::SBTarget));
1650   LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithProcessID,
1651                        (lldb::pid_t));
1652   LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithFileAndArch,
1653                        (const char *, const char *));
1654   LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetNumTargets, ());
1655   LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, GetSelectedTarget, ());
1656   LLDB_REGISTER_METHOD(void, SBDebugger, SetSelectedTarget,
1657                        (lldb::SBTarget &));
1658   LLDB_REGISTER_METHOD(lldb::SBPlatform, SBDebugger, GetSelectedPlatform, ());
1659   LLDB_REGISTER_METHOD(void, SBDebugger, SetSelectedPlatform,
1660                        (lldb::SBPlatform &));
1661   LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetNumPlatforms, ());
1662   LLDB_REGISTER_METHOD(lldb::SBPlatform, SBDebugger, GetPlatformAtIndex,
1663                        (uint32_t));
1664   LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetNumAvailablePlatforms, ());
1665   LLDB_REGISTER_METHOD(lldb::SBStructuredData, SBDebugger,
1666                        GetAvailablePlatformInfoAtIndex, (uint32_t));
1667   LLDB_REGISTER_METHOD(void, SBDebugger, DispatchInputInterrupt, ());
1668   LLDB_REGISTER_METHOD(void, SBDebugger, DispatchInputEndOfFile, ());
1669   LLDB_REGISTER_METHOD(void, SBDebugger, PushInputReader,
1670                        (lldb::SBInputReader &));
1671   LLDB_REGISTER_METHOD(void, SBDebugger, RunCommandInterpreter, (bool, bool));
1672   LLDB_REGISTER_METHOD(void, SBDebugger, RunCommandInterpreter,
1673                        (bool, bool, lldb::SBCommandInterpreterRunOptions &,
1674                         int &, bool &, bool &));
1675   LLDB_REGISTER_METHOD(lldb::SBError, SBDebugger, RunREPL,
1676                        (lldb::LanguageType, const char *));
1677   LLDB_REGISTER_STATIC_METHOD(lldb::SBDebugger, SBDebugger,
1678                               FindDebuggerWithID, (int));
1679   LLDB_REGISTER_METHOD(const char *, SBDebugger, GetInstanceName, ());
1680   LLDB_REGISTER_STATIC_METHOD(lldb::SBError, SBDebugger, SetInternalVariable,
1681                               (const char *, const char *, const char *));
1682   LLDB_REGISTER_STATIC_METHOD(lldb::SBStringList, SBDebugger,
1683                               GetInternalVariableValue,
1684                               (const char *, const char *));
1685   LLDB_REGISTER_METHOD_CONST(uint32_t, SBDebugger, GetTerminalWidth, ());
1686   LLDB_REGISTER_METHOD(void, SBDebugger, SetTerminalWidth, (uint32_t));
1687   LLDB_REGISTER_METHOD_CONST(const char *, SBDebugger, GetPrompt, ());
1688   LLDB_REGISTER_METHOD(void, SBDebugger, SetPrompt, (const char *));
1689   LLDB_REGISTER_METHOD_CONST(const char *, SBDebugger, GetReproducerPath, ());
1690   LLDB_REGISTER_METHOD_CONST(lldb::ScriptLanguage, SBDebugger,
1691                              GetScriptLanguage, ());
1692   LLDB_REGISTER_METHOD(void, SBDebugger, SetScriptLanguage,
1693                        (lldb::ScriptLanguage));
1694   LLDB_REGISTER_METHOD(bool, SBDebugger, SetUseExternalEditor, (bool));
1695   LLDB_REGISTER_METHOD(bool, SBDebugger, GetUseExternalEditor, ());
1696   LLDB_REGISTER_METHOD(bool, SBDebugger, SetUseColor, (bool));
1697   LLDB_REGISTER_METHOD_CONST(bool, SBDebugger, GetUseColor, ());
1698   LLDB_REGISTER_METHOD(bool, SBDebugger, GetDescription, (lldb::SBStream &));
1699   LLDB_REGISTER_METHOD(lldb::user_id_t, SBDebugger, GetID, ());
1700   LLDB_REGISTER_METHOD(lldb::SBError, SBDebugger, SetCurrentPlatform,
1701                        (const char *));
1702   LLDB_REGISTER_METHOD(bool, SBDebugger, SetCurrentPlatformSDKRoot,
1703                        (const char *));
1704   LLDB_REGISTER_METHOD_CONST(bool, SBDebugger, GetCloseInputOnEOF, ());
1705   LLDB_REGISTER_METHOD(void, SBDebugger, SetCloseInputOnEOF, (bool));
1706   LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory,
1707                        (const char *));
1708   LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory,
1709                        (lldb::LanguageType));
1710   LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, CreateCategory,
1711                        (const char *));
1712   LLDB_REGISTER_METHOD(bool, SBDebugger, DeleteCategory, (const char *));
1713   LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetNumCategories, ());
1714   LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategoryAtIndex,
1715                        (uint32_t));
1716   LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, GetDefaultCategory,
1717                        ());
1718   LLDB_REGISTER_METHOD(lldb::SBTypeFormat, SBDebugger, GetFormatForType,
1719                        (lldb::SBTypeNameSpecifier));
1720   LLDB_REGISTER_METHOD(lldb::SBTypeSummary, SBDebugger, GetSummaryForType,
1721                        (lldb::SBTypeNameSpecifier));
1722   LLDB_REGISTER_METHOD(lldb::SBTypeSynthetic, SBDebugger, GetSyntheticForType,
1723                        (lldb::SBTypeNameSpecifier));
1724   LLDB_REGISTER_METHOD(lldb::SBTypeFilter, SBDebugger, GetFilterForType,
1725                        (lldb::SBTypeNameSpecifier));
1726   LLDB_REGISTER_METHOD(bool, SBDebugger, EnableLog,
1727                        (const char *, const char **));
1728 }
1729 
1730 }
1731 }
1732