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/Support/DynamicLibrary.h"
61 #include "llvm/Support/ManagedStatic.h"
62 #include "llvm/Support/PrettyStackTrace.h"
63 #include "llvm/Support/Signals.h"
66 using namespace lldb_private
;
68 static llvm::ManagedStatic
<SystemLifetimeManager
> g_debugger_lifetime
;
70 SBError
SBInputReader::Initialize(
71 lldb::SBDebugger
&sb_debugger
,
72 unsigned long (*callback
)(void *, lldb::SBInputReader
*,
73 lldb::InputReaderAction
, char const *,
75 void *a
, lldb::InputReaderGranularity b
, char const *c
, char const *d
,
77 LLDB_INSTRUMENT_VA(this, sb_debugger
, callback
, a
, b
, c
, d
, e
);
82 void SBInputReader::SetIsDone(bool b
) { LLDB_INSTRUMENT_VA(this, b
); }
84 bool SBInputReader::IsActive() const {
85 LLDB_INSTRUMENT_VA(this);
90 SBDebugger::SBDebugger() { LLDB_INSTRUMENT_VA(this); }
92 SBDebugger::SBDebugger(const lldb::DebuggerSP
&debugger_sp
)
93 : m_opaque_sp(debugger_sp
) {
94 LLDB_INSTRUMENT_VA(this, debugger_sp
);
97 SBDebugger::SBDebugger(const SBDebugger
&rhs
) : m_opaque_sp(rhs
.m_opaque_sp
) {
98 LLDB_INSTRUMENT_VA(this, rhs
);
101 SBDebugger::~SBDebugger() = default;
103 SBDebugger
&SBDebugger::operator=(const SBDebugger
&rhs
) {
104 LLDB_INSTRUMENT_VA(this, rhs
);
107 m_opaque_sp
= rhs
.m_opaque_sp
;
112 const char *SBDebugger::GetBroadcasterClass() {
115 return Debugger::GetStaticBroadcasterClass().AsCString();
118 const char *SBDebugger::GetProgressFromEvent(const lldb::SBEvent
&event
,
119 uint64_t &progress_id
,
122 bool &is_debugger_specific
) {
123 LLDB_INSTRUMENT_VA(event
);
125 const ProgressEventData
*progress_data
=
126 ProgressEventData::GetEventDataFromEvent(event
.get());
127 if (progress_data
== nullptr)
129 progress_id
= progress_data
->GetID();
130 completed
= progress_data
->GetCompleted();
131 total
= progress_data
->GetTotal();
132 is_debugger_specific
= progress_data
->IsDebuggerSpecific();
133 ConstString
message(progress_data
->GetMessage());
134 return message
.AsCString();
137 lldb::SBStructuredData
138 SBDebugger::GetProgressDataFromEvent(const lldb::SBEvent
&event
) {
139 LLDB_INSTRUMENT_VA(event
);
141 StructuredData::DictionarySP dictionary_sp
=
142 ProgressEventData::GetAsStructuredData(event
.get());
147 SBStructuredData data
;
148 data
.m_impl_up
->SetObjectSP(std::move(dictionary_sp
));
152 lldb::SBStructuredData
153 SBDebugger::GetDiagnosticFromEvent(const lldb::SBEvent
&event
) {
154 LLDB_INSTRUMENT_VA(event
);
156 StructuredData::DictionarySP dictionary_sp
=
157 DiagnosticEventData::GetAsStructuredData(event
.get());
162 SBStructuredData data
;
163 data
.m_impl_up
->SetObjectSP(std::move(dictionary_sp
));
167 SBBroadcaster
SBDebugger::GetBroadcaster() {
168 LLDB_INSTRUMENT_VA(this);
169 SBBroadcaster
broadcaster(&m_opaque_sp
->GetBroadcaster(), false);
173 void SBDebugger::Initialize() {
175 SBError ignored
= SBDebugger::InitializeWithErrorHandling();
178 lldb::SBError
SBDebugger::InitializeWithErrorHandling() {
181 auto LoadPlugin
= [](const lldb::DebuggerSP
&debugger_sp
,
182 const FileSpec
&spec
,
183 Status
&error
) -> llvm::sys::DynamicLibrary
{
184 llvm::sys::DynamicLibrary dynlib
=
185 llvm::sys::DynamicLibrary::getPermanentLibrary(spec
.GetPath().c_str());
186 if (dynlib
.isValid()) {
187 typedef bool (*LLDBCommandPluginInit
)(lldb::SBDebugger
& debugger
);
189 lldb::SBDebugger
debugger_sb(debugger_sp
);
190 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger)
192 // TODO: mangle this differently for your system - on OSX, the first
193 // underscore needs to be removed and the second one stays
194 LLDBCommandPluginInit init_func
=
195 (LLDBCommandPluginInit
)(uintptr_t)dynlib
.getAddressOfSymbol(
196 "_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
198 if (init_func(debugger_sb
))
201 error
.SetErrorString("plug-in refused to load "
202 "(lldb::PluginInitialize(lldb::SBDebugger) "
205 error
.SetErrorString("plug-in is missing the required initialization: "
206 "lldb::PluginInitialize(lldb::SBDebugger)");
209 if (FileSystem::Instance().Exists(spec
))
210 error
.SetErrorString("this file does not represent a loadable dylib");
212 error
.SetErrorString("no such file");
214 return llvm::sys::DynamicLibrary();
218 if (auto e
= g_debugger_lifetime
->Initialize(
219 std::make_unique
<SystemInitializerFull
>(), LoadPlugin
)) {
220 error
.SetError(Status(std::move(e
)));
225 void SBDebugger::PrintStackTraceOnError() {
228 llvm::EnablePrettyStackTrace();
229 static std::string executable
=
230 llvm::sys::fs::getMainExecutable(nullptr, nullptr);
231 llvm::sys::PrintStackTraceOnErrorSignal(executable
);
234 static void DumpDiagnostics(void *cookie
) {
235 Diagnostics::Instance().Dump(llvm::errs());
238 void SBDebugger::PrintDiagnosticsOnError() {
241 llvm::sys::AddSignalHandler(&DumpDiagnostics
, nullptr);
244 void SBDebugger::Terminate() {
247 g_debugger_lifetime
->Terminate();
250 void SBDebugger::Clear() {
251 LLDB_INSTRUMENT_VA(this);
254 m_opaque_sp
->ClearIOHandlers();
259 SBDebugger
SBDebugger::Create() {
262 return SBDebugger::Create(false, nullptr, nullptr);
265 SBDebugger
SBDebugger::Create(bool source_init_files
) {
266 LLDB_INSTRUMENT_VA(source_init_files
);
268 return SBDebugger::Create(source_init_files
, nullptr, nullptr);
271 SBDebugger
SBDebugger::Create(bool source_init_files
,
272 lldb::LogOutputCallback callback
, void *baton
)
275 LLDB_INSTRUMENT_VA(source_init_files
, callback
, baton
);
279 // Currently we have issues if this function is called simultaneously on two
280 // different threads. The issues mainly revolve around the fact that the
281 // lldb_private::FormatManager uses global collections and having two threads
282 // parsing the .lldbinit files can cause mayhem. So to get around this for
283 // now we need to use a mutex to prevent bad things from happening.
284 static std::recursive_mutex g_mutex
;
285 std::lock_guard
<std::recursive_mutex
> guard(g_mutex
);
287 debugger
.reset(Debugger::CreateInstance(callback
, baton
));
289 SBCommandInterpreter interp
= debugger
.GetCommandInterpreter();
290 if (source_init_files
) {
291 interp
.get()->SkipLLDBInitFiles(false);
292 interp
.get()->SkipAppInitFiles(false);
293 SBCommandReturnObject result
;
294 interp
.SourceInitFileInGlobalDirectory(result
);
295 interp
.SourceInitFileInHomeDirectory(result
, false);
297 interp
.get()->SkipLLDBInitFiles(true);
298 interp
.get()->SkipAppInitFiles(true);
303 void SBDebugger::Destroy(SBDebugger
&debugger
) {
304 LLDB_INSTRUMENT_VA(debugger
);
306 Debugger::Destroy(debugger
.m_opaque_sp
);
308 if (debugger
.m_opaque_sp
.get() != nullptr)
309 debugger
.m_opaque_sp
.reset();
312 void SBDebugger::MemoryPressureDetected() {
315 // Since this function can be call asynchronously, we allow it to be non-
316 // mandatory. We have seen deadlocks with this function when called so we
317 // need to safeguard against this until we can determine what is causing the
320 const bool mandatory
= false;
322 ModuleList::RemoveOrphanSharedModules(mandatory
);
325 bool SBDebugger::IsValid() const {
326 LLDB_INSTRUMENT_VA(this);
327 return this->operator bool();
329 SBDebugger::operator bool() const {
330 LLDB_INSTRUMENT_VA(this);
332 return m_opaque_sp
.get() != nullptr;
335 void SBDebugger::SetAsync(bool b
) {
336 LLDB_INSTRUMENT_VA(this, b
);
339 m_opaque_sp
->SetAsyncExecution(b
);
342 bool SBDebugger::GetAsync() {
343 LLDB_INSTRUMENT_VA(this);
345 return (m_opaque_sp
? m_opaque_sp
->GetAsyncExecution() : false);
348 void SBDebugger::SkipLLDBInitFiles(bool b
) {
349 LLDB_INSTRUMENT_VA(this, b
);
352 m_opaque_sp
->GetCommandInterpreter().SkipLLDBInitFiles(b
);
355 void SBDebugger::SkipAppInitFiles(bool b
) {
356 LLDB_INSTRUMENT_VA(this, b
);
359 m_opaque_sp
->GetCommandInterpreter().SkipAppInitFiles(b
);
362 void SBDebugger::SetInputFileHandle(FILE *fh
, bool transfer_ownership
) {
363 LLDB_INSTRUMENT_VA(this, fh
, transfer_ownership
);
365 m_opaque_sp
->SetInputFile(
366 (FileSP
)std::make_shared
<NativeFile
>(fh
, transfer_ownership
));
369 SBError
SBDebugger::SetInputString(const char *data
) {
370 LLDB_INSTRUMENT_VA(this, data
);
372 if (data
== nullptr) {
373 sb_error
.SetErrorString("String data is null");
377 size_t size
= strlen(data
);
379 sb_error
.SetErrorString("String data is empty");
384 sb_error
.SetErrorString("invalid debugger");
388 sb_error
.SetError(m_opaque_sp
->SetInputString(data
));
392 // Shouldn't really be settable after initialization as this could cause lots
393 // of problems; don't want users trying to switch modes in the middle of a
394 // debugging session.
395 SBError
SBDebugger::SetInputFile(SBFile file
) {
396 LLDB_INSTRUMENT_VA(this, file
);
400 error
.ref().SetErrorString("invalid debugger");
404 error
.ref().SetErrorString("invalid file");
407 m_opaque_sp
->SetInputFile(file
.m_opaque_sp
);
411 SBError
SBDebugger::SetInputFile(FileSP file_sp
) {
412 LLDB_INSTRUMENT_VA(this, file_sp
);
413 return SetInputFile(SBFile(file_sp
));
416 SBError
SBDebugger::SetOutputFile(FileSP file_sp
) {
417 LLDB_INSTRUMENT_VA(this, file_sp
);
418 return SetOutputFile(SBFile(file_sp
));
421 void SBDebugger::SetOutputFileHandle(FILE *fh
, bool transfer_ownership
) {
422 LLDB_INSTRUMENT_VA(this, fh
, transfer_ownership
);
423 SetOutputFile((FileSP
)std::make_shared
<NativeFile
>(fh
, transfer_ownership
));
426 SBError
SBDebugger::SetOutputFile(SBFile file
) {
427 LLDB_INSTRUMENT_VA(this, file
);
430 error
.ref().SetErrorString("invalid debugger");
434 error
.ref().SetErrorString("invalid file");
437 m_opaque_sp
->SetOutputFile(file
.m_opaque_sp
);
441 void SBDebugger::SetErrorFileHandle(FILE *fh
, bool transfer_ownership
) {
442 LLDB_INSTRUMENT_VA(this, fh
, transfer_ownership
);
443 SetErrorFile((FileSP
)std::make_shared
<NativeFile
>(fh
, transfer_ownership
));
446 SBError
SBDebugger::SetErrorFile(FileSP file_sp
) {
447 LLDB_INSTRUMENT_VA(this, file_sp
);
448 return SetErrorFile(SBFile(file_sp
));
451 SBError
SBDebugger::SetErrorFile(SBFile file
) {
452 LLDB_INSTRUMENT_VA(this, file
);
455 error
.ref().SetErrorString("invalid debugger");
459 error
.ref().SetErrorString("invalid file");
462 m_opaque_sp
->SetErrorFile(file
.m_opaque_sp
);
466 lldb::SBStructuredData
SBDebugger::GetSetting(const char *setting
) {
467 LLDB_INSTRUMENT_VA(this, setting
);
469 SBStructuredData data
;
473 StreamString json_strm
;
474 ExecutionContext
exe_ctx(
475 m_opaque_sp
->GetCommandInterpreter().GetExecutionContext());
476 if (setting
&& strlen(setting
) > 0)
477 m_opaque_sp
->DumpPropertyValue(&exe_ctx
, json_strm
, setting
,
481 m_opaque_sp
->DumpAllPropertyValues(&exe_ctx
, json_strm
, /*dump_mask*/ 0,
484 data
.m_impl_up
->SetObjectSP(StructuredData::ParseJSON(json_strm
.GetString()));
488 FILE *SBDebugger::GetInputFileHandle() {
489 LLDB_INSTRUMENT_VA(this);
491 File
&file_sp
= m_opaque_sp
->GetInputFile();
492 return file_sp
.GetStream();
497 SBFile
SBDebugger::GetInputFile() {
498 LLDB_INSTRUMENT_VA(this);
500 return SBFile(m_opaque_sp
->GetInputFileSP());
505 FILE *SBDebugger::GetOutputFileHandle() {
506 LLDB_INSTRUMENT_VA(this);
508 StreamFile
&stream_file
= m_opaque_sp
->GetOutputStream();
509 return stream_file
.GetFile().GetStream();
514 SBFile
SBDebugger::GetOutputFile() {
515 LLDB_INSTRUMENT_VA(this);
517 SBFile
file(m_opaque_sp
->GetOutputStream().GetFileSP());
523 FILE *SBDebugger::GetErrorFileHandle() {
524 LLDB_INSTRUMENT_VA(this);
527 StreamFile
&stream_file
= m_opaque_sp
->GetErrorStream();
528 return stream_file
.GetFile().GetStream();
533 SBFile
SBDebugger::GetErrorFile() {
534 LLDB_INSTRUMENT_VA(this);
537 SBFile
file(m_opaque_sp
->GetErrorStream().GetFileSP());
543 void SBDebugger::SaveInputTerminalState() {
544 LLDB_INSTRUMENT_VA(this);
547 m_opaque_sp
->SaveInputTerminalState();
550 void SBDebugger::RestoreInputTerminalState() {
551 LLDB_INSTRUMENT_VA(this);
554 m_opaque_sp
->RestoreInputTerminalState();
556 SBCommandInterpreter
SBDebugger::GetCommandInterpreter() {
557 LLDB_INSTRUMENT_VA(this);
559 SBCommandInterpreter sb_interpreter
;
561 sb_interpreter
.reset(&m_opaque_sp
->GetCommandInterpreter());
563 return sb_interpreter
;
566 void SBDebugger::HandleCommand(const char *command
) {
567 LLDB_INSTRUMENT_VA(this, command
);
570 TargetSP
target_sp(m_opaque_sp
->GetSelectedTarget());
571 std::unique_lock
<std::recursive_mutex
> lock
;
573 lock
= std::unique_lock
<std::recursive_mutex
>(target_sp
->GetAPIMutex());
575 SBCommandInterpreter
sb_interpreter(GetCommandInterpreter());
576 SBCommandReturnObject result
;
578 sb_interpreter
.HandleCommand(command
, result
, false);
580 result
.PutError(m_opaque_sp
->GetErrorStream().GetFileSP());
581 result
.PutOutput(m_opaque_sp
->GetOutputStream().GetFileSP());
583 if (!m_opaque_sp
->GetAsyncExecution()) {
584 SBProcess
process(GetCommandInterpreter().GetProcess());
585 ProcessSP
process_sp(process
.GetSP());
588 ListenerSP lldb_listener_sp
= m_opaque_sp
->GetListener();
589 while (lldb_listener_sp
->GetEventForBroadcaster(
590 process_sp
.get(), event_sp
, std::chrono::seconds(0))) {
591 SBEvent
event(event_sp
);
592 HandleProcessEvent(process
, event
, GetOutputFile(), GetErrorFile());
599 SBListener
SBDebugger::GetListener() {
600 LLDB_INSTRUMENT_VA(this);
602 SBListener sb_listener
;
604 sb_listener
.reset(m_opaque_sp
->GetListener());
609 void SBDebugger::HandleProcessEvent(const SBProcess
&process
,
610 const SBEvent
&event
, SBFile out
,
612 LLDB_INSTRUMENT_VA(this, process
, event
, out
, err
);
614 return HandleProcessEvent(process
, event
, out
.m_opaque_sp
, err
.m_opaque_sp
);
617 void SBDebugger::HandleProcessEvent(const SBProcess
&process
,
618 const SBEvent
&event
, FILE *out
,
620 LLDB_INSTRUMENT_VA(this, process
, event
, out
, err
);
622 FileSP outfile
= std::make_shared
<NativeFile
>(out
, false);
623 FileSP errfile
= std::make_shared
<NativeFile
>(err
, false);
624 return HandleProcessEvent(process
, event
, outfile
, errfile
);
627 void SBDebugger::HandleProcessEvent(const SBProcess
&process
,
628 const SBEvent
&event
, FileSP out_sp
,
631 LLDB_INSTRUMENT_VA(this, process
, event
, out_sp
, err_sp
);
633 if (!process
.IsValid())
636 TargetSP
target_sp(process
.GetTarget().GetSP());
640 const uint32_t event_type
= event
.GetType();
641 char stdio_buffer
[1024];
644 std::lock_guard
<std::recursive_mutex
> guard(target_sp
->GetAPIMutex());
647 (Process::eBroadcastBitSTDOUT
| Process::eBroadcastBitStateChanged
)) {
648 // Drain stdout when we stop just in case we have any bytes
649 while ((len
= process
.GetSTDOUT(stdio_buffer
, sizeof(stdio_buffer
))) > 0)
651 out_sp
->Write(stdio_buffer
, len
);
655 (Process::eBroadcastBitSTDERR
| Process::eBroadcastBitStateChanged
)) {
656 // Drain stderr when we stop just in case we have any bytes
657 while ((len
= process
.GetSTDERR(stdio_buffer
, sizeof(stdio_buffer
))) > 0)
659 err_sp
->Write(stdio_buffer
, len
);
662 if (event_type
& Process::eBroadcastBitStateChanged
) {
663 StateType event_state
= SBProcess::GetStateFromEvent(event
);
665 if (event_state
== eStateInvalid
)
668 bool is_stopped
= StateIsStoppedState(event_state
);
670 process
.ReportEventState(event
, out_sp
);
674 SBSourceManager
SBDebugger::GetSourceManager() {
675 LLDB_INSTRUMENT_VA(this);
677 SBSourceManager
sb_source_manager(*this);
678 return sb_source_manager
;
681 bool SBDebugger::GetDefaultArchitecture(char *arch_name
, size_t arch_name_len
) {
682 LLDB_INSTRUMENT_VA(arch_name
, arch_name_len
);
684 if (arch_name
&& arch_name_len
) {
685 ArchSpec default_arch
= Target::GetDefaultArchitecture();
687 if (default_arch
.IsValid()) {
688 const std::string
&triple_str
= default_arch
.GetTriple().str();
689 if (!triple_str
.empty())
690 ::snprintf(arch_name
, arch_name_len
, "%s", triple_str
.c_str());
692 ::snprintf(arch_name
, arch_name_len
, "%s",
693 default_arch
.GetArchitectureName());
697 if (arch_name
&& arch_name_len
)
702 bool SBDebugger::SetDefaultArchitecture(const char *arch_name
) {
703 LLDB_INSTRUMENT_VA(arch_name
);
706 ArchSpec
arch(arch_name
);
707 if (arch
.IsValid()) {
708 Target::SetDefaultArchitecture(arch
);
716 SBDebugger::GetScriptingLanguage(const char *script_language_name
) {
717 LLDB_INSTRUMENT_VA(this, script_language_name
);
719 if (!script_language_name
)
720 return eScriptLanguageDefault
;
721 return OptionArgParser::ToScriptLanguage(
722 llvm::StringRef(script_language_name
), eScriptLanguageDefault
, nullptr);
726 SBDebugger::GetScriptInterpreterInfo(lldb::ScriptLanguage language
) {
727 LLDB_INSTRUMENT_VA(this, language
);
728 SBStructuredData data
;
730 lldb_private::ScriptInterpreter
*interp
=
731 m_opaque_sp
->GetScriptInterpreter(language
);
733 data
.m_impl_up
->SetObjectSP(interp
->GetInterpreterInfo());
739 const char *SBDebugger::GetVersionString() {
742 return lldb_private::GetVersion();
745 const char *SBDebugger::StateAsCString(StateType state
) {
746 LLDB_INSTRUMENT_VA(state
);
748 return lldb_private::StateAsCString(state
);
751 static void AddBoolConfigEntry(StructuredData::Dictionary
&dict
,
752 llvm::StringRef name
, bool value
,
753 llvm::StringRef description
) {
754 auto entry_up
= std::make_unique
<StructuredData::Dictionary
>();
755 entry_up
->AddBooleanItem("value", value
);
756 entry_up
->AddStringItem("description", description
);
757 dict
.AddItem(name
, std::move(entry_up
));
760 static void AddLLVMTargets(StructuredData::Dictionary
&dict
) {
761 auto array_up
= std::make_unique
<StructuredData::Array
>();
762 #define LLVM_TARGET(target) \
763 array_up->AddItem(std::make_unique<StructuredData::String>(#target));
764 #include "llvm/Config/Targets.def"
765 auto entry_up
= std::make_unique
<StructuredData::Dictionary
>();
766 entry_up
->AddItem("value", std::move(array_up
));
767 entry_up
->AddStringItem("description", "A list of configured LLVM targets.");
768 dict
.AddItem("targets", std::move(entry_up
));
771 SBStructuredData
SBDebugger::GetBuildConfiguration() {
774 auto config_up
= std::make_unique
<StructuredData::Dictionary
>();
776 *config_up
, "xml", XMLDocument::XMLEnabled(),
777 "A boolean value that indicates if XML support is enabled in LLDB");
779 *config_up
, "curses", LLDB_ENABLE_CURSES
,
780 "A boolean value that indicates if curses support is enabled in LLDB");
782 *config_up
, "editline", LLDB_ENABLE_LIBEDIT
,
783 "A boolean value that indicates if editline support is enabled in LLDB");
784 AddBoolConfigEntry(*config_up
, "editline_wchar", LLDB_EDITLINE_USE_WCHAR
,
785 "A boolean value that indicates if editline wide "
786 "characters support is enabled in LLDB");
788 *config_up
, "lzma", LLDB_ENABLE_LZMA
,
789 "A boolean value that indicates if lzma support is enabled in LLDB");
791 *config_up
, "python", LLDB_ENABLE_PYTHON
,
792 "A boolean value that indicates if python support is enabled in LLDB");
794 *config_up
, "lua", LLDB_ENABLE_LUA
,
795 "A boolean value that indicates if lua support is enabled in LLDB");
796 AddBoolConfigEntry(*config_up
, "fbsdvmcore", LLDB_ENABLE_FBSDVMCORE
,
797 "A boolean value that indicates if fbsdvmcore support is "
799 AddLLVMTargets(*config_up
);
801 SBStructuredData data
;
802 data
.m_impl_up
->SetObjectSP(std::move(config_up
));
806 bool SBDebugger::StateIsRunningState(StateType state
) {
807 LLDB_INSTRUMENT_VA(state
);
809 const bool result
= lldb_private::StateIsRunningState(state
);
814 bool SBDebugger::StateIsStoppedState(StateType state
) {
815 LLDB_INSTRUMENT_VA(state
);
817 const bool result
= lldb_private::StateIsStoppedState(state
, false);
822 lldb::SBTarget
SBDebugger::CreateTarget(const char *filename
,
823 const char *target_triple
,
824 const char *platform_name
,
825 bool add_dependent_modules
,
826 lldb::SBError
&sb_error
) {
827 LLDB_INSTRUMENT_VA(this, filename
, target_triple
, platform_name
,
828 add_dependent_modules
, sb_error
);
834 OptionGroupPlatform
platform_options(false);
835 platform_options
.SetPlatformName(platform_name
);
837 sb_error
.ref() = m_opaque_sp
->GetTargetList().CreateTarget(
838 *m_opaque_sp
, filename
, target_triple
,
839 add_dependent_modules
? eLoadDependentsYes
: eLoadDependentsNo
,
840 &platform_options
, target_sp
);
842 if (sb_error
.Success())
843 sb_target
.SetSP(target_sp
);
845 sb_error
.SetErrorString("invalid debugger");
848 Log
*log
= GetLog(LLDBLog::API
);
850 "SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, "
851 "platform_name=%s, add_dependent_modules=%u, error=%s) => "
853 static_cast<void *>(m_opaque_sp
.get()), filename
, target_triple
,
854 platform_name
, add_dependent_modules
, sb_error
.GetCString(),
855 static_cast<void *>(target_sp
.get()));
861 SBDebugger::CreateTargetWithFileAndTargetTriple(const char *filename
,
862 const char *target_triple
) {
863 LLDB_INSTRUMENT_VA(this, filename
, target_triple
);
868 const bool add_dependent_modules
= true;
869 Status
error(m_opaque_sp
->GetTargetList().CreateTarget(
870 *m_opaque_sp
, filename
, target_triple
,
871 add_dependent_modules
? eLoadDependentsYes
: eLoadDependentsNo
, nullptr,
873 sb_target
.SetSP(target_sp
);
876 Log
*log
= GetLog(LLDBLog::API
);
878 "SBDebugger(%p)::CreateTargetWithFileAndTargetTriple "
879 "(filename=\"%s\", triple=%s) => SBTarget(%p)",
880 static_cast<void *>(m_opaque_sp
.get()), filename
, target_triple
,
881 static_cast<void *>(target_sp
.get()));
886 SBTarget
SBDebugger::CreateTargetWithFileAndArch(const char *filename
,
887 const char *arch_cstr
) {
888 LLDB_INSTRUMENT_VA(this, filename
, arch_cstr
);
890 Log
*log
= GetLog(LLDBLog::API
);
896 if (arch_cstr
== nullptr) {
897 // The version of CreateTarget that takes an ArchSpec won't accept an
898 // empty ArchSpec, so when the arch hasn't been specified, we need to
899 // call the target triple version.
900 error
= m_opaque_sp
->GetTargetList().CreateTarget(
901 *m_opaque_sp
, filename
, arch_cstr
, eLoadDependentsYes
, nullptr,
904 PlatformSP platform_sp
=
905 m_opaque_sp
->GetPlatformList().GetSelectedPlatform();
907 Platform::GetAugmentedArchSpec(platform_sp
.get(), arch_cstr
);
909 error
= m_opaque_sp
->GetTargetList().CreateTarget(
910 *m_opaque_sp
, filename
, arch
, eLoadDependentsYes
, platform_sp
,
913 error
.SetErrorStringWithFormat("invalid arch_cstr: %s", arch_cstr
);
916 sb_target
.SetSP(target_sp
);
920 "SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", "
921 "arch=%s) => SBTarget(%p)",
922 static_cast<void *>(m_opaque_sp
.get()),
923 filename
? filename
: "<unspecified>",
924 arch_cstr
? arch_cstr
: "<unspecified>",
925 static_cast<void *>(target_sp
.get()));
930 SBTarget
SBDebugger::CreateTarget(const char *filename
) {
931 LLDB_INSTRUMENT_VA(this, filename
);
937 const bool add_dependent_modules
= true;
938 error
= m_opaque_sp
->GetTargetList().CreateTarget(
939 *m_opaque_sp
, filename
, "",
940 add_dependent_modules
? eLoadDependentsYes
: eLoadDependentsNo
, nullptr,
944 sb_target
.SetSP(target_sp
);
946 Log
*log
= GetLog(LLDBLog::API
);
948 "SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
949 static_cast<void *>(m_opaque_sp
.get()), filename
,
950 static_cast<void *>(target_sp
.get()));
954 SBTarget
SBDebugger::GetDummyTarget() {
955 LLDB_INSTRUMENT_VA(this);
959 sb_target
.SetSP(m_opaque_sp
->GetDummyTarget().shared_from_this());
961 Log
*log
= GetLog(LLDBLog::API
);
962 LLDB_LOGF(log
, "SBDebugger(%p)::GetDummyTarget() => SBTarget(%p)",
963 static_cast<void *>(m_opaque_sp
.get()),
964 static_cast<void *>(sb_target
.GetSP().get()));
968 bool SBDebugger::DeleteTarget(lldb::SBTarget
&target
) {
969 LLDB_INSTRUMENT_VA(this, target
);
973 TargetSP
target_sp(target
.GetSP());
975 // No need to lock, the target list is thread safe
976 result
= m_opaque_sp
->GetTargetList().DeleteTarget(target_sp
);
977 target_sp
->Destroy();
982 Log
*log
= GetLog(LLDBLog::API
);
983 LLDB_LOGF(log
, "SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i",
984 static_cast<void *>(m_opaque_sp
.get()),
985 static_cast<void *>(target
.m_opaque_sp
.get()), result
);
990 SBTarget
SBDebugger::GetTargetAtIndex(uint32_t idx
) {
991 LLDB_INSTRUMENT_VA(this, idx
);
995 // No need to lock, the target list is thread safe
996 sb_target
.SetSP(m_opaque_sp
->GetTargetList().GetTargetAtIndex(idx
));
1001 uint32_t SBDebugger::GetIndexOfTarget(lldb::SBTarget target
) {
1002 LLDB_INSTRUMENT_VA(this, target
);
1004 lldb::TargetSP target_sp
= target
.GetSP();
1011 return m_opaque_sp
->GetTargetList().GetIndexOfTarget(target
.GetSP());
1014 SBTarget
SBDebugger::FindTargetWithProcessID(lldb::pid_t pid
) {
1015 LLDB_INSTRUMENT_VA(this, pid
);
1019 // No need to lock, the target list is thread safe
1020 sb_target
.SetSP(m_opaque_sp
->GetTargetList().FindTargetWithProcessID(pid
));
1025 SBTarget
SBDebugger::FindTargetWithFileAndArch(const char *filename
,
1026 const char *arch_name
) {
1027 LLDB_INSTRUMENT_VA(this, filename
, arch_name
);
1030 if (m_opaque_sp
&& filename
&& filename
[0]) {
1031 // No need to lock, the target list is thread safe
1032 ArchSpec arch
= Platform::GetAugmentedArchSpec(
1033 m_opaque_sp
->GetPlatformList().GetSelectedPlatform().get(), arch_name
);
1035 m_opaque_sp
->GetTargetList().FindTargetWithExecutableAndArchitecture(
1036 FileSpec(filename
), arch_name
? &arch
: nullptr));
1037 sb_target
.SetSP(target_sp
);
1042 SBTarget
SBDebugger::FindTargetWithLLDBProcess(const ProcessSP
&process_sp
) {
1045 // No need to lock, the target list is thread safe
1047 m_opaque_sp
->GetTargetList().FindTargetWithProcess(process_sp
.get()));
1052 uint32_t SBDebugger::GetNumTargets() {
1053 LLDB_INSTRUMENT_VA(this);
1056 // No need to lock, the target list is thread safe
1057 return m_opaque_sp
->GetTargetList().GetNumTargets();
1062 SBTarget
SBDebugger::GetSelectedTarget() {
1063 LLDB_INSTRUMENT_VA(this);
1065 Log
*log
= GetLog(LLDBLog::API
);
1070 // No need to lock, the target list is thread safe
1071 target_sp
= m_opaque_sp
->GetTargetList().GetSelectedTarget();
1072 sb_target
.SetSP(target_sp
);
1077 sb_target
.GetDescription(sstr
, eDescriptionLevelBrief
);
1078 LLDB_LOGF(log
, "SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s",
1079 static_cast<void *>(m_opaque_sp
.get()),
1080 static_cast<void *>(target_sp
.get()), sstr
.GetData());
1086 void SBDebugger::SetSelectedTarget(SBTarget
&sb_target
) {
1087 LLDB_INSTRUMENT_VA(this, sb_target
);
1089 Log
*log
= GetLog(LLDBLog::API
);
1091 TargetSP
target_sp(sb_target
.GetSP());
1093 m_opaque_sp
->GetTargetList().SetSelectedTarget(target_sp
);
1097 sb_target
.GetDescription(sstr
, eDescriptionLevelBrief
);
1098 LLDB_LOGF(log
, "SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s",
1099 static_cast<void *>(m_opaque_sp
.get()),
1100 static_cast<void *>(target_sp
.get()), sstr
.GetData());
1104 SBPlatform
SBDebugger::GetSelectedPlatform() {
1105 LLDB_INSTRUMENT_VA(this);
1107 Log
*log
= GetLog(LLDBLog::API
);
1109 SBPlatform sb_platform
;
1110 DebuggerSP
debugger_sp(m_opaque_sp
);
1112 sb_platform
.SetSP(debugger_sp
->GetPlatformList().GetSelectedPlatform());
1114 LLDB_LOGF(log
, "SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s",
1115 static_cast<void *>(m_opaque_sp
.get()),
1116 static_cast<void *>(sb_platform
.GetSP().get()),
1117 sb_platform
.GetName());
1121 void SBDebugger::SetSelectedPlatform(SBPlatform
&sb_platform
) {
1122 LLDB_INSTRUMENT_VA(this, sb_platform
);
1124 Log
*log
= GetLog(LLDBLog::API
);
1126 DebuggerSP
debugger_sp(m_opaque_sp
);
1128 debugger_sp
->GetPlatformList().SetSelectedPlatform(sb_platform
.GetSP());
1131 LLDB_LOGF(log
, "SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)",
1132 static_cast<void *>(m_opaque_sp
.get()),
1133 static_cast<void *>(sb_platform
.GetSP().get()),
1134 sb_platform
.GetName());
1137 uint32_t SBDebugger::GetNumPlatforms() {
1138 LLDB_INSTRUMENT_VA(this);
1141 // No need to lock, the platform list is thread safe
1142 return m_opaque_sp
->GetPlatformList().GetSize();
1147 SBPlatform
SBDebugger::GetPlatformAtIndex(uint32_t idx
) {
1148 LLDB_INSTRUMENT_VA(this, idx
);
1150 SBPlatform sb_platform
;
1152 // No need to lock, the platform list is thread safe
1153 sb_platform
.SetSP(m_opaque_sp
->GetPlatformList().GetAtIndex(idx
));
1158 uint32_t SBDebugger::GetNumAvailablePlatforms() {
1159 LLDB_INSTRUMENT_VA(this);
1163 if (PluginManager::GetPlatformPluginNameAtIndex(idx
).empty()) {
1168 // +1 for the host platform, which should always appear first in the list.
1172 SBStructuredData
SBDebugger::GetAvailablePlatformInfoAtIndex(uint32_t idx
) {
1173 LLDB_INSTRUMENT_VA(this, idx
);
1175 SBStructuredData data
;
1176 auto platform_dict
= std::make_unique
<StructuredData::Dictionary
>();
1177 llvm::StringRef
name_str("name"), desc_str("description");
1180 PlatformSP
host_platform_sp(Platform::GetHostPlatform());
1181 platform_dict
->AddStringItem(name_str
, host_platform_sp
->GetPluginName());
1182 platform_dict
->AddStringItem(
1183 desc_str
, llvm::StringRef(host_platform_sp
->GetDescription()));
1184 } else if (idx
> 0) {
1185 llvm::StringRef plugin_name
=
1186 PluginManager::GetPlatformPluginNameAtIndex(idx
- 1);
1187 if (plugin_name
.empty()) {
1190 platform_dict
->AddStringItem(name_str
, llvm::StringRef(plugin_name
));
1192 llvm::StringRef plugin_desc
=
1193 PluginManager::GetPlatformPluginDescriptionAtIndex(idx
- 1);
1194 platform_dict
->AddStringItem(desc_str
, llvm::StringRef(plugin_desc
));
1197 data
.m_impl_up
->SetObjectSP(
1198 StructuredData::ObjectSP(platform_dict
.release()));
1202 void SBDebugger::DispatchInput(void *baton
, const void *data
, size_t data_len
) {
1203 LLDB_INSTRUMENT_VA(this, baton
, data
, data_len
);
1205 DispatchInput(data
, data_len
);
1208 void SBDebugger::DispatchInput(const void *data
, size_t data_len
) {
1209 LLDB_INSTRUMENT_VA(this, data
, data_len
);
1211 // Log *log(GetLog (LLDBLog::API));
1214 // LLDB_LOGF(log, "SBDebugger(%p)::DispatchInput (data=\"%.*s\",
1215 // size_t=%" PRIu64 ")",
1216 // m_opaque_sp.get(),
1218 // (const char *) data,
1219 // (uint64_t)data_len);
1222 // m_opaque_sp->DispatchInput ((const char *) data, data_len);
1225 void SBDebugger::DispatchInputInterrupt() {
1226 LLDB_INSTRUMENT_VA(this);
1229 m_opaque_sp
->DispatchInputInterrupt();
1232 void SBDebugger::DispatchInputEndOfFile() {
1233 LLDB_INSTRUMENT_VA(this);
1236 m_opaque_sp
->DispatchInputEndOfFile();
1239 void SBDebugger::PushInputReader(SBInputReader
&reader
) {
1240 LLDB_INSTRUMENT_VA(this, reader
);
1243 void SBDebugger::RunCommandInterpreter(bool auto_handle_events
,
1244 bool spawn_thread
) {
1245 LLDB_INSTRUMENT_VA(this, auto_handle_events
, spawn_thread
);
1248 CommandInterpreterRunOptions options
;
1249 options
.SetAutoHandleEvents(auto_handle_events
);
1250 options
.SetSpawnThread(spawn_thread
);
1251 m_opaque_sp
->GetCommandInterpreter().RunCommandInterpreter(options
);
1255 void SBDebugger::RunCommandInterpreter(bool auto_handle_events
,
1257 SBCommandInterpreterRunOptions
&options
,
1258 int &num_errors
, bool &quit_requested
,
1259 bool &stopped_for_crash
)
1262 LLDB_INSTRUMENT_VA(this, auto_handle_events
, spawn_thread
, options
,
1263 num_errors
, quit_requested
, stopped_for_crash
);
1266 options
.SetAutoHandleEvents(auto_handle_events
);
1267 options
.SetSpawnThread(spawn_thread
);
1268 CommandInterpreter
&interp
= m_opaque_sp
->GetCommandInterpreter();
1269 CommandInterpreterRunResult result
=
1270 interp
.RunCommandInterpreter(options
.ref());
1271 num_errors
= result
.GetNumErrors();
1273 result
.IsResult(lldb::eCommandInterpreterResultQuitRequested
);
1275 result
.IsResult(lldb::eCommandInterpreterResultInferiorCrash
);
1279 SBCommandInterpreterRunResult
SBDebugger::RunCommandInterpreter(
1280 const SBCommandInterpreterRunOptions
&options
) {
1281 LLDB_INSTRUMENT_VA(this, options
);
1284 return SBCommandInterpreterRunResult();
1286 CommandInterpreter
&interp
= m_opaque_sp
->GetCommandInterpreter();
1287 CommandInterpreterRunResult result
=
1288 interp
.RunCommandInterpreter(options
.ref());
1290 return SBCommandInterpreterRunResult(result
);
1293 SBError
SBDebugger::RunREPL(lldb::LanguageType language
,
1294 const char *repl_options
) {
1295 LLDB_INSTRUMENT_VA(this, language
, repl_options
);
1299 error
.ref() = m_opaque_sp
->RunREPL(language
, repl_options
);
1301 error
.SetErrorString("invalid debugger");
1305 void SBDebugger::reset(const DebuggerSP
&debugger_sp
) {
1306 m_opaque_sp
= debugger_sp
;
1309 Debugger
*SBDebugger::get() const { return m_opaque_sp
.get(); }
1311 Debugger
&SBDebugger::ref() const {
1312 assert(m_opaque_sp
.get());
1313 return *m_opaque_sp
;
1316 const lldb::DebuggerSP
&SBDebugger::get_sp() const { return m_opaque_sp
; }
1318 SBDebugger
SBDebugger::FindDebuggerWithID(int id
) {
1319 LLDB_INSTRUMENT_VA(id
);
1321 // No need to lock, the debugger list is thread safe
1322 SBDebugger sb_debugger
;
1323 DebuggerSP debugger_sp
= Debugger::FindDebuggerWithID(id
);
1325 sb_debugger
.reset(debugger_sp
);
1329 const char *SBDebugger::GetInstanceName() {
1330 LLDB_INSTRUMENT_VA(this);
1335 return ConstString(m_opaque_sp
->GetInstanceName()).AsCString();
1338 SBError
SBDebugger::SetInternalVariable(const char *var_name
, const char *value
,
1339 const char *debugger_instance_name
) {
1340 LLDB_INSTRUMENT_VA(var_name
, value
, debugger_instance_name
);
1343 DebuggerSP
debugger_sp(
1344 Debugger::FindDebuggerWithInstanceName(debugger_instance_name
));
1347 ExecutionContext
exe_ctx(
1348 debugger_sp
->GetCommandInterpreter().GetExecutionContext());
1349 error
= debugger_sp
->SetPropertyValue(&exe_ctx
, eVarSetOperationAssign
,
1352 error
.SetErrorStringWithFormat("invalid debugger instance name '%s'",
1353 debugger_instance_name
);
1356 sb_error
.SetError(error
);
1361 SBDebugger::GetInternalVariableValue(const char *var_name
,
1362 const char *debugger_instance_name
) {
1363 LLDB_INSTRUMENT_VA(var_name
, debugger_instance_name
);
1365 DebuggerSP
debugger_sp(
1366 Debugger::FindDebuggerWithInstanceName(debugger_instance_name
));
1369 ExecutionContext
exe_ctx(
1370 debugger_sp
->GetCommandInterpreter().GetExecutionContext());
1371 lldb::OptionValueSP
value_sp(
1372 debugger_sp
->GetPropertyValue(&exe_ctx
, var_name
, error
));
1374 StreamString value_strm
;
1375 value_sp
->DumpValue(&exe_ctx
, value_strm
, OptionValue::eDumpOptionValue
);
1376 const std::string
&value_str
= std::string(value_strm
.GetString());
1377 if (!value_str
.empty()) {
1378 StringList string_list
;
1379 string_list
.SplitIntoLines(value_str
);
1380 return SBStringList(&string_list
);
1384 return SBStringList();
1387 uint32_t SBDebugger::GetTerminalWidth() const {
1388 LLDB_INSTRUMENT_VA(this);
1390 return (m_opaque_sp
? m_opaque_sp
->GetTerminalWidth() : 0);
1393 void SBDebugger::SetTerminalWidth(uint32_t term_width
) {
1394 LLDB_INSTRUMENT_VA(this, term_width
);
1397 m_opaque_sp
->SetTerminalWidth(term_width
);
1400 const char *SBDebugger::GetPrompt() const {
1401 LLDB_INSTRUMENT_VA(this);
1403 Log
*log
= GetLog(LLDBLog::API
);
1405 LLDB_LOG(log
, "SBDebugger({0:x})::GetPrompt () => \"{1}\"",
1406 static_cast<void *>(m_opaque_sp
.get()),
1407 (m_opaque_sp
? m_opaque_sp
->GetPrompt() : ""));
1409 return (m_opaque_sp
? ConstString(m_opaque_sp
->GetPrompt()).GetCString()
1413 void SBDebugger::SetPrompt(const char *prompt
) {
1414 LLDB_INSTRUMENT_VA(this, prompt
);
1417 m_opaque_sp
->SetPrompt(llvm::StringRef(prompt
));
1420 const char *SBDebugger::GetReproducerPath() const {
1421 LLDB_INSTRUMENT_VA(this);
1423 return "GetReproducerPath has been deprecated";
1426 ScriptLanguage
SBDebugger::GetScriptLanguage() const {
1427 LLDB_INSTRUMENT_VA(this);
1429 return (m_opaque_sp
? m_opaque_sp
->GetScriptLanguage() : eScriptLanguageNone
);
1432 void SBDebugger::SetScriptLanguage(ScriptLanguage script_lang
) {
1433 LLDB_INSTRUMENT_VA(this, script_lang
);
1436 m_opaque_sp
->SetScriptLanguage(script_lang
);
1440 LanguageType
SBDebugger::GetREPLLanguage() const {
1441 LLDB_INSTRUMENT_VA(this);
1443 return (m_opaque_sp
? m_opaque_sp
->GetREPLLanguage() : eLanguageTypeUnknown
);
1446 void SBDebugger::SetREPLLanguage(LanguageType repl_lang
) {
1447 LLDB_INSTRUMENT_VA(this, repl_lang
);
1450 m_opaque_sp
->SetREPLLanguage(repl_lang
);
1454 bool SBDebugger::SetUseExternalEditor(bool value
) {
1455 LLDB_INSTRUMENT_VA(this, value
);
1457 return (m_opaque_sp
? m_opaque_sp
->SetUseExternalEditor(value
) : false);
1460 bool SBDebugger::GetUseExternalEditor() {
1461 LLDB_INSTRUMENT_VA(this);
1463 return (m_opaque_sp
? m_opaque_sp
->GetUseExternalEditor() : false);
1466 bool SBDebugger::SetUseColor(bool value
) {
1467 LLDB_INSTRUMENT_VA(this, value
);
1469 return (m_opaque_sp
? m_opaque_sp
->SetUseColor(value
) : false);
1472 bool SBDebugger::GetUseColor() const {
1473 LLDB_INSTRUMENT_VA(this);
1475 return (m_opaque_sp
? m_opaque_sp
->GetUseColor() : false);
1478 bool SBDebugger::SetUseSourceCache(bool value
) {
1479 LLDB_INSTRUMENT_VA(this, value
);
1481 return (m_opaque_sp
? m_opaque_sp
->SetUseSourceCache(value
) : false);
1484 bool SBDebugger::GetUseSourceCache() const {
1485 LLDB_INSTRUMENT_VA(this);
1487 return (m_opaque_sp
? m_opaque_sp
->GetUseSourceCache() : false);
1490 bool SBDebugger::GetDescription(SBStream
&description
) {
1491 LLDB_INSTRUMENT_VA(this, description
);
1493 Stream
&strm
= description
.ref();
1496 const char *name
= m_opaque_sp
->GetInstanceName().c_str();
1497 user_id_t id
= m_opaque_sp
->GetID();
1498 strm
.Printf("Debugger (instance: \"%s\", id: %" PRIu64
")", name
, id
);
1500 strm
.PutCString("No value");
1505 user_id_t
SBDebugger::GetID() {
1506 LLDB_INSTRUMENT_VA(this);
1508 return (m_opaque_sp
? m_opaque_sp
->GetID() : LLDB_INVALID_UID
);
1511 SBError
SBDebugger::SetCurrentPlatform(const char *platform_name_cstr
) {
1512 LLDB_INSTRUMENT_VA(this, platform_name_cstr
);
1516 if (platform_name_cstr
&& platform_name_cstr
[0]) {
1517 PlatformList
&platforms
= m_opaque_sp
->GetPlatformList();
1518 if (PlatformSP platform_sp
= platforms
.GetOrCreate(platform_name_cstr
))
1519 platforms
.SetSelectedPlatform(platform_sp
);
1521 sb_error
.ref().SetErrorString("platform not found");
1523 sb_error
.ref().SetErrorString("invalid platform name");
1526 sb_error
.ref().SetErrorString("invalid debugger");
1531 bool SBDebugger::SetCurrentPlatformSDKRoot(const char *sysroot
) {
1532 LLDB_INSTRUMENT_VA(this, sysroot
);
1534 if (SBPlatform platform
= GetSelectedPlatform()) {
1535 platform
.SetSDKRoot(sysroot
);
1541 bool SBDebugger::GetCloseInputOnEOF() const {
1542 LLDB_INSTRUMENT_VA(this);
1547 void SBDebugger::SetCloseInputOnEOF(bool b
) {
1548 LLDB_INSTRUMENT_VA(this, b
);
1551 SBTypeCategory
SBDebugger::GetCategory(const char *category_name
) {
1552 LLDB_INSTRUMENT_VA(this, category_name
);
1554 if (!category_name
|| *category_name
== 0)
1555 return SBTypeCategory();
1557 TypeCategoryImplSP category_sp
;
1559 if (DataVisualization::Categories::GetCategory(ConstString(category_name
),
1560 category_sp
, false)) {
1561 return SBTypeCategory(category_sp
);
1563 return SBTypeCategory();
1567 SBTypeCategory
SBDebugger::GetCategory(lldb::LanguageType lang_type
) {
1568 LLDB_INSTRUMENT_VA(this, lang_type
);
1570 TypeCategoryImplSP category_sp
;
1571 if (DataVisualization::Categories::GetCategory(lang_type
, category_sp
)) {
1572 return SBTypeCategory(category_sp
);
1574 return SBTypeCategory();
1578 SBTypeCategory
SBDebugger::CreateCategory(const char *category_name
) {
1579 LLDB_INSTRUMENT_VA(this, category_name
);
1581 if (!category_name
|| *category_name
== 0)
1582 return SBTypeCategory();
1584 TypeCategoryImplSP category_sp
;
1586 if (DataVisualization::Categories::GetCategory(ConstString(category_name
),
1587 category_sp
, true)) {
1588 return SBTypeCategory(category_sp
);
1590 return SBTypeCategory();
1594 bool SBDebugger::DeleteCategory(const char *category_name
) {
1595 LLDB_INSTRUMENT_VA(this, category_name
);
1597 if (!category_name
|| *category_name
== 0)
1600 return DataVisualization::Categories::Delete(ConstString(category_name
));
1603 uint32_t SBDebugger::GetNumCategories() {
1604 LLDB_INSTRUMENT_VA(this);
1606 return DataVisualization::Categories::GetCount();
1609 SBTypeCategory
SBDebugger::GetCategoryAtIndex(uint32_t index
) {
1610 LLDB_INSTRUMENT_VA(this, index
);
1612 return SBTypeCategory(
1613 DataVisualization::Categories::GetCategoryAtIndex(index
));
1616 SBTypeCategory
SBDebugger::GetDefaultCategory() {
1617 LLDB_INSTRUMENT_VA(this);
1619 return GetCategory("default");
1622 SBTypeFormat
SBDebugger::GetFormatForType(SBTypeNameSpecifier type_name
) {
1623 LLDB_INSTRUMENT_VA(this, type_name
);
1625 SBTypeCategory default_category_sb
= GetDefaultCategory();
1626 if (default_category_sb
.GetEnabled())
1627 return default_category_sb
.GetFormatForType(type_name
);
1628 return SBTypeFormat();
1631 SBTypeSummary
SBDebugger::GetSummaryForType(SBTypeNameSpecifier type_name
) {
1632 LLDB_INSTRUMENT_VA(this, type_name
);
1634 if (!type_name
.IsValid())
1635 return SBTypeSummary();
1636 return SBTypeSummary(DataVisualization::GetSummaryForType(type_name
.GetSP()));
1639 SBTypeFilter
SBDebugger::GetFilterForType(SBTypeNameSpecifier type_name
) {
1640 LLDB_INSTRUMENT_VA(this, type_name
);
1642 if (!type_name
.IsValid())
1643 return SBTypeFilter();
1644 return SBTypeFilter(DataVisualization::GetFilterForType(type_name
.GetSP()));
1647 SBTypeSynthetic
SBDebugger::GetSyntheticForType(SBTypeNameSpecifier type_name
) {
1648 LLDB_INSTRUMENT_VA(this, type_name
);
1650 if (!type_name
.IsValid())
1651 return SBTypeSynthetic();
1652 return SBTypeSynthetic(
1653 DataVisualization::GetSyntheticForType(type_name
.GetSP()));
1656 static llvm::ArrayRef
<const char *> GetCategoryArray(const char **categories
) {
1657 if (categories
== nullptr)
1660 while (categories
[len
] != nullptr)
1662 return llvm::ArrayRef(categories
, len
);
1665 bool SBDebugger::EnableLog(const char *channel
, const char **categories
) {
1666 LLDB_INSTRUMENT_VA(this, channel
, categories
);
1669 uint32_t log_options
=
1670 LLDB_LOG_OPTION_PREPEND_TIMESTAMP
| LLDB_LOG_OPTION_PREPEND_THREAD_NAME
;
1672 llvm::raw_string_ostream
error_stream(error
);
1673 return m_opaque_sp
->EnableLog(channel
, GetCategoryArray(categories
), "",
1674 log_options
, /*buffer_size=*/0,
1675 eLogHandlerStream
, error_stream
);
1680 void SBDebugger::SetLoggingCallback(lldb::LogOutputCallback log_callback
,
1682 LLDB_INSTRUMENT_VA(this, log_callback
, baton
);
1685 return m_opaque_sp
->SetLoggingCallback(log_callback
, baton
);
1689 void SBDebugger::SetDestroyCallback(
1690 lldb::SBDebuggerDestroyCallback destroy_callback
, void *baton
) {
1691 LLDB_INSTRUMENT_VA(this, destroy_callback
, baton
);
1693 return m_opaque_sp
->SetDestroyCallback(
1694 destroy_callback
, baton
);
1699 SBDebugger::LoadTraceFromFile(SBError
&error
,
1700 const SBFileSpec
&trace_description_file
) {
1701 LLDB_INSTRUMENT_VA(this, error
, trace_description_file
);
1702 return SBTrace::LoadTraceFromFile(error
, *this, trace_description_file
);
1705 void SBDebugger::RequestInterrupt() {
1706 LLDB_INSTRUMENT_VA(this);
1709 m_opaque_sp
->RequestInterrupt();
1711 void SBDebugger::CancelInterruptRequest() {
1712 LLDB_INSTRUMENT_VA(this);
1715 m_opaque_sp
->CancelInterruptRequest();
1718 bool SBDebugger::InterruptRequested() {
1719 LLDB_INSTRUMENT_VA(this);
1722 return m_opaque_sp
->InterruptRequested();