In This Book

You can examine the current state of program data, because variables are stored in memory and their values are always accessible.

The reason for this is that in unoptimized code, when you step from one statement to the next in the source code, what the debugger actually does is to step from one group of assembly instructions to the next; but because the assembly instruction groups correspond exactly to the source statements, it looks as if it is the source code itself that is executing.

When you debug optimized code, however, this corresp ondence breaks down:

An arrow cannot accurately represent your current location in the source code. When an arrow points to a given statement in the source code, it is likely that not all the statements before that statement have ￿nished executing, and that some of the statements after that statement have at least partly executed.

It is more di￿cult to determine the current state of program data, because variables may be stored in registers and access to them may be unreliable. Also, the order of assignments may be changed from the order in the source code.

In fact, it isn't really meaningful to talk of the current location in the source program with optimized codeonly of the instructions that are actually executing.

What Optimization Does to Data

 

In unoptimized code, the values of all program variables are kept in memory.

 

Every time the value of a variable changes, the new value is stored in memory.

 

This means that at any time, the debugger can determine the current value of

 

a variable.

 

In optimized code, the values of variables are kept in registers instead of

8

memory as m uch as possible, because register access is much faster than memory access. In addition, some v ariables ma y be eliminated and replaced b y constants. Therefore, it is m uch more di￿cult for the debugger to trac k the current value associated with a variable.

Sometimes, too, there may be multiple copies of a v ariablein loop optimizations, for instance. In suc h cases it is often impossible to obtain a meaningful value for the variable.

Debugging in Special Situations 8-21