This topic describes the compiler command-line options that you can use to debug your compilation and to display and check compilation errors.
The options that control debugging and optimizing are as follows:
-O0 |
Disables optimizations so you can debug your program before any optimization is attempted . Enables -fp option. For more information, see the following topic:
|
-O1, -O2, -O3 |
Specifies the code optimization level for applications. For more information, see the following topic:
|
-g |
Generates symbolic debugging information and line numbers in the object code for use by the source-level debuggers. Turns off -O2 and makes -O0 the default unless -O2 (or -O1 or -O3) is explicitly specified in the command line together with -g. For more information, see the following topic:
|
-debug extended |
Specifies settings that enhance debugging. To use this option, you must also specify the -g option. For more information, see the following topic:
|
-fp |
Disables the use of the ebp register in optimizations. Directs to use the ebp-based stack frame for all functions. For more information, see the following topic:
|
-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:
|
Note
Debugging of optimized code is not fully supported on Intel platforms.
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.
Most debuggers use the ebp register as a stack frame pointer to produce a stack backtrace. The -fp option disables the use of the ebp register in optimizations and directs the compiler to generate code that maintains and uses ebp as a stack frame pointer for all functions so that a debugger can still produce a stack backtrace without turning off -O1, -O2, or -O3 optimizations.
Note that using this option reduces the number of available general-purpose registers by one, and results in slightly less efficient code.
The -traceback option also forces the compiler to use ebp as the stack frame pointer. In addition, the -traceback option causes the compiler to generate extra information into the object file, which allows a symbolic stack traceback to be produced if a run-time failure occurs.
The -O0 option turns off all optimizations so you can debug your program before any optimization is attempted. To get debug information, use the -g 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 and -debug extended, which produces symbolic debug information in the object file.
Note that if you specify the -O1, -O2, or -O3 option with the -g option, some of the debugging information returned may be inaccurate (a side-effect of optimization) unless the -debug extended option is also used.
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 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 and -debug extended.
Note
When no optimization level (-On)
is specified, the -g option slows program execution;
this is because -g turns on -O0,
which causes the slowdown. However, if, for example, both -O2
and -g are specified, the code should run very
nearly at the same speed as if -g were not specified.
Refer to the table below for the summary of the effects of using the -g option with the optimization options.
These options |
Produce these results |
-g |
Debugging information produced, -O0 enabled (optimizations disabled), -fp enabled for IA-32-targeted compilations |
-g -O1 |
Debugging information produced, -O1 optimizations enabled. |
-g -O2 |
Debugging information produced, -O2 optimizations enabled. |
-g -O3 -fp |
Debugging information produced, -O3 optimizations enabled, -fp enabled for IA-32-targeted compilations. |
Use the -debug extended option with any of the last three combinations, to improve debugging.