forked from Minki/linux
196779b9b4
Both dump_stack() and show_stack() are currently implemented by each architecture. show_stack(NULL, NULL) dumps the backtrace for the current task as does dump_stack(). On some archs, dump_stack() prints extra information - pid, utsname and so on - in addition to the backtrace while the two are identical on other archs. The usages in arch-independent code of the two functions indicate show_stack(NULL, NULL) should print out bare backtrace while dump_stack() is used for debugging purposes when something went wrong, so it does make sense to print additional information on the task which triggered dump_stack(). There's no reason to require archs to implement two separate but mostly identical functions. It leads to unnecessary subtle information. This patch expands the dummy fallback dump_stack() implementation in lib/dump_stack.c such that it prints out debug information (taken from x86) and invokes show_stack(NULL, NULL) and drops arch-specific dump_stack() implementations in all archs except blackfin. Blackfin's dump_stack() does something wonky that I don't understand. Debug information can be printed separately by calling dump_stack_print_info() so that arch-specific dump_stack() implementation can still emit the same debug information. This is used in blackfin. This patch brings the following behavior changes. * On some archs, an extra level in backtrace for show_stack() could be printed. This is because the top frame was determined in dump_stack() on those archs while generic dump_stack() can't do that reliably. It can be compensated by inlining dump_stack() but not sure whether that'd be necessary. * Most archs didn't use to print debug info on dump_stack(). They do now. An example WARN dump follows. WARNING: at kernel/workqueue.c:4841 init_workqueues+0x35/0x505() Hardware name: empty Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.9.0-rc1-work+ #9 0000000000000009 ffff88007c861e08 ffffffff81c614dc ffff88007c861e48 ffffffff8108f50f ffffffff82228240 0000000000000040 ffffffff8234a03c 0000000000000000 0000000000000000 0000000000000000 ffff88007c861e58 Call Trace: [<ffffffff81c614dc>] dump_stack+0x19/0x1b [<ffffffff8108f50f>] warn_slowpath_common+0x7f/0xc0 [<ffffffff8108f56a>] warn_slowpath_null+0x1a/0x20 [<ffffffff8234a071>] init_workqueues+0x35/0x505 ... v2: CPU number added to the generic debug info as requested by s390 folks and dropped the s390 specific dump_stack(). This loses %ksp from the debug message which the maintainers think isn't important enough to keep the s390-specific dump_stack() implementation. dump_stack_print_info() is moved to kernel/printk.c from lib/dump_stack.c. Because linkage is per objecct file, dump_stack_print_info() living in the same lib file as generic dump_stack() means that archs which implement custom dump_stack() - at this point, only blackfin - can't use dump_stack_print_info() as that will bring in the generic version of dump_stack() too. v1 The v1 patch broke build on blackfin due to this issue. The build breakage was reported by Fengguang Wu. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: David S. Miller <davem@davemloft.net> Acked-by: Vineet Gupta <vgupta@synopsys.com> Acked-by: Jesper Nilsson <jesper.nilsson@axis.com> Acked-by: Vineet Gupta <vgupta@synopsys.com> Acked-by: Martin Schwidefsky <schwidefsky@de.ibm.com> [s390 bits] Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Mike Frysinger <vapier@gentoo.org> Cc: Fengguang Wu <fengguang.wu@intel.com> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Sam Ravnborg <sam@ravnborg.org> Acked-by: Richard Kuo <rkuo@codeaurora.org> [hexagon bits] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
161 lines
3.4 KiB
C
161 lines
3.4 KiB
C
/*
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
* Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
|
|
* Copyright (C) 2009 Matt Fleming
|
|
* Copyright (C) 2002 - 2012 Paul Mundt
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
* for more details.
|
|
*/
|
|
#include <linux/kallsyms.h>
|
|
#include <linux/ftrace.h>
|
|
#include <linux/debug_locks.h>
|
|
#include <linux/kdebug.h>
|
|
#include <linux/export.h>
|
|
#include <linux/uaccess.h>
|
|
#include <asm/unwinder.h>
|
|
#include <asm/stacktrace.h>
|
|
|
|
void dump_mem(const char *str, unsigned long bottom, unsigned long top)
|
|
{
|
|
unsigned long p;
|
|
int i;
|
|
|
|
printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);
|
|
|
|
for (p = bottom & ~31; p < top; ) {
|
|
printk("%04lx: ", p & 0xffff);
|
|
|
|
for (i = 0; i < 8; i++, p += 4) {
|
|
unsigned int val;
|
|
|
|
if (p < bottom || p >= top)
|
|
printk(" ");
|
|
else {
|
|
if (__get_user(val, (unsigned int __user *)p)) {
|
|
printk("\n");
|
|
return;
|
|
}
|
|
printk("%08x ", val);
|
|
}
|
|
}
|
|
printk("\n");
|
|
}
|
|
}
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
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, 1);
|
|
|
|
print_ftrace_graph_addr(addr, data, ops,
|
|
context, &graph);
|
|
}
|
|
}
|
|
}
|
|
|
|
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 = {
|
|
.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");
|
|
|
|
unwind_stack(tsk, regs, sp, &print_trace_ops, "");
|
|
|
|
printk("\n");
|
|
|
|
if (!tsk)
|
|
tsk = current;
|
|
|
|
debug_show_held_locks(tsk);
|
|
}
|
|
|
|
void show_stack(struct task_struct *tsk, unsigned long *sp)
|
|
{
|
|
unsigned long stack;
|
|
|
|
if (!tsk)
|
|
tsk = current;
|
|
if (tsk == current)
|
|
sp = (unsigned long *)current_stack_pointer;
|
|
else
|
|
sp = (unsigned long *)tsk->thread.sp;
|
|
|
|
stack = (unsigned long)sp;
|
|
dump_mem("Stack: ", stack, THREAD_SIZE +
|
|
(unsigned long)task_stack_page(tsk));
|
|
show_trace(tsk, sp, NULL);
|
|
}
|