Kernel panic buffer (or printk on system crash)
Subsystems (3)
PATCH 1/1 Kernel panic buffer (or printk on system crash)
From: Maxim Uvarov <[email protected]>
Hello everybody,
These days I was in debugging FS code and made this small debugging tool for my needs. It works like cycle buffer for printk and prints after die() or panic(). Probably it would be useful to someone else.
Signed-off-by Maxim Uvarov <[email protected]>
---
arch/x86/kernel/dumpstack.c | 4 ++++ include/linux/pbuffer.h | 6 ++++++ kernel/panic.c | 4 ++++ lib/Kconfig.debug | 21 ++++++++++++++++++++ lib/Makefile | 1 + lib/pbuffer.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 0 deletions(-) create mode 100644 include/linux/pbuffer.h create mode 100644 lib/pbuffer.c
arch/x86/kernel/dumpstack.c +4 -0
@@ -15,6 +15,7 @@#include <linux/bug.h> #include <linux/nmi.h> #include <linux/sysfs.h> +#include <linux/pbuffer.h> #include <asm/stacktrace.h>
@@ -272,6 +273,9 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)unsigned short ss;unsigned long sp;#endif +#ifdef CONFIG_DEBUG_PBUFFER +pbuf_print_panic (); +#endif printk (KERN_EMERG "%s: %04lx [#%d] " , str, err &0xffff , ++die_counter);#ifdef CONFIG_PREEMPT printk ("PREEMPT " );
include/linux/pbuffer.h new file +6 -0
@@ -0,0 +1,6 @@ +asmlinkage void pbuf_add(const char *fmt, ...) + __attribute__ ((format (printf,1 ,2 ))); +void pbuf_print_panic (void ); + +#define PBUF_FLINE pbuf_add("%s():%d\n", __func__, __LINE__); +
kernel/panic.c +4 -0
@@ -23,6 +23,7 @@#include <linux/init.h> #include <linux/nmi.h> #include <linux/dmi.h> +#include <linux/pbuffer.h> int panic_on_oops;static unsigned long tainted_mask;
@@ -93,6 +94,9 @@ NORET_TYPE void panic(const char * fmt, ...)vsnprintf (buf,sizeof (buf), fmt, args);va_end (args);printk (KERN_EMERG "Kernel panic - not syncing: %s\n" ,buf); +#ifdef CONFIG_DEBUG_PBUFFER +pbuf_print_panic (); +#endif #ifdef CONFIG_DEBUG_BUGVERBOSE dump_stack ();#endif
lib/Kconfig.debug +21 -0
@@ -1122,3 +1122,24 @@ source "samples/Kconfig" source "lib/Kconfig.kgdb" source "lib/Kconfig.kmemcheck" + +config DEBUG_PBUFFER + bool "Enable panic buffer" + depends on DEBUG_KERNEL && EXPERIMENTAL + help + Special buffer is used to be printed after system panic. It's useful + for debugging complex functions which have a lot of inlines and cycles + and recursions. I.e. where usage printk is not effective. It works + like printk but prints buffer only after kernel panic. + pbuf_add() - function with printk interface used to add messages to + panic buffer. For example you can use the following macro: + #define PBUF_FLINE pbuf_add("%s():%d\n", __FUNCTION__, __LINE__); + +config DEBUG_PBUFFER_NLINES + int "Number of pbuffer lines" + depends on DEBUG_PBUFFER + range 0 1024 + default 10 + help + Number of lines to be printed after panic. +
lib/Makefile +1 -0
@@ -48,6 +48,7 @@ obj-$(CONFIG_BTREE) += btree.o obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o obj-$(CONFIG_DEBUG_LIST) += list_debug.o obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o +obj-$(CONFIG_DEBUG_PBUFFER) += pbuffer.o ifneq ($(CONFIG_HAVE_DEC_LOCK),y) lib-y += dec_and_lock.o
lib/pbuffer.c new file +45 -0
45 lines not on this page · raw message
Best regards,
Maxim Uvarov.