blob: f3e14f2304934c4bad254d02a478657a445113b9 [file] [log] [blame]
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +00001llvm-cov - emit coverage information
2====================================
3
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +00004SYNOPSIS
5--------
6
Bob Wilsonc16b7042014-05-06 15:58:06 +00007:program:`llvm-cov` [options] SOURCEFILE
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +00008
9DESCRIPTION
10-----------
11
Bob Wilsonc16b7042014-05-06 15:58:06 +000012The :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
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000057
58OPTIONS
59-------
60
Bob Wilsonc16b7042014-05-06 15:58:06 +000061.. option:: -a, --all-blocks
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000062
Bob Wilsonc16b7042014-05-06 15:58:06 +000063 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.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000066
Bob Wilsonc16b7042014-05-06 15:58:06 +000067.. option:: -b, --branch-probabilities
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000068
Bob Wilsonc16b7042014-05-06 15:58:06 +000069 Display conditional branch probabilities and a summary of branch information.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000070
Bob Wilsonc16b7042014-05-06 15:58:06 +000071.. option:: -c, --branch-counts
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +000072
Bob Wilsonc16b7042014-05-06 15:58:06 +000073 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:: -o=<DIR|FILE>, --object-directory=<DIR>, --object-file=<FILE>
92
93 Find objects in DIR or based on FILE's path. If you specify a particular
94 object file, the coverage data files are expected to have the same base name
95 with ``.gcno`` and ``.gcda`` extensions. If you specify a directory, the
96 files are expected in that directory with the same base name as the source
97 file.
98
99.. option:: -p, --preserve-paths
100
101 Preserve path components when naming the coverage output files. In addition
102 to the source file name, include the directories from the path to that
103 file. The directories are separate by ``#`` characters, with ``.`` directories
104 removed and ``..`` directories replaced by ``^`` characters. When used with
105 the --long-file-names option, this applies to both the main file name and the
106 included file name.
107
108.. option:: -u, --unconditional-branches
109
110 Include unconditional branches in the output for the --branch-probabilities
111 option.
112
113.. option:: -version
114
115 Display the version of llvm-cov.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000116
117EXIT STATUS
118-----------
119
Dmitri Gribenkoc9e206f2012-11-29 19:10:21 +0000120:program:`llvm-cov` returns 1 if it cannot read input files. Otherwise, it
121exits with zero.
Daniel Dunbar8f4a8a62012-05-08 16:50:35 +0000122