Make ddb compile and work in userspace. Mostly this is comprised of three

types of changes:

- Add a few new methods to replace stuff like p_find(), CPU_INFO_FOREACH.

- Use db_read_bytes() instead of accessing kernel structures directly,
  and similar changes.

- Add ifdef _KERNEL where the above hasn't been done, and an XXX comment.
This commit is contained in:
ad 2009-03-07 22:02:16 +00:00
parent 09e83b297e
commit cd6b1c8f08
28 changed files with 997 additions and 382 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_disasm.c,v 1.37 2007/12/30 13:28:20 yamt Exp $ */ /* $NetBSD: db_disasm.c,v 1.38 2009/03/07 22:02:16 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -33,7 +33,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.37 2007/12/30 13:28:20 yamt Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.38 2009/03/07 22:02:16 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/proc.h> #include <sys/proc.h>
@ -1114,6 +1114,8 @@ db_disasm(
int imm2; int imm2;
int len; int len;
struct i_addr address; struct i_addr address;
#ifdef _KERNEL
pt_entry_t *pte, *pde; pt_entry_t *pte, *pde;
/* /*
@ -1131,6 +1133,7 @@ db_disasm(
db_printf("invalid address\n"); db_printf("invalid address\n");
return (loc); return (loc);
} }
#endif
get_value_inc(inst, loc, 1, false); get_value_inc(inst, loc, 1, false);
short_addr = false; short_addr = false;

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_trace.c,v 1.60 2008/07/02 19:49:58 rmind Exp $ */ /* $NetBSD: db_trace.c,v 1.61 2009/03/07 22:02:16 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -27,22 +27,29 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.60 2008/07/02 19:49:58 rmind Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.61 2009/03/07 22:02:16 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <sys/user.h> #include <sys/user.h>
#include <sys/intr.h>
#include <sys/cpu.h>
#include <machine/db_machdep.h> #include <machine/db_machdep.h>
#include <machine/frame.h> #include <machine/frame.h>
#include <machine/trap.h> #include <machine/trap.h>
#include <machine/pmap.h>
#include <ddb/db_sym.h> #include <ddb/db_sym.h>
#include <ddb/db_access.h> #include <ddb/db_access.h>
#include <ddb/db_variables.h> #include <ddb/db_variables.h>
#include <ddb/db_output.h> #include <ddb/db_output.h>
#include <ddb/db_interface.h> #include <ddb/db_interface.h>
#include <ddb/db_user.h>
#include <ddb/db_proc.h>
#include <ddb/db_cpu.h>
#include <ddb/db_command.h>
/* /*
* Machine set. * Machine set.
@ -87,7 +94,8 @@ db_i386_regop (const struct db_variable *vp, db_expr_t *val, int opcode)
*regaddr = *val; *regaddr = *val;
break; break;
default: default:
panic("db_i386_regop: unknown op %d", opcode); db_printf("db_i386_regop: unknown op %d", opcode);
db_error(NULL);
} }
return 0; return 0;
} }
@ -265,11 +273,12 @@ db_nextframe(
int *argp, /* IN */ int *argp, /* IN */
int is_trap, void (*pr)(const char *, ...)) int is_trap, void (*pr)(const char *, ...))
{ {
struct trapframe *tf; static struct trapframe tf;
struct i386tss *tss; static struct i386tss tss;
struct i386_frame *fp; struct i386_frame *fp;
struct intrframe *ifp; struct intrframe *ifp;
int traptype, trapno, err, i; int traptype, trapno, err, i;
uintptr_t ptr;
switch (is_trap) { switch (is_trap) {
case NONE: case NONE:
@ -286,9 +295,10 @@ db_nextframe(
case TRAP_TSS: case TRAP_TSS:
case INTERRUPT_TSS: case INTERRUPT_TSS:
tss = (struct i386tss *)*argp; ptr = db_get_value((int)argp, 4, false);
*ip = tss->__tss_eip; db_read_bytes((db_addr_t)ptr, sizeof(tss), (char *)&tss);
fp = (struct i386_frame *)tss->tss_ebp; *ip = tss.__tss_eip;
fp = (struct i386_frame *)tss.tss_ebp;
if (fp == NULL) if (fp == NULL)
return 0; return 0;
*nextframe = (int *)&fp->f_frame; *nextframe = (int *)&fp->f_frame;
@ -304,15 +314,15 @@ db_nextframe(
case SYSCALL: case SYSCALL:
case INTERRUPT: case INTERRUPT:
default: default:
/* The only argument to trap() or syscall() is the trapframe. */ /* The only argument to trap() or syscall() is the trapframe. */
tf = *(struct trapframe **)argp; ptr = db_get_value((int)argp, 4, false);
db_read_bytes((db_addr_t)ptr, sizeof(tf), (char *)&tf);
switch (is_trap) { switch (is_trap) {
case TRAP: case TRAP:
(*pr)("--- trap (number %d) ---\n", tf->tf_trapno); (*pr)("--- trap (number %d) ---\n", tf.tf_trapno);
break; break;
case SYSCALL: case SYSCALL:
(*pr)("--- syscall (number %d) ---\n", tf->tf_eax); (*pr)("--- syscall (number %d) ---\n", tf.tf_eax);
break; break;
case INTERRUPT: case INTERRUPT:
(*pr)("--- interrupt ---\n"); (*pr)("--- interrupt ---\n");
@ -321,11 +331,12 @@ db_nextframe(
* to interrupt stack, and convert to trapframe * to interrupt stack, and convert to trapframe
* (add 4). See frame.h. * (add 4). See frame.h.
*/ */
tf = (struct trapframe *)(*(argp - 1) + 4); ptr = db_get_value((int)(argp - 1) + 4, 4, false);
db_read_bytes((db_addr_t)ptr, sizeof(tf), (char *)&tf);
break; break;
} }
*ip = (db_addr_t)tf->tf_eip; *ip = (db_addr_t)tf.tf_eip;
fp = (struct i386_frame *)tf->tf_ebp; fp = (struct i386_frame *)tf.tf_ebp;
if (fp == NULL) if (fp == NULL)
return 0; return 0;
*nextframe = (int *)&fp->f_frame; *nextframe = (int *)&fp->f_frame;
@ -365,12 +376,12 @@ db_nextframe(
static bool static bool
db_intrstack_p(const void *vp) db_intrstack_p(const void *vp)
{ {
const struct cpu_info *ci; struct cpu_info *ci;
CPU_INFO_ITERATOR cii; const char *cp;
for (CPU_INFO_FOREACH(cii, ci)) {
const char *cp = ci->ci_intrstack;
for (ci = db_cpu_first(); ci != NULL; ci = db_cpu_next(ci)) {
db_read_bytes((db_addr_t)&ci->ci_intrstack, sizeof(cp),
(char *)&cp);
if (cp == NULL) { if (cp == NULL) {
continue; continue;
} }
@ -421,45 +432,55 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count,
callpc = (db_addr_t)ddb_regs.tf_eip; callpc = (db_addr_t)ddb_regs.tf_eip;
} else { } else {
if (trace_thread) { if (trace_thread) {
struct proc *p;
struct user *u; struct user *u;
struct lwp *l; proc_t p;
lwp_t l;
if (lwpaddr) { if (lwpaddr) {
l = (struct lwp *)addr; db_read_bytes(addr, sizeof(l),
p = l->l_proc; (char *)&l);
(*pr)("trace: pid %d ", p->p_pid); db_read_bytes((db_addr_t)l.l_proc,
sizeof(p), (char *)&p);
(*pr)("trace: pid %d ", p.p_pid);
} else { } else {
(*pr)("trace: pid %d ", (int)addr); (*pr)("trace: pid %d ", (int)addr);
p = p_find(addr, PFIND_LOCKED); lwpaddr = (db_addr_t)db_proc_find((pid_t)addr);
if (p == NULL) { if (addr == 0) {
(*pr)("not found\n"); (*pr)("not found\n");
return; return;
} }
l = LIST_FIRST(&p->p_lwps); db_read_bytes(addr, sizeof(p), (char *)&p);
KASSERT(l != NULL); db_read_bytes((db_addr_t)p.p_lwps.lh_first,
sizeof(l), (char *)&l);
} }
(*pr)("lid %d ", l->l_lid); (*pr)("lid %d ", l.l_lid);
if (!(l->l_flag & LW_INMEM)) { if (!(l.l_flag & LW_INMEM)) {
(*pr)("swapped out\n"); (*pr)("swapped out\n");
return; return;
} }
u = l->l_addr; u = l.l_addr;
if (p == curproc && l == curlwp) { #ifdef _KERNEL
if (l.l_proc == curproc &&
(lwp_t *)lwpaddr == curlwp) {
frame = (int *)ddb_regs.tf_ebp; frame = (int *)ddb_regs.tf_ebp;
callpc = (db_addr_t)ddb_regs.tf_eip; callpc = (db_addr_t)ddb_regs.tf_eip;
(*pr)("at %p\n", frame); (*pr)("at %p\n", frame);
} else { } else
frame = (int *)u->u_pcb.pcb_ebp; #endif
callpc = (db_addr_t) {
db_get_value((int)(frame + 1), 4, false); db_read_bytes((db_addr_t)&u->u_pcb.pcb_ebp,
sizeof(frame), (char *)&frame);
db_read_bytes((db_addr_t)(frame + 1),
sizeof(callpc), (char *)&callpc);
(*pr)("at %p\n", frame); (*pr)("at %p\n", frame);
frame = (int *)*frame; /* XXXfvdl db_get_value? */ db_read_bytes((db_addr_t)frame,
sizeof(frame), (char *)&frame);
} }
} else { } else {
frame = (int *)addr; frame = (int *)addr;
callpc = (db_addr_t) db_read_bytes((db_addr_t)(frame + 1),
db_get_value((int)(frame + 1), 4, false); sizeof(callpc), (char *)&callpc);
frame = (int *)*frame; /* XXXfvdl db_get_value? */ db_read_bytes((db_addr_t)frame,
sizeof(frame), (char *)&frame);
} }
} }
retaddr = frame + 1; retaddr = frame + 1;

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_machdep.h,v 1.26 2007/02/21 22:59:45 thorpej Exp $ */ /* $NetBSD: db_machdep.h,v 1.27 2009/03/07 22:02:16 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -127,7 +127,9 @@ int kdb_trap(int, int, db_regs_t *);
/* /*
* We define some of our own commands * We define some of our own commands
*/ */
#ifdef _KERNEL
#define DB_MACHINE_COMMANDS #define DB_MACHINE_COMMANDS
#endif
/* /*
* We use either a.out or Elf32 symbols in DDB. * We use either a.out or Elf32 symbols in DDB.

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_access.c,v 1.18 2007/02/21 22:59:56 thorpej Exp $ */ /* $NetBSD: db_access.c,v 1.19 2009/03/07 22:02:17 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -30,15 +30,13 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_access.c,v 1.18 2007/02/21 22:59:56 thorpej Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_access.c,v 1.19 2009/03/07 22:02:17 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <sys/endian.h>
#include <machine/db_machdep.h> /* type definitions */ #include <ddb/ddb.h>
#include <machine/endian.h>
#include <ddb/db_access.h>
/* /*
* Access unaligned data items on aligned (longword) * Access unaligned data items on aligned (longword)
@ -92,3 +90,33 @@ db_put_value(db_addr_t addr, size_t size, db_expr_t value)
db_write_bytes(addr, size, data); db_write_bytes(addr, size, data);
} }
void *
db_read_ptr(const char *name)
{
db_expr_t val;
void *p;
if (!db_value_of_name(name, &val)) {
db_printf("db_read_ptr: cannot find `%s'\n", name);
db_error(NULL);
/* NOTREACHED */
}
db_read_bytes((db_addr_t)val, sizeof(p), (char *)&p);
return p;
}
int
db_read_int(const char *name)
{
db_expr_t val;
int p;
if (!db_value_of_name(name, &val)) {
db_printf("db_read_int: cannot find `%s'\n", name);
db_error(NULL);
/* NOTREACHED */
}
db_read_bytes((db_addr_t)val, sizeof(p), (char *)&p);
return p;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_access.h,v 1.12 2007/02/21 22:59:56 thorpej Exp $ */ /* $NetBSD: db_access.h,v 1.13 2009/03/07 22:02:17 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -37,3 +37,6 @@ void db_put_value(db_addr_t, size_t, db_expr_t);
void db_read_bytes(db_addr_t, size_t, char *); void db_read_bytes(db_addr_t, size_t, char *);
void db_write_bytes(db_addr_t, size_t, const char *); void db_write_bytes(db_addr_t, size_t, const char *);
void *db_read_ptr(const char *);
int db_read_int(const char *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_command.c,v 1.128 2009/03/01 12:13:12 haad Exp $ */ /* $NetBSD: db_command.c,v 1.129 2009/03/07 22:02:17 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
* Copyright (c) 1991,1990 Carnegie Mellon University * Copyright (c) 1991,1990 Carnegie Mellon University
@ -58,14 +58,18 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.128 2009/03/01 12:13:12 haad Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.129 2009/03/07 22:02:17 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_aio.h" #include "opt_aio.h"
#include "opt_ddb.h" #include "opt_ddb.h"
#include "opt_kgdb.h" #include "opt_kgdb.h"
#include "opt_inet.h" #include "opt_inet.h"
#include "opt_uvmhist.h" #include "opt_uvmhist.h"
#include "opt_ddbparam.h" #include "opt_ddbparam.h"
#include "opt_multiprocessor.h"
#include "arp.h"
#endif
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -80,7 +84,6 @@ __KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.128 2009/03/01 12:13:12 haad Exp $"
#include <sys/vnode.h> #include <sys/vnode.h>
#include <sys/vmem.h> #include <sys/vmem.h>
#include <sys/lockdebug.h> #include <sys/lockdebug.h>
#include <sys/sleepq.h>
#include <sys/cpu.h> #include <sys/cpu.h>
#include <sys/buf.h> #include <sys/buf.h>
#include <sys/module.h> #include <sys/module.h>
@ -88,28 +91,11 @@ __KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.128 2009/03/01 12:13:12 haad Exp $"
/*include queue macros*/ /*include queue macros*/
#include <sys/queue.h> #include <sys/queue.h>
#include <machine/db_machdep.h> /* type definitions */ #include <ddb/ddb.h>
#if defined(_KERNEL_OPT)
#include "opt_multiprocessor.h"
#endif
#include <ddb/db_lex.h>
#include <ddb/db_output.h>
#include <ddb/db_command.h>
#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>
#include <uvm/uvm_extern.h> #include <uvm/uvm_extern.h>
#include <uvm/uvm_ddb.h> #include <uvm/uvm_ddb.h>
#include "arp.h"
/* /*
* Results of command search. * Results of command search.
*/ */
@ -223,8 +209,10 @@ static void db_vmem_print_cmd(db_expr_t, bool, db_expr_t, const char *);
static const struct db_command db_show_cmds[] = { static const struct db_command db_show_cmds[] = {
/*added from all sub cmds*/ /*added from all sub cmds*/
#ifdef _KERNEL /* XXX CRASH(8) */
{ DDB_ADD_CMD("callout", db_show_callout, { DDB_ADD_CMD("callout", db_show_callout,
0 ,"List all used callout functions.",NULL,NULL) }, 0 ,"List all used callout functions.",NULL,NULL) },
#endif
{ DDB_ADD_CMD("pages", db_show_all_pages, { DDB_ADD_CMD("pages", db_show_all_pages,
0 ,"List all used memory pages.",NULL,NULL) }, 0 ,"List all used memory pages.",NULL,NULL) },
{ DDB_ADD_CMD("procs", db_show_all_procs, { DDB_ADD_CMD("procs", db_show_all_procs,
@ -241,8 +229,10 @@ static const struct db_command db_show_cmds[] = {
#if defined(INET) && (NARP > 0) #if defined(INET) && (NARP > 0)
{ DDB_ADD_CMD("arptab", db_show_arptab, 0,NULL,NULL,NULL) }, { DDB_ADD_CMD("arptab", db_show_arptab, 0,NULL,NULL,NULL) },
#endif #endif
#ifdef _KERNEL
{ DDB_ADD_CMD("breaks", db_listbreak_cmd, 0, { DDB_ADD_CMD("breaks", db_listbreak_cmd, 0,
"Display all breaks.",NULL,NULL) }, "Display all breaks.",NULL,NULL) },
#endif
{ DDB_ADD_CMD("buf", db_buf_print_cmd, 0, { DDB_ADD_CMD("buf", db_buf_print_cmd, 0,
"Print the struct buf at address.", "[/f] address",NULL) }, "Print the struct buf at address.", "[/f] address",NULL) },
{ DDB_ADD_CMD("event", db_event_print_cmd, 0, { DDB_ADD_CMD("event", db_event_print_cmd, 0,
@ -289,8 +279,10 @@ static const struct db_command db_show_cmds[] = {
"Print the vmem usage.", "[/a] address", NULL) }, "Print the vmem usage.", "[/a] address", NULL) },
{ DDB_ADD_CMD("vmems", db_show_all_vmems, 0, { DDB_ADD_CMD("vmems", db_show_all_vmems, 0,
"Show all vmems.", NULL, NULL) }, "Show all vmems.", NULL, NULL) },
#ifdef _KERNEL
{ DDB_ADD_CMD("watches", db_listwatch_cmd, 0, { DDB_ADD_CMD("watches", db_listwatch_cmd, 0,
"Display all watchpoints.", NULL,NULL) }, "Display all watchpoints.", NULL,NULL) },
#endif
{ DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL,NULL) } { DDB_ADD_CMD(NULL, NULL, 0,NULL,NULL,NULL) }
}; };
@ -310,8 +302,10 @@ static const struct db_command db_command_table[] = {
"Continue execution.", "[/c]",NULL) }, "Continue execution.", "[/c]",NULL) },
{ DDB_ADD_CMD("call", db_fncall, CS_OWN, { DDB_ADD_CMD("call", db_fncall, CS_OWN,
"Call the function", "address[(expression[,...])]",NULL) }, "Call the function", "address[(expression[,...])]",NULL) },
#ifdef _KERNEL /* XXX CRASH(8) */
{ DDB_ADD_CMD("callout", db_show_callout, 0, NULL, { DDB_ADD_CMD("callout", db_show_callout, 0, NULL,
NULL,NULL ) }, NULL,NULL ) },
#endif
{ DDB_ADD_CMD("continue", db_continue_cmd, 0, { DDB_ADD_CMD("continue", db_continue_cmd, 0,
"Continue execution.", "[/c]",NULL) }, "Continue execution.", "[/c]",NULL) },
{ DDB_ADD_CMD("d", db_delete_cmd, 0, { DDB_ADD_CMD("d", db_delete_cmd, 0,
@ -325,6 +319,8 @@ static const struct db_command db_command_table[] = {
{ DDB_ADD_CMD("examine", db_examine_cmd, CS_SET_DOT, { DDB_ADD_CMD("examine", db_examine_cmd, CS_SET_DOT,
"Display the address locations.", "Display the address locations.",
"[/modifier] address[,count]",NULL) }, "[/modifier] address[,count]",NULL) },
{ DDB_ADD_CMD("exit", db_continue_cmd, 0,
"Continue execution.", "[/c]",NULL) },
{ DDB_ADD_CMD("help", db_help_print_cmd, CS_OWN|CS_NOREPEAT, { DDB_ADD_CMD("help", db_help_print_cmd, CS_OWN|CS_NOREPEAT,
"Display help about commands", "Display help about commands",
"Use other commands as arguments.",NULL) }, "Use other commands as arguments.",NULL) },
@ -349,6 +345,8 @@ static const struct db_command db_command_table[] = {
"[/axzodurc] address [address ...]",NULL) }, "[/axzodurc] address [address ...]",NULL) },
{ DDB_ADD_CMD("ps", db_show_all_procs, 0, { DDB_ADD_CMD("ps", db_show_all_procs, 0,
"Print all processes.","See show all procs",NULL) }, "Print all processes.","See show all procs",NULL) },
{ DDB_ADD_CMD("quit", db_continue_cmd, 0,
"Continue execution.", "[/c]",NULL) },
{ DDB_ADD_CMD("reboot", db_reboot_cmd, CS_OWN, { DDB_ADD_CMD("reboot", db_reboot_cmd, CS_OWN,
"Reboot","0x1 RB_ASKNAME, 0x2 RB_SINGLE, 0x4 RB_NOSYNC, 0x8 RB_HALT," "Reboot","0x1 RB_ASKNAME, 0x2 RB_SINGLE, 0x4 RB_NOSYNC, 0x8 RB_HALT,"
"0x40 RB_KDB, 0x100 RB_DUMP, 0x808 RB_POWERDOWN",NULL) }, "0x40 RB_KDB, 0x100 RB_DUMP, 0x808 RB_POWERDOWN",NULL) },
@ -396,29 +394,6 @@ char db_cmd_on_enter[DB_LINE_MAXLEN + 1] = "";
#endif /* defined(DDB_COMMANDONENTER) */ #endif /* defined(DDB_COMMANDONENTER) */
#define DB_LINE_SEP ';' #define DB_LINE_SEP ';'
/*
* Utility routine - discard tokens through end-of-line.
*/
void
db_skip_to_eol(void)
{
int t;
do {
t = db_read_token();
} while (t != tEOL);
}
void
db_error(const char *s)
{
if (s)
db_printf("%s", s);
db_flush_lex();
longjmp(db_recover);
}
/* /*
* Execute commandlist after ddb start * Execute commandlist after ddb start
* This function goes through the command list created from commands and ';' * This function goes through the command list created from commands and ';'
@ -483,7 +458,7 @@ db_register_tbl(uint8_t type, const struct db_command *cmd_tbl)
db_init_commands(); db_init_commands();
/* now create a list entry for this table */ /* now create a list entry for this table */
list_ent = malloc(sizeof(struct db_cmd_tbl_en), M_TEMP, M_ZERO); list_ent = db_zalloc(sizeof(*list_ent));
if (list_ent == NULL) if (list_ent == NULL)
return ENOMEM; return ENOMEM;
list_ent->db_cmd=cmd_tbl; list_ent->db_cmd=cmd_tbl;
@ -544,7 +519,7 @@ db_unregister_tbl(uint8_t type,const struct db_command *cmd_tbl)
if (list_ent->db_cmd == cmd_tbl){ if (list_ent->db_cmd == cmd_tbl){
TAILQ_REMOVE(list, TAILQ_REMOVE(list,
list_ent, db_cmd_next); list_ent, db_cmd_next);
free(list_ent,M_TEMP); db_free(list_ent, sizeof(*list_ent));
return 0; return 0;
} }
} }
@ -583,15 +558,7 @@ db_command_loop(void)
if (db_print_position() != 0) if (db_print_position() != 0)
db_printf("\n"); db_printf("\n");
db_output_line = 0; db_output_line = 0;
#ifdef MULTIPROCESSOR
db_printf("db{%ld}> ", (long)cpu_number());
#else
db_printf("db> ");
#endif
(void) db_read_line(); (void) db_read_line();
db_command(&db_last_command); db_command(&db_last_command);
} }
@ -1005,9 +972,11 @@ db_map_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
full = true; full = true;
if (have_addr == false) if (have_addr == false)
addr = (db_expr_t)(uintptr_t) kernel_map; addr = (db_expr_t)db_read_ptr("kernel_map");
#ifdef _KERNEL
uvm_map_printit((struct vm_map *)(uintptr_t) addr, full, db_printf); uvm_map_printit((struct vm_map *)(uintptr_t) addr, full, db_printf);
#endif /* XXX CRASH(8) */
} }
/*ARGSUSED*/ /*ARGSUSED*/
@ -1036,8 +1005,10 @@ db_object_print_cmd(db_expr_t addr, bool have_addr,
if (modif[0] == 'f') if (modif[0] == 'f')
full = true; full = true;
#ifdef _KERNEL /* XXX CRASH(8) */
uvm_object_printit((struct uvm_object *)(uintptr_t) addr, full, uvm_object_printit((struct uvm_object *)(uintptr_t) addr, full,
db_printf); db_printf);
#endif
} }
/*ARGSUSED*/ /*ARGSUSED*/
@ -1050,7 +1021,9 @@ db_page_print_cmd(db_expr_t addr, bool have_addr,
if (modif[0] == 'f') if (modif[0] == 'f')
full = true; full = true;
#ifdef _KERNEL /* XXX CRASH(8) */
uvm_page_printit((struct vm_page *)(uintptr_t) addr, full, db_printf); uvm_page_printit((struct vm_page *)(uintptr_t) addr, full, db_printf);
#endif
} }
/*ARGSUSED*/ /*ARGSUSED*/
@ -1059,7 +1032,9 @@ db_show_all_pages(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
uvm_page_printall(db_printf); uvm_page_printall(db_printf);
#endif
} }
/*ARGSUSED*/ /*ARGSUSED*/
@ -1072,7 +1047,9 @@ db_buf_print_cmd(db_expr_t addr, bool have_addr,
if (modif[0] == 'f') if (modif[0] == 'f')
full = true; full = true;
#ifdef _KERNEL /* XXX CRASH(8) */
vfs_buf_print((struct buf *)(uintptr_t) addr, full, db_printf); vfs_buf_print((struct buf *)(uintptr_t) addr, full, db_printf);
#endif
} }
/*ARGSUSED*/ /*ARGSUSED*/
@ -1085,7 +1062,9 @@ db_event_print_cmd(db_expr_t addr, bool have_addr,
if (modif[0] == 'f') if (modif[0] == 'f')
full = true; full = true;
#ifdef _KERNEL /* XXX CRASH(8) */
event_print(full, db_printf); event_print(full, db_printf);
#endif
} }
/*ARGSUSED*/ /*ARGSUSED*/
@ -1098,7 +1077,9 @@ db_vnode_print_cmd(db_expr_t addr, bool have_addr,
if (modif[0] == 'f') if (modif[0] == 'f')
full = true; full = true;
#ifdef _KERNEL /* XXX CRASH(8) */
vfs_vnode_print((struct vnode *)(uintptr_t) addr, full, db_printf); vfs_vnode_print((struct vnode *)(uintptr_t) addr, full, db_printf);
#endif
} }
/*ARGSUSED*/ /*ARGSUSED*/
@ -1107,7 +1088,9 @@ db_vmem_print_cmd(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
vmem_print((uintptr_t) addr, modif, db_printf); vmem_print((uintptr_t) addr, modif, db_printf);
#endif
} }
static void static void
@ -1119,7 +1102,9 @@ db_mount_print_cmd(db_expr_t addr, bool have_addr,
if (modif[0] == 'f') if (modif[0] == 'f')
full = true; full = true;
#ifdef _KERNEL /* XXX CRASH(8) */
vfs_mount_print((struct mount *)(uintptr_t) addr, full, db_printf); vfs_mount_print((struct mount *)(uintptr_t) addr, full, db_printf);
#endif
} }
/*ARGSUSED*/ /*ARGSUSED*/
@ -1128,7 +1113,9 @@ db_mbuf_print_cmd(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
m_print((const struct mbuf *)(uintptr_t) addr, modif, db_printf); m_print((const struct mbuf *)(uintptr_t) addr, modif, db_printf);
#endif
} }
/*ARGSUSED*/ /*ARGSUSED*/
@ -1137,7 +1124,9 @@ db_pool_print_cmd(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
pool_printit((struct pool *)(uintptr_t) addr, modif, db_printf); pool_printit((struct pool *)(uintptr_t) addr, modif, db_printf);
#endif
} }
/*ARGSUSED*/ /*ARGSUSED*/
@ -1146,7 +1135,9 @@ db_namecache_print_cmd(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
namecache_print((struct vnode *)(uintptr_t) addr, db_printf); namecache_print((struct vnode *)(uintptr_t) addr, db_printf);
#endif
} }
/*ARGSUSED*/ /*ARGSUSED*/
@ -1155,7 +1146,9 @@ db_uvmexp_print_cmd(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
uvmexp_print(db_printf); uvmexp_print(db_printf);
#endif
} }
#ifdef UVMHIST #ifdef UVMHIST
@ -1175,7 +1168,9 @@ db_lock_print_cmd(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
lockdebug_lock_print((void *)(uintptr_t)addr, db_printf); lockdebug_lock_print((void *)(uintptr_t)addr, db_printf);
#endif
} }
/* /*
@ -1187,6 +1182,7 @@ static void
db_fncall(db_expr_t addr, bool have_addr, db_fncall(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL
db_expr_t fn_addr; db_expr_t fn_addr;
#define MAXARGS 11 #define MAXARGS 11
db_expr_t args[MAXARGS]; db_expr_t args[MAXARGS];
@ -1236,12 +1232,16 @@ db_fncall(db_expr_t addr, bool have_addr,
retval = (*func)(args[0], args[1], args[2], args[3], args[4], retval = (*func)(args[0], args[1], args[2], args[3], args[4],
args[5], args[6], args[7], args[8], args[9]); args[5], args[6], args[7], args[8], args[9]);
db_printf("%s\n", db_num_to_str(retval)); db_printf("%s\n", db_num_to_str(retval));
#else /* _KERNEL */
db_printf("This command can only be used in-kernel.\n");
#endif /* _KERNEL */
} }
static void static void
db_reboot_cmd(db_expr_t addr, bool have_addr, db_reboot_cmd(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL
db_expr_t bootflags; db_expr_t bootflags;
/* Flags, default to RB_AUTOBOOT */ /* Flags, default to RB_AUTOBOOT */
@ -1258,6 +1258,9 @@ db_reboot_cmd(db_expr_t addr, bool have_addr,
*/ */
db_recover = 0; db_recover = 0;
cpu_reboot((int)bootflags, NULL); cpu_reboot((int)bootflags, NULL);
#else /* _KERNEL */
db_printf("This command can only be used in-kernel.\n");
#endif /* _KERNEL */
} }
static void static void
@ -1301,7 +1304,7 @@ db_stack_trace_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *
pr = db_printf; pr = db_printf;
while ((c = *cp++) != 0) while ((c = *cp++) != 0)
if (c == 'l') if (c == 'l')
pr = printf; pr = (void (*)(const char *, ...))printf;
if (count == -1) if (count == -1)
count = 65535; count = 65535;
@ -1313,7 +1316,7 @@ static void
db_sync_cmd(db_expr_t addr, bool have_addr, db_sync_cmd(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL
/* /*
* We are leaving DDB, never to return upward. * We are leaving DDB, never to return upward.
* Clear db_recover so that we can debug faults in functions * Clear db_recover so that we can debug faults in functions
@ -1322,6 +1325,9 @@ db_sync_cmd(db_expr_t addr, bool have_addr,
db_recover = 0; db_recover = 0;
panicstr = "dump forced via kernel debugger"; panicstr = "dump forced via kernel debugger";
cpu_reboot(RB_DUMP, NULL); cpu_reboot(RB_DUMP, NULL);
#else /* _KERNEL */
db_printf("This command can only be used in-kernel.\n");
#endif /* _KERNEL */
} }
/* /*
@ -1333,9 +1339,11 @@ db_whatis_cmd(db_expr_t address, bool have_addr,
{ {
const uintptr_t addr = (uintptr_t)address; const uintptr_t addr = (uintptr_t)address;
lwp_whatis(addr, db_printf); db_lwp_whatis(addr, db_printf);
#ifdef _KERNEL /* XXX CRASH(8) */
pool_whatis(addr, db_printf); pool_whatis(addr, db_printf);
vmem_whatis(addr, db_printf); vmem_whatis(addr, db_printf);
uvm_whatis(addr, db_printf); uvm_whatis(addr, db_printf);
module_whatis(addr, db_printf); module_whatis(addr, db_printf);
#endif
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_command.h,v 1.34 2009/01/05 22:19:40 haad Exp $ */ /* $NetBSD: db_command.h,v 1.35 2009/03/07 22:02:17 ad Exp $ */
/*- /*-
* Copyright (c) 1996, 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc. * Copyright (c) 1996, 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
@ -144,5 +144,8 @@ struct db_command {
#endif #endif
}; };
#endif /*_DDB_COMMAND_*/ void *db_alloc(size_t);
void *db_zalloc(size_t);
void db_free(void *, size_t);
#endif /*_DDB_COMMAND_*/

61
sys/ddb/db_cpu.c Normal file
View File

@ -0,0 +1,61 @@
/* $NetBSD: db_cpu.c,v 1.1 2009/03/07 22:02:17 ad Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_cpu.c,v 1.1 2009/03/07 22:02:17 ad Exp $");
#include <ddb/ddb.h>
#include <sys/param.h>
#include <sys/cpu.h>
#include <sys/proc.h>
static struct cpu_info *head;
struct cpu_info *
db_cpu_first(void)
{
head = db_read_ptr("cpu_queue");
return head;
}
struct cpu_info *
db_cpu_next(struct cpu_info *ci)
{
db_read_bytes((db_addr_t)&ci->ci_data.cpu_qchain.cqe_next,
sizeof(ci), (char *)&ci);
if (ci == head) {
ci = NULL;
}
return ci;
}

38
sys/ddb/db_cpu.h Normal file
View File

@ -0,0 +1,38 @@
/* $NetBSD: db_cpu.h,v 1.1 2009/03/07 22:02:17 ad Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _DDB_DB_CPU_H_
#define _DDB_DB_CPU_H_
struct cpu_info *db_cpu_first(void);
struct cpu_info *db_cpu_next(struct cpu_info *);
#endif /* _DDB_DB_CPU_H_ */

View File

@ -1,12 +1,12 @@
/* $NetBSD: db_elf.c,v 1.25 2008/04/28 20:23:46 martin Exp $ */ /* $NetBSD: db_elf.c,v 1.26 2009/03/07 22:02:17 ad Exp $ */
/*- /*-
* Copyright (c) 1997 The NetBSD Foundation, Inc. * Copyright (c) 1997, 2009 The NetBSD Foundation, Inc.
* All rights reserved. * All rights reserved.
* *
* This code is derived from software contributed to The NetBSD Foundation * This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center. * NASA Ames Research Center, and by Andrew Doran.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -31,17 +31,16 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_elf.c,v 1.25 2008/04/28 20:23:46 martin Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_elf.c,v 1.26 2009/03/07 22:02:17 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <machine/db_machdep.h> #include <ddb/ddb.h>
#include <ddb/db_sym.h> #include <machine/pmap.h>
#include <ddb/db_output.h> #include <machine/vmparam.h>
#include <ddb/db_extern.h>
#ifdef DB_ELF_SYMBOLS #ifdef DB_ELF_SYMBOLS
@ -61,10 +60,10 @@ static char *db_elf_find_strtab(db_symtab_t *);
#define STAB_TO_SHDR(stab, e) ((Elf_Shdr *)((stab)->private + (e)->e_shoff)) #define STAB_TO_SHDR(stab, e) ((Elf_Shdr *)((stab)->private + (e)->e_shoff))
static bool db_elf_sym_init(int, void *, void *, const char *); static bool db_elf_sym_init(int, void *, void *, const char *);
static db_sym_t db_elf_lookup(db_symtab_t *, char *); static db_sym_t db_elf_lookup(db_symtab_t *, const char *);
static db_sym_t db_elf_search_symbol(db_symtab_t *, db_addr_t, db_strategy_t, static db_sym_t db_elf_search_symbol(db_symtab_t *, db_addr_t, db_strategy_t,
db_expr_t *); db_expr_t *);
static void db_elf_symbol_values(db_symtab_t *, db_sym_t, char **, static void db_elf_symbol_values(db_symtab_t *, db_sym_t, const char **,
db_expr_t *); db_expr_t *);
static bool db_elf_line_at_pc(db_symtab_t *, db_sym_t, char **, int *, static bool db_elf_line_at_pc(db_symtab_t *, db_sym_t, char **, int *,
db_expr_t); db_expr_t);
@ -83,6 +82,23 @@ const db_symformat_t db_symformat_elf = {
db_elf_forall db_elf_forall
}; };
static db_symtab_t db_symtabs;
/*
* Add symbol table, with given name, to symbol tables.
*/
static int
db_add_symbol_table(char *start, char *end, const char *name, char *ref)
{
db_symtabs.start = start;
db_symtabs.end = end;
db_symtabs.name = name;
db_symtabs.private = ref;
return(0);
}
/* /*
* Find the symbol table and strings; tell ddb about them. * Find the symbol table and strings; tell ddb about them.
*/ */
@ -185,9 +201,6 @@ db_elf_sym_init(
*/ */
if (db_add_symbol_table((char *)symtab_start, if (db_add_symbol_table((char *)symtab_start,
(char *)symtab_end, name, (char *)symtab) != -1) { (char *)symtab_end, name, (char *)symtab) != -1) {
printf("[ using %lu bytes of %s ELF symbol table ]\n",
(u_long)roundup(((char *)esymtab - (char *)symtab),
sizeof(u_long)), name);
return (true); return (true);
} }
@ -209,6 +222,8 @@ db_elf_find_strtab(db_symtab_t *stab)
Elf_Shdr *shp = STAB_TO_SHDR(stab, elf); Elf_Shdr *shp = STAB_TO_SHDR(stab, elf);
int i; int i;
stab = &db_symtabs;
/* /*
* We don't load ELF header for ELF modules. * We don't load ELF header for ELF modules.
* Find out if this is a loadable module. If so, * Find out if this is a loadable module. If so,
@ -229,11 +244,13 @@ db_elf_find_strtab(db_symtab_t *stab)
* Lookup the symbol with the given name. * Lookup the symbol with the given name.
*/ */
static db_sym_t static db_sym_t
db_elf_lookup(db_symtab_t *stab, char *symstr) db_elf_lookup(db_symtab_t *stab, const char *symstr)
{ {
Elf_Sym *symp, *symtab_start, *symtab_end; Elf_Sym *symp, *symtab_start, *symtab_end;
char *strtab; char *strtab;
stab = &db_symtabs;
symtab_start = STAB_TO_SYMSTART(stab); symtab_start = STAB_TO_SYMSTART(stab);
symtab_end = STAB_TO_SYMEND(stab); symtab_end = STAB_TO_SYMEND(stab);
@ -261,6 +278,8 @@ db_elf_search_symbol(db_symtab_t *symtab, db_addr_t off, db_strategy_t strategy,
Elf_Sym *rsymp, *symp, *symtab_start, *symtab_end; Elf_Sym *rsymp, *symp, *symtab_start, *symtab_end;
db_addr_t diff = *diffp; db_addr_t diff = *diffp;
symtab = &db_symtabs;
symtab_start = STAB_TO_SYMSTART(symtab); symtab_start = STAB_TO_SYMSTART(symtab);
symtab_end = STAB_TO_SYMEND(symtab); symtab_end = STAB_TO_SYMEND(symtab);
@ -269,10 +288,11 @@ db_elf_search_symbol(db_symtab_t *symtab, db_addr_t off, db_strategy_t strategy,
for (symp = symtab_start; symp < symtab_end; symp++) { for (symp = symtab_start; symp < symtab_end; symp++) {
if (symp->st_name == 0) if (symp->st_name == 0)
continue; continue;
#if 0 #if 0
/* This prevents me from seeing anythin in locore.s -- eeh */ /* This prevents me from seeing anythin in locore.s -- eeh */
if (ELF_SYM_TYPE(symp->st_info) != Elf_estt_object && if (ELF_ST_TYPE(symp->st_info) != STT_OBJECT &&
ELF_SYM_TYPE(symp->st_info) != Elf_estt_func) ELF_ST_TYPE(symp->st_info) != STT_FUNC)
continue; continue;
#endif #endif
@ -318,12 +338,14 @@ db_elf_search_symbol(db_symtab_t *symtab, db_addr_t off, db_strategy_t strategy,
* Return the name and value for a symbol. * Return the name and value for a symbol.
*/ */
static void static void
db_elf_symbol_values(db_symtab_t *symtab, db_sym_t sym, char **namep, db_elf_symbol_values(db_symtab_t *symtab, db_sym_t sym, const char **namep,
db_expr_t *valuep) db_expr_t *valuep)
{ {
Elf_Sym *symp = (Elf_Sym *)sym; Elf_Sym *symp = (Elf_Sym *)sym;
char *strtab; char *strtab;
symtab = &db_symtabs;
if (namep) { if (namep) {
strtab = db_elf_find_strtab(symtab); strtab = db_elf_find_strtab(symtab);
if (strtab == NULL) if (strtab == NULL)
@ -377,6 +399,8 @@ db_elf_forall(db_symtab_t *stab, db_forall_func_t db_forall_func, void *arg)
static char suffix[2]; static char suffix[2];
Elf_Sym *symp, *symtab_start, *symtab_end; Elf_Sym *symp, *symtab_start, *symtab_end;
stab = &db_symtabs;
symtab_start = STAB_TO_SYMSTART(stab); symtab_start = STAB_TO_SYMSTART(stab);
symtab_end = STAB_TO_SYMEND(stab); symtab_end = STAB_TO_SYMEND(stab);

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_examine.c,v 1.33 2008/11/16 19:34:29 pooka Exp $ */ /* $NetBSD: db_examine.c,v 1.34 2009/03/07 22:02:17 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -30,22 +30,14 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_examine.c,v 1.33 2008/11/16 19:34:29 pooka Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_examine.c,v 1.34 2009/03/07 22:02:17 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
#include <sys/buf.h> #include <sys/buf.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <machine/db_machdep.h> /* type definitions */ #include <ddb/ddb.h>
#include <ddb/db_lex.h>
#include <ddb/db_output.h>
#include <ddb/db_command.h>
#include <ddb/db_sym.h>
#include <ddb/db_access.h>
#include <ddb/db_extern.h>
#include <ddb/db_interface.h>
static char db_examine_format[TOK_STRING_SIZE] = "x"; static char db_examine_format[TOK_STRING_SIZE] = "x";

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_expr.c,v 1.15 2007/02/22 06:41:01 thorpej Exp $ */ /* $NetBSD: db_expr.c,v 1.16 2009/03/07 22:02:17 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -30,20 +30,12 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_expr.c,v 1.15 2007/02/22 06:41:01 thorpej Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_expr.c,v 1.16 2009/03/07 22:02:17 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <machine/db_machdep.h> #include <ddb/ddb.h>
#include <ddb/db_access.h>
#include <ddb/db_command.h>
#include <ddb/db_extern.h>
#include <ddb/db_lex.h>
#include <ddb/db_output.h>
#include <ddb/db_sym.h>
#include <ddb/db_variables.h>
static bool db_term(db_expr_t *); static bool db_term(db_expr_t *);
static bool db_unary(db_expr_t *); static bool db_unary(db_expr_t *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_input.c,v 1.22 2007/02/22 06:41:01 thorpej Exp $ */ /* $NetBSD: db_input.c,v 1.23 2009/03/07 22:02:17 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -30,19 +30,17 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_input.c,v 1.22 2007/02/22 06:41:01 thorpej Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_input.c,v 1.23 2009/03/07 22:02:17 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddbparam.h" #include "opt_ddbparam.h"
#endif
#include <sys/param.h> #include <sys/param.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <sys/cpu.h>
#include <machine/db_machdep.h> #include <ddb/ddb.h>
#include <ddb/db_output.h>
#include <ddb/db_command.h>
#include <ddb/db_sym.h>
#include <ddb/db_extern.h>
#include <dev/cons.h> #include <dev/cons.h>
@ -346,6 +344,12 @@ db_inputchar(int c)
int int
db_readline(char *lstart, int lsize) db_readline(char *lstart, int lsize)
{ {
# ifdef MULTIPROCESSOR
db_printf("db{%ld}> ", (long)cpu_number());
# else
db_printf("db> ");
# endif
db_force_whitespace(); /* synch output position */ db_force_whitespace(); /* synch output position */
db_lbuf_start = lstart; db_lbuf_start = lstart;

61
sys/ddb/db_kernel.c Normal file
View File

@ -0,0 +1,61 @@
/* $NetBSD: db_kernel.c,v 1.1 2009/03/07 22:02:17 ad Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_kernel.c,v 1.1 2009/03/07 22:02:17 ad Exp $");
#include <ddb/ddb.h>
#include <sys/param.h>
#include <sys/cpu.h>
#include <sys/proc.h>
#include <sys/malloc.h>
void *
db_alloc(size_t sz)
{
return malloc(sz, M_TEMP, M_WAITOK);
}
void *
db_zalloc(size_t sz)
{
return malloc(sz, M_TEMP, M_WAITOK | M_ZERO);
}
void
db_free(void *p, size_t sz)
{
free(p, M_TEMP);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_lex.c,v 1.20 2005/11/27 13:05:28 yamt Exp $ */ /* $NetBSD: db_lex.c,v 1.21 2009/03/07 22:02:17 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -34,19 +34,12 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_lex.c,v 1.20 2005/11/27 13:05:28 yamt Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_lex.c,v 1.21 2009/03/07 22:02:17 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
#include <machine/db_machdep.h> #include <ddb/ddb.h>
#include <ddb/db_lex.h>
#include <ddb/db_output.h>
#include <ddb/db_command.h>
#include <ddb/db_sym.h>
#include <ddb/db_extern.h>
#include <ddb/db_interface.h>
db_expr_t db_tok_number; db_expr_t db_tok_number;
char db_tok_string[TOK_STRING_SIZE]; char db_tok_string[TOK_STRING_SIZE];
@ -331,3 +324,26 @@ db_lex(void)
db_flush_lex(); db_flush_lex();
return (tEOF); return (tEOF);
} }
/*
* Utility routine - discard tokens through end-of-line.
*/
void
db_skip_to_eol(void)
{
int t;
do {
t = db_read_token();
} while (t != tEOL);
}
void
db_error(const char *s)
{
if (s)
db_printf("%s", s);
db_flush_lex();
longjmp(db_recover);
}

72
sys/ddb/db_lwp.c Normal file
View File

@ -0,0 +1,72 @@
/* $NetBSD: db_lwp.c,v 1.1 2009/03/07 22:02:17 ad Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_lwp.c,v 1.1 2009/03/07 22:02:17 ad Exp $");
#include <ddb/ddb.h>
#include <sys/param.h>
#include <sys/cpu.h>
#include <sys/proc.h>
lwp_t *
db_lwp_first(void)
{
return db_read_ptr("alllwp");
}
lwp_t *
db_lwp_next(lwp_t *l)
{
db_read_bytes((db_addr_t)&l->l_list.le_next, sizeof(l), (char *)&l);
return l;
}
void
db_lwp_whatis(uintptr_t addr, void (*pr)(const char *, ...))
{
uintptr_t stack;
lwp_t l, *lp;
for (lp = db_lwp_first(); lp != NULL; lp = db_lwp_next(lp)) {
db_read_bytes((db_addr_t)lp, sizeof(l), (char *)&l);
stack = (uintptr_t)KSTACK_LOWEST_ADDR((&l));
if (addr < stack || stack + KSTACK_SIZE <= addr) {
continue;
}
(*pr)("%p is %p+%zu, LWP %p's stack\n",
(void *)addr, (void *)stack,
(size_t)(addr - stack), lp);
}
}

39
sys/ddb/db_lwp.h Normal file
View File

@ -0,0 +1,39 @@
/* $NetBSD: db_lwp.h,v 1.1 2009/03/07 22:02:17 ad Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LWPUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _DDB_DB_LWP_H_
#define _DDB_DB_LWP_H_
struct lwp *db_lwp_first(void);
struct lwp *db_lwp_next(struct lwp *);
void db_lwp_whatis(uintptr_t, void (*)(const char *, ...));
#endif /* _DDB_DB_LWP_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_output.c,v 1.29 2005/12/11 12:20:53 christos Exp $ */ /* $NetBSD: db_output.c,v 1.30 2009/03/07 22:02:17 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -31,7 +31,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_output.c,v 1.29 2005/12/11 12:20:53 christos Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_output.c,v 1.30 2009/03/07 22:02:17 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -40,13 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: db_output.c,v 1.29 2005/12/11 12:20:53 christos Exp
#include <dev/cons.h> #include <dev/cons.h>
#include <machine/db_machdep.h> #include <ddb/ddb.h>
#include <ddb/db_command.h>
#include <ddb/db_output.h>
#include <ddb/db_interface.h>
#include <ddb/db_sym.h>
#include <ddb/db_extern.h>
/* /*
* Character output - tracks position in line. * Character output - tracks position in line.

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_print.c,v 1.26 2007/02/22 06:41:01 thorpej Exp $ */ /* $NetBSD: db_print.c,v 1.27 2009/03/07 22:02:17 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -34,18 +34,12 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_print.c,v 1.26 2007/02/22 06:41:01 thorpej Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_print.c,v 1.27 2009/03/07 22:02:17 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <machine/db_machdep.h> #include <ddb/ddb.h>
#include <ddb/db_lex.h>
#include <ddb/db_variables.h>
#include <ddb/db_sym.h>
#include <ddb/db_output.h>
#include <ddb/db_extern.h>
/*ARGSUSED*/ /*ARGSUSED*/
void void

253
sys/ddb/db_proc.c Normal file
View File

@ -0,0 +1,253 @@
/* $NetBSD: db_proc.c,v 1.1 2009/03/07 22:02:17 ad Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 1982, 1986, 1989, 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: kern_proc.c 8.4 (Berkeley) 1/4/94
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_proc.c,v 1.1 2009/03/07 22:02:17 ad Exp $");
#include <ddb/ddb.h>
#include <sys/param.h>
#include <sys/cpu.h>
#include <sys/proc.h>
#include <sys/kauth.h>
proc_t *
db_proc_first(void)
{
return db_read_ptr("allproc");
}
proc_t *
db_proc_next(proc_t *p)
{
db_read_bytes((db_addr_t)&p->p_list.le_next, sizeof(p), (char *)&p);
return p;
}
proc_t *
db_proc_find(pid_t pid)
{
proc_t *p;
pid_t tp;
for (p = db_proc_first(); p != NULL; p = db_proc_next(p)) {
db_read_bytes((db_addr_t)&p->p_pid, sizeof(tp),
(char *)&tp);
if (tp == pid) {
return p;
}
}
return NULL;
}
void
db_show_all_procs(db_expr_t addr, bool haddr, db_expr_t count,
const char *modif)
{
static struct pgrp pgrp;
static proc_t p;
static lwp_t l;
const char *mode, *ename;
proc_t *pp;
lwp_t *lp;
char db_nbuf[MAXCOMLEN + 1], wbuf[MAXCOMLEN + 1];
bool run;
int cpuno;
if (modif[0] == 0)
mode = "l"; /* default == lwp mode */
else
mode = strchr("mawln", modif[0]);
if (mode == NULL || *mode == 'm') {
db_printf("usage: show all procs [/a] [/l] [/n] [/w]\n");
db_printf("\t/a == show process address info\n");
db_printf("\t/l == show LWP info\n");
db_printf("\t/n == show normal process info [default]\n");
db_printf("\t/w == show process wait/emul info\n");
return;
}
switch (*mode) {
case 'a':
db_printf("PID %10s %18s %18s %18s\n",
"COMMAND", "STRUCT PROC *", "UAREA *", "VMSPACE/VM_MAP");
break;
case 'l':
db_printf("PID %4s S %3s %9s %18s %18s %-8s\n",
"LID", "CPU", "FLAGS", "STRUCT LWP *", "NAME", "WAIT");
break;
case 'n':
db_printf("PID %8s %8s %10s S %7s %4s %16s %7s\n",
"PPID", "PGRP", "UID", "FLAGS", "LWPS", "COMMAND", "WAIT");
break;
case 'w':
db_printf("PID %4s %16s %8s %4s %-12s%s\n",
"LID", "COMMAND", "EMUL", "PRI", "WAIT-MSG",
"WAIT-CHANNEL");
break;
}
for (pp = db_proc_first(); pp != NULL; pp = db_proc_next(pp)) {
db_read_bytes((db_addr_t)pp, sizeof(p), (char *)&p);
if (p.p_stat == 0) {
continue;
}
lp = p.p_lwps.lh_first;
if (lp != NULL) {
db_read_bytes((db_addr_t)lp, sizeof(l), (char *)&l);
}
db_printf("%-5d", p.p_pid);
switch (*mode) {
case 'a':
db_printf("%10.10s %18lx %18lx %18lx\n",
p.p_comm, (long)pp,
(long)(lp != NULL ? l.l_addr : 0),
(long)p.p_vmspace);
break;
case 'l':
while (lp != NULL) {
if (l.l_name != NULL) {
db_read_bytes((db_addr_t)l.l_name,
MAXCOMLEN, db_nbuf);
} else {
strlcpy(db_nbuf, p.p_comm,
sizeof(db_nbuf));
}
run = (l.l_stat == LSONPROC ||
(l.l_pflag & LP_RUNNING) != 0);
if (l.l_cpu != NULL) {
db_read_bytes((db_addr_t)
&l.l_cpu->ci_data.cpu_index,
sizeof(cpuno), (char *)&cpuno);
} else
cpuno = -1;
if (l.l_wchan && l.l_wmesg) {
db_read_bytes((db_addr_t)l.l_wmesg,
sizeof(wbuf), (char *)wbuf);
} else {
wbuf[0] = '\0';
}
db_printf("%c%4d %d %3d %9x %18lx %18s %-8s\n",
(run ? '>' : ' '), l.l_lid,
l.l_stat, cpuno, l.l_flag, (long)lp,
db_nbuf, wbuf);
lp = LIST_NEXT((&l), l_sibling);
if (lp != NULL) {
db_printf("%-5d", p.p_pid);
db_read_bytes((db_addr_t)lp, sizeof(l),
(char *)&l);
}
}
break;
case 'n':
db_read_bytes((db_addr_t)p.p_pgrp, sizeof(pgrp),
(char *)&pgrp);
if (lp != NULL && l.l_wchan && l.l_wmesg) {
db_read_bytes((db_addr_t)l.l_wmesg,
sizeof(wbuf), (char *)wbuf);
} else {
wbuf[0] = '\0';
}
db_printf("%8d %8d %10d %d %#7x %4d %16s %7.7s\n",
p.p_pptr != NULL ? p.p_pid : -1, pgrp.pg_id,
#ifdef _KERNEL
kauth_cred_getuid(p.p_cred),
#else
/* XXX CRASH(8) */ 666,
#endif
p.p_stat, p.p_flag,
p.p_nlwps, p.p_comm,
(p.p_nlwps != 1) ? "*" : wbuf);
break;
case 'w':
while (lp != NULL) {
if (l.l_wchan && l.l_wmesg) {
db_read_bytes((db_addr_t)l.l_wmesg,
sizeof(wbuf), (char *)wbuf);
} else {
wbuf[0] = '\0';
}
db_read_bytes((db_addr_t)&p.p_emul->e_name,
sizeof(ename), (char *)&ename);
db_read_bytes((db_addr_t)ename,
sizeof(db_nbuf), db_nbuf);
db_printf(
"%4d %16s %8s %4d %-12s %-18lx\n",
l.l_lid, p.p_comm, db_nbuf,
l.l_priority, wbuf, (long)l.l_wchan);
lp = LIST_NEXT((&l), l_sibling);
if (lp != NULL) {
db_printf("%-5d", p.p_pid);
db_read_bytes((db_addr_t)lp, sizeof(l),
(char *)&l);
}
}
break;
}
}
}

39
sys/ddb/db_proc.h Normal file
View File

@ -0,0 +1,39 @@
/* $NetBSD: db_proc.h,v 1.1 2009/03/07 22:02:17 ad Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _DDB_DB_PROC_H_
#define _DDB_DB_PROC_H_
struct proc *db_proc_first(void);
struct proc *db_proc_next(struct proc *);
struct proc *db_proc_find(pid_t);
#endif /* _DDB_DB_PROC_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_sym.c,v 1.58 2008/11/30 18:21:36 martin Exp $ */ /* $NetBSD: db_sym.c,v 1.59 2009/03/07 22:02:17 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -27,22 +27,18 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_sym.c,v 1.58 2008/11/30 18:21:36 martin Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_sym.c,v 1.59 2009/03/07 22:02:17 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddbparam.h" #include "opt_ddbparam.h"
#endif
#include <sys/param.h> #include <sys/param.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <sys/systm.h> #include <sys/systm.h>
#include <sys/ksyms.h> #include <sys/ksyms.h>
#include <machine/db_machdep.h> #include <ddb/ddb.h>
#include <ddb/db_lex.h>
#include <ddb/db_sym.h>
#include <ddb/db_output.h>
#include <ddb/db_extern.h>
#include <ddb/db_command.h>
static void db_symsplit(char *, char **, char **); static void db_symsplit(char *, char **, char **);
@ -54,6 +50,7 @@ static int using_aout_symtab;
const db_symformat_t *db_symformat; const db_symformat_t *db_symformat;
static db_forall_func_t db_sift; static db_forall_func_t db_sift;
extern db_symformat_t db_symformat_aout; extern db_symformat_t db_symformat_aout;
extern db_symformat_t db_symformat_elf;
#endif #endif
@ -65,14 +62,22 @@ extern db_symformat_t db_symformat_aout;
void void
ddb_init(int symsize, void *vss, void *vse) ddb_init(int symsize, void *vss, void *vse)
{ {
#ifdef DB_AOUT_SYMBOLS #ifdef _KERNEL
# ifdef DB_AOUT_SYMBOLS
db_symformat = &db_symformat_aout; db_symformat = &db_symformat_aout;
if ((*db_symformat->sym_init)(symsize, vss, vse, TBLNAME) == true) { if ((*db_symformat->sym_init)(symsize, vss, vse, TBLNAME) == true) {
using_aout_symtab = true; using_aout_symtab = true;
return; return;
} }
#endif # endif
ksyms_addsyms_elf(symsize, vss, vse); /* Will complain if necessary */ ksyms_addsyms_elf(symsize, vss, vse); /* Will complain if necessary */
#else /* _KERNEL */
db_symformat = &db_symformat_elf;
if ((*db_symformat->sym_init)(symsize, vss, vse, TBLNAME) == true) {
using_aout_symtab = true;
return;
}
#endif /* _KERNEL */
} }
bool bool
@ -91,8 +96,10 @@ db_value_of_name(const char *name, db_expr_t *valuep)
{ {
char symbol[128]; char symbol[128];
char *mod, *sym; char *mod, *sym;
#ifdef _KERNEL
unsigned long uval; unsigned long uval;
long val; long val;
#endif
#ifdef DB_AOUT_SYMBOLS #ifdef DB_AOUT_SYMBOLS
db_sym_t ssym; db_sym_t ssym;
@ -111,6 +118,7 @@ db_value_of_name(const char *name, db_expr_t *valuep)
#endif #endif
(void)strlcpy(symbol, name, sizeof(symbol)); (void)strlcpy(symbol, name, sizeof(symbol));
db_symsplit(symbol, &mod, &sym); db_symsplit(symbol, &mod, &sym);
#ifdef _KERNEL
if (ksyms_getval_unlocked(mod, sym, &uval, KSYMS_EXTERN) == 0) { if (ksyms_getval_unlocked(mod, sym, &uval, KSYMS_EXTERN) == 0) {
val = (long) uval; val = (long) uval;
*valuep = (db_expr_t)val; *valuep = (db_expr_t)val;
@ -121,6 +129,7 @@ db_value_of_name(const char *name, db_expr_t *valuep)
*valuep = (db_expr_t)val; *valuep = (db_expr_t)val;
return true; return true;
} }
#endif
return false; return false;
} }
@ -180,7 +189,9 @@ db_sift(db_symtab_t *stab, db_sym_t sym, char *name,
void void
db_sifting(char *symstr, int mode) db_sifting(char *symstr, int mode)
{ {
#ifdef _KERNEL
char *mod, *sym; char *mod, *sym;
#endif
#ifdef DB_AOUT_SYMBOLS #ifdef DB_AOUT_SYMBOLS
struct db_sift_args dsa; struct db_sift_args dsa;
@ -194,9 +205,11 @@ db_sifting(char *symstr, int mode)
} }
#endif #endif
#ifdef _KERNEL
db_symsplit(symstr, &mod, &sym); db_symsplit(symstr, &mod, &sym);
if (ksyms_sift(mod, sym, mode) == ENODEV) if (ksyms_sift(mod, sym, mode) == ENODEV)
db_error("invalid symbol table name"); db_error("invalid symbol table name");
#endif
} }
/* /*
@ -207,10 +220,12 @@ db_sym_t
db_search_symbol(db_addr_t val, db_strategy_t strategy, db_expr_t *offp) db_search_symbol(db_addr_t val, db_strategy_t strategy, db_expr_t *offp)
{ {
unsigned int diff; unsigned int diff;
unsigned long naddr;
db_sym_t ret = DB_SYM_NULL; db_sym_t ret = DB_SYM_NULL;
#ifdef _KERNEL
unsigned long naddr;
const char *mod; const char *mod;
const char *sym; const char *sym;
#endif
#ifdef DB_AOUT_SYMBOLS #ifdef DB_AOUT_SYMBOLS
db_expr_t newdiff; db_expr_t newdiff;
@ -229,11 +244,13 @@ db_search_symbol(db_addr_t val, db_strategy_t strategy, db_expr_t *offp)
} }
#endif #endif
#ifdef _KERNEL
if (ksyms_getname(&mod, &sym, (vaddr_t)val, strategy) == 0) { if (ksyms_getname(&mod, &sym, (vaddr_t)val, strategy) == 0) {
(void)ksyms_getval_unlocked(mod, sym, &naddr, KSYMS_ANY); (void)ksyms_getval_unlocked(mod, sym, &naddr, KSYMS_ANY);
diff = val - (db_addr_t)naddr; diff = val - (db_addr_t)naddr;
ret = (db_sym_t)naddr; ret = (db_sym_t)naddr;
} else } else
#endif
diff = 0; diff = 0;
*offp = diff; *offp = diff;
return ret; return ret;
@ -245,7 +262,9 @@ db_search_symbol(db_addr_t val, db_strategy_t strategy, db_expr_t *offp)
void void
db_symbol_values(db_sym_t sym, const char **namep, db_expr_t *valuep) db_symbol_values(db_sym_t sym, const char **namep, db_expr_t *valuep)
{ {
#ifdef _KERNEL
const char *mod; const char *mod;
#endif
if (sym == DB_SYM_NULL) { if (sym == DB_SYM_NULL) {
*namep = 0; *namep = 0;
@ -262,11 +281,13 @@ db_symbol_values(db_sym_t sym, const char **namep, db_expr_t *valuep)
} }
#endif #endif
#ifdef _KERNEL
if (ksyms_getname(&mod, namep, (vaddr_t)sym, if (ksyms_getname(&mod, namep, (vaddr_t)sym,
KSYMS_ANY|KSYMS_EXACT) == 0) { KSYMS_ANY|KSYMS_EXACT) == 0) {
if (valuep) if (valuep)
*valuep = sym; *valuep = sym;
} else } else
#endif
*namep = NULL; *namep = NULL;
} }
@ -297,8 +318,10 @@ void
db_symstr(char *buf, size_t buflen, db_expr_t off, db_strategy_t strategy) db_symstr(char *buf, size_t buflen, db_expr_t off, db_strategy_t strategy)
{ {
const char *name; const char *name;
#ifdef _KERNEL
const char *mod; const char *mod;
unsigned long val; unsigned long val;
#endif
#ifdef DB_AOUT_SYMBOLS #ifdef DB_AOUT_SYMBOLS
if (using_aout_symtab) { if (using_aout_symtab) {
@ -336,6 +359,7 @@ db_symstr(char *buf, size_t buflen, db_expr_t off, db_strategy_t strategy)
return; return;
} }
#endif #endif
#ifdef _KERNEL
if (ksyms_getname(&mod, &name, (vaddr_t)off, if (ksyms_getname(&mod, &name, (vaddr_t)off,
strategy|KSYMS_CLOSEST) == 0) { strategy|KSYMS_CLOSEST) == 0) {
(void)ksyms_getval_unlocked(mod, name, &val, KSYMS_ANY); (void)ksyms_getval_unlocked(mod, name, &val, KSYMS_ANY);
@ -358,6 +382,7 @@ db_symstr(char *buf, size_t buflen, db_expr_t off, db_strategy_t strategy)
} }
} }
strlcpy(buf, db_num_to_str(off), buflen); strlcpy(buf, db_num_to_str(off), buflen);
#endif
} }
void void
@ -365,9 +390,11 @@ db_printsym(db_expr_t off, db_strategy_t strategy,
void (*pr)(const char *, ...)) void (*pr)(const char *, ...))
{ {
const char *name; const char *name;
#ifdef _KERNEL
const char *mod; const char *mod;
unsigned long uval; unsigned long uval;
long val; long val;
#endif
#ifdef notyet #ifdef notyet
char *filename; char *filename;
int linenum; int linenum;
@ -407,6 +434,7 @@ db_printsym(db_expr_t off, db_strategy_t strategy,
return; return;
} }
#endif #endif
#ifdef _KERNEL
if (ksyms_getname(&mod, &name, (vaddr_t)off, if (ksyms_getname(&mod, &name, (vaddr_t)off,
strategy|KSYMS_CLOSEST) == 0) { strategy|KSYMS_CLOSEST) == 0) {
(void)ksyms_getval_unlocked(mod, name, &uval, KSYMS_ANY); (void)ksyms_getval_unlocked(mod, name, &uval, KSYMS_ANY);
@ -428,6 +456,7 @@ db_printsym(db_expr_t off, db_strategy_t strategy,
return; return;
} }
} }
#endif
(*pr)(db_num_to_str(off)); (*pr)(db_num_to_str(off));
return; return;
} }

65
sys/ddb/db_user.h Normal file
View File

@ -0,0 +1,65 @@
/* $NetBSD: db_user.h,v 1.1 2009/03/07 22:02:17 ad Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Andrew Doran.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _DDB_DB_USER_H_
#define _DDB_DB_USER_H_
#ifndef _KERNEL
#include <sys/errno.h>
#include <sys/uio.h>
#include <machine/vmparam.h>
#include <uvm/uvm_extern.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
#include <setjmp.h>
#define KASSERT assert
#define KDASSERT assert
#define longjmp(a) longjmp((void *)(a), 1)
#define setjmp(a) setjmp((void *)(a))
typedef jmp_buf label_t;
#ifndef offsetof
#define offsetof(type, member) \
((size_t)(unsigned long)(&(((type *)0)->member)))
#endif
int cngetc(void);
void cnputc(int);
#endif /* !_KERNEL */
#endif /* !_DDB_DB_USER_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_variables.c,v 1.40 2009/01/30 21:30:56 ad Exp $ */ /* $NetBSD: db_variables.c,v 1.41 2009/03/07 22:02:17 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -27,27 +27,20 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_variables.c,v 1.40 2009/01/30 21:30:56 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_variables.c,v 1.41 2009/03/07 22:02:17 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddbparam.h" #include "opt_ddbparam.h"
#endif
#include <sys/param.h> #include <sys/param.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <uvm/uvm_extern.h> #include <uvm/uvm_extern.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <machine/db_machdep.h> #include <ddb/ddb.h>
#include <ddb/ddbvar.h> #include <ddb/ddbvar.h>
#include <ddb/db_lex.h>
#include <ddb/db_variables.h>
#include <ddb/db_command.h>
#include <ddb/db_sym.h>
#include <ddb/db_extern.h>
#include <ddb/db_output.h>
/* /*
* If this is non-zero, the DDB will be entered when the system * If this is non-zero, the DDB will be entered when the system
* panics. Initialize it so that it's patchable. * panics. Initialize it so that it's patchable.
@ -108,6 +101,7 @@ db_rw_internal_variable(const struct db_variable *vp, db_expr_t *valp, int rw)
/* /*
* sysctl(3) access to the DDB variables defined above. * sysctl(3) access to the DDB variables defined above.
*/ */
#ifdef _KERNEL
SYSCTL_SETUP(sysctl_ddb_setup, "sysctl ddb subtree setup") SYSCTL_SETUP(sysctl_ddb_setup, "sysctl ddb subtree setup")
{ {
@ -174,6 +168,7 @@ SYSCTL_SETUP(sysctl_ddb_setup, "sysctl ddb subtree setup")
NULL, 0, &db_cmd_on_enter, DB_LINE_MAXLEN, NULL, 0, &db_cmd_on_enter, DB_LINE_MAXLEN,
CTL_DDB, CTL_CREATE, CTL_EOL); CTL_DDB, CTL_CREATE, CTL_EOL);
} }
#endif /* _KERNEL */
int int
db_find_variable(const struct db_variable **varp) db_find_variable(const struct db_variable **varp)

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_write_cmd.c,v 1.22 2007/02/22 06:41:01 thorpej Exp $ */ /* $NetBSD: db_write_cmd.c,v 1.23 2009/03/07 22:02:17 ad Exp $ */
/* /*
* Mach Operating System * Mach Operating System
@ -30,19 +30,12 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_write_cmd.c,v 1.22 2007/02/22 06:41:01 thorpej Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_write_cmd.c,v 1.23 2009/03/07 22:02:17 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/proc.h> #include <sys/proc.h>
#include <machine/db_machdep.h> #include <ddb/ddb.h>
#include <ddb/db_lex.h>
#include <ddb/db_access.h>
#include <ddb/db_command.h>
#include <ddb/db_sym.h>
#include <ddb/db_extern.h>
#include <ddb/db_output.h>
/* /*
* Write to file. * Write to file.

View File

@ -1,4 +1,4 @@
/* $NetBSD: db_xxx.c,v 1.56 2009/02/18 13:31:59 yamt Exp $ */ /* $NetBSD: db_xxx.c,v 1.57 2009/03/07 22:02:17 ad Exp $ */
/* /*
* Copyright (c) 1982, 1986, 1989, 1991, 1993 * Copyright (c) 1982, 1986, 1989, 1991, 1993
@ -37,10 +37,14 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.56 2009/02/18 13:31:59 yamt Exp $"); __KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.57 2009/03/07 22:02:17 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_kgdb.h" #include "opt_kgdb.h"
#include "opt_aio.h" #include "opt_aio.h"
#endif
#include <ddb/db_user.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -54,6 +58,7 @@ __KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.56 2009/02/18 13:31:59 yamt Exp $");
#include <sys/signalvar.h> #include <sys/signalvar.h>
#include <sys/resourcevar.h> #include <sys/resourcevar.h>
#include <sys/pool.h> #include <sys/pool.h>
#include <sys/uio.h>
#include <sys/kauth.h> #include <sys/kauth.h>
#include <sys/mqueue.h> #include <sys/mqueue.h>
#include <sys/vnode.h> #include <sys/vnode.h>
@ -61,15 +66,8 @@ __KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.56 2009/02/18 13:31:59 yamt Exp $");
#include <sys/cpu.h> #include <sys/cpu.h>
#include <sys/vmem.h> #include <sys/vmem.h>
#include <machine/db_machdep.h> #include <ddb/ddb.h>
#include <ddb/db_access.h>
#include <ddb/db_command.h>
#include <ddb/db_interface.h>
#include <ddb/db_lex.h>
#include <ddb/db_output.h>
#include <ddb/db_sym.h>
#include <ddb/db_extern.h>
#ifdef KGDB #ifdef KGDB
#include <sys/kgdb.h> #include <sys/kgdb.h>
#endif #endif
@ -78,37 +76,8 @@ void
db_kill_proc(db_expr_t addr, bool haddr, db_kill_proc(db_expr_t addr, bool haddr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
struct proc *p;
db_expr_t pid, sig;
int t;
/* What pid? */ db_printf("This command is not currently supported.\n");
if (!db_expression(&pid)) {
db_error("pid?\n");
/*NOTREACHED*/
}
/* What sig? */
t = db_read_token();
if (t == tCOMMA) {
if (!db_expression(&sig)) {
db_error("sig?\n");
/*NOTREACHED*/
}
} else {
db_unread_token(t);
sig = 15;
}
if (db_read_token() != tEOL) {
db_error("?\n");
/*NOTREACHED*/
}
p = pfind((pid_t)pid);
if (p == NULL) {
db_error("no such proc\n");
/*NOTREACHED*/
}
psignal(p, (int)sig);
} }
#ifdef KGDB #ifdef KGDB
@ -126,6 +95,7 @@ void
db_show_files_cmd(db_expr_t addr, bool haddr, db_show_files_cmd(db_expr_t addr, bool haddr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
struct proc *p; struct proc *p;
int i; int i;
filedesc_t *fdp; filedesc_t *fdp;
@ -161,6 +131,7 @@ db_show_files_cmd(db_expr_t addr, bool haddr,
} }
} }
} }
#endif
} }
#ifdef AIO #ifdef AIO
@ -168,6 +139,7 @@ void
db_show_aio_jobs(db_expr_t addr, bool haddr, db_show_aio_jobs(db_expr_t addr, bool haddr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
aio_print_jobs(db_printf); aio_print_jobs(db_printf);
} }
#endif #endif
@ -176,135 +148,20 @@ void
db_show_mqueue_cmd(db_expr_t addr, bool haddr, db_show_mqueue_cmd(db_expr_t addr, bool haddr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
mqueue_print_list(db_printf); mqueue_print_list(db_printf);
#endif
} }
void void
db_show_module_cmd(db_expr_t addr, bool haddr, db_show_module_cmd(db_expr_t addr, bool haddr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
module_print_list(db_printf); module_print_list(db_printf);
} #endif
void
db_show_all_procs(db_expr_t addr, bool haddr,
db_expr_t count, const char *modif)
{
const char *mode;
struct proc *p, *pp;
struct lwp *l, *cl;
const struct proclist_desc *pd;
char db_nbuf[MAXCOMLEN + 1];
bool run;
int cpuno;
if (modif[0] == 0)
mode = "l"; /* default == lwp mode */
else
mode = strchr("mawln", modif[0]);
if (mode == NULL || *mode == 'm') {
db_printf("usage: show all procs [/a] [/l] [/n] [/w]\n");
db_printf("\t/a == show process address info\n");
db_printf("\t/l == show LWP info\n");
db_printf("\t/n == show normal process info [default]\n");
db_printf("\t/w == show process wait/emul info\n");
return;
}
switch (*mode) {
case 'a':
db_printf("PID %10s %18s %18s %18s\n",
"COMMAND", "STRUCT PROC *", "UAREA *", "VMSPACE/VM_MAP");
break;
case 'l':
db_printf("PID %4s S %3s %9s %18s %18s %-8s\n",
"LID", "CPU", "FLAGS", "STRUCT LWP *", "NAME", "WAIT");
break;
case 'n':
db_printf("PID %8s %8s %10s S %7s %4s %16s %7s\n",
"PPID", "PGRP", "UID", "FLAGS", "LWPS", "COMMAND", "WAIT");
break;
case 'w':
db_printf("PID %4s %16s %8s %4s %-12s%s\n",
"LID", "COMMAND", "EMUL", "PRI", "WAIT-MSG",
"WAIT-CHANNEL");
break;
}
pd = proclists;
cl = curlwp;
for (pd = proclists; pd->pd_list != NULL; pd++) {
LIST_FOREACH(p, pd->pd_list, p_list) {
pp = p->p_pptr;
if (p->p_stat == 0) {
continue;
}
l = LIST_FIRST(&p->p_lwps);
db_printf("%-5d", p->p_pid);
switch (*mode) {
case 'a':
db_printf("%10.10s %18lx %18lx %18lx\n",
p->p_comm, (long)p,
(long)(l != NULL ? l->l_addr : 0),
(long)p->p_vmspace);
break;
case 'l':
while (l != NULL) {
if (l->l_name != NULL) {
snprintf(db_nbuf,
sizeof(db_nbuf),
"%s", l->l_name);
} else
snprintf(db_nbuf,
sizeof(db_nbuf),
"%s", p->p_comm);
run = (l->l_stat == LSONPROC ||
(l->l_pflag & LP_RUNNING) != 0);
if (l->l_cpu != NULL)
cpuno = cpu_index(l->l_cpu);
else
cpuno = -1;
db_printf("%c%4d %d %3d %9x %18lx %18s %-8s\n",
(run ? '>' : ' '), l->l_lid,
l->l_stat, cpuno, l->l_flag, (long)l,
db_nbuf,
(l->l_wchan && l->l_wmesg) ?
l->l_wmesg : "");
l = LIST_NEXT(l, l_sibling);
if (l)
db_printf("%11s","");
}
break;
case 'n':
db_printf("%8d %8d %10d %d %#7x %4d %16s %7.7s\n",
pp ? pp->p_pid : -1, p->p_pgrp->pg_id,
kauth_cred_getuid(p->p_cred), p->p_stat, p->p_flag,
p->p_nlwps, p->p_comm,
(p->p_nlwps != 1) ? "*" : (
(l->l_wchan && l->l_wmesg) ?
l->l_wmesg : ""));
break;
case 'w':
while (l != NULL) {
db_printf(
"%4d %16s %8s %4d %-12s %-18lx\n",
l->l_lid, p->p_comm,
p->p_emul->e_name, l->l_priority,
(l->l_wchan && l->l_wmesg) ?
l->l_wmesg : "", (long)l->l_wchan);
l = LIST_NEXT(l, l_sibling);
if (l)
db_printf("%11s","");
}
break;
}
}
}
} }
void void
@ -312,7 +169,9 @@ db_show_all_pools(db_expr_t addr, bool haddr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
pool_printall(modif, db_printf); pool_printall(modif, db_printf);
#endif
} }
void void
@ -320,13 +179,16 @@ db_show_all_vmems(db_expr_t addr, bool have_addr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
vmem_printall(modif, db_printf); vmem_printall(modif, db_printf);
#endif
} }
void void
db_dmesg(db_expr_t addr, bool haddr, db_expr_t count, db_dmesg(db_expr_t addr, bool haddr, db_expr_t count,
const char *modif) const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
struct kern_msgbuf *mbp; struct kern_msgbuf *mbp;
db_expr_t print; db_expr_t print;
int ch, newl, skip, i; int ch, newl, skip, i;
@ -369,6 +231,7 @@ db_dmesg(db_expr_t addr, bool haddr, db_expr_t count,
} }
if (!newl) if (!newl)
db_printf("\n"); db_printf("\n");
#endif
} }
void void
@ -376,5 +239,7 @@ db_show_sched_qs(db_expr_t addr, bool haddr,
db_expr_t count, const char *modif) db_expr_t count, const char *modif)
{ {
#ifdef _KERNEL /* XXX CRASH(8) */
sched_print_runqueue(db_printf); sched_print_runqueue(db_printf);
#endif
} }

