Skip to main content
The Coverage Analyzer agent generates gcov coverage data for C/C++ programs, showing which lines of code were executed during a test run. This data is essential for crash analysis and verification.

Purpose

Generate code coverage data that shows:
  • Which lines were executed (and how many times)
  • Which lines were not executed
  • Branch coverage information
  • Function coverage statistics

Invocation

Invoked by the crash-analysis-agent as part of the crash analysis workflow. Receives:
  • Code repository path
  • Working directory path
  • Crashing example program and build instructions
Creates: gcov/ subdirectory in working directory

Workflow

1

Rebuild with Coverage Flags

Add coverage instrumentation to the build:
  • Add --coverage -g to both CFLAGS and LDFLAGS
  • Alternative: -fprofile-arcs -ftest-coverage
Autotools:
CMake:
Makefile:
2

Run Crashing Program

The execution generates:
  • .gcno files (created at compile time - note data)
  • .gcda files (created at runtime - data)
3

Generate Coverage Reports

4

Copy Coverage Files

Coverage File Format

Gcov files (.gcov) show line-by-line execution counts:
Legend:
  • Number: Line executed N times
  • #####: Line not executed (0 times)
  • -: Non-executable line (comments, declarations, blank lines)

Validation

After generating coverage, validate: Manual validation:
Using line-execution-checker skill:

Usage in Crash Analysis

The crash-analyzer-agent uses coverage data to:
  1. Verify execution path: Confirm hypothesized code lines were actually executed
  2. Validate causal chain: Every line in the root-cause hypothesis must show as executed
  3. Detect dead code: Identify code that couldn’t have contributed to crash
  4. Cross-check with traces: Correlate with function-level traces
Critical validation rule:
Every line of code claimed to be part of the crash’s causal chain MUST show as executed in the coverage data. If not, the hypothesis is wrong.

Coverage Metrics

Gcov provides several coverage metrics:
Percentage of executable lines that were executed

Advanced Usage

Branch Coverage

Show branch coverage details:
Output includes:

Function-Level Summary

Shows which functions were called:

HTML Reports

Generate HTML coverage reports with lcov:

Performance Impact

Coverage instrumentation has minimal overhead:
  • Compile time: Slightly slower (debug info + instrumentation)
  • Runtime: <10% slowdown typically
  • Disk space: .gcda files can be large for complex programs
Much lower overhead than function tracing - suitable for longer test runs.

Troubleshooting

  • Program didn’t execute successfully
  • Crashed before coverage data flushed
  • Missing write permissions
  • Check that --coverage was in both CFLAGS and LDFLAGS
  • Wrong .gcda file used (from different build)
  • .gcno and .gcda files don’t match (rebuild needed)
  • Run gcov from correct directory
  • Run gcov from build directory
  • Use -o flag to specify object file directory:
  • Coverage data written on normal exit only
  • For crash analysis, this is expected
  • Data shows path up to crash point

Output Structure

Crash Analysis

Main crash analysis orchestrator

Function Trace Generator

Complementary function-level trace generation