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.

Lii
  • 11,553
  • 8
  • 64
  • 88
aveschini
  • 1,632
  • 3
  • 22
  • 39
  • http://stackoverflow.com/questions/801193/modify-view-static-variables-while-debugging-in-eclipse – Momo Nov 23 '12 at 16:15

3 Answers3

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

E-Riz
  • 31,431
  • 9
  • 97
  • 134
  • You cannot configure which conditions you want to stop at. – mjaggard Apr 24 '13 at 10:49
  • @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. – E-Riz Apr 24 '13 at 16:40
  • Where can I select to stop when this variable equals 7? http://i.imgur.com/Wl6j1DH.png – mjaggard Apr 25 '13 at 10:18
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

Omar Kooheji
  • 54,530
  • 68
  • 182
  • 238
  • 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! – aveschini Nov 23 '12 at 16:17
  • No code modification is required to set up a breakpoint, just access to the source code... – Alexis Pigeon Nov 23 '12 at 16:22
  • 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. – Omar Kooheji Nov 23 '12 at 16:31
  • 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! – aveschini Nov 23 '12 at 16:40
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.

Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44