[Lldb-commits] [lldb] r231808 - Add Debugger::InitializeForLLGS to allow ref counted LLGS initialization.

Robert Flack flackr at gmail.com
Tue Mar 10 11:07:47 PDT 2015


Author: flackr
Date: Tue Mar 10 13:07:47 2015
New Revision: 231808

URL: http://llvm.org/viewvc/llvm-project?rev=231808&view=rev
Log:
Add Debugger::InitializeForLLGS to allow ref counted LLGS initialization.

After http://reviews.llvm.org/D8133 landed as r231550 process launch on remote platform stopped working.

This adds Debugger::InitializeForLLGS and tracks whether one or both of Initialize and InitializeForLLGS have been called, calling only the corresponding lldb_private::Terminate* methods as necessary. Since lldb_private::Terminate calls lldb_private::TerminateForLLGS, the latter method may be called twice if Initialize was called for both however the terminate methods ensure they are only called once after being initialized.

This still maintains the reduced binary size, though it does now technically link in lldb_private::Terminate on lldb-server even though this should never be called.

This should resolve the issue raised in http://reviews.llvm.org/D8133 where Debugger::Terminate assumed that there were 0 references to debugger and terminated early.

Differential Revision: http://reviews.llvm.org/D8183

Modified:
    lldb/trunk/include/lldb/Core/Debugger.h
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/lldb.cpp
    lldb/trunk/tools/lldb-server/lldb-server.cpp

Modified: lldb/trunk/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=231808&r1=231807&r2=231808&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Debugger.h (original)
+++ lldb/trunk/include/lldb/Core/Debugger.h Tue Mar 10 13:07:47 2015
@@ -69,6 +69,9 @@ public:
     FindTargetWithProcess (Process *process);
 
     static void
+    InitializeForLLGS (LoadPluginCallbackType load_plugin_callback);
+
+    static void
     Initialize (LoadPluginCallbackType load_plugin_callback);
     
     static void 

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=231808&r1=231807&r2=231808&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Tue Mar 10 13:07:47 2015
@@ -412,12 +412,24 @@ Debugger::TestDebuggerRefCount ()
     return g_shared_debugger_refcount;
 }
 
+static bool lldb_initialized_for_llgs = false;
+void
+Debugger::InitializeForLLGS (LoadPluginCallbackType load_plugin_callback)
+{
+    lldb_initialized_for_llgs = true;
+    g_shared_debugger_refcount++;
+    g_load_plugin_callback = load_plugin_callback;
+    lldb_private::InitializeForLLGS();
+}
+
+static bool lldb_initialized = true;
 void
 Debugger::Initialize (LoadPluginCallbackType load_plugin_callback)
 {
+    lldb_initialized = true;
+    g_shared_debugger_refcount++;
     g_load_plugin_callback = load_plugin_callback;
-    if (g_shared_debugger_refcount++ == 0)
-        lldb_private::Initialize();
+    lldb_private::Initialize();
 }
 
 void
@@ -429,7 +441,14 @@ Debugger::Terminate ()
         if (g_shared_debugger_refcount == 0)
         {
             lldb_private::WillTerminate();
-            lldb_private::Terminate();
+            if (lldb_initialized_for_llgs) {
+                lldb_initialized_for_llgs = false;
+                lldb_private::TerminateLLGS();
+            }
+            if (lldb_initialized) {
+                lldb_initialized = false;
+                lldb_private::Terminate();
+            }
 
             // Clear our master list of debugger objects
             Mutex::Locker locker (GetDebuggerListMutex ());

Modified: lldb/trunk/source/lldb.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb.cpp?rev=231808&r1=231807&r2=231808&view=diff
==============================================================================
--- lldb/trunk/source/lldb.cpp (original)
+++ lldb/trunk/source/lldb.cpp Tue Mar 10 13:07:47 2015
@@ -109,17 +109,17 @@ static void fatal_error_handler(void *us
     ::abort();
 }
 
+static bool g_inited_for_llgs = false;
 void
 lldb_private::InitializeForLLGS ()
 {
     // Make sure we initialize only once
     static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive);
-    static bool g_inited = false;
 
     Mutex::Locker locker(g_inited_mutex);
-    if (!g_inited)
+    if (!g_inited_for_llgs)
     {
-        g_inited = true;
+        g_inited_for_llgs = true;
 
 #if defined(_MSC_VER)
         const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
@@ -186,15 +186,19 @@ lldb_private::InitializeForLLGS ()
         PlatformDarwinKernel::Initialize();
         ObjectFileMachO::Initialize();
 #endif
+#ifndef LLDB_DISABLE_PYTHON
+        ScriptInterpreterPython::InitializePrivate();
+        OperatingSystemPython::Initialize();
+#endif
     }
 }
 
