• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1llvm-cov - emit coverage information
2====================================
3
4SYNOPSIS
5--------
6
7:program:`llvm-cov` *command* [*args...*]
8
9DESCRIPTION
10-----------
11
12The :program:`llvm-cov` tool shows code coverage information for
13programs that are instrumented to emit profile data. It can be used to
14work with ``gcov``\-style coverage or with ``clang``\'s instrumentation
15based profiling.
16
17If the program is invoked with a base name of ``gcov``, it will behave as if
18the :program:`llvm-cov gcov` command were called. Otherwise, a command should
19be provided.
20
21COMMANDS
22--------
23
24* :ref:`gcov <llvm-cov-gcov>`
25* :ref:`show <llvm-cov-show>`
26* :ref:`report <llvm-cov-report>`
27
28.. program:: llvm-cov gcov
29
30.. _llvm-cov-gcov:
31
32GCOV COMMAND
33------------
34
35SYNOPSIS
36^^^^^^^^
37
38:program:`llvm-cov gcov` [*options*] *SOURCEFILE*
39
40DESCRIPTION
41^^^^^^^^^^^
42
43The :program:`llvm-cov gcov` tool reads code coverage data files and displays
44the coverage information for a specified source file. It is compatible with the
45``gcov`` tool from version 4.2 of ``GCC`` and may also be compatible with some
46later versions of ``gcov``.
47
48To use :program:`llvm-cov gcov`, you must first build an instrumented version
49of your application that collects coverage data as it runs. Compile with the
50``-fprofile-arcs`` and ``-ftest-coverage`` options to add the
51instrumentation. (Alternatively, you can use the ``--coverage`` option, which
52includes both of those other options.) You should compile with debugging
53information (``-g``) and without optimization (``-O0``); otherwise, the
54coverage data cannot be accurately mapped back to the source code.
55
56At the time you compile the instrumented code, a ``.gcno`` data file will be
57generated for each object file. These ``.gcno`` files contain half of the
58coverage data. The other half of the data comes from ``.gcda`` files that are
59generated when you run the instrumented program, with a separate ``.gcda``
60file for each object file. Each time you run the program, the execution counts
61are summed into any existing ``.gcda`` files, so be sure to remove any old
62files if you do not want their contents to be included.
63
64By default, the ``.gcda`` files are written into the same directory as the
65object files, but you can override that by setting the ``GCOV_PREFIX`` and
66``GCOV_PREFIX_STRIP`` environment variables. The ``GCOV_PREFIX_STRIP``
67variable specifies a number of directory components to be removed from the
68start of the absolute path to the object file directory. After stripping those
69directories, the prefix from the ``GCOV_PREFIX`` variable is added. These
70environment variables allow you to run the instrumented program on a machine
71where the original object file directories are not accessible, but you will
72then need to copy the ``.gcda`` files back to the object file directories
73where :program:`llvm-cov gcov` expects to find them.
74
75Once you have generated the coverage data files, run :program:`llvm-cov gcov`
76for each main source file where you want to examine the coverage results. This
77should be run from the same directory where you previously ran the
78compiler. The results for the specified source file are written to a file named
79by appending a ``.gcov`` suffix. A separate output file is also created for
80each file included by the main source file, also with a ``.gcov`` suffix added.
81
82The basic content of an ``.gcov`` output file is a copy of the source file with
83an execution count and line number prepended to every line. The execution
84count is shown as ``-`` if a line does not contain any executable code. If
85a line contains code but that code was never executed, the count is displayed
86as ``#####``.
87
88OPTIONS
89^^^^^^^
90
91.. option:: -a, --all-blocks
92
93 Display all basic blocks. If there are multiple blocks for a single line of
94 source code, this option causes llvm-cov to show the count for each block
95 instead of just one count for the entire line.
96
97.. option:: -b, --branch-probabilities
98
99 Display conditional branch probabilities and a summary of branch information.
100
101.. option:: -c, --branch-counts
102
103 Display branch counts instead of probabilities (requires -b).
104
105.. option:: -f, --function-summaries
106
107 Show a summary of coverage for each function instead of just one summary for
108 an entire source file.
109
110.. option:: --help
111
112 Display available options (--help-hidden for more).
113
114.. option:: -l, --long-file-names
115
116 For coverage output of files included from the main source file, add the
117 main file name followed by ``##`` as a prefix to the output file names. This
118 can be combined with the --preserve-paths option to use complete paths for
119 both the main file and the included file.
120
121.. option:: -n, --no-output
122
123 Do not output any ``.gcov`` files. Summary information is still
124 displayed.
125
126.. option:: -o=<DIR|FILE>, --object-directory=<DIR>, --object-file=<FILE>
127
128 Find objects in DIR or based on FILE's path. If you specify a particular
129 object file, the coverage data files are expected to have the same base name
130 with ``.gcno`` and ``.gcda`` extensions. If you specify a directory, the
131 files are expected in that directory with the same base name as the source
132 file.
133
134.. option:: -p, --preserve-paths
135
136 Preserve path components when naming the coverage output files. In addition
137 to the source file name, include the directories from the path to that
138 file. The directories are separate by ``#`` characters, with ``.`` directories
139 removed and ``..`` directories replaced by ``^`` characters. When used with
140 the --long-file-names option, this applies to both the main file name and the
141 included file name.
142
143.. option:: -u, --unconditional-branches
144
145 Include unconditional branches in the output for the --branch-probabilities
146 option.
147
148.. option:: -version
149
150 Display the version of llvm-cov.
151
152EXIT STATUS
153^^^^^^^^^^^
154
155:program:`llvm-cov gcov` returns 1 if it cannot read input files.  Otherwise,
156it exits with zero.
157
158
159.. program:: llvm-cov show
160
161.. _llvm-cov-show:
162
163SHOW COMMAND
164------------
165
166SYNOPSIS
167^^^^^^^^
168
169:program:`llvm-cov show` [*options*] -instr-profile *PROFILE* *BIN* [*SOURCES*]
170
171DESCRIPTION
172^^^^^^^^^^^
173
174The :program:`llvm-cov show` command shows line by line coverage of a binary
175*BIN* using the profile data *PROFILE*. It can optionally be filtered to only
176show the coverage for the files listed in *SOURCES*.
177
178To use :program:`llvm-cov show`, you need a program that is compiled with
179instrumentation to emit profile and coverage data. To build such a program with
180``clang`` use the ``-fprofile-instr-generate`` and ``-fcoverage-mapping``
181flags. If linking with the ``clang`` driver, pass ``-fprofile-instr-generate``
182to the link stage to make sure the necessary runtime libraries are linked in.
183
184The coverage information is stored in the built executable or library itself,
185and this is what you should pass to :program:`llvm-cov show` as the *BIN*
186argument. The profile data is generated by running this instrumented program
187normally. When the program exits it will write out a raw profile file,
188typically called ``default.profraw``, which can be converted to a format that
189is suitable for the *PROFILE* argument using the :program:`llvm-profdata merge`
190tool.
191
192OPTIONS
193^^^^^^^
194
195.. option:: -show-line-counts
196
197 Show the execution counts for each line. This is enabled by default, unless
198 another ``-show`` option is used.
199
200.. option:: -show-expansions
201
202 Expand inclusions, such as preprocessor macros or textual inclusions, inline
203 in the display of the source file.
204
205.. option:: -show-instantiations
206
207 For source regions that are instantiated multiple times, such as templates in
208 ``C++``, show each instantiation separately as well as the combined summary.
209
210.. option:: -show-regions
211
212 Show the execution counts for each region by displaying a caret that points to
213 the character where the region starts.
214
215.. option:: -show-line-counts-or-regions
216
217 Show the execution counts for each line if there is only one region on the
218 line, but show the individual regions if there are multiple on the line.
219
220.. option:: -use-color[=VALUE]
221
222 Enable or disable color output. By default this is autodetected.
223
224.. option:: -arch=<name>
225
226 If the covered binary is a universal binary, select the architecture to use.
227 It is an error to specify an architecture that is not included in the
228 universal binary or to use an architecture that does not match a
229 non-universal binary.
230
231.. option:: -name=<NAME>
232
233 Show code coverage only for functions with the given name.
234
235.. option:: -name-regex=<PATTERN>
236
237 Show code coverage only for functions that match the given regular expression.
238
239.. option:: -format=<FORMAT>
240
241 Use the specified output format. The supported formats are: "text", "html".
242
243.. option:: -output-dir=PATH
244
245 Specify a directory to write coverage reports into. If the directory does not
246 exist, it is created. When used in function view mode (i.e when -name or
247 -name-regex are used to select specific functions), the report is written to
248 PATH/functions.EXTENSION. When used in file view mode, a report for each file
249 is written to PATH/REL_PATH_TO_FILE.EXTENSION.
250
251.. option:: -line-coverage-gt=<N>
252
253 Show code coverage only for functions with line coverage greater than the
254 given threshold.
255
256.. option:: -line-coverage-lt=<N>
257
258 Show code coverage only for functions with line coverage less than the given
259 threshold.
260
261.. option:: -region-coverage-gt=<N>
262
263 Show code coverage only for functions with region coverage greater than the
264 given threshold.
265
266.. option:: -region-coverage-lt=<N>
267
268 Show code coverage only for functions with region coverage less than the given
269 threshold.
270
271.. program:: llvm-cov report
272
273.. _llvm-cov-report:
274
275REPORT COMMAND
276--------------
277
278SYNOPSIS
279^^^^^^^^
280
281:program:`llvm-cov report` [*options*] -instr-profile *PROFILE* *BIN* [*SOURCES*]
282
283DESCRIPTION
284^^^^^^^^^^^
285
286The :program:`llvm-cov report` command displays a summary of the coverage of a
287binary *BIN* using the profile data *PROFILE*. It can optionally be filtered to
288only show the coverage for the files listed in *SOURCES*.
289
290If no source files are provided, a summary line is printed for each file in the
291coverage data. If any files are provided, summaries are shown for each function
292in the listed files instead.
293
294For information on compiling programs for coverage and generating profile data,
295see :ref:`llvm-cov-show`.
296
297OPTIONS
298^^^^^^^
299
300.. option:: -use-color[=VALUE]
301
302 Enable or disable color output. By default this is autodetected.
303
304.. option:: -arch=<name>
305
306 If the covered binary is a universal binary, select the architecture to use.
307 It is an error to specify an architecture that is not included in the
308 universal binary or to use an architecture that does not match a
309 non-universal binary.
310