Skip to content

Commit 590d5b4

Browse files
committed
[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.
1 parent edc22c6 commit 590d5b4

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

lldb/include/lldb/Initialization/SystemLifetimeManager.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace lldb_private {
2121
class SystemLifetimeManager {
2222
public:
2323
SystemLifetimeManager();
24-
~SystemLifetimeManager();
24+
virtual ~SystemLifetimeManager();
2525

2626
llvm::Error Initialize(std::unique_ptr<SystemInitializer> initializer,
2727
LoadPluginCallbackType plugin_callback);
@@ -32,6 +32,9 @@ class SystemLifetimeManager {
3232
std::unique_ptr<SystemInitializer> m_initializer;
3333
bool m_initialized = false;
3434

35+
virtual void InitializeDebugger(LoadPluginCallbackType plugin_callback) {};
36+
virtual void TerminateDebugger() {};
37+
3538
// Noncopyable.
3639
SystemLifetimeManager(const SystemLifetimeManager &other) = delete;
3740
SystemLifetimeManager &operator=(const SystemLifetimeManager &other) = delete;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===-- SystemLifetimeManagerDbg.h ------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_INITIALIZATION_SYSTEMLIFETIMEMANAGERDBG_H
10+
#define LLDB_INITIALIZATION_SYSTEMLIFETIMEMANAGERDBG_H
11+
12+
#include "SystemLifetimeManager.h"
13+
#include "lldb/Core/Debugger.h"
14+
15+
namespace lldb_private {
16+
17+
class SystemLifetimeManagerDbg : public SystemLifetimeManager {
18+
public:
19+
SystemLifetimeManagerDbg() : SystemLifetimeManager() {};
20+
21+
private:
22+
virtual void
23+
InitializeDebugger(LoadPluginCallbackType plugin_callback) override {
24+
Debugger::Initialize(plugin_callback);
25+
};
26+
27+
virtual void TerminateDebugger() override { Debugger::Terminate(); };
28+
29+
// Noncopyable.
30+
SystemLifetimeManagerDbg(const SystemLifetimeManagerDbg &other) = delete;
31+
SystemLifetimeManagerDbg &
32+
operator=(const SystemLifetimeManagerDbg &other) = delete;
33+
};
34+
} // namespace lldb_private
35+
36+
#endif

lldb/source/API/SBDebugger.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#include "lldb/Host/Config.h"
4545
#include "lldb/Host/StreamFile.h"
4646
#include "lldb/Host/XML.h"
47-
#include "lldb/Initialization/SystemLifetimeManager.h"
47+
#include "lldb/Initialization/SystemLifetimeManagerDbg.h"
4848
#include "lldb/Interpreter/CommandInterpreter.h"
4949
#include "lldb/Interpreter/OptionArgParser.h"
5050
#include "lldb/Interpreter/OptionGroupPlatform.h"
@@ -66,7 +66,7 @@
6666
using namespace lldb;
6767
using namespace lldb_private;
6868

69-
static llvm::ManagedStatic<SystemLifetimeManager> g_debugger_lifetime;
69+
static llvm::ManagedStatic<SystemLifetimeManagerDbg> g_debugger_lifetime;
7070

7171
SBError SBInputReader::Initialize(
7272
lldb::SBDebugger &sb_debugger,

lldb/source/Initialization/SystemLifetimeManager.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "lldb/Initialization/SystemLifetimeManager.h"
1010

11-
#include "lldb/Core/Debugger.h"
1211
#include "lldb/Initialization/SystemInitializer.h"
1312

1413
#include <utility>
@@ -36,7 +35,7 @@ llvm::Error SystemLifetimeManager::Initialize(
3635
if (auto e = m_initializer->Initialize())
3736
return e;
3837

39-
Debugger::Initialize(plugin_callback);
38+
InitializeDebugger(plugin_callback);
4039
}
4140

4241
return llvm::Error::success();
@@ -46,7 +45,7 @@ void SystemLifetimeManager::Terminate() {
4645
std::lock_guard<std::recursive_mutex> guard(m_mutex);
4746

4847
if (m_initialized) {
49-
Debugger::Terminate();
48+
TerminateDebugger();
5049
m_initializer->Terminate();
5150

5251
m_initializer.reset();

lldb/tools/lldb-test/lldb-test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "lldb/Core/Module.h"
1818
#include "lldb/Core/Section.h"
1919
#include "lldb/Expression/IRMemoryMap.h"
20-
#include "lldb/Initialization/SystemLifetimeManager.h"
20+
#include "lldb/Initialization/SystemLifetimeManagerDbg.h"
2121
#include "lldb/Interpreter/CommandInterpreter.h"
2222
#include "lldb/Interpreter/CommandReturnObject.h"
2323
#include "lldb/Symbol/CompileUnit.h"
@@ -1245,7 +1245,7 @@ int main(int argc, const char *argv[]) {
12451245

12461246
cl::ParseCommandLineOptions(argc, argv, "LLDB Testing Utility\n");
12471247

1248-
SystemLifetimeManager DebuggerLifetime;
1248+
SystemLifetimeManagerDbg DebuggerLifetime;
12491249
if (auto e = DebuggerLifetime.Initialize(
12501250
std::make_unique<SystemInitializerTest>(), nullptr)) {
12511251
WithColor::error() << "initialization failed: " << toString(std::move(e))

0 commit comments

Comments
 (0)