2001-08-17 05:00:10 +04:00
|
|
|
/* $NetBSD: db_command.c,v 1.62 2001/08/17 01:00:10 thorpej Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Mach Operating System
|
|
|
|
* Copyright (c) 1991,1990 Carnegie Mellon University
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
1999-04-13 00:38:17 +04:00
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
1993-03-21 12:45:37 +03:00
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
1993-08-02 21:48:44 +04:00
|
|
|
|
1998-07-05 18:33:56 +04:00
|
|
|
#include "opt_ddb.h"
|
2000-05-20 07:08:41 +04:00
|
|
|
#include "opt_inet.h"
|
1998-02-10 17:08:44 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Command dispatcher.
|
|
|
|
*/
|
1993-12-18 07:46:25 +03:00
|
|
|
#include <sys/param.h>
|
1996-03-07 17:33:39 +03:00
|
|
|
#include <sys/systm.h>
|
1997-09-11 10:55:56 +04:00
|
|
|
#include <sys/reboot.h>
|
1993-12-18 07:46:25 +03:00
|
|
|
#include <sys/proc.h>
|
2000-04-10 06:22:13 +04:00
|
|
|
#include <sys/vnode.h>
|
1999-05-11 01:13:05 +04:00
|
|
|
#include <sys/pool.h>
|
2000-11-24 10:25:50 +03:00
|
|
|
#include <sys/namei.h>
|
2001-08-17 05:00:10 +04:00
|
|
|
#include <sys/malloc.h>
|
1993-12-18 07:46:25 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <machine/db_machdep.h> /* type definitions */
|
|
|
|
|
2001-05-30 15:40:35 +04:00
|
|
|
#if defined(_KERNEL_OPT)
|
2000-02-21 08:48:56 +03:00
|
|
|
#include "opt_multiprocessor.h"
|
|
|
|
#endif
|
|
|
|
#ifdef MULTIPROCESSOR
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#endif
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <ddb/db_lex.h>
|
|
|
|
#include <ddb/db_output.h>
|
1994-03-23 23:00:56 +03:00
|
|
|
#include <ddb/db_command.h>
|
1996-02-05 04:56:47 +03:00
|
|
|
#include <ddb/db_break.h>
|
|
|
|
#include <ddb/db_watch.h>
|
|
|
|
#include <ddb/db_run.h>
|
|
|
|
#include <ddb/db_variables.h>
|
|
|
|
#include <ddb/db_interface.h>
|
|
|
|
#include <ddb/db_sym.h>
|
|
|
|
#include <ddb/db_extern.h>
|
|
|
|
|
1998-02-05 10:59:28 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
1998-07-05 02:18:13 +04:00
|
|
|
#include <uvm/uvm_ddb.h>
|
1998-02-05 10:59:28 +03:00
|
|
|
|
2000-06-09 01:06:46 +04:00
|
|
|
#include "arp.h"
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Exported global variables
|
|
|
|
*/
|
|
|
|
boolean_t db_cmd_loop_done;
|
1996-02-13 20:39:01 +03:00
|
|
|
label_t *db_recover;
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
*/
|
|
|
|
boolean_t db_ed_style = TRUE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Utility routine - discard tokens through end-of-line.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
db_skip_to_eol()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search for command prefix.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
db_cmd_search(name, table, cmdp)
|
2001-01-17 22:50:03 +03:00
|
|
|
const char *name;
|
|
|
|
const struct db_command *table;
|
|
|
|
const struct db_command **cmdp; /* out */
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2001-01-17 22:50:03 +03:00
|
|
|
const struct db_command *cmd;
|
1994-03-23 23:00:56 +03:00
|
|
|
int result = CMD_NONE;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
for (cmd = table; cmd->name != 0; cmd++) {
|
2001-01-17 22:50:03 +03:00
|
|
|
const char *lp;
|
|
|
|
const char *rp;
|
2000-03-30 15:31:26 +04:00
|
|
|
int c;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
lp = name;
|
|
|
|
rp = cmd->name;
|
|
|
|
while ((c = *lp) == *rp) {
|
|
|
|
if (c == 0) {
|
|
|
|
/* complete match */
|
|
|
|
*cmdp = cmd;
|
|
|
|
return (CMD_UNIQUE);
|
|
|
|
}
|
|
|
|
lp++;
|
|
|
|
rp++;
|
|
|
|
}
|
|
|
|
if (c == 0) {
|
|
|
|
/* end of name, not end of command -
|
|
|
|
partial match */
|
|
|
|
if (result == CMD_FOUND) {
|
|
|
|
result = CMD_AMBIGUOUS;
|
|
|
|
/* but keep looking for a full match -
|
|
|
|
this lets us match single letters */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*cmdp = cmd;
|
|
|
|
result = CMD_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result == CMD_NONE) {
|
|
|
|
/* check for 'help' */
|
|
|
|
if (name[0] == 'h' && name[1] == 'e'
|
|
|
|
&& name[2] == 'l' && name[3] == 'p')
|
|
|
|
result = CMD_HELP;
|
|
|
|
}
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
db_cmd_list(table)
|
2001-01-17 22:50:03 +03:00
|
|
|
const struct db_command *table;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1999-11-03 02:53:31 +03:00
|
|
|
int i, j, w, columns, lines, width=0, items, numcmds;
|
2001-01-17 22:50:03 +03:00
|
|
|
const char *p;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1999-10-28 10:37:32 +04:00
|
|
|
for (numcmds = 0; table[numcmds].name != NULL; numcmds++) {
|
|
|
|
w = strlen(table[numcmds].name);
|
|
|
|
if (w > width)
|
|
|
|
width = w;
|
|
|
|
}
|
|
|
|
width = DB_NEXT_TAB(width);
|
|
|
|
items = 0;
|
|
|
|
|
|
|
|
columns = db_max_width / width;
|
|
|
|
if (columns == 0)
|
|
|
|
columns = 1;
|
|
|
|
lines = (numcmds + columns - 1) / columns;
|
|
|
|
for (i = 0; i < lines; i++) {
|
|
|
|
for (j = 0; j < columns; j++) {
|
|
|
|
p = table[j * lines + i].name;
|
|
|
|
if (p)
|
|
|
|
db_printf("%s", p);
|
|
|
|
if (j * lines + i + lines >= numcmds) {
|
|
|
|
db_putchar('\n');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
w = strlen(p);
|
|
|
|
while (w < width) {
|
|
|
|
w = DB_NEXT_TAB(w);
|
|
|
|
db_putchar('\t');
|
|
|
|
}
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
db_command(last_cmdp, cmd_table)
|
2001-01-17 22:50:03 +03:00
|
|
|
const struct db_command **last_cmdp; /* IN_OUT */
|
|
|
|
const struct db_command *cmd_table;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2001-01-17 22:50:03 +03:00
|
|
|
const struct db_command *cmd;
|
1993-03-21 12:45:37 +03:00
|
|
|
int t;
|
|
|
|
char modif[TOK_STRING_SIZE];
|
|
|
|
db_expr_t addr, count;
|
1996-02-05 04:56:47 +03:00
|
|
|
boolean_t have_addr = FALSE;
|
1993-03-21 12:45:37 +03:00
|
|
|
int result;
|
|
|
|
|
2000-04-14 02:48:29 +04:00
|
|
|
static db_expr_t last_count = 0;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
t = db_read_token();
|
2000-04-14 02:48:29 +04:00
|
|
|
if ((t == tEOL) || (t == tCOMMA)) {
|
|
|
|
/*
|
|
|
|
* An empty line repeats last command, at 'next'.
|
|
|
|
* Only a count repeats the last command with the new count.
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
cmd = *last_cmdp;
|
|
|
|
addr = (db_expr_t)db_next;
|
2000-04-14 02:48:29 +04:00
|
|
|
if (t == tCOMMA) {
|
|
|
|
if (!db_expression(&count)) {
|
2000-06-17 09:57:41 +04:00
|
|
|
db_printf("Count missing\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
2000-04-14 02:48:29 +04:00
|
|
|
} else
|
2000-06-17 09:57:41 +04:00
|
|
|
count = last_count;
|
1993-03-21 12:45:37 +03:00
|
|
|
have_addr = FALSE;
|
|
|
|
modif[0] = '\0';
|
2000-06-17 09:57:41 +04:00
|
|
|
db_skip_to_eol();
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
else if (t == tEXCL) {
|
1996-02-05 04:56:47 +03:00
|
|
|
db_fncall(0, 0, 0, NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (t != tIDENT) {
|
|
|
|
db_printf("?\n");
|
|
|
|
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:
|
|
|
|
db_printf("No such command\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
case CMD_AMBIGUOUS:
|
|
|
|
db_printf("Ambiguous\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
case CMD_HELP:
|
|
|
|
db_cmd_list(cmd_table);
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((cmd_table = cmd->more) != 0) {
|
|
|
|
t = db_read_token();
|
|
|
|
if (t != tIDENT) {
|
|
|
|
db_cmd_list(cmd_table);
|
|
|
|
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;
|
|
|
|
have_addr = TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addr = (db_expr_t) db_dot;
|
|
|
|
have_addr = FALSE;
|
|
|
|
}
|
|
|
|
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;
|
2000-04-14 02:48:29 +04:00
|
|
|
last_count = count;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (cmd != 0) {
|
|
|
|
/*
|
|
|
|
* Execute the command.
|
|
|
|
*/
|
|
|
|
(*cmd->fcn)(addr, have_addr, count, modif);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-07-15 22:35:00 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
db_map_print_cmd(addr, have_addr, count, modif)
|
|
|
|
db_expr_t addr;
|
|
|
|
int have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char * modif;
|
|
|
|
{
|
|
|
|
boolean_t full = FALSE;
|
|
|
|
|
|
|
|
if (modif[0] == 'f')
|
|
|
|
full = TRUE;
|
|
|
|
|
2001-06-03 04:32:25 +04:00
|
|
|
if (have_addr == FALSE)
|
|
|
|
addr = (db_expr_t) kernel_map;
|
|
|
|
|
2001-06-02 22:09:08 +04:00
|
|
|
uvm_map_printit((struct vm_map *) addr, full, db_printf);
|
1993-07-15 22:35:00 +04:00
|
|
|
}
|
|
|
|
|
2001-08-17 05:00:10 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
db_malloc_print_cmd(addr, have_addr, count, modif)
|
|
|
|
db_expr_t addr;
|
|
|
|
int have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char * modif;
|
|
|
|
{
|
|
|
|
#ifdef MALLOC_DEBUG
|
|
|
|
if (!have_addr)
|
|
|
|
addr = 0;
|
|
|
|
|
|
|
|
debug_malloc_printit(db_printf, (vaddr_t) addr);
|
|
|
|
#else
|
|
|
|
db_printf("The kernel is not built with the MALLOC_DEBUG option.\n");
|
|
|
|
#endif /* MALLOC_DEBUG */
|
|
|
|
}
|
|
|
|
|
1993-07-15 22:35:00 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
db_object_print_cmd(addr, have_addr, count, modif)
|
|
|
|
db_expr_t addr;
|
|
|
|
int have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char * modif;
|
|
|
|
{
|
|
|
|
boolean_t full = FALSE;
|
|
|
|
|
|
|
|
if (modif[0] == 'f')
|
|
|
|
full = TRUE;
|
|
|
|
|
1998-02-05 10:59:28 +03:00
|
|
|
uvm_object_printit((struct uvm_object *) addr, full, db_printf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
db_page_print_cmd(addr, have_addr, count, modif)
|
|
|
|
db_expr_t addr;
|
|
|
|
int have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char * modif;
|
|
|
|
{
|
|
|
|
boolean_t full = FALSE;
|
|
|
|
|
|
|
|
if (modif[0] == 'f')
|
|
|
|
full = TRUE;
|
|
|
|
|
|
|
|
uvm_page_printit((struct vm_page *) addr, full, db_printf);
|
1993-07-15 22:35:00 +04:00
|
|
|
}
|
|
|
|
|
2000-04-10 06:22:13 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
db_buf_print_cmd(addr, have_addr, count, modif)
|
|
|
|
db_expr_t addr;
|
|
|
|
int have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char * modif;
|
|
|
|
{
|
|
|
|
boolean_t full = FALSE;
|
|
|
|
|
|
|
|
if (modif[0] == 'f')
|
|
|
|
full = TRUE;
|
|
|
|
|
|
|
|
vfs_buf_print((struct buf *)addr, full, db_printf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
db_vnode_print_cmd(addr, have_addr, count, modif)
|
|
|
|
db_expr_t addr;
|
|
|
|
int have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char * modif;
|
|
|
|
{
|
|
|
|
boolean_t full = FALSE;
|
|
|
|
|
|
|
|
if (modif[0] == 'f')
|
|
|
|
full = TRUE;
|
|
|
|
|
|
|
|
vfs_vnode_print((struct vnode *)addr, full, db_printf);
|
|
|
|
}
|
|
|
|
|
1999-05-11 01:13:05 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
db_pool_print_cmd(addr, have_addr, count, modif)
|
|
|
|
db_expr_t addr;
|
|
|
|
int have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char * modif;
|
|
|
|
{
|
2000-11-24 10:25:50 +03:00
|
|
|
pool_printit((struct pool *)addr, modif, db_printf);
|
|
|
|
}
|
1999-05-11 01:13:05 +04:00
|
|
|
|
2000-11-24 10:25:50 +03:00
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
db_namecache_print_cmd(addr, have_addr, count, modif)
|
|
|
|
db_expr_t addr;
|
|
|
|
int have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char * modif;
|
|
|
|
{
|
|
|
|
namecache_print((struct vnode *)addr, db_printf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
|
|
|
db_uvmexp_print_cmd(addr, have_addr, count, modif)
|
|
|
|
db_expr_t addr;
|
|
|
|
int have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char * modif;
|
|
|
|
{
|
|
|
|
uvmexp_print(db_printf);
|
1999-05-11 01:13:05 +04:00
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* 'show' commands
|
|
|
|
*/
|
|
|
|
|
2001-01-17 22:50:03 +03:00
|
|
|
static const struct db_command db_show_all_cmds[] = {
|
1996-02-05 04:56:47 +03:00
|
|
|
{ "callout", db_show_callout, 0, NULL },
|
1999-10-28 10:37:32 +04:00
|
|
|
{ "procs", db_show_all_procs, 0, NULL },
|
1996-02-05 04:56:47 +03:00
|
|
|
{ NULL, NULL, 0, NULL }
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
2001-01-17 22:50:03 +03:00
|
|
|
static const struct db_command db_show_cmds[] = {
|
1996-02-05 04:56:47 +03:00
|
|
|
{ "all", NULL, 0, db_show_all_cmds },
|
2000-06-09 01:06:46 +04:00
|
|
|
#if defined(INET) && (NARP > 0)
|
2000-05-20 07:08:41 +04:00
|
|
|
{ "arptab", db_show_arptab, 0, NULL },
|
|
|
|
#endif
|
1996-02-05 04:56:47 +03:00
|
|
|
{ "breaks", db_listbreak_cmd, 0, NULL },
|
2001-02-12 00:12:24 +03:00
|
|
|
{ "buf", db_buf_print_cmd, 0, NULL },
|
1996-02-05 04:56:47 +03:00
|
|
|
{ "map", db_map_print_cmd, 0, NULL },
|
2001-02-12 00:12:24 +03:00
|
|
|
{ "ncache", db_namecache_print_cmd, 0, NULL },
|
1996-02-05 04:56:47 +03:00
|
|
|
{ "object", db_object_print_cmd, 0, NULL },
|
1998-02-05 10:59:28 +03:00
|
|
|
{ "page", db_page_print_cmd, 0, NULL },
|
1999-05-11 01:13:05 +04:00
|
|
|
{ "pool", db_pool_print_cmd, 0, NULL },
|
1999-10-28 10:37:32 +04:00
|
|
|
{ "registers", db_show_regs, 0, NULL },
|
2001-02-12 00:12:24 +03:00
|
|
|
{ "uvmexp", db_uvmexp_print_cmd, 0, NULL },
|
|
|
|
{ "vnode", db_vnode_print_cmd, 0, NULL },
|
1999-10-28 10:37:32 +04:00
|
|
|
{ "watches", db_listwatch_cmd, 0, NULL },
|
2001-08-17 05:00:10 +04:00
|
|
|
{ "malloc", db_malloc_print_cmd, 0, NULL },
|
1999-10-28 10:37:32 +04:00
|
|
|
{ NULL, NULL, 0, NULL }
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
2001-01-24 23:54:41 +03:00
|
|
|
static const struct db_command db_command_table[] = {
|
1999-10-28 10:37:32 +04:00
|
|
|
{ "break", db_breakpoint_cmd, 0, NULL },
|
|
|
|
{ "c", db_continue_cmd, 0, NULL },
|
|
|
|
{ "call", db_fncall, CS_OWN, NULL },
|
2000-11-28 22:27:46 +03:00
|
|
|
{ "callout", db_show_callout, 0, NULL },
|
1999-10-28 10:37:32 +04:00
|
|
|
{ "continue", db_continue_cmd, 0, NULL },
|
|
|
|
{ "d", db_delete_cmd, 0, NULL },
|
|
|
|
{ "delete", db_delete_cmd, 0, NULL },
|
2001-07-31 08:28:16 +04:00
|
|
|
{ "dmesg", db_dmesg, 0, NULL },
|
1999-10-28 10:37:32 +04:00
|
|
|
{ "dwatch", db_deletewatch_cmd, 0, NULL },
|
|
|
|
{ "examine", db_examine_cmd, CS_SET_DOT, NULL },
|
|
|
|
{ "kill", db_kill_proc, CS_OWN, NULL },
|
1993-09-13 18:08:54 +04:00
|
|
|
#ifdef DB_MACHINE_COMMANDS
|
2001-01-22 16:56:55 +03:00
|
|
|
{ "machine", NULL, 0, db_machine_command_table },
|
1993-09-13 18:08:54 +04:00
|
|
|
#endif
|
1999-10-28 10:37:32 +04:00
|
|
|
{ "match", db_trace_until_matching_cmd,0, NULL },
|
|
|
|
{ "next", db_trace_until_matching_cmd,0, NULL },
|
2000-05-15 23:56:43 +04:00
|
|
|
{ "p", db_print_cmd, 0, NULL },
|
1996-02-05 04:56:47 +03:00
|
|
|
{ "print", db_print_cmd, 0, NULL },
|
1999-10-28 10:37:32 +04:00
|
|
|
{ "ps", db_show_all_procs, 0, NULL },
|
|
|
|
{ "reboot", db_reboot_cmd, CS_OWN, NULL },
|
|
|
|
{ "s", db_single_step_cmd, 0, NULL },
|
1996-02-05 04:56:47 +03:00
|
|
|
{ "search", db_search_cmd, CS_OWN|CS_SET_DOT, NULL },
|
|
|
|
{ "set", db_set_cmd, CS_OWN, NULL },
|
1999-10-28 10:37:32 +04:00
|
|
|
{ "show", NULL, 0, db_show_cmds },
|
2000-05-22 18:49:10 +04:00
|
|
|
{ "sifting", db_sifting_cmd, CS_OWN, NULL },
|
1996-02-05 04:56:47 +03:00
|
|
|
{ "step", db_single_step_cmd, 0, NULL },
|
1999-10-28 10:37:32 +04:00
|
|
|
{ "sync", db_sync_cmd, CS_OWN, NULL },
|
1996-02-05 04:56:47 +03:00
|
|
|
{ "trace", db_stack_trace_cmd, 0, NULL },
|
1999-10-28 10:37:32 +04:00
|
|
|
{ "until", db_trace_until_call_cmd,0, NULL },
|
|
|
|
{ "w", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
|
|
|
|
{ "watch", db_watchpoint_cmd, CS_MORE, NULL },
|
|
|
|
{ "write", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
|
|
|
|
{ "x", db_examine_cmd, CS_SET_DOT, NULL },
|
1996-02-05 04:56:47 +03:00
|
|
|
{ NULL, NULL, 0, NULL }
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
2001-01-17 22:50:03 +03:00
|
|
|
const struct db_command *db_last_command = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
db_command_loop()
|
|
|
|
{
|
1996-02-13 20:39:01 +03:00
|
|
|
label_t db_jmpbuf;
|
|
|
|
label_t *savejmp;
|
1994-01-10 01:35:10 +03:00
|
|
|
extern int db_output_line;
|
1993-07-15 22:35:00 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Initialize 'prev' and 'next' to dot.
|
|
|
|
*/
|
|
|
|
db_prev = db_dot;
|
|
|
|
db_next = db_dot;
|
|
|
|
|
|
|
|
db_cmd_loop_done = 0;
|
1996-02-13 20:39:01 +03:00
|
|
|
|
|
|
|
savejmp = db_recover;
|
|
|
|
db_recover = &db_jmpbuf;
|
|
|
|
(void) setjmp(&db_jmpbuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-01-10 01:35:10 +03:00
|
|
|
while (!db_cmd_loop_done) {
|
|
|
|
if (db_print_position() != 0)
|
|
|
|
db_printf("\n");
|
|
|
|
db_output_line = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-05-28 23:03:55 +04:00
|
|
|
|
2000-02-21 08:48:56 +03:00
|
|
|
#ifdef MULTIPROCESSOR
|
2000-05-28 23:03:55 +04:00
|
|
|
db_printf("db{%ld}> ", (long)cpu_number());
|
|
|
|
#else
|
|
|
|
db_printf("db> ");
|
2000-02-21 08:48:56 +03:00
|
|
|
#endif
|
1994-01-10 01:35:10 +03:00
|
|
|
(void) db_read_line();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-01-10 01:35:10 +03:00
|
|
|
db_command(&db_last_command, db_command_table);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-01-10 01:35:10 +03:00
|
|
|
|
|
|
|
db_recover = savejmp;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
db_error(s)
|
|
|
|
char *s;
|
|
|
|
{
|
|
|
|
if (s)
|
2000-07-08 21:10:22 +04:00
|
|
|
db_printf("%s", s);
|
1993-03-21 12:45:37 +03:00
|
|
|
db_flush_lex();
|
1996-03-14 00:06:38 +03:00
|
|
|
longjmp(db_recover);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call random function:
|
|
|
|
* !expr(arg,arg,arg)
|
|
|
|
*/
|
1996-02-05 04:56:47 +03:00
|
|
|
/*ARGSUSED*/
|
1993-03-21 12:45:37 +03:00
|
|
|
void
|
1996-02-05 04:56:47 +03:00
|
|
|
db_fncall(addr, have_addr, count, modif)
|
|
|
|
db_expr_t addr;
|
|
|
|
int have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char * modif;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
db_expr_t fn_addr;
|
|
|
|
#define MAXARGS 11
|
|
|
|
db_expr_t args[MAXARGS];
|
|
|
|
int nargs = 0;
|
|
|
|
db_expr_t retval;
|
1996-02-05 04:56:47 +03:00
|
|
|
db_expr_t (*func) __P((db_expr_t, ...));
|
1993-03-21 12:45:37 +03:00
|
|
|
int t;
|
|
|
|
|
|
|
|
if (!db_expression(&fn_addr)) {
|
|
|
|
db_printf("Bad function\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
1996-02-05 04:56:47 +03:00
|
|
|
func = (db_expr_t (*) __P((db_expr_t, ...))) fn_addr;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
t = db_read_token();
|
|
|
|
if (t == tLPAREN) {
|
|
|
|
if (db_expression(&args[0])) {
|
|
|
|
nargs++;
|
|
|
|
while ((t = db_read_token()) == tCOMMA) {
|
|
|
|
if (nargs == MAXARGS) {
|
|
|
|
db_printf("Too many arguments\n");
|
|
|
|
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) {
|
|
|
|
db_printf("?\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
db_skip_to_eol();
|
|
|
|
|
|
|
|
while (nargs < MAXARGS) {
|
|
|
|
args[nargs++] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = (*func)(args[0], args[1], args[2], args[3], args[4],
|
1996-03-31 01:30:03 +03:00
|
|
|
args[5], args[6], args[7], args[8], args[9]);
|
2000-06-06 09:06:25 +04:00
|
|
|
db_printf("%s\n", db_num_to_str(retval));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-09-11 10:55:56 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
db_reboot_cmd(addr, have_addr, count, modif)
|
|
|
|
db_expr_t addr;
|
|
|
|
int have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char * modif;
|
|
|
|
{
|
|
|
|
db_expr_t bootflags;
|
|
|
|
|
|
|
|
/* Flags, default to RB_AUTOBOOT */
|
|
|
|
if (!db_expression(&bootflags))
|
|
|
|
bootflags = (db_expr_t)RB_AUTOBOOT;
|
|
|
|
if (db_read_token() != tEOL) {
|
|
|
|
db_error("?\n");
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
2000-06-10 20:31:42 +04:00
|
|
|
/*
|
|
|
|
* We are leaving DDB, never to return upward.
|
|
|
|
* Clear db_recover so that we can debug faults in functions
|
|
|
|
* called from cpu_reboot.
|
|
|
|
*/
|
|
|
|
db_recover = 0;
|
1997-09-11 10:55:56 +04:00
|
|
|
cpu_reboot((int)bootflags, NULL);
|
|
|
|
}
|
1999-10-28 10:37:32 +04:00
|
|
|
|
2000-05-22 18:49:10 +04:00
|
|
|
void
|
|
|
|
db_sifting_cmd(addr, have_addr, count, omodif)
|
|
|
|
db_expr_t addr;
|
|
|
|
int have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char * omodif;
|
|
|
|
{
|
|
|
|
int mode, t;
|
|
|
|
|
|
|
|
t = db_read_token();
|
|
|
|
if (t == tSLASH) {
|
|
|
|
t = db_read_token();
|
|
|
|
if (t != tIDENT) {
|
|
|
|
bad_modifier:
|
|
|
|
db_printf("Bad modifier\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!strcmp(db_tok_string, "F"))
|
|
|
|
mode = 'F';
|
|
|
|
else
|
|
|
|
goto bad_modifier;
|
|
|
|
t = db_read_token();
|
|
|
|
} else
|
|
|
|
mode = 0;
|
|
|
|
|
2000-11-24 10:25:50 +03:00
|
|
|
if (t == tIDENT)
|
2000-05-22 18:49:10 +04:00
|
|
|
db_sifting(db_tok_string, mode);
|
|
|
|
else {
|
|
|
|
db_printf("Bad argument (non-string)\n");
|
|
|
|
db_flush_lex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-26 07:34:24 +04:00
|
|
|
void
|
|
|
|
db_stack_trace_cmd(addr, have_addr, count, modif)
|
|
|
|
db_expr_t addr;
|
|
|
|
boolean_t have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char *modif;
|
|
|
|
{
|
|
|
|
if (count == -1)
|
|
|
|
count = 65535;
|
|
|
|
|
|
|
|
db_stack_trace_print(addr, have_addr, count, modif, db_printf);
|
|
|
|
}
|
|
|
|
|
1999-10-28 10:37:32 +04:00
|
|
|
void
|
|
|
|
db_sync_cmd(addr, have_addr, count, modif)
|
|
|
|
db_expr_t addr;
|
|
|
|
int have_addr;
|
|
|
|
db_expr_t count;
|
|
|
|
char * modif;
|
|
|
|
{
|
2000-06-10 20:31:42 +04:00
|
|
|
/*
|
|
|
|
* We are leaving DDB, never to return upward.
|
|
|
|
* Clear db_recover so that we can debug faults in functions
|
|
|
|
* called from cpu_reboot.
|
|
|
|
*/
|
|
|
|
db_recover = 0;
|
1999-10-28 10:37:32 +04:00
|
|
|
cpu_reboot(RB_DUMP, NULL);
|
|
|
|
}
|