JDevlieghere created this revision. JDevlieghere added reviewers: davide, jingham. JDevlieghere added a project: LLDB. Herald added a subscriber: teemperor.
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. Repository: rLLDB LLDB https://reviews.llvm.org/D67644 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 @@ -2699,12 +2699,12 @@ 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); Index: lldb/lit/Commands/command-script-import.test =================================================================== --- /dev/null +++ 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 Index: lldb/lit/Commands/Inputs/frame.py =================================================================== --- /dev/null +++ lldb/lit/Commands/Inputs/frame.py @@ -0,0 +1,2 @@ +import lldb +print(lldb.frame) \ No newline at end of file
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -2699,12 +2699,12 @@ 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); Index: lldb/lit/Commands/command-script-import.test =================================================================== --- /dev/null +++ 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 Index: lldb/lit/Commands/Inputs/frame.py =================================================================== --- /dev/null +++ lldb/lit/Commands/Inputs/frame.py @@ -0,0 +1,2 @@ +import lldb +print(lldb.frame) \ No newline at end of file
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits