Search code examples
debugginglanguage-agnosticconditional-statementsbreakpoints

Is there any way to set or code breakpoints conditionally?


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.


Solution

  • 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.