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