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
gcov/ subdirectory in working directory
Workflow
Rebuild with Coverage Flags
Add coverage instrumentation to the build:CMake:Makefile:
- Add
--coverage -gto both CFLAGS and LDFLAGS - Alternative:
-fprofile-arcs -ftest-coverage
Run Crashing Program
.gcnofiles (created at compile time - note data).gcdafiles (created at runtime - data)
Coverage File Format
Gcov files (.gcov) show line-by-line execution counts:
- Number: Line executed N times
- #####: Line not executed (0 times)
- -: Non-executable line (comments, declarations, blank lines)
Validation
After generating coverage, validate: Manual validation:Usage in Crash Analysis
The crash-analyzer-agent uses coverage data to:- Verify execution path: Confirm hypothesized code lines were actually executed
- Validate causal chain: Every line in the root-cause hypothesis must show as executed
- Detect dead code: Identify code that couldn’t have contributed to crash
- Cross-check with traces: Correlate with function-level traces
Coverage Metrics
Gcov provides several coverage metrics:- Line Coverage
- Branch Coverage
- Function Coverage
Percentage of executable lines that were executed
Advanced Usage
Branch Coverage
Show branch coverage details:Function-Level Summary
HTML Reports
Generate HTML coverage reports withlcov:
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
No .gcda files generated
No .gcda files generated
- Program didn’t execute successfully
- Crashed before coverage data flushed
- Missing write permissions
- Check that
--coveragewas in both CFLAGS and LDFLAGS
.gcov files empty or zeros
.gcov files empty or zeros
- Wrong .gcda file used (from different build)
- .gcno and .gcda files don’t match (rebuild needed)
- Run gcov from correct directory
gcov: source file not found
gcov: source file not found
- Run gcov from build directory
- Use
-oflag to specify object file directory:
Coverage incomplete after crash
Coverage incomplete after crash
- Coverage data written on normal exit only
- For crash analysis, this is expected
- Data shows path up to crash point
Output Structure
Related Agents
Crash Analysis
Main crash analysis orchestrator
Function Trace Generator
Complementary function-level trace generation