From: Rainer Orth Date: Thu, 20 Sep 2018 09:23:27 +0000 (+0200) Subject: Provide pid_to_exec_file on Solaris (PR tdep/17903) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4206c05ea1542c413a4a361c29cbbd206861946c;p=binutils-gdb.git Provide pid_to_exec_file on Solaris (PR tdep/17903) While looking through gdb.log, I found that two tests FAIL like this: warning: No executable has been specified and target does not support determining executable automatically. Try using the "file" command. 0x00400dc4 in ?? () (gdb) FAIL: gdb.base/attach.exp: attach2, with no file The other is gdb.base/quit-live.exp. I've implemented the following patch that fixes both failures, only then detecting that I'd previously reported the issue as PR tdep/17903. Tested on amd64-pc-solaris2.10 and amd64-pc-solaris2.11. PR tdep/17903 * procfs.c (procfs_target): Declare pid_to_exec_file. (procfs_target::pid_to_exec_file): New. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d0f3fe3cbd4..c767fcd7ca6 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-09-20 Rainer Orth + + PR tdep/17903 + * procfs.c (procfs_target): Declare pid_to_exec_file. + (procfs_target::pid_to_exec_file): New. + 2018-09-20 Rainer Orth * auxv.c (default_print_auxv_entry): Reflect AT_SUN_CAP_HW1 diff --git a/gdb/procfs.c b/gdb/procfs.c index e66c46992af..1fd55d3c7fd 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -128,6 +128,8 @@ public: const char *pid_to_str (ptid_t) override; + char *pid_to_exec_file (int pid) override; + thread_control_capabilities get_thread_control_capabilities () override { return tc_schedlock; } @@ -3214,6 +3216,35 @@ procfs_target::pid_to_str (ptid_t ptid) return buf; } +/* Accepts an integer PID; Returns a string representing a file that + can be opened to get the symbols for the child process. */ + +char * +procfs_target::pid_to_exec_file (int pid) +{ + static char buf[PATH_MAX]; + char name[PATH_MAX]; + + /* Solaris 11 introduced /proc//execname. */ + xsnprintf (name, PATH_MAX, "/proc/%d/execname", pid); + scoped_fd fd (gdb_open_cloexec (name, O_RDONLY, 0)); + if (fd.get () < 0 || read (fd.get (), buf, PATH_MAX - 1) < 0) + { + /* If that fails, fall back to /proc//path/a.out introduced in + Solaris 10. */ + ssize_t len; + + xsnprintf (name, PATH_MAX, "/proc/%d/path/a.out", pid); + len = readlink (name, buf, PATH_MAX - 1); + if (len <= 0) + strcpy (buf, name); + else + buf[len] = '\0'; + } + + return buf; +} + /* Insert a watchpoint. */ static int