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