一.安装systemtap
apt-get install systemtap
二.安装内核调试信息
直接在
http://ddebs.ubuntu.com/pool/main/l/linux/
页面下载下面的包(不需要重新编译内核,只需要下载这个包)
linux-image-unsigned-4.15.0-66-generic-dbgsym_4.15.0-66.75_amd64.ddeb
(我的CPU是x86_64的下载的这个)
三.测试
stap -p4 sample.stp -m sample (根据sample.stp生成sample.ko,sample.stp的内容在下面)
staprun sample.ko (运行ko)
运行后不报错就说明安装OK了
注意:如果不安装内核调试信息会遇到如下问题,下面这个过程就是我踩的坑
Ubuntu18.04下安装好Systemtap后运行如下测试命令
stap -p2 sample.stp
其中sample.stp内容如下:
#cat sample.stp
probe kernel.function(“sys_read”) { printf(“hi from sys_read!\n”); exit() }
1.运行报如下错误
semantic error: while resolving probe point: identifier ‘kernel’ at sample.stp:1:7
source: probe kernel.function(“sys_read”) { printf(“hi from sys_read!\n”); exit() }
^
semantic error: missing x86_64 kernel/module debuginfo [man warning::debuginfo] under ‘/lib/modules/4.15.0-66-generic/build’
Pass 2: analysis failed. [man error::pass2]
Tip:
/usr/share/doc/systemtap/README.Debian
should help you get started.
2.运行stap-prep命令
根据
README.Debian的提示需要运行stap-prep命令
To use systemtap you need to manually install the linux-image-*-dbg and linux-header-* packages that match your running kernel. To simplify this task you can use the stap-prep command.
但运行stap-prep后会报如下问题(需要dbgsym信息)
You need package
linux-image-4.15.0-66-generic-dbgsym
but it does not seem to be available
Ubuntu -dbgsym packages are typically in a separate repository
Follow https://wiki.ubuntu.com/DebuggingProgramCrash to add this repository
3.直接在
http://ddebs.ubuntu.com/pool/main/l/linux/
页面下载下面的包(不需要重新编译内核,只需要下载这个包)
linux-image-unsigned-4.15.0-66-generic-dbgsym_4.15.0-66.75_amd64.ddeb
(我的CPU是x86_64的下载的这个)
4.下载后运行如下的命令安装
dpkg -i
linux-image-unsigned-4.15.0-66-generic-dbgsym_4.15.0-66.75_amd64.ddeb
5.再次运行stap-prep命令
综上,就可以用stap命令了
stap -p4 sample.stp -m sample (根据sample.stp生成sample.ko)
staprun sample.ko (运行ko)