GNU CC has various special options that are used for debugging either your program or GCC:
-g
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
-gstabs
-gstabs+
-gcoff
-gxcoff
-gxcoff+
-gdwarf
-gdwarf+
-glevel
-ggdblevel
-gstabslevel
-gcofflevel
-gxcofflevel
-gdwarflevel
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
prof
. You must use this option when compiling
the source files you want data about, and you must also use it when
linking.
-pg
gprof
. You must use this option when compiling
the source files you want data about, and you must also use it when
linking.
-a
-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
foo.c.rtl
' or `foo.c.jump
'). Here are the
possible letters for use in letters, and their meanings:
M
'
N
'
D
'
y
'
r
'
file.rtl
'.
x
'
r
'.
j
'
file.jump
'.
s
'
file.cse
'.
L
'
file.loop
'.
t
'
file.cse2
'.
f
'
file.flow
'.
c
'
file.combine
'.
S
'
file.sched
'.
l
'
file.lreg
'.
g
'
file.greg
'.
R
'
file.sched2
'.
J
'
file.jump2
'.
d
'
file.dbr
'.
k
'
file.stack
'.
a
'
m
'
p
'
-fpretend-float
-save-temps
foo.c
' with `-c -save-temps
' would produce files
`foo.i
' and `foo.s
', as well as `foo.o
'.
-print-file-name=library
-print-prog-name=program
-print-file-name
', but searches for a program such as `cpp
'.
-print-libgcc-file-name
-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`