Rewrite nbsd_nat_target::pid_to_exec_file to sysctl(3)
authorKamil Rytarowski <n54@gmx.com>
Sat, 14 Mar 2020 23:12:53 +0000 (00:12 +0100)
committerKamil Rytarowski <n54@gmx.com>
Tue, 17 Mar 2020 09:22:51 +0000 (10:22 +0100)
procfs on NetBSD is optional and not recommended.

* nbsd-nat.c: Include <sys/types.h>, <sys/ptrace.h> and
<sys/sysctl.h>.
* nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite.

gdb/ChangeLog
gdb/nbsd-nat.c

index 3c9215060a93c12469ababe932be382efecce662..cb2e91be8d07325fd03b25358d7cfe17f02efa58 100644 (file)
@@ -1,3 +1,9 @@
+2020-03-17  Kamil Rytarowski  <n54@gmx.com>
+
+       * nbsd-nat.c: Include <sys/types.h>, <sys/ptrace.h> and
+       <sys/sysctl.h>.
+       * nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite.
+
 2020-03-17  Tom de Vries  <tdevries@suse.de>
 
        PR gdb/23710
index e7f91bebb0df670955c20016ee518e5a601f3748..326bbe3aec30807f298f80599bb6f0754b328259 100644 (file)
 
 #include "nbsd-nat.h"
 
+#include <sys/types.h>
+#include <sys/ptrace.h>
+#include <sys/sysctl.h>
+
 /* Return the name of a file that can be opened to get the symbols for
    the child process identified by PID.  */
 
 char *
 nbsd_nat_target::pid_to_exec_file (int pid)
 {
-  ssize_t len;
   static char buf[PATH_MAX];
-  char name[PATH_MAX];
-
-  xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
-  len = readlink (name, buf, PATH_MAX - 1);
-  if (len != -1)
-    {
-      buf[len] = '\0';
-      return buf;
-    }
-
-  return NULL;
+  size_t buflen;
+  int mib[4] = {CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_PATHNAME};
+  buflen = sizeof (buf);
+  if (sysctl (mib, ARRAY_SIZE (mib), buf, &buflen, NULL, 0))
+    return NULL;
+  return buf;
 }
This page took 0.027134 seconds and 4 git commands to generate.