Debugging Optimized Code
When you debug optimized code, information in
debugger panes may lead you to suspect logic problems that do not
actually exist. Consider the following points:
- Do not rely on panes such as stack frame
panes to show the current values of variables. Numeric
and char values may be kept in processor registers, as
may pointers to other types of variables such as strings
and class objects. In the optimized program, these values
and pointers are not always written out to memory; in
some cases, they may be discarded because they are not
needed.
- Static or external variables can be
monitored at function entry and exit points but their
value as displayed by the debugger during debugging of a
function may not be valid. The debugger displays the
storage allocated to the static or external variable, but
in optimized code, changes to a variable may not be
written out to storage immediately.
- The register and storage panes are
correct. Unlike panes that show actual variables, such as
the stack frame, the registers and storage panes are
always up-to-date as of the last time execution stopped.
- Use the Disassembly view of your program
to see whether source statements whose result you were
relying on have been eliminated during optimization (via
dead code elimination, where code that performs no useful
work is removed). You may find, for example, that an
assignment to a variable in your source code does not
result in any disassembly code being produced; this may
indicate that the variable's value is never used after
the assignment.

Debug
Optimized Code