Code Coverage with gcov

Instrument C/C++ projects with gcov to capture test coverage data.

3.5k|556|Updated Oct 17, 2025
One-click install
npx skills add https://github.com/gadievron/raptor --skill code-coverage-with-gcov
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Code Coverage with gcov
Source: https://github.com/gadievron/raptor/tree/main/.claude/skills/crash-analysis/gcov-coverage
Command: npx skills add https://github.com/gadievron/raptor --skill code-coverage-with-gcov

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers instrument C/C++ projects with gcov to measure test coverage, allowing teams to identify untested code paths and improve testing efficiency.

Core Features & Use Cases

  • Instrumentation: Enable coverage data collection by compiling with --coverage flags (CFLAGS/LDFLAGS) and producing .gcda/.gcno files.
  • Reporting: Generate per-file reports with gcov and aggregate HTML reports with gcovr.
  • Use Case: A team wants to increase line and branch coverage across a large codebase by iteratively adding tests until coverage improves.

Quick Start

Build with coverage: gcc --coverage -o program source.c Run program: ./program Generate per-file report: gcov source.c Create HTML coverage: gcovr --html-details -o coverage.html

Frequently Asked Questions about Code Coverage with gcov

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I measure code coverage in C/C++ projects?

Code coverage measures which lines and branches of your code are executed by tests. Gcov instruments C/C++ binaries during compilation with --coverage flags, then generates reports showing covered and uncovered code paths, helping teams identify untested logic.

How do I set up gcov coverage instrumentation in my build?

Add --coverage flags to both CFLAGS and LDFLAGS during compilation with gcc or clang. When you run the instrumented program, it produces .gcda and .gcno files. Run gcov on source files to generate per-file reports, or gcovr to create aggregate HTML reports.

Does gcov work with CMake and Makefile builds?

Yes, gcov supports both CMake and Makefile-based builds. Set compiler flags (--coverage) in your build configuration, compile and run tests to generate coverage data, then invoke gcov or gcovr to produce reports. The standard C/C++ toolchain (gcc, clang, gcovr) handles the instrumentation.

What do I need to generate code coverage reports?

You need a C/C++ toolchain including gcc or clang, gcov, and gcovr installed. Compile with --coverage flags, run your test suite to populate .gcda files, then use gcov for per-file reports or gcovr for aggregated HTML coverage dashboards.

Can gcov measure both line and branch coverage?

Yes, gcov captures line coverage and branch coverage data. The .gcda files track which code paths executed; gcov and gcovr reports display both metrics, letting teams identify untested conditional branches and improve test completeness across the codebase.