User`s manual

Dynamic C Users Manual digi.com 97
6.3.4 Watch Expressions
Like many other debugging features, watch expressions have been around since the beginning and have
improved over time. Dynamic C 8.01 introduced the ability to evaluate watchable expressions using fly-
over hints. (The highlighted expression does not need to be set as a watch expression for evaluation in a
flyover hint.) Dynamic C 9 introduced a new way of handling structures as watch expressions. Previously
when you set a watch on a struct, its members had to be added separately and deliberately. Now they are
set as watch expressions automatically with the addition of the struct.
Pros Any valid C expression can be watched. Multiple expressions can be watched
simultaneously. Once a watch is set on an expression, its value is updated in the
Watches window whenever program execution is stopped.
The Watches window may be updated while the program is running
(which will affect timing) by issuing the “Update Watch Window” com-
mand: use the Inspect menu, Ctrl+U or the toolbar menu button shown
hereto update the Watches window.
You can use flyover hints to find out the value of any highlighted C expression
when the program is stopped.
Cons The scope of variables in watch expressions affects the value that is displayed in
the Watches window. If the variable goes out of scope, its true value will not be
displayed until it comes back into scope.
Keep in mind two additional things, which are not bad per se, but could be if they
are used carelessly: Assignment statements in a watch expression will change
the value of a variable every time watches are evaluated. Similarly, when a func-
tion call is in a watch expression, the function will run every time watches are
evaluated.
Uses Use a watch expression when the value of the expression is important to the be-
havior of the part of the program you are analyzing.
Example Watch expressions can be used to evaluate complicated conditionals. A quick
way to see this is to run the program Samples\pong.c. Set a breakpoint at
this line
if (nx <= xl || nx >= xh)
within the function pong(). While the program is stopped, highlight the sec-
tion of the expression you want evaluated. Use the watches flyover hint by hov-
ering the cursor over the highlighted expression. It will be evaluated and the
result displayed. You can see the values of, e.g., nx or x1 or the result of the
conditional expression nx <= x1, depending on what you highlight.
Keep in mind that when single stepping in assembly, the value of the watch ex-
pression may not be valid for variables located on the stack (all auto variables).
This is because the debug kernel does not keep track of the pushes and pops that
occur on the stack, and since watches of stack variables only make sense in the
context of the pushes and pops that have happened, they will not always be ac-
curate when assembly code is being single stepped.