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>
233 lines
4.8 KiB
C
233 lines
4.8 KiB
C
/*
|
|
* linux/arch/cris/traps.c
|
|
*
|
|
* Here we handle the break vectors not used by the system call
|
|
* mechanism, as well as some general stack/register dumping
|
|
* things.
|
|
*
|
|
* Copyright (C) 2000-2007 Axis Communications AB
|
|
*
|
|
* Authors: Bjorn Wesen
|
|
* Hans-Peter Nilsson
|
|
*
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
#include <asm/uaccess.h>
|
|
#include <arch/system.h>
|
|
|
|
extern void arch_enable_nmi(void);
|
|
extern void stop_watchdog(void);
|
|
extern void reset_watchdog(void);
|
|
extern void show_registers(struct pt_regs *regs);
|
|
|
|
#ifdef CONFIG_DEBUG_BUGVERBOSE
|
|
extern void handle_BUG(struct pt_regs *regs);
|
|
#else
|
|
#define handle_BUG(regs)
|
|
#endif
|
|
|
|
static int kstack_depth_to_print = 24;
|
|
|
|
void (*nmi_handler)(struct pt_regs *);
|
|
|
|
void
|
|
show_trace(unsigned long *stack)
|
|
{
|
|
unsigned long addr, module_start, module_end;
|
|
extern char _stext, _etext;
|
|
int i;
|
|
|
|
printk("\nCall Trace: ");
|
|
|
|
i = 1;
|
|
module_start = VMALLOC_START;
|
|
module_end = VMALLOC_END;
|
|
|
|
while (((long)stack & (THREAD_SIZE-1)) != 0) {
|
|
if (__get_user(addr, stack)) {
|
|
/* This message matches "failing address" marked
|
|
s390 in ksymoops, so lines containing it will
|
|
not be filtered out by ksymoops. */
|
|
printk("Failing address 0x%lx\n", (unsigned long)stack);
|
|
break;
|
|
}
|
|
stack++;
|
|
|
|
/*
|
|
* If the address is either in the text segment of the
|
|
* kernel, or in the region which contains vmalloc'ed
|
|
* memory, it *may* be the address of a calling
|
|
* routine; if so, print it so that someone tracing
|
|
* down the cause of the crash will be able to figure
|
|
* out the call path that was taken.
|
|
*/
|
|
if (((addr >= (unsigned long)&_stext) &&
|
|
(addr <= (unsigned long)&_etext)) ||
|
|
((addr >= module_start) && (addr <= module_end))) {
|
|
if (i && ((i % 8) == 0))
|
|
printk("\n ");
|
|
printk("[<%08lx>] ", addr);
|
|
i++;
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* These constants are for searching for possible module text
|
|
* segments. MODULE_RANGE is a guess of how much space is likely
|
|
* to be vmalloced.
|
|
*/
|
|
|
|
#define MODULE_RANGE (8*1024*1024)
|
|
|
|
/*
|
|
* The output (format, strings and order) is adjusted to be usable with
|
|
* ksymoops-2.4.1 with some necessary CRIS-specific patches. Please don't
|
|
* change it unless you're serious about adjusting ksymoops and syncing
|
|
* with the ksymoops maintainer.
|
|
*/
|
|
|
|
void
|
|
show_stack(struct task_struct *task, unsigned long *sp)
|
|
{
|
|
unsigned long *stack, addr;
|
|
int i;
|
|
|
|
/*
|
|
* debugging aid: "show_stack(NULL);" prints a
|
|
* back trace.
|
|
*/
|
|
|
|
if (sp == NULL) {
|
|
if (task)
|
|
sp = (unsigned long*)task->thread.ksp;
|
|
else
|
|
sp = (unsigned long*)rdsp();
|
|
}
|
|
|
|
stack = sp;
|
|
|
|
printk("\nStack from %08lx:\n ", (unsigned long)stack);
|
|
for (i = 0; i < kstack_depth_to_print; i++) {
|
|
if (((long)stack & (THREAD_SIZE-1)) == 0)
|
|
break;
|
|
if (i && ((i % 8) == 0))
|
|
printk("\n ");
|
|
if (__get_user(addr, stack)) {
|
|
/* This message matches "failing address" marked
|
|
s390 in ksymoops, so lines containing it will
|
|
not be filtered out by ksymoops. */
|
|
printk("Failing address 0x%lx\n", (unsigned long)stack);
|
|
break;
|
|
}
|
|
stack++;
|
|
printk("%08lx ", addr);
|
|
}
|
|
show_trace(sp);
|
|
}
|
|
|
|
#if 0
|
|
/* displays a short stack trace */
|
|
|
|
int
|
|
show_stack(void)
|
|
{
|
|
unsigned long *sp = (unsigned long *)rdusp();
|
|
int i;
|
|
|
|
printk("Stack dump [0x%08lx]:\n", (unsigned long)sp);
|
|
for (i = 0; i < 16; i++)
|
|
printk("sp + %d: 0x%08lx\n", i*4, sp[i]);
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
void
|
|
set_nmi_handler(void (*handler)(struct pt_regs *))
|
|
{
|
|
nmi_handler = handler;
|
|
arch_enable_nmi();
|
|
}
|
|
|
|
#ifdef CONFIG_DEBUG_NMI_OOPS
|
|
void
|
|
oops_nmi_handler(struct pt_regs *regs)
|
|
{
|
|
stop_watchdog();
|
|
oops_in_progress = 1;
|
|
printk("NMI!\n");
|
|
show_registers(regs);
|
|
oops_in_progress = 0;
|
|
}
|
|
|
|
static int __init
|
|
oops_nmi_register(void)
|
|
{
|
|
set_nmi_handler(oops_nmi_handler);
|
|
return 0;
|
|
}
|
|
|
|
__initcall(oops_nmi_register);
|
|
|
|
#endif
|
|
|
|
/*
|
|
* This gets called from entry.S when the watchdog has bitten. Show something
|
|
* similar to an Oops dump, and if the kernel is configured to be a nice
|
|
* doggy, then halt instead of reboot.
|
|
*/
|
|
void
|
|
watchdog_bite_hook(struct pt_regs *regs)
|
|
{
|
|
#ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
|
|
local_irq_disable();
|
|
stop_watchdog();
|
|
show_registers(regs);
|
|
|
|
while (1)
|
|
; /* Do nothing. */
|
|
#else
|
|
show_registers(regs);
|
|
#endif
|
|
}
|
|
|
|
/* This is normally the Oops function. */
|
|
void
|
|
die_if_kernel(const char *str, struct pt_regs *regs, long err)
|
|
{
|
|
if (user_mode(regs))
|
|
return;
|
|
|
|
#ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
|
|
/*
|
|
* This printout might take too long and could trigger
|
|
* the watchdog normally. If NICE_DOGGY is set, simply
|
|
* stop the watchdog during the printout.
|
|
*/
|
|
stop_watchdog();
|
|
#endif
|
|
|
|
handle_BUG(regs);
|
|
|
|
printk("%s: %04lx\n", str, err & 0xffff);
|
|
|
|
show_registers(regs);
|
|
|
|
oops_in_progress = 0;
|
|
|
|
#ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
|
|
reset_watchdog();
|
|
#endif
|
|
do_exit(SIGSEGV);
|
|
}
|
|
|
|
void __init
|
|
trap_init(void)
|
|
{
|
|
/* Nothing needs to be done */
|
|
}
|