strace backend
Classic strace subprocess-based tracing backend (usage, requirements, troubleshooting).
This page documents the classic strace backend used by stracectl.
What it is
The strace backend spawns the system strace binary and parses its stderr
output into SyscallEvent values. It is the default fallback when eBPF is
unavailable or when explicitly selected via --backend strace. The tracer
requires the strace binary to be present in PATH.
When it’s selected
--backend auto(default) selects eBPF when available; otherwise the CLI falls back to thestracebackend.- Use
--backend straceto force the classic subprocess tracer. - Use
--backend ebpfto force eBPF when available.
Runtime requirements
straceexecutable available inPATH(install withapt install straceon Debian/Ubuntu).- Attaching to arbitrary running processes requires
CAP_SYS_PTRACE(typically root) or kernel YAMA ptrace scope set to 0 — check your distribution docs. - Tracing a child process started by
stracegenerally does not require extra privileges.
How it runs
stracectl launches strace with these flags by default: -f -T -q. The tracer
reads strace’s stderr stream, parses lines and emits SyscallEvent values used
by the aggregator, TUI and HTTP API.
Examples:
# Trace a program using the strace backend
stracectl run --backend strace curl https://example.com
# Attach to a running process (requires ptrace permissions)
sudo stracectl attach --backend strace 1234
# Enable verbose parser diagnostics (gates raw strace diagnostics)
stracectl run --backend strace --debug curl https://example.com
Notes:
- When tracing a launched program,
stracectlputsstraceand its traced children into a separate process group so that a single cancellation kills the whole group (avoids orphaned children). - When attaching,
straceis invoked with-p PID.
Troubleshooting
- Error:
strace not found in PATH — install it with: apt install strace- Install the
stracepackage or ensure it’s inPATH.
- Install the
- Permission denied attaching to a PID
- Check
CAP_SYS_PTRACEor kernel YAMAptrace_scopesettings; run as root or adjust kernel settings.
- Check
- Parser parse errors or missing fields
- The parser handles interleaved
<unfinished ...>and<... resumed>lines by buffering prefixes per PID. Some edge cases can produce parse warnings; enable--debugto see noisy diagnostics (e.g.,EAGAINwith empty args).
- The parser handles interleaved
strace:lines (diagnostics from strace itself) are captured and logged ifstraceexits with an error.
Implementation notes
internal/tracer/strace.go— spawnsstrace, wires process group handling, reads stderr, and forwards parsedSyscallEventvalues.internal/parser/parser.go— statefulParserthat stitches<unfinished ...>/<... resumed>pairs and extracts syscall name, args, return value and latency.internal/models/event.go—SyscallEventdata structure produced by the parser/tracers.- The tracer increases the stderr scanner buffer to handle large syscall args (512KiB).
- Diagnostics:
- The package-level
tracer.Debugboolean enables additional noisy debug logs; the CLI sets this from the persistent--debugflag incmd/root.go.
- The package-level
See also
site/content/docs/ebpf.md— eBPF backend (recommended for lower overhead when available).docs/EBPF.md— repository-level eBPF notes and build instructions.cmd/root.go,internal/tracer/strace.go,internal/parser/parser.go,internal/models/event.go