Path: blob/main/contrib/llvm-project/lldb/source/API/SBDebugger.cpp
39587 views
//===-- SBDebugger.cpp ----------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/API/SBDebugger.h"9#include "SystemInitializerFull.h"10#include "lldb/Utility/Instrumentation.h"11#include "lldb/Utility/LLDBLog.h"1213#include "lldb/API/SBBroadcaster.h"14#include "lldb/API/SBCommandInterpreter.h"15#include "lldb/API/SBCommandInterpreterRunOptions.h"16#include "lldb/API/SBCommandReturnObject.h"17#include "lldb/API/SBError.h"18#include "lldb/API/SBEvent.h"19#include "lldb/API/SBFile.h"20#include "lldb/API/SBFrame.h"21#include "lldb/API/SBListener.h"22#include "lldb/API/SBProcess.h"23#include "lldb/API/SBSourceManager.h"24#include "lldb/API/SBStream.h"25#include "lldb/API/SBStringList.h"26#include "lldb/API/SBStructuredData.h"27#include "lldb/API/SBTarget.h"28#include "lldb/API/SBThread.h"29#include "lldb/API/SBTrace.h"30#include "lldb/API/SBTypeCategory.h"31#include "lldb/API/SBTypeFilter.h"32#include "lldb/API/SBTypeFormat.h"33#include "lldb/API/SBTypeNameSpecifier.h"34#include "lldb/API/SBTypeSummary.h"35#include "lldb/API/SBTypeSynthetic.h"3637#include "lldb/Core/Debugger.h"38#include "lldb/Core/DebuggerEvents.h"39#include "lldb/Core/PluginManager.h"40#include "lldb/Core/Progress.h"41#include "lldb/Core/StructuredDataImpl.h"42#include "lldb/DataFormatters/DataVisualization.h"43#include "lldb/Host/Config.h"44#include "lldb/Host/StreamFile.h"45#include "lldb/Host/XML.h"46#include "lldb/Initialization/SystemLifetimeManager.h"47#include "lldb/Interpreter/CommandInterpreter.h"48#include "lldb/Interpreter/OptionArgParser.h"49#include "lldb/Interpreter/OptionGroupPlatform.h"50#include "lldb/Target/Process.h"51#include "lldb/Target/TargetList.h"52#include "lldb/Utility/Args.h"53#include "lldb/Utility/Diagnostics.h"54#include "lldb/Utility/State.h"55#include "lldb/Version/Version.h"5657#include "llvm/ADT/STLExtras.h"58#include "llvm/ADT/StringRef.h"59#include "llvm/Support/DynamicLibrary.h"60#include "llvm/Support/ManagedStatic.h"61#include "llvm/Support/PrettyStackTrace.h"62#include "llvm/Support/Signals.h"6364using namespace lldb;65using namespace lldb_private;6667static llvm::ManagedStatic<SystemLifetimeManager> g_debugger_lifetime;6869SBError SBInputReader::Initialize(70lldb::SBDebugger &sb_debugger,71unsigned long (*callback)(void *, lldb::SBInputReader *,72lldb::InputReaderAction, char const *,73unsigned long),74void *a, lldb::InputReaderGranularity b, char const *c, char const *d,75bool e) {76LLDB_INSTRUMENT_VA(this, sb_debugger, callback, a, b, c, d, e);7778return SBError();79}8081void SBInputReader::SetIsDone(bool b) { LLDB_INSTRUMENT_VA(this, b); }8283bool SBInputReader::IsActive() const {84LLDB_INSTRUMENT_VA(this);8586return false;87}8889SBDebugger::SBDebugger() { LLDB_INSTRUMENT_VA(this); }9091SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp)92: m_opaque_sp(debugger_sp) {93LLDB_INSTRUMENT_VA(this, debugger_sp);94}9596SBDebugger::SBDebugger(const SBDebugger &rhs) : m_opaque_sp(rhs.m_opaque_sp) {97LLDB_INSTRUMENT_VA(this, rhs);98}99100SBDebugger::~SBDebugger() = default;101102SBDebugger &SBDebugger::operator=(const SBDebugger &rhs) {103LLDB_INSTRUMENT_VA(this, rhs);104105if (this != &rhs) {106m_opaque_sp = rhs.m_opaque_sp;107}108return *this;109}110111const char *SBDebugger::GetBroadcasterClass() {112LLDB_INSTRUMENT();113114return ConstString(Debugger::GetStaticBroadcasterClass()).AsCString();115}116117const char *SBDebugger::GetProgressFromEvent(const lldb::SBEvent &event,118uint64_t &progress_id,119uint64_t &completed,120uint64_t &total,121bool &is_debugger_specific) {122LLDB_INSTRUMENT_VA(event);123124const ProgressEventData *progress_data =125ProgressEventData::GetEventDataFromEvent(event.get());126if (progress_data == nullptr)127return nullptr;128progress_id = progress_data->GetID();129completed = progress_data->GetCompleted();130total = progress_data->GetTotal();131is_debugger_specific = progress_data->IsDebuggerSpecific();132ConstString message(progress_data->GetMessage());133return message.AsCString();134}135136lldb::SBStructuredData137SBDebugger::GetProgressDataFromEvent(const lldb::SBEvent &event) {138LLDB_INSTRUMENT_VA(event);139140StructuredData::DictionarySP dictionary_sp =141ProgressEventData::GetAsStructuredData(event.get());142143if (!dictionary_sp)144return {};145146SBStructuredData data;147data.m_impl_up->SetObjectSP(std::move(dictionary_sp));148return data;149}150151lldb::SBStructuredData152SBDebugger::GetDiagnosticFromEvent(const lldb::SBEvent &event) {153LLDB_INSTRUMENT_VA(event);154155StructuredData::DictionarySP dictionary_sp =156DiagnosticEventData::GetAsStructuredData(event.get());157158if (!dictionary_sp)159return {};160161SBStructuredData data;162data.m_impl_up->SetObjectSP(std::move(dictionary_sp));163return data;164}165166SBBroadcaster SBDebugger::GetBroadcaster() {167LLDB_INSTRUMENT_VA(this);168SBBroadcaster broadcaster(&m_opaque_sp->GetBroadcaster(), false);169return broadcaster;170}171172void SBDebugger::Initialize() {173LLDB_INSTRUMENT();174SBError ignored = SBDebugger::InitializeWithErrorHandling();175}176177lldb::SBError SBDebugger::InitializeWithErrorHandling() {178LLDB_INSTRUMENT();179180auto LoadPlugin = [](const lldb::DebuggerSP &debugger_sp,181const FileSpec &spec,182Status &error) -> llvm::sys::DynamicLibrary {183llvm::sys::DynamicLibrary dynlib =184llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());185if (dynlib.isValid()) {186typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger & debugger);187188lldb::SBDebugger debugger_sb(debugger_sp);189// This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger)190// function.191// TODO: mangle this differently for your system - on OSX, the first192// underscore needs to be removed and the second one stays193LLDBCommandPluginInit init_func =194(LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol(195"_ZN4lldb16PluginInitializeENS_10SBDebuggerE");196if (init_func) {197if (init_func(debugger_sb))198return dynlib;199else200error.SetErrorString("plug-in refused to load "201"(lldb::PluginInitialize(lldb::SBDebugger) "202"returned false)");203} else {204error.SetErrorString("plug-in is missing the required initialization: "205"lldb::PluginInitialize(lldb::SBDebugger)");206}207} else {208if (FileSystem::Instance().Exists(spec))209error.SetErrorString("this file does not represent a loadable dylib");210else211error.SetErrorString("no such file");212}213return llvm::sys::DynamicLibrary();214};215216SBError error;217if (auto e = g_debugger_lifetime->Initialize(218std::make_unique<SystemInitializerFull>(), LoadPlugin)) {219error.SetError(Status(std::move(e)));220}221return error;222}223224void SBDebugger::PrintStackTraceOnError() {225LLDB_INSTRUMENT();226227llvm::EnablePrettyStackTrace();228static std::string executable =229llvm::sys::fs::getMainExecutable(nullptr, nullptr);230llvm::sys::PrintStackTraceOnErrorSignal(executable);231}232233static void DumpDiagnostics(void *cookie) {234Diagnostics::Instance().Dump(llvm::errs());235}236237void SBDebugger::PrintDiagnosticsOnError() {238LLDB_INSTRUMENT();239240llvm::sys::AddSignalHandler(&DumpDiagnostics, nullptr);241}242243void SBDebugger::Terminate() {244LLDB_INSTRUMENT();245246g_debugger_lifetime->Terminate();247}248249void SBDebugger::Clear() {250LLDB_INSTRUMENT_VA(this);251252if (m_opaque_sp)253m_opaque_sp->ClearIOHandlers();254255m_opaque_sp.reset();256}257258SBDebugger SBDebugger::Create() {259LLDB_INSTRUMENT();260261return SBDebugger::Create(false, nullptr, nullptr);262}263264SBDebugger SBDebugger::Create(bool source_init_files) {265LLDB_INSTRUMENT_VA(source_init_files);266267return SBDebugger::Create(source_init_files, nullptr, nullptr);268}269270SBDebugger SBDebugger::Create(bool source_init_files,271lldb::LogOutputCallback callback, void *baton)272273{274LLDB_INSTRUMENT_VA(source_init_files, callback, baton);275276SBDebugger debugger;277278// Currently we have issues if this function is called simultaneously on two279// different threads. The issues mainly revolve around the fact that the280// lldb_private::FormatManager uses global collections and having two threads281// parsing the .lldbinit files can cause mayhem. So to get around this for282// now we need to use a mutex to prevent bad things from happening.283static std::recursive_mutex g_mutex;284std::lock_guard<std::recursive_mutex> guard(g_mutex);285286debugger.reset(Debugger::CreateInstance(callback, baton));287288SBCommandInterpreter interp = debugger.GetCommandInterpreter();289if (source_init_files) {290interp.get()->SkipLLDBInitFiles(false);291interp.get()->SkipAppInitFiles(false);292SBCommandReturnObject result;293interp.SourceInitFileInGlobalDirectory(result);294interp.SourceInitFileInHomeDirectory(result, false);295} else {296interp.get()->SkipLLDBInitFiles(true);297interp.get()->SkipAppInitFiles(true);298}299return debugger;300}301302void SBDebugger::Destroy(SBDebugger &debugger) {303LLDB_INSTRUMENT_VA(debugger);304305Debugger::Destroy(debugger.m_opaque_sp);306307if (debugger.m_opaque_sp.get() != nullptr)308debugger.m_opaque_sp.reset();309}310311void SBDebugger::MemoryPressureDetected() {312LLDB_INSTRUMENT();313314// Since this function can be call asynchronously, we allow it to be non-315// mandatory. We have seen deadlocks with this function when called so we316// need to safeguard against this until we can determine what is causing the317// deadlocks.318319const bool mandatory = false;320321ModuleList::RemoveOrphanSharedModules(mandatory);322}323324bool SBDebugger::IsValid() const {325LLDB_INSTRUMENT_VA(this);326return this->operator bool();327}328SBDebugger::operator bool() const {329LLDB_INSTRUMENT_VA(this);330331return m_opaque_sp.get() != nullptr;332}333334void SBDebugger::SetAsync(bool b) {335LLDB_INSTRUMENT_VA(this, b);336337if (m_opaque_sp)338m_opaque_sp->SetAsyncExecution(b);339}340341bool SBDebugger::GetAsync() {342LLDB_INSTRUMENT_VA(this);343344return (m_opaque_sp ? m_opaque_sp->GetAsyncExecution() : false);345}346347void SBDebugger::SkipLLDBInitFiles(bool b) {348LLDB_INSTRUMENT_VA(this, b);349350if (m_opaque_sp)351m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles(b);352}353354void SBDebugger::SkipAppInitFiles(bool b) {355LLDB_INSTRUMENT_VA(this, b);356357if (m_opaque_sp)358m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles(b);359}360361void SBDebugger::SetInputFileHandle(FILE *fh, bool transfer_ownership) {362LLDB_INSTRUMENT_VA(this, fh, transfer_ownership);363if (m_opaque_sp)364m_opaque_sp->SetInputFile(365(FileSP)std::make_shared<NativeFile>(fh, transfer_ownership));366}367368SBError SBDebugger::SetInputString(const char *data) {369LLDB_INSTRUMENT_VA(this, data);370SBError sb_error;371if (data == nullptr) {372sb_error.SetErrorString("String data is null");373return sb_error;374}375376size_t size = strlen(data);377if (size == 0) {378sb_error.SetErrorString("String data is empty");379return sb_error;380}381382if (!m_opaque_sp) {383sb_error.SetErrorString("invalid debugger");384return sb_error;385}386387sb_error.SetError(m_opaque_sp->SetInputString(data));388return sb_error;389}390391// Shouldn't really be settable after initialization as this could cause lots392// of problems; don't want users trying to switch modes in the middle of a393// debugging session.394SBError SBDebugger::SetInputFile(SBFile file) {395LLDB_INSTRUMENT_VA(this, file);396397SBError error;398if (!m_opaque_sp) {399error.ref().SetErrorString("invalid debugger");400return error;401}402if (!file) {403error.ref().SetErrorString("invalid file");404return error;405}406m_opaque_sp->SetInputFile(file.m_opaque_sp);407return error;408}409410SBError SBDebugger::SetInputFile(FileSP file_sp) {411LLDB_INSTRUMENT_VA(this, file_sp);412return SetInputFile(SBFile(file_sp));413}414415SBError SBDebugger::SetOutputFile(FileSP file_sp) {416LLDB_INSTRUMENT_VA(this, file_sp);417return SetOutputFile(SBFile(file_sp));418}419420void SBDebugger::SetOutputFileHandle(FILE *fh, bool transfer_ownership) {421LLDB_INSTRUMENT_VA(this, fh, transfer_ownership);422SetOutputFile((FileSP)std::make_shared<NativeFile>(fh, transfer_ownership));423}424425SBError SBDebugger::SetOutputFile(SBFile file) {426LLDB_INSTRUMENT_VA(this, file);427SBError error;428if (!m_opaque_sp) {429error.ref().SetErrorString("invalid debugger");430return error;431}432if (!file) {433error.ref().SetErrorString("invalid file");434return error;435}436m_opaque_sp->SetOutputFile(file.m_opaque_sp);437return error;438}439440void SBDebugger::SetErrorFileHandle(FILE *fh, bool transfer_ownership) {441LLDB_INSTRUMENT_VA(this, fh, transfer_ownership);442SetErrorFile((FileSP)std::make_shared<NativeFile>(fh, transfer_ownership));443}444445SBError SBDebugger::SetErrorFile(FileSP file_sp) {446LLDB_INSTRUMENT_VA(this, file_sp);447return SetErrorFile(SBFile(file_sp));448}449450SBError SBDebugger::SetErrorFile(SBFile file) {451LLDB_INSTRUMENT_VA(this, file);452SBError error;453if (!m_opaque_sp) {454error.ref().SetErrorString("invalid debugger");455return error;456}457if (!file) {458error.ref().SetErrorString("invalid file");459return error;460}461m_opaque_sp->SetErrorFile(file.m_opaque_sp);462return error;463}464465lldb::SBStructuredData SBDebugger::GetSetting(const char *setting) {466LLDB_INSTRUMENT_VA(this, setting);467468SBStructuredData data;469if (!m_opaque_sp)470return data;471472StreamString json_strm;473ExecutionContext exe_ctx(474m_opaque_sp->GetCommandInterpreter().GetExecutionContext());475if (setting && strlen(setting) > 0)476m_opaque_sp->DumpPropertyValue(&exe_ctx, json_strm, setting,477/*dump_mask*/ 0,478/*is_json*/ true);479else480m_opaque_sp->DumpAllPropertyValues(&exe_ctx, json_strm, /*dump_mask*/ 0,481/*is_json*/ true);482483data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_strm.GetString()));484return data;485}486487FILE *SBDebugger::GetInputFileHandle() {488LLDB_INSTRUMENT_VA(this);489if (m_opaque_sp) {490File &file_sp = m_opaque_sp->GetInputFile();491return file_sp.GetStream();492}493return nullptr;494}495496SBFile SBDebugger::GetInputFile() {497LLDB_INSTRUMENT_VA(this);498if (m_opaque_sp) {499return SBFile(m_opaque_sp->GetInputFileSP());500}501return SBFile();502}503504FILE *SBDebugger::GetOutputFileHandle() {505LLDB_INSTRUMENT_VA(this);506if (m_opaque_sp) {507StreamFile &stream_file = m_opaque_sp->GetOutputStream();508return stream_file.GetFile().GetStream();509}510return nullptr;511}512513SBFile SBDebugger::GetOutputFile() {514LLDB_INSTRUMENT_VA(this);515if (m_opaque_sp) {516SBFile file(m_opaque_sp->GetOutputStream().GetFileSP());517return file;518}519return SBFile();520}521522FILE *SBDebugger::GetErrorFileHandle() {523LLDB_INSTRUMENT_VA(this);524525if (m_opaque_sp) {526StreamFile &stream_file = m_opaque_sp->GetErrorStream();527return stream_file.GetFile().GetStream();528}529return nullptr;530}531532SBFile SBDebugger::GetErrorFile() {533LLDB_INSTRUMENT_VA(this);534SBFile file;535if (m_opaque_sp) {536SBFile file(m_opaque_sp->GetErrorStream().GetFileSP());537return file;538}539return SBFile();540}541542void SBDebugger::SaveInputTerminalState() {543LLDB_INSTRUMENT_VA(this);544545if (m_opaque_sp)546m_opaque_sp->SaveInputTerminalState();547}548549void SBDebugger::RestoreInputTerminalState() {550LLDB_INSTRUMENT_VA(this);551552if (m_opaque_sp)553m_opaque_sp->RestoreInputTerminalState();554}555SBCommandInterpreter SBDebugger::GetCommandInterpreter() {556LLDB_INSTRUMENT_VA(this);557558SBCommandInterpreter sb_interpreter;559if (m_opaque_sp)560sb_interpreter.reset(&m_opaque_sp->GetCommandInterpreter());561562return sb_interpreter;563}564565void SBDebugger::HandleCommand(const char *command) {566LLDB_INSTRUMENT_VA(this, command);567568if (m_opaque_sp) {569TargetSP target_sp(m_opaque_sp->GetSelectedTarget());570std::unique_lock<std::recursive_mutex> lock;571if (target_sp)572lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());573574SBCommandInterpreter sb_interpreter(GetCommandInterpreter());575SBCommandReturnObject result;576577sb_interpreter.HandleCommand(command, result, false);578579result.PutError(m_opaque_sp->GetErrorStream().GetFileSP());580result.PutOutput(m_opaque_sp->GetOutputStream().GetFileSP());581582if (!m_opaque_sp->GetAsyncExecution()) {583SBProcess process(GetCommandInterpreter().GetProcess());584ProcessSP process_sp(process.GetSP());585if (process_sp) {586EventSP event_sp;587ListenerSP lldb_listener_sp = m_opaque_sp->GetListener();588while (lldb_listener_sp->GetEventForBroadcaster(589process_sp.get(), event_sp, std::chrono::seconds(0))) {590SBEvent event(event_sp);591HandleProcessEvent(process, event, GetOutputFile(), GetErrorFile());592}593}594}595}596}597598SBListener SBDebugger::GetListener() {599LLDB_INSTRUMENT_VA(this);600601SBListener sb_listener;602if (m_opaque_sp)603sb_listener.reset(m_opaque_sp->GetListener());604605return sb_listener;606}607608void SBDebugger::HandleProcessEvent(const SBProcess &process,609const SBEvent &event, SBFile out,610SBFile err) {611LLDB_INSTRUMENT_VA(this, process, event, out, err);612613return HandleProcessEvent(process, event, out.m_opaque_sp, err.m_opaque_sp);614}615616void SBDebugger::HandleProcessEvent(const SBProcess &process,617const SBEvent &event, FILE *out,618FILE *err) {619LLDB_INSTRUMENT_VA(this, process, event, out, err);620621FileSP outfile = std::make_shared<NativeFile>(out, false);622FileSP errfile = std::make_shared<NativeFile>(err, false);623return HandleProcessEvent(process, event, outfile, errfile);624}625626void SBDebugger::HandleProcessEvent(const SBProcess &process,627const SBEvent &event, FileSP out_sp,628FileSP err_sp) {629630LLDB_INSTRUMENT_VA(this, process, event, out_sp, err_sp);631632if (!process.IsValid())633return;634635TargetSP target_sp(process.GetTarget().GetSP());636if (!target_sp)637return;638639const uint32_t event_type = event.GetType();640char stdio_buffer[1024];641size_t len;642643std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());644645if (event_type &646(Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged)) {647// Drain stdout when we stop just in case we have any bytes648while ((len = process.GetSTDOUT(stdio_buffer, sizeof(stdio_buffer))) > 0)649if (out_sp)650out_sp->Write(stdio_buffer, len);651}652653if (event_type &654(Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged)) {655// Drain stderr when we stop just in case we have any bytes656while ((len = process.GetSTDERR(stdio_buffer, sizeof(stdio_buffer))) > 0)657if (err_sp)658err_sp->Write(stdio_buffer, len);659}660661if (event_type & Process::eBroadcastBitStateChanged) {662StateType event_state = SBProcess::GetStateFromEvent(event);663664if (event_state == eStateInvalid)665return;666667bool is_stopped = StateIsStoppedState(event_state);668if (!is_stopped)669process.ReportEventState(event, out_sp);670}671}672673SBSourceManager SBDebugger::GetSourceManager() {674LLDB_INSTRUMENT_VA(this);675676SBSourceManager sb_source_manager(*this);677return sb_source_manager;678}679680bool SBDebugger::GetDefaultArchitecture(char *arch_name, size_t arch_name_len) {681LLDB_INSTRUMENT_VA(arch_name, arch_name_len);682683if (arch_name && arch_name_len) {684ArchSpec default_arch = Target::GetDefaultArchitecture();685686if (default_arch.IsValid()) {687const std::string &triple_str = default_arch.GetTriple().str();688if (!triple_str.empty())689::snprintf(arch_name, arch_name_len, "%s", triple_str.c_str());690else691::snprintf(arch_name, arch_name_len, "%s",692default_arch.GetArchitectureName());693return true;694}695}696if (arch_name && arch_name_len)697arch_name[0] = '\0';698return false;699}700701bool SBDebugger::SetDefaultArchitecture(const char *arch_name) {702LLDB_INSTRUMENT_VA(arch_name);703704if (arch_name) {705ArchSpec arch(arch_name);706if (arch.IsValid()) {707Target::SetDefaultArchitecture(arch);708return true;709}710}711return false;712}713714ScriptLanguage715SBDebugger::GetScriptingLanguage(const char *script_language_name) {716LLDB_INSTRUMENT_VA(this, script_language_name);717718if (!script_language_name)719return eScriptLanguageDefault;720return OptionArgParser::ToScriptLanguage(721llvm::StringRef(script_language_name), eScriptLanguageDefault, nullptr);722}723724SBStructuredData725SBDebugger::GetScriptInterpreterInfo(lldb::ScriptLanguage language) {726LLDB_INSTRUMENT_VA(this, language);727SBStructuredData data;728if (m_opaque_sp) {729lldb_private::ScriptInterpreter *interp =730m_opaque_sp->GetScriptInterpreter(language);731if (interp) {732data.m_impl_up->SetObjectSP(interp->GetInterpreterInfo());733}734}735return data;736}737738const char *SBDebugger::GetVersionString() {739LLDB_INSTRUMENT();740741return lldb_private::GetVersion();742}743744const char *SBDebugger::StateAsCString(StateType state) {745LLDB_INSTRUMENT_VA(state);746747return lldb_private::StateAsCString(state);748}749750static void AddBoolConfigEntry(StructuredData::Dictionary &dict,751llvm::StringRef name, bool value,752llvm::StringRef description) {753auto entry_up = std::make_unique<StructuredData::Dictionary>();754entry_up->AddBooleanItem("value", value);755entry_up->AddStringItem("description", description);756dict.AddItem(name, std::move(entry_up));757}758759static void AddLLVMTargets(StructuredData::Dictionary &dict) {760auto array_up = std::make_unique<StructuredData::Array>();761#define LLVM_TARGET(target) \762array_up->AddItem(std::make_unique<StructuredData::String>(#target));763#include "llvm/Config/Targets.def"764auto entry_up = std::make_unique<StructuredData::Dictionary>();765entry_up->AddItem("value", std::move(array_up));766entry_up->AddStringItem("description", "A list of configured LLVM targets.");767dict.AddItem("targets", std::move(entry_up));768}769770SBStructuredData SBDebugger::GetBuildConfiguration() {771LLDB_INSTRUMENT();772773auto config_up = std::make_unique<StructuredData::Dictionary>();774AddBoolConfigEntry(775*config_up, "xml", XMLDocument::XMLEnabled(),776"A boolean value that indicates if XML support is enabled in LLDB");777AddBoolConfigEntry(778*config_up, "curses", LLDB_ENABLE_CURSES,779"A boolean value that indicates if curses support is enabled in LLDB");780AddBoolConfigEntry(781*config_up, "editline", LLDB_ENABLE_LIBEDIT,782"A boolean value that indicates if editline support is enabled in LLDB");783AddBoolConfigEntry(*config_up, "editline_wchar", LLDB_EDITLINE_USE_WCHAR,784"A boolean value that indicates if editline wide "785"characters support is enabled in LLDB");786AddBoolConfigEntry(787*config_up, "lzma", LLDB_ENABLE_LZMA,788"A boolean value that indicates if lzma support is enabled in LLDB");789AddBoolConfigEntry(790*config_up, "python", LLDB_ENABLE_PYTHON,791"A boolean value that indicates if python support is enabled in LLDB");792AddBoolConfigEntry(793*config_up, "lua", LLDB_ENABLE_LUA,794"A boolean value that indicates if lua support is enabled in LLDB");795AddBoolConfigEntry(*config_up, "fbsdvmcore", LLDB_ENABLE_FBSDVMCORE,796"A boolean value that indicates if fbsdvmcore support is "797"enabled in LLDB");798AddLLVMTargets(*config_up);799800SBStructuredData data;801data.m_impl_up->SetObjectSP(std::move(config_up));802return data;803}804805bool SBDebugger::StateIsRunningState(StateType state) {806LLDB_INSTRUMENT_VA(state);807808const bool result = lldb_private::StateIsRunningState(state);809810return result;811}812813bool SBDebugger::StateIsStoppedState(StateType state) {814LLDB_INSTRUMENT_VA(state);815816const bool result = lldb_private::StateIsStoppedState(state, false);817818return result;819}820821lldb::SBTarget SBDebugger::CreateTarget(const char *filename,822const char *target_triple,823const char *platform_name,824bool add_dependent_modules,825lldb::SBError &sb_error) {826LLDB_INSTRUMENT_VA(this, filename, target_triple, platform_name,827add_dependent_modules, sb_error);828829SBTarget sb_target;830TargetSP target_sp;831if (m_opaque_sp) {832sb_error.Clear();833OptionGroupPlatform platform_options(false);834platform_options.SetPlatformName(platform_name);835836sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget(837*m_opaque_sp, filename, target_triple,838add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo,839&platform_options, target_sp);840841if (sb_error.Success())842sb_target.SetSP(target_sp);843} else {844sb_error.SetErrorString("invalid debugger");845}846847Log *log = GetLog(LLDBLog::API);848LLDB_LOGF(log,849"SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, "850"platform_name=%s, add_dependent_modules=%u, error=%s) => "851"SBTarget(%p)",852static_cast<void *>(m_opaque_sp.get()), filename, target_triple,853platform_name, add_dependent_modules, sb_error.GetCString(),854static_cast<void *>(target_sp.get()));855856return sb_target;857}858859SBTarget860SBDebugger::CreateTargetWithFileAndTargetTriple(const char *filename,861const char *target_triple) {862LLDB_INSTRUMENT_VA(this, filename, target_triple);863864SBTarget sb_target;865TargetSP target_sp;866if (m_opaque_sp) {867const bool add_dependent_modules = true;868Status error(m_opaque_sp->GetTargetList().CreateTarget(869*m_opaque_sp, filename, target_triple,870add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,871target_sp));872sb_target.SetSP(target_sp);873}874875Log *log = GetLog(LLDBLog::API);876LLDB_LOGF(log,877"SBDebugger(%p)::CreateTargetWithFileAndTargetTriple "878"(filename=\"%s\", triple=%s) => SBTarget(%p)",879static_cast<void *>(m_opaque_sp.get()), filename, target_triple,880static_cast<void *>(target_sp.get()));881882return sb_target;883}884885SBTarget SBDebugger::CreateTargetWithFileAndArch(const char *filename,886const char *arch_cstr) {887LLDB_INSTRUMENT_VA(this, filename, arch_cstr);888889Log *log = GetLog(LLDBLog::API);890891SBTarget sb_target;892TargetSP target_sp;893if (m_opaque_sp) {894Status error;895if (arch_cstr == nullptr) {896// The version of CreateTarget that takes an ArchSpec won't accept an897// empty ArchSpec, so when the arch hasn't been specified, we need to898// call the target triple version.899error = m_opaque_sp->GetTargetList().CreateTarget(900*m_opaque_sp, filename, arch_cstr, eLoadDependentsYes, nullptr,901target_sp);902} else {903PlatformSP platform_sp =904m_opaque_sp->GetPlatformList().GetSelectedPlatform();905ArchSpec arch =906Platform::GetAugmentedArchSpec(platform_sp.get(), arch_cstr);907if (arch.IsValid())908error = m_opaque_sp->GetTargetList().CreateTarget(909*m_opaque_sp, filename, arch, eLoadDependentsYes, platform_sp,910target_sp);911else912error.SetErrorStringWithFormat("invalid arch_cstr: %s", arch_cstr);913}914if (error.Success())915sb_target.SetSP(target_sp);916}917918LLDB_LOGF(log,919"SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", "920"arch=%s) => SBTarget(%p)",921static_cast<void *>(m_opaque_sp.get()),922filename ? filename : "<unspecified>",923arch_cstr ? arch_cstr : "<unspecified>",924static_cast<void *>(target_sp.get()));925926return sb_target;927}928929SBTarget SBDebugger::CreateTarget(const char *filename) {930LLDB_INSTRUMENT_VA(this, filename);931932SBTarget sb_target;933TargetSP target_sp;934if (m_opaque_sp) {935Status error;936const bool add_dependent_modules = true;937error = m_opaque_sp->GetTargetList().CreateTarget(938*m_opaque_sp, filename, "",939add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,940target_sp);941942if (error.Success())943sb_target.SetSP(target_sp);944}945Log *log = GetLog(LLDBLog::API);946LLDB_LOGF(log,947"SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",948static_cast<void *>(m_opaque_sp.get()), filename,949static_cast<void *>(target_sp.get()));950return sb_target;951}952953SBTarget SBDebugger::GetDummyTarget() {954LLDB_INSTRUMENT_VA(this);955956SBTarget sb_target;957if (m_opaque_sp) {958sb_target.SetSP(m_opaque_sp->GetDummyTarget().shared_from_this());959}960Log *log = GetLog(LLDBLog::API);961LLDB_LOGF(log, "SBDebugger(%p)::GetDummyTarget() => SBTarget(%p)",962static_cast<void *>(m_opaque_sp.get()),963static_cast<void *>(sb_target.GetSP().get()));964return sb_target;965}966967bool SBDebugger::DeleteTarget(lldb::SBTarget &target) {968LLDB_INSTRUMENT_VA(this, target);969970bool result = false;971if (m_opaque_sp) {972TargetSP target_sp(target.GetSP());973if (target_sp) {974// No need to lock, the target list is thread safe975result = m_opaque_sp->GetTargetList().DeleteTarget(target_sp);976target_sp->Destroy();977target.Clear();978}979}980981Log *log = GetLog(LLDBLog::API);982LLDB_LOGF(log, "SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i",983static_cast<void *>(m_opaque_sp.get()),984static_cast<void *>(target.m_opaque_sp.get()), result);985986return result;987}988989SBTarget SBDebugger::GetTargetAtIndex(uint32_t idx) {990LLDB_INSTRUMENT_VA(this, idx);991992SBTarget sb_target;993if (m_opaque_sp) {994// No need to lock, the target list is thread safe995sb_target.SetSP(m_opaque_sp->GetTargetList().GetTargetAtIndex(idx));996}997return sb_target;998}9991000uint32_t SBDebugger::GetIndexOfTarget(lldb::SBTarget target) {1001LLDB_INSTRUMENT_VA(this, target);10021003lldb::TargetSP target_sp = target.GetSP();1004if (!target_sp)1005return UINT32_MAX;10061007if (!m_opaque_sp)1008return UINT32_MAX;10091010return m_opaque_sp->GetTargetList().GetIndexOfTarget(target.GetSP());1011}10121013SBTarget SBDebugger::FindTargetWithProcessID(lldb::pid_t pid) {1014LLDB_INSTRUMENT_VA(this, pid);10151016SBTarget sb_target;1017if (m_opaque_sp) {1018// No need to lock, the target list is thread safe1019sb_target.SetSP(m_opaque_sp->GetTargetList().FindTargetWithProcessID(pid));1020}1021return sb_target;1022}10231024SBTarget SBDebugger::FindTargetWithFileAndArch(const char *filename,1025const char *arch_name) {1026LLDB_INSTRUMENT_VA(this, filename, arch_name);10271028SBTarget sb_target;1029if (m_opaque_sp && filename && filename[0]) {1030// No need to lock, the target list is thread safe1031ArchSpec arch = Platform::GetAugmentedArchSpec(1032m_opaque_sp->GetPlatformList().GetSelectedPlatform().get(), arch_name);1033TargetSP target_sp(1034m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture(1035FileSpec(filename), arch_name ? &arch : nullptr));1036sb_target.SetSP(target_sp);1037}1038return sb_target;1039}10401041SBTarget SBDebugger::FindTargetWithLLDBProcess(const ProcessSP &process_sp) {1042SBTarget sb_target;1043if (m_opaque_sp) {1044// No need to lock, the target list is thread safe1045sb_target.SetSP(1046m_opaque_sp->GetTargetList().FindTargetWithProcess(process_sp.get()));1047}1048return sb_target;1049}10501051uint32_t SBDebugger::GetNumTargets() {1052LLDB_INSTRUMENT_VA(this);10531054if (m_opaque_sp) {1055// No need to lock, the target list is thread safe1056return m_opaque_sp->GetTargetList().GetNumTargets();1057}1058return 0;1059}10601061SBTarget SBDebugger::GetSelectedTarget() {1062LLDB_INSTRUMENT_VA(this);10631064Log *log = GetLog(LLDBLog::API);10651066SBTarget sb_target;1067TargetSP target_sp;1068if (m_opaque_sp) {1069// No need to lock, the target list is thread safe1070target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget();1071sb_target.SetSP(target_sp);1072}10731074if (log) {1075SBStream sstr;1076sb_target.GetDescription(sstr, eDescriptionLevelBrief);1077LLDB_LOGF(log, "SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s",1078static_cast<void *>(m_opaque_sp.get()),1079static_cast<void *>(target_sp.get()), sstr.GetData());1080}10811082return sb_target;1083}10841085void SBDebugger::SetSelectedTarget(SBTarget &sb_target) {1086LLDB_INSTRUMENT_VA(this, sb_target);10871088Log *log = GetLog(LLDBLog::API);10891090TargetSP target_sp(sb_target.GetSP());1091if (m_opaque_sp) {1092m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp);1093}1094if (log) {1095SBStream sstr;1096sb_target.GetDescription(sstr, eDescriptionLevelBrief);1097LLDB_LOGF(log, "SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s",1098static_cast<void *>(m_opaque_sp.get()),1099static_cast<void *>(target_sp.get()), sstr.GetData());1100}1101}11021103SBPlatform SBDebugger::GetSelectedPlatform() {1104LLDB_INSTRUMENT_VA(this);11051106Log *log = GetLog(LLDBLog::API);11071108SBPlatform sb_platform;1109DebuggerSP debugger_sp(m_opaque_sp);1110if (debugger_sp) {1111sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform());1112}1113LLDB_LOGF(log, "SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s",1114static_cast<void *>(m_opaque_sp.get()),1115static_cast<void *>(sb_platform.GetSP().get()),1116sb_platform.GetName());1117return sb_platform;1118}11191120void SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform) {1121LLDB_INSTRUMENT_VA(this, sb_platform);11221123Log *log = GetLog(LLDBLog::API);11241125DebuggerSP debugger_sp(m_opaque_sp);1126if (debugger_sp) {1127debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP());1128}11291130LLDB_LOGF(log, "SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)",1131static_cast<void *>(m_opaque_sp.get()),1132static_cast<void *>(sb_platform.GetSP().get()),1133sb_platform.GetName());1134}11351136uint32_t SBDebugger::GetNumPlatforms() {1137LLDB_INSTRUMENT_VA(this);11381139if (m_opaque_sp) {1140// No need to lock, the platform list is thread safe1141return m_opaque_sp->GetPlatformList().GetSize();1142}1143return 0;1144}11451146SBPlatform SBDebugger::GetPlatformAtIndex(uint32_t idx) {1147LLDB_INSTRUMENT_VA(this, idx);11481149SBPlatform sb_platform;1150if (m_opaque_sp) {1151// No need to lock, the platform list is thread safe1152sb_platform.SetSP(m_opaque_sp->GetPlatformList().GetAtIndex(idx));1153}1154return sb_platform;1155}11561157uint32_t SBDebugger::GetNumAvailablePlatforms() {1158LLDB_INSTRUMENT_VA(this);11591160uint32_t idx = 0;1161while (true) {1162if (PluginManager::GetPlatformPluginNameAtIndex(idx).empty()) {1163break;1164}1165++idx;1166}1167// +1 for the host platform, which should always appear first in the list.1168return idx + 1;1169}11701171SBStructuredData SBDebugger::GetAvailablePlatformInfoAtIndex(uint32_t idx) {1172LLDB_INSTRUMENT_VA(this, idx);11731174SBStructuredData data;1175auto platform_dict = std::make_unique<StructuredData::Dictionary>();1176llvm::StringRef name_str("name"), desc_str("description");11771178if (idx == 0) {1179PlatformSP host_platform_sp(Platform::GetHostPlatform());1180platform_dict->AddStringItem(name_str, host_platform_sp->GetPluginName());1181platform_dict->AddStringItem(1182desc_str, llvm::StringRef(host_platform_sp->GetDescription()));1183} else if (idx > 0) {1184llvm::StringRef plugin_name =1185PluginManager::GetPlatformPluginNameAtIndex(idx - 1);1186if (plugin_name.empty()) {1187return data;1188}1189platform_dict->AddStringItem(name_str, llvm::StringRef(plugin_name));11901191llvm::StringRef plugin_desc =1192PluginManager::GetPlatformPluginDescriptionAtIndex(idx - 1);1193platform_dict->AddStringItem(desc_str, llvm::StringRef(plugin_desc));1194}11951196data.m_impl_up->SetObjectSP(1197StructuredData::ObjectSP(platform_dict.release()));1198return data;1199}12001201void SBDebugger::DispatchInput(void *baton, const void *data, size_t data_len) {1202LLDB_INSTRUMENT_VA(this, baton, data, data_len);12031204DispatchInput(data, data_len);1205}12061207void SBDebugger::DispatchInput(const void *data, size_t data_len) {1208LLDB_INSTRUMENT_VA(this, data, data_len);12091210// Log *log(GetLog (LLDBLog::API));1211//1212// if (log)1213// LLDB_LOGF(log, "SBDebugger(%p)::DispatchInput (data=\"%.*s\",1214// size_t=%" PRIu64 ")",1215// m_opaque_sp.get(),1216// (int) data_len,1217// (const char *) data,1218// (uint64_t)data_len);1219//1220// if (m_opaque_sp)1221// m_opaque_sp->DispatchInput ((const char *) data, data_len);1222}12231224void SBDebugger::DispatchInputInterrupt() {1225LLDB_INSTRUMENT_VA(this);12261227if (m_opaque_sp)1228m_opaque_sp->DispatchInputInterrupt();1229}12301231void SBDebugger::DispatchInputEndOfFile() {1232LLDB_INSTRUMENT_VA(this);12331234if (m_opaque_sp)1235m_opaque_sp->DispatchInputEndOfFile();1236}12371238void SBDebugger::PushInputReader(SBInputReader &reader) {1239LLDB_INSTRUMENT_VA(this, reader);1240}12411242void SBDebugger::RunCommandInterpreter(bool auto_handle_events,1243bool spawn_thread) {1244LLDB_INSTRUMENT_VA(this, auto_handle_events, spawn_thread);12451246if (m_opaque_sp) {1247CommandInterpreterRunOptions options;1248options.SetAutoHandleEvents(auto_handle_events);1249options.SetSpawnThread(spawn_thread);1250m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(options);1251}1252}12531254void SBDebugger::RunCommandInterpreter(bool auto_handle_events,1255bool spawn_thread,1256SBCommandInterpreterRunOptions &options,1257int &num_errors, bool &quit_requested,1258bool &stopped_for_crash)12591260{1261LLDB_INSTRUMENT_VA(this, auto_handle_events, spawn_thread, options,1262num_errors, quit_requested, stopped_for_crash);12631264if (m_opaque_sp) {1265options.SetAutoHandleEvents(auto_handle_events);1266options.SetSpawnThread(spawn_thread);1267CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();1268CommandInterpreterRunResult result =1269interp.RunCommandInterpreter(options.ref());1270num_errors = result.GetNumErrors();1271quit_requested =1272result.IsResult(lldb::eCommandInterpreterResultQuitRequested);1273stopped_for_crash =1274result.IsResult(lldb::eCommandInterpreterResultInferiorCrash);1275}1276}12771278SBCommandInterpreterRunResult SBDebugger::RunCommandInterpreter(1279const SBCommandInterpreterRunOptions &options) {1280LLDB_INSTRUMENT_VA(this, options);12811282if (!m_opaque_sp)1283return SBCommandInterpreterRunResult();12841285CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();1286CommandInterpreterRunResult result =1287interp.RunCommandInterpreter(options.ref());12881289return SBCommandInterpreterRunResult(result);1290}12911292SBError SBDebugger::RunREPL(lldb::LanguageType language,1293const char *repl_options) {1294LLDB_INSTRUMENT_VA(this, language, repl_options);12951296SBError error;1297if (m_opaque_sp)1298error.ref() = m_opaque_sp->RunREPL(language, repl_options);1299else1300error.SetErrorString("invalid debugger");1301return error;1302}13031304void SBDebugger::reset(const DebuggerSP &debugger_sp) {1305m_opaque_sp = debugger_sp;1306}13071308Debugger *SBDebugger::get() const { return m_opaque_sp.get(); }13091310Debugger &SBDebugger::ref() const {1311assert(m_opaque_sp.get());1312return *m_opaque_sp;1313}13141315const lldb::DebuggerSP &SBDebugger::get_sp() const { return m_opaque_sp; }13161317SBDebugger SBDebugger::FindDebuggerWithID(int id) {1318LLDB_INSTRUMENT_VA(id);13191320// No need to lock, the debugger list is thread safe1321SBDebugger sb_debugger;1322DebuggerSP debugger_sp = Debugger::FindDebuggerWithID(id);1323if (debugger_sp)1324sb_debugger.reset(debugger_sp);1325return sb_debugger;1326}13271328const char *SBDebugger::GetInstanceName() {1329LLDB_INSTRUMENT_VA(this);13301331if (!m_opaque_sp)1332return nullptr;13331334return ConstString(m_opaque_sp->GetInstanceName()).AsCString();1335}13361337SBError SBDebugger::SetInternalVariable(const char *var_name, const char *value,1338const char *debugger_instance_name) {1339LLDB_INSTRUMENT_VA(var_name, value, debugger_instance_name);13401341SBError sb_error;1342DebuggerSP debugger_sp(1343Debugger::FindDebuggerWithInstanceName(debugger_instance_name));1344Status error;1345if (debugger_sp) {1346ExecutionContext exe_ctx(1347debugger_sp->GetCommandInterpreter().GetExecutionContext());1348error = debugger_sp->SetPropertyValue(&exe_ctx, eVarSetOperationAssign,1349var_name, value);1350} else {1351error.SetErrorStringWithFormat("invalid debugger instance name '%s'",1352debugger_instance_name);1353}1354if (error.Fail())1355sb_error.SetError(error);1356return sb_error;1357}13581359SBStringList1360SBDebugger::GetInternalVariableValue(const char *var_name,1361const char *debugger_instance_name) {1362LLDB_INSTRUMENT_VA(var_name, debugger_instance_name);13631364DebuggerSP debugger_sp(1365Debugger::FindDebuggerWithInstanceName(debugger_instance_name));1366Status error;1367if (debugger_sp) {1368ExecutionContext exe_ctx(1369debugger_sp->GetCommandInterpreter().GetExecutionContext());1370lldb::OptionValueSP value_sp(1371debugger_sp->GetPropertyValue(&exe_ctx, var_name, error));1372if (value_sp) {1373StreamString value_strm;1374value_sp->DumpValue(&exe_ctx, value_strm, OptionValue::eDumpOptionValue);1375const std::string &value_str = std::string(value_strm.GetString());1376if (!value_str.empty()) {1377StringList string_list;1378string_list.SplitIntoLines(value_str);1379return SBStringList(&string_list);1380}1381}1382}1383return SBStringList();1384}13851386uint32_t SBDebugger::GetTerminalWidth() const {1387LLDB_INSTRUMENT_VA(this);13881389return (m_opaque_sp ? m_opaque_sp->GetTerminalWidth() : 0);1390}13911392void SBDebugger::SetTerminalWidth(uint32_t term_width) {1393LLDB_INSTRUMENT_VA(this, term_width);13941395if (m_opaque_sp)1396m_opaque_sp->SetTerminalWidth(term_width);1397}13981399const char *SBDebugger::GetPrompt() const {1400LLDB_INSTRUMENT_VA(this);14011402Log *log = GetLog(LLDBLog::API);14031404LLDB_LOG(log, "SBDebugger({0:x})::GetPrompt () => \"{1}\"",1405static_cast<void *>(m_opaque_sp.get()),1406(m_opaque_sp ? m_opaque_sp->GetPrompt() : ""));14071408return (m_opaque_sp ? ConstString(m_opaque_sp->GetPrompt()).GetCString()1409: nullptr);1410}14111412void SBDebugger::SetPrompt(const char *prompt) {1413LLDB_INSTRUMENT_VA(this, prompt);14141415if (m_opaque_sp)1416m_opaque_sp->SetPrompt(llvm::StringRef(prompt));1417}14181419const char *SBDebugger::GetReproducerPath() const {1420LLDB_INSTRUMENT_VA(this);14211422return "GetReproducerPath has been deprecated";1423}14241425ScriptLanguage SBDebugger::GetScriptLanguage() const {1426LLDB_INSTRUMENT_VA(this);14271428return (m_opaque_sp ? m_opaque_sp->GetScriptLanguage() : eScriptLanguageNone);1429}14301431void SBDebugger::SetScriptLanguage(ScriptLanguage script_lang) {1432LLDB_INSTRUMENT_VA(this, script_lang);14331434if (m_opaque_sp) {1435m_opaque_sp->SetScriptLanguage(script_lang);1436}1437}14381439LanguageType SBDebugger::GetREPLLanguage() const {1440LLDB_INSTRUMENT_VA(this);14411442return (m_opaque_sp ? m_opaque_sp->GetREPLLanguage() : eLanguageTypeUnknown);1443}14441445void SBDebugger::SetREPLLanguage(LanguageType repl_lang) {1446LLDB_INSTRUMENT_VA(this, repl_lang);14471448if (m_opaque_sp) {1449m_opaque_sp->SetREPLLanguage(repl_lang);1450}1451}14521453bool SBDebugger::SetUseExternalEditor(bool value) {1454LLDB_INSTRUMENT_VA(this, value);14551456return (m_opaque_sp ? m_opaque_sp->SetUseExternalEditor(value) : false);1457}14581459bool SBDebugger::GetUseExternalEditor() {1460LLDB_INSTRUMENT_VA(this);14611462return (m_opaque_sp ? m_opaque_sp->GetUseExternalEditor() : false);1463}14641465bool SBDebugger::SetUseColor(bool value) {1466LLDB_INSTRUMENT_VA(this, value);14671468return (m_opaque_sp ? m_opaque_sp->SetUseColor(value) : false);1469}14701471bool SBDebugger::GetUseColor() const {1472LLDB_INSTRUMENT_VA(this);14731474return (m_opaque_sp ? m_opaque_sp->GetUseColor() : false);1475}14761477bool SBDebugger::SetUseSourceCache(bool value) {1478LLDB_INSTRUMENT_VA(this, value);14791480return (m_opaque_sp ? m_opaque_sp->SetUseSourceCache(value) : false);1481}14821483bool SBDebugger::GetUseSourceCache() const {1484LLDB_INSTRUMENT_VA(this);14851486return (m_opaque_sp ? m_opaque_sp->GetUseSourceCache() : false);1487}14881489bool SBDebugger::GetDescription(SBStream &description) {1490LLDB_INSTRUMENT_VA(this, description);14911492Stream &strm = description.ref();14931494if (m_opaque_sp) {1495const char *name = m_opaque_sp->GetInstanceName().c_str();1496user_id_t id = m_opaque_sp->GetID();1497strm.Printf("Debugger (instance: \"%s\", id: %" PRIu64 ")", name, id);1498} else1499strm.PutCString("No value");15001501return true;1502}15031504user_id_t SBDebugger::GetID() {1505LLDB_INSTRUMENT_VA(this);15061507return (m_opaque_sp ? m_opaque_sp->GetID() : LLDB_INVALID_UID);1508}15091510SBError SBDebugger::SetCurrentPlatform(const char *platform_name_cstr) {1511LLDB_INSTRUMENT_VA(this, platform_name_cstr);15121513SBError sb_error;1514if (m_opaque_sp) {1515if (platform_name_cstr && platform_name_cstr[0]) {1516PlatformList &platforms = m_opaque_sp->GetPlatformList();1517if (PlatformSP platform_sp = platforms.GetOrCreate(platform_name_cstr))1518platforms.SetSelectedPlatform(platform_sp);1519else1520sb_error.ref().SetErrorString("platform not found");1521} else {1522sb_error.ref().SetErrorString("invalid platform name");1523}1524} else {1525sb_error.ref().SetErrorString("invalid debugger");1526}1527return sb_error;1528}15291530bool SBDebugger::SetCurrentPlatformSDKRoot(const char *sysroot) {1531LLDB_INSTRUMENT_VA(this, sysroot);15321533if (SBPlatform platform = GetSelectedPlatform()) {1534platform.SetSDKRoot(sysroot);1535return true;1536}1537return false;1538}15391540bool SBDebugger::GetCloseInputOnEOF() const {1541LLDB_INSTRUMENT_VA(this);15421543return false;1544}15451546void SBDebugger::SetCloseInputOnEOF(bool b) {1547LLDB_INSTRUMENT_VA(this, b);1548}15491550SBTypeCategory SBDebugger::GetCategory(const char *category_name) {1551LLDB_INSTRUMENT_VA(this, category_name);15521553if (!category_name || *category_name == 0)1554return SBTypeCategory();15551556TypeCategoryImplSP category_sp;15571558if (DataVisualization::Categories::GetCategory(ConstString(category_name),1559category_sp, false)) {1560return SBTypeCategory(category_sp);1561} else {1562return SBTypeCategory();1563}1564}15651566SBTypeCategory SBDebugger::GetCategory(lldb::LanguageType lang_type) {1567LLDB_INSTRUMENT_VA(this, lang_type);15681569TypeCategoryImplSP category_sp;1570if (DataVisualization::Categories::GetCategory(lang_type, category_sp)) {1571return SBTypeCategory(category_sp);1572} else {1573return SBTypeCategory();1574}1575}15761577SBTypeCategory SBDebugger::CreateCategory(const char *category_name) {1578LLDB_INSTRUMENT_VA(this, category_name);15791580if (!category_name || *category_name == 0)1581return SBTypeCategory();15821583TypeCategoryImplSP category_sp;15841585if (DataVisualization::Categories::GetCategory(ConstString(category_name),1586category_sp, true)) {1587return SBTypeCategory(category_sp);1588} else {1589return SBTypeCategory();1590}1591}15921593bool SBDebugger::DeleteCategory(const char *category_name) {1594LLDB_INSTRUMENT_VA(this, category_name);15951596if (!category_name || *category_name == 0)1597return false;15981599return DataVisualization::Categories::Delete(ConstString(category_name));1600}16011602uint32_t SBDebugger::GetNumCategories() {1603LLDB_INSTRUMENT_VA(this);16041605return DataVisualization::Categories::GetCount();1606}16071608SBTypeCategory SBDebugger::GetCategoryAtIndex(uint32_t index) {1609LLDB_INSTRUMENT_VA(this, index);16101611return SBTypeCategory(1612DataVisualization::Categories::GetCategoryAtIndex(index));1613}16141615SBTypeCategory SBDebugger::GetDefaultCategory() {1616LLDB_INSTRUMENT_VA(this);16171618return GetCategory("default");1619}16201621SBTypeFormat SBDebugger::GetFormatForType(SBTypeNameSpecifier type_name) {1622LLDB_INSTRUMENT_VA(this, type_name);16231624SBTypeCategory default_category_sb = GetDefaultCategory();1625if (default_category_sb.GetEnabled())1626return default_category_sb.GetFormatForType(type_name);1627return SBTypeFormat();1628}16291630SBTypeSummary SBDebugger::GetSummaryForType(SBTypeNameSpecifier type_name) {1631LLDB_INSTRUMENT_VA(this, type_name);16321633if (!type_name.IsValid())1634return SBTypeSummary();1635return SBTypeSummary(DataVisualization::GetSummaryForType(type_name.GetSP()));1636}16371638SBTypeFilter SBDebugger::GetFilterForType(SBTypeNameSpecifier type_name) {1639LLDB_INSTRUMENT_VA(this, type_name);16401641if (!type_name.IsValid())1642return SBTypeFilter();1643return SBTypeFilter(DataVisualization::GetFilterForType(type_name.GetSP()));1644}16451646SBTypeSynthetic SBDebugger::GetSyntheticForType(SBTypeNameSpecifier type_name) {1647LLDB_INSTRUMENT_VA(this, type_name);16481649if (!type_name.IsValid())1650return SBTypeSynthetic();1651return SBTypeSynthetic(1652DataVisualization::GetSyntheticForType(type_name.GetSP()));1653}16541655static llvm::ArrayRef<const char *> GetCategoryArray(const char **categories) {1656if (categories == nullptr)1657return {};1658size_t len = 0;1659while (categories[len] != nullptr)1660++len;1661return llvm::ArrayRef(categories, len);1662}16631664bool SBDebugger::EnableLog(const char *channel, const char **categories) {1665LLDB_INSTRUMENT_VA(this, channel, categories);16661667if (m_opaque_sp) {1668uint32_t log_options =1669LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;1670std::string error;1671llvm::raw_string_ostream error_stream(error);1672return m_opaque_sp->EnableLog(channel, GetCategoryArray(categories), "",1673log_options, /*buffer_size=*/0,1674eLogHandlerStream, error_stream);1675} else1676return false;1677}16781679void SBDebugger::SetLoggingCallback(lldb::LogOutputCallback log_callback,1680void *baton) {1681LLDB_INSTRUMENT_VA(this, log_callback, baton);16821683if (m_opaque_sp) {1684return m_opaque_sp->SetLoggingCallback(log_callback, baton);1685}1686}16871688void SBDebugger::SetDestroyCallback(1689lldb::SBDebuggerDestroyCallback destroy_callback, void *baton) {1690LLDB_INSTRUMENT_VA(this, destroy_callback, baton);1691if (m_opaque_sp) {1692return m_opaque_sp->SetDestroyCallback(1693destroy_callback, baton);1694}1695}16961697lldb::callback_token_t1698SBDebugger::AddDestroyCallback(lldb::SBDebuggerDestroyCallback destroy_callback,1699void *baton) {1700LLDB_INSTRUMENT_VA(this, destroy_callback, baton);17011702if (m_opaque_sp)1703return m_opaque_sp->AddDestroyCallback(destroy_callback, baton);17041705return LLDB_INVALID_CALLBACK_TOKEN;1706}17071708bool SBDebugger::RemoveDestroyCallback(lldb::callback_token_t token) {1709LLDB_INSTRUMENT_VA(this, token);17101711if (m_opaque_sp)1712return m_opaque_sp->RemoveDestroyCallback(token);17131714return false;1715}17161717SBTrace1718SBDebugger::LoadTraceFromFile(SBError &error,1719const SBFileSpec &trace_description_file) {1720LLDB_INSTRUMENT_VA(this, error, trace_description_file);1721return SBTrace::LoadTraceFromFile(error, *this, trace_description_file);1722}17231724void SBDebugger::RequestInterrupt() {1725LLDB_INSTRUMENT_VA(this);17261727if (m_opaque_sp)1728m_opaque_sp->RequestInterrupt();1729}1730void SBDebugger::CancelInterruptRequest() {1731LLDB_INSTRUMENT_VA(this);17321733if (m_opaque_sp)1734m_opaque_sp->CancelInterruptRequest();1735}17361737bool SBDebugger::InterruptRequested() {1738LLDB_INSTRUMENT_VA(this);17391740if (m_opaque_sp)1741return m_opaque_sp->InterruptRequested();1742return false;1743}17441745bool SBDebugger::SupportsLanguage(lldb::LanguageType language) {1746return TypeSystem::SupportsLanguageStatic(language);1747}174817491750