ltrace
Overview
ltrace intercepts and prints dynamic library calls of a process (similar to how strace prints syscalls). Useful when you need to see malloc, strcmp, fopen, or library-level behavior without a full debugger.
sudo apt install ltraceSyntax
ltrace [options] command [args...]
ltrace -p PIDCommon Options
| Option | Description |
|---|---|
-e filter |
Include/exclude symbols |
-p PID |
Attach to process |
-c |
Counts / summary |
-T |
Show time in calls |
-f |
Follow forks |
-o file |
Output file |
-s strsize |
String capture length |
Safety
- Attaching can slow or perturb production processes.
- Needs appropriate
ptracepermissions (kernel.yama.ptrace_scope).
- Do not leave high-volume tracing on busy services.
Examples with Explanations
Trace a command
ltrace -e fopen+fclose+read ls /tmp 2>&1 | headSummary counts
ltrace -c true
ltrace -c ./myapp --flag 2>&1 | tailAttach
ltrace -p "$(pidof myapp)" -e 'malloc+free' -cNotes & Pitfalls
- Statically linked binaries show little.
- Prefer
stracefor syscall/ENOENT path issues;ltracefor library logic.
- Go/Rust binaries may be less informative depending on linkage.
Additional Resources
man ltrace