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 🌈

  • gcov
  • show
  • report
  • export

πŸ‘‘ 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 causes llvm-cov to 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, -b is 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-hidden for 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-paths option 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 .gcov files. 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 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. 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-names option, 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 .gcov files. immediate screen moment. πŸ’–
  • -u, --unconditional-branches β€” include unconditional branches in the output for the --branch-probabilities option. more branch info when you ask for it. πŸ¦‹
  • -version β€” display the version of llvm-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 to true, unless another -show option 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 to false.
  • -show-instantiations β€” for source regions instantiated multiple times (think C++ templates), shows each instantiation separately plus the combined summary. Defaults to true.
  • -show-regions β€” shows execution counts for each region by displaying a caret pointing at the character where the region starts. Defaults to false.
  • -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 to false.
  • -show-directory-coverage β€” generates an index file in each directory containing at least one source file, with a top-level index showing aggregates. Defaults to false.
  • -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 with allowlist_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 the html format, 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 -name or -name-regex are used to select specific functions), the report is written to PATH/functions.EXTENSION. In file view mode, a report for each file is written to PATH/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 -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 β€” uses 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 β€” 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 use llvm-cov on a different machine where the same files live at a different path" situation πŸ¦‹. Multiple -path-equivalence arguments 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 in html format output 🌈. Green when coverage >= high, red when coverage < low, and yellow otherwise. Both high and low should be between 0-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 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 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 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 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 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. 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 the llvm-cov report command, 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 β€” Use N threads to export coverage data. 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.
  • -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 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/). πŸ‘‘


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