๐ง Linux Debugging Tools
Linux offers a rich ecosystem of debugging tools that help diagnose and troubleshoot system issues, performance bottlenecks, and application problems. This guide covers both built-in and third-party utilities for effective Linux debugging.
๐ Core Debugging Utilities
strace โ System Call Tracing
Tracks system calls made by a process, helping identify I/O issues, hangs, or unexpected behavior.
1 2 3 4 5 6 7 8 | |
๐ก Tip: Use
-e trace=fileto focus on file-related syscalls.
ltrace โ Library Call Tracing
Monitors dynamic library calls instead of kernel-level syscalls.
1 2 3 4 5 | |
gdb โ GNU Debugger
A powerful interactive debugger for compiled programs (especially C/C++).
1 2 3 4 5 6 7 8 9 10 11 | |
๐ ๏ธ Requires debug symbols (
-gflag during compilation).
๐ Performance Analysis Tools
top / htop โ Real-Time Process Monitoring
Displays live resource usage per process.
1 2 3 4 5 | |
perf โ Performance Profiling
Advanced profiling tool for analyzing CPU cycles, cache misses, branch predictions.
1 2 3 4 5 6 7 8 | |
vmstat, iostat, sar โ System Metrics
Part of the sysstat package, these tools provide detailed metrics over time.
1 2 3 4 5 6 7 8 | |
๐๏ธ Filesystem & Storage Diagnostics
lsof โ List Open Files
Identify which processes have files open or are listening on ports.
1 2 3 4 5 6 7 8 | |
iotop โ Per-Process I/O Monitoring
Shows real-time disk I/O per process.
1 | |
df / du โ Disk Space Usage
Monitor filesystem space and directory sizes.
1 2 3 4 5 | |
๐ Network Troubleshooting
ss / netstat โ Socket Statistics
Check active network connections and socket states.
1 2 3 4 5 | |
tcpdump โ Packet Sniffing
Capture and analyze raw packets on the wire.
1 2 3 4 5 | |
ping / traceroute / mtr โ Connectivity Testing
Basic connectivity checks and path tracing.
1 2 3 4 5 6 7 8 | |
๐ง Memory Debugging
valgrind โ Memory Error Detection
Detect memory leaks, invalid reads/writes, and other errors.
1 2 3 4 5 | |
/proc/meminfo โ Kernel Memory Info
Access low-level memory info directly from procfs.
1 | |
๐ต๏ธโโ๏ธ Logs and Journaling
journalctl โ systemd Journal Viewer
Query logs managed by systemd journal.
1 2 3 4 5 6 7 8 | |
dmesg โ Kernel Ring Buffer
View kernel boot messages and hardware diagnostics.
1 2 3 4 5 | |
๐งฐ Advanced Toolkits
BCC (BPF Compiler Collection)
Use eBPF probes for advanced tracing without modifying code.
Example: trace slow file opens:
1 | |
Install via package manager:
1 | |
htop vs atop โ Enhanced Monitoring
While htop gives visual clarity, atop stores historical snapshots for post-mortem analysis.
1 2 3 4 5 | |
๐งพ Summary Table
| Tool | Purpose |
|---|---|
strace |
Syscall tracing |
ltrace |
Library call tracing |
gdb |
Interactive source-level debugger |
perf |
CPU profiling |
htop |
Live process viewer |
lsof |
Open files and ports |
tcpdump |
Packet capture |
valgrind |
Memory leak detection |
journalctl |
systemd log inspection |
dmesg |
Kernel diagnostic output |
๐ง Best Practices
โ Always verify your assumptions about system behavior โ Prefer structured logging in applications for easier diagnosis โ Combine multiple tools for layered insights โ Use containers/namespaces to isolate experiments โ Store logs securely and rotate regularly
๐งพ See Also
- Linux Proc and FS Semantics
- Linux Namespaces and CGroups
- Patterns: Logging and Telemetry
- Anti-Patterns: Silent Failures