diff options
author | Zachary Turner <zturner@google.com> | 2015-03-31 21:03:22 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2015-03-31 21:03:22 +0000 |
commit | e6e2bb38428822f9183634cde2c8543512ee8d7d (patch) | |
tree | 2a4c329e98166c2d3511eabc76014dccd3302d96 /lldb/source/Core/Debugger.cpp | |
parent | 902716728c221edf80284a21e4f3bac0ead5c7f7 (diff) | |
download | bcm5719-llvm-e6e2bb38428822f9183634cde2c8543512ee8d7d.tar.gz bcm5719-llvm-e6e2bb38428822f9183634cde2c8543512ee8d7d.zip |
Rework LLDB system initialization.
In an effort to reduce binary size for components not wishing to
link against all of LLDB, as well as a parallel effort to reduce
link dependencies on Python, this patch splits out the notion of
LLDB initialization into "full" and "common" initialization.
All code related to initializing the full LLDB suite lives directly
in API now. Previously it was only referenced from API, but because
it was defined in lldbCore, it would get implicitly linked against
by everything including lldb-server, causing a considerable
increase in binary size.
By moving this to the API layer, it also creates a better layering
for the ongoing effort to make the embedded interpreter replacable
with one from a different language (or even be completely removeable).
One semantic change necessary to get this all working was to remove
the notion of a shared debugger refcount. The debugger is either
initialized or uninitialized now, and calling Initialize() multiple
times will simply have no effect, while the first Terminate() will
now shut it down no matter how many times Initialize() was called.
This behaves nicely with all of our supported usage patterns though,
and allows us to fix a number of nasty hacks from before.
Differential Revision: http://reviews.llvm.org/D8462
llvm-svn: 233758
Diffstat (limited to 'lldb/source/Core/Debugger.cpp')
-rw-r--r-- | lldb/source/Core/Debugger.cpp | 47 |
1 files changed, 17 insertions, 30 deletions
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp index 7134d418ead..2eedb0f844a 100644 --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -38,7 +38,6 @@ #include "lldb/Host/HostInfo.h" #include "lldb/Host/Terminal.h" #include "lldb/Host/ThreadLauncher.h" -#include "lldb/Initialization/InitializeLLDB.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/OptionValueProperties.h" #include "lldb/Interpreter/OptionValueSInt64.h" @@ -65,7 +64,6 @@ using namespace lldb; using namespace lldb_private; -static uint32_t g_shared_debugger_refcount = 0; static lldb::user_id_t g_unique_id = 1; static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024; @@ -407,35 +405,24 @@ Debugger::GetEscapeNonPrintables () const //} // -int -Debugger::TestDebuggerRefCount () -{ - return g_shared_debugger_refcount; -} - -static bool lldb_initialized = true; +static bool lldb_initialized = false; void Debugger::Initialize(LoadPluginCallbackType load_plugin_callback) { + assert(!lldb_initialized && "Debugger::Initialize called more than once!"); + lldb_initialized = true; - g_shared_debugger_refcount++; g_load_plugin_callback = load_plugin_callback; } -int +void Debugger::Terminate () { - if (g_shared_debugger_refcount > 0) - { - g_shared_debugger_refcount--; - if (g_shared_debugger_refcount == 0) - { - // Clear our master list of debugger objects - Mutex::Locker locker (GetDebuggerListMutex ()); - GetDebuggerList().clear(); - } - } - return g_shared_debugger_refcount; + assert(lldb_initialized && "Debugger::Terminate called without a matching Debugger::Initialize!"); + + // Clear our master list of debugger objects + Mutex::Locker locker (GetDebuggerListMutex ()); + GetDebuggerList().clear(); } void @@ -568,7 +555,7 @@ DebuggerSP Debugger::CreateInstance (lldb::LogOutputCallback log_callback, void *baton) { DebuggerSP debugger_sp (new Debugger(log_callback, baton)); - if (g_shared_debugger_refcount > 0) + if (lldb_initialized) { Mutex::Locker locker (GetDebuggerListMutex ()); GetDebuggerList().push_back(debugger_sp); @@ -585,7 +572,7 @@ Debugger::Destroy (DebuggerSP &debugger_sp) debugger_sp->Clear(); - if (g_shared_debugger_refcount > 0) + if (lldb_initialized) { Mutex::Locker locker (GetDebuggerListMutex ()); DebuggerList &debugger_list = GetDebuggerList (); @@ -605,7 +592,7 @@ DebuggerSP Debugger::FindDebuggerWithInstanceName (const ConstString &instance_name) { DebuggerSP debugger_sp; - if (g_shared_debugger_refcount > 0) + if (lldb_initialized) { Mutex::Locker locker (GetDebuggerListMutex ()); DebuggerList &debugger_list = GetDebuggerList(); @@ -627,7 +614,7 @@ TargetSP Debugger::FindTargetWithProcessID (lldb::pid_t pid) { TargetSP target_sp; - if (g_shared_debugger_refcount > 0) + if (lldb_initialized) { Mutex::Locker locker (GetDebuggerListMutex ()); DebuggerList &debugger_list = GetDebuggerList(); @@ -646,7 +633,7 @@ TargetSP Debugger::FindTargetWithProcess (Process *process) { TargetSP target_sp; - if (g_shared_debugger_refcount > 0) + if (lldb_initialized) { Mutex::Locker locker (GetDebuggerListMutex ()); DebuggerList &debugger_list = GetDebuggerList(); @@ -1129,7 +1116,7 @@ Debugger::GetAsyncErrorStream () size_t Debugger::GetNumDebuggers() { - if (g_shared_debugger_refcount > 0) + if (lldb_initialized) { Mutex::Locker locker (GetDebuggerListMutex ()); return GetDebuggerList().size(); @@ -1142,7 +1129,7 @@ Debugger::GetDebuggerAtIndex (size_t index) { DebuggerSP debugger_sp; - if (g_shared_debugger_refcount > 0) + if (lldb_initialized) { Mutex::Locker locker (GetDebuggerListMutex ()); DebuggerList &debugger_list = GetDebuggerList(); @@ -1159,7 +1146,7 @@ Debugger::FindDebuggerWithID (lldb::user_id_t id) { DebuggerSP debugger_sp; - if (g_shared_debugger_refcount > 0) + if (lldb_initialized) { Mutex::Locker locker (GetDebuggerListMutex ()); DebuggerList &debugger_list = GetDebuggerList(); |