因为最近开始学习Nginx,在网上看到别人介绍了一款强大的内核探测工具Systemtap,于是便准备学习下这款探测工具为以后代码分析做准备。

  第一步便是安装。在自己电脑上安装的时候,也是费了一番劲儿。因此,为防止以后需要重新安装,也希望可以帮助后来学习的人,在这里准备写一篇博客做一个记录。

  以下便是安装步骤:

  (0)、安装elfutils,提供分析调试信息的库函数,及libcap-dev。

  借助于Ubuntu方便强大的包管理器,可以很方便进行安装,如下:

sudo apt-get install elfutils
sudo apt-get install  libcap-dev

  (1)、安装systemtap。

  借助于Ubuntu方便强大的包管理器,可以很方便进行安装,如下:    

sudo apt-get install systemtap

  后续如果需要卸载,可执行如下命令:

sudo apt-get remove systemtap

  也可以通过源码进行安装,下载地址:https://sourceware.org/systemtap/ftp/releases/ 。解压然后进入根目录,执行如下命令:

./configure
make
sudo make instal

  如果后续需要卸载,可进入根目录,执行如下命令:

sudo make uninstall

  (2)、安装debug symbols。

   1)、配置ddeb repository。

sudo cat > /etc/apt/sources.list.d/ddebs.list << EOF
deb http://ddebs.ubuntu.com/ precise main restricted universe multiverse
EOF sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ECDCAD72428D7C01
sudo 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-dbgsym

chmod +x get-dbgsym

