public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Kamil Rytarowski <krytarowski@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Implement IP_STAT+IP_STATUS (aliases of the same format) on NetBSD
Date: Tue, 14 Apr 2020 15:38:25 +0000 (GMT)	[thread overview]
Message-ID: <20200414153825.312EC385DC06@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=06ca5dd49ac45e814ca167f441ac0b191b50bb37

commit 06ca5dd49ac45e814ca167f441ac0b191b50bb37
Author: Kamil Rytarowski <n54@gmx.com>
Date:   Mon Apr 13 13:05:59 2020 +0200

    Implement IP_STAT+IP_STATUS (aliases of the same format) on NetBSD
    
    Output based on FreeBSD with the following changes:
     - "utime+stime, children" merged from "utime, children" and
       "stime, children".
     - "Minor faults, children", "Major faults, children",
       "Virtual memory size" removed as not available in a direct
       equivalent.
    
    No new values missing or skipped in FreeBSD are printed, although
    there is a long list of potential candiates.
    
    gdb/ChangeLog:
    
            * nbsd-nat.c (nbsd_pid_to_kinfo_proc2): New.
            (nbsd_nat_target::info_proc): Add do_status.

Diff:
---
 gdb/ChangeLog  |   5 +++
 gdb/nbsd-nat.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 108 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b0543725c2f..8998636a1d7 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2020-04-14  Kamil Rytarowski  <n54@gmx.com>
+
+	* nbsd-nat.c (nbsd_pid_to_kinfo_proc2): New.
+	(nbsd_nat_target::info_proc): Add do_status.
+
 2020-04-14  Simon Marchi  <simon.marchi@polymtl.ca>
 	    Tom de Vries  <tdevries@suse.de>
 
diff --git a/gdb/nbsd-nat.c b/gdb/nbsd-nat.c
index 5eaf9dec8af..d41cfc815d3 100644
--- a/gdb/nbsd-nat.c
+++ b/gdb/nbsd-nat.c
@@ -58,6 +58,19 @@ nbsd_pid_to_cwd (int pid)
   return buf;
 }
 
+/* Return the kinfo_proc2 structure for the process identified by PID.  */
+
+static bool
+nbsd_pid_to_kinfo_proc2 (pid_t pid, struct kinfo_proc2 *kp)
+{
+  gdb_assert (kp != nullptr);
+
+  size_t size = sizeof (*kp);
+  int mib[6] = {CTL_KERN, KERN_PROC2, KERN_PROC_PID, pid,
+		static_cast<int> (size), 1};
+  return !sysctl (mib, ARRAY_SIZE (mib), kp, &size, NULL, 0);
+}
+
 /* Return the command line for the process identified by PID.  */
 
 static gdb::unique_xmalloc_ptr<char[]>
@@ -344,6 +357,7 @@ nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
   bool do_cwd = false;
   bool do_exe = false;
   bool do_mappings = false;
+  bool do_status = false;
 
   switch (what)
     {
@@ -352,6 +366,10 @@ nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
       do_cwd = true;
       do_exe = true;
       break;
+    case IP_STAT:
+    case IP_STATUS:
+      do_status = true;
+      break;
     case IP_MAPPINGS:
       do_mappings = true;
       break;
@@ -369,6 +387,7 @@ nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
       do_cwd = true;
       do_exe = true;
       do_mappings = true;
+      do_status = true;
       break;
     default:
       error (_("Not supported on this target."));
@@ -433,6 +452,90 @@ nbsd_nat_target::info_proc (const char *args, enum info_proc_what what)
       else
 	warning (_("unable to fetch virtual memory map"));
     }
