From 20b52c33ba3960340ecf326314517091b8ec98f4 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 18 Sep 2019 00:30:01 +0000 Subject: [ScriptInterpreter] Limit LLDB's globals to interactive mode. Jim pointed out that the LLDB global variables should only be available in interactive mode. When used from a command for example, their values might be stale or not at all what the user expects. Therefore we want to explicitly make these variables unavailable. Differential revision: https://reviews.llvm.org/D67685 llvm-svn: 372192 --- .../ScriptInterpreter/Python/ScriptInterpreterPython.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp') diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 1eecbc114b2..25a81f65115 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -616,6 +616,10 @@ void ScriptInterpreterPythonImpl::LeaveSession() { if (log) log->PutCString("ScriptInterpreterPythonImpl::LeaveSession()"); + // Unset the LLDB global variables. + PyRun_SimpleString("lldb.debugger = None; lldb.target = None; lldb.process " + "= None; lldb.thread = None; lldb.frame = None"); + // checking that we have a valid thread state - since we use our own // threading and locking in some (rare) cases during cleanup Python may end // up believing we have no thread state and PyImport_AddModule will crash if @@ -2687,12 +2691,12 @@ bool ScriptInterpreterPythonImpl::LoadScriptingModule( StreamString command_stream; // Before executing Python code, lock the GIL. - Locker py_lock( - this, - Locker::AcquireLock | (init_session ? Locker::InitSession : 0) | - (init_session ? Locker::InitGlobals : 0) | Locker::NoSTDIN, - Locker::FreeAcquiredLock | - (init_session ? Locker::TearDownSession : 0)); + Locker py_lock(this, + Locker::AcquireLock | + (init_session ? Locker::InitSession : 0) | + Locker::NoSTDIN, + Locker::FreeAcquiredLock | + (init_session ? Locker::TearDownSession : 0)); namespace fs = llvm::sys::fs; fs::file_status st; std::error_code ec = status(target_file.GetPath(), st); -- cgit v1.2.3