kernel panic有调用到dump_stack吗?
时间: 2024-01-14 16:04:45 浏览: 31
是的,当 Linux 内核发生 panic 时,会调用 `panic()` 函数,该函数会调用 `printk()` 函数输出 panic 信息,并最终调用 `dump_stack()` 函数打印当前线程的调用栈和寄存器的值等信息。
`dump_stack()` 函数的实现代码如下:
```c
void dump_stack(void)
{
struct task_struct *tsk;
struct pt_regs *regs = task_pt_regs(current);
preempt_disable();
tsk = current;
printk("Stack:\n");
print_kernel_ident();
print_modules();
if (regs)
print_ip_sym(regs->ip, " => ");
printk("\nCall Trace:\n");
print_traces(tsk);
printk("\n");
preempt_enable();
}
```
该函数通过调用 `print_kernel_ident()` 和 `print_modules()` 函数打印内核版本和已加载的内核模块信息,然后通过获取当前线程的 `pt_regs` 结构体指针,打印当前程序计数器(`ip`)指向的地址和符号名,并最终调用 `print_traces()` 函数打印当前线程的调用栈信息。
因此,当 Linux 内核发生 panic 时,`dump_stack()` 函数会被调用以打印调用栈和寄存器的值等信息,方便开发人员进行调试和排查问题。