2017-10-24 06:42:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
// Copyright (C) 2005-2017 Andes Technology Corporation
|
|
|
|
|
|
|
|
#include <linux/sched/debug.h>
|
|
|
|
#include <linux/sched/task_stack.h>
|
|
|
|
#include <linux/stacktrace.h>
|
2018-08-15 03:05:40 +00:00
|
|
|
#include <linux/ftrace.h>
|
2017-10-24 06:42:02 +00:00
|
|
|
|
|
|
|
void save_stack_trace(struct stack_trace *trace)
|
|
|
|
{
|
|
|
|
save_stack_trace_tsk(current, trace);
|
|
|
|
}
|
2018-04-19 07:45:45 +00:00
|
|
|
EXPORT_SYMBOL_GPL(save_stack_trace);
|
2017-10-24 06:42:02 +00:00
|
|
|
|
|
|
|
void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
|
|
|
|
{
|
|
|
|
unsigned long *fpn;
|
|
|
|
int skip = trace->skip;
|
|
|
|
int savesched;
|
2018-08-15 03:05:40 +00:00
|
|
|
int graph_idx = 0;
|
2017-10-24 06:42:02 +00:00
|
|
|
|
|
|
|
if (tsk == current) {
|
|
|
|
__asm__ __volatile__("\tori\t%0, $fp, #0\n":"=r"(fpn));
|
|
|
|
savesched = 1;
|
|
|
|
} else {
|
|
|
|
fpn = (unsigned long *)thread_saved_fp(tsk);
|
|
|
|
savesched = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!kstack_end(fpn) && !((unsigned long)fpn & 0x3)
|
|
|
|
&& (fpn >= (unsigned long *)TASK_SIZE)) {
|
|
|
|
unsigned long lpp, fpp;
|
|
|
|
|
2018-08-20 01:51:29 +00:00
|
|
|
lpp = fpn[LP_OFFSET];
|
2017-10-24 06:42:02 +00:00
|
|
|
fpp = fpn[FP_OFFSET];
|
|
|
|
if (!__kernel_text_address(lpp))
|
|
|
|
break;
|
2018-08-15 03:05:40 +00:00
|
|
|
else
|
|
|
|
lpp = ftrace_graph_ret_addr(tsk, &graph_idx, lpp, NULL);
|
2017-10-24 06:42:02 +00:00
|
|
|
|
|
|
|
if (savesched || !in_sched_functions(lpp)) {
|
|
|
|
if (skip) {
|
|
|
|
skip--;
|
|
|
|
} else {
|
|
|
|
trace->entries[trace->nr_entries++] = lpp;
|
|
|
|
if (trace->nr_entries >= trace->max_entries)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fpn = (unsigned long *)fpp;
|
|
|
|
}
|
|
|
|
}
|
2018-04-19 07:45:45 +00:00
|
|
|
EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
|