2 * Stack trace utility for OpenRISC
4 * Copyright (C) 2017 Stafford Horne <shorne@gmail.com>
6 * This file is licensed under the terms of the GNU General Public License
7 * version 2. This program is licensed "as is" without any warranty of any
8 * kind, whether express or implied.
10 * Losely based on work from sh and powerpc.
13 #include <linux/export.h>
14 #include <linux/sched.h>
15 #include <linux/sched/debug.h>
16 #include <linux/stacktrace.h>
18 #include <asm/processor.h>
19 #include <asm/unwinder.h>
22 * Save stack-backtrace addresses into a stack_trace buffer.
25 save_stack_address(void *data
, unsigned long addr
, int reliable
)
27 struct stack_trace
*trace
= data
;
32 if (trace
->skip
> 0) {
37 if (trace
->nr_entries
< trace
->max_entries
)
38 trace
->entries
[trace
->nr_entries
++] = addr
;
41 void save_stack_trace(struct stack_trace
*trace
)
43 unwind_stack(trace
, (unsigned long *) &trace
, save_stack_address
);
45 EXPORT_SYMBOL_GPL(save_stack_trace
);
48 save_stack_address_nosched(void *data
, unsigned long addr
, int reliable
)
50 struct stack_trace
*trace
= (struct stack_trace
*)data
;
55 if (in_sched_functions(addr
))
58 if (trace
->skip
> 0) {
63 if (trace
->nr_entries
< trace
->max_entries
)
64 trace
->entries
[trace
->nr_entries
++] = addr
;
67 void save_stack_trace_tsk(struct task_struct
*tsk
, struct stack_trace
*trace
)
69 unsigned long *sp
= NULL
;
72 sp
= (unsigned long *) &sp
;
74 sp
= (unsigned long *) KSTK_ESP(tsk
);
76 unwind_stack(trace
, sp
, save_stack_address_nosched
);
78 EXPORT_SYMBOL_GPL(save_stack_trace_tsk
);
81 save_stack_trace_regs(struct pt_regs
*regs
, struct stack_trace
*trace
)
83 unwind_stack(trace
, (unsigned long *) regs
->sp
,
84 save_stack_address_nosched
);
86 EXPORT_SYMBOL_GPL(save_stack_trace_regs
);