LLDB  mainline
SystemLifetimeManager.cpp
Go to the documentation of this file.
1 //===-- SystemLifetimeManager.cpp -----------------------------------------===//
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 
10 
11 #include "lldb/Core/Debugger.h"
13 
14 #include <utility>
15 
16 using namespace lldb_private;
17 
19 
21  assert(!m_initialized &&
22  "SystemLifetimeManager destroyed without calling Terminate!");
23 }
24 
26  std::unique_ptr<SystemInitializer> initializer,
27  LoadPluginCallbackType plugin_callback) {
28  std::lock_guard<std::recursive_mutex> guard(m_mutex);
29  if (!m_initialized) {
30  assert(!m_initializer && "Attempting to call "
31  "SystemLifetimeManager::Initialize() when it is "
32  "already initialized");
33  m_initialized = true;
34  m_initializer = std::move(initializer);
35 
36  if (auto e = m_initializer->Initialize())
37  return e;
38 
39  Debugger::Initialize(plugin_callback);
40  }
41 
42  return llvm::Error::success();
43 }
44 
46  std::lock_guard<std::recursive_mutex> guard(m_mutex);
47 
48  if (m_initialized) {
50  m_initializer->Terminate();
51 
52  m_initializer.reset();
53  m_initialized = false;
54  }
55 }
lldb_private::SystemLifetimeManager::SystemLifetimeManager
SystemLifetimeManager()
Definition: SystemLifetimeManager.cpp:18
SystemLifetimeManager.h
lldb_private::SystemLifetimeManager::~SystemLifetimeManager
~SystemLifetimeManager()
Definition: SystemLifetimeManager.cpp:20
lldb_private::SystemLifetimeManager::m_initializer
std::unique_ptr< SystemInitializer > m_initializer
Definition: SystemLifetimeManager.h:32
Debugger.h
lldb_private::SystemLifetimeManager::Terminate
void Terminate()
Definition: SystemLifetimeManager.cpp:45
lldb_private::SystemLifetimeManager::Initialize
llvm::Error Initialize(std::unique_ptr< SystemInitializer > initializer, LoadPluginCallbackType plugin_callback)
Definition: SystemLifetimeManager.cpp:25
lldb_private::Debugger::Initialize
static void Initialize(LoadPluginCallbackType load_plugin_callback)
Definition: Debugger.cpp:478
SystemInitializer.h
lldb_private::SystemLifetimeManager::m_initialized
bool m_initialized
Definition: SystemLifetimeManager.h:33
lldb_private::SystemLifetimeManager::m_mutex
std::recursive_mutex m_mutex
Definition: SystemLifetimeManager.h:31
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:29
lldb_private::Debugger::Terminate
static void Terminate()
Definition: Debugger.cpp:486