PREV UP NEXT Using and Porting GNU CC

3.7: Options for Debugging Your Program or GNU CC

GNU CC has various special options that are used for debugging either your program or GCC:

-g
Produce debugging information in the operating system's native format (stabs, COFF, XCOFF, or DWARF). GDB can work with this debugging information.

On most systems that use stabs format, `-g' enables use of extra debugging information that only GDB can use; this extra information makes debugging work better in GDB but will probably make other debuggers crash or refuse to read the program. If you want to control for certain whether to generate the extra information, use `-gstabs+', `-gstabs', `-gxcoff+', `-gxcoff', `-gdwarf+', or `-gdwarf' (see below).

Unlike most other C compilers, GNU CC allows you to use `-g' with `-O'. The shortcuts taken by optimized code may occasionally produce surprising results: some variables you declared may not exist at all; flow of control may briefly move where you did not expect it; some statements may not be executed because they compute constant results or their values were already at hand; some statements may execute in different places because they were moved out of loops.

Nevertheless it proves possible to debug optimized output. This makes it reasonable to use the optimizer for programs that might have bugs.

The following options are useful when GNU CC is generated with the capability for more than one debugging format.

-ggdb
Produce debugging information in the native format (if that is supported), including GDB extensions if at all possible.
-gstabs
Produce debugging information in stabs format (if that is supported), without GDB extensions. This is the format used by DBX on most BSD systems. On MIPS and Alpha systems this option produces embedded stabs debugging output which is not understood by DBX.
-gstabs+
Produce debugging information in stabs format (if that is supported), using GNU extensions understood only by the GNU debugger (GDB). The use of these extensions is likely to make other debuggers crash or refuse to read the program.
-gcoff
Produce debugging information in COFF format (if that is supported). This is the format used by SDB on most System V systems prior to System V Release 4.
-gxcoff
Produce debugging information in XCOFF format (if that is supported). This is the format used by the DBX debugger on IBM RS/6000 systems.
-gxcoff+
Produce debugging information in XCOFF format (if that is supported), using GNU extensions understood only by the GNU debugger (GDB). The use of these extensions is likely to make other debuggers crash or refuse to read the program.
-gdwarf
Produce debugging information in DWARF format (if that is supported). This is the format used by SDB on most System V Release 4 systems.
-gdwarf+
Produce debugging information in DWARF format (if that is supported), using GNU extensions understood only by the GNU debugger (GDB). The use of these extensions is likely to make other debuggers crash or refuse to read the program.
-glevel
-ggdblevel
-gstabslevel
-gcofflevel
-gxcofflevel
-gdwarflevel
Request debugging information and also use level to specify how much information. The default level is 2.

Level 1 produces minimal information, enough for making backtraces in parts of the program that you don't plan to debug. This includes descriptions of functions and external variables, but no information about local variables and no line numbers.

Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use `-g3'.

-p
Generate extra code to write profile information suitable for the analysis program prof. You must use this option when compiling the source files you want data about, and you must also use it when linking.
-pg
Generate extra code to write profile information suitable for the analysis program gprof. You must use this option when compiling the source files you want data about, and you must also use it when linking.
-a
Generate extra code to write profile information for basic blocks, which will record the number of times each basic block is executed, the basic block start address, and the function name containing the basic block. If `-g' is used, the line number and filename of the start of the basic block will also be recorded. If not overridden by the machine description, the default action is to append to the text file `bb.out'.

This data could be analyzed by a program like tcov. Note, however, that the format of the data is not what tcov expects. Eventually GNU gprof should be extended to process this data.

-dletters
Says to make debugging dumps during compilation at times specified by letters. This is used for debugging the compiler. The file names for most of the dumps are made by appending a word to the source file name (e.g. `foo.c.rtl' or `foo.c.jump'). Here are the possible letters for use in letters, and their meanings:
`M'
Dump all macro definitions, at the end of preprocessing, and write no output.
`N'
Dump all macro names, at the end of preprocessing.
`D'
Dump all macro definitions, at the end of preprocessing, in addition to normal output.
`y'
Dump debugging information during parsing, to standard error.
`r'
Dump after RTL generation, to `file.rtl'.
`x'
Just generate RTL for a function instead of compiling it. Usually used with `r'.
`j'
Dump after first jump optimization, to `file.jump'.
`s'
Dump after CSE (including the jump optimization that sometimes follows CSE), to `file.cse'.
`L'
Dump after loop optimization, to `file.loop'.
`t'
Dump after the second CSE pass (including the jump optimization that sometimes follows CSE), to `file.cse2'.
`f'
Dump after flow analysis, to `file.flow'.
`c'
Dump after instruction combination, to the file `file.combine'.
`S'
Dump after the first instruction scheduling pass, to `file.sched'.
`l'
Dump after local register allocation, to `file.lreg'.
`g'
Dump after global register allocation, to `file.greg'.
`R'
Dump after the second instruction scheduling pass, to `file.sched2'.
`J'
Dump after last jump optimization, to `file.jump2'.
`d'
Dump after delayed branch scheduling, to `file.dbr'.
`k'
Dump after conversion from registers to stack, to `file.stack'.
`a'
Produce all the dumps listed above.
`m'
Print statistics on memory usage, at the end of the run, to standard error.
`p'
Annotate the assembler output with a comment indicating which pattern and alternative was used.
-fpretend-float
When running a cross-compiler, pretend that the target machine uses the same floating point format as the host machine. This causes incorrect output of the actual floating constants, but the actual instruction sequence will probably be the same as GNU CC would make when running on the target machine.
-save-temps
Store the usual ``temporary'' intermediate files permanently; place them in the current directory and name them based on the source file. Thus, compiling `foo.c' with `-c -save-temps' would produce files `foo.i' and `foo.s', as well as `foo.o'.
-print-file-name=library
Print the full absolute name of the library file library that would be used when linking---and don't do anything else. With this option, GNU CC does not compile or link anything; it just prints the file name.
-print-prog-name=program
Like `-print-file-name', but searches for a program such as `cpp'.
-print-libgcc-file-name
Same as `-print-file-name=libgcc.a'.

This is useful when you use `-nostdlib' but you do want to link with `libgcc.a'. You can do

gcc -nostdlib files... `gcc -print-libgcc-file-name`