[Lldb-commits] [lldb] [lldb] Use the selected target when the override context is the dummy (PR #226332)

Med Ismail Bennani via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 24 17:56:38 PDT 2026


https://github.com/medismailben updated https://github.com/llvm/llvm-project/pull/226332

>From 714f0697f5a271dc088865ff2b3ae95be20574d8 Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani <ismail at bennani.ma>
Date: Thu, 24 Sep 2026 17:54:20 -0700
Subject: [PATCH] [lldb] Don't push the dummy target for commands from the
 IOHandler

Since 029abe67307a, IOHandlerInputComplete pushes the dummy target's
execution context as an override when no target is selected. Commands
that don't adopt the dummy target resolve that override to an empty
context (e5ab4f8a1f76), so any command run while the outer command is
still executing keeps seeing no target, even after the outer command
has created and selected a real one.

This breaks scripts that run while `target create` is still going.
For example, a dSYM's Python scripting resource that is auto-loaded
during `target create --core` and runs `settings set target.process.*`
now writes to a copy of the settings that no process reads, so the
process never sees the value. When the setting is
target.process.python-os-plugin-path, the OS plugin never loads and
only the core file's threads are available.

Only push the selected execution context when a real target is
selected, as before 029abe67307a. Pushing the dummy target was not
needed: with no override, GetExecutionContext already falls back to
the dummy target for commands that allow it. Explicit dummy target
overrides passed through SBCommandInterpreter::HandleCommand are
unaffected.

rdar://188336498

Assisted-by: Claude

Signed-off-by: Med Ismail Bennani <ismail at bennani.ma>
---
 .../source/Interpreter/CommandInterpreter.cpp |  5 +++-
 .../nested_command_selected_target.test       | 29 +++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 lldb/test/Shell/ScriptInterpreter/Python/nested_command_selected_target.test

diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 12578ca56a967e..6d361470039fda 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -3436,8 +3436,11 @@ void CommandInterpreter::IOHandlerInputComplete(IOHandler &io_handler,
 
   StartHandlingCommand();
 
+  // Only push the selected execution context when a real target is selected.
+  // The command may create and select a target (e.g. "target create"), and any
+  // command it runs afterwards must see that target, not the dummy target.
   ExecutionContext exe_ctx =
-      m_debugger.GetSelectedExecutionContext(/*adopt_dummy_target=*/true);
+      m_debugger.GetSelectedExecutionContext(/*adopt_dummy_target=*/false);
   bool pushed_exe_ctx = false;
   if (exe_ctx.HasTargetScope()) {
     OverrideExecutionContext(exe_ctx);
diff --git a/lldb/test/Shell/ScriptInterpreter/Python/nested_command_selected_target.test b/lldb/test/Shell/ScriptInterpreter/Python/nested_command_selected_target.test
new file mode 100644
index 00000000000000..8028dbb4e2978d
--- /dev/null
+++ b/lldb/test/Shell/ScriptInterpreter/Python/nested_command_selected_target.test
@@ -0,0 +1,29 @@
+# Commands run from a script while an outer command is executing must see the
+# target the outer command selected, even if no target was selected when the
+# outer command started. This is what happens when a dSYM's Python scripting
+# resource is auto-loaded during `target create` and changes target or process
+# settings.
+
+# RUN: split-file %s %t
+# RUN: %clang_host -g %t/main.c -o %t/a.out
+# RUN: %lldb -b -o "command script import %t/create_target.py" \
+# RUN:   -o "settings show target.max-string-summary-length target.process.optimization-warnings" \
+# RUN:   2>&1 | FileCheck %s
+
+# CHECK: target.max-string-summary-length (unsigned) = 42
+# CHECK: target.process.optimization-warnings (boolean) = false
+
+#--- main.c
+int main() { return 0; }
+
+#--- create_target.py
+import os
+import lldb
+
+
+def __lldb_init_module(debugger, internal_dict):
+    exe = os.path.join(os.path.dirname(__file__), "a.out")
+    target = debugger.CreateTarget(exe)
+    debugger.SetSelectedTarget(target)
+    debugger.HandleCommand("settings set target.max-string-summary-length 42")
+    debugger.HandleCommand("settings set target.process.optimization-warnings false")



More information about the lldb-commits mailing list