Home | History | Annotate | Line # | Download | only in ddb
db_command.c revision 1.43.2.1
      1  1.43.2.1   minoura /*	$NetBSD: db_command.c,v 1.43.2.1 2000/06/22 17:06:11 minoura Exp $	*/
      2      1.12       cgd 
      3       1.1       cgd /*
      4       1.1       cgd  * Mach Operating System
      5       1.1       cgd  * Copyright (c) 1991,1990 Carnegie Mellon University
      6       1.1       cgd  * All Rights Reserved.
      7       1.1       cgd  *
      8       1.1       cgd  * Permission to use, copy, modify and distribute this software and its
      9       1.1       cgd  * documentation is hereby granted, provided that both the copyright
     10       1.1       cgd  * notice and this permission notice appear in all copies of the
     11       1.1       cgd  * software, derivative works or modified versions, and any portions
     12       1.1       cgd  * thereof, and that both notices appear in supporting documentation.
     13       1.1       cgd  *
     14      1.30        pk  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15       1.1       cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
     16       1.1       cgd  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17       1.1       cgd  *
     18       1.1       cgd  * Carnegie Mellon requests users of this software to return to
     19       1.1       cgd  *
     20       1.1       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21       1.1       cgd  *  School of Computer Science
     22       1.1       cgd  *  Carnegie Mellon University
     23       1.1       cgd  *  Pittsburgh PA 15213-3890
     24       1.1       cgd  *
     25       1.1       cgd  * any improvements or extensions that they make and grant Carnegie the
     26       1.1       cgd  * rights to redistribute these changes.
     27       1.1       cgd  */
     28      1.25       mrg 
     29      1.27      tron #include "opt_ddb.h"
     30      1.40     jhawk #include "opt_inet.h"
     31       1.5   mycroft 
     32       1.1       cgd /*
     33       1.1       cgd  * Command dispatcher.
     34       1.1       cgd  */
     35       1.7   mycroft #include <sys/param.h>
     36      1.18  christos #include <sys/systm.h>
     37      1.23    scottr #include <sys/reboot.h>
     38       1.7   mycroft #include <sys/proc.h>
     39      1.36       chs #include <sys/vnode.h>
     40      1.31   thorpej #include <sys/pool.h>
     41      1.15       gwr 
     42       1.1       cgd #include <machine/db_machdep.h>		/* type definitions */
     43       1.1       cgd 
     44      1.34  sommerfe #if defined(_KERNEL) && !defined(_LKM)
     45      1.34  sommerfe #include "opt_multiprocessor.h"
     46      1.34  sommerfe #endif
     47      1.34  sommerfe #ifdef MULTIPROCESSOR
     48      1.34  sommerfe #include <machine/cpu.h>
     49      1.34  sommerfe #endif
     50      1.34  sommerfe 
     51       1.1       cgd #include <ddb/db_lex.h>
     52       1.1       cgd #include <ddb/db_output.h>
     53      1.10        pk #include <ddb/db_command.h>
     54      1.16  christos #include <ddb/db_break.h>
     55      1.16  christos #include <ddb/db_watch.h>
     56      1.16  christos #include <ddb/db_run.h>
     57      1.16  christos #include <ddb/db_variables.h>
     58      1.16  christos #include <ddb/db_interface.h>
     59      1.16  christos #include <ddb/db_sym.h>
     60      1.16  christos #include <ddb/db_extern.h>
     61      1.16  christos 
     62      1.16  christos #include <vm/vm.h>
     63       1.1       cgd 
     64      1.24       mrg #include <uvm/uvm_extern.h>
     65      1.26  jonathan #include <uvm/uvm_ddb.h>
     66      1.24       mrg 
     67  1.43.2.1   minoura #include "arp.h"
     68  1.43.2.1   minoura 
     69       1.1       cgd /*
     70       1.1       cgd  * Exported global variables
     71       1.1       cgd  */
     72       1.1       cgd boolean_t	db_cmd_loop_done;
     73      1.17       gwr label_t		*db_recover;
     74       1.1       cgd 
     75       1.1       cgd /*
     76       1.1       cgd  * if 'ed' style: 'dot' is set at start of last item printed,
     77       1.1       cgd  * and '+' points to next line.
     78       1.1       cgd  * Otherwise: 'dot' points to next item, '..' points to last.
     79       1.1       cgd  */
     80       1.1       cgd boolean_t	db_ed_style = TRUE;
     81       1.1       cgd 
     82       1.1       cgd /*
     83       1.1       cgd  * Utility routine - discard tokens through end-of-line.
     84       1.1       cgd  */
     85       1.1       cgd void
     86       1.1       cgd db_skip_to_eol()
     87       1.1       cgd {
     88       1.1       cgd 	int	t;
     89       1.1       cgd 	do {
     90       1.1       cgd 	    t = db_read_token();
     91       1.1       cgd 	} while (t != tEOL);
     92       1.1       cgd }
     93       1.1       cgd 
     94       1.1       cgd /*
     95       1.1       cgd  * Results of command search.
     96       1.1       cgd  */
     97       1.1       cgd #define	CMD_UNIQUE	0
     98       1.1       cgd #define	CMD_FOUND	1
     99       1.1       cgd #define	CMD_NONE	2
    100       1.1       cgd #define	CMD_AMBIGUOUS	3
    101       1.1       cgd #define	CMD_HELP	4
    102       1.1       cgd 
    103       1.1       cgd /*
    104       1.1       cgd  * Search for command prefix.
    105       1.1       cgd  */
    106       1.1       cgd int
    107       1.1       cgd db_cmd_search(name, table, cmdp)
    108      1.10        pk 	char			*name;
    109      1.10        pk 	struct db_command	*table;
    110      1.10        pk 	struct db_command	**cmdp;	/* out */
    111       1.1       cgd {
    112      1.10        pk 	struct db_command	*cmd;
    113      1.10        pk 	int			result = CMD_NONE;
    114       1.1       cgd 
    115       1.1       cgd 	for (cmd = table; cmd->name != 0; cmd++) {
    116      1.35  augustss 	    char *lp;
    117      1.35  augustss 	    char *rp;
    118      1.35  augustss 	    int  c;
    119       1.1       cgd 
    120       1.1       cgd 	    lp = name;
    121       1.1       cgd 	    rp = cmd->name;
    122       1.1       cgd 	    while ((c = *lp) == *rp) {
    123       1.1       cgd 		if (c == 0) {
    124       1.1       cgd 		    /* complete match */
    125       1.1       cgd 		    *cmdp = cmd;
    126       1.1       cgd 		    return (CMD_UNIQUE);
    127       1.1       cgd 		}
    128       1.1       cgd 		lp++;
    129       1.1       cgd 		rp++;
    130       1.1       cgd 	    }
    131       1.1       cgd 	    if (c == 0) {
    132       1.1       cgd 		/* end of name, not end of command -
    133       1.1       cgd 		   partial match */
    134       1.1       cgd 		if (result == CMD_FOUND) {
    135       1.1       cgd 		    result = CMD_AMBIGUOUS;
    136       1.1       cgd 		    /* but keep looking for a full match -
    137       1.1       cgd 		       this lets us match single letters */
    138       1.1       cgd 		}
    139       1.1       cgd 		else {
    140       1.1       cgd 		    *cmdp = cmd;
    141       1.1       cgd 		    result = CMD_FOUND;
    142       1.1       cgd 		}
    143       1.1       cgd 	    }
    144       1.1       cgd 	}
    145       1.1       cgd 	if (result == CMD_NONE) {
    146       1.1       cgd 	    /* check for 'help' */
    147       1.1       cgd 		if (name[0] == 'h' && name[1] == 'e'
    148       1.1       cgd 		    && name[2] == 'l' && name[3] == 'p')
    149       1.1       cgd 			result = CMD_HELP;
    150       1.1       cgd 	}
    151       1.1       cgd 	return (result);
    152       1.1       cgd }
    153       1.1       cgd 
    154       1.1       cgd void
    155       1.1       cgd db_cmd_list(table)
    156      1.10        pk 	struct db_command *table;
    157       1.1       cgd {
    158      1.33  jdolecek 	int	 i, j, w, columns, lines, width=0, items, numcmds;
    159      1.32     lukem 	char	*p;
    160       1.1       cgd 
    161      1.32     lukem 	for (numcmds = 0; table[numcmds].name != NULL; numcmds++) {
    162      1.32     lukem 		w = strlen(table[numcmds].name);
    163      1.32     lukem 		if (w > width)
    164      1.32     lukem 			width = w;
    165      1.32     lukem 	}
    166      1.32     lukem 	width = DB_NEXT_TAB(width);
    167      1.32     lukem 	items = 0;
    168      1.32     lukem 
    169      1.32     lukem 	columns = db_max_width / width;
    170      1.32     lukem 	if (columns == 0)
    171      1.32     lukem 		columns = 1;
    172      1.32     lukem 	lines = (numcmds + columns - 1) / columns;
    173      1.32     lukem 	for (i = 0; i < lines; i++) {
    174      1.32     lukem 		for (j = 0; j < columns; j++) {
    175      1.32     lukem 			p = table[j * lines + i].name;
    176      1.32     lukem 			if (p)
    177      1.32     lukem 				db_printf("%s", p);
    178      1.32     lukem 			if (j * lines + i + lines >= numcmds) {
    179      1.32     lukem 				db_putchar('\n');
    180      1.32     lukem 				break;
    181      1.32     lukem 			}
    182      1.32     lukem 			w = strlen(p);
    183      1.32     lukem 			while (w < width) {
    184      1.32     lukem 				w = DB_NEXT_TAB(w);
    185      1.32     lukem 				db_putchar('\t');
    186      1.32     lukem 			}
    187      1.32     lukem 		}
    188       1.1       cgd 	}
    189       1.1       cgd }
    190       1.1       cgd 
    191       1.1       cgd void
    192       1.1       cgd db_command(last_cmdp, cmd_table)
    193      1.10        pk 	struct db_command	**last_cmdp;	/* IN_OUT */
    194      1.10        pk 	struct db_command	*cmd_table;
    195       1.1       cgd {
    196      1.10        pk 	struct db_command	*cmd;
    197       1.1       cgd 	int		t;
    198       1.1       cgd 	char		modif[TOK_STRING_SIZE];
    199       1.1       cgd 	db_expr_t	addr, count;
    200      1.16  christos 	boolean_t	have_addr = FALSE;
    201       1.1       cgd 	int		result;
    202       1.1       cgd 
    203      1.38     jhawk 	static db_expr_t               last_count = 0;
    204      1.38     jhawk 
    205       1.1       cgd 	t = db_read_token();
    206      1.38     jhawk 	if ((t == tEOL) || (t == tCOMMA)) {
    207      1.38     jhawk 	    /*
    208      1.38     jhawk 	     * An empty line repeats last command, at 'next'.
    209      1.38     jhawk 	     * Only a count repeats the last command with the new count.
    210      1.38     jhawk 	     */
    211       1.1       cgd 	    cmd = *last_cmdp;
    212       1.1       cgd 	    addr = (db_expr_t)db_next;
    213      1.38     jhawk 	    if (t == tCOMMA) {
    214      1.38     jhawk 	            if (!db_expression(&count)) {
    215  1.43.2.1   minoura 			    db_printf("Count missing\n");
    216  1.43.2.1   minoura 			    db_flush_lex();
    217  1.43.2.1   minoura 			    return;
    218  1.43.2.1   minoura 		    }
    219      1.38     jhawk 	    } else
    220  1.43.2.1   minoura 		    count = last_count;
    221       1.1       cgd 	    have_addr = FALSE;
    222       1.1       cgd 	    modif[0] = '\0';
    223  1.43.2.1   minoura 	    db_skip_to_eol();
    224       1.1       cgd 	}
    225       1.1       cgd 	else if (t == tEXCL) {
    226      1.16  christos 	    db_fncall(0, 0, 0, NULL);
    227       1.1       cgd 	    return;
    228       1.1       cgd 	}
    229       1.1       cgd 	else if (t != tIDENT) {
    230       1.1       cgd 	    db_printf("?\n");
    231       1.1       cgd 	    db_flush_lex();
    232       1.1       cgd 	    return;
    233       1.1       cgd 	}
    234       1.1       cgd 	else {
    235       1.1       cgd 	    /*
    236       1.1       cgd 	     * Search for command
    237       1.1       cgd 	     */
    238       1.1       cgd 	    while (cmd_table) {
    239       1.1       cgd 		result = db_cmd_search(db_tok_string,
    240       1.1       cgd 				       cmd_table,
    241       1.1       cgd 				       &cmd);
    242       1.1       cgd 		switch (result) {
    243       1.1       cgd 		    case CMD_NONE:
    244       1.1       cgd 			db_printf("No such command\n");
    245       1.1       cgd 			db_flush_lex();
    246       1.1       cgd 			return;
    247       1.1       cgd 		    case CMD_AMBIGUOUS:
    248       1.1       cgd 			db_printf("Ambiguous\n");
    249       1.1       cgd 			db_flush_lex();
    250       1.1       cgd 			return;
    251       1.1       cgd 		    case CMD_HELP:
    252       1.1       cgd 			db_cmd_list(cmd_table);
    253       1.1       cgd 			db_flush_lex();
    254       1.1       cgd 			return;
    255       1.1       cgd 		    default:
    256       1.1       cgd 			break;
    257       1.1       cgd 		}
    258       1.1       cgd 		if ((cmd_table = cmd->more) != 0) {
    259       1.1       cgd 		    t = db_read_token();
    260       1.1       cgd 		    if (t != tIDENT) {
    261       1.1       cgd 			db_cmd_list(cmd_table);
    262       1.1       cgd 			db_flush_lex();
    263       1.1       cgd 			return;
    264       1.1       cgd 		    }
    265       1.1       cgd 		}
    266       1.1       cgd 	    }
    267       1.1       cgd 
    268       1.1       cgd 	    if ((cmd->flag & CS_OWN) == 0) {
    269       1.1       cgd 		/*
    270       1.1       cgd 		 * Standard syntax:
    271       1.1       cgd 		 * command [/modifier] [addr] [,count]
    272       1.1       cgd 		 */
    273       1.1       cgd 		t = db_read_token();
    274       1.1       cgd 		if (t == tSLASH) {
    275       1.1       cgd 		    t = db_read_token();
    276       1.1       cgd 		    if (t != tIDENT) {
    277       1.1       cgd 			db_printf("Bad modifier\n");
    278       1.1       cgd 			db_flush_lex();
    279       1.1       cgd 			return;
    280       1.1       cgd 		    }
    281       1.1       cgd 		    db_strcpy(modif, db_tok_string);
    282       1.1       cgd 		}
    283       1.1       cgd 		else {
    284       1.1       cgd 		    db_unread_token(t);
    285       1.1       cgd 		    modif[0] = '\0';
    286       1.1       cgd 		}
    287       1.1       cgd 
    288       1.1       cgd 		if (db_expression(&addr)) {
    289       1.1       cgd 		    db_dot = (db_addr_t) addr;
    290       1.1       cgd 		    db_last_addr = db_dot;
    291       1.1       cgd 		    have_addr = TRUE;
    292       1.1       cgd 		}
    293       1.1       cgd 		else {
    294       1.1       cgd 		    addr = (db_expr_t) db_dot;
    295       1.1       cgd 		    have_addr = FALSE;
    296       1.1       cgd 		}
    297       1.1       cgd 		t = db_read_token();
    298       1.1       cgd 		if (t == tCOMMA) {
    299       1.1       cgd 		    if (!db_expression(&count)) {
    300       1.1       cgd 			db_printf("Count missing\n");
    301       1.1       cgd 			db_flush_lex();
    302       1.1       cgd 			return;
    303       1.1       cgd 		    }
    304       1.1       cgd 		}
    305       1.1       cgd 		else {
    306       1.1       cgd 		    db_unread_token(t);
    307       1.1       cgd 		    count = -1;
    308       1.1       cgd 		}
    309       1.1       cgd 		if ((cmd->flag & CS_MORE) == 0) {
    310       1.1       cgd 		    db_skip_to_eol();
    311       1.1       cgd 		}
    312       1.1       cgd 	    }
    313       1.1       cgd 	}
    314       1.1       cgd 	*last_cmdp = cmd;
    315      1.38     jhawk 	last_count = count;
    316       1.1       cgd 	if (cmd != 0) {
    317       1.1       cgd 	    /*
    318       1.1       cgd 	     * Execute the command.
    319       1.1       cgd 	     */
    320       1.1       cgd 	    (*cmd->fcn)(addr, have_addr, count, modif);
    321       1.1       cgd 
    322       1.1       cgd 	    if (cmd->flag & CS_SET_DOT) {
    323       1.1       cgd 		/*
    324       1.1       cgd 		 * If command changes dot, set dot to
    325       1.1       cgd 		 * previous address displayed (if 'ed' style).
    326       1.1       cgd 		 */
    327       1.1       cgd 		if (db_ed_style) {
    328       1.1       cgd 		    db_dot = db_prev;
    329       1.1       cgd 		}
    330       1.1       cgd 		else {
    331       1.1       cgd 		    db_dot = db_next;
    332       1.1       cgd 		}
    333       1.1       cgd 	    }
    334       1.1       cgd 	    else {
    335       1.1       cgd 		/*
    336       1.1       cgd 		 * If command does not change dot,
    337       1.1       cgd 		 * set 'next' location to be the same.
    338       1.1       cgd 		 */
    339       1.1       cgd 		db_next = db_dot;
    340       1.1       cgd 	    }
    341       1.1       cgd 	}
    342       1.1       cgd }
    343       1.1       cgd 
    344       1.4    brezak /*ARGSUSED*/
    345       1.4    brezak void
    346       1.4    brezak db_map_print_cmd(addr, have_addr, count, modif)
    347       1.4    brezak 	db_expr_t	addr;
    348       1.4    brezak 	int		have_addr;
    349       1.4    brezak 	db_expr_t	count;
    350       1.4    brezak 	char *		modif;
    351       1.4    brezak {
    352       1.4    brezak         boolean_t full = FALSE;
    353       1.4    brezak 
    354       1.4    brezak         if (modif[0] == 'f')
    355       1.4    brezak                 full = TRUE;
    356       1.4    brezak 
    357      1.24       mrg         uvm_map_printit((vm_map_t) addr, full, db_printf);
    358       1.4    brezak }
    359       1.4    brezak 
    360       1.4    brezak /*ARGSUSED*/
    361       1.4    brezak void
    362       1.4    brezak db_object_print_cmd(addr, have_addr, count, modif)
    363       1.4    brezak 	db_expr_t	addr;
    364       1.4    brezak 	int		have_addr;
    365       1.4    brezak 	db_expr_t	count;
    366       1.4    brezak 	char *		modif;
    367       1.4    brezak {
    368       1.4    brezak         boolean_t full = FALSE;
    369       1.4    brezak 
    370       1.4    brezak         if (modif[0] == 'f')
    371       1.4    brezak                 full = TRUE;
    372       1.4    brezak 
    373      1.24       mrg 	uvm_object_printit((struct uvm_object *) addr, full, db_printf);
    374      1.24       mrg }
    375      1.24       mrg 
    376      1.24       mrg /*ARGSUSED*/
    377      1.24       mrg void
    378      1.24       mrg db_page_print_cmd(addr, have_addr, count, modif)
    379      1.24       mrg 	db_expr_t	addr;
    380      1.24       mrg 	int		have_addr;
    381      1.24       mrg 	db_expr_t	count;
    382      1.24       mrg 	char *		modif;
    383      1.24       mrg {
    384      1.24       mrg         boolean_t full = FALSE;
    385      1.24       mrg 
    386      1.24       mrg         if (modif[0] == 'f')
    387      1.24       mrg                 full = TRUE;
    388      1.24       mrg 
    389      1.24       mrg 	uvm_page_printit((struct vm_page *) addr, full, db_printf);
    390      1.36       chs }
    391      1.36       chs 
    392      1.36       chs /*ARGSUSED*/
    393      1.36       chs void
    394      1.36       chs db_buf_print_cmd(addr, have_addr, count, modif)
    395      1.36       chs 	db_expr_t	addr;
    396      1.36       chs 	int		have_addr;
    397      1.36       chs 	db_expr_t	count;
    398      1.36       chs 	char *		modif;
    399      1.36       chs {
    400      1.36       chs 	boolean_t full = FALSE;
    401      1.36       chs 
    402      1.36       chs 	if (modif[0] == 'f')
    403      1.36       chs 		full = TRUE;
    404      1.36       chs 
    405      1.36       chs 	vfs_buf_print((struct buf *)addr, full, db_printf);
    406      1.36       chs }
    407      1.36       chs 
    408      1.36       chs /*ARGSUSED*/
    409      1.36       chs void
    410      1.36       chs db_vnode_print_cmd(addr, have_addr, count, modif)
    411      1.36       chs 	db_expr_t	addr;
    412      1.36       chs 	int		have_addr;
    413      1.36       chs 	db_expr_t	count;
    414      1.36       chs 	char *		modif;
    415      1.36       chs {
    416      1.36       chs 	boolean_t full = FALSE;
    417      1.36       chs 
    418      1.36       chs 	if (modif[0] == 'f')
    419      1.36       chs 		full = TRUE;
    420      1.36       chs 
    421      1.36       chs 	vfs_vnode_print((struct vnode *)addr, full, db_printf);
    422       1.4    brezak }
    423       1.4    brezak 
    424      1.31   thorpej /*ARGSUSED*/
    425      1.31   thorpej void
    426      1.31   thorpej db_pool_print_cmd(addr, have_addr, count, modif)
    427      1.31   thorpej 	db_expr_t	addr;
    428      1.31   thorpej 	int		have_addr;
    429      1.31   thorpej 	db_expr_t	count;
    430      1.31   thorpej 	char *		modif;
    431      1.31   thorpej {
    432      1.31   thorpej 
    433      1.31   thorpej 	pool_printit((struct pool *) addr, modif, db_printf);
    434      1.31   thorpej }
    435      1.31   thorpej 
    436       1.1       cgd /*
    437       1.1       cgd  * 'show' commands
    438       1.1       cgd  */
    439       1.1       cgd 
    440      1.10        pk struct db_command db_show_all_cmds[] = {
    441      1.32     lukem 	{ "callout",	db_show_callout,	0, NULL },
    442      1.16  christos 	{ "procs",	db_show_all_procs,	0, NULL },
    443      1.16  christos 	{ NULL, 	NULL, 			0, NULL }
    444       1.1       cgd };
    445       1.1       cgd 
    446      1.10        pk struct db_command db_show_cmds[] = {
    447      1.16  christos 	{ "all",	NULL,			0,	db_show_all_cmds },
    448  1.43.2.1   minoura #if defined(INET) && (NARP > 0)
    449      1.40     jhawk 	{ "arptab",	db_show_arptab,		0,	NULL },
    450      1.40     jhawk #endif
    451      1.16  christos 	{ "breaks",	db_listbreak_cmd, 	0,	NULL },
    452      1.16  christos 	{ "map",	db_map_print_cmd,	0,	NULL },
    453      1.16  christos 	{ "object",	db_object_print_cmd,	0,	NULL },
    454      1.24       mrg 	{ "page",	db_page_print_cmd,	0,	NULL },
    455      1.37       chs 	{ "buf",	db_buf_print_cmd,	0,	NULL },
    456      1.37       chs 	{ "vnode",	db_vnode_print_cmd,	0,	NULL },
    457      1.31   thorpej 	{ "pool",	db_pool_print_cmd,	0,	NULL },
    458      1.32     lukem 	{ "registers",	db_show_regs,		0,	NULL },
    459      1.32     lukem 	{ "watches",	db_listwatch_cmd, 	0,	NULL },
    460      1.32     lukem 	{ NULL,		NULL,			0,	NULL }
    461       1.1       cgd };
    462       1.1       cgd 
    463      1.10        pk struct db_command db_command_table[] = {
    464      1.32     lukem 	{ "break",	db_breakpoint_cmd,	0,		NULL },
    465      1.32     lukem 	{ "c",		db_continue_cmd,	0,		NULL },
    466      1.32     lukem 	{ "call",	db_fncall,		CS_OWN,		NULL },
    467      1.32     lukem 	{ "callout",	db_show_callout,	0,		NULL },
    468      1.32     lukem 	{ "continue",	db_continue_cmd,	0,		NULL },
    469      1.32     lukem 	{ "d",		db_delete_cmd,		0,		NULL },
    470      1.32     lukem 	{ "delete",	db_delete_cmd,		0,		NULL },
    471      1.32     lukem 	{ "dwatch",	db_deletewatch_cmd,	0,		NULL },
    472      1.32     lukem 	{ "examine",	db_examine_cmd,		CS_SET_DOT, 	NULL },
    473      1.32     lukem 	{ "kill",	db_kill_proc,		CS_OWN,		NULL },
    474       1.6    brezak #ifdef DB_MACHINE_COMMANDS
    475      1.32     lukem 	{ "machine",    NULL,                   0,     		NULL },
    476       1.6    brezak #endif
    477      1.32     lukem 	{ "match",	db_trace_until_matching_cmd,0,		NULL },
    478      1.32     lukem 	{ "next",	db_trace_until_matching_cmd,0,		NULL },
    479      1.39     jhawk 	{ "p",		db_print_cmd,		0,		NULL },
    480      1.16  christos 	{ "print",	db_print_cmd,		0,		NULL },
    481      1.32     lukem 	{ "ps",		db_show_all_procs,	0,		NULL },
    482      1.32     lukem 	{ "reboot",	db_reboot_cmd,		CS_OWN,		NULL },
    483      1.32     lukem 	{ "s",		db_single_step_cmd,	0,		NULL },
    484      1.16  christos 	{ "search",	db_search_cmd,		CS_OWN|CS_SET_DOT, NULL },
    485      1.16  christos 	{ "set",	db_set_cmd,		CS_OWN,		NULL },
    486      1.32     lukem 	{ "show",	NULL,			0,		db_show_cmds },
    487      1.41     jhawk 	{ "sifting",    db_sifting_cmd,		CS_OWN,		NULL },
    488      1.32     lukem 	{ "step",	db_single_step_cmd,	0,		NULL },
    489      1.32     lukem 	{ "sync",	db_sync_cmd,		CS_OWN,		NULL },
    490      1.32     lukem 	{ "trace",	db_stack_trace_cmd,	0,		NULL },
    491      1.32     lukem 	{ "until",	db_trace_until_call_cmd,0,		NULL },
    492      1.16  christos 	{ "w",		db_write_cmd,		CS_MORE|CS_SET_DOT, NULL },
    493      1.16  christos 	{ "watch",	db_watchpoint_cmd,	CS_MORE,	NULL },
    494      1.32     lukem 	{ "write",	db_write_cmd,		CS_MORE|CS_SET_DOT, NULL },
    495      1.32     lukem 	{ "x",		db_examine_cmd,		CS_SET_DOT, 	NULL },
    496      1.16  christos 	{ NULL, 	NULL,			0,		NULL }
    497       1.1       cgd };
    498       1.6    brezak 
    499       1.6    brezak #ifdef DB_MACHINE_COMMANDS
    500       1.6    brezak 
    501      1.32     lukem /*
    502      1.32     lukem  * this function should be called to install the machine dependent
    503      1.32     lukem  * commands. It should be called before the debugger is enabled
    504      1.32     lukem  */
    505      1.32     lukem void
    506      1.32     lukem db_machine_commands_install(ptr)
    507      1.32     lukem 	struct db_command *ptr;
    508       1.6    brezak {
    509      1.32     lukem 	struct db_command *cmd;
    510      1.32     lukem 
    511      1.32     lukem 	for (cmd = db_command_table; cmd != 0; cmd++) {
    512      1.32     lukem 		if (strcmp(cmd->name, "machine") == 0) {
    513      1.32     lukem 			cmd->more = ptr;
    514      1.32     lukem 			break;
    515      1.32     lukem 		}
    516      1.32     lukem 	}
    517       1.6    brezak }
    518       1.6    brezak 
    519       1.6    brezak #endif
    520       1.1       cgd 
    521      1.10        pk struct db_command	*db_last_command = 0;
    522       1.1       cgd 
    523       1.1       cgd void
    524       1.1       cgd db_command_loop()
    525       1.1       cgd {
    526      1.17       gwr 	label_t		db_jmpbuf;
    527      1.17       gwr 	label_t		*savejmp;
    528       1.8   mycroft 	extern int	db_output_line;
    529       1.4    brezak 
    530       1.1       cgd 	/*
    531       1.1       cgd 	 * Initialize 'prev' and 'next' to dot.
    532       1.1       cgd 	 */
    533       1.1       cgd 	db_prev = db_dot;
    534       1.1       cgd 	db_next = db_dot;
    535       1.1       cgd 
    536       1.1       cgd 	db_cmd_loop_done = 0;
    537      1.17       gwr 
    538      1.17       gwr 	savejmp = db_recover;
    539      1.17       gwr 	db_recover = &db_jmpbuf;
    540      1.17       gwr 	(void) setjmp(&db_jmpbuf);
    541       1.8   mycroft 
    542       1.1       cgd 	while (!db_cmd_loop_done) {
    543       1.8   mycroft 		if (db_print_position() != 0)
    544       1.8   mycroft 			db_printf("\n");
    545       1.8   mycroft 		db_output_line = 0;
    546       1.1       cgd 
    547  1.43.2.1   minoura 
    548      1.34  sommerfe #ifdef MULTIPROCESSOR
    549  1.43.2.1   minoura 		db_printf("db{%ld}> ", (long)cpu_number());
    550  1.43.2.1   minoura #else
    551  1.43.2.1   minoura 		db_printf("db> ");
    552      1.34  sommerfe #endif
    553       1.8   mycroft 		(void) db_read_line();
    554       1.1       cgd 
    555       1.8   mycroft 		db_command(&db_last_command, db_command_table);
    556       1.8   mycroft 	}
    557       1.1       cgd 
    558       1.8   mycroft 	db_recover = savejmp;
    559       1.1       cgd }
    560       1.1       cgd 
    561       1.1       cgd void
    562       1.1       cgd db_error(s)
    563       1.1       cgd 	char *s;
    564       1.1       cgd {
    565       1.1       cgd 	if (s)
    566       1.1       cgd 	    db_printf(s);
    567       1.1       cgd 	db_flush_lex();
    568      1.19  christos 	longjmp(db_recover);
    569       1.1       cgd }
    570       1.1       cgd 
    571       1.1       cgd 
    572       1.1       cgd /*
    573       1.1       cgd  * Call random function:
    574       1.1       cgd  * !expr(arg,arg,arg)
    575       1.1       cgd  */
    576      1.16  christos /*ARGSUSED*/
    577       1.1       cgd void
    578      1.16  christos db_fncall(addr, have_addr, count, modif)
    579      1.16  christos 	db_expr_t	addr;
    580      1.16  christos 	int		have_addr;
    581      1.16  christos 	db_expr_t	count;
    582      1.16  christos 	char *		modif;
    583       1.1       cgd {
    584       1.1       cgd 	db_expr_t	fn_addr;
    585       1.1       cgd #define	MAXARGS		11
    586       1.1       cgd 	db_expr_t	args[MAXARGS];
    587       1.1       cgd 	int		nargs = 0;
    588       1.1       cgd 	db_expr_t	retval;
    589      1.16  christos 	db_expr_t	(*func) __P((db_expr_t, ...));
    590       1.1       cgd 	int		t;
    591       1.1       cgd 
    592       1.1       cgd 	if (!db_expression(&fn_addr)) {
    593       1.1       cgd 	    db_printf("Bad function\n");
    594       1.1       cgd 	    db_flush_lex();
    595       1.1       cgd 	    return;
    596       1.1       cgd 	}
    597      1.16  christos 	func = (db_expr_t (*) __P((db_expr_t, ...))) fn_addr;
    598       1.1       cgd 
    599       1.1       cgd 	t = db_read_token();
    600       1.1       cgd 	if (t == tLPAREN) {
    601       1.1       cgd 	    if (db_expression(&args[0])) {
    602       1.1       cgd 		nargs++;
    603       1.1       cgd 		while ((t = db_read_token()) == tCOMMA) {
    604       1.1       cgd 		    if (nargs == MAXARGS) {
    605       1.1       cgd 			db_printf("Too many arguments\n");
    606       1.1       cgd 			db_flush_lex();
    607       1.1       cgd 			return;
    608       1.1       cgd 		    }
    609       1.1       cgd 		    if (!db_expression(&args[nargs])) {
    610       1.1       cgd 			db_printf("Argument missing\n");
    611       1.1       cgd 			db_flush_lex();
    612       1.1       cgd 			return;
    613       1.1       cgd 		    }
    614       1.1       cgd 		    nargs++;
    615       1.1       cgd 		}
    616       1.1       cgd 		db_unread_token(t);
    617       1.1       cgd 	    }
    618       1.1       cgd 	    if (db_read_token() != tRPAREN) {
    619       1.1       cgd 		db_printf("?\n");
    620       1.1       cgd 		db_flush_lex();
    621       1.1       cgd 		return;
    622       1.1       cgd 	    }
    623       1.1       cgd 	}
    624       1.1       cgd 	db_skip_to_eol();
    625       1.1       cgd 
    626       1.1       cgd 	while (nargs < MAXARGS) {
    627       1.1       cgd 	    args[nargs++] = 0;
    628       1.1       cgd 	}
    629       1.1       cgd 
    630       1.1       cgd 	retval = (*func)(args[0], args[1], args[2], args[3], args[4],
    631      1.20  christos 			 args[5], args[6], args[7], args[8], args[9]);
    632  1.43.2.1   minoura 	db_printf("%s\n", db_num_to_str(retval));
    633      1.23    scottr }
    634      1.23    scottr 
    635      1.23    scottr void
    636      1.23    scottr db_reboot_cmd(addr, have_addr, count, modif)
    637      1.23    scottr 	db_expr_t	addr;
    638      1.23    scottr 	int		have_addr;
    639      1.23    scottr 	db_expr_t	count;
    640      1.23    scottr 	char *		modif;
    641      1.23    scottr {
    642      1.23    scottr 	db_expr_t bootflags;
    643      1.23    scottr 
    644      1.23    scottr 	/* Flags, default to RB_AUTOBOOT */
    645      1.23    scottr 	if (!db_expression(&bootflags))
    646      1.23    scottr 		bootflags = (db_expr_t)RB_AUTOBOOT;
    647      1.23    scottr 	if (db_read_token() != tEOL) {
    648      1.23    scottr 	    db_error("?\n");
    649      1.23    scottr 	    /*NOTREACHED*/
    650      1.23    scottr 	}
    651  1.43.2.1   minoura 	/*
    652  1.43.2.1   minoura 	 * We are leaving DDB, never to return upward.
    653  1.43.2.1   minoura 	 * Clear db_recover so that we can debug faults in functions
    654  1.43.2.1   minoura 	 * called from cpu_reboot.
    655  1.43.2.1   minoura 	 */
    656  1.43.2.1   minoura 	db_recover = 0;
    657      1.23    scottr 	cpu_reboot((int)bootflags, NULL);
    658      1.41     jhawk }
    659      1.41     jhawk 
    660      1.41     jhawk void
    661      1.41     jhawk db_sifting_cmd(addr, have_addr, count, omodif)
    662      1.41     jhawk 	db_expr_t	addr;
    663      1.41     jhawk 	int		have_addr;
    664      1.41     jhawk 	db_expr_t	count;
    665      1.41     jhawk 	char *		omodif;
    666      1.41     jhawk {
    667      1.41     jhawk 	int	mode, t;
    668      1.41     jhawk 
    669      1.41     jhawk 	t = db_read_token();
    670      1.41     jhawk 	if (t == tSLASH) {
    671      1.41     jhawk 		t = db_read_token();
    672      1.41     jhawk 		if (t != tIDENT) {
    673      1.41     jhawk 			bad_modifier:
    674      1.41     jhawk 			db_printf("Bad modifier\n");
    675      1.41     jhawk 			db_flush_lex();
    676      1.41     jhawk 			return;
    677      1.41     jhawk 		}
    678      1.41     jhawk 		if (!strcmp(db_tok_string, "F"))
    679      1.41     jhawk 			mode = 'F';
    680      1.41     jhawk 		else
    681      1.41     jhawk 			goto bad_modifier;
    682      1.41     jhawk 		t = db_read_token();
    683      1.41     jhawk 	} else
    684      1.41     jhawk 		mode = 0;
    685      1.41     jhawk 
    686      1.41     jhawk 	if (t==tIDENT)
    687      1.41     jhawk 		db_sifting(db_tok_string, mode);
    688      1.41     jhawk 	else {
    689      1.41     jhawk 		db_printf("Bad argument (non-string)\n");
    690      1.41     jhawk 		db_flush_lex();
    691      1.41     jhawk 	}
    692      1.43     jhawk }
    693      1.43     jhawk 
    694      1.43     jhawk void
    695      1.43     jhawk db_stack_trace_cmd(addr, have_addr, count, modif)
    696      1.43     jhawk 	db_expr_t	addr;
    697      1.43     jhawk 	boolean_t	have_addr;
    698      1.43     jhawk 	db_expr_t	count;
    699      1.43     jhawk 	char		*modif;
    700      1.43     jhawk {
    701      1.43     jhawk 	if (count == -1)
    702      1.43     jhawk 		count = 65535;
    703      1.43     jhawk 
    704      1.43     jhawk 	db_stack_trace_print(addr, have_addr, count, modif, db_printf);
    705      1.32     lukem }
    706      1.32     lukem 
    707      1.32     lukem void
    708      1.32     lukem db_sync_cmd(addr, have_addr, count, modif)
    709      1.32     lukem 	db_expr_t	addr;
    710      1.32     lukem 	int		have_addr;
    711      1.32     lukem 	db_expr_t	count;
    712      1.32     lukem 	char *		modif;
    713      1.32     lukem {
    714  1.43.2.1   minoura 	/*
    715  1.43.2.1   minoura 	 * We are leaving DDB, never to return upward.
    716  1.43.2.1   minoura 	 * Clear db_recover so that we can debug faults in functions
    717  1.43.2.1   minoura 	 * called from cpu_reboot.
    718  1.43.2.1   minoura 	 */
    719  1.43.2.1   minoura 	db_recover = 0;
    720      1.32     lukem 	cpu_reboot(RB_DUMP, NULL);
    721       1.1       cgd }
    722