1*c87b03e5Sespie@c Copyright (C) 1996, 1997, 1999, 2000, 2001, 2*c87b03e5Sespie@c 2002, 2003 Free Software Foundation, Inc. 3*c87b03e5Sespie@c This is part of the GCC manual. 4*c87b03e5Sespie@c For copying conditions, see the file gcc.texi. 5*c87b03e5Sespie 6*c87b03e5Sespie@ignore 7*c87b03e5Sespie@c man begin COPYRIGHT 8*c87b03e5SespieCopyright @copyright{} 1996, 1997, 1999, 2000, 2001, 2002, 2003 9*c87b03e5SespieFree Software Foundation, Inc. 10*c87b03e5Sespie 11*c87b03e5SespiePermission is granted to copy, distribute and/or modify this document 12*c87b03e5Sespieunder the terms of the GNU Free Documentation License, Version 1.2 or 13*c87b03e5Sespieany later version published by the Free Software Foundation; with the 14*c87b03e5SespieInvariant Sections being ``GNU General Public License'' and ``Funding 15*c87b03e5SespieFree Software'', the Front-Cover texts being (a) (see below), and with 16*c87b03e5Sespiethe Back-Cover Texts being (b) (see below). A copy of the license is 17*c87b03e5Sespieincluded in the gfdl(7) man page. 18*c87b03e5Sespie 19*c87b03e5Sespie(a) The FSF's Front-Cover Text is: 20*c87b03e5Sespie 21*c87b03e5Sespie A GNU Manual 22*c87b03e5Sespie 23*c87b03e5Sespie(b) The FSF's Back-Cover Text is: 24*c87b03e5Sespie 25*c87b03e5Sespie You have freedom to copy and modify this GNU Manual, like GNU 26*c87b03e5Sespie software. Copies published by the Free Software Foundation raise 27*c87b03e5Sespie funds for GNU development. 28*c87b03e5Sespie@c man end 29*c87b03e5Sespie@c Set file name and title for the man page. 30*c87b03e5Sespie@setfilename gcov 31*c87b03e5Sespie@settitle coverage testing tool 32*c87b03e5Sespie@end ignore 33*c87b03e5Sespie 34*c87b03e5Sespie@node Gcov 35*c87b03e5Sespie@chapter @command{gcov}---a Test Coverage Program 36*c87b03e5Sespie 37*c87b03e5Sespie@command{gcov} is a tool you can use in conjunction with GCC to 38*c87b03e5Sespietest code coverage in your programs. 39*c87b03e5Sespie 40*c87b03e5Sespie@menu 41*c87b03e5Sespie* Gcov Intro:: Introduction to gcov. 42*c87b03e5Sespie* Invoking Gcov:: How to use gcov. 43*c87b03e5Sespie* Gcov and Optimization:: Using gcov with GCC optimization. 44*c87b03e5Sespie* Gcov Data Files:: The files used by gcov. 45*c87b03e5Sespie@end menu 46*c87b03e5Sespie 47*c87b03e5Sespie@node Gcov Intro 48*c87b03e5Sespie@section Introduction to @command{gcov} 49*c87b03e5Sespie@c man begin DESCRIPTION 50*c87b03e5Sespie 51*c87b03e5Sespie@command{gcov} is a test coverage program. Use it in concert with GCC 52*c87b03e5Sespieto analyze your programs to help create more efficient, faster running 53*c87b03e5Sespiecode and to discover untested parts of your program. You can use 54*c87b03e5Sespie@command{gcov} as a profiling tool to help discover where your 55*c87b03e5Sespieoptimization efforts will best affect your code. You can also use 56*c87b03e5Sespie@command{gcov} along with the other profiling tool, @command{gprof}, to 57*c87b03e5Sespieassess which parts of your code use the greatest amount of computing 58*c87b03e5Sespietime. 59*c87b03e5Sespie 60*c87b03e5SespieProfiling tools help you analyze your code's performance. Using a 61*c87b03e5Sespieprofiler such as @command{gcov} or @command{gprof}, you can find out some 62*c87b03e5Sespiebasic performance statistics, such as: 63*c87b03e5Sespie 64*c87b03e5Sespie@itemize @bullet 65*c87b03e5Sespie@item 66*c87b03e5Sespiehow often each line of code executes 67*c87b03e5Sespie 68*c87b03e5Sespie@item 69*c87b03e5Sespiewhat lines of code are actually executed 70*c87b03e5Sespie 71*c87b03e5Sespie@item 72*c87b03e5Sespiehow much computing time each section of code uses 73*c87b03e5Sespie@end itemize 74*c87b03e5Sespie 75*c87b03e5SespieOnce you know these things about how your code works when compiled, you 76*c87b03e5Sespiecan look at each module to see which modules should be optimized. 77*c87b03e5Sespie@command{gcov} helps you determine where to work on optimization. 78*c87b03e5Sespie 79*c87b03e5SespieSoftware developers also use coverage testing in concert with 80*c87b03e5Sespietestsuites, to make sure software is actually good enough for a release. 81*c87b03e5SespieTestsuites can verify that a program works as expected; a coverage 82*c87b03e5Sespieprogram tests to see how much of the program is exercised by the 83*c87b03e5Sespietestsuite. Developers can then determine what kinds of test cases need 84*c87b03e5Sespieto be added to the testsuites to create both better testing and a better 85*c87b03e5Sespiefinal product. 86*c87b03e5Sespie 87*c87b03e5SespieYou should compile your code without optimization if you plan to use 88*c87b03e5Sespie@command{gcov} because the optimization, by combining some lines of code 89*c87b03e5Sespieinto one function, may not give you as much information as you need to 90*c87b03e5Sespielook for `hot spots' where the code is using a great deal of computer 91*c87b03e5Sespietime. Likewise, because @command{gcov} accumulates statistics by line (at 92*c87b03e5Sespiethe lowest resolution), it works best with a programming style that 93*c87b03e5Sespieplaces only one statement on each line. If you use complicated macros 94*c87b03e5Sespiethat expand to loops or to other control structures, the statistics are 95*c87b03e5Sespieless helpful---they only report on the line where the macro call 96*c87b03e5Sespieappears. If your complex macros behave like functions, you can replace 97*c87b03e5Sespiethem with inline functions to solve this problem. 98*c87b03e5Sespie 99*c87b03e5Sespie@command{gcov} creates a logfile called @file{@var{sourcefile}.gcov} which 100*c87b03e5Sespieindicates how many times each line of a source file @file{@var{sourcefile}.c} 101*c87b03e5Sespiehas executed. You can use these logfiles along with @command{gprof} to aid 102*c87b03e5Sespiein fine-tuning the performance of your programs. @command{gprof} gives 103*c87b03e5Sespietiming information you can use along with the information you get from 104*c87b03e5Sespie@command{gcov}. 105*c87b03e5Sespie 106*c87b03e5Sespie@command{gcov} works only on code compiled with GCC@. It is not 107*c87b03e5Sespiecompatible with any other profiling or test coverage mechanism. 108*c87b03e5Sespie 109*c87b03e5Sespie@c man end 110*c87b03e5Sespie 111*c87b03e5Sespie@node Invoking Gcov 112*c87b03e5Sespie@section Invoking gcov 113*c87b03e5Sespie 114*c87b03e5Sespie@smallexample 115*c87b03e5Sespiegcov @r{[}@var{options}@r{]} @var{sourcefile} 116*c87b03e5Sespie@end smallexample 117*c87b03e5Sespie 118*c87b03e5Sespie@command{gcov} accepts the following options: 119*c87b03e5Sespie 120*c87b03e5Sespie@ignore 121*c87b03e5Sespie@c man begin SYNOPSIS 122*c87b03e5Sespiegcov [@option{-v}|@option{--version}] [@option{-h}|@option{--help}] 123*c87b03e5Sespie [@option{-b}|@option{--branch-probabilities}] 124*c87b03e5Sespie [@option{-c}|@option{--branch-counts}] 125*c87b03e5Sespie [@option{-n}|@option{--no-output}] 126*c87b03e5Sespie [@option{-l}|@option{--long-file-names}] 127*c87b03e5Sespie [@option{-p}|@option{--preserve-paths}] 128*c87b03e5Sespie [@option{-f}|@option{--function-summaries}] 129*c87b03e5Sespie [@option{-o}|@option{--object-directory} @var{directory|file}] @var{sourcefile} 130*c87b03e5Sespie@c man end 131*c87b03e5Sespie@c man begin SEEALSO 132*c87b03e5Sespiegpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entry for @file{gcc}. 133*c87b03e5Sespie@c man end 134*c87b03e5Sespie@end ignore 135*c87b03e5Sespie 136*c87b03e5Sespie@c man begin OPTIONS 137*c87b03e5Sespie@table @gcctabopt 138*c87b03e5Sespie@item -h 139*c87b03e5Sespie@itemx --help 140*c87b03e5SespieDisplay help about using @command{gcov} (on the standard output), and 141*c87b03e5Sespieexit without doing any further processing. 142*c87b03e5Sespie 143*c87b03e5Sespie@item -v 144*c87b03e5Sespie@itemx --version 145*c87b03e5SespieDisplay the @command{gcov} version number (on the standard output), 146*c87b03e5Sespieand exit without doing any further processing. 147*c87b03e5Sespie 148*c87b03e5Sespie@item -b 149*c87b03e5Sespie@itemx --branch-probabilities 150*c87b03e5SespieWrite branch frequencies to the output file, and write branch summary 151*c87b03e5Sespieinfo to the standard output. This option allows you to see how often 152*c87b03e5Sespieeach branch in your program was taken. 153*c87b03e5Sespie 154*c87b03e5Sespie@item -c 155*c87b03e5Sespie@itemx --branch-counts 156*c87b03e5SespieWrite branch frequencies as the number of branches taken, rather than 157*c87b03e5Sespiethe percentage of branches taken. 158*c87b03e5Sespie 159*c87b03e5Sespie@item -n 160*c87b03e5Sespie@itemx --no-output 161*c87b03e5SespieDo not create the @command{gcov} output file. 162*c87b03e5Sespie 163*c87b03e5Sespie@item -l 164*c87b03e5Sespie@itemx --long-file-names 165*c87b03e5SespieCreate long file names for included source files. For example, if the 166*c87b03e5Sespieheader file @file{x.h} contains code, and was included in the file 167*c87b03e5Sespie@file{a.c}, then running @command{gcov} on the file @file{a.c} will produce 168*c87b03e5Sespiean output file called @file{a.c##x.h.gcov} instead of @file{x.h.gcov}. 169*c87b03e5SespieThis can be useful if @file{x.h} is included in multiple source files. 170*c87b03e5Sespie 171*c87b03e5Sespie@item -p 172*c87b03e5Sespie@itemx --preserve-paths 173*c87b03e5SespiePreserve complete path information in the names of generated 174*c87b03e5Sespie@file{.gcov} files. Without this option, just the filename component is 175*c87b03e5Sespieused. With this option, all directories are used, with '/' characters 176*c87b03e5Sespietranslated to '#' characters, '.' directory components removed and '..' 177*c87b03e5Sespiecomponents renamed to '^'. This is useful if sourcefiles are in several 178*c87b03e5Sespiedifferent directories. It also affects the @samp{-l} option. 179*c87b03e5Sespie 180*c87b03e5Sespie@item -f 181*c87b03e5Sespie@itemx --function-summaries 182*c87b03e5SespieOutput summaries for each function in addition to the file level summary. 183*c87b03e5Sespie 184*c87b03e5Sespie@item -o @var{directory|file} 185*c87b03e5Sespie@itemx --object-directory @var{directory} 186*c87b03e5Sespie@itemx --object-file @var{file} 187*c87b03e5SespieSpecify either the directory containing the gcov data files, or the 188*c87b03e5Sespieobject path name. The @file{.bb}, @file{.bbg}, and 189*c87b03e5Sespie@file{.da} data files are searched for using this option. If a directory 190*c87b03e5Sespieis specified, the data files are in that directory and named after the 191*c87b03e5Sespiesource file name, without its extension. If a file is specified here, 192*c87b03e5Sespiethe data files are named after that file, without its extension. If this 193*c87b03e5Sespieoption is not supplied, it defaults to the current directory. 194*c87b03e5Sespie 195*c87b03e5Sespie@end table 196*c87b03e5Sespie 197*c87b03e5Sespie@command{gcov} should be run with the current directory the same as that 198*c87b03e5Sespiewhen you invoked the compiler. Otherwise it will not be able to locate 199*c87b03e5Sespiethe source files. @command{gcov} produces files called 200*c87b03e5Sespie@file{@var{mangledname}.gcov} in the current directory. These contain 201*c87b03e5Sespiethe coverage information of the source file they correspond to. 202*c87b03e5SespieOne @file{.gcov} file is produced for each source file containing code, 203*c87b03e5Sespiewhich was compiled to produce the data files. The @file{.gcov} files 204*c87b03e5Sespiecontain the ':' separated fields along with program source code. The 205*c87b03e5Sespieformat is 206*c87b03e5Sespie 207*c87b03e5Sespie@smallexample 208*c87b03e5Sespie@var{execution_count}:@var{line_number}:@var{source line text} 209*c87b03e5Sespie@end smallexample 210*c87b03e5Sespie 211*c87b03e5SespieAdditional block information may succeed each line, when requested by 212*c87b03e5Sespiecommand line option. The @var{execution_count} is @samp{-} for lines 213*c87b03e5Sespiecontaining no code and @samp{#####} for lines which were never 214*c87b03e5Sespieexecuted. Some lines of information at the start have @var{line_number} 215*c87b03e5Sespieof zero. 216*c87b03e5Sespie 217*c87b03e5SespieWhen printing percentages, 0% and 100% are only printed when the values 218*c87b03e5Sespieare @emph{exactly} 0% and 100% respectively. Other values which would 219*c87b03e5Sespieconventionally be rounded to 0% or 100% are instead printed as the 220*c87b03e5Sespienearest non-boundary value. 221*c87b03e5Sespie 222*c87b03e5SespieWhen using @command{gcov}, you must first compile your program with two 223*c87b03e5Sespiespecial GCC options: @samp{-fprofile-arcs -ftest-coverage}. 224*c87b03e5SespieThis tells the compiler to generate additional information needed by 225*c87b03e5Sespiegcov (basically a flow graph of the program) and also includes 226*c87b03e5Sespieadditional code in the object files for generating the extra profiling 227*c87b03e5Sespieinformation needed by gcov. These additional files are placed in the 228*c87b03e5Sespiedirectory where the object file is located. 229*c87b03e5Sespie 230*c87b03e5SespieRunning the program will cause profile output to be generated. For each 231*c87b03e5Sespiesource file compiled with @option{-fprofile-arcs}, an accompanying @file{.da} 232*c87b03e5Sespiefile will be placed in the object file directory. 233*c87b03e5Sespie 234*c87b03e5SespieRunning @command{gcov} with your program's source file names as arguments 235*c87b03e5Sespiewill now produce a listing of the code along with frequency of execution 236*c87b03e5Sespiefor each line. For example, if your program is called @file{tmp.c}, this 237*c87b03e5Sespieis what you see when you use the basic @command{gcov} facility: 238*c87b03e5Sespie 239*c87b03e5Sespie@smallexample 240*c87b03e5Sespie$ gcc -fprofile-arcs -ftest-coverage tmp.c 241*c87b03e5Sespie$ a.out 242*c87b03e5Sespie$ gcov tmp.c 243*c87b03e5Sespie90.00% of 10 source lines executed in file tmp.c 244*c87b03e5SespieCreating tmp.c.gcov. 245*c87b03e5Sespie@end smallexample 246*c87b03e5Sespie 247*c87b03e5SespieThe file @file{tmp.c.gcov} contains output from @command{gcov}. 248*c87b03e5SespieHere is a sample: 249*c87b03e5Sespie 250*c87b03e5Sespie@smallexample 251*c87b03e5Sespie -: 0:Source:tmp.c 252*c87b03e5Sespie -: 0:Object:tmp.bb 253*c87b03e5Sespie -: 1:#include <stdio.h> 254*c87b03e5Sespie -: 2: 255*c87b03e5Sespie -: 3:int main (void) 256*c87b03e5Sespie 1: 4:@{ 257*c87b03e5Sespie 1: 5: int i, total; 258*c87b03e5Sespie -: 6: 259*c87b03e5Sespie 1: 7: total = 0; 260*c87b03e5Sespie -: 8: 261*c87b03e5Sespie 11: 9: for (i = 0; i < 10; i++) 262*c87b03e5Sespie 10: 10: total += i; 263*c87b03e5Sespie -: 11: 264*c87b03e5Sespie 1: 12: if (total != 45) 265*c87b03e5Sespie #####: 13: printf ("Failure\n"); 266*c87b03e5Sespie -: 14: else 267*c87b03e5Sespie 1: 15: printf ("Success\n"); 268*c87b03e5Sespie 1: 16: return 0; 269*c87b03e5Sespie 1: 17:@} 270*c87b03e5Sespie@end smallexample 271*c87b03e5Sespie 272*c87b03e5Sespie@need 450 273*c87b03e5SespieWhen you use the @option{-b} option, your output looks like this: 274*c87b03e5Sespie 275*c87b03e5Sespie@smallexample 276*c87b03e5Sespie$ gcov -b tmp.c 277*c87b03e5Sespie90.00% of 10 source lines executed in file tmp.c 278*c87b03e5Sespie80.00% of 5 branches executed in file tmp.c 279*c87b03e5Sespie80.00% of 5 branches taken at least once in file tmp.c 280*c87b03e5Sespie50.00% of 2 calls executed in file tmp.c 281*c87b03e5SespieCreating tmp.c.gcov. 282*c87b03e5Sespie@end smallexample 283*c87b03e5Sespie 284*c87b03e5SespieHere is a sample of a resulting @file{tmp.c.gcov} file: 285*c87b03e5Sespie 286*c87b03e5Sespie@smallexample 287*c87b03e5Sespie -: 0:Source:tmp.c 288*c87b03e5Sespie -: 0:Object:tmp.bb 289*c87b03e5Sespie -: 1:#include <stdio.h> 290*c87b03e5Sespie -: 2: 291*c87b03e5Sespie -: 3:int main (void) 292*c87b03e5Sespie 1: 4:@{ 293*c87b03e5Sespie 1: 5: int i, total; 294*c87b03e5Sespie -: 6: 295*c87b03e5Sespie 1: 7: total = 0; 296*c87b03e5Sespie -: 8: 297*c87b03e5Sespie 11: 9: for (i = 0; i < 10; i++) 298*c87b03e5Sespiebranch 0: taken 90% 299*c87b03e5Sespiebranch 1: taken 100% 300*c87b03e5Sespiebranch 2: taken 100% 301*c87b03e5Sespie 10: 10: total += i; 302*c87b03e5Sespie -: 11: 303*c87b03e5Sespie 1: 12: if (total != 45) 304*c87b03e5Sespiebranch 0: taken 100% 305*c87b03e5Sespie #####: 13: printf ("Failure\n"); 306*c87b03e5Sespiecall 0: never executed 307*c87b03e5Sespiebranch 1: never executed 308*c87b03e5Sespie -: 14: else 309*c87b03e5Sespie 1: 15: printf ("Success\n"); 310*c87b03e5Sespiecall 0: returns 100% 311*c87b03e5Sespie 1: 16: return 0; 312*c87b03e5Sespie 1: 17:@} 313*c87b03e5Sespie@end smallexample 314*c87b03e5Sespie 315*c87b03e5SespieFor each basic block, a line is printed after the last line of the basic 316*c87b03e5Sespieblock describing the branch or call that ends the basic block. There can 317*c87b03e5Sespiebe multiple branches and calls listed for a single source line if there 318*c87b03e5Sespieare multiple basic blocks that end on that line. In this case, the 319*c87b03e5Sespiebranches and calls are each given a number. There is no simple way to map 320*c87b03e5Sespiethese branches and calls back to source constructs. In general, though, 321*c87b03e5Sespiethe lowest numbered branch or call will correspond to the leftmost construct 322*c87b03e5Sespieon the source line. 323*c87b03e5Sespie 324*c87b03e5SespieFor a branch, if it was executed at least once, then a percentage 325*c87b03e5Sespieindicating the number of times the branch was taken divided by the 326*c87b03e5Sespienumber of times the branch was executed will be printed. Otherwise, the 327*c87b03e5Sespiemessage ``never executed'' is printed. 328*c87b03e5Sespie 329*c87b03e5SespieFor a call, if it was executed at least once, then a percentage 330*c87b03e5Sespieindicating the number of times the call returned divided by the number 331*c87b03e5Sespieof times the call was executed will be printed. This will usually be 332*c87b03e5Sespie100%, but may be less for functions call @code{exit} or @code{longjmp}, 333*c87b03e5Sespieand thus may not return every time they are called. 334*c87b03e5Sespie 335*c87b03e5SespieThe execution counts are cumulative. If the example program were 336*c87b03e5Sespieexecuted again without removing the @file{.da} file, the count for the 337*c87b03e5Sespienumber of times each line in the source was executed would be added to 338*c87b03e5Sespiethe results of the previous run(s). This is potentially useful in 339*c87b03e5Sespieseveral ways. For example, it could be used to accumulate data over a 340*c87b03e5Sespienumber of program runs as part of a test verification suite, or to 341*c87b03e5Sespieprovide more accurate long-term information over a large number of 342*c87b03e5Sespieprogram runs. 343*c87b03e5Sespie 344*c87b03e5SespieThe data in the @file{.da} files is saved immediately before the program 345*c87b03e5Sespieexits. For each source file compiled with @option{-fprofile-arcs}, the 346*c87b03e5Sespieprofiling code first attempts to read in an existing @file{.da} file; if 347*c87b03e5Sespiethe file doesn't match the executable (differing number of basic block 348*c87b03e5Sespiecounts) it will ignore the contents of the file. It then adds in the 349*c87b03e5Sespienew execution counts and finally writes the data to the file. 350*c87b03e5Sespie 351*c87b03e5Sespie@node Gcov and Optimization 352*c87b03e5Sespie@section Using @command{gcov} with GCC Optimization 353*c87b03e5Sespie 354*c87b03e5SespieIf you plan to use @command{gcov} to help optimize your code, you must 355*c87b03e5Sespiefirst compile your program with two special GCC options: 356*c87b03e5Sespie@samp{-fprofile-arcs -ftest-coverage}. Aside from that, you can use any 357*c87b03e5Sespieother GCC options; but if you want to prove that every single line 358*c87b03e5Sespiein your program was executed, you should not compile with optimization 359*c87b03e5Sespieat the same time. On some machines the optimizer can eliminate some 360*c87b03e5Sespiesimple code lines by combining them with other lines. For example, code 361*c87b03e5Sespielike this: 362*c87b03e5Sespie 363*c87b03e5Sespie@smallexample 364*c87b03e5Sespieif (a != b) 365*c87b03e5Sespie c = 1; 366*c87b03e5Sespieelse 367*c87b03e5Sespie c = 0; 368*c87b03e5Sespie@end smallexample 369*c87b03e5Sespie 370*c87b03e5Sespie@noindent 371*c87b03e5Sespiecan be compiled into one instruction on some machines. In this case, 372*c87b03e5Sespiethere is no way for @command{gcov} to calculate separate execution counts 373*c87b03e5Sespiefor each line because there isn't separate code for each line. Hence 374*c87b03e5Sespiethe @command{gcov} output looks like this if you compiled the program with 375*c87b03e5Sespieoptimization: 376*c87b03e5Sespie 377*c87b03e5Sespie@smallexample 378*c87b03e5Sespie 100: 12:if (a != b) 379*c87b03e5Sespie 100: 13: c = 1; 380*c87b03e5Sespie 100: 14:else 381*c87b03e5Sespie 100: 15: c = 0; 382*c87b03e5Sespie@end smallexample 383*c87b03e5Sespie 384*c87b03e5SespieThe output shows that this block of code, combined by optimization, 385*c87b03e5Sespieexecuted 100 times. In one sense this result is correct, because there 386*c87b03e5Sespiewas only one instruction representing all four of these lines. However, 387*c87b03e5Sespiethe output does not indicate how many times the result was 0 and how 388*c87b03e5Sespiemany times the result was 1. 389*c87b03e5Sespie@c man end 390*c87b03e5Sespie 391*c87b03e5Sespie@node Gcov Data Files 392*c87b03e5Sespie@section Brief description of @command{gcov} data files 393*c87b03e5Sespie 394*c87b03e5Sespie@command{gcov} uses three files for doing profiling. The names of these 395*c87b03e5Sespiefiles are derived from the original @emph{source} file by substituting 396*c87b03e5Sespiethe file suffix with either @file{.bb}, @file{.bbg}, or @file{.da}. All 397*c87b03e5Sespieof these files are placed in the same directory as the source file, and 398*c87b03e5Sespiecontain data stored in a platform-independent method. 399*c87b03e5Sespie 400*c87b03e5SespieThe @file{.bb} and @file{.bbg} files are generated when the source file 401*c87b03e5Sespieis compiled with the GCC @option{-ftest-coverage} option. The 402*c87b03e5Sespie@file{.bb} file contains a list of source files (including headers), 403*c87b03e5Sespiefunctions within those files, and line numbers corresponding to each 404*c87b03e5Sespiebasic block in the source file. 405*c87b03e5Sespie 406*c87b03e5SespieThe @file{.bb} file format consists of several lists of 4-byte integers 407*c87b03e5Sespiewhich correspond to the line numbers of each basic block in the file. 408*c87b03e5SespieEach list is terminated by a line number of 0. A line number of 409*c87b03e5Sespie@minus{}1 is used to designate that the source file name (padded to a 410*c87b03e5Sespie4-byte boundary and followed by another @minus{}1) follows. In 411*c87b03e5Sespieaddition, a line number of @minus{}2 is used to designate that the name 412*c87b03e5Sespieof a function (also padded to a 4-byte boundary and followed by a 413*c87b03e5Sespie@minus{}2) follows. 414*c87b03e5Sespie 415*c87b03e5SespieThe @file{.bbg} file is used to reconstruct the program flow graph for 416*c87b03e5Sespiethe source file. It contains a list of the program flow arcs (possible 417*c87b03e5Sespiebranches taken from one basic block to another) for each function which, 418*c87b03e5Sespiein combination with the @file{.bb} file, enables gcov to reconstruct the 419*c87b03e5Sespieprogram flow. 420*c87b03e5Sespie 421*c87b03e5SespieIn the @file{.bbg} file, the format is: 422*c87b03e5Sespie@smallexample 423*c87b03e5Sespie name of function #0 424*c87b03e5Sespie checksum of function #0 425*c87b03e5Sespie number of basic blocks for function #0 (4-byte number) 426*c87b03e5Sespie total number of arcs for function #0 (4-byte number) 427*c87b03e5Sespie count of arcs in basic block #0 (4-byte number) 428*c87b03e5Sespie destination basic block of arc #0 (4-byte number) 429*c87b03e5Sespie flag bits (4-byte number) 430*c87b03e5Sespie destination basic block of arc #1 (4-byte number) 431*c87b03e5Sespie flag bits (4-byte number) 432*c87b03e5Sespie @dots{} 433*c87b03e5Sespie destination basic block of arc #N (4-byte number) 434*c87b03e5Sespie flag bits (4-byte number) 435*c87b03e5Sespie count of arcs in basic block #1 (4-byte number) 436*c87b03e5Sespie destination basic block of arc #0 (4-byte number) 437*c87b03e5Sespie flag bits (4-byte number) 438*c87b03e5Sespie @dots{} 439*c87b03e5Sespie@end smallexample 440*c87b03e5Sespie 441*c87b03e5SespieA @minus{}1 (stored as a 4-byte number) is used to separate each function's 442*c87b03e5Sespielist of basic blocks, and to verify that the file has been read 443*c87b03e5Sespiecorrectly. 444*c87b03e5Sespie 445*c87b03e5SespieThe function name is stored as a @minus{}1 (4 bytes), the length (4 bytes), 446*c87b03e5Sespiethe name itself (padded to 4-byte boundary) followed by a @minus{}1 (4 bytes). 447*c87b03e5Sespie 448*c87b03e5SespieThe flags are defined as follows: 449*c87b03e5Sespie@itemize 450*c87b03e5Sespie@item bit0 451*c87b03e5SespieOn function spanning tree 452*c87b03e5Sespie 453*c87b03e5Sespie@item bit1 454*c87b03e5SespieIs a fake edge 455*c87b03e5Sespie 456*c87b03e5Sespie@item bit2 457*c87b03e5SespieIs the fall through edge from one block to its immediate successor. 458*c87b03e5Sespie 459*c87b03e5Sespie@item bit3-bit31 460*c87b03e5SespieFor future expansion 461*c87b03e5Sespie 462*c87b03e5Sespie@end itemize 463*c87b03e5Sespie 464*c87b03e5SespieThe @file{.da} file is generated when a program containing object files 465*c87b03e5Sespiebuilt with the GCC @option{-fprofile-arcs} option is executed. A 466*c87b03e5Sespieseparate @file{.da} file is created for each source file compiled with 467*c87b03e5Sespiethis option, and the name of the @file{.da} file is stored as an 468*c87b03e5Sespieabsolute pathname in the resulting object file. This path name is 469*c87b03e5Sespiederived from the object file name by substituting a @file{.da} suffix. 470*c87b03e5Sespie 471*c87b03e5SespieThe @file{.da} consists of one or more blocks with the following 472*c87b03e5Sespiestructure: 473*c87b03e5Sespie@smallexample 474*c87b03e5Sespie "magic" number @minus{}123 (4-byte number) 475*c87b03e5Sespie number of functions (4-byte number) 476*c87b03e5Sespie length of the "extension block" in bytes 477*c87b03e5Sespie extension block (variable length) 478*c87b03e5Sespie name of function #0 (the same format as in .bbg file) 479*c87b03e5Sespie checksum of function #0 480*c87b03e5Sespie number of instrumented arcs (4-byte number) 481*c87b03e5Sespie count of arc #0 (8-byte number) 482*c87b03e5Sespie count of arc #1 (8-byte number) 483*c87b03e5Sespie @dots{} 484*c87b03e5Sespie count of arc #M_0 (8-byte number) 485*c87b03e5Sespie name of function #1 (the same format as in .bbg file) 486*c87b03e5Sespie checksum of function #1 487*c87b03e5Sespie @dots{} 488*c87b03e5Sespie@end smallexample 489*c87b03e5SespieMultiple program runs might merge data into a single block, or might 490*c87b03e5Sespieappend a new block. The current structure of the extension block is as 491*c87b03e5Sespiefollows: 492*c87b03e5Sespie@smallexample 493*c87b03e5Sespie number of instrumented arcs in whole program (4-byte number) 494*c87b03e5Sespie sum all of instrumented arcs in whole program (8-byte number) 495*c87b03e5Sespie maximal value of counter in whole program (8-byte number) 496*c87b03e5Sespie number of instrumented arcs in the object file (4-byte number) 497*c87b03e5Sespie sum all of instrumented arcs in the object file (8-byte number) 498*c87b03e5Sespie maximal value of counter in the object file (8-byte number) 499*c87b03e5Sespie@end smallexample 500*c87b03e5Sespie 501*c87b03e5SespieAll three of these files use the functions in @file{gcov-io.h} to store 502*c87b03e5Sespieintegers; the functions in this header provide a machine-independent 503*c87b03e5Sespiemechanism for storing and retrieving data from a stream. 504*c87b03e5Sespie 505