一、systemtap工具编译
1.1、需要的源码,源码下载路径
https://sourceware.org/systemtap/ftp/releases/
https://sourceware.org/elfutils/ftp/
1.2、交叉编译
编译前在工具链目录下搜索是否存在obstack.h fts.h头文件,编译elfutils需要
1.2.1、编译zlib库
tar -zxf zlib-1.2.11.tar.gz
cd zlib-1.2.11
CC=arm-linux-gcc ./configure --prefix=/home/dyh/tools/systemtap/zlib-1.2.11/output
make
make install
1.2.2、编译elfutils工具包
tar -xf elfutils-0.166.tar.bz2
cd elfutils-0.166
export LDFLAGS=-L/home/dyh/tools/systemtap/zlib-1.2.11/output/lib
export CPPFLAGS=-I/home/dyh/tools/systemtap/zlib-1.2.11/output/include
export LIBS=-lz
./configure --host=arm-linux --prefix=/home/dyh/tools/systemtap/elfutils-0.166/output --with-zlib
make
make install
1.2.3、编译systemtap工具
1.2.3.1、编译脚本
tar -zxf systemtap-3.0.tar.gz
cd systemtap-3.0
./configure --host=arm-linux --with-elfutils=/home/dyh/tools/systemtap/elfutils-0.166 CXXFLAGS=-static CFLAGS=-static --prefix=/home/dyh/tools/systemtap/systemtap-3.0/output --exec-prefix=/home/dyh/tools/systemtap/systemtap-3.0/output/usr --disable-docs --disable-refdocs --disable-grapher --without-rpm --disable-option-checking --disable-nls --enable-FEATURE=no --disable-ssp --without-nss --disable-translator
make
make install
1.2.3.2、编译遇到的问题
问题:找不到头文件
解决:添加头文件路径
./staprun/Makefile中CPPFLAGS变量后补充1.2.2生成libelf.h头文件的路径
问题:找不到动态库
解决:添加动态库路径
./staprun/Makefile中LDFLAGS变量后补充1.2.2生成libelf.so动态库的路径
2、验证systemtap能否正常工作
2.1、创建hello-world.stap脚本
PC端(https://blog.csdn.net/sydyh43/article/details/119281834)
probe begin
{
print ("hello world.\n")
exit ()
}
2.2、编译hello-world.stap脚本,生成hello-world.ko文件
/home/dyh/tools/systemtap/systemtap-3.0/host-output/bin/stap -gv -a arm -r /home/dyh/tools/systemtap/systemtap-3.0/host-output -B CROSS-COMPILE=arm-linux- -m hello-world.ko hello-world.stap
设备端
2.3、将1.2.3编译出来的staprun、stapio和3.2编译出来的hello-world.ko拷贝到根文件系统目录,制作根文件系统
2.4、设备上运行staprun hello-world.ko能否输出hello world
3、systemTap的使用
https://sourceware.org/systemtap/wiki
https://segmentfault.com/a/1190000010774974
PS:
1、stap命令与staprun命令的区别在于:
stap命令的操作对象是stp文件或script命令等,而staprun命令的操作对象是编译生成的内核模块。
2、设备使用systemtap,内核需要打开以下功能