📄 debugging-options.html
字号:
<html lang="en">
<head>
<title>Using the GNU Compiler Collection (GCC)</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Using the GNU Compiler Collection (GCC)">
<meta name="generator" content="makeinfo 4.3">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
<!--
Copyright © 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
<p>Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "GNU General Public License" and "Funding
Free Software", the Front-Cover texts being (a) (see below), and with
the Back-Cover Texts being (b) (see below). A copy of the license is
included in the section entitled "GNU Free Documentation License".
<p>(a) The FSF's Front-Cover Text is:
<p>A GNU Manual
<p>(b) The FSF's Back-Cover Text is:
<p>You have freedom to copy and modify this GNU Manual, like GNU
software. Copies published by the Free Software Foundation raise
funds for GNU development.-->
</head>
<body>
<div class="node">
<p>
Node:<a name="Debugging%20Options">Debugging Options</a>,
Next:<a rel="next" accesskey="n" href="Optimize-Options.html#Optimize%20Options">Optimize Options</a>,
Previous:<a rel="previous" accesskey="p" href="Warning-Options.html#Warning%20Options">Warning Options</a>,
Up:<a rel="up" accesskey="u" href="Invoking-GCC.html#Invoking%20GCC">Invoking GCC</a>
<hr><br>
</div>
<h3 class="section">Options for Debugging Your Program or GCC</h3>
<p>GCC has various special options that are used for debugging
either your program or GCC:
<dl>
<dt><code>-g</code>
<dd>Produce debugging information in the operating system's native format
(stabs, COFF, XCOFF, or DWARF). GDB can work with this debugging
information.
<p>On most systems that use stabs format, <code>-g</code> 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 <code>-gstabs+</code>, <code>-gstabs</code>,
<code>-gxcoff+</code>, <code>-gxcoff</code>, <code>-gdwarf-1+</code>, <code>-gdwarf-1</code>,
or <code>-gvms</code> (see below).
<p>Unlike most other C compilers, GCC allows you to use <code>-g</code> with
<code>-O</code>. 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.
<p>Nevertheless it proves possible to debug optimized output. This makes
it reasonable to use the optimizer for programs that might have bugs.
<p>The following options are useful when GCC is generated with the
capability for more than one debugging format.
<br><dt><code>-ggdb</code>
<dd>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.
<br><dt><code>-gstabs</code>
<dd>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.
<br><dt><code>-gstabs+</code>
<dd>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.
<br><dt><code>-gcoff</code>
<dd>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.
<br><dt><code>-gxcoff</code>
<dd>Produce debugging information in XCOFF format (if that is supported).
This is the format used by the DBX debugger on IBM RS/6000 systems.
<br><dt><code>-gxcoff+</code>
<dd>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.
<br><dt><code>-gdwarf</code>
<dd>Produce debugging information in DWARF version 1 format (if that is
supported). This is the format used by SDB on most System V Release 4
systems.
<p>This option is deprecated.
<br><dt><code>-gdwarf+</code>
<dd>Produce debugging information in DWARF version 1 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.
<p>This option is deprecated.
<br><dt><code>-gdwarf-2</code>
<dd>Produce debugging information in DWARF version 2 format (if that is
supported). This is the format used by DBX on IRIX 6.
<br><dt><code>-gvms</code>
<dd>Produce debugging information in VMS debug format (if that is
supported). This is the format used by DEBUG on VMS systems.
<br><dt><code>-g</code><var>level</var><code></code>
<dd><dt><code>-ggdb</code><var>level</var><code></code>
<dd><dt><code>-gstabs</code><var>level</var><code></code>
<dd><dt><code>-gcoff</code><var>level</var><code></code>
<dd><dt><code>-gxcoff</code><var>level</var><code></code>
<dd><dt><code>-gvms</code><var>level</var><code></code>
<dd>Request debugging information and also use <var>level</var> to specify how
much information. The default level is 2.
<p>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.
<p>Level 3 includes extra information, such as all the macro definitions
present in the program. Some debuggers support macro expansion when
you use <code>-g3</code>.
<p>Note that in order to avoid confusion between DWARF1 debug level 2,
and DWARF2, neither <code>-gdwarf</code> nor <code>-gdwarf-2</code> accept
a concatenated debug level. Instead use an additional <code>-g</code><var>level</var><code></code>
option to change the debug level for DWARF1 or DWARF2.
<br><dt><code>-feliminate-dwarf2-dups</code>
<dd>Compress DWARF2 debugging information by eliminating duplicated
information about each symbol. This option only makes sense when
generating DWARF2 debugging information with <code>-gdwarf-2</code>.
<br><dt><code>-p</code>
<dd>Generate extra code to write profile information suitable for the
analysis program <code>prof</code>. You must use this option when compiling
the source files you want data about, and you must also use it when
linking.
<br><dt><code>-pg</code>
<dd>Generate extra code to write profile information suitable for the
analysis program <code>gprof</code>. You must use this option when compiling
the source files you want data about, and you must also use it when
linking.
<br><dt><code>-Q</code>
<dd>Makes the compiler print out each function name as it is compiled, and
print some statistics about each pass when it finishes.
<br><dt><code>-ftime-report</code>
<dd>Makes the compiler print some statistics about the time consumed by each
pass when it finishes.
<br><dt><code>-fmem-report</code>
<dd>Makes the compiler print some statistics about permanent memory
allocation when it finishes.
<br><dt><code>-fprofile-arcs</code>
<dd>Instrument <dfn>arcs</dfn> during compilation to generate coverage data or
for profile-directed block ordering. During execution the program
records how many times each branch is executed and how many times it is
taken. When the compiled program exits it saves this data to a file
called <code></code><var>auxname</var><code>.da</code> for each source file. <var>auxname</var> 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. <code>foo.da</code>
for input file <code>dir/foo.c</code>, or <code>dir/foo.da</code> for output file
specified as <code>-o dir/foo.o</code>).
<p>For profile-directed block ordering, compile the program with
<code>-fprofile-arcs</code> plus optimization and code generation options,
generate the arc profile information by running the program on a
selected workload, and then compile the program again with the same
optimization and code generation options plus
<code>-fbranch-probabilities</code> (see <a href="Optimize-Options.html#Optimize%20Options">Options that Control Optimization</a>).
<p>The other use of <code>-fprofile-arcs</code> is for use with <code>gcov</code>,
when it is used with the <code>-ftest-coverage</code> option.
<p>With <code>-fprofile-arcs</code>, 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.
<br><dt><code>-ftest-coverage</code>
<dd>Create data files for the <code>gcov</code> code-coverage utility
(see <a href="Gcov.html#Gcov"><code>gcov</code>--a Test Coverage Program</a>). See
<code>-fprofile-arcs</code> option above for a description of <var>auxname</var>.
<dl>
<dt><code></code><var>auxname</var><code>.bb</code>
<dd>A mapping from basic blocks to line numbers, which <code>gcov</code> uses to
associate basic block execution counts with line numbers.
<br><dt><code></code><var>auxname</var><code>.bbg</code>
<dd>A list of all arcs in the program flow graph. This allows <code>gcov</code>
to reconstruct the program flow graph, so that it can compute all basic
block and arc execution counts from the information in the
<code></code><var>auxname</var><code>.da</code> file.
</dl>
<p>Use <code>-ftest-coverage</code> with <code>-fprofile-arcs</code>; the latter
option adds instrumentation to the program, which then writes
execution counts to another data file:
<dl>
<dt><code></code><var>auxname</var><code>.da</code>
<dd>Runtime arc execution counts, used in conjunction with the arc
information in the file <code></code><var>auxname</var><code>.bbg</code>.
</dl>
<p>Coverage data will map better to the source files if
<code>-ftest-coverage</code> is used without optimization.
<br><dt><code>-d</code><var>letters</var><code></code>
<dd>Says to make debugging dumps during compilation at times specified by
<var>letters</var>. This is used for debugging the compiler. The file names
for most of the dumps are made by appending a pass number and a word to
the <var>dumpname</var>. <var>dumpname</var> 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. In both cases any
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -