Home | History | Annotate | Line # | Download | only in ddb
db_xxx.c revision 1.1
      1 /*	$NetBSD: db_xxx.c,v 1.1 1997/05/21 19:54:00 gwr 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 	int map = modif[0] == 'm';
    109 	int doingzomb = 0;
    110 	struct proc *p, *pp;
    111 
    112 	p = allproc.lh_first;
    113 	db_printf("  pid proc     addr     %s comm         wchan\n",
    114 	    map ? "map     " : "uid  ppid  pgrp  flag stat em ");
    115 	while (p != 0) {
    116 		pp = p->p_pptr;
    117 		if (p->p_stat) {
    118 			db_printf("%5d %p %p ",
    119 			    p->p_pid, p, p->p_addr);
    120 			if (map)
    121 				db_printf("%p %s   ",
    122 				    p->p_vmspace, p->p_comm);
    123 			else
    124 				db_printf("%3d %5d %5d  %06x  %d  %s  %s   ",
    125 				    p->p_cred->p_ruid, pp ? pp->p_pid : -1,
    126 				    p->p_pgrp->pg_id, p->p_flag, p->p_stat,
    127 				    p->p_emul->e_name, p->p_comm);
    128 			if (p->p_wchan) {
    129 				if (p->p_wmesg)
    130 					db_printf("%s ", p->p_wmesg);
    131 				db_printf("%p", p->p_wchan);
    132 			}
    133 			db_printf("\n");
    134 		}
    135 		p = p->p_list.le_next;
    136 		if (p == 0 && doingzomb == 0) {
    137 			doingzomb = 1;
    138 			p = zombproc.lh_first;
    139 		}
    140 	}
    141 }
    142 
    143 void
    144 db_show_callout(addr, haddr, count, modif)
    145 	db_expr_t addr;
    146 	int haddr;
    147 	db_expr_t count;
    148 	char *modif;
    149 {
    150 	register struct callout *p1;
    151 	register int	cum;
    152 	register int	s;
    153 	db_expr_t	offset;
    154 	char		*name;
    155 
    156 	db_printf("      cum     ticks      arg  func\n");
    157 	s = splhigh();
    158 	for (cum = 0, p1 = calltodo.c_next; p1; p1 = p1->c_next) {
    159 		register int t = p1->c_time;
    160 
    161 		if (t > 0)
    162 			cum += t;
    163 
    164 		db_find_sym_and_offset((db_addr_t)p1->c_func, &name, &offset);
    165 		if (name == NULL)
    166 			name = "?";
    167 
    168 		db_printf("%9d %9d %p  %s (%p)\n",
    169 			  cum, t, p1->c_arg, name, p1->c_func);
    170 	}
    171 	splx(s);
    172 }
    173