1 llvm-cov - emit coverage information
2 ====================================
7 :program:`llvm-cov` [options] SOURCEFILE
12 The :program:`llvm-cov` tool reads code coverage data files and displays the
13 coverage information for a specified source file. It is compatible with the
14 ``gcov`` tool from version 4.2 of ``GCC`` and may also be compatible with
15 some later versions of ``gcov``.
17 To use llvm-cov, you must first build an instrumented version of your
18 application that collects coverage data as it runs. Compile with the
19 ``-fprofile-arcs`` and ``-ftest-coverage`` options to add the
20 instrumentation. (Alternatively, you can use the ``--coverage`` option, which
21 includes both of those other options.) You should compile with debugging
22 information (``-g``) and without optimization (``-O0``); otherwise, the
23 coverage data cannot be accurately mapped back to the source code.
25 At the time you compile the instrumented code, a ``.gcno`` data file will be
26 generated for each object file. These ``.gcno`` files contain half of the
27 coverage data. The other half of the data comes from ``.gcda`` files that are
28 generated when you run the instrumented program, with a separate ``.gcda``
29 file for each object file. Each time you run the program, the execution counts
30 are summed into any existing ``.gcda`` files, so be sure to remove any old
31 files if you do not want their contents to be included.
33 By default, the ``.gcda`` files are written into the same directory as the
34 object files, but you can override that by setting the ``GCOV_PREFIX`` and
35 ``GCOV_PREFIX_STRIP`` environment variables. The ``GCOV_PREFIX_STRIP``
36 variable specifies a number of directory components to be removed from the
37 start of the absolute path to the object file directory. After stripping those
38 directories, the prefix from the ``GCOV_PREFIX`` variable is added. These
39 environment variables allow you to run the instrumented program on a machine
40 where the original object file directories are not accessible, but you will
41 then need to copy the ``.gcda`` files back to the object file directories
42 where llvm-cov expects to find them.
44 Once you have generated the coverage data files, run llvm-cov for each main
45 source file where you want to examine the coverage results. This should be run
46 from the same directory where you previously ran the compiler. The results for
47 the specified source file are written to a file named by appending a ``.gcov``
48 suffix. A separate output file is also created for each file included by the
49 main source file, also with a ``.gcov`` suffix added.
51 The basic content of an llvm-cov output file is a copy of the source file with
52 an execution count and line number prepended to every line. The execution
53 count is shown as ``-`` if a line does not contain any executable code. If
54 a line contains code but that code was never executed, the count is displayed
61 .. option:: -a, --all-blocks
63 Display all basic blocks. If there are multiple blocks for a single line of
64 source code, this option causes llvm-cov to show the count for each block
65 instead of just one count for the entire line.
67 .. option:: -b, --branch-probabilities
69 Display conditional branch probabilities and a summary of branch information.
71 .. option:: -c, --branch-counts
73 Display branch counts instead of probabilities (requires -b).
75 .. option:: -f, --function-summaries
77 Show a summary of coverage for each function instead of just one summary for
78 an entire source file.
82 Display available options (--help-hidden for more).
84 .. option:: -l, --long-file-names
86 For coverage output of files included from the main source file, add the
87 main file name followed by ``##`` as a prefix to the output file names. This
88 can be combined with the --preserve-paths option to use complete paths for
89 both the main file and the included file.
91 .. option:: -n, --no-output
93 Do not output any ``.gcov`` files. Summary information is still
96 .. option:: -o=<DIR|FILE>, --object-directory=<DIR>, --object-file=<FILE>
98 Find objects in DIR or based on FILE's path. If you specify a particular
99 object file, the coverage data files are expected to have the same base name
100 with ``.gcno`` and ``.gcda`` extensions. If you specify a directory, the
101 files are expected in that directory with the same base name as the source
104 .. option:: -p, --preserve-paths
106 Preserve path components when naming the coverage output files. In addition
107 to the source file name, include the directories from the path to that
108 file. The directories are separate by ``#`` characters, with ``.`` directories
109 removed and ``..`` directories replaced by ``^`` characters. When used with
110 the --long-file-names option, this applies to both the main file name and the
113 .. option:: -u, --unconditional-branches
115 Include unconditional branches in the output for the --branch-probabilities
120 Display the version of llvm-cov.
125 :program:`llvm-cov` returns 1 if it cannot read input files. Otherwise, it