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.
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.
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.
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.
Set a breakpoint in the code you want to stop in when the value changes.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With