LLVM-COV(1)

πŸ’– llvm-cov β€” like, the whole vibe

okay bestie, welcome to llvm-cov, part of the LLVM manual pages (that's the LLVM bit up in the corner, and yeah it's section 1, the user commands section, iykyk). grab a strawberry πŸ“ and let's get into it.


✨ NAME ✨

llvm-cov β€” emit coverage information πŸ’…


✨ SYNOPSIS ✨

llvm-cov command [args...]

✨ DESCRIPTION ✨

so basically, llvm-cov shows you code coverage info for programs that have been instrumented to emit profile data. no cap. it works with gcov-style coverage and with clang's instrumentation-based profiling β€” both, she contains multitudes πŸ‘‘

and here's a lil plot twist: if the program gets invoked with a base name of gcov, it just... behaves as if you'd called llvm-cov gcov directly. sneaky. otherwise, bestie, you gotta give it a command. don't leave her hanging πŸ™ˆ


✨ COMMANDS ✨

  • gcov
  • show
  • report
  • export

🌸 GCOV COMMAND 🌸

SYNOPSIS

llvm-cov gcov [options] SOURCEFILE

DESCRIPTION

the llvm-cov gcov tool reads code coverage data files and shows you the coverage info for a source file you pick. she's compatible with the gcov tool from version 4.2 of GCC, and may also be compatible with some later versions of gcov (we're being honest, not shady).

to use llvm-cov gcov, you first have to build an instrumented version of your app that collects coverage data while it runs. compile with the -fprofile-arcs and -ftest-coverage options to add the instrumentation. (or, alternate route, you can use the --coverage option, which is giving "both of those other options in one" β€” it includes them both.)

so when you compile the instrumented code, a .gcno data file gets generated for each object file. these .gcno files hold half of the coverage data. the other half comes from .gcda files, which get generated when you actually run the instrumented program β€” one separate .gcda file per object file. and here's the part that gets people: every time you run the program, the execution counts get summed into any existing .gcda files. so be sure to remove any old files if you don't want their contents included. for real, delete them. πŸ—‘οΈ

by default the .gcda files get written into the same directory as the object files, but you can override that by setting the GCOV_PREFIX and GCOV_PREFIX_STRIP environment variables. GCOV_PREFIX_STRIP specifies a number of directory components to be removed from the start of the absolute path to the object file directory. after stripping those directories, the prefix from GCOV_PREFIX gets added. these env vars let you run the instrumented program on a machine where the original object file directories aren't accessible β€” but then you'll need to copy the .gcda files back to the object file directories where llvm-cov gcov expects to find them. so it's a trade, bestie 🀝

once you've generated the coverage data files, run llvm-cov gcov for each main source file where you wanna examine the coverage results. run it from the same directory where you previously ran the compiler β€” that part matters. the results for the specified source file get written to a file named by appending a .gcov suffix. and a separate output file also gets created for each file included by the main source file, also with a .gcov suffix added. so many files. she's prolific ✨

the basic content of an .gcov output file is a copy of the source file with an execution count and line number prepended to every line. the execution count shows as - if a line doesn't contain any executable code. and if a line contains code but that code was never executed? the count displays as #####. dramatic, honestly πŸ’€

