Skip to content

Commit 9544943

Browse files
authored
[lldb-dap] Specify the executable path in the attach info (llvm#138557)
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 llvm#138197
1 parent 673047e commit 9544943

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lldb/tools/lldb-dap/Handler/AttachRequestHandler.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const {
4949
llvm::json::Object response;
5050
lldb::SBError error;
5151
FillResponse(request, response);
52-
lldb::SBAttachInfo attach_info;
5352
const int invalid_port = 0;
5453
const auto *arguments = request.getObject("arguments");
5554
const lldb::pid_t pid =
@@ -58,10 +57,7 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const {
5857
GetInteger<uint64_t>(arguments, "gdb-remote-port").value_or(invalid_port);
5958
const auto gdb_remote_hostname =
6059
GetString(arguments, "gdb-remote-hostname").value_or("localhost");
61-
if (pid != LLDB_INVALID_PROCESS_ID)
62-
attach_info.SetProcessID(pid);
6360
const auto wait_for = GetBoolean(arguments, "waitFor").value_or(false);
64-
attach_info.SetWaitForLaunch(wait_for, false /*async*/);
6561
dap.configuration.initCommands = GetStrings(arguments, "initCommands");
6662
dap.configuration.preRunCommands = GetStrings(arguments, "preRunCommands");
6763
dap.configuration.postRunCommands = GetStrings(arguments, "postRunCommands");
@@ -161,7 +157,13 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const {
161157
dap.target.ConnectRemote(listener, connect_url.c_str(), "gdb-remote",
162158
error);
163159
} else {
164-
// Attach by process name or id.
160+
// Attach by pid or process name.
161+
lldb::SBAttachInfo attach_info;
162+
if (pid != LLDB_INVALID_PROCESS_ID)
163+
attach_info.SetProcessID(pid);
164+
else if (dap.configuration.program.has_value())
165+
attach_info.SetExecutable(dap.configuration.program->data());
166+
attach_info.SetWaitForLaunch(wait_for, false /*async*/);
165167
dap.target.Attach(attach_info, error);
166168
}
167169
} else {

0 commit comments

Comments
 (0)