[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- SBDebugger.cpp ----------------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2022-02-03 20:26:10 +08:00
|
|
|
#include "lldb/API/SBDebugger.h"
|
2018-05-26 04:28:16 +08:00
|
|
|
#include "SystemInitializerFull.h"
|
2022-01-20 03:38:26 +08:00
|
|
|
#include "lldb/Utility/Instrumentation.h"
|
2022-02-03 20:26:10 +08:00
|
|
|
#include "lldb/Utility/LLDBLog.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-06-09 15:37:52 +08:00
|
|
|
#include "lldb/API/SBBroadcaster.h"
|
|
|
|
#include "lldb/API/SBCommandInterpreter.h"
|
2020-05-01 04:28:42 +08:00
|
|
|
#include "lldb/API/SBCommandInterpreterRunOptions.h"
|
2010-06-09 15:37:52 +08:00
|
|
|
#include "lldb/API/SBCommandReturnObject.h"
|
2011-04-30 09:09:13 +08:00
|
|
|
#include "lldb/API/SBError.h"
|
2010-06-09 15:37:52 +08:00
|
|
|
#include "lldb/API/SBEvent.h"
|
2019-10-03 12:04:48 +08:00
|
|
|
#include "lldb/API/SBFile.h"
|
2010-06-09 15:37:52 +08:00
|
|
|
#include "lldb/API/SBFrame.h"
|
|
|
|
#include "lldb/API/SBListener.h"
|
|
|
|
#include "lldb/API/SBProcess.h"
|
|
|
|
#include "lldb/API/SBSourceManager.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2010-09-04 08:03:46 +08:00
|
|
|
#include "lldb/API/SBStringList.h"
|
2017-08-09 17:20:40 +08:00
|
|
|
#include "lldb/API/SBStructuredData.h"
|
2010-09-04 08:03:46 +08:00
|
|
|
#include "lldb/API/SBTarget.h"
|
|
|
|
#include "lldb/API/SBThread.h"
|
2012-02-15 10:34:21 +08:00
|
|
|
#include "lldb/API/SBTypeCategory.h"
|
|
|
|
#include "lldb/API/SBTypeFilter.h"
|
|
|
|
#include "lldb/API/SBTypeFormat.h"
|
|
|
|
#include "lldb/API/SBTypeNameSpecifier.h"
|
|
|
|
#include "lldb/API/SBTypeSummary.h"
|
|
|
|
#include "lldb/API/SBTypeSynthetic.h"
|
|
|
|
|
2010-10-11 09:05:37 +08:00
|
|
|
#include "lldb/Core/Debugger.h"
|
2022-03-15 00:01:53 +08:00
|
|
|
#include "lldb/Core/DebuggerEvents.h"
|
2017-08-09 17:20:40 +08:00
|
|
|
#include "lldb/Core/PluginManager.h"
|
2021-03-02 07:26:35 +08:00
|
|
|
#include "lldb/Core/Progress.h"
|
2014-01-28 07:43:24 +08:00
|
|
|
#include "lldb/Core/StreamFile.h"
|
2017-08-09 17:20:40 +08:00
|
|
|
#include "lldb/Core/StructuredDataImpl.h"
|
2013-01-29 07:47:25 +08:00
|
|
|
#include "lldb/DataFormatters/DataVisualization.h"
|
2019-12-11 00:54:30 +08:00
|
|
|
#include "lldb/Host/Config.h"
|
2018-02-19 23:06:28 +08:00
|
|
|
#include "lldb/Host/XML.h"
|
2015-04-01 05:03:22 +08:00
|
|
|
#include "lldb/Initialization/SystemLifetimeManager.h"
|
2010-10-11 09:05:37 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
2018-04-10 17:03:59 +08:00
|
|
|
#include "lldb/Interpreter/OptionArgParser.h"
|
2011-09-24 08:52:29 +08:00
|
|
|
#include "lldb/Interpreter/OptionGroupPlatform.h"
|
2010-10-11 09:05:37 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/TargetList.h"
|
2018-04-18 02:53:35 +08:00
|
|
|
#include "lldb/Utility/Args.h"
|
2018-08-07 19:07:21 +08:00
|
|
|
#include "lldb/Utility/State.h"
|
2021-12-09 04:23:57 +08:00
|
|
|
#include "lldb/Version/Version.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2015-10-20 12:50:09 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2016-09-17 03:09:12 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2014-08-28 04:15:09 +08:00
|
|
|
#include "llvm/Support/DynamicLibrary.h"
|
2015-04-01 05:03:22 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2022-04-08 02:12:09 +08:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
|
|
|
#include "llvm/Support/Signals.h"
|
2014-08-28 04:15:09 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2013-12-03 03:35:49 +08:00
|
|
|
static llvm::sys::DynamicLibrary LoadPlugin(const lldb::DebuggerSP &debugger_sp,
|
|
|
|
const FileSpec &spec,
|
2017-05-12 12:51:55 +08:00
|
|
|
Status &error) {
|
2014-08-28 04:15:09 +08:00
|
|
|
llvm::sys::DynamicLibrary dynlib =
|
|
|
|
llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
|
|
|
|
if (dynlib.isValid()) {
|
2013-12-03 03:35:49 +08:00
|
|
|
typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger & debugger);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-12-03 03:35:49 +08:00
|
|
|
lldb::SBDebugger debugger_sb(debugger_sp);
|
|
|
|
// This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger)
|
|
|
|
// function.
|
|
|
|
// TODO: mangle this differently for your system - on OSX, the first
|
|
|
|
// underscore needs to be removed and the second one stays
|
2014-08-28 04:15:09 +08:00
|
|
|
LLDBCommandPluginInit init_func =
|
2017-10-25 07:46:00 +08:00
|
|
|
(LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol(
|
2014-08-28 04:15:09 +08:00
|
|
|
"_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
|
2013-12-03 03:35:49 +08:00
|
|
|
if (init_func) {
|
|
|
|
if (init_func(debugger_sb))
|
2014-08-28 04:15:09 +08:00
|
|
|
return dynlib;
|
2013-12-03 03:35:49 +08:00
|
|
|
else
|
|
|
|
error.SetErrorString("plug-in refused to load "
|
|
|
|
"(lldb::PluginInitialize(lldb::SBDebugger) "
|
|
|
|
"returned false)");
|
|
|
|
} else {
|
|
|
|
error.SetErrorString("plug-in is missing the required initialization: "
|
|
|
|
"lldb::PluginInitialize(lldb::SBDebugger)");
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2018-11-02 01:09:25 +08:00
|
|
|
if (FileSystem::Instance().Exists(spec))
|
2013-12-03 03:35:49 +08:00
|
|
|
error.SetErrorString("this file does not represent a loadable dylib");
|
|
|
|
else
|
|
|
|
error.SetErrorString("no such file");
|
|
|
|
}
|
2014-08-28 04:15:09 +08:00
|
|
|
return llvm::sys::DynamicLibrary();
|
2013-12-03 03:35:49 +08:00
|
|
|
}
|
|
|
|
|
2015-04-01 05:03:22 +08:00
|
|
|
static llvm::ManagedStatic<SystemLifetimeManager> g_debugger_lifetime;
|
|
|
|
|
|
|
|
SBError SBInputReader::Initialize(
|
|
|
|
lldb::SBDebugger &sb_debugger,
|
2019-03-09 03:09:27 +08:00
|
|
|
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) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, sb_debugger, callback, a, b, c, d, e);
|
2019-03-09 03:09:27 +08:00
|
|
|
|
2015-04-01 05:03:22 +08:00
|
|
|
return SBError();
|
|
|
|
}
|
|
|
|
|
2022-01-20 03:38:26 +08:00
|
|
|
void SBInputReader::SetIsDone(bool b) { LLDB_INSTRUMENT_VA(this, b); }
|
2019-03-06 08:06:00 +08:00
|
|
|
|
|
|
|
bool SBInputReader::IsActive() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2015-10-31 09:22:59 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2022-01-20 03:38:26 +08:00
|
|
|
SBDebugger::SBDebugger() { LLDB_INSTRUMENT_VA(this); }
|
2015-10-31 09:22:59 +08:00
|
|
|
|
|
|
|
SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp)
|
2019-03-06 08:06:00 +08:00
|
|
|
: m_opaque_sp(debugger_sp) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, debugger_sp);
|
2019-03-06 08:06:00 +08:00
|
|
|
}
|
2015-10-31 09:22:59 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
SBDebugger::SBDebugger(const SBDebugger &rhs) : m_opaque_sp(rhs.m_opaque_sp) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, rhs);
|
2019-03-06 08:06:00 +08:00
|
|
|
}
|
2015-10-31 09:22:59 +08:00
|
|
|
|
|
|
|
SBDebugger::~SBDebugger() = default;
|
|
|
|
|
|
|
|
SBDebugger &SBDebugger::operator=(const SBDebugger &rhs) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, rhs);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
if (this != &rhs) {
|
|
|
|
m_opaque_sp = rhs.m_opaque_sp;
|
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return *this;
|
2015-10-31 09:22:59 +08:00
|
|
|
}
|
|
|
|
|
2021-03-02 07:26:35 +08:00
|
|
|
const char *SBDebugger::GetBroadcasterClass() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT();
|
2021-03-02 07:26:35 +08:00
|
|
|
|
|
|
|
return Debugger::GetStaticBroadcasterClass().AsCString();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBDebugger::GetProgressFromEvent(const lldb::SBEvent &event,
|
|
|
|
uint64_t &progress_id,
|
|
|
|
uint64_t &completed,
|
|
|
|
uint64_t &total,
|
|
|
|
bool &is_debugger_specific) {
|
2022-02-26 09:20:39 +08:00
|
|
|
LLDB_INSTRUMENT_VA(event);
|
2022-03-15 00:01:53 +08:00
|
|
|
const ProgressEventData *progress_data =
|
|
|
|
ProgressEventData::GetEventDataFromEvent(event.get());
|
2021-03-02 07:26:35 +08:00
|
|
|
if (progress_data == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
progress_id = progress_data->GetID();
|
|
|
|
completed = progress_data->GetCompleted();
|
|
|
|
total = progress_data->GetTotal();
|
|
|
|
is_debugger_specific = progress_data->IsDebuggerSpecific();
|
2022-01-10 14:54:08 +08:00
|
|
|
return progress_data->GetMessage().c_str();
|
2021-03-02 07:26:35 +08:00
|
|
|
}
|
|
|
|
|
2022-03-17 01:17:44 +08:00
|
|
|
lldb::SBStructuredData
|
|
|
|
SBDebugger::GetDiagnosticFromEvent(const lldb::SBEvent &event) {
|
|
|
|
LLDB_INSTRUMENT_VA(event);
|
|
|
|
|
|
|
|
const DiagnosticEventData *diagnostic_data =
|
|
|
|
DiagnosticEventData::GetEventDataFromEvent(event.get());
|
|
|
|
if (!diagnostic_data)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
auto dictionary = std::make_unique<StructuredData::Dictionary>();
|
|
|
|
dictionary->AddStringItem("message", diagnostic_data->GetMessage());
|
|
|
|
dictionary->AddStringItem("type", diagnostic_data->GetPrefix());
|
|
|
|
dictionary->AddBooleanItem("debugger_specific",
|
|
|
|
diagnostic_data->IsDebuggerSpecific());
|
|
|
|
|
|
|
|
SBStructuredData data;
|
|
|
|
data.m_impl_up->SetObjectSP(std::move(dictionary));
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2021-03-02 07:26:35 +08:00
|
|
|
SBBroadcaster SBDebugger::GetBroadcaster() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2021-03-02 07:26:35 +08:00
|
|
|
SBBroadcaster broadcaster(&m_opaque_sp->GetBroadcaster(), false);
|
2022-01-10 14:54:08 +08:00
|
|
|
return broadcaster;
|
2021-03-02 07:26:35 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void SBDebugger::Initialize() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT();
|
2019-02-22 06:26:16 +08:00
|
|
|
SBError ignored = SBDebugger::InitializeWithErrorHandling();
|
2018-12-04 01:28:29 +08:00
|
|
|
}
|
|
|
|
|
2019-02-22 06:26:16 +08:00
|
|
|
lldb::SBError SBDebugger::InitializeWithErrorHandling() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT();
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2018-12-04 01:28:29 +08:00
|
|
|
SBError error;
|
|
|
|
if (auto e = g_debugger_lifetime->Initialize(
|
2019-08-15 06:19:23 +08:00
|
|
|
std::make_unique<SystemInitializerFull>(), LoadPlugin)) {
|
2018-12-04 01:28:29 +08:00
|
|
|
error.SetError(Status(std::move(e)));
|
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return error;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2022-04-08 02:12:09 +08:00
|
|
|
void SBDebugger::PrintStackTraceOnError() {
|
|
|
|
LLDB_INSTRUMENT();
|
|
|
|
|
|
|
|
llvm::EnablePrettyStackTrace();
|
|
|
|
// We don't have a meaningful argv[0] to use, so use "SBDebugger" as a
|
|
|
|
// substitute.
|
|
|
|
llvm::sys::PrintStackTraceOnErrorSignal("SBDebugger");
|
|
|
|
}
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
void SBDebugger::Terminate() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT();
|
2019-03-06 08:06:00 +08:00
|
|
|
|
|
|
|
g_debugger_lifetime->Terminate();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-07-31 04:12:55 +08:00
|
|
|
void SBDebugger::Clear() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-12-21 02:35:50 +08:00
|
|
|
if (m_opaque_sp)
|
2014-01-28 07:43:24 +08:00
|
|
|
m_opaque_sp->ClearIOHandlers();
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2010-07-31 04:12:55 +08:00
|
|
|
m_opaque_sp.reset();
|
|
|
|
}
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
SBDebugger SBDebugger::Create() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT();
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBDebugger::Create(false, nullptr, nullptr);
|
2011-08-13 08:22:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBDebugger SBDebugger::Create(bool source_init_files) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(source_init_files);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBDebugger::Create(source_init_files, nullptr, nullptr);
|
2012-02-21 10:23:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBDebugger SBDebugger::Create(bool source_init_files,
|
|
|
|
lldb::LogOutputCallback callback, void *baton)
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(source_init_files, callback, baton);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2011-08-13 08:22:20 +08:00
|
|
|
SBDebugger debugger;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
// Currently we have issues if this function is called simultaneously on two
|
2018-05-01 00:49:04 +08:00
|
|
|
// different threads. The issues mainly revolve around the fact that the
|
|
|
|
// lldb_private::FormatManager uses global collections and having two threads
|
|
|
|
// parsing the .lldbinit files can cause mayhem. So to get around this for
|
|
|
|
// now we need to use a mutex to prevent bad things from happening.
|
2014-04-04 12:06:10 +08:00
|
|
|
static std::recursive_mutex g_mutex;
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(g_mutex);
|
|
|
|
|
2011-01-22 09:02:07 +08:00
|
|
|
debugger.reset(Debugger::CreateInstance(callback, baton));
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2011-01-22 09:02:07 +08:00
|
|
|
SBCommandInterpreter interp = debugger.GetCommandInterpreter();
|
|
|
|
if (source_init_files) {
|
2011-08-13 08:22:20 +08:00
|
|
|
interp.get()->SkipLLDBInitFiles(false);
|
2011-01-22 09:02:07 +08:00
|
|
|
interp.get()->SkipAppInitFiles(false);
|
2011-08-13 08:22:20 +08:00
|
|
|
SBCommandReturnObject result;
|
2022-02-15 20:28:34 +08:00
|
|
|
interp.SourceInitFileInGlobalDirectory(result);
|
2020-08-20 04:04:35 +08:00
|
|
|
interp.SourceInitFileInHomeDirectory(result, false);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2011-01-22 09:02:07 +08:00
|
|
|
interp.get()->SkipLLDBInitFiles(true);
|
2011-08-13 08:22:20 +08:00
|
|
|
interp.get()->SkipAppInitFiles(true);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-23 09:19:29 +08:00
|
|
|
return debugger;
|
2011-01-22 09:02:07 +08:00
|
|
|
}
|
|
|
|
|
2011-12-15 12:38:41 +08:00
|
|
|
void SBDebugger::Destroy(SBDebugger &debugger) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(debugger);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-04-10 04:22:01 +08:00
|
|
|
Debugger::Destroy(debugger.m_opaque_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-04-10 04:22:01 +08:00
|
|
|
if (debugger.m_opaque_sp.get() != nullptr)
|
|
|
|
debugger.m_opaque_sp.reset();
|
2011-12-15 12:38:41 +08:00
|
|
|
}
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
void SBDebugger::MemoryPressureDetected() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT();
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Since this function can be call asynchronously, we allow it to be non-
|
|
|
|
// mandatory. We have seen deadlocks with this function when called so we
|
|
|
|
// need to safeguard against this until we can determine what is causing the
|
|
|
|
// deadlocks.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
const bool mandatory = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
ModuleList::RemoveOrphanSharedModules(mandatory);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
bool SBDebugger::IsValid() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
Add "operator bool" to SB APIs
Summary:
Our python version of the SB API has (the python equivalent of)
operator bool, but the C++ version doesn't.
This is because our python operators are added by modify-python-lldb.py,
which performs postprocessing on the swig-generated interface files.
In this patch, I add the "operator bool" to all SB classes which have an
IsValid method (which is the same logic used by modify-python-lldb.py).
This way, we make the two interfaces more constent, and it allows us to
rely on swig's automatic syntesis of python __nonzero__ methods instead
of doing manual fixups.
Reviewers: zturner, jingham, clayborg, jfb, serge-sans-paille
Subscribers: jdoerfert, lldb-commits
Differential Revision: https://reviews.llvm.org/D58792
llvm-svn: 355824
2019-03-11 21:58:46 +08:00
|
|
|
return this->operator bool();
|
|
|
|
}
|
|
|
|
SBDebugger::operator bool() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
|
|
|
return m_opaque_sp.get() != nullptr;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
void SBDebugger::SetAsync(bool b) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, b);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->SetAsyncExecution(b);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
bool SBDebugger::GetAsync() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
return (m_opaque_sp ? m_opaque_sp->GetAsyncExecution() : false);
|
2011-09-14 07:25:31 +08:00
|
|
|
}
|
|
|
|
|
2010-10-11 09:05:37 +08:00
|
|
|
void SBDebugger::SkipLLDBInitFiles(bool b) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, b);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-10-11 09:05:37 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles(b);
|
|
|
|
}
|
|
|
|
|
2011-08-13 07:34:31 +08:00
|
|
|
void SBDebugger::SkipAppInitFiles(bool b) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, b);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2011-08-13 07:34:31 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles(b);
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void SBDebugger::SetInputFileHandle(FILE *fh, bool transfer_ownership) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, fh, transfer_ownership);
|
2021-11-25 00:13:48 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->SetInputFile(
|
|
|
|
(FileSP)std::make_shared<NativeFile>(fh, transfer_ownership));
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2021-11-25 00:13:48 +08:00
|
|
|
SBError SBDebugger::SetInputString(const char *data) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, data);
|
2021-11-25 00:13:48 +08:00
|
|
|
SBError sb_error;
|
|
|
|
if (data == nullptr) {
|
|
|
|
sb_error.SetErrorString("String data is null");
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_error;
|
2021-11-25 00:13:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t size = strlen(data);
|
|
|
|
if (size == 0) {
|
|
|
|
sb_error.SetErrorString("String data is empty");
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_error;
|
2021-11-25 00:13:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_opaque_sp) {
|
|
|
|
sb_error.SetErrorString("invalid debugger");
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_error;
|
2021-11-25 00:13:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sb_error.SetError(m_opaque_sp->SetInputString(data));
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_error;
|
2019-10-11 03:10:59 +08:00
|
|
|
}
|
|
|
|
|
2019-10-03 12:04:48 +08:00
|
|
|
// Shouldn't really be settable after initialization as this could cause lots
|
|
|
|
// of problems; don't want users trying to switch modes in the middle of a
|
|
|
|
// debugging session.
|
|
|
|
SBError SBDebugger::SetInputFile(SBFile file) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, file);
|
2019-10-03 12:04:48 +08:00
|
|
|
|
|
|
|
SBError error;
|
|
|
|
if (!m_opaque_sp) {
|
|
|
|
error.ref().SetErrorString("invalid debugger");
|
2022-01-10 14:54:08 +08:00
|
|
|
return error;
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
2021-11-25 00:13:48 +08:00
|
|
|
error.SetError(m_opaque_sp->SetInputFile(file.m_opaque_sp));
|
2022-01-10 14:54:08 +08:00
|
|
|
return error;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2021-11-25 00:13:48 +08:00
|
|
|
SBError SBDebugger::SetInputFile(FileSP file_sp) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, file_sp);
|
2022-01-10 14:54:08 +08:00
|
|
|
return SetInputFile(SBFile(file_sp));
|
2021-11-25 00:13:48 +08:00
|
|
|
}
|
|
|
|
|
2019-10-11 03:10:59 +08:00
|
|
|
SBError SBDebugger::SetOutputFile(FileSP file_sp) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, file_sp);
|
2022-01-10 14:54:08 +08:00
|
|
|
return SetOutputFile(SBFile(file_sp));
|
2019-10-11 03:10:59 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void SBDebugger::SetOutputFileHandle(FILE *fh, bool transfer_ownership) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, fh, transfer_ownership);
|
2019-10-03 12:31:46 +08:00
|
|
|
SetOutputFile((FileSP)std::make_shared<NativeFile>(fh, transfer_ownership));
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-10-03 12:04:48 +08:00
|
|
|
SBError SBDebugger::SetOutputFile(SBFile file) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, file);
|
2019-10-03 12:04:48 +08:00
|
|
|
SBError error;
|
|
|
|
if (!m_opaque_sp) {
|
|
|
|
error.ref().SetErrorString("invalid debugger");
|
2022-01-10 14:54:08 +08:00
|
|
|
return error;
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
|
|
|
if (!file) {
|
|
|
|
error.ref().SetErrorString("invalid file");
|
2022-01-10 14:54:08 +08:00
|
|
|
return error;
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
|
|
|
m_opaque_sp->SetOutputFile(file.m_opaque_sp);
|
2022-01-10 14:54:08 +08:00
|
|
|
return error;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBDebugger::SetErrorFileHandle(FILE *fh, bool transfer_ownership) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, fh, transfer_ownership);
|
2019-10-03 12:31:46 +08:00
|
|
|
SetErrorFile((FileSP)std::make_shared<NativeFile>(fh, transfer_ownership));
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-10-11 03:10:59 +08:00
|
|
|
SBError SBDebugger::SetErrorFile(FileSP file_sp) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, file_sp);
|
2022-01-10 14:54:08 +08:00
|
|
|
return SetErrorFile(SBFile(file_sp));
|
2019-10-11 03:10:59 +08:00
|
|
|
}
|
|
|
|
|
2019-10-03 12:04:48 +08:00
|
|
|
SBError SBDebugger::SetErrorFile(SBFile file) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, file);
|
2019-10-03 12:04:48 +08:00
|
|
|
SBError error;
|
|
|
|
if (!m_opaque_sp) {
|
|
|
|
error.ref().SetErrorString("invalid debugger");
|
2022-01-10 14:54:08 +08:00
|
|
|
return error;
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
|
|
|
if (!file) {
|
|
|
|
error.ref().SetErrorString("invalid file");
|
2022-01-10 14:54:08 +08:00
|
|
|
return error;
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
|
|
|
m_opaque_sp->SetErrorFile(file.m_opaque_sp);
|
2022-01-10 14:54:08 +08:00
|
|
|
return error;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
FILE *SBDebugger::GetInputFileHandle() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp) {
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
File &file_sp = m_opaque_sp->GetInputFile();
|
2022-01-10 14:54:08 +08:00
|
|
|
return file_sp.GetStream();
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-10-03 12:04:48 +08:00
|
|
|
SBFile SBDebugger::GetInputFile() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-10-03 12:04:48 +08:00
|
|
|
if (m_opaque_sp) {
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBFile(m_opaque_sp->GetInputFileSP());
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBFile();
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
FILE *SBDebugger::GetOutputFileHandle() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp) {
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
StreamFile &stream_file = m_opaque_sp->GetOutputStream();
|
2022-01-10 14:54:08 +08:00
|
|
|
return stream_file.GetFile().GetStream();
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-10-03 12:04:48 +08:00
|
|
|
SBFile SBDebugger::GetOutputFile() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-10-03 12:04:48 +08:00
|
|
|
if (m_opaque_sp) {
|
|
|
|
SBFile file(m_opaque_sp->GetOutputStream().GetFileSP());
|
2022-01-10 14:54:08 +08:00
|
|
|
return file;
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBFile();
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
FILE *SBDebugger::GetErrorFileHandle() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp) {
|
remove File::SetStream(), make new files instead.
Summary:
This patch removes File::SetStream() and File::SetDescriptor(),
and replaces most direct uses of File with pointers to File.
Instead of calling SetStream() on a file, we make a new file and
replace it.
My ultimate goal here is to introduce a new API class SBFile, which
has full support for python io.IOStream file objects. These can
redirect read() and write() to python code, so lldb::Files will
need a way to dispatch those methods. Additionally it will need some
form of sharing and assigning files, as a SBFile will be passed in and
assigned to the main IO streams of the debugger.
In my prototype patch queue, I make File itself copyable and add a
secondary class FileOps to manage the sharing and dispatch. In that
case SBFile was a unique_ptr<File>.
(here: https://github.com/smoofra/llvm-project/tree/files)
However in review, Pavel Labath suggested that it be shared_ptr instead.
(here: https://reviews.llvm.org/D67793)
In order for SBFile to use shared_ptr<File>, everything else should
as well.
If this patch is accepted, I will make SBFile use a shared_ptr
I will remove FileOps from future patches and use subclasses of File
instead.
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67891
llvm-svn: 373090
2019-09-27 22:33:35 +08:00
|
|
|
StreamFile &stream_file = m_opaque_sp->GetErrorStream();
|
2022-01-10 14:54:08 +08:00
|
|
|
return stream_file.GetFile().GetStream();
|
2015-10-31 09:22:59 +08:00
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-10-03 12:04:48 +08:00
|
|
|
SBFile SBDebugger::GetErrorFile() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-10-03 12:04:48 +08:00
|
|
|
SBFile file;
|
|
|
|
if (m_opaque_sp) {
|
|
|
|
SBFile file(m_opaque_sp->GetErrorStream().GetFileSP());
|
2022-01-10 14:54:08 +08:00
|
|
|
return file;
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBFile();
|
2019-10-03 12:04:48 +08:00
|
|
|
}
|
|
|
|
|
2012-12-01 04:23:19 +08:00
|
|
|
void SBDebugger::SaveInputTerminalState() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-12-01 04:23:19 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->SaveInputTerminalState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBDebugger::RestoreInputTerminalState() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-12-01 04:23:19 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->RestoreInputTerminalState();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
SBCommandInterpreter SBDebugger::GetCommandInterpreter() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
SBCommandInterpreter sb_interpreter;
|
|
|
|
if (m_opaque_sp)
|
|
|
|
sb_interpreter.reset(&m_opaque_sp->GetCommandInterpreter());
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_interpreter;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBDebugger::HandleCommand(const char *command) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, command);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp) {
|
2010-12-21 04:49:23 +08:00
|
|
|
TargetSP target_sp(m_opaque_sp->GetSelectedTarget());
|
2015-10-31 09:22:59 +08:00
|
|
|
std::unique_lock<std::recursive_mutex> lock;
|
|
|
|
if (target_sp)
|
2016-03-08 05:50:25 +08:00
|
|
|
lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
SBCommandInterpreter sb_interpreter(GetCommandInterpreter());
|
2013-03-28 07:08:40 +08:00
|
|
|
SBCommandReturnObject result;
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-03-08 05:50:25 +08:00
|
|
|
sb_interpreter.HandleCommand(command, result, false);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2019-10-10 05:50:52 +08:00
|
|
|
result.PutError(m_opaque_sp->GetErrorStream().GetFileSP());
|
|
|
|
result.PutOutput(m_opaque_sp->GetOutputStream().GetFileSP());
|
2010-10-27 07:49:36 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
if (!m_opaque_sp->GetAsyncExecution()) {
|
2010-06-09 00:52:24 +08:00
|
|
|
SBProcess process(GetCommandInterpreter().GetProcess());
|
2012-01-30 15:41:31 +08:00
|
|
|
ProcessSP process_sp(process.GetSP());
|
|
|
|
if (process_sp) {
|
2010-06-23 09:19:29 +08:00
|
|
|
EventSP event_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
ListenerSP lldb_listener_sp = m_opaque_sp->GetListener();
|
2016-11-30 18:41:42 +08:00
|
|
|
while (lldb_listener_sp->GetEventForBroadcaster(
|
|
|
|
process_sp.get(), event_sp, std::chrono::seconds(0))) {
|
2010-06-23 09:19:29 +08:00
|
|
|
SBEvent event(event_sp);
|
2019-10-15 04:15:28 +08:00
|
|
|
HandleProcessEvent(process, event, GetOutputFile(), GetErrorFile());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBListener SBDebugger::GetListener() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
SBListener sb_listener;
|
|
|
|
if (m_opaque_sp)
|
2010-12-21 04:49:23 +08:00
|
|
|
sb_listener.reset(m_opaque_sp->GetListener());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_listener;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-10-15 04:15:28 +08:00
|
|
|
void SBDebugger::HandleProcessEvent(const SBProcess &process,
|
|
|
|
const SBEvent &event, SBFile out,
|
|
|
|
SBFile err) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, process, event, out, err);
|
2019-10-15 04:15:28 +08:00
|
|
|
|
|
|
|
return HandleProcessEvent(process, event, out.m_opaque_sp, err.m_opaque_sp);
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void SBDebugger::HandleProcessEvent(const SBProcess &process,
|
2011-09-13 08:29:56 +08:00
|
|
|
const SBEvent &event, FILE *out,
|
|
|
|
FILE *err) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, process, event, out, err);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-10-15 04:15:28 +08:00
|
|
|
FileSP outfile = std::make_shared<NativeFile>(out, false);
|
|
|
|
FileSP errfile = std::make_shared<NativeFile>(err, false);
|
|
|
|
return HandleProcessEvent(process, event, outfile, errfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBDebugger::HandleProcessEvent(const SBProcess &process,
|
|
|
|
const SBEvent &event, FileSP out_sp,
|
|
|
|
FileSP err_sp) {
|
|
|
|
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, process, event, out_sp, err_sp);
|
2019-10-15 04:15:28 +08:00
|
|
|
|
2011-09-13 08:29:56 +08:00
|
|
|
if (!process.IsValid())
|
|
|
|
return;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-04-19 07:15:17 +08:00
|
|
|
TargetSP target_sp(process.GetTarget().GetSP());
|
|
|
|
if (!target_sp)
|
2010-06-09 00:52:24 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
const uint32_t event_type = event.GetType();
|
|
|
|
char stdio_buffer[1024];
|
|
|
|
size_t len;
|
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-12-21 04:49:23 +08:00
|
|
|
if (event_type &
|
2010-06-09 00:52:24 +08:00
|
|
|
(Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged)) {
|
|
|
|
// Drain stdout when we stop just in case we have any bytes
|
|
|
|
while ((len = process.GetSTDOUT(stdio_buffer, sizeof(stdio_buffer))) > 0)
|
2019-10-15 04:15:28 +08:00
|
|
|
if (out_sp)
|
|
|
|
out_sp->Write(stdio_buffer, len);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-04-19 07:15:17 +08:00
|
|
|
if (event_type &
|
|
|
|
(Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged)) {
|
|
|
|
// Drain stderr when we stop just in case we have any bytes
|
2011-04-26 06:05:51 +08:00
|
|
|
while ((len = process.GetSTDERR(stdio_buffer, sizeof(stdio_buffer))) > 0)
|
2019-10-15 04:15:28 +08:00
|
|
|
if (err_sp)
|
|
|
|
err_sp->Write(stdio_buffer, len);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-04-19 07:15:17 +08:00
|
|
|
if (event_type & Process::eBroadcastBitStateChanged) {
|
|
|
|
StateType event_state = SBProcess::GetStateFromEvent(event);
|
2010-10-30 12:51:46 +08:00
|
|
|
|
2011-04-26 06:05:51 +08:00
|
|
|
if (event_state == eStateInvalid)
|
2011-04-19 07:15:17 +08:00
|
|
|
return;
|
2010-10-30 12:51:46 +08:00
|
|
|
|
2010-12-21 04:49:23 +08:00
|
|
|
bool is_stopped = StateIsStoppedState(event_state);
|
|
|
|
if (!is_stopped)
|
2019-10-15 04:15:28 +08:00
|
|
|
process.ReportEventState(event, out_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-04-19 07:15:17 +08:00
|
|
|
SBSourceManager SBDebugger::GetSourceManager() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-10-30 12:51:46 +08:00
|
|
|
SBSourceManager sb_source_manager(*this);
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_source_manager;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-09-24 08:52:29 +08:00
|
|
|
bool SBDebugger::GetDefaultArchitecture(char *arch_name, size_t arch_name_len) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(arch_name, arch_name_len);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2011-09-24 08:52:29 +08:00
|
|
|
if (arch_name && arch_name_len) {
|
|
|
|
ArchSpec default_arch = Target::GetDefaultArchitecture();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (default_arch.IsValid()) {
|
2011-09-24 08:52:29 +08:00
|
|
|
const std::string &triple_str = default_arch.GetTriple().str();
|
|
|
|
if (!triple_str.empty())
|
|
|
|
::snprintf(arch_name, arch_name_len, "%s", triple_str.c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2012-10-19 00:33:33 +08:00
|
|
|
::snprintf(arch_name, arch_name_len, "%s",
|
2012-01-30 15:41:31 +08:00
|
|
|
default_arch.GetArchitectureName());
|
|
|
|
return true;
|
2011-09-24 08:52:29 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-09-24 08:52:29 +08:00
|
|
|
if (arch_name && arch_name_len)
|
2010-06-09 00:52:24 +08:00
|
|
|
arch_name[0] = '\0';
|
2011-09-24 08:52:29 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-10-31 05:32:03 +08:00
|
|
|
bool SBDebugger::SetDefaultArchitecture(const char *arch_name) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(arch_name);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (arch_name) {
|
2015-10-31 05:32:03 +08:00
|
|
|
ArchSpec arch(arch_name);
|
|
|
|
if (arch.IsValid()) {
|
2011-04-19 07:15:17 +08:00
|
|
|
Target::SetDefaultArchitecture(arch);
|
2015-10-31 05:32:03 +08:00
|
|
|
return true;
|
2011-09-24 08:52:29 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-09-24 08:52:29 +08:00
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
ScriptLanguage
|
|
|
|
SBDebugger::GetScriptingLanguage(const char *script_language_name) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, script_language_name);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-09-12 07:27:09 +08:00
|
|
|
if (!script_language_name)
|
|
|
|
return eScriptLanguageDefault;
|
2018-04-10 17:03:59 +08:00
|
|
|
return OptionArgParser::ToScriptLanguage(
|
|
|
|
llvm::StringRef(script_language_name), eScriptLanguageDefault, nullptr);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
[lldb] make it easier to find LLDB's python
It is surprisingly difficult to write a simple python script that
can reliably `import lldb` without failing, or crashing. I'm
currently resorting to convolutions like this:
def find_lldb(may_reexec=False):
if prefix := os.environ.get('LLDB_PYTHON_PREFIX'):
if os.path.realpath(prefix) != os.path.realpath(sys.prefix):
raise Exception("cannot import lldb.\n"
f" sys.prefix should be: {prefix}\n"
f" but it is: {sys.prefix}")
else:
line1, line2 = subprocess.run(
['lldb', '-x', '-b', '-o', 'script print(sys.prefix)'],
encoding='utf8', stdout=subprocess.PIPE,
check=True).stdout.strip().splitlines()
assert line1.strip() == '(lldb) script print(sys.prefix)'
prefix = line2.strip()
os.environ['LLDB_PYTHON_PREFIX'] = prefix
if sys.prefix != prefix:
if not may_reexec:
raise Exception(
"cannot import lldb.\n" +
f" This python, at {sys.prefix}\n"
f" does not math LLDB's python at {prefix}")
os.environ['LLDB_PYTHON_PREFIX'] = prefix
python_exe = os.path.join(prefix, 'bin', 'python3')
os.execl(python_exe, python_exe, *sys.argv)
lldb_path = subprocess.run(['lldb', '-P'],
check=True, stdout=subprocess.PIPE,
encoding='utf8').stdout.strip()
sys.path = [lldb_path] + sys.path
This patch aims to replace all that with:
#!/usr/bin/env lldb-python
import lldb
...
... by adding the following features:
* new command line option: --print-script-interpreter-info. This
prints language-specific information about the script interpreter
in JSON format.
* new tool (unix only): lldb-python which finds python and exec's it.
Reviewed By: JDevlieghere
Differential Revision: https://reviews.llvm.org/D112973
2021-11-11 02:33:33 +08:00
|
|
|
SBStructuredData
|
|
|
|
SBDebugger::GetScriptInterpreterInfo(lldb::ScriptLanguage language) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, language);
|
[lldb] make it easier to find LLDB's python
It is surprisingly difficult to write a simple python script that
can reliably `import lldb` without failing, or crashing. I'm
currently resorting to convolutions like this:
def find_lldb(may_reexec=False):
if prefix := os.environ.get('LLDB_PYTHON_PREFIX'):
if os.path.realpath(prefix) != os.path.realpath(sys.prefix):
raise Exception("cannot import lldb.\n"
f" sys.prefix should be: {prefix}\n"
f" but it is: {sys.prefix}")
else:
line1, line2 = subprocess.run(
['lldb', '-x', '-b', '-o', 'script print(sys.prefix)'],
encoding='utf8', stdout=subprocess.PIPE,
check=True).stdout.strip().splitlines()
assert line1.strip() == '(lldb) script print(sys.prefix)'
prefix = line2.strip()
os.environ['LLDB_PYTHON_PREFIX'] = prefix
if sys.prefix != prefix:
if not may_reexec:
raise Exception(
"cannot import lldb.\n" +
f" This python, at {sys.prefix}\n"
f" does not math LLDB's python at {prefix}")
os.environ['LLDB_PYTHON_PREFIX'] = prefix
python_exe = os.path.join(prefix, 'bin', 'python3')
os.execl(python_exe, python_exe, *sys.argv)
lldb_path = subprocess.run(['lldb', '-P'],
check=True, stdout=subprocess.PIPE,
encoding='utf8').stdout.strip()
sys.path = [lldb_path] + sys.path
This patch aims to replace all that with:
#!/usr/bin/env lldb-python
import lldb
...
... by adding the following features:
* new command line option: --print-script-interpreter-info. This
prints language-specific information about the script interpreter
in JSON format.
* new tool (unix only): lldb-python which finds python and exec's it.
Reviewed By: JDevlieghere
Differential Revision: https://reviews.llvm.org/D112973
2021-11-11 02:33:33 +08:00
|
|
|
SBStructuredData data;
|
|
|
|
if (m_opaque_sp) {
|
|
|
|
lldb_private::ScriptInterpreter *interp =
|
|
|
|
m_opaque_sp->GetScriptInterpreter(language);
|
|
|
|
if (interp) {
|
|
|
|
data.m_impl_up->SetObjectSP(interp->GetInterpreterInfo());
|
|
|
|
}
|
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return data;
|
[lldb] make it easier to find LLDB's python
It is surprisingly difficult to write a simple python script that
can reliably `import lldb` without failing, or crashing. I'm
currently resorting to convolutions like this:
def find_lldb(may_reexec=False):
if prefix := os.environ.get('LLDB_PYTHON_PREFIX'):
if os.path.realpath(prefix) != os.path.realpath(sys.prefix):
raise Exception("cannot import lldb.\n"
f" sys.prefix should be: {prefix}\n"
f" but it is: {sys.prefix}")
else:
line1, line2 = subprocess.run(
['lldb', '-x', '-b', '-o', 'script print(sys.prefix)'],
encoding='utf8', stdout=subprocess.PIPE,
check=True).stdout.strip().splitlines()
assert line1.strip() == '(lldb) script print(sys.prefix)'
prefix = line2.strip()
os.environ['LLDB_PYTHON_PREFIX'] = prefix
if sys.prefix != prefix:
if not may_reexec:
raise Exception(
"cannot import lldb.\n" +
f" This python, at {sys.prefix}\n"
f" does not math LLDB's python at {prefix}")
os.environ['LLDB_PYTHON_PREFIX'] = prefix
python_exe = os.path.join(prefix, 'bin', 'python3')
os.execl(python_exe, python_exe, *sys.argv)
lldb_path = subprocess.run(['lldb', '-P'],
check=True, stdout=subprocess.PIPE,
encoding='utf8').stdout.strip()
sys.path = [lldb_path] + sys.path
This patch aims to replace all that with:
#!/usr/bin/env lldb-python
import lldb
...
... by adding the following features:
* new command line option: --print-script-interpreter-info. This
prints language-specific information about the script interpreter
in JSON format.
* new tool (unix only): lldb-python which finds python and exec's it.
Reviewed By: JDevlieghere
Differential Revision: https://reviews.llvm.org/D112973
2021-11-11 02:33:33 +08:00
|
|
|
}
|
|
|
|
|
2011-02-23 08:35:02 +08:00
|
|
|
const char *SBDebugger::GetVersionString() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT();
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2014-04-04 12:06:10 +08:00
|
|
|
return lldb_private::GetVersion();
|
2010-06-23 09:19:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBDebugger::StateAsCString(StateType state) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(state);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
return lldb_private::StateAsCString(state);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2018-02-19 23:06:28 +08:00
|
|
|
static void AddBoolConfigEntry(StructuredData::Dictionary &dict,
|
|
|
|
llvm::StringRef name, bool value,
|
|
|
|
llvm::StringRef description) {
|
2019-08-15 06:19:23 +08:00
|
|
|
auto entry_up = std::make_unique<StructuredData::Dictionary>();
|
2018-02-19 23:06:28 +08:00
|
|
|
entry_up->AddBooleanItem("value", value);
|
|
|
|
entry_up->AddStringItem("description", description);
|
|
|
|
dict.AddItem(name, std::move(entry_up));
|
|
|
|
}
|
|
|
|
|
2018-06-28 22:23:04 +08:00
|
|
|
static void AddLLVMTargets(StructuredData::Dictionary &dict) {
|
2019-08-15 06:19:23 +08:00
|
|
|
auto array_up = std::make_unique<StructuredData::Array>();
|
2018-06-28 22:23:04 +08:00
|
|
|
#define LLVM_TARGET(target) \
|
2019-08-15 06:19:23 +08:00
|
|
|
array_up->AddItem(std::make_unique<StructuredData::String>(#target));
|
2018-06-28 22:23:04 +08:00
|
|
|
#include "llvm/Config/Targets.def"
|
2019-08-15 06:19:23 +08:00
|
|
|
auto entry_up = std::make_unique<StructuredData::Dictionary>();
|
2018-06-28 22:23:04 +08:00
|
|
|
entry_up->AddItem("value", std::move(array_up));
|
|
|
|
entry_up->AddStringItem("description", "A list of configured LLVM targets.");
|
|
|
|
dict.AddItem("targets", std::move(entry_up));
|
|
|
|
}
|
|
|
|
|
2018-02-19 23:06:28 +08:00
|
|
|
SBStructuredData SBDebugger::GetBuildConfiguration() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT();
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2019-08-15 06:19:23 +08:00
|
|
|
auto config_up = std::make_unique<StructuredData::Dictionary>();
|
2018-02-19 23:06:28 +08:00
|
|
|
AddBoolConfigEntry(
|
|
|
|
*config_up, "xml", XMLDocument::XMLEnabled(),
|
|
|
|
"A boolean value that indicates if XML support is enabled in LLDB");
|
2019-09-02 21:33:12 +08:00
|
|
|
AddBoolConfigEntry(
|
2019-12-13 01:13:04 +08:00
|
|
|
*config_up, "curses", LLDB_ENABLE_CURSES,
|
2019-09-02 21:33:12 +08:00
|
|
|
"A boolean value that indicates if curses support is enabled in LLDB");
|
2019-12-21 13:01:08 +08:00
|
|
|
AddBoolConfigEntry(
|
|
|
|
*config_up, "editline", LLDB_ENABLE_LIBEDIT,
|
|
|
|
"A boolean value that indicates if editline support is enabled in LLDB");
|
|
|
|
AddBoolConfigEntry(
|
|
|
|
*config_up, "lzma", LLDB_ENABLE_LZMA,
|
|
|
|
"A boolean value that indicates if lzma support is enabled in LLDB");
|
|
|
|
AddBoolConfigEntry(
|
|
|
|
*config_up, "python", LLDB_ENABLE_PYTHON,
|
|
|
|
"A boolean value that indicates if python support is enabled in LLDB");
|
|
|
|
AddBoolConfigEntry(
|
|
|
|
*config_up, "lua", LLDB_ENABLE_LUA,
|
|
|
|
"A boolean value that indicates if lua support is enabled in LLDB");
|
2021-12-02 06:04:59 +08:00
|
|
|
AddBoolConfigEntry(*config_up, "fbsdvmcore", LLDB_ENABLE_FBSDVMCORE,
|
|
|
|
"A boolean value that indicates if fbsdvmcore support is "
|
|
|
|
"enabled in LLDB");
|
2018-06-28 22:23:04 +08:00
|
|
|
AddLLVMTargets(*config_up);
|
2018-02-19 23:06:28 +08:00
|
|
|
|
|
|
|
SBStructuredData data;
|
|
|
|
data.m_impl_up->SetObjectSP(std::move(config_up));
|
2022-01-10 14:54:08 +08:00
|
|
|
return data;
|
2018-02-19 23:06:28 +08:00
|
|
|
}
|
|
|
|
|
2011-06-16 05:24:24 +08:00
|
|
|
bool SBDebugger::StateIsRunningState(StateType state) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(state);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
const bool result = lldb_private::StateIsRunningState(state);
|
2011-06-16 05:24:24 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2015-10-31 09:22:59 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool SBDebugger::StateIsStoppedState(StateType state) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(state);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-05-09 07:06:07 +08:00
|
|
|
const bool result = lldb_private::StateIsStoppedState(state, false);
|
|
|
|
|
|
|
|
return result;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-05-09 07:06:07 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb::SBTarget SBDebugger::CreateTarget(const char *filename,
|
|
|
|
const char *target_triple,
|
2011-09-24 08:52:29 +08:00
|
|
|
const char *platform_name,
|
|
|
|
bool add_dependent_modules,
|
|
|
|
lldb::SBError &sb_error) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, filename, target_triple, platform_name,
|
|
|
|
add_dependent_modules, sb_error);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2011-09-24 08:52:29 +08:00
|
|
|
SBTarget sb_target;
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp;
|
2012-05-09 07:06:07 +08:00
|
|
|
if (m_opaque_sp) {
|
2011-09-24 08:52:29 +08:00
|
|
|
sb_error.Clear();
|
|
|
|
OptionGroupPlatform platform_options(false);
|
2012-05-09 07:06:07 +08:00
|
|
|
platform_options.SetPlatformName(platform_name);
|
|
|
|
|
|
|
|
sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget(
|
2018-09-20 17:09:05 +08:00
|
|
|
*m_opaque_sp, filename, target_triple,
|
|
|
|
add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo,
|
2012-05-09 07:06:07 +08:00
|
|
|
&platform_options, target_sp);
|
|
|
|
|
2013-09-06 00:53:14 +08:00
|
|
|
if (sb_error.Success())
|
2012-01-30 15:41:31 +08:00
|
|
|
sb_target.SetSP(target_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2012-01-30 15:41:31 +08:00
|
|
|
sb_error.SetErrorString("invalid debugger");
|
2010-12-21 04:49:23 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::API);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, "
|
|
|
|
"platform_name=%s, add_dependent_modules=%u, error=%s) => "
|
|
|
|
"SBTarget(%p)",
|
|
|
|
static_cast<void *>(m_opaque_sp.get()), filename, target_triple,
|
|
|
|
platform_name, add_dependent_modules, sb_error.GetCString(),
|
|
|
|
static_cast<void *>(target_sp.get()));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_target;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBTarget
|
2011-04-19 07:15:17 +08:00
|
|
|
SBDebugger::CreateTargetWithFileAndTargetTriple(const char *filename,
|
2010-06-09 00:52:24 +08:00
|
|
|
const char *target_triple) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, filename, target_triple);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
SBTarget sb_target;
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp) {
|
2010-12-21 04:49:23 +08:00
|
|
|
const bool add_dependent_modules = true;
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error(m_opaque_sp->GetTargetList().CreateTarget(
|
2018-09-20 17:09:05 +08:00
|
|
|
*m_opaque_sp, filename, target_triple,
|
|
|
|
add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,
|
2012-01-30 15:41:31 +08:00
|
|
|
target_sp));
|
|
|
|
sb_target.SetSP(target_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::API);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"SBDebugger(%p)::CreateTargetWithFileAndTargetTriple "
|
|
|
|
"(filename=\"%s\", triple=%s) => SBTarget(%p)",
|
|
|
|
static_cast<void *>(m_opaque_sp.get()), filename, target_triple,
|
|
|
|
static_cast<void *>(target_sp.get()));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_target;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-02-23 08:35:02 +08:00
|
|
|
SBTarget SBDebugger::CreateTargetWithFileAndArch(const char *filename,
|
2010-06-09 00:52:24 +08:00
|
|
|
const char *arch_cstr) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, filename, arch_cstr);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::API);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-24 08:52:29 +08:00
|
|
|
SBTarget sb_target;
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2021-01-27 04:15:09 +08:00
|
|
|
if (arch_cstr == nullptr) {
|
|
|
|
// The version of CreateTarget that takes an ArchSpec won't accept an
|
|
|
|
// empty ArchSpec, so when the arch hasn't been specified, we need to
|
|
|
|
// call the target triple version.
|
2022-01-20 03:38:26 +08:00
|
|
|
error = m_opaque_sp->GetTargetList().CreateTarget(
|
|
|
|
*m_opaque_sp, filename, arch_cstr, eLoadDependentsYes, nullptr,
|
|
|
|
target_sp);
|
2021-01-27 04:15:09 +08:00
|
|
|
} else {
|
2022-01-20 03:38:26 +08:00
|
|
|
PlatformSP platform_sp =
|
|
|
|
m_opaque_sp->GetPlatformList().GetSelectedPlatform();
|
|
|
|
ArchSpec arch =
|
|
|
|
Platform::GetAugmentedArchSpec(platform_sp.get(), arch_cstr);
|
2021-01-27 04:15:09 +08:00
|
|
|
if (arch.IsValid())
|
2022-01-20 03:38:26 +08:00
|
|
|
error = m_opaque_sp->GetTargetList().CreateTarget(
|
|
|
|
*m_opaque_sp, filename, arch, eLoadDependentsYes, platform_sp,
|
|
|
|
target_sp);
|
2021-01-27 04:15:09 +08:00
|
|
|
else
|
|
|
|
error.SetErrorStringWithFormat("invalid arch_cstr: %s", arch_cstr);
|
|
|
|
}
|
2021-01-26 10:02:39 +08:00
|
|
|
if (error.Success())
|
|
|
|
sb_target.SetSP(target_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2021-03-02 07:26:35 +08:00
|
|
|
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", "
|
|
|
|
"arch=%s) => SBTarget(%p)",
|
2021-01-27 04:15:09 +08:00
|
|
|
static_cast<void *>(m_opaque_sp.get()),
|
|
|
|
filename ? filename : "<unspecified>",
|
|
|
|
arch_cstr ? arch_cstr : "<unspecified>",
|
2019-07-25 01:56:10 +08:00
|
|
|
static_cast<void *>(target_sp.get()));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_target;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-09-14 07:25:31 +08:00
|
|
|
SBTarget SBDebugger::CreateTarget(const char *filename) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, filename);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-01-30 15:41:31 +08:00
|
|
|
SBTarget sb_target;
|
|
|
|
TargetSP target_sp;
|
2011-09-14 07:25:31 +08:00
|
|
|
if (m_opaque_sp) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2011-09-24 08:52:29 +08:00
|
|
|
const bool add_dependent_modules = true;
|
2015-10-31 09:22:59 +08:00
|
|
|
error = m_opaque_sp->GetTargetList().CreateTarget(
|
2018-09-20 17:09:05 +08:00
|
|
|
*m_opaque_sp, filename, "",
|
|
|
|
add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr,
|
|
|
|
target_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-12-11 16:09:39 +08:00
|
|
|
if (error.Success())
|
2012-01-30 15:41:31 +08:00
|
|
|
sb_target.SetSP(target_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::API);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
|
|
|
|
static_cast<void *>(m_opaque_sp.get()), filename,
|
|
|
|
static_cast<void *>(target_sp.get()));
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_target;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2017-09-15 04:22:49 +08:00
|
|
|
SBTarget SBDebugger::GetDummyTarget() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2017-09-15 04:22:49 +08:00
|
|
|
SBTarget sb_target;
|
|
|
|
if (m_opaque_sp) {
|
2020-11-10 07:25:59 +08:00
|
|
|
sb_target.SetSP(m_opaque_sp->GetDummyTarget().shared_from_this());
|
2017-09-15 04:22:49 +08:00
|
|
|
}
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::API);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "SBDebugger(%p)::GetDummyTarget() => SBTarget(%p)",
|
|
|
|
static_cast<void *>(m_opaque_sp.get()),
|
|
|
|
static_cast<void *>(sb_target.GetSP().get()));
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_target;
|
2017-09-15 04:22:49 +08:00
|
|
|
}
|
|
|
|
|
2014-04-04 12:06:10 +08:00
|
|
|
bool SBDebugger::DeleteTarget(lldb::SBTarget &target) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, target);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2011-06-16 05:24:24 +08:00
|
|
|
bool result = false;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp) {
|
2014-04-04 12:06:10 +08:00
|
|
|
TargetSP target_sp(target.GetSP());
|
2012-01-30 15:41:31 +08:00
|
|
|
if (target_sp) {
|
2014-04-04 12:06:10 +08:00
|
|
|
// No need to lock, the target list is thread safe
|
2010-08-27 05:32:51 +08:00
|
|
|
result = m_opaque_sp->GetTargetList().DeleteTarget(target_sp);
|
2012-01-30 15:41:31 +08:00
|
|
|
target_sp->Destroy();
|
|
|
|
target.Clear();
|
2011-09-14 07:25:31 +08:00
|
|
|
}
|
|
|
|
}
|
2013-11-21 05:07:01 +08:00
|
|
|
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::API);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i",
|
|
|
|
static_cast<void *>(m_opaque_sp.get()),
|
|
|
|
static_cast<void *>(target.m_opaque_sp.get()), result);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
return result;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-02-15 10:34:21 +08:00
|
|
|
SBTarget SBDebugger::GetTargetAtIndex(uint32_t idx) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, idx);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-01-30 15:41:31 +08:00
|
|
|
SBTarget sb_target;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp) {
|
2012-01-30 15:41:31 +08:00
|
|
|
// No need to lock, the target list is thread safe
|
2014-04-04 12:06:10 +08:00
|
|
|
sb_target.SetSP(m_opaque_sp->GetTargetList().GetTargetAtIndex(idx));
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_target;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-04-04 12:06:10 +08:00
|
|
|
uint32_t SBDebugger::GetIndexOfTarget(lldb::SBTarget target) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, target);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-05-09 07:06:07 +08:00
|
|
|
lldb::TargetSP target_sp = target.GetSP();
|
|
|
|
if (!target_sp)
|
|
|
|
return UINT32_MAX;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (!m_opaque_sp)
|
2012-05-09 07:06:07 +08:00
|
|
|
return UINT32_MAX;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-08-27 05:32:51 +08:00
|
|
|
return m_opaque_sp->GetTargetList().GetIndexOfTarget(target.GetSP());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-09-06 00:53:14 +08:00
|
|
|
SBTarget SBDebugger::FindTargetWithProcessID(lldb::pid_t pid) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, pid);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-01-30 15:41:31 +08:00
|
|
|
SBTarget sb_target;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp) {
|
2012-01-30 15:41:31 +08:00
|
|
|
// No need to lock, the target list is thread safe
|
2014-04-04 12:06:10 +08:00
|
|
|
sb_target.SetSP(m_opaque_sp->GetTargetList().FindTargetWithProcessID(pid));
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_target;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-04-04 12:06:10 +08:00
|
|
|
SBTarget SBDebugger::FindTargetWithFileAndArch(const char *filename,
|
2010-06-09 00:52:24 +08:00
|
|
|
const char *arch_name) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, filename, arch_name);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-01-30 15:41:31 +08:00
|
|
|
SBTarget sb_target;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp && filename && filename[0]) {
|
2012-01-30 15:41:31 +08:00
|
|
|
// No need to lock, the target list is thread safe
|
2017-10-31 18:56:03 +08:00
|
|
|
ArchSpec arch = Platform::GetAugmentedArchSpec(
|
|
|
|
m_opaque_sp->GetPlatformList().GetSelectedPlatform().get(), arch_name);
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp(
|
2014-04-04 12:06:10 +08:00
|
|
|
m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture(
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec(filename), arch_name ? &arch : nullptr));
|
2012-01-30 15:41:31 +08:00
|
|
|
sb_target.SetSP(target_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_target;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-04-19 07:15:17 +08:00
|
|
|
SBTarget SBDebugger::FindTargetWithLLDBProcess(const ProcessSP &process_sp) {
|
2012-01-30 15:41:31 +08:00
|
|
|
SBTarget sb_target;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp) {
|
2012-01-30 15:41:31 +08:00
|
|
|
// No need to lock, the target list is thread safe
|
|
|
|
sb_target.SetSP(
|
2010-08-27 05:32:51 +08:00
|
|
|
m_opaque_sp->GetTargetList().FindTargetWithProcess(process_sp.get()));
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-11-21 05:07:01 +08:00
|
|
|
return sb_target;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
uint32_t SBDebugger::GetNumTargets() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp) {
|
2012-01-30 15:41:31 +08:00
|
|
|
// No need to lock, the target list is thread safe
|
2010-08-27 05:32:51 +08:00
|
|
|
return m_opaque_sp->GetTargetList().GetNumTargets();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
2010-06-23 09:19:29 +08:00
|
|
|
return 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-11-21 05:07:01 +08:00
|
|
|
|
|
|
|
SBTarget SBDebugger::GetSelectedTarget() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::API);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-11-21 05:07:01 +08:00
|
|
|
SBTarget sb_target;
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp;
|
2013-11-21 05:07:01 +08:00
|
|
|
if (m_opaque_sp) {
|
2012-01-30 15:41:31 +08:00
|
|
|
// No need to lock, the target list is thread safe
|
2010-08-27 05:32:51 +08:00
|
|
|
target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget();
|
2012-01-30 15:41:31 +08:00
|
|
|
sb_target.SetSP(target_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2013-11-21 05:07:01 +08:00
|
|
|
if (log) {
|
2010-10-26 11:11:13 +08:00
|
|
|
SBStream sstr;
|
2013-11-21 05:07:01 +08:00
|
|
|
sb_target.GetDescription(sstr, eDescriptionLevelBrief);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s",
|
|
|
|
static_cast<void *>(m_opaque_sp.get()),
|
|
|
|
static_cast<void *>(target_sp.get()), sstr.GetData());
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_target;
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2012-09-07 06:02:28 +08:00
|
|
|
void SBDebugger::SetSelectedTarget(SBTarget &sb_target) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, sb_target);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::API);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp(sb_target.GetSP());
|
|
|
|
if (m_opaque_sp) {
|
2020-12-11 16:09:39 +08:00
|
|
|
m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
if (log) {
|
2010-10-26 11:11:13 +08:00
|
|
|
SBStream sstr;
|
2012-09-07 06:02:28 +08:00
|
|
|
sb_target.GetDescription(sstr, eDescriptionLevelBrief);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s",
|
|
|
|
static_cast<void *>(m_opaque_sp.get()),
|
|
|
|
static_cast<void *>(target_sp.get()), sstr.GetData());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-04 12:06:10 +08:00
|
|
|
SBPlatform SBDebugger::GetSelectedPlatform() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::API);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-07 06:02:28 +08:00
|
|
|
SBPlatform sb_platform;
|
|
|
|
DebuggerSP debugger_sp(m_opaque_sp);
|
2012-09-07 05:58:25 +08:00
|
|
|
if (debugger_sp) {
|
|
|
|
sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s",
|
|
|
|
static_cast<void *>(m_opaque_sp.get()),
|
|
|
|
static_cast<void *>(sb_platform.GetSP().get()),
|
|
|
|
sb_platform.GetName());
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_platform;
|
2012-09-07 05:58:25 +08:00
|
|
|
}
|
|
|
|
|
2012-08-21 00:21:04 +08:00
|
|
|
void SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, sb_platform);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::API);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
DebuggerSP debugger_sp(m_opaque_sp);
|
|
|
|
if (debugger_sp) {
|
|
|
|
debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)",
|
|
|
|
static_cast<void *>(m_opaque_sp.get()),
|
|
|
|
static_cast<void *>(sb_platform.GetSP().get()),
|
|
|
|
sb_platform.GetName());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2017-08-09 17:20:40 +08:00
|
|
|
uint32_t SBDebugger::GetNumPlatforms() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2017-08-09 17:20:40 +08:00
|
|
|
if (m_opaque_sp) {
|
|
|
|
// No need to lock, the platform list is thread safe
|
|
|
|
return m_opaque_sp->GetPlatformList().GetSize();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBPlatform SBDebugger::GetPlatformAtIndex(uint32_t idx) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, idx);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2017-08-09 17:20:40 +08:00
|
|
|
SBPlatform sb_platform;
|
|
|
|
if (m_opaque_sp) {
|
|
|
|
// No need to lock, the platform list is thread safe
|
|
|
|
sb_platform.SetSP(m_opaque_sp->GetPlatformList().GetAtIndex(idx));
|
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_platform;
|
2017-08-09 17:20:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SBDebugger::GetNumAvailablePlatforms() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2017-08-09 17:20:40 +08:00
|
|
|
uint32_t idx = 0;
|
|
|
|
while (true) {
|
2021-10-22 03:00:33 +08:00
|
|
|
if (PluginManager::GetPlatformPluginNameAtIndex(idx).empty()) {
|
2017-08-09 17:20:40 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
// +1 for the host platform, which should always appear first in the list.
|
|
|
|
return idx + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBStructuredData SBDebugger::GetAvailablePlatformInfoAtIndex(uint32_t idx) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, idx);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2017-08-09 17:20:40 +08:00
|
|
|
SBStructuredData data;
|
2019-08-15 06:19:23 +08:00
|
|
|
auto platform_dict = std::make_unique<StructuredData::Dictionary>();
|
2017-08-09 17:20:40 +08:00
|
|
|
llvm::StringRef name_str("name"), desc_str("description");
|
|
|
|
|
|
|
|
if (idx == 0) {
|
|
|
|
PlatformSP host_platform_sp(Platform::GetHostPlatform());
|
2021-10-15 19:07:39 +08:00
|
|
|
platform_dict->AddStringItem(name_str, host_platform_sp->GetPluginName());
|
2017-08-09 17:20:40 +08:00
|
|
|
platform_dict->AddStringItem(
|
|
|
|
desc_str, llvm::StringRef(host_platform_sp->GetDescription()));
|
|
|
|
} else if (idx > 0) {
|
2021-10-22 03:00:33 +08:00
|
|
|
llvm::StringRef plugin_name =
|
2017-08-09 17:20:40 +08:00
|
|
|
PluginManager::GetPlatformPluginNameAtIndex(idx - 1);
|
2021-10-22 03:00:33 +08:00
|
|
|
if (plugin_name.empty()) {
|
2022-01-10 14:54:08 +08:00
|
|
|
return data;
|
2017-08-09 17:20:40 +08:00
|
|
|
}
|
|
|
|
platform_dict->AddStringItem(name_str, llvm::StringRef(plugin_name));
|
|
|
|
|
2021-10-22 03:00:33 +08:00
|
|
|
llvm::StringRef plugin_desc =
|
2017-08-09 17:20:40 +08:00
|
|
|
PluginManager::GetPlatformPluginDescriptionAtIndex(idx - 1);
|
|
|
|
platform_dict->AddStringItem(desc_str, llvm::StringRef(plugin_desc));
|
|
|
|
}
|
|
|
|
|
|
|
|
data.m_impl_up->SetObjectSP(
|
|
|
|
StructuredData::ObjectSP(platform_dict.release()));
|
2022-01-10 14:54:08 +08:00
|
|
|
return data;
|
2017-08-09 17:20:40 +08:00
|
|
|
}
|
|
|
|
|
2010-11-20 04:47:54 +08:00
|
|
|
void SBDebugger::DispatchInput(void *baton, const void *data, size_t data_len) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, baton, data, data_len);
|
2019-03-09 03:09:27 +08:00
|
|
|
|
2012-08-21 00:21:04 +08:00
|
|
|
DispatchInput(data, data_len);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-11-20 04:47:54 +08:00
|
|
|
void SBDebugger::DispatchInput(const void *data, size_t data_len) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, data, data_len);
|
2019-03-09 03:09:27 +08:00
|
|
|
|
2022-01-31 22:57:48 +08:00
|
|
|
// Log *log(GetLog (LLDBLog::API));
|
2016-09-07 04:57:50 +08:00
|
|
|
//
|
2014-01-28 07:43:24 +08:00
|
|
|
// if (log)
|
2019-07-25 01:56:10 +08:00
|
|
|
// LLDB_LOGF(log, "SBDebugger(%p)::DispatchInput (data=\"%.*s\",
|
2014-01-28 07:43:24 +08:00
|
|
|
// size_t=%" PRIu64 ")",
|
|
|
|
// m_opaque_sp.get(),
|
|
|
|
// (int) data_len,
|
|
|
|
// (const char *) data,
|
|
|
|
// (uint64_t)data_len);
|
2016-09-07 04:57:50 +08:00
|
|
|
//
|
2010-11-20 04:47:54 +08:00
|
|
|
// if (m_opaque_sp)
|
|
|
|
// m_opaque_sp->DispatchInput ((const char *) data, data_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBDebugger::DispatchInputInterrupt() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-11-20 04:47:54 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->DispatchInputInterrupt();
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void SBDebugger::DispatchInputEndOfFile() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->DispatchInputEndOfFile();
|
|
|
|
}
|
2010-06-23 09:19:29 +08:00
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
void SBDebugger::PushInputReader(SBInputReader &reader) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, reader);
|
2019-03-06 08:06:00 +08:00
|
|
|
}
|
2014-10-11 08:38:27 +08:00
|
|
|
|
|
|
|
void SBDebugger::RunCommandInterpreter(bool auto_handle_events,
|
2014-01-28 07:43:24 +08:00
|
|
|
bool spawn_thread) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, auto_handle_events, spawn_thread);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_sp) {
|
2014-10-11 08:38:27 +08:00
|
|
|
CommandInterpreterRunOptions options;
|
2020-05-01 04:17:48 +08:00
|
|
|
options.SetAutoHandleEvents(auto_handle_events);
|
|
|
|
options.SetSpawnThread(spawn_thread);
|
|
|
|
m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(options);
|
2014-10-11 08:38:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBDebugger::RunCommandInterpreter(bool auto_handle_events,
|
|
|
|
bool spawn_thread,
|
|
|
|
SBCommandInterpreterRunOptions &options,
|
2014-10-14 09:20:07 +08:00
|
|
|
int &num_errors, bool &quit_requested,
|
|
|
|
bool &stopped_for_crash)
|
2014-10-11 08:38:27 +08:00
|
|
|
|
|
|
|
{
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, auto_handle_events, spawn_thread, options,
|
|
|
|
num_errors, quit_requested, stopped_for_crash);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2014-10-11 08:38:27 +08:00
|
|
|
if (m_opaque_sp) {
|
2020-05-01 04:17:48 +08:00
|
|
|
options.SetAutoHandleEvents(auto_handle_events);
|
|
|
|
options.SetSpawnThread(spawn_thread);
|
2014-10-11 08:38:27 +08:00
|
|
|
CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();
|
2020-05-02 02:29:07 +08:00
|
|
|
CommandInterpreterRunResult result =
|
|
|
|
interp.RunCommandInterpreter(options.ref());
|
|
|
|
num_errors = result.GetNumErrors();
|
|
|
|
quit_requested =
|
|
|
|
result.IsResult(lldb::eCommandInterpreterResultQuitRequested);
|
|
|
|
stopped_for_crash =
|
|
|
|
result.IsResult(lldb::eCommandInterpreterResultInferiorCrash);
|
2014-10-11 08:38:27 +08:00
|
|
|
}
|
This patch captures and serializes all output being written by the
command line driver, including the lldb prompt being output by
editline, the asynchronous process output & error messages, and
asynchronous messages written by target stop-hooks.
As part of this it introduces a new Stream class,
StreamAsynchronousIO. A StreamAsynchronousIO object is created with a
broadcaster, who will eventually broadcast the stream's data for a
listener to handle, and an event type indicating what type of event
the broadcaster will broadcast. When the Write method is called on a
StreamAsynchronousIO object, the data is appended to an internal
string. When the Flush method is called on a StreamAsynchronousIO
object, it broadcasts it's data string and clears the string.
Anything in lldb-core that needs to generate asynchronous output for
the end-user should use the StreamAsynchronousIO objects.
I have also added a new notification type for InputReaders, to let
them know that a asynchronous output has been written. This is to
allow the input readers to, for example, refresh their prompts and
lines, if desired. I added the case statements to all the input
readers to catch this notification, but I haven't added any code for
handling them yet (except to the IOChannel input reader).
llvm-svn: 130721
2011-05-03 04:41:46 +08:00
|
|
|
}
|
|
|
|
|
2020-05-02 04:23:51 +08:00
|
|
|
SBCommandInterpreterRunResult SBDebugger::RunCommandInterpreter(
|
|
|
|
const SBCommandInterpreterRunOptions &options) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, options);
|
2020-05-02 04:23:51 +08:00
|
|
|
|
|
|
|
if (!m_opaque_sp)
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBCommandInterpreterRunResult();
|
2020-05-02 04:23:51 +08:00
|
|
|
|
|
|
|
CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();
|
|
|
|
CommandInterpreterRunResult result =
|
|
|
|
interp.RunCommandInterpreter(options.ref());
|
|
|
|
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBCommandInterpreterRunResult(result);
|
2020-05-02 04:23:51 +08:00
|
|
|
}
|
|
|
|
|
2015-10-20 08:23:46 +08:00
|
|
|
SBError SBDebugger::RunREPL(lldb::LanguageType language,
|
|
|
|
const char *repl_options) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, language, repl_options);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-20 08:23:46 +08:00
|
|
|
SBError error;
|
|
|
|
if (m_opaque_sp)
|
|
|
|
error.ref() = m_opaque_sp->RunREPL(language, repl_options);
|
|
|
|
else
|
|
|
|
error.SetErrorString("invalid debugger");
|
2022-01-10 14:54:08 +08:00
|
|
|
return error;
|
2015-10-20 08:23:46 +08:00
|
|
|
}
|
|
|
|
|
2011-04-19 07:15:17 +08:00
|
|
|
void SBDebugger::reset(const DebuggerSP &debugger_sp) {
|
2010-06-23 09:19:29 +08:00
|
|
|
m_opaque_sp = debugger_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debugger *SBDebugger::get() const { return m_opaque_sp.get(); }
|
|
|
|
|
|
|
|
Debugger &SBDebugger::ref() const {
|
|
|
|
assert(m_opaque_sp.get());
|
|
|
|
return *m_opaque_sp;
|
|
|
|
}
|
|
|
|
|
2011-10-01 10:59:24 +08:00
|
|
|
const lldb::DebuggerSP &SBDebugger::get_sp() const { return m_opaque_sp; }
|
2010-06-23 09:19:29 +08:00
|
|
|
|
2010-07-01 00:22:25 +08:00
|
|
|
SBDebugger SBDebugger::FindDebuggerWithID(int id) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(id);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-12-21 04:49:23 +08:00
|
|
|
// No need to lock, the debugger list is thread safe
|
2010-07-01 00:22:25 +08:00
|
|
|
SBDebugger sb_debugger;
|
2011-04-19 07:15:17 +08:00
|
|
|
DebuggerSP debugger_sp = Debugger::FindDebuggerWithID(id);
|
2010-07-01 00:22:25 +08:00
|
|
|
if (debugger_sp)
|
|
|
|
sb_debugger.reset(debugger_sp);
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_debugger;
|
2010-07-01 00:22:25 +08:00
|
|
|
}
|
2010-08-31 03:44:40 +08:00
|
|
|
|
2010-09-10 01:45:09 +08:00
|
|
|
const char *SBDebugger::GetInstanceName() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
return (m_opaque_sp ? m_opaque_sp->GetInstanceName().AsCString() : nullptr);
|
2010-09-10 01:45:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBError SBDebugger::SetInternalVariable(const char *var_name, const char *value,
|
|
|
|
const char *debugger_instance_name) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(var_name, value, debugger_instance_name);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-08-23 02:39:03 +08:00
|
|
|
SBError sb_error;
|
|
|
|
DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName(
|
|
|
|
ConstString(debugger_instance_name)));
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2012-08-23 02:39:03 +08:00
|
|
|
if (debugger_sp) {
|
2021-02-02 21:41:41 +08:00
|
|
|
ExecutionContext exe_ctx(
|
|
|
|
debugger_sp->GetCommandInterpreter().GetExecutionContext());
|
2012-08-23 02:39:03 +08:00
|
|
|
error = debugger_sp->SetPropertyValue(&exe_ctx, eVarSetOperationAssign,
|
|
|
|
var_name, value);
|
|
|
|
} else {
|
|
|
|
error.SetErrorStringWithFormat("invalid debugger instance name '%s'",
|
|
|
|
debugger_instance_name);
|
|
|
|
}
|
|
|
|
if (error.Fail())
|
|
|
|
sb_error.SetError(error);
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_error;
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
|
2011-04-19 07:15:17 +08:00
|
|
|
SBStringList
|
2010-09-10 01:45:09 +08:00
|
|
|
SBDebugger::GetInternalVariableValue(const char *var_name,
|
|
|
|
const char *debugger_instance_name) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(var_name, debugger_instance_name);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-08-23 02:39:03 +08:00
|
|
|
DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName(
|
|
|
|
ConstString(debugger_instance_name)));
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2012-08-23 02:39:03 +08:00
|
|
|
if (debugger_sp) {
|
2021-02-02 21:41:41 +08:00
|
|
|
ExecutionContext exe_ctx(
|
|
|
|
debugger_sp->GetCommandInterpreter().GetExecutionContext());
|
2012-08-23 02:39:03 +08:00
|
|
|
lldb::OptionValueSP value_sp(
|
|
|
|
debugger_sp->GetPropertyValue(&exe_ctx, var_name, false, error));
|
|
|
|
if (value_sp) {
|
|
|
|
StreamString value_strm;
|
|
|
|
value_sp->DumpValue(&exe_ctx, value_strm, OptionValue::eDumpOptionValue);
|
2020-01-29 03:23:46 +08:00
|
|
|
const std::string &value_str = std::string(value_strm.GetString());
|
2012-08-23 02:39:03 +08:00
|
|
|
if (!value_str.empty()) {
|
|
|
|
StringList string_list;
|
2014-01-28 07:43:24 +08:00
|
|
|
string_list.SplitIntoLines(value_str);
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBStringList(&string_list);
|
2012-08-23 02:39:03 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBStringList();
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
uint32_t SBDebugger::GetTerminalWidth() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
return (m_opaque_sp ? m_opaque_sp->GetTerminalWidth() : 0);
|
2010-09-18 09:14:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBDebugger::SetTerminalWidth(uint32_t term_width) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, term_width);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-09-18 09:14:36 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->SetTerminalWidth(term_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBDebugger::GetPrompt() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::API);
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "SBDebugger(%p)::GetPrompt () => \"%s\"",
|
|
|
|
static_cast<void *>(m_opaque_sp.get()),
|
|
|
|
(m_opaque_sp ? m_opaque_sp->GetPrompt().str().c_str() : ""));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-24 02:06:53 +08:00
|
|
|
return (m_opaque_sp ? ConstString(m_opaque_sp->GetPrompt()).GetCString()
|
|
|
|
: nullptr);
|
2010-09-18 09:14:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBDebugger::SetPrompt(const char *prompt) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, prompt);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-09-18 09:14:36 +08:00
|
|
|
if (m_opaque_sp)
|
2021-05-18 15:03:28 +08:00
|
|
|
m_opaque_sp->SetPrompt(llvm::StringRef(prompt));
|
2010-09-18 09:14:36 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-14 03:18:16 +08:00
|
|
|
const char *SBDebugger::GetReproducerPath() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2018-11-14 03:18:16 +08:00
|
|
|
return (m_opaque_sp
|
|
|
|
? ConstString(m_opaque_sp->GetReproducerPath()).GetCString()
|
|
|
|
: nullptr);
|
|
|
|
}
|
|
|
|
|
2010-09-18 09:14:36 +08:00
|
|
|
ScriptLanguage SBDebugger::GetScriptLanguage() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
return (m_opaque_sp ? m_opaque_sp->GetScriptLanguage() : eScriptLanguageNone);
|
2010-09-18 09:14:36 +08:00
|
|
|
}
|
|
|
|
|
2011-04-19 07:15:17 +08:00
|
|
|
void SBDebugger::SetScriptLanguage(ScriptLanguage script_lang) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, script_lang);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2010-09-18 09:14:36 +08:00
|
|
|
if (m_opaque_sp) {
|
|
|
|
m_opaque_sp->SetScriptLanguage(script_lang);
|
2010-12-21 04:49:23 +08:00
|
|
|
}
|
2010-09-18 09:14:36 +08:00
|
|
|
}
|
|
|
|
|
2022-01-06 06:42:21 +08:00
|
|
|
LanguageType SBDebugger::GetREPLLanguage() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2022-01-06 06:42:21 +08:00
|
|
|
|
|
|
|
return (m_opaque_sp ? m_opaque_sp->GetREPLLanguage() : eLanguageTypeUnknown);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SBDebugger::SetREPLLanguage(LanguageType repl_lang) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, repl_lang);
|
2022-01-06 06:42:21 +08:00
|
|
|
|
|
|
|
if (m_opaque_sp) {
|
|
|
|
m_opaque_sp->SetREPLLanguage(repl_lang);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
bool SBDebugger::SetUseExternalEditor(bool value) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, value);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
return (m_opaque_sp ? m_opaque_sp->SetUseExternalEditor(value) : false);
|
2010-08-31 03:44:40 +08:00
|
|
|
}
|
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
bool SBDebugger::GetUseExternalEditor() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
return (m_opaque_sp ? m_opaque_sp->GetUseExternalEditor() : false);
|
2010-08-31 03:44:40 +08:00
|
|
|
}
|
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
bool SBDebugger::SetUseColor(bool value) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, value);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
return (m_opaque_sp ? m_opaque_sp->SetUseColor(value) : false);
|
2013-05-24 04:47:45 +08:00
|
|
|
}
|
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
bool SBDebugger::GetUseColor() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
return (m_opaque_sp ? m_opaque_sp->GetUseColor() : false);
|
2013-05-24 04:47:45 +08:00
|
|
|
}
|
|
|
|
|
2020-04-20 22:17:17 +08:00
|
|
|
bool SBDebugger::SetUseSourceCache(bool value) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, value);
|
2020-04-20 22:17:17 +08:00
|
|
|
|
|
|
|
return (m_opaque_sp ? m_opaque_sp->SetUseSourceCache(value) : false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBDebugger::GetUseSourceCache() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2020-04-20 22:17:17 +08:00
|
|
|
|
|
|
|
return (m_opaque_sp ? m_opaque_sp->GetUseSourceCache() : false);
|
|
|
|
}
|
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
bool SBDebugger::GetDescription(SBStream &description) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, description);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2011-11-13 14:57:31 +08:00
|
|
|
Stream &strm = description.ref();
|
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
if (m_opaque_sp) {
|
|
|
|
const char *name = m_opaque_sp->GetInstanceName().AsCString();
|
2011-04-19 07:15:17 +08:00
|
|
|
user_id_t id = m_opaque_sp->GetID();
|
2012-11-30 05:49:15 +08:00
|
|
|
strm.Printf("Debugger (instance: \"%s\", id: %" PRIu64 ")", name, id);
|
2010-09-20 13:20:02 +08:00
|
|
|
} else
|
2011-11-13 14:57:31 +08:00
|
|
|
strm.PutCString("No value");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-09-20 13:20:02 +08:00
|
|
|
return true;
|
|
|
|
}
|
2010-11-20 04:47:54 +08:00
|
|
|
|
|
|
|
user_id_t SBDebugger::GetID() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
return (m_opaque_sp ? m_opaque_sp->GetID() : LLDB_INVALID_UID);
|
2010-11-20 04:47:54 +08:00
|
|
|
}
|
2011-04-30 09:09:13 +08:00
|
|
|
|
2014-09-20 04:11:50 +08:00
|
|
|
SBError SBDebugger::SetCurrentPlatform(const char *platform_name_cstr) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, platform_name_cstr);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2011-04-30 09:09:13 +08:00
|
|
|
SBError sb_error;
|
|
|
|
if (m_opaque_sp) {
|
2014-09-20 04:11:50 +08:00
|
|
|
if (platform_name_cstr && platform_name_cstr[0]) {
|
2022-03-10 01:12:28 +08:00
|
|
|
ConstString platform_name(platform_name_cstr);
|
|
|
|
PlatformSP platform_sp(Platform::Find(platform_name));
|
|
|
|
|
|
|
|
if (platform_sp) {
|
|
|
|
// Already have a platform with this name, just select it
|
|
|
|
m_opaque_sp->GetPlatformList().SetSelectedPlatform(platform_sp);
|
|
|
|
} else {
|
|
|
|
// We don't have a platform by this name yet, create one
|
|
|
|
platform_sp = Platform::Create(platform_name, sb_error.ref());
|
|
|
|
if (platform_sp) {
|
|
|
|
// We created the platform, now append and select it
|
|
|
|
bool make_selected = true;
|
|
|
|
m_opaque_sp->GetPlatformList().Append(platform_sp, make_selected);
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2014-09-20 04:11:50 +08:00
|
|
|
sb_error.ref().SetErrorString("invalid platform name");
|
2011-04-30 09:09:13 +08:00
|
|
|
}
|
2014-09-20 04:11:50 +08:00
|
|
|
} else {
|
|
|
|
sb_error.ref().SetErrorString("invalid debugger");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2022-01-10 14:54:08 +08:00
|
|
|
return sb_error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-06-17 11:31:01 +08:00
|
|
|
bool SBDebugger::SetCurrentPlatformSDKRoot(const char *sysroot) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, sysroot);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2022-01-18 18:26:07 +08:00
|
|
|
if (SBPlatform platform = GetSelectedPlatform()) {
|
|
|
|
platform.SetSDKRoot(sysroot);
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-04-30 09:09:13 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-17 11:31:01 +08:00
|
|
|
bool SBDebugger::GetCloseInputOnEOF() const {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2011-06-17 11:31:01 +08:00
|
|
|
return (m_opaque_sp ? m_opaque_sp->GetCloseInputOnEOF() : false);
|
|
|
|
}
|
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
void SBDebugger::SetCloseInputOnEOF(bool b) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, b);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
m_opaque_sp->SetCloseInputOnEOF(b);
|
2011-05-29 12:06:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBTypeCategory SBDebugger::GetCategory(const char *category_name) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, category_name);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2011-05-29 12:06:55 +08:00
|
|
|
if (!category_name || *category_name == 0)
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBTypeCategory();
|
2012-02-15 10:34:21 +08:00
|
|
|
|
|
|
|
TypeCategoryImplSP category_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-15 10:34:21 +08:00
|
|
|
if (DataVisualization::Categories::GetCategory(ConstString(category_name),
|
2019-03-06 08:06:00 +08:00
|
|
|
category_sp, false)) {
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBTypeCategory(category_sp);
|
2019-03-06 08:06:00 +08:00
|
|
|
} else {
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBTypeCategory();
|
2019-03-06 08:06:00 +08:00
|
|
|
}
|
2012-02-15 10:34:21 +08:00
|
|
|
}
|
|
|
|
|
2015-12-19 05:25:24 +08:00
|
|
|
SBTypeCategory SBDebugger::GetCategory(lldb::LanguageType lang_type) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, lang_type);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-12-19 05:25:24 +08:00
|
|
|
TypeCategoryImplSP category_sp;
|
2019-03-06 08:06:00 +08:00
|
|
|
if (DataVisualization::Categories::GetCategory(lang_type, category_sp)) {
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBTypeCategory(category_sp);
|
2019-03-06 08:06:00 +08:00
|
|
|
} else {
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBTypeCategory();
|
2019-03-06 08:06:00 +08:00
|
|
|
}
|
2015-12-19 05:25:24 +08:00
|
|
|
}
|
|
|
|
|
2012-02-15 10:34:21 +08:00
|
|
|
SBTypeCategory SBDebugger::CreateCategory(const char *category_name) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, category_name);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-02-15 10:34:21 +08:00
|
|
|
if (!category_name || *category_name == 0)
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBTypeCategory();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-15 10:34:21 +08:00
|
|
|
TypeCategoryImplSP category_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-15 10:34:21 +08:00
|
|
|
if (DataVisualization::Categories::GetCategory(ConstString(category_name),
|
2019-03-06 08:06:00 +08:00
|
|
|
category_sp, true)) {
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBTypeCategory(category_sp);
|
2019-03-06 08:06:00 +08:00
|
|
|
} else {
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBTypeCategory();
|
2019-03-06 08:06:00 +08:00
|
|
|
}
|
2012-02-15 10:34:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SBDebugger::DeleteCategory(const char *category_name) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, category_name);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-02-15 10:34:21 +08:00
|
|
|
if (!category_name || *category_name == 0)
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-15 10:34:21 +08:00
|
|
|
return DataVisualization::Categories::Delete(ConstString(category_name));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SBDebugger::GetNumCategories() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-02-15 10:34:21 +08:00
|
|
|
return DataVisualization::Categories::GetCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
SBTypeCategory SBDebugger::GetCategoryAtIndex(uint32_t index) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, index);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBTypeCategory(
|
|
|
|
DataVisualization::Categories::GetCategoryAtIndex(index));
|
2012-02-15 10:34:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBTypeCategory SBDebugger::GetDefaultCategory() {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2022-01-10 14:54:08 +08:00
|
|
|
return GetCategory("default");
|
2012-02-15 10:34:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBTypeFormat SBDebugger::GetFormatForType(SBTypeNameSpecifier type_name) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, type_name);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-02-15 10:34:21 +08:00
|
|
|
SBTypeCategory default_category_sb = GetDefaultCategory();
|
|
|
|
if (default_category_sb.GetEnabled())
|
2022-01-10 14:54:08 +08:00
|
|
|
return default_category_sb.GetFormatForType(type_name);
|
|
|
|
return SBTypeFormat();
|
2012-02-15 10:34:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBTypeSummary SBDebugger::GetSummaryForType(SBTypeNameSpecifier type_name) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, type_name);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
if (!type_name.IsValid())
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBTypeSummary();
|
|
|
|
return SBTypeSummary(DataVisualization::GetSummaryForType(type_name.GetSP()));
|
2012-02-15 10:34:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBTypeFilter SBDebugger::GetFilterForType(SBTypeNameSpecifier type_name) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, type_name);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
if (!type_name.IsValid())
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBTypeFilter();
|
|
|
|
return SBTypeFilter(DataVisualization::GetFilterForType(type_name.GetSP()));
|
2012-02-15 10:34:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBTypeSynthetic SBDebugger::GetSyntheticForType(SBTypeNameSpecifier type_name) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, type_name);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2015-10-31 09:22:59 +08:00
|
|
|
if (!type_name.IsValid())
|
2022-01-10 14:54:08 +08:00
|
|
|
return SBTypeSynthetic();
|
|
|
|
return SBTypeSynthetic(
|
|
|
|
DataVisualization::GetSyntheticForType(type_name.GetSP()));
|
2012-02-15 10:34:21 +08:00
|
|
|
}
|
|
|
|
|
2017-03-01 18:08:40 +08:00
|
|
|
static llvm::ArrayRef<const char *> GetCategoryArray(const char **categories) {
|
|
|
|
if (categories == nullptr)
|
|
|
|
return {};
|
|
|
|
size_t len = 0;
|
|
|
|
while (categories[len] != nullptr)
|
|
|
|
++len;
|
|
|
|
return llvm::makeArrayRef(categories, len);
|
|
|
|
}
|
|
|
|
|
2012-02-21 10:23:08 +08:00
|
|
|
bool SBDebugger::EnableLog(const char *channel, const char **categories) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, channel, categories);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
2012-02-21 10:23:08 +08:00
|
|
|
if (m_opaque_sp) {
|
|
|
|
uint32_t log_options =
|
|
|
|
LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
|
2017-03-15 17:06:58 +08:00
|
|
|
std::string error;
|
|
|
|
llvm::raw_string_ostream error_stream(error);
|
2017-03-01 18:08:40 +08:00
|
|
|
return m_opaque_sp->EnableLog(channel, GetCategoryArray(categories), "",
|
2017-03-15 17:06:58 +08:00
|
|
|
log_options, error_stream);
|
2012-02-21 10:23:08 +08:00
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
2012-02-23 06:49:20 +08:00
|
|
|
|
|
|
|
void SBDebugger::SetLoggingCallback(lldb::LogOutputCallback log_callback,
|
|
|
|
void *baton) {
|
2022-01-20 03:38:26 +08:00
|
|
|
LLDB_INSTRUMENT_VA(this, log_callback, baton);
|
2019-03-09 03:09:27 +08:00
|
|
|
|
2012-02-23 06:49:20 +08:00
|
|
|
if (m_opaque_sp) {
|
|
|
|
return m_opaque_sp->SetLoggingCallback(log_callback, baton);
|
|
|
|
}
|
|
|
|
}
|