From Script to Kernel Module
SystemTap works very differently from standard interpreters or even eBPF. When you run a script (script.stp), a complex five-step pipeline executes before a single probe fires:
- Parse: The
stapfrontend reads and validates your.stpscript syntax. - Elaborate: It resolves your probe points (e.g.,
kernel.function("sys_open")) against the Kernel Debug Symbols (debuginfo). This step maps human-readable function names to exact memory addresses in the running kernel. Withoutdebuginfo, this step fails entirely. - Translate: It converts your script into C code — a
.cfile that implements the probe logic as kernel-compatible functions. - Compile: It invokes
gccto compile that C code into a Linux Kernel Module (.kofile), linking against the kernel headers fromkernel-devel. - Run: It calls
insmodto load the module into the live kernel. The module attaches to kernel hooks (viakprobesoruprobesunder the hood), collects data, and streams results back to your terminal via a relay buffer.
Latency Warning: Because it compiles C code on every invocation, a SystemTap script typically takes 10–30 seconds to start. This is not a tool for instant ad-hoc queries the way tcpdump or strace is. Plan for this startup cost in production runbooks.
The dependency problem in practice: The debuginfo packages for a kernel are large — often 300–500 MB. On a minimal production server, they are almost never pre-installed. This means your first step in any SystemTap investigation on a new host is a package installation, which may require internet access or an internal mirror. This operational friction is a primary reason eBPF with CO-RE (Compile Once, Run Everywhere) and BTF (BPF Type Format) eventually displaced SystemTap — eBPF programs can carry their own type information and don't require matching debuginfo on the target host.