summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2019-09-17 03:55:58 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2019-09-17 03:55:58 +0000
commita879f40ba105ab5ceb79725424c77c1fd68a58a1 (patch)
treecd362561f17b9cdf37564c78cceb8e76e5fdec12
parent4816e516e5ca77d623f96699834e86d924022af9 (diff)
downloadbcm5719-llvm-a879f40ba105ab5ceb79725424c77c1fd68a58a1.tar.gz
bcm5719-llvm-a879f40ba105ab5ceb79725424c77c1fd68a58a1.zip
[ScriptInterpreter] Initialize globals when loading a scripting module.
The LoadScriptingModule used by command script import wasn't initializing the LLDB global variables (things like `lldb.frame` and `lldb.debugger`). They would get initialized however when running the interactive script interpreter or running a single script line (e.g. `script print(lldb.frame)`). This patch fixes that by properly initializing the globals when loading a Python module. Differential revision: https://reviews.llvm.org/D67644 llvm-svn: 372060
-rw-r--r--lldb/lit/Commands/Inputs/frame.py2
-rw-r--r--lldb/lit/Commands/command-script-import.test8
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp12
3 files changed, 16 insertions, 6 deletions
diff --git a/lldb/lit/Commands/Inputs/frame.py b/lldb/lit/Commands/Inputs/frame.py
new file mode 100644
index 00000000000..cd7b61c976e
--- /dev/null
+++ b/lldb/lit/Commands/Inputs/frame.py
@@ -0,0 +1,2 @@
+import lldb
+print(lldb.frame)
diff --git a/lldb/lit/Commands/command-script-import.test b/lldb/lit/Commands/command-script-import.test
new file mode 100644
index 00000000000..318b4f43540
--- /dev/null
+++ b/lldb/lit/Commands/command-script-import.test
@@ -0,0 +1,8 @@
+# RUN: echo 'b main' > %t.in
+# RUN: echo 'run' >> %t.in
+# RUN: echo 'command script import %S/Inputs/frame.py' >> %t.in
+
+# RUN: %clang -g -O0 %S/../Settings/Inputs/main.c -o %t.out
+# RUN: %lldb -b -s %t.in %t.out | FileCheck %s
+
+# CHECK: frame #0
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 7fe3157dfc2..8b11be665c1 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -2699,12 +2699,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) |
- Locker::NoSTDIN,
- Locker::FreeAcquiredLock |
- (init_session ? Locker::TearDownSession : 0));
+ 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));
namespace fs = llvm::sys::fs;
fs::file_status st;
std::error_code ec = status(target_file.GetPath(), st);
OpenPOWER on IntegriCloud