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