1 //===-- SBDebugger.cpp ----------------------------------------------------===//
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 "lldb/API/SBDebugger.h"
10 #include "SystemInitializerFull.h"
11 #include "lldb/Utility/Instrumentation.h"
12 #include "lldb/Utility/LLDBLog.h"
14 #include "lldb/API/SBBroadcaster.h"
15 #include "lldb/API/SBCommandInterpreter.h"
16 #include "lldb/API/SBCommandInterpreterRunOptions.h"
17 #include "lldb/API/SBCommandReturnObject.h"
18 #include "lldb/API/SBError.h"
19 #include "lldb/API/SBEvent.h"
20 #include "lldb/API/SBFile.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/SBTrace.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"
38 #include "lldb/Core/Debugger.h"
39 #include "lldb/Core/DebuggerEvents.h"
40 #include "lldb/Core/PluginManager.h"
41 #include "lldb/Core/Progress.h"
42 #include "lldb/Core/StructuredDataImpl.h"
43 #include "lldb/DataFormatters/DataVisualization.h"
44 #include "lldb/Host/Config.h"
45 #include "lldb/Host/StreamFile.h"
46 #include "lldb/Host/XML.h"
47 #include "lldb/Initialization/SystemLifetimeManager.h"
48 #include "lldb/Interpreter/CommandInterpreter.h"
49 #include "lldb/Interpreter/OptionArgParser.h"
50 #include "lldb/Interpreter/OptionGroupPlatform.h"
51 #include "lldb/Target/Process.h"
52 #include "lldb/Target/TargetList.h"
53 #include "lldb/Utility/Args.h"
54 #include "lldb/Utility/Diagnostics.h"
55 #include "lldb/Utility/State.h"
56 #include "lldb/Version/Version.h"
58 #include "llvm/ADT/STLExtras.h"
59 #include "llvm/ADT/StringRef.h"
60 #include "llvm/Config/llvm-config.h" // for LLVM_ENABLE_CURL
61 #include "llvm/Support/DynamicLibrary.h"
62 #include "llvm/Support/ManagedStatic.h"
63 #include "llvm/Support/PrettyStackTrace.h"
64 #include "llvm/Support/Signals.h"
67 using namespace lldb_private
;
69 static llvm::ManagedStatic
<SystemLifetimeManager
> g_debugger_lifetime
;
71 SBError
SBInputReader::Initialize(
72 lldb::SBDebugger
&sb_debugger
,
73 unsigned long (*callback
)(void *, lldb::SBInputReader
*,
74 lldb::InputReaderAction
, char const *,
76 void *a
, lldb::InputReaderGranularity b
, char const *c
, char const *d
,
78 LLDB_INSTRUMENT_VA(this, sb_debugger
, callback
, a
, b
, c
, d
, e
);
83 void SBInputReader::SetIsDone(bool b
) { LLDB_INSTRUMENT_VA(this, b
); }
85 bool SBInputReader::IsActive() const {
86 LLDB_INSTRUMENT_VA(this);
91 SBDebugger::SBDebugger() { LLDB_INSTRUMENT_VA(this); }
93 SBDebugger::SBDebugger(const lldb::DebuggerSP
&debugger_sp
)
94 : m_opaque_sp(debugger_sp
) {
95 LLDB_INSTRUMENT_VA(this, debugger_sp
);
98 SBDebugger::SBDebugger(const SBDebugger
&rhs
) : m_opaque_sp(rhs
.m_opaque_sp
) {
99 LLDB_INSTRUMENT_VA(this, rhs
);
102 SBDebugger::~SBDebugger() = default;
104 SBDebugger
&SBDebugger::operator=(const SBDebugger
&rhs
) {
105 LLDB_INSTRUMENT_VA(this, rhs
);
108 m_opaque_sp
= rhs
.m_opaque_sp
;
113 const char *SBDebugger::GetBroadcasterClass() {
116 return ConstString(Debugger::GetStaticBroadcasterClass()).AsCString();
119 const char *SBDebugger::GetProgressFromEvent(const lldb::SBEvent
&event
,
120 uint64_t &progress_id
,
123 bool &is_debugger_specific
) {
124 LLDB_INSTRUMENT_VA(event
);
126 const ProgressEventData
*progress_data
=
127 ProgressEventData::GetEventDataFromEvent(event
.get());
128 if (progress_data
== nullptr)
130 progress_id
= progress_data
->GetID();
131 completed
= progress_data
->GetCompleted();
132 total
= progress_data
->GetTotal();
133 is_debugger_specific
= progress_data
->IsDebuggerSpecific();
134 ConstString
message(progress_data
->GetMessage());
135 return message
.AsCString();
138 lldb::SBStructuredData
139 SBDebugger::GetProgressDataFromEvent(const lldb::SBEvent
&event
) {
140 LLDB_INSTRUMENT_VA(event
);
142 StructuredData::DictionarySP dictionary_sp
=
143 ProgressEventData::GetAsStructuredData(event
.get());
148 SBStructuredData data
;
149 data
.m_impl_up
->SetObjectSP(std::move(dictionary_sp
));
153 lldb::SBStructuredData
154 SBDebugger::GetDiagnosticFromEvent(const lldb::SBEvent
&event
) {
155 LLDB_INSTRUMENT_VA(event
);
157 StructuredData::DictionarySP dictionary_sp
=
158 DiagnosticEventData::GetAsStructuredData(event
.get());
163 SBStructuredData data
;
164 data
.m_impl_up
->SetObjectSP(std::move(dictionary_sp
));
168 SBBroadcaster
SBDebugger::GetBroadcaster() {
169 LLDB_INSTRUMENT_VA(this);
170 SBBroadcaster
broadcaster(&m_opaque_sp
->GetBroadcaster(), false);
174 void SBDebugger::Initialize() {
176 SBError ignored
= SBDebugger::InitializeWithErrorHandling();
179 lldb::SBError
SBDebugger::InitializeWithErrorHandling() {
182 auto LoadPlugin
= [](const lldb::DebuggerSP
&debugger_sp
,
183 const FileSpec
&spec
,
184 Status
&error
) -> llvm::sys::DynamicLibrary
{
185 llvm::sys::DynamicLibrary dynlib
=
186 llvm::sys::DynamicLibrary::getPermanentLibrary(spec
.GetPath().c_str());
187 if (dynlib
.isValid()) {
188 typedef bool (*LLDBCommandPluginInit
)(lldb::SBDebugger
& debugger
);
190 lldb::SBDebugger
debugger_sb(debugger_sp
);
191 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger)
193 // TODO: mangle this differently for your system - on OSX, the first
194 // underscore needs to be removed and the second one stays
195 LLDBCommandPluginInit init_func
=
196 (LLDBCommandPluginInit
)(uintptr_t)dynlib
.getAddressOfSymbol(
197 "_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
199 if (init_func(debugger_sb
))
202 error
= Status::FromErrorString(
203 "plug-in refused to load "
204 "(lldb::PluginInitialize(lldb::SBDebugger) "
207 error
= Status::FromErrorString(
208 "plug-in is missing the required initialization: "
209 "lldb::PluginInitialize(lldb::SBDebugger)");
212 if (FileSystem::Instance().Exists(spec
))
213 error
= Status::FromErrorString(
214 "this file does not represent a loadable dylib");
216 error
= Status::FromErrorString("no such file");
218 return llvm::sys::DynamicLibrary();
222 if (auto e
= g_debugger_lifetime
->Initialize(
223 std::make_unique
<SystemInitializerFull
>(), LoadPlugin
)) {
224 error
.SetError(Status::FromError(std::move(e
)));
229 void SBDebugger::PrintStackTraceOnError() {
232 llvm::EnablePrettyStackTrace();
233 static std::string executable
=
234 llvm::sys::fs::getMainExecutable(nullptr, nullptr);
235 llvm::sys::PrintStackTraceOnErrorSignal(executable
);
238 static void DumpDiagnostics(void *cookie
) {
239 Diagnostics::Instance().Dump(llvm::errs());
242 void SBDebugger::PrintDiagnosticsOnError() {
245 llvm::sys::AddSignalHandler(&DumpDiagnostics
, nullptr);
248 void SBDebugger::Terminate() {
251 g_debugger_lifetime
->Terminate();
254 void SBDebugger::Clear() {
255 LLDB_INSTRUMENT_VA(this);
258 m_opaque_sp
->ClearIOHandlers();
263 SBDebugger
SBDebugger::Create() {
266 return SBDebugger::Create(false, nullptr, nullptr);
269 SBDebugger
SBDebugger::Create(bool source_init_files
) {
270 LLDB_INSTRUMENT_VA(source_init_files
);
272 return SBDebugger::Create(source_init_files
, nullptr, nullptr);
275 SBDebugger
SBDebugger::Create(bool source_init_files
,
276 lldb::LogOutputCallback callback
, void *baton
)
279 LLDB_INSTRUMENT_VA(source_init_files
, callback
, baton
);
283 // Currently we have issues if this function is called simultaneously on two
284 // different threads. The issues mainly revolve around the fact that the
285 // lldb_private::FormatManager uses global collections and having two threads
286 // parsing the .lldbinit files can cause mayhem. So to get around this for
287 // now we need to use a mutex to prevent bad things from happening.
288 static std::recursive_mutex g_mutex
;
289 std::lock_guard
<std::recursive_mutex
> guard(g_mutex
);
291 debugger
.reset(Debugger::CreateInstance(callback
, baton
));
293 SBCommandInterpreter interp
= debugger
.GetCommandInterpreter();
294 if (source_init_files
) {
295 interp
.get()->SkipLLDBInitFiles(false);
296 interp
.get()->SkipAppInitFiles(false);
297 SBCommandReturnObject result
;
298 interp
.SourceInitFileInGlobalDirectory(result
);
299 interp
.SourceInitFileInHomeDirectory(result
, false);
301 interp
.get()->SkipLLDBInitFiles(true);
302 interp
.get()->SkipAppInitFiles(true);
307 void SBDebugger::Destroy(SBDebugger
&debugger
) {
308 LLDB_INSTRUMENT_VA(debugger
);
310 Debugger::Destroy(debugger
.m_opaque_sp
);
312 if (debugger
.m_opaque_sp
.get() != nullptr)
313 debugger
.m_opaque_sp
.reset();
316 void SBDebugger::MemoryPressureDetected() {
319 // Since this function can be call asynchronously, we allow it to be non-
320 // mandatory. We have seen deadlocks with this function when called so we
321 // need to safeguard against this until we can determine what is causing the
324 const bool mandatory
= false;
326 ModuleList::RemoveOrphanSharedModules(mandatory
);
329 bool SBDebugger::IsValid() const {
330 LLDB_INSTRUMENT_VA(this);
331 return this->operator bool();
333 SBDebugger::operator bool() const {
334 LLDB_INSTRUMENT_VA(this);
336 return m_opaque_sp
.get() != nullptr;
339 void SBDebugger::SetAsync(bool b
) {
340 LLDB_INSTRUMENT_VA(this, b
);
343 m_opaque_sp
->SetAsyncExecution(b
);
346 bool SBDebugger::GetAsync() {
347 LLDB_INSTRUMENT_VA(this);
349 return (m_opaque_sp
? m_opaque_sp
->GetAsyncExecution() : false);
352 void SBDebugger::SkipLLDBInitFiles(bool b
) {
353 LLDB_INSTRUMENT_VA(this, b
);
356 m_opaque_sp
->GetCommandInterpreter().SkipLLDBInitFiles(b
);
359 void SBDebugger::SkipAppInitFiles(bool b
) {
360 LLDB_INSTRUMENT_VA(this, b
);
363 m_opaque_sp
->GetCommandInterpreter().SkipAppInitFiles(b
);
366 void SBDebugger::SetInputFileHandle(FILE *fh
, bool transfer_ownership
) {
367 LLDB_INSTRUMENT_VA(this, fh
, transfer_ownership
);
369 m_opaque_sp
->SetInputFile(
370 (FileSP
)std::make_shared
<NativeFile
>(fh
, transfer_ownership
));
373 SBError
SBDebugger::SetInputString(const char *data
) {
374 LLDB_INSTRUMENT_VA(this, data
);
376 if (data
== nullptr) {
377 sb_error
= Status::FromErrorString("String data is null");
381 size_t size
= strlen(data
);
383 sb_error
= Status::FromErrorString("String data is empty");
388 sb_error
= Status::FromErrorString("invalid debugger");
392 sb_error
.SetError(m_opaque_sp
->SetInputString(data
));
396 // Shouldn't really be settable after initialization as this could cause lots
397 // of problems; don't want users trying to switch modes in the middle of a
398 // debugging session.
399 SBError
SBDebugger::SetInputFile(SBFile file
) {
400 LLDB_INSTRUMENT_VA(this, file
);
404 error
.ref() = Status::FromErrorString("invalid debugger");
408 error
.ref() = Status::FromErrorString("invalid file");
411 m_opaque_sp
->SetInputFile(file
.m_opaque_sp
);
415 SBError
SBDebugger::SetInputFile(FileSP file_sp
) {
416 LLDB_INSTRUMENT_VA(this, file_sp
);
417 return SetInputFile(SBFile(file_sp
));
420 SBError
SBDebugger::SetOutputFile(FileSP file_sp
) {
421 LLDB_INSTRUMENT_VA(this, file_sp
);
422 return SetOutputFile(SBFile(file_sp
));
425 void SBDebugger::SetOutputFileHandle(FILE *fh
, bool transfer_ownership
) {
426 LLDB_INSTRUMENT_VA(this, fh
, transfer_ownership
);
427 SetOutputFile((FileSP
)std::make_shared
<NativeFile
>(fh
, transfer_ownership
));
430 SBError
SBDebugger::SetOutputFile(SBFile file
) {
431 LLDB_INSTRUMENT_VA(this, file
);
434 error
.ref() = Status::FromErrorString("invalid debugger");
438 error
.ref() = Status::FromErrorString("invalid file");
441 m_opaque_sp
->SetOutputFile(file
.m_opaque_sp
);
445 void SBDebugger::SetErrorFileHandle(FILE *fh
, bool transfer_ownership
) {
446 LLDB_INSTRUMENT_VA(this, fh
, transfer_ownership
);
447 SetErrorFile((FileSP
)std::make_shared
<NativeFile
>(fh
, transfer_ownership
));
450 SBError
SBDebugger::SetErrorFile(FileSP file_sp
) {
451 LLDB_INSTRUMENT_VA(this, file_sp
);
452 return SetErrorFile(SBFile(file_sp
));
455 SBError
SBDebugger::SetErrorFile(SBFile file
) {
456 LLDB_INSTRUMENT_VA(this, file
);
459 error
.ref() = Status::FromErrorString("invalid debugger");
463 error
.ref() = Status::FromErrorString("invalid file");
466 m_opaque_sp
->SetErrorFile(file
.m_opaque_sp
);
470 lldb::SBStructuredData
SBDebugger::GetSetting(const char *setting
) {
471 LLDB_INSTRUMENT_VA(this, setting
);
473 SBStructuredData data
;
477 StreamString json_strm
;
478 ExecutionContext
exe_ctx(
479 m_opaque_sp
->GetCommandInterpreter().GetExecutionContext());
480 if (setting
&& strlen(setting
) > 0)
481 m_opaque_sp
->DumpPropertyValue(&exe_ctx
, json_strm
, setting
,
485 m_opaque_sp
->DumpAllPropertyValues(&exe_ctx
, json_strm
, /*dump_mask*/ 0,
488 data
.m_impl_up
->SetObjectSP(StructuredData::ParseJSON(json_strm
.GetString()));
492 FILE *SBDebugger::GetInputFileHandle() {
493 LLDB_INSTRUMENT_VA(this);
495 File
&file_sp
= m_opaque_sp
->GetInputFile();
496 return file_sp
.GetStream();
501 SBFile
SBDebugger::GetInputFile() {
502 LLDB_INSTRUMENT_VA(this);
504 return SBFile(m_opaque_sp
->GetInputFileSP());
509 FILE *SBDebugger::GetOutputFileHandle() {
510 LLDB_INSTRUMENT_VA(this);
512 StreamFile
&stream_file
= m_opaque_sp
->GetOutputStream();
513 return stream_file
.GetFile().GetStream();
518 SBFile
SBDebugger::GetOutputFile() {
519 LLDB_INSTRUMENT_VA(this);
521 SBFile
file(m_opaque_sp
->GetOutputStream().GetFileSP());
527 FILE *SBDebugger::GetErrorFileHandle() {
528 LLDB_INSTRUMENT_VA(this);
531 StreamFile
&stream_file
= m_opaque_sp
->GetErrorStream();
532 return stream_file
.GetFile().GetStream();
537 SBFile
SBDebugger::GetErrorFile() {
538 LLDB_INSTRUMENT_VA(this);
541 SBFile
file(m_opaque_sp
->GetErrorStream().GetFileSP());
547 void SBDebugger::SaveInputTerminalState() {
548 LLDB_INSTRUMENT_VA(this);
551 m_opaque_sp
->SaveInputTerminalState();
554 void SBDebugger::RestoreInputTerminalState() {
555 LLDB_INSTRUMENT_VA(this);
558 m_opaque_sp
->RestoreInputTerminalState();
560 SBCommandInterpreter
SBDebugger::GetCommandInterpreter() {
561 LLDB_INSTRUMENT_VA(this);
563 SBCommandInterpreter sb_interpreter
;
565 sb_interpreter
.reset(&m_opaque_sp
->GetCommandInterpreter());
567 return sb_interpreter
;
570 void SBDebugger::HandleCommand(const char *command
) {
571 LLDB_INSTRUMENT_VA(this, command
);
574 TargetSP
target_sp(m_opaque_sp
->GetSelectedTarget());
575 std::unique_lock
<std::recursive_mutex
> lock
;
577 lock
= std::unique_lock
<std::recursive_mutex
>(target_sp
->GetAPIMutex());
579 SBCommandInterpreter
sb_interpreter(GetCommandInterpreter());
580 SBCommandReturnObject result
;
582 sb_interpreter
.HandleCommand(command
, result
, false);
584 result
.PutError(m_opaque_sp
->GetErrorStream().GetFileSP());
585 result
.PutOutput(m_opaque_sp
->GetOutputStream().GetFileSP());
587 if (!m_opaque_sp
->GetAsyncExecution()) {
588 SBProcess
process(GetCommandInterpreter().GetProcess());
589 ProcessSP
process_sp(process
.GetSP());
592 ListenerSP lldb_listener_sp
= m_opaque_sp
->GetListener();
593 while (lldb_listener_sp
->GetEventForBroadcaster(
594 process_sp
.get(), event_sp
, std::chrono::seconds(0))) {
595 SBEvent
event(event_sp
);
596 HandleProcessEvent(process
, event
, GetOutputFile(), GetErrorFile());
603 SBListener
SBDebugger::GetListener() {
604 LLDB_INSTRUMENT_VA(this);
606 SBListener sb_listener
;
608 sb_listener
.reset(m_opaque_sp
->GetListener());
613 void SBDebugger::HandleProcessEvent(const SBProcess
&process
,
614 const SBEvent
&event
, SBFile out
,
616 LLDB_INSTRUMENT_VA(this, process
, event
, out
, err
);
618 return HandleProcessEvent(process
, event
, out
.m_opaque_sp
, err
.m_opaque_sp
);
621 void SBDebugger::HandleProcessEvent(const SBProcess
&process
,
622 const SBEvent
&event
, FILE *out
,
624 LLDB_INSTRUMENT_VA(this, process
, event
, out
, err
);
626 FileSP outfile
= std::make_shared
<NativeFile
>(out
, false);
627 FileSP errfile
= std::make_shared
<NativeFile
>(err
, false);
628 return HandleProcessEvent(process
, event
, outfile
, errfile
);
631 void SBDebugger::HandleProcessEvent(const SBProcess
&process
,
632 const SBEvent
&event
, FileSP out_sp
,
635 LLDB_INSTRUMENT_VA(this, process
, event
, out_sp
, err_sp
);
637 if (!process
.IsValid())
640 TargetSP
target_sp(process
.GetTarget().GetSP());
644 const uint32_t event_type
= event
.GetType();
645 char stdio_buffer
[1024];
648 std::lock_guard
<std::recursive_mutex
> guard(target_sp
->GetAPIMutex());
651 (Process::eBroadcastBitSTDOUT
| Process::eBroadcastBitStateChanged
)) {
652 // Drain stdout when we stop just in case we have any bytes
653 while ((len
= process
.GetSTDOUT(stdio_buffer
, sizeof(stdio_buffer
))) > 0)
655 out_sp
->Write(stdio_buffer
, len
);
659 (Process::eBroadcastBitSTDERR
| Process::eBroadcastBitStateChanged
)) {
660 // Drain stderr when we stop just in case we have any bytes
661 while ((len
= process
.GetSTDERR(stdio_buffer
, sizeof(stdio_buffer
))) > 0)
663 err_sp
->Write(stdio_buffer
, len
);
666 if (event_type
& Process::eBroadcastBitStateChanged
) {
667 StateType event_state
= SBProcess::GetStateFromEvent(event
);
669 if (event_state
== eStateInvalid
)
672 bool is_stopped
= StateIsStoppedState(event_state
);
674 process
.ReportEventState(event
, out_sp
);
678 SBSourceManager
SBDebugger::GetSourceManager() {
679 LLDB_INSTRUMENT_VA(this);
681 SBSourceManager
sb_source_manager(*this);
682 return sb_source_manager
;
685 bool SBDebugger::GetDefaultArchitecture(char *arch_name
, size_t arch_name_len
) {
686 LLDB_INSTRUMENT_VA(arch_name
, arch_name_len
);
688 if (arch_name
&& arch_name_len
) {
689 ArchSpec default_arch
= Target::GetDefaultArchitecture();
691 if (default_arch
.IsValid()) {
692 const std::string
&triple_str
= default_arch
.GetTriple().str();
693 if (!triple_str
.empty())
694 ::snprintf(arch_name
, arch_name_len
, "%s", triple_str
.c_str());
696 ::snprintf(arch_name
, arch_name_len
, "%s",
697 default_arch
.GetArchitectureName());
701 if (arch_name
&& arch_name_len
)
706 bool SBDebugger::SetDefaultArchitecture(const char *arch_name
) {
707 LLDB_INSTRUMENT_VA(arch_name
);
710 ArchSpec
arch(arch_name
);
711 if (arch
.IsValid()) {
712 Target::SetDefaultArchitecture(arch
);
720 SBDebugger::GetScriptingLanguage(const char *script_language_name
) {
721 LLDB_INSTRUMENT_VA(this, script_language_name
);
723 if (!script_language_name
)
724 return eScriptLanguageDefault
;
725 return OptionArgParser::ToScriptLanguage(
726 llvm::StringRef(script_language_name
), eScriptLanguageDefault
, nullptr);
730 SBDebugger::GetScriptInterpreterInfo(lldb::ScriptLanguage language
) {
731 LLDB_INSTRUMENT_VA(this, language
);
732 SBStructuredData data
;
734 lldb_private::ScriptInterpreter
*interp
=
735 m_opaque_sp
->GetScriptInterpreter(language
);
737 data
.m_impl_up
->SetObjectSP(interp
->GetInterpreterInfo());
743 const char *SBDebugger::GetVersionString() {
746 return lldb_private::GetVersion();
749 const char *SBDebugger::StateAsCString(StateType state
) {
750 LLDB_INSTRUMENT_VA(state
);
752 return lldb_private::StateAsCString(state
);
755 static void AddBoolConfigEntry(StructuredData::Dictionary
&dict
,
756 llvm::StringRef name
, bool value
,
757 llvm::StringRef description
) {
758 auto entry_up
= std::make_unique
<StructuredData::Dictionary
>();
759 entry_up
->AddBooleanItem("value", value
);
760 entry_up
->AddStringItem("description", description
);
761 dict
.AddItem(name
, std::move(entry_up
));
764 static void AddLLVMTargets(StructuredData::Dictionary
&dict
) {
765 auto array_up
= std::make_unique
<StructuredData::Array
>();
766 #define LLVM_TARGET(target) \
767 array_up->AddItem(std::make_unique<StructuredData::String>(#target));
768 #include "llvm/Config/Targets.def"
769 auto entry_up
= std::make_unique
<StructuredData::Dictionary
>();
770 entry_up
->AddItem("value", std::move(array_up
));
771 entry_up
->AddStringItem("description", "A list of configured LLVM targets.");
772 dict
.AddItem("targets", std::move(entry_up
));
775 SBStructuredData
SBDebugger::GetBuildConfiguration() {
778 auto config_up
= std::make_unique
<StructuredData::Dictionary
>();
780 *config_up
, "xml", XMLDocument::XMLEnabled(),
781 "A boolean value that indicates if XML support is enabled in LLDB");
783 *config_up
, "curl", LLVM_ENABLE_CURL
,
784 "A boolean value that indicates if CURL support is enabled in LLDB");
786 *config_up
, "curses", LLDB_ENABLE_CURSES
,
787 "A boolean value that indicates if curses support is enabled in LLDB");
789 *config_up
, "editline", LLDB_ENABLE_LIBEDIT
,
790 "A boolean value that indicates if editline support is enabled in LLDB");
791 AddBoolConfigEntry(*config_up
, "editline_wchar", LLDB_EDITLINE_USE_WCHAR
,
792 "A boolean value that indicates if editline wide "
793 "characters support is enabled in LLDB");
795 *config_up
, "lzma", LLDB_ENABLE_LZMA
,
796 "A boolean value that indicates if lzma support is enabled in LLDB");
798 *config_up
, "python", LLDB_ENABLE_PYTHON
,
799 "A boolean value that indicates if python support is enabled in LLDB");
801 *config_up
, "lua", LLDB_ENABLE_LUA
,
802 "A boolean value that indicates if lua support is enabled in LLDB");
803 AddBoolConfigEntry(*config_up
, "fbsdvmcore", LLDB_ENABLE_FBSDVMCORE
,
804 "A boolean value that indicates if fbsdvmcore support is "
806 AddLLVMTargets(*config_up
);
808 SBStructuredData data
;
809 data
.m_impl_up
->SetObjectSP(std::move(config_up
));
813 bool SBDebugger::StateIsRunningState(StateType state
) {
814 LLDB_INSTRUMENT_VA(state
);
816 const bool result
= lldb_private::StateIsRunningState(state
);
821 bool SBDebugger::StateIsStoppedState(StateType state
) {
822 LLDB_INSTRUMENT_VA(state
);
824 const bool result
= lldb_private::StateIsStoppedState(state
, false);
829 lldb::SBTarget
SBDebugger::CreateTarget(const char *filename
,
830 const char *target_triple
,
831 const char *platform_name
,
832 bool add_dependent_modules
,
833 lldb::SBError
&sb_error
) {
834 LLDB_INSTRUMENT_VA(this, filename
, target_triple
, platform_name
,
835 add_dependent_modules
, sb_error
);
841 OptionGroupPlatform
platform_options(false);
842 platform_options
.SetPlatformName(platform_name
);
844 sb_error
.ref() = m_opaque_sp
->GetTargetList().CreateTarget(
845 *m_opaque_sp
, filename
, target_triple
,
846 add_dependent_modules
? eLoadDependentsYes
: eLoadDependentsNo
,
847 &platform_options
, target_sp
);
849 if (sb_error
.Success())
850 sb_target
.SetSP(target_sp
);
852 sb_error
= Status::FromErrorString("invalid debugger");
855 Log
*log
= GetLog(LLDBLog::API
);
857 "SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, "
858 "platform_name=%s, add_dependent_modules=%u, error=%s) => "
860 static_cast<void *>(m_opaque_sp
.get()), filename
, target_triple
,
861 platform_name
, add_dependent_modules
, sb_error
.GetCString(),
862 static_cast<void *>(target_sp
.get()));
868 SBDebugger::CreateTargetWithFileAndTargetTriple(const char *filename
,
869 const char *target_triple
) {
870 LLDB_INSTRUMENT_VA(this, filename
, target_triple
);
875 const bool add_dependent_modules
= true;
876 Status
error(m_opaque_sp
->GetTargetList().CreateTarget(
877 *m_opaque_sp
, filename
, target_triple
,
878 add_dependent_modules
? eLoadDependentsYes
: eLoadDependentsNo
, nullptr,
880 sb_target
.SetSP(target_sp
);
883 Log
*log
= GetLog(LLDBLog::API
);
885 "SBDebugger(%p)::CreateTargetWithFileAndTargetTriple "
886 "(filename=\"%s\", triple=%s) => SBTarget(%p)",
887 static_cast<void *>(m_opaque_sp
.get()), filename
, target_triple
,
888 static_cast<void *>(target_sp
.get()));
893 SBTarget
SBDebugger::CreateTargetWithFileAndArch(const char *filename
,
894 const char *arch_cstr
) {
895 LLDB_INSTRUMENT_VA(this, filename
, arch_cstr
);
897 Log
*log
= GetLog(LLDBLog::API
);
903 if (arch_cstr
== nullptr) {
904 // The version of CreateTarget that takes an ArchSpec won't accept an
905 // empty ArchSpec, so when the arch hasn't been specified, we need to
906 // call the target triple version.
907 error
= m_opaque_sp
->GetTargetList().CreateTarget(
908 *m_opaque_sp
, filename
, arch_cstr
, eLoadDependentsYes
, nullptr,
911 PlatformSP platform_sp
=
912 m_opaque_sp
->GetPlatformList().GetSelectedPlatform();
914 Platform::GetAugmentedArchSpec(platform_sp
.get(), arch_cstr
);
916 error
= m_opaque_sp
->GetTargetList().CreateTarget(
917 *m_opaque_sp
, filename
, arch
, eLoadDependentsYes
, platform_sp
,
920 error
= Status::FromErrorStringWithFormat("invalid arch_cstr: %s",
924 sb_target
.SetSP(target_sp
);
928 "SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", "
929 "arch=%s) => SBTarget(%p)",
930 static_cast<void *>(m_opaque_sp
.get()),
931 filename
? filename
: "<unspecified>",
932 arch_cstr
? arch_cstr
: "<unspecified>",
933 static_cast<void *>(target_sp
.get()));
938 SBTarget
SBDebugger::CreateTarget(const char *filename
) {
939 LLDB_INSTRUMENT_VA(this, filename
);
945 const bool add_dependent_modules
= true;
946 error
= m_opaque_sp
->GetTargetList().CreateTarget(
947 *m_opaque_sp
, filename
, "",
948 add_dependent_modules
? eLoadDependentsYes
: eLoadDependentsNo
, nullptr,
952 sb_target
.SetSP(target_sp
);
954 Log
*log
= GetLog(LLDBLog::API
);
956 "SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
957 static_cast<void *>(m_opaque_sp
.get()), filename
,
958 static_cast<void *>(target_sp
.get()));
962 SBTarget
SBDebugger::GetDummyTarget() {
963 LLDB_INSTRUMENT_VA(this);
967 sb_target
.SetSP(m_opaque_sp
->GetDummyTarget().shared_from_this());
969 Log
*log
= GetLog(LLDBLog::API
);
970 LLDB_LOGF(log
, "SBDebugger(%p)::GetDummyTarget() => SBTarget(%p)",
971 static_cast<void *>(m_opaque_sp
.get()),
972 static_cast<void *>(sb_target
.GetSP().get()));
976 bool SBDebugger::DeleteTarget(lldb::SBTarget
&target
) {
977 LLDB_INSTRUMENT_VA(this, target
);
981 TargetSP
target_sp(target
.GetSP());
983 // No need to lock, the target list is thread safe
984 result
= m_opaque_sp
->GetTargetList().DeleteTarget(target_sp
);
985 target_sp
->Destroy();
990 Log
*log
= GetLog(LLDBLog::API
);
991 LLDB_LOGF(log
, "SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i",
992 static_cast<void *>(m_opaque_sp
.get()),
993 static_cast<void *>(target
.m_opaque_sp
.get()), result
);
998 SBTarget
SBDebugger::GetTargetAtIndex(uint32_t idx
) {
999 LLDB_INSTRUMENT_VA(this, idx
);
1003 // No need to lock, the target list is thread safe
1004 sb_target
.SetSP(m_opaque_sp
->GetTargetList().GetTargetAtIndex(idx
));
1009 uint32_t SBDebugger::GetIndexOfTarget(lldb::SBTarget target
) {
1010 LLDB_INSTRUMENT_VA(this, target
);
1012 lldb::TargetSP target_sp
= target
.GetSP();
1019 return m_opaque_sp
->GetTargetList().GetIndexOfTarget(target
.GetSP());
1022 SBTarget
SBDebugger::FindTargetWithProcessID(lldb::pid_t pid
) {
1023 LLDB_INSTRUMENT_VA(this, pid
);
1027 // No need to lock, the target list is thread safe
1028 sb_target
.SetSP(m_opaque_sp
->GetTargetList().FindTargetWithProcessID(pid
));
1033 SBTarget
SBDebugger::FindTargetWithFileAndArch(const char *filename
,
1034 const char *arch_name
) {
1035 LLDB_INSTRUMENT_VA(this, filename
, arch_name
);
1038 if (m_opaque_sp
&& filename
&& filename
[0]) {
1039 // No need to lock, the target list is thread safe
1040 ArchSpec arch
= Platform::GetAugmentedArchSpec(
1041 m_opaque_sp
->GetPlatformList().GetSelectedPlatform().get(), arch_name
);
1043 m_opaque_sp
->GetTargetList().FindTargetWithExecutableAndArchitecture(
1044 FileSpec(filename
), arch_name
? &arch
: nullptr));
1045 sb_target
.SetSP(target_sp
);
1050 SBTarget
SBDebugger::FindTargetWithLLDBProcess(const ProcessSP
&process_sp
) {
1053 // No need to lock, the target list is thread safe
1055 m_opaque_sp
->GetTargetList().FindTargetWithProcess(process_sp
.get()));
1060 uint32_t SBDebugger::GetNumTargets() {
1061 LLDB_INSTRUMENT_VA(this);
1064 // No need to lock, the target list is thread safe
1065 return m_opaque_sp
->GetTargetList().GetNumTargets();
1070 SBTarget
SBDebugger::GetSelectedTarget() {
1071 LLDB_INSTRUMENT_VA(this);
1073 Log
*log
= GetLog(LLDBLog::API
);
1078 // No need to lock, the target list is thread safe
1079 target_sp
= m_opaque_sp
->GetTargetList().GetSelectedTarget();
1080 sb_target
.SetSP(target_sp
);
1085 sb_target
.GetDescription(sstr
, eDescriptionLevelBrief
);
1086 LLDB_LOGF(log
, "SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s",
1087 static_cast<void *>(m_opaque_sp
.get()),
1088 static_cast<void *>(target_sp
.get()), sstr
.GetData());
1094 void SBDebugger::SetSelectedTarget(SBTarget
&sb_target
) {
1095 LLDB_INSTRUMENT_VA(this, sb_target
);
1097 Log
*log
= GetLog(LLDBLog::API
);
1099 TargetSP
target_sp(sb_target
.GetSP());
1101 m_opaque_sp
->GetTargetList().SetSelectedTarget(target_sp
);
1105 sb_target
.GetDescription(sstr
, eDescriptionLevelBrief
);
1106 LLDB_LOGF(log
, "SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s",
1107 static_cast<void *>(m_opaque_sp
.get()),
1108 static_cast<void *>(target_sp
.get()), sstr
.GetData());
1112 SBPlatform
SBDebugger::GetSelectedPlatform() {
1113 LLDB_INSTRUMENT_VA(this);
1115 Log
*log
= GetLog(LLDBLog::API
);
1117 SBPlatform sb_platform
;
1118 DebuggerSP
debugger_sp(m_opaque_sp
);
1120 sb_platform
.SetSP(debugger_sp
->GetPlatformList().GetSelectedPlatform());
1122 LLDB_LOGF(log
, "SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s",
1123 static_cast<void *>(m_opaque_sp
.get()),
1124 static_cast<void *>(sb_platform
.GetSP().get()),
1125 sb_platform
.GetName());
1129 void SBDebugger::SetSelectedPlatform(SBPlatform
&sb_platform
) {
1130 LLDB_INSTRUMENT_VA(this, sb_platform
);
1132 Log
*log
= GetLog(LLDBLog::API
);
1134 DebuggerSP
debugger_sp(m_opaque_sp
);
1136 debugger_sp
->GetPlatformList().SetSelectedPlatform(sb_platform
.GetSP());
1139 LLDB_LOGF(log
, "SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)",
1140 static_cast<void *>(m_opaque_sp
.get()),
1141 static_cast<void *>(sb_platform
.GetSP().get()),
1142 sb_platform
.GetName());
1145 uint32_t SBDebugger::GetNumPlatforms() {
1146 LLDB_INSTRUMENT_VA(this);
1149 // No need to lock, the platform list is thread safe
1150 return m_opaque_sp
->GetPlatformList().GetSize();
1155 SBPlatform
SBDebugger::GetPlatformAtIndex(uint32_t idx
) {
1156 LLDB_INSTRUMENT_VA(this, idx
);
1158 SBPlatform sb_platform
;
1160 // No need to lock, the platform list is thread safe
1161 sb_platform
.SetSP(m_opaque_sp
->GetPlatformList().GetAtIndex(idx
));
1166 uint32_t SBDebugger::GetNumAvailablePlatforms() {
1167 LLDB_INSTRUMENT_VA(this);
1171 if (PluginManager::GetPlatformPluginNameAtIndex(idx
).empty()) {
1176 // +1 for the host platform, which should always appear first in the list.
1180 SBStructuredData
SBDebugger::GetAvailablePlatformInfoAtIndex(uint32_t idx
) {
1181 LLDB_INSTRUMENT_VA(this, idx
);
1183 SBStructuredData data
;
1184 auto platform_dict
= std::make_unique
<StructuredData::Dictionary
>();
1185 llvm::StringRef
name_str("name"), desc_str("description");
1188 PlatformSP
host_platform_sp(Platform::GetHostPlatform());
1189 platform_dict
->AddStringItem(name_str
, host_platform_sp
->GetPluginName());
1190 platform_dict
->AddStringItem(
1191 desc_str
, llvm::StringRef(host_platform_sp
->GetDescription()));
1192 } else if (idx
> 0) {
1193 llvm::StringRef plugin_name
=
1194 PluginManager::GetPlatformPluginNameAtIndex(idx
- 1);
1195 if (plugin_name
.empty()) {
1198 platform_dict
->AddStringItem(name_str
, llvm::StringRef(plugin_name
));
1200 llvm::StringRef plugin_desc
=
1201 PluginManager::GetPlatformPluginDescriptionAtIndex(idx
- 1);
1202 platform_dict
->AddStringItem(desc_str
, llvm::StringRef(plugin_desc
));
1205 data
.m_impl_up
->SetObjectSP(
1206 StructuredData::ObjectSP(platform_dict
.release()));
1210 void SBDebugger::DispatchInput(void *baton
, const void *data
, size_t data_len
) {
1211 LLDB_INSTRUMENT_VA(this, baton
, data
, data_len
);
1213 DispatchInput(data
, data_len
);
1216 void SBDebugger::DispatchInput(const void *data
, size_t data_len
) {
1217 LLDB_INSTRUMENT_VA(this, data
, data_len
);
1219 // Log *log(GetLog (LLDBLog::API));
1222 // LLDB_LOGF(log, "SBDebugger(%p)::DispatchInput (data=\"%.*s\",
1223 // size_t=%" PRIu64 ")",
1224 // m_opaque_sp.get(),
1226 // (const char *) data,
1227 // (uint64_t)data_len);
1230 // m_opaque_sp->DispatchInput ((const char *) data, data_len);
1233 void SBDebugger::DispatchInputInterrupt() {
1234 LLDB_INSTRUMENT_VA(this);
1237 m_opaque_sp
->DispatchInputInterrupt();
1240 void SBDebugger::DispatchInputEndOfFile() {
1241 LLDB_INSTRUMENT_VA(this);
1244 m_opaque_sp
->DispatchInputEndOfFile();
1247 void SBDebugger::PushInputReader(SBInputReader
&reader
) {
1248 LLDB_INSTRUMENT_VA(this, reader
);
1251 void SBDebugger::RunCommandInterpreter(bool auto_handle_events
,
1252 bool spawn_thread
) {
1253 LLDB_INSTRUMENT_VA(this, auto_handle_events
, spawn_thread
);
1256 CommandInterpreterRunOptions options
;
1257 options
.SetAutoHandleEvents(auto_handle_events
);
1258 options
.SetSpawnThread(spawn_thread
);
1259 m_opaque_sp
->GetCommandInterpreter().RunCommandInterpreter(options
);
1263 void SBDebugger::RunCommandInterpreter(bool auto_handle_events
,
1265 SBCommandInterpreterRunOptions
&options
,
1266 int &num_errors
, bool &quit_requested
,
1267 bool &stopped_for_crash
)
1270 LLDB_INSTRUMENT_VA(this, auto_handle_events
, spawn_thread
, options
,
1271 num_errors
, quit_requested
, stopped_for_crash
);
1274 options
.SetAutoHandleEvents(auto_handle_events
);
1275 options
.SetSpawnThread(spawn_thread
);
1276 CommandInterpreter
&interp
= m_opaque_sp
->GetCommandInterpreter();
1277 CommandInterpreterRunResult result
=
1278 interp
.RunCommandInterpreter(options
.ref());
1279 num_errors
= result
.GetNumErrors();
1281 result
.IsResult(lldb::eCommandInterpreterResultQuitRequested
);
1283 result
.IsResult(lldb::eCommandInterpreterResultInferiorCrash
);
1287 SBCommandInterpreterRunResult
SBDebugger::RunCommandInterpreter(
1288 const SBCommandInterpreterRunOptions
&options
) {
1289 LLDB_INSTRUMENT_VA(this, options
);
1292 return SBCommandInterpreterRunResult();
1294 CommandInterpreter
&interp
= m_opaque_sp
->GetCommandInterpreter();
1295 CommandInterpreterRunResult result
=
1296 interp
.RunCommandInterpreter(options
.ref());
1298 return SBCommandInterpreterRunResult(result
);
1301 SBError
SBDebugger::RunREPL(lldb::LanguageType language
,
1302 const char *repl_options
) {
1303 LLDB_INSTRUMENT_VA(this, language
, repl_options
);
1307 error
.ref() = m_opaque_sp
->RunREPL(language
, repl_options
);
1309 error
= Status::FromErrorString("invalid debugger");
1313 void SBDebugger::reset(const DebuggerSP
&debugger_sp
) {
1314 m_opaque_sp
= debugger_sp
;
1317 Debugger
*SBDebugger::get() const { return m_opaque_sp
.get(); }
1319 Debugger
&SBDebugger::ref() const {
1320 assert(m_opaque_sp
.get());
1321 return *m_opaque_sp
;
1324 const lldb::DebuggerSP
&SBDebugger::get_sp() const { return m_opaque_sp
; }
1326 SBDebugger
SBDebugger::FindDebuggerWithID(int id
) {
1327 LLDB_INSTRUMENT_VA(id
);
1329 // No need to lock, the debugger list is thread safe
1330 SBDebugger sb_debugger
;
1331 DebuggerSP debugger_sp
= Debugger::FindDebuggerWithID(id
);
1333 sb_debugger
.reset(debugger_sp
);
1337 const char *SBDebugger::GetInstanceName() {
1338 LLDB_INSTRUMENT_VA(this);
1343 return ConstString(m_opaque_sp
->GetInstanceName()).AsCString();
1346 SBError
SBDebugger::SetInternalVariable(const char *var_name
, const char *value
,
1347 const char *debugger_instance_name
) {
1348 LLDB_INSTRUMENT_VA(var_name
, value
, debugger_instance_name
);
1351 DebuggerSP
debugger_sp(
1352 Debugger::FindDebuggerWithInstanceName(debugger_instance_name
));
1355 ExecutionContext
exe_ctx(
1356 debugger_sp
->GetCommandInterpreter().GetExecutionContext());
1357 error
= debugger_sp
->SetPropertyValue(&exe_ctx
, eVarSetOperationAssign
,
1360 error
= Status::FromErrorStringWithFormat(
1361 "invalid debugger instance name '%s'", debugger_instance_name
);
1364 sb_error
.SetError(std::move(error
));
1369 SBDebugger::GetInternalVariableValue(const char *var_name
,
1370 const char *debugger_instance_name
) {
1371 LLDB_INSTRUMENT_VA(var_name
, debugger_instance_name
);
1373 DebuggerSP
debugger_sp(
1374 Debugger::FindDebuggerWithInstanceName(debugger_instance_name
));
1377 ExecutionContext
exe_ctx(
1378 debugger_sp
->GetCommandInterpreter().GetExecutionContext());
1379 lldb::OptionValueSP
value_sp(
1380 debugger_sp
->GetPropertyValue(&exe_ctx
, var_name
, error
));
1382 StreamString value_strm
;
1383 value_sp
->DumpValue(&exe_ctx
, value_strm
, OptionValue::eDumpOptionValue
);
1384 const std::string
&value_str
= std::string(value_strm
.GetString());
1385 if (!value_str
.empty()) {
1386 StringList string_list
;
1387 string_list
.SplitIntoLines(value_str
);
1388 return SBStringList(&string_list
);
1392 return SBStringList();
1395 uint32_t SBDebugger::GetTerminalWidth() const {
1396 LLDB_INSTRUMENT_VA(this);
1398 return (m_opaque_sp
? m_opaque_sp
->GetTerminalWidth() : 0);
1401 void SBDebugger::SetTerminalWidth(uint32_t term_width
) {
1402 LLDB_INSTRUMENT_VA(this, term_width
);
1405 m_opaque_sp
->SetTerminalWidth(term_width
);
1408 const char *SBDebugger::GetPrompt() const {
1409 LLDB_INSTRUMENT_VA(this);
1411 Log
*log
= GetLog(LLDBLog::API
);
1413 LLDB_LOG(log
, "SBDebugger({0:x})::GetPrompt () => \"{1}\"",
1414 static_cast<void *>(m_opaque_sp
.get()),
1415 (m_opaque_sp
? m_opaque_sp
->GetPrompt() : ""));
1417 return (m_opaque_sp
? ConstString(m_opaque_sp
->GetPrompt()).GetCString()
1421 void SBDebugger::SetPrompt(const char *prompt
) {
1422 LLDB_INSTRUMENT_VA(this, prompt
);
1425 m_opaque_sp
->SetPrompt(llvm::StringRef(prompt
));
1428 const char *SBDebugger::GetReproducerPath() const {
1429 LLDB_INSTRUMENT_VA(this);
1431 return "GetReproducerPath has been deprecated";
1434 ScriptLanguage
SBDebugger::GetScriptLanguage() const {
1435 LLDB_INSTRUMENT_VA(this);
1437 return (m_opaque_sp
? m_opaque_sp
->GetScriptLanguage() : eScriptLanguageNone
);
1440 void SBDebugger::SetScriptLanguage(ScriptLanguage script_lang
) {
1441 LLDB_INSTRUMENT_VA(this, script_lang
);
1444 m_opaque_sp
->SetScriptLanguage(script_lang
);
1448 LanguageType
SBDebugger::GetREPLLanguage() const {
1449 LLDB_INSTRUMENT_VA(this);
1451 return (m_opaque_sp
? m_opaque_sp
->GetREPLLanguage() : eLanguageTypeUnknown
);
1454 void SBDebugger::SetREPLLanguage(LanguageType repl_lang
) {
1455 LLDB_INSTRUMENT_VA(this, repl_lang
);
1458 m_opaque_sp
->SetREPLLanguage(repl_lang
);
1462 bool SBDebugger::SetUseExternalEditor(bool value
) {
1463 LLDB_INSTRUMENT_VA(this, value
);
1465 return (m_opaque_sp
? m_opaque_sp
->SetUseExternalEditor(value
) : false);
1468 bool SBDebugger::GetUseExternalEditor() {
1469 LLDB_INSTRUMENT_VA(this);
1471 return (m_opaque_sp
? m_opaque_sp
->GetUseExternalEditor() : false);
1474 bool SBDebugger::SetUseColor(bool value
) {
1475 LLDB_INSTRUMENT_VA(this, value
);
1477 return (m_opaque_sp
? m_opaque_sp
->SetUseColor(value
) : false);
1480 bool SBDebugger::GetUseColor() const {
1481 LLDB_INSTRUMENT_VA(this);
1483 return (m_opaque_sp
? m_opaque_sp
->GetUseColor() : false);
1486 bool SBDebugger::SetShowInlineDiagnostics(bool value
) {
1487 LLDB_INSTRUMENT_VA(this, value
);
1489 return (m_opaque_sp
? m_opaque_sp
->SetShowInlineDiagnostics(value
) : false);
1492 bool SBDebugger::SetUseSourceCache(bool value
) {
1493 LLDB_INSTRUMENT_VA(this, value
);
1495 return (m_opaque_sp
? m_opaque_sp
->SetUseSourceCache(value
) : false);
1498 bool SBDebugger::GetUseSourceCache() const {
1499 LLDB_INSTRUMENT_VA(this);
1501 return (m_opaque_sp
? m_opaque_sp
->GetUseSourceCache() : false);
1504 bool SBDebugger::GetDescription(SBStream
&description
) {
1505 LLDB_INSTRUMENT_VA(this, description
);
1507 Stream
&strm
= description
.ref();
1510 const char *name
= m_opaque_sp
->GetInstanceName().c_str();
1511 user_id_t id
= m_opaque_sp
->GetID();
1512 strm
.Printf("Debugger (instance: \"%s\", id: %" PRIu64
")", name
, id
);
1514 strm
.PutCString("No value");
1519 user_id_t
SBDebugger::GetID() {
1520 LLDB_INSTRUMENT_VA(this);
1522 return (m_opaque_sp
? m_opaque_sp
->GetID() : LLDB_INVALID_UID
);
1525 SBError
SBDebugger::SetCurrentPlatform(const char *platform_name_cstr
) {
1526 LLDB_INSTRUMENT_VA(this, platform_name_cstr
);
1530 if (platform_name_cstr
&& platform_name_cstr
[0]) {
1531 PlatformList
&platforms
= m_opaque_sp
->GetPlatformList();
1532 if (PlatformSP platform_sp
= platforms
.GetOrCreate(platform_name_cstr
))
1533 platforms
.SetSelectedPlatform(platform_sp
);
1535 sb_error
.ref() = Status::FromErrorString("platform not found");
1537 sb_error
.ref() = Status::FromErrorString("invalid platform name");
1540 sb_error
.ref() = Status::FromErrorString("invalid debugger");
1545 bool SBDebugger::SetCurrentPlatformSDKRoot(const char *sysroot
) {
1546 LLDB_INSTRUMENT_VA(this, sysroot
);
1548 if (SBPlatform platform
= GetSelectedPlatform()) {
1549 platform
.SetSDKRoot(sysroot
);
1555 bool SBDebugger::GetCloseInputOnEOF() const {
1556 LLDB_INSTRUMENT_VA(this);
1561 void SBDebugger::SetCloseInputOnEOF(bool b
) {
1562 LLDB_INSTRUMENT_VA(this, b
);
1565 SBTypeCategory
SBDebugger::GetCategory(const char *category_name
) {
1566 LLDB_INSTRUMENT_VA(this, category_name
);
1568 if (!category_name
|| *category_name
== 0)
1569 return SBTypeCategory();
1571 TypeCategoryImplSP category_sp
;
1573 if (DataVisualization::Categories::GetCategory(ConstString(category_name
),
1574 category_sp
, false)) {
1575 return SBTypeCategory(category_sp
);
1577 return SBTypeCategory();
1581 SBTypeCategory
SBDebugger::GetCategory(lldb::LanguageType lang_type
) {
1582 LLDB_INSTRUMENT_VA(this, lang_type
);
1584 TypeCategoryImplSP category_sp
;
1585 if (DataVisualization::Categories::GetCategory(lang_type
, category_sp
)) {
1586 return SBTypeCategory(category_sp
);
1588 return SBTypeCategory();
1592 SBTypeCategory
SBDebugger::CreateCategory(const char *category_name
) {
1593 LLDB_INSTRUMENT_VA(this, category_name
);
1595 if (!category_name
|| *category_name
== 0)
1596 return SBTypeCategory();
1598 TypeCategoryImplSP category_sp
;
1600 if (DataVisualization::Categories::GetCategory(ConstString(category_name
),
1601 category_sp
, true)) {
1602 return SBTypeCategory(category_sp
);
1604 return SBTypeCategory();
1608 bool SBDebugger::DeleteCategory(const char *category_name
) {
1609 LLDB_INSTRUMENT_VA(this, category_name
);
1611 if (!category_name
|| *category_name
== 0)
1614 return DataVisualization::Categories::Delete(ConstString(category_name
));
1617 uint32_t SBDebugger::GetNumCategories() {
1618 LLDB_INSTRUMENT_VA(this);
1620 return DataVisualization::Categories::GetCount();
1623 SBTypeCategory
SBDebugger::GetCategoryAtIndex(uint32_t index
) {
1624 LLDB_INSTRUMENT_VA(this, index
);
1626 return SBTypeCategory(
1627 DataVisualization::Categories::GetCategoryAtIndex(index
));
1630 SBTypeCategory
SBDebugger::GetDefaultCategory() {
1631 LLDB_INSTRUMENT_VA(this);
1633 return GetCategory("default");
1636 SBTypeFormat
SBDebugger::GetFormatForType(SBTypeNameSpecifier type_name
) {
1637 LLDB_INSTRUMENT_VA(this, type_name
);
1639 SBTypeCategory default_category_sb
= GetDefaultCategory();
1640 if (default_category_sb
.GetEnabled())
1641 return default_category_sb
.GetFormatForType(type_name
);
1642 return SBTypeFormat();
1645 SBTypeSummary
SBDebugger::GetSummaryForType(SBTypeNameSpecifier type_name
) {
1646 LLDB_INSTRUMENT_VA(this, type_name
);
1648 if (!type_name
.IsValid())
1649 return SBTypeSummary();
1650 return SBTypeSummary(DataVisualization::GetSummaryForType(type_name
.GetSP()));
1653 SBTypeFilter
SBDebugger::GetFilterForType(SBTypeNameSpecifier type_name
) {
1654 LLDB_INSTRUMENT_VA(this, type_name
);
1656 if (!type_name
.IsValid())
1657 return SBTypeFilter();
1658 return SBTypeFilter(DataVisualization::GetFilterForType(type_name
.GetSP()));
1661 SBTypeSynthetic
SBDebugger::GetSyntheticForType(SBTypeNameSpecifier type_name
) {
1662 LLDB_INSTRUMENT_VA(this, type_name
);
1664 if (!type_name
.IsValid())
1665 return SBTypeSynthetic();
1666 return SBTypeSynthetic(
1667 DataVisualization::GetSyntheticForType(type_name
.GetSP()));
1670 void SBDebugger::ResetStatistics() {
1671 LLDB_INSTRUMENT_VA(this);
1673 DebuggerStats::ResetStatistics(*m_opaque_sp
, nullptr);
1676 static llvm::ArrayRef
<const char *> GetCategoryArray(const char **categories
) {
1677 if (categories
== nullptr)
1680 while (categories
[len
] != nullptr)
1682 return llvm::ArrayRef(categories
, len
);
1685 bool SBDebugger::EnableLog(const char *channel
, const char **categories
) {
1686 LLDB_INSTRUMENT_VA(this, channel
, categories
);
1689 uint32_t log_options
=
1690 LLDB_LOG_OPTION_PREPEND_TIMESTAMP
| LLDB_LOG_OPTION_PREPEND_THREAD_NAME
;
1692 llvm::raw_string_ostream
error_stream(error
);
1693 return m_opaque_sp
->EnableLog(channel
, GetCategoryArray(categories
), "",
1694 log_options
, /*buffer_size=*/0,
1695 eLogHandlerStream
, error_stream
);
1700 void SBDebugger::SetLoggingCallback(lldb::LogOutputCallback log_callback
,
1702 LLDB_INSTRUMENT_VA(this, log_callback
, baton
);
1705 return m_opaque_sp
->SetLoggingCallback(log_callback
, baton
);
1709 void SBDebugger::SetDestroyCallback(
1710 lldb::SBDebuggerDestroyCallback destroy_callback
, void *baton
) {
1711 LLDB_INSTRUMENT_VA(this, destroy_callback
, baton
);
1713 return m_opaque_sp
->SetDestroyCallback(
1714 destroy_callback
, baton
);
1718 lldb::callback_token_t
1719 SBDebugger::AddDestroyCallback(lldb::SBDebuggerDestroyCallback destroy_callback
,
1721 LLDB_INSTRUMENT_VA(this, destroy_callback
, baton
);
1724 return m_opaque_sp
->AddDestroyCallback(destroy_callback
, baton
);
1726 return LLDB_INVALID_CALLBACK_TOKEN
;
1729 bool SBDebugger::RemoveDestroyCallback(lldb::callback_token_t token
) {
1730 LLDB_INSTRUMENT_VA(this, token
);
1733 return m_opaque_sp
->RemoveDestroyCallback(token
);
1739 SBDebugger::LoadTraceFromFile(SBError
&error
,
1740 const SBFileSpec
&trace_description_file
) {
1741 LLDB_INSTRUMENT_VA(this, error
, trace_description_file
);
1742 return SBTrace::LoadTraceFromFile(error
, *this, trace_description_file
);
1745 void SBDebugger::RequestInterrupt() {
1746 LLDB_INSTRUMENT_VA(this);
1749 m_opaque_sp
->RequestInterrupt();
1751 void SBDebugger::CancelInterruptRequest() {
1752 LLDB_INSTRUMENT_VA(this);
1755 m_opaque_sp
->CancelInterruptRequest();
1758 bool SBDebugger::InterruptRequested() {
1759 LLDB_INSTRUMENT_VA(this);
1762 return m_opaque_sp
->InterruptRequested();
1766 bool SBDebugger::SupportsLanguage(lldb::LanguageType language
) {
1767 return TypeSystem::SupportsLanguageStatic(language
);