1 //===-- SBDebugger.cpp ------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "SBReproducerPrivate.h"
10 #include "SystemInitializerFull.h"
12 #include "lldb/API/SBDebugger.h"
14 #include "lldb/lldb-private.h"
16 #include "lldb/API/SBBroadcaster.h"
17 #include "lldb/API/SBCommandInterpreter.h"
18 #include "lldb/API/SBCommandReturnObject.h"
19 #include "lldb/API/SBError.h"
20 #include "lldb/API/SBEvent.h"
21 #include "lldb/API/SBFrame.h"
22 #include "lldb/API/SBListener.h"
23 #include "lldb/API/SBProcess.h"
24 #include "lldb/API/SBSourceManager.h"
25 #include "lldb/API/SBStream.h"
26 #include "lldb/API/SBStringList.h"
27 #include "lldb/API/SBStructuredData.h"
28 #include "lldb/API/SBTarget.h"
29 #include "lldb/API/SBThread.h"
30 #include "lldb/API/SBTypeCategory.h"
31 #include "lldb/API/SBTypeFilter.h"
32 #include "lldb/API/SBTypeFormat.h"
33 #include "lldb/API/SBTypeNameSpecifier.h"
34 #include "lldb/API/SBTypeSummary.h"
35 #include "lldb/API/SBTypeSynthetic.h"
37 #include "lldb/Core/Debugger.h"
38 #include "lldb/Core/PluginManager.h"
39 #include "lldb/Core/StreamFile.h"
40 #include "lldb/Core/StructuredDataImpl.h"
41 #include "lldb/DataFormatters/DataVisualization.h"
42 #include "lldb/Host/XML.h"
43 #include "lldb/Initialization/SystemLifetimeManager.h"
44 #include "lldb/Interpreter/CommandInterpreter.h"
45 #include "lldb/Interpreter/OptionArgParser.h"
46 #include "lldb/Interpreter/OptionGroupPlatform.h"
47 #include "lldb/Target/Process.h"
48 #include "lldb/Target/TargetList.h"
49 #include "lldb/Utility/Args.h"
50 #include "lldb/Utility/State.h"
52 #include "llvm/ADT/STLExtras.h"
53 #include "llvm/ADT/StringRef.h"
54 #include "llvm/Support/DynamicLibrary.h"
55 #include "llvm/Support/ManagedStatic.h"
58 using namespace lldb_private;
60 /// Helper class for replaying commands through the reproducer.
63 CommandLoader(std::vector<std::string> files) : m_files(files) {}
65 static std::unique_ptr<CommandLoader> Create() {
66 repro::Loader *loader = repro::Reproducer::Instance().GetLoader();
70 FileSpec file = loader->GetFile<repro::CommandProvider::Info>();
74 auto error_or_file = llvm::MemoryBuffer::getFile(file.GetPath());
75 if (auto err = error_or_file.getError())
78 std::vector<std::string> files;
79 llvm::yaml::Input yin((*error_or_file)->getBuffer());
82 if (auto err = yin.error())
85 for (auto &file : files) {
86 FileSpec absolute_path =
87 loader->GetRoot().CopyByAppendingPathComponent(file);
88 file = absolute_path.GetPath();
91 return llvm::make_unique<CommandLoader>(std::move(files));
95 if (m_index >= m_files.size())
97 return FileSystem::Instance().Fopen(m_files[m_index++].c_str(), "r");
101 std::vector<std::string> m_files;
102 unsigned m_index = 0;
105 static llvm::sys::DynamicLibrary LoadPlugin(const lldb::DebuggerSP &debugger_sp,
106 const FileSpec &spec,
108 llvm::sys::DynamicLibrary dynlib =
109 llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
110 if (dynlib.isValid()) {
111 typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger & debugger);
113 lldb::SBDebugger debugger_sb(debugger_sp);
114 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger)
116 // TODO: mangle this differently for your system - on OSX, the first
117 // underscore needs to be removed and the second one stays
118 LLDBCommandPluginInit init_func =
119 (LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol(
120 "_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
122 if (init_func(debugger_sb))
125 error.SetErrorString("plug-in refused to load "
126 "(lldb::PluginInitialize(lldb::SBDebugger) "
129 error.SetErrorString("plug-in is missing the required initialization: "
130 "lldb::PluginInitialize(lldb::SBDebugger)");
133 if (FileSystem::Instance().Exists(spec))
134 error.SetErrorString("this file does not represent a loadable dylib");
136 error.SetErrorString("no such file");
138 return llvm::sys::DynamicLibrary();
141 static llvm::ManagedStatic<SystemLifetimeManager> g_debugger_lifetime;
143 SBError SBInputReader::Initialize(
144 lldb::SBDebugger &sb_debugger,
145 unsigned long (*callback)(void *, lldb::SBInputReader *,
146 lldb::InputReaderAction, char const *,
148 void *a, lldb::InputReaderGranularity b, char const *c, char const *d,
151 lldb::SBError, SBInputReader, Initialize,
153 unsigned long (*)(void *, lldb::SBInputReader *, lldb::InputReaderAction,
154 const char *, unsigned long),
155 void *, lldb::InputReaderGranularity, const char *, const char *, bool),
156 sb_debugger, callback, a, b, c, d, e);
161 void SBInputReader::SetIsDone(bool b) {
162 LLDB_RECORD_METHOD(void, SBInputReader, SetIsDone, (bool), b);
165 bool SBInputReader::IsActive() const {
166 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBInputReader, IsActive);
171 SBDebugger::SBDebugger() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBDebugger); }
173 SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp)
174 : m_opaque_sp(debugger_sp) {
175 LLDB_RECORD_CONSTRUCTOR(SBDebugger, (const lldb::DebuggerSP &), debugger_sp);
178 SBDebugger::SBDebugger(const SBDebugger &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
179 LLDB_RECORD_CONSTRUCTOR(SBDebugger, (const lldb::SBDebugger &), rhs);
182 SBDebugger::~SBDebugger() = default;
184 SBDebugger &SBDebugger::operator=(const SBDebugger &rhs) {
185 LLDB_RECORD_METHOD(lldb::SBDebugger &,
186 SBDebugger, operator=,(const lldb::SBDebugger &), rhs);
189 m_opaque_sp = rhs.m_opaque_sp;
191 return LLDB_RECORD_RESULT(*this);
194 void SBDebugger::Initialize() {
195 LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, Initialize);
196 SBError ignored = SBDebugger::InitializeWithErrorHandling();
199 lldb::SBError SBDebugger::InitializeWithErrorHandling() {
200 LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBError, SBDebugger,
201 InitializeWithErrorHandling);
206 if (auto e = g_debugger_lifetime->Initialize(
207 llvm::make_unique<SystemInitializerFull>(), LoadPlugin)) {
208 error.SetError(Status(std::move(e)));
210 return LLDB_RECORD_RESULT(error);
213 void SBDebugger::Terminate() {
214 LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, Terminate);
216 g_debugger_lifetime->Terminate();
219 void SBDebugger::Clear() {
220 LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, Clear);
224 m_opaque_sp->ClearIOHandlers();
229 SBDebugger SBDebugger::Create() {
230 LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBDebugger, SBDebugger, Create);
232 return LLDB_RECORD_RESULT(SBDebugger::Create(false, nullptr, nullptr));
235 SBDebugger SBDebugger::Create(bool source_init_files) {
236 LLDB_RECORD_STATIC_METHOD(lldb::SBDebugger, SBDebugger, Create, (bool),
239 return LLDB_RECORD_RESULT(
240 SBDebugger::Create(source_init_files, nullptr, nullptr));
243 SBDebugger SBDebugger::Create(bool source_init_files,
244 lldb::LogOutputCallback callback, void *baton)
247 LLDB_RECORD_DUMMY(lldb::SBDebugger, SBDebugger, Create,
248 (bool, lldb::LogOutputCallback, void *), source_init_files,
253 // Currently we have issues if this function is called simultaneously on two
254 // different threads. The issues mainly revolve around the fact that the
255 // lldb_private::FormatManager uses global collections and having two threads
256 // parsing the .lldbinit files can cause mayhem. So to get around this for
257 // now we need to use a mutex to prevent bad things from happening.
258 static std::recursive_mutex g_mutex;
259 std::lock_guard<std::recursive_mutex> guard(g_mutex);
261 debugger.reset(Debugger::CreateInstance(callback, baton));
264 SBCommandInterpreter interp = debugger.GetCommandInterpreter();
265 if (source_init_files) {
266 interp.get()->SkipLLDBInitFiles(false);
267 interp.get()->SkipAppInitFiles(false);
268 SBCommandReturnObject result;
269 interp.SourceInitFileInHomeDirectory(result);
271 interp.get()->SkipLLDBInitFiles(true);
272 interp.get()->SkipAppInitFiles(true);
277 void SBDebugger::Destroy(SBDebugger &debugger) {
278 LLDB_RECORD_STATIC_METHOD(void, SBDebugger, Destroy, (lldb::SBDebugger &),
282 Debugger::Destroy(debugger.m_opaque_sp);
284 if (debugger.m_opaque_sp.get() != nullptr)
285 debugger.m_opaque_sp.reset();
288 void SBDebugger::MemoryPressureDetected() {
289 LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, MemoryPressureDetected);
291 // Since this function can be call asynchronously, we allow it to be non-
292 // mandatory. We have seen deadlocks with this function when called so we
293 // need to safeguard against this until we can determine what is causing the
296 const bool mandatory = false;
298 ModuleList::RemoveOrphanSharedModules(mandatory);
301 bool SBDebugger::IsValid() const {
302 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, IsValid);
303 return this->operator bool();
305 SBDebugger::operator bool() const {
306 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, operator bool);
308 return m_opaque_sp.get() != nullptr;
311 void SBDebugger::SetAsync(bool b) {
312 LLDB_RECORD_METHOD(void, SBDebugger, SetAsync, (bool), b);
315 m_opaque_sp->SetAsyncExecution(b);
318 bool SBDebugger::GetAsync() {
319 LLDB_RECORD_METHOD_NO_ARGS(bool, SBDebugger, GetAsync);
321 return (m_opaque_sp ? m_opaque_sp->GetAsyncExecution() : false);
324 void SBDebugger::SkipLLDBInitFiles(bool b) {
325 LLDB_RECORD_METHOD(void, SBDebugger, SkipLLDBInitFiles, (bool), b);
328 m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles(b);
331 void SBDebugger::SkipAppInitFiles(bool b) {
332 LLDB_RECORD_METHOD(void, SBDebugger, SkipAppInitFiles, (bool), b);
335 m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles(b);
338 // Shouldn't really be settable after initialization as this could cause lots
339 // of problems; don't want users trying to switch modes in the middle of a
340 // debugging session.
341 void SBDebugger::SetInputFileHandle(FILE *fh, bool transfer_ownership) {
342 LLDB_RECORD_METHOD(void, SBDebugger, SetInputFileHandle, (FILE *, bool), fh,
348 repro::DataRecorder *recorder = nullptr;
349 if (repro::Generator *g = repro::Reproducer::Instance().GetGenerator())
350 recorder = g->GetOrCreate<repro::CommandProvider>().GetNewDataRecorder();
352 static std::unique_ptr<CommandLoader> loader = CommandLoader::Create();
354 fh = loader->GetNextFile();
356 m_opaque_sp->SetInputFileHandle(fh, transfer_ownership, recorder);
359 void SBDebugger::SetOutputFileHandle(FILE *fh, bool transfer_ownership) {
360 LLDB_RECORD_METHOD(void, SBDebugger, SetOutputFileHandle, (FILE *, bool), fh,
364 m_opaque_sp->SetOutputFileHandle(fh, transfer_ownership);
367 void SBDebugger::SetErrorFileHandle(FILE *fh, bool transfer_ownership) {
368 LLDB_RECORD_METHOD(void, SBDebugger, SetErrorFileHandle, (FILE *, bool), fh,
373 m_opaque_sp->SetErrorFileHandle(fh, transfer_ownership);
376 FILE *SBDebugger::GetInputFileHandle() {
377 LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetInputFileHandle);
380 StreamFileSP stream_file_sp(m_opaque_sp->GetInputFile());
382 return LLDB_RECORD_RESULT(stream_file_sp->GetFile().GetStream());
387 FILE *SBDebugger::GetOutputFileHandle() {
388 LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetOutputFileHandle);
391 StreamFileSP stream_file_sp(m_opaque_sp->GetOutputFile());
393 return LLDB_RECORD_RESULT(stream_file_sp->GetFile().GetStream());
398 FILE *SBDebugger::GetErrorFileHandle() {
399 LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetErrorFileHandle);
402 StreamFileSP stream_file_sp(m_opaque_sp->GetErrorFile());
404 return LLDB_RECORD_RESULT(stream_file_sp->GetFile().GetStream());
409 void SBDebugger::SaveInputTerminalState() {
410 LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, SaveInputTerminalState);
413 m_opaque_sp->SaveInputTerminalState();
416 void SBDebugger::RestoreInputTerminalState() {
417 LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, RestoreInputTerminalState);
420 m_opaque_sp->RestoreInputTerminalState();
422 SBCommandInterpreter SBDebugger::GetCommandInterpreter() {
423 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBCommandInterpreter, SBDebugger,
424 GetCommandInterpreter);
427 SBCommandInterpreter sb_interpreter;
429 sb_interpreter.reset(&m_opaque_sp->GetCommandInterpreter());
432 return LLDB_RECORD_RESULT(sb_interpreter);
435 void SBDebugger::HandleCommand(const char *command) {
436 LLDB_RECORD_METHOD(void, SBDebugger, HandleCommand, (const char *), command);
439 TargetSP target_sp(m_opaque_sp->GetSelectedTarget());
440 std::unique_lock<std::recursive_mutex> lock;
442 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
444 SBCommandInterpreter sb_interpreter(GetCommandInterpreter());
445 SBCommandReturnObject result;
447 sb_interpreter.HandleCommand(command, result, false);
449 if (GetErrorFileHandle() != nullptr)
450 result.PutError(GetErrorFileHandle());
451 if (GetOutputFileHandle() != nullptr)
452 result.PutOutput(GetOutputFileHandle());
454 if (!m_opaque_sp->GetAsyncExecution()) {
455 SBProcess process(GetCommandInterpreter().GetProcess());
456 ProcessSP process_sp(process.GetSP());
459 ListenerSP lldb_listener_sp = m_opaque_sp->GetListener();
460 while (lldb_listener_sp->GetEventForBroadcaster(
461 process_sp.get(), event_sp, std::chrono::seconds(0))) {
462 SBEvent event(event_sp);
463 HandleProcessEvent(process, event, GetOutputFileHandle(),
464 GetErrorFileHandle());
471 SBListener SBDebugger::GetListener() {
472 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBListener, SBDebugger, GetListener);
475 SBListener sb_listener;
477 sb_listener.reset(m_opaque_sp->GetListener());
480 return LLDB_RECORD_RESULT(sb_listener);
483 void SBDebugger::HandleProcessEvent(const SBProcess &process,
484 const SBEvent &event, FILE *out,
487 void, SBDebugger, HandleProcessEvent,
488 (const lldb::SBProcess &, const lldb::SBEvent &, FILE *, FILE *), process,
491 if (!process.IsValid())
494 TargetSP target_sp(process.GetTarget().GetSP());
498 const uint32_t event_type = event.GetType();
499 char stdio_buffer[1024];
502 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
505 (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged)) {
506 // Drain stdout when we stop just in case we have any bytes
507 while ((len = process.GetSTDOUT(stdio_buffer, sizeof(stdio_buffer))) > 0)
509 ::fwrite(stdio_buffer, 1, len, out);
513 (Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged)) {
514 // Drain stderr when we stop just in case we have any bytes
515 while ((len = process.GetSTDERR(stdio_buffer, sizeof(stdio_buffer))) > 0)
517 ::fwrite(stdio_buffer, 1, len, err);
520 if (event_type & Process::eBroadcastBitStateChanged) {
521 StateType event_state = SBProcess::GetStateFromEvent(event);
523 if (event_state == eStateInvalid)
526 bool is_stopped = StateIsStoppedState(event_state);
528 process.ReportEventState(event, out);
532 SBSourceManager SBDebugger::GetSourceManager() {
533 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBSourceManager, SBDebugger,
536 SBSourceManager sb_source_manager(*this);
537 return LLDB_RECORD_RESULT(sb_source_manager);
540 bool SBDebugger::GetDefaultArchitecture(char *arch_name, size_t arch_name_len) {
541 LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, GetDefaultArchitecture,
542 (char *, size_t), "", arch_name_len);
544 if (arch_name && arch_name_len) {
545 ArchSpec default_arch = Target::GetDefaultArchitecture();
547 if (default_arch.IsValid()) {
548 const std::string &triple_str = default_arch.GetTriple().str();
549 if (!triple_str.empty())
550 ::snprintf(arch_name, arch_name_len, "%s", triple_str.c_str());
552 ::snprintf(arch_name, arch_name_len, "%s",
553 default_arch.GetArchitectureName());
557 if (arch_name && arch_name_len)
562 bool SBDebugger::SetDefaultArchitecture(const char *arch_name) {
563 LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, SetDefaultArchitecture,
564 (const char *), arch_name);
567 ArchSpec arch(arch_name);
568 if (arch.IsValid()) {
569 Target::SetDefaultArchitecture(arch);
577 SBDebugger::GetScriptingLanguage(const char *script_language_name) {
578 LLDB_RECORD_METHOD(lldb::ScriptLanguage, SBDebugger, GetScriptingLanguage,
579 (const char *), script_language_name);
581 if (!script_language_name) return eScriptLanguageDefault;
582 return OptionArgParser::ToScriptLanguage(
583 llvm::StringRef(script_language_name), eScriptLanguageDefault, nullptr);
586 const char *SBDebugger::GetVersionString() {
587 LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBDebugger, GetVersionString);
589 return lldb_private::GetVersion();
592 const char *SBDebugger::StateAsCString(StateType state) {
593 LLDB_RECORD_STATIC_METHOD(const char *, SBDebugger, StateAsCString,
594 (lldb::StateType), state);
596 return lldb_private::StateAsCString(state);
599 static void AddBoolConfigEntry(StructuredData::Dictionary &dict,
600 llvm::StringRef name, bool value,
601 llvm::StringRef description) {
602 auto entry_up = llvm::make_unique<StructuredData::Dictionary>();
603 entry_up->AddBooleanItem("value", value);
604 entry_up->AddStringItem("description", description);
605 dict.AddItem(name, std::move(entry_up));
608 static void AddLLVMTargets(StructuredData::Dictionary &dict) {
609 auto array_up = llvm::make_unique<StructuredData::Array>();
610 #define LLVM_TARGET(target) \
611 array_up->AddItem(llvm::make_unique<StructuredData::String>(#target));
612 #include "llvm/Config/Targets.def"
613 auto entry_up = llvm::make_unique<StructuredData::Dictionary>();
614 entry_up->AddItem("value", std::move(array_up));
615 entry_up->AddStringItem("description", "A list of configured LLVM targets.");
616 dict.AddItem("targets", std::move(entry_up));
619 SBStructuredData SBDebugger::GetBuildConfiguration() {
620 LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBStructuredData, SBDebugger,
621 GetBuildConfiguration);
623 auto config_up = llvm::make_unique<StructuredData::Dictionary>();
625 *config_up, "xml", XMLDocument::XMLEnabled(),
626 "A boolean value that indicates if XML support is enabled in LLDB");
627 AddLLVMTargets(*config_up);
629 SBStructuredData data;
630 data.m_impl_up->SetObjectSP(std::move(config_up));
631 return LLDB_RECORD_RESULT(data);
634 bool SBDebugger::StateIsRunningState(StateType state) {
635 LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, StateIsRunningState,
636 (lldb::StateType), state);
639 const bool result = lldb_private::StateIsRunningState(state);
644 bool SBDebugger::StateIsStoppedState(StateType state) {
645 LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, StateIsStoppedState,
646 (lldb::StateType), state);
649 const bool result = lldb_private::StateIsStoppedState(state, false);
654 lldb::SBTarget SBDebugger::CreateTarget(const char *filename,
655 const char *target_triple,
656 const char *platform_name,
657 bool add_dependent_modules,
658 lldb::SBError &sb_error) {
660 lldb::SBTarget, SBDebugger, CreateTarget,
661 (const char *, const char *, const char *, bool, lldb::SBError &),
662 filename, target_triple, platform_name, add_dependent_modules, sb_error);
668 OptionGroupPlatform platform_options(false);
669 platform_options.SetPlatformName(platform_name);
671 sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget(
672 *m_opaque_sp, filename, target_triple,
673 add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo,
674 &platform_options, target_sp);
676 if (sb_error.Success())
677 sb_target.SetSP(target_sp);
679 sb_error.SetErrorString("invalid debugger");
682 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
684 log->Printf("SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, "
685 "platform_name=%s, add_dependent_modules=%u, error=%s) => "
687 static_cast<void *>(m_opaque_sp.get()), filename, target_triple,
688 platform_name, add_dependent_modules, sb_error.GetCString(),
689 static_cast<void *>(target_sp.get()));
691 return LLDB_RECORD_RESULT(sb_target);
695 SBDebugger::CreateTargetWithFileAndTargetTriple(const char *filename,
696 const char *target_triple) {
697 LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger,
698 CreateTargetWithFileAndTargetTriple,
699 (const char *, const char *), filename, target_triple);
704 const bool add_dependent_modules = true;
705 Status error(m_opaque_sp->GetTargetList().CreateTarget(
706 *m_opaque_sp, filename, target_triple,
707 add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,
709 sb_target.SetSP(target_sp);
712 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
714 log->Printf("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple "
715 "(filename=\"%s\", triple=%s) => SBTarget(%p)",
716 static_cast<void *>(m_opaque_sp.get()), filename, target_triple,
717 static_cast<void *>(target_sp.get()));
719 return LLDB_RECORD_RESULT(sb_target);
722 SBTarget SBDebugger::CreateTargetWithFileAndArch(const char *filename,
723 const char *arch_cstr) {
724 LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, CreateTargetWithFileAndArch,
725 (const char *, const char *), filename, arch_cstr);
727 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
733 const bool add_dependent_modules = true;
735 error = m_opaque_sp->GetTargetList().CreateTarget(
736 *m_opaque_sp, filename, arch_cstr,
737 add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,
740 if (error.Success()) {
741 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get());
742 sb_target.SetSP(target_sp);
747 log->Printf("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", "
748 "arch=%s) => SBTarget(%p)",
749 static_cast<void *>(m_opaque_sp.get()), filename, arch_cstr,
750 static_cast<void *>(target_sp.get()));
752 return LLDB_RECORD_RESULT(sb_target);
755 SBTarget SBDebugger::CreateTarget(const char *filename) {
756 LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, CreateTarget, (const char *),
763 const bool add_dependent_modules = true;
764 error = m_opaque_sp->GetTargetList().CreateTarget(
765 *m_opaque_sp, filename, "",
766 add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,
769 if (error.Success()) {
770 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get());
771 sb_target.SetSP(target_sp);
774 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
777 "SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
778 static_cast<void *>(m_opaque_sp.get()), filename,
779 static_cast<void *>(target_sp.get()));
780 return LLDB_RECORD_RESULT(sb_target);
783 SBTarget SBDebugger::GetDummyTarget() {
784 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTarget, SBDebugger, GetDummyTarget);
788 sb_target.SetSP(m_opaque_sp->GetDummyTarget()->shared_from_this());
790 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
793 "SBDebugger(%p)::GetDummyTarget() => SBTarget(%p)",
794 static_cast<void *>(m_opaque_sp.get()),
795 static_cast<void *>(sb_target.GetSP().get()));
796 return LLDB_RECORD_RESULT(sb_target);
799 bool SBDebugger::DeleteTarget(lldb::SBTarget &target) {
800 LLDB_RECORD_METHOD(bool, SBDebugger, DeleteTarget, (lldb::SBTarget &),
805 TargetSP target_sp(target.GetSP());
807 // No need to lock, the target list is thread safe
808 result = m_opaque_sp->GetTargetList().DeleteTarget(target_sp);
809 target_sp->Destroy();
811 const bool mandatory = true;
812 ModuleList::RemoveOrphanSharedModules(mandatory);
816 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
818 log->Printf("SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i",
819 static_cast<void *>(m_opaque_sp.get()),
820 static_cast<void *>(target.m_opaque_sp.get()), result);
825 SBTarget SBDebugger::GetTargetAtIndex(uint32_t idx) {
826 LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, GetTargetAtIndex, (uint32_t),
831 // No need to lock, the target list is thread safe
832 sb_target.SetSP(m_opaque_sp->GetTargetList().GetTargetAtIndex(idx));
834 return LLDB_RECORD_RESULT(sb_target);
837 uint32_t SBDebugger::GetIndexOfTarget(lldb::SBTarget target) {
838 LLDB_RECORD_METHOD(uint32_t, SBDebugger, GetIndexOfTarget, (lldb::SBTarget),
841 lldb::TargetSP target_sp = target.GetSP();
848 return m_opaque_sp->GetTargetList().GetIndexOfTarget(target.GetSP());
851 SBTarget SBDebugger::FindTargetWithProcessID(lldb::pid_t pid) {
852 LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithProcessID,
857 // No need to lock, the target list is thread safe
858 sb_target.SetSP(m_opaque_sp->GetTargetList().FindTargetWithProcessID(pid));
860 return LLDB_RECORD_RESULT(sb_target);
863 SBTarget SBDebugger::FindTargetWithFileAndArch(const char *filename,
864 const char *arch_name) {
865 LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithFileAndArch,
866 (const char *, const char *), filename, arch_name);
869 if (m_opaque_sp && filename && filename[0]) {
870 // No need to lock, the target list is thread safe
871 ArchSpec arch = Platform::GetAugmentedArchSpec(
872 m_opaque_sp->GetPlatformList().GetSelectedPlatform().get(), arch_name);
874 m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture(
875 FileSpec(filename), arch_name ? &arch : nullptr));
876 sb_target.SetSP(target_sp);
878 return LLDB_RECORD_RESULT(sb_target);
881 SBTarget SBDebugger::FindTargetWithLLDBProcess(const ProcessSP &process_sp) {
884 // No need to lock, the target list is thread safe
886 m_opaque_sp->GetTargetList().FindTargetWithProcess(process_sp.get()));
891 uint32_t SBDebugger::GetNumTargets() {
892 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumTargets);
895 // No need to lock, the target list is thread safe
896 return m_opaque_sp->GetTargetList().GetNumTargets();
901 SBTarget SBDebugger::GetSelectedTarget() {
902 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTarget, SBDebugger, GetSelectedTarget);
904 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
909 // No need to lock, the target list is thread safe
910 target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget();
911 sb_target.SetSP(target_sp);
916 sb_target.GetDescription(sstr, eDescriptionLevelBrief);
917 log->Printf("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s",
918 static_cast<void *>(m_opaque_sp.get()),
919 static_cast<void *>(target_sp.get()), sstr.GetData());
922 return LLDB_RECORD_RESULT(sb_target);
925 void SBDebugger::SetSelectedTarget(SBTarget &sb_target) {
926 LLDB_RECORD_METHOD(void, SBDebugger, SetSelectedTarget, (lldb::SBTarget &),
929 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
931 TargetSP target_sp(sb_target.GetSP());
933 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get());
937 sb_target.GetDescription(sstr, eDescriptionLevelBrief);
938 log->Printf("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s",
939 static_cast<void *>(m_opaque_sp.get()),
940 static_cast<void *>(target_sp.get()), sstr.GetData());
944 SBPlatform SBDebugger::GetSelectedPlatform() {
945 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBPlatform, SBDebugger, GetSelectedPlatform);
947 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
949 SBPlatform sb_platform;
950 DebuggerSP debugger_sp(m_opaque_sp);
952 sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform());
955 log->Printf("SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s",
956 static_cast<void *>(m_opaque_sp.get()),
957 static_cast<void *>(sb_platform.GetSP().get()),
958 sb_platform.GetName());
959 return LLDB_RECORD_RESULT(sb_platform);
962 void SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform) {
963 LLDB_RECORD_METHOD(void, SBDebugger, SetSelectedPlatform,
964 (lldb::SBPlatform &), sb_platform);
966 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
968 DebuggerSP debugger_sp(m_opaque_sp);
970 debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP());
974 log->Printf("SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)",
975 static_cast<void *>(m_opaque_sp.get()),
976 static_cast<void *>(sb_platform.GetSP().get()),
977 sb_platform.GetName());
980 uint32_t SBDebugger::GetNumPlatforms() {
981 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumPlatforms);
984 // No need to lock, the platform list is thread safe
985 return m_opaque_sp->GetPlatformList().GetSize();
990 SBPlatform SBDebugger::GetPlatformAtIndex(uint32_t idx) {
991 LLDB_RECORD_METHOD(lldb::SBPlatform, SBDebugger, GetPlatformAtIndex,
994 SBPlatform sb_platform;
996 // No need to lock, the platform list is thread safe
997 sb_platform.SetSP(m_opaque_sp->GetPlatformList().GetAtIndex(idx));
999 return LLDB_RECORD_RESULT(sb_platform);
1002 uint32_t SBDebugger::GetNumAvailablePlatforms() {
1003 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumAvailablePlatforms);
1007 if (!PluginManager::GetPlatformPluginNameAtIndex(idx)) {
1012 // +1 for the host platform, which should always appear first in the list.
1016 SBStructuredData SBDebugger::GetAvailablePlatformInfoAtIndex(uint32_t idx) {
1017 LLDB_RECORD_METHOD(lldb::SBStructuredData, SBDebugger,
1018 GetAvailablePlatformInfoAtIndex, (uint32_t), idx);
1020 SBStructuredData data;
1021 auto platform_dict = llvm::make_unique<StructuredData::Dictionary>();
1022 llvm::StringRef name_str("name"), desc_str("description");
1025 PlatformSP host_platform_sp(Platform::GetHostPlatform());
1026 platform_dict->AddStringItem(
1027 name_str, host_platform_sp->GetPluginName().GetStringRef());
1028 platform_dict->AddStringItem(
1029 desc_str, llvm::StringRef(host_platform_sp->GetDescription()));
1030 } else if (idx > 0) {
1031 const char *plugin_name =
1032 PluginManager::GetPlatformPluginNameAtIndex(idx - 1);
1034 return LLDB_RECORD_RESULT(data);
1036 platform_dict->AddStringItem(name_str, llvm::StringRef(plugin_name));
1038 const char *plugin_desc =
1039 PluginManager::GetPlatformPluginDescriptionAtIndex(idx - 1);
1041 return LLDB_RECORD_RESULT(data);
1043 platform_dict->AddStringItem(desc_str, llvm::StringRef(plugin_desc));
1046 data.m_impl_up->SetObjectSP(
1047 StructuredData::ObjectSP(platform_dict.release()));
1048 return LLDB_RECORD_RESULT(data);
1051 void SBDebugger::DispatchInput(void *baton, const void *data, size_t data_len) {
1052 LLDB_RECORD_DUMMY(void, SBDebugger, DispatchInput,
1053 (void *, const void *, size_t), baton, data, data_len);
1055 DispatchInput(data, data_len);
1058 void SBDebugger::DispatchInput(const void *data, size_t data_len) {
1059 LLDB_RECORD_DUMMY(void, SBDebugger, DispatchInput, (const void *, size_t),
1062 // Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1065 // log->Printf ("SBDebugger(%p)::DispatchInput (data=\"%.*s\",
1066 // size_t=%" PRIu64 ")",
1067 // m_opaque_sp.get(),
1069 // (const char *) data,
1070 // (uint64_t)data_len);
1073 // m_opaque_sp->DispatchInput ((const char *) data, data_len);
1076 void SBDebugger::DispatchInputInterrupt() {
1077 LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, DispatchInputInterrupt);
1080 m_opaque_sp->DispatchInputInterrupt();
1083 void SBDebugger::DispatchInputEndOfFile() {
1084 LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, DispatchInputEndOfFile);
1087 m_opaque_sp->DispatchInputEndOfFile();
1090 void SBDebugger::PushInputReader(SBInputReader &reader) {
1091 LLDB_RECORD_METHOD(void, SBDebugger, PushInputReader, (lldb::SBInputReader &),
1095 void SBDebugger::RunCommandInterpreter(bool auto_handle_events,
1096 bool spawn_thread) {
1097 LLDB_RECORD_METHOD(void, SBDebugger, RunCommandInterpreter, (bool, bool),
1098 auto_handle_events, spawn_thread);
1101 CommandInterpreterRunOptions options;
1103 m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(
1104 auto_handle_events, spawn_thread, options);
1108 void SBDebugger::RunCommandInterpreter(bool auto_handle_events,
1110 SBCommandInterpreterRunOptions &options,
1111 int &num_errors, bool &quit_requested,
1112 bool &stopped_for_crash)
1115 LLDB_RECORD_METHOD(void, SBDebugger, RunCommandInterpreter,
1116 (bool, bool, lldb::SBCommandInterpreterRunOptions &, int &,
1118 auto_handle_events, spawn_thread, options, num_errors,
1119 quit_requested, stopped_for_crash);
1122 CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();
1123 interp.RunCommandInterpreter(auto_handle_events, spawn_thread,
1125 num_errors = interp.GetNumErrors();
1126 quit_requested = interp.GetQuitRequested();
1127 stopped_for_crash = interp.GetStoppedForCrash();
1131 SBError SBDebugger::RunREPL(lldb::LanguageType language,
1132 const char *repl_options) {
1133 LLDB_RECORD_METHOD(lldb::SBError, SBDebugger, RunREPL,
1134 (lldb::LanguageType, const char *), language,
1139 error.ref() = m_opaque_sp->RunREPL(language, repl_options);
1141 error.SetErrorString("invalid debugger");
1142 return LLDB_RECORD_RESULT(error);
1145 void SBDebugger::reset(const DebuggerSP &debugger_sp) {
1146 m_opaque_sp = debugger_sp;
1149 Debugger *SBDebugger::get() const { return m_opaque_sp.get(); }
1151 Debugger &SBDebugger::ref() const {
1152 assert(m_opaque_sp.get());
1153 return *m_opaque_sp;
1156 const lldb::DebuggerSP &SBDebugger::get_sp() const { return m_opaque_sp; }
1158 SBDebugger SBDebugger::FindDebuggerWithID(int id) {
1159 LLDB_RECORD_STATIC_METHOD(lldb::SBDebugger, SBDebugger, FindDebuggerWithID,
1162 // No need to lock, the debugger list is thread safe
1163 SBDebugger sb_debugger;
1164 DebuggerSP debugger_sp = Debugger::FindDebuggerWithID(id);
1166 sb_debugger.reset(debugger_sp);
1167 return LLDB_RECORD_RESULT(sb_debugger);
1170 const char *SBDebugger::GetInstanceName() {
1171 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBDebugger, GetInstanceName);
1173 return (m_opaque_sp ? m_opaque_sp->GetInstanceName().AsCString() : nullptr);
1176 SBError SBDebugger::SetInternalVariable(const char *var_name, const char *value,
1177 const char *debugger_instance_name) {
1178 LLDB_RECORD_STATIC_METHOD(lldb::SBError, SBDebugger, SetInternalVariable,
1179 (const char *, const char *, const char *),
1180 var_name, value, debugger_instance_name);
1183 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName(
1184 ConstString(debugger_instance_name)));
1187 ExecutionContext exe_ctx(
1188 debugger_sp->GetCommandInterpreter().GetExecutionContext());
1189 error = debugger_sp->SetPropertyValue(&exe_ctx, eVarSetOperationAssign,
1192 error.SetErrorStringWithFormat("invalid debugger instance name '%s'",
1193 debugger_instance_name);
1196 sb_error.SetError(error);
1197 return LLDB_RECORD_RESULT(sb_error);
1201 SBDebugger::GetInternalVariableValue(const char *var_name,
1202 const char *debugger_instance_name) {
1203 LLDB_RECORD_STATIC_METHOD(
1204 lldb::SBStringList, SBDebugger, GetInternalVariableValue,
1205 (const char *, const char *), var_name, debugger_instance_name);
1207 SBStringList ret_value;
1208 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName(
1209 ConstString(debugger_instance_name)));
1212 ExecutionContext exe_ctx(
1213 debugger_sp->GetCommandInterpreter().GetExecutionContext());
1214 lldb::OptionValueSP value_sp(
1215 debugger_sp->GetPropertyValue(&exe_ctx, var_name, false, error));
1217 StreamString value_strm;
1218 value_sp->DumpValue(&exe_ctx, value_strm, OptionValue::eDumpOptionValue);
1219 const std::string &value_str = value_strm.GetString();
1220 if (!value_str.empty()) {
1221 StringList string_list;
1222 string_list.SplitIntoLines(value_str);
1223 return LLDB_RECORD_RESULT(SBStringList(&string_list));
1227 return LLDB_RECORD_RESULT(SBStringList());
1230 uint32_t SBDebugger::GetTerminalWidth() const {
1231 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBDebugger, GetTerminalWidth);
1233 return (m_opaque_sp ? m_opaque_sp->GetTerminalWidth() : 0);
1236 void SBDebugger::SetTerminalWidth(uint32_t term_width) {
1237 LLDB_RECORD_METHOD(void, SBDebugger, SetTerminalWidth, (uint32_t),
1241 m_opaque_sp->SetTerminalWidth(term_width);
1244 const char *SBDebugger::GetPrompt() const {
1245 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBDebugger, GetPrompt);
1247 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1250 log->Printf("SBDebugger(%p)::GetPrompt () => \"%s\"",
1251 static_cast<void *>(m_opaque_sp.get()),
1252 (m_opaque_sp ? m_opaque_sp->GetPrompt().str().c_str() : ""));
1254 return (m_opaque_sp ? ConstString(m_opaque_sp->GetPrompt()).GetCString()
1258 void SBDebugger::SetPrompt(const char *prompt) {
1259 LLDB_RECORD_METHOD(void, SBDebugger, SetPrompt, (const char *), prompt);
1262 m_opaque_sp->SetPrompt(llvm::StringRef::withNullAsEmpty(prompt));
1265 const char *SBDebugger::GetReproducerPath() const {
1266 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBDebugger, GetReproducerPath);
1269 ? ConstString(m_opaque_sp->GetReproducerPath()).GetCString()
1273 ScriptLanguage SBDebugger::GetScriptLanguage() const {
1274 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::ScriptLanguage, SBDebugger,
1277 return (m_opaque_sp ? m_opaque_sp->GetScriptLanguage() : eScriptLanguageNone);
1280 void SBDebugger::SetScriptLanguage(ScriptLanguage script_lang) {
1281 LLDB_RECORD_METHOD(void, SBDebugger, SetScriptLanguage,
1282 (lldb::ScriptLanguage), script_lang);
1285 m_opaque_sp->SetScriptLanguage(script_lang);
1289 bool SBDebugger::SetUseExternalEditor(bool value) {
1290 LLDB_RECORD_METHOD(bool, SBDebugger, SetUseExternalEditor, (bool), value);
1292 return (m_opaque_sp ? m_opaque_sp->SetUseExternalEditor(value) : false);
1295 bool SBDebugger::GetUseExternalEditor() {
1296 LLDB_RECORD_METHOD_NO_ARGS(bool, SBDebugger, GetUseExternalEditor);
1298 return (m_opaque_sp ? m_opaque_sp->GetUseExternalEditor() : false);
1301 bool SBDebugger::SetUseColor(bool value) {
1302 LLDB_RECORD_METHOD(bool, SBDebugger, SetUseColor, (bool), value);
1304 return (m_opaque_sp ? m_opaque_sp->SetUseColor(value) : false);
1307 bool SBDebugger::GetUseColor() const {
1308 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, GetUseColor);
1310 return (m_opaque_sp ? m_opaque_sp->GetUseColor() : false);
1313 bool SBDebugger::GetDescription(SBStream &description) {
1314 LLDB_RECORD_METHOD(bool, SBDebugger, GetDescription, (lldb::SBStream &),
1317 Stream &strm = description.ref();
1320 const char *name = m_opaque_sp->GetInstanceName().AsCString();
1321 user_id_t id = m_opaque_sp->GetID();
1322 strm.Printf("Debugger (instance: \"%s\", id: %" PRIu64 ")", name, id);
1324 strm.PutCString("No value");
1329 user_id_t SBDebugger::GetID() {
1330 LLDB_RECORD_METHOD_NO_ARGS(lldb::user_id_t, SBDebugger, GetID);
1332 return (m_opaque_sp ? m_opaque_sp->GetID() : LLDB_INVALID_UID);
1335 SBError SBDebugger::SetCurrentPlatform(const char *platform_name_cstr) {
1336 LLDB_RECORD_METHOD(lldb::SBError, SBDebugger, SetCurrentPlatform,
1337 (const char *), platform_name_cstr);
1341 if (platform_name_cstr && platform_name_cstr[0]) {
1342 ConstString platform_name(platform_name_cstr);
1343 PlatformSP platform_sp(Platform::Find(platform_name));
1346 // Already have a platform with this name, just select it
1347 m_opaque_sp->GetPlatformList().SetSelectedPlatform(platform_sp);
1349 // We don't have a platform by this name yet, create one
1350 platform_sp = Platform::Create(platform_name, sb_error.ref());
1352 // We created the platform, now append and select it
1353 bool make_selected = true;
1354 m_opaque_sp->GetPlatformList().Append(platform_sp, make_selected);
1358 sb_error.ref().SetErrorString("invalid platform name");
1361 sb_error.ref().SetErrorString("invalid debugger");
1363 return LLDB_RECORD_RESULT(sb_error);
1366 bool SBDebugger::SetCurrentPlatformSDKRoot(const char *sysroot) {
1367 LLDB_RECORD_METHOD(bool, SBDebugger, SetCurrentPlatformSDKRoot,
1368 (const char *), sysroot);
1370 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1372 PlatformSP platform_sp(
1373 m_opaque_sp->GetPlatformList().GetSelectedPlatform());
1377 log->Printf("SBDebugger::SetCurrentPlatformSDKRoot (\"%s\")", sysroot);
1378 platform_sp->SetSDKRootDirectory(ConstString(sysroot));
1385 bool SBDebugger::GetCloseInputOnEOF() const {
1386 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, GetCloseInputOnEOF);
1388 return (m_opaque_sp ? m_opaque_sp->GetCloseInputOnEOF() : false);
1391 void SBDebugger::SetCloseInputOnEOF(bool b) {
1392 LLDB_RECORD_METHOD(void, SBDebugger, SetCloseInputOnEOF, (bool), b);
1395 m_opaque_sp->SetCloseInputOnEOF(b);
1398 SBTypeCategory SBDebugger::GetCategory(const char *category_name) {
1399 LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory,
1400 (const char *), category_name);
1402 if (!category_name || *category_name == 0)
1403 return LLDB_RECORD_RESULT(SBTypeCategory());
1405 TypeCategoryImplSP category_sp;
1407 if (DataVisualization::Categories::GetCategory(ConstString(category_name),
1408 category_sp, false)) {
1409 return LLDB_RECORD_RESULT(SBTypeCategory(category_sp));
1411 return LLDB_RECORD_RESULT(SBTypeCategory());
1415 SBTypeCategory SBDebugger::GetCategory(lldb::LanguageType lang_type) {
1416 LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory,
1417 (lldb::LanguageType), lang_type);
1419 TypeCategoryImplSP category_sp;
1420 if (DataVisualization::Categories::GetCategory(lang_type, category_sp)) {
1421 return LLDB_RECORD_RESULT(SBTypeCategory(category_sp));
1423 return LLDB_RECORD_RESULT(SBTypeCategory());
1427 SBTypeCategory SBDebugger::CreateCategory(const char *category_name) {
1428 LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, CreateCategory,
1429 (const char *), category_name);
1431 if (!category_name || *category_name == 0)
1432 return LLDB_RECORD_RESULT(SBTypeCategory());
1434 TypeCategoryImplSP category_sp;
1436 if (DataVisualization::Categories::GetCategory(ConstString(category_name),
1437 category_sp, true)) {
1438 return LLDB_RECORD_RESULT(SBTypeCategory(category_sp));
1440 return LLDB_RECORD_RESULT(SBTypeCategory());
1444 bool SBDebugger::DeleteCategory(const char *category_name) {
1445 LLDB_RECORD_METHOD(bool, SBDebugger, DeleteCategory, (const char *),
1448 if (!category_name || *category_name == 0)
1451 return DataVisualization::Categories::Delete(ConstString(category_name));
1454 uint32_t SBDebugger::GetNumCategories() {
1455 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumCategories);
1457 return DataVisualization::Categories::GetCount();
1460 SBTypeCategory SBDebugger::GetCategoryAtIndex(uint32_t index) {
1461 LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategoryAtIndex,
1464 return LLDB_RECORD_RESULT(
1465 SBTypeCategory(DataVisualization::Categories::GetCategoryAtIndex(index)));
1468 SBTypeCategory SBDebugger::GetDefaultCategory() {
1469 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTypeCategory, SBDebugger,
1470 GetDefaultCategory);
1472 return LLDB_RECORD_RESULT(GetCategory("default"));
1475 SBTypeFormat SBDebugger::GetFormatForType(SBTypeNameSpecifier type_name) {
1476 LLDB_RECORD_METHOD(lldb::SBTypeFormat, SBDebugger, GetFormatForType,
1477 (lldb::SBTypeNameSpecifier), type_name);
1479 SBTypeCategory default_category_sb = GetDefaultCategory();
1480 if (default_category_sb.GetEnabled())
1481 return LLDB_RECORD_RESULT(default_category_sb.GetFormatForType(type_name));
1482 return LLDB_RECORD_RESULT(SBTypeFormat());
1485 SBTypeSummary SBDebugger::GetSummaryForType(SBTypeNameSpecifier type_name) {
1486 LLDB_RECORD_METHOD(lldb::SBTypeSummary, SBDebugger, GetSummaryForType,
1487 (lldb::SBTypeNameSpecifier), type_name);
1489 if (!type_name.IsValid())
1490 return LLDB_RECORD_RESULT(SBTypeSummary());
1491 return LLDB_RECORD_RESULT(
1492 SBTypeSummary(DataVisualization::GetSummaryForType(type_name.GetSP())));
1495 SBTypeFilter SBDebugger::GetFilterForType(SBTypeNameSpecifier type_name) {
1496 LLDB_RECORD_METHOD(lldb::SBTypeFilter, SBDebugger, GetFilterForType,
1497 (lldb::SBTypeNameSpecifier), type_name);
1499 if (!type_name.IsValid())
1500 return LLDB_RECORD_RESULT(SBTypeFilter());
1501 return LLDB_RECORD_RESULT(
1502 SBTypeFilter(DataVisualization::GetFilterForType(type_name.GetSP())));
1505 SBTypeSynthetic SBDebugger::GetSyntheticForType(SBTypeNameSpecifier type_name) {
1506 LLDB_RECORD_METHOD(lldb::SBTypeSynthetic, SBDebugger, GetSyntheticForType,
1507 (lldb::SBTypeNameSpecifier), type_name);
1509 if (!type_name.IsValid())
1510 return LLDB_RECORD_RESULT(SBTypeSynthetic());
1511 return LLDB_RECORD_RESULT(SBTypeSynthetic(
1512 DataVisualization::GetSyntheticForType(type_name.GetSP())));
1515 static llvm::ArrayRef<const char *> GetCategoryArray(const char **categories) {
1516 if (categories == nullptr)
1519 while (categories[len] != nullptr)
1521 return llvm::makeArrayRef(categories, len);
1524 bool SBDebugger::EnableLog(const char *channel, const char **categories) {
1525 LLDB_RECORD_METHOD(bool, SBDebugger, EnableLog, (const char *, const char **),
1526 channel, categories);
1529 uint32_t log_options =
1530 LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
1532 llvm::raw_string_ostream error_stream(error);
1533 return m_opaque_sp->EnableLog(channel, GetCategoryArray(categories), "",
1534 log_options, error_stream);
1539 void SBDebugger::SetLoggingCallback(lldb::LogOutputCallback log_callback,
1541 LLDB_RECORD_DUMMY(void, SBDebugger, SetLoggingCallback,
1542 (lldb::LogOutputCallback, void *), log_callback, baton);
1545 return m_opaque_sp->SetLoggingCallback(log_callback, baton);
1549 namespace lldb_private {
1553 void RegisterMethods<SBInputReader>(Registry &R) {
1554 LLDB_REGISTER_METHOD(void, SBInputReader, SetIsDone, (bool));
1555 LLDB_REGISTER_METHOD_CONST(bool, SBInputReader, IsActive, ());
1558 static void SetFileHandleRedirect(SBDebugger *, FILE *, bool) {
1562 static bool GetDefaultArchitectureRedirect(char *arch_name,
1563 size_t arch_name_len) {
1564 // The function is writing to its argument. Without the redirect it would
1565 // write into the replay buffer.
1567 return SBDebugger::GetDefaultArchitecture(buffer, arch_name_len);
1571 void RegisterMethods<SBDebugger>(Registry &R) {
1572 // Custom implementation.
1573 R.Register(&invoke<void (SBDebugger::*)(
1574 FILE *, bool)>::method<&SBDebugger::SetErrorFileHandle>::doit,
1575 &SetFileHandleRedirect);
1576 R.Register(&invoke<void (SBDebugger::*)(
1577 FILE *, bool)>::method<&SBDebugger::SetOutputFileHandle>::doit,
1578 &SetFileHandleRedirect);
1579 R.Register<bool(char *, size_t)>(static_cast<bool (*)(char *, size_t)>(
1580 &SBDebugger::GetDefaultArchitecture),
1581 &GetDefaultArchitectureRedirect);
1583 LLDB_REGISTER_CONSTRUCTOR(SBDebugger, ());
1584 LLDB_REGISTER_CONSTRUCTOR(SBDebugger, (const lldb::DebuggerSP &));
1585 LLDB_REGISTER_CONSTRUCTOR(SBDebugger, (const lldb::SBDebugger &));
1586 LLDB_REGISTER_METHOD(lldb::SBDebugger &,
1587 SBDebugger, operator=,(const lldb::SBDebugger &));
1588 LLDB_REGISTER_STATIC_METHOD(void, SBDebugger, Initialize, ());
1589 LLDB_REGISTER_STATIC_METHOD(lldb::SBError, SBDebugger,
1590 InitializeWithErrorHandling, ());
1591 LLDB_REGISTER_STATIC_METHOD(void, SBDebugger, Terminate, ());
1592 LLDB_REGISTER_METHOD(void, SBDebugger, Clear, ());
1593 LLDB_REGISTER_STATIC_METHOD(lldb::SBDebugger, SBDebugger, Create, ());
1594 LLDB_REGISTER_STATIC_METHOD(lldb::SBDebugger, SBDebugger, Create, (bool));
1595 LLDB_REGISTER_STATIC_METHOD(void, SBDebugger, Destroy,
1596 (lldb::SBDebugger &));
1597 LLDB_REGISTER_STATIC_METHOD(void, SBDebugger, MemoryPressureDetected, ());
1598 LLDB_REGISTER_METHOD_CONST(bool, SBDebugger, IsValid, ());
1599 LLDB_REGISTER_METHOD_CONST(bool, SBDebugger, operator bool, ());
1600 LLDB_REGISTER_METHOD(void, SBDebugger, SetAsync, (bool));
1601 LLDB_REGISTER_METHOD(bool, SBDebugger, GetAsync, ());
1602 LLDB_REGISTER_METHOD(void, SBDebugger, SkipLLDBInitFiles, (bool));
1603 LLDB_REGISTER_METHOD(void, SBDebugger, SkipAppInitFiles, (bool));
1604 LLDB_REGISTER_METHOD(void, SBDebugger, SetInputFileHandle, (FILE *, bool));
1605 LLDB_REGISTER_METHOD(FILE *, SBDebugger, GetInputFileHandle, ());
1606 LLDB_REGISTER_METHOD(FILE *, SBDebugger, GetOutputFileHandle, ());
1607 LLDB_REGISTER_METHOD(FILE *, SBDebugger, GetErrorFileHandle, ());
1608 LLDB_REGISTER_METHOD(void, SBDebugger, SaveInputTerminalState, ());
1609 LLDB_REGISTER_METHOD(void, SBDebugger, RestoreInputTerminalState, ());
1610 LLDB_REGISTER_METHOD(lldb::SBCommandInterpreter, SBDebugger,
1611 GetCommandInterpreter, ());
1612 LLDB_REGISTER_METHOD(void, SBDebugger, HandleCommand, (const char *));
1613 LLDB_REGISTER_METHOD(lldb::SBListener, SBDebugger, GetListener, ());
1614 LLDB_REGISTER_METHOD(
1615 void, SBDebugger, HandleProcessEvent,
1616 (const lldb::SBProcess &, const lldb::SBEvent &, FILE *, FILE *));
1617 LLDB_REGISTER_METHOD(lldb::SBSourceManager, SBDebugger, GetSourceManager,
1619 LLDB_REGISTER_STATIC_METHOD(bool, SBDebugger, SetDefaultArchitecture,
1621 LLDB_REGISTER_METHOD(lldb::ScriptLanguage, SBDebugger, GetScriptingLanguage,
1623 LLDB_REGISTER_STATIC_METHOD(const char *, SBDebugger, GetVersionString, ());
1624 LLDB_REGISTER_STATIC_METHOD(const char *, SBDebugger, StateAsCString,
1626 LLDB_REGISTER_STATIC_METHOD(lldb::SBStructuredData, SBDebugger,
1627 GetBuildConfiguration, ());
1628 LLDB_REGISTER_STATIC_METHOD(bool, SBDebugger, StateIsRunningState,
1630 LLDB_REGISTER_STATIC_METHOD(bool, SBDebugger, StateIsStoppedState,
1632 LLDB_REGISTER_METHOD(
1633 lldb::SBTarget, SBDebugger, CreateTarget,
1634 (const char *, const char *, const char *, bool, lldb::SBError &));
1635 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger,
1636 CreateTargetWithFileAndTargetTriple,
1637 (const char *, const char *));
1638 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger,
1639 CreateTargetWithFileAndArch,
1640 (const char *, const char *));
1641 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, CreateTarget,
1643 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, GetDummyTarget, ());
1644 LLDB_REGISTER_METHOD(bool, SBDebugger, DeleteTarget, (lldb::SBTarget &));
1645 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, GetTargetAtIndex,
1647 LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetIndexOfTarget,
1649 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithProcessID,
1651 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithFileAndArch,
1652 (const char *, const char *));
1653 LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetNumTargets, ());
1654 LLDB_REGISTER_METHOD(lldb::SBTarget, SBDebugger, GetSelectedTarget, ());
1655 LLDB_REGISTER_METHOD(void, SBDebugger, SetSelectedTarget,
1656 (lldb::SBTarget &));
1657 LLDB_REGISTER_METHOD(lldb::SBPlatform, SBDebugger, GetSelectedPlatform, ());
1658 LLDB_REGISTER_METHOD(void, SBDebugger, SetSelectedPlatform,
1659 (lldb::SBPlatform &));
1660 LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetNumPlatforms, ());
1661 LLDB_REGISTER_METHOD(lldb::SBPlatform, SBDebugger, GetPlatformAtIndex,
1663 LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetNumAvailablePlatforms, ());
1664 LLDB_REGISTER_METHOD(lldb::SBStructuredData, SBDebugger,
1665 GetAvailablePlatformInfoAtIndex, (uint32_t));
1666 LLDB_REGISTER_METHOD(void, SBDebugger, DispatchInputInterrupt, ());
1667 LLDB_REGISTER_METHOD(void, SBDebugger, DispatchInputEndOfFile, ());
1668 LLDB_REGISTER_METHOD(void, SBDebugger, PushInputReader,
1669 (lldb::SBInputReader &));
1670 LLDB_REGISTER_METHOD(void, SBDebugger, RunCommandInterpreter, (bool, bool));
1671 LLDB_REGISTER_METHOD(void, SBDebugger, RunCommandInterpreter,
1672 (bool, bool, lldb::SBCommandInterpreterRunOptions &,
1673 int &, bool &, bool &));
1674 LLDB_REGISTER_METHOD(lldb::SBError, SBDebugger, RunREPL,
1675 (lldb::LanguageType, const char *));
1676 LLDB_REGISTER_STATIC_METHOD(lldb::SBDebugger, SBDebugger,
1677 FindDebuggerWithID, (int));
1678 LLDB_REGISTER_METHOD(const char *, SBDebugger, GetInstanceName, ());
1679 LLDB_REGISTER_STATIC_METHOD(lldb::SBError, SBDebugger, SetInternalVariable,
1680 (const char *, const char *, const char *));
1681 LLDB_REGISTER_STATIC_METHOD(lldb::SBStringList, SBDebugger,
1682 GetInternalVariableValue,
1683 (const char *, const char *));
1684 LLDB_REGISTER_METHOD_CONST(uint32_t, SBDebugger, GetTerminalWidth, ());
1685 LLDB_REGISTER_METHOD(void, SBDebugger, SetTerminalWidth, (uint32_t));
1686 LLDB_REGISTER_METHOD_CONST(const char *, SBDebugger, GetPrompt, ());
1687 LLDB_REGISTER_METHOD(void, SBDebugger, SetPrompt, (const char *));
1688 LLDB_REGISTER_METHOD_CONST(const char *, SBDebugger, GetReproducerPath, ());
1689 LLDB_REGISTER_METHOD_CONST(lldb::ScriptLanguage, SBDebugger,
1690 GetScriptLanguage, ());
1691 LLDB_REGISTER_METHOD(void, SBDebugger, SetScriptLanguage,
1692 (lldb::ScriptLanguage));
1693 LLDB_REGISTER_METHOD(bool, SBDebugger, SetUseExternalEditor, (bool));
1694 LLDB_REGISTER_METHOD(bool, SBDebugger, GetUseExternalEditor, ());
1695 LLDB_REGISTER_METHOD(bool, SBDebugger, SetUseColor, (bool));
1696 LLDB_REGISTER_METHOD_CONST(bool, SBDebugger, GetUseColor, ());
1697 LLDB_REGISTER_METHOD(bool, SBDebugger, GetDescription, (lldb::SBStream &));
1698 LLDB_REGISTER_METHOD(lldb::user_id_t, SBDebugger, GetID, ());
1699 LLDB_REGISTER_METHOD(lldb::SBError, SBDebugger, SetCurrentPlatform,
1701 LLDB_REGISTER_METHOD(bool, SBDebugger, SetCurrentPlatformSDKRoot,
1703 LLDB_REGISTER_METHOD_CONST(bool, SBDebugger, GetCloseInputOnEOF, ());
1704 LLDB_REGISTER_METHOD(void, SBDebugger, SetCloseInputOnEOF, (bool));
1705 LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory,
1707 LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory,
1708 (lldb::LanguageType));
1709 LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, CreateCategory,
1711 LLDB_REGISTER_METHOD(bool, SBDebugger, DeleteCategory, (const char *));
1712 LLDB_REGISTER_METHOD(uint32_t, SBDebugger, GetNumCategories, ());
1713 LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategoryAtIndex,
1715 LLDB_REGISTER_METHOD(lldb::SBTypeCategory, SBDebugger, GetDefaultCategory,
1717 LLDB_REGISTER_METHOD(lldb::SBTypeFormat, SBDebugger, GetFormatForType,
1718 (lldb::SBTypeNameSpecifier));
1719 LLDB_REGISTER_METHOD(lldb::SBTypeSummary, SBDebugger, GetSummaryForType,
1720 (lldb::SBTypeNameSpecifier));
1721 LLDB_REGISTER_METHOD(lldb::SBTypeSynthetic, SBDebugger, GetSyntheticForType,
1722 (lldb::SBTypeNameSpecifier));
1723 LLDB_REGISTER_METHOD(lldb::SBTypeFilter, SBDebugger, GetFilterForType,
1724 (lldb::SBTypeNameSpecifier));
1725 LLDB_REGISTER_METHOD(bool, SBDebugger, EnableLog,
1726 (const char *, const char **));