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