Loading lessons...
Debugging Strategy
How to find and fix bugs systematically.
1. Reproduce
Run it. Find the input that breaks it.
2. Read the error lines first
The compiler points at the line and column.
3. Print suspects
c
printf("DEBUG: num=%d size=%d
", num, size);
4. Split the problem
Test small pieces in isolation.
5. Watch boundaries
Bugs cluster around 0, the ends of loops, and array ends.
6. Use a debugger (gdb)
bash
break main
next
print num
TL;DR
- Reproduce the bug first.
- Read the error line.
- printf focused messages.
- Test boundaries.
- Use a debugger.