OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [doc/] [gcov.1] - Blame information for rev 617

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.