Reputation: 4585
Is it possible to break execution when a watch variable (not a property, just a normal variable) changes to see where the change occurred? I searched and found this question which relates to properties it seems which is not what I'm looking for.
This variable is used several times in several thousand lines of code, but it is only changed from null
when a problem happens. We are trying to track that problem down.
Upvotes: 9
Views: 17805
Reputation: 1
inside vs code:
right click on breakpoint, choose EditBreakpoint right click, edit breakpoint
in the Expression, enter an expression as condition, when to stop the program e.g. SomeVariable == 0x7f2c44a31f98 (0x7f2c44a31f98 is the address of the variable to be watched) enter an expression for break condition
press enter
For our example, when SomeVariable is equal to 0x87654321, it won't stop, once the SomeVariable is equal to 0x7f2c44a31f98, it will stop
Upvotes: 0
Reputation: 1062780
+
in it to indicate that it is conditionalHowever: frankly, I find the following simpler and much more efficient - especially for fields; say we start with:
string name;
we change it just for now to:
private string __name;
string name {
get { return __name; }
set { __name = value; }
}
and just put a break-point on the set
line. It should still compile, and you can see the change trivially. For more complex cases:
private string __name;
string name {
get { return __name; }
set {
if(__name != value) {
__name = value; // a non-trivial change
}
}
}
and put the breakpoint on the inner-most line; this bypasses code that sets the field without actually changing the value.
Upvotes: 6