Add a new 'why' argument to kdb_enter(), and a set of constants to use

for that argument.  This will allow DDB to detect the broad category of
reason why the debugger has been entered, which it can use for the
purposes of deciding which DDB script to run.

Assign approximate why values to all current consumers of the
kdb_enter() interface.
This commit is contained in:
Robert Watson 2007-12-25 17:52:02 +00:00
parent 6862d27ecd
commit 3de213cc00
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=174898
33 changed files with 95 additions and 48 deletions

View File

@ -1277,7 +1277,8 @@ hammer_time(u_int64_t modulep, u_int64_t physfree)
#ifdef KDB
if (boothowto & RB_KDB)
kdb_enter("Boot flags requested debugger");
kdb_enter(KDB_WHY_BOOTFLAGS,
"Boot flags requested debugger");
#endif
identify_cpu(); /* Final stage of CPU initialization */

View File

@ -203,7 +203,7 @@ ap_watchdog(u_int cpuid)
if (watchdog_nmi)
watchdog_ipi_nmi();
else
kdb_enter("mp_watchdog");
kdb_enter(KDB_WHY_WATCHDOG, "mp_watchdog");
}
}
bcopy(old_pcomm, p->p_comm, MAXCOMLEN + 1);

View File

@ -508,7 +508,7 @@ at91_rx_put(struct uart_softc *sc, int key)
#if defined(KDB) && defined(ALT_BREAK_TO_DEBUGGER)
if (sc->sc_sysdev != NULL && sc->sc_sysdev->type == UART_DEV_CONSOLE) {
if (kdb_alt_break(key, &sc->sc_altbrk))
kdb_enter("Break sequence to console");
kdb_enter(KDB_WHY_BREAK, "Break sequence to console");
}
#endif
uart_rx_put(sc, key);

View File

@ -87,7 +87,7 @@
#ifdef __FreeBSD__
#undef MSG_IDENTIFY
#define SCSI_LOW_DEBUGGER(dev) kdb_enter(dev)
#define SCSI_LOW_DEBUGGER(dev) kdb_enter(KDB_WHY_CAM, dev)
#define SCSI_LOW_DELAY(mu) DELAY((mu))
#define SCSI_LOW_SPLSCSI splcam
#define SCSI_LOW_BZERO(pt, size) bzero((pt), (size))

View File

@ -3632,7 +3632,7 @@ DbgBreakPoint(void)
#if __FreeBSD_version < 502113
Debugger("DbgBreakPoint(): breakpoint");
#else
kdb_enter("DbgBreakPoint(): breakpoint");
kdb_enter(KDB_WHY_NDIS, "DbgBreakPoint(): breakpoint");
#endif
}

View File

@ -73,13 +73,13 @@ AcpiOsSignal(UINT32 Function, void *Info)
printf("ACPI fatal signal, type 0x%x code 0x%x argument 0x%x",
fatal->Type, fatal->Code, fatal->Argument);
#ifdef ACPI_DEBUG
kdb_enter("AcpiOsSignal");
kdb_enter(KDB_WHY_ACPI, "AcpiOsSignal");
#endif
break;
case ACPI_SIGNAL_BREAKPOINT:
#ifdef ACPI_DEBUG
kdb_enter((char *)Info);
kdb_enter(KDB_WHY_ACPI, (char *)Info);
#endif
break;

View File

