Using and Porting the GNU Compiler Collection (GCC)
GCC 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-1+
', or `-gdwarf-1
'
(see below).
Unlike most other C compilers, 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.
-ggdb
-gstabs
-gstabs+
-gcoff
-gxcoff
-gxcoff+
-gdwarf
-gdwarf+
-gdwarf-2
-glevel
-ggdblevel
-gstabslevel
-gcofflevel
-gxcofflevel
-gdwarflevel
-gdwarf-2level
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.
-Q
-ax
-a
' is
used. Additional output is the source and target address of the basic
blocks where a jump takes place, the number of times a jump is executed,
and (optionally) the complete sequence of basic blocks being executed.
The output is appended to file `bb.out
'.
You can examine different profiling aspects without recompilation. Your
executable will read a list of function names from file `bb.in
'.
Profiling starts when a function on the list is entered and stops when
that invocation is exited. To exclude a function from profiling, prefix
its name with `-'. If a function name is not unique, you can
disambiguate it by writing it in the form
`/path/filename.d:functionname
'. Your executable will write the
available paths and filenames in file `bb.out
'.
Several function names have a special meaning:
__bb_jumps__
bb.out
'.
__bb_hidecall__
__bb_showret__
__bb_trace__
bbtrace.gz
'.
The file will be compressed using the program `gzip
', which must
exist in your PATH
. On systems without the `popen
'
function, the file will be named `bbtrace
' and will not be
compressed. Profiling for even a few seconds on these systems will produce a very large file. Note: __bb_hidecall__
and
__bb_showret__
will not affect the sequence written to
`bbtrace.gz
'.
Here's a short example using different profiling parameters
in file `bb.in
'. Assume function foo
consists of basic blocks
1 and 2 and is called twice from block 3 of function main
. After
the calls, block 3 transfers control to block 4 of main
.
With __bb_trace__
and main
contained in file `bb.in
',
the following sequence of blocks is written to file `bbtrace.gz
':
0 3 1 2 1 2 4. The return from block 2 to block 3 is not shown, because
the return is to a point inside the block and not to the top. The
block address 0 always indicates, that control is transferred
to the trace from somewhere outside the observed functions. With
`-foo
' added to `bb.in
', the blocks of function
foo
are removed from the trace, so only 0 3 4 remains.
With __bb_jumps__
and main
contained in file `bb.in
',
jump frequencies will be written to file `bb.out
'. The
frequencies are obtained by constructing a trace of blocks
and incrementing a counter for every neighbouring pair of blocks
in the trace. The trace 0 3 1 2 1 2 4 displays the following
frequencies:
Jump from block 0x0 to block 0x3 executed 1 time(s) Jump from block 0x3 to block 0x1 executed 1 time(s) Jump from block 0x1 to block 0x2 executed 2 time(s) Jump from block 0x2 to block 0x1 executed 1 time(s) Jump from block 0x2 to block 0x4 executed 1 time(s)
With __bb_hidecall__
, control transfer due to call instructions
is removed from the trace, that is the trace is cut into three parts: 0
3 4, 0 1 2 and 0 1 2. With __bb_showret__
, control transfer due
to return instructions is added to the trace. The trace becomes: 0 3 1
2 3 1 2 3 4. Note, that this trace is not the same, as the sequence
written to `bbtrace.gz
'. It is solely used for counting jump
frequencies.
-fprofile-arcs
Since not every arc in the program must be instrumented, programs
compiled with this option run faster than programs compiled with
`-a
', which adds instrumentation code to every basic block in the
program. The tradeoff: since gcov
does not have
execution counts for all branches, it must start with the execution
counts for the instrumented branches, and then iterate over the program
flow graph until the entire graph has been solved. Hence, gcov
runs a little more slowly than a program which uses information from
`-a
'.
`-fprofile-arcs
' also makes it possible to estimate branch
probabilities, and to calculate basic block execution counts. In
general, basic block execution counts do not give enough information to
estimate all branch probabilities. When the compiled program exits, it
saves the arc execution counts to a file called
`sourcename.da
'. Use the compiler option
`-fbranch-probabilities
' (see Optimize Options) when recompiling, to optimize using estimated
branch probabilities.
-ftest-coverage
gcov
code-coverage utility
(see Gcov).
The data file names begin with the name of your source file:
sourcename.bb
gcov
uses to
associate basic block execution counts with line numbers.
sourcename.bbg
gcov
to reconstruct the program flow graph, so that it can compute all basic
block and arc execution counts from the information in the
sourcename.da
file (this last file is the output from
`-fprofile-arcs
').
-Q
-dletters
foo.c.rtl
' or `foo.c.jump
'). Here are the
possible letters for use in letters, and their meanings:
b
'
file.bp
'.
c
'
file.combine
'.
d
'
file.dbr
'.
D
'
r
'
file.rtl
'.
j
'
file.jump
'.
F
'
file.addressof
'.
f
'
file.flow
'.
g
'
file.greg
'.
G
'
file.gcse
'.
j
'
file.jump
'.
J
'
file.jump2
'.
k
'
file.stack
'.
l
'
file.lreg
'.
L
'
file.loop
'.
M
'
file.mach
'.
N
'
file.regmove
'.
r
'
file.rtl
'.
R
'
file.sched2
'.
s
'
file.cse
'.
S
'
file.sched
'.
t
'
file.cse2
'.
a
'
m
'
p
'
x
'
r
'.
y
'
A
'
-fdump-unnumbered
-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
' or `-nodefaultlibs
'
but you do want to link with `libgcc.a
'. You can do
gcc -nostdlib files... `gcc -print-libgcc-file-name`
-print-search-dirs
This is useful when gcc prints the error message
`installation problem, cannot exec cpp: No such file or directory
'.
To resolve this you either need to put `cpp
' and the other compiler
components where gcc expects to find them, or you can set the environment
variable GCC_EXEC_PREFIX
to the directory where you installed them.
Don't forget the trailing '/'.
See Environment Variables.
Using and Porting the GNU Compiler Collection (GCC)
Packaging copyright © 1988-2000 OAR Corporation
Context copyright by each document's author. See Free Software Foundation for information.