LLDB mainline
SBDebugger.cpp
Go to the documentation of this file.
1//===-- SBDebugger.cpp ----------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
13
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"
25#include "lldb/API/SBStream.h"
28#include "lldb/API/SBTarget.h"
29#include "lldb/API/SBThread.h"
30#include "lldb/API/SBTrace.h"
37
38#include "lldb/Core/Debugger.h"
41#include "lldb/Core/Progress.h"
45#include "lldb/Host/Config.h"
46#include "lldb/Host/XML.h"
51#include "lldb/Target/Process.h"
53#include "lldb/Utility/Args.h"
55#include "lldb/Utility/State.h"
57
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"
64
65using namespace lldb;
66using namespace lldb_private;
67
68static llvm::sys::DynamicLibrary LoadPlugin(const lldb::DebuggerSP &debugger_sp,
69 const FileSpec &spec,
70 Status &error) {
71 llvm::sys::DynamicLibrary dynlib =
72 llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
73 if (dynlib.isValid()) {
74 typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger & debugger);
75
76 lldb::SBDebugger debugger_sb(debugger_sp);
77 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger)
78 // function.
79 // TODO: mangle this differently for your system - on OSX, the first
80 // underscore needs to be removed and the second one stays
81 LLDBCommandPluginInit init_func =
82 (LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol(
83 "_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
84 if (init_func) {
85 if (init_func(debugger_sb))
86 return dynlib;
87 else
88 error.SetErrorString("plug-in refused to load "
89 "(lldb::PluginInitialize(lldb::SBDebugger) "
90 "returned false)");
91 } else {
92 error.SetErrorString("plug-in is missing the required initialization: "
93 "lldb::PluginInitialize(lldb::SBDebugger)");
94 }
95 } else {
96 if (FileSystem::Instance().Exists(spec))
97 error.SetErrorString("this file does not represent a loadable dylib");
98 else
99 error.SetErrorString("no such file");
100 }
101 return llvm::sys::DynamicLibrary();
102}
103
104static llvm::ManagedStatic<SystemLifetimeManager> g_debugger_lifetime;
105
107 lldb::SBDebugger &sb_debugger,
108 unsigned long (*callback)(void *, lldb::SBInputReader *,
109 lldb::InputReaderAction, char const *,
110 unsigned long),
111 void *a, lldb::InputReaderGranularity b, char const *c, char const *d,
112 bool e) {
113 LLDB_INSTRUMENT_VA(this, sb_debugger, callback, a, b, c, d, e);
114
115 return SBError();
116}
117
119
121 LLDB_INSTRUMENT_VA(this);
122
123 return false;
124}
125
127
128SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp)
129 : m_opaque_sp(debugger_sp) {
130 LLDB_INSTRUMENT_VA(this, debugger_sp);
131}
132
133SBDebugger::SBDebugger(const SBDebugger &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
134 LLDB_INSTRUMENT_VA(this, rhs);
135}
136
137SBDebugger::~SBDebugger() = default;
138
140 LLDB_INSTRUMENT_VA(this, rhs);
141
142 if (this != &rhs) {
144 }
145 return *this;
146}
147
150
152}
153
155 uint64_t &progress_id,
156 uint64_t &completed,
157 uint64_t &total,
158 bool &is_debugger_specific) {
159 LLDB_INSTRUMENT_VA(event);
160 const ProgressEventData *progress_data =
162 if (progress_data == nullptr)
163 return nullptr;
164 progress_id = progress_data->GetID();
165 completed = progress_data->GetCompleted();
166 total = progress_data->GetTotal();
167 is_debugger_specific = progress_data->IsDebuggerSpecific();
168 return progress_data->GetMessage().c_str();
169}
170
173 LLDB_INSTRUMENT_VA(event);
174
175 const DiagnosticEventData *diagnostic_data =
177 if (!diagnostic_data)
178 return {};
179
180 auto dictionary = std::make_unique<StructuredData::Dictionary>();
181 dictionary->AddStringItem("message", diagnostic_data->GetMessage());
182 dictionary->AddStringItem("type", diagnostic_data->GetPrefix());
183 dictionary->AddBooleanItem("debugger_specific",
184 diagnostic_data->IsDebuggerSpecific());
185
186 SBStructuredData data;
187 data.m_impl_up->SetObjectSP(std::move(dictionary));
188 return data;
189}
190
192 LLDB_INSTRUMENT_VA(this);
193 SBBroadcaster broadcaster(&m_opaque_sp->GetBroadcaster(), false);
194 return broadcaster;
195}
196
200}
201
204
206 if (auto e = g_debugger_lifetime->Initialize(
207 std::make_unique<SystemInitializerFull>(), LoadPlugin)) {
208 error.SetError(Status(std::move(e)));
209 }
210 return error;
211}
212
215
216 llvm::EnablePrettyStackTrace();
217 static std::string executable =
218 llvm::sys::fs::getMainExecutable(nullptr, nullptr);
219 llvm::sys::PrintStackTraceOnErrorSignal(executable);
220}
221
222static void DumpDiagnostics(void *cookie) {
223 Diagnostics::Instance().Dump(llvm::errs());
224}
225
228
229 llvm::sys::AddSignalHandler(&DumpDiagnostics, nullptr);
230}
231
234
235 g_debugger_lifetime->Terminate();
236}
237
239 LLDB_INSTRUMENT_VA(this);
240
241 if (m_opaque_sp)
242 m_opaque_sp->ClearIOHandlers();
243
244 m_opaque_sp.reset();
245}
246
249
250 return SBDebugger::Create(false, nullptr, nullptr);
251}
252
253SBDebugger SBDebugger::Create(bool source_init_files) {
254 LLDB_INSTRUMENT_VA(source_init_files);
255
256 return SBDebugger::Create(source_init_files, nullptr, nullptr);
257}
258
259SBDebugger SBDebugger::Create(bool source_init_files,
260 lldb::LogOutputCallback callback, void *baton)
261
262{
263 LLDB_INSTRUMENT_VA(source_init_files, callback, baton);
264
265 SBDebugger debugger;
266
267 // Currently we have issues if this function is called simultaneously on two
268 // different threads. The issues mainly revolve around the fact that the
269 // lldb_private::FormatManager uses global collections and having two threads
270 // parsing the .lldbinit files can cause mayhem. So to get around this for
271 // now we need to use a mutex to prevent bad things from happening.
272 static std::recursive_mutex g_mutex;
273 std::lock_guard<std::recursive_mutex> guard(g_mutex);
274
275 debugger.reset(Debugger::CreateInstance(callback, baton));
276
278 if (source_init_files) {
279 interp.get()->SkipLLDBInitFiles(false);
280 interp.get()->SkipAppInitFiles(false);
282 interp.SourceInitFileInGlobalDirectory(result);
283 interp.SourceInitFileInHomeDirectory(result, false);
284 } else {
285 interp.get()->SkipLLDBInitFiles(true);
286 interp.get()->SkipAppInitFiles(true);
287 }
288 return debugger;
289}
290
292 LLDB_INSTRUMENT_VA(debugger);
293
295
296 if (debugger.m_opaque_sp.get() != nullptr)
297 debugger.m_opaque_sp.reset();
298}
299
302
303 // Since this function can be call asynchronously, we allow it to be non-
304 // mandatory. We have seen deadlocks with this function when called so we
305 // need to safeguard against this until we can determine what is causing the
306 // deadlocks.
307
308 const bool mandatory = false;
309
311}
312
314 LLDB_INSTRUMENT_VA(this);
315 return this->operator bool();
316}
317SBDebugger::operator bool() const {
318 LLDB_INSTRUMENT_VA(this);
319
320 return m_opaque_sp.get() != nullptr;
321}
322
324 LLDB_INSTRUMENT_VA(this, b);
325
326 if (m_opaque_sp)
327 m_opaque_sp->SetAsyncExecution(b);
328}
329
331 LLDB_INSTRUMENT_VA(this);
332
333 return (m_opaque_sp ? m_opaque_sp->GetAsyncExecution() : false);
334}
335
337 LLDB_INSTRUMENT_VA(this, b);
338
339 if (m_opaque_sp)
340 m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles(b);
341}
342
344 LLDB_INSTRUMENT_VA(this, b);
345
346 if (m_opaque_sp)
347 m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles(b);
348}
349
350void SBDebugger::SetInputFileHandle(FILE *fh, bool transfer_ownership) {
351 LLDB_INSTRUMENT_VA(this, fh, transfer_ownership);
352 if (m_opaque_sp)
353 m_opaque_sp->SetInputFile(
354 (FileSP)std::make_shared<NativeFile>(fh, transfer_ownership));
355}
356
358 LLDB_INSTRUMENT_VA(this, data);
359 SBError sb_error;
360 if (data == nullptr) {
361 sb_error.SetErrorString("String data is null");
362 return sb_error;
363 }
364
365 size_t size = strlen(data);
366 if (size == 0) {
367 sb_error.SetErrorString("String data is empty");
368 return sb_error;
369 }
370
371 if (!m_opaque_sp) {
372 sb_error.SetErrorString("invalid debugger");
373 return sb_error;
374 }
375
376 sb_error.SetError(m_opaque_sp->SetInputString(data));
377 return sb_error;
378}
379
380// Shouldn't really be settable after initialization as this could cause lots
381// of problems; don't want users trying to switch modes in the middle of a
382// debugging session.
384 LLDB_INSTRUMENT_VA(this, file);
385
387 if (!m_opaque_sp) {
388 error.ref().SetErrorString("invalid debugger");
389 return error;
390 }
391 if (!file) {
392 error.ref().SetErrorString("invalid file");
393 return error;
394 }
395 m_opaque_sp->SetInputFile(file.m_opaque_sp);
396 return error;
397}
398
400 LLDB_INSTRUMENT_VA(this, file_sp);
401 return SetInputFile(SBFile(file_sp));
402}
403
405 LLDB_INSTRUMENT_VA(this, file_sp);
406 return SetOutputFile(SBFile(file_sp));
407}
408
409void SBDebugger::SetOutputFileHandle(FILE *fh, bool transfer_ownership) {
410 LLDB_INSTRUMENT_VA(this, fh, transfer_ownership);
411 SetOutputFile((FileSP)std::make_shared<NativeFile>(fh, transfer_ownership));
412}
413
415 LLDB_INSTRUMENT_VA(this, file);
417 if (!m_opaque_sp) {
418 error.ref().SetErrorString("invalid debugger");
419 return error;
420 }
421 if (!file) {
422 error.ref().SetErrorString("invalid file");
423 return error;
424 }
425 m_opaque_sp->SetOutputFile(file.m_opaque_sp);
426 return error;
427}
428
429void SBDebugger::SetErrorFileHandle(FILE *fh, bool transfer_ownership) {
430 LLDB_INSTRUMENT_VA(this, fh, transfer_ownership);
431 SetErrorFile((FileSP)std::make_shared<NativeFile>(fh, transfer_ownership));
432}
433
435 LLDB_INSTRUMENT_VA(this, file_sp);
436 return SetErrorFile(SBFile(file_sp));
437}
438
440 LLDB_INSTRUMENT_VA(this, file);
442 if (!m_opaque_sp) {
443 error.ref().SetErrorString("invalid debugger");
444 return error;
445 }
446 if (!file) {
447 error.ref().SetErrorString("invalid file");
448 return error;
449 }
450 m_opaque_sp->SetErrorFile(file.m_opaque_sp);
451 return error;
452}
453
455 LLDB_INSTRUMENT_VA(this, setting);
456
457 SBStructuredData data;
458 if (!m_opaque_sp)
459 return data;
460
461 StreamString json_strm;
462 ExecutionContext exe_ctx(
463 m_opaque_sp->GetCommandInterpreter().GetExecutionContext());
464 if (setting && strlen(setting) > 0)
465 m_opaque_sp->DumpPropertyValue(&exe_ctx, json_strm, setting,
466 /*dump_mask*/ 0,
467 /*is_json*/ true);
468 else
469 m_opaque_sp->DumpAllPropertyValues(&exe_ctx, json_strm, /*dump_mask*/ 0,
470 /*is_json*/ true);
471
472 data.m_impl_up->SetObjectSP(
473 StructuredData::ParseJSON(json_strm.GetString().str()));
474 return data;
475}
476
478 LLDB_INSTRUMENT_VA(this);
479 if (m_opaque_sp) {
480 File &file_sp = m_opaque_sp->GetInputFile();
481 return file_sp.GetStream();
482 }
483 return nullptr;
484}
485
487 LLDB_INSTRUMENT_VA(this);
488 if (m_opaque_sp) {
489 return SBFile(m_opaque_sp->GetInputFileSP());
490 }
491 return SBFile();
492}
493
495 LLDB_INSTRUMENT_VA(this);
496 if (m_opaque_sp) {
497 StreamFile &stream_file = m_opaque_sp->GetOutputStream();
498 return stream_file.GetFile().GetStream();
499 }
500 return nullptr;
501}
502
504 LLDB_INSTRUMENT_VA(this);
505 if (m_opaque_sp) {
506 SBFile file(m_opaque_sp->GetOutputStream().GetFileSP());
507 return file;
508 }
509 return SBFile();
510}
511
513 LLDB_INSTRUMENT_VA(this);
514
515 if (m_opaque_sp) {
516 StreamFile &stream_file = m_opaque_sp->GetErrorStream();
517 return stream_file.GetFile().GetStream();
518 }
519 return nullptr;
520}
521
523 LLDB_INSTRUMENT_VA(this);
524 SBFile file;
525 if (m_opaque_sp) {
526 SBFile file(m_opaque_sp->GetErrorStream().GetFileSP());
527 return file;
528 }
529 return SBFile();
530}
531
533 LLDB_INSTRUMENT_VA(this);
534
535 if (m_opaque_sp)
536 m_opaque_sp->SaveInputTerminalState();
537}
538
540 LLDB_INSTRUMENT_VA(this);
541
542 if (m_opaque_sp)
543 m_opaque_sp->RestoreInputTerminalState();
544}
546 LLDB_INSTRUMENT_VA(this);
547
548 SBCommandInterpreter sb_interpreter;
549 if (m_opaque_sp)
550 sb_interpreter.reset(&m_opaque_sp->GetCommandInterpreter());
551
552 return sb_interpreter;
553}
554
555void SBDebugger::HandleCommand(const char *command) {
556 LLDB_INSTRUMENT_VA(this, command);
557
558 if (m_opaque_sp) {
559 TargetSP target_sp(m_opaque_sp->GetSelectedTarget());
560 std::unique_lock<std::recursive_mutex> lock;
561 if (target_sp)
562 lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
563
566
567 sb_interpreter.HandleCommand(command, result, false);
568
569 result.PutError(m_opaque_sp->GetErrorStream().GetFileSP());
570 result.PutOutput(m_opaque_sp->GetOutputStream().GetFileSP());
571
572 if (!m_opaque_sp->GetAsyncExecution()) {
573 SBProcess process(GetCommandInterpreter().GetProcess());
574 ProcessSP process_sp(process.GetSP());
575 if (process_sp) {
576 EventSP event_sp;
577 ListenerSP lldb_listener_sp = m_opaque_sp->GetListener();
578 while (lldb_listener_sp->GetEventForBroadcaster(
579 process_sp.get(), event_sp, std::chrono::seconds(0))) {
580 SBEvent event(event_sp);
581 HandleProcessEvent(process, event, GetOutputFile(), GetErrorFile());
582 }
583 }
584 }
585 }
586}
587
589 LLDB_INSTRUMENT_VA(this);
590
591 SBListener sb_listener;
592 if (m_opaque_sp)
593 sb_listener.reset(m_opaque_sp->GetListener());
594
595 return sb_listener;
596}
597
599 const SBEvent &event, SBFile out,
600 SBFile err) {
601 LLDB_INSTRUMENT_VA(this, process, event, out, err);
602
603 return HandleProcessEvent(process, event, out.m_opaque_sp, err.m_opaque_sp);
604}
605
607 const SBEvent &event, FILE *out,
608 FILE *err) {
609 LLDB_INSTRUMENT_VA(this, process, event, out, err);
610
611 FileSP outfile = std::make_shared<NativeFile>(out, false);
612 FileSP errfile = std::make_shared<NativeFile>(err, false);
613 return HandleProcessEvent(process, event, outfile, errfile);
614}
615
617 const SBEvent &event, FileSP out_sp,
618 FileSP err_sp) {
619
620 LLDB_INSTRUMENT_VA(this, process, event, out_sp, err_sp);
621
622 if (!process.IsValid())
623 return;
624
625 TargetSP target_sp(process.GetTarget().GetSP());
626 if (!target_sp)
627 return;
628
629 const uint32_t event_type = event.GetType();
630 char stdio_buffer[1024];
631 size_t len;
632
633 std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
634
635 if (event_type &
637 // Drain stdout when we stop just in case we have any bytes
638 while ((len = process.GetSTDOUT(stdio_buffer, sizeof(stdio_buffer))) > 0)
639 if (out_sp)
640 out_sp->Write(stdio_buffer, len);
641 }
642
643 if (event_type &
645 // Drain stderr when we stop just in case we have any bytes
646 while ((len = process.GetSTDERR(stdio_buffer, sizeof(stdio_buffer))) > 0)
647 if (err_sp)
648 err_sp->Write(stdio_buffer, len);
649 }
650
651 if (event_type & Process::eBroadcastBitStateChanged) {
652 StateType event_state = SBProcess::GetStateFromEvent(event);
653
654 if (event_state == eStateInvalid)
655 return;
656
657 bool is_stopped = StateIsStoppedState(event_state);
658 if (!is_stopped)
659 process.ReportEventState(event, out_sp);
660 }
661}
662
664 LLDB_INSTRUMENT_VA(this);
665
666 SBSourceManager sb_source_manager(*this);
667 return sb_source_manager;
668}
669
670bool SBDebugger::GetDefaultArchitecture(char *arch_name, size_t arch_name_len) {
671 LLDB_INSTRUMENT_VA(arch_name, arch_name_len);
672
673 if (arch_name && arch_name_len) {
675
676 if (default_arch.IsValid()) {
677 const std::string &triple_str = default_arch.GetTriple().str();
678 if (!triple_str.empty())
679 ::snprintf(arch_name, arch_name_len, "%s", triple_str.c_str());
680 else
681 ::snprintf(arch_name, arch_name_len, "%s",
682 default_arch.GetArchitectureName());
683 return true;
684 }
685 }
686 if (arch_name && arch_name_len)
687 arch_name[0] = '\0';
688 return false;
689}
690
691bool SBDebugger::SetDefaultArchitecture(const char *arch_name) {
692 LLDB_INSTRUMENT_VA(arch_name);
693
694 if (arch_name) {
695 ArchSpec arch(arch_name);
696 if (arch.IsValid()) {
698 return true;
699 }
700 }
701 return false;
702}
703
705SBDebugger::GetScriptingLanguage(const char *script_language_name) {
706 LLDB_INSTRUMENT_VA(this, script_language_name);
707
708 if (!script_language_name)
711 llvm::StringRef(script_language_name), eScriptLanguageDefault, nullptr);
712}
713
716 LLDB_INSTRUMENT_VA(this, language);
717 SBStructuredData data;
718 if (m_opaque_sp) {
720 m_opaque_sp->GetScriptInterpreter(language);
721 if (interp) {
722 data.m_impl_up->SetObjectSP(interp->GetInterpreterInfo());
723 }
724 }
725 return data;
726}
727
730
732}
733
735 LLDB_INSTRUMENT_VA(state);
736
737 return lldb_private::StateAsCString(state);
738}
739
741 llvm::StringRef name, bool value,
742 llvm::StringRef description) {
743 auto entry_up = std::make_unique<StructuredData::Dictionary>();
744 entry_up->AddBooleanItem("value", value);
745 entry_up->AddStringItem("description", description);
746 dict.AddItem(name, std::move(entry_up));
747}
748
750 auto array_up = std::make_unique<StructuredData::Array>();
751#define LLVM_TARGET(target) \
752 array_up->AddItem(std::make_unique<StructuredData::String>(#target));
753#include "llvm/Config/Targets.def"
754 auto entry_up = std::make_unique<StructuredData::Dictionary>();
755 entry_up->AddItem("value", std::move(array_up));
756 entry_up->AddStringItem("description", "A list of configured LLVM targets.");
757 dict.AddItem("targets", std::move(entry_up));
758}
759
762
763 auto config_up = std::make_unique<StructuredData::Dictionary>();
765 *config_up, "xml", XMLDocument::XMLEnabled(),
766 "A boolean value that indicates if XML support is enabled in LLDB");
768 *config_up, "curses", LLDB_ENABLE_CURSES,
769 "A boolean value that indicates if curses support is enabled in LLDB");
771 *config_up, "editline", LLDB_ENABLE_LIBEDIT,
772 "A boolean value that indicates if editline support is enabled in LLDB");
774 *config_up, "lzma", LLDB_ENABLE_LZMA,
775 "A boolean value that indicates if lzma support is enabled in LLDB");
777 *config_up, "python", LLDB_ENABLE_PYTHON,
778 "A boolean value that indicates if python support is enabled in LLDB");
780 *config_up, "lua", LLDB_ENABLE_LUA,
781 "A boolean value that indicates if lua support is enabled in LLDB");
782 AddBoolConfigEntry(*config_up, "fbsdvmcore", LLDB_ENABLE_FBSDVMCORE,
783 "A boolean value that indicates if fbsdvmcore support is "
784 "enabled in LLDB");
785 AddLLVMTargets(*config_up);
786
787 SBStructuredData data;
788 data.m_impl_up->SetObjectSP(std::move(config_up));
789 return data;
790}
791
793 LLDB_INSTRUMENT_VA(state);
794
795 const bool result = lldb_private::StateIsRunningState(state);
796
797 return result;
798}
799
801 LLDB_INSTRUMENT_VA(state);
802
803 const bool result = lldb_private::StateIsStoppedState(state, false);
804
805 return result;
806}
807
809 const char *target_triple,
810 const char *platform_name,
811 bool add_dependent_modules,
812 lldb::SBError &sb_error) {
813 LLDB_INSTRUMENT_VA(this, filename, target_triple, platform_name,
814 add_dependent_modules, sb_error);
815
816 SBTarget sb_target;
817 TargetSP target_sp;
818 if (m_opaque_sp) {
819 sb_error.Clear();
820 OptionGroupPlatform platform_options(false);
821 platform_options.SetPlatformName(platform_name);
822
823 sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget(
824 *m_opaque_sp, filename, target_triple,
825 add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo,
826 &platform_options, target_sp);
827
828 if (sb_error.Success())
829 sb_target.SetSP(target_sp);
830 } else {
831 sb_error.SetErrorString("invalid debugger");
832 }
833
834 Log *log = GetLog(LLDBLog::API);
835 LLDB_LOGF(log,
836 "SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, "
837 "platform_name=%s, add_dependent_modules=%u, error=%s) => "
838 "SBTarget(%p)",
839 static_cast<void *>(m_opaque_sp.get()), filename, target_triple,
840 platform_name, add_dependent_modules, sb_error.GetCString(),
841 static_cast<void *>(target_sp.get()));
842
843 return sb_target;
844}
845
848 const char *target_triple) {
849 LLDB_INSTRUMENT_VA(this, filename, target_triple);
850
851 SBTarget sb_target;
852 TargetSP target_sp;
853 if (m_opaque_sp) {
854 const bool add_dependent_modules = true;
855 Status error(m_opaque_sp->GetTargetList().CreateTarget(
856 *m_opaque_sp, filename, target_triple,
857 add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,
858 target_sp));
859 sb_target.SetSP(target_sp);
860 }
861
862 Log *log = GetLog(LLDBLog::API);
863 LLDB_LOGF(log,
864 "SBDebugger(%p)::CreateTargetWithFileAndTargetTriple "
865 "(filename=\"%s\", triple=%s) => SBTarget(%p)",
866 static_cast<void *>(m_opaque_sp.get()), filename, target_triple,
867 static_cast<void *>(target_sp.get()));
868
869 return sb_target;
870}
871
873 const char *arch_cstr) {
874 LLDB_INSTRUMENT_VA(this, filename, arch_cstr);
875
876 Log *log = GetLog(LLDBLog::API);
877
878 SBTarget sb_target;
879 TargetSP target_sp;
880 if (m_opaque_sp) {
882 if (arch_cstr == nullptr) {
883 // The version of CreateTarget that takes an ArchSpec won't accept an
884 // empty ArchSpec, so when the arch hasn't been specified, we need to
885 // call the target triple version.
886 error = m_opaque_sp->GetTargetList().CreateTarget(
887 *m_opaque_sp, filename, arch_cstr, eLoadDependentsYes, nullptr,
888 target_sp);
889 } else {
890 PlatformSP platform_sp =
891 m_opaque_sp->GetPlatformList().GetSelectedPlatform();
892 ArchSpec arch =
893 Platform::GetAugmentedArchSpec(platform_sp.get(), arch_cstr);
894 if (arch.IsValid())
895 error = m_opaque_sp->GetTargetList().CreateTarget(
896 *m_opaque_sp, filename, arch, eLoadDependentsYes, platform_sp,
897 target_sp);
898 else
899 error.SetErrorStringWithFormat("invalid arch_cstr: %s", arch_cstr);
900 }
901 if (error.Success())
902 sb_target.SetSP(target_sp);
903 }
904
905 LLDB_LOGF(log,
906 "SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", "
907 "arch=%s) => SBTarget(%p)",
908 static_cast<void *>(m_opaque_sp.get()),
909 filename ? filename : "<unspecified>",
910 arch_cstr ? arch_cstr : "<unspecified>",
911 static_cast<void *>(target_sp.get()));
912
913 return sb_target;
914}
915
916SBTarget SBDebugger::CreateTarget(const char *filename) {
917 LLDB_INSTRUMENT_VA(this, filename);
918
919 SBTarget sb_target;
920 TargetSP target_sp;
921 if (m_opaque_sp) {
923 const bool add_dependent_modules = true;
924 error = m_opaque_sp->GetTargetList().CreateTarget(
925 *m_opaque_sp, filename, "",
926 add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,
927 target_sp);
928
929 if (error.Success())
930 sb_target.SetSP(target_sp);
931 }
932 Log *log = GetLog(LLDBLog::API);
933 LLDB_LOGF(log,
934 "SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
935 static_cast<void *>(m_opaque_sp.get()), filename,
936 static_cast<void *>(target_sp.get()));
937 return sb_target;
938}
939
941 LLDB_INSTRUMENT_VA(this);
942
943 SBTarget sb_target;
944 if (m_opaque_sp) {
945 sb_target.SetSP(m_opaque_sp->GetDummyTarget().shared_from_this());
946 }
947 Log *log = GetLog(LLDBLog::API);
948 LLDB_LOGF(log, "SBDebugger(%p)::GetDummyTarget() => SBTarget(%p)",
949 static_cast<void *>(m_opaque_sp.get()),
950 static_cast<void *>(sb_target.GetSP().get()));
951 return sb_target;
952}
953
955 LLDB_INSTRUMENT_VA(this, target);
956
957 bool result = false;
958 if (m_opaque_sp) {
959 TargetSP target_sp(target.GetSP());
960 if (target_sp) {
961 // No need to lock, the target list is thread safe
962 result = m_opaque_sp->GetTargetList().DeleteTarget(target_sp);
963 target_sp->Destroy();
964 target.Clear();
965 }
966 }
967
968 Log *log = GetLog(LLDBLog::API);
969 LLDB_LOGF(log, "SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i",
970 static_cast<void *>(m_opaque_sp.get()),
971 static_cast<void *>(target.m_opaque_sp.get()), result);
972
973 return result;
974}
975
977 LLDB_INSTRUMENT_VA(this, idx);
978
979 SBTarget sb_target;
980 if (m_opaque_sp) {
981 // No need to lock, the target list is thread safe
982 sb_target.SetSP(m_opaque_sp->GetTargetList().GetTargetAtIndex(idx));
983 }
984 return sb_target;
985}
986
988 LLDB_INSTRUMENT_VA(this, target);
989
990 lldb::TargetSP target_sp = target.GetSP();
991 if (!target_sp)
992 return UINT32_MAX;
993
994 if (!m_opaque_sp)
995 return UINT32_MAX;
996
997 return m_opaque_sp->GetTargetList().GetIndexOfTarget(target.GetSP());
998}
999
1001 LLDB_INSTRUMENT_VA(this, pid);
1002
1003 SBTarget sb_target;
1004 if (m_opaque_sp) {
1005 // No need to lock, the target list is thread safe
1006 sb_target.SetSP(m_opaque_sp->GetTargetList().FindTargetWithProcessID(pid));
1007 }
1008 return sb_target;
1009}
1010
1012 const char *arch_name) {
1013 LLDB_INSTRUMENT_VA(this, filename, arch_name);
1014
1015 SBTarget sb_target;
1016 if (m_opaque_sp && filename && filename[0]) {
1017 // No need to lock, the target list is thread safe
1019 m_opaque_sp->GetPlatformList().GetSelectedPlatform().get(), arch_name);
1020 TargetSP target_sp(
1021 m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture(
1022 FileSpec(filename), arch_name ? &arch : nullptr));
1023 sb_target.SetSP(target_sp);
1024 }
1025 return sb_target;
1026}
1027
1029 SBTarget sb_target;
1030 if (m_opaque_sp) {
1031 // No need to lock, the target list is thread safe
1032 sb_target.SetSP(
1033 m_opaque_sp->GetTargetList().FindTargetWithProcess(process_sp.get()));
1034 }
1035 return sb_target;
1036}
1037
1039 LLDB_INSTRUMENT_VA(this);
1040
1041 if (m_opaque_sp) {
1042 // No need to lock, the target list is thread safe
1043 return m_opaque_sp->GetTargetList().GetNumTargets();
1044 }
1045 return 0;
1046}
1047
1049 LLDB_INSTRUMENT_VA(this);
1050
1051 Log *log = GetLog(LLDBLog::API);
1052
1053 SBTarget sb_target;
1054 TargetSP target_sp;
1055 if (m_opaque_sp) {
1056 // No need to lock, the target list is thread safe
1057 target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget();
1058 sb_target.SetSP(target_sp);
1059 }
1060
1061 if (log) {
1062 SBStream sstr;
1063 sb_target.GetDescription(sstr, eDescriptionLevelBrief);
1064 LLDB_LOGF(log, "SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s",
1065 static_cast<void *>(m_opaque_sp.get()),
1066 static_cast<void *>(target_sp.get()), sstr.GetData());
1067 }
1068
1069 return sb_target;
1070}
1071
1073 LLDB_INSTRUMENT_VA(this, sb_target);
1074
1075 Log *log = GetLog(LLDBLog::API);
1076
1077 TargetSP target_sp(sb_target.GetSP());
1078 if (m_opaque_sp) {
1079 m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp);
1080 }
1081 if (log) {
1082 SBStream sstr;
1083 sb_target.GetDescription(sstr, eDescriptionLevelBrief);
1084 LLDB_LOGF(log, "SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s",
1085 static_cast<void *>(m_opaque_sp.get()),
1086 static_cast<void *>(target_sp.get()), sstr.GetData());
1087 }
1088}
1089
1091 LLDB_INSTRUMENT_VA(this);
1092
1093 Log *log = GetLog(LLDBLog::API);
1094
1095 SBPlatform sb_platform;
1096 DebuggerSP debugger_sp(m_opaque_sp);
1097 if (debugger_sp) {
1098 sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform());
1099 }
1100 LLDB_LOGF(log, "SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s",
1101 static_cast<void *>(m_opaque_sp.get()),
1102 static_cast<void *>(sb_platform.GetSP().get()),
1103 sb_platform.GetName());
1104 return sb_platform;
1105}
1106
1108 LLDB_INSTRUMENT_VA(this, sb_platform);
1109
1110 Log *log = GetLog(LLDBLog::API);
1111
1112 DebuggerSP debugger_sp(m_opaque_sp);
1113 if (debugger_sp) {
1114 debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP());
1115 }
1116
1117 LLDB_LOGF(log, "SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)",
1118 static_cast<void *>(m_opaque_sp.get()),
1119 static_cast<void *>(sb_platform.GetSP().get()),
1120 sb_platform.GetName());
1121}
1122
1124 LLDB_INSTRUMENT_VA(this);
1125
1126 if (m_opaque_sp) {
1127 // No need to lock, the platform list is thread safe
1128 return m_opaque_sp->GetPlatformList().GetSize();
1129 }
1130 return 0;
1131}
1132
1134 LLDB_INSTRUMENT_VA(this, idx);
1135
1136 SBPlatform sb_platform;
1137 if (m_opaque_sp) {
1138 // No need to lock, the platform list is thread safe
1139 sb_platform.SetSP(m_opaque_sp->GetPlatformList().GetAtIndex(idx));
1140 }
1141 return sb_platform;
1142}
1143
1145 LLDB_INSTRUMENT_VA(this);
1146
1147 uint32_t idx = 0;
1148 while (true) {
1150 break;
1151 }
1152 ++idx;
1153 }
1154 // +1 for the host platform, which should always appear first in the list.
1155 return idx + 1;
1156}
1157
1159 LLDB_INSTRUMENT_VA(this, idx);
1160
1161 SBStructuredData data;
1162 auto platform_dict = std::make_unique<StructuredData::Dictionary>();
1163 llvm::StringRef name_str("name"), desc_str("description");
1164
1165 if (idx == 0) {
1166 PlatformSP host_platform_sp(Platform::GetHostPlatform());
1167 platform_dict->AddStringItem(name_str, host_platform_sp->GetPluginName());
1168 platform_dict->AddStringItem(
1169 desc_str, llvm::StringRef(host_platform_sp->GetDescription()));
1170 } else if (idx > 0) {
1171 llvm::StringRef plugin_name =
1173 if (plugin_name.empty()) {
1174 return data;
1175 }
1176 platform_dict->AddStringItem(name_str, llvm::StringRef(plugin_name));
1177
1178 llvm::StringRef plugin_desc =
1180 platform_dict->AddStringItem(desc_str, llvm::StringRef(plugin_desc));
1181 }
1182
1183 data.m_impl_up->SetObjectSP(
1184 StructuredData::ObjectSP(platform_dict.release()));
1185 return data;
1186}
1187
1188void SBDebugger::DispatchInput(void *baton, const void *data, size_t data_len) {
1189 LLDB_INSTRUMENT_VA(this, baton, data, data_len);
1190
1191 DispatchInput(data, data_len);
1192}
1193
1194void SBDebugger::DispatchInput(const void *data, size_t data_len) {
1195 LLDB_INSTRUMENT_VA(this, data, data_len);
1196
1197 // Log *log(GetLog (LLDBLog::API));
1198 //
1199 // if (log)
1200 // LLDB_LOGF(log, "SBDebugger(%p)::DispatchInput (data=\"%.*s\",
1201 // size_t=%" PRIu64 ")",
1202 // m_opaque_sp.get(),
1203 // (int) data_len,
1204 // (const char *) data,
1205 // (uint64_t)data_len);
1206 //
1207 // if (m_opaque_sp)
1208 // m_opaque_sp->DispatchInput ((const char *) data, data_len);
1209}
1210
1212 LLDB_INSTRUMENT_VA(this);
1213
1214 if (m_opaque_sp)
1215 m_opaque_sp->DispatchInputInterrupt();
1216}
1217
1219 LLDB_INSTRUMENT_VA(this);
1220
1221 if (m_opaque_sp)
1222 m_opaque_sp->DispatchInputEndOfFile();
1223}
1224
1226 LLDB_INSTRUMENT_VA(this, reader);
1227}
1228
1229void SBDebugger::RunCommandInterpreter(bool auto_handle_events,
1230 bool spawn_thread) {
1231 LLDB_INSTRUMENT_VA(this, auto_handle_events, spawn_thread);
1232
1233 if (m_opaque_sp) {
1235 options.SetAutoHandleEvents(auto_handle_events);
1236 options.SetSpawnThread(spawn_thread);
1237 m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(options);
1238 }
1239}
1240
1241void SBDebugger::RunCommandInterpreter(bool auto_handle_events,
1242 bool spawn_thread,
1244 int &num_errors, bool &quit_requested,
1245 bool &stopped_for_crash)
1246
1247{
1248 LLDB_INSTRUMENT_VA(this, auto_handle_events, spawn_thread, options,
1249 num_errors, quit_requested, stopped_for_crash);
1250
1251 if (m_opaque_sp) {
1252 options.SetAutoHandleEvents(auto_handle_events);
1253 options.SetSpawnThread(spawn_thread);
1254 CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();
1256 interp.RunCommandInterpreter(options.ref());
1257 num_errors = result.GetNumErrors();
1258 quit_requested =
1260 stopped_for_crash =
1262 }
1263}
1264
1266 const SBCommandInterpreterRunOptions &options) {
1267 LLDB_INSTRUMENT_VA(this, options);
1268
1269 if (!m_opaque_sp)
1271
1272 CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();
1274 interp.RunCommandInterpreter(options.ref());
1275
1276 return SBCommandInterpreterRunResult(result);
1277}
1278
1280 const char *repl_options) {
1281 LLDB_INSTRUMENT_VA(this, language, repl_options);
1282
1283 SBError error;
1284 if (m_opaque_sp)
1285 error.ref() = m_opaque_sp->RunREPL(language, repl_options);
1286 else
1287 error.SetErrorString("invalid debugger");
1288 return error;
1289}
1290
1291void SBDebugger::reset(const DebuggerSP &debugger_sp) {
1292 m_opaque_sp = debugger_sp;
1293}
1294
1295Debugger *SBDebugger::get() const { return m_opaque_sp.get(); }
1296
1298 assert(m_opaque_sp.get());
1299 return *m_opaque_sp;
1300}
1301
1302const lldb::DebuggerSP &SBDebugger::get_sp() const { return m_opaque_sp; }
1303
1306
1307 // No need to lock, the debugger list is thread safe
1308 SBDebugger sb_debugger;
1309 DebuggerSP debugger_sp = Debugger::FindDebuggerWithID(id);
1310 if (debugger_sp)
1311 sb_debugger.reset(debugger_sp);
1312 return sb_debugger;
1313}
1314
1316 LLDB_INSTRUMENT_VA(this);
1317
1318 return (m_opaque_sp ? m_opaque_sp->GetInstanceName().AsCString() : nullptr);
1319}
1320
1321SBError SBDebugger::SetInternalVariable(const char *var_name, const char *value,
1322 const char *debugger_instance_name) {
1323 LLDB_INSTRUMENT_VA(var_name, value, debugger_instance_name);
1324
1325 SBError sb_error;
1326 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName(
1327 ConstString(debugger_instance_name)));
1328 Status error;
1329 if (debugger_sp) {
1330 ExecutionContext exe_ctx(
1331 debugger_sp->GetCommandInterpreter().GetExecutionContext());
1332 error = debugger_sp->SetPropertyValue(&exe_ctx, eVarSetOperationAssign,
1333 var_name, value);
1334 } else {
1335 error.SetErrorStringWithFormat("invalid debugger instance name '%s'",
1336 debugger_instance_name);
1337 }
1338 if (error.Fail())
1339 sb_error.SetError(error);
1340 return sb_error;
1341}
1342
1345 const char *debugger_instance_name) {
1346 LLDB_INSTRUMENT_VA(var_name, debugger_instance_name);
1347
1348 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName(
1349 ConstString(debugger_instance_name)));
1350 Status error;
1351 if (debugger_sp) {
1352 ExecutionContext exe_ctx(
1353 debugger_sp->GetCommandInterpreter().GetExecutionContext());
1354 lldb::OptionValueSP value_sp(
1355 debugger_sp->GetPropertyValue(&exe_ctx, var_name, false, error));
1356 if (value_sp) {
1357 StreamString value_strm;
1358 value_sp->DumpValue(&exe_ctx, value_strm, OptionValue::eDumpOptionValue);
1359 const std::string &value_str = std::string(value_strm.GetString());
1360 if (!value_str.empty()) {
1361 StringList string_list;
1362 string_list.SplitIntoLines(value_str);
1363 return SBStringList(&string_list);
1364 }
1365 }
1366 }
1367 return SBStringList();
1368}
1369
1371 LLDB_INSTRUMENT_VA(this);
1372
1373 return (m_opaque_sp ? m_opaque_sp->GetTerminalWidth() : 0);
1374}
1375
1377 LLDB_INSTRUMENT_VA(this, term_width);
1378
1379 if (m_opaque_sp)
1380 m_opaque_sp->SetTerminalWidth(term_width);
1381}
1382
1383const char *SBDebugger::GetPrompt() const {
1384 LLDB_INSTRUMENT_VA(this);
1385
1386 Log *log = GetLog(LLDBLog::API);
1387
1388 LLDB_LOGF(log, "SBDebugger(%p)::GetPrompt () => \"%s\"",
1389 static_cast<void *>(m_opaque_sp.get()),
1390 (m_opaque_sp ? m_opaque_sp->GetPrompt().str().c_str() : ""));
1391
1392 return (m_opaque_sp ? ConstString(m_opaque_sp->GetPrompt()).GetCString()
1393 : nullptr);
1394}
1395
1396void SBDebugger::SetPrompt(const char *prompt) {
1397 LLDB_INSTRUMENT_VA(this, prompt);
1398
1399 if (m_opaque_sp)
1400 m_opaque_sp->SetPrompt(llvm::StringRef(prompt));
1401}
1402
1404 LLDB_INSTRUMENT_VA(this);
1405
1406 return "GetReproducerPath has been deprecated";
1407}
1408
1410 LLDB_INSTRUMENT_VA(this);
1411
1412 return (m_opaque_sp ? m_opaque_sp->GetScriptLanguage() : eScriptLanguageNone);
1413}
1414
1416 LLDB_INSTRUMENT_VA(this, script_lang);
1417
1418 if (m_opaque_sp) {
1419 m_opaque_sp->SetScriptLanguage(script_lang);
1420 }
1421}
1422
1424 LLDB_INSTRUMENT_VA(this);
1425
1426 return (m_opaque_sp ? m_opaque_sp->GetREPLLanguage() : eLanguageTypeUnknown);
1427}
1428
1430 LLDB_INSTRUMENT_VA(this, repl_lang);
1431
1432 if (m_opaque_sp) {
1433 m_opaque_sp->SetREPLLanguage(repl_lang);
1434 }
1435}
1436
1438 LLDB_INSTRUMENT_VA(this, value);
1439
1440 return (m_opaque_sp ? m_opaque_sp->SetUseExternalEditor(value) : false);
1441}
1442
1444 LLDB_INSTRUMENT_VA(this);
1445
1446 return (m_opaque_sp ? m_opaque_sp->GetUseExternalEditor() : false);
1447}
1448
1449bool SBDebugger::SetUseColor(bool value) {
1450 LLDB_INSTRUMENT_VA(this, value);
1451
1452 return (m_opaque_sp ? m_opaque_sp->SetUseColor(value) : false);
1453}
1454
1456 LLDB_INSTRUMENT_VA(this);
1457
1458 return (m_opaque_sp ? m_opaque_sp->GetUseColor() : false);
1459}
1460
1462 LLDB_INSTRUMENT_VA(this, value);
1463
1464 return (m_opaque_sp ? m_opaque_sp->SetUseSourceCache(value) : false);
1465}
1466
1468 LLDB_INSTRUMENT_VA(this);
1469
1470 return (m_opaque_sp ? m_opaque_sp->GetUseSourceCache() : false);
1471}
1472
1474 LLDB_INSTRUMENT_VA(this, description);
1475
1476 Stream &strm = description.ref();
1477
1478 if (m_opaque_sp) {
1479 const char *name = m_opaque_sp->GetInstanceName().AsCString();
1480 user_id_t id = m_opaque_sp->GetID();
1481 strm.Printf("Debugger (instance: \"%s\", id: %" PRIu64 ")", name, id);
1482 } else
1483 strm.PutCString("No value");
1484
1485 return true;
1486}
1487
1489 LLDB_INSTRUMENT_VA(this);
1490
1491 return (m_opaque_sp ? m_opaque_sp->GetID() : LLDB_INVALID_UID);
1492}
1493
1494SBError SBDebugger::SetCurrentPlatform(const char *platform_name_cstr) {
1495 LLDB_INSTRUMENT_VA(this, platform_name_cstr);
1496
1497 SBError sb_error;
1498 if (m_opaque_sp) {
1499 if (platform_name_cstr && platform_name_cstr[0]) {
1500 PlatformList &platforms = m_opaque_sp->GetPlatformList();
1501 if (PlatformSP platform_sp = platforms.GetOrCreate(platform_name_cstr))
1502 platforms.SetSelectedPlatform(platform_sp);
1503 else
1504 sb_error.ref().SetErrorString("platform not found");
1505 } else {
1506 sb_error.ref().SetErrorString("invalid platform name");
1507 }
1508 } else {
1509 sb_error.ref().SetErrorString("invalid debugger");
1510 }
1511 return sb_error;
1512}
1513
1514bool SBDebugger::SetCurrentPlatformSDKRoot(const char *sysroot) {
1515 LLDB_INSTRUMENT_VA(this, sysroot);
1516
1517 if (SBPlatform platform = GetSelectedPlatform()) {
1518 platform.SetSDKRoot(sysroot);
1519 return true;
1520 }
1521 return false;
1522}
1523
1525 LLDB_INSTRUMENT_VA(this);
1526
1527 return (m_opaque_sp ? m_opaque_sp->GetCloseInputOnEOF() : false);
1528}
1529
1531 LLDB_INSTRUMENT_VA(this, b);
1532
1533 if (m_opaque_sp)
1534 m_opaque_sp->SetCloseInputOnEOF(b);
1535}
1536
1537SBTypeCategory SBDebugger::GetCategory(const char *category_name) {
1538 LLDB_INSTRUMENT_VA(this, category_name);
1539
1540 if (!category_name || *category_name == 0)
1541 return SBTypeCategory();
1542
1543 TypeCategoryImplSP category_sp;
1544
1546 category_sp, false)) {
1547 return SBTypeCategory(category_sp);
1548 } else {
1549 return SBTypeCategory();
1550 }
1551}
1552
1554 LLDB_INSTRUMENT_VA(this, lang_type);
1555
1556 TypeCategoryImplSP category_sp;
1557 if (DataVisualization::Categories::GetCategory(lang_type, category_sp)) {
1558 return SBTypeCategory(category_sp);
1559 } else {
1560 return SBTypeCategory();
1561 }
1562}
1563
1564SBTypeCategory SBDebugger::CreateCategory(const char *category_name) {
1565 LLDB_INSTRUMENT_VA(this, category_name);
1566
1567 if (!category_name || *category_name == 0)
1568 return SBTypeCategory();
1569
1570 TypeCategoryImplSP category_sp;
1571
1573 category_sp, true)) {
1574 return SBTypeCategory(category_sp);
1575 } else {
1576 return SBTypeCategory();
1577 }
1578}
1579
1580bool SBDebugger::DeleteCategory(const char *category_name) {
1581 LLDB_INSTRUMENT_VA(this, category_name);
1582
1583 if (!category_name || *category_name == 0)
1584 return false;
1585
1587}
1588
1590 LLDB_INSTRUMENT_VA(this);
1591
1593}
1594
1596 LLDB_INSTRUMENT_VA(this, index);
1597
1598 return SBTypeCategory(
1600}
1601
1603 LLDB_INSTRUMENT_VA(this);
1604
1605 return GetCategory("default");
1606}
1607
1609 LLDB_INSTRUMENT_VA(this, type_name);
1610
1611 SBTypeCategory default_category_sb = GetDefaultCategory();
1612 if (default_category_sb.GetEnabled())
1613 return default_category_sb.GetFormatForType(type_name);
1614 return SBTypeFormat();
1615}
1616
1618 LLDB_INSTRUMENT_VA(this, type_name);
1619
1620 if (!type_name.IsValid())
1621 return SBTypeSummary();
1623}
1624
1626 LLDB_INSTRUMENT_VA(this, type_name);
1627
1628 if (!type_name.IsValid())
1629 return SBTypeFilter();
1631}
1632
1634 LLDB_INSTRUMENT_VA(this, type_name);
1635
1636 if (!type_name.IsValid())
1637 return SBTypeSynthetic();
1638 return SBTypeSynthetic(
1640}
1641
1642static llvm::ArrayRef<const char *> GetCategoryArray(const char **categories) {
1643 if (categories == nullptr)
1644 return {};
1645 size_t len = 0;
1646 while (categories[len] != nullptr)
1647 ++len;
1648 return llvm::ArrayRef(categories, len);
1649}
1650
1651bool SBDebugger::EnableLog(const char *channel, const char **categories) {
1652 LLDB_INSTRUMENT_VA(this, channel, categories);
1653
1654 if (m_opaque_sp) {
1655 uint32_t log_options =
1657 std::string error;
1658 llvm::raw_string_ostream error_stream(error);
1659 return m_opaque_sp->EnableLog(channel, GetCategoryArray(categories), "",
1660 log_options, /*buffer_size=*/0,
1661 eLogHandlerStream, error_stream);
1662 } else
1663 return false;
1664}
1665
1667 void *baton) {
1668 LLDB_INSTRUMENT_VA(this, log_callback, baton);
1669
1670 if (m_opaque_sp) {
1671 return m_opaque_sp->SetLoggingCallback(log_callback, baton);
1672 }
1673}
1674
1675SBTrace
1677 const SBFileSpec &trace_description_file) {
1678 LLDB_INSTRUMENT_VA(this, error, trace_description_file);
1679 return SBTrace::LoadTraceFromFile(error, *this, trace_description_file);
1680}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
#define LLDB_LOGF(log,...)
Definition: Log.h:344
#define LLDB_LOG_OPTION_PREPEND_TIMESTAMP
Definition: Log.h:38
#define LLDB_LOG_OPTION_PREPEND_THREAD_NAME
Definition: Log.h:40
static llvm::sys::DynamicLibrary LoadPlugin(const lldb::DebuggerSP &debugger_sp, const FileSpec &spec, Status &error)
Definition: SBDebugger.cpp:68
static llvm::ArrayRef< const char * > GetCategoryArray(const char **categories)
static void DumpDiagnostics(void *cookie)
Definition: SBDebugger.cpp:222
static void AddBoolConfigEntry(StructuredData::Dictionary &dict, llvm::StringRef name, bool value, llvm::StringRef description)
Definition: SBDebugger.cpp:740
static void AddLLVMTargets(StructuredData::Dictionary &dict)
Definition: SBDebugger.cpp:749
static llvm::ManagedStatic< SystemLifetimeManager > g_debugger_lifetime
Definition: SBDebugger.cpp:104
lldb_private::CommandInterpreterRunOptions & ref() const
void reset(lldb_private::CommandInterpreter *)
void SourceInitFileInHomeDirectory(lldb::SBCommandReturnObject &result)
lldb_private::CommandInterpreter * get()
void SourceInitFileInGlobalDirectory(lldb::SBCommandReturnObject &result)
lldb::ReturnStatus HandleCommand(const char *command_line, lldb::SBCommandReturnObject &result, bool add_to_history=false)
static lldb::SBError SetInternalVariable(const char *var_name, const char *value, const char *debugger_instance_name)
bool DeleteCategory(const char *category_name)
lldb::LanguageType GetREPLLanguage() const
lldb::SBTarget GetTargetAtIndex(uint32_t idx)
Definition: SBDebugger.cpp:976
lldb::SBTarget FindTargetWithProcessID(pid_t pid)
lldb::SBTarget CreateTarget(const char *filename, const char *target_triple, const char *platform_name, bool add_dependent_modules, lldb::SBError &error)
Definition: SBDebugger.cpp:808
SBError RunREPL(lldb::LanguageType language, const char *repl_options)
bool DeleteTarget(lldb::SBTarget &target)
Definition: SBDebugger.cpp:954
void SkipAppInitFiles(bool b)
Definition: SBDebugger.cpp:343
lldb::SBDebugger & operator=(const lldb::SBDebugger &rhs)
Definition: SBDebugger.cpp:139
static void Terminate()
Definition: SBDebugger.cpp:232
lldb::SBPlatform GetPlatformAtIndex(uint32_t idx)
Get one of the currently active platforms.
void SkipLLDBInitFiles(bool b)
Definition: SBDebugger.cpp:336
void SetAsync(bool b)
Definition: SBDebugger.cpp:323
SBTypeSummary GetSummaryForType(SBTypeNameSpecifier)
SBTypeCategory GetCategoryAtIndex(uint32_t)
bool SetUseExternalEditor(bool input)
bool GetCloseInputOnEOF() const
static bool GetDefaultArchitecture(char *arch_name, size_t arch_name_len)
Definition: SBDebugger.cpp:670
static void MemoryPressureDetected()
Definition: SBDebugger.cpp:300
void SetPrompt(const char *prompt)
bool GetDescription(lldb::SBStream &description)
bool GetUseExternalEditor()
static void PrintStackTraceOnError()
Definition: SBDebugger.cpp:213
static lldb::SBDebugger Create()
Definition: SBDebugger.cpp:247
void SetInputFileHandle(FILE *f, bool transfer_ownership)
Definition: SBDebugger.cpp:350
void RunCommandInterpreter(bool auto_handle_events, bool spawn_thread)
Run the command interpreter.
static const char * GetVersionString()
Definition: SBDebugger.cpp:728
lldb_private::Debugger & ref() const
lldb::SBStructuredData GetSetting(const char *setting=nullptr)
Getting a specific setting value into SBStructuredData format.
Definition: SBDebugger.cpp:454
const char * GetReproducerPath() const
void SetOutputFileHandle(FILE *f, bool transfer_ownership)
Definition: SBDebugger.cpp:409
static lldb::SBError InitializeWithErrorHandling()
Definition: SBDebugger.cpp:202
void SetTerminalWidth(uint32_t term_width)
void HandleCommand(const char *command)
Definition: SBDebugger.cpp:555
lldb::SBCommandInterpreter GetCommandInterpreter()
Definition: SBDebugger.cpp:545
void HandleProcessEvent(const lldb::SBProcess &process, const lldb::SBEvent &event, FILE *out, FILE *err)
Definition: SBDebugger.cpp:606
SBFile GetInputFile()
Definition: SBDebugger.cpp:486
const char * GetPrompt() const
bool SetUseColor(bool use_color)
const lldb::DebuggerSP & get_sp() const
static bool StateIsRunningState(lldb::StateType state)
Definition: SBDebugger.cpp:792
SBError SetErrorFile(SBFile file)
Definition: SBDebugger.cpp:439
bool SetUseSourceCache(bool use_source_cache)
uint32_t GetNumCategories()
static lldb::SBStringList GetInternalVariableValue(const char *var_name, const char *debugger_instance_name)
bool GetUseColor() const
lldb::SBListener GetListener()
Definition: SBDebugger.cpp:588
void SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton)
lldb::DebuggerSP m_opaque_sp
Definition: SBDebugger.h:441
lldb::ScriptLanguage GetScriptLanguage() const
void SetScriptLanguage(lldb::ScriptLanguage script_lang)
uint32_t GetNumAvailablePlatforms()
Get the number of available platforms.
lldb::SBTarget FindTargetWithLLDBProcess(const lldb::ProcessSP &processSP)
SBStructuredData GetScriptInterpreterInfo(ScriptLanguage)
Definition: SBDebugger.cpp:715
lldb::SBPlatform GetSelectedPlatform()
static const char * GetBroadcasterClass()
Definition: SBDebugger.cpp:148
lldb::SBTarget CreateTargetWithFileAndArch(const char *filename, const char *archname)
Definition: SBDebugger.cpp:872
bool IsValid() const
Definition: SBDebugger.cpp:313
static void Initialize()
Definition: SBDebugger.cpp:197
static bool StateIsStoppedState(lldb::StateType state)
Definition: SBDebugger.cpp:800
lldb::SBError SetCurrentPlatform(const char *platform_name)
lldb::SBSourceManager GetSourceManager()
Definition: SBDebugger.cpp:663
SBTypeCategory GetCategory(const char *category_name)
void SetREPLLanguage(lldb::LanguageType repl_lang)
static SBDebugger FindDebuggerWithID(int id)
uint32_t GetNumPlatforms()
Get the number of currently active platforms.
void DispatchInputEndOfFile()
uint32_t GetTerminalWidth() const
SBTypeFilter GetFilterForType(SBTypeNameSpecifier)
lldb::SBTarget FindTargetWithFileAndArch(const char *filename, const char *arch)
static const char * StateAsCString(lldb::StateType state)
Definition: SBDebugger.cpp:734
void PushInputReader(lldb::SBInputReader &reader)
static const char * GetProgressFromEvent(const lldb::SBEvent &event, uint64_t &progress_id, uint64_t &completed, uint64_t &total, bool &is_debugger_specific)
Get progress data from a SBEvent whose type is eBroadcastBitProgress.
Definition: SBDebugger.cpp:154
lldb::SBTarget GetDummyTarget()
Definition: SBDebugger.cpp:940
bool EnableLog(const char *channel, const char **categories)
static bool SetDefaultArchitecture(const char *arch_name)
Definition: SBDebugger.cpp:691
lldb_private::Debugger * get() const
void RestoreInputTerminalState()
Definition: SBDebugger.cpp:539
SBFile GetOutputFile()
Definition: SBDebugger.cpp:503
lldb::SBBroadcaster GetBroadcaster()
Definition: SBDebugger.cpp:191
void DispatchInput(void *baton, const void *data, size_t data_len)
void SetSelectedTarget(SBTarget &target)
SBTypeCategory GetDefaultCategory()
bool GetUseSourceCache() const
SBFile GetErrorFile()
Definition: SBDebugger.cpp:522
lldb::SBStructuredData GetAvailablePlatformInfoAtIndex(uint32_t idx)
Get the name and description of one of the available platforms.
static SBStructuredData GetBuildConfiguration()
Definition: SBDebugger.cpp:760
SBTypeCategory CreateCategory(const char *category_name)
bool SetCurrentPlatformSDKRoot(const char *sysroot)
void SetErrorFileHandle(FILE *f, bool transfer_ownership)
Definition: SBDebugger.cpp:429
SBTrace LoadTraceFromFile(SBError &error, const SBFileSpec &trace_description_file)
Load a trace from a trace description file and create Targets, Processes and Threads based on the con...
uint32_t GetNumTargets()
FILE * GetInputFileHandle()
Definition: SBDebugger.cpp:477
SBError SetInputFile(SBFile file)
Definition: SBDebugger.cpp:383
void DispatchInputInterrupt()
SBError SetInputString(const char *data)
Definition: SBDebugger.cpp:357
uint32_t GetIndexOfTarget(lldb::SBTarget target)
Definition: SBDebugger.cpp:987
SBError SetOutputFile(SBFile file)
Definition: SBDebugger.cpp:414
SBTypeSynthetic GetSyntheticForType(SBTypeNameSpecifier)
lldb::SBTarget GetSelectedTarget()
void SaveInputTerminalState()
Definition: SBDebugger.cpp:532
FILE * GetErrorFileHandle()
Definition: SBDebugger.cpp:512
void SetSelectedPlatform(lldb::SBPlatform &platform)
void reset(const lldb::DebuggerSP &debugger_sp)
FILE * GetOutputFileHandle()
Definition: SBDebugger.cpp:494
const char * GetInstanceName()
static void PrintDiagnosticsOnError()
Definition: SBDebugger.cpp:226
void SetCloseInputOnEOF(bool b)
lldb::user_id_t GetID()
lldb::SBTarget CreateTargetWithFileAndTargetTriple(const char *filename, const char *target_triple)
Definition: SBDebugger.cpp:847
static lldb::SBStructuredData GetDiagnosticFromEvent(const lldb::SBEvent &event)
Definition: SBDebugger.cpp:172
lldb::ScriptLanguage GetScriptingLanguage(const char *script_language_name)
Definition: SBDebugger.cpp:705
static void Destroy(lldb::SBDebugger &debugger)
Definition: SBDebugger.cpp:291
SBTypeFormat GetFormatForType(SBTypeNameSpecifier)
bool Success() const
Definition: SBError.cpp:69
void SetErrorString(const char *err_str)
Definition: SBError.cpp:126
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:100
lldb_private::Status & ref()
Definition: SBError.cpp:161
const char * GetCString() const
Get the error string as a NULL terminated UTF8 c-string.
Definition: SBError.cpp:43
void Clear()
Definition: SBError.cpp:51
lldb_private::Event * get() const
Definition: SBEvent.cpp:133
FileSP m_opaque_sp
Definition: SBFile.h:45
SBError Initialize(lldb::SBDebugger &sb_debugger, unsigned long(*callback)(void *, lldb::SBInputReader *, lldb::InputReaderAction, char const *, unsigned long), void *a, lldb::InputReaderGranularity b, char const *c, char const *d, bool e)
Definition: SBDebugger.cpp:106
bool IsActive() const
Definition: SBDebugger.cpp:120
void SetIsDone(bool)
Definition: SBDebugger.cpp:118
void reset(lldb::ListenerSP listener_sp)
Definition: SBListener.cpp:292
const char * GetName()
Definition: SBPlatform.cpp:337
lldb::PlatformSP GetSP() const
Definition: SBPlatform.cpp:346
void SetSP(const lldb::PlatformSP &platform_sp)
Definition: SBPlatform.cpp:348
void ReportEventState(const lldb::SBEvent &event, FILE *out) const
Definition: SBProcess.cpp:305
lldb::ProcessSP GetSP() const
Definition: SBProcess.cpp:102
static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event)
Definition: SBProcess.cpp:713
lldb::SBTarget GetTarget() const
Definition: SBProcess.cpp:233
size_t GetSTDOUT(char *dst, size_t dst_len) const
Definition: SBProcess.cpp:260
bool IsValid() const
Definition: SBProcess.cpp:112
size_t GetSTDERR(char *dst, size_t dst_len) const
Definition: SBProcess.cpp:273
lldb_private::Stream & ref()
Definition: SBStream.cpp:176
const char * GetData()
Definition: SBStream.cpp:44
StructuredDataImplUP m_impl_up
bool GetDescription(lldb::SBStream &description, lldb::DescriptionLevel description_level)
Definition: SBTarget.cpp:1675
void SetSP(const lldb::TargetSP &target_sp)
Definition: SBTarget.cpp:578
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:576
lldb::TargetSP m_opaque_sp
Definition: SBTarget.h:891
static SBTrace LoadTraceFromFile(SBError &error, SBDebugger &debugger, const SBFileSpec &trace_description_file)
See SBDebugger::LoadTraceFromFile.
Definition: SBTrace.cpp:31
SBTypeFormat GetFormatForType(SBTypeNameSpecifier)
lldb::TypeNameSpecifierImplSP GetSP()
An architecture specification class.
Definition: ArchSpec.h:32
bool IsValid() const
Tests if this ArchSpec is valid.
Definition: ArchSpec.h:361
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:463
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition: ArchSpec.cpp:547
void SetAutoHandleEvents(bool auto_handle_events)
bool IsResult(lldb::CommandInterpreterResult result)
void SkipAppInitFiles(bool skip_app_init_files)
void SkipLLDBInitFiles(bool skip_lldbinit_files)
CommandInterpreterRunResult RunCommandInterpreter(CommandInterpreterRunOptions &options)
A uniqued constant string class.
Definition: ConstString.h:39
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:192
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:215
static bool Delete(ConstString category)
static lldb::TypeCategoryImplSP GetCategoryAtIndex(size_t)
static bool GetCategory(ConstString category, lldb::TypeCategoryImplSP &entry, bool allow_create=true)
static lldb::ScriptedSyntheticChildrenSP GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp)
static lldb::TypeFilterImplSP GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp)
static lldb::TypeSummaryImplSP GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp)
A class to manage flag bits.
Definition: Debugger.h:77
static lldb::DebuggerSP CreateInstance(lldb::LogOutputCallback log_callback=nullptr, void *baton=nullptr)
Definition: Debugger.cpp:671
static lldb::DebuggerSP FindDebuggerWithID(lldb::user_id_t id)
Definition: Debugger.cpp:1221
static ConstString GetStaticBroadcasterClass()
Definition: Debugger.cpp:754
static lldb::DebuggerSP FindDebuggerWithInstanceName(ConstString instance_name)
Definition: Debugger.cpp:711
static void Destroy(lldb::DebuggerSP &debugger_sp)
Definition: Debugger.cpp:682
const std::string & GetMessage() const
llvm::StringRef GetPrefix() const
static const DiagnosticEventData * GetEventDataFromEvent(const Event *event_ptr)
bool Dump(llvm::raw_ostream &stream)
Gather diagnostics and print a message to the given output stream.
Definition: Diagnostics.cpp:51
static Diagnostics & Instance()
Definition: Diagnostics.cpp:40
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file utility class.
Definition: FileSpec.h:56
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:366
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
An abstract base class for files.
Definition: File.h:36
virtual FILE * GetStream()
Get the underlying libc stream for this file, or NULL.
Definition: File.cpp:127
static size_t RemoveOrphanSharedModules(bool mandatory)
Definition: ModuleList.cpp:781
void SetPlatformName(const char *platform_name)
void SetSelectedPlatform(const lldb::PlatformSP &platform_sp)
Definition: Platform.h:1017
lldb::PlatformSP GetOrCreate(llvm::StringRef name)
Definition: Platform.cpp:1970
static ArchSpec GetAugmentedArchSpec(Platform *platform, llvm::StringRef triple)
Augments the triple either with information from platform or the host system (if platform is null).
Definition: Platform.cpp:265
static lldb::PlatformSP GetHostPlatform()
Get the native host platform plug-in.
Definition: Platform.cpp:137
static llvm::StringRef GetPlatformPluginDescriptionAtIndex(uint32_t idx)
static llvm::StringRef GetPlatformPluginNameAtIndex(uint32_t idx)
static const ProgressEventData * GetEventDataFromEvent(const Event *event_ptr)
const std::string & GetMessage() const
virtual StructuredData::DictionarySP GetInterpreterInfo()
An error handling class.
Definition: Status.h:44
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
size_t SplitIntoLines(const std::string &lines)
Definition: StringList.cpp:152
void AddItem(llvm::StringRef key, ObjectSP value_sp)
std::shared_ptr< Object > ObjectSP
static ObjectSP ParseJSON(const std::string &json_text)
static ArchSpec GetDefaultArchitecture()
Definition: Target.cpp:2519
static void SetDefaultArchitecture(const ArchSpec &arch)
Definition: Target.cpp:2523
static bool XMLEnabled()
Definition: XML.cpp:81
#define LLDB_INVALID_UID
Definition: lldb-defines.h:80
#define UINT32_MAX
Definition: lldb-defines.h:19
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:309
const char * GetVersion()
Retrieves a string representing the complete LLDB version, which includes the lldb version number,...
Definition: Version.cpp:38
bool StateIsStoppedState(lldb::StateType state, bool must_exist)
Check if a state represents a state where the process or thread is stopped.
Definition: State.cpp:89
bool StateIsRunningState(lldb::StateType state)
Check if a state represents a state where the process or thread is running.
Definition: State.cpp:68
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition: State.cpp:14
Definition: SBAddress.h:15
ScriptLanguage
Script interpreter types.
@ eScriptLanguageDefault
@ eScriptLanguageNone
@ eDescriptionLevelBrief
@ eCommandInterpreterResultInferiorCrash
Stopped because the corresponding option was set and the inferior crashed.
@ eCommandInterpreterResultQuitRequested
Stopped because quit was requested.
StateType
Process and Thread States.
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
uint64_t pid_t
Definition: lldb-types.h:85
uint64_t user_id_t
Definition: lldb-types.h:84
void(* LogOutputCallback)(const char *, void *baton)
Definition: lldb-types.h:70
InputReaderGranularity
Token size/granularities for Input Readers.
static lldb::ScriptLanguage ToScriptLanguage(llvm::StringRef s, lldb::ScriptLanguage fail_value, bool *success_ptr)