Claude Skill

Coverage Analysis

>

Editor's Note

> Covers overview, when to apply, quick reference.

Page Outline

OverviewWhen to ApplyQuick ReferenceIdeal Coverage WorkflowStep-by-Step

Source Content

Normalized top-level metadata comes from the directory layer. The body below is the upstream source content for this item.

Coverage Analysis

Coverage analysis is essential for understanding which parts of your code are exercised during fuzzing. It helps identify fuzzing blockers like magic value checks and tracks the effectiveness of harness improvements over time.

Overview

Code coverage during fuzzing serves two critical purposes:

  • **Assessing harness effectiveness**: Understand which parts of your application are actually executed by your fuzzing harnesses
  • **Tracking fuzzing progress**: Monitor how coverage changes when updating harnesses, fuzzers, or the system under test (SUT)

Coverage is a proxy for fuzzer capability and performance. While coverage [is not ideal for measuring fuzzer performance](https://arxiv.org/abs/1808.09700) in absolute terms, it reliably indicates whether your harness works effectively in a given setup.

Key Concepts

| Concept | Description | |---------|-------------| | **Coverage instrumentation** | Compiler flags that track which code paths are executed | | **Corpus coverage** | Coverage achieved by running all test cases in a fuzzing corpus | | **Magic value checks** | Hard-to-discover conditional checks that block fuzzer progress | | **Coverage-guided fuzzing** | Fuzzing strategy that prioritizes inputs that discover new code paths | | **Coverage report** | Visual or textual representation of executed vs. unexecuted code |

When to Apply

**Apply this technique when:**

  • Starting a new fuzzing campaign to establish a baseline
  • Fuzzer appears to plateau without finding new paths
  • After harness modifications to verify improvements
  • When migrating between different fuzzers
  • Identifying areas requiring dictionary entries or seed inputs
  • Debugging why certain code paths aren't reached

**Skip this technique when:**

  • Fuzzing campaign is actively finding crashes
  • Coverage infrastructure isn't set up yet
  • Working with extremely large codebases where full coverage reports are impractical
  • Fuzzer's internal coverage metrics are sufficient for your needs

Quick Reference

| Task | Command/Pattern | |------|-----------------| | LLVM coverage instrumentation (C/C++) | `-fprofile-instr-generate -fcoverage-mapping` | | GCC coverage instrumentation | `-ftest-coverage -fprofile-arcs` | | cargo-fuzz coverage (Rust) | `cargo +nightly fuzz coverage <target>` | | Generate LLVM profile data | `llvm-profdata merge -sparse file.profraw -o file.profdata` | | LLVM coverage report | `llvm-cov report ./binary -instr-profile=file.profdata` | | LLVM HTML report | `llvm-cov show ./binary -instr-profile=file.profdata -format=html -output-dir html/` | | gcovr HTML report | `gcovr --html-details -o coverage.html` |

Ideal Coverage Workflow

The following workflow represents best practices for integrating coverage analysis into your fuzzing campaigns:

[Fuzzing Campaign]
       |
       v
[Generate Corpus]
       |
       v
[Coverage Analysis]
       |
       +---> Coverage Increased? --> Continue fuzzing with larger corpus
       |
       +---> Coverage Decreased? --> Fix harness or investigate SUT changes
       |
       +---> Coverage Plateaued? --> Add dictionary entries or seed inputs

**Key principle**: Use the corpus generated *after* each fuzzing campaign to calculate coverage, rather than real-time fuzzer statistics. This approach provides reproducible, comparable measurements across different fuzzing tools.

Step-by-Step

Step 1: Build with Coverage Instrumentation

Choose your instrumentation method based on toolchain:

**LLVM/Clang (C/C++):**

clang++ -fprofile-instr-generate -fcoverage-mapping \
  -O2 -DNO_MAIN \
  main.cc harness.cc execute-rt.cc -o fuzz_exec

**GCC (C/C++):**

g++ -ftest-coverage -fprofile-arcs \
  -O2 -DNO_MAIN \
  main.cc harness.cc execute-rt.cc -o fu

<!-- truncated -->

Related Items

Deploy agents, MCP servers, and backends fast logo

Railway - Deploy agents and MCP servers fast

Try Railway