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>
176 lines
4.3 KiB
C
176 lines
4.3 KiB
C
/* Provide basic stack dumping functions
|
|
*
|
|
* Copyright 2004-2009 Analog Devices Inc.
|
|
*
|
|
* Licensed under the GPL-2 or later
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/thread_info.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/module.h>
|
|
#include <asm/trace.h>
|
|
|
|
/*
|
|
* Checks to see if the address pointed to is either a
|
|
* 16-bit CALL instruction, or a 32-bit CALL instruction
|
|
*/
|
|
static bool is_bfin_call(unsigned short *addr)
|
|
{
|
|
unsigned int opcode;
|
|
|
|
if (!get_instruction(&opcode, addr))
|
|
return false;
|
|
|
|
if ((opcode >= 0x0060 && opcode <= 0x0067) ||
|
|
(opcode >= 0x0070 && opcode <= 0x0077) ||
|
|
(opcode >= 0xE3000000 && opcode <= 0xE3FFFFFF))
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void show_stack(struct task_struct *task, unsigned long *stack)
|
|
{
|
|
#ifdef CONFIG_PRINTK
|
|
unsigned int *addr, *endstack, *fp = 0, *frame;
|
|
unsigned short *ins_addr;
|
|
char buf[150];
|
|
unsigned int i, j, ret_addr, frame_no = 0;
|
|
|
|
/*
|
|
* If we have been passed a specific stack, use that one otherwise
|
|
* if we have been passed a task structure, use that, otherwise
|
|
* use the stack of where the variable "stack" exists
|
|
*/
|
|
|
|
if (stack == NULL) {
|
|
if (task) {
|
|
/* We know this is a kernel stack, so this is the start/end */
|
|
stack = (unsigned long *)task->thread.ksp;
|
|
endstack = (unsigned int *)(((unsigned int)(stack) & ~(THREAD_SIZE - 1)) + THREAD_SIZE);
|
|
} else {
|
|
/* print out the existing stack info */
|
|
stack = (unsigned long *)&stack;
|
|
endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
|
|
}
|
|
} else
|
|
endstack = (unsigned int *)PAGE_ALIGN((unsigned int)stack);
|
|
|
|
printk(KERN_NOTICE "Stack info:\n");
|
|
decode_address(buf, (unsigned int)stack);
|
|
printk(KERN_NOTICE " SP: [0x%p] %s\n", stack, buf);
|
|
|
|
if (!access_ok(VERIFY_READ, stack, (unsigned int)endstack - (unsigned int)stack)) {
|
|
printk(KERN_NOTICE "Invalid stack pointer\n");
|
|
return;
|
|
}
|
|
|
|
/* First thing is to look for a frame pointer */
|
|
for (addr = (unsigned int *)((unsigned int)stack & ~0xF); addr < endstack; addr++) {
|
|
if (*addr & 0x1)
|
|
continue;
|
|
ins_addr = (unsigned short *)*addr;
|
|
ins_addr--;
|
|
if (is_bfin_call(ins_addr))
|
|
fp = addr - 1;
|
|
|
|
if (fp) {
|
|
/* Let's check to see if it is a frame pointer */
|
|
while (fp >= (addr - 1) && fp < endstack
|
|
&& fp && ((unsigned int) fp & 0x3) == 0)
|
|
fp = (unsigned int *)*fp;
|
|
if (fp == 0 || fp == endstack) {
|
|
fp = addr - 1;
|
|
break;
|
|
}
|
|
fp = 0;
|
|
}
|
|
}
|
|
if (fp) {
|
|
frame = fp;
|
|
printk(KERN_NOTICE " FP: (0x%p)\n", fp);
|
|
} else
|
|
frame = 0;
|
|
|
|
/*
|
|
* Now that we think we know where things are, we
|
|
* walk the stack again, this time printing things out
|
|
* incase there is no frame pointer, we still look for
|
|
* valid return addresses
|
|
*/
|
|
|
|
/* First time print out data, next time, print out symbols */
|
|
for (j = 0; j <= 1; j++) {
|
|
if (j)
|
|
printk(KERN_NOTICE "Return addresses in stack:\n");
|
|
else
|
|
printk(KERN_NOTICE " Memory from 0x%08lx to %p", ((long unsigned int)stack & ~0xF), endstack);
|
|
|
|
fp = frame;
|
|
frame_no = 0;
|
|
|
|
for (addr = (unsigned int *)((unsigned int)stack & ~0xF), i = 0;
|
|
addr < endstack; addr++, i++) {
|
|
|
|
ret_addr = 0;
|
|
if (!j && i % 8 == 0)
|
|
printk(KERN_NOTICE "%p:", addr);
|
|
|
|
/* if it is an odd address, or zero, just skip it */
|
|
if (*addr & 0x1 || !*addr)
|
|
goto print;
|
|
|
|
ins_addr = (unsigned short *)*addr;
|
|
|
|
/* Go back one instruction, and see if it is a CALL */
|
|
ins_addr--;
|
|
ret_addr = is_bfin_call(ins_addr);
|
|
print:
|
|
if (!j && stack == (unsigned long *)addr)
|
|
printk("[%08x]", *addr);
|
|
else if (ret_addr)
|
|
if (j) {
|
|
decode_address(buf, (unsigned int)*addr);
|
|
if (frame == addr) {
|
|
printk(KERN_NOTICE " frame %2i : %s\n", frame_no, buf);
|
|
continue;
|
|
}
|
|
printk(KERN_NOTICE " address : %s\n", buf);
|
|
} else
|
|
printk("<%08x>", *addr);
|
|
else if (fp == addr) {
|
|
if (j)
|
|
frame = addr+1;
|
|
else
|
|
printk("(%08x)", *addr);
|
|
|
|
fp = (unsigned int *)*addr;
|
|
frame_no++;
|
|
|
|
} else if (!j)
|
|
printk(" %08x ", *addr);
|
|
}
|
|
if (!j)
|
|
printk("\n");
|
|
}
|
|
#endif
|
|
}
|
|
EXPORT_SYMBOL(show_stack);
|
|
|
|
void dump_stack(void)
|
|
{
|
|
unsigned long stack;
|
|
#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
|
|
int tflags;
|
|
#endif
|
|
trace_buffer_save(tflags);
|
|
dump_bfin_trace_buffer();
|
|
dump_stack_print_info(KERN_DEFAULT);
|
|
show_stack(current, &stack);
|
|
trace_buffer_restore(tflags);
|
|
}
|
|
EXPORT_SYMBOL(dump_stack);
|