LLVM-COV(1)
β¨ LLVM-COV(1) β¨
okay so bestie, welcome to the LLVM manual page for llvm-cov β and trust, this one is a whole vibe π
πΈ NAME πΈ
llvm-cov β emit coverage information π
π¦ SYNOPSIS π¦
llvm-cov command [argsβ¦]
β¨ DESCRIPTION β¨
So the llvm-cov tool shows code coverage information for programs that are instrumented to emit profile data. That's the whole point. It's giving receipts for your code. π
You can use it to work with gcov-style coverage or with clang's instrumentation based profiling. Both. She contains multitudes.
Now here's the cute little plot twist π: if the program gets invoked with a base name of gcov, it will behave as if the llvm-cov gcov command were called. Otherwise, you gotta provide a command. 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. She is compatible with the gcov tool from version 4.2 of GCC, and may also be compatible with some later versions of gcov. (may. we said may. don't come for her.) π
To use llvm-cov gcov, you must first build an instrumented version of your application that collects coverage data as it runs. So compile with the -fprofile-arcs and -ftest-coverage options to add the instrumentation. (Alternatively β iconique behavior β you can use the --coverage option, which includes both of those other options. Two birds, one flag. ποΈ)
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 comes from .gcda files, which get generated when you run the instrumented program, with a separate .gcda file for each object file. And listen π β 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. That's not a suggestion bestie, that's a warning. Old counts will sneak into your totals like an ex in your DMs. π
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. Here's the lore π§: 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 let you run the instrumented program on a machine where the original object file directories are not 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 like, cute trick, but there's homework. βοΈ
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. And run it from the same directory where you previously ran the compiler. (Same directory. She's sentimental like that. π₯Ί) 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. Every included file gets its own little moment. β¨
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. And the counts? Let's decode π:
- 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
#####.
##### is literally the code equivalent of screaming into the void. π
π 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. All the blocks, no crumbs. π§-b,--branch-probabilitiesβ Display conditional branch probabilities and a summary of branch information. She's showing her work. π-c,--branch-countsβ Display branch counts instead of probabilities (requires-b). Yes, you need-b. Don't try to skip steps bestie, it won't work. π«-m,--demangled-namesβ Demangle function names. Because_ZN3foo3barEvis not a personality. π-f,--function-summariesβ Show a summary of coverage for each function instead of just one summary for an entire source file. Per-function breakdown, main character energy for every function. π--helpβ Display available options (--help-hiddenfor more). There's always 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. Long names, long receipts. π-n,--no-outputβ Do not output any.gcovfiles. Summary information is still displayed though, so you're not left with nothing. π«Ά-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 fighter. π₯-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. Paths: preserved. Chaos: contained. π-rβ Only dump files with relative paths or absolute paths with the prefix specified by-s. Selective. We love a filter. π-s <string>β Source prefix to elide. That's it, that's the whole option. βοΈ-t,--stdoutβ Print to stdout instead of producing.gcovfiles. Straight to the terminal, no middleman. π₯οΈ-u,--unconditional-branchesβ Include unconditional branches in the output for the--branch-probabilitiesoption. Unconditional branches deserve representation too. π-versionβ Display the version ofllvm-cov. Know your build, bestie. β-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. Cryptographically cute. π
π EXIT STATUS π
llvm-cov gcov returns 1 if it cannot read input files. Otherwise, it exits with zero. Simple. Binary. No in-between. βοΈ
β¨ SHOW COMMAND β¨
πΈ SYNOPSIS πΈ
llvm-cov show [options] -instr-profile PROFILE [BIN] [-object BIN]β¦
[-sources] [SOURCE]β¦
π DESCRIPTION π
okay bestie so llvm-cov show is THE one that gives you the line-by-line coverage tea for the binaries BINβ¦, using the profile data PROFILE. and if you want, you can filter it so it only spills about the files you listed in SOURCEβ¦. chef's kiss. π
BIN can be literally any of these, no gatekeeping:
- an executable
- an object file
- a dynamic library
- an archive (thin or otherwise)
to even use llvm-cov show, you need a program that's been compiled with instrumentation so it actually emits profile and coverage data. to build that with clang, pass -fprofile-instr-generate and -fcoverage-mapping β both, together, periodt. and if you're linking with the clang driver, you gotta pass -fprofile-instr-generate to the link stage too so the necessary runtime libraries actually get linked in. don't skip that step, i'm begging π«Ά
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? that comes from just... running your instrumented program like normal. when it exits it writes out a raw profile file, typically called default.profraw, and then you convert it into something the PROFILE argument can actually eat using the llvm-profdata merge tool. iconic pipeline, honestly.
π OPTIONS π
-show-branches=<VIEW>β shows coverage for branch conditions, either as a count or as a percentage. the supported views are:"count","percent".-show-line-countsβ shows the execution counts for each line. defaults totrue, unless another-showoption is used.-show-expansionsβ expands inclusions (think preprocessor macros or textual inclusions) inline in the display of the source file. defaults tofalse.-show-instantiationsβ for source regions that get instantiated multiple times (looking at you, C++ templates π), shows each instantiation separately plus the combined summary. defaults totrue.-show-regionsβ shows 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β shows the execution counts for each line if there's only one region on the line, but shows the individual regions if there are multiple on the line. defaults tofalse.-use-colorβ enable or disable color output. by default this is autodetected. (vibe check does itself, slay)-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 is what picks 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.-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 withallowlist_fun:, immediately followed by the name of the function to accept. that 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 thehtmlformat. (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-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 make reports way more human-readable. you can specify this option 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β use N threads to write file reports (only applicable when-output-diris specified). 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.-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 usellvm-covon a different machine where you have the same files sitting at a different path. long-distance relationship but make it coverage π-coverage-watermark=<high>,<low>β set high and low watermarks for coverage inhtmlformat output. this lets you set the high and low watermark of coverage however you want: 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 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 (as with debuginfod). defaults to system build ID directories.
π 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. optionally you can filter it down to only show coverage for the files listed in SOURCEβ¦. π¦
BIN may be an executable, object file, dynamic library, or archive (thin or otherwise). same deal as show, no surprises.
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 the full lore on compiling programs for coverage and generating profile data, go peek at SHOW COMMAND. it's all there, 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'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 totrue.-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 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 viaDEBUGINFOD_URLS.-debug-file-directory=<dir>β provides a directory to search for objects corresponding to binary IDs in the profile.
π EXPORT COMMAND π
β¨ SYNOPSIS β¨
llvm-cov export [options] -instr-profile PROFILE [BIN] [-object BIN]β¦
[-sources] [SOURCE]β¦
π DESCRIPTION π
okay so llvm-cov export is the one that takes your coverage data and gives it to you in a file format, bestie. it exports the coverage data of the binaries BINβ¦ using the profile data PROFILE, and it can do that 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, what gets exported is the line-based coverage, branch coverage, and summaries. same tea, different cup π«Ά
and the exported data can optionally be filtered, so you only export the coverage for the files listed in SOURCEβ¦. very "I only want to see what I care about" of you, honestly iconic πΈ
For the whole lore on compiling programs for coverage and generating profile data, go read SHOW COMMAND β it's right there, no cap.
π 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 included in the universal binary, and it's also an error 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),"lcov". yes bestie, "text" is the JSON one, that's just how it is π-summary-onlyβ export only summary information for each file in the coverage data. this mode will not export coverage information for smaller units like individual functions or regions. the result will contain the same information as produced by thellvm-cov reportcommand, just presented in JSON or lcov format instead of text. same facts, cuter outfit β¨-ignore-filename-regex=<PATTERN>β skip source code files whose file paths match the given regular expression. bye girl, not you π-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 β and that's the default. multitasking queen π-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. it's giving "I'll find it myself, don't worry" π§-debug-file-directory=<dir>β provides a directory to search for objects corresponding to binary IDs in the profile.
π AUTHOR π
Maintained by the LLVM Team (https://llvm.org/). π
β COPYRIGHT β
2003-2024, LLVM Project
and that's the whole page, bestie!! π this part came from page 15, dated 2024-04-14, and it's LLVM-COV(1) β go forth and export your coverage, you absolute main character π¦π
π¦ where this page comes from
- ubuntu noble: llvm-16 1:16.0.6-23ubuntu4 Β· APACHE-2-LLVM-EXCEPTIONS
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms