| name | debugging-methodology |
| description | Systematic debugging for memory, performance, and system-level issues. Use when diagnosing memory leaks, tracing syscalls with strace/eBPF, profiling, or reasoning about races. |
| user-invocable | false |
| allowed-tools | Bash, Read, Grep, Glob |
| model | opus |
| created | "2025-12-27T00:00:00.000Z" |
| modified | "2026-05-09T00:00:00.000Z" |
| reviewed | "2026-04-25T00:00:00.000Z" |
Debugging Methodology
Systematic approach to finding and fixing bugs.
When to Use This Skill
| Use this skill when... | Use something else instead when... |
|---|
| Diagnosing a live bug, memory leak, race, or perf regression | Bug is hidden by a swallowed error → code-hidden-failures --track errors |
| Reasoning about reproduction, isolation, and root cause | Bug is hidden by silent success-on-empty → code-hidden-failures --track degradation |
| Choosing strace/eBPF/perf for system-level investigation | Reviewing surrounding code quality once root cause is known → code-review |
| Documenting hypotheses and binary-searching the failure | Refactoring the buggy module after the fix → code-refactor |
Core Principles
- Occam's Razor - Start with the simplest explanation
- Binary Search - Isolate the problem area systematically
- Preserve Evidence - Understand state before making changes
- Document Hypotheses - Track what was tried and didn't work
Debugging Workflow
1. Understand → What is expected vs actual behavior?
2. Reproduce → Can you trigger the bug reliably?
3. Locate → Where in the code does it happen?
4. Diagnose → Why does it happen? (root cause)
5. Fix → Minimal change to resolve
6. Verify → Confirm fix works, no regressions
Common Bug Patterns
| Symptom | Likely Cause | Check First |
|---|
| TypeError/null | Missing null check | Input validation |
| Off-by-one | Loop bounds, array index | Boundary conditions |
| Race condition | Async timing | Await/promise handling |
| Import error | Path/module resolution | File paths, exports |
| Type mismatch | Wrong type passed | Function signatures |
| Flaky test | Timing, shared state | Test isolation |
System-Level Tools
Memory Analysis
valgrind --leak-check=full --show-leak-kinds=all ./program
valgrind --tool=massif ./program
python -m memory_profiler script.py
Performance Profiling
perf record -g ./program
perf report
perf top
python -m cProfile -s cumtime script.py
System Tracing (Traditional)
strace -f -e trace=all -p PID
ltrace -f -S ./program
lsof -p PID
pmap -x PID
eBPF Tracing (Modern, Production-Safe)
eBPF is the modern replacement for strace/ptrace-based tracing. Key advantages:
- Low overhead: Safe for production use
- No recompilation: Works on running binaries
- Non-intrusive: Doesn't stop program execution
- Kernel-verified: Bounded execution, can't crash the system
sudo syscount -p PID
sudo opensnoop -p PID
sudo execsnoop
sudo tcpconnect
sudo funccount 'vfs_*'
sudo bpftrace -e 'tracepoint:syscalls:sys_enter_open { printf("%s %s\n", comm, str(args->filename)); }'
sudo bpftrace -e 'uprobe:/bin/bash:readline { printf("readline\n"); }'
sudo bpftrace -e 'uprobe:./myapp:main.handleRequest { printf("called\n"); }'
eBPF Tool Hierarchy:
| Level | Tool | Use Case |
|---|
| High | BCC tools | Pre-built tracing scripts |
| Medium | bpftrace | One-liner custom traces |
| Low | libbpf/gobpf | Custom eBPF programs |
When to use eBPF over strace:
- Production systems (strace adds 10-100x overhead)
- Long-running traces
- High-frequency syscalls
- When you can't afford to slow down the process
Network Debugging
tcpdump -i any port 8080
ss -tuln
netstat -tuln
Language-Specific Debugging
Python
import pdb; pdb.set_trace()
import ipdb; ipdb.set_trace()
print(f"{var=}")
JavaScript/TypeScript
debugger;
console.log({ var1, var2, context: 'function_name' });
Rust
dbg!(&variable);
RUST_BACKTRACE=1 cargo run
Debugging Questions
When stuck, ask:
- What changed recently that could cause this?
- Does it happen in all environments or just one?
- Is the bug in my code or a dependency?
- What assumptions am I making that might be wrong?
- Can I write a minimal reproduction?
Effective Debugging Practices
- Targeted changes: Form a hypothesis, change one thing at a time
- Use proper debuggers: Step through code with breakpoints when possible
- Find root causes: Trace issues to their origin, fix the source
- Reproduce first: Create a minimal reproduction before attempting a fix
- Verify the fix: Confirm the fix resolves the issue and passes tests