Master the fundamental concepts of debugging mastery through this focused micro-challenge.
GDB offers breakpoint mechanisms beyond simple line breaks. Conditional breakpoints, watchpoints, and catchpoints let you pause execution exactly when specific conditions are met, which saves hours of manual stepping through loops.
Conditional breakpoints stop only when a predicate is true:
break foo if x==5: Stop in foo only when x equals 5condition 1 x==10: Add a condition to breakpoint #1Hardware watchpoints use CPU debug registers:
watch variable: Stop when a variable is writtenrwatch variable: Stop when a variable is readCatchpoints intercept events:
catch syscall open: Stop on specific system callscatch throw: Stop when C++ exceptions are thrownYou will write a program with a loop and document which GDB commands would catch specific state changes. These features are essential for debugging complex programs where the bug only triggers after thousands of iterations.
Conditional breakpoints shine in loops that run thousands of iterations: instead of pressing continue repeatedly, you stop only when the counter hits the failing value. Watchpoints catch memory corruption the moment a variable changes, even if you do not know which line writes to it. Catchpoints on catch syscall reveal when a program opens unexpected files or spawns child processes during security reviews.
Write a C program with a loop and variables that documents and demonstrates GDB advanced breakpoint concepts through its output.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github