linux 内核调试(dump_stack)
2015-05-26 00:31
218 查看
刚刚接触内核,在调试过程中用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);
注意使用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] [<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
我在自己的主机上试了一下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);
注意使用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] [<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
相关文章推荐
- linux内核调试技巧 dump_stack()
- 【转】linux内核调试技巧之一 dump_stack
- linux内核调试技巧二:dump_stack
- linux内核调试技巧之一 dump_stack
- 内存管理器(十五)内核调试利器----dump_stack( )
- dump_stack内核调试
- 内核调试之dump_stack
- 关于linux内核调试的实现
- 使用 ftrace 调试 Linux 内核,第 1 部分
- 使用kgdb调试linux内核及内核模块
- linux 内核调试方法
- Ubuntu 12.10安装Bochs 2.6, 调试linux-0.11内核
- Linux内核调试方法
- linux 内核模块调试错误
- linux 内核oops调试技术
- Linux 内核的测试和调试
- Linux内核开发的一点调试技巧
- SUSE 11.2 下使用bochs调试linux-0.11内核(原创)
- 使用 ftrace 调试 Linux 内核,第 2 部分
- Eclipse + qemu调试Linux 0.11内核