[Lldb-commits] [lldb] r215256 - Fix some python shutdown / ordering issues.
Zachary Turner
zturner at google.com
Fri Aug 8 16:20:26 PDT 2014
Author: zturner
Date: Fri Aug 8 18:20:25 2014
New Revision: 215256
URL: http://llvm.org/viewvc/llvm-project?rev=215256&view=rev
Log:
Fix some python shutdown / ordering issues.
Differential Revision: http://reviews.llvm.org/D4826
Reviewed by: Enrico Granata
Modified:
lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h
lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
lldb/trunk/test/dotest.py
Modified: lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h?rev=215256&r1=215255&r2=215256&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h (original)
+++ lldb/trunk/include/lldb/Interpreter/PythonDataObjects.h Fri Aug 8 18:20:25 2014
@@ -62,9 +62,11 @@ namespace lldb_private {
{
if (py_obj != m_py_obj)
{
- Py_XDECREF(m_py_obj);
+ if (Py_IsInitialized())
+ Py_XDECREF(m_py_obj);
m_py_obj = py_obj;
- Py_XINCREF(m_py_obj);
+ if (Py_IsInitialized())
+ Py_XINCREF(m_py_obj);
}
return true;
}
Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h?rev=215256&r1=215255&r2=215256&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h Fri Aug 8 18:20:25 2014
@@ -357,7 +357,8 @@ protected:
virtual
~ScriptInterpreterPythonObject()
{
- Py_XDECREF(m_object);
+ if (Py_IsInitialized())
+ Py_XDECREF(m_object);
m_object = NULL;
}
private:
Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=215256&r1=215255&r2=215256&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Fri Aug 8 18:20:25 2014
@@ -1806,7 +1806,11 @@ ScriptInterpreterPython::Clear ()
Locker locker(this,
ScriptInterpreterPython::Locker::AcquireLock,
ScriptInterpreterPython::Locker::FreeAcquiredLock);
- PyRun_SimpleString("lldb.debugger = None; lldb.target = None; lldb.process = None; lldb.thread = None; lldb.frame = None");
+
+ // This may be called as part of Py_Finalize. In that case the modules are destroyed in random
+ // order and we can't guarantee that we can access these.
+ if (Py_IsInitialized())
+ PyRun_SimpleString("lldb.debugger = None; lldb.target = None; lldb.process = None; lldb.thread = None; lldb.frame = None");
}
bool
Modified: lldb/trunk/test/dotest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=215256&r1=215255&r2=215256&view=diff
==============================================================================
--- lldb/trunk/test/dotest.py (original)
+++ lldb/trunk/test/dotest.py Fri Aug 8 18:20:25 2014
@@ -20,7 +20,6 @@ Type:
for available options.
"""
-import atexit
import commands
import os
import errno
@@ -419,7 +418,6 @@ def setupCrashInfoHook():
cmd = "xcrun clang %s -o %s -framework Python -Xlinker -dylib -iframework /System/Library/Frameworks/ -Xlinker -F /System/Library/Frameworks/" % (dylib_src,dylib_dst)
if subprocess.call(cmd,shell=True) == 0 and os.path.exists(dylib_dst):
setCrashInfoHook = setCrashInfoHook_Mac
- atexit.register(deleteCrashInfoDylib,dylib_dst)
else:
pass
@@ -1201,6 +1199,11 @@ def checkDsymForUUIDIsNotOn():
print "Exiting..."
sys.exit(0)
+def exitTestSuite(exitCode = None):
+ lldb.SBDebugger.Terminate()
+ if exitCode:
+ sys.exit(exitCode)
+
# On MacOS X, check to make sure that domain for com.apple.DebugSymbols defaults
# does not exist before proceeding to running the test suite.
if sys.platform.startswith("darwin"):
@@ -1232,11 +1235,7 @@ for testdir in testdirs:
# For the time being, let's bracket the test runner within the
# lldb.SBDebugger.Initialize()/Terminate() pair.
-import lldb, atexit
-# Update: the act of importing lldb now executes lldb.SBDebugger.Initialize(),
-# there's no need to call it a second time.
-#lldb.SBDebugger.Initialize()
-atexit.register(lambda: lldb.SBDebugger.Terminate())
+import lldb
# Create a singleton SBDebugger in the lldb namespace.
lldb.DBG = lldb.SBDebugger.Create()
@@ -1246,7 +1245,7 @@ if lldb_platform_name:
lldb.remote_platform = lldb.SBPlatform(lldb_platform_name)
if not lldb.remote_platform.IsValid():
print "error: unable to create the LLDB platform named '%s'." % (lldb_platform_name)
- sys.exit(1)
+ exitTestSuite(1)
if lldb_platform_url:
# We must connect to a remote platform if a LLDB platform URL was specified
print "Connecting to remote platform '%s' at '%s'..." % (lldb_platform_name, lldb_platform_url)
@@ -1256,7 +1255,7 @@ if lldb_platform_name:
print "Connected."
else:
print "error: failed to connect to remote platform using URL '%s': %s" % (lldb_platform_url, err)
- sys.exit(1)
+ exitTestSuite(1)
if lldb_platform_working_dir:
print "Setting remote platform working directory to '%s'..." % (lldb_platform_working_dir)
@@ -1397,7 +1396,7 @@ if not parsable:
if not compilers or len(compilers) == 0:
print "No eligible compiler found, exiting."
- sys.exit(1)
+ exitTestSuite(1)
if isinstance(compilers, list) and len(compilers) >= 1:
iterCompilers = True
@@ -1738,4 +1737,4 @@ if ("LLDB_TESTSUITE_FORCE_FINISH" in os.
subprocess.Popen(["/bin/sh", "-c", "kill %s; exit 0" % (os.getpid())])
# Exiting.
-sys.exit(failed)
+exitTestSuite()
\ No newline at end of file
More information about the lldb-commits
mailing list