LLVM-COV(1)

πŸ’– LLVM-COV(1) β€” straight from the LLVM manual, bestie πŸ’–

✨ NAME ✨

okay so llvm-cov is the tool that emits coverage information. That’s the whole vibe. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

llvm-cov command [args…]

🌸 DESCRIPTION 🌸

The llvm-cov tool shows code coverage information for programs that are instrumented to emit profile data. It can work with gcov-style coverage or with clang’s instrumentation based profiling. Both eras, honestly. πŸ‘‘

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. Like, pick one, bestie. 🫢


πŸ¦‹ 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 is compatible with the gcov tool from version 4.2 of GCC and may also be compatible with some later versions of gcov. Vintage but still cute. ✨

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.) Slay, compiler flags. πŸ”₯

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. fr fr, clean up those old .gcda files or the counts will pile up. πŸ’€

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. env-var relocation era, iconic but you still gotta move the files. 🧚

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. Very β€œone file for you and one for your bestie.” πŸŽ€

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 #####. That ##### is literally the β€œnever ran, bestie” marker. 😭

πŸ’… 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. Block-by-block detail, obsessed. πŸ’–
  • -b, --branch-probabilities β€” Display conditional branch probabilities and a summary of branch information.
  • -c, --branch-counts β€” Display branch counts instead of probabilities (requires -b). No -b, no branch-counts era. 🫢
  • -m, --demangled-names β€” Demangle function names.
  • -f, --function-summaries β€” Show a summary of coverage for each function instead of just one summary for an entire source file.
  • --help β€” Display available options (--help-hidden for 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, full paths, main-character filename energy. πŸ‘‘
  • -n, --no-output β€” Do not output any .gcov files. Summary information is still displayed.
  • -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.
  • -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-names option, this applies to both the main file name and the included file name.
  • -r β€” Only dump files with relative paths or absolute paths with the prefix specified by -s.
  • -s <string> β€” Source prefix to elide.
  • -t, --stdout β€” Print to stdout instead of producing .gcov files.
  • -u, --unconditional-branches β€” Include unconditional branches in the output for the --branch-probabilities option.
  • -version β€” Display the version of llvm-cov.
  • -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. Hash-named output files? Weird, cute, secure-ish vibe. ✨

⭐ EXIT STATUS ⭐

llvm-cov gcov returns 1 if it cannot read input files. Otherwise, it exits with zero. πŸ¦‹

✨ SHOW COMMAND ✨

🌸 SYNOPSIS 🌸

llvm-cov show [options] -instr-profile PROFILE BIN [-object BIN,…]
              [[-object BIN]] [SOURCES]

πŸ’– DESCRIPTION πŸ’–

Okay so llvm-cov show is the one that shows you coverage line by line, bestie β€” for the binaries BIN,…, using the profile data PROFILE. And if you want, you can filter it so it only shows coverage for the files you listed in SOURCES. Slay.

BIN can literally be an executable, an object file, a dynamic library, or an archive (thin or otherwise) β€” all valid, no gatekeeping πŸ’…

Now, to use llvm-cov show, you need a program that's compiled with instrumentation so it actually emits profile and coverage data. If you're building 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 get linked in β€” don't skip that step, iykyk 🫢

The coverage info gets stored in the built executable or library itself, and that is what you pass to llvm-cov show as the BIN argument. The profile data, though, comes from running your instrumented program normally β€” when it exits it writes out a raw profile file, typically called default.profraw, which you then convert into something suitable for the PROFILE argument using the llvm-profdata merge tool. Iconic little pipeline, honestly ✨


πŸŽ€ OPTIONS πŸŽ€

  • -show-branches=<VIEW> β€” show coverage for branch conditions, either as count or percentage. Supported views are: β€œcount”, β€œpercent”.
  • -show-line-counts β€” show the execution counts for each line. Defaults to true, unless another -show option is used.
  • -show-expansions β€” expand inclusions, like 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 (think templates in C++), show each instantiation separately plus the combined summary. Defaults to true.
  • -show-regions β€” show the 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 β€” show execution counts for each line if there's only one region on that line, but show 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.
  • -arch=NAMES** β€” specify a list of architectures such that the Nth entry corresponds to the Nth specified binary. If the covered object is a universal binary, this picks which architecture to use. It's an error to specify an architecture that isn't in the universal binary, or to use one 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-whitelist=<FILE> β€” show code coverage only for functions listed in the given file. Each line in the file should start with whitelist_fun:, immediately followed by the name of the function to accept. That name can be a wildcard expression too. Heads up: this option will be deprecated in favour of -name-allowlist=<FILE> in future releases πŸ™ˆ
  • -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. 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 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. Very demure, very organized πŸ’…
  • -Xdemangler=TOOL|TOOL-OPTION** β€” specify a symbol demangler, which makes reports 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 β€” 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. That's 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 coverage data on one machine, then run llvm-cov on a different machine where you have the same files at a different path. Bestie portability moment πŸ¦‹
  • -coverage-watermark=<high>,<low> β€” set high and low watermarks for coverage in html format output. This lets you pick 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. 🌈

πŸ‘‘ REPORT COMMAND πŸ‘‘

🌟 SYNOPSIS 🌟

llvm-cov report [options] -instr-profile PROFILE BIN [-object BIN,…]
                [[-object BIN]] [SOURCES]

πŸ’œ DESCRIPTION πŸ’œ

llvm-cov report gives you a summary of the coverage of the binaries BIN,… using the profile data PROFILE. And yep, you can optionally filter it so it only shows coverage for the files listed in SOURCES. Same energy, less line-by-line spam πŸŽ€

BIN may be an executable, object file, dynamic library, or archive (thin or otherwise) β€” same deal as always.

If no source files are provided, a summary line gets printed for each file in the coverage data. But if you do provide files, summaries can be shown for each function in the listed files β€” that is, if the -show-functions option is enabled. ✨

For the info on how to compile programs for coverage and generate profile data, go look at SHOW COMMAND β€” it's all up there, no cap.


🧚 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's an error to specify an architecture that isn't included in the universal binary, or to use one 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.

πŸ¦‹ EXPORT COMMAND πŸ¦‹

πŸ’« SYNOPSIS πŸ’«

llvm-cov export [options] -instr-profile PROFILE BIN [-object BIN,…]
                [[-object BIN]] [SOURCES]

πŸ“ DESCRIPTION πŸ“

llvm-cov export exports the coverage data of the binaries BIN,… using the profile data PROFILE, in either JSON or lcov trace file format. Pick your fighter 🫢

When you're exporting JSON, the regions, functions, branches, expansions, and summaries of the coverage data all get exported. When you're exporting an lcov trace file, the line-based coverage, branch coverage, and summaries get exported.

The exported data can optionally be filtered so you only export coverage for the files listed in SOURCES.

And for the info on compiling programs for coverage and generating profile data β€” again β€” see SHOW COMMAND. It's giving "go read the top of the page", but like, lovingly πŸ’–


⭐ OPTIONS ⭐

  • -arch=<name> β€” if the covered binary is a universal binary, select the architecture to use. It's an error to specify an architecture that isn't included in the universal binary, or to use one that doesn't match a non-universal binary. πŸ’€
  • -format=<FORMAT> β€” use the specified output format. 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 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. ✨
  • -ignore-filename-regex=<PATTERN> β€” skip source code files whose file paths 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. That's 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.

✨ AUTHOR ✨

So who's the icon behind all of this? The page says it's Maintained by the LLVM Team (https://llvm.org/). That's the whole credit, bestie β€” no individual names, just the squad. 🫢 Go say hi to them at that URL and tell them their coverage tool ate. πŸ‘‘


The copyright line reads: 2003-2023, LLVM Project. That's two whole decades of work, no cap β€” literally older than some of us. 😭 Respect the elders. 🌸


ngl, that's a wrap on the whole page, bestie β€” you've officially read the entire llvm-cov manual and your brain is now 100% more ✨coverage-aware✨ than it was before. πŸ’…

Okay so real talk, this whole thing was LLVM-COV(1), dated 2023-07-14, and it lives on page 15 of your manual β€” so if you ever need to find your way back, that's your coordinates. πŸ¦‹ Now go run some reports, get that coverage to 100%, and remember: untested code is not the vibe. periodt. πŸ’–πŸ”₯🌈

πŸ“¦ where this page comes from