[Lldb-commits] [lldb] f119c93 - [lldb] Use the selected target when the override context is the dummy (#226332)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Sep 24 19:04:31 PDT 2026
Author: Med Ismail Bennani
Date: 2026-09-24T19:04:25-07:00
New Revision: f119c93418ebd6aa3a95b7346fe3f6c86fba57f7
URL: https://github.com/llvm/llvm-project/commit/f119c93418ebd6aa3a95b7346fe3f6c86fba57f7
DIFF: https://github.com/llvm/llvm-project/commit/f119c93418ebd6aa3a95b7346fe3f6c86fba57f7.diff
LOG: [lldb] Use the selected target when the override context is the dummy (#226332)
Added:
lldb/test/Shell/ScriptInterpreter/Python/nested_command_selected_target.test
Modified:
lldb/source/Interpreter/CommandInterpreter.cpp
Removed:
################################################################################
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 12578ca56a967..6d361470039fd 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 0000000000000..8028dbb4e2978
--- /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