+static bool g_inited = false;
 void
 lldb_private::Initialize ()
 {
     // Make sure we initialize only once
     static Mutex g_inited_mutex(Mutex::eMutexTypeRecursive);
-    static bool g_inited = false;
 
     InitializeForLLGS();
     Mutex::Locker locker(g_inited_mutex);
@@ -202,11 +206,6 @@ lldb_private::Initialize ()
     {
         g_inited = true;
 
-#ifndef LLDB_DISABLE_PYTHON
-        ScriptInterpreterPython::InitializePrivate();
-        OperatingSystemPython::Initialize();
-#endif
-
         // Initialize LLVM and Clang
         llvm::InitializeAllTargets();
         llvm::InitializeAllAsmPrinters();
@@ -271,89 +270,99 @@ lldb_private::WillTerminate()
 void
 lldb_private::TerminateLLGS ()
 {
-    Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
-    ObjectContainerBSDArchive::Terminate();
-    ObjectFileELF::Terminate();
-    SymbolVendorELF::Terminate();
-    SymbolFileDWARF::Terminate();
-    SymbolFileSymtab::Terminate();
-    UnwindAssembly_x86::Terminate();
-    UnwindAssemblyInstEmulation::Terminate();
-    EmulateInstructionARM::Terminate ();
-    EmulateInstructionARM64::Terminate ();
-    ObjectFilePECOFF::Terminate ();
-    DynamicLoaderPOSIXDYLD::Terminate ();
-    PlatformFreeBSD::Terminate();
-    PlatformLinux::Terminate();
-    PlatformWindows::Terminate();
-    PlatformKalimba::Terminate();
-    PlatformAndroid::Terminate();
-    SymbolFileDWARFDebugMap::Terminate();
-    ItaniumABILanguageRuntime::Terminate();
-    DynamicLoaderMacOSXDYLD::Terminate();
-    AppleObjCRuntimeV2::Terminate();
-    AppleObjCRuntimeV1::Terminate();
-    ObjectContainerUniversalMachO::Terminate();
-    PlatformMacOSX::Terminate();
-    PlatformRemoteiOS::Terminate();
-    PlatformiOSSimulator::Terminate();
-    SystemRuntimeMacOSX::Terminate();
+    if (g_inited_for_llgs)
+    {
+        g_inited_for_llgs = false;
+
+        Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
+        ObjectContainerBSDArchive::Terminate();
+        ObjectFileELF::Terminate();
+        SymbolVendorELF::Terminate();
+        SymbolFileDWARF::Terminate();
+        SymbolFileSymtab::Terminate();
+        UnwindAssembly_x86::Terminate();
+        UnwindAssemblyInstEmulation::Terminate();
+        EmulateInstructionARM::Terminate ();
+        EmulateInstructionARM64::Terminate ();
+        ObjectFilePECOFF::Terminate ();
+        DynamicLoaderPOSIXDYLD::Terminate ();
+        PlatformFreeBSD::Terminate();
+        PlatformLinux::Terminate();
+        PlatformWindows::Terminate();
+        PlatformKalimba::Terminate();
+        PlatformAndroid::Terminate();
+        SymbolFileDWARFDebugMap::Terminate();
+        ItaniumABILanguageRuntime::Terminate();
+        DynamicLoaderMacOSXDYLD::Terminate();
+        AppleObjCRuntimeV2::Terminate();
+        AppleObjCRuntimeV1::Terminate();
+        ObjectContainerUniversalMachO::Terminate();
+        PlatformMacOSX::Terminate();
+        PlatformRemoteiOS::Terminate();
+        PlatformiOSSimulator::Terminate();
+        SystemRuntimeMacOSX::Terminate();
 
 #if defined (__APPLE__)
-    DynamicLoaderDarwinKernel::Terminate();
-    ObjectFileMachO::Terminate();
-    PlatformDarwinKernel::Terminate();
-    SymbolVendorMacOSX::Terminate();
+        DynamicLoaderDarwinKernel::Terminate();
+        ObjectFileMachO::Terminate();
+        PlatformDarwinKernel::Terminate();
+        SymbolVendorMacOSX::Terminate();
+#endif
+
+#ifndef LLDB_DISABLE_PYTHON
+        OperatingSystemPython::Terminate();
 #endif
 
-    Log::Terminate();
+        Log::Terminate();
+    }
 }
 
 void
 lldb_private::Terminate ()
 {
-    Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
-    // Terminate and unload and loaded system or user LLDB plug-ins
-    PluginManager::Terminate();
-    ABIMacOSX_i386::Terminate();
-    ABIMacOSX_arm::Terminate();
-    ABIMacOSX_arm64::Terminate();
-    ABISysV_x86_64::Terminate();
-    ABISysV_ppc::Terminate();
-    ABISysV_ppc64::Terminate();
-    DisassemblerLLVMC::Terminate();
-
-    JITLoaderGDB::Terminate();
-    ProcessElfCore::Terminate();
-    MemoryHistoryASan::Terminate();
-    AddressSanitizerRuntime::Terminate();
+    if (g_inited)
+    {
+        g_inited = false;
+
+        Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
+        // Terminate and unload and loaded system or user LLDB plug-ins
+        PluginManager::Terminate();
+        ABIMacOSX_i386::Terminate();
+        ABIMacOSX_arm::Terminate();
+        ABIMacOSX_arm64::Terminate();
+        ABISysV_x86_64::Terminate();
+        ABISysV_ppc::Terminate();
+        ABISysV_ppc64::Terminate();
+        DisassemblerLLVMC::Terminate();
+
+        JITLoaderGDB::Terminate();
+        ProcessElfCore::Terminate();
+        MemoryHistoryASan::Terminate();
+        AddressSanitizerRuntime::Terminate();
 
 #if defined (__APPLE__)
-    ProcessMachCore::Terminate();
-    ProcessKDP::Terminate();
+        ProcessMachCore::Terminate();
+        ProcessKDP::Terminate();
 #endif
 #if defined(_MSC_VER)
-    DynamicLoaderWindows::Terminate();
+        DynamicLoaderWindows::Terminate();
 #endif
 
 #if defined (__linux__)
-    ProcessLinux::Terminate();
+        ProcessLinux::Terminate();
 #endif
 
 #if defined (__FreeBSD__)
-    ProcessFreeBSD::Terminate();
+        ProcessFreeBSD::Terminate();
 #endif
-    Debugger::SettingsTerminate ();
+        Debugger::SettingsTerminate ();
 
-    PlatformRemoteGDBServer::Terminate();
-    ProcessGDBRemote::Terminate();
-    DynamicLoaderStatic::Terminate();
+        PlatformRemoteGDBServer::Terminate();
+        ProcessGDBRemote::Terminate();
+        DynamicLoaderStatic::Terminate();
 
-#ifndef LLDB_DISABLE_PYTHON
-    OperatingSystemPython::Terminate();
-#endif
-
-    TerminateLLGS();
+        TerminateLLGS();
+    }
 }
 
 #if defined (__APPLE__)

Modified: lldb/trunk/tools/lldb-server/lldb-server.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-server/lldb-server.cpp?rev=231808&r1=231807&r2=231808&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-server/lldb-server.cpp (original)
+++ lldb/trunk/tools/lldb-server/lldb-server.cpp Tue Mar 10 13:07:47 2015
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "lldb/lldb-private.h"
+#include "lldb/Core/Debugger.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -29,14 +29,13 @@ int main_platform (int argc, char *argv[
 static void
 initialize ()
 {
-    lldb_private::InitializeForLLGS();
+    lldb_private::Debugger::InitializeForLLGS(NULL);
 }
 
 static void
 terminate ()
 {
-    lldb_private::WillTerminate();
-    lldb_private::TerminateLLGS();
+    lldb_private::Debugger::Terminate();
 }
 
 //----------------------------------------------------------------------





More information about the lldb-commits mailing list