2017-11-24 22:00:32 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2006-07-03 15:24:41 +08:00
|
|
|
/*
|
|
|
|
* Stack trace management functions
|
|
|
|
*
|
2012-07-20 17:15:04 +08:00
|
|
|
* Copyright IBM Corp. 2006
|
2006-07-03 15:24:41 +08:00
|
|
|
* Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
2017-02-09 01:51:35 +08:00
|
|
|
#include <linux/sched/debug.h>
|
2006-07-03 15:24:41 +08:00
|
|
|
#include <linux/stacktrace.h>
|
|
|
|
#include <linux/kallsyms.h>
|
2017-02-10 04:20:23 +08:00
|
|
|
#include <linux/export.h>
|
2019-01-28 15:33:08 +08:00
|
|
|
#include <asm/stacktrace.h>
|
|
|
|
#include <asm/unwind.h>
|
2016-02-01 21:14:04 +08:00
|
|
|
|
|
|
|
void save_stack_trace(struct stack_trace *trace)
|
|
|
|
{
|
2019-01-28 15:33:08 +08:00
|
|
|
struct unwind_state state;
|
2016-02-01 21:14:04 +08:00
|
|
|
|
2019-01-28 15:33:08 +08:00
|
|
|
unwind_for_each_frame(&state, current, NULL, 0) {
|
|
|
|
if (trace->nr_entries >= trace->max_entries)
|
|
|
|
break;
|
|
|
|
if (trace->skip > 0)
|
|
|
|
trace->skip--;
|
|
|
|
else
|
|
|
|
trace->entries[trace->nr_entries++] = state.ip;
|
|
|
|
}
|
2008-02-05 23:50:45 +08:00
|
|
|
}
|
2008-07-03 15:17:55 +08:00
|
|
|
EXPORT_SYMBOL_GPL(save_stack_trace);
|
2008-02-05 23:50:45 +08:00
|
|
|
|
|
|
|
void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
|
|
|
|
{
|
2019-01-28 15:33:08 +08:00
|
|
|
struct unwind_state state;
|
2008-02-05 23:50:45 +08:00
|
|
|
|
2019-01-28 15:33:08 +08:00
|
|
|
unwind_for_each_frame(&state, tsk, NULL, 0) {
|
|
|
|
if (trace->nr_entries >= trace->max_entries)
|
|
|
|
break;
|
|
|
|
if (in_sched_functions(state.ip))
|
|
|
|
continue;
|
|
|
|
if (trace->skip > 0)
|
|
|
|
trace->skip--;
|
|
|
|
else
|
|
|
|
trace->entries[trace->nr_entries++] = state.ip;
|
|
|
|
}
|
2006-07-03 15:24:41 +08:00
|
|
|
}
|
2008-07-03 15:17:55 +08:00
|
|
|
EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
|
2016-01-29 13:20:28 +08:00
|
|
|
|
|
|
|
void save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace)
|
|
|
|
{
|
2019-01-28 15:33:08 +08:00
|
|
|
struct unwind_state state;
|
2016-01-29 13:20:28 +08:00
|
|
|
|
2019-01-28 15:33:08 +08:00
|
|
|
unwind_for_each_frame(&state, current, regs, 0) {
|
|
|
|
if (trace->nr_entries >= trace->max_entries)
|
|
|
|
break;
|
|
|
|
if (trace->skip > 0)
|
|
|
|
trace->skip--;
|
|
|
|
else
|
|
|
|
trace->entries[trace->nr_entries++] = state.ip;
|
|
|
|
}
|
2016-01-29 13:20:28 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(save_stack_trace_regs);
|