LLVM-COV(1)

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

okay bestie, welcome to llvm-cov, the LLVM manual page, and honestly? it's giving ✨main character energy✨ because it's a whole suite of tools wearing one trenchcoat. let's get into it 🫢


🌸 SYNOPSIS

llvm-cov command [args...]

πŸ¦‹ DESCRIPTION

so llvm-cov shows you code coverage information for programs that are instrumented to emit profile data. that's the whole vibe. you can use it to work with gcov-style coverage, or with clang's instrumentation based profiling. both. either. iconic of it tbh.

and here's a little plot twist for you: if the program gets invoked with a base name of gcov, it just behaves as if the llvm-cov gcov command were called. sneaky! otherwise, bestie, you gotta provide a command. no command, no coverage, no slay. 😭


πŸ‘‘ COMMANDS

these are the flavors, pick your fighter:

  • gcov
  • show
  • report
  • export

πŸŽ€ GCOV COMMAND

✨ SYNOPSIS

llvm-cov gcov [options] SOURCEFILE

πŸ’– DESCRIPTION

okay so the llvm-cov gcov tool reads code coverage data files and displays the coverage info for a source file you pick. it's compatible with the gcov tool from version 4.2 of GCC, and it may also be compatible with some later versions of gcov. may!! no promises!! πŸ™ˆ

to use llvm-cov gcov, you first have to build an instrumented version of your app that collects coverage data as it runs. compile with the -fprofile-arcs and -ftest-coverage options to add that instrumentation. (or alternatively, use the --coverage option, which just includes both of those other options β€” two birds, one flag, we love efficiency πŸ’…)

the way that this works: at the time you compile the instrumented code, a .gcno data file gets generated for each object file. those .gcno files hold half of the coverage data. the other half comes from .gcda files, which get generated when you run the instrumented program β€” and there's a separate .gcda file for each object file, periodt.

⚠️ heads up bestie: every single time you run the program, the execution counts get summed into any existing .gcda files. so if you don't want old data mixed in, go delete those old files first. not a drill. πŸ”₯

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. here's how those two work together:

  • 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 the GCOV_PREFIX variable gets added.

these env vars let you run the instrumented program on a machine where the original object file directories aren't accessible. but β€” and this is the catch β€” you'll then need to copy the .gcda files back to the object file directories where llvm-cov gcov expects to find them. so it's a little field trip for your files 🧚

once you've generated the coverage data files, run llvm-cov gcov for each main source file where you want to examine the coverage results. run it from the same directory where you previously ran the compiler (yes, that 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. everyone gets a file, we're inclusive here.

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 does contain code but that code was never executed, the count is displayed as #####. dramatic but accurate πŸ’€


