If you associate an expression with a watchpoint (by selecting the Conditional button in the Watchpoint Properties dialog box
entering an expression), TotalView evaluates the expression after the watchpoint triggers. The programming statements that you can use are identical to those used when you create an eval point, except that you can’t call functions from a watchpoint expression.
When the value of the iValue global variable is neither 42 nor 44, TotalView stores the new and old memory values in the
iNewValue and
iOldValue variables. These variables are defined in the program. (Storing the old and new values is a convenient way of letting you monitor the changes made by your program.)
If a watchpoint has the same length as the $oldval or
$newval data type, the value of these variables is apparent. However, if the data type is shorter than the length of the watch region, TotalView searches for the first changed location in the watched region and uses that location for the
$oldval and
$newval variables. (It aligns data in the watched region based on the size of the data’s type. For example, if the data type is a 4-byte integer and byte 7 in the watched region changes, TotalView uses bytes 4 through 7 of the watchpoint when it assigns values to these variables.)
For example, suppose you’re watching an array of 1000 integers called must_be_positive, and you want to trigger a watchpoint as soon as one element becomes negative. You declare the type for
$oldval and
$newval to be
int and use the following condition:
When your program writes a new value to the array, TotalView triggers the watchpoint, sets the values of
$oldval and
$newval, and evaluates the expression. When
$newval is negative, the
$stop statement halts the process.
This can be a very powerful technique for range-checking all the values your program writes into an array. (Because of byte length restrictions, you can only use this technique on Solaris.)