dump_stack是用来回溯内核运行的信息的,打印内核信息堆栈段;
dump_stack原型:
void dump_stack(void);
1、使用这个功能时需要将内核配置勾选上;
make menuconfig -> kernel hacking--> kernel debug
2、在函数中使用:


1 #include <linux/module.h> 2 #include <linux/init.h> 3 #include <linux/kprobes.h> 4 #include <asm/traps.h> 5 6 MODULE_LICENSE("Dual BSD/GPL"); 7 8 static int __init hello_init(void) 9 { 10 printk(KERN_ALERT "dump_stack start\n"); 11 dump_stack(); 12 printk(KERN_ALERT "dump_stack over\n"); 13 return 0; 14 } 15 static void __exit hello_exit(void) 16 { 17 printk(KERN_ALERT "test module\n"); 18 } 19 20 module_init(hello_init); 21 module_exit(hello_exit);
3、需要加入的头文件:


1 #include <linux/kprobes.h> 2 #include <asm/traps.h>
4、得到hello.ko之后,insmod hello.ko,打印信息如下:


1 [ 3719.352022] usb 1-8: new high speed USB device number 11 using ehci_hcd 2 [ 4266.252826] usb 1-8: USB disconnect, device number 11 3 [ 5246.942980] dump_stack start 4 [ 5246.942985] Pid: 3438, comm: insmod Not tainted 3.0.0-21-generic #35-Ubuntu 5 [ 5246.942987] Call Trace: 6 [ 5246.942993] [] hello_init+0x17/0x1000 [hello] 7 [ 5246.942999] [] do_one_initcall+0x42/0x180 8 [ 5246.943003] [] sys_init_module+0xbe/0x230 9 [ 5246.943006] [] system_call_fastpath+0x16/0x1b 10 [ 5246.943008] dump_stack over
在不同环境下,Call Trace也可能被称为Back Trace;