LLVM-COV(1)

πŸ“¦
version 16.0.6 Β· 3 versions
, in ubuntu noble

✨ 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 πŸ‘‘

  • 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. 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 causes llvm-cov to 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 _ZN3foo3barEv is 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-hidden for 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-paths option to use complete paths for both the main file and the included file. Long names, long receipts. πŸ“œ
  • -n, --no-output β€” Do not output any .gcov files. 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 .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. 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-names option, 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 .gcov files. Straight to the terminal, no middleman. πŸ–₯️
  • -u, --unconditional-branches β€” Include unconditional branches in the output for the --branch-probabilities option. Unconditional branches deserve representation too. 🌈
  • -version β€” Display the version of llvm-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 to true, unless another -show option is used.
  • -show-expansions β€” expands inclusions (think preprocessor macros or textual inclusions) inline in the display of the source file. defaults to false.
  • -show-instantiations β€” for source regions that get instantiated multiple times (looking at you, C++ templates πŸ‘€), shows each instantiation separately plus the combined summary. defaults to true.
  • -show-regions β€” shows the execution counts for each region by displaying a caret that points to the character where the region starts. defaults to false.
  • -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 to false.
  • -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 with allowlist_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 the html format. (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 -name or -name-regex are used to select specific functions), the report is written to PATH/functions.EXTENSION. when used in file view mode, a report for each file is written to PATH/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 -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 β€” use 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. 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 use llvm-cov on 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 in html format 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 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 (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 to true.
  • -show-branch-summary β€” show statistics for all branch conditions. defaults to true.
  • -show-functions β€” show coverage summaries for each function. defaults to false.
  • -show-instantiation-summary β€” show statistics for all function instantiations. defaults to false.
  • -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 via DEBUGINFOD_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 the llvm-cov report command, 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 β€” use N threads to export coverage data. when N=0, llvm-cov auto-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 via DEBUGINFOD_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/). πŸ’–


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