因為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`