5.2.3. Conditional Breakpoints
In many real-world cases, a program may perform its task well during the first few thousand times; it may then start crashing or encountering errors during its eight thousandth iteration of the task. Debugging programs like this can be difficult, as it is hard to imagine a programmer with the patience to issue a continue
command thousands of times just to get to the iteration that crashed.
Situations like this are common in real life, which is why GDB allows programmers to attach conditions to a breakpoint. For example, consider the following program:
To set a conditional breakpoint at the GDB prompt:
With this condition, the program execution will eventually stop with the following output:
Inspect the breakpoint information (using info br
) to review the breakpoint status: