This topic describes the command-line options that you can use to help debug your compilation.
The options that control debugging and optimizing are as follows:
-O0 (Linux and Mac OS) or /O:0 (Windows*) |
Disables optimizations so you can debug your program before any optimization is attempted. On Linux and Mac OS, -fno-omit-frame-pointer is set if option -O0 (or -g) is specified. For more information, see the following topic:
|
-O1 or /O1 |
Specifies the code optimization level for applications. For more information, see the following topic:
|
-g or /debug:full |
Generates symbolic debugging information and line numbers in the object code for use by the source-level debuggers. Turns off -O2 (Linux and Mac OS) or /O2 (Windows) and makes -O0 (Linux and Mac OS) or /Od (Windows) the default unless -O2, -O1 or -O3 (Linux and Mac OS) or /O2, /O1 or /O3 (Windows and Mac OS) is explicitly specified in the command line, together with -g or /debug:full. For more information, see the following topic:
|
-debug extended (Linux and Mac OS only) |
Specifies settings that enhance debugging. To use this option, you must also specify the -g option. For more information, see the following topic:
|
-fp or /Oy- |
Disables the ebp register in optimizations and sets the ebp register to be used as the frame pointer. For more information, see the following topic:
|
-traceback (Linux and Mac OS) or /traceback (Windows) |
Causes the compiler to generate extra information in the object file, which allows a symbolic stack traceback. For more information, see the following topic:
|
The -O0 (Linux and Mac OS) or /O:0 (Windows) option turns off all optimizations so you can debug your program before any optimization is attempted. To get the debug information, use the -g (Linux and Mac OS) or /debug:full (Windows) option.
The compiler lets you generate code to support symbolic debugging while one of the O1, O2, or O3 optimization options is specified on the command line along with -g (Linux and Mac OS) or /debug:full (Windows*), which 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 and Mac OS systems, 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 Mac OS) or /O:0 (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 -g or /debug:full and, on Linux and Mac OS systems, also -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 /O:0, which causes the slowdown. However, if, for example, both -O2 (Linux and Mac OS) or /O2 (Windows) and -g (Linux and Mac OS) or /debug:full (Windows) 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 and Mac OS) or /debug:full (Windows*) |
Debugging information produced, -O0 or /O:0 enabled (meaning optimizations are disabled). For Linux and Mac OS systems, -fp is also enabled for compilations targeted for IA-32 architecture. |
-g -O1 (Linux and Mac OS) or /debug:full /O1 (Windows*) |
Debugging information produced, O1 optimizations enabled. |
-g -O2 (Linux and Mac OS) or |
Debugging information produced, O2 optimizations enabled. |
-g -O2 (Linux and Mac OS) or |
Debugging information produced, O2 optimizations enabled; for Windows systems using IA-32 architecture, /Oy disabled. |
-g -O3 -fp (Linux and Mac OS) or /debug:full /O3 (Windows) |
Debugging information produced, O3 optimizations enabled; for Linux systems, -fp enabled for compilations targeted for IA-32 architecture. |
On Linux* systems, use the -debug extended option with any of the last three combinations, to improve debugging. For optimized code, use the following options: -On, -g, -debug extended, where n is 1, 2, or 3. For non-optimized code, use the -g option.
Debugging of optimized code is not fully supported on Intel platforms.