2005-01-06 01:34:41 +00:00
|
|
|
/*-
|
1993-06-12 14:58:17 +00:00
|
|
|
* Mach Operating System
|
|
|
|
* Copyright (c) 1991,1990 Carnegie Mellon University
|
|
|
|
* All Rights Reserved.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* Permission to use, copy, modify and distribute this software and its
|
|
|
|
* documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
|
1993-06-12 14:58:17 +00:00
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* Carnegie Mellon requests users of this software to return to
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Author: David B. Golub, Carnegie Mellon University
|
|
|
|
* Date: 7/90
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Command dispatcher.
|
|
|
|
*/
|
2003-06-10 22:09:23 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/param.h>
|
1999-01-14 06:22:10 +00:00
|
|
|
#include <sys/linker_set.h>
|
2001-11-27 19:56:28 +00:00
|
|
|
#include <sys/lock.h>
|
2004-07-10 23:47:20 +00:00
|
|
|
#include <sys/kdb.h>
|
2001-11-27 19:56:28 +00:00
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/proc.h>
|
1996-08-27 19:46:28 +00:00
|
|
|
#include <sys/reboot.h>
|
2001-11-27 19:56:28 +00:00
|
|
|
#include <sys/signalvar.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/systm.h>
|
1999-08-09 10:35:05 +00:00
|
|
|
#include <sys/cons.h>
|
2011-06-07 01:28:12 +00:00
|
|
|
#include <sys/conf.h>
|
2004-02-29 09:55:32 +00:00
|
|
|
#include <sys/watchdog.h>
|
2008-09-15 22:45:14 +00:00
|
|
|
#include <sys/kernel.h>
|
1999-05-09 10:51:13 +00:00
|
|
|
|
1995-12-10 19:08:32 +00:00
|
|
|
#include <ddb/ddb.h>
|
1995-11-24 14:13:42 +00:00
|
|
|
#include <ddb/db_command.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
#include <ddb/db_lex.h>
|
|
|
|
#include <ddb/db_output.h>
|
|
|
|
|
2003-08-16 16:57:57 +00:00
|
|
|
#include <machine/cpu.h>
|
2001-07-08 04:56:07 +00:00
|
|
|
#include <machine/setjmp.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Exported global variables
|
|
|
|
*/
|
2016-09-09 04:16:53 +00:00
|
|
|
int db_cmd_loop_done;
|
1993-06-12 14:58:17 +00:00
|
|
|
db_addr_t db_dot;
|
|
|
|
db_addr_t db_last_addr;
|
|
|
|
db_addr_t db_prev;
|
|
|
|
db_addr_t db_next;
|
2001-06-13 10:58:39 +00:00
|
|
|
|
2011-06-07 01:28:12 +00:00
|
|
|
static db_cmdfcn_t db_dump;
|
1995-11-29 10:25:50 +00:00
|
|
|
static db_cmdfcn_t db_fncall;
|
2004-07-12 01:38:07 +00:00
|
|
|
static db_cmdfcn_t db_gdb;
|
2006-10-10 07:26:54 +00:00
|
|
|
static db_cmdfcn_t db_halt;
|
2001-11-27 19:56:28 +00:00
|
|
|
static db_cmdfcn_t db_kill;
|
2001-11-03 04:55:48 +00:00
|
|
|
static db_cmdfcn_t db_reset;
|
2004-07-21 05:07:09 +00:00
|
|
|
static db_cmdfcn_t db_stack_trace;
|
2016-08-26 02:46:47 +00:00
|
|
|
static db_cmdfcn_t db_stack_trace_active;
|
2005-10-02 11:41:12 +00:00
|
|
|
static db_cmdfcn_t db_stack_trace_all;
|
2004-02-29 09:55:32 +00:00
|
|
|
static db_cmdfcn_t db_watchdog;
|
1996-08-27 19:46:28 +00:00
|
|
|
|
2005-08-10 07:08:14 +00:00
|
|
|
/*
|
|
|
|
* 'show' commands
|
|
|
|
*/
|
|
|
|
|
2016-08-26 02:46:47 +00:00
|
|
|
static struct command db_show_active_cmds[] = {
|
|
|
|
{ "trace", db_stack_trace_active, 0, NULL },
|
|
|
|
};
|
|
|
|
struct command_table db_show_active_table =
|
|
|
|
LIST_HEAD_INITIALIZER(db_show_active_table);
|
|
|
|
|
2005-08-10 07:08:14 +00:00
|
|
|
static struct command db_show_all_cmds[] = {
|
2015-05-22 19:04:06 +00:00
|
|
|
{ "trace", db_stack_trace_all, 0, NULL },
|
2006-03-07 22:17:06 +00:00
|
|
|
};
|
2008-09-15 22:45:14 +00:00
|
|
|
struct command_table db_show_all_table =
|
|
|
|
LIST_HEAD_INITIALIZER(db_show_all_table);
|
2006-03-07 22:17:06 +00:00
|
|
|
|
2005-08-10 07:08:14 +00:00
|
|
|
static struct command db_show_cmds[] = {
|
2016-08-26 02:46:47 +00:00
|
|
|
{ "active", 0, 0, &db_show_active_table },
|
2006-03-07 22:17:06 +00:00
|
|
|
{ "all", 0, 0, &db_show_all_table },
|
2015-05-22 19:04:06 +00:00
|
|
|
{ "registers", db_show_regs, 0, NULL },
|
|
|
|
{ "breaks", db_listbreak_cmd, 0, NULL },
|
|
|
|
{ "threads", db_show_threads, 0, NULL },
|
2005-08-10 07:08:14 +00:00
|
|
|
};
|
2008-09-15 22:45:14 +00:00
|
|
|
struct command_table db_show_table = LIST_HEAD_INITIALIZER(db_show_table);
|
2005-08-10 07:08:14 +00:00
|
|
|
|
2008-09-15 22:45:14 +00:00
|
|
|
static struct command db_cmds[] = {
|
2015-05-22 19:04:06 +00:00
|
|
|
{ "print", db_print_cmd, 0, NULL },
|
|
|
|
{ "p", db_print_cmd, 0, NULL },
|
|
|
|
{ "examine", db_examine_cmd, CS_SET_DOT, NULL },
|
|
|
|
{ "x", db_examine_cmd, CS_SET_DOT, NULL },
|
|
|
|
{ "search", db_search_cmd, CS_OWN|CS_SET_DOT, NULL },
|
|
|
|
{ "set", db_set_cmd, CS_OWN, NULL },
|
|
|
|
{ "write", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
|
|
|
|
{ "w", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
|
|
|
|
{ "delete", db_delete_cmd, 0, NULL },
|
|
|
|
{ "d", db_delete_cmd, 0, NULL },
|
|
|
|
{ "dump", db_dump, 0, NULL },
|
|
|
|
{ "break", db_breakpoint_cmd, 0, NULL },
|
|
|
|
{ "b", db_breakpoint_cmd, 0, NULL },
|
|
|
|
{ "dwatch", db_deletewatch_cmd, 0, NULL },
|
|
|
|
{ "watch", db_watchpoint_cmd, CS_MORE,NULL },
|
|
|
|
{ "dhwatch", db_deletehwatch_cmd, 0, NULL },
|
|
|
|
{ "hwatch", db_hwatchpoint_cmd, 0, NULL },
|
|
|
|
{ "step", db_single_step_cmd, 0, NULL },
|
|
|
|
{ "s", db_single_step_cmd, 0, NULL },
|
|
|
|
{ "continue", db_continue_cmd, 0, NULL },
|
|
|
|
{ "c", db_continue_cmd, 0, NULL },
|
|
|
|
{ "until", db_trace_until_call_cmd,0, NULL },
|
|
|
|
{ "next", db_trace_until_matching_cmd,0, NULL },
|
|
|
|
{ "match", db_trace_until_matching_cmd,0, NULL },
|
|
|
|
{ "trace", db_stack_trace, CS_OWN, NULL },
|
|
|
|
{ "t", db_stack_trace, CS_OWN, NULL },
|
2016-08-26 02:46:47 +00:00
|
|
|
/* XXX alias for active trace */
|
|
|
|
{ "acttrace", db_stack_trace_active, 0, NULL },
|
2008-09-15 22:45:14 +00:00
|
|
|
/* XXX alias for all trace */
|
2015-05-22 19:04:06 +00:00
|
|
|
{ "alltrace", db_stack_trace_all, 0, NULL },
|
|
|
|
{ "where", db_stack_trace, CS_OWN, NULL },
|
|
|
|
{ "bt", db_stack_trace, CS_OWN, NULL },
|
|
|
|
{ "call", db_fncall, CS_OWN, NULL },
|
2006-03-07 22:17:06 +00:00
|
|
|
{ "show", 0, 0, &db_show_table },
|
2015-05-22 19:04:06 +00:00
|
|
|
{ "ps", db_ps, 0, NULL },
|
|
|
|
{ "gdb", db_gdb, 0, NULL },
|
|
|
|
{ "halt", db_halt, 0, NULL },
|
|
|
|
{ "reboot", db_reset, 0, NULL },
|
|
|
|
{ "reset", db_reset, 0, NULL },
|
|
|
|
{ "kill", db_kill, CS_OWN, NULL },
|
|
|
|
{ "watchdog", db_watchdog, CS_OWN, NULL },
|
|
|
|
{ "thread", db_set_thread, CS_OWN, NULL },
|
|
|
|
{ "run", db_run_cmd, CS_OWN, NULL },
|
|
|
|
{ "script", db_script_cmd, CS_OWN, NULL },
|
|
|
|
{ "scripts", db_scripts_cmd, 0, NULL },
|
|
|
|
{ "unscript", db_unscript_cmd, CS_OWN, NULL },
|
|
|
|
{ "capture", db_capture_cmd, CS_OWN, NULL },
|
|
|
|
{ "textdump", db_textdump_cmd, CS_OWN, NULL },
|
|
|
|
{ "findstack", db_findstack_cmd, 0, NULL },
|
2006-03-07 22:17:06 +00:00
|
|
|
};
|
2008-09-15 22:45:14 +00:00
|
|
|
struct command_table db_cmd_table = LIST_HEAD_INITIALIZER(db_cmd_table);
|
2006-03-07 22:17:06 +00:00
|
|
|
|
2016-04-15 17:27:20 +00:00
|
|
|
static struct command *db_last_command = NULL;
|
1996-09-14 09:13:15 +00:00
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
/*
|
|
|
|
* if 'ed' style: 'dot' is set at start of last item printed,
|
|
|
|
* and '+' points to next line.
|
|
|
|
* Otherwise: 'dot' points to next item, '..' points to last.
|
|
|
|
*/
|
2015-05-21 15:16:18 +00:00
|
|
|
static bool db_ed_style = true;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Utility routine - discard tokens through end-of-line.
|
|
|
|
*/
|
|
|
|
void
|
2014-10-12 18:01:52 +00:00
|
|
|
db_skip_to_eol(void)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
int t;
|
|
|
|
do {
|
|
|
|
t = db_read_token();
|
|
|
|
} while (t != tEOL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Results of command search.
|
|
|
|
*/
|
|
|
|
#define CMD_UNIQUE 0
|
|
|
|
#define CMD_FOUND 1
|
|
|
|
#define CMD_NONE 2
|
|
|
|
#define CMD_AMBIGUOUS 3
|
|
|
|
#define CMD_HELP 4
|
|
|
|
|
2006-03-07 22:17:06 +00:00
|
|
|
static void db_cmd_match(char *name, struct command *cmd,
|
|
|
|
struct command **cmdp, int *resultp);
|
|
|
|
static void db_cmd_list(struct command_table *table);
|
|
|
|
static int db_cmd_search(char *name, struct command_table *table,
|
|
|
|
struct command **cmdp);
|
2002-03-20 05:14:42 +00:00
|
|
|
static void db_command(struct command **last_cmdp,
|
Add a simple scripting facility to DDB(4), allowing the user to
define a set of named scripts. Each script consists of a list of DDB
commands separated by ";"s that will be executed verbatim. No higher
level language constructs, such as branching, are provided for:
scripts are executed by sequentially injecting commands into the DDB
input buffer.
Four new commands are present in DDB: "run" to run a specific script,
"script" to define or print a script, "scripts" to list currently
defined scripts, and "unscript" to delete a script, modeled on shell
alias commands. Scripts may also be manipulated using sysctls in the
debug.ddb.scripting MIB space, although users will prefer to use the
soon-to-be-added ddb(8) tool for usability reasons.
Scripts with certain names are automatically executed on various DDB
events, such as entering the debugger via a panic, a witness error,
watchdog, breakpoint, sysctl, serial break, etc, allowing customized
handling.
MFC after: 3 months
2007-12-26 09:33:19 +00:00
|
|
|
struct command_table *cmd_table, int dopager);
|
1995-11-24 14:13:42 +00:00
|
|
|
|
2008-09-15 22:45:14 +00:00
|
|
|
/*
|
|
|
|
* Initialize the command lists from the static tables.
|
|
|
|
*/
|
2008-09-25 19:50:14 +00:00
|
|
|
void
|
|
|
|
db_command_init(void)
|
2008-09-15 22:45:14 +00:00
|
|
|
{
|
|
|
|
#define N(a) (sizeof(a) / sizeof(a[0]))
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < N(db_cmds); i++)
|
|
|
|
db_command_register(&db_cmd_table, &db_cmds[i]);
|
|
|
|
for (i = 0; i < N(db_show_cmds); i++)
|
|
|
|
db_command_register(&db_show_table, &db_show_cmds[i]);
|
2016-08-26 02:46:47 +00:00
|
|
|
for (i = 0; i < N(db_show_active_cmds); i++)
|
|
|
|
db_command_register(&db_show_active_table,
|
|
|
|
&db_show_active_cmds[i]);
|
2008-09-15 22:45:14 +00:00
|
|
|
for (i = 0; i < N(db_show_all_cmds); i++)
|
|
|
|
db_command_register(&db_show_all_table, &db_show_all_cmds[i]);
|
|
|
|
#undef N
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register a command.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
db_command_register(struct command_table *list, struct command *cmd)
|
|
|
|
{
|
|
|
|
struct command *c, *last;
|
|
|
|
|
|
|
|
last = NULL;
|
|
|
|
LIST_FOREACH(c, list, next) {
|
|
|
|
int n = strcmp(cmd->name, c->name);
|
|
|
|
|
|
|
|
/* Check that the command is not already present. */
|
|
|
|
if (n == 0) {
|
|
|
|
printf("%s: Warning, the command \"%s\" already exists;"
|
|
|
|
" ignoring request\n", __func__, cmd->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (n < 0) {
|
|
|
|
/* NB: keep list sorted lexicographically */
|
|
|
|
LIST_INSERT_BEFORE(c, cmd, next);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
last = c;
|
|
|
|
}
|
|
|
|
if (last == NULL)
|
|
|
|
LIST_INSERT_HEAD(list, cmd, next);
|
|
|
|
else
|
|
|
|
LIST_INSERT_AFTER(last, cmd, next);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a command previously registered with db_command_register.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
db_command_unregister(struct command_table *list, struct command *cmd)
|
|
|
|
{
|
|
|
|
struct command *c;
|
|
|
|
|
|
|
|
LIST_FOREACH(c, list, next) {
|
|
|
|
if (cmd == c) {
|
|
|
|
LIST_REMOVE(cmd, next);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* NB: intentionally quiet */
|
|
|
|
}
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
/*
|
2006-03-07 22:17:06 +00:00
|
|
|
* Helper function to match a single command.
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
2006-03-07 22:17:06 +00:00
|
|
|
static void
|
2014-10-12 18:01:52 +00:00
|
|
|
db_cmd_match(char *name, struct command *cmd, struct command **cmdp,
|
|
|
|
int *resultp)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
2006-03-07 22:17:06 +00:00
|
|
|
char *lp, *rp;
|
|
|
|
int c;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
2006-03-07 22:17:06 +00:00
|
|
|
lp = name;
|
|
|
|
rp = cmd->name;
|
|
|
|
while ((c = *lp) == *rp) {
|
1993-06-12 14:58:17 +00:00
|
|
|
if (c == 0) {
|
2006-03-07 22:17:06 +00:00
|
|
|
/* complete match */
|
|
|
|
*cmdp = cmd;
|
|
|
|
*resultp = CMD_UNIQUE;
|
|
|
|
return;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
lp++;
|
|
|
|
rp++;
|
2006-03-07 22:17:06 +00:00
|
|
|
}
|
|
|
|
if (c == 0) {
|
1993-06-12 14:58:17 +00:00
|
|
|
/* end of name, not end of command -
|
|
|
|
partial match */
|
2006-03-07 22:17:06 +00:00
|
|
|
if (*resultp == CMD_FOUND) {
|
|
|
|
*resultp = CMD_AMBIGUOUS;
|
|
|
|
/* but keep looking for a full match -
|
|
|
|
this lets us match single letters */
|
|
|
|
} else {
|
|
|
|
*cmdp = cmd;
|
|
|
|
*resultp = CMD_FOUND;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-07 22:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search for command prefix.
|
|
|
|
*/
|
|
|
|
static int
|
2014-10-12 18:01:52 +00:00
|
|
|
db_cmd_search(char *name, struct command_table *table, struct command **cmdp)
|
2006-03-07 22:17:06 +00:00
|
|
|
{
|
|
|
|
struct command *cmd;
|
|
|
|
int result = CMD_NONE;
|
|
|
|
|
2008-09-15 22:45:14 +00:00
|
|
|
LIST_FOREACH(cmd, table, next) {
|
|
|
|
db_cmd_match(name,cmd,cmdp,&result);
|
2006-03-07 22:17:06 +00:00
|
|
|
if (result == CMD_UNIQUE)
|
2008-09-15 22:45:14 +00:00
|
|
|
break;
|
2006-03-07 22:17:06 +00:00
|
|
|
}
|
2008-09-15 22:45:14 +00:00
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
if (result == CMD_NONE) {
|
2006-03-07 22:17:06 +00:00
|
|
|
/* check for 'help' */
|
1993-06-12 14:58:17 +00:00
|
|
|
if (name[0] == 'h' && name[1] == 'e'
|
|
|
|
&& name[2] == 'l' && name[3] == 'p')
|
|
|
|
result = CMD_HELP;
|
|
|
|
}
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1995-11-29 10:25:50 +00:00
|
|
|
static void
|
2014-10-12 18:01:52 +00:00
|
|
|
db_cmd_list(struct command_table *table)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
2015-05-23 14:59:27 +00:00
|
|
|
struct command *cmd;
|
2017-07-06 12:27:14 +00:00
|
|
|
int have_subcommands;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
2017-07-06 12:27:14 +00:00
|
|
|
have_subcommands = 0;
|
2008-09-15 22:45:14 +00:00
|
|
|
LIST_FOREACH(cmd, table, next) {
|
2017-07-06 12:27:14 +00:00
|
|
|
if (cmd->more != NULL)
|
|
|
|
have_subcommands++;
|
2014-06-02 23:50:19 +00:00
|
|
|
db_printf("%-16s", cmd->name);
|
|
|
|
db_end_line(16);
|
1996-09-14 09:13:15 +00:00
|
|
|
}
|
2017-07-06 12:27:14 +00:00
|
|
|
|
|
|
|
if (have_subcommands > 0) {
|
|
|
|
db_printf("\nThe following have subcommands; append \"help\" "
|
|
|
|
"to list (e.g. \"show help\"):\n");
|
|
|
|
LIST_FOREACH(cmd, table, next) {
|
|
|
|
if (cmd->more == NULL)
|
|
|
|
continue;
|
|
|
|
db_printf("%-16s", cmd->name);
|
|
|
|
db_end_line(16);
|
|
|
|
}
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
1995-11-29 10:25:50 +00:00
|
|
|
static void
|
2014-10-12 18:01:52 +00:00
|
|
|
db_command(struct command **last_cmdp, struct command_table *cmd_table,
|
|
|
|
int dopager)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
2008-09-15 22:45:14 +00:00
|
|
|
struct command *cmd = NULL;
|
1993-06-12 14:58:17 +00:00
|
|
|
int t;
|
|
|
|
char modif[TOK_STRING_SIZE];
|
|
|
|
db_expr_t addr, count;
|
2015-05-21 15:16:18 +00:00
|
|
|
bool have_addr = false;
|
1993-06-12 14:58:17 +00:00
|
|
|
int result;
|
|
|
|
|
|
|
|
t = db_read_token();
|
|
|
|
if (t == tEOL) {
|
|
|
|
/* empty line repeats last command, at 'next' */
|
|
|
|
cmd = *last_cmdp;
|
|
|
|
addr = (db_expr_t)db_next;
|
2015-05-18 22:27:46 +00:00
|
|
|
have_addr = false;
|
1993-06-12 14:58:17 +00:00
|
|
|
count = 1;
|
|
|
|
modif[0] = '\0';
|
|
|
|
}
|
|
|
|
else if (t == tEXCL) {
|
2015-05-21 15:16:18 +00:00
|
|
|
db_fncall((db_expr_t)0, (bool)false, (db_expr_t)0, (char *)0);
|
1993-06-12 14:58:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (t != tIDENT) {
|
2017-07-06 12:30:39 +00:00
|
|
|
db_printf("Unrecognized input; use \"help\" "
|
|
|
|
"to list available commands\n");
|
1993-06-12 14:58:17 +00:00
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* Search for command
|
|
|
|
*/
|
|
|
|
while (cmd_table) {
|
|
|
|
result = db_cmd_search(db_tok_string,
|
|
|
|
cmd_table,
|
|
|
|
&cmd);
|
|
|
|
switch (result) {
|
|
|
|
case CMD_NONE:
|
2017-07-06 12:27:14 +00:00
|
|
|
db_printf("No such command; use \"help\" "
|
|
|
|
"to list available commands\n");
|
1993-06-12 14:58:17 +00:00
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
case CMD_AMBIGUOUS:
|
|
|
|
db_printf("Ambiguous\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
case CMD_HELP:
|
2017-07-06 12:27:14 +00:00
|
|
|
if (cmd_table == &db_cmd_table) {
|
|
|
|
db_printf("This is ddb(4), the kernel debugger; "
|
|
|
|
"see http://man.freebsd.org/ddb/4 for help.\n");
|
|
|
|
db_printf("Use \"bt\" for backtrace, \"dump\" for "
|
|
|
|
"kernel core dump, \"reset\" to reboot.\n");
|
|
|
|
db_printf("Available commands:\n");
|
|
|
|
}
|
2006-03-07 22:17:06 +00:00
|
|
|
db_cmd_list(cmd_table);
|
1993-06-12 14:58:17 +00:00
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-03-07 22:17:06 +00:00
|
|
|
if ((cmd_table = cmd->more) != NULL) {
|
1993-06-12 14:58:17 +00:00
|
|
|
t = db_read_token();
|
|
|
|
if (t != tIDENT) {
|
2017-07-06 12:27:14 +00:00
|
|
|
db_printf("Subcommand required; "
|
|
|
|
"available subcommands:\n");
|
2006-03-07 22:17:06 +00:00
|
|
|
db_cmd_list(cmd_table);
|
1993-06-12 14:58:17 +00:00
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cmd->flag & CS_OWN) == 0) {
|
|
|
|
/*
|
|
|
|
* Standard syntax:
|
|
|
|
* command [/modifier] [addr] [,count]
|
|
|
|
*/
|
|
|
|
t = db_read_token();
|
|
|
|
if (t == tSLASH) {
|
|
|
|
t = db_read_token();
|
|
|
|
if (t != tIDENT) {
|
|
|
|
db_printf("Bad modifier\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
db_strcpy(modif, db_tok_string);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
db_unread_token(t);
|
|
|
|
modif[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (db_expression(&addr)) {
|
|
|
|
db_dot = (db_addr_t) addr;
|
|
|
|
db_last_addr = db_dot;
|
2015-05-18 22:27:46 +00:00
|
|
|
have_addr = true;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
addr = (db_expr_t) db_dot;
|
2015-05-18 22:27:46 +00:00
|
|
|
have_addr = false;
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
t = db_read_token();
|
|
|
|
if (t == tCOMMA) {
|
|
|
|
if (!db_expression(&count)) {
|
|
|
|
db_printf("Count missing\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
db_unread_token(t);
|
|
|
|
count = -1;
|
|
|
|
}
|
|
|
|
if ((cmd->flag & CS_MORE) == 0) {
|
|
|
|
db_skip_to_eol();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*last_cmdp = cmd;
|
2016-04-15 17:27:20 +00:00
|
|
|
if (cmd != NULL) {
|
1993-06-12 14:58:17 +00:00
|
|
|
/*
|
|
|
|
* Execute the command.
|
|
|
|
*/
|
Add a simple scripting facility to DDB(4), allowing the user to
define a set of named scripts. Each script consists of a list of DDB
commands separated by ";"s that will be executed verbatim. No higher
level language constructs, such as branching, are provided for:
scripts are executed by sequentially injecting commands into the DDB
input buffer.
Four new commands are present in DDB: "run" to run a specific script,
"script" to define or print a script, "scripts" to list currently
defined scripts, and "unscript" to delete a script, modeled on shell
alias commands. Scripts may also be manipulated using sysctls in the
debug.ddb.scripting MIB space, although users will prefer to use the
soon-to-be-added ddb(8) tool for usability reasons.
Scripts with certain names are automatically executed on various DDB
events, such as entering the debugger via a panic, a witness error,
watchdog, breakpoint, sysctl, serial break, etc, allowing customized
handling.
MFC after: 3 months
2007-12-26 09:33:19 +00:00
|
|
|
if (dopager)
|
|
|
|
db_enable_pager();
|
|
|
|
else
|
|
|
|
db_disable_pager();
|
1993-06-12 14:58:17 +00:00
|
|
|
(*cmd->fcn)(addr, have_addr, count, modif);
|
Add a simple scripting facility to DDB(4), allowing the user to
define a set of named scripts. Each script consists of a list of DDB
commands separated by ";"s that will be executed verbatim. No higher
level language constructs, such as branching, are provided for:
scripts are executed by sequentially injecting commands into the DDB
input buffer.
Four new commands are present in DDB: "run" to run a specific script,
"script" to define or print a script, "scripts" to list currently
defined scripts, and "unscript" to delete a script, modeled on shell
alias commands. Scripts may also be manipulated using sysctls in the
debug.ddb.scripting MIB space, although users will prefer to use the
soon-to-be-added ddb(8) tool for usability reasons.
Scripts with certain names are automatically executed on various DDB
events, such as entering the debugger via a panic, a witness error,
watchdog, breakpoint, sysctl, serial break, etc, allowing customized
handling.
MFC after: 3 months
2007-12-26 09:33:19 +00:00
|
|
|
if (dopager)
|
|
|
|
db_disable_pager();
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
if (cmd->flag & CS_SET_DOT) {
|
|
|
|
/*
|
|
|
|
* If command changes dot, set dot to
|
|
|
|
* previous address displayed (if 'ed' style).
|
|
|
|
*/
|
|
|
|
if (db_ed_style) {
|
|
|
|
db_dot = db_prev;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
db_dot = db_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* If command does not change dot,
|
|
|
|
* set 'next' location to be the same.
|
|
|
|
*/
|
|
|
|
db_next = db_dot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-02-13 02:19:29 +00:00
|
|
|
/*
|
|
|
|
* At least one non-optional command must be implemented using
|
|
|
|
* DB_COMMAND() so that db_cmd_set gets created. Here is one.
|
|
|
|
*/
|
|
|
|
DB_COMMAND(panic, db_panic)
|
1995-02-05 21:09:04 +00:00
|
|
|
{
|
2006-07-19 18:26:53 +00:00
|
|
|
db_disable_pager();
|
1995-03-19 14:29:26 +00:00
|
|
|
panic("from debugger");
|
1995-02-05 21:09:04 +00:00
|
|
|
}
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
void
|
2014-10-12 18:01:52 +00:00
|
|
|
db_command_loop(void)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Initialize 'prev' and 'next' to dot.
|
|
|
|
*/
|
|
|
|
db_prev = db_dot;
|
|
|
|
db_next = db_dot;
|
|
|
|
|
|
|
|
db_cmd_loop_done = 0;
|
|
|
|
while (!db_cmd_loop_done) {
|
|
|
|
if (db_print_position() != 0)
|
|
|
|
db_printf("\n");
|
|
|
|
|
|
|
|
db_printf("db> ");
|
|
|
|
(void) db_read_line();
|
|
|
|
|
2008-09-15 22:45:14 +00:00
|
|
|
db_command(&db_last_command, &db_cmd_table, /* dopager */ 1);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add a simple scripting facility to DDB(4), allowing the user to
define a set of named scripts. Each script consists of a list of DDB
commands separated by ";"s that will be executed verbatim. No higher
level language constructs, such as branching, are provided for:
scripts are executed by sequentially injecting commands into the DDB
input buffer.
Four new commands are present in DDB: "run" to run a specific script,
"script" to define or print a script, "scripts" to list currently
defined scripts, and "unscript" to delete a script, modeled on shell
alias commands. Scripts may also be manipulated using sysctls in the
debug.ddb.scripting MIB space, although users will prefer to use the
soon-to-be-added ddb(8) tool for usability reasons.
Scripts with certain names are automatically executed on various DDB
events, such as entering the debugger via a panic, a witness error,
watchdog, breakpoint, sysctl, serial break, etc, allowing customized
handling.
MFC after: 3 months
2007-12-26 09:33:19 +00:00
|
|
|
/*
|
|
|
|
* Execute a command on behalf of a script. The caller is responsible for
|
|
|
|
* making sure that the command string is < DB_MAXLINE or it will be
|
|
|
|
* truncated.
|
|
|
|
*
|
|
|
|
* XXXRW: Runs by injecting faked input into DDB input stream; it would be
|
|
|
|
* nicer to use an alternative approach that didn't mess with the previous
|
|
|
|
* command buffer.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
db_command_script(const char *command)
|
|
|
|
{
|
|
|
|
db_prev = db_next = db_dot;
|
|
|
|
db_inject_line(command);
|
2008-09-15 22:45:14 +00:00
|
|
|
db_command(&db_last_command, &db_cmd_table, /* dopager */ 0);
|
Add a simple scripting facility to DDB(4), allowing the user to
define a set of named scripts. Each script consists of a list of DDB
commands separated by ";"s that will be executed verbatim. No higher
level language constructs, such as branching, are provided for:
scripts are executed by sequentially injecting commands into the DDB
input buffer.
Four new commands are present in DDB: "run" to run a specific script,
"script" to define or print a script, "scripts" to list currently
defined scripts, and "unscript" to delete a script, modeled on shell
alias commands. Scripts may also be manipulated using sysctls in the
debug.ddb.scripting MIB space, although users will prefer to use the
soon-to-be-added ddb(8) tool for usability reasons.
Scripts with certain names are automatically executed on various DDB
events, such as entering the debugger via a panic, a witness error,
watchdog, breakpoint, sysctl, serial break, etc, allowing customized
handling.
MFC after: 3 months
2007-12-26 09:33:19 +00:00
|
|
|
}
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
void
|
2014-10-12 18:01:52 +00:00
|
|
|
db_error(const char *s)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
if (s)
|
2001-07-19 02:05:00 +00:00
|
|
|
db_printf("%s", s);
|
1993-06-12 14:58:17 +00:00
|
|
|
db_flush_lex();
|
2004-07-10 23:47:20 +00:00
|
|
|
kdb_reenter();
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
2011-06-07 01:28:12 +00:00
|
|
|
static void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_dump(db_expr_t dummy, bool dummy2, db_expr_t dummy3, char *dummy4)
|
2011-06-07 01:28:12 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2012-11-01 04:07:08 +00:00
|
|
|
if (textdump_pending) {
|
|
|
|
db_printf("textdump_pending set.\n"
|
|
|
|
"run \"textdump unset\" first or \"textdump dump\" for a textdump.\n");
|
|
|
|
return;
|
|
|
|
}
|
2015-05-18 22:27:46 +00:00
|
|
|
error = doadump(false);
|
2011-06-07 01:28:12 +00:00
|
|
|
if (error) {
|
|
|
|
db_printf("Cannot dump: ");
|
|
|
|
switch (error) {
|
|
|
|
case EBUSY:
|
|
|
|
db_printf("debugger got invoked while dumping.\n");
|
|
|
|
break;
|
|
|
|
case ENXIO:
|
|
|
|
db_printf("no dump device specified.\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
db_printf("unknown error (error=%d).\n", error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call random function:
|
|
|
|
* !expr(arg,arg,arg)
|
|
|
|
*/
|
2005-07-02 23:52:37 +00:00
|
|
|
|
|
|
|
/* The generic implementation supports a maximum of 10 arguments. */
|
|
|
|
typedef db_expr_t __db_f(db_expr_t, db_expr_t, db_expr_t, db_expr_t,
|
|
|
|
db_expr_t, db_expr_t, db_expr_t, db_expr_t, db_expr_t, db_expr_t);
|
|
|
|
|
|
|
|
static __inline int
|
|
|
|
db_fncall_generic(db_expr_t addr, db_expr_t *rv, int nargs, db_expr_t args[])
|
|
|
|
{
|
|
|
|
__db_f *f = (__db_f *)addr;
|
|
|
|
|
|
|
|
if (nargs > 10) {
|
|
|
|
db_printf("Too many arguments (max 10)\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
*rv = (*f)(args[0], args[1], args[2], args[3], args[4], args[5],
|
|
|
|
args[6], args[7], args[8], args[9]);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1995-11-29 10:25:50 +00:00
|
|
|
static void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_fncall(db_expr_t dummy1, bool dummy2, db_expr_t dummy3, char *dummy4)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
db_expr_t fn_addr;
|
2005-07-02 23:52:37 +00:00
|
|
|
db_expr_t args[DB_MAXARGS];
|
1993-06-12 14:58:17 +00:00
|
|
|
int nargs = 0;
|
|
|
|
db_expr_t retval;
|
|
|
|
int t;
|
|
|
|
|
|
|
|
if (!db_expression(&fn_addr)) {
|
|
|
|
db_printf("Bad function\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = db_read_token();
|
|
|
|
if (t == tLPAREN) {
|
|
|
|
if (db_expression(&args[0])) {
|
|
|
|
nargs++;
|
|
|
|
while ((t = db_read_token()) == tCOMMA) {
|
2005-07-02 23:52:37 +00:00
|
|
|
if (nargs == DB_MAXARGS) {
|
|
|
|
db_printf("Too many arguments (max %d)\n", DB_MAXARGS);
|
1993-06-12 14:58:17 +00:00
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!db_expression(&args[nargs])) {
|
|
|
|
db_printf("Argument missing\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nargs++;
|
|
|
|
}
|
|
|
|
db_unread_token(t);
|
|
|
|
}
|
|
|
|
if (db_read_token() != tRPAREN) {
|
2017-07-06 12:30:39 +00:00
|
|
|
db_printf("Mismatched parens\n");
|
1993-06-12 14:58:17 +00:00
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
db_skip_to_eol();
|
2006-07-19 18:26:53 +00:00
|
|
|
db_disable_pager();
|
1993-06-12 14:58:17 +00:00
|
|
|
|
2005-07-02 23:52:37 +00:00
|
|
|
if (DB_CALL(fn_addr, &retval, nargs, args))
|
|
|
|
db_printf("= %#lr\n", (long)retval);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
1996-08-27 19:46:28 +00:00
|
|
|
|
2006-10-10 07:26:54 +00:00
|
|
|
static void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_halt(db_expr_t dummy, bool dummy2, db_expr_t dummy3, char *dummy4)
|
2006-10-10 07:26:54 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
cpu_halt();
|
|
|
|
}
|
|
|
|
|
2001-11-27 19:56:28 +00:00
|
|
|
static void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_kill(db_expr_t dummy1, bool dummy2, db_expr_t dummy3, char *dummy4)
|
2001-11-27 19:56:28 +00:00
|
|
|
{
|
|
|
|
db_expr_t old_radix, pid, sig;
|
|
|
|
struct proc *p;
|
|
|
|
|
2014-10-11 20:25:19 +00:00
|
|
|
#define DB_ERROR(f) do { db_printf f; db_flush_lex(); goto out; } while (0)
|
2001-11-27 19:56:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PIDs and signal numbers are typically represented in base
|
|
|
|
* 10, so make that the default here. It can, of course, be
|
|
|
|
* overridden by specifying a prefix.
|
|
|
|
*/
|
|
|
|
old_radix = db_radix;
|
|
|
|
db_radix = 10;
|
|
|
|
/* Retrieve arguments. */
|
|
|
|
if (!db_expression(&sig))
|
|
|
|
DB_ERROR(("Missing signal number\n"));
|
|
|
|
if (!db_expression(&pid))
|
|
|
|
DB_ERROR(("Missing process ID\n"));
|
|
|
|
db_skip_to_eol();
|
2010-07-12 10:18:10 +00:00
|
|
|
if (!_SIG_VALID(sig))
|
2001-11-27 19:56:28 +00:00
|
|
|
DB_ERROR(("Signal number out of range\n"));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the process in question. allproc_lock is not needed
|
|
|
|
* since we're in DDB.
|
|
|
|
*/
|
|
|
|
/* sx_slock(&allproc_lock); */
|
2007-01-17 15:05:52 +00:00
|
|
|
FOREACH_PROC_IN_SYSTEM(p)
|
2001-11-27 19:56:28 +00:00
|
|
|
if (p->p_pid == pid)
|
|
|
|
break;
|
|
|
|
/* sx_sunlock(&allproc_lock); */
|
|
|
|
if (p == NULL)
|
2002-01-17 02:14:44 +00:00
|
|
|
DB_ERROR(("Can't find process with pid %ld\n", (long) pid));
|
2001-11-27 19:56:28 +00:00
|
|
|
|
|
|
|
/* If it's already locked, bail; otherwise, do the deed. */
|
|
|
|
if (PROC_TRYLOCK(p) == 0)
|
2002-01-17 02:14:44 +00:00
|
|
|
DB_ERROR(("Can't lock process with pid %ld\n", (long) pid));
|
2001-11-27 19:56:28 +00:00
|
|
|
else {
|
Among signal generation syscalls, only sigqueue(2) is allowed by POSIX
to fail due to lack of resources to queue siginfo. Add KSI_SIGQ flag
that allows sigqueue_add() to fail while trying to allocate memory for
new siginfo. When the flag is not set, behaviour is the same as for
KSI_TRAP: if memory cannot be allocated, set bit in sq_kill. KSI_TRAP is
kept to preserve KBI.
Add SI_KERNEL si_code, to be used in siginfo.si_code when signal is
generated by kernel. Deliver siginfo when signal is generated by kill(2)
family of syscalls (SI_USER with properly filled si_uid and si_pid), or
by kernel (SI_KERNEL, mostly job control or SIGIO). Since KSI_SIGQ flag
is not set for the ksi, low memory condition cause old behaviour.
Keep psignal(9) KBI intact, but modify it to generate SI_KERNEL
si_code. Pgsignal(9) and gsignal(9) now take ksi explicitely. Add
pksignal(9) that behaves like psignal but takes ksi, and ddb kill
command implemented as pksignal(..., ksi = NULL) to not do allocation
while in debugger.
While there, remove some register specifiers and use ANSI C prototypes.
Reviewed by: davidxu
MFC after: 1 month
2009-11-17 11:39:15 +00:00
|
|
|
pksignal(p, sig, NULL);
|
2001-11-27 19:56:28 +00:00
|
|
|
PROC_UNLOCK(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
db_radix = old_radix;
|
|
|
|
#undef DB_ERROR
|
|
|
|
}
|
|
|
|
|
2010-05-24 16:41:05 +00:00
|
|
|
/*
|
|
|
|
* Reboot. In case there is an additional argument, take it as delay in
|
|
|
|
* seconds. Default to 15s if we cannot parse it and make sure we will
|
|
|
|
* never wait longer than 1 week. Some code is similar to
|
|
|
|
* kern_shutdown.c:shutdown_panic().
|
|
|
|
*/
|
|
|
|
#ifndef DB_RESET_MAXDELAY
|
|
|
|
#define DB_RESET_MAXDELAY (3600 * 24 * 7)
|
|
|
|
#endif
|
|
|
|
|
2001-11-03 04:55:48 +00:00
|
|
|
static void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_reset(db_expr_t addr, bool have_addr, db_expr_t count __unused,
|
2010-05-24 16:41:05 +00:00
|
|
|
char *modif __unused)
|
2001-11-03 04:55:48 +00:00
|
|
|
{
|
2010-05-24 16:41:05 +00:00
|
|
|
int delay, loop;
|
|
|
|
|
|
|
|
if (have_addr) {
|
|
|
|
delay = (int)db_hex2dec(addr);
|
|
|
|
|
|
|
|
/* If we parse to fail, use 15s. */
|
|
|
|
if (delay == -1)
|
|
|
|
delay = 15;
|
|
|
|
|
|
|
|
/* Cap at one week. */
|
|
|
|
if ((uintmax_t)delay > (uintmax_t)DB_RESET_MAXDELAY)
|
|
|
|
delay = DB_RESET_MAXDELAY;
|
|
|
|
|
|
|
|
db_printf("Automatic reboot in %d seconds - "
|
|
|
|
"press a key on the console to abort\n", delay);
|
|
|
|
for (loop = delay * 10; loop > 0; --loop) {
|
|
|
|
DELAY(1000 * 100); /* 1/10th second */
|
|
|
|
/* Did user type a key? */
|
|
|
|
if (cncheckc() != -1)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-11-03 04:55:48 +00:00
|
|
|
|
|
|
|
cpu_reset();
|
|
|
|
}
|
2004-02-29 09:55:32 +00:00
|
|
|
|
|
|
|
static void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_watchdog(db_expr_t dummy1, bool dummy2, db_expr_t dummy3, char *dummy4)
|
2004-02-29 09:55:32 +00:00
|
|
|
{
|
2011-04-05 14:15:58 +00:00
|
|
|
db_expr_t old_radix, tout;
|
|
|
|
int err, i;
|
2004-02-29 09:55:32 +00:00
|
|
|
|
2011-04-05 14:15:58 +00:00
|
|
|
old_radix = db_radix;
|
|
|
|
db_radix = 10;
|
|
|
|
err = db_expression(&tout);
|
|
|
|
db_skip_to_eol();
|
|
|
|
db_radix = old_radix;
|
|
|
|
|
|
|
|
/* If no argument is provided the watchdog will just be disabled. */
|
|
|
|
if (err == 0) {
|
|
|
|
db_printf("No argument provided, disabling watchdog\n");
|
|
|
|
tout = 0;
|
|
|
|
} else if ((tout & WD_INTERVAL) == WD_TO_NEVER) {
|
|
|
|
db_error("Out of range watchdog interval\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EVENTHANDLER_INVOKE(watchdog_list, tout, &i);
|
2004-02-29 09:55:32 +00:00
|
|
|
}
|
2004-07-12 01:38:07 +00:00
|
|
|
|
|
|
|
static void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_gdb(db_expr_t dummy1, bool dummy2, db_expr_t dummy3, char *dummy4)
|
2004-07-12 01:38:07 +00:00
|
|
|
{
|
|
|
|
|
2011-02-18 22:25:11 +00:00
|
|
|
if (kdb_dbbe_select("gdb") != 0) {
|
2004-07-12 01:38:07 +00:00
|
|
|
db_printf("The remote GDB backend could not be selected.\n");
|
2011-02-18 22:25:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Mark that we are done in the debugger. kdb_trap()
|
|
|
|
* should re-enter with the new backend.
|
|
|
|
*/
|
|
|
|
db_cmd_loop_done = 1;
|
|
|
|
db_printf("(ctrl-c will return control to ddb)\n");
|
2004-07-12 01:38:07 +00:00
|
|
|
}
|
2004-07-21 05:07:09 +00:00
|
|
|
|
|
|
|
static void
|
2015-05-21 15:16:18 +00:00
|
|
|
db_stack_trace(db_expr_t tid, bool hastid, db_expr_t count, char *modif)
|
2004-07-21 05:07:09 +00:00
|
|
|
{
|
|
|
|
struct thread *td;
|
|
|
|
db_expr_t radix;
|
2004-11-23 23:11:47 +00:00
|
|
|
pid_t pid;
|
2004-07-21 05:07:09 +00:00
|
|
|
int t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We parse our own arguments. We don't like the default radix.
|
|
|
|
*/
|
|
|
|
radix = db_radix;
|
|
|
|
db_radix = 10;
|
|
|
|
hastid = db_expression(&tid);
|
|
|
|
t = db_read_token();
|
|
|
|
if (t == tCOMMA) {
|
|
|
|
if (!db_expression(&count)) {
|
|
|
|
db_printf("Count missing\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
db_unread_token(t);
|
|
|
|
count = -1;
|
|
|
|
}
|
|
|
|
db_skip_to_eol();
|
|
|
|
db_radix = radix;
|
|
|
|
|
|
|
|
if (hastid) {
|
|
|
|
td = kdb_thr_lookup((lwpid_t)tid);
|
|
|
|
if (td == NULL)
|
|
|
|
td = kdb_thr_from_pid((pid_t)tid);
|
|
|
|
if (td == NULL) {
|
|
|
|
db_printf("Thread %d not found\n", (int)tid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
td = kdb_thread;
|
2004-11-23 23:11:47 +00:00
|
|
|
if (td->td_proc != NULL)
|
|
|
|
pid = td->td_proc->p_pid;
|
|
|
|
else
|
|
|
|
pid = -1;
|
|
|
|
db_printf("Tracing pid %d tid %ld td %p\n", pid, (long)td->td_tid, td);
|
2004-07-21 05:07:09 +00:00
|
|
|
db_trace_thread(td, count);
|
|
|
|
}
|
2005-10-02 11:41:12 +00:00
|
|
|
|
|
|
|
static void
|
2016-08-26 02:46:47 +00:00
|
|
|
_db_stack_trace_all(bool active_only)
|
2005-10-02 11:41:12 +00:00
|
|
|
{
|
|
|
|
struct proc *p;
|
|
|
|
struct thread *td;
|
2006-11-02 11:47:38 +00:00
|
|
|
jmp_buf jb;
|
|
|
|
void *prev_jb;
|
2005-10-02 11:41:12 +00:00
|
|
|
|
2007-01-17 15:05:52 +00:00
|
|
|
FOREACH_PROC_IN_SYSTEM(p) {
|
2006-11-02 11:47:38 +00:00
|
|
|
prev_jb = kdb_jmpbuf(jb);
|
|
|
|
if (setjmp(jb) == 0) {
|
|
|
|
FOREACH_THREAD_IN_PROC(p, td) {
|
2016-08-26 02:46:47 +00:00
|
|
|
if (td->td_state == TDS_RUNNING)
|
|
|
|
db_printf("\nTracing command %s pid %d"
|
|
|
|
" tid %ld td %p (CPU %d)\n",
|
|
|
|
p->p_comm, p->p_pid,
|
|
|
|
(long)td->td_tid, td,
|
|
|
|
td->td_oncpu);
|
|
|
|
else if (active_only)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
db_printf("\nTracing command %s pid %d"
|
|
|
|
" tid %ld td %p\n", p->p_comm,
|
|
|
|
p->p_pid, (long)td->td_tid, td);
|
2006-11-02 11:47:38 +00:00
|
|
|
db_trace_thread(td, -1);
|
|
|
|
if (db_pager_quit) {
|
|
|
|
kdb_jmpbuf(prev_jb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2005-10-02 11:41:12 +00:00
|
|
|
}
|
2006-11-02 11:47:38 +00:00
|
|
|
kdb_jmpbuf(prev_jb);
|
2005-10-02 11:41:12 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-24 16:41:05 +00:00
|
|
|
|
2016-08-26 02:46:47 +00:00
|
|
|
static void
|
|
|
|
db_stack_trace_active(db_expr_t dummy, bool dummy2, db_expr_t dummy3,
|
|
|
|
char *dummy4)
|
|
|
|
{
|
|
|
|
|
|
|
|
_db_stack_trace_all(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
db_stack_trace_all(db_expr_t dummy, bool dummy2, db_expr_t dummy3,
|
|
|
|
char *dummy4)
|
|
|
|
{
|
|
|
|
|
|
|
|
_db_stack_trace_all(false);
|
|
|
|
}
|
|
|
|
|
2010-05-24 16:41:05 +00:00
|
|
|
/*
|
|
|
|
* Take the parsed expression value from the command line that was parsed
|
|
|
|
* as a hexadecimal value and convert it as if the expression was parsed
|
|
|
|
* as a decimal value. Returns -1 if the expression was not a valid
|
|
|
|
* decimal value.
|
|
|
|
*/
|
|
|
|
db_expr_t
|
|
|
|
db_hex2dec(db_expr_t expr)
|
|
|
|
{
|
|
|
|
uintptr_t x, y;
|
|
|
|
db_expr_t val;
|
|
|
|
|
|
|
|
y = 1;
|
|
|
|
val = 0;
|
|
|
|
x = expr;
|
|
|
|
while (x != 0) {
|
|
|
|
if (x % 16 > 9)
|
|
|
|
return (-1);
|
|
|
|
val += (x % 16) * (y);
|
|
|
|
x >>= 4;
|
|
|
|
y *= 10;
|
|
|
|
}
|
|
|
|
return (val);
|
|
|
|
}
|