From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2023) id 312EC385DC06; Tue, 14 Apr 2020 15:38:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 312EC385DC06 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Kamil Rytarowski To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Implement IP_STAT+IP_STATUS (aliases of the same format) on NetBSD X-Act-Checkin: binutils-gdb X-Git-Author: Kamil Rytarowski X-Git-Refname: refs/heads/master X-Git-Oldrev: 34ca55313b8e6c0f6354f2dc5a3a35e38c32ae82 X-Git-Newrev: 06ca5dd49ac45e814ca167f441ac0b191b50bb37 Message-Id: <20200414153825.312EC385DC06@sourceware.org> Date: Tue, 14 Apr 2020 15:38:25 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Apr 2020 15:38:25 -0000 https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=06ca5dd49ac45e814ca167f441ac0b191b50bb37 commit 06ca5dd49ac45e814ca167f441ac0b191b50bb37 Author: Kamil Rytarowski 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 + + * nbsd-nat.c (nbsd_pid_to_kinfo_proc2): New. + (nbsd_nat_target::info_proc): Add do_status. + 2020-04-14 Simon Marchi Tom de Vries 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 (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 @@ -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; }