Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 1 | llvm-cov - emit coverage information |
| 2 | ==================================== |
| 3 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 4 | SYNOPSIS |
| 5 | -------- |
| 6 | |
Bob Wilson | c16b704 | 2014-05-06 15:58:06 +0000 | [diff] [blame^] | 7 | :program:`llvm-cov` [options] SOURCEFILE |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 8 | |
| 9 | DESCRIPTION |
| 10 | ----------- |
| 11 | |
Bob Wilson | c16b704 | 2014-05-06 15:58:06 +0000 | [diff] [blame^] | 12 | The :program:`llvm-cov` tool reads code coverage data files and displays the |
| 13 | coverage 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 |
| 15 | some later versions of ``gcov``. |
| 16 | |
| 17 | To use llvm-cov, you must first build an instrumented version of your |
| 18 | application that collects coverage data as it runs. Compile with the |
| 19 | ``-fprofile-arcs`` and ``-ftest-coverage`` options to add the |
| 20 | instrumentation. (Alternatively, you can use the ``--coverage`` option, which |
| 21 | includes both of those other options.) You should compile with debugging |
| 22 | information (``-g``) and without optimization (``-O0``); otherwise, the |
| 23 | coverage data cannot be accurately mapped back to the source code. |
| 24 | |
| 25 | At the time you compile the instrumented code, a ``.gcno`` data file will be |
| 26 | generated for each object file. These ``.gcno`` files contain half of the |
| 27 | coverage data. The other half of the data comes from ``.gcda`` files that are |
| 28 | generated when you run the instrumented program, with a separate ``.gcda`` |
| 29 | file for each object file. Each time you run the program, the execution counts |
| 30 | are summed into any existing ``.gcda`` files, so be sure to remove any old |
| 31 | files if you do not want their contents to be included. |
| 32 | |
| 33 | By default, the ``.gcda`` files are written into the same directory as the |
| 34 | object files, but you can override that by setting the ``GCOV_PREFIX`` and |
| 35 | ``GCOV_PREFIX_STRIP`` environment variables. The ``GCOV_PREFIX_STRIP`` |
| 36 | variable specifies a number of directory components to be removed from the |
| 37 | start of the absolute path to the object file directory. After stripping those |
| 38 | directories, the prefix from the ``GCOV_PREFIX`` variable is added. These |
| 39 | environment variables allow you to run the instrumented program on a machine |
| 40 | where the original object file directories are not accessible, but you will |
| 41 | then need to copy the ``.gcda`` files back to the object file directories |
| 42 | where llvm-cov expects to find them. |
| 43 | |
| 44 | Once you have generated the coverage data files, run llvm-cov for each main |
| 45 | source file where you want to examine the coverage results. This should be run |
| 46 | from the same directory where you previously ran the compiler. The results for |
| 47 | the specified source file are written to a file named by appending a ``.gcov`` |
| 48 | suffix. A separate output file is also created for each file included by the |
| 49 | main source file, also with a ``.gcov`` suffix added. |
| 50 | |
| 51 | The basic content of an llvm-cov output file is a copy of the source file with |
| 52 | an execution count and line number prepended to every line. The execution |
| 53 | count is shown as ``-`` if a line does not contain any executable code. If |
| 54 | a line contains code but that code was never executed, the count is displayed |
| 55 | as ``#####``. |
| 56 | |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 57 | |
| 58 | OPTIONS |
| 59 | ------- |
| 60 | |
Bob Wilson | c16b704 | 2014-05-06 15:58:06 +0000 | [diff] [blame^] | 61 | .. option:: -a, --all-blocks |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 62 | |
Bob Wilson | c16b704 | 2014-05-06 15:58:06 +0000 | [diff] [blame^] | 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. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 66 | |
Bob Wilson | c16b704 | 2014-05-06 15:58:06 +0000 | [diff] [blame^] | 67 | .. option:: -b, --branch-probabilities |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 68 | |
Bob Wilson | c16b704 | 2014-05-06 15:58:06 +0000 | [diff] [blame^] | 69 | Display conditional branch probabilities and a summary of branch information. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 70 | |
Bob Wilson | c16b704 | 2014-05-06 15:58:06 +0000 | [diff] [blame^] | 71 | .. option:: -c, --branch-counts |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 72 | |
Bob Wilson | c16b704 | 2014-05-06 15:58:06 +0000 | [diff] [blame^] | 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:: -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 Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 116 | |
| 117 | EXIT STATUS |
| 118 | ----------- |
| 119 | |
Dmitri Gribenko | c9e206f | 2012-11-29 19:10:21 +0000 | [diff] [blame] | 120 | :program:`llvm-cov` returns 1 if it cannot read input files. Otherwise, it |
| 121 | exits with zero. |
Daniel Dunbar | 8f4a8a6 | 2012-05-08 16:50:35 +0000 | [diff] [blame] | 122 | |