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