From 3c3871e5e6e218053dc1b1fe1d48ac32560feef7 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Sat, 4 Jan 2003 20:54:58 +0000 Subject: [PATCH] Introduce the void backtrace(void); function which will print a backtrace if DDB is in the kernel and an explanation if not. This is useful for recording backtraces in non-fatal circumstances and does not require pollution with DDB #includes in the files where it is used. It would of course be nice to have a non-DDB dependent version too, but since the meat of a backtrace is MD it is probably not worth it. --- sys/kern/kern_shutdown.c | 14 ++++++++++++++ sys/sys/systm.h | 1 + 2 files changed, 15 insertions(+) diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c index 1867b8a5d10..d63ece6a411 100644 --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -438,6 +438,20 @@ shutdown_reset(void *junk, int howto) /* NOTREACHED */ /* assuming reset worked */ } +/* + * Print a backtrace if we can. + */ + +void +backtrace(void) +{ +#ifdef DDB + db_print_backtrace(); +#else + printf("Sorry, need DDB option to print backtrace"); +#endif +} + #ifdef SMP static u_int panic_cpu = NOCPU; #endif diff --git a/sys/sys/systm.h b/sys/sys/systm.h index e3b3a2a61f9..1126762df53 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -135,6 +135,7 @@ void panic(const char *, ...) __printflike(1, 2); void panic(const char *, ...) __dead2 __printflike(1, 2); #endif +void backtrace(void); void cpu_boot(int); void cpu_rootconf(void); extern uint32_t crc32_tab[]; -- 2.45.2