Home | History | Annotate | Line # | Download | only in ddb
db_xxx.c revision 1.1
      1  1.1  gwr /*	$NetBSD: db_xxx.c,v 1.1 1997/05/21 19:54:00 gwr 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.1  gwr 
     48  1.1  gwr #include <sys/callout.h>
     49  1.1  gwr #include <sys/signalvar.h>
     50  1.1  gwr 
     51  1.1  gwr #include <machine/db_machdep.h>
     52  1.1  gwr 
     53  1.1  gwr #include <ddb/db_access.h>
     54  1.1  gwr #include <ddb/db_command.h>
     55  1.1  gwr #include <ddb/db_interface.h>
     56  1.1  gwr #include <ddb/db_lex.h>
     57  1.1  gwr #include <ddb/db_output.h>
     58  1.1  gwr #include <ddb/db_sym.h>
     59  1.1  gwr #include <ddb/db_extern.h>
     60  1.1  gwr 
     61  1.1  gwr void
     62  1.1  gwr db_kill_proc(addr, haddr, count, modif)
     63  1.1  gwr 	db_expr_t addr;
     64  1.1  gwr 	int haddr;
     65  1.1  gwr 	db_expr_t count;
     66  1.1  gwr 	char *modif;
     67  1.1  gwr {
     68  1.1  gwr 	struct proc *p;
     69  1.1  gwr 	db_expr_t pid, sig;
     70  1.1  gwr 	int t;
     71  1.1  gwr 
     72  1.1  gwr 	/* What pid? */
     73  1.1  gwr 	if (!db_expression(&pid)) {
     74  1.1  gwr 		db_error("pid?\n");
     75  1.1  gwr 	    /*NOTREACHED*/
     76  1.1  gwr 	}
     77  1.1  gwr 	/* What sig? */
     78  1.1  gwr 	t = db_read_token();
     79  1.1  gwr 	if (t == tCOMMA) {
     80  1.1  gwr 		if (!db_expression(&sig)) {
     81  1.1  gwr 			db_error("sig?\n");
     82  1.1  gwr 			/*NOTREACHED*/
     83  1.1  gwr 		}
     84  1.1  gwr 	} else {
     85  1.1  gwr 		db_unread_token(t);
     86  1.1  gwr 		sig = 15;
     87  1.1  gwr 	}
     88  1.1  gwr 	if (db_read_token() != tEOL) {
     89  1.1  gwr 	    db_error("?\n");
     90  1.1  gwr 	    /*NOTREACHED*/
     91  1.1  gwr 	}
     92  1.1  gwr 
     93  1.1  gwr 	p = pfind((pid_t)pid);
     94  1.1  gwr 	if (p == NULL) {
     95  1.1  gwr 		db_error("no such proc\n");
     96  1.1  gwr 	    /*NOTREACHED*/
     97  1.1  gwr 	}
     98  1.1  gwr 	psignal(p, (int)sig);
     99  1.1  gwr }
    100  1.1  gwr 
    101  1.1  gwr void
    102  1.1  gwr db_show_all_procs(addr, haddr, count, modif)
    103  1.1  gwr 	db_expr_t addr;
    104  1.1  gwr 	int haddr;
    105  1.1  gwr 	db_expr_t count;
    106  1.1  gwr 	char *modif;
    107  1.1  gwr {
    108  1.1  gwr 	int map = modif[0] == 'm';
    109  1.1  gwr 	int doingzomb = 0;
    110  1.1  gwr 	struct proc *p, *pp;
    111  1.1  gwr 
    112  1.1  gwr 	p = allproc.lh_first;
    113  1.1  gwr 	db_printf("  pid proc     addr     %s comm         wchan\n",
    114  1.1  gwr 	    map ? "map     " : "uid  ppid  pgrp  flag stat em ");
    115  1.1  gwr 	while (p != 0) {
    116  1.1  gwr 		pp = p->p_pptr;
    117  1.1  gwr 		if (p->p_stat) {
    118  1.1  gwr 			db_printf("%5d %p %p ",
    119  1.1  gwr 			    p->p_pid, p, p->p_addr);
    120  1.1  gwr 			if (map)
    121  1.1  gwr 				db_printf("%p %s   ",
    122  1.1  gwr 				    p->p_vmspace, p->p_comm);
    123  1.1  gwr 			else
    124  1.1  gwr 				db_printf("%3d %5d %5d  %06x  %d  %s  %s   ",
    125  1.1  gwr 				    p->p_cred->p_ruid, pp ? pp->p_pid : -1,
    126  1.1  gwr 				    p->p_pgrp->pg_id, p->p_flag, p->p_stat,
    127  1.1  gwr 				    p->p_emul->e_name, p->p_comm);
    128  1.1  gwr 			if (p->p_wchan) {
    129  1.1  gwr 				if (p->p_wmesg)
    130  1.1  gwr 					db_printf("%s ", p->p_wmesg);
    131  1.1  gwr 				db_printf("%p", p->p_wchan);
    132  1.1  gwr 			}
    133  1.1  gwr 			db_printf("\n");
    134  1.1  gwr 		}
    135  1.1  gwr 		p = p->p_list.le_next;
    136  1.1  gwr 		if (p == 0 && doingzomb == 0) {
    137  1.1  gwr 			doingzomb = 1;
    138  1.1  gwr 			p = zombproc.lh_first;
    139  1.1  gwr 		}
    140  1.1  gwr 	}
    141  1.1  gwr }
    142  1.1  gwr 
    143  1.1  gwr void
    144  1.1  gwr db_show_callout(addr, haddr, count, modif)
    145  1.1  gwr 	db_expr_t addr;
    146  1.1  gwr 	int haddr;
    147  1.1  gwr 	db_expr_t count;
    148  1.1  gwr 	char *modif;
    149  1.1  gwr {
    150  1.1  gwr 	register struct callout *p1;
    151  1.1  gwr 	register int	cum;
    152  1.1  gwr 	register int	s;
    153  1.1  gwr 	db_expr_t	offset;
    154  1.1  gwr 	char		*name;
    155  1.1  gwr 
    156  1.1  gwr 	db_printf("      cum     ticks      arg  func\n");
    157  1.1  gwr 	s = splhigh();
    158  1.1  gwr 	for (cum = 0, p1 = calltodo.c_next; p1; p1 = p1->c_next) {
    159  1.1  gwr 		register int t = p1->c_time;
    160  1.1  gwr 
    161  1.1  gwr 		if (t > 0)
    162  1.1  gwr 			cum += t;
    163  1.1  gwr 
    164  1.1  gwr 		db_find_sym_and_offset((db_addr_t)p1->c_func, &name, &offset);
    165  1.1  gwr 		if (name == NULL)
    166  1.1  gwr 			name = "?";
    167  1.1  gwr 
    168  1.1  gwr 		db_printf("%9d %9d %p  %s (%p)\n",
    169  1.1  gwr 			  cum, t, p1->c_arg, name, p1->c_func);
    170  1.1  gwr 	}
    171  1.1  gwr 	splx(s);
    172  1.1  gwr }
    173