diff options
author | Guo Ren <ren_guo@c-sky.com> | 2018-12-09 09:18:05 +0300 |
---|---|---|
committer | Guo Ren <ren_guo@c-sky.com> | 2018-12-31 18:12:22 +0300 |
commit | 0ea2dc7cd668be5475babecaf6fdeaa464e2847b (patch) | |
tree | 733fef9d2126b7323d4ec80e62e0c3ea583e01f7 /arch/csky/kernel/stacktrace.c | |
parent | 859e5f45cbb33fe5d591a8e429667f0b7d4f4be8 (diff) | |
download | linux-0ea2dc7cd668be5475babecaf6fdeaa464e2847b.tar.xz |
csky: stacktrace supported.
The gcc option "-mbacktrace" will push fp(r8),lr into stack and we could
unwind the stack with:
fp = *fp
lr = (unsigned int *)fp[1]
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
Diffstat (limited to 'arch/csky/kernel/stacktrace.c')
-rw-r--r-- | arch/csky/kernel/stacktrace.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/arch/csky/kernel/stacktrace.c b/arch/csky/kernel/stacktrace.c new file mode 100644 index 000000000000..fec777a643f1 --- /dev/null +++ b/arch/csky/kernel/stacktrace.c @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. */ + +#include <linux/sched/debug.h> +#include <linux/sched/task_stack.h> +#include <linux/stacktrace.h> +#include <linux/ftrace.h> + +void save_stack_trace(struct stack_trace *trace) +{ + save_stack_trace_tsk(current, trace); +} +EXPORT_SYMBOL_GPL(save_stack_trace); + +void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) +{ + unsigned long *fp, *stack_start, *stack_end; + unsigned long addr; + int skip = trace->skip; + int savesched; + int graph_idx = 0; + + if (tsk == current) { + asm volatile("mov %0, r8\n":"=r"(fp)); + savesched = 1; + } else { + fp = (unsigned long *)thread_saved_fp(tsk); + savesched = 0; + } + + addr = (unsigned long) fp & THREAD_MASK; + stack_start = (unsigned long *) addr; + stack_end = (unsigned long *) (addr + THREAD_SIZE); + + while (fp > stack_start && fp < stack_end) { + unsigned long lpp, fpp; + + fpp = fp[0]; + lpp = fp[1]; + if (!__kernel_text_address(lpp)) + break; + else + lpp = ftrace_graph_ret_addr(tsk, &graph_idx, lpp, NULL); + + if (savesched || !in_sched_functions(lpp)) { + if (skip) { + skip--; + } else { + trace->entries[trace->nr_entries++] = lpp; + if (trace->nr_entries >= trace->max_entries) + break; + } + } + fp = (unsigned long *)fpp; + } +} +EXPORT_SYMBOL_GPL(save_stack_trace_tsk); |