[Lldb-commits] [lldb] [lldb] Setup session when calling Python interfaces (PR #197966)

via lldb-commits lldb-commits at lists.llvm.org
Fri May 15 09:06:00 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Nerixyz (Nerixyz)

<details>
<summary>Changes</summary>

When using the Python interfaces like scripted frame providers in lldb-dap, Python's `print` statements don't show in the output window. They do show when done in synthetic children or summaries.

This is because when calling the interface functions/methods, the stdout/stderr handles were never changed. This PR fixes the issue by passing `InitSession` (and `TearDownSession`) to the `Locker`. As a side effect, this will also set `lldb.debugger`.

---
Full diff: https://github.com/llvm/llvm-project/pull/197966.diff


1 Files Affected:

- (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h (+9-6) 


``````````diff
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
index 637ca1b2ab1f9..921a8fe715198 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h
@@ -192,8 +192,9 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
         return create_error("Missing scripting object.");
     }
 
-    Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
-                   Locker::FreeLock);
+    Locker py_lock(&m_interpreter,
+                   Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN,
+                   Locker::FreeLock | Locker::TearDownSession);
 
     PythonObject result = {};
 
@@ -413,8 +414,9 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
       return ErrorWithMessage<T>(caller_signature, "missing script class name",
                                  error);
 
-    Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
-                   Locker::FreeLock);
+    Locker py_lock(&m_interpreter,
+                   Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN,
+                   Locker::FreeLock | Locker::TearDownSession);
 
     // Get the interpreter dictionary.
     auto dict =
@@ -508,8 +510,9 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
       return ErrorWithMessage<T>(caller_signature, "python object ill-formed",
                                  error);
 
-    Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
-                   Locker::FreeLock);
+    Locker py_lock(&m_interpreter,
+                   Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN,
+                   Locker::FreeLock | Locker::TearDownSession);
 
     PythonObject implementor(PyRefType::Borrowed,
                              (PyObject *)m_object_instance_sp->GetValue());

``````````

</details>


https://github.com/llvm/llvm-project/pull/197966


More information about the lldb-commits mailing list