+  if (do_status)
+    {
+      struct kinfo_proc2 kp;
+      if (!nbsd_pid_to_kinfo_proc2 (pid, &kp))
+	warning (_("Failed to fetch process information"));
+      else
+	{
+	  auto process_status
+	    = [] (int8_t stat)
+	      {
+		switch (stat)
+		  {
+		  case SIDL:
+		    return "IDL";
+		  case SACTIVE:
+		    return "ACTIVE";
+		  case SDYING:
+		    return "DYING";
+		  case SSTOP:
+		    return "STOP";
+		  case SZOMB:
+		    return "ZOMB";
+		  case SDEAD:
+		    return "DEAD";
+		  default:
+		    return "? (unknown)";
+		  }
+	      };
+
+	  printf_filtered ("Name: %s\n", kp.p_comm);
+	  printf_filtered ("State: %s\n", process_status(kp.p_realstat));
+	  printf_filtered ("Parent process: %" PRId32 "\n", kp.p_ppid);
+	  printf_filtered ("Process group: %" PRId32 "\n", kp.p__pgid);
+	  printf_filtered ("Session id: %" PRId32 "\n", kp.p_sid);
+	  printf_filtered ("TTY: %" PRId32 "\n", kp.p_tdev);
+	  printf_filtered ("TTY owner process group: %" PRId32 "\n", kp.p_tpgid);
+	  printf_filtered ("User IDs (real, effective, saved): "
+			   "%" PRIu32 " %" PRIu32 " %" PRIu32 "\n",
+			   kp.p_ruid, kp.p_uid, kp.p_svuid);
+	  printf_filtered ("Group IDs (real, effective, saved): "
+			   "%" PRIu32 " %" PRIu32 " %" PRIu32 "\n",
+			   kp.p_rgid, kp.p_gid, kp.p_svgid);
+
+	  printf_filtered ("Groups:");
+	  for (int i = 0; i < kp.p_ngroups; i++)
+	    printf_filtered (" %" PRIu32, kp.p_groups[i]);
+	  printf_filtered ("\n");
+	  printf_filtered ("Minor faults (no memory page): %" PRIu64 "\n",
+			   kp.p_uru_minflt);
+	  printf_filtered ("Major faults (memory page faults): %" PRIu64 "\n",
+			   kp.p_uru_majflt);
+	  printf_filtered ("utime: %" PRIu32 ".%06" PRIu32 "\n",
+			   kp.p_uutime_sec, kp.p_uutime_usec);
+	  printf_filtered ("stime: %" PRIu32 ".%06" PRIu32 "\n",
+			   kp.p_ustime_sec, kp.p_ustime_usec);
+	  printf_filtered ("utime+stime, children: %" PRIu32 ".%06" PRIu32 "\n",
+			   kp.p_uctime_sec, kp.p_uctime_usec);
+	  printf_filtered ("'nice' value: %" PRIu8 "\n", kp.p_nice);
+	  printf_filtered ("Start time: %" PRIu32 ".%06" PRIu32 "\n",
+			   kp.p_ustart_sec, kp.p_ustart_usec);
+	  int pgtok = getpagesize () / 1024;
+	  printf_filtered ("Data size: %" PRIuMAX " kB\n",
+			   (uintmax_t) kp.p_vm_dsize * pgtok);
+	  printf_filtered ("Stack size: %" PRIuMAX " kB\n",
+			   (uintmax_t) kp.p_vm_ssize * pgtok);
+	  printf_filtered ("Text size: %" PRIuMAX " kB\n",
+			   (uintmax_t) kp.p_vm_tsize * pgtok);
+	  printf_filtered ("Resident set size: %" PRIuMAX " kB\n",
+			   (uintmax_t) kp.p_vm_rssize * pgtok);
+	  printf_filtered ("Maximum RSS: %" PRIu64 " kB\n", kp.p_uru_maxrss);
+	  printf_filtered ("Pending Signals:");
+	  for (size_t i = 0; i < ARRAY_SIZE (kp.p_siglist.__bits); i++)
+	    printf_filtered (" %08" PRIx32, kp.p_siglist.__bits[i]);
+	  printf_filtered ("\n");
+	  printf_filtered ("Ignored Signals:");
+	  for (size_t i = 0; i < ARRAY_SIZE (kp.p_sigignore.__bits); i++)
+	    printf_filtered (" %08" PRIx32, kp.p_sigignore.__bits[i]);
+	  printf_filtered ("\n");
+	  printf_filtered ("Caught Signals:");
+	  for (size_t i = 0; i < ARRAY_SIZE (kp.p_sigcatch.__bits); i++)
+	    printf_filtered (" %08" PRIx32, kp.p_sigcatch.__bits[i]);
+	  printf_filtered ("\n");
+	}
+    }
 
   return true;
 }


                 reply	other threads:[~2020-04-14 15:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200414153825.312EC385DC06@sourceware.org \
    --to=krytarowski@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).