Linux 2.6.25.3
[linux/fpc-iii.git] / arch / mips / kernel / stacktrace.c
blobebd9db8d1ecebfe7a065145df4d2c204a24ed313
1 /*
2 * arch/mips/kernel/stacktrace.c
4 * Stack trace management functions
6 * Copyright (C) 2006 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
7 */
8 #include <linux/sched.h>
9 #include <linux/stacktrace.h>
10 #include <asm/stacktrace.h>
13 * Save stack-backtrace addresses into a stack_trace buffer:
15 static void save_raw_context_stack(struct stack_trace *trace,
16 unsigned long reg29)
18 unsigned long *sp = (unsigned long *)reg29;
19 unsigned long addr;
21 while (!kstack_end(sp)) {
22 addr = *sp++;
23 if (__kernel_text_address(addr)) {
24 if (trace->skip > 0)
25 trace->skip--;
26 else
27 trace->entries[trace->nr_entries++] = addr;
28 if (trace->nr_entries >= trace->max_entries)
29 break;
34 static void save_context_stack(struct stack_trace *trace, struct pt_regs *regs)
36 unsigned long sp = regs->regs[29];
37 #ifdef CONFIG_KALLSYMS
38 unsigned long ra = regs->regs[31];
39 unsigned long pc = regs->cp0_epc;
41 if (raw_show_trace || !__kernel_text_address(pc)) {
42 unsigned long stack_page =
43 (unsigned long)task_stack_page(current);
44 if (stack_page && sp >= stack_page &&
45 sp <= stack_page + THREAD_SIZE - 32)
46 save_raw_context_stack(trace, sp);
47 return;
49 do {
50 if (trace->skip > 0)
51 trace->skip--;
52 else
53 trace->entries[trace->nr_entries++] = pc;
54 if (trace->nr_entries >= trace->max_entries)
55 break;
56 pc = unwind_stack(current, &sp, pc, &ra);
57 } while (pc);
58 #else
59 save_raw_context_stack(trace, sp);
60 #endif
64 * Save stack-backtrace addresses into a stack_trace buffer.
66 void save_stack_trace(struct stack_trace *trace)
68 struct pt_regs dummyregs;
69 struct pt_regs *regs = &dummyregs;
71 WARN_ON(trace->nr_entries || !trace->max_entries);
73 prepare_frametrace(regs);
74 save_context_stack(trace, regs);