Home | History | Annotate | Line # | Download | only in ddb
db_xxx.c revision 1.13
      1  1.13  thorpej /*	$NetBSD: db_xxx.c,v 1.13 2001/09/11 04:32:19 thorpej 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.1      gwr #include <sys/proc.h>
     47  1.12   atatat #include <sys/msgbuf.h>
     48   1.1      gwr 
     49   1.1      gwr #include <sys/callout.h>
     50   1.1      gwr #include <sys/signalvar.h>
     51   1.3     ross #include <sys/resourcevar.h>
     52   1.1      gwr 
     53   1.1      gwr #include <machine/db_machdep.h>
     54   1.1      gwr 
     55   1.1      gwr #include <ddb/db_access.h>
     56   1.1      gwr #include <ddb/db_command.h>
     57   1.1      gwr #include <ddb/db_interface.h>
     58   1.1      gwr #include <ddb/db_lex.h>
     59   1.1      gwr #include <ddb/db_output.h>
     60   1.1      gwr #include <ddb/db_sym.h>
     61   1.1      gwr #include <ddb/db_extern.h>
     62   1.1      gwr 
     63   1.1      gwr void
     64   1.1      gwr db_kill_proc(addr, haddr, count, modif)
     65   1.1      gwr 	db_expr_t addr;
     66   1.1      gwr 	int haddr;
     67   1.1      gwr 	db_expr_t count;
     68   1.1      gwr 	char *modif;
     69   1.1      gwr {
     70   1.1      gwr 	struct proc *p;
     71   1.1      gwr 	db_expr_t pid, sig;
     72   1.1      gwr 	int t;
     73   1.1      gwr 
     74   1.1      gwr 	/* What pid? */
     75   1.1      gwr 	if (!db_expression(&pid)) {
     76   1.1      gwr 		db_error("pid?\n");
     77   1.1      gwr 	    /*NOTREACHED*/
     78   1.1      gwr 	}
     79   1.1      gwr 	/* What sig? */
     80   1.1      gwr 	t = db_read_token();
     81   1.1      gwr 	if (t == tCOMMA) {
     82   1.1      gwr 		if (!db_expression(&sig)) {
     83   1.1      gwr 			db_error("sig?\n");
     84   1.1      gwr 			/*NOTREACHED*/
     85   1.1      gwr 		}
     86   1.1      gwr 	} else {
     87   1.1      gwr 		db_unread_token(t);
     88   1.1      gwr 		sig = 15;
     89   1.1      gwr 	}
     90   1.1      gwr 	if (db_read_token() != tEOL) {
     91   1.1      gwr 	    db_error("?\n");
     92   1.1      gwr 	    /*NOTREACHED*/
     93   1.1      gwr 	}
     94   1.1      gwr 
     95   1.1      gwr 	p = pfind((pid_t)pid);
     96   1.1      gwr 	if (p == NULL) {
     97   1.1      gwr 		db_error("no such proc\n");
     98   1.1      gwr 	    /*NOTREACHED*/
     99   1.1      gwr 	}
    100   1.1      gwr 	psignal(p, (int)sig);
    101   1.1      gwr }
    102   1.1      gwr 
    103   1.1      gwr void
    104   1.1      gwr db_show_all_procs(addr, haddr, count, modif)
    105   1.1      gwr 	db_expr_t addr;
    106   1.1      gwr 	int haddr;
    107   1.1      gwr 	db_expr_t count;
    108   1.1      gwr 	char *modif;
    109   1.1      gwr {
    110   1.3     ross 	int i;
    111   1.2    chuck 	char *mode;
    112   1.1      gwr 	struct proc *p, *pp;
    113   1.3     ross 	struct timeval tv[3];
    114   1.5  thorpej 	const struct proclist_desc *pd;
    115   1.1      gwr 
    116   1.2    chuck 	if (modif[0] == 0)
    117   1.2    chuck 		modif[0] = 'n';			/* default == normal mode */
    118   1.2    chuck 
    119   1.2    chuck 	mode = strchr("mawn", modif[0]);
    120   1.2    chuck 	if (mode == NULL || *mode == 'm') {
    121   1.2    chuck 		db_printf("usage: show all procs [/a] [/n] [/w]\n");
    122   1.2    chuck 		db_printf("\t/a == show process address info\n");
    123   1.2    chuck 		db_printf("\t/n == show normal process info [default]\n");
    124   1.2    chuck 		db_printf("\t/w == show process wait/emul info\n");
    125   1.2    chuck 		return;
    126   1.2    chuck 	}
    127   1.2    chuck 
    128   1.2    chuck 	switch (*mode) {
    129   1.2    chuck 
    130   1.2    chuck 	case 'a':
    131   1.3     ross 		db_printf(" PID       %10s %18s %18s %18s\n",
    132   1.2    chuck 		    "COMMAND", "STRUCT PROC *", "UAREA *", "VMSPACE/VM_MAP");
    133   1.2    chuck 		break;
    134   1.2    chuck 	case 'n':
    135   1.3     ross 		db_printf(" PID       %10s %10s %10s S %7s %16s %7s\n",
    136   1.2    chuck 		    "PPID", "PGRP", "UID", "FLAGS", "COMMAND", "WAIT");
    137   1.2    chuck 		break;
    138   1.2    chuck 	case 'w':
    139   1.3     ross 		db_printf(" PID       %10s %8s %4s %5s %5s %-12s%s\n",
    140   1.3     ross 		    "COMMAND", "EMUL", "PRI", "UTIME", "STIME",
    141   1.3     ross 		    "WAIT-MSG", "WAIT-CHANNEL");
    142   1.2    chuck 		break;
    143   1.2    chuck 	}
    144   1.2    chuck 
    145   1.6  thorpej 	/* XXX LOCKING XXX */
    146   1.5  thorpej 	pd = proclists;
    147   1.5  thorpej  loop:
    148   1.5  thorpej 	for (p = LIST_FIRST(pd->pd_list); p != NULL;
    149   1.5  thorpej 	     p = LIST_NEXT(p, p_list)) {
    150   1.1      gwr 		pp = p->p_pptr;
    151   1.1      gwr 		if (p->p_stat) {
    152   1.2    chuck 
    153   1.3     ross 			db_printf("%c%-10d", " >"[curproc == p], p->p_pid);
    154   1.2    chuck 
    155   1.2    chuck 			switch (*mode) {
    156   1.2    chuck 
    157   1.2    chuck 			case 'a':
    158   1.2    chuck 				db_printf("%10.10s %18p %18p %18p\n",
    159   1.2    chuck 				    p->p_comm, p, p->p_addr, p->p_vmspace);
    160   1.2    chuck 				break;
    161   1.2    chuck 
    162   1.2    chuck 			case 'n':
    163   1.2    chuck 				db_printf("%10d %10d %10d %d %#7x %16s %7.7s\n",
    164   1.2    chuck 				    pp ? pp->p_pid : -1, p->p_pgrp->pg_id,
    165   1.2    chuck 				    p->p_cred->p_ruid, p->p_stat, p->p_flag,
    166   1.2    chuck 				    p->p_comm, (p->p_wchan && p->p_wmesg) ?
    167   1.2    chuck 					p->p_wmesg : "");
    168   1.2    chuck 				break;
    169   1.2    chuck 
    170   1.2    chuck 			case 'w':
    171   1.3     ross 				db_printf("%10s %8s %4d", p->p_comm,
    172   1.3     ross 				    p->p_emul->e_name,p->p_priority);
    173   1.3     ross 				calcru(p, tv+0, tv+1, tv+2);
    174   1.3     ross 				for(i = 0; i < 2; ++i) {
    175   1.8   kleink 					db_printf("%4ld.%1ld",
    176   1.8   kleink 					    (long)tv[i].tv_sec,
    177   1.8   kleink 					    (long)tv[i].tv_usec/100000);
    178   1.3     ross 				}
    179   1.3     ross 				if(p->p_wchan && p->p_wmesg) {
    180   1.3     ross 					db_printf(" %-12s", p->p_wmesg);
    181   1.4      eeh 					db_printsym((db_expr_t)p->p_wchan,
    182   1.9    jhawk 					    DB_STGY_XTRN, db_printf);
    183   1.3     ross 				}
    184   1.3     ross 				db_printf("\n");
    185   1.2    chuck 				break;
    186   1.2    chuck 
    187   1.1      gwr 			}
    188   1.1      gwr 		}
    189   1.1      gwr 	}
    190   1.5  thorpej 	pd++;
    191   1.5  thorpej 	if (pd->pd_list != NULL)
    192   1.5  thorpej 		goto loop;
    193   1.1      gwr }
    194   1.1      gwr 
    195   1.1      gwr void
    196   1.1      gwr db_show_callout(addr, haddr, count, modif)
    197   1.1      gwr 	db_expr_t addr;
    198   1.1      gwr 	int haddr;
    199   1.1      gwr 	db_expr_t count;
    200   1.1      gwr 	char *modif;
    201   1.1      gwr {
    202  1.10      eeh 	extern struct callout_queue *callwheel;
    203  1.10      eeh 	extern int callwheelsize;
    204  1.13  thorpej 	uint64_t hint;
    205  1.10      eeh 	int i;
    206   1.1      gwr 
    207  1.11  thorpej 	for (i = 0; i < callwheelsize; i++) {
    208  1.10      eeh 		struct callout_queue *bucket = &callwheel[i];
    209  1.13  thorpej 		struct callout *c = TAILQ_FIRST(&bucket->cq_q);
    210  1.10      eeh 
    211  1.13  thorpej 		if (c) {
    212  1.13  thorpej 			db_printf("bucket %d (hint %llx):\n", i,
    213  1.13  thorpej 			    (long long) bucket->cq_hint);
    214  1.13  thorpej 			hint = UQUAD_MAX;
    215  1.13  thorpej 			while (c) {
    216  1.13  thorpej 				if (c->c_time < hint)
    217  1.13  thorpej 					hint = c->c_time;
    218  1.13  thorpej 				db_printf("%p: time %llx arg %p flags %x "
    219  1.13  thorpej 				    "func %p: ", c, (long long) c->c_time,
    220  1.13  thorpej 				    c->c_arg, c->c_flags, c->c_func);
    221  1.13  thorpej 				db_printsym((u_long)c->c_func, DB_STGY_PROC,
    222  1.13  thorpej 				    db_printf);
    223  1.13  thorpej 				db_printf("\n");
    224  1.13  thorpej 				c = TAILQ_NEXT(c, c_link);
    225  1.13  thorpej 			}
    226  1.13  thorpej 			if (bucket->cq_hint < hint)
    227  1.13  thorpej 				printf("** HINT IS STALE\n");
    228  1.10      eeh 		}
    229  1.10      eeh 	}
    230  1.12   atatat }
    231  1.12   atatat 
    232  1.12   atatat void
    233  1.12   atatat db_dmesg(addr, haddr, count, modif)
    234  1.12   atatat 	db_expr_t addr;
    235  1.12   atatat 	int haddr;
    236  1.12   atatat 	db_expr_t count;
    237  1.12   atatat 	char *modif;
    238  1.12   atatat {
    239  1.12   atatat 	struct kern_msgbuf *mbp;
    240  1.12   atatat 	int ch, newl, skip, i;
    241  1.12   atatat 	char *p, *bufdata;
    242  1.12   atatat 
    243  1.12   atatat 	mbp = msgbufp;
    244  1.12   atatat 	bufdata = &mbp->msg_bufc[0];
    245  1.12   atatat 
    246  1.12   atatat 	for (newl = skip = i = 0, p = bufdata + mbp->msg_bufx;
    247  1.12   atatat 	    i < mbp->msg_bufs; i++, p++) {
    248  1.12   atatat 		if (p == bufdata + mbp->msg_bufs)
    249  1.12   atatat 			p = bufdata;
    250  1.12   atatat 		ch = *p;
    251  1.12   atatat 		/* Skip "\n<.*>" syslog sequences. */
    252  1.12   atatat 		if (skip) {
    253  1.12   atatat 			if (ch == '>')
    254  1.12   atatat 				newl = skip = 0;
    255  1.12   atatat 			continue;
    256  1.12   atatat 		}
    257  1.12   atatat 		if (newl && ch == '<') {
    258  1.12   atatat 			skip = 1;
    259  1.12   atatat 			continue;
    260  1.12   atatat 		}
    261  1.12   atatat 		if (ch == '\0')
    262  1.12   atatat 			continue;
    263  1.12   atatat 		newl = ch == '\n';
    264  1.12   atatat 		db_printf("%c", ch);
    265  1.12   atatat 	}
    266  1.12   atatat 	if (!newl)
    267  1.12   atatat 		db_printf("\n");
    268   1.1      gwr }
    269