1.首先安装systemtap:
sudo apt-get install systemtap
2.安装linux kernel的debug info
可以到http://ddebs.ubuntu.com/pool/main/l/linux/下载与kernel版本一致的debug info包,可以参照http://blog.youkuaiyun.com/ustc_dylan/article/details/7079876来进行。
我这里用另外一种方法,就是重新编译kernel。过程如下:
(1)apt-get install linux-source-2.6.38 下载内核源码
(2)进入源码目录:
cd /usr/src/
解压源码包:
bzip2 -d linux-source-2.6.38.tar.bz2
tar xvf linux-source-2.6.38.tar
(3)进入源码目录,执行make menuconfig
/usr/src/linux-source-2.6.38/linux-source-2.6.38# make menuconfig
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/kxgettext.o
*** Unable to find the ncurses libraries or the
*** required header files.
*** 'make menuconfig' requires the ncurses libraries.
***
*** Install ncurses (ncurses-devel) and try again.
***
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
这是由于libncurses5-dev包没有安装,执行以下命令:
apt-get install libncurses5-dev
再尝试make menuconfig,将以下编译选项选中(默认都是选中的)
Kernel hacking
Kernel debugging
Compile the kernel with debug info
General setup
Kprobes
执行make;make modules_install;make install
执行cp vmlinux /lib/modules/2.6.38/2.6.38-prep (从一个教程上看来的,但是觉得没有必要这么做)
重启系统。
(4)安装elfutils
sudo apt-get install elfutils
(5)执行以下命令,有正确的返回值说明systemtap安装成功
#stap -ve ’probe begin { log("hello world") exit () }’
#stap -c df -e ’probe syscall.open { if (target()==pid()) log(name." ".argstr) }’
参考:
http://blog.chinaunix.net/space.php?uid=20589995&do=blog&id=1621748
http://linux.chinaunix.net/docs/2006-12-15/3479.shtml