views:

86

answers:

2

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.

+2  A: 

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).

BalusC
It is not a variable change but modification to the state of an object that needs to be watched.
Murali VP
Then set the breakpoints on the object's properties.
BalusC
@BallusC: If only whoever wrote this code actually used getters and setters :)
Uri
I do not mean getters/setters. I actually meant class/instance variables. Put the breakpoints on variables, not methods.
BalusC
+3  A: 

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
Kelly French