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 β¨
gcovshowreportexport
πΈ 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 makesllvm-covshow 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-hiddenfor 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-pathsoption to use complete paths for both the main file and the included file. collab energy π€-n,--no-outputβ do not output any.gcovfiles. 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.gcnoand.gcdaextensions. 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-namesoption, 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.gcovfiles.-u,--unconditional-branchesβ include unconditional branches in the output for the--branch-probabilitiesoption.-versionβ display the version ofllvm-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 totrue, unless you use another-showoption, 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 tofalse.-show-instantiationsβ for source regions that get instantiated multiple times (think C++ templates), it shows each instantiation separately and the combined summary. defaults totrue.-show-regionsβ shows execution counts for each region by drawing a caret pointing at the character where the region starts. defaults tofalse.-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 tofalse.-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 tofalse.-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 withallowlist_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 thehtmlformat.-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-nameor-name-regexare used to select specific functions), the report goes toPATH/functions.EXTENSION. when used in file view mode, a report for each file goes toPATH/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 -nfor 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-diris specified). whenN=0,llvm-covauto-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 runningllvm-covon a different machine where you have the same files at a different path. you can pass multiple-path-equivalencearguments 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 inhtmlformat 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, andhigh > 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 totrueif debuginfod is compiled in and configured via theDEBUGINFOD_URLSenvironment 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 totrue.-show-branch-summaryβ shows statistics for all branch conditions. defaults totrue.-show-mcdc-summaryβ shows MC/DC statistics. defaults tofalse.-show-functionsβ shows coverage summaries for each function. defaults tofalse.-show-instantiation-summaryβ shows statistics for all function instantiations. defaults tofalse.-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 viaDEBUGINFOD_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 thellvm-cov reportcommand 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β useNthreads to export coverage data. whenN=0,llvm-covauto-detects an appropriate number of threads to use. and thatN=0situation? 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 asdebuginfodis compiled in and configured viaDEBUGINFOD_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. π
β COPYRIGHT β
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
- fedora 43: llvm20 20.1.8-2.fc43 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- fedora 43: llvm20 20.1.8-2.fc43 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- fedora 44: llvm20 20.1.8-2.fc44 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- fedora 44: llvm20 20.1.8-2.fc44 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms