JDevlieghere created this revision.
JDevlieghere added a reviewer: jingham.
Jim pointed out that the LLDB global variables should only be available in
interactive mode. When used from a command, their values might be stale or not
at all what the user expects. Therefore we want to explicitly makes these
variables unavailable.
https://reviews.llvm.org/D67685
Files:
lldb/lit/Commands/Inputs/frame.py
lldb/lit/Commands/command-script-import.test
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===================================================================
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -2691,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/lit/Commands/command-script-import.test
===================================================================
--- lldb/lit/Commands/command-script-import.test
+++ lldb/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/lit/Commands/Inputs/frame.py
===================================================================
--- lldb/lit/Commands/Inputs/frame.py
+++ lldb/lit/Commands/Inputs/frame.py
@@ -1,2 +1,2 @@
import lldb
-print(lldb.frame)
+print("frame:py: {}".format(lldb.frame))
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
===================================================================
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -2691,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/lit/Commands/command-script-import.test
===================================================================
--- lldb/lit/Commands/command-script-import.test
+++ lldb/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/lit/Commands/Inputs/frame.py
===================================================================
--- lldb/lit/Commands/Inputs/frame.py
+++ lldb/lit/Commands/Inputs/frame.py
@@ -1,2 +1,2 @@
import lldb
-print(lldb.frame)
+print("frame:py: {}".format(lldb.frame))
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits