Home

gcov

gcov is a test coverage tool that ships with the GNU Compiler Collection (GCC). It analyzes how much of a C or C++ program’s source code is exercised by a set of tests, helping developers identify untested or under-tested code paths. gcov works by using instrumentation added by the compiler during compilation and by processing profiling data collected at run time.

When a program is compiled with coverage instrumentation, GCC generates additional data files during execution. Compiling

Usage generally follows a pattern: compile with coverage flags, run the program to generate profiling data,

gcov is part of GCC and is commonly used in conjunction with other coverage tooling to aggregate

typically
uses
flags
such
as
-fprofile-arcs
and
-ftest-coverage
to
enable
branch
and
line
coverage
data
collection.
Running
the
instrumented
program
creates
.gcda
and
.gcno
files
that
record
execution
information.
After
tests
have
run,
gcov
is
invoked
on
the
corresponding
source
file
to
produce
a
human-readable
report,
often
in
the
form
of
a
.gcov
file
that
shows
per-line
execution
counts
and,
if
branch
data
was
collected,
branch
information
as
well.
then
run
gcov
on
the
source
file
(and
optionally
use
-b
for
branch
data).
The
resulting
reports
highlight
executed
lines
with
counts
and
can
be
complemented
by
tools
like
gcovr
or
lcov
to
produce
summaries
or
HTML
reports.
results
across
multiple
files
or
test
runs.
Limitations
include
reliance
on
instrumentation
at
compile
time,
potential
changes
in
coverage
accuracy
with
optimizations,
and
the
need
to
retain
source
and
debug
information
to
interpret
the
reports
effectively.