LLVM-COV(1)
π llvm-cov π
okay bestie, welcome to the LLVM-COV(1) page β aka the manual for llvm-cov, the coverage tool that is genuinely so useful and lowkey iconic. It's giving βlet me show you exactly what your code did when it ran.β β¨
πΈ NAME πΈ
llvm-cov β emit coverage information
π SYNOPSIS π
llvm-cov command [args...]
π¦ DESCRIPTION π¦
the llvm-cov tool shows code coverage info for programs that are instrumented to emit profile data. it can work with gcov-style coverage or with clang's instrumentation based profiling. no cap, it's flexible like that. π
if the program is invoked with a base name of gcov, it behaves as if the llvm-cov gcov command were called. otherwise, a command should be provided. yep, that's the vibe check. π«Ά
π COMMANDS π
gcovshowreportexport
π GCOV COMMAND π
β¨ SYNOPSIS β¨
llvm-cov gcov [options] SOURCEFILE
πΌ DESCRIPTION πΌ
the llvm-cov gcov tool reads code coverage data files and displays the coverage information for a specified source file. 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. slay. π
to use llvm-cov gcov, you must first build an instrumented version of your application that collects coverage data as it runs. compile with the -fprofile-arcs and -ftest-coverage options to add the instrumentation. (alternatively, you can use the --coverage option, which includes both of those other options.) literally the classic coverage setup. π
at the time you compile the instrumented code, a .gcno data file will be generated for each object file. these .gcno files contain half of the coverage data. the other half of the data comes from .gcda files that are generated when you run the instrumented program, with a separate .gcda file for each object file. each time you run the program, the execution counts are summed into any existing .gcda files, so be sure to remove any old files if you do not want their contents to be included. yes, that means stale data can accumulate β do not ignore that warning, bestie. π
by default, the .gcda files are 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. the GCOV_PREFIX_STRIP variable 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 is added. these environment variables allow you to run the instrumented program on a machine where the original object file directories are not accessible, but you will then need to copy the .gcda files back to the object file directories where llvm-cov gcov expects to find them. it's giving βportable but you still gotta do the copying.β π¦
once you have generated the coverage data files, run llvm-cov gcov for each main source file where you want to examine the coverage results. this should be run from the same directory where you previously ran the compiler. the results for the specified source file are written to a file named by appending a .gcov suffix. a separate output file is also created for each file included by the main source file, also with a .gcov suffix added. lots of .gcov files, lots of receipts. π
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 is shown as - if a line does not contain any executable code. if a line contains code but that code was never executed, the count is displayed as #####. iconic little symbols, honestly. π₯
π OPTIONS π
-a,--all-blocksβ display all basic blocks. if there are multiple blocks for a single line of source code, this option causesllvm-covto show the count for each block instead of just one count for the entire line. more detail, more drama. β¨-b,--branch-probabilitiesβ display conditional branch probabilities and a summary of branch information. branch lore unlocked. πΈ-c,--branch-countsβ display branch counts instead of probabilities (requires-b). yes,-bis required β don't skip the prerequisite, bestie. π«Ά-m,--demangled-namesβ demangle function names. because readable names are the moment. π-f,--function-summariesβ show a summary of coverage for each function instead of just one summary for an entire source file. per-function tea. π--helpβ display available options (--help-hiddenfor more). there's always more under the hood. π-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. long names, full context, no crumbs. π-n,--no-outputβ do not output any.gcovfiles. summary information is still displayed. so you still get the recap, just not the files. β¨-o <DIR|FILE>,--object-directory=<DIR>,--object-file=<FILE>β find objects inDIRor based onFILE'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. choose your fighter: directory or file path. π-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-namesoption, this applies to both the main file name and the included file name. path preservation, but make it keyboard-friendly. π-rβ only dump files with relative paths or absolute paths with the prefix specified by-s. filtered output, very selective, very main character. π-s <string>β source prefix to elide. short and sweet. π-t,--stdoutβ print to stdout instead of producing.gcovfiles. immediate screen moment. π-u,--unconditional-branchesβ include unconditional branches in the output for the--branch-probabilitiesoption. more branch info when you ask for it. π¦-versionβ display the version ofllvm-cov. gotta know what you're working with. β-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 MD5 hash calculated for it. hashed names, very security-coded, very cute. πβ¨
π¦ EXIT STATUS π¦
llvm-cov gcov returns 1 if it cannot read input files. otherwise, it exits with zero. simple, clear, no mystery. ππ
πΈ SHOW COMMAND πΈ
SYNOPSIS
llvm-cov show [options] -instr-profile PROFILE [BIN] [-object BIN]...
[-sources] [SOURCE]...
DESCRIPTION
okay so bestie, llvm-cov show is the one that shows you line-by-line coverage of the binaries BIN... using profile data PROFILE π
and yes, it can optionally be filtered so you only see coverage for the files you list in SOURCE..., which is lowkey the best part because who has time to scroll through everything.
Real talk: BIN can be an executable, an object file, a dynamic library, or an archive (thin or otherwise). Iconic range, honestly π«Ά.
To actually use llvm-cov show, you need a program compiled with instrumentation so it emits profile and coverage data. To build one with clang, 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 actually get linked in β don't skip this, it's giving "oh no why is nothing working" energy otherwise π.
The coverage info lives inside the built executable or library itself, and that is what you pass to llvm-cov show as the BIN argument. The profile data comes from just running this instrumented program like a normal person. When the program exits it writes out a raw profile file (typically called default.profraw), and you convert that into something suitable for the PROFILE argument using the llvm-profdata merge tool. slay π.
OPTIONS
-show-branches=<VIEW> β shows coverage for branch conditions, either as count or percentage. The supported views are:"count","percent".-show-mcdcβ shows modified condition/decision coverage (MC/DC) for every applicable boolean expression π.-show-line-countsβ shows execution counts for each line. Defaults totrue, unless another-showoption is used. (sneaky little default rule, iykyk)-show-expansionsβ expands inclusions (like preprocessor macros or textual inclusions) inline in the display of the source file. Defaults tofalse.-show-instantiationsβ for source regions instantiated multiple times (think C++ templates), shows each instantiation separately plus the combined summary. Defaults totrue.-show-regionsβ shows execution counts for each region by displaying a caret pointing at the character where the region starts. Defaults tofalse.-show-line-counts-or-regionsβ shows execution counts per line when there's only one region on the line, but shows the individual regions when there are multiple on the line. Defaults tofalse.-show-directory-coverageβ generates an index file in each directory containing at least one source file, with a top-level index showing aggregates. Defaults tofalse.-use-colorβ enables or disables color output. By default this is autodetected π.-arch=NAMES β specify a list of architectures where the Nth entry corresponds to 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 isn't in the universal binary, or to use an architecture that doesn't match a non-universal binary π.-name=<NAME>β shows code coverage only for functions with the given name.-name-allowlist=<FILE>β shows code coverage only for functions listed in the given file. Each line in the file should start withallowlist_fun:, immediately followed by the name of the function to accept. 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>β uses 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, ngl.-output-dir=PATHβ specifies a directory to write coverage reports into. If the directory doesn't exist, it gets created π«Ά. In function view mode (i.e. when-nameor-name-regexare used to select specific functions), the report is written toPATH/functions.EXTENSION. In file view mode, a report for each file is written toPATH/REL_PATH_TO_FILE.EXTENSION.-Xdemangler=<TOOL>|<TOOL-OPTION>β specifies a symbol demangler, which can make reports way more human-readable π. This option can be specified multiple times to supply arguments to the demangler (e.g.-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β usesNthreads to write file reports (only applicable when-output-diris specified). WhenN=0,llvm-covauto-detects an appropriate number of threads to use β and that's the default, bestie β.-compilation-dir=<dir>β a 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>β 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 whole "generate coverage data on one machine, then usellvm-covon a different machine where the same files live at a different path" situation π¦. Multiple-path-equivalencearguments can be passed to specify different mappings. Each argument is a source path<from>and its corresponding local path<to>. The mappings are applied in the order they're specified, and if multiple mappings can apply to a single path, the first mapping encountered is used. periodt.-coverage-watermark=<high>,<low>β sets high and low watermarks for coverage inhtmlformat output π. Green when coverage >= high, red when coverage < low, and yellow otherwise. Both high and low should be between0-100, and high > low.-debuginfodβ uses debuginfod to look up coverage mapping for binary IDs 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 idea as debuginfod). Defaults to 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 π no silent skipping, she checks.
π¦ REPORT COMMAND π¦
SYNOPSIS
llvm-cov report [options] -instr-profile PROFILE [BIN] [-object BIN]...
[-sources] [SOURCE]...
DESCRIPTION
So llvm-cov report is the summary girlie π
β it displays a summary of the coverage of the binaries BIN... using the profile data PROFILE. It can optionally be filtered to only show coverage for the files listed in SOURCE..., same deal as before.
BIN may be an executable, an object file, a dynamic library, or an archive (thin or otherwise) β¨.
Here's the tea: if no source files are provided, a summary line is 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. ikr.
For info on compiling programs for coverage and generating profile data, see SHOW COMMAND above π (we already covered all that, you're welcome).
OPTIONS
-use-color[=VALUE]β enables or disables 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 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 applicable when binaries have been 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 but not 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. she's strict, respect it π.
okay and there's more coming, don't go anywhere β
π€ EXPORT COMMAND π€
SYNOPSIS
llvm-cov export [options] -instr-profile PROFILE [BIN] [-object BIN]...
[-sources] [SOURCE]...
DESCRIPTION
Okay so the llvm-cov export command is the one that packages up coverage data from the binaries BIN... using the profile data PROFILE, and it can spit it out in either JSON or lcov trace file format. π
When youβre exporting JSON, the regions, functions, branches, expansions, and summaries of the coverage data get exported. When youβre exporting an lcov trace file, the line-based coverage, branch coverage, and summaries get exported. Slay. β¨
The exported data can optionally be filtered to only export the coverage for the files listed in SOURCE....
For the tea on compiling programs for coverage and generating profile data, see SHOW COMMAND. π«Ά
β¨ OPTIONS β¨
-arch=<name>β If the covered binary is a universal binary, select the architecture to use. It is an error to specify an architecture that is not included in the universal binary or to use an architecture that does not match a non-universal binary. π-format=<FORMAT>β Use the specified output format. The supported formats are:"text"(JSON),"lcov".-summary-onlyβ Export only summary information for each file in the coverage data. This mode will not export coverage information for smaller units such as individual functions or regions. The result will contain the same information as produced by thellvm-cov reportcommand, but presented in JSON or lcov format rather than text. π-ignore-filename-regex=<PATTERN>β Skip source code files with file paths that match the given regular expression.-skip-expansionsβ Skip exporting macro expansion coverage data.-skip-functionsβ Skip exporting per-function coverage data.-num-threads=N,-j=Nβ UseNthreads to export coverage data. WhenN=0,llvm-covauto-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.-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 viaDEBUGINFOD_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 cannot be found for a binary ID present in the profile, neither on the command line nor via binary ID lookup. π
π§ͺ CONVERT-FOR-TESTING COMMAND π§ͺ
β οΈ WARNING: This command is for the LLVM developers who are working on llvm-cov only. β οΈ
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, thereby reducing the size of test files. The output file typically bears the .covmapping extension. πΈ
The .covmapping files can be read back by llvm-cov just as ordinary binary files. No cap. π
π AUTHOR π
Maintained by the LLVM Team (https://llvm.org/). π
π COPYRIGHT π
2003-2025, LLVM Project
π Thatβs the whole LLVM-COV(1) moment, bestie β the cute little footer tea is version 19, dated 2025-01-17. Stay covered and stay iconic! π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: llvm19 19.1.7-160000.2.2 Β· Apache-2.0 WITH LLVM-exception AND NCSA
- opensuse-leap 16.0: llvm19 19.1.7-160000.2.2 Β· Apache-2.0 WITH LLVM-exception AND NCSA
- opensuse-leap 16.0: llvm19 19.1.7-160000.2.2 Β· Apache-2.0 WITH LLVM-exception AND NCSA
- opensuse-leap 16.0: llvm19 19.1.7-160000.2.2 Β· Apache-2.0 WITH LLVM-exception AND NCSA
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms