您的位置:首页 > 运维架构 > Shell

systemtap安装&内核调试环境配置

2012-07-16 16:27 537 查看
参考其官网:http://sourceware.org/systemtap/wiki

我是在ubuntu下安装的,所以转至这个网页:

http://sourceware.org/systemtap/wiki/SystemtapOnUbuntu

参考网页:http://blog.csdn.net/ustc_dylan/article/details/7079876

http://blog.csdn.net/heli007/article/details/7187748

1.systemtap的安装

systemtap的安装是很简单的,一条命令足以:

$sudo apt-get install systemtap

此时,你执行如下测试命令:

$sudo stap -ve 'probe
begin { log("hello world") exit() }'

也是可以正确打印出hello world的,但是,注意到这个小脚本中并不包含任何的与内核相关的跟踪信息,只是简单的打印hello world,因此,现在并不能开始调试内核,要对系统的环境进行配置。

2.环境配置

为什么配置?配置什么?

既然号称调试内核,那么一定是要有符号表的,但是一般情况下你安装的内核是不包含debug信息的,因为这个太大了。所以,我们现在需要增加debug信息,添加符号表等调试过程中需要的信息。有两种方式:

(1)重新编译内核,这次记得要在配置选项中增加debug选项。然后用新编译的内核替换你现在的内核。注意,这两个内核的版本要相同。(uname -r 就可以看到你用的哪个版本的内核了)

(2)按照官网的解决方法:

$sudo apt-get install linux-image-$(uname -r)-dbgsym.

但是这个命令并不凑效,因为你的更新源中可能并没有包含相应的dbgsys。因此,你可以自己下载对应版本的dbgsym。下载的网址是:http://ddebs.ubuntu.com/pool/main/l/linux/

下载完毕之后:

$sudo dpkg -i linux-image-3.2.0-26-generic-pae-dbgsym_3.2.0-26.41_i386.ddeb

这样,就在你的现有内核的基础上加入了调试信息。

但是现在还是不能够跟踪内核,按照官网的步骤,你还需要:

$sudo apt-get install elfutils
然后编辑shell脚本config_elfutils,并且运行($sudo sh config_elfutils),现在你可以跟踪内核信息了。

for file in `find /usr/lib/debug -name '*.ko' -print`
do
buildid=`eu-readelf -n $file| grep Build.ID: | awk '{print $3}'`
dir=`echo $buildid | cut -c1-2`
fn=`echo $buildid | cut -c3-`
mkdir -p /usr/lib/debug/.build-id/$dir
ln -s $file /usr/lib/debug/.build-id/$dir/$fn
ln -s $file /usr/lib/debug/.build-id/$dir/${fn}.debug
done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  file 脚本 ubuntu shell 测试
相关文章推荐