This topic describes the relationship between various command-line options that control debugging and optimizing.
Whenever you enable debugging with -g (Linux* OS and Mac OS* X) or /debug:full (Windows* OS), 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.
The compiler lets you generate code to support symbolic debugging when one of the O1, O2, or O3 optimization options is specified on the command line along with -g (Linux OS and Mac OS X) or /debug:full (Windows OS); this produces symbolic debug information in the object file.
Note that if you specify an O1, O2, or O3 option with the -g or /debug:full option, some of the debugging information returned may be inaccurate as a side-effect of optimization. To counter this on Linux OS and Mac OS X, 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 OS and Mac OS X) or /Od (Windows OS) 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, for example, both -O2 (Linux OS and Mac OS X) or /O2 (Windows OS) and -g (Linux OS and Mac OS X) or /debug:full (Windows OS) are specified, the code should not experience much of a slowdown.
Refer to the table below for the summary of the effects of using the -g or /debug:full option with the optimization options.
These options |
Produce these results |
---|---|
-g (Linux OS and Mac OS X) or /debug:full (Windows OS) |
Debugging information produced, -O0 or /Od enabled (meaning optimizations are disabled). For Linux OS and Mac OS X, -fp is also enabled for compilations targeted for IA-32 architecture. |
-g -O1 (Linux OS and Mac OS X) or /debug:full /O1 (Windows*) |
Debugging information produced, O1 optimizations enabled. |
-g -O2 (Linux OS and Mac OS X) or /debug:full /O2 (Windows OS) |
Debugging information produced, O2 optimizations enabled. |
-g -O2 (Linux OS and Mac OS X) or /debug:full /O2 /Oy- (Windows OS) |
Debugging information produced, O2 optimizations enabled; for Windows OS using IA-32 architecture, /Oy disabled. |
-g -O3 -fp (Linux OS and Mac OS X) or /debug:full /O3 (Windows OS) |
Debugging information produced, O3 optimizations enabled; for Linux OS, -fp enabled for compilations targeted for IA-32 architecture. |
Even the use of 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
Copyright © 1996-2010, Intel Corporation. All rights reserved.