OPTIONS

  • -a, --all-blocks β€” display all basic blocks. if there's multiple blocks for a single line of source code, this makes llvm-cov show the count for each block instead of just one count for the whole entire line.
  • -b, --branch-probabilities β€” display conditional branch probabilities plus a summary of branch info.
  • -c, --branch-counts β€” display branch counts instead of probabilities. (requires -b, don't skip it πŸ™)
  • -m, --demangled-names β€” demangle function names. she speaks human now.
  • -f, --function-summaries β€” show a summary of coverage for each function instead of just one summary for the entire source file.
  • --help β€” display available options (--help-hidden for more).
  • -l, --long-file-names β€” for coverage output of files included from the main source file, add the main file name followed by ## as a prefix to the output file names. this can be combined with the --preserve-paths option to use complete paths for both the main file and the included file. collab energy 🀝
  • -n, --no-output β€” do not output any .gcov files. summary info is still displayed though, so you're not losing everything.
  • -o <DIR|FILE>, --object-directory=<DIR>, --object-file=<FILE> β€” find objects in DIR or based on FILE's path. if you specify a particular object file, the coverage data files are expected to have the same base name with .gcno and .gcda extensions. if you specify a directory, the files are expected in that directory with the same base name as the source file.
  • -p, --preserve-paths β€” preserve path components when naming the coverage output files. in addition to the source file name, include the directories from the path to that file. the directories are separate by # characters, with . directories removed and .. directories replaced by ^ characters. when used with the --long-file-names option, this applies to both the main file name and the included file name.
  • -r β€” only dump files with relative paths, or absolute paths with the prefix specified by -s.
  • -s <string> β€” source prefix to elide.
  • -t, --stdout β€” print to stdout instead of producing .gcov files.
  • -u, --unconditional-branches β€” include unconditional branches in the output for the --branch-probabilities option.
  • -version β€” display the version of llvm-cov.
  • -x, --hash-filenames β€” use md5 hash of file name when naming the coverage output files. the source file name will be suffixed by ## followed by the MD5 hash calculated for it. fancy πŸ”₯

EXIT STATUS

llvm-cov gcov returns 1 if it cannot read input files. otherwise, it exits with zero. that's it, that's the whole mood 🫢


πŸ’– SHOW COMMAND πŸ’–

✨ SYNOPSIS ✨

llvm-cov show [options] -instr-profile PROFILE [BIN] [-object BIN]...
              [-sources] [SOURCE]...

πŸ¦‹ DESCRIPTION πŸ¦‹

okay bestie, this is the command. llvm-cov show gives you line-by-line coverage of the binaries BIN... using the profile data PROFILE. and if you want, you can filter it so it only shows coverage for the files you list in SOURCE.... obsessed.

so BIN can be literally any of these β€” an executable, an object file, a dynamic library, or an archive (thin or otherwise). it's giving flexible πŸ’…

to actually use llvm-cov show you need a program compiled with instrumentation so it emits profile and coverage data. to build one of those with clang, you use the -fprofile-instr-generate and -fcoverage-mapping flags. and if you're linking with the clang driver, make sure you pass -fprofile-instr-generate to the link stage too, so the necessary runtime libraries get linked in. don't skip that part, it's important fr fr.

the coverage info is stored inside the built executable or library itself, and that's the thing you hand to llvm-cov show as a BIN argument. the profile data gets generated by just... running this instrumented program normally. when it exits it writes out a raw profile file β€” usually called default.profraw β€” and you can convert that into something suitable for the PROFILE argument using the llvm-profdata merge tool. easy peasy ✨


πŸ’… OPTIONS πŸ’…

  • -show-branches=<VIEW> β€” shows coverage for branch conditions, either as a count or as a percentage. the supported views are: "count", "percent".
  • -show-mcdc β€” shows modified condition/decision coverage (MC/DC) for every applicable boolean expression. fancy stuff πŸŽ€
  • -show-line-counts β€” shows the execution counts for each line. defaults to true, unless you use another -show option, in which case it doesn't.
  • -show-expansions β€” expands inclusions β€” like preprocessor macros or textual inclusions β€” inline right in the display of the source file. defaults to false.
  • -show-instantiations β€” for source regions that get instantiated multiple times (think C++ templates), it shows each instantiation separately and the combined summary. defaults to true.
  • -show-regions β€” shows execution counts for each region by drawing a caret pointing at the character where the region starts. defaults to false.
  • -show-line-counts-or-regions β€” shows execution counts per line if there's only one region on that line, but shows the individual regions if there's more than one. defaults to false.
  • -show-directory-coverage β€” generates an index file in each directory that has at least one source file, plus a top level index showing aggregates. defaults to false.
  • -use-color β€” turns color output on or off. by default this is autodetected. 🌈
  • -arch=[*NAMES*] β€” give a list of architectures where the Nth entry lines up with the Nth binary you specified. if the covered object is a universal binary, this picks which architecture to use. heads up: it's an error to specify an architecture that isn't in the universal binary, or to use one that doesn't match a non-universal binary. no cap.
  • -name=<NAME> β€” shows code coverage only for functions with that given name.
  • -name-allowlist=<FILE> β€” shows code coverage only for functions listed in the given file. every line in that file should start with allowlist_fun:, immediately followed by the name of the function to accept. and that name can be a wildcard expression πŸ‘‘
  • -name-regex=<PATTERN> β€” shows code coverage only for functions matching the given regular expression.
  • -ignore-filename-regex=<PATTERN> β€” skips source code files whose file paths match the given regular expression.
  • -format=<FORMAT> β€” use the specified output format. the supported formats are: "text", "html".
  • -tab-size=<TABSIZE> β€” replaces tabs with TABSIZE spaces when preparing reports. currently this is only supported for the html format.
  • -output-dir=PATH β€” specify a directory to write coverage reports into. if it doesn't exist, it gets created. when used in function view mode (aka when -name or -name-regex are used to select specific functions), the report goes to PATH/functions.EXTENSION. when used in file view mode, a report for each file goes to PATH/REL_PATH_TO_FILE.EXTENSION.
  • -Xdemangler=<TOOL>|<TOOL-OPTION> β€” specify a symbol demangler, which makes reports more human-readable. you can pass this option multiple times to feed arguments to the demangler (like -Xdemangler c++filt -Xdemangler -n for C++). the demangler is expected to read a newline-separated list of symbols from stdin and write a newline-separated list of the same length to stdout.
  • -num-threads=N, -j=N β€” use N threads to write file reports (only applies when -output-dir is specified). when N=0, llvm-cov auto-detects an appropriate number of threads to use, and that's the default. main character energy ✨
  • -compilation-dir=<dir> β€” a directory used as a base for relative coverage mapping paths. only applies when binaries were compiled with one of -fcoverage-prefix-map, -fcoverage-compilation-dir, or -ffile-compilation-dir.
  • -line-coverage-gt=<N> β€” shows code coverage only for functions with line coverage greater than the given threshold.
  • -line-coverage-lt=<N> β€” shows code coverage only for functions with line coverage less than the given threshold.
  • -region-coverage-gt=<N> β€” shows code coverage only for functions with region coverage greater than the given threshold.
  • -region-coverage-lt=<N> β€” shows code coverage only for functions with region coverage less than the given threshold.
  • -path-equivalence=<from>,<to> β€” maps the paths in the coverage data to local source file paths. this is the slay for generating coverage data on one machine and then running llvm-cov on a different machine where you have the same files at a different path. you can pass multiple -path-equivalence arguments to specify different mappings, and each argument is a source path from plus its corresponding local path to. the mappings get applied in the order you specify them. and if multiple mappings could apply to a single path, the first mapping encountered is the one that's used. iykyk.
  • -coverage-watermark=<high>,<low> β€” sets the high and low watermarks for coverage in html format output. this lets you set the high and low coverage watermark however you want: green when coverage >= high, red when coverage < low, and yellow otherwise. both high and low should be between 0-100, and high > low. periodt.
  • -debuginfod β€” uses debuginfod to look up coverage mapping for binary IDs that are present in the profile but not in any object given on the command line. defaults to true if debuginfod is compiled in and configured via the DEBUGINFOD_URLS environment variable.
  • -debug-file-directory=<dir> β€” provides local directories to search for objects corresponding to binary IDs in the profile (same deal as with debuginfod). defaults to the system build ID directories.
  • -check-binary-ids β€” fails if an object file can't be found for a binary ID present in the profile β€” neither on the command line nor via binary ID lookup.

πŸ”₯ REPORT COMMAND πŸ”₯

✨ SYNOPSIS ✨

llvm-cov report [options] -instr-profile PROFILE [BIN] [-object BIN]...
                [-sources] [SOURCE]...

πŸ¦‹ DESCRIPTION πŸ¦‹

llvm-cov report shows you a summary of the coverage of the binaries BIN... using the profile data PROFILE. and yeah, it can optionally be filtered to only show coverage for the files listed in SOURCE.... same vibe as show, but summarized πŸ’…

BIN may be an executable, an object file, a dynamic library, or an archive (thin or otherwise). all of the above, we don't discriminate ✨

if you don't provide any source files, you get a summary line printed for each file in the coverage data. if you do provide files, summaries can be shown for each function in those listed files β€” but only if the -show-functions option is enabled. so like, turn it on bestie.

and for info on compiling programs for coverage and generating profile data, go see SHOW COMMAND. it's all there 🫢


πŸ’… OPTIONS πŸ’…

  • -use-color[=VALUE] β€” enable or disable color output. by default this is autodetected. 🌈
  • -arch=<name> β€” if the covered binary is a universal binary, this selects which architecture to use. it's an error to specify an architecture that isn't included in the universal binary, or to use an architecture that doesn't match a non-universal binary.
  • -show-region-summary β€” shows statistics for all regions. defaults to true.
  • -show-branch-summary β€” shows statistics for all branch conditions. defaults to true.
  • -show-mcdc-summary β€” shows MC/DC statistics. defaults to false.
  • -show-functions β€” shows coverage summaries for each function. defaults to false.
  • -show-instantiation-summary β€” shows statistics for all function instantiations. defaults to false.
  • -ignore-filename-regex=<PATTERN> β€” skips source code files whose file paths match the given regular expression.
  • -compilation-dir=<dir> β€” a directory used as a base for relative coverage mapping paths. only applies when binaries were compiled with one of -fcoverage-prefix-map, -fcoverage-compilation-dir, or -ffile-compilation-dir.
  • -debuginfod β€” attempts to look up coverage mapping from objects using debuginfod. this is attempted by default for binary IDs present in the profile that weren't provided on the command line, so long as debuginfod is compiled in and configured via DEBUGINFOD_URLS.
  • -debug-file-directory=<dir> β€” provides a directory to search for objects corresponding to binary IDs in the profile.
  • -check-binary-ids β€” fails if an object file can't be found for a binary ID present in the profile β€” neither on the command line nor via binary ID lookup.

πŸ’… EXPORT COMMAND πŸ’…

✨ SYNOPSIS ✨

llvm-cov export [options] -instr-profile PROFILE [BIN] [-object BIN]...
[-sources] [SOURCE]...

🌈 DESCRIPTION 🌈

okay bestie so the llvm-cov export command takes the coverage data from the binaries BIN... using the profile data PROFILE and exports it β€” either as JSON or as an lcov trace file. pick your fighter. πŸ’–

When you're exporting JSON, what gets exported is the regions, functions, branches, expansions, and summaries of the coverage data. When you're exporting an lcov trace file instead, you get the line-based coverage, the branch coverage, and the summaries. both valid, both serving πŸ’…

and like, you can optionally filter the exported data so it only exports the coverage for the files listed in SOURCE.... selective queen behavior. ✨

For the whole "how do I even compile my programs for coverage and generate profile data" situation, go read SHOW COMMAND. it's all in there, i promise. 🫢


πŸŽ€ OPTIONS πŸŽ€

  • -arch=<name> β€” if the covered binary is a universal binary, this picks which architecture to use. and listen, it is an error to specify an architecture that isn't included in the universal binary, or to use an architecture that doesn't match a non-universal binary. so like, know your binary before you come for it 😭
  • -format=<FORMAT> β€” use the specified output format. the supported formats are: "text" (JSON), "lcov". yes bestie, "text" gives you JSON, that's just how it is, don't fight it πŸ’€
  • -summary-only β€” export only summary information for each file in the coverage data. this mode will not export coverage info for smaller units like individual functions or regions. the result will contain the same information as what the llvm-cov report command produces, except presented in JSON or lcov format instead of text. same tea, different mug β˜•
  • -ignore-filename-regex=<PATTERN> β€” skip source code files whose file paths match the given regular expression. not today, random file πŸ™ˆ
  • -skip-expansions β€” skip exporting macro expansion coverage data. bye bye expansions πŸ‘‹
  • -skip-functions β€” skip exporting per-function coverage data. functions? never heard of her πŸ’…
  • -num-threads=N, -j=N β€” use N threads to export coverage data. when N=0, llvm-cov auto-detects an appropriate number of threads to use. and that N=0 situation? that's the default. she multitasks πŸ’–
  • -compilation-dir=<dir> β€” directory used as a base for relative coverage mapping paths. only applicable when binaries have been compiled with one of -fcoverage-prefix-map, -fcoverage-compilation-dir, or -ffile-compilation-dir. context matters bestie ✨
  • -debuginfod β€” attempt to look up coverage mapping from objects using debuginfod. this is attempted by default for binary IDs present in the profile but not provided on the command line β€” so long as debuginfod is compiled in and configured via DEBUGINFOD_URLS. so like, if it's not set up, don't expect the magic πŸͺ„
  • -debug-file-directory=<dir> β€” provides a directory to search for objects corresponding to binary IDs in the profile. a lil home for your objects 🏠
  • -check-binary-ids β€” fail if an object file cannot be found for a binary ID present in the profile, neither on the command line nor via binary ID lookup. strict! i love a boundaries-having option πŸ’…

πŸ§ͺ CONVERT-FOR-TESTING COMMAND πŸ§ͺ

WARNING: this command is for the LLVM developers who are working on llvm-cov only. not your average bestie command, it's giving ✨internal tool✨, so don't go using it for your own stuff 😭

🌸 SYNOPSIS 🌸

llvm-cov convert-for-testing BIN -o OUT

πŸ¦‹ DESCRIPTION πŸ¦‹

The llvm-cov convert-for-testing command serves the purpose of testing llvm-cov itself. it can extract all code coverage data from the binary BIN to the file OUT, which thereby reduces the size of test files. the output file typically bears the .covmapping extension. iconic little diet file πŸ’…

and the .covmapping files can be read back by llvm-cov just as ordinary binary files. so like, it round-trips, no cap πŸ”₯


πŸ‘‘ AUTHOR πŸ‘‘

Maintained by the LLVM Team (https://llvm.org/). periodt. πŸ’–


2003-2025, LLVM Project


okay that's literally the whole page bestie, you ate, you read the entire thing, main character energy fr fr πŸŒΈπŸ’œβœ¨

this was LLVM-COV(1), last touched 2025-09-03 πŸŽ€ β€” go forth and cov, my love 🫢🌈

πŸ“¦ where this page comes from