1、问题
SystemTap工具能调试新增的内核模块吗?比如自己编写的helloworld模块。
答案:是可以的。
2、关键点:
1)使用SystemTap调试内核模块,探测点的编写格式示例为:
module("ext3").function("ext3_*")
2) 需要将新增的helloworld模块cp到/lib/modules/`uname -r`/extra目录中,否则找不到符号。
3、实例:
1)helloworld模块
a)模块代码(hello.c):
b)编译方法:新建一个Makefile文件。文件的内容如下:
obj-m :=hello.o
使用下面的命令进行编译:
# make -C /usr/src/kernels/`uname -r`/ modules M=$PWD
2)编译后的模块名为hello.ko,将其cp到 /lib/modules/`uname -r`/extra目录中,并安装模块:
cp ./hello.ko /lib/modules/`uname -r`/extra
insmod /lib/modules/`uname -r`/extra/hello.ko
3) 编写systemtap脚本,示例如下:
4) 执行systemtap脚本:
# stap hello.stp > hello_output.txt &
# rmmod hello
SystemTap工具能调试新增的内核模块吗?比如自己编写的helloworld模块。
答案:是可以的。
2、关键点:
1)使用SystemTap调试内核模块,探测点的编写格式示例为:
module("ext3").function("ext3_*")
2) 需要将新增的helloworld模块cp到/lib/modules/`uname -r`/extra目录中,否则找不到符号。
3、实例:
1)helloworld模块
a)模块代码(hello.c):
点击(此处)折叠或打开
- #include<linux/module.h>
- #include<linux/init.h>
-
- int test()
- {
- printk("Testing....\n");
- }
-
- int __init hello_init (void)
-
- {
- printk("HelloWorld\n");
- test();
- return 0;
- }
-
-
- void __exit hello_exit(void)
- {
- test();
- printk("GoodBye\n");
- }
-
- EXPORT_SYMBOL_GPL(test);
- MODULE_AUTHOR("jb ");
- MODULE_DESCRIPTION("hello");
- MODULE_LICENSE("GPL");
-
- module_init(hello_init);
- module_exit(hello_exit);
b)编译方法:新建一个Makefile文件。文件的内容如下:
obj-m :=hello.o
使用下面的命令进行编译:
# make -C /usr/src/kernels/`uname -r`/ modules M=$PWD
2)编译后的模块名为hello.ko,将其cp到 /lib/modules/`uname -r`/extra目录中,并安装模块:
cp ./hello.ko /lib/modules/`uname -r`/extra
insmod /lib/modules/`uname -r`/extra/hello.ko
3) 编写systemtap脚本,示例如下:
点击(此处)折叠或打开
- probe module("hello").function("test")
- {
- print("Hello Systemtap!\n")
- }
4) 执行systemtap脚本:
# stap hello.stp > hello_output.txt &
# rmmod hello