gcov-tool - Linux


gcov-tool is a tool used for generating code coverage information from executables compiled with the -coverage flag. It provides detailed reports on which lines of code have been executed and which have not, aiding in identifying untested or potentially problematic areas of the codebase.


gcov-tool [options] executable-file


  • -l: Generate line-by-line coverage information.
  • -f: Generate function coverage information.
  • -b: Generate block coverage information.
  • –source: Specify the source code file to generate coverage information for.
  • –output: Specify the output file to write coverage information to. Default is stdout.
  • –html: Generate HTML coverage report.
  • –xml: Generate XML coverage report.
  • –json: Generate JSON coverage report.
  • –ignore: Ignore specific source files from coverage analysis.
  • –ignore-pattern: Ignore source files matching a specific pattern from coverage analysis.
  • –debug: Enable debugging output.


Simple usage: Generate line-by-line coverage for the main.c executable:

gcov-tool main

Advanced usage: Generate XML coverage report for multiple source files, ignoring specific files:

gcov-tool --source src/file1.c --source src/file2.c --output coverage.xml --ignore src/file3.c --ignore-pattern "*.test.c"

Common Issues

  • Missing coverage information: Ensure the executable was compiled with the -coverage flag.
  • Inaccurate coverage information: Verify the source code files used for coverage generation match the executable being analyzed.
  • Unknown source file: Specify the path to the source code file using the --source option.


With lcov: Generate HTML and text coverage reports:

lcov --capture --directory . --output-file coverage.info
genhtml coverage.info --output-directory coverage-report

Related Commands

  • gcov: Generates coverage information during compilation.
  • lcov: Merges coverage information from multiple sources and generates reports.
  • coverage: Python package for measuring code coverage.