Debugging optimized code

Debugging optimized programs presents special problems. Optimization can change the sequence of operations, add or remove code, and perform other transformations that make it difficult to associate the generated code with the original source statements. For example, the optimizer can remove all stores to a variable and represent the value in one or more machine registers. Most debuggers are incapable of following the removal of stores to a variable, and to the debugger it appears as though that variable is never updated, or possibly even set.

If you are debugging SMP code, -qsmp=noopt ensures that the compiler performs only the minimum transformations necessary to parallelize your code and preserves maximum debug capability.

First debug your program, then recompile it with your desired optimization options, and test the optimized program before placing the program into production. If the optimized code does not produce the expected results, you can attempt to isolate the specific optimization problems in a debugging session.

The following table presents options that provide specialized information, which can be helpful during the development of optimized code.

Diagnostic options

Option
Behavior
-qkeepparm
Ensures that procedure parameters are stored on the stack even during optimization. This can negatively impact execution performance. The -qkeepparm option then provides access to the values of incoming parameters to tools, such as debuggers, simply by preserving those values on the stack.
-qlist
Instructs the compiler to emit an object listing. The object listing includes hex and pseudo-assembly representations of the generated instructions, traceback tables, and text constants.
-qreport
Instructs the compiler to produce a report of the loop transformations it performed and how the program was parallelized. The option is enabled when -qhot or -qsmp is specified.
-qinitauto
Instructs the compiler to emit code that initializes all automatic variables to a given value.
-qipa=list
Instructs the compiler to emit an object listing that provides information for IPA optimization.

You can also use the SNAPSHOT directive to ensure to that certain variables are visible to the debugger at points in your application.