https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/138557
>From 8289d760034dc18315d116aaeddda9033ff1390a Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere <jo...@devlieghere.com> Date: Mon, 5 May 2025 10:18:12 -0700 Subject: [PATCH 1/2] [lldb-dap] Specify the executable path in the attach info Currently, we are only using the executable name when attaching. The AttachRequestHandler isn't setting the path in the attach info, which means that we rely on the target when attaching by name. When wo go down this path, we only look at the executable's filename, not its full path. Since we know the full path from the attach arguments, we should specify it in the attach info. Fixes #138197 --- lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp index 7084d30f2625b..a509aa09a385c 100644 --- a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp @@ -49,7 +49,6 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { llvm::json::Object response; lldb::SBError error; FillResponse(request, response); - lldb::SBAttachInfo attach_info; const int invalid_port = 0; const auto *arguments = request.getObject("arguments"); const lldb::pid_t pid = @@ -58,10 +57,7 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { GetInteger<uint64_t>(arguments, "gdb-remote-port").value_or(invalid_port); const auto gdb_remote_hostname = GetString(arguments, "gdb-remote-hostname").value_or("localhost"); - if (pid != LLDB_INVALID_PROCESS_ID) - attach_info.SetProcessID(pid); const auto wait_for = GetBoolean(arguments, "waitFor").value_or(false); - attach_info.SetWaitForLaunch(wait_for, false /*async*/); dap.configuration.initCommands = GetStrings(arguments, "initCommands"); dap.configuration.preRunCommands = GetStrings(arguments, "preRunCommands"); dap.configuration.postRunCommands = GetStrings(arguments, "postRunCommands"); @@ -161,7 +157,13 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { dap.target.ConnectRemote(listener, connect_url.c_str(), "gdb-remote", error); } else { - // Attach by process name or id. + // Attach by pid or process name. + lldb::SBAttachInfo attach_info; + if (pid != LLDB_INVALID_PROCESS_ID) + attach_info.SetProcessID(pid); + if (dap.configuration.program.has_value()) + attach_info.SetExecutable(dap.configuration.program->data()); + attach_info.SetWaitForLaunch(wait_for, false /*async*/); dap.target.Attach(attach_info, error); } } else { >From 67cf8207acca1856c05c84fd6d3b82efd1409483 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere <jo...@devlieghere.com> Date: Mon, 5 May 2025 12:33:58 -0700 Subject: [PATCH 2/2] Address Jacob's feedback --- lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp index a509aa09a385c..7a0f091128e4a 100644 --- a/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp @@ -161,7 +161,7 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const { lldb::SBAttachInfo attach_info; if (pid != LLDB_INVALID_PROCESS_ID) attach_info.SetProcessID(pid); - if (dap.configuration.program.has_value()) + else if (dap.configuration.program.has_value()) attach_info.SetExecutable(dap.configuration.program->data()); attach_info.SetWaitForLaunch(wait_for, false /*async*/); dap.target.Attach(attach_info, error); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits