]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add netbsd_nat::pid_to_exec_file
authorKamil Rytarowski <n54@gmx.com>
Wed, 2 Sep 2020 17:08:37 +0000 (19:08 +0200)
committerKamil Rytarowski <n54@gmx.com>
Thu, 10 Sep 2020 13:37:32 +0000 (15:37 +0200)
gdb/ChangeLog:

        * netbsd-nat.h: Include <unistd.h>.
        * (netbsd_nat::pid_to_exec_file): Add.
        * netbsd-nat.c: Include <sys/types.h> and <sys/sysctl.h>.
        * (netbsd_nat::pid_to_exec_file) Add.

gdb/ChangeLog
gdb/nat/netbsd-nat.c
gdb/nat/netbsd-nat.h

index b4042befb9b4d78d3bb83b917b829336a650338a..2b8a0ac9e3a426419ae34790815162ed62a90a3d 100644 (file)
@@ -1,3 +1,10 @@
+2020-09-10  Kamil Rytarowski  <n54@gmx.com>
+
+       * netbsd-nat.h: Include <unistd.h>.
+       * (netbsd_nat::pid_to_exec_file): Add.
+       * netbsd-nat.c: Include <sys/types.h> and <sys/sysctl.h>.
+       * (netbsd_nat::pid_to_exec_file) Add.
+
 2020-09-10  Kamil Rytarowski  <n54@gmx.com>
 
        * configure.nat (NATDEPFILES): Add nat/netbsd-nat.o when needed.
index 2b5a4183e30acf9535c2cb39e6e60ff05de17628..a63ac04a39c2f883488909de75868f056eeeb266 100644 (file)
 
 #include "nat/netbsd-nat.h"
 
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
 namespace netbsd_nat
 {
+
+/* See netbsd-nat.h.  */
+
+const char *
+pid_to_exec_file (pid_t pid)
+{
+  static char buf[PATH_MAX];
+  int mib[4] = {CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_PATHNAME};
+  size_t buflen = sizeof (buf);
+  if (::sysctl (mib, ARRAY_SIZE (mib), buf, &buflen, NULL, 0) != 0)
+    return NULL;
+  return buf;
+}
+
 }
index 5fa08746610e4f92869cccd9235102d36f6caa51..d11fadd247c1d09a3142ffcfe45fe179207769c8 100644 (file)
 #ifndef NAT_NETBSD_NAT_H
 #define NAT_NETBSD_NAT_H
 
+#include <unistd.h>
+
 namespace netbsd_nat
 {
+
+/* Return the executable file name of a process specified by PID.  Returns the
+   string in a static buffer.  */
+
+extern const char *pid_to_exec_file (pid_t pid);
+
 }
 
 #endif