forked from OSchip/llvm-project
[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
This commit is contained in:
parent
6e353b4df3
commit
20b52c33ba
|
@ -1,2 +1,2 @@
|
|||
import lldb
|
||||
print(lldb.frame)
|
||||
print("frame:py: {}".format(lldb.frame))
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
# RUN: echo 'command script import %S/Inputs/frame.py' >> %t.in
|
||||
|
||||
# RUN: %clang -g -O0 %S/Inputs/main.c -o %t.out
|
||||
# RUN: %lldb -b -s %t.in %t.out | FileCheck %s
|
||||
# RUN: %lldb -b -s %t.in -o 'script print("script: {}").format(lldb.frame)' %t.out | FileCheck %s
|
||||
|
||||
# CHECK: frame #0
|
||||
# Make sure that we don't have access to lldb.frame from the Python script.
|
||||
# CHECK: frame:py: None
|
||||
|
||||
# Make sure that we do have access to lldb.frame from the script command.
|
||||
# CHECK: script: frame #0
|
||||
|
|
|
@ -7,12 +7,12 @@ class MyFrameRecognizer(object):
|
|||
if frame.name == "foo":
|
||||
arg1 = frame.EvaluateExpression("$arg1").signed
|
||||
arg2 = frame.EvaluateExpression("$arg2").signed
|
||||
val1 = lldb.target.CreateValueFromExpression("a", "%d" % arg1)
|
||||
val2 = lldb.target.CreateValueFromExpression("b", "%d" % arg2)
|
||||
val1 = frame.GetThread().GetProcess().GetTarget().CreateValueFromExpression("a", "%d" % arg1)
|
||||
val2 = frame.GetThread().GetProcess().GetTarget().CreateValueFromExpression("b", "%d" % arg2)
|
||||
return [val1, val2]
|
||||
elif frame.name == "bar":
|
||||
arg1 = frame.EvaluateExpression("$arg1").signed
|
||||
val1 = lldb.target.CreateValueFromExpression("a", "(int *)%d" % arg1)
|
||||
val1 = frame.GetThread().GetProcess().GetTarget().CreateValueFromExpression("a", "(int *)%d" % arg1)
|
||||
return [val1]
|
||||
return []
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ ThreadInfo *g_thread_list_ptr = &g_thread1;
|
|||
int main (int argc, char const *argv[], char const *envp[])
|
||||
{
|
||||
printf ("g_thread_list is %p\n", g_thread_list_ptr);
|
||||
return 0; //% v = lldb.target.FindFirstGlobalVariable('g_thread_list_ptr')
|
||||
return 0; //% v = self.dbg.GetSelectedTarget().FindFirstGlobalVariable('g_thread_list_ptr')
|
||||
//% v_gla = v.GetChildMemberWithName('regs').GetLoadAddress()
|
||||
//% v_aof = v.GetChildMemberWithName('regs').AddressOf().GetValueAsUnsigned(lldb.LLDB_INVALID_ADDRESS)
|
||||
//% expr = '(%s)0x%x' % (v.GetType().GetName(), v.GetValueAsUnsigned(0))
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue