Skip to content

Commit bbfae10

Browse files
[lldb] Use correct path for lldb-server executable
1 parent 616d104 commit bbfae10

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lldb/tools/lldb-server/lldb-platform.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,13 +545,28 @@ int main_platform(int argc, char *argv[]) {
545545

546546
MainLoop main_loop;
547547
{
548+
char progpath[1024];
549+
#if defined(_WIN32)
550+
if (GetModuleFileName(NULL, progpath, sizeof(progpath)) == 0) {
551+
printf("Error retrieving executable path.\n");
552+
return 1;
553+
}
554+
#else
555+
ssize_t len = readlink("/proc/self/exe", progpath, sizeof(progpath) - 1);
556+
if (len == -1) {
557+
perror("readlink");
558+
return 1;
559+
}
560+
progpath[len] = '\0';
561+
#endif
562+
548563
llvm::Expected<std::vector<MainLoopBase::ReadHandleUP>> platform_handles =
549564
platform_sock->Accept(
550565
main_loop, [progname, gdbserver_port, &inferior_arguments, log_file,
551566
log_channels, &main_loop,
552567
&platform_handles](std::unique_ptr<Socket> sock_up) {
553568
printf("Connection established.\n");
554-
Status error = spawn_process(progname, sock_up.get(),
569+
Status error = spawn_process(progpath, sock_up.get(),
555570
gdbserver_port, inferior_arguments,
556571
log_file, log_channels, main_loop);
557572
if (error.Fail()) {

0 commit comments

Comments
 (0)