17
sys/ddb/ddb.h Normal file
View File

@ -0,0 +1,17 @@
#include <machine/db_machdep.h> /* type definitions */
#include <ddb/db_user.h>
#include <ddb/db_lex.h>
#include <ddb/db_output.h>
#include <ddb/db_command.h>
#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>
#include <ddb/db_lwp.h>
#include <ddb/db_access.h>
#include <ddb/db_proc.h>
#include <ddb/db_cpu.h>

View File

@ -1,4 +1,4 @@
# $NetBSD: files.ddb,v 1.2 2007/09/22 18:40:27 martin Exp $ # $NetBSD: files.ddb,v 1.3 2009/03/07 22:02:17 ad Exp $
# #
# DDB options # DDB options
@ -12,11 +12,15 @@ file ddb/db_access.c ddb | kgdb # XXX kgdb reference
file ddb/db_aout.c ddb file ddb/db_aout.c ddb
file ddb/db_break.c ddb file ddb/db_break.c ddb
file ddb/db_command.c ddb file ddb/db_command.c ddb
file ddb/db_cpu.c ddb
file ddb/db_examine.c ddb file ddb/db_examine.c ddb
file ddb/db_expr.c ddb file ddb/db_expr.c ddb
file ddb/db_input.c ddb file ddb/db_input.c ddb
file ddb/db_kernel.c ddb
file ddb/db_lex.c ddb file ddb/db_lex.c ddb
file ddb/db_lwp.c ddb
file ddb/db_output.c ddb file ddb/db_output.c ddb
file ddb/db_proc.c ddb
file ddb/db_print.c ddb file ddb/db_print.c ddb
file ddb/db_run.c ddb | kgdb # XXX kgdb reference file ddb/db_run.c ddb | kgdb # XXX kgdb reference
file ddb/db_sym.c ddb file ddb/db_sym.c ddb