Is it possible to conditionally set or encode breakpoints?

I have been wondering for a while - is there a way to intercept code / program ...? Conditionally? For example, can I specify something like: "when this variable becomes this value, break and open the debugger"? (It would be very useful, especially in long loops, when you want to debug loop execution for the value of the last loop.)

I assume this may be IDE-specific, since debugging is implemented differently in different IDEs ... I would be interested to know how to do this in any IDE, but especially in Eclipse and Visual Studio.

+6
language-agnostic debugging conditional breakpoints
source share
5 answers

This is possible in Visual Studio. You can usually click on the left edge to insert a 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 only tell the debugger a break at this breakpoint if the predicate is executed.

+5
source share

In Visual Studio, you can declaratively set a conditional breakpoint that is similar to a regular breakpoint, but will only break when a certain condition is true. A condition can use local variables and whatever is available, where the breakpoint is set from. Just right-click on any breakpoint (red dot) and select "Condition ...".

In addition, .NET languages ​​can call the Debugger.Break() method to programmatically interrupt execution. This can also be done in the if :

 if (count > 8 && Debugger.IsAttached) Debugger.Break(); 
+3
source share

If conditional breakpoints are not supported by your IDE, add an if statement and kill it inside.

 if (variable == 3) { // Stub code to attach breakpoint. 1 = 1; } 
+3
source share

Setting a conditional breakpoint in Eclipse (thanks for the answers from Visual Studio!):

Set a breakpoint. Right-click and select "Breakpoint Properties ...". Check the box next to "Include condition" and enter the condition code in the text area.

+2
source share

Most IDEs allow you to use conditional breakpoints for this reason. In Visual Studio, you can right-click the red dot of the margin breakpoint and open the conditions dialog box. You can also get the condition dialog from the breakpoint window in Visual Studio. I am not familiar with Eclipse.

+1
source share

All Articles