⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debugging-options.html

📁 自己收集的linux入门到学懂高级编程书集 包括linux程序设计第三版
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<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.6"><!--Copyright &copy; 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.   <p>Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.2 orany later version published by the Free Software Foundation; with theInvariant Sections being "GNU General Public License" and "FundingFree Software", the Front-Cover texts being (a) (see below), and withthe Back-Cover Texts being (b) (see below).  A copy of the license isincluded 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.--><meta http-equiv="Content-Style-Type" content="text/css"><style type="text/css"><!--  pre.display { font-family:inherit }  pre.format  { font-family:inherit }  pre.smalldisplay { font-family:inherit; font-size:smaller }  pre.smallformat  { font-family:inherit; font-size:smaller }  pre.smallexample { font-size:smaller }  pre.smalllisp    { font-size:smaller }--></style></head><body><div class="node"><p>Node:&nbsp;<a name="Debugging%20Options">Debugging Options</a>,Next:&nbsp;<a rel="next" accesskey="n" href="Optimize-Options.html#Optimize%20Options">Optimize Options</a>,Previous:&nbsp;<a rel="previous" accesskey="p" href="Warning-Options.html#Warning%20Options">Warning Options</a>,Up:&nbsp;<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 debuggingeither 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 debugginginformation.     <p>On most systems that use stabs format, <code>-g</code> enables use of extradebugging information that only GDB can use; this extra informationmakes debugging work better in GDB but will probably make other debuggerscrash orrefuse to read the program.  If you want to control for certain whetherto generate the extra information, use <code>-gstabs+</code>, <code>-gstabs</code>,<code>-gxcoff+</code>, <code>-gxcoff</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 occasionallyproduce surprising results: some variables you declared may not existat all; flow of control may briefly move where you did not expect it;some statements may not be executed because they compute constantresults or their values were already at hand; some statements mayexecute in different places because they were moved out of loops.     <p>Nevertheless it proves possible to debug optimized output.  This makesit reasonable to use the optimizer for programs that might have bugs.     <p>The following options are useful when GCC is generated with thecapability for more than one debugging format.     <br><dt><code>-ggdb</code>     <dd>Produce debugging information for use by GDB.  This means to use themost expressive format available (DWARF 2, stabs, or the native formatif neither of those are supported), including GDB extensions if at allpossible.     <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 BSDsystems.  On MIPS, Alpha and System V Release 4 systems this optionproduces 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>-feliminate-unused-debug-symbols</code>     <dd>Produce debugging information in stabs format (if that is supported),for only symbols that are actually used.     <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).  Theuse of these extensions is likely to make other debuggers crash orrefuse 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 toSystem 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).  Theuse of these extensions is likely to make other debuggers crash orrefuse to read the program, and may cause assemblers other than the GNUassembler (GAS) to fail with an error.     <br><dt><code>-gdwarf-2</code>     <dd>Produce debugging information in DWARF version 2 format (if that issupported).  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 issupported).  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 howmuch information.  The default level is 2.     <p>Level 1 produces minimal information, enough for making backtraces inparts of the program that you don't plan to debug.  This includesdescriptions of functions and external variables, but no informationabout local variables and no line numbers.     <p>Level 3 includes extra information, such as all the macro definitionspresent in the program.  Some debuggers support macro expansion whenyou use <code>-g3</code>.     <p>Note that in order to avoid confusion between DWARF1 debug level 2,and DWARF2 <code>-gdwarf-2</code> does not accept a concatenated debuglevel.  Instead use an additional <code>-g</code><var>level</var><code></code> option tochange the debug level for DWARF2.     <br><dt><code>-feliminate-dwarf2-dups</code>     <dd>Compress DWARF2 debugging information by eliminating duplicatedinformation about each symbol.  This option only makes sense whengenerating DWARF2 debugging information with <code>-gdwarf-2</code>.     <br><dt><code>-p</code>     <dd>Generate extra code to write profile information suitable for theanalysis program <code>prof</code>.  You must use this option when compilingthe source files you want data about, and you must also use it whenlinking.     <br><dt><code>-pg</code>     <dd>Generate extra code to write profile information suitable for theanalysis program <code>gprof</code>.  You must use this option when compilingthe source files you want data about, and you must also use it whenlinking.     <br><dt><code>-Q</code>     <dd>Makes the compiler print out each function name as it is compiled, andprint 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 eachpass when it finishes.     <br><dt><code>-fmem-report</code>     <dd>Makes the compiler print some statistics about permanent memoryallocation when it finishes.     <br><dt><code>-fprofile-arcs</code>     <dd>Add code so that program flow <dfn>arcs</dfn> are instrumented.  Duringexecution the program records how many times each branch and call isexecuted and how many times it is taken or returns.  When the compiledprogram exits it saves this data to a file called<code></code><var>auxname</var><code>.gcda</code> for each source file. The data may be used forprofile-directed optimizations (<code>-fbranch-probabilities</code>), or fortest coverage analysis (<code>-ftest-coverage</code>). Each object file's<var>auxname</var> is generated from the name of the output file, ifexplicitly specified and it is not the final executable, otherwise it isthe basename of the source file. In both cases any suffix is removed(e.g.  <code>foo.gcda</code> for input file <code>dir/foo.c</code>, or<code>dir/foo.gcda</code> for output file specified as <code>-o dir/foo.o</code>).          <ul>          <li>Compile the source files with <code>-fprofile-arcs</code> plus optimizationand code generation options. For test coverage analysis, use theadditional <code>-ftest-coverage</code> option. You do not need to profileevery source file in a program.          <li>Link your object files with <code>-lgcov</code> or <code>-fprofile-arcs</code>(the latter implies the former).          <li>Run the program on a representative workload to generate the arc profileinformation. This may be repeated any number of times. You can runconcurrent instances of your program, and provided that the file systemsupports locking, the data files will be correctly updated. Also<code>fork</code> calls are detected and correctly handled (double countingwill not happen).          <li>For profile-directed optimizations, compile the source files again withthe same optimization and code generation options plus<code>-fbranch-probabilities</code> (see <a href="Optimize-Options.html#Optimize%20Options">Options that Control Optimization</a>).          <li>For test coverage analysis, use <code>gcov</code> to produce human readableinformation from the <code>.gcno</code> and <code>.gcda</code> files. Refer to the<code>gcov</code> documentation for further information.     </ul>     <p>With <code>-fprofile-arcs</code>, for each function of your program GCCcreates 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: thecompiler adds code to count the number of times that these arcs areexecuted.  When an arc is the only exit or only entrance to a block, theinstrumentation code can be added to the block; otherwise, a new basicblock must be created to hold the instrumentation code.     <br><dt><code>-ftest-coverage</code>     <dd>Produce a notes file that the <code>gcov</code> code-coverage utility(see <a href="Gcov.html#Gcov"><code>gcov</code>--a Test Coverage Program</a>) can use toshow program coverage. Each source file's note file is called<code></code><var>auxname</var><code>.gcno</code>. Refer to the <code>-fprofile-arcs</code> optionabove for a description of <var>auxname</var> and instructions on how togenerate test coverage data. Coverage data will match the source filesmore closely, if you do not optimize.     <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 namesfor most of the dumps are made by appending a pass number and a word tothe <var>dumpname</var>. <var>dumpname</var> is generated from the name of theoutput file, if explicitly specified and it is not an executable,otherwise it is the basename of the source file. In both cases anysuffix is removed (e.g.  <code>foo.01.rtl</code> or <code>foo.02.sibling</code>). Here are the possible letters for use in <var>letters</var>, and theirmeanings:          <dl><dt><code>A</code>          <dd>Annotate the assembler output with miscellaneous debugging information. <br><dt><code>b</code>          <dd>Dump after computing branch probabilities, to <code></code><var>file</var><code>.12.bp</code>. <br><dt><code>B</code>          <dd>Dump after block reordering, to <code></code><var>file</var><code>.31.bbro</code>. <br><dt><code>c</code>          <dd>Dump after instruction combination, to the file <code></code><var>file</var><code>.20.combine</code>. <br><dt><code>C</code>          <dd>Dump after the first if conversion, to the file <code></code><var>file</var><code>.14.ce1</code>. Also dump after the second if conversion, to the file <code></code><var>file</var><code>.21.ce2</code>. <br><dt><code>d</code>          <dd>Dump after branch target load optimization, to to <code></code><var>file</var><code>.32.btl</code>. Also dump after delayed branch scheduling, to <code></code><var>file</var><code>.36.dbr</code>. <br><dt><code>D</code>          <dd>Dump all macro definitions, at the end of preprocessing, in addition tonormal output. <br><dt><code>E</code>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -