Author: avg
Date: Mon Oct 29 12:47:15 2018
New Revision: 339857
URL: https://svnweb.freebsd.org/changeset/base/339857

Log:
  MFC r337528: add an option for ddb ps command to print process arguments
  
  Sponsored by: Panzura

Modified:
  stable/11/share/man/man4/ddb.4
  stable/11/sys/ddb/db_ps.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/share/man/man4/ddb.4
==============================================================================
--- stable/11/share/man/man4/ddb.4      Mon Oct 29 12:45:08 2018        
(r339856)
+++ stable/11/share/man/man4/ddb.4      Mon Oct 29 12:47:15 2018        
(r339857)
@@ -537,16 +537,15 @@ If the thread is not found, search the thread stack ca
 cached stack address.
 Otherwise, prints nothing.
 .Pp
-.It Ic show Cm all procs Ns Op Li / Ns Cm m
-.It Ic ps Ns Op Li / Ns Cm m
+.It Ic show Cm all procs Ns Op Li / Ns Cm a
+.It Ic ps Ns Op Li / Ns Cm a
 Display all process information.
 The process information may not be shown if it is not
 supported in the machine, or the bottom of the stack of the
 target process is not in the main memory at that time.
 The
-.Cm m
-modifier will alter the display to show VM map
-addresses for the process and not show other information.
+.Cm a
+modifier will print command line arguments for each process.
 .\"
 .Pp
 .It Ic show Cm all trace

Modified: stable/11/sys/ddb/db_ps.c
==============================================================================
--- stable/11/sys/ddb/db_ps.c   Mon Oct 29 12:45:08 2018        (r339856)
+++ stable/11/sys/ddb/db_ps.c   Mon Oct 29 12:47:15 2018        (r339857)
@@ -47,8 +47,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.
@@ -59,6 +64,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
@@ -87,6 +110,7 @@ db_ps(db_expr_t addr, bool hasaddr, db_expr_t count, c
        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))
@@ -204,6 +228,10 @@ db_ps(db_expr_t addr, bool hasaddr, db_expr_t count, c
                        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) {
@@ -296,6 +324,10 @@ dumpthread(volatile struct proc *p, volatile struct th
                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");
 }
 
@@ -442,12 +474,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(" threads: %d\n", p->p_numthreads);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to