aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Watson <rwatson@FreeBSD.org>2007-12-25 17:52:02 +0000
committerRobert Watson <rwatson@FreeBSD.org>2007-12-25 17:52:02 +0000
commit3de213cc00f2889d2cd693968fd38c10a7f5def1 (patch)
treeae45f86ab6fb75519ba2d9dbc206616dba84cc13
parent6862d27ecd3a641713fe08d9572a27bf218cc8d9 (diff)
downloadsrc-3de213cc00f2889d2cd693968fd38c10a7f5def1.tar.gz
src-3de213cc00f2889d2cd693968fd38c10a7f5def1.zip
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.
Notes
Notes: svn path=/head/; revision=174898
-rw-r--r--sys/amd64/amd64/machdep.c3
-rw-r--r--sys/amd64/amd64/mp_watchdog.c2
-rw-r--r--sys/arm/at91/uart_dev_at91usart.c2
-rw-r--r--sys/cam/scsi/scsi_low.h2
-rw-r--r--sys/compat/ndis/subr_ntoskrnl.c2
-rw-r--r--sys/dev/acpica/Osd/OsdDebug.c4
-rw-r--r--sys/dev/dcons/dcons_os.c6
-rw-r--r--sys/dev/ofw/ofw_console.c2
-rw-r--r--sys/dev/sio/sio.c6
-rw-r--r--sys/dev/syscons/syscons.c2
-rw-r--r--sys/dev/uart/uart_core.c5
-rw-r--r--sys/fs/unionfs/union_subr.c6
-rw-r--r--sys/i386/i386/machdep.c2
-rw-r--r--sys/i386/i386/mp_watchdog.c2
-rw-r--r--sys/ia64/ia64/machdep.c3
-rw-r--r--sys/kern/kern_clock.c2
-rw-r--r--sys/kern/kern_shutdown.c2
-rw-r--r--sys/kern/subr_kdb.c16
-rw-r--r--sys/kern/subr_witness.c4
-rw-r--r--sys/kern/vfs_subr.c4
-rw-r--r--sys/netgraph/ng_base.c4
-rw-r--r--sys/pc98/cbus/sio.c6
-rw-r--r--sys/pc98/pc98/machdep.c2
-rw-r--r--sys/powerpc/aim/machdep.c3
-rw-r--r--sys/powerpc/powermac/pswitch.c2
-rw-r--r--sys/security/mac_test/mac_test.c2
-rw-r--r--sys/sparc64/pci/psycho.c2
-rw-r--r--sys/sparc64/sparc64/machdep.c2
-rw-r--r--sys/sparc64/sparc64/trap.c2
-rw-r--r--sys/sun4v/sun4v/hvcons.c8
-rw-r--r--sys/sun4v/sun4v/machdep.c2
-rw-r--r--sys/sun4v/sun4v/trap.c2
-rw-r--r--sys/sys/kdb.h29
33 files changed, 95 insertions, 48 deletions
diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index 24226f7e7e8e..24e9ec842fdd 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -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 */
diff --git a/sys/amd64/amd64/mp_watchdog.c b/sys/amd64/amd64/mp_watchdog.c
index b6ac77731664..1803270b573f 100644
--- a/sys/amd64/amd64/mp_watchdog.c
+++ b/sys/amd64/amd64/mp_watchdog.c
@@ -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);
diff --git a/sys/arm/at91/uart_dev_at91usart.c b/sys/arm/at91/uart_dev_at91usart.c
index 88625899f197..f87dcaaaab64 100644
--- a/sys/arm/at91/uart_dev_at91usart.c
+++ b/sys/arm/at91/uart_dev_at91usart.c
@@ -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);
diff --git a/sys/cam/scsi/scsi_low.h b/sys/cam/scsi/scsi_low.h
index 4dfa6021533d..8d6dbede240d 100644
--- a/sys/cam/scsi/scsi_low.h
+++ b/sys/cam/scsi/scsi_low.h
@@ -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))
diff --git a/sys/compat/ndis/subr_ntoskrnl.c b/sys/compat/ndis/subr_ntoskrnl.c
index 367d9f6593c8..dd76d252ca95 100644
--- a/sys/compat/ndis/subr_ntoskrnl.c
+++ b/sys/compat/ndis/subr_ntoskrnl.c
@@ -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
}
diff --git a/sys/dev/acpica/Osd/OsdDebug.c b/sys/dev/acpica/Osd/OsdDebug.c
index b127181b1c0f..27b94a09d89d 100644
--- a/sys/dev/acpica/Osd/OsdDebug.c
+++ b/sys/dev/acpica/Osd/OsdDebug.c
@@ -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;
diff --git a/sys/dev/dcons/dcons_os.c b/sys/dev/dcons/dcons_os.c
index d47515c9bfaf..7eb89aadbae8 100644
--- a/sys/dev/dcons/dcons_os.c
+++ b/sys/dev/dcons/dcons_os.c
@@ -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) {
diff --git a/sys/dev/ofw/ofw_console.c b/sys/dev/ofw/ofw_console.c
index 0d1133f57ac0..7d6f5ebd9e7e 100644
--- a/sys/dev/ofw/ofw_console.c
+++ b/sys/dev/ofw/ofw_console.c
@@ -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);
}
diff --git a/sys/dev/sio/sio.c b/sys/dev/sio/sio.c
index 3db7f591a426..a62b411da578 100644
--- a/sys/dev/sio/sio.c
+++ b/sys/dev/sio/sio.c
@@ -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
diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c
index 04ad041dec3f..b74989571c0f 100644
--- a/sys/dev/syscons/syscons.c
+++ b/sys/dev/syscons/syscons.c
@@ -3373,7 +3373,7 @@ next_code:
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;
diff --git a/sys/dev/uart/uart_core.c b/sys/dev/uart/uart_core.c
index f99127881e82..b47304184960 100644
--- a/sys/dev/uart/uart_core.c
+++ b/sys/dev/uart/uart_core.c
@@ -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;
}
diff --git a/sys/fs/unionfs/union_subr.c b/sys/fs/unionfs/union_subr.c
index 05dd0771cff8..4ff6308a5180 100644
--- a/sys/fs/unionfs/union_subr.c
+++ b/sys/fs/unionfs/union_subr.c
@@ -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");
};
diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c
index 01fbf1c89657..202e2a921109 100644
--- a/sys/i386/i386/machdep.c
+++ b/sys/i386/i386/machdep.c
@@ -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 */
diff --git a/sys/i386/i386/mp_watchdog.c b/sys/i386/i386/mp_watchdog.c
index b6ac77731664..1803270b573f 100644
--- a/sys/i386/i386/mp_watchdog.c
+++ b/sys/i386/i386/mp_watchdog.c
@@ -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);
diff --git a/sys/ia64/ia64/machdep.c b/sys/ia64/ia64/machdep.c
index 3c44b2e303c6..e6e5d7ff88f1 100644
--- a/sys/ia64/ia64/machdep.c
+++ b/sys/ia64/ia64/machdep.c
@@ -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);
diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c
index 217e2efbd991..fb0ca7e21ce5 100644
--- a/sys/kern/kern_clock.c
+++ b/sys/kern/kern_clock.c
@@ -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
diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c
index 088e781e2335..baeed23f107c 100644
--- a/sys/kern/kern_shutdown.c
+++ b/sys/kern/kern_shutdown.c
@@ -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) {
diff --git a/sys/kern/subr_kdb.c b/sys/kern/subr_kdb.c
index 0ab79fbc2af1..8b66a584ec51 100644
--- a/sys/kern/subr_kdb.c
+++ b/sys/kern/subr_kdb.c
@@ -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;
}
}
diff --git a/sys/kern/subr_witness.c b/sys/kern/subr_witness.c
index 3019a7a4016d..c5402c768f42 100644
--- a/sys/kern/subr_witness.c
+++ b/sys/kern/subr_witness.c
@@ -1123,7 +1123,7 @@ debugger:
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
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 0e3a0ac75b2b..e912006238e6 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -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
}
diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c
index ad0bec6fbb0c..47fde6078755 100644
--- a/sys/netgraph/ng_base.c
+++ b/sys/netgraph/ng_base.c
@@ -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)
diff --git a/sys/pc98/cbus/sio.c b/sys/pc98/cbus/sio.c
index 648cb04667d4..6533a5386e25 100644
--- a/sys/pc98/cbus/sio.c
+++ b/sys/pc98/cbus/sio.c
@@ -2369,7 +2369,8 @@ more_intr:
#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 @@ more_intr:
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
diff --git a/sys/pc98/pc98/machdep.c b/sys/pc98/pc98/machdep.c
index 1472af0fa4ff..62d313f5d97a 100644
--- a/sys/pc98/pc98/machdep.c
+++ b/sys/pc98/pc98/machdep.c
@@ -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 */
diff --git a/sys/powerpc/aim/machdep.c b/sys/powerpc/aim/machdep.c
index 7cea2c0bd4d0..16da70e0868d 100644
--- a/sys/powerpc/aim/machdep.c
+++ b/sys/powerpc/aim/machdep.c
@@ -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
}
diff --git a/sys/powerpc/powermac/pswitch.c b/sys/powerpc/powermac/pswitch.c
index 62777eb33748..c437392d45e9 100644
--- a/sys/powerpc/powermac/pswitch.c
+++ b/sys/powerpc/powermac/pswitch.c
@@ -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);
}
diff --git a/sys/security/mac_test/mac_test.c b/sys/security/mac_test/mac_test.c
index 32042e6035bc..e28e4c3a01ec 100644
--- a/sys/security/mac_test/mac_test.c
+++ b/sys/security/mac_test/mac_test.c
@@ -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
diff --git a/sys/sparc64/pci/psycho.c b/sys/sparc64/pci/psycho.c
index 9f5632f3dd08..846afdd57f6a 100644
--- a/sys/sparc64/pci/psycho.c
+++ b/sys/sparc64/pci/psycho.c
@@ -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;
diff --git a/sys/sparc64/sparc64/machdep.c b/sys/sparc64/sparc64/machdep.c
index 2e6d05e572bc..7d1aa0277d52 100644
--- a/sys/sparc64/sparc64/machdep.c
+++ b/sys/sparc64/sparc64/machdep.c
@@ -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
}
diff --git a/sys/sparc64/sparc64/trap.c b/sys/sparc64/sparc64/trap.c
index 8d0ea358dfd3..e9e3c40ffcd4 100644
--- a/sys/sparc64/sparc64/trap.c
+++ b/sys/sparc64/sparc64/trap.c
@@ -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 */
diff --git a/sys/sun4v/sun4v/hvcons.c b/sys/sun4v/sun4v/hvcons.c
index 201b22c004c0..3329d0534556 100644
--- a/sys/sun4v/sun4v/hvcons.c
+++ b/sys/sun4v/sun4v/hvcons.c
@@ -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);
}
diff --git a/sys/sun4v/sun4v/machdep.c b/sys/sun4v/sun4v/machdep.c
index 16a508a43a1a..1d0bf662e127 100644
--- a/sys/sun4v/sun4v/machdep.c
+++ b/sys/sun4v/sun4v/machdep.c
@@ -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");
}
diff --git a/sys/sun4v/sun4v/trap.c b/sys/sun4v/sun4v/trap.c
index 75d5ce05a40d..f04c4242a211 100644
--- a/sys/sun4v/sun4v/trap.c
+++ b/sys/sun4v/sun4v/trap.c
@@ -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",
diff --git a/sys/sys/kdb.h b/sys/sys/kdb.h
index ece16fc5aff8..0f989f5cac40 100644
--- a/sys/sys/kdb.h
+++ b/sys/sys/kdb.h
@@ -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_ */