ubuntu上安装systemtap

 因为ubuntu发行版的kernel没有调试信息,所以导致systemtap无法使用,所以得自己安装调试信息包,可能由于版本的问题,网上的很多方法,包括官方网站上提供的那个,发现各种不行(本人11.04),后来看了http://posulliv.github.com/2010/02/26/installing-stap.html才安装成功的,因为这种方法是下本发行版对应的kernel源码直接安装(而且完全是ctrl-c + ctrl-v式的傻瓜式安装),我认为应该适合任何版本,所以推荐一下。

1.安装systemtap包

$ sudo apt-get install systemtap
$ sudo apt-get install systemtap-sdt-dev

2.然后铁定报错,找不到debug信息。 !--

$ stap -e 'probe kernel.function("sys_open") {log("hello world") exit()}'
semantic error: libdwfl failure (missing x86_64 kernel/module debuginfo under
'/lib/modules/2.6.31-19-generic/build'): No such file or directory while resolving probe point
kernel.function("sys_open")
semantic error: no probes found
Pass 2: analysis failed.  Try again with another '--vp 01' option.
$

3.安装kernel

$ cd $HOME
$ sudo apt-get install dpkg-dev debhelper gawk
$ mkdir tmp
$ cd tmp
$ sudo apt-get build-dep --no-install-recommends linux-image-$(uname -r)
$ apt-get source linux-image-$(uname -r)
$ cd linux-2.6.31 (this is currently the kernel version of 9.10)
$ fakeroot debian/rules clean
$ AUTOBUILD=1 fakeroot debian/rules binary-generic skipdbg=false
$ sudo dpkg -i ../linux-image-debug-2.6.31-19-generic_2.6.31-19.56_amd64.ddeb

4.启动stap

$ sudo stap -e 'probe kernel.function("sys_open") {log("hello world") exit()}' &
[1] 951
$ touch /tmp/padraig
$ hello world
$ [1]+ Done


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

注意第3部分的操作,将生成下面3个包

linux-headers-2.6.38-15-generic_2.6.38-15.64_i386.deb
linux-image-2.6.38-15-generic_2.6.38-15.64_i386.deb
linux-image-2.6.38-15-generic-dbgsym_2.6.38-15.64_i386.ddeb

这要注意最后一步,因为生成的kernel包的版本不一定是你系统的当前版本,所以最好用uname -r仔细对应核实一下,切记一定要一样,倘若不一样,则先

sudo dpkg -i linux-image-2.6.38-15-generic_2.6.38-15.64_i386.deb

安装一下正确的内核,然后重启系统选择新安装的内核,然后在安装linux-image-2.6.38-15-generic-dbgsym_2.6.38-15.64_i386.ddeb,这时候再运行stap可能还会报一个kernel header找不到的错误(我当时没记录其错误日志,这里没法子贴出来看),这个只要用apt-get安装一下就OK了

sudo apt-get install linux-headers-`uname -r`

 


posted @ 2012-07-25 20:45  白帆mvp  阅读(3844)  评论(1编辑  收藏  举报