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