Home | History | Annotate | Line # | Download | only in ddb
db_xxx.c revision 1.2
      1 /*	$NetBSD: db_xxx.c,v 1.2 1997/10/24 18:26:36 chuck 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/proc.h>
     47 
     48 #include <sys/callout.h>
     49 #include <sys/signalvar.h>
     50 
     51 #include <machine/db_machdep.h>
     52 
     53 #include <ddb/db_access.h>
     54 #include <ddb/db_command.h>
     55 #include <ddb/db_interface.h>
     56 #include <ddb/db_lex.h>
     57 #include <ddb/db_output.h>
     58 #include <ddb/db_sym.h>
     59 #include <ddb/db_extern.h>
     60 
     61 void
     62 db_kill_proc(addr, haddr, count, modif)
     63 	db_expr_t addr;
     64 	int haddr;
     65 	db_expr_t count;
     66 	char *modif;
     67 {
     68 	struct proc *p;
     69 	db_expr_t pid, sig;
     70 	int t;
     71 
     72 	/* What pid? */
     73 	if (!db_expression(&pid)) {
     74 		db_error("pid?\n");
     75 	    /*NOTREACHED*/
     76 	}
     77 	/* What sig? */
     78 	t = db_read_token();
     79 	if (t == tCOMMA) {
     80 		if (!db_expression(&sig)) {
     81 			db_error("sig?\n");
     82 			/*NOTREACHED*/
     83 		}
     84 	} else {
     85 		db_unread_token(t);
     86 		sig = 15;
     87 	}
     88 	if (db_read_token() != tEOL) {
     89 	    db_error("?\n");
     90 	    /*NOTREACHED*/
     91 	}
     92 
     93 	p = pfind((pid_t)pid);
     94 	if (p == NULL) {
     95 		db_error("no such proc\n");
     96 	    /*NOTREACHED*/
     97 	}
     98 	psignal(p, (int)sig);
     99 }
    100 
    101 void
    102 db_show_all_procs(addr, haddr, count, modif)
    103 	db_expr_t addr;
    104 	int haddr;
    105 	db_expr_t count;
    106 	char *modif;
    107 {
    108 	char *mode;
    109 	int doingzomb = 0;
    110 	struct proc *p, *pp;
    111 
    112 	if (modif[0] == 0)
    113 		modif[0] = 'n';			/* default == normal mode */
    114 
    115 	mode = strchr("mawn", modif[0]);
    116 	if (mode == NULL || *mode == 'm') {
    117 		db_printf("usage: show all procs [/a] [/n] [/w]\n");
    118 		db_printf("\t/a == show process address info\n");
    119 		db_printf("\t/n == show normal process info [default]\n");
    120 		db_printf("\t/w == show process wait/emul info\n");
    121 		return;
    122 	}
    123 
    124 	p = allproc.lh_first;
    125 
    126 	switch (*mode) {
    127 
    128 	case 'a':
    129 		db_printf("PID        %10s %18s %18s %18s\n",
    130 		    "COMMAND", "STRUCT PROC *", "UAREA *", "VMSPACE/VM_MAP");
    131 		break;
    132 	case 'n':
    133 		db_printf("PID        %10s %10s %10s S %7s %16s %7s\n",
    134 		    "PPID", "PGRP", "UID", "FLAGS", "COMMAND", "WAIT");
    135 		break;
    136 	case 'w':
    137 		db_printf("PID        %16s %8s %18s %s\n",
    138 		    "COMMAND", "EMUL", "WAIT-CHANNEL", "WAIT-MSG");
    139 		break;
    140 	}
    141 
    142 	while (p != 0) {
    143 		pp = p->p_pptr;
    144 		if (p->p_stat) {
    145 
    146 			db_printf("%-10d ", p->p_pid);
    147 
    148 			switch (*mode) {
    149 
    150 			case 'a':
    151 				db_printf("%10.10s %18p %18p %18p\n",
    152 				    p->p_comm, p, p->p_addr, p->p_vmspace);
    153 				break;
    154 
    155 			case 'n':
    156 				db_printf("%10d %10d %10d %d %#7x %16s %7.7s\n",
    157 				    pp ? pp->p_pid : -1, p->p_pgrp->pg_id,
    158 				    p->p_cred->p_ruid, p->p_stat, p->p_flag,
    159 				    p->p_comm, (p->p_wchan && p->p_wmesg) ?
    160 					p->p_wmesg : "");
    161 				break;
    162 
    163 			case 'w':
    164 				db_printf("%16s %8s %18p %s\n", p->p_comm,
    165 				    p->p_emul->e_name, p->p_wchan,
    166 				    (p->p_wchan && p->p_wmesg) ?
    167 					p->p_wmesg : "");
    168 				break;
    169 
    170 			}
    171 		}
    172 		p = p->p_list.le_next;
    173 		if (p == 0 && doingzomb == 0) {
    174 			doingzomb = 1;
    175 			p = zombproc.lh_first;
    176 		}
    177 	}
    178 }
    179 
    180 void
    181 db_show_callout(addr, haddr, count, modif)
    182 	db_expr_t addr;
    183 	int haddr;
    184 	db_expr_t count;
    185 	char *modif;
    186 {
    187 	register struct callout *p1;
    188 	register int	cum;
    189 	register int	s;
    190 	db_expr_t	offset;
    191 	char		*name;
    192 
    193 	db_printf("      cum     ticks      arg  func\n");
    194 	s = splhigh();
    195 	for (cum = 0, p1 = calltodo.c_next; p1; p1 = p1->c_next) {
    196 		register int t = p1->c_time;
    197 
    198 		if (t > 0)
    199 			cum += t;
    200 
    201 		db_find_sym_and_offset((db_addr_t)p1->c_func, &name, &offset);
    202 		if (name == NULL)
    203 			name = "?";
    204 
    205 		db_printf("%9d %9d %p  %s (%p)\n",
    206 			  cum, t, p1->c_arg, name, p1->c_func);
    207 	}
    208 	splx(s);
    209 }
    210