xref: /aosp_15_r20/external/llvm/docs/CoverageMappingFormat.rst (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker.. role:: raw-html(raw)
2*9880d681SAndroid Build Coastguard Worker   :format: html
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Worker=================================
5*9880d681SAndroid Build Coastguard WorkerLLVM Code Coverage Mapping Format
6*9880d681SAndroid Build Coastguard Worker=================================
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Worker.. contents::
9*9880d681SAndroid Build Coastguard Worker   :local:
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard WorkerIntroduction
12*9880d681SAndroid Build Coastguard Worker============
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard WorkerLLVM's code coverage mapping format is used to provide code coverage
15*9880d681SAndroid Build Coastguard Workeranalysis using LLVM's and Clang's instrumenation based profiling
16*9880d681SAndroid Build Coastguard Worker(Clang's ``-fprofile-instr-generate`` option).
17*9880d681SAndroid Build Coastguard Worker
18*9880d681SAndroid Build Coastguard WorkerThis document is aimed at those who use LLVM's code coverage mapping to provide
19*9880d681SAndroid Build Coastguard Workercode coverage analysis for their own programs, and for those who would like
20*9880d681SAndroid Build Coastguard Workerto know how it works under the hood. A prior knowledge of how Clang's profile
21*9880d681SAndroid Build Coastguard Workerguided optimization works is useful, but not required.
22*9880d681SAndroid Build Coastguard Worker
23*9880d681SAndroid Build Coastguard WorkerWe start by showing how to use LLVM and Clang for code coverage analysis,
24*9880d681SAndroid Build Coastguard Workerthen we briefly desribe LLVM's code coverage mapping format and the
25*9880d681SAndroid Build Coastguard Workerway that Clang and LLVM's code coverage tool work with this format. After
26*9880d681SAndroid Build Coastguard Workerthe basics are down, more advanced features of the coverage mapping format
27*9880d681SAndroid Build Coastguard Workerare discussed - such as the data structures, LLVM IR representation and
28*9880d681SAndroid Build Coastguard Workerthe binary encoding.
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard WorkerQuick Start
31*9880d681SAndroid Build Coastguard Worker===========
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard WorkerHere's a short story that describes how to generate code coverage overview
34*9880d681SAndroid Build Coastguard Workerfor a sample source file called *test.c*.
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Worker* First, compile an instrumented version of your program using Clang's
37*9880d681SAndroid Build Coastguard Worker  ``-fprofile-instr-generate`` option with the additional ``-fcoverage-mapping``
38*9880d681SAndroid Build Coastguard Worker  option:
39*9880d681SAndroid Build Coastguard Worker
40*9880d681SAndroid Build Coastguard Worker  ``clang -o test -fprofile-instr-generate -fcoverage-mapping test.c``
41*9880d681SAndroid Build Coastguard Worker* Then, run the instrumented binary. The runtime will produce a file called
42*9880d681SAndroid Build Coastguard Worker  *default.profraw* containing the raw profile instrumentation data:
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker  ``./test``
45*9880d681SAndroid Build Coastguard Worker* After that, merge the profile data using the *llvm-profdata* tool:
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Worker  ``llvm-profdata merge -o test.profdata default.profraw``
48*9880d681SAndroid Build Coastguard Worker* Finally, run LLVM's code coverage tool (*llvm-cov*) to produce the code
49*9880d681SAndroid Build Coastguard Worker  coverage overview for the sample source file:
50*9880d681SAndroid Build Coastguard Worker
51*9880d681SAndroid Build Coastguard Worker  ``llvm-cov show ./test -instr-profile=test.profdata test.c``
52*9880d681SAndroid Build Coastguard Worker
53*9880d681SAndroid Build Coastguard WorkerHigh Level Overview
54*9880d681SAndroid Build Coastguard Worker===================
55*9880d681SAndroid Build Coastguard Worker
56*9880d681SAndroid Build Coastguard WorkerLLVM's code coverage mapping format is designed to be a self contained
57*9880d681SAndroid Build Coastguard Workerdata format, that can be embedded into the LLVM IR and object files.
58*9880d681SAndroid Build Coastguard WorkerIt's described in this document as a **mapping** format because its goal is
59*9880d681SAndroid Build Coastguard Workerto store the data that is required for a code coverage tool to map between
60*9880d681SAndroid Build Coastguard Workerthe specific source ranges in a file and the execution counts obtained
61*9880d681SAndroid Build Coastguard Workerafter running the instrumented version of the program.
62*9880d681SAndroid Build Coastguard Worker
63*9880d681SAndroid Build Coastguard WorkerThe mapping data is used in two places in the code coverage process:
64*9880d681SAndroid Build Coastguard Worker
65*9880d681SAndroid Build Coastguard Worker1. When clang compiles a source file with ``-fcoverage-mapping``, it
66*9880d681SAndroid Build Coastguard Worker   generates the mapping information that describes the mapping between the
67*9880d681SAndroid Build Coastguard Worker   source ranges and the profiling instrumentation counters.
68*9880d681SAndroid Build Coastguard Worker   This information gets embedded into the LLVM IR and conveniently
69*9880d681SAndroid Build Coastguard Worker   ends up in the final executable file when the program is linked.
70*9880d681SAndroid Build Coastguard Worker
71*9880d681SAndroid Build Coastguard Worker2. It is also used by *llvm-cov* - the mapping information is extracted from an
72*9880d681SAndroid Build Coastguard Worker   object file and is used to associate the execution counts (the values of the
73*9880d681SAndroid Build Coastguard Worker   profile instrumentation counters), and the source ranges in a file.
74*9880d681SAndroid Build Coastguard Worker   After that, the tool is able to generate various code coverage reports
75*9880d681SAndroid Build Coastguard Worker   for the program.
76*9880d681SAndroid Build Coastguard Worker
77*9880d681SAndroid Build Coastguard WorkerThe coverage mapping format aims to be a "universal format" that would be
78*9880d681SAndroid Build Coastguard Workersuitable for usage by any frontend, and not just by Clang. It also aims to
79*9880d681SAndroid Build Coastguard Workerprovide the frontend the possibility of generating the minimal coverage mapping
80*9880d681SAndroid Build Coastguard Workerdata in order to reduce the size of the IR and object files - for example,
81*9880d681SAndroid Build Coastguard Workerinstead of emitting mapping information for each statement in a function, the
82*9880d681SAndroid Build Coastguard Workerfrontend is allowed to group the statements with the same execution count into
83*9880d681SAndroid Build Coastguard Workerregions of code, and emit the mapping information only for those regions.
84*9880d681SAndroid Build Coastguard Worker
85*9880d681SAndroid Build Coastguard WorkerAdvanced Concepts
86*9880d681SAndroid Build Coastguard Worker=================
87*9880d681SAndroid Build Coastguard Worker
88*9880d681SAndroid Build Coastguard WorkerThe remainder of this guide is meant to give you insight into the way the
89*9880d681SAndroid Build Coastguard Workercoverage mapping format works.
90*9880d681SAndroid Build Coastguard Worker
91*9880d681SAndroid Build Coastguard WorkerThe coverage mapping format operates on a per-function level as the
92*9880d681SAndroid Build Coastguard Workerprofile instrumentation counters are associated with a specific function.
93*9880d681SAndroid Build Coastguard WorkerFor each function that requires code coverage, the frontend has to create
94*9880d681SAndroid Build Coastguard Workercoverage mapping data that can map between the source code ranges and
95*9880d681SAndroid Build Coastguard Workerthe profile instrumentation counters for that function.
96*9880d681SAndroid Build Coastguard Worker
97*9880d681SAndroid Build Coastguard WorkerMapping Region
98*9880d681SAndroid Build Coastguard Worker--------------
99*9880d681SAndroid Build Coastguard Worker
100*9880d681SAndroid Build Coastguard WorkerThe function's coverage mapping data contains an array of mapping regions.
101*9880d681SAndroid Build Coastguard WorkerA mapping region stores the `source code range`_ that is covered by this region,
102*9880d681SAndroid Build Coastguard Workerthe `file id <coverage file id_>`_, the `coverage mapping counter`_ and
103*9880d681SAndroid Build Coastguard Workerthe region's kind.
104*9880d681SAndroid Build Coastguard WorkerThere are several kinds of mapping regions:
105*9880d681SAndroid Build Coastguard Worker
106*9880d681SAndroid Build Coastguard Worker* Code regions associate portions of source code and `coverage mapping
107*9880d681SAndroid Build Coastguard Worker  counters`_. They make up the majority of the mapping regions. They are used
108*9880d681SAndroid Build Coastguard Worker  by the code coverage tool to compute the execution counts for lines,
109*9880d681SAndroid Build Coastguard Worker  highlight the regions of code that were never executed, and to obtain
110*9880d681SAndroid Build Coastguard Worker  the various code coverage statistics for a function.
111*9880d681SAndroid Build Coastguard Worker  For example:
112*9880d681SAndroid Build Coastguard Worker
113*9880d681SAndroid Build Coastguard Worker  :raw-html:`<pre class='highlight' style='line-height:initial;'><span>int main(int argc, const char *argv[]) </span><span style='background-color:#4A789C'>{    </span> <span class='c1'>// Code Region from 1:40 to 9:2</span>
114*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#4A789C'>                                            </span>
115*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#4A789C'>  if (argc &gt; 1) </span><span style='background-color:#85C1F5'>{                         </span>   <span class='c1'>// Code Region from 3:17 to 5:4</span>
116*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#85C1F5'>    printf("%s\n", argv[1]);              </span>
117*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#85C1F5'>  }</span><span style='background-color:#4A789C'> else </span><span style='background-color:#F6D55D'>{                                </span>   <span class='c1'>// Code Region from 5:10 to 7:4</span>
118*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#F6D55D'>    printf("\n");                         </span>
119*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#F6D55D'>  }</span><span style='background-color:#4A789C'>                                         </span>
120*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#4A789C'>  return 0;                                 </span>
121*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#4A789C'>}</span>
122*9880d681SAndroid Build Coastguard Worker  </pre>`
123*9880d681SAndroid Build Coastguard Worker* Skipped regions are used to represent source ranges that were skipped
124*9880d681SAndroid Build Coastguard Worker  by Clang's preprocessor. They don't associate with
125*9880d681SAndroid Build Coastguard Worker  `coverage mapping counters`_, as the frontend knows that they are never
126*9880d681SAndroid Build Coastguard Worker  executed. They are used by the code coverage tool to mark the skipped lines
127*9880d681SAndroid Build Coastguard Worker  inside a function as non-code lines that don't have execution counts.
128*9880d681SAndroid Build Coastguard Worker  For example:
129*9880d681SAndroid Build Coastguard Worker
130*9880d681SAndroid Build Coastguard Worker  :raw-html:`<pre class='highlight' style='line-height:initial;'><span>int main() </span><span style='background-color:#4A789C'>{               </span> <span class='c1'>// Code Region from 1:12 to 6:2</span>
131*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#85C1F5'>#ifdef DEBUG             </span>   <span class='c1'>// Skipped Region from 2:1 to 4:2</span>
132*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#85C1F5'>  printf("Hello world"); </span>
133*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#85C1F5'>#</span><span style='background-color:#4A789C'>endif                     </span>
134*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#4A789C'>  return 0;                </span>
135*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#4A789C'>}</span>
136*9880d681SAndroid Build Coastguard Worker  </pre>`
137*9880d681SAndroid Build Coastguard Worker* Expansion regions are used to represent Clang's macro expansions. They
138*9880d681SAndroid Build Coastguard Worker  have an additional property - *expanded file id*. This property can be
139*9880d681SAndroid Build Coastguard Worker  used by the code coverage tool to find the mapping regions that are created
140*9880d681SAndroid Build Coastguard Worker  as a result of this macro expansion, by checking if their file id matches the
141*9880d681SAndroid Build Coastguard Worker  expanded file id. They don't associate with `coverage mapping counters`_,
142*9880d681SAndroid Build Coastguard Worker  as the code coverage tool can determine the execution count for this region
143*9880d681SAndroid Build Coastguard Worker  by looking up the execution count of the first region with a corresponding
144*9880d681SAndroid Build Coastguard Worker  file id.
145*9880d681SAndroid Build Coastguard Worker  For example:
146*9880d681SAndroid Build Coastguard Worker
147*9880d681SAndroid Build Coastguard Worker  :raw-html:`<pre class='highlight' style='line-height:initial;'><span>int func(int x) </span><span style='background-color:#4A789C'>{                             </span>
148*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#4A789C'>  #define MAX(x,y) </span><span style='background-color:#85C1F5'>((x) &gt; (y)? </span><span style='background-color:#F6D55D'>(x)</span><span style='background-color:#85C1F5'> : </span><span style='background-color:#F4BA70'>(y)</span><span style='background-color:#85C1F5'>)</span><span style='background-color:#4A789C'>     </span>
149*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#4A789C'>  return </span><span style='background-color:#7FCA9F'>MAX</span><span style='background-color:#4A789C'>(x, 42);                          </span> <span class='c1'>// Expansion Region from 3:10 to 3:13</span>
150*9880d681SAndroid Build Coastguard Worker  <span style='background-color:#4A789C'>}</span>
151*9880d681SAndroid Build Coastguard Worker  </pre>`
152*9880d681SAndroid Build Coastguard Worker
153*9880d681SAndroid Build Coastguard Worker.. _source code range:
154*9880d681SAndroid Build Coastguard Worker
155*9880d681SAndroid Build Coastguard WorkerSource Range:
156*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^
157*9880d681SAndroid Build Coastguard Worker
158*9880d681SAndroid Build Coastguard WorkerThe source range record contains the starting and ending location of a certain
159*9880d681SAndroid Build Coastguard Workermapping region. Both locations include the line and the column numbers.
160*9880d681SAndroid Build Coastguard Worker
161*9880d681SAndroid Build Coastguard Worker.. _coverage file id:
162*9880d681SAndroid Build Coastguard Worker
163*9880d681SAndroid Build Coastguard WorkerFile ID:
164*9880d681SAndroid Build Coastguard Worker^^^^^^^^
165*9880d681SAndroid Build Coastguard Worker
166*9880d681SAndroid Build Coastguard WorkerThe file id an integer value that tells us
167*9880d681SAndroid Build Coastguard Workerin which source file or macro expansion is this region located.
168*9880d681SAndroid Build Coastguard WorkerIt enables Clang to produce mapping information for the code
169*9880d681SAndroid Build Coastguard Workerdefined inside macros, like this example demonstrates:
170*9880d681SAndroid Build Coastguard Worker
171*9880d681SAndroid Build Coastguard Worker:raw-html:`<pre class='highlight' style='line-height:initial;'><span>void func(const char *str) </span><span style='background-color:#4A789C'>{        </span> <span class='c1'>// Code Region from 1:28 to 6:2 with file id 0</span>
172*9880d681SAndroid Build Coastguard Worker<span style='background-color:#4A789C'>  #define PUT </span><span style='background-color:#85C1F5'>printf("%s\n", str)</span><span style='background-color:#4A789C'>   </span> <span class='c1'>// 2 Code Regions from 2:15 to 2:34 with file ids 1 and 2</span>
173*9880d681SAndroid Build Coastguard Worker<span style='background-color:#4A789C'>  if(*str)                          </span>
174*9880d681SAndroid Build Coastguard Worker<span style='background-color:#4A789C'>    </span><span style='background-color:#F6D55D'>PUT</span><span style='background-color:#4A789C'>;                            </span> <span class='c1'>// Expansion Region from 4:5 to 4:8 with file id 0 that expands a macro with file id 1</span>
175*9880d681SAndroid Build Coastguard Worker<span style='background-color:#4A789C'>  </span><span style='background-color:#F6D55D'>PUT</span><span style='background-color:#4A789C'>;                              </span> <span class='c1'>// Expansion Region from 5:3 to 5:6 with file id 0 that expands a macro with file id 2</span>
176*9880d681SAndroid Build Coastguard Worker<span style='background-color:#4A789C'>}</span>
177*9880d681SAndroid Build Coastguard Worker</pre>`
178*9880d681SAndroid Build Coastguard Worker
179*9880d681SAndroid Build Coastguard Worker.. _coverage mapping counter:
180*9880d681SAndroid Build Coastguard Worker.. _coverage mapping counters:
181*9880d681SAndroid Build Coastguard Worker
182*9880d681SAndroid Build Coastguard WorkerCounter:
183*9880d681SAndroid Build Coastguard Worker^^^^^^^^
184*9880d681SAndroid Build Coastguard Worker
185*9880d681SAndroid Build Coastguard WorkerA coverage mapping counter can represents a reference to the profile
186*9880d681SAndroid Build Coastguard Workerinstrumentation counter. The execution count for a region with such counter
187*9880d681SAndroid Build Coastguard Workeris determined by looking up the value of the corresponding profile
188*9880d681SAndroid Build Coastguard Workerinstrumentation counter.
189*9880d681SAndroid Build Coastguard Worker
190*9880d681SAndroid Build Coastguard WorkerIt can also represent a binary arithmetical expression that operates on
191*9880d681SAndroid Build Coastguard Workercoverage mapping counters or other expressions.
192*9880d681SAndroid Build Coastguard WorkerThe execution count for a region with an expression counter is determined by
193*9880d681SAndroid Build Coastguard Workerevaluating the expression's arguments and then adding them together or
194*9880d681SAndroid Build Coastguard Workersubtracting them from one another.
195*9880d681SAndroid Build Coastguard WorkerIn the example below, a subtraction expression is used to compute the execution
196*9880d681SAndroid Build Coastguard Workercount for the compound statement that follows the *else* keyword:
197*9880d681SAndroid Build Coastguard Worker
198*9880d681SAndroid Build Coastguard Worker:raw-html:`<pre class='highlight' style='line-height:initial;'><span>int main(int argc, const char *argv[]) </span><span style='background-color:#4A789C'>{   </span> <span class='c1'>// Region's counter is a reference to the profile counter #0</span>
199*9880d681SAndroid Build Coastguard Worker<span style='background-color:#4A789C'>                                           </span>
200*9880d681SAndroid Build Coastguard Worker<span style='background-color:#4A789C'>  if (argc &gt; 1) </span><span style='background-color:#85C1F5'>{                        </span>   <span class='c1'>// Region's counter is a reference to the profile counter #1</span>
201*9880d681SAndroid Build Coastguard Worker<span style='background-color:#85C1F5'>    printf("%s\n", argv[1]);             </span><span>   </span>
202*9880d681SAndroid Build Coastguard Worker<span style='background-color:#85C1F5'>  }</span><span style='background-color:#4A789C'> else </span><span style='background-color:#F6D55D'>{                               </span>   <span class='c1'>// Region's counter is an expression (reference to the profile counter #0 - reference to the profile counter #1)</span>
203*9880d681SAndroid Build Coastguard Worker<span style='background-color:#F6D55D'>    printf("\n");                        </span>
204*9880d681SAndroid Build Coastguard Worker<span style='background-color:#F6D55D'>  }</span><span style='background-color:#4A789C'>                                        </span>
205*9880d681SAndroid Build Coastguard Worker<span style='background-color:#4A789C'>  return 0;                                </span>
206*9880d681SAndroid Build Coastguard Worker<span style='background-color:#4A789C'>}</span>
207*9880d681SAndroid Build Coastguard Worker</pre>`
208*9880d681SAndroid Build Coastguard Worker
209*9880d681SAndroid Build Coastguard WorkerFinally, a coverage mapping counter can also represent an execution count of
210*9880d681SAndroid Build Coastguard Workerof zero. The zero counter is used to provide coverage mapping for
211*9880d681SAndroid Build Coastguard Workerunreachable statements and expressions, like in the example below:
212*9880d681SAndroid Build Coastguard Worker
213*9880d681SAndroid Build Coastguard Worker:raw-html:`<pre class='highlight' style='line-height:initial;'><span>int main() </span><span style='background-color:#4A789C'>{                  </span>
214*9880d681SAndroid Build Coastguard Worker<span style='background-color:#4A789C'>  return 0;                   </span>
215*9880d681SAndroid Build Coastguard Worker<span style='background-color:#4A789C'>  </span><span style='background-color:#85C1F5'>printf("Hello world!\n")</span><span style='background-color:#4A789C'>;   </span> <span class='c1'>// Unreachable region's counter is zero</span>
216*9880d681SAndroid Build Coastguard Worker<span style='background-color:#4A789C'>}</span>
217*9880d681SAndroid Build Coastguard Worker</pre>`
218*9880d681SAndroid Build Coastguard Worker
219*9880d681SAndroid Build Coastguard WorkerThe zero counters allow the code coverage tool to display proper line execution
220*9880d681SAndroid Build Coastguard Workercounts for the unreachable lines and highlight the unreachable code.
221*9880d681SAndroid Build Coastguard WorkerWithout them, the tool would think that those lines and regions were still
222*9880d681SAndroid Build Coastguard Workerexecuted, as it doesn't possess the frontend's knowledge.
223*9880d681SAndroid Build Coastguard Worker
224*9880d681SAndroid Build Coastguard WorkerLLVM IR Representation
225*9880d681SAndroid Build Coastguard Worker======================
226*9880d681SAndroid Build Coastguard Worker
227*9880d681SAndroid Build Coastguard WorkerThe coverage mapping data is stored in the LLVM IR using a single global
228*9880d681SAndroid Build Coastguard Workerconstant structure variable called *__llvm_coverage_mapping*
229*9880d681SAndroid Build Coastguard Workerwith the *__llvm_covmap* section specifier.
230*9880d681SAndroid Build Coastguard Worker
231*9880d681SAndroid Build Coastguard WorkerFor example, let’s consider a C file and how it gets compiled to LLVM:
232*9880d681SAndroid Build Coastguard Worker
233*9880d681SAndroid Build Coastguard Worker.. _coverage mapping sample:
234*9880d681SAndroid Build Coastguard Worker
235*9880d681SAndroid Build Coastguard Worker.. code-block:: c
236*9880d681SAndroid Build Coastguard Worker
237*9880d681SAndroid Build Coastguard Worker  int foo() {
238*9880d681SAndroid Build Coastguard Worker    return 42;
239*9880d681SAndroid Build Coastguard Worker  }
240*9880d681SAndroid Build Coastguard Worker  int bar() {
241*9880d681SAndroid Build Coastguard Worker    return 13;
242*9880d681SAndroid Build Coastguard Worker  }
243*9880d681SAndroid Build Coastguard Worker
244*9880d681SAndroid Build Coastguard WorkerThe coverage mapping variable generated by Clang has 3 fields:
245*9880d681SAndroid Build Coastguard Worker
246*9880d681SAndroid Build Coastguard Worker* Coverage mapping header.
247*9880d681SAndroid Build Coastguard Worker
248*9880d681SAndroid Build Coastguard Worker* An array of function records.
249*9880d681SAndroid Build Coastguard Worker
250*9880d681SAndroid Build Coastguard Worker* Coverage mapping data which is an array of bytes. Zero paddings are added at the end to force 8 byte alignment.
251*9880d681SAndroid Build Coastguard Worker
252*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm
253*9880d681SAndroid Build Coastguard Worker
254*9880d681SAndroid Build Coastguard Worker  @__llvm_coverage_mapping = internal constant { { i32, i32, i32, i32 }, [2 x { i64, i32, i64 }], [40 x i8] }
255*9880d681SAndroid Build Coastguard Worker  {
256*9880d681SAndroid Build Coastguard Worker    { i32, i32, i32, i32 } ; Coverage map header
257*9880d681SAndroid Build Coastguard Worker    {
258*9880d681SAndroid Build Coastguard Worker      i32 2,  ; The number of function records
259*9880d681SAndroid Build Coastguard Worker      i32 20, ; The length of the string that contains the encoded translation unit filenames
260*9880d681SAndroid Build Coastguard Worker      i32 20, ; The length of the string that contains the encoded coverage mapping data
261*9880d681SAndroid Build Coastguard Worker      i32 1,  ; Coverage mapping format version
262*9880d681SAndroid Build Coastguard Worker    },
263*9880d681SAndroid Build Coastguard Worker    [2 x { i64, i32, i64 }] [ ; Function records
264*9880d681SAndroid Build Coastguard Worker     { i64, i32, i64 } {
265*9880d681SAndroid Build Coastguard Worker       i64 0x5cf8c24cdb18bdac, ; Function's name MD5
266*9880d681SAndroid Build Coastguard Worker       i32 9, ; Function's encoded coverage mapping data string length
267*9880d681SAndroid Build Coastguard Worker       i64 0  ; Function's structural hash
268*9880d681SAndroid Build Coastguard Worker     },
269*9880d681SAndroid Build Coastguard Worker     { i64, i32, i64 } {
270*9880d681SAndroid Build Coastguard Worker       i64 0xe413754a191db537, ; Function's name MD5
271*9880d681SAndroid Build Coastguard Worker       i32 9, ; Function's encoded coverage mapping data string length
272*9880d681SAndroid Build Coastguard Worker       i64 0  ; Function's structural hash
273*9880d681SAndroid Build Coastguard Worker     }],
274*9880d681SAndroid Build Coastguard Worker   [40 x i8] c"..." ; Encoded data (dissected later)
275*9880d681SAndroid Build Coastguard Worker  }, section "__llvm_covmap", align 8
276*9880d681SAndroid Build Coastguard Worker
277*9880d681SAndroid Build Coastguard WorkerThe function record layout has evolved since version 1. In version 1, the function record for *foo* is defined as follows:
278*9880d681SAndroid Build Coastguard Worker
279*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm
280*9880d681SAndroid Build Coastguard Worker
281*9880d681SAndroid Build Coastguard Worker     { i8*, i32, i32, i64 } { i8* getelementptr inbounds ([3 x i8]* @__profn_foo, i32 0, i32 0), ; Function's name
282*9880d681SAndroid Build Coastguard Worker       i32 3, ; Function's name length
283*9880d681SAndroid Build Coastguard Worker       i32 9, ; Function's encoded coverage mapping data string length
284*9880d681SAndroid Build Coastguard Worker       i64 0  ; Function's structural hash
285*9880d681SAndroid Build Coastguard Worker     }
286*9880d681SAndroid Build Coastguard Worker
287*9880d681SAndroid Build Coastguard Worker
288*9880d681SAndroid Build Coastguard WorkerCoverage Mapping Header:
289*9880d681SAndroid Build Coastguard Worker------------------------
290*9880d681SAndroid Build Coastguard Worker
291*9880d681SAndroid Build Coastguard WorkerThe coverage mapping header has the following fields:
292*9880d681SAndroid Build Coastguard Worker
293*9880d681SAndroid Build Coastguard Worker* The number of function records.
294*9880d681SAndroid Build Coastguard Worker
295*9880d681SAndroid Build Coastguard Worker* The length of the string in the third field of *__llvm_coverage_mapping* that contains the encoded translation unit filenames.
296*9880d681SAndroid Build Coastguard Worker
297*9880d681SAndroid Build Coastguard Worker* The length of the string in the third field of *__llvm_coverage_mapping* that contains the encoded coverage mapping data.
298*9880d681SAndroid Build Coastguard Worker
299*9880d681SAndroid Build Coastguard Worker* The format version. The current version is 2 (encoded as a 1).
300*9880d681SAndroid Build Coastguard Worker
301*9880d681SAndroid Build Coastguard Worker.. _function records:
302*9880d681SAndroid Build Coastguard Worker
303*9880d681SAndroid Build Coastguard WorkerFunction record:
304*9880d681SAndroid Build Coastguard Worker----------------
305*9880d681SAndroid Build Coastguard Worker
306*9880d681SAndroid Build Coastguard WorkerA function record is a structure of the following type:
307*9880d681SAndroid Build Coastguard Worker
308*9880d681SAndroid Build Coastguard Worker.. code-block:: llvm
309*9880d681SAndroid Build Coastguard Worker
310*9880d681SAndroid Build Coastguard Worker  { i64, i32, i64 }
311*9880d681SAndroid Build Coastguard Worker
312*9880d681SAndroid Build Coastguard WorkerIt contains function name's MD5, the length of the encoded mapping data for that function, and function's
313*9880d681SAndroid Build Coastguard Workerstructural hash value.
314*9880d681SAndroid Build Coastguard Worker
315*9880d681SAndroid Build Coastguard WorkerEncoded data:
316*9880d681SAndroid Build Coastguard Worker-------------
317*9880d681SAndroid Build Coastguard Worker
318*9880d681SAndroid Build Coastguard WorkerThe encoded data is stored in a single string that contains
319*9880d681SAndroid Build Coastguard Workerthe encoded filenames used by this translation unit and the encoded coverage
320*9880d681SAndroid Build Coastguard Workermapping data for each function in this translation unit.
321*9880d681SAndroid Build Coastguard Worker
322*9880d681SAndroid Build Coastguard WorkerThe encoded data has the following structure:
323*9880d681SAndroid Build Coastguard Worker
324*9880d681SAndroid Build Coastguard Worker``[filenames, coverageMappingDataForFunctionRecord0, coverageMappingDataForFunctionRecord1, ..., padding]``
325*9880d681SAndroid Build Coastguard Worker
326*9880d681SAndroid Build Coastguard WorkerIf necessary, the encoded data is padded with zeroes so that the size
327*9880d681SAndroid Build Coastguard Workerof the data string is rounded up to the nearest multiple of 8 bytes.
328*9880d681SAndroid Build Coastguard Worker
329*9880d681SAndroid Build Coastguard WorkerDissecting the sample:
330*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^
331*9880d681SAndroid Build Coastguard Worker
332*9880d681SAndroid Build Coastguard WorkerHere's an overview of the encoded data that was stored in the
333*9880d681SAndroid Build Coastguard WorkerIR for the `coverage mapping sample`_ that was shown earlier:
334*9880d681SAndroid Build Coastguard Worker
335*9880d681SAndroid Build Coastguard Worker* The IR contains the following string constant that represents the encoded
336*9880d681SAndroid Build Coastguard Worker  coverage mapping data for the sample translation unit:
337*9880d681SAndroid Build Coastguard Worker
338*9880d681SAndroid Build Coastguard Worker  .. code-block:: llvm
339*9880d681SAndroid Build Coastguard Worker
340*9880d681SAndroid Build Coastguard Worker    c"\01\12/Users/alex/test.c\01\00\00\01\01\01\0C\02\02\01\00\00\01\01\04\0C\02\02\00\00"
341*9880d681SAndroid Build Coastguard Worker
342*9880d681SAndroid Build Coastguard Worker* The string contains values that are encoded in the LEB128 format, which is
343*9880d681SAndroid Build Coastguard Worker  used throughout for storing integers. It also contains a string value.
344*9880d681SAndroid Build Coastguard Worker
345*9880d681SAndroid Build Coastguard Worker* The length of the substring that contains the encoded translation unit
346*9880d681SAndroid Build Coastguard Worker  filenames is the value of the second field in the *__llvm_coverage_mapping*
347*9880d681SAndroid Build Coastguard Worker  structure, which is 20, thus the filenames are encoded in this string:
348*9880d681SAndroid Build Coastguard Worker
349*9880d681SAndroid Build Coastguard Worker  .. code-block:: llvm
350*9880d681SAndroid Build Coastguard Worker
351*9880d681SAndroid Build Coastguard Worker    c"\01\12/Users/alex/test.c"
352*9880d681SAndroid Build Coastguard Worker
353*9880d681SAndroid Build Coastguard Worker  This string contains the following data:
354*9880d681SAndroid Build Coastguard Worker
355*9880d681SAndroid Build Coastguard Worker  * Its first byte has a value of ``0x01``. It stores the number of filenames
356*9880d681SAndroid Build Coastguard Worker    contained in this string.
357*9880d681SAndroid Build Coastguard Worker  * Its second byte stores the length of the first filename in this string.
358*9880d681SAndroid Build Coastguard Worker  * The remaining 18 bytes are used to store the first filename.
359*9880d681SAndroid Build Coastguard Worker
360*9880d681SAndroid Build Coastguard Worker* The length of the substring that contains the encoded coverage mapping data
361*9880d681SAndroid Build Coastguard Worker  for the first function is the value of the third field in the first
362*9880d681SAndroid Build Coastguard Worker  structure in an array of `function records`_ stored in the
363*9880d681SAndroid Build Coastguard Worker  third field of the *__llvm_coverage_mapping* structure, which is the 9.
364*9880d681SAndroid Build Coastguard Worker  Therefore, the coverage mapping for the first function record is encoded
365*9880d681SAndroid Build Coastguard Worker  in this string:
366*9880d681SAndroid Build Coastguard Worker
367*9880d681SAndroid Build Coastguard Worker  .. code-block:: llvm
368*9880d681SAndroid Build Coastguard Worker
369*9880d681SAndroid Build Coastguard Worker    c"\01\00\00\01\01\01\0C\02\02"
370*9880d681SAndroid Build Coastguard Worker
371*9880d681SAndroid Build Coastguard Worker  This string consists of the following bytes:
372*9880d681SAndroid Build Coastguard Worker
373*9880d681SAndroid Build Coastguard Worker  +----------+-------------------------------------------------------------------------------------------------------------------------+
374*9880d681SAndroid Build Coastguard Worker  | ``0x01`` | The number of file ids used by this function. There is only one file id used by the mapping data in this function.      |
375*9880d681SAndroid Build Coastguard Worker  +----------+-------------------------------------------------------------------------------------------------------------------------+
376*9880d681SAndroid Build Coastguard Worker  | ``0x00`` | An index into the filenames array which corresponds to the file "/Users/alex/test.c".                                   |
377*9880d681SAndroid Build Coastguard Worker  +----------+-------------------------------------------------------------------------------------------------------------------------+
378*9880d681SAndroid Build Coastguard Worker  | ``0x00`` | The number of counter expressions used by this function. This function doesn't use any expressions.                     |
379*9880d681SAndroid Build Coastguard Worker  +----------+-------------------------------------------------------------------------------------------------------------------------+
380*9880d681SAndroid Build Coastguard Worker  | ``0x01`` | The number of mapping regions that are stored in an array for the function's file id #0.                                |
381*9880d681SAndroid Build Coastguard Worker  +----------+-------------------------------------------------------------------------------------------------------------------------+
382*9880d681SAndroid Build Coastguard Worker  | ``0x01`` | The coverage mapping counter for the first region in this function. The value of 1 tells us that it's a coverage        |
383*9880d681SAndroid Build Coastguard Worker  |          | mapping counter that is a reference to the profile instrumentation counter with an index of 0.                          |
384*9880d681SAndroid Build Coastguard Worker  +----------+-------------------------------------------------------------------------------------------------------------------------+
385*9880d681SAndroid Build Coastguard Worker  | ``0x01`` | The starting line of the first mapping region in this function.                                                         |
386*9880d681SAndroid Build Coastguard Worker  +----------+-------------------------------------------------------------------------------------------------------------------------+
387*9880d681SAndroid Build Coastguard Worker  | ``0x0C`` | The starting column of the first mapping region in this function.                                                       |
388*9880d681SAndroid Build Coastguard Worker  +----------+-------------------------------------------------------------------------------------------------------------------------+
389*9880d681SAndroid Build Coastguard Worker  | ``0x02`` | The ending line of the first mapping region in this function.                                                           |
390*9880d681SAndroid Build Coastguard Worker  +----------+-------------------------------------------------------------------------------------------------------------------------+
391*9880d681SAndroid Build Coastguard Worker  | ``0x02`` | The ending column of the first mapping region in this function.                                                         |
392*9880d681SAndroid Build Coastguard Worker  +----------+-------------------------------------------------------------------------------------------------------------------------+
393*9880d681SAndroid Build Coastguard Worker
394*9880d681SAndroid Build Coastguard Worker* The length of the substring that contains the encoded coverage mapping data
395*9880d681SAndroid Build Coastguard Worker  for the second function record is also 9. It's structured like the mapping data
396*9880d681SAndroid Build Coastguard Worker  for the first function record.
397*9880d681SAndroid Build Coastguard Worker
398*9880d681SAndroid Build Coastguard Worker* The two trailing bytes are zeroes and are used to pad the coverage mapping
399*9880d681SAndroid Build Coastguard Worker  data to give it the 8 byte alignment.
400*9880d681SAndroid Build Coastguard Worker
401*9880d681SAndroid Build Coastguard WorkerEncoding
402*9880d681SAndroid Build Coastguard Worker========
403*9880d681SAndroid Build Coastguard Worker
404*9880d681SAndroid Build Coastguard WorkerThe per-function coverage mapping data is encoded as a stream of bytes,
405*9880d681SAndroid Build Coastguard Workerwith a simple structure. The structure consists of the encoding
406*9880d681SAndroid Build Coastguard Worker`types <cvmtypes_>`_ like variable-length unsigned integers, that
407*9880d681SAndroid Build Coastguard Workerare used to encode `File ID Mapping`_, `Counter Expressions`_ and
408*9880d681SAndroid Build Coastguard Workerthe `Mapping Regions`_.
409*9880d681SAndroid Build Coastguard Worker
410*9880d681SAndroid Build Coastguard WorkerThe format of the structure follows:
411*9880d681SAndroid Build Coastguard Worker
412*9880d681SAndroid Build Coastguard Worker  ``[file id mapping, counter expressions, mapping regions]``
413*9880d681SAndroid Build Coastguard Worker
414*9880d681SAndroid Build Coastguard WorkerThe translation unit filenames are encoded using the same encoding
415*9880d681SAndroid Build Coastguard Worker`types <cvmtypes_>`_ as the per-function coverage mapping data, with the
416*9880d681SAndroid Build Coastguard Workerfollowing structure:
417*9880d681SAndroid Build Coastguard Worker
418*9880d681SAndroid Build Coastguard Worker  ``[numFilenames : LEB128, filename0 : string, filename1 : string, ...]``
419*9880d681SAndroid Build Coastguard Worker
420*9880d681SAndroid Build Coastguard Worker.. _cvmtypes:
421*9880d681SAndroid Build Coastguard Worker
422*9880d681SAndroid Build Coastguard WorkerTypes
423*9880d681SAndroid Build Coastguard Worker-----
424*9880d681SAndroid Build Coastguard Worker
425*9880d681SAndroid Build Coastguard WorkerThis section describes the basic types that are used by the encoding format
426*9880d681SAndroid Build Coastguard Workerand can appear after ``:`` in the ``[foo : type]`` description.
427*9880d681SAndroid Build Coastguard Worker
428*9880d681SAndroid Build Coastguard Worker.. _LEB128:
429*9880d681SAndroid Build Coastguard Worker
430*9880d681SAndroid Build Coastguard WorkerLEB128
431*9880d681SAndroid Build Coastguard Worker^^^^^^
432*9880d681SAndroid Build Coastguard Worker
433*9880d681SAndroid Build Coastguard WorkerLEB128 is an unsigned integer value that is encoded using DWARF's LEB128
434*9880d681SAndroid Build Coastguard Workerencoding, optimizing for the case where values are small
435*9880d681SAndroid Build Coastguard Worker(1 byte for values less than 128).
436*9880d681SAndroid Build Coastguard Worker
437*9880d681SAndroid Build Coastguard Worker.. _Strings:
438*9880d681SAndroid Build Coastguard Worker
439*9880d681SAndroid Build Coastguard WorkerStrings
440*9880d681SAndroid Build Coastguard Worker^^^^^^^
441*9880d681SAndroid Build Coastguard Worker
442*9880d681SAndroid Build Coastguard Worker``[length : LEB128, characters...]``
443*9880d681SAndroid Build Coastguard Worker
444*9880d681SAndroid Build Coastguard WorkerString values are encoded with a `LEB value <LEB128_>`_ for the length
445*9880d681SAndroid Build Coastguard Workerof the string and a sequence of bytes for its characters.
446*9880d681SAndroid Build Coastguard Worker
447*9880d681SAndroid Build Coastguard Worker.. _file id mapping:
448*9880d681SAndroid Build Coastguard Worker
449*9880d681SAndroid Build Coastguard WorkerFile ID Mapping
450*9880d681SAndroid Build Coastguard Worker---------------
451*9880d681SAndroid Build Coastguard Worker
452*9880d681SAndroid Build Coastguard Worker``[numIndices : LEB128, filenameIndex0 : LEB128, filenameIndex1 : LEB128, ...]``
453*9880d681SAndroid Build Coastguard Worker
454*9880d681SAndroid Build Coastguard WorkerFile id mapping in a function's coverage mapping stream
455*9880d681SAndroid Build Coastguard Workercontains the indices into the translation unit's filenames array.
456*9880d681SAndroid Build Coastguard Worker
457*9880d681SAndroid Build Coastguard WorkerCounter
458*9880d681SAndroid Build Coastguard Worker-------
459*9880d681SAndroid Build Coastguard Worker
460*9880d681SAndroid Build Coastguard Worker``[value : LEB128]``
461*9880d681SAndroid Build Coastguard Worker
462*9880d681SAndroid Build Coastguard WorkerA `coverage mapping counter`_ is stored in a single `LEB value <LEB128_>`_.
463*9880d681SAndroid Build Coastguard WorkerIt is composed of two things --- the `tag <counter-tag_>`_
464*9880d681SAndroid Build Coastguard Workerwhich is stored in the lowest 2 bits, and the `counter data`_ which is stored
465*9880d681SAndroid Build Coastguard Workerin the remaining bits.
466*9880d681SAndroid Build Coastguard Worker
467*9880d681SAndroid Build Coastguard Worker.. _counter-tag:
468*9880d681SAndroid Build Coastguard Worker
469*9880d681SAndroid Build Coastguard WorkerTag:
470*9880d681SAndroid Build Coastguard Worker^^^^
471*9880d681SAndroid Build Coastguard Worker
472*9880d681SAndroid Build Coastguard WorkerThe counter's tag encodes the counter's kind
473*9880d681SAndroid Build Coastguard Workerand, if the counter is an expression, the expression's kind.
474*9880d681SAndroid Build Coastguard WorkerThe possible tag values are:
475*9880d681SAndroid Build Coastguard Worker
476*9880d681SAndroid Build Coastguard Worker* 0 - The counter is zero.
477*9880d681SAndroid Build Coastguard Worker
478*9880d681SAndroid Build Coastguard Worker* 1 - The counter is a reference to the profile instrumentation counter.
479*9880d681SAndroid Build Coastguard Worker
480*9880d681SAndroid Build Coastguard Worker* 2 - The counter is a subtraction expression.
481*9880d681SAndroid Build Coastguard Worker
482*9880d681SAndroid Build Coastguard Worker* 3 - The counter is an addition expression.
483*9880d681SAndroid Build Coastguard Worker
484*9880d681SAndroid Build Coastguard Worker.. _counter data:
485*9880d681SAndroid Build Coastguard Worker
486*9880d681SAndroid Build Coastguard WorkerData:
487*9880d681SAndroid Build Coastguard Worker^^^^^
488*9880d681SAndroid Build Coastguard Worker
489*9880d681SAndroid Build Coastguard WorkerThe counter's data is interpreted in the following manner:
490*9880d681SAndroid Build Coastguard Worker
491*9880d681SAndroid Build Coastguard Worker* When the counter is a reference to the profile instrumentation counter,
492*9880d681SAndroid Build Coastguard Worker  then the counter's data is the id of the profile counter.
493*9880d681SAndroid Build Coastguard Worker* When the counter is an expression, then the counter's data
494*9880d681SAndroid Build Coastguard Worker  is the index into the array of counter expressions.
495*9880d681SAndroid Build Coastguard Worker
496*9880d681SAndroid Build Coastguard Worker.. _Counter Expressions:
497*9880d681SAndroid Build Coastguard Worker
498*9880d681SAndroid Build Coastguard WorkerCounter Expressions
499*9880d681SAndroid Build Coastguard Worker-------------------
500*9880d681SAndroid Build Coastguard Worker
501*9880d681SAndroid Build Coastguard Worker``[numExpressions : LEB128, expr0LHS : LEB128, expr0RHS : LEB128, expr1LHS : LEB128, expr1RHS : LEB128, ...]``
502*9880d681SAndroid Build Coastguard Worker
503*9880d681SAndroid Build Coastguard WorkerCounter expressions consist of two counters as they
504*9880d681SAndroid Build Coastguard Workerrepresent binary arithmetic operations.
505*9880d681SAndroid Build Coastguard WorkerThe expression's kind is determined from the `tag <counter-tag_>`_ of the
506*9880d681SAndroid Build Coastguard Workercounter that references this expression.
507*9880d681SAndroid Build Coastguard Worker
508*9880d681SAndroid Build Coastguard Worker.. _Mapping Regions:
509*9880d681SAndroid Build Coastguard Worker
510*9880d681SAndroid Build Coastguard WorkerMapping Regions
511*9880d681SAndroid Build Coastguard Worker---------------
512*9880d681SAndroid Build Coastguard Worker
513*9880d681SAndroid Build Coastguard Worker``[numRegionArrays : LEB128, regionsForFile0, regionsForFile1, ...]``
514*9880d681SAndroid Build Coastguard Worker
515*9880d681SAndroid Build Coastguard WorkerThe mapping regions are stored in an array of sub-arrays where every
516*9880d681SAndroid Build Coastguard Workerregion in a particular sub-array has the same file id.
517*9880d681SAndroid Build Coastguard Worker
518*9880d681SAndroid Build Coastguard WorkerThe file id for a sub-array of regions is the index of that
519*9880d681SAndroid Build Coastguard Workersub-array in the main array e.g. The first sub-array will have the file id
520*9880d681SAndroid Build Coastguard Workerof 0.
521*9880d681SAndroid Build Coastguard Worker
522*9880d681SAndroid Build Coastguard WorkerSub-Array of Regions
523*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^
524*9880d681SAndroid Build Coastguard Worker
525*9880d681SAndroid Build Coastguard Worker``[numRegions : LEB128, region0, region1, ...]``
526*9880d681SAndroid Build Coastguard Worker
527*9880d681SAndroid Build Coastguard WorkerThe mapping regions for a specific file id are stored in an array that is
528*9880d681SAndroid Build Coastguard Workersorted in an ascending order by the region's starting location.
529*9880d681SAndroid Build Coastguard Worker
530*9880d681SAndroid Build Coastguard WorkerMapping Region
531*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^^^
532*9880d681SAndroid Build Coastguard Worker
533*9880d681SAndroid Build Coastguard Worker``[header, source range]``
534*9880d681SAndroid Build Coastguard Worker
535*9880d681SAndroid Build Coastguard WorkerThe mapping region record contains two sub-records ---
536*9880d681SAndroid Build Coastguard Workerthe `header`_, which stores the counter and/or the region's kind,
537*9880d681SAndroid Build Coastguard Workerand the `source range`_ that contains the starting and ending
538*9880d681SAndroid Build Coastguard Workerlocation of this region.
539*9880d681SAndroid Build Coastguard Worker
540*9880d681SAndroid Build Coastguard Worker.. _header:
541*9880d681SAndroid Build Coastguard Worker
542*9880d681SAndroid Build Coastguard WorkerHeader
543*9880d681SAndroid Build Coastguard Worker^^^^^^
544*9880d681SAndroid Build Coastguard Worker
545*9880d681SAndroid Build Coastguard Worker``[counter]``
546*9880d681SAndroid Build Coastguard Worker
547*9880d681SAndroid Build Coastguard Workeror
548*9880d681SAndroid Build Coastguard Worker
549*9880d681SAndroid Build Coastguard Worker``[pseudo-counter]``
550*9880d681SAndroid Build Coastguard Worker
551*9880d681SAndroid Build Coastguard WorkerThe header encodes the region's counter and the region's kind.
552*9880d681SAndroid Build Coastguard Worker
553*9880d681SAndroid Build Coastguard WorkerThe value of the counter's tag distinguishes between the counters and
554*9880d681SAndroid Build Coastguard Workerpseudo-counters --- if the tag is zero, than this header contains a
555*9880d681SAndroid Build Coastguard Workerpseudo-counter, otherwise this header contains an ordinary counter.
556*9880d681SAndroid Build Coastguard Worker
557*9880d681SAndroid Build Coastguard WorkerCounter:
558*9880d681SAndroid Build Coastguard Worker""""""""
559*9880d681SAndroid Build Coastguard Worker
560*9880d681SAndroid Build Coastguard WorkerA mapping region whose header has a counter with a non-zero tag is
561*9880d681SAndroid Build Coastguard Workera code region.
562*9880d681SAndroid Build Coastguard Worker
563*9880d681SAndroid Build Coastguard WorkerPseudo-Counter:
564*9880d681SAndroid Build Coastguard Worker"""""""""""""""
565*9880d681SAndroid Build Coastguard Worker
566*9880d681SAndroid Build Coastguard Worker``[value : LEB128]``
567*9880d681SAndroid Build Coastguard Worker
568*9880d681SAndroid Build Coastguard WorkerA pseudo-counter is stored in a single `LEB value <LEB128_>`_, just like
569*9880d681SAndroid Build Coastguard Workerthe ordinary counter. It has the following interpretation:
570*9880d681SAndroid Build Coastguard Worker
571*9880d681SAndroid Build Coastguard Worker* bits 0-1: tag, which is always 0.
572*9880d681SAndroid Build Coastguard Worker
573*9880d681SAndroid Build Coastguard Worker* bit 2: expansionRegionTag. If this bit is set, then this mapping region
574*9880d681SAndroid Build Coastguard Worker  is an expansion region.
575*9880d681SAndroid Build Coastguard Worker
576*9880d681SAndroid Build Coastguard Worker* remaining bits: data. If this region is an expansion region, then the data
577*9880d681SAndroid Build Coastguard Worker  contains the expanded file id of that region.
578*9880d681SAndroid Build Coastguard Worker
579*9880d681SAndroid Build Coastguard Worker  Otherwise, the data contains the region's kind. The possible region
580*9880d681SAndroid Build Coastguard Worker  kind values are:
581*9880d681SAndroid Build Coastguard Worker
582*9880d681SAndroid Build Coastguard Worker  * 0 - This mapping region is a code region with a counter of zero.
583*9880d681SAndroid Build Coastguard Worker  * 2 - This mapping region is a skipped region.
584*9880d681SAndroid Build Coastguard Worker
585*9880d681SAndroid Build Coastguard Worker.. _source range:
586*9880d681SAndroid Build Coastguard Worker
587*9880d681SAndroid Build Coastguard WorkerSource Range
588*9880d681SAndroid Build Coastguard Worker^^^^^^^^^^^^
589*9880d681SAndroid Build Coastguard Worker
590*9880d681SAndroid Build Coastguard Worker``[deltaLineStart : LEB128, columnStart : LEB128, numLines : LEB128, columnEnd : LEB128]``
591*9880d681SAndroid Build Coastguard Worker
592*9880d681SAndroid Build Coastguard WorkerThe source range record contains the following fields:
593*9880d681SAndroid Build Coastguard Worker
594*9880d681SAndroid Build Coastguard Worker* *deltaLineStart*: The difference between the starting line of the
595*9880d681SAndroid Build Coastguard Worker  current mapping region and the starting line of the previous mapping region.
596*9880d681SAndroid Build Coastguard Worker
597*9880d681SAndroid Build Coastguard Worker  If the current mapping region is the first region in the current
598*9880d681SAndroid Build Coastguard Worker  sub-array, then it stores the starting line of that region.
599*9880d681SAndroid Build Coastguard Worker
600*9880d681SAndroid Build Coastguard Worker* *columnStart*: The starting column of the mapping region.
601*9880d681SAndroid Build Coastguard Worker
602*9880d681SAndroid Build Coastguard Worker* *numLines*: The difference between the ending line and the starting line
603*9880d681SAndroid Build Coastguard Worker  of the current mapping region.
604*9880d681SAndroid Build Coastguard Worker
605*9880d681SAndroid Build Coastguard Worker* *columnEnd*: The ending column of the mapping region.
606