https://github.com/slydiman created https://github.com/llvm/llvm-project/pull/134383
It reduces the memory usage in lldb-server. Later I will try to remove the rest Debugger dependencies to reduce lldb-server size. >From 629601c6c1e974e7981d2e61583c69540bf1cd5c Mon Sep 17 00:00:00 2001 From: Dmitry Vasilyev <dvassil...@accesssoftek.com> Date: Fri, 4 Apr 2025 17:49:07 +0400 Subject: [PATCH] [LLDB][NFC] Remove Debugger dependency in SystemLifetimeManager It reduces the memory usage in lldb-server. Later I will try to remove the rest Debugger dependencies to reduce lldb-server size. --- .../Initialization/SystemLifetimeManager.h | 5 ++- .../Initialization/SystemLifetimeManagerDbg.h | 36 +++++++++++++++++++ lldb/source/API/SBDebugger.cpp | 4 +-- .../Initialization/SystemLifetimeManager.cpp | 5 ++- lldb/tools/lldb-test/lldb-test.cpp | 4 +-- 5 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 lldb/include/lldb/Initialization/SystemLifetimeManagerDbg.h diff --git a/lldb/include/lldb/Initialization/SystemLifetimeManager.h b/lldb/include/lldb/Initialization/SystemLifetimeManager.h index 06328e60133fe..55138b33be712 100644 --- a/lldb/include/lldb/Initialization/SystemLifetimeManager.h +++ b/lldb/include/lldb/Initialization/SystemLifetimeManager.h @@ -21,7 +21,7 @@ namespace lldb_private { class SystemLifetimeManager { public: SystemLifetimeManager(); - ~SystemLifetimeManager(); + virtual ~SystemLifetimeManager(); llvm::Error Initialize(std::unique_ptr<SystemInitializer> initializer, LoadPluginCallbackType plugin_callback); @@ -32,6 +32,9 @@ class SystemLifetimeManager { std::unique_ptr<SystemInitializer> m_initializer; bool m_initialized = false; + virtual void InitializeDebugger(LoadPluginCallbackType plugin_callback) {}; + virtual void TerminateDebugger() {}; + // Noncopyable. SystemLifetimeManager(const SystemLifetimeManager &other) = delete; SystemLifetimeManager &operator=(const SystemLifetimeManager &other) = delete; diff --git a/lldb/include/lldb/Initialization/SystemLifetimeManagerDbg.h b/lldb/include/lldb/Initialization/SystemLifetimeManagerDbg.h new file mode 100644 index 0000000000000..81e0b9a382b70 --- /dev/null +++ b/lldb/include/lldb/Initialization/SystemLifetimeManagerDbg.h @@ -0,0 +1,36 @@ +//===-- SystemLifetimeManagerDbg.h ------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_INITIALIZATION_SYSTEMLIFETIMEMANAGERDBG_H +#define LLDB_INITIALIZATION_SYSTEMLIFETIMEMANAGERDBG_H + +#include "lldb/Initialization/SystemLifetimeManager.h" +#include "lldb/Core/Debugger.h" + +namespace lldb_private { + +class SystemLifetimeManagerDbg : SystemLifetimeManager { +public: + SystemLifetimeManagerDbg() : SystemLifetimeManager() {}; + +private: + virtual void InitializeDebugger(LoadPluginCallbackType plugin_callback) override { + Debugger::Initialize(plugin_callback); + }; + + virtual void TerminateDebugger() override { + Debugger::Terminate(); + }; + + // Noncopyable. + SystemLifetimeManagerDbg(const SystemLifetimeManagerDbg &other) = delete; + SystemLifetimeManagerDbg &operator=(const SystemLifetimeManagerDbg &other) = delete; +}; +} + +#endif diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index e646b09e05852..55ccfd415ca47 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -44,7 +44,7 @@ #include "lldb/Host/Config.h" #include "lldb/Host/StreamFile.h" #include "lldb/Host/XML.h" -#include "lldb/Initialization/SystemLifetimeManager.h" +#include "lldb/Initialization/SystemLifetimeManagerDbg.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/OptionArgParser.h" #include "lldb/Interpreter/OptionGroupPlatform.h" @@ -66,7 +66,7 @@ using namespace lldb; using namespace lldb_private; -static llvm::ManagedStatic<SystemLifetimeManager> g_debugger_lifetime; +static llvm::ManagedStatic<SystemLifetimeManagerDbg> g_debugger_lifetime; SBError SBInputReader::Initialize( lldb::SBDebugger &sb_debugger, diff --git a/lldb/source/Initialization/SystemLifetimeManager.cpp b/lldb/source/Initialization/SystemLifetimeManager.cpp index f9de41a675356..b07fe71affec7 100644 --- a/lldb/source/Initialization/SystemLifetimeManager.cpp +++ b/lldb/source/Initialization/SystemLifetimeManager.cpp @@ -8,7 +8,6 @@ #include "lldb/Initialization/SystemLifetimeManager.h" -#include "lldb/Core/Debugger.h" #include "lldb/Initialization/SystemInitializer.h" #include <utility> @@ -36,7 +35,7 @@ llvm::Error SystemLifetimeManager::Initialize( if (auto e = m_initializer->Initialize()) return e; - Debugger::Initialize(plugin_callback); + InitializeDebugger(plugin_callback); } return llvm::Error::success(); @@ -46,7 +45,7 @@ void SystemLifetimeManager::Terminate() { std::lock_guard<std::recursive_mutex> guard(m_mutex); if (m_initialized) { - Debugger::Terminate(); + TerminateDebugger(); m_initializer->Terminate(); m_initializer.reset(); diff --git a/lldb/tools/lldb-test/lldb-test.cpp b/lldb/tools/lldb-test/lldb-test.cpp index 1960240dc4151..81ac0b8898d6e 100644 --- a/lldb/tools/lldb-test/lldb-test.cpp +++ b/lldb/tools/lldb-test/lldb-test.cpp @@ -17,7 +17,7 @@ #include "lldb/Core/Module.h" #include "lldb/Core/Section.h" #include "lldb/Expression/IRMemoryMap.h" -#include "lldb/Initialization/SystemLifetimeManager.h" +#include "lldb/Initialization/SystemLifetimeManagerDbg.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/CommandReturnObject.h" #include "lldb/Symbol/CompileUnit.h" @@ -1245,7 +1245,7 @@ int main(int argc, const char *argv[]) { cl::ParseCommandLineOptions(argc, argv, "LLDB Testing Utility\n"); - SystemLifetimeManager DebuggerLifetime; + SystemLifetimeManagerDbg DebuggerLifetime; if (auto e = DebuggerLifetime.Initialize( std::make_unique<SystemInitializerTest>(), nullptr)) { WithColor::error() << "initialization failed: " << toString(std::move(e)) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits