Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-line dependent conditional breakpoints

Is it possible to set a breakpoint so that the program stops executing after an instruction has made certain condition true?

A class has a variable named currency and I want to make a breakpoint to make the program stop at any line after currency == 20. I do not know the line number where currency is changed, so this would be like putting a breakpoint in every line of my class [ed. where currency gets changed].

Is there any way to accomplish that (besides adding a breakpoint at each line)?

I am using NetBeans, but a solution in any other IDE is welcome.

like image 514
xtracto Avatar asked Jan 22 '10 15:01

xtracto


People also ask

What are conditional breakpoints?

Conditional breakpoints allow you to break inside a code block when a defined expression evaluates to true. Conditional breakpoints highlight as orange instead of blue. Add a conditional breakpoint by right clicking a line number, selecting Add Conditional Breakpoint , and entering an expression.

How do you set a breakpoint in Goland?

Set line breakpointsClick the gutter at the executable line of code where you want to set the breakpoint. Alternatively, place the caret at the line and press Ctrl+F8 .

How many types of breakpoints can be set in Informatica?

There are six types of breakpoints as follows: Automatic. Conditional. Request.

Is a conditional breakpoint that is not associated with any particular line but with a variable?

A more sophisticated approach uses dynamic (or "conditional") breakpoints. These are not bound to a particular line, but rather to a particular situation. When you run it, the PowerShell debugger will automatically stop the script whenever a new value is assigned to the variable $a.


1 Answers

Here is a link on setting conditional breakpoints in NetBeans: http://www.java-hair.com/?p=61

The relevant text:

In NetBeans, create a breakpoint, the right click on the little pink square that signifies the break. Click on “Customize”. When the customize dialog comes up, check “Condition” and fill in the condition. Above is an example of this dialog in NetBeans.

They also cover Eclipse and JDeveloper.

Edit: in response to your comment - no, this can't be done the way you want it. The way a debugger sets a breakpoint is by changing a byte in the instruction where the breakpoint is set. When the instruction is evaluated, the presence of that byte transfers control to the debugger, who replaces the byte with whatever was there before. When execution is resumed, the debugger moves the instruction pointer to the instruction where the breakpoint was set.

A conditional breakpoint on a single line is then easy to implement - when control transfers to the debugger, he simply checks the condition, and if it is not true then he resumes execution automatically.

So, how would it work if you didn't have to attach the conditional breakpoint to a line? It would have to be attached to every single line (just as you surmised you would need to do to achieve this effect otherwise). I haven't had the need to do this, but I imagine it would be undesirable as it would slow program execution considerably. A better approach might be to use your IDE to search through the code for all instances of currency to see where it might be set, and put conditional breakpoints around there.

like image 110
danben Avatar answered Oct 29 '22 13:10

danben