Home | History | Annotate | Line # | Download | only in ddb
db_xxx.c revision 1.11.2.1
      1 /*	$NetBSD: db_xxx.c,v 1.11.2.1 2001/03/05 22:49:32 nathanw Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1989, 1991, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	from: kern_proc.c	8.4 (Berkeley) 1/4/94
     36  */
     37 
     38 /*
     39  * Miscellaneous DDB functions that are intimate (xxx) with various
     40  * data structures and functions used by the kernel (proc, callout).
     41  */
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/kernel.h>
     46 #include <sys/lwp.h>
     47 #include <sys/proc.h>
     48 
     49 #include <sys/callout.h>
     50 #include <sys/signalvar.h>
     51 #include <sys/resourcevar.h>
     52 
     53 #include <machine/db_machdep.h>
     54 
     55 #include <ddb/db_access.h>
     56 #include <ddb/db_command.h>
     57 #include <ddb/db_interface.h>
     58 #include <ddb/db_lex.h>
     59 #include <ddb/db_output.h>
     60 #include <ddb/db_sym.h>
     61 #include <ddb/db_extern.h>
     62 
     63 void
     64 db_kill_proc(addr, haddr, count, modif)
     65 	db_expr_t addr;
     66 	int haddr;
     67 	db_expr_t count;
     68 	char *modif;
     69 {
     70 	struct proc *p;
     71 	db_expr_t pid, sig;
     72 	int t;
     73 
     74 	/* What pid? */
     75 	if (!db_expression(&pid)) {
     76 		db_error("pid?\n");
     77 	    /*NOTREACHED*/
     78 	}
     79 	/* What sig? */
     80 	t = db_read_token();
     81 	if (t == tCOMMA) {
     82 		if (!db_expression(&sig)) {
     83 			db_error("sig?\n");
     84 			/*NOTREACHED*/
     85 		}
     86 	} else {
     87 		db_unread_token(t);
     88 		sig = 15;
     89 	}
     90 	if (db_read_token() != tEOL) {
     91 	    db_error("?\n");
     92 	    /*NOTREACHED*/
     93 	}
     94 
     95 	p = pfind((pid_t)pid);
     96 	if (p == NULL) {
     97 		db_error("no such proc\n");
     98 	    /*NOTREACHED*/
     99 	}
    100 	psignal(p, (int)sig);
    101 }
    102 
    103 void
    104 db_show_all_procs(addr, haddr, count, modif)
    105 	db_expr_t addr;
    106 	int haddr;
    107 	db_expr_t count;
    108 	char *modif;
    109 {
    110 	int i;
    111 
    112 	char *mode;
    113 	struct proc *p, *pp, *cp;
    114 	struct lwp *l, *cl;
    115 	struct timeval tv[3];
    116 	const struct proclist_desc *pd;
    117 
    118 	if (modif[0] == 0)
    119 		modif[0] = 'n';			/* default == normal mode */
    120 
    121 	mode = strchr("mawln", modif[0]);
    122 	if (mode == NULL || *mode == 'm') {
    123 		db_printf("usage: show all procs [/a] [/n] [/w]\n");
    124 		db_printf("\t/a == show process address info\n");
    125 		db_printf("\t/l == show LWP info\n");
    126 		db_printf("\t/n == show normal process info [default]\n");
    127 		db_printf("\t/w == show process wait/emul info\n");
    128 		return;
    129 	}
    130 
    131 	switch (*mode) {
    132 
    133 	case 'a':
    134 		db_printf(" PID       %10s %18s %18s %18s\n",
    135 		    "COMMAND", "STRUCT PROC *", "UAREA *", "VMSPACE/VM_MAP");
    136 		break;
    137 	case 'l':
    138 		db_printf(" PID        %4s S %7s %18s %18s %-12s\n",
    139 		    "LID", "FLAGS", "STRUCT LWP *", "UAREA *", "WAIT");
    140 		break;
    141 	case 'n':
    142 		db_printf(" PID       %8s %8s %10s S %7s %4s %16s %7s\n",
    143 		    "PPID", "PGRP", "UID", "FLAGS", "LWPS", "COMMAND", "WAIT");
    144 		break;
    145 	case 'w':
    146 		db_printf(" PID       %10s %8s %4s %5s %5s %-12s%s\n",
    147 		    "COMMAND", "EMUL", "PRI", "UTIME", "STIME",
    148 		    "WAIT-MSG", "WAIT-CHANNEL");
    149 		break;
    150 	}
    151 
    152 	/* XXX LOCKING XXX */
    153 	pd = proclists;
    154 	cp = curproc ? curproc->l_proc : 0;
    155 	cl = curproc;
    156  loop:
    157 	for (p = LIST_FIRST(pd->pd_list); p != NULL;
    158 	     p = LIST_NEXT(p, p_list)) {
    159 		pp = p->p_pptr;
    160 		if (p->p_stat) {
    161 			l = LIST_FIRST(&p->p_lwps);
    162 			db_printf("%c%-10d", " >"[cp == p], p->p_pid);
    163 
    164 			switch (*mode) {
    165 
    166 			case 'a':
    167 				db_printf("%10.10s %18p %18p %18p\n",
    168 				    p->p_comm, p, l->l_addr, p->p_vmspace);
    169 				break;
    170 			case 'l':
    171 				do {
    172 					db_printf("%c%4d %d %#7x %18p %18p %s\n",
    173 					    " >"[cl == l], l->l_lid,
    174 					    l->l_stat, l->l_flag, l,
    175 					    l->l_addr,
    176 					    (l->l_wchan && l->l_wmesg) ?
    177 					    l->l_wmesg : "");
    178 
    179 					l = LIST_NEXT(l, l_sibling);
    180 					if (l)
    181 						db_printf("%11s","");
    182 				} while (l != NULL);
    183 				break;
    184 			case 'n':
    185 				db_printf("%8d %8d %10d %d %#7x %4d %16s %7.7s\n",
    186 				    pp ? pp->p_pid : -1, p->p_pgrp->pg_id,
    187 				    p->p_cred->p_ruid, p->p_stat, p->p_flag,
    188 				    p->p_nlwps, p->p_comm,
    189 				    (p->p_nlwps > 1) ? "*" : (
    190 				    (l->l_wchan && l->l_wmesg) ?
    191 				    l->l_wmesg : ""));
    192 				break;
    193 
    194 			case 'w':
    195 				db_printf("%10s %8s %4d", p->p_comm,
    196 				    p->p_emul->e_name,l->l_priority);
    197 				calcru(p, tv+0, tv+1, tv+2);
    198 				for(i = 0; i < 2; ++i) {
    199 					db_printf("%4ld.%1ld",
    200 					    (long)tv[i].tv_sec,
    201 					    (long)tv[i].tv_usec/100000);
    202 				}
    203 				if(p->p_nlwps <= 1) {
    204 				if(l->l_wchan && l->l_wmesg) {
    205 					db_printf(" %-12s", l->l_wmesg);
    206 					db_printsym((db_expr_t)l->l_wchan,
    207 					    DB_STGY_XTRN, db_printf);
    208 				} } else {
    209 					db_printf(" * ");
    210 				}
    211 				db_printf("\n");
    212 				break;
    213 
    214 			}
    215 		}
    216 	}
    217 	pd++;
    218 	if (pd->pd_list != NULL)
    219 		goto loop;
    220 }
    221 
    222 void
    223 db_show_callout(addr, haddr, count, modif)
    224 	db_expr_t addr;
    225 	int haddr;
    226 	db_expr_t count;
    227 	char *modif;
    228 {
    229 	extern struct callout_queue *callwheel;
    230 	extern int callwheelsize;
    231 	int i;
    232 
    233 	for (i = 0; i < callwheelsize; i++) {
    234 		struct callout_queue *bucket = &callwheel[i];
    235 		struct callout *c = TAILQ_FIRST(bucket);
    236 
    237 		if (c) db_printf("bucket %d:\n", i);
    238 		while (c) {
    239 			db_printf("%p: time %llx arg %p flags %x func %p: ",
    240 				  c, (long long) c->c_time, c->c_arg,
    241 				  c->c_flags, c->c_func);
    242 			db_printsym((u_long)c->c_func, DB_STGY_PROC, db_printf);
    243 			db_printf("\n");
    244 			c = TAILQ_NEXT(c, c_link);
    245 		}
    246 	}
    247 }
    248