43

when developing C++ with VS you have this amazing feature of data breakpoints, which trigger when the data at a certain address in memory changes.

is there a similar feature when developing java in eclipse?

thanks!

edit: about the "suspend when value changes" feature: i have the impression that the execution must still reach the line where the breakpoint is. the thing is i want it to trigger anywhere as soon as the value changes.

clamp
  • 33,000
  • 75
  • 203
  • 299

6 Answers6

62

You can set a watchpoint on a field: put the cursor at the line where the field is being declared and select the menu Run -> Toggle Watchpoint
or just set a breakpoint by double-clicking at the left margin on that line.

You can change the properties of the watchpoint like suspend on field access or suspend on field modification after adding it. Just right-click on the watchpoint at the left margin and select Breakpoint Properties...

Search the help for watchpoint to get more information:

A watchpoint is a special breakpoint that stops the execution of an application whenever the value of a given expression changes, without specifying where it might occur. ...

user85421
  • 28,957
  • 10
  • 64
  • 87
  • 3
    This is useful (and I +1'ed), but it's still not quite the answer to the question. This break on *any* instance of that declaration, not on a specific instance. – Javid Jamae Aug 11 '11 at 17:42
  • I only have the watchpoint option available when the field is not final. How can I watch access to a final object? (I want to see whenever an item is added to or retrieved from a map.) – dj18 May 13 '16 at 15:09
  • that should have been another question... but strange, with Eclipse Mars there is no problem setting a watchpoint at a final variable (just tested with an ArrayList and a Path), but, no matter of final or not, this will not watch the contents of the object saved in the variable - it _only_ watches the content of the variable itself, that is, in your case, if the map instance is changed. You can put a breakpoint on the corresponding methods of the (Hash)Map and add a condition to check that `this` is the instance you want to watch. – user85421 May 18 '16 at 12:20
6

Using the Variable view:

  • right click the field and select "Toggle Watchpoint", and then
  • right click the same instance again and select "Instance breakpoints..." which allows you to restrict a specific breakpoint to a given instance.

Note that the performance is probably not as good as with a memory hardware breakpoint (like in VC++ for example).

Francois Misiak
  • 101
  • 1
  • 3
  • Does this option still exist? In Eclipse 2018-09 (4.9.0) I am only able to set a thread filter in the breakpoint properties. – Marcono1234 Nov 03 '18 at 18:28
3

Under breakpoint properties, you have the option of making it conditional and checking the radio button "Suspend when value changes".

Neil
  • 5,762
  • 24
  • 36
  • thanks, but how exactly do i provide the object or a variable to that object which i want to monitor? – clamp Nov 03 '10 at 10:35
  • You enter that in the field below. Granted, that's not the same as breaking whenever that variable changes, but if there's a bottleneck in which your program passes often, you can place such a breakpoint there and in theory break only when a certain value changes. – Neil Nov 03 '10 at 10:37
3

Right click on the Breakpoint and select Breakpoint properties.

In the opening screen, choose: Conditional -> Suspend when value changes

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
1

The closest thing would be editing the breakpoint properties. You could add conditions to check for distinct values. Another way could be adding a breakpoint to the setter method.

You can set the breakpoint properties by right-clicking on an already set breakpoint in the breakpoint view.

stacker
  • 68,052
  • 28
  • 140
  • 210
1

As far as I know, there is no such generic feature in Eclipse. However, you can give some conditions to an existing breakpoint:

Add a breakpoint somewhere in your code. Then, in the "Breakpoint" view, right click on it, then choose "Breakpoint properties". In the panel, you can add a condition that must be verified to make the application stops on this breakpoint (for example if (foo > 0)).

This is not exactly what you want, but I do not think Eclipse provides such feature.

Romain Linsolas
  • 79,475
  • 49
  • 202
  • 273