LinuxCommandLibrary

gcov

test coverage analysis program

TLDR

Generate a coverage report named file.cpp.gcov

$ gcov [path/to/file.cpp]
copy
Write individual execution counts for every basic block
$ gcov -a [path/to/file.cpp]
copy
Write branch frequencies to output and print summary as percentage
$ gcov -b [path/to/file.cpp]
copy
Write branch frequencies as number of branches taken
$ gcov -c [path/to/file.cpp]
copy
Do not create a gcov output file
$ gcov -n [path/to/file.cpp]
copy
Write file level and function level summaries
$ gcov -f [path/to/file.cpp]
copy

SYNOPSIS

gcov [options] source-files

DESCRIPTION

gcov is a test coverage program used with GCC to analyze which parts of a program have been executed during testing. It helps identify untested code paths, improving test suite completeness.
To use gcov, compile your program with -fprofile-arcs -ftest-coverage (or --coverage). After running the program, gcov reads the generated .gcno and .gcda files to produce annotated source listings showing execution counts for each line.
Output files (*.gcov) contain the original source code annotated with execution counts. Lines marked ##### were never executed. Branch information helps identify untested conditional paths.

PARAMETERS

-a, --all-blocks

Write individual execution counts for every basic block
-b, --branch-probabilities
Write branch frequencies to output file as percentages
-c, --branch-counts
Write branch frequencies as counts rather than percentages
-f, --function-summaries
Output summaries for each function in addition to file summary
-n, --no-output
Do not create gcov output file
-l, --long-file-names
Use long file names for output files
-p, --preserve-paths
Preserve complete path information in output file names
-o, --object-directory DIR
Search for object files in DIR
-s, --source-prefix PREFIX
Remove source path prefix for shorter output names

CAVEATS

Requires programs to be compiled with special GCC flags. Only works with GCC-compiled code. Running the program multiple times accumulates coverage data unless .gcda files are deleted between runs. Inline functions may show misleading counts.

HISTORY

gcov has been part of the GNU Compiler Collection (GCC) since the early 1990s. It evolved alongside GCC's profiling capabilities and remains a fundamental tool for C/C++ code coverage analysis in the open-source ecosystem.

SEE ALSO

gcc(1), lcov(1), gprof(1)

> TERMINAL_GEAR

Curated for the Linux community

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

$16.99
nuphy Air75 V2 Portable 75% Mechanical Keyboard,Wireless Keyboard

nuphy Air75 V2 Portable 75% Mechanical Keyboard,Wireless Keyboard

$129.95
Raspberry Pi 5 8GB

Raspberry Pi 5 8GB

$134.50
Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

$16.99
Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

$1,589.00
GMKtec Gaming PC, K11 AMD Ryzen 9 8945HS, 32GB DDR5 RAM 1TB Mini PC Desktop Computer, Oculink, Dual NIC 2.5GbE LAN, HDMI/DisplayPort/USB4*2

GMKtec Gaming PC, K11 AMD Ryzen 9 8945HS, 32GB DDR5 RAM 1TB Mini PC Desktop Computer, Oculink, Dual NIC 2.5GbE LAN, HDMI/DisplayPort/USB4*2

$739.99