LLVM-COV(1)

πŸ“¦ version 15.0.7, in opensuse-leap 16.0

πŸ’– NAME πŸ’–

llvm-cov(1) from LLVM β€” literally here to emit coverage information. That's the whole main-character job, bestie. ✨

✨ SYNOPSIS ✨

llvm-cov command [args...]

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so llvm-cov is the tool that shows you code coverage information for programs that are instrumented to emit profile data. It can vibe with gcov-style coverage or with clang's instrumentation based profiling. If the program gets invoked with a base name of gcov, it's gonna behave as if the llvm-cov gcov command were called. Otherwise? A command should be provided β€” don't leave it hanging, 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's compatible with the gcov tool from version 4.2 of GCC, and may also be compatible with some later versions of gcov β€” so don't come for me if future-gcov is weird, iykyk. πŸ™ˆ

To use llvm-cov gcov, you first gotta build an instrumented version of your application that collects coverage data as it runs. Compile with -fprofile-arcs and -ftest-coverage to add the instrumentation. (Or use --coverage, which includes both of those other options β€” cute shortcut, same energy.) ✨

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 that are generated when you run the instrumented program, with a separate .gcda file for each object file. Every 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 last bit is important β€” stale counts do not slay. πŸ’€

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 gets 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'll then need to copy the .gcda files back to the object file directories where llvm-cov gcov expects to find them. 🫢

Once you've generated the coverage data files, run llvm-cov gcov for each main source file where you want to examine the coverage results. Run it from the same directory where you previously ran the compiler β€” yes, the same directory, bestie. 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. ✨

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 #####. So ##### is giving "this code walked so the test suite could run, but it never actually ran" energy. 😭

πŸ’… OPTIONS πŸ’…

Okay bestie, here's the full flag menu β€” no skips, no missing 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. 🧚
  • -b, --branch-probabilities β€” Display conditional branch probabilities and a summary of branch information. 🌈
  • -c, --branch-counts β€” Display branch counts instead of probabilities (requires -b). ⚠️
  • -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. πŸŽ€
  • -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 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. πŸ¦‹
  • -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. πŸ”₯

🌈 EXIT STATUS 🌈

llvm-cov gcov returns 1 if it cannot read input files. Otherwise, it exits with zero. Clean, simple, slay. πŸ’…

πŸ’… SHOW COMMAND πŸ’…

πŸ“œ SYNOPSIS

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

🌸 DESCRIPTION

Okay so llvm-cov show is the icon that gives you the line-by-line receipts on your binaries BIN,... using the profile data PROFILE. You can optionally filter it to only show coverage for the files you list in SOURCES β€” very "I only care about these files" of you, honestly.

BIN can be an executable, an object file, a dynamic library, or an archive (thin or otherwise). Versatile queen πŸ’….

To actually use llvm-cov show, bestie, you need a program compiled with instrumentation so it emits profile and coverage data. Build one with clang using 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, it's giving necessary πŸ’€.

The coverage info lives inside the built executable or library itself, and that's what you pass to llvm-cov show as a BIN argument. The profile data comes from running that instrumented program normally. When it exits, it writes out a raw profile file, typically called default.profraw, and you convert that into a format suitable for the PROFILE argument using the llvm-profdata merge tool. Slay, that's the whole pipeline ✨.

⭐ OPTIONS ⭐

  • -show-branches=<VIEW> β€” shows coverage for branch conditions, either as a count or as a percentage. Supported views: "count", "percent".
  • -show-line-counts β€” shows the execution counts for each line. Defaults to true, unless you use another -show option.
  • -show-expansions β€” expands inclusions (like preprocessor macros or textual inclusions) inline in the source file display. Defaults to false.
  • -show-instantiations β€” for source regions that get instantiated multiple times (C++ templates, looking at you πŸ‘€), shows each instantiation separately plus the combined summary. Defaults to true.
  • -show-regions β€” shows 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 per-line execution counts if there's only one region on the line, but shows the individual regions if there are multiple. Defaults to false.
  • -use-color β€” enables or disables color output. By default this is autodetected.
  • -arch=[*NAMES*] β€” specifies a list of architectures, where the Nth entry corresponds to the Nth specified binary. If the covered object is a universal binary, this specifies which 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 β€” so don't do that πŸ™ˆ.
  • -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. This name can be a wildcard expression.
  • -name-whitelist=<FILE> β€” shows code coverage only for functions listed in the given file. Each line should start with whitelist_fun:, immediately followed by the name of the function to accept. This name can be a wildcard expression. Heads up: this option will be deprecated for -name-allowlist=<FILE> in future releases.
  • -name-regex=<PATTERN> β€” shows code coverage only for functions that match 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. Supported formats: "text", "html".
  • -tab-size=<TABSIZE> β€” replaces tabs with TABSIZE spaces when preparing reports. Currently this is only supported for the html format.
  • -output-dir=PATH β€” specifies 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> β€” specifies a symbol demangler. This can make reports more human-readable (we love 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 β€” this is the default.
  • -compilation-dir=<dir> β€” the 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 lets you generate coverage data on one machine and then use llvm-cov on a different machine where you have the same files on a different path. Machine-hopping icon πŸ’«.
  • -coverage-watermark=<high>,<low> β€” sets the 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.

πŸŽ€ REPORT COMMAND πŸŽ€

πŸ“œ SYNOPSIS

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

🌸 DESCRIPTION

llvm-cov report is the summary queen πŸ‘‘ β€” 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 SOURCES.

BIN may be an executable, object file, dynamic library, or archive (thin or otherwise). Same energy as before, no cap.

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 if the -show-functions option is enabled.

For the information on compiling programs for coverage and generating profile data, see SHOW COMMAND β€” it's all up there, bestie. 🫢

⭐ OPTIONS ⭐

  • -use-color[=VALUE] β€” enables or disables color output. By default this is autodetected.
  • -arch=<name> β€” if the covered binary is a universal binary, selects 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-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> β€” the 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 coverage data of the binaries BIN,... using the profile data PROFILE, in either JSON or lcov trace file format. It's giving data pipeline main character energy ✨.

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 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, selects 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> β€” uses the specified output format. Supported formats: "text" (JSON), "lcov".
  • -summary-only β€” exports only summary information for each file in the coverage data. This mode won't export coverage info for smaller units like 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 instead of text. Literally the same tea, different cup πŸ“.
  • -ignore-filename-regex=<PATTERN> β€” skips source code files whose file paths match the given regular expression.
  • -skip-expansions β€” skips exporting macro expansion coverage data.
  • -skip-functions β€” skips exporting per-function coverage data.
  • -num-threads=N, -j=N β€” uses 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> β€” the 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 πŸ‘‘

Okay so this whole thing is maintained by the LLVM Team β€” literal icons β€” and you can find them at https://llvm.org/ if you wanna say hi or file a bug or whatever. 🫢

2003-2023, LLVM Project β€” that's the copyright, bestie. Respect the legacy. ✨


and that's the whole page!! πŸ’… You just read LLVM-COV(1), version 15, dated 2023-01-14 β€” go forth and cover your code, bestie, you're literally gonna slay those coverage reports πŸ¦‹πŸ’–πŸŽ€πŸŒΈβ­πŸ”₯πŸ‘‘πŸŒˆπŸ’œπŸ§šπŸ“

πŸ“¦ where this page comes from