Provide pid_to_exec_file on Solaris (PR tdep/17903)
Commit Message
Hi Tom,
> Rainer> + scoped_fd fd (open (name, O_RDONLY));
>
> You may wish to use gdb_open_cloexec.
this worked just as well, so after retesting on amd64-pc-solaris2.11,
I've committed the following patch.
Thanks.
Rainer
# HG changeset patch
# Parent 020f5ee983bb3daaef32d4d8424e6f60d24111c2
Provide pid_to_exec_file on Solaris
@@ -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; }
@@ -3138,6 +3140,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/<proc-id>/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/<proc-id>/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