Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way in the Eclipse debugger to be notified when the state of a Java object changes?

I'm debugging some legacy code where we have a cached object that appears to be changed externally.

If I know the object identifier for it (while debugging), is there some way to "watch" it so that if some other code in the same thread or another thread attempts to modify its state it'll trigger my debug?

I can't use just an expression watch for it since there may be references to that object elsewhere and as there are many instances of the same class.

like image 645
Uri Avatar asked Nov 10 '09 17:11

Uri


People also ask

What can the Eclipse debugger do?

Eclipse allows running an application in Debug mode which helps with stepping through each line of code in a program. Eclipse also provides a Debug Perspective which is a set of views grouped together that help inspect code and make the debugging process very effective.

What is Remote debugging in Eclipse?

The remote debugging of the Java program is an ultimate tool in the arsenal of a Java developer, which is often becoming the last and only tool to investigate a bug on a Java application running on the remote host like on a Linux server or Windows server.

How can you see variable references while debugging in Eclipse?

While debugging you can use the "Display" window where you can write pieces of code and "execute" them with inspect (highlight the code -> right click -> inspect). In that window you have access to all variables of the breakpoint's context.


2 Answers

Set a breakpoint in the code you want to stop in when the value changes.

  • Start in the breakpoint view.
  • Select the breakpoint
  • right-click and goto the "breakpoint properties"
  • Check the 'Enable Condition' box
  • in the text field enter the name of the variable to watch
  • select the 'value of condition changes' radio button
like image 153
Kelly S. French Avatar answered Nov 02 '22 06:11

Kelly S. French


If it is declared somewhere as a class or instance variable (should be, how else could you cache it), then you can also just set a breakpoint on the particular line. It will be called watchpoint and will by default be triggered on access and modification (configureable through breakpoint properties).

like image 26
BalusC Avatar answered Nov 02 '22 04:11

BalusC