1 llvm-cov - emit coverage information
2 ====================================
9 :program:`llvm-cov` *command* [*args...*]
14 The :program:`llvm-cov` tool shows code coverage information for
15 programs that are instrumented to emit profile data. It can be used to
16 work with ``gcov``\-style coverage or with ``clang``\'s instrumentation
19 If the program is invoked with a base name of ``gcov``, it will behave as if
20 the :program:`llvm-cov gcov` command were called. Otherwise, a command should
26 * :ref:`gcov <llvm-cov-gcov>`
27 * :ref:`show <llvm-cov-show>`
28 * :ref:`report <llvm-cov-report>`
29 * :ref:`export <llvm-cov-export>`
31 .. program:: llvm-cov gcov
41 :program:`llvm-cov gcov` [*options*] *SOURCEFILE*
46 The :program:`llvm-cov gcov` tool reads code coverage data files and displays
47 the coverage information for a specified source file. It is compatible with the
48 ``gcov`` tool from version 4.2 of ``GCC`` and may also be compatible with some
49 later versions of ``gcov``.
51 To use :program:`llvm-cov gcov`, you must first build an instrumented version
52 of your application that collects coverage data as it runs. Compile with the
53 ``-fprofile-arcs`` and ``-ftest-coverage`` options to add the
54 instrumentation. (Alternatively, you can use the ``--coverage`` option, which
55 includes both of those other options.)
57 At the time you compile the instrumented code, a ``.gcno`` data file will be
58 generated for each object file. These ``.gcno`` files contain half of the
59 coverage data. The other half of the data comes from ``.gcda`` files that are
60 generated when you run the instrumented program, with a separate ``.gcda``
61 file for each object file. Each time you run the program, the execution counts
62 are summed into any existing ``.gcda`` files, so be sure to remove any old
63 files if you do not want their contents to be included.
65 By default, the ``.gcda`` files are written into the same directory as the
66 object files, but you can override that by setting the ``GCOV_PREFIX`` and
67 ``GCOV_PREFIX_STRIP`` environment variables. The ``GCOV_PREFIX_STRIP``
68 variable specifies a number of directory components to be removed from the
69 start of the absolute path to the object file directory. After stripping those
70 directories, the prefix from the ``GCOV_PREFIX`` variable is added. These
71 environment variables allow you to run the instrumented program on a machine
72 where the original object file directories are not accessible, but you will
73 then need to copy the ``.gcda`` files back to the object file directories
74 where :program:`llvm-cov gcov` expects to find them.
76 Once you have generated the coverage data files, run :program:`llvm-cov gcov`
77 for each main source file where you want to examine the coverage results. This
78 should be run from the same directory where you previously ran the
79 compiler. The results for the specified source file are written to a file named
80 by appending a ``.gcov`` suffix. A separate output file is also created for
81 each file included by the main source file, also with a ``.gcov`` suffix added.
83 The basic content of an ``.gcov`` output file is a copy of the source file with
84 an execution count and line number prepended to every line. The execution
85 count is shown as ``-`` if a line does not contain any executable code. If
86 a line contains code but that code was never executed, the count is displayed
92 .. option:: -a, --all-blocks
94 Display all basic blocks. If there are multiple blocks for a single line of
95 source code, this option causes llvm-cov to show the count for each block
96 instead of just one count for the entire line.
98 .. option:: -b, --branch-probabilities
100 Display conditional branch probabilities and a summary of branch information.
102 .. option:: -c, --branch-counts
104 Display branch counts instead of probabilities (requires -b).
106 .. option:: -m, --demangled-names
108 Demangle function names.
110 .. option:: -f, --function-summaries
112 Show a summary of coverage for each function instead of just one summary for
113 an entire source file.
117 Display available options (--help-hidden for more).
119 .. option:: -l, --long-file-names
121 For coverage output of files included from the main source file, add the
122 main file name followed by ``##`` as a prefix to the output file names. This
123 can be combined with the --preserve-paths option to use complete paths for
124 both the main file and the included file.
126 .. option:: -n, --no-output
128 Do not output any ``.gcov`` files. Summary information is still
131 .. option:: -o <DIR|FILE>, --object-directory=<DIR>, --object-file=<FILE>
133 Find objects in DIR or based on FILE's path. If you specify a particular
134 object file, the coverage data files are expected to have the same base name
135 with ``.gcno`` and ``.gcda`` extensions. If you specify a directory, the
136 files are expected in that directory with the same base name as the source
139 .. option:: -p, --preserve-paths
141 Preserve path components when naming the coverage output files. In addition
142 to the source file name, include the directories from the path to that
143 file. The directories are separate by ``#`` characters, with ``.`` directories
144 removed and ``..`` directories replaced by ``^`` characters. When used with
145 the --long-file-names option, this applies to both the main file name and the
150 Only dump files with relative paths or absolute paths with the prefix specified
153 .. option:: -s <string>
155 Source prefix to elide.
157 .. option:: -t, --stdout
159 Print to stdout instead of producing ``.gcov`` files.
161 .. option:: -u, --unconditional-branches
163 Include unconditional branches in the output for the --branch-probabilities
168 Display the version of llvm-cov.
170 .. option:: -x, --hash-filenames
172 Use md5 hash of file name when naming the coverage output files. The source
173 file name will be suffixed by ``##`` followed by MD5 hash calculated for it.
178 :program:`llvm-cov gcov` returns 1 if it cannot read input files. Otherwise,
181 .. program:: llvm-cov show
191 :program:`llvm-cov show` [*options*] -instr-profile *PROFILE* [*BIN*] [*-object BIN*]... [*-sources*] [*SOURCE*]...
196 The :program:`llvm-cov show` command shows line by line coverage of the
197 binaries *BIN*... using the profile data *PROFILE*. It can optionally be
198 filtered to only show the coverage for the files listed in *SOURCE*....
200 *BIN* may be an executable, object file, dynamic library, or archive (thin or
203 To use :program:`llvm-cov show`, you need a program that is compiled with
204 instrumentation to emit profile and coverage data. To build such a program with
205 ``clang`` use the ``-fprofile-instr-generate`` and ``-fcoverage-mapping``
206 flags. If linking with the ``clang`` driver, pass ``-fprofile-instr-generate``
207 to the link stage to make sure the necessary runtime libraries are linked in.
209 The coverage information is stored in the built executable or library itself,
210 and this is what you should pass to :program:`llvm-cov show` as a *BIN*
211 argument. The profile data is generated by running this instrumented program
212 normally. When the program exits it will write out a raw profile file,
213 typically called ``default.profraw``, which can be converted to a format that
214 is suitable for the *PROFILE* argument using the :program:`llvm-profdata merge`
220 .. option:: -show-branches=<VIEW>
222 Show coverage for branch conditions in terms of either count or percentage.
223 The supported views are: "count", "percent".
225 .. option:: -show-line-counts
227 Show the execution counts for each line. Defaults to true, unless another
228 ``-show`` option is used.
230 .. option:: -show-expansions
232 Expand inclusions, such as preprocessor macros or textual inclusions, inline
233 in the display of the source file. Defaults to false.
235 .. option:: -show-instantiations
237 For source regions that are instantiated multiple times, such as templates in
238 ``C++``, show each instantiation separately as well as the combined summary.
241 .. option:: -show-regions
243 Show the execution counts for each region by displaying a caret that points to
244 the character where the region starts. Defaults to false.
246 .. option:: -show-line-counts-or-regions
248 Show the execution counts for each line if there is only one region on the
249 line, but show the individual regions if there are multiple on the line.
252 .. option:: -show-directory-coverage
254 Generate an index file in each directory that contains at least one source
255 file with a top level index showing aggregates. Defaults to false.
257 .. option:: -use-color
259 Enable or disable color output. By default this is autodetected.
261 .. option:: -arch=[*NAMES*]
263 Specify a list of architectures such that the Nth entry in the list
264 corresponds to the Nth specified binary. If the covered object is a universal
265 binary, this specifies the architecture to use. It is an error to specify an
266 architecture that is not included in the universal binary or to use an
267 architecture that does not match a non-universal binary.
269 .. option:: -name=<NAME>
271 Show code coverage only for functions with the given name.
273 .. option:: -name-allowlist=<FILE>
275 Show code coverage only for functions listed in the given file. Each line in
276 the file should start with `allowlist_fun:`, immediately followed by the name
277 of the function to accept. This name can be a wildcard expression.
279 .. option:: -name-regex=<PATTERN>
281 Show code coverage only for functions that match the given regular expression.
283 .. option:: -ignore-filename-regex=<PATTERN>
285 Skip source code files with file paths that match the given regular expression.
287 .. option:: -format=<FORMAT>
289 Use the specified output format. The supported formats are: "text", "html".
291 .. option:: -tab-size=<TABSIZE>
293 Replace tabs with <TABSIZE> spaces when preparing reports. Currently, this is
294 only supported for the html format.
296 .. option:: -output-dir=PATH
298 Specify a directory to write coverage reports into. If the directory does not
299 exist, it is created. When used in function view mode (i.e when -name or
300 -name-regex are used to select specific functions), the report is written to
301 PATH/functions.EXTENSION. When used in file view mode, a report for each file
302 is written to PATH/REL_PATH_TO_FILE.EXTENSION.
304 .. option:: -Xdemangler=<TOOL>|<TOOL-OPTION>
306 Specify a symbol demangler. This can be used to make reports more
307 human-readable. This option can be specified multiple times to supply
308 arguments to the demangler (e.g `-Xdemangler c++filt -Xdemangler -n` for C++).
309 The demangler is expected to read a newline-separated list of symbols from
310 stdin and write a newline-separated list of the same length to stdout.
312 .. option:: -num-threads=N, -j=N
314 Use N threads to write file reports (only applicable when -output-dir is
315 specified). When N=0, llvm-cov auto-detects an appropriate number of threads to
316 use. This is the default.
318 .. option:: -compilation-dir=<dir>
320 Directory used as a base for relative coverage mapping paths. Only applicable
321 when binaries have been compiled with one of `-fcoverage-prefix-map`
322 `-fcoverage-compilation-dir`, or `-ffile-compilation-dir`.
324 .. option:: -line-coverage-gt=<N>
326 Show code coverage only for functions with line coverage greater than the
329 .. option:: -line-coverage-lt=<N>
331 Show code coverage only for functions with line coverage less than the given
334 .. option:: -region-coverage-gt=<N>
336 Show code coverage only for functions with region coverage greater than the
339 .. option:: -region-coverage-lt=<N>
341 Show code coverage only for functions with region coverage less than the given
344 .. option:: -path-equivalence=<from>,<to>
346 Map the paths in the coverage data to local source file paths. This allows you
347 to generate the coverage data on one machine, and then use llvm-cov on a
348 different machine where you have the same files on a different path. Multiple
349 `-path-equivalence` arguments can be passed to specify different mappings. Each
350 argument consists of a source path `<from>` and its corresponding local path `<to>`.
351 The mappings are applied in the order they are specified. If multiple mappings can
352 be applied to a single path, the first mapping encountered is used.
354 .. option:: -coverage-watermark=<high>,<low>
356 Set high and low watermarks for coverage in html format output. This allows you
357 to set the high and low watermark of coverage as desired, green when
358 coverage >= high, red when coverage < low, and yellow otherwise. Both high and
359 low should be between 0-100 and high > low.
361 .. option:: -debuginfod
363 Use debuginfod to look up coverage mapping for binary IDs present in the
364 profile but not in any object given on the command line. Defaults to true if
365 debuginfod is compiled in and configured via the DEBUGINFOD_URLS environment
368 .. option:: -debug-file-directory=<dir>
370 Provides local directories to search for objects corresponding to binary IDs in
371 the profile (as with debuginfod). Defaults to system build ID directories.
373 .. option:: -check-binary-ids
375 Fail if an object file cannot be found for a binary ID present in the profile,
376 neither on the command line nor via binary ID lookup.
378 .. program:: llvm-cov report
388 :program:`llvm-cov report` [*options*] -instr-profile *PROFILE* [*BIN*] [*-object BIN*]... [*-sources*] [*SOURCE*]...
393 The :program:`llvm-cov report` command displays a summary of the coverage of
394 the binaries *BIN*... using the profile data *PROFILE*. It can optionally be
395 filtered to only show the coverage for the files listed in *SOURCE*....
397 *BIN* may be an executable, object file, dynamic library, or archive (thin or
400 If no source files are provided, a summary line is printed for each file in the
401 coverage data. If any files are provided, summaries can be shown for each
402 function in the listed files if the ``-show-functions`` option is enabled.
404 For information on compiling programs for coverage and generating profile data,
405 see :ref:`llvm-cov-show`.
410 .. option:: -use-color[=VALUE]
412 Enable or disable color output. By default this is autodetected.
414 .. option:: -arch=<name>
416 If the covered binary is a universal binary, select the architecture to use.
417 It is an error to specify an architecture that is not included in the
418 universal binary or to use an architecture that does not match a
419 non-universal binary.
421 .. option:: -show-region-summary
423 Show statistics for all regions. Defaults to true.
425 .. option:: -show-branch-summary
427 Show statistics for all branch conditions. Defaults to true.
429 .. option:: -show-functions
431 Show coverage summaries for each function. Defaults to false.
433 .. option:: -show-instantiation-summary
435 Show statistics for all function instantiations. Defaults to false.
437 .. option:: -ignore-filename-regex=<PATTERN>
439 Skip source code files with file paths that match the given regular expression.
441 .. option:: -compilation-dir=<dir>
443 Directory used as a base for relative coverage mapping paths. Only applicable
444 when binaries have been compiled with one of `-fcoverage-prefix-map`
445 `-fcoverage-compilation-dir`, or `-ffile-compilation-dir`.
447 .. option:: -debuginfod
449 Attempt to look up coverage mapping from objects using debuginfod. This is
450 attempted by default for binary IDs present in the profile but not provided on
451 the command line, so long as debuginfod is compiled in and configured via
454 .. option:: -debug-file-directory=<dir>
456 Provides a directory to search for objects corresponding to binary IDs in the
459 .. option:: -check-binary-ids
461 Fail if an object file cannot be found for a binary ID present in the profile,
462 neither on the command line nor via binary ID lookup.
464 .. program:: llvm-cov export
474 :program:`llvm-cov export` [*options*] -instr-profile *PROFILE* [*BIN*] [*-object BIN*]... [*-sources*] [*SOURCE*]...
479 The :program:`llvm-cov export` command exports coverage data of the binaries
480 *BIN*... using the profile data *PROFILE* in either JSON or lcov trace file
483 When exporting JSON, the regions, functions, branches, expansions, and
484 summaries of the coverage data will be exported. When exporting an lcov trace
485 file, the line-based coverage, branch coverage, and summaries will be exported.
487 The exported data can optionally be filtered to only export the coverage
488 for the files listed in *SOURCE*....
490 For information on compiling programs for coverage and generating profile data,
491 see :ref:`llvm-cov-show`.
496 .. option:: -arch=<name>
498 If the covered binary is a universal binary, select the architecture to use.
499 It is an error to specify an architecture that is not included in the
500 universal binary or to use an architecture that does not match a
501 non-universal binary.
503 .. option:: -format=<FORMAT>
505 Use the specified output format. The supported formats are: "text" (JSON),
508 .. option:: -summary-only
510 Export only summary information for each file in the coverage data. This mode
511 will not export coverage information for smaller units such as individual
512 functions or regions. The result will contain the same information as produced
513 by the :program:`llvm-cov report` command, but presented in JSON or lcov
514 format rather than text.
516 .. option:: -ignore-filename-regex=<PATTERN>
518 Skip source code files with file paths that match the given regular expression.
520 .. option:: -skip-expansions
522 Skip exporting macro expansion coverage data.
524 .. option:: -skip-functions
526 Skip exporting per-function coverage data.
528 .. option:: -num-threads=N, -j=N
530 Use N threads to export coverage data. When N=0, llvm-cov auto-detects an
531 appropriate number of threads to use. This is the default.
533 .. option:: -compilation-dir=<dir>
535 Directory used as a base for relative coverage mapping paths. Only applicable
536 when binaries have been compiled with one of `-fcoverage-prefix-map`
537 `-fcoverage-compilation-dir`, or `-ffile-compilation-dir`.
539 .. option:: -debuginfod
541 Attempt to look up coverage mapping from objects using debuginfod. This is
542 attempted by default for binary IDs present in the profile but not provided on
543 the command line, so long as debuginfod is compiled in and configured via
546 .. option:: -debug-file-directory=<dir>
548 Provides a directory to search for objects corresponding to binary IDs in the
551 .. option:: -check-binary-ids
553 Fail if an object file cannot be found for a binary ID present in the profile,
554 neither on the command line nor via binary ID lookup.
556 CONVERT-FOR-TESTING COMMAND
557 ---------------------------
560 This command is for the LLVM developers who are working on ``llvm-cov`` only.
565 :program:`llvm-cov convert-for-testing` *BIN* -o *OUT*
570 The :program:`llvm-cov convert-for-testing` command serves the purpose of
571 testing `llvm-cov` itself. It can extract all code coverage data from the
572 binary *BIN* to the file *OUT*, thereby reducing the size of test files. The
573 output file typically bears the :program:`.covmapping` extension.
575 The :program:`.covmapping` files can be read back by ``llvm-cov`` just as
576 ordinary binary files.