linux 内核模块 dumpstack

时间:2021-05-27 15:44:49

内核打印 stack 要用到 dump_stack()

 

 1 #include <linux/module.h>
 2 #include <linux/init.h>
 3 
 4 #include <linux/kprobes.h>
 5 #include <asm/traps.h>
 6 
 7 #define MOD_AUTHOR          "MLN"
 8 #define MOD_DESCRIPTION     "dump stack Module !"                  
 9 #define MOD_LICENSE         "GPL"
10 #define MOD_VERSION         "1.0.00"
11 
12 static void func(void)
13 {
14     dump_stack();
15 }
16 
17 static int __init dumpstack_init(void)
18 {
19     printk("dump stack Module loaded, version: %s\n",MOD_VERSION);
20     func();
21     return 0;
22 }
23 static void __exit dumpstack_exit(void)
24 {
25     printk("dump stack Module unloaded.\n");
26 }
27 
28 module_init(dumpstack_init);
29 module_exit(dumpstack_exit);
30 
31 MODULE_LICENSE(MOD_LICENSE);
32 MODULE_AUTHOR(MOD_AUTHOR);
33 MODULE_DESCRIPTION(MOD_DESCRIPTION);