计算机 · 2021年12月18日 0

kernel tracing techniques

Install debug symbols

And read this SO answer.

[Install kernel source]

sudo apt install linux-source-4.15.0

Then go to /usr/src/linux-source-4.15.0 to uncompress the kernel source files.

The kernel source version 4.15.0 is not 100 percent matched with uname -r output, but it doesn’t seem to be a big problem.

Perf probe

Now you can trace kernel functions with perf probe command.

perf probe -s /usr/src/linux-source-4.15.0 -vvv -L tcp_sendmsg

很多时候,出于debug或者观测的目的,我们需要能够trace内核的执行流程和内部状态变化。因此这里汇总下常用的Linux Kernel Tracing技术。

kprobe

关于kprobe的介绍和入门教程可以学习这篇csdn上博客。这篇博客写的真是太好了,不像大多数csdn上的其他文章,都是转载还不注明出处的垃圾。不过里面例子里的do_fork函数应该是_do_fork函数才对,我不知道是作者笔误还是因为函数名称在Linux的版本更迭中变了,没有去查证。

ftrace

一篇ftrace的入门教程。这篇文章也讲了另外几种技术,后面一一介绍。

ebpf

SystemTap