blob: f80850091e798c1eab0ad3f820cdf21350cf22b3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2001 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
Paolo 'Blaisorblade' Giarrussob3461032005-05-28 15:52:00 -07006#include "linux/config.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include "linux/sched.h"
8#include "linux/kernel.h"
9#include "linux/module.h"
10#include "linux/kallsyms.h"
11#include "asm/page.h"
12#include "asm/processor.h"
13#include "sysrq.h"
14#include "user_util.h"
15
Paolo 'Blaisorblade' Giarrussob3461032005-05-28 15:52:00 -070016/* Catch non-i386 SUBARCH's. */
17#if !defined(CONFIG_UML_X86) || defined(CONFIG_64BIT)
18void show_trace(struct task_struct *task, unsigned long * stack)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019{
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 unsigned long addr;
21
22 if (!stack) {
Paolo 'Blaisorblade' Giarrussob3461032005-05-28 15:52:00 -070023 stack = (unsigned long*) &stack;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 WARN_ON(1);
25 }
26
27 printk("Call Trace: \n");
28 while (((long) stack & (THREAD_SIZE-1)) != 0) {
29 addr = *stack;
30 if (__kernel_text_address(addr)) {
31 printk("%08lx: [<%08lx>]", (unsigned long) stack, addr);
32 print_symbol(" %s", addr);
33 printk("\n");
34 }
35 stack++;
36 }
37 printk("\n");
38}
Paolo 'Blaisorblade' Giarrussob3461032005-05-28 15:52:00 -070039#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41/*
42 * stack dumps generator - this is used by arch-independent code.
43 * And this is identical to i386 currently.
44 */
45void dump_stack(void)
46{
47 unsigned long stack;
48
Paolo 'Blaisorblade' Giarrussob3461032005-05-28 15:52:00 -070049 show_trace(current, &stack);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51EXPORT_SYMBOL(dump_stack);
52
53/*Stolen from arch/i386/kernel/traps.c */
54static int kstack_depth_to_print = 24;
55
56/* This recently started being used in arch-independent code too, as in
57 * kernel/sched.c.*/
58void show_stack(struct task_struct *task, unsigned long *esp)
59{
60 unsigned long *stack;
61 int i;
62
63 if (esp == NULL) {
Paolo 'Blaisorblade' Giarrussob3461032005-05-28 15:52:00 -070064 if (task != current && task != NULL) {
65 /* XXX: Isn't this bogus? I.e. isn't this the
66 * *userspace* stack of this task? If not so, use this
67 * even when task == current (as in i386).
68 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 esp = (unsigned long *) KSTK_ESP(task);
70 /* Which one? No actual difference - just coding style.*/
71 //esp = (unsigned long *) PT_REGS_IP(&task->thread.regs);
72 } else {
73 esp = (unsigned long *) &esp;
74 }
75 }
76
77 stack = esp;
78 for(i = 0; i < kstack_depth_to_print; i++) {
79 if (kstack_end(stack))
80 break;
81 if (i && ((i % 8) == 0))
82 printk("\n ");
83 printk("%08lx ", *stack++);
84 }
85
Paolo 'Blaisorblade' Giarrussob3461032005-05-28 15:52:00 -070086 printk("Call Trace: \n");
87 show_trace(current, esp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}