Skip to contentSkip to conversation

Kernel panic buffer (or printk on system crash)

PATCH New Maxim Uvarov 1 participant 1 message Jun 1, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

---

 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
index c89a386..313b2ba 100644
@@ -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
new file mode 100644
index 0000000..47b2c4e
@@ -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
index 3b16cd9..42c25cb 100644
@@ -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
index e722e9d..9f65397 100644
@@ -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
index 3f1062c..2d4be91 100644
@@ -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.