tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

diff: add show proc command to ddb



Hello, tech-kern@!

I really wanted a show proc command to avoid looking up process
information by running ps with all flags and intensive scrolling.

The show proc output mostly combines the outputs of all switches
in ps.

Also some minor fixes applied.

Example output (using crash):

crash> show proc 0t1
init: pid 1 proc ffff800047f8ecd0 vmspace/map ffff800047f93e60 flags 4001
  lwp 1 ffff800047f969c0 pcb ffff800048d1bd80
    stat 3 flags 80 cpu 1 pri 42
    wmesg wait wchan ffff800047f8ed00
crash> ps | grep python
1507   200 5   0         0   ffff80005c081740          python2.6
1507     5 3   0        80   ffff80005d018460          python2.6 select
1507     4 3   1        80   ffff80005d018880          python2.6 select
1507     3 3   0        80   ffff80005c865020          python2.6 select
1507     2 3   0        80   ffff80005c785000          python2.6 parked
1507     1 3   0        80   ffff80005c782780          python2.6 select
crash> show proc /a ffff80005c081740
lwp_t ffff80005c081740
python2.6: pid 1507 proc ffff80005b9017d8 vmspace/map ffff80005da7e8b8 flags 400
0
  lwp 200 ffff80005c081740 pcb ffff80005dabfd80
    stat 5 flags 0 cpu 0 pri 43
  lwp 5 ffff80005d018460 pcb ffff80005d023d80
    stat 3 flags 80 cpu 0 pri 43
    wmesg select wchan ffff80004743f1c0
  lwp 4 ffff80005d018880 pcb ffff80005cabfd80
    stat 3 flags 80 cpu 1 pri 43
    wmesg select wchan ffff80004743f240
  lwp 3 ffff80005c865020 pcb ffff80005cabbd80
    stat 3 flags 80 cpu 0 pri 43
    wmesg select wchan ffff80004743f1c0
  lwp 2 ffff80005c785000 pcb ffff80005c7cbd80
    stat 3 flags 80 cpu 0 pri 41
    wmesg parked wchan fffff1dd00c2af88
  lwp 1 ffff80005c782780 pcb ffff80005c7e0d80
    stat 3 flags 80 cpu 0 pri 43
    wmesg select wchan ffff80004743f1c0
crash> show proc
usage: show proc [/a] [/p] address|pid
        /a == argument is an address of any lwp
        /p == argument is a pid [default]


Index: db_command.c
===================================================================
RCS file: /cvsroot/src/sys/ddb/db_command.c,v
retrieving revision 1.134
diff -u -p -r1.134 db_command.c
--- db_command.c        13 Sep 2010 08:42:04 -0000      1.134
+++ db_command.c        5 Apr 2011 23:06:17 -0000
@@ -219,10 +219,12 @@ static const struct db_command db_show_c
 #endif
        { DDB_ADD_CMD("pages",  db_show_all_pages,
            0 ,"List all used memory pages.",NULL,NULL) },
