Aggressive optimizations (e.g. -O3) cause machine instructions to diverge from machine code. At this level, the compiler employs optimization techniques such as loop unrolling, function inlining, instruction re-ordering, optimizing out variables, and more.

The net effect of aggressive optimization is that the behavior of a debugger becomes much less predictable. For example, some breakpoints may be impossible to reach, as they may correspond to lines of code that have been optimized out (and therefore not are not included in the executable). Likewise, execution may occur in an arbitrary order, resulting in 'stepping through' the code appear to jump around randomly, rather than following each line of code sequentially.

In general, it is most straightforward to debug un-optimized code. Whenever the debugger appears to behave in a strange or unpredictable way, this is likely due to the effect of optimizations.

 
©   Cornell University  |  Center for Advanced Computing  |  Copyright Statement  |  Inclusivity Statement