CoverageMappingFormat.rst 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. .. role:: raw-html(raw)
  2. :format: html
  3. =================================
  4. LLVM Code Coverage Mapping Format
  5. =================================
  6. .. contents::
  7. :local:
  8. Introduction
  9. ============
  10. LLVM's code coverage mapping format is used to provide code coverage
  11. analysis using LLVM's and Clang's instrumenation based profiling
  12. (Clang's ``-fprofile-instr-generate`` option).
  13. This document is aimed at those who use LLVM's code coverage mapping to provide
  14. code coverage analysis for their own programs, and for those who would like
  15. to know how it works under the hood. A prior knowledge of how Clang's profile
  16. guided optimization works is useful, but not required.
  17. We start by showing how to use LLVM and Clang for code coverage analysis,
  18. then we briefly describe LLVM's code coverage mapping format and the
  19. way that Clang and LLVM's code coverage tool work with this format. After
  20. the basics are down, more advanced features of the coverage mapping format
  21. are discussed - such as the data structures, LLVM IR representation and
  22. the binary encoding.
  23. Quick Start
  24. ===========
  25. Here's a short story that describes how to generate code coverage overview
  26. for a sample source file called *test.c*.
  27. * First, compile an instrumented version of your program using Clang's
  28. ``-fprofile-instr-generate`` option with the additional ``-fcoverage-mapping``
  29. option:
  30. ``clang -o test -fprofile-instr-generate -fcoverage-mapping test.c``
  31. * Then, run the instrumented binary. The runtime will produce a file called
  32. *default.profraw* containing the raw profile instrumentation data:
  33. ``./test``
  34. * After that, merge the profile data using the *llvm-profdata* tool:
  35. ``llvm-profdata merge -o test.profdata default.profraw``
  36. * Finally, run LLVM's code coverage tool (*llvm-cov*) to produce the code
  37. coverage overview for the sample source file:
  38. ``llvm-cov show ./test -instr-profile=test.profdata test.c``
  39. High Level Overview
  40. ===================
  41. LLVM's code coverage mapping format is designed to be a self contained
  42. data format, that can be embedded into the LLVM IR and object files.
  43. It's described in this document as a **mapping** format because its goal is
  44. to store the data that is required for a code coverage tool to map between
  45. the specific source ranges in a file and the execution counts obtained
  46. after running the instrumented version of the program.
  47. The mapping data is used in two places in the code coverage process:
  48. 1. When clang compiles a source file with ``-fcoverage-mapping``, it
  49. generates the mapping information that describes the mapping between the
  50. source ranges and the profiling instrumentation counters.
  51. This information gets embedded into the LLVM IR and conveniently
  52. ends up in the final executable file when the program is linked.
  53. 2. It is also used by *llvm-cov* - the mapping information is extracted from an
  54. object file and is used to associate the execution counts (the values of the
  55. profile instrumentation counters), and the source ranges in a file.
  56. After that, the tool is able to generate various code coverage reports
  57. for the program.
  58. The coverage mapping format aims to be a "universal format" that would be
  59. suitable for usage by any frontend, and not just by Clang. It also aims to
  60. provide the frontend the possibility of generating the minimal coverage mapping
  61. data in order to reduce the size of the IR and object files - for example,
  62. instead of emitting mapping information for each statement in a function, the
  63. frontend is allowed to group the statements with the same execution count into
  64. regions of code, and emit the mapping information only for those regions.
  65. Advanced Concepts
  66. =================
  67. The remainder of this guide is meant to give you insight into the way the
  68. coverage mapping format works.
  69. The coverage mapping format operates on a per-function level as the
  70. profile instrumentation counters are associated with a specific function.
  71. For each function that requires code coverage, the frontend has to create
  72. coverage mapping data that can map between the source code ranges and
  73. the profile instrumentation counters for that function.
  74. Mapping Region
  75. --------------
  76. The function's coverage mapping data contains an array of mapping regions.
  77. A mapping region stores the `source code range`_ that is covered by this region,
  78. the `file id <coverage file id_>`_, the `coverage mapping counter`_ and
  79. the region's kind.
  80. There are several kinds of mapping regions:
  81. * Code regions associate portions of source code and `coverage mapping
  82. counters`_. They make up the majority of the mapping regions. They are used
  83. by the code coverage tool to compute the execution counts for lines,
  84. highlight the regions of code that were never executed, and to obtain
  85. the various code coverage statistics for a function.
  86. For example:
  87. :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>
  88. <span style='background-color:#4A789C'> </span>
  89. <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>
  90. <span style='background-color:#85C1F5'> printf("%s\n", argv[1]); </span>
  91. <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>
  92. <span style='background-color:#F6D55D'> printf("\n"); </span>
  93. <span style='background-color:#F6D55D'> }</span><span style='background-color:#4A789C'> </span>
  94. <span style='background-color:#4A789C'> return 0; </span>
  95. <span style='background-color:#4A789C'>}</span>
  96. </pre>`
  97. * Skipped regions are used to represent source ranges that were skipped
  98. by Clang's preprocessor. They don't associate with
  99. `coverage mapping counters`_, as the frontend knows that they are never
  100. executed. They are used by the code coverage tool to mark the skipped lines
  101. inside a function as non-code lines that don't have execution counts.
  102. For example:
  103. :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>
  104. <span style='background-color:#85C1F5'>#ifdef DEBUG </span> <span class='c1'>// Skipped Region from 2:1 to 4:2</span>
  105. <span style='background-color:#85C1F5'> printf("Hello world"); </span>
  106. <span style='background-color:#85C1F5'>#</span><span style='background-color:#4A789C'>endif </span>
  107. <span style='background-color:#4A789C'> return 0; </span>
  108. <span style='background-color:#4A789C'>}</span>
  109. </pre>`
  110. * Expansion regions are used to represent Clang's macro expansions. They
  111. have an additional property - *expanded file id*. This property can be
  112. used by the code coverage tool to find the mapping regions that are created
  113. as a result of this macro expansion, by checking if their file id matches the
  114. expanded file id. They don't associate with `coverage mapping counters`_,
  115. as the code coverage tool can determine the execution count for this region
  116. by looking up the execution count of the first region with a corresponding
  117. file id.
  118. For example:
  119. :raw-html:`<pre class='highlight' style='line-height:initial;'><span>int func(int x) </span><span style='background-color:#4A789C'>{ </span>
  120. <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>
  121. <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>
  122. <span style='background-color:#4A789C'>}</span>
  123. </pre>`
  124. .. _source code range:
  125. Source Range:
  126. ^^^^^^^^^^^^^
  127. The source range record contains the starting and ending location of a certain
  128. mapping region. Both locations include the line and the column numbers.
  129. .. _coverage file id:
  130. File ID:
  131. ^^^^^^^^
  132. The file id an integer value that tells us
  133. in which source file or macro expansion is this region located.
  134. It enables Clang to produce mapping information for the code
  135. defined inside macros, like this example demonstrates:
  136. :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>
  137. <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>
  138. <span style='background-color:#4A789C'> if(*str) </span>
  139. <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>
  140. <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>
  141. <span style='background-color:#4A789C'>}</span>
  142. </pre>`
  143. .. _coverage mapping counter:
  144. .. _coverage mapping counters:
  145. Counter:
  146. ^^^^^^^^
  147. A coverage mapping counter can represents a reference to the profile
  148. instrumentation counter. The execution count for a region with such counter
  149. is determined by looking up the value of the corresponding profile
  150. instrumentation counter.
  151. It can also represent a binary arithmetical expression that operates on
  152. coverage mapping counters or other expressions.
  153. The execution count for a region with an expression counter is determined by
  154. evaluating the expression's arguments and then adding them together or
  155. subtracting them from one another.
  156. In the example below, a subtraction expression is used to compute the execution
  157. count for the compound statement that follows the *else* keyword:
  158. :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>
  159. <span style='background-color:#4A789C'> </span>
  160. <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>
  161. <span style='background-color:#85C1F5'> printf("%s\n", argv[1]); </span><span> </span>
  162. <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>
  163. <span style='background-color:#F6D55D'> printf("\n"); </span>
  164. <span style='background-color:#F6D55D'> }</span><span style='background-color:#4A789C'> </span>
  165. <span style='background-color:#4A789C'> return 0; </span>
  166. <span style='background-color:#4A789C'>}</span>
  167. </pre>`
  168. Finally, a coverage mapping counter can also represent an execution count of
  169. of zero. The zero counter is used to provide coverage mapping for
  170. unreachable statements and expressions, like in the example below:
  171. :raw-html:`<pre class='highlight' style='line-height:initial;'><span>int main() </span><span style='background-color:#4A789C'>{ </span>
  172. <span style='background-color:#4A789C'> return 0; </span>
  173. <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>
  174. <span style='background-color:#4A789C'>}</span>
  175. </pre>`
  176. The zero counters allow the code coverage tool to display proper line execution
  177. counts for the unreachable lines and highlight the unreachable code.
  178. Without them, the tool would think that those lines and regions were still
  179. executed, as it doesn't possess the frontend's knowledge.
  180. LLVM IR Representation
  181. ======================
  182. The coverage mapping data is stored in the LLVM IR using a single global
  183. constant structure variable called *__llvm_coverage_mapping*
  184. with the *__llvm_covmap* section specifier.
  185. For example, let’s consider a C file and how it gets compiled to LLVM:
  186. .. _coverage mapping sample:
  187. .. code-block:: c
  188. int foo() {
  189. return 42;
  190. }
  191. int bar() {
  192. return 13;
  193. }
  194. The coverage mapping variable generated by Clang has 3 fields:
  195. * Coverage mapping header.
  196. * An array of function records.
  197. * Coverage mapping data which is an array of bytes. Zero paddings are added at the end to force 8 byte alignment.
  198. .. code-block:: llvm
  199. @__llvm_coverage_mapping = internal constant { { i32, i32, i32, i32 }, [2 x { i64, i32, i64 }], [40 x i8] }
  200. {
  201. { i32, i32, i32, i32 } ; Coverage map header
  202. {
  203. i32 2, ; The number of function records
  204. i32 20, ; The length of the string that contains the encoded translation unit filenames
  205. i32 20, ; The length of the string that contains the encoded coverage mapping data
  206. i32 2, ; Coverage mapping format version
  207. },
  208. [2 x { i64, i32, i64 }] [ ; Function records
  209. { i64, i32, i64 } {
  210. i64 0x5cf8c24cdb18bdac, ; Function's name MD5
  211. i32 9, ; Function's encoded coverage mapping data string length
  212. i64 0 ; Function's structural hash
  213. },
  214. { i64, i32, i64 } {
  215. i64 0xe413754a191db537, ; Function's name MD5
  216. i32 9, ; Function's encoded coverage mapping data string length
  217. i64 0 ; Function's structural hash
  218. }],
  219. [40 x i8] c"..." ; Encoded data (dissected later)
  220. }, section "__llvm_covmap", align 8
  221. The current version of the format is version 3. The only difference from version 2 is that a special encoding for column end locations was introduced to indicate gap regions.
  222. The function record layout has evolved since version 1. In version 1, the function record for *foo* is defined as follows:
  223. .. code-block:: llvm
  224. { i8*, i32, i32, i64 } { i8* getelementptr inbounds ([3 x i8]* @__profn_foo, i32 0, i32 0), ; Function's name
  225. i32 3, ; Function's name length
  226. i32 9, ; Function's encoded coverage mapping data string length
  227. i64 0 ; Function's structural hash
  228. }
  229. Coverage Mapping Header:
  230. ------------------------
  231. The coverage mapping header has the following fields:
  232. * The number of function records.
  233. * The length of the string in the third field of *__llvm_coverage_mapping* that contains the encoded translation unit filenames.
  234. * The length of the string in the third field of *__llvm_coverage_mapping* that contains the encoded coverage mapping data.
  235. * The format version. The current version is 3 (encoded as a 2).
  236. .. _function records:
  237. Function record:
  238. ----------------
  239. A function record is a structure of the following type:
  240. .. code-block:: llvm
  241. { i64, i32, i64 }
  242. It contains function name's MD5, the length of the encoded mapping data for that function, and function's
  243. structural hash value.
  244. Encoded data:
  245. -------------
  246. The encoded data is stored in a single string that contains
  247. the encoded filenames used by this translation unit and the encoded coverage
  248. mapping data for each function in this translation unit.
  249. The encoded data has the following structure:
  250. ``[filenames, coverageMappingDataForFunctionRecord0, coverageMappingDataForFunctionRecord1, ..., padding]``
  251. If necessary, the encoded data is padded with zeroes so that the size
  252. of the data string is rounded up to the nearest multiple of 8 bytes.
  253. Dissecting the sample:
  254. ^^^^^^^^^^^^^^^^^^^^^^
  255. Here's an overview of the encoded data that was stored in the
  256. IR for the `coverage mapping sample`_ that was shown earlier:
  257. * The IR contains the following string constant that represents the encoded
  258. coverage mapping data for the sample translation unit:
  259. .. code-block:: llvm
  260. 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"
  261. * The string contains values that are encoded in the LEB128 format, which is
  262. used throughout for storing integers. It also contains a string value.
  263. * The length of the substring that contains the encoded translation unit
  264. filenames is the value of the second field in the *__llvm_coverage_mapping*
  265. structure, which is 20, thus the filenames are encoded in this string:
  266. .. code-block:: llvm
  267. c"\01\12/Users/alex/test.c"
  268. This string contains the following data:
  269. * Its first byte has a value of ``0x01``. It stores the number of filenames
  270. contained in this string.
  271. * Its second byte stores the length of the first filename in this string.
  272. * The remaining 18 bytes are used to store the first filename.
  273. * The length of the substring that contains the encoded coverage mapping data
  274. for the first function is the value of the third field in the first
  275. structure in an array of `function records`_ stored in the
  276. third field of the *__llvm_coverage_mapping* structure, which is the 9.
  277. Therefore, the coverage mapping for the first function record is encoded
  278. in this string:
  279. .. code-block:: llvm
  280. c"\01\00\00\01\01\01\0C\02\02"
  281. This string consists of the following bytes:
  282. +----------+-------------------------------------------------------------------------------------------------------------------------+
  283. | ``0x01`` | The number of file ids used by this function. There is only one file id used by the mapping data in this function. |
  284. +----------+-------------------------------------------------------------------------------------------------------------------------+
  285. | ``0x00`` | An index into the filenames array which corresponds to the file "/Users/alex/test.c". |
  286. +----------+-------------------------------------------------------------------------------------------------------------------------+
  287. | ``0x00`` | The number of counter expressions used by this function. This function doesn't use any expressions. |
  288. +----------+-------------------------------------------------------------------------------------------------------------------------+
  289. | ``0x01`` | The number of mapping regions that are stored in an array for the function's file id #0. |
  290. +----------+-------------------------------------------------------------------------------------------------------------------------+
  291. | ``0x01`` | The coverage mapping counter for the first region in this function. The value of 1 tells us that it's a coverage |
  292. | | mapping counter that is a reference to the profile instrumentation counter with an index of 0. |
  293. +----------+-------------------------------------------------------------------------------------------------------------------------+
  294. | ``0x01`` | The starting line of the first mapping region in this function. |
  295. +----------+-------------------------------------------------------------------------------------------------------------------------+
  296. | ``0x0C`` | The starting column of the first mapping region in this function. |
  297. +----------+-------------------------------------------------------------------------------------------------------------------------+
  298. | ``0x02`` | The ending line of the first mapping region in this function. |
  299. +----------+-------------------------------------------------------------------------------------------------------------------------+
  300. | ``0x02`` | The ending column of the first mapping region in this function. |
  301. +----------+-------------------------------------------------------------------------------------------------------------------------+
  302. * The length of the substring that contains the encoded coverage mapping data
  303. for the second function record is also 9. It's structured like the mapping data
  304. for the first function record.
  305. * The two trailing bytes are zeroes and are used to pad the coverage mapping
  306. data to give it the 8 byte alignment.
  307. Encoding
  308. ========
  309. The per-function coverage mapping data is encoded as a stream of bytes,
  310. with a simple structure. The structure consists of the encoding
  311. `types <cvmtypes_>`_ like variable-length unsigned integers, that
  312. are used to encode `File ID Mapping`_, `Counter Expressions`_ and
  313. the `Mapping Regions`_.
  314. The format of the structure follows:
  315. ``[file id mapping, counter expressions, mapping regions]``
  316. The translation unit filenames are encoded using the same encoding
  317. `types <cvmtypes_>`_ as the per-function coverage mapping data, with the
  318. following structure:
  319. ``[numFilenames : LEB128, filename0 : string, filename1 : string, ...]``
  320. .. _cvmtypes:
  321. Types
  322. -----
  323. This section describes the basic types that are used by the encoding format
  324. and can appear after ``:`` in the ``[foo : type]`` description.
  325. .. _LEB128:
  326. LEB128
  327. ^^^^^^
  328. LEB128 is an unsigned integer value that is encoded using DWARF's LEB128
  329. encoding, optimizing for the case where values are small
  330. (1 byte for values less than 128).
  331. .. _CoverageStrings:
  332. Strings
  333. ^^^^^^^
  334. ``[length : LEB128, characters...]``
  335. String values are encoded with a `LEB value <LEB128_>`_ for the length
  336. of the string and a sequence of bytes for its characters.
  337. .. _file id mapping:
  338. File ID Mapping
  339. ---------------
  340. ``[numIndices : LEB128, filenameIndex0 : LEB128, filenameIndex1 : LEB128, ...]``
  341. File id mapping in a function's coverage mapping stream
  342. contains the indices into the translation unit's filenames array.
  343. Counter
  344. -------
  345. ``[value : LEB128]``
  346. A `coverage mapping counter`_ is stored in a single `LEB value <LEB128_>`_.
  347. It is composed of two things --- the `tag <counter-tag_>`_
  348. which is stored in the lowest 2 bits, and the `counter data`_ which is stored
  349. in the remaining bits.
  350. .. _counter-tag:
  351. Tag:
  352. ^^^^
  353. The counter's tag encodes the counter's kind
  354. and, if the counter is an expression, the expression's kind.
  355. The possible tag values are:
  356. * 0 - The counter is zero.
  357. * 1 - The counter is a reference to the profile instrumentation counter.
  358. * 2 - The counter is a subtraction expression.
  359. * 3 - The counter is an addition expression.
  360. .. _counter data:
  361. Data:
  362. ^^^^^
  363. The counter's data is interpreted in the following manner:
  364. * When the counter is a reference to the profile instrumentation counter,
  365. then the counter's data is the id of the profile counter.
  366. * When the counter is an expression, then the counter's data
  367. is the index into the array of counter expressions.
  368. .. _Counter Expressions:
  369. Counter Expressions
  370. -------------------
  371. ``[numExpressions : LEB128, expr0LHS : LEB128, expr0RHS : LEB128, expr1LHS : LEB128, expr1RHS : LEB128, ...]``
  372. Counter expressions consist of two counters as they
  373. represent binary arithmetic operations.
  374. The expression's kind is determined from the `tag <counter-tag_>`_ of the
  375. counter that references this expression.
  376. .. _Mapping Regions:
  377. Mapping Regions
  378. ---------------
  379. ``[numRegionArrays : LEB128, regionsForFile0, regionsForFile1, ...]``
  380. The mapping regions are stored in an array of sub-arrays where every
  381. region in a particular sub-array has the same file id.
  382. The file id for a sub-array of regions is the index of that
  383. sub-array in the main array e.g. The first sub-array will have the file id
  384. of 0.
  385. Sub-Array of Regions
  386. ^^^^^^^^^^^^^^^^^^^^
  387. ``[numRegions : LEB128, region0, region1, ...]``
  388. The mapping regions for a specific file id are stored in an array that is
  389. sorted in an ascending order by the region's starting location.
  390. Mapping Region
  391. ^^^^^^^^^^^^^^
  392. ``[header, source range]``
  393. The mapping region record contains two sub-records ---
  394. the `header`_, which stores the counter and/or the region's kind,
  395. and the `source range`_ that contains the starting and ending
  396. location of this region.
  397. .. _header:
  398. Header
  399. ^^^^^^
  400. ``[counter]``
  401. or
  402. ``[pseudo-counter]``
  403. The header encodes the region's counter and the region's kind.
  404. The value of the counter's tag distinguishes between the counters and
  405. pseudo-counters --- if the tag is zero, than this header contains a
  406. pseudo-counter, otherwise this header contains an ordinary counter.
  407. Counter:
  408. """"""""
  409. A mapping region whose header has a counter with a non-zero tag is
  410. a code region.
  411. Pseudo-Counter:
  412. """""""""""""""
  413. ``[value : LEB128]``
  414. A pseudo-counter is stored in a single `LEB value <LEB128_>`_, just like
  415. the ordinary counter. It has the following interpretation:
  416. * bits 0-1: tag, which is always 0.
  417. * bit 2: expansionRegionTag. If this bit is set, then this mapping region
  418. is an expansion region.
  419. * remaining bits: data. If this region is an expansion region, then the data
  420. contains the expanded file id of that region.
  421. Otherwise, the data contains the region's kind. The possible region
  422. kind values are:
  423. * 0 - This mapping region is a code region with a counter of zero.
  424. * 2 - This mapping region is a skipped region.
  425. .. _source range:
  426. Source Range
  427. ^^^^^^^^^^^^
  428. ``[deltaLineStart : LEB128, columnStart : LEB128, numLines : LEB128, columnEnd : LEB128]``
  429. The source range record contains the following fields:
  430. * *deltaLineStart*: The difference between the starting line of the
  431. current mapping region and the starting line of the previous mapping region.
  432. If the current mapping region is the first region in the current
  433. sub-array, then it stores the starting line of that region.
  434. * *columnStart*: The starting column of the mapping region.
  435. * *numLines*: The difference between the ending line and the starting line
  436. of the current mapping region.
  437. * *columnEnd*: The ending column of the mapping region. If the high bit is set,
  438. the current mapping region is a gap area. A count for a gap area is only used
  439. as the line execution count if there are no other regions on a line.