Skip to contentSkip to conversation

Smarter stack traces using the frame pointer

RFC Dan Kegel 1 participant 1 message Nov 6, 2003

lore
Share & tools
lore

Dan Kegel

author
#0 lore raw

For what it's worth, on ppc I've made stack traces slightly smarter, too. I think the ppc stack dump code always used the frame
pointer, but it still output a bunch of garbage at the end of the stack dump. As a byproduct of porting the module tracking patch to ppc, I had to check each address printed out by the stack dumper, and fairly often they're not legal text addresses. I print a ? after the questionable ones now. No big deal, but it is *slightly* smarter. Here's the bit in question:

ppc/kernel/process.c renamed from arch/ppc/kernel/process.c +5 -1
@@ -514,7 +564,11 @@
 			break;
 		if (cnt++ % 7 == 0)
 			printk("\n");
-		printk("%08lX ", i);
+		if (kernel_text_address(i)) {	/* mostly just want to mark modules */
+			printk("%08lX ", i);
+		} else {			/* FIXME: should we ignore fishy adrs like x86? */
+			printk("%08lX? ", i);	/* Or append a '?' (ksymoops doesn't mind) */
+		}
 		if (cnt > 32) break;
 		if (__get_user(sp, (unsigned long **)sp))
 			break;

And here's the whole module tracking patch, including my port of it to ppc (the paths have the first component removed, sorry):

# Purpose: add module info to oops log
# Source http://www.kernel.org/pub/linux/kernel/people/andrea/kernels/v2.4/2.4.23pre6aa3/90_module-oops-tracking-3
# See also http://marc.theaimsgroup.com/?l=linux-kernel&m=102772338115172&w=2

# ppc port added by [email protected] Oct 2003
i386/kernel/traps.c +7 -2
diff -urNp z/arch/i386/kernel/traps.c 2.4.19rc3aa2/arch/i386/kernel/traps.c
@@ -113,6 +113,7 @@ static inline int kernel_text_address(un
 		 * module area. Of course it'd be better to test only
 		 * for the .text subset... */
 		if (mod_bound(addr, 0, mod)) {
+			module_oops_tracking_mark(mod);
 			retval = 1;
 			break;
 		}
@@ -208,6 +209,8 @@ void show_registers(struct pt_regs *regs
 		esp = regs->esp;
 		ss = regs->xss & 0xffff;
 	}
+	module_oops_tracking_init();
+	kernel_text_address(regs->eip);
 	printk("CPU:    %d\nEIP:    %04x:[<%08lx>]    %s\nEFLAGS: %08lx\n",
 		smp_processor_id(), 0xffff & regs->xcs, regs->eip, print_tainted(), regs->eflags);
 	printk("eax: %08lx   ebx: %08lx   ecx: %08lx   edx: %08lx\n",
@@ -226,8 +229,9 @@ void show_registers(struct pt_regs *regs
 
 		printk("\nStack: ");
 		show_stack((unsigned long*)esp);
+		module_oops_tracking_print();
 
-		printk("\nCode: ");
+		printk("Code: ");
 		if(regs->eip < PAGE_OFFSET)
 			goto bad;
 
@@ -288,7 +292,8 @@ void die(const char * str, struct pt_reg
 	spin_lock_irq(&die_lock);
 	bust_spinlocks(1);
 	handle_BUG(regs);
-	printk("%s: %04lx\n", str, err & 0xffff);
+	printk("%s: %04lx ", str, err & 0xffff);
+	printk(oops_id);
 	show_registers(regs);
 	bust_spinlocks(0);
 	spin_unlock_irq(&die_lock);
linux/kernel.h +2 -0
diff -urNp z/include/linux/kernel.h 2.4.19rc3aa2/include/linux/kernel.h
@@ -109,6 +109,8 @@ extern const char *print_tainted(void);
 
 extern void dump_stack(void);
 
+extern char *oops_id;
+
 #if DEBUG
 #define pr_debug(fmt,arg...) \
 	printk(KERN_DEBUG fmt,##arg)
linux/module.h +11 -0
diff -urNp z/include/linux/module.h 2.4.19rc3aa2/include/linux/module.h
@@ -110,6 +110,7 @@ struct module_info
 #define MOD_USED_ONCE		16
 #define MOD_JUST_FREED		32
 #define MOD_INITIALIZING	64
+#define MOD_OOPS_PRINT		128UL
 
 /* Values for query_module's which.  */
 
@@ -411,4 +412,14 @@ __attribute__((section("__ksymtab"))) =	
 #define SET_MODULE_OWNER(some_struct) do { } while (0)
 #endif
 
+#ifdef CONFIG_MODULES
+extern void module_oops_tracking_init(void);
+extern void module_oops_tracking_mark(struct module *);
+extern void module_oops_tracking_print(void);
+#else
+#define module_oops_tracking_init() do { } while (0)
+#define module_oops_tracking_mark(x) do { } while (0)
+#define module_oops_tracking_print() do { } while (0)
+#endif
+
 #endif /* _LINUX_MODULE_H */
version.c +2 -0
diff -urNp z/init/version.c 2.4.19rc3aa2/init/version.c
@@ -24,3 +24,5 @@ struct new_utsname system_utsname = {
 const char *linux_banner =
 	"Linux version " UTS_RELEASE " (" LINUX_COMPILE_BY "@"
 	LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION "\n";
+
+const char *oops_id = UTS_RELEASE " " UTS_VERSION "\n";
module.c +44 -0

50 lines not on this page · raw message

ppc/kernel/process.c renamed from arch/ppc/kernel/process.c +55 -1

80 lines not on this page · raw message

ppc/kernel/traps.c renamed from ppc/kernel/traps.c.old +2 -1
@@ -97,7 +97,8 @@
 	set_backlight_enable(1);
 	set_backlight_level(BACKLIGHT_MAX);
 #endif
-	printk("Oops: %s, sig: %ld\n", str, err);
+	printk("Oops: %s, sig: %ld ", str, err);
+	printk(oops_id);
 	show_regs(fp);
 #ifdef CONFIG_BOOTX_TEXT
 	force_printk_to_btext = 0;