This topic describes the command-line options that you can use to debug your compilation and to display and check compilation errors.
The options that enable you to get debug information while optimizing are as follows:
-O0 |
Disables optimizations. Enables -fp option. |
-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. |
-fp |
Disables the use of the ebp register in optimizations. Directs to use the ebp-based stack frame for all functions. |
Use the -g option to direct the compiler to generate code to provide symbolic debugging information and line numbers in the object code that will be used by your source-level debugger. For example:
ifort -g prog1.f
Turns off -O2 and makes -O0 the default unless -O2 (or -O1 or -O3) is explicitly specified in the command line together with -g.
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.
-fp Summary
Default |
OFF |
-O1 , -O2, or -O3 |
Disable -fp |
-O0 |
Enables -fp |
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 the 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, which produces symbolic debug information in the object file.
Note that if you specify an -O1, -O2, or -O3 option with the -g option, some of the debugging information returned may be inaccurate as a side-effect of optimization.
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 optimization enabled, then you can specify the -O1, -O2, or -O3 option on the command line along with -g.
Note
The -g option slows
down the program when no optimization level (-On) is specified. In this case -g turns on -O0, which is what
slows the program down. 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. |
The assembly listing file is generated without debugging information, but if you produce an object file, it will contain debugging information. If you link the object file and then use the GDB debugger on it, you will get full symbolic representation.