• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1llvm-cov - emit coverage information
2====================================
3
4SYNOPSIS
5--------
6
7:program:`llvm-cov` [options] SOURCEFILE
8
9DESCRIPTION
10-----------
11
12The :program:`llvm-cov` tool reads code coverage data files and displays the
13coverage 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
15some later versions of ``gcov``.
16
17To use llvm-cov, you must first build an instrumented version of your
18application that collects coverage data as it runs. Compile with the
19``-fprofile-arcs`` and ``-ftest-coverage`` options to add the
20instrumentation. (Alternatively, you can use the ``--coverage`` option, which
21includes both of those other options.) You should compile with debugging
22information (``-g``) and without optimization (``-O0``); otherwise, the
23coverage data cannot be accurately mapped back to the source code.
24
25At the time you compile the instrumented code, a ``.gcno`` data file will be
26generated for each object file. These ``.gcno`` files contain half of the
27coverage data. The other half of the data comes from ``.gcda`` files that are
28generated when you run the instrumented program, with a separate ``.gcda``
29file for each object file. Each time you run the program, the execution counts
30are summed into any existing ``.gcda`` files, so be sure to remove any old
31files if you do not want their contents to be included.
32
33By default, the ``.gcda`` files are written into the same directory as the
34object files, but you can override that by setting the ``GCOV_PREFIX`` and
35``GCOV_PREFIX_STRIP`` environment variables. The ``GCOV_PREFIX_STRIP``
36variable specifies a number of directory components to be removed from the
37start of the absolute path to the object file directory. After stripping those
38directories, the prefix from the ``GCOV_PREFIX`` variable is added. These
39environment variables allow you to run the instrumented program on a machine
40where the original object file directories are not accessible, but you will
41then need to copy the ``.gcda`` files back to the object file directories
42where llvm-cov expects to find them.
43
44Once you have generated the coverage data files, run llvm-cov for each main
45source file where you want to examine the coverage results. This should be run
46from the same directory where you previously ran the compiler. The results for
47the specified source file are written to a file named by appending a ``.gcov``
48suffix. A separate output file is also created for each file included by the
49main source file, also with a ``.gcov`` suffix added.
50
51The basic content of an llvm-cov output file is a copy of the source file with
52an execution count and line number prepended to every line. The execution
53count is shown as ``-`` if a line does not contain any executable code. If
54a line contains code but that code was never executed, the count is displayed
55as ``#####``.
56
57
58OPTIONS
59-------
60
61.. option:: -a, --all-blocks
62
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.
66
67.. option:: -b, --branch-probabilities
68
69 Display conditional branch probabilities and a summary of branch information.
70
71.. option:: -c, --branch-counts
72
73 Display branch counts instead of probabilities (requires -b).
74
75.. option:: -f, --function-summaries
76
77 Show a summary of coverage for each function instead of just one summary for
78 an entire source file.
79
80.. option:: --help
81
82 Display available options (--help-hidden for more).
83
84.. option:: -l, --long-file-names
85
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.
90
91.. option:: -n, --no-output
92
93 Do not output any ``.gcov`` files. Summary information is still
94 displayed.
95
96.. option:: -o=<DIR|FILE>, --object-directory=<DIR>, --object-file=<FILE>
97
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
102 file.
103
104.. option:: -p, --preserve-paths
105
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
111 included file name.
112
113.. option:: -u, --unconditional-branches
114
115 Include unconditional branches in the output for the --branch-probabilities
116 option.
117
118.. option:: -version
119
120 Display the version of llvm-cov.
121
122EXIT STATUS
123-----------
124
125:program:`llvm-cov` returns 1 if it cannot read input files.  Otherwise, it
126exits with zero.
127
128