[Lldb-commits] [lldb] r372060 - [ScriptInterpreter] Initialize globals when loading a scripting module.
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Mon Sep 16 20:55:58 PDT 2019
Author: jdevlieghere
Date: Mon Sep 16 20:55:58 2019
New Revision: 372060
URL: http://llvm.org/viewvc/llvm-project?rev=372060&view=rev
Log:
[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
Added:
lldb/trunk/lit/Commands/Inputs/
lldb/trunk/lit/Commands/Inputs/frame.py
lldb/trunk/lit/Commands/command-script-import.test
Modified:
lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
Added: lldb/trunk/lit/Commands/Inputs/frame.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Commands/Inputs/frame.py?rev=372060&view=auto
==============================================================================
--- lldb/trunk/lit/Commands/Inputs/frame.py (added)
+++ lldb/trunk/lit/Commands/Inputs/frame.py Mon Sep 16 20:55:58 2019
@@ -0,0 +1,2 @@
+import lldb
+print(lldb.frame)
Added: lldb/trunk/lit/Commands/command-script-import.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Commands/command-script-import.test?rev=372060&view=auto
==============================================================================
--- lldb/trunk/lit/Commands/command-script-import.test (added)
+++ lldb/trunk/lit/Commands/command-script-import.test Mon Sep 16 20:55:58 2019
@@ -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
Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp?rev=372060&r1=372059&r2=372060&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp Mon Sep 16 20:55:58 2019
@@ -2699,12 +2699,12 @@ bool ScriptInterpreterPythonImpl::LoadSc
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);
More information about the lldb-commits
mailing list