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 * 26c3aac50fSPeter Wemm * $FreeBSD$ 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> 380ec81012SJohn Polstra #include <sys/linker_set.h> 39ad146781SPaul Traina #include <sys/reboot.h> 40f540b106SGarrett Wollman #include <sys/systm.h> 41ce9edcf5SPoul-Henning Kamp #include <sys/cons.h> 423000820aSPoul-Henning Kamp 435ccbc3ccSBruce Evans #include <ddb/ddb.h> 44058284fcSBruce Evans #include <ddb/db_command.h> 455b81b6b3SRodney W. Grimes #include <ddb/db_lex.h> 465b81b6b3SRodney W. Grimes #include <ddb/db_output.h> 475b81b6b3SRodney W. Grimes 480b1ae809SJulian Elischer #include <machine/setjmp.h> 495b81b6b3SRodney W. Grimes 505b81b6b3SRodney W. Grimes /* 515b81b6b3SRodney W. Grimes * Exported global variables 525b81b6b3SRodney W. Grimes */ 535b81b6b3SRodney W. Grimes boolean_t db_cmd_loop_done; 545b81b6b3SRodney W. Grimes db_addr_t db_dot; 556337f4efSBruce Evans jmp_buf db_jmpbuf; 565b81b6b3SRodney W. Grimes db_addr_t db_last_addr; 575b81b6b3SRodney W. Grimes db_addr_t db_prev; 585b81b6b3SRodney W. Grimes db_addr_t db_next; 59f41325dbSPeter Wemm 60f41325dbSPeter Wemm SET_DECLARE(db_cmd_set, struct command); 61f41325dbSPeter Wemm SET_DECLARE(db_show_cmd_set, struct command); 625b81b6b3SRodney W. Grimes 63f73a856dSPoul-Henning Kamp static db_cmdfcn_t db_fncall; 64ad146781SPaul Traina static db_cmdfcn_t db_gdb; 65ad146781SPaul Traina 666337f4efSBruce Evans /* XXX this is actually forward-static. */ 676337f4efSBruce Evans extern struct command db_show_cmds[]; 686337f4efSBruce Evans 695b81b6b3SRodney W. Grimes /* 705b81b6b3SRodney W. Grimes * if 'ed' style: 'dot' is set at start of last item printed, 715b81b6b3SRodney W. Grimes * and '+' points to next line. 725b81b6b3SRodney W. Grimes * Otherwise: 'dot' points to next item, '..' points to last. 735b81b6b3SRodney W. Grimes */ 74f73a856dSPoul-Henning Kamp static boolean_t db_ed_style = TRUE; 755b81b6b3SRodney W. Grimes 765b81b6b3SRodney W. Grimes /* 775b81b6b3SRodney W. Grimes * Utility routine - discard tokens through end-of-line. 785b81b6b3SRodney W. Grimes */ 795b81b6b3SRodney W. Grimes void 805b81b6b3SRodney W. Grimes db_skip_to_eol() 815b81b6b3SRodney W. Grimes { 825b81b6b3SRodney W. Grimes int t; 835b81b6b3SRodney W. Grimes do { 845b81b6b3SRodney W. Grimes t = db_read_token(); 855b81b6b3SRodney W. Grimes } while (t != tEOL); 865b81b6b3SRodney W. Grimes } 875b81b6b3SRodney W. Grimes 885b81b6b3SRodney W. Grimes /* 895b81b6b3SRodney W. Grimes * Results of command search. 905b81b6b3SRodney W. Grimes */ 915b81b6b3SRodney W. Grimes #define CMD_UNIQUE 0 925b81b6b3SRodney W. Grimes #define CMD_FOUND 1 935b81b6b3SRodney W. Grimes #define CMD_NONE 2 945b81b6b3SRodney W. Grimes #define CMD_AMBIGUOUS 3 955b81b6b3SRodney W. Grimes #define CMD_HELP 4 965b81b6b3SRodney W. Grimes 976337f4efSBruce Evans static void db_cmd_list __P((struct command *table, 98f41325dbSPeter Wemm struct command **aux_tablep, 99f41325dbSPeter Wemm struct command **aux_tablep_end)); 100f73a856dSPoul-Henning Kamp static int db_cmd_search __P((char *name, struct command *table, 1016337f4efSBruce Evans struct command **aux_tablep, 102f41325dbSPeter Wemm struct command **aux_tablep_end, 103058284fcSBruce Evans struct command **cmdp)); 104f73a856dSPoul-Henning Kamp static void db_command __P((struct command **last_cmdp, 1056337f4efSBruce Evans struct command *cmd_table, 106f41325dbSPeter Wemm struct command **aux_cmd_tablep, 107f41325dbSPeter Wemm struct command **aux_cmd_tablep_end)); 108058284fcSBruce Evans 1095b81b6b3SRodney W. Grimes /* 1105b81b6b3SRodney W. Grimes * Search for command prefix. 1115b81b6b3SRodney W. Grimes */ 112f73a856dSPoul-Henning Kamp static int 113f41325dbSPeter Wemm db_cmd_search(name, table, aux_tablep, aux_tablep_end, cmdp) 1145b81b6b3SRodney W. Grimes char * name; 1155b81b6b3SRodney W. Grimes struct command *table; 1166337f4efSBruce Evans struct command **aux_tablep; 117f41325dbSPeter Wemm struct command **aux_tablep_end; 1185b81b6b3SRodney W. Grimes struct command **cmdp; /* out */ 1195b81b6b3SRodney W. Grimes { 1205b81b6b3SRodney W. Grimes struct command *cmd; 1216337f4efSBruce Evans struct command **aux_cmdp; 1225b81b6b3SRodney W. Grimes int result = CMD_NONE; 1235b81b6b3SRodney W. Grimes 1245b81b6b3SRodney W. Grimes for (cmd = table; cmd->name != 0; cmd++) { 1255b81b6b3SRodney W. Grimes register char *lp; 1265b81b6b3SRodney W. Grimes register char *rp; 1275b81b6b3SRodney W. Grimes register int c; 1285b81b6b3SRodney W. Grimes 1295b81b6b3SRodney W. Grimes lp = name; 1305b81b6b3SRodney W. Grimes rp = cmd->name; 1315b81b6b3SRodney W. Grimes while ((c = *lp) == *rp) { 1325b81b6b3SRodney W. Grimes if (c == 0) { 1335b81b6b3SRodney W. Grimes /* complete match */ 1345b81b6b3SRodney W. Grimes *cmdp = cmd; 1355b81b6b3SRodney W. Grimes return (CMD_UNIQUE); 1365b81b6b3SRodney W. Grimes } 1375b81b6b3SRodney W. Grimes lp++; 1385b81b6b3SRodney W. Grimes rp++; 1395b81b6b3SRodney W. Grimes } 1405b81b6b3SRodney W. Grimes if (c == 0) { 1415b81b6b3SRodney W. Grimes /* end of name, not end of command - 1425b81b6b3SRodney W. Grimes partial match */ 1435b81b6b3SRodney W. Grimes if (result == CMD_FOUND) { 1445b81b6b3SRodney W. Grimes result = CMD_AMBIGUOUS; 1455b81b6b3SRodney W. Grimes /* but keep looking for a full match - 1465b81b6b3SRodney W. Grimes this lets us match single letters */ 1475b81b6b3SRodney W. Grimes } 1485b81b6b3SRodney W. Grimes else { 1495b81b6b3SRodney W. Grimes *cmdp = cmd; 1505b81b6b3SRodney W. Grimes result = CMD_FOUND; 1515b81b6b3SRodney W. Grimes } 1525b81b6b3SRodney W. Grimes } 1535b81b6b3SRodney W. Grimes } 1546337f4efSBruce Evans if (result == CMD_NONE && aux_tablep != 0) 1556337f4efSBruce Evans /* XXX repeat too much code. */ 156f41325dbSPeter Wemm for (aux_cmdp = aux_tablep; aux_cmdp < aux_tablep_end; aux_cmdp++) { 1576337f4efSBruce Evans register char *lp; 1586337f4efSBruce Evans register char *rp; 1596337f4efSBruce Evans register int c; 1606337f4efSBruce Evans 1616337f4efSBruce Evans lp = name; 1626337f4efSBruce Evans rp = (*aux_cmdp)->name; 1636337f4efSBruce Evans while ((c = *lp) == *rp) { 1646337f4efSBruce Evans if (c == 0) { 1656337f4efSBruce Evans /* complete match */ 1666337f4efSBruce Evans *cmdp = *aux_cmdp; 1676337f4efSBruce Evans return (CMD_UNIQUE); 1686337f4efSBruce Evans } 1696337f4efSBruce Evans lp++; 1706337f4efSBruce Evans rp++; 1716337f4efSBruce Evans } 1726337f4efSBruce Evans if (c == 0) { 1736337f4efSBruce Evans /* end of name, not end of command - 1746337f4efSBruce Evans partial match */ 1756337f4efSBruce Evans if (result == CMD_FOUND) { 1766337f4efSBruce Evans result = CMD_AMBIGUOUS; 1776337f4efSBruce Evans /* but keep looking for a full match - 1786337f4efSBruce Evans this lets us match single letters */ 1796337f4efSBruce Evans } 1806337f4efSBruce Evans else { 1816337f4efSBruce Evans *cmdp = *aux_cmdp; 1826337f4efSBruce Evans result = CMD_FOUND; 1836337f4efSBruce Evans } 1846337f4efSBruce Evans } 1856337f4efSBruce Evans } 1865b81b6b3SRodney W. Grimes if (result == CMD_NONE) { 1875b81b6b3SRodney W. Grimes /* check for 'help' */ 1885b81b6b3SRodney W. Grimes if (name[0] == 'h' && name[1] == 'e' 1895b81b6b3SRodney W. Grimes && name[2] == 'l' && name[3] == 'p') 1905b81b6b3SRodney W. Grimes result = CMD_HELP; 1915b81b6b3SRodney W. Grimes } 1925b81b6b3SRodney W. Grimes return (result); 1935b81b6b3SRodney W. Grimes } 1945b81b6b3SRodney W. Grimes 195f73a856dSPoul-Henning Kamp static void 196f41325dbSPeter Wemm db_cmd_list(table, aux_tablep, aux_tablep_end) 1975b81b6b3SRodney W. Grimes struct command *table; 1986337f4efSBruce Evans struct command **aux_tablep; 199f41325dbSPeter Wemm struct command **aux_tablep_end; 2005b81b6b3SRodney W. Grimes { 2015b81b6b3SRodney W. Grimes register struct command *cmd; 2026337f4efSBruce Evans register struct command **aux_cmdp; 2035b81b6b3SRodney W. Grimes 2045b81b6b3SRodney W. Grimes for (cmd = table; cmd->name != 0; cmd++) { 2055b81b6b3SRodney W. Grimes db_printf("%-12s", cmd->name); 2065b81b6b3SRodney W. Grimes db_end_line(); 2075b81b6b3SRodney W. Grimes } 2086337f4efSBruce Evans if (aux_tablep == 0) 2096337f4efSBruce Evans return; 210f41325dbSPeter Wemm for (aux_cmdp = aux_tablep; aux_cmdp < aux_tablep_end; aux_cmdp++) { 2116337f4efSBruce Evans db_printf("%-12s", (*aux_cmdp)->name); 2126337f4efSBruce Evans db_end_line(); 2136337f4efSBruce Evans } 2145b81b6b3SRodney W. Grimes } 2155b81b6b3SRodney W. Grimes 216f73a856dSPoul-Henning Kamp static void 217f41325dbSPeter Wemm db_command(last_cmdp, cmd_table, aux_cmd_tablep, aux_cmd_tablep_end) 2185b81b6b3SRodney W. Grimes struct command **last_cmdp; /* IN_OUT */ 2195b81b6b3SRodney W. Grimes struct command *cmd_table; 2206337f4efSBruce Evans struct command **aux_cmd_tablep; 221f41325dbSPeter Wemm struct command **aux_cmd_tablep_end; 2225b81b6b3SRodney W. Grimes { 2235b81b6b3SRodney W. Grimes struct command *cmd; 2245b81b6b3SRodney W. Grimes int t; 2255b81b6b3SRodney W. Grimes char modif[TOK_STRING_SIZE]; 2265b81b6b3SRodney W. Grimes db_expr_t addr, count; 227381fe1aaSGarrett Wollman boolean_t have_addr = FALSE; 2285b81b6b3SRodney W. Grimes int result; 2295b81b6b3SRodney W. Grimes 2305b81b6b3SRodney W. Grimes t = db_read_token(); 2315b81b6b3SRodney W. Grimes if (t == tEOL) { 2325b81b6b3SRodney W. Grimes /* empty line repeats last command, at 'next' */ 2335b81b6b3SRodney W. Grimes cmd = *last_cmdp; 2345b81b6b3SRodney W. Grimes addr = (db_expr_t)db_next; 2355b81b6b3SRodney W. Grimes have_addr = FALSE; 2365b81b6b3SRodney W. Grimes count = 1; 2375b81b6b3SRodney W. Grimes modif[0] = '\0'; 2385b81b6b3SRodney W. Grimes } 2395b81b6b3SRodney W. Grimes else if (t == tEXCL) { 240976794d9SBruce Evans db_fncall((db_expr_t)0, (boolean_t)0, (db_expr_t)0, (char *)0); 2415b81b6b3SRodney W. Grimes return; 2425b81b6b3SRodney W. Grimes } 2435b81b6b3SRodney W. Grimes else if (t != tIDENT) { 2445b81b6b3SRodney W. Grimes db_printf("?\n"); 2455b81b6b3SRodney W. Grimes db_flush_lex(); 2465b81b6b3SRodney W. Grimes return; 2475b81b6b3SRodney W. Grimes } 2485b81b6b3SRodney W. Grimes else { 2495b81b6b3SRodney W. Grimes /* 2505b81b6b3SRodney W. Grimes * Search for command 2515b81b6b3SRodney W. Grimes */ 2525b81b6b3SRodney W. Grimes while (cmd_table) { 2535b81b6b3SRodney W. Grimes result = db_cmd_search(db_tok_string, 2545b81b6b3SRodney W. Grimes cmd_table, 2556337f4efSBruce Evans aux_cmd_tablep, 256f41325dbSPeter Wemm aux_cmd_tablep_end, 2575b81b6b3SRodney W. Grimes &cmd); 2585b81b6b3SRodney W. Grimes switch (result) { 2595b81b6b3SRodney W. Grimes case CMD_NONE: 2605b81b6b3SRodney W. Grimes db_printf("No such command\n"); 2615b81b6b3SRodney W. Grimes db_flush_lex(); 2625b81b6b3SRodney W. Grimes return; 2635b81b6b3SRodney W. Grimes case CMD_AMBIGUOUS: 2645b81b6b3SRodney W. Grimes db_printf("Ambiguous\n"); 2655b81b6b3SRodney W. Grimes db_flush_lex(); 2665b81b6b3SRodney W. Grimes return; 2675b81b6b3SRodney W. Grimes case CMD_HELP: 268f41325dbSPeter Wemm db_cmd_list(cmd_table, aux_cmd_tablep, aux_cmd_tablep_end); 2695b81b6b3SRodney W. Grimes db_flush_lex(); 2705b81b6b3SRodney W. Grimes return; 2715b81b6b3SRodney W. Grimes default: 2725b81b6b3SRodney W. Grimes break; 2735b81b6b3SRodney W. Grimes } 2745b81b6b3SRodney W. Grimes if ((cmd_table = cmd->more) != 0) { 2756337f4efSBruce Evans /* XXX usually no more aux's. */ 2766337f4efSBruce Evans aux_cmd_tablep = 0; 2776337f4efSBruce Evans if (cmd_table == db_show_cmds) 278f41325dbSPeter Wemm aux_cmd_tablep = SET_BEGIN(db_show_cmd_set); 279f41325dbSPeter Wemm aux_cmd_tablep_end = SET_LIMIT(db_show_cmd_set); 2806337f4efSBruce Evans 2815b81b6b3SRodney W. Grimes t = db_read_token(); 2825b81b6b3SRodney W. Grimes if (t != tIDENT) { 283f41325dbSPeter Wemm db_cmd_list(cmd_table, aux_cmd_tablep, aux_cmd_tablep_end); 2845b81b6b3SRodney W. Grimes db_flush_lex(); 2855b81b6b3SRodney W. Grimes return; 2865b81b6b3SRodney W. Grimes } 2875b81b6b3SRodney W. Grimes } 2885b81b6b3SRodney W. Grimes } 2895b81b6b3SRodney W. Grimes 2905b81b6b3SRodney W. Grimes if ((cmd->flag & CS_OWN) == 0) { 2915b81b6b3SRodney W. Grimes /* 2925b81b6b3SRodney W. Grimes * Standard syntax: 2935b81b6b3SRodney W. Grimes * command [/modifier] [addr] [,count] 2945b81b6b3SRodney W. Grimes */ 2955b81b6b3SRodney W. Grimes t = db_read_token(); 2965b81b6b3SRodney W. Grimes if (t == tSLASH) { 2975b81b6b3SRodney W. Grimes t = db_read_token(); 2985b81b6b3SRodney W. Grimes if (t != tIDENT) { 2995b81b6b3SRodney W. Grimes db_printf("Bad modifier\n"); 3005b81b6b3SRodney W. Grimes db_flush_lex(); 3015b81b6b3SRodney W. Grimes return; 3025b81b6b3SRodney W. Grimes } 3035b81b6b3SRodney W. Grimes db_strcpy(modif, db_tok_string); 3045b81b6b3SRodney W. Grimes } 3055b81b6b3SRodney W. Grimes else { 3065b81b6b3SRodney W. Grimes db_unread_token(t); 3075b81b6b3SRodney W. Grimes modif[0] = '\0'; 3085b81b6b3SRodney W. Grimes } 3095b81b6b3SRodney W. Grimes 3105b81b6b3SRodney W. Grimes if (db_expression(&addr)) { 3115b81b6b3SRodney W. Grimes db_dot = (db_addr_t) addr; 3125b81b6b3SRodney W. Grimes db_last_addr = db_dot; 3135b81b6b3SRodney W. Grimes have_addr = TRUE; 3145b81b6b3SRodney W. Grimes } 3155b81b6b3SRodney W. Grimes else { 3165b81b6b3SRodney W. Grimes addr = (db_expr_t) db_dot; 3175b81b6b3SRodney W. Grimes have_addr = FALSE; 3185b81b6b3SRodney W. Grimes } 3195b81b6b3SRodney W. Grimes t = db_read_token(); 3205b81b6b3SRodney W. Grimes if (t == tCOMMA) { 3215b81b6b3SRodney W. Grimes if (!db_expression(&count)) { 3225b81b6b3SRodney W. Grimes db_printf("Count missing\n"); 3235b81b6b3SRodney W. Grimes db_flush_lex(); 3245b81b6b3SRodney W. Grimes return; 3255b81b6b3SRodney W. Grimes } 3265b81b6b3SRodney W. Grimes } 3275b81b6b3SRodney W. Grimes else { 3285b81b6b3SRodney W. Grimes db_unread_token(t); 3295b81b6b3SRodney W. Grimes count = -1; 3305b81b6b3SRodney W. Grimes } 3315b81b6b3SRodney W. Grimes if ((cmd->flag & CS_MORE) == 0) { 3325b81b6b3SRodney W. Grimes db_skip_to_eol(); 3335b81b6b3SRodney W. Grimes } 3345b81b6b3SRodney W. Grimes } 3355b81b6b3SRodney W. Grimes } 3365b81b6b3SRodney W. Grimes *last_cmdp = cmd; 3375b81b6b3SRodney W. Grimes if (cmd != 0) { 3385b81b6b3SRodney W. Grimes /* 3395b81b6b3SRodney W. Grimes * Execute the command. 3405b81b6b3SRodney W. Grimes */ 3415b81b6b3SRodney W. Grimes (*cmd->fcn)(addr, have_addr, count, modif); 3425b81b6b3SRodney W. Grimes 3435b81b6b3SRodney W. Grimes if (cmd->flag & CS_SET_DOT) { 3445b81b6b3SRodney W. Grimes /* 3455b81b6b3SRodney W. Grimes * If command changes dot, set dot to 3465b81b6b3SRodney W. Grimes * previous address displayed (if 'ed' style). 3475b81b6b3SRodney W. Grimes */ 3485b81b6b3SRodney W. Grimes if (db_ed_style) { 3495b81b6b3SRodney W. Grimes db_dot = db_prev; 3505b81b6b3SRodney W. Grimes } 3515b81b6b3SRodney W. Grimes else { 3525b81b6b3SRodney W. Grimes db_dot = db_next; 3535b81b6b3SRodney W. Grimes } 3545b81b6b3SRodney W. Grimes } 3555b81b6b3SRodney W. Grimes else { 3565b81b6b3SRodney W. Grimes /* 3575b81b6b3SRodney W. Grimes * If command does not change dot, 3585b81b6b3SRodney W. Grimes * set 'next' location to be the same. 3595b81b6b3SRodney W. Grimes */ 3605b81b6b3SRodney W. Grimes db_next = db_dot; 3615b81b6b3SRodney W. Grimes } 3625b81b6b3SRodney W. Grimes } 3635b81b6b3SRodney W. Grimes } 3645b81b6b3SRodney W. Grimes 3655b81b6b3SRodney W. Grimes /* 3665b81b6b3SRodney W. Grimes * 'show' commands 3675b81b6b3SRodney W. Grimes */ 368f23b4c91SGarrett Wollman 369f73a856dSPoul-Henning Kamp static struct command db_show_all_cmds[] = { 3705b81b6b3SRodney W. Grimes #if 0 3715b81b6b3SRodney W. Grimes { "threads", db_show_all_threads, 0, 0 }, 37226f9a767SRodney W. Grimes #endif 3738a129caeSDavid Greenman { "procs", db_ps, 0, 0 }, 3745b81b6b3SRodney W. Grimes { (char *)0 } 3755b81b6b3SRodney W. Grimes }; 3765b81b6b3SRodney W. Grimes 377f73a856dSPoul-Henning Kamp static struct command db_show_cmds[] = { 3785b81b6b3SRodney W. Grimes { "all", 0, 0, db_show_all_cmds }, 3795b81b6b3SRodney W. Grimes { "registers", db_show_regs, 0, 0 }, 3805b81b6b3SRodney W. Grimes { "breaks", db_listbreak_cmd, 0, 0 }, 3815b81b6b3SRodney W. Grimes #if 0 3825b81b6b3SRodney W. Grimes { "thread", db_show_one_thread, 0, 0 }, 3835b81b6b3SRodney W. Grimes #endif 3845b81b6b3SRodney W. Grimes #if 0 3855b81b6b3SRodney W. Grimes { "port", ipc_port_print, 0, 0 }, 3865b81b6b3SRodney W. Grimes #endif 3875b81b6b3SRodney W. Grimes { (char *)0, } 3885b81b6b3SRodney W. Grimes }; 3895b81b6b3SRodney W. Grimes 390f73a856dSPoul-Henning Kamp static struct command db_command_table[] = { 3915b81b6b3SRodney W. Grimes { "print", db_print_cmd, 0, 0 }, 39223898040SJoerg Wunsch { "p", db_print_cmd, 0, 0 }, 3935b81b6b3SRodney W. Grimes { "examine", db_examine_cmd, CS_SET_DOT, 0 }, 3945b81b6b3SRodney W. Grimes { "x", db_examine_cmd, CS_SET_DOT, 0 }, 3955b81b6b3SRodney W. Grimes { "search", db_search_cmd, CS_OWN|CS_SET_DOT, 0 }, 3965b81b6b3SRodney W. Grimes { "set", db_set_cmd, CS_OWN, 0 }, 3975b81b6b3SRodney W. Grimes { "write", db_write_cmd, CS_MORE|CS_SET_DOT, 0 }, 3985b81b6b3SRodney W. Grimes { "w", db_write_cmd, CS_MORE|CS_SET_DOT, 0 }, 3995b81b6b3SRodney W. Grimes { "delete", db_delete_cmd, 0, 0 }, 4005b81b6b3SRodney W. Grimes { "d", db_delete_cmd, 0, 0 }, 4015b81b6b3SRodney W. Grimes { "break", db_breakpoint_cmd, 0, 0 }, 4025b81b6b3SRodney W. Grimes { "dwatch", db_deletewatch_cmd, 0, 0 }, 4035b81b6b3SRodney W. Grimes { "watch", db_watchpoint_cmd, CS_MORE,0 }, 4045b81b6b3SRodney W. Grimes { "step", db_single_step_cmd, 0, 0 }, 4055b81b6b3SRodney W. Grimes { "s", db_single_step_cmd, 0, 0 }, 4065b81b6b3SRodney W. Grimes { "continue", db_continue_cmd, 0, 0 }, 4075b81b6b3SRodney W. Grimes { "c", db_continue_cmd, 0, 0 }, 4085b81b6b3SRodney W. Grimes { "until", db_trace_until_call_cmd,0, 0 }, 4095b81b6b3SRodney W. Grimes { "next", db_trace_until_matching_cmd,0, 0 }, 4105b81b6b3SRodney W. Grimes { "match", db_trace_until_matching_cmd,0, 0 }, 4115b81b6b3SRodney W. Grimes { "trace", db_stack_trace_cmd, 0, 0 }, 4125b81b6b3SRodney W. Grimes { "call", db_fncall, CS_OWN, 0 }, 4135b81b6b3SRodney W. Grimes { "show", 0, 0, db_show_cmds }, 41451f4a07bSGuido van Rooij { "ps", db_ps, 0, 0 }, 415ad146781SPaul Traina { "gdb", db_gdb, 0, 0 }, 4165b81b6b3SRodney W. Grimes { (char *)0, } 4175b81b6b3SRodney W. Grimes }; 4185b81b6b3SRodney W. Grimes 419f73a856dSPoul-Henning Kamp static struct command *db_last_command = 0; 4205b81b6b3SRodney W. Grimes 421b5e8ce9fSBruce Evans #if 0 4225b81b6b3SRodney W. Grimes void 4235b81b6b3SRodney W. Grimes db_help_cmd() 4245b81b6b3SRodney W. Grimes { 4255b81b6b3SRodney W. Grimes struct command *cmd = db_command_table; 4265b81b6b3SRodney W. Grimes 4275b81b6b3SRodney W. Grimes while (cmd->name != 0) { 4285b81b6b3SRodney W. Grimes db_printf("%-12s", cmd->name); 4295b81b6b3SRodney W. Grimes db_end_line(); 4305b81b6b3SRodney W. Grimes cmd++; 4315b81b6b3SRodney W. Grimes } 4325b81b6b3SRodney W. Grimes } 433b5e8ce9fSBruce Evans #endif 4345b81b6b3SRodney W. Grimes 435b7aa38c1SBruce Evans /* 436b7aa38c1SBruce Evans * At least one non-optional command must be implemented using 437b7aa38c1SBruce Evans * DB_COMMAND() so that db_cmd_set gets created. Here is one. 438b7aa38c1SBruce Evans */ 439b7aa38c1SBruce Evans DB_COMMAND(panic, db_panic) 4403eac4884SPoul-Henning Kamp { 441edf8a815SDavid Greenman panic("from debugger"); 4423eac4884SPoul-Henning Kamp } 4433eac4884SPoul-Henning Kamp 4443eac4884SPoul-Henning Kamp void 4455b81b6b3SRodney W. Grimes db_command_loop() 4465b81b6b3SRodney W. Grimes { 4475b81b6b3SRodney W. Grimes /* 4485b81b6b3SRodney W. Grimes * Initialize 'prev' and 'next' to dot. 4495b81b6b3SRodney W. Grimes */ 4505b81b6b3SRodney W. Grimes db_prev = db_dot; 4515b81b6b3SRodney W. Grimes db_next = db_dot; 4525b81b6b3SRodney W. Grimes 4535b81b6b3SRodney W. Grimes db_cmd_loop_done = 0; 4545b81b6b3SRodney W. Grimes while (!db_cmd_loop_done) { 4555b81b6b3SRodney W. Grimes 4565b81b6b3SRodney W. Grimes (void) setjmp(db_jmpbuf); 4575b81b6b3SRodney W. Grimes if (db_print_position() != 0) 4585b81b6b3SRodney W. Grimes db_printf("\n"); 4595b81b6b3SRodney W. Grimes 4605b81b6b3SRodney W. Grimes db_printf("db> "); 4615b81b6b3SRodney W. Grimes (void) db_read_line(); 4625b81b6b3SRodney W. Grimes 4636337f4efSBruce Evans db_command(&db_last_command, db_command_table, 464f41325dbSPeter Wemm SET_BEGIN(db_cmd_set), SET_LIMIT(db_cmd_set)); 4655b81b6b3SRodney W. Grimes } 4665b81b6b3SRodney W. Grimes } 4675b81b6b3SRodney W. Grimes 4685b81b6b3SRodney W. Grimes void 4695b81b6b3SRodney W. Grimes db_error(s) 4705b81b6b3SRodney W. Grimes char *s; 4715b81b6b3SRodney W. Grimes { 4725b81b6b3SRodney W. Grimes if (s) 4735b81b6b3SRodney W. Grimes db_printf(s); 4745b81b6b3SRodney W. Grimes db_flush_lex(); 4755b81b6b3SRodney W. Grimes longjmp(db_jmpbuf, 1); 4765b81b6b3SRodney W. Grimes } 4775b81b6b3SRodney W. Grimes 4785b81b6b3SRodney W. Grimes 4795b81b6b3SRodney W. Grimes /* 4805b81b6b3SRodney W. Grimes * Call random function: 4815b81b6b3SRodney W. Grimes * !expr(arg,arg,arg) 4825b81b6b3SRodney W. Grimes */ 483f73a856dSPoul-Henning Kamp static void 484976794d9SBruce Evans db_fncall(dummy1, dummy2, dummy3, dummy4) 485976794d9SBruce Evans db_expr_t dummy1; 486976794d9SBruce Evans boolean_t dummy2; 487976794d9SBruce Evans db_expr_t dummy3; 488976794d9SBruce Evans char * dummy4; 4895b81b6b3SRodney W. Grimes { 4905b81b6b3SRodney W. Grimes db_expr_t fn_addr; 491058284fcSBruce Evans #define MAXARGS 11 /* XXX only 10 are passed */ 4925b81b6b3SRodney W. Grimes db_expr_t args[MAXARGS]; 4935b81b6b3SRodney W. Grimes int nargs = 0; 4945b81b6b3SRodney W. Grimes db_expr_t retval; 495058284fcSBruce Evans typedef db_expr_t fcn_10args_t __P((db_expr_t, db_expr_t, db_expr_t, 496058284fcSBruce Evans db_expr_t, db_expr_t, db_expr_t, 497058284fcSBruce Evans db_expr_t, db_expr_t, db_expr_t, 498058284fcSBruce Evans db_expr_t)); 499058284fcSBruce Evans fcn_10args_t *func; 5005b81b6b3SRodney W. Grimes int t; 5015b81b6b3SRodney W. Grimes 5025b81b6b3SRodney W. Grimes if (!db_expression(&fn_addr)) { 5035b81b6b3SRodney W. Grimes db_printf("Bad function\n"); 5045b81b6b3SRodney W. Grimes db_flush_lex(); 5055b81b6b3SRodney W. Grimes return; 5065b81b6b3SRodney W. Grimes } 507058284fcSBruce Evans func = (fcn_10args_t *)fn_addr; /* XXX */ 5085b81b6b3SRodney W. Grimes 5095b81b6b3SRodney W. Grimes t = db_read_token(); 5105b81b6b3SRodney W. Grimes if (t == tLPAREN) { 5115b81b6b3SRodney W. Grimes if (db_expression(&args[0])) { 5125b81b6b3SRodney W. Grimes nargs++; 5135b81b6b3SRodney W. Grimes while ((t = db_read_token()) == tCOMMA) { 5145b81b6b3SRodney W. Grimes if (nargs == MAXARGS) { 5155b81b6b3SRodney W. Grimes db_printf("Too many arguments\n"); 5165b81b6b3SRodney W. Grimes db_flush_lex(); 5175b81b6b3SRodney W. Grimes return; 5185b81b6b3SRodney W. Grimes } 5195b81b6b3SRodney W. Grimes if (!db_expression(&args[nargs])) { 5205b81b6b3SRodney W. Grimes db_printf("Argument missing\n"); 5215b81b6b3SRodney W. Grimes db_flush_lex(); 5225b81b6b3SRodney W. Grimes return; 5235b81b6b3SRodney W. Grimes } 5245b81b6b3SRodney W. Grimes nargs++; 5255b81b6b3SRodney W. Grimes } 5265b81b6b3SRodney W. Grimes db_unread_token(t); 5275b81b6b3SRodney W. Grimes } 5285b81b6b3SRodney W. Grimes if (db_read_token() != tRPAREN) { 5295b81b6b3SRodney W. Grimes db_printf("?\n"); 5305b81b6b3SRodney W. Grimes db_flush_lex(); 5315b81b6b3SRodney W. Grimes return; 5325b81b6b3SRodney W. Grimes } 5335b81b6b3SRodney W. Grimes } 5345b81b6b3SRodney W. Grimes db_skip_to_eol(); 5355b81b6b3SRodney W. Grimes 5365b81b6b3SRodney W. Grimes while (nargs < MAXARGS) { 5375b81b6b3SRodney W. Grimes args[nargs++] = 0; 5385b81b6b3SRodney W. Grimes } 5395b81b6b3SRodney W. Grimes 5405b81b6b3SRodney W. Grimes retval = (*func)(args[0], args[1], args[2], args[3], args[4], 5415b81b6b3SRodney W. Grimes args[5], args[6], args[7], args[8], args[9] ); 5421c6989faSPeter Wemm db_printf("%#lr\n", (long)retval); 5435b81b6b3SRodney W. Grimes } 544ad146781SPaul Traina 545ad146781SPaul Traina /* Enter GDB remote protocol debugger on the next trap. */ 546ad146781SPaul Traina 5473000820aSPoul-Henning Kamp dev_t gdbdev = NODEV; 5483000820aSPoul-Henning Kamp cn_getc_t *gdb_getc; 5493000820aSPoul-Henning Kamp cn_putc_t *gdb_putc; 5505c92a5b3SKirk McKusick 551ad146781SPaul Traina static void 552ad146781SPaul Traina db_gdb (dummy1, dummy2, dummy3, dummy4) 553ad146781SPaul Traina db_expr_t dummy1; 554ad146781SPaul Traina boolean_t dummy2; 555ad146781SPaul Traina db_expr_t dummy3; 556ad146781SPaul Traina char * dummy4; 557ad146781SPaul Traina { 5585c92a5b3SKirk McKusick 5593000820aSPoul-Henning Kamp if (gdbdev == NODEV) { 5605c92a5b3SKirk McKusick db_printf("No gdb port enabled. Set flag 0x80 on desired port\n"); 5615c92a5b3SKirk McKusick db_printf("in your configuration file (currently sio only).\n"); 5625c92a5b3SKirk McKusick return; 5635c92a5b3SKirk McKusick } 564ad146781SPaul Traina boothowto ^= RB_GDB; 565ad146781SPaul Traina 566ad146781SPaul Traina db_printf("Next trap will enter %s\n", 567ad146781SPaul Traina boothowto & RB_GDB ? "GDB remote protocol mode" 568ad146781SPaul Traina : "DDB debugger"); 569ad146781SPaul Traina } 570