Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track value of a variable in Eclipse Java Debugger

I would like to track the value of a boolean (not Boolean) variable in the Eclipse debugger.

I need to know when it does change and, for this, i need to track it's value through all the execution; not only when it is in scope.

More particularly: I have a class (let's call it myClass) with a boolean member variable called isAvailable. My program instantiate 4 or 5 myClass objects. I am expecting that at the end of the execution the isAvailable value of all of my objects is set to true. Contrarily to my excpectation one of myClass objects has isAvailable set to false. I need to know which (in a lot of) methods is setting isAvailable to false.

like image 248
aveschini Avatar asked Nov 17 '25 12:11

aveschini


2 Answers

You can set a watchpoint on the member field. A watchpoint is like a breakpoint that suspends execution when the field is either accessed or modified (you can configure which conditions you want to stop at). See http://www.vogella.com/articles/EclipseDebugging/article.html#advanced_watchpoint

like image 170
E-Riz Avatar answered Nov 20 '25 04:11

E-Riz


Do you have access to the code the class is in?

Instead of using the variable use setters and getters to access it, then just put a break point on the setter.

IF you just need to know when it changes put a conditional break point and have the expression be something like:

available != this.available

Assuming your setter is of the following format:

public void setAvailable(boolean available){
    this.available = available;
}

You can get a conditional break point by right clicking on the break point symbol once you've set a break point.

Here is an FAQ about conditional break points: http://wiki.eclipse.org/FAQ_How_do_I_set_a_conditional_breakpoint%3F

like image 42
Omar Kooheji Avatar answered Nov 20 '25 03:11

Omar Kooheji



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!