[Lldb-commits] [lldb] [lldb] Fix dummy target filtering regression in CommandInterpreter (PR #198949)

Ivan Tadeu Ferreira Antunes Filho via lldb-commits lldb-commits at lists.llvm.org
Fri May 22 09:01:38 PDT 2026


https://github.com/itf updated https://github.com/llvm/llvm-project/pull/198949

>From 6b783610cdd74c98e06ff2e540cadc7a97e9f647 Mon Sep 17 00:00:00 2001
From: ivan tadeu ferreira antunes filho <antunesi at google.com>
Date: Thu, 21 May 2026 00:08:41 +0000
Subject: [PATCH 1/2]    [lldb] Fix dummy target filtering regression in
 CommandInterpreter during script sourcing

---
 .../source/Interpreter/CommandInterpreter.cpp | 12 ++++++++---
 .../Shell/Commands/process-attach-dummy.test  | 20 +++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 lldb/test/Shell/Commands/process-attach-dummy.test

diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 31016b626d621..2f082db2087e3 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -3284,9 +3284,15 @@ void CommandInterpreter::FindCommandsForApropos(llvm::StringRef search_word,
 
 ExecutionContext
 CommandInterpreter::GetExecutionContext(bool adopt_dummy_target) const {
-  return !m_overriden_exe_contexts.empty()
-             ? m_overriden_exe_contexts.top()
-             : m_debugger.GetSelectedExecutionContext(adopt_dummy_target);
+  if (!m_overriden_exe_contexts.empty()) {
+    ExecutionContext override_ctx = m_overriden_exe_contexts.top();
+    if (!adopt_dummy_target && override_ctx.GetTargetPtr() &&
+        override_ctx.GetTargetPtr()->IsDummyTarget()) {
+      override_ctx.Clear();
+    }
+    return override_ctx;
+  }
+  return m_debugger.GetSelectedExecutionContext(adopt_dummy_target);
 }
 
 void CommandInterpreter::OverrideExecutionContext(
diff --git a/lldb/test/Shell/Commands/process-attach-dummy.test b/lldb/test/Shell/Commands/process-attach-dummy.test
new file mode 100644
index 0000000000000..dd592293c29a7
--- /dev/null
+++ b/lldb/test/Shell/Commands/process-attach-dummy.test
@@ -0,0 +1,20 @@
+# Test that process attach correctly creates a real target instead of attaching
+# to the dummy target when executed inside a sourced script or command session.
+#
+# Sourced scripts run by the IOHandler override the execution context to contain
+# the dummy target by default (as a fallback target). When process attach runs,
+# it expects to bypass the dummy target (adopt_dummy_target = false).
+# CommandInterpreter::GetExecutionContext must respect this flag and clear the
+# dummy target from the overridden context, allowing process attach to create
+# and select a new real target.
+#
+# If the bug is present, process attach attaches directly to the dummy target,
+# leaving the main target list empty (target list outputs "No targets.").
+# If the bug is fixed, it successfully creates "target #0: <none>".
+
+# RUN: %lldb -s %s 2>&1 | FileCheck %s
+
+script lldb.debugger.GetCommandInterpreter().HandleCommand("process attach -p 99999", lldb.SBCommandReturnObject())
+
+target list
+# CHECK: target #0: <none>

>From 0ccaca5b559e1035425c03ba7b1e016e8d41dbe2 Mon Sep 17 00:00:00 2001
From: Ivan Tadeu Ferreira Antunes Filho <antunesi at google.com>
Date: Fri, 22 May 2026 12:01:26 -0400
Subject: [PATCH 2/2] Simplify GetExecutionContext logic

---
 lldb/source/Interpreter/CommandInterpreter.cpp | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 2f082db2087e3..64e2da1f0388b 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -3284,15 +3284,9 @@ void CommandInterpreter::FindCommandsForApropos(llvm::StringRef search_word,
 
 ExecutionContext
 CommandInterpreter::GetExecutionContext(bool adopt_dummy_target) const {
-  if (!m_overriden_exe_contexts.empty()) {
-    ExecutionContext override_ctx = m_overriden_exe_contexts.top();
-    if (!adopt_dummy_target && override_ctx.GetTargetPtr() &&
-        override_ctx.GetTargetPtr()->IsDummyTarget()) {
-      override_ctx.Clear();
-    }
-    return override_ctx;
-  }
-  return m_debugger.GetSelectedExecutionContext(adopt_dummy_target);
+  return (m_overriden_exe_contexts.empty() || !adopt_dummy_target)
+             ? m_debugger.GetSelectedExecutionContext(adopt_dummy_target)
+             : m_overriden_exe_contexts.top();
 }
 
 void CommandInterpreter::OverrideExecutionContext(



More information about the lldb-commits mailing list