2006-07-03 07:24:41 +00:00
|
|
|
/*
|
|
|
|
* Stack trace management functions
|
|
|
|
*
|
2012-07-20 09:15:04 +00:00
|
|
|
* Copyright IBM Corp. 2006
|
2006-07-03 07:24:41 +00:00
|
|
|
* Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/stacktrace.h>
|
|
|
|
#include <linux/kallsyms.h>
|
2008-07-17 15:16:45 +00:00
|
|
|
#include <linux/module.h>
|
2006-07-03 07:24:41 +00:00
|
|
|
|
2016-02-09 11:58:54 +00:00
|
|
|
static int __save_address(void *data, unsigned long address, int nosched)
|
2006-07-03 07:24:41 +00:00
|
|
|
{
|
2016-02-09 11:58:54 +00:00
|
|
|
struct stack_trace *trace = data;
|
2006-07-03 07:24:41 +00:00
|
|
|
|
2016-02-09 11:58:54 +00:00
|
|
|
if (nosched && in_sched_functions(address))
|
|
|
|
return 0;
|
|
|
|
if (trace->skip > 0) {
|
|
|
|
trace->skip--;
|
|
|
|
return 0;
|
2006-07-03 07:24:41 +00:00
|
|
|
}
|
2016-02-09 11:58:54 +00:00
|
|
|
if (trace->nr_entries < trace->max_entries) {
|
|
|
|
trace->entries[trace->nr_entries++] = address;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2006-07-03 07:24:41 +00:00
|
|
|
}
|
|
|
|
|
2016-02-09 11:58:54 +00:00
|
|
|
static int save_address(void *data, unsigned long address)
|
2006-07-03 07:24:41 +00:00
|
|
|
{
|
2016-02-09 11:58:54 +00:00
|
|
|
return __save_address(data, address, 0);
|
|
|
|
}
|
2006-07-03 07:24:41 +00:00
|
|
|
|
2016-02-09 11:58:54 +00:00
|
|
|
static int save_address_nosched(void *data, unsigned long address)
|
|
|
|
{
|
|
|
|
return __save_address(data, address, 1);
|
2016-02-01 13:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void save_stack_trace(struct stack_trace *trace)
|
|
|
|
{
|
|
|
|
unsigned long sp;
|
|
|
|
|
2016-01-31 16:06:16 +00:00
|
|
|
sp = current_stack_pointer();
|
2016-02-09 11:58:54 +00:00
|
|
|
dump_trace(save_address, trace, NULL, sp);
|
2016-02-01 13:06:57 +00:00
|
|
|
if (trace->nr_entries < trace->max_entries)
|
|
|
|
trace->entries[trace->nr_entries++] = ULONG_MAX;
|
2008-02-05 15:50:45 +00:00
|
|
|
}
|
2008-07-03 07:17:55 +00:00
|
|
|
EXPORT_SYMBOL_GPL(save_stack_trace);
|
2008-02-05 15:50:45 +00:00
|
|
|
|
|
|
|
void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
|
|
|
|
{
|
2016-02-09 11:58:54 +00:00
|
|
|
unsigned long sp;
|
2008-02-05 15:50:45 +00:00
|
|
|
|
2016-01-18 12:12:19 +00:00
|
|
|
sp = tsk->thread.ksp;
|
2016-01-31 16:06:16 +00:00
|
|
|
if (tsk == current)
|
|
|
|
sp = current_stack_pointer();
|
2016-02-09 11:58:54 +00:00
|
|
|
dump_trace(save_address_nosched, trace, tsk, sp);
|
2008-02-05 15:50:45 +00:00
|
|
|
if (trace->nr_entries < trace->max_entries)
|
|
|
|
trace->entries[trace->nr_entries++] = ULONG_MAX;
|
2006-07-03 07:24:41 +00:00
|
|
|
}
|
2008-07-03 07:17:55 +00:00
|
|
|
EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
|
2016-01-29 05:20:28 +00: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 11:58:54 +00:00
|
|
|
dump_trace(save_address, trace, NULL, sp);
|
2016-01-29 05:20:28 +00:00
|
|
|
if (trace->nr_entries < trace->max_entries)
|
|
|
|
trace->entries[trace->nr_entries++] = ULONG_MAX;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(save_stack_trace_regs);
|