Index: sys/amd64/amd64/trap.c =================================================================== --- sys/amd64/amd64/trap.c +++ sys/amd64/amd64/trap.c @@ -811,9 +811,19 @@ curproc->p_pid, curthread->td_name); #ifdef KDB - if (debugger_on_panic || kdb_active) - if (kdb_trap(type, 0, frame)) + if (debugger_on_panic || kdb_active) { + bool handled; + bool reenter; + + reenter = kdb_active; + if (!reenter) + kdb_why = KDB_WHY_TRAP; + handled = kdb_trap(type, 0, frame); + if (!reenter) + kdb_why = KDB_WHY_UNSET; + if (handled) return; + } #endif printf("trap number = %d\n", type); if (type <= MAX_TRAP_MSG) Index: sys/i386/i386/trap.c =================================================================== --- sys/i386/i386/trap.c +++ sys/i386/i386/trap.c @@ -938,12 +938,19 @@ #ifdef KDB if (debugger_on_panic || kdb_active) { + bool handled; + bool reenter; + + reenter = kdb_active; + if (!reenter) + kdb_why = KDB_WHY_TRAP; frame->tf_err = eva; /* smuggle fault address to ddb */ - if (kdb_trap(type, 0, frame)) { - frame->tf_err = code; /* restore error code */ + handled = kdb_trap(type, 0, frame); + frame->tf_err = code; /* restore error code */ + if (!reenter) + kdb_why = KDB_WHY_UNSET; + if (handled) return; - } - frame->tf_err = code; /* restore error code */ } #endif printf("trap number = %d\n", type); Index: sys/powerpc/powerpc/trap.c =================================================================== --- sys/powerpc/powerpc/trap.c +++ sys/powerpc/powerpc/trap.c @@ -452,9 +452,19 @@ printtrap(frame->exc, frame, 1, (frame->srr1 & PSL_PR)); #ifdef KDB - if ((debugger_on_panic || kdb_active) && - kdb_trap(frame->exc, 0, frame)) - return; + if (debugger_on_panic || kdb_active) { + bool handled; + bool reenter; + + reenter = kdb_active; + if (!reenter) + kdb_why = KDB_WHY_TRAP; + handled = kdb_trap(frame->exc, 0, frame); + if (!reenter) + kdb_why = KDB_WHY_UNSET; + if (handled) + return; + } #endif panic("%s trap", trapname(frame->exc)); } Index: sys/sys/kdb.h =================================================================== --- sys/sys/kdb.h +++ sys/sys/kdb.h @@ -101,6 +101,7 @@ #define KDB_WHY_UNSET NULL /* No reason set. */ #define KDB_WHY_PANIC "panic" /* panic() was called. */ #define KDB_WHY_KASSERT "kassert" /* kassert failed. */ +#define KDB_WHY_TRAP "trap" /* Fatal trap. */ #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. */