From 4e14dfc722b8e9e07a355f97aa60a3d9f0739071 Mon Sep 17 00:00:00 2001 From: Matt Fleming Date: Fri, 7 Aug 2009 16:11:19 +0100 Subject: sh: Use the generalized stacktrace ops Copy the stacktrace ops code from x86 and provide a central function for use by functions that need to dump a callstack. Signed-off-by: Matt Fleming Signed-off-by: Paul Mundt --- arch/sh/kernel/dumpstack.c | 128 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 arch/sh/kernel/dumpstack.c (limited to 'arch/sh/kernel/dumpstack.c') diff --git a/arch/sh/kernel/dumpstack.c b/arch/sh/kernel/dumpstack.c new file mode 100644 index 00000000000..6ab996fc612 --- /dev/null +++ b/arch/sh/kernel/dumpstack.c @@ -0,0 +1,128 @@ +/* + * Copyright (C) 1991, 1992 Linus Torvalds + * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs + * Copyright (C) 2009 Matt Fleming + */ +#include +#include +#include + +#include + +void printk_address(unsigned long address, int reliable) +{ + printk(" [<%p>] %s%pS\n", (void *) address, + reliable ? "" : "? ", (void *) address); +} + +#ifdef CONFIG_FUNCTION_GRAPH_TRACER +static void +print_ftrace_graph_addr(unsigned long addr, void *data, + const struct stacktrace_ops *ops, + struct thread_info *tinfo, int *graph) +{ + struct task_struct *task = tinfo->task; + unsigned long ret_addr; + int index = task->curr_ret_stack; + + if (addr != (unsigned long)return_to_handler) + return; + + if (!task->ret_stack || index < *graph) + return; + + index -= *graph; + ret_addr = task->ret_stack[index].ret; + + ops->address(data, ret_addr, 1); + + (*graph)++; +} +#else +static inline void +print_ftrace_graph_addr(unsigned long addr, void *data, + const struct stacktrace_ops *ops, + struct thread_info *tinfo, int *graph) +{ } +#endif + +/* + * Unwind the call stack and pass information to the stacktrace_ops + * functions. + */ +void dump_trace(struct task_struct *task, struct pt_regs *regs, + unsigned long *sp, const struct stacktrace_ops *ops, + void *data) +{ + struct thread_info *context; + int graph = 0; + + context = (struct thread_info *) + ((unsigned long)sp & (~(THREAD_SIZE - 1))); + + while (!kstack_end(sp)) { + unsigned long addr = *sp++; + + if (__kernel_text_address(addr)) { + ops->address(data, addr, 0); + + print_ftrace_graph_addr(addr, data, ops, + context, &graph); + } + } +} +EXPORT_SYMBOL(dump_trace); + + +static void +print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) +{ + printk(data); + print_symbol(msg, symbol); + printk("\n"); +} + +static void print_trace_warning(void *data, char *msg) +{ + printk("%s%s\n", (char *)data, msg); +} + +static int print_trace_stack(void *data, char *name) +{ + printk("%s <%s> ", (char *)data, name); + return 0; +} + +/* + * Print one address/symbol entries per line. + */ +static void print_trace_address(void *data, unsigned long addr, int reliable) +{ + printk(data); + printk_address(addr, reliable); +} + +static const struct stacktrace_ops print_trace_ops = { + .warning = print_trace_warning, + .warning_symbol = print_trace_warning_symbol, + .stack = print_trace_stack, + .address = print_trace_address, +}; + +void show_trace(struct task_struct *tsk, unsigned long *sp, + struct pt_regs *regs) +{ + if (regs && user_mode(regs)) + return; + + printk("\nCall trace:\n"); + + dump_trace(tsk, regs, sp, &print_trace_ops, ""); + + printk("\n"); + + if (!tsk) + tsk = current; + + debug_show_held_locks(tsk); +} -- cgit v1.2.3-70-g09d2 From 0eff9f66de79a0707a9c3a2f8528ccfd62100f0b Mon Sep 17 00:00:00 2001 From: Matt Fleming Date: Tue, 11 Aug 2009 22:43:20 +0100 Subject: sh: Use the new stack unwinder API Instead of implementing our own stack unwinder via dump_trace() we should use the new stack unwinder API because it is more modular. This change allows us to decouple the interface for generating stacktraces from the implementation of a stack unwinder. Signed-off-by: Matt Fleming Signed-off-by: Paul Mundt --- arch/sh/kernel/dumpstack.c | 17 ++++++----------- arch/sh/kernel/stacktrace.c | 5 +++-- arch/sh/oprofile/backtrace.c | 5 +++-- 3 files changed, 12 insertions(+), 15 deletions(-) (limited to 'arch/sh/kernel/dumpstack.c') diff --git a/arch/sh/kernel/dumpstack.c b/arch/sh/kernel/dumpstack.c index 6ab996fc612..005dc1d1146 100644 --- a/arch/sh/kernel/dumpstack.c +++ b/arch/sh/kernel/dumpstack.c @@ -6,7 +6,7 @@ #include #include #include - +#include #include void printk_address(unsigned long address, int reliable) @@ -46,13 +46,10 @@ print_ftrace_graph_addr(unsigned long addr, void *data, { } #endif -/* - * Unwind the call stack and pass information to the stacktrace_ops - * functions. - */ -void dump_trace(struct task_struct *task, struct pt_regs *regs, - unsigned long *sp, const struct stacktrace_ops *ops, - void *data) +void +stack_reader_dump(struct task_struct *task, struct pt_regs *regs, + unsigned long *sp, const struct stacktrace_ops *ops, + void *data) { struct thread_info *context; int graph = 0; @@ -71,8 +68,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs, } } } -EXPORT_SYMBOL(dump_trace); - static void print_trace_warning_symbol(void *data, char *msg, unsigned long symbol) @@ -117,7 +112,7 @@ void show_trace(struct task_struct *tsk, unsigned long *sp, printk("\nCall trace:\n"); - dump_trace(tsk, regs, sp, &print_trace_ops, ""); + unwind_stack(tsk, regs, sp, &print_trace_ops, ""); printk("\n"); diff --git a/arch/sh/kernel/stacktrace.c b/arch/sh/kernel/stacktrace.c index 6c24a400b05..45b1adde3ab 100644 --- a/arch/sh/kernel/stacktrace.c +++ b/arch/sh/kernel/stacktrace.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -57,7 +58,7 @@ void save_stack_trace(struct stack_trace *trace) { unsigned long *sp = (unsigned long *)current_stack_pointer; - dump_trace(current, NULL, sp, &save_stack_ops, trace); + unwind_stack(current, NULL, sp, &save_stack_ops, trace); } EXPORT_SYMBOL_GPL(save_stack_trace); @@ -89,6 +90,6 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) { unsigned long *sp = (unsigned long *)tsk->thread.sp; - dump_trace(current, NULL, sp, &save_stack_ops_nosched, trace); + unwind_stack(current, NULL, sp, &save_stack_ops_nosched, trace); } EXPORT_SYMBOL_GPL(save_stack_trace_tsk); diff --git a/arch/sh/oprofile/backtrace.c b/arch/sh/oprofile/backtrace.c index 62e4e4d0273..37cd75d7930 100644 --- a/arch/sh/oprofile/backtrace.c +++ b/arch/sh/oprofile/backtrace.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -120,8 +121,8 @@ void sh_backtrace(struct pt_regs * const regs, unsigned int depth) stackaddr = (unsigned long *)regs->regs[15]; if (!user_mode(regs)) { if (depth) - dump_trace(NULL, regs, stackaddr, - &backtrace_ops, &depth); + unwind_stack(NULL, regs, stackaddr, + &backtrace_ops, &depth); return; } -- cgit v1.2.3-70-g09d2 From f9967e23c10f025d85bbf66a2a5f18f016890ccb Mon Sep 17 00:00:00 2001 From: Paul Mundt Date: Sat, 15 Aug 2009 01:09:03 +0900 Subject: sh: flag the default unwinder as reliable. This flags the default unwinder as reliable, as it tends to be reliable enough for the purposes of the stacktrace buffer. We leave the unreliable cases for the unwind methods that we know to be completely broken. Signed-off-by: Paul Mundt --- arch/sh/kernel/dumpstack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/sh/kernel/dumpstack.c') diff --git a/arch/sh/kernel/dumpstack.c b/arch/sh/kernel/dumpstack.c index 005dc1d1146..6f5ad151340 100644 --- a/arch/sh/kernel/dumpstack.c +++ b/arch/sh/kernel/dumpstack.c @@ -61,7 +61,7 @@ stack_reader_dump(struct task_struct *task, struct pt_regs *regs, unsigned long addr = *sp++; if (__kernel_text_address(addr)) { - ops->address(data, addr, 0); + ops->address(data, addr, 1); print_ftrace_graph_addr(addr, data, ops, context, &graph); -- cgit v1.2.3-70-g09d2