[Lldb-commits] [lldb] [lldb-dap] Create an empty target when the attach program is a process name (PR #233684)
Nathan Fusselman via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 19 22:10:38 PDT 2026
https://github.com/nathanfusselman created https://github.com/llvm/llvm-project/pull/233684
Attach by name passes a process name as program, which CreateTarget can't load, so its error leaked into the rest of attach (attachCommands failed after succeeding). Fall back to an empty target for attach.
rdar://190247729
>From a8ee9b36022fec0f6e2cd7a7e1c4562021ee22c7 Mon Sep 17 00:00:00 2001
From: Nathan Fusselman <nfusselman at apple.com>
Date: Mon, 19 Oct 2026 22:03:48 -0700
Subject: [PATCH] [lldb-dap] Create an empty target when the attach program is
a process name
Attach by name passes a process name as program, which CreateTarget
can't load, so its error leaked into the rest of attach (attachCommands
failed after succeeding). Fall back to an empty target for attach.
rdar://190247729
---
.../attach-commands/TestDAP_attachCommands.py | 25 +++++++++++++++++++
lldb/tools/lldb-dap/DAP.cpp | 8 ++++++
2 files changed, 33 insertions(+)
diff --git a/lldb/test/API/tools/lldb-dap/attach-commands/TestDAP_attachCommands.py b/lldb/test/API/tools/lldb-dap/attach-commands/TestDAP_attachCommands.py
index ffe3b77d2f5e5..0dce62709d0bf 100644
--- a/lldb/test/API/tools/lldb-dap/attach-commands/TestDAP_attachCommands.py
+++ b/lldb/test/API/tools/lldb-dap/attach-commands/TestDAP_attachCommands.py
@@ -124,6 +124,31 @@ def test_attach_command_process_failures(self):
"attachCommands failed to attach to a process", response_error.format
)
+ @skipIfNetBSD # Hangs on NetBSD as well
+ @skipIfWasm # the test releases the inferior with an expression
+ def test_program_is_process_name(self):
+ """
+ Tests that "attachCommands" attach when "program" is a process name,
+ which is not a file lldb can create a target from.
+ """
+ program = self.getBuildArtifact("a.out")
+ session = self.build_and_create_session()
+
+ process_event = session.attach(
+ AttachArgs(
+ program="no-such-process-name",
+ attachCommands=[
+ f'target create -d "{program}"',
+ "process launch --stop-at-user-entry",
+ ],
+ stopOnEntry=True,
+ )
+ )
+ session.verify_stopped_on_entry(after=process_event)
+
+ session.evaluate("`expression is_ready = 1", context="repl")
+ session.continue_to_exit()
+
@skipIfNetBSD # Hangs on NetBSD as well
def test_terminate_commands(self):
"""
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 5a816ec4ccbb9..70142ec4c2457 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -686,6 +686,14 @@ lldb::SBTarget DAP::CreateTarget(lldb::SBError &error) {
/*add_dependent_modules=*/true, // Add dependent modules.
error);
+ // For an attach, the program may be a process name rather than a file.
+ if (!target.IsValid() && is_attach) {
+ target = this->debugger.CreateTarget(
+ /*filename=*/"", configuration.targetTriple.c_str(),
+ configuration.platformName.c_str(),
+ /*add_dependent_modules=*/false, error);
+ }
+
return target;
}
More information about the lldb-commits
mailing list