I've been wondering this for a while - is there a way to code/program breakpoints...? Conditionally? For example, can I specify something like - "when this variable becomes this value, break and open the debugger"? (Would be quite useful, especially in long loops when you want to debug loop execution of a late loop value.)
I suppose this may be IDE-specific since debugging is implemented differently in different IDEs... I'd be interested to know how to do this in any IDE, but specifically in Eclipse and Visual Studio.
This is definitely possible in Visual Studio. You can normally click in the left margin to insert the breakpoint, and then right click on that breakpoint. One of the options in the right click menu is "Condition...", and you can specify a predicate that will tell the debugger only the break on that breakpoint if the predicate is met.
In Visual Studio, you can declaratively set conditional breakpoint, which are like normal breakpoint but will only break when a certain condition is true. The condition can use local variables and whatever is accessible from where the breakpoint is set. Just right click any breakpoint (red dot) and select "Condition...".
In addition, .NET languages can call the Debugger.Break()
method to programmatically break the execution. This also can be done within an if
statement:
if (count > 8 && Debugger.IsAttached)
Debugger.Break();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With