|[ < ]||[ > ]||[ << ]||[ Up ]||[ >> ]||[Top]||[Contents]||[Index]||[ ? ]|
3.9 Options for Debugging Your Program or GCC
GCC has various special options that are used for debugging either your program or GCC:
- @gcctabopt -g
Produce debugging information in the operating system's native format (stabs, COFF, XCOFF, or DWARF 2). 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’, or ‘-gvms’ (see below).
GCC 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 GCC is generated with the capability for more than one debugging format.
- @gcctabopt -ggdb
Produce debugging information for use by GDB. This means to use the most expressive format available (DWARF 2, stabs, or the native format if neither of those are supported), including GDB extensions if at all possible.
- @gcctabopt -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, Alpha and System V Release 4 systems this option produces stabs debugging output which is not understood by DBX or SDB. On System V Release 4 systems this option requires the GNU assembler.
- @gcctabopt -feliminate-unused-debug-symbols
Produce debugging information in stabs format (if that is supported), for only symbols that are actually used.
- @gcctabopt -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.
- @gcctabopt -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.
- @gcctabopt -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.
- @gcctabopt -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, and may cause assemblers other than the GNU assembler (GAS) to fail with an error.
- @gcctabopt -gdwarf-2
Produce debugging information in DWARF version 2 format (if that is supported). This is the format used by DBX on IRIX 6. With this option, GCC uses features of DWARF version 3 when they are useful; version 3 is upward compatible with version 2, but may still cause problems for older debuggers.
- @gcctabopt -gvms
Produce debugging information in VMS debug format (if that is supported). This is the format used by DEBUG on VMS systems.
- @gcctabopt -glevel
- @gcctabopt -ggdblevel
- @gcctabopt -gstabslevel
- @gcctabopt -gcofflevel
- @gcctabopt -gxcofflevel
- @gcctabopt -gvmslevel
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’.
‘-gdwarf-2’ does not accept a concatenated debug level, because GCC used to support an option ‘-gdwarf’ that meant to generate debug information in version 1 of the DWARF format (which is very different from version 2), and it would have been too confusing. That debug format is long obsolete, but the option cannot be changed now. Instead use an additional ‘-glevel’ option to change the debug level for DWARF2.
- @gcctabopt -feliminate-dwarf2-dups
Compress DWARF2 debugging information by eliminating duplicated information about each symbol. This option only makes sense when generating DWARF2 debugging information with ‘-gdwarf-2’.
- @gcctabopt -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.
- @gcctabopt -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.
- @gcctabopt -Q
Makes the compiler print out each function name as it is compiled, and print some statistics about each pass when it finishes.
- @gcctabopt -ftime-report
Makes the compiler print some statistics about the time consumed by each pass when it finishes.
- @gcctabopt -fmem-report
Makes the compiler print some statistics about permanent memory allocation when it finishes.
- @gcctabopt -fprofile-arcs
Add code so that program flow arcs are instrumented. During execution the program records how many times each branch and call is executed and how many times it is taken or returns. When the compiled program exits it saves this data to a file called ‘auxname.gcda’ for each source file. The data may be used for profile-directed optimizations (‘-fbranch-probabilities’), or for test coverage analysis (‘-ftest-coverage’). Each object file's auxname is generated from the name of the output file, if explicitly specified and it is not the final executable, otherwise it is the basename of the source file. In both cases any suffix is removed (e.g. ‘foo.gcda’ for input file ‘dir/foo.c’, or ‘dir/foo.gcda’ for output file specified as ‘-o dir/foo.o’).
- Compile the source files with ‘-fprofile-arcs’ plus optimization and code generation options. For test coverage analysis, use the additional ‘-ftest-coverage’ option. You do not need to profile every source file in a program.
- Link your object files with ‘-lgcov’ or ‘-fprofile-arcs’ (the latter implies the former).
Run the program on a representative workload to generate the arc profile
information. This may be repeated any number of times. You can run
concurrent instances of your program, and provided that the file system
supports locking, the data files will be correctly updated. Also
forkcalls are detected and correctly handled (double counting will not happen).
- For profile-directed optimizations, compile the source files again with the same optimization and code generation options plus ‘-fbranch-probabilities’ (see section Options that Control Optimization).
For test coverage analysis, use
gcovto produce human readable information from the ‘.gcno’ and ‘.gcda’ files. Refer to the
gcovdocumentation for further information.
With ‘-fprofile-arcs’, for each function of your program GCC creates a program flow graph, then finds a spanning tree for the graph. Only arcs that are not on the spanning tree have to be instrumented: the compiler adds code to count the number of times that these arcs are executed. When an arc is the only exit or only entrance to a block, the instrumentation code can be added to the block; otherwise, a new basic block must be created to hold the instrumentation code.
- @gcctabopt -ftree-based-profiling
This option is used in addition to ‘-fprofile-arcs’ or ‘-fbranch-probabilities’ to control whether those optimizations are performed on a tree-based or rtl-based internal representation. If you use this option when compiling with ‘-fprofile-arcs’, you must also use it when compiling later with ‘-fbranch-probabilities’. Currently the tree-based optimization is in an early stage of development, and this option is recommended only for those people working on improving it.
- @gcctabopt -ftest-coverage
Produce a notes file that the
gcovcode-coverage utility (see section
gcov—a Test Coverage Program) can use to show program coverage. Each source file's note file is called ‘auxname.gcno’. Refer to the ‘-fprofile-arcs’ option above for a description of auxname and instructions on how to generate test coverage data. Coverage data will match the source files more closely, if you do not optimize.
- @gcctabopt -dletters
- @gcctabopt -fdump-rtl-pass
Says to make debugging dumps during compilation at times specified by letters. This is used for debugging the RTL-based passes of the compiler. The file names for most of the dumps are made by appending a pass number and a word to the dumpname. dumpname is generated from the name of the output file, if explicitly specified and it is not an executable, otherwise it is the basename of the source file.
Most debug dumps can be enabled either passing a letter to the ‘-d’ option, or with a long ‘-fdump-rtl’ switch; here are the possible letters for use in letters and pass, and their meanings:
- @gcctabopt -dA
Annotate the assembler output with miscellaneous debugging information.
- @gcctabopt -db
- @gcctabopt -fdump-rtl-bp
Dump after computing branch probabilities, to ‘file.09.bp’.
- @gcctabopt -dB
- @gcctabopt -fdump-rtl-bbro
Dump after block reordering, to ‘file.30.bbro’.
- @gcctabopt -dc
- @gcctabopt -fdump-rtl-combine
Dump after instruction combination, to the file ‘file.17.combine’.
- @gcctabopt -dC
- @gcctabopt -fdump-rtl-ce1
- @gcctabopt -fdump-rtl-ce2
‘-dC’ and ‘-fdump-rtl-ce1’ enable dumping after the first if conversion, to the file ‘file.11.ce1’. ‘-dC’ and ‘-fdump-rtl-ce2’ enable dumping after the second if conversion, to the file ‘file.18.ce2’.
- @gcctabopt -dd
- @gcctabopt -fdump-rtl-btl
- @gcctabopt -fdump-rtl-dbr
‘-dd’ and ‘-fdump-rtl-btl’ enable dumping after branch target load optimization, to ‘file.31.btl’. ‘-dd’ and ‘-fdump-rtl-dbr’ enable dumping after delayed branch scheduling, to ‘file.36.dbr’.
- @gcctabopt -dD
Dump all macro definitions, at the end of preprocessing, in addition to normal output.
- @gcctabopt -dE
- @gcctabopt -fdump-rtl-ce3
Dump after the third if conversion, to ‘file.28.ce3’.
- @gcctabopt -df
- @gcctabopt -fdump-rtl-cfg
- @gcctabopt -fdump-rtl-life
‘-df’ and ‘-fdump-rtl-cfg’ enable dumping after control and data flow analysis, to ‘file.08.cfg’. ‘-df’ and ‘-fdump-rtl-cfg’ enable dumping dump after life analysis, to ‘file.16.life’.
- @gcctabopt -dg
- @gcctabopt -fdump-rtl-greg
Dump after global register allocation, to ‘file.23.greg’.
- @gcctabopt -dG
- @gcctabopt -fdump-rtl-gcse
- @gcctabopt -fdump-rtl-bypass
‘-dG’ and ‘-fdump-rtl-gcse’ enable dumping after GCSE, to ‘file.05.gcse’. ‘-dG’ and ‘-fdump-rtl-bypass’ enable dumping after jump bypassing and control flow optimizations, to ‘file.07.bypass’.
- @gcctabopt -dh
- @gcctabopt -fdump-rtl-eh
Dump after finalization of EH handling code, to ‘file.02.eh’.
- @gcctabopt -di
- @gcctabopt -fdump-rtl-sibling
Dump after sibling call optimizations, to ‘file.01.sibling’.
- @gcctabopt -dj
- @gcctabopt -fdump-rtl-jump
Dump after the first jump optimization, to ‘file.03.jump’.
- @gcctabopt -dk
- @gcctabopt -fdump-rtl-stack
Dump after conversion from registers to stack, to ‘file.33.stack’.
- @gcctabopt -dl
- @gcctabopt -fdump-rtl-lreg
Dump after local register allocation, to ‘file.22.lreg’.
- @gcctabopt -dL
- @gcctabopt -fdump-rtl-loop
- @gcctabopt -fdump-rtl-loop2
‘-dL’ and ‘-fdump-rtl-loop’ enable dumping after the first loop optimization pass, to ‘file.06.loop’. ‘-dL’ and ‘-fdump-rtl-loop2’ enable dumping after the second pass, to ‘file.13.loop2’.
- @gcctabopt -dm
- @gcctabopt -fdump-rtl-sms
Dump after modulo scheduling, to ‘file.20.sms’.
- @gcctabopt -dM
- @gcctabopt -fdump-rtl-mach
Dump after performing the machine dependent reorganization pass, to ‘file.35.mach’.
- @gcctabopt -dn
- @gcctabopt -fdump-rtl-rnreg
Dump after register renumbering, to ‘file.29.rnreg’.
- @gcctabopt -dN
- @gcctabopt -fdump-rtl-regmove
Dump after the register move pass, to ‘file.19.regmove’.
- @gcctabopt -do
- @gcctabopt -fdump-rtl-postreload
Dump after post-reload optimizations, to ‘file.24.postreload’.
- @gcctabopt -dr
- @gcctabopt -fdump-rtl-expand
Dump after RTL generation, to ‘file.00.expand’.
- @gcctabopt -dR
- @gcctabopt -fdump-rtl-sched2
Dump after the second scheduling pass, to ‘file.32.sched2’.
- @gcctabopt -ds
- @gcctabopt -fdump-rtl-cse
Dump after CSE (including the jump optimization that sometimes follows CSE), to ‘file.04.cse’.
- @gcctabopt -dS
- @gcctabopt -fdump-rtl-sched
Dump after the first scheduling pass, to ‘file.21.sched’.
- @gcctabopt -dt
- @gcctabopt -fdump-rtl-cse2
Dump after the second CSE pass (including the jump optimization that sometimes follows CSE), to ‘file.15.cse2’.
- @gcctabopt -dT
- @gcctabopt -fdump-rtl-tracer
Dump after running tracer, to ‘file.12.tracer’.
- @gcctabopt -dV
- @gcctabopt -fdump-rtl-vpt
- @gcctabopt -fdump-rtl-vartrack
‘-dV’ and ‘-fdump-rtl-vpt’ enable dumping after the value profile transformations, to ‘file.10.vpt’. ‘-dV’ and ‘-fdump-rtl-vartrack’ enable dumping after variable tracking, to ‘file.34.vartrack’.
- @gcctabopt -dw
- @gcctabopt -fdump-rtl-flow2
Dump after the second flow pass, to ‘file.26.flow2’.
- @gcctabopt -dz
- @gcctabopt -fdump-rtl-peephole2
Dump after the peephole pass, to ‘file.27.peephole2’.
- @gcctabopt -dZ
- @gcctabopt -fdump-rtl-web
Dump after live range splitting, to ‘file.14.web’.
- @gcctabopt -da
- @gcctabopt -fdump-rtl-all
Produce all the dumps listed above.
- @gcctabopt -dH
Produce a core dump whenever an error occurs.
- @gcctabopt -dm
Print statistics on memory usage, at the end of the run, to standard error.
- @gcctabopt -dp
Annotate the assembler output with a comment indicating which pattern and alternative was used. The length of each instruction is also printed.
- @gcctabopt -dP
Dump the RTL in the assembler output as a comment before each instruction. Also turns on ‘-dp’ annotation.
- @gcctabopt -dv
For each of the other indicated dump files (either with ‘-d’ or ‘-fdump-rtl-pass’), dump a representation of the control flow graph suitable for viewing with VCG to ‘file.pass.vcg’.
- @gcctabopt -dx
Just generate RTL for a function instead of compiling it. Usually used with ‘r’ (‘-fdump-rtl-expand’).
- @gcctabopt -dy
Dump debugging information during parsing, to standard error.
- @gcctabopt -fdump-unnumbered
When doing debugging dumps (see ‘-d’ option above), suppress instruction numbers and line number note output. This makes it more feasible to use diff on debugging dumps for compiler invocations with different options, in particular with and without ‘-g’.
- @gcctabopt -fdump-translation-unit (C and C++ only)
- @gcctabopt -fdump-translation-unit-options (C and C++ only)
Dump a representation of the tree structure for the entire translation unit to a file. The file name is made by appending ‘.tu’ to the source file name. If the ‘-options’ form is used, options controls the details of the dump as described for the ‘-fdump-tree’ options.
- @gcctabopt -fdump-class-hierarchy (C++ only)
- @gcctabopt -fdump-class-hierarchy-options (C++ only)
Dump a representation of each class's hierarchy and virtual function table layout to a file. The file name is made by appending ‘.class’ to the source file name. If the ‘-options’ form is used, options controls the details of the dump as described for the ‘-fdump-tree’ options.
- @gcctabopt -fdump-ipa-switch
Control the dumping at various stages of inter-procedural analysis language tree to a file. The file name is generated by appending a switch specific suffix to the source file name. The following dumps are possible:
Enables all inter-procedural analysis dumps; currently the only produced dump is the ‘cgraph’ dump.
Dumps information about call-graph optimization, unused function removal, and inlining decisions.
- @gcctabopt -fdump-tree-switch (C and C++ only)
- @gcctabopt -fdump-tree-switch-options (C and C++ only)
Control the dumping at various stages of processing the intermediate language tree to a file. The file name is generated by appending a switch specific suffix to the source file name. If the ‘-options’ form is used, options is a list of ‘-’ separated options that control the details of the dump. Not all options are applicable to all dumps, those which are not meaningful will be ignored. The following options are available
Print the address of each node. Usually this is not meaningful as it changes according to the environment and source file. Its primary use is for tying up a dump file with a debug environment.
Inhibit dumping of members of a scope or body of a function merely because that scope has been reached. Only dump such items when they are directly reachable by some other path. When dumping pretty-printed trees, this option inhibits dumping the bodies of control structures.
Print a raw representation of the tree. By default, trees are pretty-printed into a C-like representation.
Enable more detailed dumps (not honored by every dump option).
Enable dumping various statistics about the pass (not honored by every dump option).
Enable showing basic block boundaries (disabled in raw dumps).
Enable showing virtual operands for every statement.
Enable showing line numbers for statements.
Enable showing the unique ID (
DECL_UID) for each variable.
Turn on all options, except ‘raw’, ‘slim’ and ‘lineno’.
The following tree dumps are possible:
Dump before any tree based optimization, to ‘file.original’.
Dump after all tree based optimization, to ‘file.optimized’.
Dump after function inlining, to ‘file.inlined’.
Dump each function before and after the gimplification pass to a file. The file name is made by appending ‘.gimple’ to the source file name.
Dump the control flow graph of each function to a file. The file name is made by appending ‘.cfg’ to the source file name.
Dump the control flow graph of each function to a file in VCG format. The file name is made by appending ‘.vcg’ to the source file name. Note that if the file contains more than one function, the generated file cannot be used directly by VCG. You will need to cut and paste each function's graph into its own separate file first.
Dump each function after copying loop headers. The file name is made by appending ‘.ch’ to the source file name.
Dump SSA related information to a file. The file name is made by appending ‘.ssa’ to the source file name.
Dump aliasing information for each function. The file name is made by appending ‘.alias’ to the source file name.
Dump each function after CCP. The file name is made by appending ‘.ccp’ to the source file name.
Dump trees after partial redundancy elimination. The file name is made by appending ‘.pre’ to the source file name.
Dump trees after full redundancy elimination. The file name is made by appending ‘.fre’ to the source file name.
Dump each function after dead code elimination. The file name is made by appending ‘.dce’ to the source file name.
Dump each function after adding mudflap instrumentation. The file name is made by appending ‘.mudflap’ to the source file name.
Dump each function after performing scalar replacement of aggregates. The file name is made by appending ‘.sra’ to the source file name.
Dump each function after applying dominator tree optimizations. The file name is made by appending ‘.dom’ to the source file name.
Dump each function after applying dead store elimination. The file name is made by appending ‘.dse’ to the source file name.
Dump each function after optimizing PHI nodes into straightline code. The file name is made by appending ‘.phiopt’ to the source file name.
Dump each function after forward propagating single use variables. The file name is made by appending ‘.forwprop’ to the source file name.
Dump each function after applying the copy rename optimization. The file name is made by appending ‘.copyrename’ to the source file name.
Dump each function after applying the named return value optimization on generic trees. The file name is made by appending ‘.nrv’ to the source file name.
Dump each function after applying vectorization of loops. The file name is made by appending ‘.vect’ to the source file name.
Enable all the available tree dumps with the flags provided in this option.
- @gcctabopt -ftree-vectorizer-verbose=n
This option controls the amount of debugging output the vectorizer prints. This information is written to standard error, unless ‘-fdump-tree-all’ or ‘-fdump-tree-vect’ is specified, in which case it is output to the usual dump listing file, ‘.vect’.
- @gcctabopt -frandom-seed=string
This option provides a seed that GCC uses when it would otherwise use random numbers. It is used to generate certain symbol names that have to be different in every compiled file. It is also used to place unique stamps in coverage data files and the object files that produce them. You can use the ‘-frandom-seed’ option to produce reproducibly identical object files.
The string should be different for every file you compile.
- @gcctabopt -fsched-verbose=n
On targets that use instruction scheduling, this option controls the amount of debugging output the scheduler prints. This information is written to standard error, unless ‘-dS’ or ‘-dR’ is specified, in which case it is output to the usual dump listing file, ‘.sched’ or ‘.sched2’ respectively. However for n greater than nine, the output is always printed to standard error.
For n greater than zero, ‘-fsched-verbose’ outputs the same information as ‘-dRS’. For n greater than one, it also output basic block probabilities, detailed ready list information and unit/insn info. For n greater than two, it includes RTL at abort point, control-flow and regions info. And for n over four, ‘-fsched-verbose’ also includes dependence info.
- @gcctabopt -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’. This creates a preprocessed ‘foo.i’ output file even though the compiler now normally uses an integrated preprocessor.
When used in combination with the ‘-x’ command line option, ‘-save-temps’ is sensible enough to avoid over writing an input source file with the same extension as an intermediate file. The corresponding intermediate file may be obtained by renaming the source file before using ‘-save-temps’.
- @gcctabopt -time
Report the CPU time taken by each subprocess in the compilation sequence. For C source files, this is the compiler proper and assembler (plus the linker if linking is done). The output looks like this:
# cc1 0.12 0.01 # as 0.00 0.01
The first number on each line is the “user time”, that is time spent executing the program itself. The second number is “system time”, time spent executing operating system routines on behalf of the program. Both numbers are in seconds.
- @gcctabopt -fvar-tracking
Run variable tracking pass. It computes where variables are stored at each position in code. Better debugging information is then generated (if the debugging information format supports this information).
It is enabled by default when compiling with optimization (‘-Os’, ‘-O’, ‘-O2’, ...), debugging information (‘-g’) and the debug info format supports it.
- @gcctabopt -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, GCC does not compile or link anything; it just prints the file name.
- @gcctabopt -print-multi-directory
Print the directory name corresponding to the multilib selected by any other switches present in the command line. This directory is supposed to exist in
- @gcctabopt -print-multi-lib
Print the mapping from multilib directory names to compiler switches that enable them. The directory name is separated from the switches by ‘;’, and each switch starts with an ‘@’ instead of the ‘-’, without spaces between multiple switches. This is supposed to ease shell-processing.
- @gcctabopt -print-prog-name=program
Like ‘-print-file-name’, but searches for a program such as ‘cpp’.
- @gcctabopt -print-libgcc-file-name
Same as ‘-print-file-name=libgcc.a’.
This is useful when you use ‘-nostdlib’ or ‘-nodefaultlibs’ but you do want to link with ‘libgcc.a’. You can do
gcc -nostdlib files… `gcc -print-libgcc-file-name`
- @gcctabopt -print-search-dirs
Print the name of the configured installation directory and a list of program and library directories
gccwill search—and don't do anything else.
This is useful when
gccprints the error message ‘installation problem, cannot exec cpp0: No such file or directory’. To resolve this you either need to put ‘cpp0’ and the other compiler components where
gccexpects to find them, or you can set the environment variable
GCC_EXEC_PREFIXto the directory where you installed them. Don't forget the trailing ‘/’. See section Environment Variables Affecting GCC.
- @gcctabopt -dumpmachine
Print the compiler's target machine (for example, ‘i686-pc-linux-gnu’)—and don't do anything else.
- @gcctabopt -dumpversion
Print the compiler version (for example, ‘3.0’)—and don't do anything else.
- @gcctabopt -dumpspecs
Print the compiler's built-in specs—and don't do anything else. (This is used when GCC itself is being built.) See section Specifying subprocesses and the switches to pass to them.
- @gcctabopt -feliminate-unused-debug-types
Normally, when producing DWARF2 output, GCC will emit debugging information for all types declared in a compilation unit, regardless of whether or not they are actually used in that compilation unit. Sometimes this is useful, such as if, in the debugger, you want to cast a value to a type that is not actually used in your program (but is declared). More often, however, this results in a significant amount of wasted space. With this option, GCC will avoid producing debug symbol output for types that are nowhere used in the source file being compiled.
|[ < ]||[ > ]||[ << ]||[ Up ]||[ >> ]||[Top]||[Contents]||[Index]||[ ? ]|