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>
|
2006-07-03 15:24:41 +08:00
|
|
|
|
2016-02-09 19:58:54 +08:00
|
|
|
static int __save_address(void *data, unsigned long address, int nosched)
|
2006-07-03 15:24:41 +08:00
|
|
|
{
|
2016-02-09 19:58:54 +08:00
|
|
|
struct stack_trace *trace = data;
|
2006-07-03 15:24:41 +08:00
|
|
|
|
2016-02-09 19:58:54 +08:00
|
|
|
if (nosched && in_sched_functions(address))
|
|
|
|
return 0;
|
|
|
|
if (trace->skip > 0) {
|
|
|
|
trace->skip--;
|
|
|
|
return 0;
|
2006-07-03 15:24:41 +08:00
|
|
|
}
|
2016-02-09 19:58:54 +08:00
|
|
|
if (trace->nr_entries < trace->max_entries) {
|
|
|
|
trace->entries[trace->nr_entries++] = address;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2006-07-03 15:24:41 +08:00
|
|
|
}
|
|
|
|
|
2016-10-17 17:08:31 +08:00
|
|
|
static int save_address(void *data, unsigned long address, int reliable)
|
2006-07-03 15:24:41 +08:00
|
|
|
{
|
2016-02-09 19:58:54 +08:00
|
|
|
return __save_address(data, address, 0);
|
|
|
|
}
|
2006-07-03 15:24:41 +08:00
|
|
|
|
2016-10-17 17:08:31 +08:00
|
|
|
static int save_address_nosched(void *data, unsigned long address, int reliable)
|
2016-02-09 19:58:54 +08:00
|
|
|
{
|
|
|
|
return __save_address(data, address, 1);
|
2016-02-01 21:14:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void save_stack_trace(struct stack_trace *trace)
|
|
|
|
{
|
|
|
|
unsigned long sp;
|
|
|
|
|
2016-02-01 00:06:16 +08:00
|
|
|
sp = current_stack_pointer();
|
2016-02-09 19:58:54 +08:00
|
|
|
dump_trace(save_address, trace, NULL, sp);
|
2016-02-01 21:06:57 +08:00
|
|
|
if (trace->nr_entries < trace->max_entries)
|
|
|
|
trace->entries[trace->nr_entries++] = ULONG_MAX;
|
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)
|
|
|
|
{
|
2016-02-09 19:58:54 +08:00
|
|
|
unsigned long sp;
|
2008-02-05 23:50:45 +08:00
|
|
|
|
2016-01-18 20:12:19 +08:00
|
|
|
sp = tsk->thread.ksp;
|
2016-02-01 00:06:16 +08:00
|
|
|
if (tsk == current)
|
|
|
|
sp = current_stack_pointer();
|
2016-02-09 19:58:54 +08:00
|
|
|
dump_trace(save_address_nosched, trace, tsk, sp);
|
2008-02-05 23:50:45 +08:00
|
|
|
if (trace->nr_entries < trace->max_entries)
|
|
|
|
trace->entries[trace->nr_entries++] = ULONG_MAX;
|
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)
|
|
|
|
{
|
|
|
|
unsigned long sp;
|
|
|
|
|
|
|
|
sp = kernel_stack_pointer(regs);
|
2016-02-09 19:58:54 +08:00
|
|
|
dump_trace(save_address, trace, NULL, sp);
|
2016-01-29 13:20:28 +08:00
|
|
|
if (trace->nr_entries < trace->max_entries)
|
|
|
|
trace->entries[trace->nr_entries++] = ULONG_MAX;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(save_stack_trace_regs);
|