dump_stack的简单使用
来源:互联网 发布:花生壳域名 编辑:程序博客网 时间:2024/06/05 03:53
刚刚接触内核时,在调试过程中用printk打印信息当然是直接有效的办法,但当我们不知到一个函数或者一个模块到底在哪里出了问题时我们可以利用dump_stack有效的找到问题的根源,下面只是简单的给出了使用方法。
在运行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] [] hello_init+0x17/0x1000 [hello]
[ 5246.942999] [] do_one_initcall+0x42/0x180
[ 5246.943003] [] sys_init_module+0xbe/0x230
[ 5246.943006] [] system_call_fastpath+0x16/0x1b
[ 5246.943008] dump_stack over
打出运行这个模块时调用的函数
删除模rmmod hello
我在自己的主机上试了一下dump_stack()
Makefile文件
obj-m := hello.oKERNELBUILD :=/lib/modules/$(shell uname -r)/builddefault: make -C $(KERNELBUILD) M=$(shell pwd) modules clean: rm -rf *.o *.ko *.mod.c .*.cmd *.markers *.order *.symvers .tmp_versionshello.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);注意使用dump_stack()要加上这两个头文件
#include <linux/kprobes.h>#include <asm/traps.h>然后make得到hello.ko
在运行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] [] hello_init+0x17/0x1000 [hello]
[ 5246.942999] [] do_one_initcall+0x42/0x180
[ 5246.943003] [] sys_init_module+0xbe/0x230
[ 5246.943006] [] system_call_fastpath+0x16/0x1b
[ 5246.943008] dump_stack over
打出运行这个模块时调用的函数
删除模rmmod hello
补充:
Android.mk文件
obj-m := hello.o#hello-objs := hello-world.oKVERSION := $(ANDROID_PRODUCT_OUT)/obj/KERNEL_OBJall: make ARCH=arm CROSS_COMPILE=arm-eabi- -C $(KVERSION) M=$(PWD) modulesclean: make -C $(KVERSION) M=$(PWD) clean在android编译环境下编译,编译出来的.ko文件可以在手机中insmod
1 0
- dump_stack的简单使用
- dump_stack的简单使用
- dump_stack的简单使用
- dump_stack的简单使用
- dump_stack的简单使用
- dump_stack的简单使用
- dump_stack的简单使用 [Kernel space]
- 应用层的dump_stack()
- dump_stack()
- dump_stack
- dump_stack( )
- 使用dump_stack()打印出内核调用堆栈
- 使用dump_stack查看内核函数调用
- 使用dump_stack()打印出内核调用堆栈
- 使用dump_stack()打印出内核调用堆栈
- 关于BUG_ON() dump_stack 的一点笔记
- 内核中dump_stack()的实现,并在用户态模拟dump_stack()
- Linux内核调试之使用BUG_ON 和dump_stack
- 4个工人有4个任务
- 【OC03-1】面向对象——封装、继承、多态(连载三)
- 协变covariant[+T] 逆变contravariant[-T]
- 黑马程序员--iOS--C基础(结构体)
- 文件与目录
- dump_stack的简单使用
- css的伪类别
- 【OC04-1】Foundation框架、字符串(连载四)
- Foundation Framework 常用类使用方法
- #pragma once 的具体作用; #pragma once 和 ifdefine的区别
- 【OC04-2】数组、可变数组(连载五)
- 如何申请linux kernel 的maillist
- 最小监视代价
- perl_学习笔记_条件语句和循环语句