LLVM-COV(1)
π LLVM-COV(1) β the glow-up version π
okay bestie, so this is the LLVM-COV(1) manual page from the LLVM fam, and it's literally the whole vibe for coverage information. grab a strawberry drink π and let's go.
β¨ NAME β¨
llvm-cov β emit coverage information π
πΈ SYNOPSIS πΈ
llvm-cov command [args...]
π¦ DESCRIPTION π¦
so like, the llvm-cov tool shows code coverage information for programs that are instrumented to emit profile data. that's the whole main character energy right there π
it can be used to work with gcov-style coverage or with clang's instrumentation based profiling. two vibes, one tool, we love that for us π«Ά
and here's the little plot twist π if the program is invoked with a base name of gcov, it will behave as if the llvm-cov gcov command were called. otherwise, a command should be provided. no command, no coverage, no slay. periodt.
π 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 is compatible with the gcov tool from version 4.2 of GCC and may also be compatible with some later versions of gcov. so like, it's giving legacy support, and honestly? iconic. β
okay so here's the whole ritual, bestie, listen up π§
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. one flag, two jobs, efficient queen π
) you should compile with debugging information (-g) and without optimization (-O0); otherwise, the coverage data cannot be accurately mapped back to the source code. like, fr fr, -O0 is not optional if you want numbers that make sense π
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. not me accidentally double-counting my entire test suite π
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. so like, the files have to come home eventually π
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. so many little files, all of them your children now π₯Ή
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 #####. and honestly? ##### is the most dramatic thing in this whole manual π
π 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. every block gets its moment β¨-b,--branch-probabilitiesβ display conditional branch probabilities and a summary of branch information. the "which way did it go" report πΈ-c,--branch-countsβ display branch counts instead of probabilities (requires-b). so like, numbers instead of percentages. and yes, it requires-b, don't try to skip ahead bestie π-f,--function-summariesβ show a summary of coverage for each function instead of just one summary for an entire source file. per-function breakdown, very detail-oriented of you π--helpβ display available options (--help-hiddenfor more). the hidden ones are lowkey the fun ones π-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, long paths, no cap π-n,--no-outputβ do not output any.gcovfiles. summary information is still displayed. so you get the tea without 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.gcnoand.gcdaextensions. if you specify a directory, the files are expected in that directory with the same base name as the source file. pick your path, queen π£οΈ-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.#,^, chaos, love it π-u,--unconditional-branchesβ include unconditional branches in the output for the--branch-probabilitiesoption. yes, even the branches that had no choice. they deserve representation π«Ά-versionβ display the version ofllvm-cov. just the version. simple. clean. iconic.-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 and slaying π₯
π EXIT STATUS π
llvm-cov gcov returns 1 if it cannot read input files. otherwise, it exits with zero. so like, 1 means it's not reading, 0 means we're thriving π
β¨ SHOW COMMAND β¨
πΈ SYNOPSIS πΈ
llvm-cov show [options] -instr-profile PROFILE BIN [-object BIN,...]
[[-object BIN]] [SOURCES]
π DESCRIPTION π
Okay so llvm-cov show is THE main character of line-by-line coverage. It shows you the coverage of your binaries BIN,... line by line, using the profile data in PROFILE. And if you want, you can filter it down so it only shows coverage for the files you list in SOURCES. Bestie, it's so good.
BIN can be an executable, an object file, a dynamic library, or an archive (thin or otherwise) β it's flexible like that π«Ά.
To actually use llvm-cov show, you need a program compiled with instrumentation that emits profile and coverage data. To build that 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, the vibes will be off π).
The coverage information is stored inside the built executable or library itself, and that is what you pass to llvm-cov show as a BIN argument. The profile data gets generated by running this instrumented program normally β just, like, living its life. When the program exits, it writes out a raw profile file, typically called default.profraw, which you can convert into a format suitable for the PROFILE argument using the llvm-profdata merge tool. Slay.
β¨ OPTIONS β¨
-show-branches=<VIEW>β Show coverage for branch conditions, in terms of either count or percentage. The supported views are:"count","percent".-show-line-countsβ Show the execution counts for each line. Defaults totrue, unless another-showoption is used.-show-expansionsβ Expand inclusions, like preprocessor macros or textual inclusions, inline in the display of the source file. Defaults tofalse.-show-instantiationsβ For source regions that are instantiated multiple times, like templates in C++, show each instantiation separately and the combined summary. Defaults totrue.-show-regionsβ Show the execution counts for each region by displaying a caret that points to the character where the region starts. Defaults tofalse.-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 tofalse.-use-colorβ Enable or disable color output. By default this is autodetected. π-arch=[*NAMES*]β Specify a list of architectures such that the Nth entry in the list corresponds to the Nth specified binary. If the covered object is a universal binary, this specifies 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.-name=<NAME>β Show code coverage only for functions with the given name.-name-whitelist=<FILE>β Show code coverage only for functions listed in the given file. Each line in the file should start withwhitelist_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 with file paths that 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.-output-dir=PATHβ Specify a directory to write coverage reports into. If the directory doesn't exist, it is created. When used in function view mode (i.e. when-nameor-name-regexare used to select specific functions), the report is written toPATH/functions.EXTENSION. When used in file view mode, a report for each file is written toPATH/REL_PATH_TO_FILE.EXTENSION.-Xdemangler=<TOOL>|<TOOL-OPTION>β Specify a symbol demangler. This can be used to make reports 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β UseNthreads to write file reports (only applicable when-output-diris specified). WhenN=0, llvm-cov auto-detects an appropriate number of threads to use. This is the default.-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. Iconic cross-machine behaviour, honestly π¦.
π REPORT COMMAND π
π SYNOPSIS π
llvm-cov report [options] -instr-profile PROFILE BIN [-object BIN,...]
[[-object BIN]] [SOURCES]
πΈ DESCRIPTION πΈ
The llvm-cov report command displays a summary of the coverage of the binaries BIN,... using the profile data PROFILE. It can optionally be filtered to only show the coverage for the files listed in SOURCES. Same energy as show, but make it a highlight reel instead of the full episode.
BIN may be an executable, object file, dynamic library, or archive (thin or otherwise).
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.
For info on compiling programs for coverage and generating profile data, see SHOW COMMAND (scroll up, bestie π ).
β¨ 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 isn't included in the universal binary, or to use an architecture that doesn't match a non-universal binary.-show-branch-summaryβ Show statistics for all branch conditions. Defaults totrue.-show-functionsβ Show coverage summaries for each function. Defaults tofalse.-show-instantiation-summaryβ Show statistics for all function instantiations. Defaults tofalse.-ignore-filename-regex=<PATTERN>β Skip source code files with file paths that match the given regular expression.
π¦ EXPORT COMMAND π¦
π SYNOPSIS π
llvm-cov export [options] -instr-profile PROFILE BIN [-object BIN,...]
[[-object BIN]] [SOURCES]
π DESCRIPTION π
The llvm-cov export command exports coverage data of the binaries BIN,... using the profile data PROFILE, in either JSON or lcov trace file format. It's giving data-liberation, it's giving machine-readable β¨.
When exporting JSON, the regions, functions, branches, expansions, and summaries of the coverage data will be exported. When exporting an lcov trace file, the line-based coverage, branch coverage, and summaries will be exported.
The exported data can optionally be filtered to only export the coverage for the files listed in SOURCES.
For info 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 isn't included in the universal binary, or to use an architecture that doesn't 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-cov auto-detects an appropriate number of threads to use. This is the default.
π AUTHOR π
Maintained by the LLVM Team (https://llvm.org/). Kings, honestly.
π COPYRIGHT π
2003-2024, LLVM Project
okay that's the whole page bestie, and just so you know β this was LLVM-COV(1) from the 12th page of the 2024-07-18 release, and it was literally a whole journey. go forth and measure ur coverage, ily, periodt πβ¨π«Ά
π¦ where this page comes from
- fedora 43: llvm12 12.0.1-12.fc41 Β· NCSA
- fedora 43: llvm12 12.0.1-12.fc41 Β· NCSA
- fedora 44: llvm12 12.0.1-12.fc41 Β· NCSA
- fedora 44: llvm12 12.0.1-12.fc41 Β· NCSA
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms