Gcov Coverage
🤖 AI Summary
Instruments C/C++ programs with gcov to measure test coverage by compiling with `--coverage`, running the program to generate `.gcda` execution data, and producing line-by-line text reports via `gcov` or HTML reports via `gcovr`.
How to Install
Claude Code:
git clone --depth 1 https://github.com/gadievron/raptor.git && cp raptor/.claude/skills/crash-analysis/gcov-coverage ~/.claude/skills/SKILL.md -rCode Coverage with gcov
Purpose
Instrument C/C++ programs with gcov to measure test coverage.
How It Works
Build with Coverage
gcc --coverage -o program source.c
Run Program
./program
# Creates .gcda files with execution data
Generate Reports
Text report:
gcov source.c
# Creates source.c.gcov with line-by-line coverage
HTML report:
gcovr --html-details -o coverage.html
Coverage Flags
--coverage(shorthand for-fprofile-arcs -ftest-coverage -lgcov)- Add to both
CFLAGSandLDFLAGS
Build System Integration
Makefile
ENABLE_COVERAGE ?= 0
ifeq ($(ENABLE_COVERAGE),1)
CFLAGS += --coverage
LDFLAGS += --coverage
endif
CMake
option(ENABLE_COVERAGE "Enable coverage" OFF)
if(ENABLE_COVERAGE)
add_compile_options(--coverage)
add_link_options(--coverage)
endif()
When User Requests Coverage
Steps
- Detect build system (Makefile/CMake/other)
- Add
--coverageto CFLAGS and LDFLAGS - Clean previous build:
make cleanorrm -f *.gcda *.gcno - Build with coverage:
make ENABLE_COVERAGE=1orcmake -DENABLE_COVERAGE=ON - Run tests:
make testor./test_suite - Generate report:
gcovr --html-details coverage.html --print-summary - Present summary and path to HTML report
Output
Text (.gcov files):
-: 0:Source:main.c
5: 42: int x = 10;
#####: 43: unused_code();
5:= executed 5 times#####:= not executed-:= non-executable
HTML: Interactive report with color-coded coverage
Metrics
- Line coverage: Executed lines / total lines
- Branch coverage: Taken branches / total branches
- Function coverage: Called functions / total functions
Target: 80%+ line coverage, 70%+ branch coverage
Details
| Category | AI/ML → ml |
| Source | gadievron/raptor |
| SKILL.md | View on GitHub → |
| Repo Stars | ★ 3.0K |
| Est. per Skill | 234 (shared across 13 skills from this repo) |
| Difficulty | Intermediate |
| Risk Level | N/A |
Related Skills
theme-factory
Theme Factory Skill This skill provides a curated collection of professional font and color themes t
theme-factory
Theme Factory Skill This skill provides a curated collection of professional font and color themes t
mcp-builder
MCP Server Development Guide Overview Create MCP (Model Context Protocol) servers that enable LLMs t
web-design-guidelines
Web Interface Guidelines Review files for compliance with Web Interface Guidelines. How It Works 1.
Works Well With
Skills from the same repository — often designed to work together
Commands
/create-skill - Save Custom Approach as Reusable Skill Save a successful custom approach as a reusab
Code Understanding
Code Understanding Skill You are a deep thinker. This gives you adversarial code comprehension for t
Function Tracing
Function Call Tracing Purpose Trace all function calls in C/C++ programs with per-thread logs and Pe