Debugging in the presence of optimization
Debug and compile your program with your desired optimization options. Test the optimized program before placing it 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 list presents options that provide specialized information, which can be helpful during the debugging of optimized code:
- 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.
- Instructs the compiler to produce a report of the loop transformations it performed, how the program was parallelized, what inlining was done, and some other transformations. To generate a listing file, you must specify the -qreport option with at least one optimization option such as -qhot, -qsmp, -qinline, or -qsimd.
- Reports potential synchronization issues in parallel code. For details, see -qinfo.
- Detects automatic variables that are used before they are set, and flags them with informational messages at compile time. For details, see -qinfo.
- Instructs the compiler to emit an object listing that provides information for IPA optimization.
- Generates code that performs certain types of runtime checking.
- 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.
- 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.
- Instructs the compiler to emit code that initializes all automatic variables to a given value.
- Generates additional symbolic information to allow the linker to do cross-file type checking of external variables and functions. This option requires the linker -btypchk option to be active.
- Generates debugging information to be used by a symbolic debugger. You can use different -g levels to debug optimized code by viewing or possibly modifying accessible variables at selected source locations in the debugger. Higher -g levels provide a more complete debug support, while lower levels provide higher runtime performance. For details, see -g.
In addition, you can also use the snapshot pragma to ensure that certain variables are visible to the debugger at points in your application. For details, see #pragma ibm snapshot.


