前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >dump_stack 分析使用

dump_stack 分析使用

作者头像
233333
发布2018-03-07 15:18:58
2.3K0
发布2018-03-07 15:18:58
举报
文章被收录于专栏:linux驱动个人学习

dump_stack是用来回溯内核运行的信息的,打印内核信息堆栈段;

dump_stack原型:

void dump_stack(void);

1、使用这个功能时需要将内核配置勾选上;

make menuconfig -> kernel hacking--> kernel debug

2、在函数中使用:

代码语言:javascript
复制
 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、需要加入的头文件:

代码语言:javascript
复制
1 #include <linux/kprobes.h>
2 #include <asm/traps.h>

4、得到hello.ko之后,insmod hello.ko,打印信息如下:

代码语言:javascript
复制
 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;

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-02-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档