Optimizing compilers produce code that impedes source-level debugging. Examples are given in which optimization changes the behavior of a program even when the optimizer is correct, showing that in some circumstances it is not possible to completely debug an unoptimized version of a program. Source-level debuggers designed for unoptimized code may mislead the debugger user when invoked on optimized code. One situation that can mislead the user is a mismatch between where the user expects a breakpoint to be located and the breakpoint''s actual location. A mismatch may occur due to statement reordering or discontiguous code generated from a statement. This work describes a mapping between statements and breakpoint locations that ameliorates this problem. The mapping enables debugger behavior on optimized code that approximates debugger behavior on unoptimized code closely enough that the user need not make severe changes in debugging strategies. This work presents a method of determining when this has occurred, proves the method correct, and shows how a debugger can describe the relevant effects of optimization. The determination method is more general than previously published methods, handling global optimization, flow graph transformations, and not being tightly coupled to optimizations performed by a particular compiler. The information a compiler must make available to the debugger for this task is also described. A third situation that can mislead the user is when optimization has eliminated information in the run-time (procedure activation) stack that the debugger uses (on some architectures) to provide a call stack trace. This work gives several methods of providing the expected stack trace when the run-time stack does not contain this information.
Cited By
- Adl-Tabatabai A and Gross T Detection and recovery of endangered variables caused by instruction scheduling Proceedings of the ACM SIGPLAN 1993 conference on Programming language design and implementation, (13-25)
- Adl-Tabatabai A and Gross T (2019). Detection and recovery of endangered variables caused by instruction scheduling, ACM SIGPLAN Notices, 28:6, (13-25), Online publication date: 1-Jun-1993.
- Adl-Tabatabai A and Gross T Evicted variables and the interaction of global register allocation and symbolic debugging Proceedings of the 20th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, (371-383)
Recommendations
Debugging optimized code without being misled
Correct optimization can change the behavior of an incorrect program; therefore at times it is necessary to debug optimized code. However, optimizing compilers produce code that impedes source-level debugging.
Optimization can cause an inconsistency ...