[Lldb-commits] [lldb] [lldb-dap] Create an empty target when the attach program is a process name (PR #233684)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 19 22:11:18 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Nathan Fusselman (nathanfusselman)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/233684.diff
2 Files Affected:
- (modified) lldb/test/API/tools/lldb-dap/attach-commands/TestDAP_attachCommands.py (+25)
- (modified) lldb/tools/lldb-dap/DAP.cpp (+8)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/233684
More information about the lldb-commits
mailing list