gcc50: Upgrade to GCC 5.1 release candidate plus
[dragonfly.git] / gnu / usr.bin / cc50 / drivers / gcov / gcov.1
1 .\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
49 .\" If the F register is turned on, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD.  Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .nr rF 0
58 .if \n(.g .if rF .nr rF 1
59 .if (\n(rF:(\n(.g==0)) \{
60 .    if \nF \{
61 .        de IX
62 .        tm Index:\\$1\t\\n%\t"\\$2"
63 ..
64 .        if !\nF==2 \{
65 .            nr % 0
66 .            nr F 2
67 .        \}
68 .    \}
69 .\}
70 .rr rF
71 .\"
72 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
73 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
74 .    \" fudge factors for nroff and troff
75 .if n \{\
76 .    ds #H 0
77 .    ds #V .8m
78 .    ds #F .3m
79 .    ds #[ \f1
80 .    ds #] \fP
81 .\}
82 .if t \{\
83 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
84 .    ds #V .6m
85 .    ds #F 0
86 .    ds #[ \&
87 .    ds #] \&
88 .\}
89 .    \" simple accents for nroff and troff
90 .if n \{\
91 .    ds ' \&
92 .    ds ` \&
93 .    ds ^ \&
94 .    ds , \&
95 .    ds ~ ~
96 .    ds /
97 .\}
98 .if t \{\
99 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
100 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
101 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
102 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
103 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
104 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
105 .\}
106 .    \" troff and (daisy-wheel) nroff accents
107 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
108 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
109 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
110 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
111 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
112 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
113 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
114 .ds ae a\h'-(\w'a'u*4/10)'e
115 .ds Ae A\h'-(\w'A'u*4/10)'E
116 .    \" corrections for vroff
117 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
118 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
119 .    \" for low resolution devices (crt and lpr)
120 .if \n(.H>23 .if \n(.V>19 \
121 \{\
122 .    ds : e
123 .    ds 8 ss
124 .    ds o a
125 .    ds d- d\h'-1'\(ga
126 .    ds D- D\h'-1'\(hy
127 .    ds th \o'bp'
128 .    ds Th \o'LP'
129 .    ds ae ae
130 .    ds Ae AE
131 .\}
132 .rm #[ #] #H #V #F C
133 .\" ========================================================================
134 .\"
135 .IX Title "GCOV 1"
136 .TH GCOV 1 "2015-04-12" "gcc-5.0.1" "GNU"
137 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
138 .\" way too many mistakes in technical documents.
139 .if n .ad l
140 .nh
141 .SH "NAME"
142 gcov \- coverage testing tool
143 .SH "SYNOPSIS"
144 .IX Header "SYNOPSIS"
145 gcov [\fB\-v\fR|\fB\-\-version\fR] [\fB\-h\fR|\fB\-\-help\fR]
146      [\fB\-a\fR|\fB\-\-all\-blocks\fR]
147      [\fB\-b\fR|\fB\-\-branch\-probabilities\fR]
148      [\fB\-c\fR|\fB\-\-branch\-counts\fR]
149      [\fB\-d\fR|\fB\-\-display\-progress\fR]
150      [\fB\-f\fR|\fB\-\-function\-summaries\fR]
151      [\fB\-i\fR|\fB\-\-intermediate\-format\fR]
152      [\fB\-l\fR|\fB\-\-long\-file\-names\fR]
153      [\fB\-m\fR|\fB\-\-demangled\-names\fR]
154      [\fB\-n\fR|\fB\-\-no\-output\fR]
155      [\fB\-o\fR|\fB\-\-object\-directory\fR \fIdirectory|file\fR]
156      [\fB\-p\fR|\fB\-\-preserve\-paths\fR]
157      [\fB\-r\fR|\fB\-\-relative\-only\fR]
158      [\fB\-s\fR|\fB\-\-source\-prefix\fR \fIdirectory\fR]
159      [\fB\-u\fR|\fB\-\-unconditional\-branches\fR]
160      \fIfiles\fR
161 .SH "DESCRIPTION"
162 .IX Header "DESCRIPTION"
163 \&\fBgcov\fR is a test coverage program.  Use it in concert with \s-1GCC\s0
164 to analyze your programs to help create more efficient, faster running
165 code and to discover untested parts of your program.  You can use
166 \&\fBgcov\fR as a profiling tool to help discover where your
167 optimization efforts will best affect your code.  You can also use
168 \&\fBgcov\fR along with the other profiling tool, \fBgprof\fR, to
169 assess which parts of your code use the greatest amount of computing
170 time.
171 .PP
172 Profiling tools help you analyze your code's performance.  Using a
173 profiler such as \fBgcov\fR or \fBgprof\fR, you can find out some
174 basic performance statistics, such as:
175 .IP "*" 4
176 how often each line of code executes
177 .IP "*" 4
178 what lines of code are actually executed
179 .IP "*" 4
180 how much computing time each section of code uses
181 .PP
182 Once you know these things about how your code works when compiled, you
183 can look at each module to see which modules should be optimized.
184 \&\fBgcov\fR helps you determine where to work on optimization.
185 .PP
186 Software developers also use coverage testing in concert with
187 testsuites, to make sure software is actually good enough for a release.
188 Testsuites can verify that a program works as expected; a coverage
189 program tests to see how much of the program is exercised by the
190 testsuite.  Developers can then determine what kinds of test cases need
191 to be added to the testsuites to create both better testing and a better
192 final product.
193 .PP
194 You should compile your code without optimization if you plan to use
195 \&\fBgcov\fR because the optimization, by combining some lines of code
196 into one function, may not give you as much information as you need to
197 look for `hot spots' where the code is using a great deal of computer
198 time.  Likewise, because \fBgcov\fR accumulates statistics by line (at
199 the lowest resolution), it works best with a programming style that
200 places only one statement on each line.  If you use complicated macros
201 that expand to loops or to other control structures, the statistics are
202 less helpful\-\-\-they only report on the line where the macro call
203 appears.  If your complex macros behave like functions, you can replace
204 them with inline functions to solve this problem.
205 .PP
206 \&\fBgcov\fR creates a logfile called \fI\fIsourcefile\fI.gcov\fR which
207 indicates how many times each line of a source file \fI\fIsourcefile\fI.c\fR
208 has executed.  You can use these logfiles along with \fBgprof\fR to aid
209 in fine-tuning the performance of your programs.  \fBgprof\fR gives
210 timing information you can use along with the information you get from
211 \&\fBgcov\fR.
212 .PP
213 \&\fBgcov\fR works only on code compiled with \s-1GCC. \s0 It is not
214 compatible with any other profiling or test coverage mechanism.
215 .SH "OPTIONS"
216 .IX Header "OPTIONS"
217 .IP "\fB\-h\fR" 4
218 .IX Item "-h"
219 .PD 0
220 .IP "\fB\-\-help\fR" 4
221 .IX Item "--help"
222 .PD
223 Display help about using \fBgcov\fR (on the standard output), and
224 exit without doing any further processing.
225 .IP "\fB\-v\fR" 4
226 .IX Item "-v"
227 .PD 0
228 .IP "\fB\-\-version\fR" 4
229 .IX Item "--version"
230 .PD
231 Display the \fBgcov\fR version number (on the standard output),
232 and exit without doing any further processing.
233 .IP "\fB\-a\fR" 4
234 .IX Item "-a"
235 .PD 0
236 .IP "\fB\-\-all\-blocks\fR" 4
237 .IX Item "--all-blocks"
238 .PD
239 Write individual execution counts for every basic block.  Normally gcov
240 outputs execution counts only for the main blocks of a line.  With this
241 option you can determine if blocks within a single line are not being
242 executed.
243 .IP "\fB\-b\fR" 4
244 .IX Item "-b"
245 .PD 0
246 .IP "\fB\-\-branch\-probabilities\fR" 4
247 .IX Item "--branch-probabilities"
248 .PD
249 Write branch frequencies to the output file, and write branch summary
250 info to the standard output.  This option allows you to see how often
251 each branch in your program was taken.  Unconditional branches will not
252 be shown, unless the \fB\-u\fR option is given.
253 .IP "\fB\-c\fR" 4
254 .IX Item "-c"
255 .PD 0
256 .IP "\fB\-\-branch\-counts\fR" 4
257 .IX Item "--branch-counts"
258 .PD
259 Write branch frequencies as the number of branches taken, rather than
260 the percentage of branches taken.
261 .IP "\fB\-n\fR" 4
262 .IX Item "-n"
263 .PD 0
264 .IP "\fB\-\-no\-output\fR" 4
265 .IX Item "--no-output"
266 .PD
267 Do not create the \fBgcov\fR output file.
268 .IP "\fB\-l\fR" 4
269 .IX Item "-l"
270 .PD 0
271 .IP "\fB\-\-long\-file\-names\fR" 4
272 .IX Item "--long-file-names"
273 .PD
274 Create long file names for included source files.  For example, if the
275 header file \fIx.h\fR contains code, and was included in the file
276 \&\fIa.c\fR, then running \fBgcov\fR on the file \fIa.c\fR will
277 produce an output file called \fIa.c##x.h.gcov\fR instead of
278 \&\fIx.h.gcov\fR.  This can be useful if \fIx.h\fR is included in
279 multiple source files and you want to see the individual
280 contributions.  If you use the \fB\-p\fR option, both the including
281 and included file names will be complete path names.
282 .IP "\fB\-p\fR" 4
283 .IX Item "-p"
284 .PD 0
285 .IP "\fB\-\-preserve\-paths\fR" 4
286 .IX Item "--preserve-paths"
287 .PD
288 Preserve complete path information in the names of generated
289 \&\fI.gcov\fR files.  Without this option, just the filename component is
290 used.  With this option, all directories are used, with \fB/\fR characters
291 translated to \fB#\fR characters, \fI.\fR directory components
292 removed and unremoveable \fI..\fR
293 components renamed to \fB^\fR.  This is useful if sourcefiles are in several
294 different directories.
295 .IP "\fB\-r\fR" 4
296 .IX Item "-r"
297 .PD 0
298 .IP "\fB\-\-relative\-only\fR" 4
299 .IX Item "--relative-only"
300 .PD
301 Only output information about source files with a relative pathname
302 (after source prefix elision).  Absolute paths are usually system
303 header files and coverage of any inline functions therein is normally
304 uninteresting.
305 .IP "\fB\-f\fR" 4
306 .IX Item "-f"
307 .PD 0
308 .IP "\fB\-\-function\-summaries\fR" 4
309 .IX Item "--function-summaries"
310 .PD
311 Output summaries for each function in addition to the file level summary.
312 .IP "\fB\-o\fR \fIdirectory|file\fR" 4
313 .IX Item "-o directory|file"
314 .PD 0
315 .IP "\fB\-\-object\-directory\fR \fIdirectory\fR" 4
316 .IX Item "--object-directory directory"
317 .IP "\fB\-\-object\-file\fR \fIfile\fR" 4
318 .IX Item "--object-file file"
319 .PD
320 Specify either the directory containing the gcov data files, or the
321 object path name.  The \fI.gcno\fR, and
322 \&\fI.gcda\fR data files are searched for using this option.  If a directory
323 is specified, the data files are in that directory and named after the
324 input file name, without its extension.  If a file is specified here,
325 the data files are named after that file, without its extension.
326 .IP "\fB\-s\fR \fIdirectory\fR" 4
327 .IX Item "-s directory"
328 .PD 0
329 .IP "\fB\-\-source\-prefix\fR \fIdirectory\fR" 4
330 .IX Item "--source-prefix directory"
331 .PD
332 A prefix for source file names to remove when generating the output
333 coverage files.  This option is useful when building in a separate
334 directory, and the pathname to the source directory is not wanted when
335 determining the output file names.  Note that this prefix detection is
336 applied before determining whether the source file is absolute.
337 .IP "\fB\-u\fR" 4
338 .IX Item "-u"
339 .PD 0
340 .IP "\fB\-\-unconditional\-branches\fR" 4
341 .IX Item "--unconditional-branches"
342 .PD
343 When branch probabilities are given, include those of unconditional branches.
344 Unconditional branches are normally not interesting.
345 .IP "\fB\-d\fR" 4
346 .IX Item "-d"
347 .PD 0
348 .IP "\fB\-\-display\-progress\fR" 4
349 .IX Item "--display-progress"
350 .PD
351 Display the progress on the standard output.
352 .IP "\fB\-i\fR" 4
353 .IX Item "-i"
354 .PD 0
355 .IP "\fB\-\-intermediate\-format\fR" 4
356 .IX Item "--intermediate-format"
357 .PD
358 Output gcov file in an easy-to-parse intermediate text format that can
359 be used by \fBlcov\fR or other tools. The output is a single
360 \&\fI.gcov\fR file per \fI.gcda\fR file. No source code is required.
361 .Sp
362 The format of the intermediate \fI.gcov\fR file is plain text with
363 one entry per line
364 .Sp
365 .Vb 4
366 \&        file:<source_file_name>
367 \&        function:<line_number>,<execution_count>,<function_name>
368 \&        lcount:<line number>,<execution_count>
369 \&        branch:<line_number>,<branch_coverage_type>
370 \&        
371 \&        Where the <branch_coverage_type> is
372 \&           notexec (Branch not executed)
373 \&           taken (Branch executed and taken)
374 \&           nottaken (Branch executed, but not taken)
375 \&        
376 \&        There can be multiple <file> entries in an intermediate gcov
377 \&        file. All entries following a <file> pertain to that source file
378 \&        until the next <file> entry.
379 .Ve
380 .Sp
381 Here is a sample when \fB\-i\fR is used in conjunction with \fB\-b\fR option:
382 .Sp
383 .Vb 9
384 \&        file:array.cc
385 \&        function:11,1,_Z3sumRKSt6vectorIPiSaIS0_EE
386 \&        function:22,1,main
387 \&        lcount:11,1
388 \&        lcount:12,1
389 \&        lcount:14,1
390 \&        branch:14,taken
391 \&        lcount:26,1
392 \&        branch:28,nottaken
393 .Ve
394 .IP "\fB\-m\fR" 4
395 .IX Item "-m"
396 .PD 0
397 .IP "\fB\-\-demangled\-names\fR" 4
398 .IX Item "--demangled-names"
399 .PD
400 Display demangled function names in output. The default is to show
401 mangled function names.
402 .PP
403 \&\fBgcov\fR should be run with the current directory the same as that
404 when you invoked the compiler.  Otherwise it will not be able to locate
405 the source files.  \fBgcov\fR produces files called
406 \&\fI\fImangledname\fI.gcov\fR in the current directory.  These contain
407 the coverage information of the source file they correspond to.
408 One \fI.gcov\fR file is produced for each source (or header) file
409 containing code,
410 which was compiled to produce the data files.  The \fImangledname\fR part
411 of the output file name is usually simply the source file name, but can
412 be something more complicated if the \fB\-l\fR or \fB\-p\fR options are
413 given.  Refer to those options for details.
414 .PP
415 If you invoke \fBgcov\fR with multiple input files, the
416 contributions from each input file are summed.  Typically you would
417 invoke it with the same list of files as the final link of your executable.
418 .PP
419 The \fI.gcov\fR files contain the \fB:\fR separated fields along with
420 program source code.  The format is
421 .PP
422 .Vb 1
423 \&        <execution_count>:<line_number>:<source line text>
424 .Ve
425 .PP
426 Additional block information may succeed each line, when requested by
427 command line option.  The \fIexecution_count\fR is \fB\-\fR for lines
428 containing no code.  Unexecuted lines are marked \fB#####\fR or
429 \&\fB====\fR, depending on whether they are reachable by
430 non-exceptional paths or only exceptional paths such as \*(C+ exception
431 handlers, respectively.
432 .PP
433 Some lines of information at the start have \fIline_number\fR of zero.
434 These preamble lines are of the form
435 .PP
436 .Vb 1
437 \&        \-:0:<tag>:<value>
438 .Ve
439 .PP
440 The ordering and number of these preamble lines will be augmented as
441 \&\fBgcov\fR development progresses \-\-\- do not rely on them remaining
442 unchanged.  Use \fItag\fR to locate a particular preamble line.
443 .PP
444 The additional block information is of the form
445 .PP
446 .Vb 1
447 \&        <tag> <information>
448 .Ve
449 .PP
450 The \fIinformation\fR is human readable, but designed to be simple
451 enough for machine parsing too.
452 .PP
453 When printing percentages, 0% and 100% are only printed when the values
454 are \fIexactly\fR 0% and 100% respectively.  Other values which would
455 conventionally be rounded to 0% or 100% are instead printed as the
456 nearest non-boundary value.
457 .PP
458 When using \fBgcov\fR, you must first compile your program with two
459 special \s-1GCC\s0 options: \fB\-fprofile\-arcs \-ftest\-coverage\fR.
460 This tells the compiler to generate additional information needed by
461 gcov (basically a flow graph of the program) and also includes
462 additional code in the object files for generating the extra profiling
463 information needed by gcov.  These additional files are placed in the
464 directory where the object file is located.
465 .PP
466 Running the program will cause profile output to be generated.  For each
467 source file compiled with \fB\-fprofile\-arcs\fR, an accompanying
468 \&\fI.gcda\fR file will be placed in the object file directory.
469 .PP
470 Running \fBgcov\fR with your program's source file names as arguments
471 will now produce a listing of the code along with frequency of execution
472 for each line.  For example, if your program is called \fItmp.c\fR, this
473 is what you see when you use the basic \fBgcov\fR facility:
474 .PP
475 .Vb 5
476 \&        $ gcc \-fprofile\-arcs \-ftest\-coverage tmp.c
477 \&        $ a.out
478 \&        $ gcov tmp.c
479 \&        90.00% of 10 source lines executed in file tmp.c
480 \&        Creating tmp.c.gcov.
481 .Ve
482 .PP
483 The file \fItmp.c.gcov\fR contains output from \fBgcov\fR.
484 Here is a sample:
485 .PP
486 .Vb 10
487 \&                \-:    0:Source:tmp.c
488 \&                \-:    0:Graph:tmp.gcno
489 \&                \-:    0:Data:tmp.gcda
490 \&                \-:    0:Runs:1
491 \&                \-:    0:Programs:1
492 \&                \-:    1:#include <stdio.h>
493 \&                \-:    2:
494 \&                \-:    3:int main (void)
495 \&                1:    4:{
496 \&                1:    5:  int i, total;
497 \&                \-:    6:
498 \&                1:    7:  total = 0;
499 \&                \-:    8:
500 \&               11:    9:  for (i = 0; i < 10; i++)
501 \&               10:   10:    total += i;
502 \&                \-:   11:
503 \&                1:   12:  if (total != 45)
504 \&            #####:   13:    printf ("Failure\en");
505 \&                \-:   14:  else
506 \&                1:   15:    printf ("Success\en");
507 \&                1:   16:  return 0;
508 \&                \-:   17:}
509 .Ve
510 .PP
511 When you use the \fB\-a\fR option, you will get individual block
512 counts, and the output looks like this:
513 .PP
514 .Vb 10
515 \&                \-:    0:Source:tmp.c
516 \&                \-:    0:Graph:tmp.gcno
517 \&                \-:    0:Data:tmp.gcda
518 \&                \-:    0:Runs:1
519 \&                \-:    0:Programs:1
520 \&                \-:    1:#include <stdio.h>
521 \&                \-:    2:
522 \&                \-:    3:int main (void)
523 \&                1:    4:{
524 \&                1:    4\-block  0
525 \&                1:    5:  int i, total;
526 \&                \-:    6:
527 \&                1:    7:  total = 0;
528 \&                \-:    8:
529 \&               11:    9:  for (i = 0; i < 10; i++)
530 \&               11:    9\-block  0
531 \&               10:   10:    total += i;
532 \&               10:   10\-block  0
533 \&                \-:   11:
534 \&                1:   12:  if (total != 45)
535 \&                1:   12\-block  0
536 \&            #####:   13:    printf ("Failure\en");
537 \&            $$$$$:   13\-block  0
538 \&                \-:   14:  else
539 \&                1:   15:    printf ("Success\en");
540 \&                1:   15\-block  0
541 \&                1:   16:  return 0;
542 \&                1:   16\-block  0
543 \&                \-:   17:}
544 .Ve
545 .PP
546 In this mode, each basic block is only shown on one line \*(-- the last
547 line of the block.  A multi-line block will only contribute to the
548 execution count of that last line, and other lines will not be shown
549 to contain code, unless previous blocks end on those lines.
550 The total execution count of a line is shown and subsequent lines show
551 the execution counts for individual blocks that end on that line.  After each
552 block, the branch and call counts of the block will be shown, if the
553 \&\fB\-b\fR option is given.
554 .PP
555 Because of the way \s-1GCC\s0 instruments calls, a call count can be shown
556 after a line with no individual blocks.
557 As you can see, line 13 contains a basic block that was not executed.
558 .PP
559 When you use the \fB\-b\fR option, your output looks like this:
560 .PP
561 .Vb 6
562 \&        $ gcov \-b tmp.c
563 \&        90.00% of 10 source lines executed in file tmp.c
564 \&        80.00% of 5 branches executed in file tmp.c
565 \&        80.00% of 5 branches taken at least once in file tmp.c
566 \&        50.00% of 2 calls executed in file tmp.c
567 \&        Creating tmp.c.gcov.
568 .Ve
569 .PP
570 Here is a sample of a resulting \fItmp.c.gcov\fR file:
571 .PP
572 .Vb 10
573 \&                \-:    0:Source:tmp.c
574 \&                \-:    0:Graph:tmp.gcno
575 \&                \-:    0:Data:tmp.gcda
576 \&                \-:    0:Runs:1
577 \&                \-:    0:Programs:1
578 \&                \-:    1:#include <stdio.h>
579 \&                \-:    2:
580 \&                \-:    3:int main (void)
581 \&        function main called 1 returned 1 blocks executed 75%
582 \&                1:    4:{
583 \&                1:    5:  int i, total;
584 \&                \-:    6:
585 \&                1:    7:  total = 0;
586 \&                \-:    8:
587 \&               11:    9:  for (i = 0; i < 10; i++)
588 \&        branch  0 taken 91% (fallthrough)
589 \&        branch  1 taken 9%
590 \&               10:   10:    total += i;
591 \&                \-:   11:
592 \&                1:   12:  if (total != 45)
593 \&        branch  0 taken 0% (fallthrough)
594 \&        branch  1 taken 100%
595 \&            #####:   13:    printf ("Failure\en");
596 \&        call    0 never executed
597 \&                \-:   14:  else
598 \&                1:   15:    printf ("Success\en");
599 \&        call    0 called 1 returned 100%
600 \&                1:   16:  return 0;
601 \&                \-:   17:}
602 .Ve
603 .PP
604 For each function, a line is printed showing how many times the function
605 is called, how many times it returns and what percentage of the
606 function's blocks were executed.
607 .PP
608 For each basic block, a line is printed after the last line of the basic
609 block describing the branch or call that ends the basic block.  There can
610 be multiple branches and calls listed for a single source line if there
611 are multiple basic blocks that end on that line.  In this case, the
612 branches and calls are each given a number.  There is no simple way to map
613 these branches and calls back to source constructs.  In general, though,
614 the lowest numbered branch or call will correspond to the leftmost construct
615 on the source line.
616 .PP
617 For a branch, if it was executed at least once, then a percentage
618 indicating the number of times the branch was taken divided by the
619 number of times the branch was executed will be printed.  Otherwise, the
620 message \*(L"never executed\*(R" is printed.
621 .PP
622 For a call, if it was executed at least once, then a percentage
623 indicating the number of times the call returned divided by the number
624 of times the call was executed will be printed.  This will usually be
625 100%, but may be less for functions that call \f(CW\*(C`exit\*(C'\fR or \f(CW\*(C`longjmp\*(C'\fR,
626 and thus may not return every time they are called.
627 .PP
628 The execution counts are cumulative.  If the example program were
629 executed again without removing the \fI.gcda\fR file, the count for the
630 number of times each line in the source was executed would be added to
631 the results of the previous run(s).  This is potentially useful in
632 several ways.  For example, it could be used to accumulate data over a
633 number of program runs as part of a test verification suite, or to
634 provide more accurate long-term information over a large number of
635 program runs.
636 .PP
637 The data in the \fI.gcda\fR files is saved immediately before the program
638 exits.  For each source file compiled with \fB\-fprofile\-arcs\fR, the
639 profiling code first attempts to read in an existing \fI.gcda\fR file; if
640 the file doesn't match the executable (differing number of basic block
641 counts) it will ignore the contents of the file.  It then adds in the
642 new execution counts and finally writes the data to the file.
643 .SS "Using \fBgcov\fP with \s-1GCC\s0 Optimization"
644 .IX Subsection "Using gcov with GCC Optimization"
645 If you plan to use \fBgcov\fR to help optimize your code, you must
646 first compile your program with two special \s-1GCC\s0 options:
647 \&\fB\-fprofile\-arcs \-ftest\-coverage\fR.  Aside from that, you can use any
648 other \s-1GCC\s0 options; but if you want to prove that every single line
649 in your program was executed, you should not compile with optimization
650 at the same time.  On some machines the optimizer can eliminate some
651 simple code lines by combining them with other lines.  For example, code
652 like this:
653 .PP
654 .Vb 4
655 \&        if (a != b)
656 \&          c = 1;
657 \&        else
658 \&          c = 0;
659 .Ve
660 .PP
661 can be compiled into one instruction on some machines.  In this case,
662 there is no way for \fBgcov\fR to calculate separate execution counts
663 for each line because there isn't separate code for each line.  Hence
664 the \fBgcov\fR output looks like this if you compiled the program with
665 optimization:
666 .PP
667 .Vb 4
668 \&              100:   12:if (a != b)
669 \&              100:   13:  c = 1;
670 \&              100:   14:else
671 \&              100:   15:  c = 0;
672 .Ve
673 .PP
674 The output shows that this block of code, combined by optimization,
675 executed 100 times.  In one sense this result is correct, because there
676 was only one instruction representing all four of these lines.  However,
677 the output does not indicate how many times the result was 0 and how
678 many times the result was 1.
679 .PP
680 Inlineable functions can create unexpected line counts.  Line counts are
681 shown for the source code of the inlineable function, but what is shown
682 depends on where the function is inlined, or if it is not inlined at all.
683 .PP
684 If the function is not inlined, the compiler must emit an out of line
685 copy of the function, in any object file that needs it.  If
686 \&\fIfileA.o\fR and \fIfileB.o\fR both contain out of line bodies of a
687 particular inlineable function, they will also both contain coverage
688 counts for that function.  When \fIfileA.o\fR and \fIfileB.o\fR are
689 linked together, the linker will, on many systems, select one of those
690 out of line bodies for all calls to that function, and remove or ignore
691 the other.  Unfortunately, it will not remove the coverage counters for
692 the unused function body.  Hence when instrumented, all but one use of
693 that function will show zero counts.
694 .PP
695 If the function is inlined in several places, the block structure in
696 each location might not be the same.  For instance, a condition might
697 now be calculable at compile time in some instances.  Because the
698 coverage of all the uses of the inline function will be shown for the
699 same source lines, the line counts themselves might seem inconsistent.
700 .PP
701 Long-running applications can use the \f(CW\*(C`_gcov_reset\*(C'\fR and \f(CW\*(C`_gcov_dump\*(C'\fR
702 facilities to restrict profile collection to the program region of
703 interest. Calling \f(CW\*(C`_gcov_reset(void)\*(C'\fR will clear all profile counters
704 to zero, and calling \f(CW\*(C`_gcov_dump(void)\*(C'\fR will cause the profile information
705 collected at that point to be dumped to \fI.gcda\fR output files.
706 .SH "SEE ALSO"
707 .IX Header "SEE ALSO"
708 \&\fIgpl\fR\|(7), \fIgfdl\fR\|(7), \fIfsf\-funding\fR\|(7), \fIgcc\fR\|(1) and the Info entry for \fIgcc\fR.
709 .SH "COPYRIGHT"
710 .IX Header "COPYRIGHT"
711 Copyright (c) 1996\-2015 Free Software Foundation, Inc.
712 .PP
713 Permission is granted to copy, distribute and/or modify this document
714 under the terms of the \s-1GNU\s0 Free Documentation License, Version 1.3 or
715 any later version published by the Free Software Foundation; with the
716 Invariant Sections being \*(L"\s-1GNU\s0 General Public License\*(R" and \*(L"Funding
717 Free Software\*(R", the Front-Cover texts being (a) (see below), and with
718 the Back-Cover Texts being (b) (see below).  A copy of the license is
719 included in the \fIgfdl\fR\|(7) man page.
720 .PP
721 (a) The \s-1FSF\s0's Front-Cover Text is:
722 .PP
723 .Vb 1
724 \&     A GNU Manual
725 .Ve
726 .PP
727 (b) The \s-1FSF\s0's Back-Cover Text is:
728 .PP
729 .Vb 3
730 \&     You have freedom to copy and modify this GNU Manual, like GNU
731 \&     software.  Copies published by the Free Software Foundation raise
732 \&     funds for GNU development.
733 .Ve