Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 1 | /* |
| 2 | * arch/mips/kernel/stacktrace.c |
| 3 | * |
| 4 | * Stack trace management functions |
| 5 | * |
| 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> |
| 11 | |
| 12 | /* |
| 13 | * Save stack-backtrace addresses into a stack_trace buffer: |
| 14 | */ |
| 15 | static void save_raw_context_stack(struct stack_trace *trace, |
Atsushi Nemoto | 2312669 | 2006-09-28 19:15:33 +0900 | [diff] [blame] | 16 | unsigned long reg29) |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 17 | { |
| 18 | unsigned long *sp = (unsigned long *)reg29; |
| 19 | unsigned long addr; |
| 20 | |
| 21 | while (!kstack_end(sp)) { |
| 22 | addr = *sp++; |
| 23 | if (__kernel_text_address(addr)) { |
Atsushi Nemoto | 2312669 | 2006-09-28 19:15:33 +0900 | [diff] [blame] | 24 | if (trace->skip > 0) |
| 25 | trace->skip--; |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 26 | else |
Atsushi Nemoto | 2312669 | 2006-09-28 19:15:33 +0900 | [diff] [blame] | 27 | trace->entries[trace->nr_entries++] = addr; |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 28 | if (trace->nr_entries >= trace->max_entries) |
| 29 | break; |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame^] | 34 | static void save_context_stack(struct stack_trace *trace, struct pt_regs *regs) |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 35 | { |
| 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; |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 40 | |
| 41 | if (raw_show_trace || !__kernel_text_address(pc)) { |
Atsushi Nemoto | 1924600 | 2006-09-29 18:02:51 +0900 | [diff] [blame] | 42 | unsigned long stack_page = |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame^] | 43 | (unsigned long)task_stack_page(current); |
Atsushi Nemoto | 2312669 | 2006-09-28 19:15:33 +0900 | [diff] [blame] | 44 | if (stack_page && sp >= stack_page && |
| 45 | sp <= stack_page + THREAD_SIZE - 32) |
| 46 | save_raw_context_stack(trace, sp); |
Atsushi Nemoto | 1924600 | 2006-09-29 18:02:51 +0900 | [diff] [blame] | 47 | return; |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 48 | } |
| 49 | do { |
Atsushi Nemoto | 2312669 | 2006-09-28 19:15:33 +0900 | [diff] [blame] | 50 | if (trace->skip > 0) |
| 51 | trace->skip--; |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 52 | else |
Atsushi Nemoto | 2312669 | 2006-09-28 19:15:33 +0900 | [diff] [blame] | 53 | trace->entries[trace->nr_entries++] = pc; |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 54 | if (trace->nr_entries >= trace->max_entries) |
| 55 | break; |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame^] | 56 | pc = unwind_stack(current, &sp, pc, &ra); |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 57 | } while (pc); |
| 58 | #else |
Atsushi Nemoto | eea32d4 | 2006-10-16 22:48:49 +0900 | [diff] [blame] | 59 | save_raw_context_stack(trace, sp); |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 60 | #endif |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /* |
| 64 | * Save stack-backtrace addresses into a stack_trace buffer. |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 65 | */ |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame^] | 66 | void save_stack_trace(struct stack_trace *trace) |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 67 | { |
| 68 | struct pt_regs dummyregs; |
| 69 | struct pt_regs *regs = &dummyregs; |
| 70 | |
| 71 | WARN_ON(trace->nr_entries || !trace->max_entries); |
| 72 | |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame^] | 73 | prepare_frametrace(regs); |
| 74 | save_context_stack(trace, regs); |
Atsushi Nemoto | 1df0f0f | 2006-09-26 23:44:01 +0900 | [diff] [blame] | 75 | } |