+       { DDB_ADD_CMD("proc",   db_show_proc,
+           0 ,"Print process information.",NULL,NULL) },
        { DDB_ADD_CMD("procs",  db_show_all_procs,
            0 ,"List all processes.",NULL,NULL) },
        { DDB_ADD_CMD("pools",  db_show_all_pools,
-           0 ,"Show all poolS",NULL,NULL) },
+           0 ,"Show all pools",NULL,NULL) },
 #ifdef AIO
        /*added from all sub cmds*/
        { DDB_ADD_CMD("aio_jobs",       db_show_aio_jobs,       0,
Index: db_interface.h
===================================================================
RCS file: /cvsroot/src/sys/ddb/db_interface.h,v
retrieving revision 1.25
diff -u -p -r1.25 db_interface.h
--- db_interface.h      18 Feb 2009 13:31:59 -0000      1.25
+++ db_interface.h      5 Apr 2011 23:06:17 -0000
@@ -46,6 +46,7 @@ void          db_show_files_cmd(db_expr_t, bool,
 
 /* kern/kern_proc.c */
 void           db_kill_proc(db_expr_t, bool, db_expr_t, const char *);
+void           db_show_proc(db_expr_t, bool, db_expr_t, const char *);
 void           db_show_all_procs(db_expr_t, bool, db_expr_t, const char *);
 void           db_show_all_pools(db_expr_t, bool, db_expr_t, const char *);
 void           db_show_sched_qs(db_expr_t, bool, db_expr_t, const char *);
Index: db_proc.c
===================================================================
RCS file: /cvsroot/src/sys/ddb/db_proc.c,v
retrieving revision 1.3
diff -u -p -r1.3 db_proc.c
--- db_proc.c   9 Mar 2009 06:07:05 -0000       1.3
+++ db_proc.c   5 Apr 2011 23:06:17 -0000
@@ -129,8 +129,8 @@ db_show_all_procs(db_expr_t addr, bool h
        if (mode == NULL || *mode == 'm') {
                db_printf("usage: show all procs [/a] [/l] [/n] [/w]\n");
                db_printf("\t/a == show process address info\n");
-               db_printf("\t/l == show LWP info\n");
-               db_printf("\t/n == show normal process info [default]\n");
+               db_printf("\t/l == show LWP info [default]\n");
+               db_printf("\t/n == show normal process info\n");
                db_printf("\t/w == show process wait/emul info\n");
                return;
        }
@@ -257,3 +257,86 @@ db_show_all_procs(db_expr_t addr, bool h
        }
 }
 
+void
+db_show_proc(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
+{
+       static proc_t p;
+       static lwp_t l;
+       const char *mode;
+       proc_t *pp;
+       lwp_t *lp;
+       char db_nbuf[MAXCOMLEN + 1], wbuf[MAXCOMLEN + 1];
+       bool run;
+       int cpuno;
+
+       if (modif[0] == 0)
+               mode = "p";                     /* default == by pid */
+       else
+               mode = strchr("ap", modif[0]);
+
+       if (mode == NULL || !haddr) {
+               db_printf("usage: show proc [/a] [/p] address|pid\n");
+               db_printf("\t/a == argument is an address of any lwp\n");
+               db_printf("\t/p == argument is a pid [default]\n");
+               return;
+       }
+
+       switch (*mode) {
+       case 'a':
+               lp = (lwp_t *)addr;
+               db_printf("lwp_t %lx\n", (long)lp);
+               db_read_bytes((db_addr_t)lp, sizeof(l), (char *)&l);
+               pp = l.l_proc;
+               break;
+       default:
+       case 'p':
+               pp = db_proc_find((pid_t)addr);
+               lp = NULL;
+               break;
+       }
+
+       if (pp == NULL) {
+               db_printf("bad address\n");
+               return;
+       }
+
+       db_read_bytes((db_addr_t)pp, sizeof(p), (char *)&p);
+       if (lp == NULL)
+               lp = p.p_lwps.lh_first;
+
+       db_printf("%s: pid %d proc %lx vmspace/map %lx flags %x\n",
+           p.p_comm, p.p_pid, (long)pp, (long)p.p_vmspace, p.p_flag);
+
+       while (lp != NULL) {
+               db_read_bytes((db_addr_t)lp, sizeof(l), (char *)&l);
+
+               run = (l.l_stat == LSONPROC ||
+                   (l.l_pflag & LP_RUNNING) != 0);
+
+               db_printf("%slwp %d", (run ? "> " : "  "), l.l_lid);
+               if (l.l_name != NULL) {
+                       db_read_bytes((db_addr_t)l.l_name,
+                           MAXCOMLEN, db_nbuf);
+                       db_printf(" [%s]", db_nbuf);
+               }
+               db_printf(" %lx pcb %lx\n", (long)lp, (long)l.l_addr);
+
+               if (l.l_cpu != NULL) {
+                       db_read_bytes((db_addr_t)
+                           &l.l_cpu->ci_data.cpu_index,
+                           sizeof(cpuno), (char *)&cpuno);
+               } else
+                       cpuno = -1;
+               db_printf("    stat %d flags %x cpu %d pri %d \n",
+                   l.l_stat, l.l_flag, cpuno, l.l_priority);
+
+               if (l.l_wchan && l.l_wmesg) {
+                       db_read_bytes((db_addr_t)l.l_wmesg,
+                           sizeof(wbuf), (char *)wbuf);
+                       db_printf("    wmesg %s wchan %lx\n",
+                           wbuf, (long)l.l_wchan);
+               }
+
+               lp = LIST_NEXT(&l, l_sibling);
+       }
+}


Home | Main Index | Thread Index | Old Index