1 // SPDX-License-Identifier: GPL-2.0
3 * Stack trace management functions
5 * Copyright IBM Corp. 2006
6 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
9 #include <linux/sched.h>
10 #include <linux/sched/debug.h>
11 #include <linux/stacktrace.h>
12 #include <linux/kallsyms.h>
13 #include <linux/export.h>
14 #include <asm/stacktrace.h>
15 #include <asm/unwind.h>
17 void save_stack_trace(struct stack_trace
*trace
)
19 struct unwind_state state
;
21 unwind_for_each_frame(&state
, current
, NULL
, 0) {
22 if (trace
->nr_entries
>= trace
->max_entries
)
27 trace
->entries
[trace
->nr_entries
++] = state
.ip
;
30 EXPORT_SYMBOL_GPL(save_stack_trace
);
32 void save_stack_trace_tsk(struct task_struct
*tsk
, struct stack_trace
*trace
)
34 struct unwind_state state
;
36 unwind_for_each_frame(&state
, tsk
, NULL
, 0) {
37 if (trace
->nr_entries
>= trace
->max_entries
)
39 if (in_sched_functions(state
.ip
))
44 trace
->entries
[trace
->nr_entries
++] = state
.ip
;
47 EXPORT_SYMBOL_GPL(save_stack_trace_tsk
);
49 void save_stack_trace_regs(struct pt_regs
*regs
, struct stack_trace
*trace
)
51 struct unwind_state state
;
53 unwind_for_each_frame(&state
, current
, regs
, 0) {
54 if (trace
->nr_entries
>= trace
->max_entries
)
59 trace
->entries
[trace
->nr_entries
++] = state
.ip
;
62 EXPORT_SYMBOL_GPL(save_stack_trace_regs
);