blob: acb12f6737570ebb7e4e8a98d8c4e741e1cb50b4 [file] [log] [blame]
David S. Miller10e26722006-11-16 13:38:57 -08001#include <linux/sched.h>
2#include <linux/stacktrace.h>
3#include <linux/thread_info.h>
Stephen Rothwella05fe032008-07-08 22:15:40 +10004#include <linux/module.h>
David S. Miller10e26722006-11-16 13:38:57 -08005#include <asm/ptrace.h>
David S. Miller85a79352008-03-24 20:06:24 -07006#include <asm/stacktrace.h>
David S. Miller10e26722006-11-16 13:38:57 -08007
David S. Miller4f70f7a2008-08-12 18:33:56 -07008#include "kstack.h"
9
David S. Miller6a5726d2008-11-28 01:19:41 -080010static void __save_stack_trace(struct thread_info *tp,
11 struct stack_trace *trace,
12 bool skip_sched)
David S. Miller10e26722006-11-16 13:38:57 -080013{
David S. Miller6f63e782008-08-13 17:17:52 -070014 unsigned long ksp, fp;
David S. Miller10e26722006-11-16 13:38:57 -080015
David S. Miller6a5726d2008-11-28 01:19:41 -080016 if (tp == current_thread_info()) {
17 stack_trace_flush();
18 __asm__ __volatile__("mov %%fp, %0" : "=r" (ksp));
19 } else {
20 ksp = tp->ksp;
21 }
David S. Miller10e26722006-11-16 13:38:57 -080022
23 fp = ksp + STACK_BIAS;
David S. Miller10e26722006-11-16 13:38:57 -080024 do {
David S. Miller14d2c682008-05-21 18:15:53 -070025 struct sparc_stackf *sf;
David S. Miller77c664f2008-04-24 03:28:52 -070026 struct pt_regs *regs;
27 unsigned long pc;
David S. Miller10e26722006-11-16 13:38:57 -080028
David S. Miller4f70f7a2008-08-12 18:33:56 -070029 if (!kstack_valid(tp, fp))
David S. Miller10e26722006-11-16 13:38:57 -080030 break;
31
David S. Miller14d2c682008-05-21 18:15:53 -070032 sf = (struct sparc_stackf *) fp;
33 regs = (struct pt_regs *) (sf + 1);
David S. Miller77c664f2008-04-24 03:28:52 -070034
David S. Miller4f70f7a2008-08-12 18:33:56 -070035 if (kstack_is_trap_frame(tp, regs)) {
David S. Miller14d2c682008-05-21 18:15:53 -070036 if (!(regs->tstate & TSTATE_PRIV))
37 break;
David S. Miller77c664f2008-04-24 03:28:52 -070038 pc = regs->tpc;
39 fp = regs->u_regs[UREG_I6] + STACK_BIAS;
40 } else {
David S. Miller14d2c682008-05-21 18:15:53 -070041 pc = sf->callers_pc;
42 fp = (unsigned long)sf->fp + STACK_BIAS;
David S. Miller77c664f2008-04-24 03:28:52 -070043 }
44
David S. Miller10e26722006-11-16 13:38:57 -080045 if (trace->skip > 0)
46 trace->skip--;
David S. Miller6a5726d2008-11-28 01:19:41 -080047 else if (!skip_sched || !in_sched_functions(pc))
David S. Miller77c664f2008-04-24 03:28:52 -070048 trace->entries[trace->nr_entries++] = pc;
David S. Miller10e26722006-11-16 13:38:57 -080049 } while (trace->nr_entries < trace->max_entries);
50}
David S. Miller6a5726d2008-11-28 01:19:41 -080051
52void save_stack_trace(struct stack_trace *trace)
53{
54 __save_stack_trace(current_thread_info(), trace, false);
55}
Ingo Molnar7b4c9502008-07-03 09:17:55 +020056EXPORT_SYMBOL_GPL(save_stack_trace);
David S. Miller6a5726d2008-11-28 01:19:41 -080057
58void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
59{
60 struct thread_info *tp = task_thread_info(tsk);
61
62 __save_stack_trace(tp, trace, true);
63}
64EXPORT_SYMBOL_GPL(save_stack_trace_tsk);