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