More gcc80 adjustments.
[dragonfly.git] / gnu / usr.bin / cc80 / drivers / gcov / gcov.1
1 .\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35)
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 >0, 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 .if !\nF .nr F 0
58 .if \nF>0 \{\
59 .    de IX
60 .    tm Index:\\$1\t\\n%\t"\\$2"
61 ..
62 .    if !\nF==2 \{\
63 .        nr % 0
64 .        nr F 2
65 .    \}
66 .\}
67 .\"
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70 .    \" fudge factors for nroff and troff
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
95 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101 .\}
102 .    \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 .    \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 .    \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
117 \{\
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
127 .\}
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
130 .\"
131 .IX Title "GCOV 1"
132 .TH GCOV 1 "2018-05-02" "gcc-8.1.0" "GNU"
133 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
134 .\" way too many mistakes in technical documents.
135 .if n .ad l
136 .nh
137 .SH "NAME"
138 gcov \- coverage testing tool
139 .SH "SYNOPSIS"
140 .IX Header "SYNOPSIS"
141 gcov [\fB\-v\fR|\fB\-\-version\fR] [\fB\-h\fR|\fB\-\-help\fR]
142      [\fB\-a\fR|\fB\-\-all\-blocks\fR]
143      [\fB\-b\fR|\fB\-\-branch\-probabilities\fR]
144      [\fB\-c\fR|\fB\-\-branch\-counts\fR]
145      [\fB\-d\fR|\fB\-\-display\-progress\fR]
146      [\fB\-f\fR|\fB\-\-function\-summaries\fR]
147      [\fB\-i\fR|\fB\-\-intermediate\-format\fR]
148      [\fB\-j\fR|\fB\-\-human\-readable\fR]
149      [\fB\-k\fR|\fB\-\-use\-colors\fR]
150      [\fB\-l\fR|\fB\-\-long\-file\-names\fR]
151      [\fB\-m\fR|\fB\-\-demangled\-names\fR]
152      [\fB\-n\fR|\fB\-\-no\-output\fR]
153      [\fB\-o\fR|\fB\-\-object\-directory\fR \fIdirectory|file\fR]
154      [\fB\-p\fR|\fB\-\-preserve\-paths\fR]
155      [\fB\-r\fR|\fB\-\-relative\-only\fR]
156      [\fB\-s\fR|\fB\-\-source\-prefix\fR \fIdirectory\fR]
157      [\fB\-u\fR|\fB\-\-unconditional\-branches\fR]
158      [\fB\-x\fR|\fB\-\-hash\-filenames\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\-a\fR" 4
217 .IX Item "-a"
218 .PD 0
219 .IP "\fB\-\-all\-blocks\fR" 4
220 .IX Item "--all-blocks"
221 .PD
222 Write individual execution counts for every basic block.  Normally gcov
223 outputs execution counts only for the main blocks of a line.  With this
224 option you can determine if blocks within a single line are not being
225 executed.
226 .IP "\fB\-b\fR" 4
227 .IX Item "-b"
228 .PD 0
229 .IP "\fB\-\-branch\-probabilities\fR" 4
230 .IX Item "--branch-probabilities"
231 .PD
232 Write branch frequencies to the output file, and write branch summary
233 info to the standard output.  This option allows you to see how often
234 each branch in your program was taken.  Unconditional branches will not
235 be shown, unless the \fB\-u\fR option is given.
236 .IP "\fB\-c\fR" 4
237 .IX Item "-c"
238 .PD 0
239 .IP "\fB\-\-branch\-counts\fR" 4
240 .IX Item "--branch-counts"
241 .PD
242 Write branch frequencies as the number of branches taken, rather than
243 the percentage of branches taken.
244 .IP "\fB\-d\fR" 4
245 .IX Item "-d"
246 .PD 0
247 .IP "\fB\-\-display\-progress\fR" 4
248 .IX Item "--display-progress"
249 .PD
250 Display the progress on the standard output.
251 .IP "\fB\-f\fR" 4
252 .IX Item "-f"
253 .PD 0
254 .IP "\fB\-\-function\-summaries\fR" 4
255 .IX Item "--function-summaries"
256 .PD
257 Output summaries for each function in addition to the file level summary.
258 .IP "\fB\-h\fR" 4
259 .IX Item "-h"
260 .PD 0
261 .IP "\fB\-\-help\fR" 4
262 .IX Item "--help"
263 .PD
264 Display help about using \fBgcov\fR (on the standard output), and
265 exit without doing any further processing.
266 .IP "\fB\-i\fR" 4
267 .IX Item "-i"
268 .PD 0
269 .IP "\fB\-\-intermediate\-format\fR" 4
270 .IX Item "--intermediate-format"
271 .PD
272 Output gcov file in an easy-to-parse intermediate text format that can
273 be used by \fBlcov\fR or other tools. The output is a single
274 \&\fI.gcov\fR file per \fI.gcda\fR file. No source code is required.
275 .Sp
276 The format of the intermediate \fI.gcov\fR file is plain text with
277 one entry per line
278 .Sp
279 .Vb 5
280 \&        version:<gcc_version>
281 \&        file:<source_file_name>
282 \&        function:<start_line_number>,<end_line_number>,<execution_count>,<function_name>
283 \&        lcount:<line number>,<execution_count>,<has_unexecuted_block>
284 \&        branch:<line_number>,<branch_coverage_type>
285 \&        
286 \&        Where the <branch_coverage_type> is
287 \&           notexec (Branch not executed)
288 \&           taken (Branch executed and taken)
289 \&           nottaken (Branch executed, but not taken)
290 .Ve
291 .Sp
292 There can be multiple \fIfile\fR entries in an intermediate gcov
293 file. All entries following a \fIfile\fR pertain to that source file
294 until the next \fIfile\fR entry.  If there are multiple functions that
295 start on a single line, then corresponding lcount is repeated multiple
296 times.
297 .Sp
298 Here is a sample when \fB\-i\fR is used in conjunction with \fB\-b\fR option:
299 .Sp
300 .Vb 10
301 \&        version: 8.1.0 20180103
302 \&        file:tmp.cpp
303 \&        function:7,7,0,_ZN3FooIcEC2Ev
304 \&        function:7,7,1,_ZN3FooIiEC2Ev
305 \&        function:8,8,0,_ZN3FooIcE3incEv
306 \&        function:8,8,2,_ZN3FooIiE3incEv
307 \&        function:18,37,1,main
308 \&        lcount:7,0,1
309 \&        lcount:7,1,0
310 \&        lcount:8,0,1
311 \&        lcount:8,2,0
312 \&        lcount:18,1,0
313 \&        lcount:21,1,0
314 \&        branch:21,taken
315 \&        branch:21,nottaken
316 \&        lcount:23,1,0
317 \&        branch:23,taken
318 \&        branch:23,nottaken
319 \&        lcount:24,1,0
320 \&        branch:24,taken
321 \&        branch:24,nottaken
322 \&        lcount:25,1,0
323 \&        lcount:27,11,0
324 \&        branch:27,taken
325 \&        branch:27,taken
326 \&        lcount:28,10,0
327 \&        lcount:30,1,1
328 \&        branch:30,nottaken
329 \&        branch:30,taken
330 \&        lcount:32,1,0
331 \&        branch:32,nottaken
332 \&        branch:32,taken
333 \&        lcount:33,0,1
334 \&        branch:33,notexec
335 \&        branch:33,notexec
336 \&        lcount:35,1,0
337 \&        branch:35,taken
338 \&        branch:35,nottaken
339 \&        lcount:36,1,0
340 .Ve
341 .IP "\fB\-j\fR" 4
342 .IX Item "-j"
343 .PD 0
344 .IP "\fB\-\-human\-readable\fR" 4
345 .IX Item "--human-readable"
346 .PD
347 Write counts in human readable format (like 24k).
348 .IP "\fB\-k\fR" 4
349 .IX Item "-k"
350 .PD 0
351 .IP "\fB\-\-use\-colors\fR" 4
352 .IX Item "--use-colors"
353 .PD
354 Use colors for lines of code that have zero coverage.  We use red color for
355 non-exceptional lines and cyan for exceptional.  Same colors are used for
356 basic blocks with \fB\-a\fR option.
357 .IP "\fB\-l\fR" 4
358 .IX Item "-l"
359 .PD 0
360 .IP "\fB\-\-long\-file\-names\fR" 4
361 .IX Item "--long-file-names"
362 .PD
363 Create long file names for included source files.  For example, if the
364 header file \fIx.h\fR contains code, and was included in the file
365 \&\fIa.c\fR, then running \fBgcov\fR on the file \fIa.c\fR will
366 produce an output file called \fIa.c##x.h.gcov\fR instead of
367 \&\fIx.h.gcov\fR.  This can be useful if \fIx.h\fR is included in
368 multiple source files and you want to see the individual
369 contributions.  If you use the \fB\-p\fR option, both the including
370 and included file names will be complete path names.
371 .IP "\fB\-m\fR" 4
372 .IX Item "-m"
373 .PD 0
374 .IP "\fB\-\-demangled\-names\fR" 4
375 .IX Item "--demangled-names"
376 .PD
377 Display demangled function names in output. The default is to show
378 mangled function names.
379 .IP "\fB\-n\fR" 4
380 .IX Item "-n"
381 .PD 0
382 .IP "\fB\-\-no\-output\fR" 4
383 .IX Item "--no-output"
384 .PD
385 Do not create the \fBgcov\fR output file.
386 .IP "\fB\-o\fR \fIdirectory|file\fR" 4
387 .IX Item "-o directory|file"
388 .PD 0
389 .IP "\fB\-\-object\-directory\fR \fIdirectory\fR" 4
390 .IX Item "--object-directory directory"
391 .IP "\fB\-\-object\-file\fR \fIfile\fR" 4
392 .IX Item "--object-file file"
393 .PD
394 Specify either the directory containing the gcov data files, or the
395 object path name.  The \fI.gcno\fR, and
396 \&\fI.gcda\fR data files are searched for using this option.  If a directory
397 is specified, the data files are in that directory and named after the
398 input file name, without its extension.  If a file is specified here,
399 the data files are named after that file, without its extension.
400 .IP "\fB\-p\fR" 4
401 .IX Item "-p"
402 .PD 0
403 .IP "\fB\-\-preserve\-paths\fR" 4
404 .IX Item "--preserve-paths"
405 .PD
406 Preserve complete path information in the names of generated
407 \&\fI.gcov\fR files.  Without this option, just the filename component is
408 used.  With this option, all directories are used, with \fB/\fR characters
409 translated to \fB#\fR characters, \fI.\fR directory components
410 removed and unremoveable \fI..\fR
411 components renamed to \fB^\fR.  This is useful if sourcefiles are in several
412 different directories.
413 .IP "\fB\-r\fR" 4
414 .IX Item "-r"
415 .PD 0
416 .IP "\fB\-\-relative\-only\fR" 4
417 .IX Item "--relative-only"
418 .PD
419 Only output information about source files with a relative pathname
420 (after source prefix elision).  Absolute paths are usually system
421 header files and coverage of any inline functions therein is normally
422 uninteresting.
423 .IP "\fB\-s\fR \fIdirectory\fR" 4
424 .IX Item "-s directory"
425 .PD 0
426 .IP "\fB\-\-source\-prefix\fR \fIdirectory\fR" 4
427 .IX Item "--source-prefix directory"
428 .PD
429 A prefix for source file names to remove when generating the output
430 coverage files.  This option is useful when building in a separate
431 directory, and the pathname to the source directory is not wanted when
432 determining the output file names.  Note that this prefix detection is
433 applied before determining whether the source file is absolute.
434 .IP "\fB\-u\fR" 4
435 .IX Item "-u"
436 .PD 0
437 .IP "\fB\-\-unconditional\-branches\fR" 4
438 .IX Item "--unconditional-branches"
439 .PD
440 When branch probabilities are given, include those of unconditional branches.
441 Unconditional branches are normally not interesting.
442 .IP "\fB\-v\fR" 4
443 .IX Item "-v"
444 .PD 0
445 .IP "\fB\-\-version\fR" 4
446 .IX Item "--version"
447 .PD
448 Display the \fBgcov\fR version number (on the standard output),
449 and exit without doing any further processing.
450 .IP "\fB\-w\fR" 4
451 .IX Item "-w"
452 .PD 0
453 .IP "\fB\-\-verbose\fR" 4
454 .IX Item "--verbose"
455 .PD
456 Print verbose informations related to basic blocks and arcs.
457 .IP "\fB\-x\fR" 4
458 .IX Item "-x"
459 .PD 0
460 .IP "\fB\-\-hash\-filenames\fR" 4
461 .IX Item "--hash-filenames"
462 .PD
463 By default, gcov uses the full pathname of the source files to to create
464 an output filename.  This can lead to long filenames that can overflow
465 filesystem limits.  This option creates names of the form
466 \&\fI\fIsource-file\fI##\fImd5\fI.gcov\fR,
467 where the \fIsource-file\fR component is the final filename part and
468 the \fImd5\fR component is calculated from the full mangled name that
469 would have been used otherwise.
470 .PP
471 \&\fBgcov\fR should be run with the current directory the same as that
472 when you invoked the compiler.  Otherwise it will not be able to locate
473 the source files.  \fBgcov\fR produces files called
474 \&\fI\fImangledname\fI.gcov\fR in the current directory.  These contain
475 the coverage information of the source file they correspond to.
476 One \fI.gcov\fR file is produced for each source (or header) file
477 containing code,
478 which was compiled to produce the data files.  The \fImangledname\fR part
479 of the output file name is usually simply the source file name, but can
480 be something more complicated if the \fB\-l\fR or \fB\-p\fR options are
481 given.  Refer to those options for details.
482 .PP
483 If you invoke \fBgcov\fR with multiple input files, the
484 contributions from each input file are summed.  Typically you would
485 invoke it with the same list of files as the final link of your executable.
486 .PP
487 The \fI.gcov\fR files contain the \fB:\fR separated fields along with
488 program source code.  The format is
489 .PP
490 .Vb 1
491 \&        <execution_count>:<line_number>:<source line text>
492 .Ve
493 .PP
494 Additional block information may succeed each line, when requested by
495 command line option.  The \fIexecution_count\fR is \fB\-\fR for lines
496 containing no code.  Unexecuted lines are marked \fB#####\fR or
497 \&\fB=====\fR, depending on whether they are reachable by
498 non-exceptional paths or only exceptional paths such as \*(C+ exception
499 handlers, respectively. Given \fB\-a\fR option, unexecuted blocks are
500 marked \fB$$$$$\fR or \fB%%%%%\fR, depending on whether a basic block
501 is reachable via non-exceptional or exceptional paths.
502 Executed basic blocks having a statement with zero \fIexecution_count\fR
503 end with \fB*\fR character and are colored with magenta color with \fB\-k\fR
504 option.  The functionality is not supported in Ada.
505 .PP
506 Note that \s-1GCC\s0 can completely remove the bodies of functions that are
507 not needed \*(-- for instance if they are inlined everywhere.  Such functions
508 are marked with \fB\-\fR, which can be confusing.
509 Use the \fB\-fkeep\-inline\-functions\fR and \fB\-fkeep\-static\-functions\fR
510 options to retain these functions and
511 allow gcov to properly show their \fIexecution_count\fR.
512 .PP
513 Some lines of information at the start have \fIline_number\fR of zero.
514 These preamble lines are of the form
515 .PP
516 .Vb 1
517 \&        \-:0:<tag>:<value>
518 .Ve
519 .PP
520 The ordering and number of these preamble lines will be augmented as
521 \&\fBgcov\fR development progresses \-\-\- do not rely on them remaining
522 unchanged.  Use \fItag\fR to locate a particular preamble line.
523 .PP
524 The additional block information is of the form
525 .PP
526 .Vb 1
527 \&        <tag> <information>
528 .Ve
529 .PP
530 The \fIinformation\fR is human readable, but designed to be simple
531 enough for machine parsing too.
532 .PP
533 When printing percentages, 0% and 100% are only printed when the values
534 are \fIexactly\fR 0% and 100% respectively.  Other values which would
535 conventionally be rounded to 0% or 100% are instead printed as the
536 nearest non-boundary value.
537 .PP
538 When using \fBgcov\fR, you must first compile your program with two
539 special \s-1GCC\s0 options: \fB\-fprofile\-arcs \-ftest\-coverage\fR.
540 This tells the compiler to generate additional information needed by
541 gcov (basically a flow graph of the program) and also includes
542 additional code in the object files for generating the extra profiling
543 information needed by gcov.  These additional files are placed in the
544 directory where the object file is located.
545 .PP
546 Running the program will cause profile output to be generated.  For each
547 source file compiled with \fB\-fprofile\-arcs\fR, an accompanying
548 \&\fI.gcda\fR file will be placed in the object file directory.
549 .PP
550 Running \fBgcov\fR with your program's source file names as arguments
551 will now produce a listing of the code along with frequency of execution
552 for each line.  For example, if your program is called \fItmp.cpp\fR, this
553 is what you see when you use the basic \fBgcov\fR facility:
554 .PP
555 .Vb 6
556 \&        $ g++ \-fprofile\-arcs \-ftest\-coverage tmp.cpp
557 \&        $ a.out
558 \&        $ gcov tmp.cpp \-m
559 \&        File \*(Aqtmp.cpp\*(Aq
560 \&        Lines executed:92.86% of 14
561 \&        Creating \*(Aqtmp.cpp.gcov\*(Aq
562 .Ve
563 .PP
564 The file \fItmp.cpp.gcov\fR contains output from \fBgcov\fR.
565 Here is a sample:
566 .PP
567 .Vb 10
568 \&                \-:    0:Source:tmp.cpp
569 \&                \-:    0:Graph:tmp.gcno
570 \&                \-:    0:Data:tmp.gcda
571 \&                \-:    0:Runs:1
572 \&                \-:    0:Programs:1
573 \&                \-:    1:#include <stdio.h>
574 \&                \-:    2:
575 \&                \-:    3:template<class T>
576 \&                \-:    4:class Foo
577 \&                \-:    5:{
578 \&                \-:    6:  public:
579 \&               1*:    7:  Foo(): b (1000) {}
580 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
581 \&        Foo<char>::Foo():
582 \&            #####:    7:  Foo(): b (1000) {}
583 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
584 \&        Foo<int>::Foo():
585 \&                1:    7:  Foo(): b (1000) {}
586 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
587 \&               2*:    8:  void inc () { b++; }
588 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
589 \&        Foo<char>::inc():
590 \&            #####:    8:  void inc () { b++; }
591 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
592 \&        Foo<int>::inc():
593 \&                2:    8:  void inc () { b++; }
594 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
595 \&                \-:    9:
596 \&                \-:   10:  private:
597 \&                \-:   11:  int b;
598 \&                \-:   12:};
599 \&                \-:   13:
600 \&                \-:   14:template class Foo<int>;
601 \&                \-:   15:template class Foo<char>;
602 \&                \-:   16:
603 \&                \-:   17:int
604 \&                1:   18:main (void)
605 \&                \-:   19:{
606 \&                \-:   20:  int i, total;
607 \&                1:   21:  Foo<int> counter;
608 \&                \-:   22:
609 \&                1:   23:  counter.inc();
610 \&                1:   24:  counter.inc();
611 \&                1:   25:  total = 0;
612 \&                \-:   26:
613 \&               11:   27:  for (i = 0; i < 10; i++)
614 \&               10:   28:    total += i;
615 \&                \-:   29:
616 \&               1*:   30:  int v = total > 100 ? 1 : 2;
617 \&                \-:   31:
618 \&                1:   32:  if (total != 45)
619 \&            #####:   33:    printf ("Failure\en");
620 \&                \-:   34:  else
621 \&                1:   35:    printf ("Success\en");
622 \&                1:   36:  return 0;
623 \&                \-:   37:}
624 .Ve
625 .PP
626 Note that line 7 is shown in the report multiple times.  First occurrence
627 presents total number of execution of the line and the next two belong
628 to instances of class Foo constructors.  As you can also see, line 30 contains
629 some unexecuted basic blocks and thus execution count has asterisk symbol.
630 .PP
631 When you use the \fB\-a\fR option, you will get individual block
632 counts, and the output looks like this:
633 .PP
634 .Vb 10
635 \&                \-:    0:Source:tmp.cpp
636 \&                \-:    0:Graph:tmp.gcno
637 \&                \-:    0:Data:tmp.gcda
638 \&                \-:    0:Runs:1
639 \&                \-:    0:Programs:1
640 \&                \-:    1:#include <stdio.h>
641 \&                \-:    2:
642 \&                \-:    3:template<class T>
643 \&                \-:    4:class Foo
644 \&                \-:    5:{
645 \&                \-:    6:  public:
646 \&               1*:    7:  Foo(): b (1000) {}
647 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
648 \&        Foo<char>::Foo():
649 \&            #####:    7:  Foo(): b (1000) {}
650 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
651 \&        Foo<int>::Foo():
652 \&                1:    7:  Foo(): b (1000) {}
653 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
654 \&               2*:    8:  void inc () { b++; }
655 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
656 \&        Foo<char>::inc():
657 \&            #####:    8:  void inc () { b++; }
658 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
659 \&        Foo<int>::inc():
660 \&                2:    8:  void inc () { b++; }
661 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
662 \&                \-:    9:
663 \&                \-:   10:  private:
664 \&                \-:   11:  int b;
665 \&                \-:   12:};
666 \&                \-:   13:
667 \&                \-:   14:template class Foo<int>;
668 \&                \-:   15:template class Foo<char>;
669 \&                \-:   16:
670 \&                \-:   17:int
671 \&                1:   18:main (void)
672 \&                \-:   19:{
673 \&                \-:   20:  int i, total;
674 \&                1:   21:  Foo<int> counter;
675 \&                1:   21\-block  0
676 \&                \-:   22:
677 \&                1:   23:  counter.inc();
678 \&                1:   23\-block  0
679 \&                1:   24:  counter.inc();
680 \&                1:   24\-block  0
681 \&                1:   25:  total = 0;
682 \&                \-:   26:
683 \&               11:   27:  for (i = 0; i < 10; i++)
684 \&                1:   27\-block  0
685 \&               11:   27\-block  1
686 \&               10:   28:    total += i;
687 \&               10:   28\-block  0
688 \&                \-:   29:
689 \&               1*:   30:  int v = total > 100 ? 1 : 2;
690 \&                1:   30\-block  0
691 \&            %%%%%:   30\-block  1
692 \&                1:   30\-block  2
693 \&                \-:   31:
694 \&                1:   32:  if (total != 45)
695 \&                1:   32\-block  0
696 \&            #####:   33:    printf ("Failure\en");
697 \&            %%%%%:   33\-block  0
698 \&                \-:   34:  else
699 \&                1:   35:    printf ("Success\en");
700 \&                1:   35\-block  0
701 \&                1:   36:  return 0;
702 \&                1:   36\-block  0
703 \&                \-:   37:}
704 .Ve
705 .PP
706 In this mode, each basic block is only shown on one line \*(-- the last
707 line of the block.  A multi-line block will only contribute to the
708 execution count of that last line, and other lines will not be shown
709 to contain code, unless previous blocks end on those lines.
710 The total execution count of a line is shown and subsequent lines show
711 the execution counts for individual blocks that end on that line.  After each
712 block, the branch and call counts of the block will be shown, if the
713 \&\fB\-b\fR option is given.
714 .PP
715 Because of the way \s-1GCC\s0 instruments calls, a call count can be shown
716 after a line with no individual blocks.
717 As you can see, line 33 contains a basic block that was not executed.
718 .PP
719 When you use the \fB\-b\fR option, your output looks like this:
720 .PP
721 .Vb 10
722 \&                \-:    0:Source:tmp.cpp
723 \&                \-:    0:Graph:tmp.gcno
724 \&                \-:    0:Data:tmp.gcda
725 \&                \-:    0:Runs:1
726 \&                \-:    0:Programs:1
727 \&                \-:    1:#include <stdio.h>
728 \&                \-:    2:
729 \&                \-:    3:template<class T>
730 \&                \-:    4:class Foo
731 \&                \-:    5:{
732 \&                \-:    6:  public:
733 \&               1*:    7:  Foo(): b (1000) {}
734 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
735 \&        Foo<char>::Foo():
736 \&        function Foo<char>::Foo() called 0 returned 0% blocks executed 0%
737 \&            #####:    7:  Foo(): b (1000) {}
738 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
739 \&        Foo<int>::Foo():
740 \&        function Foo<int>::Foo() called 1 returned 100% blocks executed 100%
741 \&                1:    7:  Foo(): b (1000) {}
742 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
743 \&               2*:    8:  void inc () { b++; }
744 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
745 \&        Foo<char>::inc():
746 \&        function Foo<char>::inc() called 0 returned 0% blocks executed 0%
747 \&            #####:    8:  void inc () { b++; }
748 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
749 \&        Foo<int>::inc():
750 \&        function Foo<int>::inc() called 2 returned 100% blocks executed 100%
751 \&                2:    8:  void inc () { b++; }
752 \&        \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
753 \&                \-:    9:
754 \&                \-:   10:  private:
755 \&                \-:   11:  int b;
756 \&                \-:   12:};
757 \&                \-:   13:
758 \&                \-:   14:template class Foo<int>;
759 \&                \-:   15:template class Foo<char>;
760 \&                \-:   16:
761 \&                \-:   17:int
762 \&        function main called 1 returned 100% blocks executed 81%
763 \&                1:   18:main (void)
764 \&                \-:   19:{
765 \&                \-:   20:  int i, total;
766 \&                1:   21:  Foo<int> counter;
767 \&        call    0 returned 100%
768 \&        branch  1 taken 100% (fallthrough)
769 \&        branch  2 taken 0% (throw)
770 \&                \-:   22:
771 \&                1:   23:  counter.inc();
772 \&        call    0 returned 100%
773 \&        branch  1 taken 100% (fallthrough)
774 \&        branch  2 taken 0% (throw)
775 \&                1:   24:  counter.inc();
776 \&        call    0 returned 100%
777 \&        branch  1 taken 100% (fallthrough)
778 \&        branch  2 taken 0% (throw)
779 \&                1:   25:  total = 0;
780 \&                \-:   26:
781 \&               11:   27:  for (i = 0; i < 10; i++)
782 \&        branch  0 taken 91% (fallthrough)
783 \&        branch  1 taken 9%
784 \&               10:   28:    total += i;
785 \&                \-:   29:
786 \&               1*:   30:  int v = total > 100 ? 1 : 2;
787 \&        branch  0 taken 0% (fallthrough)
788 \&        branch  1 taken 100%
789 \&                \-:   31:
790 \&                1:   32:  if (total != 45)
791 \&        branch  0 taken 0% (fallthrough)
792 \&        branch  1 taken 100%
793 \&            #####:   33:    printf ("Failure\en");
794 \&        call    0 never executed
795 \&        branch  1 never executed
796 \&        branch  2 never executed
797 \&                \-:   34:  else
798 \&                1:   35:    printf ("Success\en");
799 \&        call    0 returned 100%
800 \&        branch  1 taken 100% (fallthrough)
801 \&        branch  2 taken 0% (throw)
802 \&                1:   36:  return 0;
803 \&                \-:   37:}
804 .Ve
805 .PP
806 For each function, a line is printed showing how many times the function
807 is called, how many times it returns and what percentage of the
808 function's blocks were executed.
809 .PP
810 For each basic block, a line is printed after the last line of the basic
811 block describing the branch or call that ends the basic block.  There can
812 be multiple branches and calls listed for a single source line if there
813 are multiple basic blocks that end on that line.  In this case, the
814 branches and calls are each given a number.  There is no simple way to map
815 these branches and calls back to source constructs.  In general, though,
816 the lowest numbered branch or call will correspond to the leftmost construct
817 on the source line.
818 .PP
819 For a branch, if it was executed at least once, then a percentage
820 indicating the number of times the branch was taken divided by the
821 number of times the branch was executed will be printed.  Otherwise, the
822 message \*(L"never executed\*(R" is printed.
823 .PP
824 For a call, if it was executed at least once, then a percentage
825 indicating the number of times the call returned divided by the number
826 of times the call was executed will be printed.  This will usually be
827 100%, but may be less for functions that call \f(CW\*(C`exit\*(C'\fR or \f(CW\*(C`longjmp\*(C'\fR,
828 and thus may not return every time they are called.
829 .PP
830 The execution counts are cumulative.  If the example program were
831 executed again without removing the \fI.gcda\fR file, the count for the
832 number of times each line in the source was executed would be added to
833 the results of the previous run(s).  This is potentially useful in
834 several ways.  For example, it could be used to accumulate data over a
835 number of program runs as part of a test verification suite, or to
836 provide more accurate long-term information over a large number of
837 program runs.
838 .PP
839 The data in the \fI.gcda\fR files is saved immediately before the program
840 exits.  For each source file compiled with \fB\-fprofile\-arcs\fR, the
841 profiling code first attempts to read in an existing \fI.gcda\fR file; if
842 the file doesn't match the executable (differing number of basic block
843 counts) it will ignore the contents of the file.  It then adds in the
844 new execution counts and finally writes the data to the file.
845 .SS "Using \fBgcov\fP with \s-1GCC\s0 Optimization"
846 .IX Subsection "Using gcov with GCC Optimization"
847 If you plan to use \fBgcov\fR to help optimize your code, you must
848 first compile your program with two special \s-1GCC\s0 options:
849 \&\fB\-fprofile\-arcs \-ftest\-coverage\fR.  Aside from that, you can use any
850 other \s-1GCC\s0 options; but if you want to prove that every single line
851 in your program was executed, you should not compile with optimization
852 at the same time.  On some machines the optimizer can eliminate some
853 simple code lines by combining them with other lines.  For example, code
854 like this:
855 .PP
856 .Vb 4
857 \&        if (a != b)
858 \&          c = 1;
859 \&        else
860 \&          c = 0;
861 .Ve
862 .PP
863 can be compiled into one instruction on some machines.  In this case,
864 there is no way for \fBgcov\fR to calculate separate execution counts
865 for each line because there isn't separate code for each line.  Hence
866 the \fBgcov\fR output looks like this if you compiled the program with
867 optimization:
868 .PP
869 .Vb 4
870 \&              100:   12:if (a != b)
871 \&              100:   13:  c = 1;
872 \&              100:   14:else
873 \&              100:   15:  c = 0;
874 .Ve
875 .PP
876 The output shows that this block of code, combined by optimization,
877 executed 100 times.  In one sense this result is correct, because there
878 was only one instruction representing all four of these lines.  However,
879 the output does not indicate how many times the result was 0 and how
880 many times the result was 1.
881 .PP
882 Inlineable functions can create unexpected line counts.  Line counts are
883 shown for the source code of the inlineable function, but what is shown
884 depends on where the function is inlined, or if it is not inlined at all.
885 .PP
886 If the function is not inlined, the compiler must emit an out of line
887 copy of the function, in any object file that needs it.  If
888 \&\fIfileA.o\fR and \fIfileB.o\fR both contain out of line bodies of a
889 particular inlineable function, they will also both contain coverage
890 counts for that function.  When \fIfileA.o\fR and \fIfileB.o\fR are
891 linked together, the linker will, on many systems, select one of those
892 out of line bodies for all calls to that function, and remove or ignore
893 the other.  Unfortunately, it will not remove the coverage counters for
894 the unused function body.  Hence when instrumented, all but one use of
895 that function will show zero counts.
896 .PP
897 If the function is inlined in several places, the block structure in
898 each location might not be the same.  For instance, a condition might
899 now be calculable at compile time in some instances.  Because the
900 coverage of all the uses of the inline function will be shown for the
901 same source lines, the line counts themselves might seem inconsistent.
902 .PP
903 Long-running applications can use the \f(CW\*(C`_\|_gcov_reset\*(C'\fR and \f(CW\*(C`_\|_gcov_dump\*(C'\fR
904 facilities to restrict profile collection to the program region of
905 interest. Calling \f(CW\*(C`_\|_gcov_reset(void)\*(C'\fR will clear all profile counters
906 to zero, and calling \f(CW\*(C`_\|_gcov_dump(void)\*(C'\fR will cause the profile information
907 collected at that point to be dumped to \fI.gcda\fR output files.
908 Instrumented applications use a static destructor with priority 99
909 to invoke the \f(CW\*(C`_\|_gcov_dump\*(C'\fR function. Thus \f(CW\*(C`_\|_gcov_dump\*(C'\fR
910 is executed after all user defined static destructors,
911 as well as handlers registered with \f(CW\*(C`atexit\*(C'\fR.
912 If an executable loads a dynamic shared object via dlopen functionality,
913 \&\fB\-Wl,\-\-dynamic\-list\-data\fR is needed to dump all profile data.
914 .SH "SEE ALSO"
915 .IX Header "SEE ALSO"
916 \&\fIgpl\fR\|(7), \fIgfdl\fR\|(7), \fIfsf\-funding\fR\|(7), \fIgcc\fR\|(1) and the Info entry for \fIgcc\fR.
917 .SH "COPYRIGHT"
918 .IX Header "COPYRIGHT"
919 Copyright (c) 1996\-2018 Free Software Foundation, Inc.
920 .PP
921 Permission is granted to copy, distribute and/or modify this document
922 under the terms of the \s-1GNU\s0 Free Documentation License, Version 1.3 or
923 any later version published by the Free Software Foundation; with the
924 Invariant Sections being \*(L"\s-1GNU\s0 General Public License\*(R" and \*(L"Funding
925 Free Software\*(R", the Front-Cover texts being (a) (see below), and with
926 the Back-Cover Texts being (b) (see below).  A copy of the license is
927 included in the \fIgfdl\fR\|(7) man page.
928 .PP
929 (a) The \s-1FSF\s0's Front-Cover Text is:
930 .PP
931 .Vb 1
932 \&     A GNU Manual
933 .Ve
934 .PP
935 (b) The \s-1FSF\s0's Back-Cover Text is:
936 .PP
937 .Vb 3
938 \&     You have freedom to copy and modify this GNU Manual, like GNU
939 \&     software.  Copies published by the Free Software Foundation raise
940 \&     funds for GNU development.
941 .Ve