dump_stack的简单使用 [Kernel space]
来源:互联网 发布:云计算演讲稿 编辑:程序博客网 时间:2024/05/18 17:00
转: http://blog.chinaunix.net/uid-26403844-id-3361770.html
在调试过程中用printk打印信息当然是直接有效的办法,但当我们不知到一个函数或者一个模块到底在哪里出了问题时我们可以利用dump_stack有效的找到问题的根源,下面只是简单的给出了使用方法。
我在自己的主机上试了一下dump_stack()Makefile文件
点击(此处)折叠或打开
- obj-m := hello.o
- KERNELBUILD :=/lib/modules/$(shell uname -r)/build
- default:
- make -C $(KERNELBUILD) M=$(shell pwd) modules
- clean:
- rm -rf *.o *.ko *.mod.c .*.cmd *.markers *.order *.symvers .tmp_versions
hello.c文件
点击(此处)折叠或打开
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/kprobes.h>
- #include <asm/traps.h>
-
- MODULE_LICENSE("Dual BSD/GPL");
-
- static int __init hello_init(void)
- {
- printk(KERN_ALERT "dump_stack start\n");
- dump_stack();
- printk(KERN_ALERT "dump_stack over\n");
- return 0;
- }
- static void __exit hello_exit(void)
- {
- printk(KERN_ALERT "test module\n");
- }
-
- module_init(hello_init);
- module_exit(hello_exit);
点击(此处)折叠或打开
- #include <linux/kprobes.h>
- #include <asm/traps.h>
在运行insmod hello.ko把模块插入内核
运行dmesg
[ 3719.352022] usb 1-8: new high speed USB device number 11 using ehci_hcd
[ 4266.252826] usb 1-8: USB disconnect, device number 11
[ 5246.942980] dump_stack start
[ 5246.942985] Pid: 3438, comm: insmod Not tainted 3.0.0-21-generic #35-Ubuntu
[ 5246.942987] Call Trace:
[ 5246.942993] [<ffffffffa0072017>] hello_init+0x17/0x1000 [hello]
[ 5246.942999] [<ffffffff81002042>] do_one_initcall+0x42/0x180
[ 5246.943003] [<ffffffff810a011e>] sys_init_module+0xbe/0x230
[ 5246.943006] [<ffffffff815fd202>] system_call_fastpath+0x16/0x1b
[ 5246.943008] dump_stack over
打出运行这个模块时调用的函数
删除模rmmod hello
补充:
Android.mk文件
点击(此处)折叠或打开
- obj-m := hello.o
- #hello-objs := hello-world.o
- KVERSION := $(ANDROID_PRODUCT_OUT)/obj/KERNEL_OBJ
- all:
- make ARCH=arm CROSS_COMPILE=arm-eabi- -C $(KVERSION) M=$(PWD) modules
- clean:
- make -C $(KVERSION) M=$(PWD) clean
在android编译环境下编译,编译出来的.ko文件可以在手机中insmod
看一个具体的实例,从上往下看,越上面是越最近调用的,越有参考价值:
(这里我在handler_pre函数中调用dump_stack的)
解释下:0x0/0x10c : 代表函数的总长度及当时的PC值在此函数的偏移量
<7>This is new module_init!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<4>[<c005b3bc>] (dump_stack+0x0/0x14) from [<bf014034>] (g_hello_init+0x18/0x24 [new_module])<4>[<bf01401c>] (g_hello_init+0x0/0x24 [new_module]) from [<c0056304>] (do_one_initcall+0x34/0x188)<4>[<c00562d0>] (do_one_initcall+0x0/0x188) from [<c00ac10c>] (sys_init_module+0x90/0x1a0)<4>[<c00ac07c>] (sys_init_module+0x0/0x1a0) from [<c0056f20>] (ret_fast_syscall+0x0/0x2c)<4> r7:00000080 r6:00000000 r5:beb5dd24 r4:00000254<4>1312.966 - <6>init: event { 'add', '/module/new_module', 'module', '', -1, -1 }
从dump stack log信息来看,调整flow如下
insmod 模块 之后,sys_init_module -->do_one_initcall ->g_hello_init->dump_stack
0 0
- dump_stack的简单使用 [Kernel space]
- dump_stack的简单使用
- dump_stack的简单使用
- dump_stack的简单使用
- dump_stack的简单使用
- dump_stack的简单使用
- dump_stack的简单使用
- kernel 调试之——dump_stack
- 一种User Mode下访问物理内存及Kernel Space的简单实现
- 一种User Mode下访问物理内存及Kernel Space的简单实现
- 应用层的dump_stack()
- dump_stack()
- dump_stack
- dump_stack( )
- kernel space对文件的读写操作
- kernel thread简单使用
- Kernel Space - User Space Interfaces_Mmap
- user space to kernel space
- java之路 myBatis重新学习(三)高级结果映射
- 【iOS开发】多屏尺的自动适配 AutoLayout (纯代码方式)
- 利用Request对象的包解析漏洞绕过防注入程序(hackbar)
- 真机调试时 无法在sdcard创建文件夹 或者push文件时没有权限
- 结构型模式--外观模式
- dump_stack的简单使用 [Kernel space]
- android--45个实例源码
- 第9周项目3-输出星号图b
- Android----http请求工具类
- hdu 1318 Palindromes
- Android Volley的基本用法
- iOS工程如何支持64-bit
- ThinkPHP用A或者R调用时要注意的坑
- Head First设计模式读书笔记