aboutsummaryrefslogtreecommitdiff
path: root/sys/ddb/db_ps.c
diff options
context:
space:
mode:
authorAndriy Gapon <avg@FreeBSD.org>2018-08-09 11:21:31 +0000
committerAndriy Gapon <avg@FreeBSD.org>2018-08-09 11:21:31 +0000
commit27cfcd95993f512af6b4a5a5fd764b370e64ef34 (patch)
tree73eef0a2db99dad16aab70c0d98aae4d4bdd27f5 /sys/ddb/db_ps.c
parent6402bc3d1e0ee98ee0c04d0130a0c920e9446cbe (diff)
downloadsrc-27cfcd95993f512af6b4a5a5fd764b370e64ef34.tar.gz
src-27cfcd95993f512af6b4a5a5fd764b370e64ef34.zip
add an option for ddb ps command to print process arguments
We use ps to collect the information of all processes in textdump. But it doesn't contain process arguments which however sometimes are very useful for debugging. The new 'a' modifier adds that capability. While here, remove 'm' modifier from ddb.4. It was in the manual page from its very first revision, but I could not find any evidence of the code ever supporting it. Submitted by: Terry Hu <thu@panzura.com> Reviewed by: kib MFC after: 1 week Sponsored by: Panzura Differential Revision: https://reviews.freebsd.org/D16603
Notes
Notes: svn path=/head/; revision=337528
Diffstat (limited to 'sys/ddb/db_ps.c')
-rw-r--r--sys/ddb/db_ps.c39
1 files changed, 33 insertions, 6 deletions
diff --git a/sys/ddb/db_ps.c b/sys/ddb/db_ps.c
index 0c9687c62fbd..2c7c205785bf 100644
--- a/sys/ddb/db_ps.c
+++ b/sys/ddb/db_ps.c
@@ -50,8 +50,13 @@ __FBSDID("$FreeBSD$");
#include <ddb/ddb.h>
+#define PRINT_NONE 0
+#define PRINT_ARGS 1
+
static void dumpthread(volatile struct proc *p, volatile struct thread *td,
int all);
+static int ps_mode;
+
/*
* At least one non-optional show-command must be implemented using
* DB_SHOW_ALL_COMMAND() so that db_show_all_cmd_set gets created.
@@ -62,6 +67,24 @@ DB_SHOW_ALL_COMMAND(procs, db_procs_cmd)
db_ps(addr, have_addr, count, modif);
}
+static void
+dump_args(volatile struct proc *p)
+{
+ char *args;
+ int i, len;
+
+ if (p->p_args == NULL)
+ return;
+ args = p->p_args->ar_args;
+ len = (int)p->p_args->ar_length;
+ for (i = 0; i < len; i++) {
+ if (args[i] == '\0')
+ db_printf(" ");
+ else
+ db_printf("%c", args[i]);
+ }
+}
+
/*
* Layout:
* - column counts
@@ -90,6 +113,7 @@ db_ps(db_expr_t addr, bool hasaddr, db_expr_t count, char *modif)
char state[9];
int np, rflag, sflag, dflag, lflag, wflag;
+ ps_mode = modif[0] == 'a' ? PRINT_ARGS : PRINT_NONE;
np = nprocs;
if (!LIST_EMPTY(&allproc))
@@ -207,6 +231,10 @@ db_ps(db_expr_t addr, bool hasaddr, db_expr_t count, char *modif)
db_printf("%s", p->p_comm);
if (p->p_flag & P_SYSTEM)
db_printf("]");
+ if (ps_mode == PRINT_ARGS) {
+ db_printf(" ");
+ dump_args(p);
+ }
db_printf("\n");
}
FOREACH_THREAD_IN_PROC(p, td) {
@@ -299,6 +327,10 @@ dumpthread(volatile struct proc *p, volatile struct thread *td, int all)
db_printf("%s", td->td_proc->p_comm);
if (p->p_flag & P_SYSTEM)
db_printf("]");
+ if (ps_mode == PRINT_ARGS && all == 0) {
+ db_printf(" ");
+ dump_args(p);
+ }
db_printf("\n");
}
@@ -445,12 +477,7 @@ DB_SHOW_COMMAND(proc, db_show_proc)
db_printf(" ABI: %s\n", p->p_sysent->sv_name);
if (p->p_args != NULL) {
db_printf(" arguments: ");
- for (i = 0; i < (int)p->p_args->ar_length; i++) {
- if (p->p_args->ar_args[i] == '\0')
- db_printf(" ");
- else
- db_printf("%c", p->p_args->ar_args[i]);
- }
+ dump_args(p);
db_printf("\n");
}
db_printf(" repear: %p reapsubtree: %d\n",