⭐ OPTIONS

  • -a, --all-blocks β€” display all basic blocks. if there are 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 entire line. more data, more fun.
  • -b, --branch-probabilities β€” display conditional branch probabilities, plus a summary of branch information. 🌿
  • -c, --branch-counts β€” display branch counts instead of probabilities. (requires -b! don't forget the -b, bestie 🫢)
  • -m, --demangled-names β€” demangle function names. give those names their glow-up ✨
  • -f, --function-summaries β€” show a summary of coverage for each function, instead of just one summary for an entire source file.
  • --help β€” display available options. (--help-hidden for more, if you're nosy πŸ‘€)
  • -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.
  • -n, --no-output β€” do not output any .gcov files. summary information is still displayed though, so you're not missing out.
  • -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 separated 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. stream it straight to your eyeballs πŸ’œ
  • -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. cryptographic glow-up πŸ”

🌈 EXIT STATUS

llvm-cov gcov returns 1 if it can't read input files. otherwise, it exits with zero. simple as that, no cap. πŸ“


✨ SHOW COMMAND ✨

πŸŽ€ SYNOPSIS

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

πŸ’… DESCRIPTION

okay so llvm-cov show is the one that goes line by line through your binaries BIN... and shows you the coverage using the profile data in PROFILE. you can also filter it so it only shows the tea for the files you listed in SOURCE... β€” bestie behaviour honestly. πŸ’–

and BIN? it can be literally any of these: an executable, an object file, a dynamic library, or an archive (thin or otherwise). slay, versatile. ✨

to actually use llvm-cov show you need a program that was 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, pass -fprofile-instr-generate to the link stage too, so the necessary runtime libraries get linked in. no skipping that step, it matters. 🫢

the coverage info lives inside the built executable or library itself, and that's the thing you hand over to llvm-cov show as a BIN argument. the profile data comes from running that instrumented program like normal β€” when it exits it writes out a raw profile file, usually called default.profraw, and you convert that into something suitable for the PROFILE argument using the llvm-profdata merge tool. it's giving pipeline. it's giving main character workflow. πŸ‘‘


πŸ”₯ OPTIONS πŸ”₯

  • -show-branches=<VIEW> β€” show coverage for branch conditions, either as a count or a percentage. the supported views are: "count", "percent". pick your fighter. πŸ’…
  • -show-mcdc β€” show modified condition/decision coverage (MC/DC) for each applicable boolean expression. fancy AND thorough, we love that for you. ✨
  • -show-line-counts β€” show the execution counts for each line. defaults to true, unless another -show option gets used. πŸ™ˆ
  • -show-expansions β€” expand inclusions, like preprocessor macros or textual inclusions, inline in the display of the source file. defaults to false.
  • -show-instantiations β€” for source regions that get instantiated multiple times (looking at you, C++ templates πŸ‘€), show each instantiation separately and the combined summary. defaults to true.
  • -show-regions β€” show the execution counts for each region by displaying a caret that points to the character where the region starts. defaults to false.
  • -show-line-counts-or-regions β€” show the execution counts for each line if there's only one region on the line, but show the individual regions if there are multiple on the line. defaults to false.
  • -show-directory-coverage β€” generate an index file in each directory that contains at least one source file, with a top level index showing aggregates. defaults to false.
  • -use-color β€” enable or disable color output. by default this is autodetected. ✨
  • -arch=[*NAMES*] β€” specify a list of architectures where the Nth entry lines up with the Nth specified binary. if the covered object is a universal binary, this says which architecture to use. it is an error to specify an architecture that's not included in the universal binary, or to use an architecture that doesn't match a non-universal binary. ⚠️
  • -name=<NAME> β€” show code coverage only for functions with the given name.
  • -name-allowlist=<FILE> β€” show code coverage only for functions listed in the given file. each line in the file should start with allowlist_fun:, immediately followed by the name of the function to accept. this name can be a wildcard expression. πŸ¦‹
  • -name-regex=<PATTERN> β€” show code coverage only for functions that match the given regular expression.
  • -ignore-filename-regex=<PATTERN> β€” skip 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> β€” replace tabs with <TABSIZE> spaces when preparing reports. currently this is only supported for the html format. (iykyk) πŸ™ˆ
  • -output-dir=PATH β€” specify a directory to write coverage reports into. if the directory doesn't exist, it gets created. when used in function view mode (i.e. when -name or -name-regex are used to select specific functions), the report is written to PATH/functions.EXTENSION. when used in file view mode, a report for each file is written to PATH/REL_PATH_TO_FILE.EXTENSION. πŸ’–
  • -Xdemangler=<TOOL>|<TOOL-OPTION> β€” specify a symbol demangler. this can make reports more human-readable. this option can be specified multiple times to supply arguments to the demangler (e.g. -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 applicable when -output-dir is specified). when N=0, llvm-cov auto-detects an appropriate number of threads to use. this is the default. ⭐
  • -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.
  • -line-coverage-gt=<N> β€” show code coverage only for functions with line coverage greater than the given threshold.
  • -line-coverage-lt=<N> β€” show code coverage only for functions with line coverage less than the given threshold.
  • -region-coverage-gt=<N> β€” show code coverage only for functions with region coverage greater than the given threshold.
  • -region-coverage-lt=<N> β€” show code coverage only for functions with region coverage less than the given threshold.
  • -path-equivalence=<from>,<to> β€” map the paths in the coverage data to local source file paths. this lets you generate the coverage data on one machine and then use llvm-cov on a different machine where you have the same files on a different path. multiple -path-equivalence arguments can be passed to specify different mappings. each argument consists of a source path <from> and its corresponding local path <to>. the mappings are applied in the order they're specified. if multiple mappings can be applied to a single path, the first mapping encountered is used. 🌈
  • -coverage-watermark=<high>,<low> β€” set high and low watermarks for coverage in html format output. this lets you set the high and low watermark of coverage as desired: green when coverage >= high, red when coverage < low, and yellow otherwise. both high and low should be between 0-100 and high > low. 🎨
  • -debuginfod β€” use debuginfod to look up coverage mapping for binary IDs 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 (as with debuginfod). defaults to system build ID directories.
  • -check-binary-ids β€” fail 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. πŸ’€
  • -empty-profile β€” display the baseline coverage of the binaries with all zero execution counts. mutually exclusive with -instr-profile. (can't have both bestie, pick one 😭)

πŸ“Š REPORT COMMAND πŸ“Š

πŸŽ€ SYNOPSIS

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

πŸ’… DESCRIPTION

llvm-cov report is the summary girly of the family. it displays a summary of the coverage of the binaries BIN... using the profile data PROFILE, and it can optionally be filtered to only show coverage for the files listed in SOURCE.... πŸ’–

and again, BIN can be an executable, an object file, a dynamic library, or an archive (thin or otherwise). iconic range. ✨

if no source files are provided, a summary line gets printed for each file in the coverage data. if any files are provided, summaries can be shown for each function in the listed files β€” but only if the -show-functions option is enabled. πŸ‘‘

for info on compiling programs for coverage and generating profile data, see SHOW COMMAND. (it's right up there bestie, go look 🫢)


πŸ”₯ OPTIONS πŸ”₯

  • -use-color[=VALUE] β€” enable or disable color output. by default this is autodetected.
  • -arch=<name> β€” if the covered binary is a universal binary, select the architecture to use. it is an error to specify an architecture that's not included in the universal binary, or to use an architecture that doesn't match a non-universal binary. ⚠️
  • -show-region-summary β€” show statistics for all regions. defaults to true.
  • -show-branch-summary β€” show statistics for all branch conditions. defaults to true.
  • -show-mcdc-summary β€” show MC/DC statistics. defaults to false.
  • -show-functions β€” show coverage summaries for each function. defaults to false.
  • -show-instantiation-summary β€” show statistics for all function instantiations. defaults to false.
  • -ignore-filename-regex=<PATTERN> β€” skip source code files whose file paths match the given regular expression.
  • -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.
  • -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. πŸ¦‹
  • -debug-file-directory=<dir> β€” provides a directory to search for objects corresponding to binary IDs in the profile.
  • -check-binary-ids β€” fail 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. πŸ’€
  • -empty-profile β€” display the baseline coverage of the binaries with all zero execution counts. mutually exclusive with -instr-profile. (again β€” pick one, not both 😭)

✨ EXPORT COMMAND ✨

🌸 SYNOPSIS 🌸

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

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay bestie so the llvm-cov export command is the one that ships your coverage data out the door πŸ’Œ β€” it takes the coverage data from the binaries BIN... and, using the profile data PROFILE, exports it in either JSON or lcov trace file format. 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, branch coverage, and summaries. Different format, different vibe, same data underneath, iykyk πŸ’…

And if you want, the exported data can be filtered β€” you can tell it to only export the coverage for the files listed in SOURCE.... Very demure, very selective πŸŽ€

Wanna know how to actually compile programs for coverage and generate profile data in the first place? That's all in SHOW COMMAND, go look 🫢


πŸ‘‘ OPTIONS πŸ‘‘

  • -arch=<name> β€” if the covered binary is a universal binary, this picks which architecture to use. And heads up: it is an error to specify an architecture that isn't actually in the universal binary, or to use an architecture that doesn't match a non-universal binary. So like… don't do that 😭
  • -format=<FORMAT> β€” use the specified output format. The supported formats are: "text" (JSON), and "lcov". That's the whole menu bestie.
  • -summary-only β€” export only the 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 contains the same information that the llvm-cov report command produces, but presented in JSON or lcov format rather than text. Same tea, different cup β˜•
  • -ignore-filename-regex=<PATTERN> β€” skip source code files whose file paths match the given regular expression. Begone, irrelevant files 🚫
  • -skip-expansions β€” skip exporting macro expansion coverage data. No expansions today, thank you πŸ™ˆ
  • -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'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. Conditional queen πŸ‘‘
  • -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. Very "I'll find it myself" energy πŸ”
  • -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 mode: activated πŸ”₯
  • -empty-profile β€” export the baseline coverage of the binaries with all zero execution counts. Mutually exclusive with -instr-profile β€” you literally cannot have both, they're beefing βš”οΈ

πŸ’– CONVERT-FOR-TESTING COMMAND πŸ’–

⚠️ WARNING: this command is for the LLVM developers who are working on llvm-cov only. It is not for you, bestie, unless you are an LLVM dev working on llvm-cov. Read the room 🫣

🧚 SYNOPSIS 🧚

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

🌈 DESCRIPTION 🌈

The llvm-cov convert-for-testing command exists for one purpose and one purpose only: testing llvm-cov itself. It can extract all the code coverage data from the binary BIN into the file OUT, which has the side effect of reducing the size of test files. The output file typically rocks the .covmapping extension πŸ’…

And the plot twist? Those .covmapping files can be read back by llvm-cov just as if they were ordinary binary files. Iconic, honestly πŸ‘‘


πŸŽ€ AUTHOR πŸŽ€

Maintained by the LLVM Team (https://llvm.org/). They keep the whole thing running, no cap 🫢


2003-2026, LLVM Project β€” the copyright holding it down since way back πŸ’œ


And that's the whole page, bestie!! πŸŽ‰ This was the LLVM-COV(1) manual, from the 21 release, dated 2026-07-22 β€” the source is the LLVM Project and the version number is right there in the footer. Go forth and export your coverage data, you absolute main character πŸŒΈπŸ’–βœ¨

πŸ“¦ where this page comes from