没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Ubuntu+Systemtap 进行 Linux 内核和用户空间开发测试
扬帆 sailing_9806#163.com
http://blog.csdn.net/sailor_8318/article/details/25076745
(本原创文章发表于 扬帆 的个人 blog,未经本人许可,不得用于商业用途。任何个人、媒
体、其他网站不得私自抄袭;网络媒体转载请注明出处,增加原文链接,否则属于侵权行为。
如有任何问题,请留言或者发邮件给 sailing_9806#163.com)
【摘要】本文主要介绍在 ubuntu 平台 + 自定义内核上如何安装 systemtap 工具包及解决编
译加载运行过程中的一些问题,如何利用 systemtap 工具监测分析内核函数,内核模块及用
户态程序。
【关键字】ubuntu, systemtap, utrace, backtrace, dtrace, callstack
1 Systemtap 安装 ......................................................................................................................... 2
1.1 Apt-get 自动安装 systemtap ........................................................................................ 2
1.2 源代码编译安装 systemtap ......................................................................................... 2
1.2.1 卸载通过 apt-get 自动安装的 systemtap ........................................................ 2
1.2.2 下载 systemtap 源码包 .................................................................................... 2
1.2.3 编译安装 ........................................................................................................... 3
1.3 安装内核 debug info .................................................................................................... 3
2 Hello World 基本测试 .............................................................................................................. 3
3 内核函数测试 ........................................................................................................................... 4
3.1 基本功能 ....................................................................................................................... 4
3.2 函数调用栈 ................................................................................................................... 4
4 内核模块测试 ........................................................................................................................... 5
5 用户态监控 Utrace ................................................................................................................... 6
5.1 Utrace patch .................................................................................................................. 6
5.2 函数跟踪测试 ............................................................................................................... 7
5.3 打印用户态调用栈 ....................................................................................................... 9
6 Systemtap 加载 KO 异常,Unknown symbol in module ....................................................... 10
6.1 异常现象 ..................................................................................................................... 10
6.2 分析异常原因 ............................................................................................................. 10
6.3 Workaround ................................................................................................................ 12
7 error: implicit declaration of function ‘unregister_uprobe’ .................................................... 13
8 参考资料 ................................................................................................................................. 14
Systemtap 是学习内核一个必不可少的工具,它不仅可以侦测内核空间的相关信息,还可以
侦测用户空间的信息,是研究内核源代码、优化系统性能及调试诊断系统问题的一个必备工
具。相关原理信息可参见附录 https://wiki.ubuntu.com/Kernel/Systemtap 及“Linux 下的一个
全新的性能测量和调式诊断工具 Systemtap, 第 3 部分: Systemtap”
http://www.ibm.com/developerworks/cn/linux/l-cn-systemtap3/#main
1 Systemtap 安装
1.1 Apt-get 自动安装 systemtap
用系统工具自动安装 systemtap 时,用户不用考虑各个软件包的依赖关系,系统会自动根据
当前内核版本下载相应的软件包。
dd@ubuntu:/mnt/hgfs/systemtap/kvm$ sudo apt-get install systemtap
。。
The following extra packages will be installed:
libdw1 systemtap-common systemtap-runtime
The following NEW packages will be installed:
libdw1 systemtap systemtap-common systemtap-runtime
。
Get:1 http://us.archive.ubuntu.com/ubuntu/ quantal-updates/main libdw1 i386
0.153-1ubuntu1.1 [216 kB]
。。
如上可知,系统自动安装了相关的 4 个软件包 libdw1 systemtap-common systemtap-runtime
1.2 源代码编译安装 systemtap
有时候系统自动安装的不一定能用,这个时候需要升级,此时只能通过下载源代码自己编译
1.2.1 卸载通过 apt-get 自动安装的 systemtap
首先要卸载系统之前安装的相关 package,避免后续带来其他副作用。
dd@ubuntu:/mnt/hgfs/systemtap$ sudo apt-get remove systemtap systemtap-common
systemtap-runtime
。。
Removing systemtap ...
Removing systemtap-common ...
Removing systemtap-runtime ...
Processing triggers for man-db ...
1.2.2 下载 systemtap 源码包
下载相应版本的源码包。源码包并不是越新越好,因为他们之间有一定的依赖关系,最简单
的是按照内核源码包发布的时间来选择 systemtap。
https://fedorahosted.org/releases/e/l/elfutils/
ftp://sources.redhat.com/pub/systemtap/releases/
1.2.3 编译安装
dd@ubuntu:/mnt/hgfs/systemtap/systemtap-2.0$./configure --with-elfutils=../elfutils-0.156
--prefix=/usr/local
。。。。。
configure: ./configure '--with-elfutils=../elfutils-0.156' '--prefix=/usr/local'
--prefix=/home/dd/systemtap-2.0-4155
configure: Running systemtap uninstalled, entirely out of the build tree,
configure: is not supported.
重启系统之后再执行,仍然如此,不知是否有其他副作用
dd@ubuntu:/mnt/hgfs/systemtap/systemtap-2.0$ sudo make
。。
ln -fs libdw.so libdw.so.1
ln: failed to create symbolic link `libdw.so.1': Operation not supported
make[4]: *** [libdw.so] Error 1
windows 不支持符号链接,因此 system 包不能放在 windows 目录编译
dd@ubuntu:~/systemtap/systemtap-2.0$ sudo make
。。。
m4 -Di386 -DDISASSEMBLER ../../../elfutils-0.156/libcpu/defs/i386 > i386_defsT
/bin/bash: m4: command not found
1.3 安装内核 debug info
System 调试内核或者 application,必须有 debug info,因此必须安装内核 debug symbol。具
体参见附录。
若没有安装 debug info,则报错如下:
drq@ubuntu:~$ sudo stap -e 'probe kernel.function("sys_open") {log("hello world") exit()}'
WARNING: cannot find module kernel debuginfo: No DWARF information found
semantic error: no match while resolving probe point kernel.function("sys_open")
Pass 2: analysis failed. Try again with another '--vp 01' option.
2 Hello World 基本测试
Systemtap 安装完毕后,进行简单的测试。如果能打印出 hello world 则认为基本功能 OK。
dd@ubuntu:/usr/src$ sudo stap -ve 'probe begin { log("hello world") exit() }'
Pass 1: parsed user script and 81 library script(s) using 22640virt/13560res/2192shr kb, in
80usr/10sys/93real ms.
Pass 2: analyzed script: 1 probe(s), 2 function(s), 0 embed(s), 0 global(s) using
剩余13页未读,继续阅读
资源评论
杨帆_8318
- 粉丝: 880
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功