Home | History | Annotate | Line # | Download | only in ddb
db_command.c revision 1.28.2.2.2.1
      1  1.28.2.2.2.1       chs /*	$NetBSD: db_command.c,v 1.28.2.2.2.1 1999/06/07 04:25:29 chs 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.28.2.2        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.5   mycroft 
     31           1.1       cgd /*
     32           1.1       cgd  * Command dispatcher.
     33           1.1       cgd  */
     34           1.7   mycroft #include <sys/param.h>
     35          1.18  christos #include <sys/systm.h>
     36          1.23    scottr #include <sys/reboot.h>
     37           1.7   mycroft #include <sys/proc.h>
     38  1.28.2.2.2.1       chs #include <sys/vnode.h>
     39          1.15       gwr 
     40           1.1       cgd #include <machine/db_machdep.h>		/* type definitions */
     41           1.1       cgd 
     42           1.1       cgd #include <ddb/db_lex.h>
     43           1.1       cgd #include <ddb/db_output.h>
     44          1.10        pk #include <ddb/db_command.h>
     45          1.16  christos #include <ddb/db_break.h>
     46          1.16  christos #include <ddb/db_watch.h>
     47          1.16  christos #include <ddb/db_run.h>
     48          1.16  christos #include <ddb/db_variables.h>
     49          1.16  christos #include <ddb/db_interface.h>
     50          1.16  christos #include <ddb/db_sym.h>
     51          1.16  christos #include <ddb/db_extern.h>
     52          1.16  christos 
     53          1.16  christos #include <vm/vm.h>
     54           1.1       cgd 
     55          1.24       mrg #include <uvm/uvm_extern.h>
     56          1.26  jonathan #include <uvm/uvm_ddb.h>
     57          1.24       mrg 
     58           1.1       cgd /*
     59           1.1       cgd  * Exported global variables
     60           1.1       cgd  */
     61           1.1       cgd boolean_t	db_cmd_loop_done;
     62          1.17       gwr label_t		*db_recover;
     63           1.1       cgd 
     64           1.1       cgd /*
     65           1.1       cgd  * if 'ed' style: 'dot' is set at start of last item printed,
     66           1.1       cgd  * and '+' points to next line.
     67           1.1       cgd  * Otherwise: 'dot' points to next item, '..' points to last.
     68           1.1       cgd  */
     69           1.1       cgd boolean_t	db_ed_style = TRUE;
     70           1.1       cgd 
     71           1.1       cgd /*
     72           1.1       cgd  * Utility routine - discard tokens through end-of-line.
     73           1.1       cgd  */
     74           1.1       cgd void
     75           1.1       cgd db_skip_to_eol()
     76           1.1       cgd {
     77           1.1       cgd 	int	t;
     78           1.1       cgd 	do {
     79           1.1       cgd 	    t = db_read_token();
     80           1.1       cgd 	} while (t != tEOL);
     81           1.1       cgd }
     82           1.1       cgd 
     83           1.1       cgd /*
     84           1.1       cgd  * Results of command search.
     85           1.1       cgd  */
     86           1.1       cgd #define	CMD_UNIQUE	0
     87           1.1       cgd #define	CMD_FOUND	1
     88           1.1       cgd #define	CMD_NONE	2
     89           1.1       cgd #define	CMD_AMBIGUOUS	3
     90           1.1       cgd #define	CMD_HELP	4
     91           1.1       cgd 
     92           1.1       cgd /*
     93           1.1       cgd  * Search for command prefix.
     94           1.1       cgd  */
     95           1.1       cgd int
     96           1.1       cgd db_cmd_search(name, table, cmdp)
     97          1.10        pk 	char			*name;
     98          1.10        pk 	struct db_command	*table;
     99          1.10        pk 	struct db_command	**cmdp;	/* out */
    100           1.1       cgd {
    101          1.10        pk 	struct db_command	*cmd;
    102          1.10        pk 	int			result = CMD_NONE;
    103           1.1       cgd 
    104           1.1       cgd 	for (cmd = table; cmd->name != 0; cmd++) {
    105           1.1       cgd 	    register char *lp;
    106           1.1       cgd 	    register char *rp;
    107           1.1       cgd 	    register int  c;
    108           1.1       cgd 
    109           1.1       cgd 	    lp = name;
    110           1.1       cgd 	    rp = cmd->name;
    111           1.1       cgd 	    while ((c = *lp) == *rp) {
    112           1.1       cgd 		if (c == 0) {
    113           1.1       cgd 		    /* complete match */
    114           1.1       cgd 		    *cmdp = cmd;
    115           1.1       cgd 		    return (CMD_UNIQUE);
    116           1.1       cgd 		}
    117           1.1       cgd 		lp++;
    118           1.1       cgd 		rp++;
    119           1.1       cgd 	    }
    120           1.1       cgd 	    if (c == 0) {
    121           1.1       cgd 		/* end of name, not end of command -
    122           1.1       cgd 		   partial match */
    123           1.1       cgd 		if (result == CMD_FOUND) {
    124           1.1       cgd 		    result = CMD_AMBIGUOUS;
    125           1.1       cgd 		    /* but keep looking for a full match -
    126           1.1       cgd 		       this lets us match single letters */
    127           1.1       cgd 		}
    128           1.1       cgd 		else {
    129           1.1       cgd 		    *cmdp = cmd;
    130           1.1       cgd 		    result = CMD_FOUND;
    131           1.1       cgd 		}
    132           1.1       cgd 	    }
    133           1.1       cgd 	}
    134           1.1       cgd 	if (result == CMD_NONE) {
    135           1.1       cgd 	    /* check for 'help' */
    136           1.1       cgd 		if (name[0] == 'h' && name[1] == 'e'
    137           1.1       cgd 		    && name[2] == 'l' && name[3] == 'p')
    138           1.1       cgd 			result = CMD_HELP;
    139           1.1       cgd 	}
    140           1.1       cgd 	return (result);
    141           1.1       cgd }
    142           1.1       cgd 
    143           1.1       cgd void
    144           1.1       cgd db_cmd_list(table)
    145          1.10        pk 	struct db_command *table;
    146           1.1       cgd {
    147          1.10        pk 	register struct db_command *cmd;
    148           1.1       cgd 
    149           1.1       cgd 	for (cmd = table; cmd->name != 0; cmd++) {
    150           1.1       cgd 	    db_printf("%-12s", cmd->name);
    151           1.1       cgd 	    db_end_line();
    152           1.1       cgd 	}
    153           1.1       cgd }
    154           1.1       cgd 
    155           1.1       cgd void
    156           1.1       cgd db_command(last_cmdp, cmd_table)
    157          1.10        pk 	struct db_command	**last_cmdp;	/* IN_OUT */
    158          1.10        pk 	struct db_command	*cmd_table;
    159           1.1       cgd {
    160          1.10        pk 	struct db_command	*cmd;
    161           1.1       cgd 	int		t;
    162           1.1       cgd 	char		modif[TOK_STRING_SIZE];
    163           1.1       cgd 	db_expr_t	addr, count;
    164          1.16  christos 	boolean_t	have_addr = FALSE;
    165           1.1       cgd 	int		result;
    166           1.1       cgd 
    167           1.1       cgd 	t = db_read_token();
    168           1.1       cgd 	if (t == tEOL) {
    169           1.1       cgd 	    /* empty line repeats last command, at 'next' */
    170           1.1       cgd 	    cmd = *last_cmdp;
    171           1.1       cgd 	    addr = (db_expr_t)db_next;
    172           1.1       cgd 	    have_addr = FALSE;
    173           1.1       cgd 	    count = 1;
    174           1.1       cgd 	    modif[0] = '\0';
    175           1.1       cgd 	}
    176           1.1       cgd 	else if (t == tEXCL) {
    177          1.16  christos 	    db_fncall(0, 0, 0, NULL);
    178           1.1       cgd 	    return;
    179           1.1       cgd 	}
    180           1.1       cgd 	else if (t != tIDENT) {
    181           1.1       cgd 	    db_printf("?\n");
    182           1.1       cgd 	    db_flush_lex();
    183           1.1       cgd 	    return;
    184           1.1       cgd 	}
    185           1.1       cgd 	else {
    186           1.1       cgd 	    /*
    187           1.1       cgd 	     * Search for command
    188           1.1       cgd 	     */
    189           1.1       cgd 	    while (cmd_table) {
    190           1.1       cgd 		result = db_cmd_search(db_tok_string,
    191           1.1       cgd 				       cmd_table,
    192           1.1       cgd 				       &cmd);
    193           1.1       cgd 		switch (result) {
    194           1.1       cgd 		    case CMD_NONE:
    195           1.1       cgd 			db_printf("No such command\n");
    196           1.1       cgd 			db_flush_lex();
    197           1.1       cgd 			return;
    198           1.1       cgd 		    case CMD_AMBIGUOUS:
    199           1.1       cgd 			db_printf("Ambiguous\n");
    200           1.1       cgd 			db_flush_lex();
    201           1.1       cgd 			return;
    202           1.1       cgd 		    case CMD_HELP:
    203           1.1       cgd 			db_cmd_list(cmd_table);
    204           1.1       cgd 			db_flush_lex();
    205           1.1       cgd 			return;
    206           1.1       cgd 		    default:
    207           1.1       cgd 			break;
    208           1.1       cgd 		}
    209           1.1       cgd 		if ((cmd_table = cmd->more) != 0) {
    210           1.1       cgd 		    t = db_read_token();
    211           1.1       cgd 		    if (t != tIDENT) {
    212           1.1       cgd 			db_cmd_list(cmd_table);
    213           1.1       cgd 			db_flush_lex();
    214           1.1       cgd 			return;
    215           1.1       cgd 		    }
    216           1.1       cgd 		}
    217           1.1       cgd 	    }
    218           1.1       cgd 
    219           1.1       cgd 	    if ((cmd->flag & CS_OWN) == 0) {
    220           1.1       cgd 		/*
    221           1.1       cgd 		 * Standard syntax:
    222           1.1       cgd 		 * command [/modifier] [addr] [,count]
    223           1.1       cgd 		 */
    224           1.1       cgd 		t = db_read_token();
    225           1.1       cgd 		if (t == tSLASH) {
    226           1.1       cgd 		    t = db_read_token();
    227           1.1       cgd 		    if (t != tIDENT) {
    228           1.1       cgd 			db_printf("Bad modifier\n");
    229           1.1       cgd 			db_flush_lex();
    230           1.1       cgd 			return;
    231           1.1       cgd 		    }
    232           1.1       cgd 		    db_strcpy(modif, db_tok_string);
    233           1.1       cgd 		}
    234           1.1       cgd 		else {
    235           1.1       cgd 		    db_unread_token(t);
    236           1.1       cgd 		    modif[0] = '\0';
    237           1.1       cgd 		}
    238           1.1       cgd 
    239           1.1       cgd 		if (db_expression(&addr)) {
    240           1.1       cgd 		    db_dot = (db_addr_t) addr;
    241           1.1       cgd 		    db_last_addr = db_dot;
    242           1.1       cgd 		    have_addr = TRUE;
    243           1.1       cgd 		}
    244           1.1       cgd 		else {
    245           1.1       cgd 		    addr = (db_expr_t) db_dot;
    246           1.1       cgd 		    have_addr = FALSE;
    247           1.1       cgd 		}
    248           1.1       cgd 		t = db_read_token();
    249           1.1       cgd 		if (t == tCOMMA) {
    250           1.1       cgd 		    if (!db_expression(&count)) {
    251           1.1       cgd 			db_printf("Count missing\n");
    252           1.1       cgd 			db_flush_lex();
    253           1.1       cgd 			return;
    254           1.1       cgd 		    }
    255           1.1       cgd 		}
    256           1.1       cgd 		else {
    257           1.1       cgd 		    db_unread_token(t);
    258           1.1       cgd 		    count = -1;
    259           1.1       cgd 		}
    260           1.1       cgd 		if ((cmd->flag & CS_MORE) == 0) {
    261           1.1       cgd 		    db_skip_to_eol();
    262           1.1       cgd 		}
    263           1.1       cgd 	    }
    264           1.1       cgd 	}
    265           1.1       cgd 	*last_cmdp = cmd;
    266           1.1       cgd 	if (cmd != 0) {
    267           1.1       cgd 	    /*
    268           1.1       cgd 	     * Execute the command.
    269           1.1       cgd 	     */
    270           1.1       cgd 	    (*cmd->fcn)(addr, have_addr, count, modif);
    271           1.1       cgd 
    272           1.1       cgd 	    if (cmd->flag & CS_SET_DOT) {
    273           1.1       cgd 		/*
    274           1.1       cgd 		 * If command changes dot, set dot to
    275           1.1       cgd 		 * previous address displayed (if 'ed' style).
    276           1.1       cgd 		 */
    277           1.1       cgd 		if (db_ed_style) {
    278           1.1       cgd 		    db_dot = db_prev;
    279           1.1       cgd 		}
    280           1.1       cgd 		else {
    281           1.1       cgd 		    db_dot = db_next;
    282           1.1       cgd 		}
    283           1.1       cgd 	    }
    284           1.1       cgd 	    else {
    285           1.1       cgd 		/*
    286           1.1       cgd 		 * If command does not change dot,
    287           1.1       cgd 		 * set 'next' location to be the same.
    288           1.1       cgd 		 */
    289           1.1       cgd 		db_next = db_dot;
    290           1.1       cgd 	    }
    291           1.1       cgd 	}
    292           1.1       cgd }
    293           1.1       cgd 
    294           1.4    brezak /*ARGSUSED*/
    295           1.4    brezak void
    296           1.4    brezak db_map_print_cmd(addr, have_addr, count, modif)
    297           1.4    brezak 	db_expr_t	addr;
    298           1.4    brezak 	int		have_addr;
    299           1.4    brezak 	db_expr_t	count;
    300           1.4    brezak 	char *		modif;
    301           1.4    brezak {
    302           1.4    brezak         boolean_t full = FALSE;
    303           1.4    brezak 
    304           1.4    brezak         if (modif[0] == 'f')
    305           1.4    brezak                 full = TRUE;
    306           1.4    brezak 
    307          1.24       mrg         uvm_map_printit((vm_map_t) addr, full, db_printf);
    308           1.4    brezak }
    309           1.4    brezak 
    310           1.4    brezak /*ARGSUSED*/
    311           1.4    brezak void
    312           1.4    brezak db_object_print_cmd(addr, have_addr, count, modif)
    313           1.4    brezak 	db_expr_t	addr;
    314           1.4    brezak 	int		have_addr;
    315           1.4    brezak 	db_expr_t	count;
    316           1.4    brezak 	char *		modif;
    317           1.4    brezak {
    318           1.4    brezak         boolean_t full = FALSE;
    319           1.4    brezak 
    320           1.4    brezak         if (modif[0] == 'f')
    321           1.4    brezak                 full = TRUE;
    322           1.4    brezak 
    323          1.24       mrg 	uvm_object_printit((struct uvm_object *) addr, full, db_printf);
    324          1.24       mrg }
    325          1.24       mrg 
    326          1.24       mrg /*ARGSUSED*/
    327          1.24       mrg void
    328          1.24       mrg db_page_print_cmd(addr, have_addr, count, modif)
    329          1.24       mrg 	db_expr_t	addr;
    330          1.24       mrg 	int		have_addr;
    331          1.24       mrg 	db_expr_t	count;
    332          1.24       mrg 	char *		modif;
    333          1.24       mrg {
    334          1.24       mrg         boolean_t full = FALSE;
    335          1.24       mrg 
    336          1.24       mrg         if (modif[0] == 'f')
    337          1.24       mrg                 full = TRUE;
    338          1.24       mrg 
    339          1.24       mrg 	uvm_page_printit((struct vm_page *) addr, full, db_printf);
    340           1.4    brezak }
    341           1.4    brezak 
    342  1.28.2.2.2.1       chs /*ARGSUSED*/
    343  1.28.2.2.2.1       chs void
    344  1.28.2.2.2.1       chs db_buf_print_cmd(addr, have_addr, count, modif)
    345  1.28.2.2.2.1       chs 	db_expr_t	addr;
    346  1.28.2.2.2.1       chs 	int		have_addr;
    347  1.28.2.2.2.1       chs 	db_expr_t	count;
    348  1.28.2.2.2.1       chs 	char *		modif;
    349  1.28.2.2.2.1       chs {
    350  1.28.2.2.2.1       chs 	boolean_t full = FALSE;
    351  1.28.2.2.2.1       chs 
    352  1.28.2.2.2.1       chs 	if (modif[0] == 'f')
    353  1.28.2.2.2.1       chs 		full = TRUE;
    354  1.28.2.2.2.1       chs 
    355  1.28.2.2.2.1       chs 	vfs_buf_print((struct buf *)addr, full, db_printf);
    356  1.28.2.2.2.1       chs }
    357  1.28.2.2.2.1       chs 
    358  1.28.2.2.2.1       chs /*ARGSUSED*/
    359  1.28.2.2.2.1       chs void
    360  1.28.2.2.2.1       chs db_vnode_print_cmd(addr, have_addr, count, modif)
    361  1.28.2.2.2.1       chs 	db_expr_t	addr;
    362  1.28.2.2.2.1       chs 	int		have_addr;
    363  1.28.2.2.2.1       chs 	db_expr_t	count;
    364  1.28.2.2.2.1       chs 	char *		modif;
    365  1.28.2.2.2.1       chs {
    366  1.28.2.2.2.1       chs 	boolean_t full = FALSE;
    367  1.28.2.2.2.1       chs 
    368  1.28.2.2.2.1       chs 	if (modif[0] == 'f')
    369  1.28.2.2.2.1       chs 		full = TRUE;
    370  1.28.2.2.2.1       chs 
    371  1.28.2.2.2.1       chs 	vfs_vnode_print((struct vnode *) addr, full, db_printf);
    372  1.28.2.2.2.1       chs }
    373  1.28.2.2.2.1       chs 
    374           1.1       cgd /*
    375           1.1       cgd  * 'show' commands
    376           1.1       cgd  */
    377           1.1       cgd 
    378          1.10        pk struct db_command db_show_all_cmds[] = {
    379          1.16  christos 	{ "procs",	db_show_all_procs,	0, NULL },
    380          1.16  christos 	{ "callout",	db_show_callout,	0, NULL },
    381          1.16  christos 	{ NULL, 	NULL, 			0, NULL }
    382           1.1       cgd };
    383           1.1       cgd 
    384          1.10        pk struct db_command db_show_cmds[] = {
    385          1.16  christos 	{ "all",	NULL,			0,	db_show_all_cmds },
    386          1.16  christos 	{ "registers",	db_show_regs,		0,	NULL },
    387          1.16  christos 	{ "breaks",	db_listbreak_cmd, 	0,	NULL },
    388          1.16  christos 	{ "watches",	db_listwatch_cmd, 	0,	NULL },
    389          1.16  christos 	{ "map",	db_map_print_cmd,	0,	NULL },
    390          1.16  christos 	{ "object",	db_object_print_cmd,	0,	NULL },
    391          1.24       mrg 	{ "page",	db_page_print_cmd,	0,	NULL },
    392  1.28.2.2.2.1       chs 	{ "buf",	db_buf_print_cmd,	0,	NULL },
    393  1.28.2.2.2.1       chs 	{ "vnode",	db_vnode_print_cmd,	0,	NULL },
    394          1.16  christos 	{ NULL,		NULL,			0,	NULL, }
    395           1.1       cgd };
    396           1.1       cgd 
    397          1.10        pk struct db_command db_command_table[] = {
    398           1.6    brezak #ifdef DB_MACHINE_COMMANDS
    399           1.6    brezak   /* this must be the first entry, if it exists */
    400          1.16  christos 	{ "machine",    NULL,                   0,     		NULL},
    401           1.6    brezak #endif
    402          1.16  christos 	{ "print",	db_print_cmd,		0,		NULL },
    403          1.16  christos 	{ "examine",	db_examine_cmd,		CS_SET_DOT, 	NULL },
    404          1.16  christos 	{ "x",		db_examine_cmd,		CS_SET_DOT, 	NULL },
    405          1.16  christos 	{ "search",	db_search_cmd,		CS_OWN|CS_SET_DOT, NULL },
    406          1.16  christos 	{ "set",	db_set_cmd,		CS_OWN,		NULL },
    407          1.16  christos 	{ "write",	db_write_cmd,		CS_MORE|CS_SET_DOT, NULL },
    408          1.16  christos 	{ "w",		db_write_cmd,		CS_MORE|CS_SET_DOT, NULL },
    409          1.16  christos 	{ "delete",	db_delete_cmd,		0,		NULL },
    410          1.16  christos 	{ "d",		db_delete_cmd,		0,		NULL },
    411          1.16  christos 	{ "break",	db_breakpoint_cmd,	0,		NULL },
    412          1.16  christos 	{ "dwatch",	db_deletewatch_cmd,	0,		NULL },
    413          1.16  christos 	{ "watch",	db_watchpoint_cmd,	CS_MORE,	NULL },
    414          1.16  christos 	{ "step",	db_single_step_cmd,	0,		NULL },
    415          1.16  christos 	{ "s",		db_single_step_cmd,	0,		NULL },
    416          1.16  christos 	{ "continue",	db_continue_cmd,	0,		NULL },
    417          1.16  christos 	{ "c",		db_continue_cmd,	0,		NULL },
    418          1.16  christos 	{ "until",	db_trace_until_call_cmd,0,		NULL },
    419          1.16  christos 	{ "next",	db_trace_until_matching_cmd,0,		NULL },
    420          1.16  christos 	{ "match",	db_trace_until_matching_cmd,0,		NULL },
    421          1.16  christos 	{ "trace",	db_stack_trace_cmd,	0,		NULL },
    422          1.16  christos 	{ "call",	db_fncall,		CS_OWN,		NULL },
    423          1.16  christos 	{ "ps",		db_show_all_procs,	0,		NULL },
    424          1.23    scottr 	{ "kill",	db_kill_proc,		CS_OWN,		NULL },
    425          1.16  christos 	{ "callout",	db_show_callout,	0,		NULL },
    426          1.23    scottr 	{ "reboot",	db_reboot_cmd,		CS_OWN,		NULL },
    427          1.16  christos 	{ "show",	NULL,			0,		db_show_cmds },
    428          1.16  christos 	{ NULL, 	NULL,			0,		NULL }
    429           1.1       cgd };
    430           1.6    brezak 
    431           1.6    brezak #ifdef DB_MACHINE_COMMANDS
    432           1.6    brezak 
    433           1.6    brezak /* this function should be called to install the machine dependent
    434           1.6    brezak    commands. It should be called before the debugger is enabled  */
    435           1.6    brezak void db_machine_commands_install(ptr)
    436           1.6    brezak struct db_command *ptr;
    437           1.6    brezak {
    438           1.6    brezak   db_command_table[0].more = ptr;
    439           1.6    brezak   return;
    440           1.6    brezak }
    441           1.6    brezak 
    442           1.6    brezak #endif
    443           1.1       cgd 
    444          1.10        pk struct db_command	*db_last_command = 0;
    445           1.1       cgd 
    446           1.1       cgd void
    447           1.1       cgd db_help_cmd()
    448           1.1       cgd {
    449          1.10        pk 	struct db_command *cmd = db_command_table;
    450           1.1       cgd 
    451           1.1       cgd 	while (cmd->name != 0) {
    452           1.1       cgd 	    db_printf("%-12s", cmd->name);
    453           1.1       cgd 	    db_end_line();
    454           1.1       cgd 	    cmd++;
    455           1.1       cgd 	}
    456           1.1       cgd }
    457           1.1       cgd 
    458           1.1       cgd void
    459           1.1       cgd db_command_loop()
    460           1.1       cgd {
    461          1.17       gwr 	label_t		db_jmpbuf;
    462          1.17       gwr 	label_t		*savejmp;
    463           1.8   mycroft 	extern int	db_output_line;
    464           1.4    brezak 
    465           1.1       cgd 	/*
    466           1.1       cgd 	 * Initialize 'prev' and 'next' to dot.
    467           1.1       cgd 	 */
    468           1.1       cgd 	db_prev = db_dot;
    469           1.1       cgd 	db_next = db_dot;
    470           1.1       cgd 
    471           1.1       cgd 	db_cmd_loop_done = 0;
    472          1.17       gwr 
    473          1.17       gwr 	savejmp = db_recover;
    474          1.17       gwr 	db_recover = &db_jmpbuf;
    475          1.17       gwr 	(void) setjmp(&db_jmpbuf);
    476           1.8   mycroft 
    477           1.1       cgd 	while (!db_cmd_loop_done) {
    478           1.8   mycroft 		if (db_print_position() != 0)
    479           1.8   mycroft 			db_printf("\n");
    480           1.8   mycroft 		db_output_line = 0;
    481           1.1       cgd 
    482           1.8   mycroft 		db_printf("db> ");
    483           1.8   mycroft 		(void) db_read_line();
    484           1.1       cgd 
    485           1.8   mycroft 		db_command(&db_last_command, db_command_table);
    486           1.8   mycroft 	}
    487           1.1       cgd 
    488           1.8   mycroft 	db_recover = savejmp;
    489           1.1       cgd }
    490           1.1       cgd 
    491           1.1       cgd void
    492           1.1       cgd db_error(s)
    493           1.1       cgd 	char *s;
    494           1.1       cgd {
    495           1.1       cgd 	if (s)
    496           1.1       cgd 	    db_printf(s);
    497           1.1       cgd 	db_flush_lex();
    498          1.19  christos 	longjmp(db_recover);
    499           1.1       cgd }
    500           1.1       cgd 
    501           1.1       cgd 
    502           1.1       cgd /*
    503           1.1       cgd  * Call random function:
    504           1.1       cgd  * !expr(arg,arg,arg)
    505           1.1       cgd  */
    506          1.16  christos /*ARGSUSED*/
    507           1.1       cgd void
    508          1.16  christos db_fncall(addr, have_addr, count, modif)
    509          1.16  christos 	db_expr_t	addr;
    510          1.16  christos 	int		have_addr;
    511          1.16  christos 	db_expr_t	count;
    512          1.16  christos 	char *		modif;
    513           1.1       cgd {
    514           1.1       cgd 	db_expr_t	fn_addr;
    515           1.1       cgd #define	MAXARGS		11
    516           1.1       cgd 	db_expr_t	args[MAXARGS];
    517           1.1       cgd 	int		nargs = 0;
    518           1.1       cgd 	db_expr_t	retval;
    519          1.16  christos 	db_expr_t	(*func) __P((db_expr_t, ...));
    520           1.1       cgd 	int		t;
    521           1.1       cgd 
    522           1.1       cgd 	if (!db_expression(&fn_addr)) {
    523           1.1       cgd 	    db_printf("Bad function\n");
    524           1.1       cgd 	    db_flush_lex();
    525           1.1       cgd 	    return;
    526           1.1       cgd 	}
    527          1.16  christos 	func = (db_expr_t (*) __P((db_expr_t, ...))) fn_addr;
    528           1.1       cgd 
    529           1.1       cgd 	t = db_read_token();
    530           1.1       cgd 	if (t == tLPAREN) {
    531           1.1       cgd 	    if (db_expression(&args[0])) {
    532           1.1       cgd 		nargs++;
    533           1.1       cgd 		while ((t = db_read_token()) == tCOMMA) {
    534           1.1       cgd 		    if (nargs == MAXARGS) {
    535           1.1       cgd 			db_printf("Too many arguments\n");
    536           1.1       cgd 			db_flush_lex();
    537           1.1       cgd 			return;
    538           1.1       cgd 		    }
    539           1.1       cgd 		    if (!db_expression(&args[nargs])) {
    540           1.1       cgd 			db_printf("Argument missing\n");
    541           1.1       cgd 			db_flush_lex();
    542           1.1       cgd 			return;
    543           1.1       cgd 		    }
    544           1.1       cgd 		    nargs++;
    545           1.1       cgd 		}
    546           1.1       cgd 		db_unread_token(t);
    547           1.1       cgd 	    }
    548           1.1       cgd 	    if (db_read_token() != tRPAREN) {
    549           1.1       cgd 		db_printf("?\n");
    550           1.1       cgd 		db_flush_lex();
    551           1.1       cgd 		return;
    552           1.1       cgd 	    }
    553           1.1       cgd 	}
    554           1.1       cgd 	db_skip_to_eol();
    555           1.1       cgd 
    556           1.1       cgd 	while (nargs < MAXARGS) {
    557           1.1       cgd 	    args[nargs++] = 0;
    558           1.1       cgd 	}
    559           1.1       cgd 
    560           1.1       cgd 	retval = (*func)(args[0], args[1], args[2], args[3], args[4],
    561          1.20  christos 			 args[5], args[6], args[7], args[8], args[9]);
    562          1.21   mycroft 	db_printf("%#ln\n", retval);
    563          1.23    scottr }
    564          1.23    scottr 
    565          1.23    scottr void
    566          1.23    scottr db_reboot_cmd(addr, have_addr, count, modif)
    567          1.23    scottr 	db_expr_t	addr;
    568          1.23    scottr 	int		have_addr;
    569          1.23    scottr 	db_expr_t	count;
    570          1.23    scottr 	char *		modif;
    571          1.23    scottr {
    572          1.23    scottr 	db_expr_t bootflags;
    573          1.23    scottr 
    574          1.23    scottr 	/* Flags, default to RB_AUTOBOOT */
    575          1.23    scottr 	if (!db_expression(&bootflags))
    576          1.23    scottr 		bootflags = (db_expr_t)RB_AUTOBOOT;
    577          1.23    scottr 	if (db_read_token() != tEOL) {
    578          1.23    scottr 	    db_error("?\n");
    579          1.23    scottr 	    /*NOTREACHED*/
    580          1.23    scottr 	}
    581          1.23    scottr 	cpu_reboot((int)bootflags, NULL);
    582           1.1       cgd }
    583