[PATCH] D67685: [ScriptInterpreter] Make sure LLDB's global variables are only available in interactive mode.

Jonas Devlieghere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 17 17:32:27 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL372192: [ScriptInterpreter] Limit LLDB's globals to interactive mode. (authored by JDevlieghere, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D67685?vs=220588&id=220592#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67685/new/

https://reviews.llvm.org/D67685

Files:
  lldb/trunk/lit/Commands/Inputs/frame.py
  lldb/trunk/lit/Commands/command-script-import.test
  lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/recognizer.py
  lldb/trunk/packages/Python/lldbsuite/test/python_api/sbvalue_const_addrof/main.cpp
  lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp


Index: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -616,6 +616,10 @@
   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 @@
     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);
Index: lldb/trunk/lit/Commands/command-script-import.test
===================================================================
--- lldb/trunk/lit/Commands/command-script-import.test
+++ lldb/trunk/lit/Commands/command-script-import.test
@@ -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
Index: lldb/trunk/lit/Commands/Inputs/frame.py
===================================================================
--- lldb/trunk/lit/Commands/Inputs/frame.py
+++ lldb/trunk/lit/Commands/Inputs/frame.py
@@ -1,2 +1,2 @@
 import lldb
-print(lldb.frame)
+print("frame:py: {}".format(lldb.frame))
Index: lldb/trunk/packages/Python/lldbsuite/test/python_api/sbvalue_const_addrof/main.cpp
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/python_api/sbvalue_const_addrof/main.cpp
+++ lldb/trunk/packages/Python/lldbsuite/test/python_api/sbvalue_const_addrof/main.cpp
@@ -28,7 +28,7 @@
 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))
Index: lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/recognizer.py
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/recognizer.py
+++ lldb/trunk/packages/Python/lldbsuite/test/commands/frame/recognizer/recognizer.py
@@ -7,12 +7,12 @@
         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 []
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67685.220592.patch
Type: text/x-patch
Size: 4834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190918/0f2d9127/attachment-0001.bin>


More information about the llvm-commits mailing list