sudo ./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-`
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

    然后执行该文件:

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-linking
In file included from include/linux/mutex.h::,
from /tmp/staphH2yQD/stap_6e022ad97cbe9c6f46b582f7a0eac81d_1242_src.c::
include/linux/spinlock_types.h::: error: ‘__ARCH_SPIN_LOCK_UNLOCKED’ undeclared here (not in a function)
.raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
^
include/linux/spinlock_types.h::: note: in expansion of macro ‘__RAW_SPIN_LOCK_INITIALIZER’
{ { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } }
^
include/linux/spinlock_types.h::: note: in expansion of macro ‘__SPIN_LOCK_INITIALIZER’
(spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname)
^
include/linux/mutex.h::: note: in expansion of macro ‘__SPIN_LOCK_UNLOCKED’
, .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
^
include/linux/mutex.h::: note: in expansion of macro ‘__MUTEX_INITIALIZER’
struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
^
/tmp/staphH2yQD/stap_6e022ad97cbe9c6f46b582f7a0eac81d_1242_src.c::: note: in expansion of macro ‘DEFINE_MUTEX’
static DEFINE_MUTEX(module_refresh_mutex);
^
scripts/Makefile.build:: recipe for target '/tmp/staphH2yQD/stap_6e022ad97cbe9c6f46b582f7a0eac81d_1242_src.o' failed
make[]: *** [/tmp/staphH2yQD/stap_6e022ad97cbe9c6f46b582f7a0eac81d_1242_src.o] Error
Makefile:: recipe for target '_module_/tmp/staphH2yQD' failed
make: *** [_module_/tmp/staphH2yQD] Error
WARNING: kbuild exited with status:
Pass : 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

在Ubuntu上安装使用Systemtap的更多相关文章

  1. [异常解决] ubuntu上安装JLink驱动遇到的坑及给后来者的建议

    一.前言 最近将整个电脑格式化,改成了linux操作系统 希望这样能让自己在一个新的世界探索技术.提升自己吧- win上的工具用多了,就不想变化了- 继上一篇<ubuntu上安装虚拟机遇到的问题 ...

  2. Ubuntu上安装Robomongo及添加到启动器

    到目前为止,Robomongo仍是MongoDB最好的客户端管理工具,如需在Ubuntu上安装Robomongo,可直接从官网下载.tar.gz压缩包进行解压,然后直接运行bin目录下的robomon ...

  3. 在 Ubuntu 上安装 Android Studio

    在 Ubuntu 上安装 Android Studio http://www.linuxidc.com/Linux/2013-05/84812.htm 打开terminal,输入以下命令 sudo a ...

  4. Ubuntu上安装Karma失败对策

    在Ubuntu上安装Karma遇到超时 timeout 错误.Google了一下,国外的码农给了一个快捷的解决方案,实测可行,贴在这里: sudo apt-get install npm nodejs ...

  5. 在Ubuntu上安装LAMP服务器

    1.安装Ubuntu上安装LAMP apt-get install lamp-server^ 2.安装过程中设置MySql密码 3.测试 创建index.php var/www/html/index. ...

  6. [译]How to Setup Sync Gateway on Ubuntu如何在ubuntu上安装sync-gateway

    参考文章https://hidekiitakura.com/2015/03/21/how-to-setup-sync-gateway-on-ubuntudigitalocean/ 在此对作者表示感谢 ...

  7. 在Ubuntu上安装JDK、Ant、Jmeter和Jenkins

    一.前期准备 1. 在win7下载VMware.Ubuntu(用迅雷下比较快) 2. 安装完VMware后新建虚拟机,选择iso: 3. 具体配置参考如下,至此Ubantu安装完成 二.在Ubuntu ...

  8. Ubuntu上安装MongoDB(译)

    add by zhj:直接从第四步开始就可以了,而且安装好MongoDB后会自动启动的,不必自己去执行启动命令 原文:https://docs.mongodb.com/manual/tutorial/ ...

  9. Ubuntu上安装ns2-2.34

    Ubuntu上安装ns2-2.34 步骤1 下载ns-allinone-2.34 $ tar zxf ns-allinone-2.34.tar.gz 步骤2 sudo apt-get install ...

随机推荐

  1. PHP 开启 ssh2

    首先,为PHP安装SSH2扩展需要两个软件包, libssh2和ssh2(php pecl拓展). 两者的最新版本分别为libssh2-1.5.0.tar.gz和ssh2-0.12.tgz,下载地址分 ...

  2. Python Tutorial 学习(四)--More Control Flow Tools

    4.1 if 表达式 作为最为人熟知的if.你肯定对这样的一些表达式不感到陌生: >>> x = int(raw_input("Please enter an intege ...

  3. CentOS下命令行和桌面模式的切换方法(转载)

    桌面模式和命令行模式的切换方法 用编辑器打开 /etc/inittab 文件(这里用的是vi,你可以选择你喜欢的): #vi /etc/inittab 打开效果图如下: 桌面模式    : 把光标所在 ...

  4. 『安全科普』WEB安全之渗透测试流程

    熟悉渗透流程,攻击会像摆积木一样简单! 0x 01:信息收集 收集网站信息对渗透测试非常重要,收集到的信息往往会让你在渗透中获得意外惊喜. 1. 网站结构 可以使用扫描工具扫描目录,主要扫出网站管理员 ...

  5. 转:PHP开发者应了解的24个库

    原文来自于:http://blog.jobbole.com/54201/ 作为一个PHP开发者,现在是一个令人激动的时刻.每天有许许多多有用的库分发出来,在Github上很容易发现和使用这些库.下面是 ...

  6. [BZOJ 1026] [SCOI 2009] Windy数 【数位DP】

    题目链接:BZOJ - 1026 题目分析 这道题是一道数位DP的基础题,对于完全不会数位DP的我来说也是难题.. 对于询问 [a,b] 的区间的答案,我们对询问进行差分,求 [0,b] - [0,a ...

  7. 利用多线程资源竞争技术上传shell

    通过多线程资源竞争的手段同时上传两个头像,就可以在Apache+Rails环境下实现远程代码执行.这并不是天方夜谭,同时我相信许多文件上传系统都会有这个漏洞……这是一个非常有趣的安全实验,一起来看看吧 ...

  8. javascript content

    1. Chrome, Mozila, IE 2. jQuery, underscore, zepto 3. underscore 4. Backbone, AngularJS 5. RequireJS ...

  9. 使用 InstallShield limited edition 打包部署Outlook 2013 Office add-in插件

    原文: Outlook: Deploying an Outlook 2013 add-in (using InstallShield LE) Today I had to create an inst ...

  10. ARM机器码分析

    我们编写的汇编程序还是不够底层,CPU都是对机器码进行操作的,所以还需要用汇编器将汇编代码转换成机器码才能被CPU处理.下面举几个例子来说说分析ARM机器码的方法. 对编译连接之后得到的ELF进行反汇 ...