Strace Tips for Better Debugging
a year ago
- #Linux
- #debugging
- #strace
- Building software without libc to understand Linux syscalls and internals better.
- Projects include a minimal shell, terminal Snake game, ARM64 assembly HTTP server, and threads implementation.
- Using strace for debugging with extensive options.
- Key strace options: -f (follow child processes), -v (unabbreviated structs), -s (string size limit), -o (save output to log).
- Additional useful strace flags: -yy (file descriptor info), -Y (command names for PIDs), -t (timestamps), -T (time spent in syscalls).
- Debugging aids: -n (syscall numbers), -i (instruction pointer), -C (syscall summary).
- Stack traces with -k for programs compiled with -g.
- Selective syscall tracing with -e (e.g., %net, %mem), -z (successful calls), -Z (failed calls), -P (path-specific calls).
- Tampering with syscalls using -e inject for fault injection, retval, signal, or delays.
- Useful for debugging failure cases, with injected errors marked as INJECTED in output.