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