Have you faced the problem of breakpoint clutter where breakpoints keep piling up only to hinder the debugging session? It is then that one realizes that there are some breakpoints that can be deleted and others disabled.
A useful feature in a debugger is a temporary breakpoint that automagically gets deleted when hit thereby reducing the clutter of unnecessary breakpoints. These breakpoints are useful when you wish to stop at a code location only once and do not require the execution to stop at that location ever again.
For example, say you are trying to determine whether a particular test scenario invokes a specific line of code or not, in that case a temporary breakpoint can be used as the breakpoint is not useful once it has been hit alteast once.
Below are steps on how to set temporary breakpoints in various debuggers.
Use the tb command to set a temporary breakpoint in gdb. It is similar to the break command but the breakpoint will automatically be deleted when hit.
Set a temporary breakpoint.
Like “break” except the breakpoint is only temporary,
so it will be deleted when hit. Equivalent to “break” followed
by using “enable delete” on the breakpoint number.
In Windbg, breakpoints set in the Command window using the bl /1 command can be used to create temporary breakpoints. The /1 tells Windbg that the breakpoint should be deleted when hit.
In Windbg temporary breakpoints are also known as “one shot breakpoints”.
I found it a bit painful to create temporary breakpoints in Visual Studio. The only way I could create one was by setting a breakpoint and then setting the hit count for the breakpoint to be equal to 1. The article here explains how to set a hit count in Visual Studio.
The amount of work involved to do this sometimes doesn’t make temporary breakpoints worthwhile to set. Moreover the breakpoint lingers on and doesn’t actually get deleted when hit.