OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [doc/] [gcov.1] - Blame information for rev 826

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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