@ -207,11 +207,13 @@ dcons_check_break(struct dcons_softc *dc, int c)
#ifdef GDB
if (gdb_cur == &dcons_gdb_dbgport) {
kdb_dbbe_select("gdb");
kdb_enter("Break sequence on dcons gdb port");
kdb_enter(KDB_WHY_BREAK,
"Break sequence on dcons gdb port");
}
#endif
} else
kdb_enter("Break sequence on dcons console port");
kdb_enter(KDB_WHY_BREAK,
"Break sequence on dcons console port");
}
#else
switch (dc->brk_state) {

View File

@ -282,7 +282,7 @@ ofw_cngetc(struct consdev *cp)
if (OF_read(stdin, &ch, 1) > 0) {
#if defined(KDB) && defined(ALT_BREAK_TO_DEBUGGER)
if (kdb_alt_break(ch, &alt_break_state))
kdb_enter("Break sequence on console");
kdb_enter(KDB_WHY_BREAK, "Break sequence on console");
#endif
return (ch);
}

View File

@ -1502,7 +1502,8 @@ siointr1(com)
#ifdef ALT_BREAK_TO_DEBUGGER
if (com->unit == comconsole &&
kdb_alt_break(recv_data, &com->alt_brk_state) != 0)
kdb_enter("Break sequence on console");
kdb_enter(KDB_WHY_BREAK,
"Break sequence on console");
#endif /* ALT_BREAK_TO_DEBUGGER */
#endif /* KDB */
if (line_status & (LSR_BI | LSR_FE | LSR_PE)) {
@ -1521,7 +1522,8 @@ siointr1(com)
if (line_status & LSR_BI) {
#if defined(KDB) && defined(BREAK_TO_DEBUGGER)
if (com->unit == comconsole) {
kdb_enter("Line break on console");
kdb_enter(KDB_WHY_BREAK,
"Line break on console");
goto cont;
}
#endif

View File

@ -3373,7 +3373,7 @@ scgetc(sc_softc_t *sc, u_int flags)
case DBG:
#ifndef SC_DISABLE_KDBKEY
if (enable_kdbkey)
kdb_enter("manual escape to debugger");
kdb_enter(KDB_WHY_BREAK, "manual escape to debugger");
#endif
break;

View File

@ -122,7 +122,7 @@ uart_intr_break(void *arg)
#if defined(KDB) && defined(BREAK_TO_DEBUGGER)
if (sc->sc_sysdev != NULL && sc->sc_sysdev->type == UART_DEV_CONSOLE) {
kdb_enter("Line break on console");
kdb_enter(KDB_WHY_BREAK, "Line break on console");
return (0);
}
#endif
@ -176,7 +176,8 @@ uart_intr_rxready(void *arg)
if (sc->sc_sysdev != NULL && sc->sc_sysdev->type == UART_DEV_CONSOLE) {
while (rxp != sc->sc_rxput) {
if (kdb_alt_break(sc->sc_rxbuf[rxp++], &sc->sc_altbrk))
kdb_enter("Break sequence on console");
kdb_enter(KDB_WHY_BREAK,
"Break sequence on console");
if (rxp == sc->sc_rxbufsz)
rxp = 0;
}

View File

@ -1062,7 +1062,8 @@ unionfs_checkuppervp(struct vnode *vp, char *fil, int lno)
if (vp->v_op != unionfs_vnodeop_p) {
printf("unionfs_checkuppervp: on non-unionfs-node.\n");
#ifdef KDB
kdb_enter("unionfs_checkuppervp: on non-unionfs-node.\n");
kdb_enter(KDB_WHY_UNIONFS,
"unionfs_checkuppervp: on non-unionfs-node.\n");
#endif
panic("unionfs_checkuppervp");
};
@ -1081,7 +1082,8 @@ unionfs_checklowervp(struct vnode *vp, char *fil, int lno)
if (vp->v_op != unionfs_vnodeop_p) {
printf("unionfs_checklowervp: on non-unionfs-node.\n");
#ifdef KDB
kdb_enter("unionfs_checklowervp: on non-unionfs-node.\n");
kdb_enter(KDB_WHY_UNIONFS,
"unionfs_checklowervp: on non-unionfs-node.\n");
#endif
panic("unionfs_checklowervp");
};

View File

@ -2275,7 +2275,7 @@ init386(first)
#ifdef KDB
if (boothowto & RB_KDB)
kdb_enter("Boot flags requested debugger");
kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
#endif
finishidentcpu(); /* Final stage of CPU initialization */

View File

@ -203,7 +203,7 @@ ap_watchdog(u_int cpuid)
if (watchdog_nmi)
watchdog_ipi_nmi();
else
kdb_enter("mp_watchdog");
kdb_enter(KDB_WHY_WATCHDOG, "mp_watchdog");
}
}
bcopy(old_pcomm, p->p_comm, MAXCOMLEN + 1);

View File

@ -824,7 +824,8 @@ ia64_init(void)
#ifdef KDB
if (boothowto & RB_KDB)
kdb_enter("Boot flags requested debugger\n");
kdb_enter(KDB_WHY_BOOTFLAGS,
"Boot flags requested debugger\n");
#endif
ia64_set_tpr(0);

View File

@ -637,7 +637,7 @@ watchdog_fire(void)
#if defined(KDB) && !defined(KDB_UNATTENDED)
kdb_backtrace();
kdb_enter("watchdog timeout");
kdb_enter(KDB_WHY_WATCHDOG, "watchdog timeout");
#else
panic("watchdog timeout");
#endif

View File

@ -544,7 +544,7 @@ panic(const char *fmt, ...)
if (newpanic && trace_on_panic)
kdb_backtrace();
if (debugger_on_panic)
kdb_enter("panic");
kdb_enter(KDB_WHY_PANIC, "panic");
#ifdef RESTARTABLE_PANICS
/* See if the user aborted the panic, in which case we continue. */
if (panicstr == NULL) {

View File

@ -97,6 +97,11 @@ SYSCTL_INT(_debug_kdb, OID_AUTO, stop_cpus, CTLTYPE_INT | CTLFLAG_RW,
TUNABLE_INT("debug.kdb.stop_cpus", &kdb_stop_cpus);
#endif
/*
* Flag to indicate to debuggers why the debugger was entered.
*/
const char * volatile kdb_why = KDB_WHY_UNSET;
static int
kdb_sysctl_available(SYSCTL_HANDLER_ARGS)
{
@ -163,7 +168,7 @@ kdb_sysctl_enter(SYSCTL_HANDLER_ARGS)
return (error);
if (kdb_active)
return (EBUSY);
kdb_enter("sysctl debug.kdb.enter");
kdb_enter(KDB_WHY_SYSCTL, "sysctl debug.kdb.enter");
return (0);
}
@ -295,17 +300,20 @@ kdb_dbbe_select(const char *name)
* Enter the currently selected debugger. If a message has been provided,
* it is printed first. If the debugger does not support the enter method,
* it is entered by using breakpoint(), which enters the debugger through
* kdb_trap().
* kdb_trap(). The 'why' argument will contain a more mechanically usable
* string than 'msg', and is relied upon by DDB scripting to identify the
* reason for entering the debugger so that the right script can be run.
*/
void
kdb_enter(const char *msg)
kdb_enter(const char *why, const char *msg)
{
if (kdb_dbbe != NULL && kdb_active == 0) {
if (msg != NULL)
printf("KDB: enter: %s\n", msg);
kdb_why = why;
breakpoint();
kdb_why = KDB_WHY_UNSET;
}
}

View File

@ -1123,7 +1123,7 @@ witness_checkorder(struct lock_object *lock, int flags, const char *file,
if (witness_trace)
kdb_backtrace();
if (witness_kdb)
kdb_enter(__func__);
kdb_enter(KDB_WHY_WITNESS, __func__);
#endif
}
@ -1396,7 +1396,7 @@ witness_warn(int flags, struct lock_object *lock, const char *fmt, ...)
panic("witness_warn");
#ifdef KDB
else if (witness_kdb && n)
kdb_enter(__func__);
kdb_enter(KDB_WHY_WITNESS, __func__);
else if (witness_trace && n)
kdb_backtrace();
#endif

View File

@ -3456,7 +3456,7 @@ vfs_badlock(const char *msg, const char *str, struct vnode *vp)
if (vfs_badlock_print)
printf("%s: %p %s\n", str, (void *)vp, msg);
if (vfs_badlock_ddb)
kdb_enter("lock violation");
kdb_enter(KDB_WHY_VFSLOCK, "lock violation");
}
void
@ -3576,7 +3576,7 @@ vop_strategy_pre(void *ap)
printf(
"VOP_STRATEGY: bp is not locked but should be\n");
if (vfs_badlock_ddb)
kdb_enter("lock violation");
kdb_enter(KDB_WHY_VFSLOCK, "lock violation");
}
#endif
}

View File

@ -3465,12 +3465,12 @@ ng_setisr(node_p node)
do { \
if (NGI_NODE(item) ) { \
printf("item already has node"); \
kdb_enter("has node"); \
kdb_enter(KDB_WHY_NETGRAPH, "has node"); \
NGI_CLR_NODE(item); \
} \
if (NGI_HOOK(item) ) { \
printf("item already has hook"); \
kdb_enter("has hook"); \
kdb_enter(KDB_WHY_NETGRAPH, "has hook"); \
NGI_CLR_HOOK(item); \
} \
} while (0)

View File

@ -2369,7 +2369,8 @@ status_read:;
#ifdef ALT_BREAK_TO_DEBUGGER
if (com->unit == comconsole &&
kdb_alt_break(recv_data, &com->alt_brk_state) != 0)
kdb_enter("Break sequence on console");
kdb_enter(KDB_WHY_BREAK,
"Break sequence on console");
#endif /* ALT_BREAK_TO_DEBUGGER */
#endif /* KDB */
if (line_status & (LSR_BI | LSR_FE | LSR_PE)) {
@ -2388,7 +2389,8 @@ status_read:;
if (line_status & LSR_BI) {
#if defined(KDB) && defined(BREAK_TO_DEBUGGER)
if (com->unit == comconsole) {
kdb_enter("Line break on console");
kdb_enter(KDB_WHY_BREAK,
"Line break on console");
goto cont;
}
#endif

View File

@ -2061,7 +2061,7 @@ init386(first)
#ifdef KDB
if (boothowto & RB_KDB)
kdb_enter("Boot flags requested debugger");
kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
#endif
finishidentcpu(); /* Final stage of CPU initialization */

View File

@ -398,7 +398,8 @@ powerpc_init(u_int startkernel, u_int endkernel, u_int basekernel, void *mdp)
#ifdef KDB
if (boothowto & RB_KDB)
kdb_enter("Boot flags requested debugger");
kdb_enter(KDB_WHY_BOOTFLAGS,
"Boot flags requested debugger");
#endif
}

View File

@ -139,6 +139,6 @@ pswitch_intr(void *arg)
dev = (device_t)arg;
kdb_enter(device_get_nameunit(dev));
kdb_enter(KDB_WHY_POWERPC, device_get_nameunit(dev));
return (FILTER_HANDLED);
}

View File

@ -117,7 +117,7 @@ SYSCTL_NODE(_security_mac_test, OID_AUTO, counter, CTLFLAG_RW, 0,
#define COUNTER_INC(variable) atomic_add_int(&counter_##variable, 1)
#ifdef KDB
#define DEBUGGER(func, string) kdb_enter((string))
#define DEBUGGER(func, string) kdb_enter(KDB_WHY_MAC, (string))
#else
#define DEBUGGER(func, string) printf("mac_test: %s: %s\n", (func), (string))
#endif

View File

@ -850,7 +850,7 @@ psycho_powerfail(void *arg)
#ifdef DEBUGGER_ON_POWERFAIL
struct psycho_softc *sc = arg;
kdb_enter("powerfail");
kdb_enter(KDB_WHY_POWERFAIL, "powerfail");
#else
static int shutdown;

View File

@ -448,7 +448,7 @@ sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3, ofw_vec_t *vec)
#ifdef KDB
if (boothowto & RB_KDB)
kdb_enter("Boot flags requested debugger");
kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
#endif
}

