CodeViewSymbols.rst 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. =====================================
  2. CodeView Symbol Records
  3. =====================================
  4. .. contents::
  5. :local:
  6. .. _symbols_intro:
  7. Introduction
  8. ============
  9. This document describes the usage and serialization format of the various
  10. CodeView symbol records that LLVM understands. Like
  11. :doc:`CodeView Type Records <CodeViewTypes>`, we describe only the important
  12. types which are generated by modern C++ toolchains.
  13. Record Categories
  14. =================
  15. Symbol records share one major similarity with :doc:`type records <CodeViewTypes>`:
  16. They start with the same :ref:`record prefix <leaf_types>`, which we will not describe
  17. again (refer to the previous link for a description). As a result of this, a sequence
  18. of symbol records can be processed with largely the same code as that which processes
  19. type records. There are several important differences between symbol and type records:
  20. * Symbol records only appear in the :doc:`PublicStream`, :doc:`GlobalStream`, and
  21. :doc:`Module Info Streams <ModiStream>`.
  22. * Type records only appear in the :doc:`TPI & IPI streams <TpiStream>`.
  23. * While types are referenced from other CodeView records via :ref:`type indices <type_indices>`,
  24. symbol records are referenced by the byte offset of the record in the stream that it appears
  25. in.
  26. * Types can reference types (via type indices), and symbols can reference both types (via type
  27. indices) and symbols (via offsets), but types can never reference symbols.
  28. * There is no notion of :ref:`Leaf Records <leaf_types>` and :ref:`Member Records <member_types>`
  29. as there are with types. Every symbol record describes is own length.
  30. * Certain special symbol records begin a "scope". For these records, all following records
  31. up until the next ``S_END`` record are "children" of this symbol record. For example,
  32. given a symbol record which describes a certain function, all local variables of this
  33. function would appear following the function up until the corresponding ``S_END`` record.
  34. Finally, there are three general categories of symbol record, grouped by where they are legal
  35. to appear in a PDB file. Public Symbols (which appear only in the
  36. :doc:`publics stream <PublicStream>`), Global Symbols (which appear only in the
  37. :doc:`globals stream <GlobalStream>`) and module symbols (which appear in the
  38. :doc:`module info stream <ModiStream>`).
  39. .. _public_symbols:
  40. Public Symbols
  41. --------------
  42. Public symbols are the CodeView equivalent of DWARF ``.debug_pubnames``. There
  43. is one public symbol record for every function or variable in the program that
  44. has a mangled name. The :doc:`Publics Stream <PublicStream>`, which contains these
  45. records, additionally contains a hash table that allows one to quickly locate a
  46. record by mangled name.
  47. S_PUB32 (0x110e)
  48. ^^^^^^^^^^^^^^^^
  49. There is only type of public symbol, an ``S_PUB32`` which describes a mangled
  50. name, a flag indicating what kind of symbol it is (e.g. function, variable), and
  51. the symbol's address. The :ref:`dbi_section_map_substream` of the
  52. :doc:`DBI Stream <DbiStream>` can be consulted to determine what module this address
  53. corresponds to, and from there that module's :doc:`module debug stream <ModiStream>`
  54. can be consulted to locate full information for the symbol with the given address.
  55. .. _global_symbols:
  56. Global Symbols
  57. --------------
  58. While there is one :ref:`public symbol <public_symbols>` for every symbol in the
  59. program with `external` linkage, there is one global symbol for every symbol in the
  60. program with linkage (including internal linkage). As a result, global symbols do
  61. not describe a mangled name *or* an address, since symbols with internal linkage
  62. need not have any mangling at all, and also may not have an address. Thus, all
  63. global symbols simply refer directly to the full symbol record via a module/offset
  64. combination.
  65. Similarly to :ref:`public symbols <public_symbols>`, all global symbols are contained
  66. in a single :doc:`Globals Stream <GlobalStream>`, which contains a hash table mapping
  67. fully qualified name to the corresponding record in the globals stream (which as
  68. mentioned, then contains information allowing one to locate the full record in the
  69. corresponding module symbol stream).
  70. Note that a consequence and limitation of this design is that program-wide lookup
  71. by anything other than an exact textually matching fully-qualified name of whatever
  72. the compiler decided to emit is impractical. This differs from DWARF, where even
  73. though we don't necessarily have O(1) lookup by basename within a given scope (including
  74. O(1) scope, we at least have O(n) access within a given scope).
  75. .. important::
  76. Program-wide lookup of names by anything other than an exact textually matching fully
  77. qualified name is not possible.
  78. S_GDATA32
  79. ^^^^^^^^^^
  80. S_GTHREAD32 (0x1113)
  81. ^^^^^^^^^^^^^^^^^^^^
  82. S_PROCREF (0x1125)
  83. ^^^^^^^^^^^^^^^^^^
  84. S_LPROCREF (0x1127)
  85. ^^^^^^^^^^^^^^^^^^^
  86. S_GMANDATA (0x111d)
  87. ^^^^^^^^^^^^^^^^^^^
  88. .. _module_symbols:
  89. Module Symbols
  90. --------------
  91. S_END (0x0006)
  92. ^^^^^^^^^^^^^^
  93. S_FRAMEPROC (0x1012)
  94. ^^^^^^^^^^^^^^^^^^^^
  95. S_OBJNAME (0x1101)
  96. ^^^^^^^^^^^^^^^^^^
  97. S_THUNK32 (0x1102)
  98. ^^^^^^^^^^^^^^^^^^
  99. S_BLOCK32 (0x1103)
  100. ^^^^^^^^^^^^^^^^^^
  101. S_LABEL32 (0x1105)
  102. ^^^^^^^^^^^^^^^^^^
  103. S_REGISTER (0x1106)
  104. ^^^^^^^^^^^^^^^^^^^
  105. S_BPREL32 (0x110b)
  106. ^^^^^^^^^^^^^^^^^^
  107. S_LPROC32 (0x110f)
  108. ^^^^^^^^^^^^^^^^^^
  109. S_GPROC32 (0x1110)
  110. ^^^^^^^^^^^^^^^^^^
  111. S_REGREL32 (0x1111)
  112. ^^^^^^^^^^^^^^^^^^^
  113. S_COMPILE2 (0x1116)
  114. ^^^^^^^^^^^^^^^^^^^
  115. S_UNAMESPACE (0x1124)
  116. ^^^^^^^^^^^^^^^^^^^^^
  117. S_TRAMPOLINE (0x112c)
  118. ^^^^^^^^^^^^^^^^^^^^^
  119. S_SECTION (0x1136)
  120. ^^^^^^^^^^^^^^^^^^
  121. S_COFFGROUP (0x1137)
  122. ^^^^^^^^^^^^^^^^^^^^
  123. S_EXPORT (0x1138)
  124. ^^^^^^^^^^^^^^^^^
  125. S_CALLSITEINFO (0x1139)
  126. ^^^^^^^^^^^^^^^^^^^^^^^
  127. S_FRAMECOOKIE (0x113a)
  128. ^^^^^^^^^^^^^^^^^^^^^^
  129. S_COMPILE3 (0x113c)
  130. ^^^^^^^^^^^^^^^^^^^
  131. S_ENVBLOCK (0x113d)
  132. ^^^^^^^^^^^^^^^^^^^
  133. S_LOCAL (0x113e)
  134. ^^^^^^^^^^^^^^^^
  135. S_DEFRANGE (0x113f)
  136. ^^^^^^^^^^^^^^^^^^^
  137. S_DEFRANGE_SUBFIELD (0x1140)
  138. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  139. S_DEFRANGE_REGISTER (0x1141)
  140. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  141. S_DEFRANGE_FRAMEPOINTER_REL (0x1142)
  142. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  143. S_DEFRANGE_SUBFIELD_REGISTER (0x1143)
  144. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  145. S_DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE (0x1144)
  146. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  147. S_DEFRANGE_REGISTER_REL (0x1145)
  148. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  149. S_LPROC32_ID (0x1146)
  150. ^^^^^^^^^^^^^^^^^^^^^
  151. S_GPROC32_ID (0x1147)
  152. ^^^^^^^^^^^^^^^^^^^^^
  153. S_BUILDINFO (0x114c)
  154. ^^^^^^^^^^^^^^^^^^^^
  155. S_INLINESITE (0x114d)
  156. ^^^^^^^^^^^^^^^^^^^^^
  157. S_INLINESITE_END (0x114e)
  158. ^^^^^^^^^^^^^^^^^^^^^^^^^
  159. S_PROC_ID_END (0x114f)
  160. ^^^^^^^^^^^^^^^^^^^^^^
  161. S_FILESTATIC (0x1153)
  162. ^^^^^^^^^^^^^^^^^^^^^
  163. S_LPROC32_DPC (0x1155)
  164. ^^^^^^^^^^^^^^^^^^^^^^
  165. S_LPROC32_DPC_ID (0x1156)
  166. ^^^^^^^^^^^^^^^^^^^^^^^^^
  167. S_CALLEES (0x115a)
  168. ^^^^^^^^^^^^^^^^^^
  169. S_CALLERS (0x115b)
  170. ^^^^^^^^^^^^^^^^^^
  171. S_HEAPALLOCSITE (0x115e)
  172. ^^^^^^^^^^^^^^^^^^^^^^^^
  173. S_FASTLINK (0x1167)
  174. ^^^^^^^^^^^^^^^^^^^
  175. S_INLINEES (0x1168)
  176. ^^^^^^^^^^^^^^^^^^^
  177. .. _module_and_global_symbols:
  178. Symbols which can go in either/both of the module info stream & global stream
  179. -----------------------------------------------------------------------------
  180. S_CONSTANT (0x1107)
  181. ^^^^^^^^^^^^^^^^^^^
  182. S_UDT (0x1108)
  183. ^^^^^^^^^^^^^^
  184. S_LDATA32 (0x110c)
  185. ^^^^^^^^^^^^^^^^^^
  186. S_LTHREAD32 (0x1112)
  187. ^^^^^^^^^^^^^^^^^^^^
  188. S_LMANDATA (0x111c)
  189. ^^^^^^^^^^^^^^^^^^^
  190. S_MANCONSTANT (0x112d)
  191. ^^^^^^^^^^^^^^^^^^^^^^