Lesson 116 +10 XP

Debugging Strategy

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

printf("DEBUG: num=%d size=%d\n", 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)

break main
next
print num

TL;DR

  • Reproduce the bug first.
  • Read the error line.
  • printf focused messages.
  • Test boundaries.
  • Use a debugger.