| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /*  | 
 | 2 |  * Copyright (C) 2001 Jeff Dike (jdike@karaya.com) | 
 | 3 |  * Licensed under the GPL | 
 | 4 |  */ | 
 | 5 |  | 
 | 6 | #include "linux/sched.h" | 
 | 7 | #include "linux/kernel.h" | 
 | 8 | #include "linux/module.h" | 
 | 9 | #include "linux/kallsyms.h" | 
 | 10 | #include "asm/page.h" | 
 | 11 | #include "asm/processor.h" | 
 | 12 | #include "sysrq.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 |  | 
| Paolo 'Blaisorblade' Giarrusso | b346103 | 2005-05-28 15:52:00 -0700 | [diff] [blame] | 14 | /* Catch non-i386 SUBARCH's. */ | 
 | 15 | #if !defined(CONFIG_UML_X86) || defined(CONFIG_64BIT) | 
 | 16 | void show_trace(struct task_struct *task, unsigned long * stack) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 |         unsigned long addr; | 
 | 19 |  | 
 | 20 |         if (!stack) { | 
| Paolo 'Blaisorblade' Giarrusso | b346103 | 2005-05-28 15:52:00 -0700 | [diff] [blame] | 21 | 		stack = (unsigned long*) &stack; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | 		WARN_ON(1); | 
 | 23 | 	} | 
 | 24 |  | 
 | 25 |         printk("Call Trace: \n"); | 
 | 26 |         while (((long) stack & (THREAD_SIZE-1)) != 0) { | 
 | 27 |                 addr = *stack; | 
 | 28 | 		if (__kernel_text_address(addr)) { | 
 | 29 | 			printk("%08lx:  [<%08lx>]", (unsigned long) stack, addr); | 
 | 30 | 			print_symbol(" %s", addr); | 
 | 31 | 			printk("\n"); | 
 | 32 |                 } | 
 | 33 |                 stack++; | 
 | 34 |         } | 
 | 35 |         printk("\n"); | 
 | 36 | } | 
| Paolo 'Blaisorblade' Giarrusso | b346103 | 2005-05-28 15:52:00 -0700 | [diff] [blame] | 37 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 |  | 
 | 39 | /* | 
 | 40 |  * stack dumps generator - this is used by arch-independent code. | 
 | 41 |  * And this is identical to i386 currently. | 
 | 42 |  */ | 
 | 43 | void dump_stack(void) | 
 | 44 | { | 
 | 45 | 	unsigned long stack; | 
 | 46 |  | 
| Paolo 'Blaisorblade' Giarrusso | b346103 | 2005-05-28 15:52:00 -0700 | [diff] [blame] | 47 | 	show_trace(current, &stack); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } | 
 | 49 | EXPORT_SYMBOL(dump_stack); | 
 | 50 |  | 
 | 51 | /*Stolen from arch/i386/kernel/traps.c */ | 
| Jeff Dike | 0d0d0ed | 2007-02-10 01:44:15 -0800 | [diff] [blame] | 52 | static const int kstack_depth_to_print = 24; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 |  | 
 | 54 | /* This recently started being used in arch-independent code too, as in | 
 | 55 |  * kernel/sched.c.*/ | 
 | 56 | void show_stack(struct task_struct *task, unsigned long *esp) | 
 | 57 | { | 
 | 58 | 	unsigned long *stack; | 
 | 59 | 	int i; | 
 | 60 |  | 
 | 61 | 	if (esp == NULL) { | 
| Paolo 'Blaisorblade' Giarrusso | b346103 | 2005-05-28 15:52:00 -0700 | [diff] [blame] | 62 | 		if (task != current && task != NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | 			esp = (unsigned long *) KSTK_ESP(task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | 		} else { | 
 | 65 | 			esp = (unsigned long *) &esp; | 
 | 66 | 		} | 
 | 67 | 	} | 
 | 68 |  | 
 | 69 | 	stack = esp; | 
 | 70 | 	for(i = 0; i < kstack_depth_to_print; i++) { | 
 | 71 | 		if (kstack_end(stack)) | 
 | 72 | 			break; | 
 | 73 | 		if (i && ((i % 8) == 0)) | 
 | 74 | 			printk("\n       "); | 
 | 75 | 		printk("%08lx ", *stack++); | 
 | 76 | 	} | 
 | 77 |  | 
| Paolo 'Blaisorblade' Giarrusso | b346103 | 2005-05-28 15:52:00 -0700 | [diff] [blame] | 78 | 	printk("Call Trace: \n"); | 
| Allan Graves | fad1c45 | 2005-10-04 14:53:52 -0400 | [diff] [blame] | 79 | 	show_trace(task, esp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |