CodeViewTypes.rst 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. =====================================
  2. CodeView Type Records
  3. =====================================
  4. .. contents::
  5. :local:
  6. .. _types_intro:
  7. Introduction
  8. ============
  9. This document describes the usage and serialization format of the various
  10. CodeView type records that LLVM understands. This document does not describe
  11. every single CodeView type record that is defined. In some cases, this is
  12. because the records are clearly deprecated and can only appear in very old
  13. software (e.g. the 16-bit types). On other cases, it is because the records
  14. have never been observed in practice. This could be because they are only
  15. generated for non-C++ code (e.g. Visual Basic, C#), or because they have been
  16. made obsolete by newer records, or any number of other reasons. However, the
  17. records we describe here should cover 99% of type records that one can expect
  18. to encounter when dealing with modern C++ toolchains.
  19. Record Categories
  20. =================
  21. We can think of a sequence of CodeView type records as an array of variable length
  22. `leaf records`. Each such record describes its own length as part of a fixed-size
  23. header, as well as the kind of record it is. Leaf records are either padded to 4
  24. bytes (if this type stream appears in a TPI/IPI stream of a PDB) or not padded at
  25. all (if this type stream appears in the ``.debug$T`` section of an object file).
  26. Padding is implemented by inserting a decreasing sequence of `<_padding_records>`
  27. that terminates with ``LF_PAD0``.
  28. The final category of record is a ``member record``. One particular leaf type --
  29. ``LF_FIELDLIST`` -- contains a series of embedded records. While the outer
  30. ``LF_FIELDLIST`` describes its length (like any other leaf record), the embedded
  31. records -- called ``member records`` do not.
  32. .. _leaf_types:
  33. Leaf Records
  34. ------------
  35. All leaf records begin with the following 4 byte prefix:
  36. .. code-block:: c++
  37. struct RecordHeader {
  38. uint16_t RecordLen; // Record length, not including this 2 byte field.
  39. uint16_t RecordKind; // Record kind enum.
  40. };
  41. LF_POINTER (0x1002)
  42. ^^^^^^^^^^^^^^^^^^^
  43. **Usage:** Describes a pointer to another type.
  44. **Layout:**
  45. .. code-block:: none
  46. .--------------------.-- +0
  47. | Referent Type |
  48. .--------------------.-- +4
  49. | Attributes |
  50. .--------------------.-- +8
  51. | Member Ptr Info | Only present if |Attributes| indicates this is a member pointer.
  52. .--------------------.-- +E
  53. Attributes is a bitfield with the following layout:
  54. .. code-block:: none
  55. .-----------------------------------------------------------------------------------------------------.
  56. | Unused | Flags | Size | Modifiers | Mode | Kind |
  57. .-----------------------------------------------------------------------------------------------------.
  58. | | | | | | |
  59. 0x100 +0x16 +0x13 +0xD +0x8 +0x5 +0x0
  60. where the various fields are defined by the following enums:
  61. .. code-block:: c++
  62. enum class PointerKind : uint8_t {
  63. Near16 = 0x00, // 16 bit pointer
  64. Far16 = 0x01, // 16:16 far pointer
  65. Huge16 = 0x02, // 16:16 huge pointer
  66. BasedOnSegment = 0x03, // based on segment
  67. BasedOnValue = 0x04, // based on value of base
  68. BasedOnSegmentValue = 0x05, // based on segment value of base
  69. BasedOnAddress = 0x06, // based on address of base
  70. BasedOnSegmentAddress = 0x07, // based on segment address of base
  71. BasedOnType = 0x08, // based on type
  72. BasedOnSelf = 0x09, // based on self
  73. Near32 = 0x0a, // 32 bit pointer
  74. Far32 = 0x0b, // 16:32 pointer
  75. Near64 = 0x0c // 64 bit pointer
  76. };
  77. enum class PointerMode : uint8_t {
  78. Pointer = 0x00, // "normal" pointer
  79. LValueReference = 0x01, // "old" reference
  80. PointerToDataMember = 0x02, // pointer to data member
  81. PointerToMemberFunction = 0x03, // pointer to member function
  82. RValueReference = 0x04 // r-value reference
  83. };
  84. enum class PointerModifiers : uint8_t {
  85. None = 0x00, // "normal" pointer
  86. Flat32 = 0x01, // "flat" pointer
  87. Volatile = 0x02, // pointer is marked volatile
  88. Const = 0x04, // pointer is marked const
  89. Unaligned = 0x08, // pointer is marked unaligned
  90. Restrict = 0x10, // pointer is marked restrict
  91. };
  92. enum class PointerFlags : uint8_t {
  93. WinRTSmartPointer = 0x01, // pointer is a WinRT smart pointer
  94. LValueRefThisPointer = 0x02, // pointer is a 'this' pointer of a member function with ref qualifier (e.g. void X::foo() &)
  95. RValueRefThisPointer = 0x04 // pointer is a 'this' pointer of a member function with ref qualifier (e.g. void X::foo() &&)
  96. };
  97. The ``Size`` field of the Attributes bitmask is a 1-byte value indicating the
  98. pointer size. For example, a `void*` would have a size of either 4 or 8 depending
  99. on the target architecture. On the other hand, if ``Mode`` indicates that this is
  100. a pointer to member function or pointer to data member, then the size can be any
  101. implementation defined number.
  102. The ``Member Ptr Info`` field of the ``LF_POINTER`` record is only present if the
  103. attributes indicate that this is a pointer to member.
  104. Note that "plain" pointers to primitive types are not represented by ``LF_POINTER``
  105. records, they are indicated by special reserved :ref:`TypeIndex values <type_indices>`.
  106. LF_MODIFIER (0x1001)
  107. ^^^^^^^^^^^^^^^^^^^^
  108. LF_PROCEDURE (0x1008)
  109. ^^^^^^^^^^^^^^^^^^^^^
  110. LF_MFUNCTION (0x1009)
  111. ^^^^^^^^^^^^^^^^^^^^^
  112. LF_LABEL (0x000e)
  113. ^^^^^^^^^^^^^^^^^
  114. LF_ARGLIST (0x1201)
  115. ^^^^^^^^^^^^^^^^^^^
  116. LF_FIELDLIST (0x1203)
  117. ^^^^^^^^^^^^^^^^^^^^^
  118. LF_ARRAY (0x1503)
  119. ^^^^^^^^^^^^^^^^^
  120. LF_CLASS (0x1504)
  121. ^^^^^^^^^^^^^^^^^
  122. LF_STRUCTURE (0x1505)
  123. ^^^^^^^^^^^^^^^^^^^^^
  124. LF_INTERFACE (0x1519)
  125. ^^^^^^^^^^^^^^^^^^^^^
  126. LF_UNION (0x1506)
  127. ^^^^^^^^^^^^^^^^^
  128. LF_ENUM (0x1507)
  129. ^^^^^^^^^^^^^^^^
  130. LF_TYPESERVER2 (0x1515)
  131. ^^^^^^^^^^^^^^^^^^^^^^^
  132. LF_VFTABLE (0x151d)
  133. ^^^^^^^^^^^^^^^^^^^
  134. LF_VTSHAPE (0x000a)
  135. ^^^^^^^^^^^^^^^^^^^
  136. LF_BITFIELD (0x1205)
  137. ^^^^^^^^^^^^^^^^^^^^
  138. LF_FUNC_ID (0x1601)
  139. ^^^^^^^^^^^^^^^^^^^
  140. LF_MFUNC_ID (0x1602)
  141. ^^^^^^^^^^^^^^^^^^^^
  142. LF_BUILDINFO (0x1603)
  143. ^^^^^^^^^^^^^^^^^^^^^
  144. LF_SUBSTR_LIST (0x1604)
  145. ^^^^^^^^^^^^^^^^^^^^^^^
  146. LF_STRING_ID (0x1605)
  147. ^^^^^^^^^^^^^^^^^^^^^
  148. LF_UDT_SRC_LINE (0x1606)
  149. ^^^^^^^^^^^^^^^^^^^^^^^^
  150. LF_UDT_MOD_SRC_LINE (0x1607)
  151. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  152. LF_METHODLIST (0x1206)
  153. ^^^^^^^^^^^^^^^^^^^^^^
  154. LF_PRECOMP (0x1509)
  155. ^^^^^^^^^^^^^^^^^^^
  156. LF_ENDPRECOMP (0x0014)
  157. ^^^^^^^^^^^^^^^^^^^^^^
  158. .. _member_types:
  159. Member Records
  160. --------------
  161. LF_BCLASS (0x1400)
  162. ^^^^^^^^^^^^^^^^^^
  163. LF_BINTERFACE (0x151a)
  164. ^^^^^^^^^^^^^^^^^^^^^^
  165. LF_VBCLASS (0x1401)
  166. ^^^^^^^^^^^^^^^^^^^
  167. LF_IVBCLASS (0x1402)
  168. ^^^^^^^^^^^^^^^^^^^^
  169. LF_VFUNCTAB (0x1409)
  170. ^^^^^^^^^^^^^^^^^^^^
  171. LF_STMEMBER (0x150e)
  172. ^^^^^^^^^^^^^^^^^^^^
  173. LF_METHOD (0x150f)
  174. ^^^^^^^^^^^^^^^^^^
  175. LF_MEMBER (0x150d)
  176. ^^^^^^^^^^^^^^^^^^
  177. LF_NESTTYPE (0x1510)
  178. ^^^^^^^^^^^^^^^^^^^^
  179. LF_ONEMETHOD (0x1511)
  180. ^^^^^^^^^^^^^^^^^^^^^
  181. LF_ENUMERATE (0x1502)
  182. ^^^^^^^^^^^^^^^^^^^^^
  183. LF_INDEX (0x1404)
  184. ^^^^^^^^^^^^^^^^^
  185. .. _padding_records:
  186. Padding Records
  187. ---------------
  188. LF_PADn (0xf0 + n)
  189. ^^^^^^^^^^^^^^^^^^