View File

@ -289,7 +289,7 @@ trap(struct trapframe *tf)
}
if (debugger_on_signal &&
(sig == 4 || sig == 10 || sig == 11))
kdb_enter("trapsig");
kdb_enter(KDB_WHY_TRAPSIG, "trapsig");
ksiginfo_init_trap(&ksi);
ksi.ksi_signo = sig;
ksi.ksi_code = (int)tf->tf_type; /* XXX not POSIX */

View File

@ -224,10 +224,10 @@ hvcn_cngetc(struct consdev *cp)
while ((l = hv_cons_getchar(&ch)) != H_EOK) {
#if defined(KDB)
if (l == H_BREAK || l == H_HUP)
kdb_enter("Break sequence on console");
kdb_enter(KDB_WHY_BREAK, "Break sequence on console");
if (kdb_alt_break(ch, &alt_break_state))
kdb_enter("Break sequence on console");
kdb_enter(KDB_WHY_BREAK, "Break sequence on console");
#endif
if (l != -2 && l != 0) {
return (-1);
@ -248,9 +248,9 @@ hvcn_cncheckc(struct consdev *cp)
if ((l = hv_cons_getchar(&ch)) == H_EOK) {
#if defined(KDB)
if (l == H_BREAK || l == H_HUP)
kdb_enter("Break sequence on console");
kdb_enter(KDB_WHY_BREAK, "Break sequence on console");
if (kdb_alt_break(ch, &alt_break_state))
kdb_enter("Break sequence on console");
kdb_enter(KDB_WHY_BREAK, "Break sequence on console");
#endif
return (ch);
}

View File

@ -510,7 +510,7 @@ sparc64_init(caddr_t mdp, u_long o1, u_long o2, u_long o3, ofw_vec_t *vec)
#ifdef KDB
if (boothowto & RB_KDB)
kdb_enter("Boot flags requested debugger");
kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
#endif
BVPRINTF("sparc64_init done\n");
}

View File

@ -366,7 +366,7 @@ trap(struct trapframe *tf, int64_t type, uint64_t data)
}
if (debugger_on_signal &&
(sig == 4 || sig == 10 || sig == 11))
kdb_enter("trapsig");
kdb_enter(KDB_WHY_TRAPSIG, "trapsig");
#ifdef VERBOSE
if (sig == 4 || sig == 10 || sig == 11)
printf("trap: %ld:%s: 0x%lx at 0x%lx on cpu=%d sig=%d proc=%s\n",

View File

@ -66,7 +66,7 @@ extern struct thread *kdb_thread; /* Current thread. */
int kdb_alt_break(int, int *);
void kdb_backtrace(void);
int kdb_dbbe_select(const char *);
void kdb_enter(const char *);
void kdb_enter(const char *, const char *);
void kdb_init(void);
void * kdb_jmpbuf(jmp_buf);
void kdb_reenter(void);
@ -78,4 +78,31 @@ struct thread *kdb_thr_next(struct thread *);
int kdb_thr_select(struct thread *);
int kdb_trap(int, int, struct trapframe *);
/*
* KDB enters the debugger via breakpoint(), which leaves the debugger without
* a lot of information about why it was entered. This simple enumerated set
* captures some basic information.
*
* It is recommended that values here be short (<16 character) alpha-numeric
* strings, as they will be used to construct DDB(4) script names.
*/
extern const char * volatile kdb_why;
#define KDB_WHY_UNSET NULL /* No reason set. */
#define KDB_WHY_PANIC "panic" /* panic() was called. */
#define KDB_WHY_SYSCTL "sysctl" /* Sysctl entered debugger. */
#define KDB_WHY_BOOTFLAGS "bootflags" /* Boot flags were set. */
#define KDB_WHY_WITNESS "witness" /* Witness entered debugger. */
#define KDB_WHY_VFSLOCK "vfslock" /* VFS detected lock problem. */
#define KDB_WHY_NETGRAPH "netgraph" /* Netgraph entered debugger. */
#define KDB_WHY_BREAK "break" /* Console or serial break. */
#define KDB_WHY_WATCHDOG "watchdog" /* Watchdog entered debugger. */
#define KDB_WHY_CAM "cam" /* CAM has entered debugger. */
#define KDB_WHY_NDIS "ndis" /* NDIS entered debugger. */
#define KDB_WHY_ACPI "acpi" /* ACPI entered debugger. */
#define KDB_WHY_TRAPSIG "trapsig" /* Sun4v/Sparc fault. */
#define KDB_WHY_POWERFAIL "powerfail" /* Powerfail NMI. */
#define KDB_WHY_MAC "mac" /* MAC Framework. */
#define KDB_WHY_POWERPC "powerpc" /* Unhandled powerpc intr. */
#define KDB_WHY_UNIONFS "unionfs" /* Unionfs bug. */
#endif /* !_SYS_KDB_H_ */