2 * Copyright (C) 1991, 1992 Linus Torvalds
3 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
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>
17 #include <asm/stacktrace.h>
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)
29 bp = stack_frame(task, regs);
30 if (try_stack_unwind(task, regs, &stack, &bp, ops, data))
37 if (task && task != current)
38 stack = (unsigned long *)task->thread.sp;
42 bp = stack_frame(task, regs);
45 struct thread_info *context;
47 context = (struct thread_info *)
48 ((unsigned long)stack & (~(THREAD_SIZE - 1)));
49 bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
51 stack = (unsigned long *)context->previous_esp;
54 if (ops->stack(data, "IRQ") < 0)
59 EXPORT_SYMBOL(dump_trace);
62 show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
63 unsigned long *sp, unsigned long bp, char *log_lvl)
70 sp = (unsigned long *)task->thread.sp;
72 sp = (unsigned long *)&sp;
76 for (i = 0; i < kstack_depth_to_print; i++) {
77 if (kstack_end(stack))
79 if (i && ((i % STACKSLOTS_PER_LINE) == 0))
80 printk(KERN_CONT "\n");
81 printk(KERN_CONT " %08lx", *stack++);
84 printk(KERN_CONT "\n");
85 show_trace_log_lvl(task, regs, sp, bp, log_lvl);
89 void show_registers(struct pt_regs *regs)
94 __show_regs(regs, !user_mode_vm(regs));
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));
100 * When in-kernel, we also print out the stack and code at the
101 * time of the fault..
103 if (!user_mode_vm(regs)) {
104 unsigned int code_prologue = code_bytes * 43 / 64;
105 unsigned int code_len = code_bytes;
109 printk(KERN_EMERG "Stack:\n");
110 show_stack_log_lvl(NULL, regs, ®s->sp, 0, KERN_EMERG);
112 printk(KERN_EMERG "Code: ");
114 ip = (u8 *)regs->ip - code_prologue;
115 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
116 /* try starting at IP */
118 code_len = code_len - code_prologue + 1;
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.");
126 if (ip == (u8 *)regs->ip)
127 printk(KERN_CONT "<%02x> ", c);
129 printk(KERN_CONT "%02x ", c);
132 printk(KERN_CONT "\n");
135 int is_valid_bugaddr(unsigned long ip)
139 if (ip < PAGE_OFFSET)
141 if (probe_kernel_address((unsigned short *)ip, ud2))
144 return ud2 == 0x0b0f;