- Updated to 3.4-rc1.
[linux-flexiantxendom0-3.2.10.git] / arch / x86 / kernel / dumpstack_32.c
1 /*
2  *  Copyright (C) 1991, 1992  Linus Torvalds
3  *  Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
4  */
5 #include <linux/kallsyms.h>
6 #include <linux/kprobes.h>
7 #include <linux/uaccess.h>
8 #include <linux/hardirq.h>
9 #include <linux/kdebug.h>
10 #include <linux/module.h>
11 #include <linux/ptrace.h>
12 #include <linux/kexec.h>
13 #include <linux/sysfs.h>
14 #include <linux/bug.h>
15 #include <linux/nmi.h>
16
17 #include <asm/stacktrace.h>
18
19
20 void dump_trace(struct task_struct *task, struct pt_regs *regs,
21                 unsigned long *stack, unsigned long bp,
22                 const struct stacktrace_ops *ops, void *data)
23 {
24         int graph = 0;
25
26         if (!task)
27                 task = current;
28
29         bp = stack_frame(task, regs);
30         if (try_stack_unwind(task, regs, &stack, &bp, ops, data))
31                 return;
32
33         if (!stack) {
34                 unsigned long dummy;
35
36                 stack = &dummy;
37                 if (task && task != current)
38                         stack = (unsigned long *)task->thread.sp;
39         }
40
41         if (!bp)
42                 bp = stack_frame(task, regs);
43
44         for (;;) {
45                 struct thread_info *context;
46
47                 context = (struct thread_info *)
48                         ((unsigned long)stack & (~(THREAD_SIZE - 1)));
49                 bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
50
51                 stack = (unsigned long *)context->previous_esp;
52                 if (!stack)
53                         break;
54                 if (ops->stack(data, "IRQ") < 0)
55                         break;
56                 touch_nmi_watchdog();
57         }
58 }
59 EXPORT_SYMBOL(dump_trace);
60
61 void
62 show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
63                    unsigned long *sp, unsigned long bp, char *log_lvl)
64 {
65         unsigned long *stack;
66         int i;
67
68         if (sp == NULL) {
69                 if (task)
70                         sp = (unsigned long *)task->thread.sp;
71                 else
72                         sp = (unsigned long *)&sp;
73         }
74
75         stack = sp;
76         for (i = 0; i < kstack_depth_to_print; i++) {
77                 if (kstack_end(stack))
78                         break;
79                 if (i && ((i % STACKSLOTS_PER_LINE) == 0))
80                         printk(KERN_CONT "\n");
81                 printk(KERN_CONT " %08lx", *stack++);
82                 touch_nmi_watchdog();
83         }
84         printk(KERN_CONT "\n");
85         show_trace_log_lvl(task, regs, sp, bp, log_lvl);
86 }
87
88
89 void show_registers(struct pt_regs *regs)
90 {
91         int i;
92
93         print_modules();
94         __show_regs(regs, !user_mode_vm(regs));
95
96         printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
97                 TASK_COMM_LEN, current->comm, task_pid_nr(current),
98                 current_thread_info(), current, task_thread_info(current));
99         /*
100          * When in-kernel, we also print out the stack and code at the
101          * time of the fault..
102          */
103         if (!user_mode_vm(regs)) {
104                 unsigned int code_prologue = code_bytes * 43 / 64;
105                 unsigned int code_len = code_bytes;
106                 unsigned char c;
107                 u8 *ip;
108
109                 printk(KERN_EMERG "Stack:\n");
110                 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
111
112                 printk(KERN_EMERG "Code: ");
113
114                 ip = (u8 *)regs->ip - code_prologue;
115                 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
116                         /* try starting at IP */
117                         ip = (u8 *)regs->ip;
118                         code_len = code_len - code_prologue + 1;
119                 }
120                 for (i = 0; i < code_len; i++, ip++) {
121                         if (ip < (u8 *)PAGE_OFFSET ||
122                                         probe_kernel_address(ip, c)) {
123                                 printk(KERN_CONT " Bad EIP value.");
124                                 break;
125                         }
126                         if (ip == (u8 *)regs->ip)
127                                 printk(KERN_CONT "<%02x> ", c);
128                         else
129                                 printk(KERN_CONT "%02x ", c);
130                 }
131         }
132         printk(KERN_CONT "\n");
133 }
134
135 int is_valid_bugaddr(unsigned long ip)
136 {
137         unsigned short ud2;
138
139         if (ip < PAGE_OFFSET)
140                 return 0;
141         if (probe_kernel_address((unsigned short *)ip, ud2))
142                 return 0;
143
144         return ud2 == 0x0b0f;
145 }