3

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.

1

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

3 Comments

You cannot configure which conditions you want to stop at.
@mjaggard, yes you can. Create a Watch Point, select it in the Breakpints view, and there you see checkboxes for stopping at Access and Modification. Select which conditions you want to stop at.
Where can I select to stop when this variable equals 7? i.imgur.com/Wl6j1DH.png
3

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

4 Comments

Well, i thought that could be a good way, but i didn't write the code (i'm only bug fixing) and it is a huge project with lots and lots of classes so before spending hours editing the code i would try something more automatic!
No code modification is required to set up a breakpoint, just access to the source code...
The Setter gived you a single point of access, you can set a conditional breakpoint on every line of code that accesses the variable if you can't edit the code. However if lots of other classes are accessing a raw variable without a setter then your code suffers from tight coupling and should probably be re-factored to use a setter/getter anyway.
thank all of you for your answers. I have access to the code but there is no setter in the class for isAvailable. So, before adding a setter and change every class that accesses the variable or adding breakpoints in every method that accesses the variable, I will try something different... if nothing works i will try to follow your suggestions and will let you know how it goes!
0

Put a breakpoint in the method that sets the value for isAvailable.

When the breakpoint is hit, you'll have the possibility to check the whole execution stack. You will also be able to inspect the object and determine which of the 4 or 5 instances is concerned.

1 Comment

How do we do that in android studio

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.