From 3c4f89d7029ad73ce25c798ab2109d3eea7d7151 Mon Sep 17 00:00:00 2001 From: Tamas Berghammer Date: Thu, 12 Feb 2015 18:18:27 +0000 Subject: Add Initialize/Terminate method to Platform base plugin Platform holds a smart pointer to each platform object created in a static variable what cause the platform destructors called only on program exit when other static variables are not availables. With this change the destructors are called on lldb_private::Terminate() + Fix DebuggerRefCount handling in ScriptInterpreterPython Differential Revision: http://reviews.llvm.org/D7590 llvm-svn: 228944 --- lldb/source/Interpreter/ScriptInterpreterPython.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lldb/source/Interpreter/ScriptInterpreterPython.cpp') diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index 8155cbb189f..84472411e0f 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -2825,8 +2825,20 @@ ScriptInterpreterPython::InitializePrivate () } } + // 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" : ""); -- cgit v1.2.3