Introduce linux_proc_pid_to_exec_file
authorGary Benson <gbenson@redhat.com>
Fri, 17 Apr 2015 08:47:30 +0000 (09:47 +0100)
committerGary Benson <gbenson@redhat.com>
Fri, 17 Apr 2015 08:47:30 +0000 (09:47 +0100)
This commit introduces a new function linux_proc_pid_to_exec_file
that shared Linux code can use to discover the filename of the
executable that was run to create a process on the system.

gdb/ChangeLog:

* nat/linux-procfs.h (linux_proc_pid_to_exec_file):
New declaration.
* nat/linux-procfs.c (linux_proc_pid_to_exec_file):
New function, factored out from...
* linux-nat.c (linux_child_pid_to_exec_file): ...here.

gdb/ChangeLog
gdb/linux-nat.c
gdb/nat/linux-procfs.c
gdb/nat/linux-procfs.h

index af853853dcb3cfe901da5de37e945448fff2ad60..ddedf87c98803240d22a5aa2bcbdd5cd1b591650 100644 (file)
@@ -1,3 +1,11 @@
+2015-04-17  Gary Benson <gbenson@redhat.com>
+
+       * nat/linux-procfs.h (linux_proc_pid_to_exec_file):
+       New declaration.
+       * nat/linux-procfs.c (linux_proc_pid_to_exec_file):
+       New function, factored out from...
+       * linux-nat.c (linux_child_pid_to_exec_file): ...here.
+
 2015-04-17  Gary Benson <gbenson@redhat.com>
 
        * exec.c (solist.h): New include.
index 6c198cfe6386ffece519e16a3a78d8060e1e2cd0..b04aa68c79d00e0860805b6d561545efdbbd608b 100644 (file)
@@ -4106,15 +4106,7 @@ linux_nat_thread_name (struct target_ops *self, struct thread_info *thr)
 static char *
 linux_child_pid_to_exec_file (struct target_ops *self, int pid)
 {
-  static char buf[PATH_MAX];
-  char name[PATH_MAX];
-
-  xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
-  memset (buf, 0, PATH_MAX);
-  if (readlink (name, buf, PATH_MAX - 1) <= 0)
-    strcpy (buf, name);
-
-  return buf;
+  return linux_proc_pid_to_exec_file (pid);
 }
 
 /* Implement the to_xfer_partial interface for memory reads using the /proc
index 7599b32ed3eade6072136e8cb99c9ec231802e3e..44364c5fbbd01c570226739e5e2aba49051a4886 100644 (file)
@@ -273,3 +273,22 @@ linux_proc_task_list_dir_exists (pid_t pid)
   xsnprintf (pathname, sizeof (pathname), "/proc/%ld/task", (long) pid);
   return (stat (pathname, &buf) == 0);
 }
+
+/* See linux-procfs.h.  */
+
+char *
+linux_proc_pid_to_exec_file (int pid)
+{
+  static char buf[PATH_MAX];
+  char name[PATH_MAX];
+  ssize_t len;
+
+  xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
+  len = readlink (name, buf, PATH_MAX - 1);
+  if (len <= 0)
+    strcpy (buf, name);
+  else
+    buf[len] = '\0';
+
+  return buf;
+}
index c4f57885b1d0da60e99d818a897d9414a874f3bf..fdbf3838135f790aab76a1cc11e4713f7e05bc21 100644 (file)
@@ -73,4 +73,10 @@ extern void linux_proc_attach_tgid_threads (pid_t pid,
 /* Return true if the /proc/PID/task/ directory exists.  */
 extern int linux_proc_task_list_dir_exists (pid_t pid);
 
+/* Return the full absolute name of the executable file that was run
+   to create the process PID.  The returned value persists until this
+   function is next called.  */
+
+extern char *linux_proc_pid_to_exec_file (int pid);
+
 #endif /* COMMON_LINUX_PROCFS_H */
This page took 0.031623 seconds and 4 git commands to generate.