Module Name: src Committed By: christos Date: Sun Apr 10 20:59:22 UTC 2011
Modified Files: src/sys/ddb: db_command.c db_interface.h db_proc.c Log Message: Add: usage: show proc [/a] [/p] address|pid /a == argument is an address of any lwp /p == argument is a pid [default] From: Vladimir Kirillov proger at wilab dot org dot ua To generate a diff of this commit: cvs rdiff -u -r1.134 -r1.135 src/sys/ddb/db_command.c cvs rdiff -u -r1.25 -r1.26 src/sys/ddb/db_interface.h cvs rdiff -u -r1.3 -r1.4 src/sys/ddb/db_proc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/ddb/db_command.c diff -u src/sys/ddb/db_command.c:1.134 src/sys/ddb/db_command.c:1.135 --- src/sys/ddb/db_command.c:1.134 Mon Sep 13 04:42:04 2010 +++ src/sys/ddb/db_command.c Sun Apr 10 16:59:22 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: db_command.c,v 1.134 2010/09/13 08:42:04 drochner Exp $ */ +/* $NetBSD: db_command.c,v 1.135 2011/04/10 20:59:22 christos Exp $ */ /* * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.134 2010/09/13 08:42:04 drochner Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.135 2011/04/10 20:59:22 christos Exp $"); #ifdef _KERNEL_OPT #include "opt_aio.h" @@ -219,10 +219,12 @@ #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: src/sys/ddb/db_interface.h diff -u src/sys/ddb/db_interface.h:1.25 src/sys/ddb/db_interface.h:1.26 --- src/sys/ddb/db_interface.h:1.25 Wed Feb 18 08:31:59 2009 +++ src/sys/ddb/db_interface.h Sun Apr 10 16:59:22 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: db_interface.h,v 1.25 2009/02/18 13:31:59 yamt Exp $ */ +/* $NetBSD: db_interface.h,v 1.26 2011/04/10 20:59:22 christos Exp $ */ /*- * Copyright (c) 1995 The NetBSD Foundation, Inc. @@ -46,6 +46,7 @@ /* 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: src/sys/ddb/db_proc.c diff -u src/sys/ddb/db_proc.c:1.3 src/sys/ddb/db_proc.c:1.4 --- src/sys/ddb/db_proc.c:1.3 Mon Mar 9 02:07:05 2009 +++ src/sys/ddb/db_proc.c Sun Apr 10 16:59:22 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: db_proc.c,v 1.3 2009/03/09 06:07:05 mrg Exp $ */ +/* $NetBSD: db_proc.c,v 1.4 2011/04/10 20:59:22 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: db_proc.c,v 1.3 2009/03/09 06:07:05 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_proc.c,v 1.4 2011/04/10 20:59:22 christos Exp $"); #ifndef _KERNEL #include <stdbool.h> @@ -129,8 +129,8 @@ 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 @@ } } +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); + } +}