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