在Ubuntu上安装使用Systemtap

本文发布时间: 2019-Mar-22
因为最近开始学习Nginx,在网上看到别人介绍了一款强大的内核探测工具Systemtap,于是便准备学习下这款探测工具为以后代码分析做准备。  第一步便是安装。在自己电脑上安装的时候,也是费了一番劲儿。因此,为防止以后需要重新安装,也希望可以帮助后来学习的人,在这里准备写一篇博客做一个记录。  以下便是安装步骤:  (0)、安装elfutils,提供分析调试信息的库函数,及libcap-dev。  借助于Ubuntu方便强大的包管理器,可以很方便进行安装,如下:sudo apt-get install elfutilssudo apt-get install libcap-dev  (1)、安装systemtap。  借助于Ubuntu方便强大的包管理器,可以很方便进行安装,如下:    sudo apt-get install systemtap  后续如果需要卸载,可执行如下命令:sudo apt-get remove systemtap  也可以通过源码进行安装,下载地址:https://sourceware.org/systemtap/ftp/releases/ 。解压然后进入根目录,执行如下命令:./configuremakesudo make instal  如果后续需要卸载,可进入根目录,执行如下命令:sudo make uninstall  (2)、安装debug symbols。   1)、配置ddeb repository。sudo cat > /etc/apt/sources.list.d/ddebs.list << EOFdeb http://ddebs.ubuntu.com/ precise main restricted universe multiverseEOFsudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ECDCAD72428D7C01sudo apt-get update  上面添加仓库地址也可以直接在ddebs.list文件后面添加相应地址。   2)、添加完repository之后,便是下载和你当前内核版本相对应的debug symbols。在这里推荐一位外国朋友写的脚本,写的非常好,博文链接(http://www.domaigne.com/blog/random/getting-debug-kernel-on-ubuntu/),感兴趣的可以去学习学习。因此为了减少错误发生,这里采用这里的脚本进行下载和安装:wget http://www.domaigne.com/download/tools/get-dbgsymchmod +x get-dbgsymsudo ./get-dbgsy  执行脚本后,可以去做些其他事情,因为这里可能需要等待较长的时间。  3)、生成systemtap/libelf所需的模块信息。将如下命令放入debug_ko.sh: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}.debugdone    然后执行该文件:sudo ./debug_ko.sh  (4)、测试安装是否成功。执行如下命令:stap -e 'probe kernel.function('sys_open') {log('hello world') exit()}'  如果在终端打印出“hello world”说明安装成功。如果没有,继续往下看。  (5)、如果按照上述步骤安装完之后,仍然不能使用,那么请参考下面的场景分别进行补充。  1)、如果执行(4)中的命令后,终端打印如下信息:stap: Symbol `SSL_ImplementedCiphers' has different size in shared object, consider re-linkingIn file included from include/linux/mutex.h:15:0, from /tmp/staphH2yQD/stap_6e022ad97cbe9c6f46b582f7a0eac81d_1242_src.c:25:include/linux/spinlock_types.h:55:14: error: ‘__ARCH_SPIN_LOCK_UNLOCKED’ undeclared here (not in a function) .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, ^include/linux/spinlock_types.h:79:15: note: in expansion of macro ‘__RAW_SPIN_LOCK_INITIALIZER’ { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } } ^include/linux/spinlock_types.h:82:16: note: in expansion of macro ‘__SPIN_LOCK_INITIALIZER’ (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname) ^include/linux/mutex.h:111:18: note: in expansion of macro ‘__SPIN_LOCK_UNLOCKED’ , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) ^include/linux/mutex.h:117:27: note: in expansion of macro ‘__MUTEX_INITIALIZER’ struct mutex mutexname = __MUTEX_INITIALIZER(mutexname) ^/tmp/staphH2yQD/stap_6e022ad97cbe9c6f46b582f7a0eac81d_1242_src.c:26:8: note: in expansion of macro ‘DEFINE_MUTEX’ static DEFINE_MUTEX(module_refresh_mutex); ^scripts/Makefile.build:258: recipe for target '/tmp/staphH2yQD/stap_6e022ad97cbe9c6f46b582f7a0eac81d_1242_src.o' failedmake[1]: *** [/tmp/staphH2yQD/stap_6e022ad97cbe9c6f46b582f7a0eac81d_1242_src.o] Error 1Makefile:1398: recipe for target '_module_/tmp/staphH2yQD' failedmake: *** [_module_/tmp/staphH2yQD] Error 2WARNING: kbuild exited with status: 2Pass 4: compilation failed. [man error::pass4]  说明有些共享库需要重新readlink,执行如下命令:readlink /lib/modules/`uname -r`/build/参考文章如下:  1、http://www.domaigne.com/blog/random/running-systemtap-on-ubuntu/  2、https://sourceware.org/systemtap/wiki/SystemtapOnUbuntu  3、https://wiki.ubuntu.com/Kernel/Systemtap出处:http://www.cnblogs.com/wtb2012/p/5218889.html


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:09pm
栏目列表