forked from Minki/linux
758d39ebd3
We have four different stack tracers of which three had bugs. So it's time to merge them to a single stack tracer which allows to specify a call back function which will be called for each step. This patch changes behavior a bit: - the "nosched" and "in_sched_functions" check within save_stack_trace_tsk did work only for the last stack frame within a context. Now it considers the check for each stack frame like it should. - both the oprofile variant and the perf_events variant did save a return address twice if a zero back chain was detected, which indicates an interrupt frame. The new dump_trace function will call the oprofile and perf_events backends with the psw address that is contained within the corresponding pt_regs structure instead. - the original show_trace and save_context_stack functions did already use the psw address of the pt_regs structure if a zero back chain was detected. However now we ignore the psw address if it is a user space address. After all we trace the kernel stack and not the user space stack. This way we also get rid of the garbage user space address in case of warnings and / or panic call traces. So this should make life easier since now there is only one stack tracer left which we can break. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
74 lines
1.7 KiB
C
74 lines
1.7 KiB
C
/*
|
|
* Stack trace management functions
|
|
*
|
|
* Copyright IBM Corp. 2006
|
|
* Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
|
|
*/
|
|
|
|
#include <linux/sched.h>
|
|
#include <linux/stacktrace.h>
|
|
#include <linux/kallsyms.h>
|
|
#include <linux/module.h>
|
|
|
|
static int __save_address(void *data, unsigned long address, int nosched)
|
|
{
|
|
struct stack_trace *trace = data;
|
|
|
|
if (nosched && in_sched_functions(address))
|
|
return 0;
|
|
if (trace->skip > 0) {
|
|
trace->skip--;
|
|
return 0;
|
|
}
|
|
if (trace->nr_entries < trace->max_entries) {
|
|
trace->entries[trace->nr_entries++] = address;
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static int save_address(void *data, unsigned long address)
|
|
{
|
|
return __save_address(data, address, 0);
|
|
}
|
|
|
|
static int save_address_nosched(void *data, unsigned long address)
|
|
{
|
|
return __save_address(data, address, 1);
|
|
}
|
|
|
|
void save_stack_trace(struct stack_trace *trace)
|
|
{
|
|
unsigned long sp;
|
|
|
|
sp = current_stack_pointer();
|
|
dump_trace(save_address, trace, NULL, sp);
|
|
if (trace->nr_entries < trace->max_entries)
|
|
trace->entries[trace->nr_entries++] = ULONG_MAX;
|
|
}
|
|
EXPORT_SYMBOL_GPL(save_stack_trace);
|
|
|
|
void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
|
|
{
|
|
unsigned long sp;
|
|
|
|
sp = tsk->thread.ksp;
|
|
if (tsk == current)
|
|
sp = current_stack_pointer();
|
|
dump_trace(save_address_nosched, trace, tsk, sp);
|
|
if (trace->nr_entries < trace->max_entries)
|
|
trace->entries[trace->nr_entries++] = ULONG_MAX;
|
|
}
|
|
EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
|
|
|
|
void save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace)
|
|
{
|
|
unsigned long sp;
|
|
|
|
sp = kernel_stack_pointer(regs);
|
|
dump_trace(save_address, trace, NULL, sp);
|
|
if (trace->nr_entries < trace->max_entries)
|
|
trace->entries[trace->nr_entries++] = ULONG_MAX;
|
|
}
|
|
EXPORT_SYMBOL_GPL(save_stack_trace_regs);
|