Fix internal warning when "gdb -p xxx"
[deliverable/binutils-gdb.git] / gdb / fbsd-nat.c
index a2a1f60ec4b4a2f3c1a2e09199182f7beeb93bf2..9f30edf4b27b997f3ed9c71e562a9ea7eece4efd 100644 (file)
@@ -39,9 +39,9 @@
 char *
 fbsd_pid_to_exec_file (struct target_ops *self, int pid)
 {
-  size_t len = PATH_MAX;
-  char *buf = xcalloc (len, sizeof (char));
-  char *path;
+  ssize_t len = PATH_MAX;
+  static char buf[PATH_MAX];
+  char name[PATH_MAX];
 
 #ifdef KERN_PROC_PATHNAME
   int mib[4];
@@ -54,15 +54,15 @@ fbsd_pid_to_exec_file (struct target_ops *self, int pid)
     return buf;
 #endif
 
-  path = xstrprintf ("/proc/%d/file", pid);
-  if (readlink (path, buf, PATH_MAX - 1) == -1)
+  xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
+  len = readlink (name, buf, PATH_MAX - 1);
+  if (len != -1)
     {
-      xfree (buf);
-      buf = NULL;
+      buf[len] = '\0';
+      return buf;
     }
 
-  xfree (path);
-  return buf;
+  return NULL;
 }
 
 static int
This page took 0.119924 seconds and 4 git commands to generate.