From c3f8f2462068d0ea9b00cd728620418ac6ac0c5e Mon Sep 17 00:00:00 2001 From: jhb Date: Thu, 19 Sep 2002 18:49:46 +0000 Subject: Add ability to dump stacktraces on kernel panics when DDB is compiled into the kernel. By default this is turned off since otherwise it could scroll valuable panic messages off of the screen. This option can be turned on by the DDB_TRACE kernel option as well as the debug.trace_on_panic sysctl. Also, fix the DDB_UNATTENDED option to use its own header instead of abusing opt_ddb.h. This way turning that one option on or off doesn't force you to recompile all of ddb. Requested by: many (1), bde (2*) * - I know bde prefers !abusing option headers in general but can't remember if he as brought up this specific case. --- sys/kern/kern_shutdown.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'sys/kern') diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c index 13a9c7a..f8f676e 100644 --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -40,6 +40,8 @@ */ #include "opt_ddb.h" +#include "opt_ddb_trace.h" +#include "opt_ddb_unattended.h" #include "opt_hw_wdog.h" #include "opt_panic.h" #include "opt_show_busybufs.h" @@ -91,6 +93,14 @@ int debugger_on_panic = 1; #endif SYSCTL_INT(_debug, OID_AUTO, debugger_on_panic, CTLFLAG_RW, &debugger_on_panic, 0, "Run debugger on kernel panic"); + +#ifdef DDB_TRACE +int trace_on_panic = 1; +#else +int trace_on_panic = 0; +#endif +SYSCTL_INT(_debug, OID_AUTO, trace_on_panic, CTLFLAG_RW, + &trace_on_panic, 0, "Print stack trace on kernel panic"); #endif int sync_on_panic = 1; @@ -434,7 +444,7 @@ void panic(const char *fmt, ...) { struct thread *td = curthread; - int bootopt; + int bootopt, newpanic; va_list ap; static char buf[256]; @@ -453,10 +463,13 @@ panic(const char *fmt, ...) #endif bootopt = RB_AUTOBOOT | RB_DUMP; + newpanic = 0; if (panicstr) bootopt |= RB_NOSYNC; - else + else { panicstr = fmt; + newpanic = 1; + } va_start(ap, fmt); (void)vsnprintf(buf, sizeof(buf), fmt, ap); @@ -475,6 +488,8 @@ panic(const char *fmt, ...) #endif #if defined(DDB) + if (newpanic && trace_on_panic) + db_print_backtrace(); if (debugger_on_panic) Debugger ("panic"); #ifdef RESTARTABLE_PANICS -- cgit v1.1