views:

757

answers:

3

Suppose I have a class

public classs MyClass {

   private Set<String> set = new HashSet<String>();

//and many methods here


}

is there a possibility to make an eclipse debugger stop at every line where set member is used ?

+12  A: 

I haven't used Eclipse for a while, but from what I remember this was possible in the Callisto release at least. If you set a breakpoint on the line containing the declaration, and then go into the advanced properties for that breakpoint, I believe you can set options for modification and access of that variable.

Edit: I just checked with Eclipse Europa. It does work broadly as I thought; the breakpoint is called a watchpoint when you set it on a variable; and in the "Breakpoint Properties" page (accessible by right-clicking on the breakpoint's bauble in the margin, and possibly in other ways) you can determine whether the debugger should stop on "Field access" and "Field Modification". In your case, you want the first one selected.

Andrzej Doyle
+1  A: 

Yes. You can put a breakpoint at the expression

private String propString;

The breakpoint gets another symbol and shows the tool tip "Watchpoint [Acess and modification] "

Whith Shift+Ctrl+I you can watch the value of a selected variable name when the debugger is in step mode.

You also can change variable values at runtime when the debugger is in step mode.

The eclipse debugger is a very useful and powerful tool.

Markus Lausberg
A: 

This has been part of the eclipse debugger from very start. You just have to set a breakpoint at the line where the variable is declared. For more control you can right click on the breakpoint and select breakpoint properties where you can set if you want to stop only on Access or Modification.

Please keep in mind that modification is actually the change in the value for value types and change in reference for reference types. For example if you set a modification breakpoint (watchpoint) on a HashMap then the debugger wont stop if you add items into this hashmap since adding items doesn't change the address/reference of the variable.