| name | strace-ltrace |
| description | strace and ltrace skill for system call and library call tracing. Use when a binary behaves incorrectly without crashing, diagnosing file-not-found errors, permission failures, network issues, or unexpected library calls by tracing syscalls and library function calls. Activates on queries about strace, ltrace, syscall tracing, library interception, ENOENT, EPERM, strace -e, or diagnosing binary behaviour without a debugger. |
strace / ltrace
Purpose
Guide agents through tracing system calls with strace and library calls with ltrace — the most effective tools for diagnosing incorrect binary behaviour without a crash or debugger.
Triggers
- "My program behaves incorrectly — how do I trace what it's doing?"
- "How do I find what files a binary is opening?"
- "strace shows ENOENT — how do I interpret it?"
- "How do I trace network calls with strace?"
- "What is ltrace and how does it differ from strace?"
- "How do I trace a running process?"
Workflow
1. Basic strace usage
strace ./myapp arg1 arg2
strace -p 12345
strace -f ./myapp
strace ./myapp 2> trace.txt
strace -t -f ./myapp 2>&1 | head -100
2. Filter by syscall category
strace -e trace=file ./myapp
strace -e trace=network ./myapp
strace -e trace=open,openat,read,write ./myapp
strace -e trace=process ./myapp
strace -e trace=memory ./myapp
strace -e trace=signal ./myapp
strace -e trace=file,network ./myapp
| Category | Syscalls included |
|---|
file | open, openat, stat, access, unlink, rename, ... |
network | socket, connect, bind, accept, send, recv, ... |
process | fork, exec, wait, clone, exit, ... |
memory | mmap, munmap, mprotect, brk, ... |
signal | kill, sigaction, sigprocmask, ... |
ipc | pipe, socket pair, shmget, ... |
desc | close, dup, poll, select, epoll, ... |
3. Interpreting common errors
strace -e trace=file ./myapp 2>&1 | grep -E "ENOENT|EPERM|EACCES|ENOTSUP"
| Error | Meaning | Common cause |
|---|
ENOENT | No such file or directory | Config file missing, wrong path |
EACCES | Permission denied | File permissions, SELinux |
EPERM | Operation not permitted | Missing capability, suid needed |
EADDRINUSE | Address already in use | Port already bound |
ETIMEDOUT | Connection timed out | Network unreachable, firewall |
ECONNREFUSED | Connection refused | Server not listening |
EAGAIN | Resource temporarily unavailable | Non-blocking I/O, try again |
ENOMEM | Out of memory | Allocation failed |
EBADF | Bad file descriptor | Using closed/invalid fd |
ENOEXEC | Exec format error | Wrong binary format for arch |
strace ./myapp 2>&1 | grep 'ENOENT'
4. Useful strace flags
strace -s 256 ./myapp
strace -t ./myapp
strace -T ./myapp
strace -r ./myapp
strace -c ./myapp
strace -f -p ./myapp
strace -e verbose=all ./myapp
strace -i ./myapp
5. ltrace — library call tracing
ltrace ./myapp
ltrace -e malloc,free,fopen ./myapp
ltrace -n 2 ./myapp
ltrace -S ./myapp
ltrace -p 12345
ltrace -c ./myapp
Typical ltrace output:
malloc(1024) = 0x55a1b2c3d000
fopen("/etc/myapp.conf", "r") = 0
free(0x55a1b2c3d000) = <void>
strace vs ltrace:
| strace | ltrace |
|---|
| Traces | Kernel syscalls | User-space library calls |
| Overhead | Lower | Higher (PLT hooking) |
| Shows | open(), read(), write() | fopen(), malloc(), printf() |
| Use when | Binary interacts with OS/files/network | Binary calls library functions you can't see |
6. Practical diagnosis workflows
strace -e trace=openat,open ./myapp 2>&1 | grep ENOENT
strace -e trace=network -f ./myapp 2>&1 | grep connect
strace -e trace=openat ./myapp 2>&1 | grep "\.so"
strace -e trace=file ./myapp 2>&1 | grep -E "EACCES|EPERM"
strace -c ./myapp 2>&1
strace -e trace=ipc,shm ./myapp
strace -e trace=execve -f ./myapp
7. seccomp filter debugging
If a program is killed by a seccomp policy, strace reveals which syscall triggered it:
strace -e trace=all ./myapp 2>&1 | tail -5
For strace output patterns and ltrace filtering examples, see references/strace-patterns.md.
Related skills
- Use
skills/debuggers/gdb when strace shows the failing location and you need to inspect internals
- Use
skills/binaries/elf-inspection to understand what libraries and symbols a binary uses
- Use
skills/binaries/dynamic-linking for diagnosing LD_* and library loading issues
- Use
skills/profilers/linux-perf for performance profiling (strace overhead is too high for perf)