In This Book

Figure 8-4. Unoptimized Code: Statement-to-Instruction Mapping

This means that even though it is the object code that is being executed and not the source code, a view of the source code in the debugger can still give you an accurate view of what the object code is doing. For example, when you step from statement 1 to statement 2, instructions 1 through 5 are executed in order, and the current location is now instruction 6, corresponding to statement 2.

Figure 8-5 shows the several things that happen to source-code statements in optimized code.

As before, a source-code statement corresponds to several instructions. But these instructions are no longer contiguous; instead, there may be several groups of instructions, called fragments because they represent only part of a statement. (A fragment is formally de￿ned as a maximal set of contiguous instructions corresponding to the same source statement.) In the example, the statement on line 11 corresponds to three fragmen ts: instruction 4, instructions 9 and 10, and instruction 12.

 

Instructions in the object code can now correspond to more than one source

 

 

 

 

 

 

statement. In the example, instruction 4 is associated with the statements on

8

 

lines 11, 12, 13, 16, 17, and 18.

 

 

 

The order of statemen t execution can change. In the example, the

 

 

 

 

 

 

instructions from line 12 both begin and end execution before the

 

 

instructions from line 10, though some of the instructions from those lines

 

 

are interleaved.

 

Debugging in Special Situations 8-19