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 the -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 -O1, -O2, or -O3 is explicitly specified in the command line together with -g.|
|Disable using the EBP register as general purpose register.|
|Option||Effect on -fp|
|-O1, -O2, or -O3||Disables -fp.|
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 -O1, -O2, or -O3 is specified on the command line along with -g, 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 as a side-effect of optimization.
It is best to make your optimization and/or debugging choices explicit:
The -g option slows down the program when -O1, -O2, or -O3 is not specified. In this case -g turns on -O0 which is what slows the program down. If both -O2 and -g are specified, the code should run nearly the same speed as if -g were not specified.
Refer to the following table 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 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.