Visible to Intel only — GUID: GUID-1DB4628E-2171-47B1-83CB-1D26FF71C5A0
Visible to Intel only — GUID: GUID-1DB4628E-2171-47B1-83CB-1D26FF71C5A0
Debugging and Optimizations
This topic describes the relationship between various command-line options that control debugging and optimizing.
Whenever you enable debugging with the -g option (Linux* and macOS) or /debug:full option (Windows*) , you disable optimizations. You can override this behavior by explicitly specifying compiler options for optimizations on the command line.
The following summarizes commonly used options for debugging and for optimization.
Option |
Description |
---|---|
Linux and macOS -O0 Windows /Od |
Disables optimizations so you can debug your program before any optimization is attempted. This is the default behavior when debugging.
NOTE:
On Linux* and macOS, -fno-omit-frame-pointer is set if either option -O0 or -g is specified. For more information, see the following topics:
|
Linux and macOS O1, O2, or O3 Windows O |
Specifies the code optimization level for applications. If you use any of these options, it is recommended that you use -debug extended when debugging. For more information, see the following topics:
|
Linux and macOS -g Windows /debug:full |
Generates symbolic debugging information and line numbers in the object code for use by the source-level debuggers. Turns off O2 and makes -O0 (Linux* and macOS) or /Od (Windows*) the default. The exception to this is if options O1, O2, or O3 are explicitly specified in the command line. For more information, see the following topics:
|
Linux and macOS -debug extended |
Specifies settings that enhance debugging. For more information, see the following topic:
|
Linux and macOS -fp Windows /Oy (IA-32 architecture only) |
Disables the ebp register in optimizations and sets the ebp register to be used as the frame pointer. For more information, see the following compiler option topics:
|
traceback |
Causes the compiler to generate extra information in the object file, which allows a symbolic stack traceback. For more information, see the following topic:
|
Combine Optimization and Debugging
The compiler lets you generate code to support symbolic debugging when O1, O2, or O3 optimization options are specified on the command line along with -g (Linux* and macOS) or /debug:full (Windows*); this produces symbolic debug information in the object file.
Note that if you specify an O1, O2, or O3 option with the -g (Linux* and macOS) or /debug:full (Windows*) option, some of the debugging information returned may be inaccurate as a side-effect of optimization.
To counter this on Linux* and macOS, you should also specify the -debug extended option.
It is best to make your optimization and/or debugging choices explicit:
If you need to debug your program excluding any optimization effect, use the -O0 (Linux* and macOS) or /Od (Windows*) option, which turns off all the optimizations.
If you need to debug your program with optimizations enabled, then you can specify the O1, O2, or O3 option on the command line along with debug extended.
When no optimization level is specified, the -g or /debug:full option slows program execution; this is because this option turns on -O0 or /Od, which causes the slowdown. However, if both O2 and -g (Linux* and macOS) or /debug:full (Windows*) are specified, for example, the code should not experience much of a slowdown.
Refer to the following table for the summary of the effects of using the -g or /debug:full option with the optimization options.
Option |
Effect |
---|---|
Linux and macOS -g Windows /debug:full |
Debugging information produced, -O0 (Linux* and macOS) or /Od (Windows*) enabled (meaning optimizations are disabled). For Linux* and macOS, -fp is also enabled for compilations targeted for IA-32 architecture. |
Linux and macOS -g-O1 Windows /debug:full /O1 |
Debugging information produced, O1 optimizations enabled. |
Linux and macOS -g-O2 ,Windows /debug:full /O2 |
Debugging information produced, O2 optimizations enabled. |
Linux and macOS -g-O2 Windows /debug:full /O2 /Oy- |
Debugging information produced, O2 optimizations enabled. For Windows* using IA-32 architecture, /Oy disabled. |
Linux and macOS -g -O3 -fp Windows /debug:full /O3 |
Debugging information produced, O3 optimizations enabled. For Linux*, -fp enabled for compilations targeted for IA-32 architecture. |
Even the use of option debug extended with optimized programs may not allow you to examine all variables or to set breaks at all lines, due to code movement or removal during the optimization process.