1LLVM-COV(1) LLVM LLVM-COV(1)
2
3
4
6 llvm-cov - emit coverage information
7
9 llvm-cov command [args...]
10
12 The llvm-cov tool shows code coverage information for programs that are
13 instrumented to emit profile data. It can be used to work with
14 gcov-style coverage or with clang's instrumentation based profiling.
15
16 If the program is invoked with a base name of gcov, it will behave as
17 if the llvm-cov gcov command were called. Otherwise, a command should
18 be provided.
19
21 • gcov
22
23 • show
24
25 • report
26
27 • export
28
30 SYNOPSIS
31 llvm-cov gcov [options] SOURCEFILE
32
33 DESCRIPTION
34 The llvm-cov gcov tool reads code coverage data files and displays the
35 coverage information for a specified source file. It is compatible with
36 the gcov tool from version 4.2 of GCC and may also be compatible with
37 some later versions of gcov.
38
39 To use llvm-cov gcov, you must first build an instrumented version of
40 your application that collects coverage data as it runs. Compile with
41 the -fprofile-arcs and -ftest-coverage options to add the instrumenta‐
42 tion. (Alternatively, you can use the --coverage option, which includes
43 both of those other options.) You should compile with debugging infor‐
44 mation (-g) and without optimization (-O0); otherwise, the coverage
45 data cannot be accurately mapped back to the source code.
46
47 At the time you compile the instrumented code, a .gcno data file will
48 be generated for each object file. These .gcno files contain half of
49 the coverage data. The other half of the data comes from .gcda files
50 that are generated when you run the instrumented program, with a sepa‐
51 rate .gcda file for each object file. Each time you run the program,
52 the execution counts are summed into any existing .gcda files, so be
53 sure to remove any old files if you do not want their contents to be
54 included.
55
56 By default, the .gcda files are written into the same directory as the
57 object files, but you can override that by setting the GCOV_PREFIX and
58 GCOV_PREFIX_STRIP environment variables. The GCOV_PREFIX_STRIP variable
59 specifies a number of directory components to be removed from the start
60 of the absolute path to the object file directory. After stripping
61 those directories, the prefix from the GCOV_PREFIX variable is added.
62 These environment variables allow you to run the instrumented program
63 on a machine where the original object file directories are not acces‐
64 sible, but you will then need to copy the .gcda files back to the ob‐
65 ject file directories where llvm-cov gcov expects to find them.
66
67 Once you have generated the coverage data files, run llvm-cov gcov for
68 each main source file where you want to examine the coverage results.
69 This should be run from the same directory where you previously ran the
70 compiler. The results for the specified source file are written to a
71 file named by appending a .gcov suffix. A separate output file is also
72 created for each file included by the main source file, also with a
73 .gcov suffix added.
74
75 The basic content of an .gcov output file is a copy of the source file
76 with an execution count and line number prepended to every line. The
77 execution count is shown as - if a line does not contain any executable
78 code. If a line contains code but that code was never executed, the
79 count is displayed as #####.
80
81 OPTIONS
82 -a, --all-blocks
83 Display all basic blocks. If there are multiple blocks for a
84 single line of source code, this option causes llvm-cov to show
85 the count for each block instead of just one count for the en‐
86 tire line.
87
88 -b, --branch-probabilities
89 Display conditional branch probabilities and a summary of branch
90 information.
91
92 -c, --branch-counts
93 Display branch counts instead of probabilities (requires -b).
94
95 -f, --function-summaries
96 Show a summary of coverage for each function instead of just one
97 summary for an entire source file.
98
99 --help Display available options (--help-hidden for more).
100
101 -l, --long-file-names
102 For coverage output of files included from the main source file,
103 add the main file name followed by ## as a prefix to the output
104 file names. This can be combined with the --preserve-paths op‐
105 tion to use complete paths for both the main file and the in‐
106 cluded file.
107
108 -n, --no-output
109 Do not output any .gcov files. Summary information is still dis‐
110 played.
111
112 -o=<DIR|FILE>, --object-directory=<DIR>, --object-file=<FILE>
113 Find objects in DIR or based on FILE's path. If you specify a
114 particular object file, the coverage data files are expected to
115 have the same base name with .gcno and .gcda extensions. If you
116 specify a directory, the files are expected in that directory
117 with the same base name as the source file.
118
119 -p, --preserve-paths
120 Preserve path components when naming the coverage output files.
121 In addition to the source file name, include the directories
122 from the path to that file. The directories are separate by #
123 characters, with . directories removed and .. directories re‐
124 placed by ^ characters. When used with the --long-file-names op‐
125 tion, this applies to both the main file name and the included
126 file name.
127
128 -u, --unconditional-branches
129 Include unconditional branches in the output for the
130 --branch-probabilities option.
131
132 -version
133 Display the version of llvm-cov.
134
135 -x, --hash-filenames
136 Use md5 hash of file name when naming the coverage output files.
137 The source file name will be suffixed by ## followed by MD5 hash
138 calculated for it.
139
140 EXIT STATUS
141 llvm-cov gcov returns 1 if it cannot read input files. Otherwise, it
142 exits with zero.
143
145 SYNOPSIS
146 llvm-cov show [options] -instr-profile PROFILE BIN [-object BIN,...]
147 [[-object BIN]] [SOURCES]
148
149 DESCRIPTION
150 The llvm-cov show command shows line by line coverage of the binaries
151 BIN,... using the profile data PROFILE. It can optionally be filtered
152 to only show the coverage for the files listed in SOURCES.
153
154 BIN may be an executable, object file, dynamic library, or archive
155 (thin or otherwise).
156
157 To use llvm-cov show, you need a program that is compiled with instru‐
158 mentation to emit profile and coverage data. To build such a program
159 with clang use the -fprofile-instr-generate and -fcoverage-mapping
160 flags. If linking with the clang driver, pass -fprofile-instr-generate
161 to the link stage to make sure the necessary runtime libraries are
162 linked in.
163
164 The coverage information is stored in the built executable or library
165 itself, and this is what you should pass to llvm-cov show as a BIN ar‐
166 gument. The profile data is generated by running this instrumented pro‐
167 gram normally. When the program exits it will write out a raw profile
168 file, typically called default.profraw, which can be converted to a
169 format that is suitable for the PROFILE argument using the llvm-prof‐
170 data merge tool.
171
172 OPTIONS
173 -show-branches=<VIEW>
174 Show coverage for branch conditions in terms of either count or
175 percentage. The supported views are: "count", "percent".
176
177 -show-line-counts
178 Show the execution counts for each line. Defaults to true, un‐
179 less another -show option is used.
180
181 -show-expansions
182 Expand inclusions, such as preprocessor macros or textual inclu‐
183 sions, inline in the display of the source file. Defaults to
184 false.
185
186 -show-instantiations
187 For source regions that are instantiated multiple times, such as
188 templates in C++, show each instantiation separately as well as
189 the combined summary. Defaults to true.
190
191 -show-regions
192 Show the execution counts for each region by displaying a caret
193 that points to the character where the region starts. Defaults
194 to false.
195
196 -show-line-counts-or-regions
197 Show the execution counts for each line if there is only one re‐
198 gion on the line, but show the individual regions if there are
199 multiple on the line. Defaults to false.
200
201 -use-color
202 Enable or disable color output. By default this is autodetected.
203
204 -arch=[*NAMES*]
205 Specify a list of architectures such that the Nth entry in the
206 list corresponds to the Nth specified binary. If the covered ob‐
207 ject is a universal binary, this specifies the architecture to
208 use. It is an error to specify an architecture that is not in‐
209 cluded in the universal binary or to use an architecture that
210 does not match a non-universal binary.
211
212 -name=<NAME>
213 Show code coverage only for functions with the given name.
214
215 -name-whitelist=<FILE>
216 Show code coverage only for functions listed in the given file.
217 Each line in the file should start with whitelist_fun:, immedi‐
218 ately followed by the name of the function to accept. This name
219 can be a wildcard expression.
220
221 -name-regex=<PATTERN>
222 Show code coverage only for functions that match the given regu‐
223 lar expression.
224
225 -ignore-filename-regex=<PATTERN>
226 Skip source code files with file paths that match the given reg‐
227 ular expression.
228
229 -format=<FORMAT>
230 Use the specified output format. The supported formats are:
231 "text", "html".
232
233 -tab-size=<TABSIZE>
234 Replace tabs with <TABSIZE> spaces when preparing reports. Cur‐
235 rently, this is only supported for the html format.
236
237 -output-dir=PATH
238 Specify a directory to write coverage reports into. If the di‐
239 rectory does not exist, it is created. When used in function
240 view mode (i.e when -name or -name-regex are used to select spe‐
241 cific functions), the report is written to PATH/functions.EXTEN‐
242 SION. When used in file view mode, a report for each file is
243 written to PATH/REL_PATH_TO_FILE.EXTENSION.
244
245 -Xdemangler=<TOOL>|<TOOL-OPTION>
246 Specify a symbol demangler. This can be used to make reports
247 more human-readable. This option can be specified multiple times
248 to supply arguments to the demangler (e.g -Xdemangler c++filt
249 -Xdemangler -n for C++). The demangler is expected to read a
250 newline-separated list of symbols from stdin and write a new‐
251 line-separated list of the same length to stdout.
252
253 -num-threads=N, -j=N
254 Use N threads to write file reports (only applicable when -out‐
255 put-dir is specified). When N=0, llvm-cov auto-detects an appro‐
256 priate number of threads to use. This is the default.
257
258 -line-coverage-gt=<N>
259 Show code coverage only for functions with line coverage greater
260 than the given threshold.
261
262 -line-coverage-lt=<N>
263 Show code coverage only for functions with line coverage less
264 than the given threshold.
265
266 -region-coverage-gt=<N>
267 Show code coverage only for functions with region coverage
268 greater than the given threshold.
269
270 -region-coverage-lt=<N>
271 Show code coverage only for functions with region coverage less
272 than the given threshold.
273
274 -path-equivalence=<from>,<to>
275 Map the paths in the coverage data to local source file paths.
276 This allows you to generate the coverage data on one machine,
277 and then use llvm-cov on a different machine where you have the
278 same files on a different path.
279
281 SYNOPSIS
282 llvm-cov report [options] -instr-profile PROFILE BIN [-object BIN,...]
283 [[-object BIN]] [SOURCES]
284
285 DESCRIPTION
286 The llvm-cov report command displays a summary of the coverage of the
287 binaries BIN,... using the profile data PROFILE. It can optionally be
288 filtered to only show the coverage for the files listed in SOURCES.
289
290 BIN may be an executable, object file, dynamic library, or archive
291 (thin or otherwise).
292
293 If no source files are provided, a summary line is printed for each
294 file in the coverage data. If any files are provided, summaries can be
295 shown for each function in the listed files if the -show-functions op‐
296 tion is enabled.
297
298 For information on compiling programs for coverage and generating pro‐
299 file data, see SHOW COMMAND.
300
301 OPTIONS
302 -use-color[=VALUE]
303 Enable or disable color output. By default this is autodetected.
304
305 -arch=<name>
306 If the covered binary is a universal binary, select the archi‐
307 tecture to use. It is an error to specify an architecture that
308 is not included in the universal binary or to use an architec‐
309 ture that does not match a non-universal binary.
310
311 -show-branch-summary
312 Show statistics for all branch conditions. Defaults to true.
313
314 -show-functions
315 Show coverage summaries for each function. Defaults to false.
316
317 -show-instantiation-summary
318 Show statistics for all function instantiations. Defaults to
319 false.
320
321 -ignore-filename-regex=<PATTERN>
322 Skip source code files with file paths that match the given reg‐
323 ular expression.
324
326 SYNOPSIS
327 llvm-cov export [options] -instr-profile PROFILE BIN [-object BIN,...]
328 [[-object BIN]] [SOURCES]
329
330 DESCRIPTION
331 The llvm-cov export command exports coverage data of the binaries
332 BIN,... using the profile data PROFILE in either JSON or lcov trace
333 file format.
334
335 When exporting JSON, the regions, functions, branches, expansions, and
336 summaries of the coverage data will be exported. When exporting an lcov
337 trace file, the line-based coverage, branch coverage, and summaries
338 will be exported.
339
340 The exported data can optionally be filtered to only export the cover‐
341 age for the files listed in SOURCES.
342
343 For information on compiling programs for coverage and generating pro‐
344 file data, see SHOW COMMAND.
345
346 OPTIONS
347 -arch=<name>
348 If the covered binary is a universal binary, select the archi‐
349 tecture to use. It is an error to specify an architecture that
350 is not included in the universal binary or to use an architec‐
351 ture that does not match a non-universal binary.
352
353 -format=<FORMAT>
354 Use the specified output format. The supported formats are:
355 "text" (JSON), "lcov".
356
357 -summary-only
358 Export only summary information for each file in the coverage
359 data. This mode will not export coverage information for smaller
360 units such as individual functions or regions. The result will
361 contain the same information as produced by the llvm-cov report
362 command, but presented in JSON or lcov format rather than text.
363
364 -ignore-filename-regex=<PATTERN>
365 Skip source code files with file paths that match the given reg‐
366 ular expression.
367
368 -skip-expansions
369
370 Skip exporting macro expansion coverage data.
371
372 -skip-functions
373
374 Skip exporting per-function coverage data.
375
376 -num-threads=N, -j=N
377
378 Use N threads to export coverage data. When N=0, llvm-cov
379 auto-detects an appropriate number of threads to use. This is
380 the default.
381
383 Maintained by the LLVM Team (https://llvm.org/).
384
386 2003-2023, LLVM Project
387
388
389
390
39112 2023-07-20 LLVM-COV(1)