[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
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
namespace lldb_private {
|
namespace lldb_private {
|
||||||
class CommandPluginInterfaceImplementation;
|
class CommandPluginInterfaceImplementation;
|
||||||
|
class SystemInitializerFull;
|
||||||
namespace python {
|
namespace python {
|
||||||
class SWIGBridge;
|
class SWIGBridge;
|
||||||
}
|
}
|
||||||
@ -508,6 +509,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
friend class lldb_private::CommandPluginInterfaceImplementation;
|
friend class lldb_private::CommandPluginInterfaceImplementation;
|
||||||
friend class lldb_private::python::SWIGBridge;
|
friend class lldb_private::python::SWIGBridge;
|
||||||
|
friend class lldb_private::SystemInitializerFull;
|
||||||
|
|
||||||
SBDebugger(const lldb::DebuggerSP &debugger_sp);
|
SBDebugger(const lldb::DebuggerSP &debugger_sp);
|
||||||
|
|
||||||
|
@ -23,8 +23,7 @@ public:
|
|||||||
SystemLifetimeManager();
|
SystemLifetimeManager();
|
||||||
~SystemLifetimeManager();
|
~SystemLifetimeManager();
|
||||||
|
|
||||||
llvm::Error Initialize(std::unique_ptr<SystemInitializer> initializer,
|
llvm::Error Initialize(std::unique_ptr<SystemInitializer> initializer);
|
||||||
LoadPluginCallbackType plugin_callback);
|
|
||||||
void Terminate();
|
void Terminate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -179,48 +179,9 @@ void SBDebugger::Initialize() {
|
|||||||
lldb::SBError SBDebugger::InitializeWithErrorHandling() {
|
lldb::SBError SBDebugger::InitializeWithErrorHandling() {
|
||||||
LLDB_INSTRUMENT();
|
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;
|
SBError error;
|
||||||
if (auto e = g_debugger_lifetime->Initialize(
|
if (auto e = g_debugger_lifetime->Initialize(
|
||||||
std::make_unique<SystemInitializerFull>(), LoadPlugin)) {
|
std::make_unique<SystemInitializerFull>())) {
|
||||||
error.SetError(Status::FromError(std::move(e)));
|
error.SetError(Status::FromError(std::move(e)));
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "SystemInitializerFull.h"
|
#include "SystemInitializerFull.h"
|
||||||
#include "lldb/API/SBCommandInterpreter.h"
|
#include "lldb/API/SBCommandInterpreter.h"
|
||||||
|
#include "lldb/API/SBDebugger.h"
|
||||||
#include "lldb/Core/Debugger.h"
|
#include "lldb/Core/Debugger.h"
|
||||||
#include "lldb/Core/PluginManager.h"
|
#include "lldb/Core/PluginManager.h"
|
||||||
#include "lldb/Core/Progress.h"
|
#include "lldb/Core/Progress.h"
|
||||||
@ -86,10 +87,53 @@ llvm::Error SystemInitializerFull::Initialize() {
|
|||||||
|
|
||||||
LLDB_LOG(GetLog(SystemLog::System), "{0}", GetVersion());
|
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();
|
return llvm::Error::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemInitializerFull::Terminate() {
|
void SystemInitializerFull::Terminate() {
|
||||||
|
Debugger::Terminate();
|
||||||
|
|
||||||
Debugger::SettingsTerminate();
|
Debugger::SettingsTerminate();
|
||||||
|
|
||||||
// Terminate plug-ins in core LLDB.
|
// Terminate plug-ins in core LLDB.
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include "lldb/Initialization/SystemLifetimeManager.h"
|
#include "lldb/Initialization/SystemLifetimeManager.h"
|
||||||
|
|
||||||
#include "lldb/Core/Debugger.h"
|
|
||||||
#include "lldb/Initialization/SystemInitializer.h"
|
#include "lldb/Initialization/SystemInitializer.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@ -23,8 +22,7 @@ SystemLifetimeManager::~SystemLifetimeManager() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
llvm::Error SystemLifetimeManager::Initialize(
|
llvm::Error SystemLifetimeManager::Initialize(
|
||||||
std::unique_ptr<SystemInitializer> initializer,
|
std::unique_ptr<SystemInitializer> initializer) {
|
||||||
LoadPluginCallbackType plugin_callback) {
|
|
||||||
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
||||||
if (!m_initialized) {
|
if (!m_initialized) {
|
||||||
assert(!m_initializer && "Attempting to call "
|
assert(!m_initializer && "Attempting to call "
|
||||||
@ -35,8 +33,6 @@ llvm::Error SystemLifetimeManager::Initialize(
|
|||||||
|
|
||||||
if (auto e = m_initializer->Initialize())
|
if (auto e = m_initializer->Initialize())
|
||||||
return e;
|
return e;
|
||||||
|
|
||||||
Debugger::Initialize(plugin_callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return llvm::Error::success();
|
return llvm::Error::success();
|
||||||
@ -46,7 +42,6 @@ void SystemLifetimeManager::Terminate() {
|
|||||||
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
std::lock_guard<std::recursive_mutex> guard(m_mutex);
|
||||||
|
|
||||||
if (m_initialized) {
|
if (m_initialized) {
|
||||||
Debugger::Terminate();
|
|
||||||
m_initializer->Terminate();
|
m_initializer->Terminate();
|
||||||
|
|
||||||
m_initializer.reset();
|
m_initializer.reset();
|
||||||
|
@ -41,7 +41,7 @@ int main_platform(int argc, char *argv[]);
|
|||||||
namespace llgs {
|
namespace llgs {
|
||||||
static void initialize() {
|
static void initialize() {
|
||||||
if (auto e = g_debugger_lifetime->Initialize(
|
if (auto e = g_debugger_lifetime->Initialize(
|
||||||
std::make_unique<SystemInitializerLLGS>(), nullptr))
|
std::make_unique<SystemInitializerLLGS>()))
|
||||||
llvm::consumeError(std::move(e));
|
llvm::consumeError(std::move(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,10 +51,14 @@ llvm::Error SystemInitializerTest::Initialize() {
|
|||||||
// Settings must be initialized AFTER PluginManager::Initialize is called.
|
// Settings must be initialized AFTER PluginManager::Initialize is called.
|
||||||
Debugger::SettingsInitialize();
|
Debugger::SettingsInitialize();
|
||||||
|
|
||||||
|
Debugger::Initialize(nullptr);
|
||||||
|
|
||||||
return llvm::Error::success();
|
return llvm::Error::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemInitializerTest::Terminate() {
|
void SystemInitializerTest::Terminate() {
|
||||||
|
Debugger::Terminate();
|
||||||
|
|
||||||
Debugger::SettingsTerminate();
|
Debugger::SettingsTerminate();
|
||||||
|
|
||||||
// Terminate and unload and loaded system or user LLDB plug-ins
|
// Terminate and unload and loaded system or user LLDB plug-ins
|
||||||
|
@ -1247,7 +1247,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
|
|
||||||
SystemLifetimeManager DebuggerLifetime;
|
SystemLifetimeManager DebuggerLifetime;
|
||||||
if (auto e = DebuggerLifetime.Initialize(
|
if (auto e = DebuggerLifetime.Initialize(
|
||||||
std::make_unique<SystemInitializerTest>(), nullptr)) {
|
std::make_unique<SystemInitializerTest>())) {
|
||||||
WithColor::error() << "initialization failed: " << toString(std::move(e))
|
WithColor::error() << "initialization failed: " << toString(std::move(e))
|
||||||
<< '\n';
|
<< '\n';
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user