{
public:
+ static void
+ Initialize ();
+
+ static void
+ Terminate ();
+
//------------------------------------------------------------------
- /// Get the native host platform plug-in.
+ /// Get the native host platform plug-in.
///
/// There should only be one of these for each host that LLDB runs
/// upon that should be statically compiled in and registered using
}
}
+ // Importing 'lldb' module calls SBDebugger::Initialize, which calls Debugger::Initialize, which increments a
+ // global debugger ref-count; therefore we need to check the ref-count before and after importing lldb, and if the
+ // ref-count increased we need to call Debugger::Terminate here to decrement the ref-count so that when the final
+ // call to Debugger::Terminate is made, the ref-count has the correct value.
+
+ int old_count = Debugger::TestDebuggerRefCount ();
+
PyRun_SimpleString ("sys.dont_write_bytecode = 1; import lldb.embedded_interpreter; from lldb.embedded_interpreter import run_python_interpreter; from lldb.embedded_interpreter import run_one_line");
+ int new_count = Debugger::TestDebuggerRefCount ();
+
+ if (new_count > old_count)
+ Debugger::Terminate ();
+
if (threads_already_initialized) {
if (log)
log->Printf("Releasing PyGILState. Returning to state = %slocked\n", gstate == PyGILState_UNLOCKED ? "un" : "");
void
PlatformAndroid::Initialize ()
{
+ PlatformLinux::Initialize ();
+
if (g_initialize_count++ == 0)
{
PluginManager::RegisterPlugin (PlatformAndroid::GetPluginNameStatic(),
PluginManager::UnregisterPlugin (PlatformAndroid::CreateInstance);
}
}
+
+ PlatformLinux::Terminate ();
}
PlatformSP
void
PlatformFreeBSD::Initialize ()
{
+ Platform::Initialize ();
+
if (g_initialize_count++ == 0)
{
#if defined (__FreeBSD__)
{
if (g_initialize_count > 0 && --g_initialize_count == 0)
PluginManager::UnregisterPlugin (PlatformFreeBSD::CreateInstance);
+
+ Platform::Terminate ();
}
//------------------------------------------------------------------
void
PlatformKalimba::Initialize ()
{
+ Platform::Initialize ();
+
if (g_initialize_count++ == 0)
{
PluginManager::RegisterPlugin(PlatformKalimba::GetPluginNameStatic(false),
PluginManager::UnregisterPlugin (PlatformKalimba::CreateInstance);
}
}
+
+ Platform::Terminate ();
}
Error
void
PlatformLinux::Initialize ()
{
+ PlatformPOSIX::Initialize ();
+
if (g_initialize_count++ == 0)
{
#if defined(__linux__)
PluginManager::UnregisterPlugin (PlatformLinux::CreateInstance);
}
}
+
+ PlatformPOSIX::Terminate ();
}
Error
void
PlatformDarwinKernel::Initialize ()
{
+ PlatformDarwin::Initialize ();
+
if (g_initialize_count++ == 0)
{
PluginManager::RegisterPlugin (PlatformDarwinKernel::GetPluginNameStatic(),
PluginManager::UnregisterPlugin (PlatformDarwinKernel::CreateInstance);
}
}
+
+ PlatformDarwin::Terminate ();
}
PlatformSP
void
PlatformMacOSX::Initialize ()
{
+ PlatformDarwin::Initialize ();
+
if (g_initialize_count++ == 0)
{
#if defined (__APPLE__)
PluginManager::UnregisterPlugin (PlatformMacOSX::CreateInstance);
}
}
+
+ PlatformDarwin::Terminate ();
}
PlatformSP
void
PlatformRemoteiOS::Initialize ()
{
+ PlatformDarwin::Initialize ();
+
if (g_initialize_count++ == 0)
{
PluginManager::RegisterPlugin (PlatformRemoteiOS::GetPluginNameStatic(),
PluginManager::UnregisterPlugin (PlatformRemoteiOS::CreateInstance);
}
}
+
+ PlatformDarwin::Terminate ();
}
PlatformSP
void
PlatformiOSSimulator::Initialize ()
{
+ PlatformDarwin::Initialize ();
+
if (g_initialize_count++ == 0)
{
PluginManager::RegisterPlugin (PlatformiOSSimulator::GetPluginNameStatic(),
PluginManager::UnregisterPlugin (PlatformiOSSimulator::CreateInstance);
}
}
+
+ PlatformDarwin::Terminate ();
}
PlatformSP
void
PlatformWindows::Initialize(void)
{
+ Platform::Initialize ();
+
if (g_initialize_count++ == 0)
{
#if defined (_WIN32)
PluginManager::UnregisterPlugin (PlatformWindows::CreateInstance);
}
}
+
+ Platform::Terminate ();
}
//------------------------------------------------------------------
void
PlatformRemoteGDBServer::Initialize ()
{
+ Platform::Initialize ();
+
if (g_initialized == false)
{
g_initialized = true;
g_initialized = false;
PluginManager::UnregisterPlugin (PlatformRemoteGDBServer::CreateInstance);
}
+
+ Platform::Terminate ();
}
PlatformSP
using namespace lldb;
using namespace lldb_private;
-
+
+static uint32_t g_initialize_count = 0;
+
// Use a singleton function for g_local_platform_sp to avoid init
// constructors since LLDB is often part of a shared library
static PlatformSP&
}
void
+Platform::Initialize ()
+{
+ g_initialize_count++;
+}
+
+void
+Platform::Terminate ()
+{
+ if (g_initialize_count > 0)
+ {
+ if (--g_initialize_count == 0)
+ {
+ Mutex::Locker locker(GetPlatformListMutex ());
+ GetPlatformList().clear();
+ }
+ }
+}
+
+void
Platform::SetHostPlatform (const lldb::PlatformSP &platform_sp)
{
// The native platform should use its static void Platform::Initialize()
ProcessFreeBSD::Terminate();
#endif
+ PlatformRemoteGDBServer::Terminate();
ProcessGDBRemote::Terminate();
DynamicLoaderStatic::Terminate();