mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-21 17:46:51 +00:00
[LLDB][NFC] Remove Debugger dependency in SystemLifetimeManager (#134383)
It reduces the memory usage in lldb-server.
This commit is contained in:
parent
3b84b1e163
commit
7e70d708a3
lldb
include/lldb
source
tools
@ -16,6 +16,7 @@
|
||||
|
||||
namespace lldb_private {
|
||||
class CommandPluginInterfaceImplementation;
|
||||
class SystemInitializerFull;
|
||||
namespace python {
|
||||
class SWIGBridge;
|
||||
}
|
||||
@ -508,6 +509,7 @@ public:
|
||||
protected:
|
||||
friend class lldb_private::CommandPluginInterfaceImplementation;
|
||||
friend class lldb_private::python::SWIGBridge;
|
||||
friend class lldb_private::SystemInitializerFull;
|
||||
|
||||
SBDebugger(const lldb::DebuggerSP &debugger_sp);
|
||||
|
||||
|
@ -23,8 +23,7 @@ public:
|
||||
SystemLifetimeManager();
|
||||
~SystemLifetimeManager();
|
||||
|
||||
llvm::Error Initialize(std::unique_ptr<SystemInitializer> initializer,
|
||||
LoadPluginCallbackType plugin_callback);
|
||||
llvm::Error Initialize(std::unique_ptr<SystemInitializer> initializer);
|
||||
void Terminate();
|
||||
|
||||
private:
|
||||
|
@ -179,48 +179,9 @@ void SBDebugger::Initialize() {
|
||||
lldb::SBError SBDebugger::InitializeWithErrorHandling() {
|
||||
LLDB_INSTRUMENT();
|
||||
|
||||
auto LoadPlugin = [](const lldb::DebuggerSP &debugger_sp,
|
||||
const FileSpec &spec,
|
||||
Status &error) -> llvm::sys::DynamicLibrary {
|
||||
llvm::sys::DynamicLibrary dynlib =
|
||||
llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
|
||||
if (dynlib.isValid()) {
|
||||
typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger debugger);
|
||||
|
||||
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
|
||||
LLDBCommandPluginInit init_func =
|
||||
(LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol(
|
||||
"_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
|
||||
if (init_func) {
|
||||
if (init_func(debugger_sb))
|
||||
return dynlib;
|
||||
else
|
||||
error = Status::FromErrorString(
|
||||
"plug-in refused to load "
|
||||
"(lldb::PluginInitialize(lldb::SBDebugger) "
|
||||
"returned false)");
|
||||
} else {
|
||||
error = Status::FromErrorString(
|
||||
"plug-in is missing the required initialization: "
|
||||
"lldb::PluginInitialize(lldb::SBDebugger)");
|
||||
}
|
||||
} else {
|
||||
if (FileSystem::Instance().Exists(spec))
|
||||
error = Status::FromErrorString(
|
||||
"this file does not represent a loadable dylib");
|
||||
else
|
||||
error = Status::FromErrorString("no such file");
|
||||
}
|
||||
return llvm::sys::DynamicLibrary();
|
||||
};
|
||||
|
||||
SBError error;
|
||||
if (auto e = g_debugger_lifetime->Initialize(
|
||||
std::make_unique<SystemInitializerFull>(), LoadPlugin)) {
|
||||
std::make_unique<SystemInitializerFull>())) {
|
||||
error.SetError(Status::FromError(std::move(e)));
|
||||
}
|
||||
return error;
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "SystemInitializerFull.h"
|
||||
#include "lldb/API/SBCommandInterpreter.h"
|
||||
#include "lldb/API/SBDebugger.h"
|
||||
#include "lldb/Core/Debugger.h"
|
||||
#include "lldb/Core/PluginManager.h"
|
||||
#include "lldb/Core/Progress.h"
|
||||
@ -86,10 +87,53 @@ llvm::Error SystemInitializerFull::Initialize() {
|
||||
|
||||
LLDB_LOG(GetLog(SystemLog::System), "{0}", GetVersion());
|
||||
|
||||
auto LoadPlugin = [](const lldb::DebuggerSP &debugger_sp,
|
||||
const FileSpec &spec,
|
||||
Status &error) -> llvm::sys::DynamicLibrary {
|
||||
llvm::sys::DynamicLibrary dynlib =
|
||||
llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
|
||||
if (dynlib.isValid()) {
|
||||
typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger debugger);
|
||||
|
||||
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
|
||||
LLDBCommandPluginInit init_func =
|
||||
(LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol(
|
||||
"_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
|
||||
if (init_func) {
|
||||
if (init_func(debugger_sb))
|
||||
return dynlib;
|
||||
else
|
||||
error = Status::FromErrorString(
|
||||
"plug-in refused to load "
|
||||
"(lldb::PluginInitialize(lldb::SBDebugger) "
|
||||
"returned false)");
|
||||
} else {
|
||||
error = Status::FromErrorString(
|
||||
"plug-in is missing the required initialization: "
|
||||
"lldb::PluginInitialize(lldb::SBDebugger)");
|
||||
}
|
||||
} else {
|
||||
if (FileSystem::Instance().Exists(spec))
|
||||
error = Status::FromErrorString(
|
||||
"this file does not represent a loadable dylib");
|
||||
else
|
||||
error = Status::FromErrorString("no such file");
|
||||
}
|
||||
return llvm::sys::DynamicLibrary();
|
||||
};
|
||||
|
||||
Debugger::Initialize(LoadPlugin);
|
||||
|
||||
return llvm::Error::success();
|
||||
}
|
||||
|
||||
void SystemInitializerFull::Terminate() {
|
||||
Debugger::Terminate();
|
||||
|
||||
Debugger::SettingsTerminate();
|
||||
|
||||
// Terminate plug-ins in core LLDB.
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include "lldb/Initialization/SystemLifetimeManager.h"
|
||||
|
||||
#include "lldb/Core/Debugger.h"
|
||||
#include "lldb/Initialization/SystemInitializer.h"
|
||||
|
||||
#include <utility>
|
||||
@ -23,8 +22,7 @@ SystemLifetimeManager::~SystemLifetimeManager() {
|
||||
}
|
||||
|
||||
llvm::Error SystemLifetimeManager::Initialize(
|
||||
std::unique_ptr<SystemInitializer> initializer,
|
||||
LoadPluginCallbackType plugin_callback) {
|
||||
std::unique_ptr<SystemInitializer> initializer) {
|
||||
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
||||
if (!m_initialized) {
|
||||
assert(!m_initializer && "Attempting to call "
|
||||
@ -35,8 +33,6 @@ llvm::Error SystemLifetimeManager::Initialize(
|
||||
|
||||
if (auto e = m_initializer->Initialize())
|
||||
return e;
|
||||
|
||||
Debugger::Initialize(plugin_callback);
|
||||
}
|
||||
|
||||
return llvm::Error::success();
|
||||
@ -46,7 +42,6 @@ void SystemLifetimeManager::Terminate() {
|
||||
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
||||
|
||||
if (m_initialized) {
|
||||
Debugger::Terminate();
|
||||
m_initializer->Terminate();
|
||||
|
||||
m_initializer.reset();
|
||||
|
@ -41,7 +41,7 @@ int main_platform(int argc, char *argv[]);
|
||||
namespace llgs {
|
||||
static void initialize() {
|
||||
if (auto e = g_debugger_lifetime->Initialize(
|
||||
std::make_unique<SystemInitializerLLGS>(), nullptr))
|
||||
std::make_unique<SystemInitializerLLGS>()))
|
||||
llvm::consumeError(std::move(e));
|
||||
}
|
||||
|
||||
|
@ -51,10 +51,14 @@ llvm::Error SystemInitializerTest::Initialize() {
|
||||
// Settings must be initialized AFTER PluginManager::Initialize is called.
|
||||
Debugger::SettingsInitialize();
|
||||
|
||||
Debugger::Initialize(nullptr);
|
||||
|
||||
return llvm::Error::success();
|
||||
}
|
||||
|
||||
void SystemInitializerTest::Terminate() {
|
||||
Debugger::Terminate();
|
||||
|
||||
Debugger::SettingsTerminate();
|
||||
|
||||
// Terminate and unload and loaded system or user LLDB plug-ins
|
||||
|
@ -1247,7 +1247,7 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
SystemLifetimeManager DebuggerLifetime;
|
||||
if (auto e = DebuggerLifetime.Initialize(
|
||||
std::make_unique<SystemInitializerTest>(), nullptr)) {
|
||||
std::make_unique<SystemInitializerTest>())) {
|
||||
WithColor::error() << "initialization failed: " << toString(std::move(e))
|
||||
<< '\n';
|
||||
return 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user