blob: a586aba337a7afcbd0f93f50c36c59167face762 [file] [log] [blame]
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +09001/*
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 */
15static void save_raw_context_stack(struct stack_trace *trace,
Atsushi Nemoto23126692006-09-28 19:15:33 +090016 unsigned long reg29)
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090017{
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 Nemoto23126692006-09-28 19:15:33 +090024 if (trace->skip > 0)
25 trace->skip--;
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090026 else
Atsushi Nemoto23126692006-09-28 19:15:33 +090027 trace->entries[trace->nr_entries++] = addr;
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090028 if (trace->nr_entries >= trace->max_entries)
29 break;
30 }
31 }
32}
33
Atsushi Nemoto19246002006-09-29 18:02:51 +090034static void save_context_stack(struct stack_trace *trace,
Atsushi Nemoto23126692006-09-28 19:15:33 +090035 struct task_struct *task, struct pt_regs *regs)
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090036{
37 unsigned long sp = regs->regs[29];
38#ifdef CONFIG_KALLSYMS
39 unsigned long ra = regs->regs[31];
40 unsigned long pc = regs->cp0_epc;
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090041
42 if (raw_show_trace || !__kernel_text_address(pc)) {
Atsushi Nemoto19246002006-09-29 18:02:51 +090043 unsigned long stack_page =
44 (unsigned long)task_stack_page(task);
Atsushi Nemoto23126692006-09-28 19:15:33 +090045 if (stack_page && sp >= stack_page &&
46 sp <= stack_page + THREAD_SIZE - 32)
47 save_raw_context_stack(trace, sp);
Atsushi Nemoto19246002006-09-29 18:02:51 +090048 return;
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090049 }
50 do {
Atsushi Nemoto23126692006-09-28 19:15:33 +090051 if (trace->skip > 0)
52 trace->skip--;
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090053 else
Atsushi Nemoto23126692006-09-28 19:15:33 +090054 trace->entries[trace->nr_entries++] = pc;
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090055 if (trace->nr_entries >= trace->max_entries)
56 break;
Atsushi Nemoto19246002006-09-29 18:02:51 +090057 pc = unwind_stack(task, &sp, pc, &ra);
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090058 } while (pc);
59#else
Atsushi Nemotoeea32d42006-10-16 22:48:49 +090060 save_raw_context_stack(trace, sp);
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090061#endif
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090062}
63
64/*
65 * Save stack-backtrace addresses into a stack_trace buffer.
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090066 */
Atsushi Nemoto23126692006-09-28 19:15:33 +090067void save_stack_trace(struct stack_trace *trace, struct task_struct *task)
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090068{
69 struct pt_regs dummyregs;
70 struct pt_regs *regs = &dummyregs;
71
72 WARN_ON(trace->nr_entries || !trace->max_entries);
73
74 if (task && task != current) {
75 regs->regs[29] = task->thread.reg29;
76 regs->regs[31] = 0;
77 regs->cp0_epc = task->thread.reg31;
78 } else {
79 if (!task)
80 task = current;
81 prepare_frametrace(regs);
82 }
83
Atsushi Nemoto19246002006-09-29 18:02:51 +090084 save_context_stack(trace, task, regs);
Atsushi Nemoto1df0f0f2006-09-26 23:44:01 +090085}