xref: /freebsd/sys/ddb/db_command.c (revision 058284fceb843b1fc95ffb704de3f9bd088607a9)
15b81b6b3SRodney W. Grimes /*
25b81b6b3SRodney W. Grimes  * Mach Operating System
35b81b6b3SRodney W. Grimes  * Copyright (c) 1991,1990 Carnegie Mellon University
45b81b6b3SRodney W. Grimes  * All Rights Reserved.
55b81b6b3SRodney W. Grimes  *
65b81b6b3SRodney W. Grimes  * Permission to use, copy, modify and distribute this software and its
75b81b6b3SRodney W. Grimes  * documentation is hereby granted, provided that both the copyright
85b81b6b3SRodney W. Grimes  * notice and this permission notice appear in all copies of the
95b81b6b3SRodney W. Grimes  * software, derivative works or modified versions, and any portions
105b81b6b3SRodney W. Grimes  * thereof, and that both notices appear in supporting documentation.
115b81b6b3SRodney W. Grimes  *
125b81b6b3SRodney W. Grimes  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
135b81b6b3SRodney W. Grimes  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
145b81b6b3SRodney W. Grimes  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
155b81b6b3SRodney W. Grimes  *
165b81b6b3SRodney W. Grimes  * Carnegie Mellon requests users of this software to return to
175b81b6b3SRodney W. Grimes  *
185b81b6b3SRodney W. Grimes  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
195b81b6b3SRodney W. Grimes  *  School of Computer Science
205b81b6b3SRodney W. Grimes  *  Carnegie Mellon University
215b81b6b3SRodney W. Grimes  *  Pittsburgh PA 15213-3890
225b81b6b3SRodney W. Grimes  *
235b81b6b3SRodney W. Grimes  * any improvements or extensions that they make and grant Carnegie the
245b81b6b3SRodney W. Grimes  * rights to redistribute these changes.
250edf66ecSRodney W. Grimes  *
26058284fcSBruce Evans  *	$Id: db_command.c,v 1.14 1995/08/27 02:39:39 bde Exp $
275b81b6b3SRodney W. Grimes  */
280edf66ecSRodney W. Grimes 
295b81b6b3SRodney W. Grimes /*
305b81b6b3SRodney W. Grimes  *	Author: David B. Golub, Carnegie Mellon University
315b81b6b3SRodney W. Grimes  *	Date:	7/90
325b81b6b3SRodney W. Grimes  */
330edf66ecSRodney W. Grimes 
345b81b6b3SRodney W. Grimes /*
355b81b6b3SRodney W. Grimes  * Command dispatcher.
365b81b6b3SRodney W. Grimes  */
37f540b106SGarrett Wollman #include <sys/param.h>
38f540b106SGarrett Wollman #include <sys/systm.h>
39f540b106SGarrett Wollman #include <sys/proc.h>
40f540b106SGarrett Wollman #include <ddb/ddb.h>
415b81b6b3SRodney W. Grimes 
42058284fcSBruce Evans #include <ddb/db_command.h>
435b81b6b3SRodney W. Grimes #include <ddb/db_lex.h>
445b81b6b3SRodney W. Grimes #include <ddb/db_output.h>
455b81b6b3SRodney W. Grimes 
465b81b6b3SRodney W. Grimes #include <setjmp.h>
475b81b6b3SRodney W. Grimes 
485b81b6b3SRodney W. Grimes /*
495b81b6b3SRodney W. Grimes  * Exported global variables
505b81b6b3SRodney W. Grimes  */
515b81b6b3SRodney W. Grimes boolean_t	db_cmd_loop_done;
525b81b6b3SRodney W. Grimes jmp_buf		db_jmpbuf;
535b81b6b3SRodney W. Grimes db_addr_t	db_dot;
545b81b6b3SRodney W. Grimes db_addr_t	db_last_addr;
555b81b6b3SRodney W. Grimes db_addr_t	db_prev;
565b81b6b3SRodney W. Grimes db_addr_t	db_next;
575b81b6b3SRodney W. Grimes 
585b81b6b3SRodney W. Grimes /*
595b81b6b3SRodney W. Grimes  * if 'ed' style: 'dot' is set at start of last item printed,
605b81b6b3SRodney W. Grimes  * and '+' points to next line.
615b81b6b3SRodney W. Grimes  * Otherwise: 'dot' points to next item, '..' points to last.
625b81b6b3SRodney W. Grimes  */
635b81b6b3SRodney W. Grimes boolean_t	db_ed_style = TRUE;
645b81b6b3SRodney W. Grimes 
655b81b6b3SRodney W. Grimes /*
665b81b6b3SRodney W. Grimes  * Utility routine - discard tokens through end-of-line.
675b81b6b3SRodney W. Grimes  */
685b81b6b3SRodney W. Grimes void
695b81b6b3SRodney W. Grimes db_skip_to_eol()
705b81b6b3SRodney W. Grimes {
715b81b6b3SRodney W. Grimes 	int	t;
725b81b6b3SRodney W. Grimes 	do {
735b81b6b3SRodney W. Grimes 	    t = db_read_token();
745b81b6b3SRodney W. Grimes 	} while (t != tEOL);
755b81b6b3SRodney W. Grimes }
765b81b6b3SRodney W. Grimes 
775b81b6b3SRodney W. Grimes /*
785b81b6b3SRodney W. Grimes  * Command table
795b81b6b3SRodney W. Grimes  */
805b81b6b3SRodney W. Grimes struct command {
815b81b6b3SRodney W. Grimes 	char *	name;		/* command name */
82058284fcSBruce Evans 	db_cmdfcn_t *fcn;	/* function to call */
835b81b6b3SRodney W. Grimes 	int	flag;		/* extra info: */
845b81b6b3SRodney W. Grimes #define	CS_OWN		0x1	    /* non-standard syntax */
855b81b6b3SRodney W. Grimes #define	CS_MORE		0x2	    /* standard syntax, but may have other
865b81b6b3SRodney W. Grimes 				       words at end */
875b81b6b3SRodney W. Grimes #define	CS_SET_DOT	0x100	    /* set dot after command */
885b81b6b3SRodney W. Grimes 	struct command *more;	/* another level of command */
895b81b6b3SRodney W. Grimes };
905b81b6b3SRodney W. Grimes 
915b81b6b3SRodney W. Grimes /*
925b81b6b3SRodney W. Grimes  * Results of command search.
935b81b6b3SRodney W. Grimes  */
945b81b6b3SRodney W. Grimes #define	CMD_UNIQUE	0
955b81b6b3SRodney W. Grimes #define	CMD_FOUND	1
965b81b6b3SRodney W. Grimes #define	CMD_NONE	2
975b81b6b3SRodney W. Grimes #define	CMD_AMBIGUOUS	3
985b81b6b3SRodney W. Grimes #define	CMD_HELP	4
995b81b6b3SRodney W. Grimes 
100058284fcSBruce Evans extern void	db_cmd_list __P((struct command *table));
101058284fcSBruce Evans extern int	db_cmd_search __P((char *name, struct command *table,
102058284fcSBruce Evans 				   struct command **cmdp));
103058284fcSBruce Evans extern void	db_command __P((struct command **last_cmdp,
104058284fcSBruce Evans 				struct command *cmd_table));
105058284fcSBruce Evans 
1065b81b6b3SRodney W. Grimes /*
1075b81b6b3SRodney W. Grimes  * Search for command prefix.
1085b81b6b3SRodney W. Grimes  */
1095b81b6b3SRodney W. Grimes int
1105b81b6b3SRodney W. Grimes db_cmd_search(name, table, cmdp)
1115b81b6b3SRodney W. Grimes 	char *		name;
1125b81b6b3SRodney W. Grimes 	struct command	*table;
1135b81b6b3SRodney W. Grimes 	struct command	**cmdp;	/* out */
1145b81b6b3SRodney W. Grimes {
1155b81b6b3SRodney W. Grimes 	struct command	*cmd;
1165b81b6b3SRodney W. Grimes 	int		result = CMD_NONE;
1175b81b6b3SRodney W. Grimes 
1185b81b6b3SRodney W. Grimes 	for (cmd = table; cmd->name != 0; cmd++) {
1195b81b6b3SRodney W. Grimes 	    register char *lp;
1205b81b6b3SRodney W. Grimes 	    register char *rp;
1215b81b6b3SRodney W. Grimes 	    register int  c;
1225b81b6b3SRodney W. Grimes 
1235b81b6b3SRodney W. Grimes 	    lp = name;
1245b81b6b3SRodney W. Grimes 	    rp = cmd->name;
1255b81b6b3SRodney W. Grimes 	    while ((c = *lp) == *rp) {
1265b81b6b3SRodney W. Grimes 		if (c == 0) {
1275b81b6b3SRodney W. Grimes 		    /* complete match */
1285b81b6b3SRodney W. Grimes 		    *cmdp = cmd;
1295b81b6b3SRodney W. Grimes 		    return (CMD_UNIQUE);
1305b81b6b3SRodney W. Grimes 		}
1315b81b6b3SRodney W. Grimes 		lp++;
1325b81b6b3SRodney W. Grimes 		rp++;
1335b81b6b3SRodney W. Grimes 	    }
1345b81b6b3SRodney W. Grimes 	    if (c == 0) {
1355b81b6b3SRodney W. Grimes 		/* end of name, not end of command -
1365b81b6b3SRodney W. Grimes 		   partial match */
1375b81b6b3SRodney W. Grimes 		if (result == CMD_FOUND) {
1385b81b6b3SRodney W. Grimes 		    result = CMD_AMBIGUOUS;
1395b81b6b3SRodney W. Grimes 		    /* but keep looking for a full match -
1405b81b6b3SRodney W. Grimes 		       this lets us match single letters */
1415b81b6b3SRodney W. Grimes 		}
1425b81b6b3SRodney W. Grimes 		else {
1435b81b6b3SRodney W. Grimes 		    *cmdp = cmd;
1445b81b6b3SRodney W. Grimes 		    result = CMD_FOUND;
1455b81b6b3SRodney W. Grimes 		}
1465b81b6b3SRodney W. Grimes 	    }
1475b81b6b3SRodney W. Grimes 	}
1485b81b6b3SRodney W. Grimes 	if (result == CMD_NONE) {
1495b81b6b3SRodney W. Grimes 	    /* check for 'help' */
1505b81b6b3SRodney W. Grimes 		if (name[0] == 'h' && name[1] == 'e'
1515b81b6b3SRodney W. Grimes 		    && name[2] == 'l' && name[3] == 'p')
1525b81b6b3SRodney W. Grimes 			result = CMD_HELP;
1535b81b6b3SRodney W. Grimes 	}
1545b81b6b3SRodney W. Grimes 	return (result);
1555b81b6b3SRodney W. Grimes }
1565b81b6b3SRodney W. Grimes 
1575b81b6b3SRodney W. Grimes void
1585b81b6b3SRodney W. Grimes db_cmd_list(table)
1595b81b6b3SRodney W. Grimes 	struct command *table;
1605b81b6b3SRodney W. Grimes {
1615b81b6b3SRodney W. Grimes 	register struct command *cmd;
1625b81b6b3SRodney W. Grimes 
1635b81b6b3SRodney W. Grimes 	for (cmd = table; cmd->name != 0; cmd++) {
1645b81b6b3SRodney W. Grimes 	    db_printf("%-12s", cmd->name);
1655b81b6b3SRodney W. Grimes 	    db_end_line();
1665b81b6b3SRodney W. Grimes 	}
1675b81b6b3SRodney W. Grimes }
1685b81b6b3SRodney W. Grimes 
1695b81b6b3SRodney W. Grimes void
1705b81b6b3SRodney W. Grimes db_command(last_cmdp, cmd_table)
1715b81b6b3SRodney W. Grimes 	struct command	**last_cmdp;	/* IN_OUT */
1725b81b6b3SRodney W. Grimes 	struct command	*cmd_table;
1735b81b6b3SRodney W. Grimes {
1745b81b6b3SRodney W. Grimes 	struct command	*cmd;
1755b81b6b3SRodney W. Grimes 	int		t;
1765b81b6b3SRodney W. Grimes 	char		modif[TOK_STRING_SIZE];
1775b81b6b3SRodney W. Grimes 	db_expr_t	addr, count;
178381fe1aaSGarrett Wollman 	boolean_t	have_addr = FALSE;
1795b81b6b3SRodney W. Grimes 	int		result;
1805b81b6b3SRodney W. Grimes 
1815b81b6b3SRodney W. Grimes 	t = db_read_token();
1825b81b6b3SRodney W. Grimes 	if (t == tEOL) {
1835b81b6b3SRodney W. Grimes 	    /* empty line repeats last command, at 'next' */
1845b81b6b3SRodney W. Grimes 	    cmd = *last_cmdp;
1855b81b6b3SRodney W. Grimes 	    addr = (db_expr_t)db_next;
1865b81b6b3SRodney W. Grimes 	    have_addr = FALSE;
1875b81b6b3SRodney W. Grimes 	    count = 1;
1885b81b6b3SRodney W. Grimes 	    modif[0] = '\0';
1895b81b6b3SRodney W. Grimes 	}
1905b81b6b3SRodney W. Grimes 	else if (t == tEXCL) {
191976794d9SBruce Evans 	    db_fncall((db_expr_t)0, (boolean_t)0, (db_expr_t)0, (char *)0);
1925b81b6b3SRodney W. Grimes 	    return;
1935b81b6b3SRodney W. Grimes 	}
1945b81b6b3SRodney W. Grimes 	else if (t != tIDENT) {
1955b81b6b3SRodney W. Grimes 	    db_printf("?\n");
1965b81b6b3SRodney W. Grimes 	    db_flush_lex();
1975b81b6b3SRodney W. Grimes 	    return;
1985b81b6b3SRodney W. Grimes 	}
1995b81b6b3SRodney W. Grimes 	else {
2005b81b6b3SRodney W. Grimes 	    /*
2015b81b6b3SRodney W. Grimes 	     * Search for command
2025b81b6b3SRodney W. Grimes 	     */
2035b81b6b3SRodney W. Grimes 	    while (cmd_table) {
2045b81b6b3SRodney W. Grimes 		result = db_cmd_search(db_tok_string,
2055b81b6b3SRodney W. Grimes 				       cmd_table,
2065b81b6b3SRodney W. Grimes 				       &cmd);
2075b81b6b3SRodney W. Grimes 		switch (result) {
2085b81b6b3SRodney W. Grimes 		    case CMD_NONE:
2095b81b6b3SRodney W. Grimes 			db_printf("No such command\n");
2105b81b6b3SRodney W. Grimes 			db_flush_lex();
2115b81b6b3SRodney W. Grimes 			return;
2125b81b6b3SRodney W. Grimes 		    case CMD_AMBIGUOUS:
2135b81b6b3SRodney W. Grimes 			db_printf("Ambiguous\n");
2145b81b6b3SRodney W. Grimes 			db_flush_lex();
2155b81b6b3SRodney W. Grimes 			return;
2165b81b6b3SRodney W. Grimes 		    case CMD_HELP:
2175b81b6b3SRodney W. Grimes 			db_cmd_list(cmd_table);
2185b81b6b3SRodney W. Grimes 			db_flush_lex();
2195b81b6b3SRodney W. Grimes 			return;
2205b81b6b3SRodney W. Grimes 		    default:
2215b81b6b3SRodney W. Grimes 			break;
2225b81b6b3SRodney W. Grimes 		}
2235b81b6b3SRodney W. Grimes 		if ((cmd_table = cmd->more) != 0) {
2245b81b6b3SRodney W. Grimes 		    t = db_read_token();
2255b81b6b3SRodney W. Grimes 		    if (t != tIDENT) {
2265b81b6b3SRodney W. Grimes 			db_cmd_list(cmd_table);
2275b81b6b3SRodney W. Grimes 			db_flush_lex();
2285b81b6b3SRodney W. Grimes 			return;
2295b81b6b3SRodney W. Grimes 		    }
2305b81b6b3SRodney W. Grimes 		}
2315b81b6b3SRodney W. Grimes 	    }
2325b81b6b3SRodney W. Grimes 
2335b81b6b3SRodney W. Grimes 	    if ((cmd->flag & CS_OWN) == 0) {
2345b81b6b3SRodney W. Grimes 		/*
2355b81b6b3SRodney W. Grimes 		 * Standard syntax:
2365b81b6b3SRodney W. Grimes 		 * command [/modifier] [addr] [,count]
2375b81b6b3SRodney W. Grimes 		 */
2385b81b6b3SRodney W. Grimes 		t = db_read_token();
2395b81b6b3SRodney W. Grimes 		if (t == tSLASH) {
2405b81b6b3SRodney W. Grimes 		    t = db_read_token();
2415b81b6b3SRodney W. Grimes 		    if (t != tIDENT) {
2425b81b6b3SRodney W. Grimes 			db_printf("Bad modifier\n");
2435b81b6b3SRodney W. Grimes 			db_flush_lex();
2445b81b6b3SRodney W. Grimes 			return;
2455b81b6b3SRodney W. Grimes 		    }
2465b81b6b3SRodney W. Grimes 		    db_strcpy(modif, db_tok_string);
2475b81b6b3SRodney W. Grimes 		}
2485b81b6b3SRodney W. Grimes 		else {
2495b81b6b3SRodney W. Grimes 		    db_unread_token(t);
2505b81b6b3SRodney W. Grimes 		    modif[0] = '\0';
2515b81b6b3SRodney W. Grimes 		}
2525b81b6b3SRodney W. Grimes 
2535b81b6b3SRodney W. Grimes 		if (db_expression(&addr)) {
2545b81b6b3SRodney W. Grimes 		    db_dot = (db_addr_t) addr;
2555b81b6b3SRodney W. Grimes 		    db_last_addr = db_dot;
2565b81b6b3SRodney W. Grimes 		    have_addr = TRUE;
2575b81b6b3SRodney W. Grimes 		}
2585b81b6b3SRodney W. Grimes 		else {
2595b81b6b3SRodney W. Grimes 		    addr = (db_expr_t) db_dot;
2605b81b6b3SRodney W. Grimes 		    have_addr = FALSE;
2615b81b6b3SRodney W. Grimes 		}
2625b81b6b3SRodney W. Grimes 		t = db_read_token();
2635b81b6b3SRodney W. Grimes 		if (t == tCOMMA) {
2645b81b6b3SRodney W. Grimes 		    if (!db_expression(&count)) {
2655b81b6b3SRodney W. Grimes 			db_printf("Count missing\n");
2665b81b6b3SRodney W. Grimes 			db_flush_lex();
2675b81b6b3SRodney W. Grimes 			return;
2685b81b6b3SRodney W. Grimes 		    }
2695b81b6b3SRodney W. Grimes 		}
2705b81b6b3SRodney W. Grimes 		else {
2715b81b6b3SRodney W. Grimes 		    db_unread_token(t);
2725b81b6b3SRodney W. Grimes 		    count = -1;
2735b81b6b3SRodney W. Grimes 		}
2745b81b6b3SRodney W. Grimes 		if ((cmd->flag & CS_MORE) == 0) {
2755b81b6b3SRodney W. Grimes 		    db_skip_to_eol();
2765b81b6b3SRodney W. Grimes 		}
2775b81b6b3SRodney W. Grimes 	    }
2785b81b6b3SRodney W. Grimes 	}
2795b81b6b3SRodney W. Grimes 	*last_cmdp = cmd;
2805b81b6b3SRodney W. Grimes 	if (cmd != 0) {
2815b81b6b3SRodney W. Grimes 	    /*
2825b81b6b3SRodney W. Grimes 	     * Execute the command.
2835b81b6b3SRodney W. Grimes 	     */
2845b81b6b3SRodney W. Grimes 	    (*cmd->fcn)(addr, have_addr, count, modif);
2855b81b6b3SRodney W. Grimes 
2865b81b6b3SRodney W. Grimes 	    if (cmd->flag & CS_SET_DOT) {
2875b81b6b3SRodney W. Grimes 		/*
2885b81b6b3SRodney W. Grimes 		 * If command changes dot, set dot to
2895b81b6b3SRodney W. Grimes 		 * previous address displayed (if 'ed' style).
2905b81b6b3SRodney W. Grimes 		 */
2915b81b6b3SRodney W. Grimes 		if (db_ed_style) {
2925b81b6b3SRodney W. Grimes 		    db_dot = db_prev;
2935b81b6b3SRodney W. Grimes 		}
2945b81b6b3SRodney W. Grimes 		else {
2955b81b6b3SRodney W. Grimes 		    db_dot = db_next;
2965b81b6b3SRodney W. Grimes 		}
2975b81b6b3SRodney W. Grimes 	    }
2985b81b6b3SRodney W. Grimes 	    else {
2995b81b6b3SRodney W. Grimes 		/*
3005b81b6b3SRodney W. Grimes 		 * If command does not change dot,
3015b81b6b3SRodney W. Grimes 		 * set 'next' location to be the same.
3025b81b6b3SRodney W. Grimes 		 */
3035b81b6b3SRodney W. Grimes 		db_next = db_dot;
3045b81b6b3SRodney W. Grimes 	    }
3055b81b6b3SRodney W. Grimes 	}
3065b81b6b3SRodney W. Grimes }
3075b81b6b3SRodney W. Grimes 
3085b81b6b3SRodney W. Grimes /*
3095b81b6b3SRodney W. Grimes  * 'show' commands
3105b81b6b3SRodney W. Grimes  */
311f23b4c91SGarrett Wollman 
3125b81b6b3SRodney W. Grimes struct command db_show_all_cmds[] = {
3135b81b6b3SRodney W. Grimes #if 0
3145b81b6b3SRodney W. Grimes 	{ "threads",	db_show_all_threads,	0,	0 },
31526f9a767SRodney W. Grimes #endif
3168a129caeSDavid Greenman 	{ "procs",	db_ps,			0,	0 },
3175b81b6b3SRodney W. Grimes 	{ (char *)0 }
3185b81b6b3SRodney W. Grimes };
3195b81b6b3SRodney W. Grimes 
3205b81b6b3SRodney W. Grimes struct command db_show_cmds[] = {
3215b81b6b3SRodney W. Grimes 	{ "all",	0,			0,	db_show_all_cmds },
3225b81b6b3SRodney W. Grimes 	{ "registers",	db_show_regs,		0,	0 },
3235b81b6b3SRodney W. Grimes 	{ "breaks",	db_listbreak_cmd, 	0,	0 },
3245b81b6b3SRodney W. Grimes 	{ "watches",	db_listwatch_cmd, 	0,	0 },
3255b81b6b3SRodney W. Grimes #if 0
3265b81b6b3SRodney W. Grimes 	{ "thread",	db_show_one_thread,	0,	0 },
3275b81b6b3SRodney W. Grimes #endif
3285b81b6b3SRodney W. Grimes 	{ "map",	vm_map_print,		0,	0 },
3295b81b6b3SRodney W. Grimes 	{ "object",	vm_object_print,	0,	0 },
3305b81b6b3SRodney W. Grimes #if 0
3315b81b6b3SRodney W. Grimes 	{ "page",	vm_page_print,		0,	0 },
3325b81b6b3SRodney W. Grimes #endif
3335b81b6b3SRodney W. Grimes #if 0
3345b81b6b3SRodney W. Grimes 	{ "port",	ipc_port_print,		0,	0 },
3355b81b6b3SRodney W. Grimes #endif
3365b81b6b3SRodney W. Grimes 	{ (char *)0, }
3375b81b6b3SRodney W. Grimes };
3385b81b6b3SRodney W. Grimes 
3395b81b6b3SRodney W. Grimes struct command db_command_table[] = {
3405b81b6b3SRodney W. Grimes 	{ "print",	db_print_cmd,		0,	0 },
34123898040SJoerg Wunsch 	{ "p",		db_print_cmd,		0,	0 },
3425b81b6b3SRodney W. Grimes 	{ "examine",	db_examine_cmd,		CS_SET_DOT, 0 },
3435b81b6b3SRodney W. Grimes 	{ "x",		db_examine_cmd,		CS_SET_DOT, 0 },
3445b81b6b3SRodney W. Grimes 	{ "search",	db_search_cmd,		CS_OWN|CS_SET_DOT, 0 },
3455b81b6b3SRodney W. Grimes 	{ "set",	db_set_cmd,		CS_OWN,	0 },
3465b81b6b3SRodney W. Grimes 	{ "write",	db_write_cmd,		CS_MORE|CS_SET_DOT, 0 },
3475b81b6b3SRodney W. Grimes 	{ "w",		db_write_cmd,		CS_MORE|CS_SET_DOT, 0 },
3485b81b6b3SRodney W. Grimes 	{ "delete",	db_delete_cmd,		0,	0 },
3495b81b6b3SRodney W. Grimes 	{ "d",		db_delete_cmd,		0,	0 },
3505b81b6b3SRodney W. Grimes 	{ "break",	db_breakpoint_cmd,	0,	0 },
3515b81b6b3SRodney W. Grimes 	{ "dwatch",	db_deletewatch_cmd,	0,	0 },
3525b81b6b3SRodney W. Grimes 	{ "watch",	db_watchpoint_cmd,	CS_MORE,0 },
3535b81b6b3SRodney W. Grimes 	{ "step",	db_single_step_cmd,	0,	0 },
3545b81b6b3SRodney W. Grimes 	{ "s",		db_single_step_cmd,	0,	0 },
3555b81b6b3SRodney W. Grimes 	{ "continue",	db_continue_cmd,	0,	0 },
3565b81b6b3SRodney W. Grimes 	{ "c",		db_continue_cmd,	0,	0 },
3575b81b6b3SRodney W. Grimes 	{ "until",	db_trace_until_call_cmd,0,	0 },
3585b81b6b3SRodney W. Grimes 	{ "next",	db_trace_until_matching_cmd,0,	0 },
3595b81b6b3SRodney W. Grimes 	{ "match",	db_trace_until_matching_cmd,0,	0 },
3605b81b6b3SRodney W. Grimes 	{ "trace",	db_stack_trace_cmd,	0,	0 },
3615b81b6b3SRodney W. Grimes 	{ "call",	db_fncall,		CS_OWN,	0 },
3625b81b6b3SRodney W. Grimes 	{ "show",	0,			0,	db_show_cmds },
36351f4a07bSGuido van Rooij 	{ "ps",		db_ps,			0,	0 },
3643eac4884SPoul-Henning Kamp 	{ "panic",	db_panic,		0,	0 },
3655b81b6b3SRodney W. Grimes 	{ (char *)0, }
3665b81b6b3SRodney W. Grimes };
3675b81b6b3SRodney W. Grimes 
3685b81b6b3SRodney W. Grimes struct command	*db_last_command = 0;
3695b81b6b3SRodney W. Grimes 
370b5e8ce9fSBruce Evans #if 0
3715b81b6b3SRodney W. Grimes void
3725b81b6b3SRodney W. Grimes db_help_cmd()
3735b81b6b3SRodney W. Grimes {
3745b81b6b3SRodney W. Grimes 	struct command *cmd = db_command_table;
3755b81b6b3SRodney W. Grimes 
3765b81b6b3SRodney W. Grimes 	while (cmd->name != 0) {
3775b81b6b3SRodney W. Grimes 	    db_printf("%-12s", cmd->name);
3785b81b6b3SRodney W. Grimes 	    db_end_line();
3795b81b6b3SRodney W. Grimes 	    cmd++;
3805b81b6b3SRodney W. Grimes 	}
3815b81b6b3SRodney W. Grimes }
382b5e8ce9fSBruce Evans #endif
3835b81b6b3SRodney W. Grimes 
3845b81b6b3SRodney W. Grimes void
385976794d9SBruce Evans db_panic(dummy1, dummy2, dummy3, dummy4)
386976794d9SBruce Evans 	db_expr_t	dummy1;
387976794d9SBruce Evans 	boolean_t	dummy2;
388976794d9SBruce Evans 	db_expr_t	dummy3;
389976794d9SBruce Evans 	char *		dummy4;
3903eac4884SPoul-Henning Kamp {
391edf8a815SDavid Greenman 	panic("from debugger");
3923eac4884SPoul-Henning Kamp }
3933eac4884SPoul-Henning Kamp 
3943eac4884SPoul-Henning Kamp void
3955b81b6b3SRodney W. Grimes db_command_loop()
3965b81b6b3SRodney W. Grimes {
3975b81b6b3SRodney W. Grimes 	/*
3985b81b6b3SRodney W. Grimes 	 * Initialize 'prev' and 'next' to dot.
3995b81b6b3SRodney W. Grimes 	 */
4005b81b6b3SRodney W. Grimes 	db_prev = db_dot;
4015b81b6b3SRodney W. Grimes 	db_next = db_dot;
4025b81b6b3SRodney W. Grimes 
4035b81b6b3SRodney W. Grimes 	db_cmd_loop_done = 0;
4045b81b6b3SRodney W. Grimes 	while (!db_cmd_loop_done) {
4055b81b6b3SRodney W. Grimes 
4065b81b6b3SRodney W. Grimes 	    (void) setjmp(db_jmpbuf);
4075b81b6b3SRodney W. Grimes 	    if (db_print_position() != 0)
4085b81b6b3SRodney W. Grimes 		db_printf("\n");
4095b81b6b3SRodney W. Grimes 
4105b81b6b3SRodney W. Grimes 	    db_printf("db> ");
4115b81b6b3SRodney W. Grimes 	    (void) db_read_line();
4125b81b6b3SRodney W. Grimes 
4135b81b6b3SRodney W. Grimes 	    db_command(&db_last_command, db_command_table);
4145b81b6b3SRodney W. Grimes 	}
4155b81b6b3SRodney W. Grimes }
4165b81b6b3SRodney W. Grimes 
4175b81b6b3SRodney W. Grimes void
4185b81b6b3SRodney W. Grimes db_error(s)
4195b81b6b3SRodney W. Grimes 	char *s;
4205b81b6b3SRodney W. Grimes {
4215b81b6b3SRodney W. Grimes 	if (s)
4225b81b6b3SRodney W. Grimes 	    db_printf(s);
4235b81b6b3SRodney W. Grimes 	db_flush_lex();
4245b81b6b3SRodney W. Grimes 	longjmp(db_jmpbuf, 1);
4255b81b6b3SRodney W. Grimes }
4265b81b6b3SRodney W. Grimes 
4275b81b6b3SRodney W. Grimes 
4285b81b6b3SRodney W. Grimes /*
4295b81b6b3SRodney W. Grimes  * Call random function:
4305b81b6b3SRodney W. Grimes  * !expr(arg,arg,arg)
4315b81b6b3SRodney W. Grimes  */
4325b81b6b3SRodney W. Grimes void
433976794d9SBruce Evans db_fncall(dummy1, dummy2, dummy3, dummy4)
434976794d9SBruce Evans 	db_expr_t	dummy1;
435976794d9SBruce Evans 	boolean_t	dummy2;
436976794d9SBruce Evans 	db_expr_t	dummy3;
437976794d9SBruce Evans 	char *		dummy4;
4385b81b6b3SRodney W. Grimes {
4395b81b6b3SRodney W. Grimes 	db_expr_t	fn_addr;
440058284fcSBruce Evans #define	MAXARGS		11	/* XXX only 10 are passed */
4415b81b6b3SRodney W. Grimes 	db_expr_t	args[MAXARGS];
4425b81b6b3SRodney W. Grimes 	int		nargs = 0;
4435b81b6b3SRodney W. Grimes 	db_expr_t	retval;
444058284fcSBruce Evans 	typedef db_expr_t fcn_10args_t __P((db_expr_t, db_expr_t, db_expr_t,
445058284fcSBruce Evans 					    db_expr_t, db_expr_t, db_expr_t,
446058284fcSBruce Evans 					    db_expr_t, db_expr_t, db_expr_t,
447058284fcSBruce Evans 					    db_expr_t));
448058284fcSBruce Evans 	fcn_10args_t	*func;
4495b81b6b3SRodney W. Grimes 	int		t;
4505b81b6b3SRodney W. Grimes 
4515b81b6b3SRodney W. Grimes 	if (!db_expression(&fn_addr)) {
4525b81b6b3SRodney W. Grimes 	    db_printf("Bad function\n");
4535b81b6b3SRodney W. Grimes 	    db_flush_lex();
4545b81b6b3SRodney W. Grimes 	    return;
4555b81b6b3SRodney W. Grimes 	}
456058284fcSBruce Evans 	func = (fcn_10args_t *)fn_addr;	/* XXX */
4575b81b6b3SRodney W. Grimes 
4585b81b6b3SRodney W. Grimes 	t = db_read_token();
4595b81b6b3SRodney W. Grimes 	if (t == tLPAREN) {
4605b81b6b3SRodney W. Grimes 	    if (db_expression(&args[0])) {
4615b81b6b3SRodney W. Grimes 		nargs++;
4625b81b6b3SRodney W. Grimes 		while ((t = db_read_token()) == tCOMMA) {
4635b81b6b3SRodney W. Grimes 		    if (nargs == MAXARGS) {
4645b81b6b3SRodney W. Grimes 			db_printf("Too many arguments\n");
4655b81b6b3SRodney W. Grimes 			db_flush_lex();
4665b81b6b3SRodney W. Grimes 			return;
4675b81b6b3SRodney W. Grimes 		    }
4685b81b6b3SRodney W. Grimes 		    if (!db_expression(&args[nargs])) {
4695b81b6b3SRodney W. Grimes 			db_printf("Argument missing\n");
4705b81b6b3SRodney W. Grimes 			db_flush_lex();
4715b81b6b3SRodney W. Grimes 			return;
4725b81b6b3SRodney W. Grimes 		    }
4735b81b6b3SRodney W. Grimes 		    nargs++;
4745b81b6b3SRodney W. Grimes 		}
4755b81b6b3SRodney W. Grimes 		db_unread_token(t);
4765b81b6b3SRodney W. Grimes 	    }
4775b81b6b3SRodney W. Grimes 	    if (db_read_token() != tRPAREN) {
4785b81b6b3SRodney W. Grimes 		db_printf("?\n");
4795b81b6b3SRodney W. Grimes 		db_flush_lex();
4805b81b6b3SRodney W. Grimes 		return;
4815b81b6b3SRodney W. Grimes 	    }
4825b81b6b3SRodney W. Grimes 	}
4835b81b6b3SRodney W. Grimes 	db_skip_to_eol();
4845b81b6b3SRodney W. Grimes 
4855b81b6b3SRodney W. Grimes 	while (nargs < MAXARGS) {
4865b81b6b3SRodney W. Grimes 	    args[nargs++] = 0;
4875b81b6b3SRodney W. Grimes 	}
4885b81b6b3SRodney W. Grimes 
4895b81b6b3SRodney W. Grimes 	retval = (*func)(args[0], args[1], args[2], args[3], args[4],
4905b81b6b3SRodney W. Grimes 			 args[5], args[6], args[7], args[8], args[9] );
4915b81b6b3SRodney W. Grimes 	db_printf("%#n\n", retval);
4925b81b6b3SRodney W. Grimes }
493