db_command.c revision 150819
1139747Simp/*- 24Srgrimes * Mach Operating System 34Srgrimes * Copyright (c) 1991,1990 Carnegie Mellon University 44Srgrimes * All Rights Reserved. 58876Srgrimes * 64Srgrimes * Permission to use, copy, modify and distribute this software and its 74Srgrimes * documentation is hereby granted, provided that both the copyright 84Srgrimes * notice and this permission notice appear in all copies of the 94Srgrimes * software, derivative works or modified versions, and any portions 104Srgrimes * thereof, and that both notices appear in supporting documentation. 118876Srgrimes * 128876Srgrimes * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS 134Srgrimes * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 144Srgrimes * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 158876Srgrimes * 164Srgrimes * Carnegie Mellon requests users of this software to return to 178876Srgrimes * 184Srgrimes * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 194Srgrimes * School of Computer Science 204Srgrimes * Carnegie Mellon University 214Srgrimes * Pittsburgh PA 15213-3890 228876Srgrimes * 234Srgrimes * any improvements or extensions that they make and grant Carnegie the 244Srgrimes * rights to redistribute these changes. 254Srgrimes */ 264Srgrimes/* 274Srgrimes * Author: David B. Golub, Carnegie Mellon University 284Srgrimes * Date: 7/90 294Srgrimes */ 304Srgrimes/* 314Srgrimes * Command dispatcher. 324Srgrimes */ 33116176Sobrien 34116176Sobrien#include <sys/cdefs.h> 35116176Sobrien__FBSDID("$FreeBSD: head/sys/ddb/db_command.c 150819 2005-10-02 11:41:12Z rwatson $"); 36116176Sobrien 372056Swollman#include <sys/param.h> 3842654Sjdp#include <sys/linker_set.h> 3986998Sdd#include <sys/lock.h> 40131952Smarcel#include <sys/kdb.h> 4186998Sdd#include <sys/mutex.h> 4286998Sdd#include <sys/proc.h> 4317848Spst#include <sys/reboot.h> 4486998Sdd#include <sys/signalvar.h> 452056Swollman#include <sys/systm.h> 4649558Sphk#include <sys/cons.h> 47126399Sphk#include <sys/watchdog.h> 4812734Sbde 492056Swollman#include <ddb/ddb.h> 5012473Sbde#include <ddb/db_command.h> 514Srgrimes#include <ddb/db_lex.h> 524Srgrimes#include <ddb/db_output.h> 534Srgrimes 54118990Smarcel#include <machine/cpu.h> 5579418Sjulian#include <machine/setjmp.h> 564Srgrimes 574Srgrimes/* 584Srgrimes * Exported global variables 594Srgrimes */ 604Srgrimesboolean_t db_cmd_loop_done; 6118296Sbdedb_addr_t db_dot; 624Srgrimesdb_addr_t db_last_addr; 634Srgrimesdb_addr_t db_prev; 644Srgrimesdb_addr_t db_next; 654Srgrimes 6678161SpeterSET_DECLARE(db_cmd_set, struct command); 6778161SpeterSET_DECLARE(db_show_cmd_set, struct command); 6878161Speter 6912515Sphkstatic db_cmdfcn_t db_fncall; 70132002Smarcelstatic db_cmdfcn_t db_gdb; 7186998Sddstatic db_cmdfcn_t db_kill; 7285944Speterstatic db_cmdfcn_t db_reset; 73132482Smarcelstatic db_cmdfcn_t db_stack_trace; 74150819Srwatsonstatic db_cmdfcn_t db_stack_trace_all; 75126399Sphkstatic db_cmdfcn_t db_watchdog; 7617848Spst 77148919Sobrien/* 78148919Sobrien * 'show' commands 79148919Sobrien */ 8018296Sbde 81148919Sobrienstatic struct command db_show_all_cmds[] = { 82148919Sobrien { "procs", db_ps, 0, 0 }, 83148919Sobrien { (char *)0 } 84148919Sobrien}; 85148919Sobrien 86148919Sobrienstatic struct command db_show_cmds[] = { 87148919Sobrien { "all", 0, 0, db_show_all_cmds }, 88148919Sobrien { "registers", db_show_regs, 0, 0 }, 89148919Sobrien { "breaks", db_listbreak_cmd, 0, 0 }, 90148919Sobrien { "threads", db_show_threads, 0, 0 }, 91148919Sobrien { (char *)0, } 92148919Sobrien}; 93148919Sobrien 94148919Sobrienstatic struct command db_command_table[] = { 95148919Sobrien { "print", db_print_cmd, 0, 0 }, 96148919Sobrien { "p", db_print_cmd, 0, 0 }, 97148919Sobrien { "examine", db_examine_cmd, CS_SET_DOT, 0 }, 98148919Sobrien { "x", db_examine_cmd, CS_SET_DOT, 0 }, 99148919Sobrien { "search", db_search_cmd, CS_OWN|CS_SET_DOT, 0 }, 100148919Sobrien { "set", db_set_cmd, CS_OWN, 0 }, 101148919Sobrien { "write", db_write_cmd, CS_MORE|CS_SET_DOT, 0 }, 102148919Sobrien { "w", db_write_cmd, CS_MORE|CS_SET_DOT, 0 }, 103148919Sobrien { "delete", db_delete_cmd, 0, 0 }, 104148919Sobrien { "d", db_delete_cmd, 0, 0 }, 105148919Sobrien { "break", db_breakpoint_cmd, 0, 0 }, 106148919Sobrien { "dwatch", db_deletewatch_cmd, 0, 0 }, 107148919Sobrien { "watch", db_watchpoint_cmd, CS_MORE,0 }, 108148919Sobrien { "dhwatch", db_deletehwatch_cmd, 0, 0 }, 109148919Sobrien { "hwatch", db_hwatchpoint_cmd, 0, 0 }, 110148919Sobrien { "step", db_single_step_cmd, 0, 0 }, 111148919Sobrien { "s", db_single_step_cmd, 0, 0 }, 112148919Sobrien { "continue", db_continue_cmd, 0, 0 }, 113148919Sobrien { "c", db_continue_cmd, 0, 0 }, 114148919Sobrien { "until", db_trace_until_call_cmd,0, 0 }, 115148919Sobrien { "next", db_trace_until_matching_cmd,0, 0 }, 116148919Sobrien { "match", db_trace_until_matching_cmd,0, 0 }, 117148919Sobrien { "trace", db_stack_trace, CS_OWN, 0 }, 118150819Srwatson { "traceall", db_stack_trace_all, 0, 0 }, 119148919Sobrien { "where", db_stack_trace, CS_OWN, 0 }, 120148919Sobrien { "call", db_fncall, CS_OWN, 0 }, 121148919Sobrien { "show", 0, 0, db_show_cmds }, 122148919Sobrien { "ps", db_ps, 0, 0 }, 123148919Sobrien { "gdb", db_gdb, 0, 0 }, 124148919Sobrien { "reset", db_reset, 0, 0 }, 125148919Sobrien { "kill", db_kill, CS_OWN, 0 }, 126148919Sobrien { "watchdog", db_watchdog, 0, 0 }, 127148919Sobrien { "thread", db_set_thread, CS_OWN, 0 }, 128148919Sobrien { (char *)0, } 129148919Sobrien}; 130148919Sobrien 131148919Sobrienstatic struct command *db_last_command = 0; 132148919Sobrien 1334Srgrimes/* 1344Srgrimes * if 'ed' style: 'dot' is set at start of last item printed, 1354Srgrimes * and '+' points to next line. 1364Srgrimes * Otherwise: 'dot' points to next item, '..' points to last. 1374Srgrimes */ 13812515Sphkstatic boolean_t db_ed_style = TRUE; 1394Srgrimes 1404Srgrimes/* 1414Srgrimes * Utility routine - discard tokens through end-of-line. 1424Srgrimes */ 1434Srgrimesvoid 1444Srgrimesdb_skip_to_eol() 1454Srgrimes{ 1464Srgrimes int t; 1474Srgrimes do { 1484Srgrimes t = db_read_token(); 1494Srgrimes } while (t != tEOL); 1504Srgrimes} 1514Srgrimes 1524Srgrimes/* 1534Srgrimes * Results of command search. 1544Srgrimes */ 1554Srgrimes#define CMD_UNIQUE 0 1564Srgrimes#define CMD_FOUND 1 1574Srgrimes#define CMD_NONE 2 1584Srgrimes#define CMD_AMBIGUOUS 3 1594Srgrimes#define CMD_HELP 4 1604Srgrimes 16193009Sbdestatic void db_cmd_list(struct command *table, struct command **aux_tablep, 16293009Sbde struct command **aux_tablep_end); 16392756Salfredstatic int db_cmd_search(char *name, struct command *table, 16493009Sbde struct command **aux_tablep, 16593009Sbde struct command **aux_tablep_end, struct command **cmdp); 16692756Salfredstatic void db_command(struct command **last_cmdp, 16793009Sbde struct command *cmd_table, struct command **aux_cmd_tablep, 16893009Sbde struct command **aux_cmd_tablep_end); 16912473Sbde 1704Srgrimes/* 1714Srgrimes * Search for command prefix. 1724Srgrimes */ 17312515Sphkstatic int 17478161Speterdb_cmd_search(name, table, aux_tablep, aux_tablep_end, cmdp) 1754Srgrimes char * name; 1764Srgrimes struct command *table; 17718296Sbde struct command **aux_tablep; 17878161Speter struct command **aux_tablep_end; 1794Srgrimes struct command **cmdp; /* out */ 1804Srgrimes{ 1814Srgrimes struct command *cmd; 18218296Sbde struct command **aux_cmdp; 1834Srgrimes int result = CMD_NONE; 1844Srgrimes 1854Srgrimes for (cmd = table; cmd->name != 0; cmd++) { 1864Srgrimes register char *lp; 1874Srgrimes register char *rp; 1884Srgrimes register int c; 1894Srgrimes 1904Srgrimes lp = name; 1914Srgrimes rp = cmd->name; 1924Srgrimes while ((c = *lp) == *rp) { 1934Srgrimes if (c == 0) { 1944Srgrimes /* complete match */ 1954Srgrimes *cmdp = cmd; 1964Srgrimes return (CMD_UNIQUE); 1974Srgrimes } 1984Srgrimes lp++; 1994Srgrimes rp++; 2004Srgrimes } 2014Srgrimes if (c == 0) { 2024Srgrimes /* end of name, not end of command - 2034Srgrimes partial match */ 2044Srgrimes if (result == CMD_FOUND) { 2054Srgrimes result = CMD_AMBIGUOUS; 2064Srgrimes /* but keep looking for a full match - 2074Srgrimes this lets us match single letters */ 2084Srgrimes } 2094Srgrimes else { 2104Srgrimes *cmdp = cmd; 2114Srgrimes result = CMD_FOUND; 2124Srgrimes } 2134Srgrimes } 2144Srgrimes } 21518296Sbde if (result == CMD_NONE && aux_tablep != 0) 21618296Sbde /* XXX repeat too much code. */ 21778161Speter for (aux_cmdp = aux_tablep; aux_cmdp < aux_tablep_end; aux_cmdp++) { 21818296Sbde register char *lp; 21918296Sbde register char *rp; 22018296Sbde register int c; 22118296Sbde 22218296Sbde lp = name; 22318296Sbde rp = (*aux_cmdp)->name; 22418296Sbde while ((c = *lp) == *rp) { 22518296Sbde if (c == 0) { 22618296Sbde /* complete match */ 22718296Sbde *cmdp = *aux_cmdp; 22818296Sbde return (CMD_UNIQUE); 22918296Sbde } 23018296Sbde lp++; 23118296Sbde rp++; 23218296Sbde } 23318296Sbde if (c == 0) { 23418296Sbde /* end of name, not end of command - 23518296Sbde partial match */ 23618296Sbde if (result == CMD_FOUND) { 23718296Sbde result = CMD_AMBIGUOUS; 23818296Sbde /* but keep looking for a full match - 23918296Sbde this lets us match single letters */ 24018296Sbde } 24118296Sbde else { 24218296Sbde *cmdp = *aux_cmdp; 24318296Sbde result = CMD_FOUND; 24418296Sbde } 24518296Sbde } 24618296Sbde } 2474Srgrimes if (result == CMD_NONE) { 2484Srgrimes /* check for 'help' */ 2494Srgrimes if (name[0] == 'h' && name[1] == 'e' 2504Srgrimes && name[2] == 'l' && name[3] == 'p') 2514Srgrimes result = CMD_HELP; 2524Srgrimes } 2534Srgrimes return (result); 2544Srgrimes} 2554Srgrimes 25612515Sphkstatic void 25778161Speterdb_cmd_list(table, aux_tablep, aux_tablep_end) 2584Srgrimes struct command *table; 25918296Sbde struct command **aux_tablep; 26078161Speter struct command **aux_tablep_end; 2614Srgrimes{ 2624Srgrimes register struct command *cmd; 26318296Sbde register struct command **aux_cmdp; 2644Srgrimes 2654Srgrimes for (cmd = table; cmd->name != 0; cmd++) { 2664Srgrimes db_printf("%-12s", cmd->name); 2674Srgrimes db_end_line(); 2684Srgrimes } 26918296Sbde if (aux_tablep == 0) 27018296Sbde return; 27178161Speter for (aux_cmdp = aux_tablep; aux_cmdp < aux_tablep_end; aux_cmdp++) { 27218296Sbde db_printf("%-12s", (*aux_cmdp)->name); 27318296Sbde db_end_line(); 27418296Sbde } 2754Srgrimes} 2764Srgrimes 27712515Sphkstatic void 27878161Speterdb_command(last_cmdp, cmd_table, aux_cmd_tablep, aux_cmd_tablep_end) 2794Srgrimes struct command **last_cmdp; /* IN_OUT */ 2804Srgrimes struct command *cmd_table; 28118296Sbde struct command **aux_cmd_tablep; 28278161Speter struct command **aux_cmd_tablep_end; 2834Srgrimes{ 2844Srgrimes struct command *cmd; 2854Srgrimes int t; 2864Srgrimes char modif[TOK_STRING_SIZE]; 2874Srgrimes db_expr_t addr, count; 288798Swollman boolean_t have_addr = FALSE; 2894Srgrimes int result; 2904Srgrimes 2914Srgrimes t = db_read_token(); 2924Srgrimes if (t == tEOL) { 2934Srgrimes /* empty line repeats last command, at 'next' */ 2944Srgrimes cmd = *last_cmdp; 2954Srgrimes addr = (db_expr_t)db_next; 2964Srgrimes have_addr = FALSE; 2974Srgrimes count = 1; 2984Srgrimes modif[0] = '\0'; 2994Srgrimes } 3004Srgrimes else if (t == tEXCL) { 30110348Sbde db_fncall((db_expr_t)0, (boolean_t)0, (db_expr_t)0, (char *)0); 3024Srgrimes return; 3034Srgrimes } 3044Srgrimes else if (t != tIDENT) { 3054Srgrimes db_printf("?\n"); 3064Srgrimes db_flush_lex(); 3074Srgrimes return; 3084Srgrimes } 3094Srgrimes else { 3104Srgrimes /* 3114Srgrimes * Search for command 3124Srgrimes */ 3134Srgrimes while (cmd_table) { 3144Srgrimes result = db_cmd_search(db_tok_string, 3154Srgrimes cmd_table, 31618296Sbde aux_cmd_tablep, 31778161Speter aux_cmd_tablep_end, 3184Srgrimes &cmd); 3194Srgrimes switch (result) { 3204Srgrimes case CMD_NONE: 3214Srgrimes db_printf("No such command\n"); 3224Srgrimes db_flush_lex(); 3234Srgrimes return; 3244Srgrimes case CMD_AMBIGUOUS: 3254Srgrimes db_printf("Ambiguous\n"); 3264Srgrimes db_flush_lex(); 3274Srgrimes return; 3284Srgrimes case CMD_HELP: 32978161Speter db_cmd_list(cmd_table, aux_cmd_tablep, aux_cmd_tablep_end); 3304Srgrimes db_flush_lex(); 3314Srgrimes return; 3324Srgrimes default: 3334Srgrimes break; 3344Srgrimes } 3354Srgrimes if ((cmd_table = cmd->more) != 0) { 33618296Sbde /* XXX usually no more aux's. */ 33718296Sbde aux_cmd_tablep = 0; 338104321Sphk if (cmd_table == db_show_cmds) { 33978161Speter aux_cmd_tablep = SET_BEGIN(db_show_cmd_set); 34078161Speter aux_cmd_tablep_end = SET_LIMIT(db_show_cmd_set); 341104321Sphk } 34218296Sbde 3434Srgrimes t = db_read_token(); 3444Srgrimes if (t != tIDENT) { 34578161Speter db_cmd_list(cmd_table, aux_cmd_tablep, aux_cmd_tablep_end); 3464Srgrimes db_flush_lex(); 3474Srgrimes return; 3484Srgrimes } 3494Srgrimes } 3504Srgrimes } 3514Srgrimes 3524Srgrimes if ((cmd->flag & CS_OWN) == 0) { 3534Srgrimes /* 3544Srgrimes * Standard syntax: 3554Srgrimes * command [/modifier] [addr] [,count] 3564Srgrimes */ 3574Srgrimes t = db_read_token(); 3584Srgrimes if (t == tSLASH) { 3594Srgrimes t = db_read_token(); 3604Srgrimes if (t != tIDENT) { 3614Srgrimes db_printf("Bad modifier\n"); 3624Srgrimes db_flush_lex(); 3634Srgrimes return; 3644Srgrimes } 3654Srgrimes db_strcpy(modif, db_tok_string); 3664Srgrimes } 3674Srgrimes else { 3684Srgrimes db_unread_token(t); 3694Srgrimes modif[0] = '\0'; 3704Srgrimes } 3714Srgrimes 3724Srgrimes if (db_expression(&addr)) { 3734Srgrimes db_dot = (db_addr_t) addr; 3744Srgrimes db_last_addr = db_dot; 3754Srgrimes have_addr = TRUE; 3764Srgrimes } 3774Srgrimes else { 3784Srgrimes addr = (db_expr_t) db_dot; 3794Srgrimes have_addr = FALSE; 3804Srgrimes } 3814Srgrimes t = db_read_token(); 3824Srgrimes if (t == tCOMMA) { 3834Srgrimes if (!db_expression(&count)) { 3844Srgrimes db_printf("Count missing\n"); 3854Srgrimes db_flush_lex(); 3864Srgrimes return; 3874Srgrimes } 3884Srgrimes } 3894Srgrimes else { 3904Srgrimes db_unread_token(t); 3914Srgrimes count = -1; 3924Srgrimes } 3934Srgrimes if ((cmd->flag & CS_MORE) == 0) { 3944Srgrimes db_skip_to_eol(); 3954Srgrimes } 3964Srgrimes } 3974Srgrimes } 3984Srgrimes *last_cmdp = cmd; 3994Srgrimes if (cmd != 0) { 4004Srgrimes /* 4014Srgrimes * Execute the command. 4024Srgrimes */ 4034Srgrimes (*cmd->fcn)(addr, have_addr, count, modif); 404118268Sjhb db_setup_paging(NULL, NULL, -1); 4054Srgrimes 4064Srgrimes if (cmd->flag & CS_SET_DOT) { 4074Srgrimes /* 4084Srgrimes * If command changes dot, set dot to 4094Srgrimes * previous address displayed (if 'ed' style). 4104Srgrimes */ 4114Srgrimes if (db_ed_style) { 4124Srgrimes db_dot = db_prev; 4134Srgrimes } 4144Srgrimes else { 4154Srgrimes db_dot = db_next; 4164Srgrimes } 4174Srgrimes } 4184Srgrimes else { 4194Srgrimes /* 4204Srgrimes * If command does not change dot, 4214Srgrimes * set 'next' location to be the same. 4224Srgrimes */ 4234Srgrimes db_next = db_dot; 4244Srgrimes } 4254Srgrimes } 4264Srgrimes} 4274Srgrimes 4284Srgrimes/* 42933296Sbde * At least one non-optional command must be implemented using 43033296Sbde * DB_COMMAND() so that db_cmd_set gets created. Here is one. 43133296Sbde */ 43233296SbdeDB_COMMAND(panic, db_panic) 4336204Sphk{ 4347170Sdg panic("from debugger"); 4356204Sphk} 4366204Sphk 4376204Sphkvoid 4384Srgrimesdb_command_loop() 4394Srgrimes{ 4404Srgrimes /* 4414Srgrimes * Initialize 'prev' and 'next' to dot. 4424Srgrimes */ 4434Srgrimes db_prev = db_dot; 4444Srgrimes db_next = db_dot; 4454Srgrimes 4464Srgrimes db_cmd_loop_done = 0; 4474Srgrimes while (!db_cmd_loop_done) { 4484Srgrimes if (db_print_position() != 0) 4494Srgrimes db_printf("\n"); 4504Srgrimes 4514Srgrimes db_printf("db> "); 4524Srgrimes (void) db_read_line(); 4534Srgrimes 45418296Sbde db_command(&db_last_command, db_command_table, 45578161Speter SET_BEGIN(db_cmd_set), SET_LIMIT(db_cmd_set)); 4564Srgrimes } 4574Srgrimes} 4584Srgrimes 4594Srgrimesvoid 4604Srgrimesdb_error(s) 461103746Smarkm const char *s; 4624Srgrimes{ 4634Srgrimes if (s) 46479884Skris db_printf("%s", s); 4654Srgrimes db_flush_lex(); 466131952Smarcel kdb_reenter(); 4674Srgrimes} 4684Srgrimes 4694Srgrimes 4704Srgrimes/* 4714Srgrimes * Call random function: 4724Srgrimes * !expr(arg,arg,arg) 4734Srgrimes */ 474147745Smarcel 475147745Smarcel/* The generic implementation supports a maximum of 10 arguments. */ 476147745Smarceltypedef db_expr_t __db_f(db_expr_t, db_expr_t, db_expr_t, db_expr_t, 477147745Smarcel db_expr_t, db_expr_t, db_expr_t, db_expr_t, db_expr_t, db_expr_t); 478147745Smarcel 479147745Smarcelstatic __inline int 480147745Smarceldb_fncall_generic(db_expr_t addr, db_expr_t *rv, int nargs, db_expr_t args[]) 481147745Smarcel{ 482147745Smarcel __db_f *f = (__db_f *)addr; 483147745Smarcel 484147745Smarcel if (nargs > 10) { 485147745Smarcel db_printf("Too many arguments (max 10)\n"); 486147745Smarcel return (0); 487147745Smarcel } 488147745Smarcel *rv = (*f)(args[0], args[1], args[2], args[3], args[4], args[5], 489147745Smarcel args[6], args[7], args[8], args[9]); 490147745Smarcel return (1); 491147745Smarcel} 492147745Smarcel 49312515Sphkstatic void 49410348Sbdedb_fncall(dummy1, dummy2, dummy3, dummy4) 49510348Sbde db_expr_t dummy1; 49610348Sbde boolean_t dummy2; 49710348Sbde db_expr_t dummy3; 49810348Sbde char * dummy4; 4994Srgrimes{ 5004Srgrimes db_expr_t fn_addr; 501147745Smarcel db_expr_t args[DB_MAXARGS]; 5024Srgrimes int nargs = 0; 5034Srgrimes db_expr_t retval; 5044Srgrimes int t; 5054Srgrimes 5064Srgrimes if (!db_expression(&fn_addr)) { 5074Srgrimes db_printf("Bad function\n"); 5084Srgrimes db_flush_lex(); 5094Srgrimes return; 5104Srgrimes } 5114Srgrimes 5124Srgrimes t = db_read_token(); 5134Srgrimes if (t == tLPAREN) { 5144Srgrimes if (db_expression(&args[0])) { 5154Srgrimes nargs++; 5164Srgrimes while ((t = db_read_token()) == tCOMMA) { 517147745Smarcel if (nargs == DB_MAXARGS) { 518147745Smarcel db_printf("Too many arguments (max %d)\n", DB_MAXARGS); 5194Srgrimes db_flush_lex(); 5204Srgrimes return; 5214Srgrimes } 5224Srgrimes if (!db_expression(&args[nargs])) { 5234Srgrimes db_printf("Argument missing\n"); 5244Srgrimes db_flush_lex(); 5254Srgrimes return; 5264Srgrimes } 5274Srgrimes nargs++; 5284Srgrimes } 5294Srgrimes db_unread_token(t); 5304Srgrimes } 5314Srgrimes if (db_read_token() != tRPAREN) { 5324Srgrimes db_printf("?\n"); 5334Srgrimes db_flush_lex(); 5344Srgrimes return; 5354Srgrimes } 5364Srgrimes } 5374Srgrimes db_skip_to_eol(); 5384Srgrimes 539147745Smarcel if (DB_CALL(fn_addr, &retval, nargs, args)) 540147745Smarcel db_printf("= %#lr\n", (long)retval); 5414Srgrimes} 54217848Spst 54317848Spststatic void 54486998Sdddb_kill(dummy1, dummy2, dummy3, dummy4) 54586998Sdd db_expr_t dummy1; 54686998Sdd boolean_t dummy2; 54786998Sdd db_expr_t dummy3; 54886998Sdd char * dummy4; 54986998Sdd{ 55086998Sdd db_expr_t old_radix, pid, sig; 55186998Sdd struct proc *p; 55286998Sdd 55386998Sdd#define DB_ERROR(f) do { db_printf f; db_flush_lex(); goto out; } while (0) 55486998Sdd 55586998Sdd /* 55686998Sdd * PIDs and signal numbers are typically represented in base 55786998Sdd * 10, so make that the default here. It can, of course, be 55886998Sdd * overridden by specifying a prefix. 55986998Sdd */ 56086998Sdd old_radix = db_radix; 56186998Sdd db_radix = 10; 56286998Sdd /* Retrieve arguments. */ 56386998Sdd if (!db_expression(&sig)) 56486998Sdd DB_ERROR(("Missing signal number\n")); 56586998Sdd if (!db_expression(&pid)) 56686998Sdd DB_ERROR(("Missing process ID\n")); 56786998Sdd db_skip_to_eol(); 56886998Sdd if (sig < 0 || sig > _SIG_MAXSIG) 56986998Sdd DB_ERROR(("Signal number out of range\n")); 57086998Sdd 57186998Sdd /* 57286998Sdd * Find the process in question. allproc_lock is not needed 57386998Sdd * since we're in DDB. 57486998Sdd */ 57586998Sdd /* sx_slock(&allproc_lock); */ 57686998Sdd LIST_FOREACH(p, &allproc, p_list) 57786998Sdd if (p->p_pid == pid) 57886998Sdd break; 57986998Sdd /* sx_sunlock(&allproc_lock); */ 58086998Sdd if (p == NULL) 58189442Smjacob DB_ERROR(("Can't find process with pid %ld\n", (long) pid)); 58286998Sdd 58386998Sdd /* If it's already locked, bail; otherwise, do the deed. */ 58486998Sdd if (PROC_TRYLOCK(p) == 0) 58589442Smjacob DB_ERROR(("Can't lock process with pid %ld\n", (long) pid)); 58686998Sdd else { 58786998Sdd psignal(p, sig); 58886998Sdd PROC_UNLOCK(p); 58986998Sdd } 59086998Sdd 59186998Sddout: 59286998Sdd db_radix = old_radix; 59386998Sdd#undef DB_ERROR 59486998Sdd} 59586998Sdd 59686998Sddstatic void 59785944Speterdb_reset(dummy1, dummy2, dummy3, dummy4) 59885944Speter db_expr_t dummy1; 59985944Speter boolean_t dummy2; 60085944Speter db_expr_t dummy3; 60185944Speter char * dummy4; 60285944Speter{ 60385944Speter 60485944Speter cpu_reset(); 60585944Speter} 606126399Sphk 607126399Sphkstatic void 608126399Sphkdb_watchdog(dummy1, dummy2, dummy3, dummy4) 609126399Sphk db_expr_t dummy1; 610126399Sphk boolean_t dummy2; 611126399Sphk db_expr_t dummy3; 612126399Sphk char * dummy4; 613126399Sphk{ 614126399Sphk int i; 615126399Sphk 616126399Sphk /* 617126399Sphk * XXX: It might make sense to be able to set the watchdog to a 618126399Sphk * XXX: timeout here so that failure or hang as a result of subsequent 619126399Sphk * XXX: ddb commands could be recovered by a reset. 620126399Sphk */ 621126399Sphk 622126399Sphk EVENTHANDLER_INVOKE(watchdog_list, 0, &i); 623126399Sphk} 624132002Smarcel 625132002Smarcelstatic void 626132002Smarceldb_gdb(db_expr_t dummy1, boolean_t dummy2, db_expr_t dummy3, char *dummy4) 627132002Smarcel{ 628132002Smarcel 629132002Smarcel if (kdb_dbbe_select("gdb") != 0) 630132002Smarcel db_printf("The remote GDB backend could not be selected.\n"); 631132002Smarcel else 632132002Smarcel db_printf("Step to enter the remote GDB backend.\n"); 633132002Smarcel} 634132482Smarcel 635132482Smarcelstatic void 636132482Smarceldb_stack_trace(db_expr_t tid, boolean_t hastid, db_expr_t count, char *modif) 637132482Smarcel{ 638132482Smarcel struct thread *td; 639132482Smarcel db_expr_t radix; 640138038Srwatson pid_t pid; 641132482Smarcel int t; 642132482Smarcel 643132482Smarcel /* 644132482Smarcel * We parse our own arguments. We don't like the default radix. 645132482Smarcel */ 646132482Smarcel radix = db_radix; 647132482Smarcel db_radix = 10; 648132482Smarcel hastid = db_expression(&tid); 649132482Smarcel t = db_read_token(); 650132482Smarcel if (t == tCOMMA) { 651132482Smarcel if (!db_expression(&count)) { 652132482Smarcel db_printf("Count missing\n"); 653132482Smarcel db_flush_lex(); 654132482Smarcel return; 655132482Smarcel } 656132482Smarcel } else { 657132482Smarcel db_unread_token(t); 658132482Smarcel count = -1; 659132482Smarcel } 660132482Smarcel db_skip_to_eol(); 661132482Smarcel db_radix = radix; 662132482Smarcel 663132482Smarcel if (hastid) { 664132482Smarcel td = kdb_thr_lookup((lwpid_t)tid); 665132482Smarcel if (td == NULL) 666132482Smarcel td = kdb_thr_from_pid((pid_t)tid); 667132482Smarcel if (td == NULL) { 668132482Smarcel db_printf("Thread %d not found\n", (int)tid); 669132482Smarcel return; 670132482Smarcel } 671132482Smarcel } else 672132482Smarcel td = kdb_thread; 673138038Srwatson if (td->td_proc != NULL) 674138038Srwatson pid = td->td_proc->p_pid; 675138038Srwatson else 676138038Srwatson pid = -1; 677138038Srwatson db_printf("Tracing pid %d tid %ld td %p\n", pid, (long)td->td_tid, td); 678132482Smarcel db_trace_thread(td, count); 679132482Smarcel} 680150819Srwatson 681150819Srwatsonstatic void 682150819Srwatsondb_stack_trace_all(db_expr_t dummy, boolean_t dummy2, db_expr_t dummy3, 683150819Srwatson char *dummy4) 684150819Srwatson{ 685150819Srwatson struct proc *p; 686150819Srwatson struct thread *td; 687150819Srwatson 688150819Srwatson for (p = LIST_FIRST(&allproc); p != NULL; p = LIST_NEXT(p, p_list)) { 689150819Srwatson FOREACH_THREAD_IN_PROC(p, td) { 690150819Srwatson db_printf("\nTracing command %s pid %d tid %ld td %p\n", 691150819Srwatson p->p_comm, p->p_pid, (long)td->td_tid, td); 692150819Srwatson db_trace_thread(td, -1); 693150819Srwatson } 694150819Srwatson } 695150819Srwatson} 696