Implement "info proc cwd" for NetBSD
authorKamil Rytarowski <n54@gmx.com>
Sun, 12 Apr 2020 17:24:01 +0000 (19:24 +0200)
committerKamil Rytarowski <n54@gmx.com>
Sun, 12 Apr 2020 18:15:00 +0000 (20:15 +0200)
Add nbsd_pid_to_cwd() to query the program current directory.

gdb/ChangeLog:

* nbsd-nat.c (nbsd_pid_to_cwd): Add.
(nbsd_nat_target::info_proc): Add do_cwd.

gdb/ChangeLog
gdb/nbsd-nat.c

index 3bbd5c3129d09d1eed270a1ca8d9b80c8eb28182..9e49cf9cf97f49835049666d86df8abc98ecd034 100644 (file)
@@ -1,3 +1,8 @@
+2020-04-12  Kamil Rytarowski  <n54@gmx.com>
+
+       * nbsd-nat.c (nbsd_pid_to_cwd): Add.
+        (nbsd_nat_target::info_proc): Add do_cwd.
+
 2020-04-12  Kamil Rytarowski  <n54@gmx.com>
 
        * nbsd-nat.c (nbsd_nat_target::info_proc): Add do_exe.
index 05aedf8e3f1e10aebafc282b9f3b7f8864f5fe2c..1bb35f82c1853cd9f6e37eceb6c0f10f6341d27c 100644 (file)
@@ -44,6 +44,20 @@ nbsd_nat_target::pid_to_exec_file (int pid)
   return buf;
 }
 
+/* Return the current directory for the process identified by PID.  */
+
+static std::string
+nbsd_pid_to_cwd (int pid)
+{
+  char buf[PATH_MAX];
+  size_t buflen;
+  int mib[4] = {CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_CWD};
+  buflen = sizeof (buf);
+  if (sysctl (mib, ARRAY_SIZE (mib), buf, &buflen, NULL, 0))
+    return "";
+  return buf;
+}
+
 /* Generic thread (LWP) lister within a specified process.  The callback
    parameters is a C++ function that is called for each detected thread.  */
 
@@ -299,6 +313,7 @@ bool
 nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
 {
   pid_t pid;
+  bool do_cwd = false;
   bool do_exe = false;
   bool do_mappings = false;
 
@@ -310,6 +325,9 @@ nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
     case IP_EXE:
       do_exe = true;
       break;
+    case IP_CWD:
+      do_cwd = true;
+      break;
     default:
       error (_("Not supported on this target."));
     }
@@ -328,6 +346,14 @@ nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
 
   printf_filtered (_("process %d\n"), pid);
 
+  if (do_cwd)
+    {
+      std::string cwd = nbsd_pid_to_cwd (pid);
+      if (cwd != "")
+       printf_filtered ("cwd = '%s'\n", cwd.c_str ());
+      else
+       warning (_("unable to fetch current working directory"));
+    }
   if (do_exe)
     {
       const char *exe = pid_to_exec_file (pid);
This page took 0.03723 seconds and 4 git commands to generate.