当linux内核崩溃时,内核堆栈和调用跟踪如何记录到控制台?

时间:2016-11-29 12:49:45

标签: linux linux-kernel

Pid: 16251, comm: bash Not tainted 2.6.32.59 #78

Call Trace:

 [<ffffffff81367a50>] ? do_page_fault+0x1b6/0x394

 [<ffffffff8136583f>] ? page_fault+0x1f/0x30

 [<ffffffff812160c5>] ? sysrq_handle_crash+0xd/0x16

 [<ffffffff812164be>] ? __handle_sysrq+0xaf/0x14a

 [<ffffffff8121659e>] ? write_sysrq_trigger+0x45/0x4c

 [<ffffffff81216559>] ? write_sysrq_trigger+0x0/0x4c

 [<ffffffff81116468>] ? proc_reg_write+0x85/0xa6

 [<ffffffff810d54cc>] ? vfs_write+0xa8/0x14c

 [<ffffffff810d566e>] ? sys_write+0x48/0x9e

 [<ffffffff8102d025>] ? sysenter_dispatch+0x7/0x2b

BUG: unable to handle kernel NULL pointer dereference at (null)

IP: [<ffffffff812160c5>] sysrq_handle_crash+0xd/0x16

PGD 26ad8f067 PUD 1e2aa6067 PMD 0 

Oops: 0002 [#1] SMP 

linux的哪个组件将这些Info记录到控制台?

1 个答案:

答案 0 :(得分:0)

这些日志将打印在内核的恐慌功能中。

当Linux内核无法快速或轻松恢复时,将调用Linux内核恐慌,包括错误的驱动程序,过载的内存和软件错误。

当调用panic时,它将使用vsnprintf和dump_stack等API来显示有关控制台问题原因的一些有用信息,如果启用KDUMP功能,还可以触发加载崩溃内核,你可以做一些此函数中的自定义操作有助于在内核崩溃时收集所需信息:

  linux/kernel/panic.c

/**
 *      panic - halt the system
 *      @fmt: The text string to print
 *
 *      Display a message, then perform cleanups.
 *
 *      This function never returns.
 */
NORET_TYPE void panic(const char * fmt, ...)
{
....
    bust_spinlocks(1);
    va_start(args, fmt);
    vsnprintf(buf, sizeof(buf), fmt, args);
    va_end(args);
....
#ifdef CONFIG_DEBUG_BUGVERBOSE
    dump_stack();
#endif
   ....

    /*
     * If we have crashed and we have a crash kernel loaded let it handle
     * everything else.
     * Do we want to call this before we try to display a message?
     */
    crash_kexec(NULL);

    kmsg_dump(KMSG_DUMP_PANIC);


    kcore_logon(1);
    printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
....