2007-05-16 02:37:20 +07:00
|
|
|
#include <linux/module.h>
|
2007-04-28 15:59:37 +07:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/stacktrace.h>
|
|
|
|
|
|
|
|
#include "stacktrace.h"
|
|
|
|
|
|
|
|
int walk_stackframe(unsigned long fp, unsigned long low, unsigned long high,
|
|
|
|
int (*fn)(struct stackframe *, void *), void *data)
|
|
|
|
{
|
|
|
|
struct stackframe *frame;
|
|
|
|
|
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* Check current frame pointer is within bounds
|
|
|
|
*/
|
2007-05-26 18:04:17 +07:00
|
|
|
if (fp < (low + 12) || fp + 4 >= high)
|
2007-04-28 15:59:37 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
frame = (struct stackframe *)(fp - 12);
|
|
|
|
|
|
|
|
if (fn(frame, data))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the low bound - the next frame must always
|
|
|
|
* be at a higher address than the current frame.
|
|
|
|
*/
|
|
|
|
low = fp + 4;
|
|
|
|
fp = frame->fp;
|
|
|
|
} while (fp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2007-05-16 02:37:20 +07:00
|
|
|
EXPORT_SYMBOL(walk_stackframe);
|
2007-04-28 15:59:37 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_STACKTRACE
|
|
|
|
struct stack_trace_data {
|
|
|
|
struct stack_trace *trace;
|
2008-04-24 12:31:46 +07:00
|
|
|
unsigned int no_sched_functions;
|
2007-04-28 15:59:37 +07:00
|
|
|
unsigned int skip;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int save_trace(struct stackframe *frame, void *d)
|
|
|
|
{
|
|
|
|
struct stack_trace_data *data = d;
|
|
|
|
struct stack_trace *trace = data->trace;
|
2008-04-24 12:31:46 +07:00
|
|
|
unsigned long addr = frame->lr;
|
2007-04-28 15:59:37 +07:00
|
|
|
|
2008-04-24 12:31:46 +07:00
|
|
|
if (data->no_sched_functions && in_sched_functions(addr))
|
|
|
|
return 0;
|
2007-04-28 15:59:37 +07:00
|
|
|
if (data->skip) {
|
|
|
|
data->skip--;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-24 12:31:46 +07:00
|
|
|
trace->entries[trace->nr_entries++] = addr;
|
2007-04-28 15:59:37 +07:00
|
|
|
|
|
|
|
return trace->nr_entries >= trace->max_entries;
|
|
|
|
}
|
|
|
|
|
2008-04-24 12:31:46 +07:00
|
|
|
void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
|
2007-04-28 15:59:37 +07:00
|
|
|
{
|
|
|
|
struct stack_trace_data data;
|
|
|
|
unsigned long fp, base;
|
|
|
|
|
|
|
|
data.trace = trace;
|
|
|
|
data.skip = trace->skip;
|
2008-04-24 12:31:46 +07:00
|
|
|
base = (unsigned long)task_stack_page(tsk);
|
|
|
|
|
|
|
|
if (tsk != current) {
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/*
|
|
|
|
* What guarantees do we have here that 'tsk'
|
|
|
|
* is not running on another CPU?
|
|
|
|
*/
|
|
|
|
BUG();
|
|
|
|
#else
|
|
|
|
data.no_sched_functions = 1;
|
|
|
|
fp = thread_saved_fp(tsk);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
data.no_sched_functions = 0;
|
|
|
|
asm("mov %0, fp" : "=r" (fp));
|
|
|
|
}
|
2007-04-28 15:59:37 +07:00
|
|
|
|
|
|
|
walk_stackframe(fp, base, base + THREAD_SIZE, save_trace, &data);
|
2008-04-24 12:31:46 +07:00
|
|
|
if (trace->nr_entries < trace->max_entries)
|
|
|
|
trace->entries[trace->nr_entries++] = ULONG_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
void save_stack_trace(struct stack_trace *trace)
|
|
|
|
{
|
|
|
|
save_stack_trace_tsk(current, trace);
|
2007-04-28 15:59:37 +07:00
|
|
|
}
|
2008-07-03 14:17:55 +07:00
|
|
|
EXPORT_SYMBOL_GPL(save_stack_trace);
|
2007-04-28 15:59:37 +07:00
|
|
|
#endif
|