Dwarf.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/BinaryFormat/Dwarf.h ---Dwarf Constants-------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. /// \file
  15. /// This file contains constants used for implementing Dwarf
  16. /// debug support.
  17. ///
  18. /// For details on the Dwarf specfication see the latest DWARF Debugging
  19. /// Information Format standard document on http://www.dwarfstd.org. This
  20. /// file often includes support for non-released standard features.
  21. //
  22. //===----------------------------------------------------------------------===//
  23. #ifndef LLVM_BINARYFORMAT_DWARF_H
  24. #define LLVM_BINARYFORMAT_DWARF_H
  25. #include "llvm/Support/Compiler.h"
  26. #include "llvm/Support/DataTypes.h"
  27. #include "llvm/Support/ErrorHandling.h"
  28. #include "llvm/Support/Format.h"
  29. #include "llvm/Support/FormatVariadicDetails.h"
  30. #include "llvm/ADT/Triple.h"
  31. #include <limits>
  32. namespace llvm {
  33. class StringRef;
  34. template<typename T> class Optional;
  35. namespace dwarf {
  36. //===----------------------------------------------------------------------===//
  37. // DWARF constants as gleaned from the DWARF Debugging Information Format V.5
  38. // reference manual http://www.dwarfstd.org/.
  39. //
  40. // Do not mix the following two enumerations sets. DW_TAG_invalid changes the
  41. // enumeration base type.
  42. enum LLVMConstants : uint32_t {
  43. /// LLVM mock tags (see also llvm/BinaryFormat/Dwarf.def).
  44. /// \{
  45. DW_TAG_invalid = ~0U, ///< Tag for invalid results.
  46. DW_VIRTUALITY_invalid = ~0U, ///< Virtuality for invalid results.
  47. DW_MACINFO_invalid = ~0U, ///< Macinfo type for invalid results.
  48. /// \}
  49. /// Special values for an initial length field.
  50. /// \{
  51. DW_LENGTH_lo_reserved = 0xfffffff0, ///< Lower bound of the reserved range.
  52. DW_LENGTH_DWARF64 = 0xffffffff, ///< Indicator of 64-bit DWARF format.
  53. DW_LENGTH_hi_reserved = 0xffffffff, ///< Upper bound of the reserved range.
  54. /// \}
  55. /// Other constants.
  56. /// \{
  57. DWARF_VERSION = 4, ///< Default dwarf version we output.
  58. DW_PUBTYPES_VERSION = 2, ///< Section version number for .debug_pubtypes.
  59. DW_PUBNAMES_VERSION = 2, ///< Section version number for .debug_pubnames.
  60. DW_ARANGES_VERSION = 2, ///< Section version number for .debug_aranges.
  61. /// \}
  62. /// Identifiers we use to distinguish vendor extensions.
  63. /// \{
  64. DWARF_VENDOR_DWARF = 0, ///< Defined in v2 or later of the DWARF standard.
  65. DWARF_VENDOR_APPLE = 1,
  66. DWARF_VENDOR_BORLAND = 2,
  67. DWARF_VENDOR_GNU = 3,
  68. DWARF_VENDOR_GOOGLE = 4,
  69. DWARF_VENDOR_LLVM = 5,
  70. DWARF_VENDOR_MIPS = 6,
  71. DWARF_VENDOR_WASM = 7,
  72. DWARF_VENDOR_ALTIUM,
  73. DWARF_VENDOR_COMPAQ,
  74. DWARF_VENDOR_GHS,
  75. DWARF_VENDOR_GO,
  76. DWARF_VENDOR_HP,
  77. DWARF_VENDOR_IBM,
  78. DWARF_VENDOR_INTEL,
  79. DWARF_VENDOR_PGI,
  80. DWARF_VENDOR_SUN,
  81. DWARF_VENDOR_UPC,
  82. ///\}
  83. };
  84. /// Constants that define the DWARF format as 32 or 64 bit.
  85. enum DwarfFormat : uint8_t { DWARF32, DWARF64 };
  86. /// Special ID values that distinguish a CIE from a FDE in DWARF CFI.
  87. /// Not inside an enum because a 64-bit value is needed.
  88. /// @{
  89. const uint32_t DW_CIE_ID = UINT32_MAX;
  90. const uint64_t DW64_CIE_ID = UINT64_MAX;
  91. /// @}
  92. /// Identifier of an invalid DIE offset in the .debug_info section.
  93. const uint32_t DW_INVALID_OFFSET = UINT32_MAX;
  94. enum Tag : uint16_t {
  95. #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) DW_TAG_##NAME = ID,
  96. #include "llvm/BinaryFormat/Dwarf.def"
  97. DW_TAG_lo_user = 0x4080,
  98. DW_TAG_hi_user = 0xffff,
  99. DW_TAG_user_base = 0x1000 ///< Recommended base for user tags.
  100. };
  101. inline bool isType(Tag T) {
  102. switch (T) {
  103. default:
  104. return false;
  105. #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \
  106. case DW_TAG_##NAME: \
  107. return (KIND == DW_KIND_TYPE);
  108. #include "llvm/BinaryFormat/Dwarf.def"
  109. }
  110. }
  111. /// Attributes.
  112. enum Attribute : uint16_t {
  113. #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) DW_AT_##NAME = ID,
  114. #include "llvm/BinaryFormat/Dwarf.def"
  115. DW_AT_lo_user = 0x2000,
  116. DW_AT_hi_user = 0x3fff,
  117. };
  118. enum Form : uint16_t {
  119. #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) DW_FORM_##NAME = ID,
  120. #include "llvm/BinaryFormat/Dwarf.def"
  121. DW_FORM_lo_user = 0x1f00, ///< Not specified by DWARF.
  122. };
  123. enum LocationAtom {
  124. #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) DW_OP_##NAME = ID,
  125. #include "llvm/BinaryFormat/Dwarf.def"
  126. DW_OP_lo_user = 0xe0,
  127. DW_OP_hi_user = 0xff,
  128. DW_OP_LLVM_fragment = 0x1000, ///< Only used in LLVM metadata.
  129. DW_OP_LLVM_convert = 0x1001, ///< Only used in LLVM metadata.
  130. DW_OP_LLVM_tag_offset = 0x1002, ///< Only used in LLVM metadata.
  131. DW_OP_LLVM_entry_value = 0x1003, ///< Only used in LLVM metadata.
  132. DW_OP_LLVM_implicit_pointer = 0x1004, ///< Only used in LLVM metadata.
  133. DW_OP_LLVM_arg = 0x1005, ///< Only used in LLVM metadata.
  134. };
  135. enum TypeKind : uint8_t {
  136. #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) DW_ATE_##NAME = ID,
  137. #include "llvm/BinaryFormat/Dwarf.def"
  138. DW_ATE_lo_user = 0x80,
  139. DW_ATE_hi_user = 0xff
  140. };
  141. enum DecimalSignEncoding {
  142. // Decimal sign attribute values
  143. DW_DS_unsigned = 0x01,
  144. DW_DS_leading_overpunch = 0x02,
  145. DW_DS_trailing_overpunch = 0x03,
  146. DW_DS_leading_separate = 0x04,
  147. DW_DS_trailing_separate = 0x05
  148. };
  149. enum EndianityEncoding {
  150. // Endianity attribute values
  151. #define HANDLE_DW_END(ID, NAME) DW_END_##NAME = ID,
  152. #include "llvm/BinaryFormat/Dwarf.def"
  153. DW_END_lo_user = 0x40,
  154. DW_END_hi_user = 0xff
  155. };
  156. enum AccessAttribute {
  157. // Accessibility codes
  158. DW_ACCESS_public = 0x01,
  159. DW_ACCESS_protected = 0x02,
  160. DW_ACCESS_private = 0x03
  161. };
  162. enum VisibilityAttribute {
  163. // Visibility codes
  164. DW_VIS_local = 0x01,
  165. DW_VIS_exported = 0x02,
  166. DW_VIS_qualified = 0x03
  167. };
  168. enum VirtualityAttribute {
  169. #define HANDLE_DW_VIRTUALITY(ID, NAME) DW_VIRTUALITY_##NAME = ID,
  170. #include "llvm/BinaryFormat/Dwarf.def"
  171. DW_VIRTUALITY_max = 0x02
  172. };
  173. enum DefaultedMemberAttribute {
  174. #define HANDLE_DW_DEFAULTED(ID, NAME) DW_DEFAULTED_##NAME = ID,
  175. #include "llvm/BinaryFormat/Dwarf.def"
  176. DW_DEFAULTED_max = 0x02
  177. };
  178. enum SourceLanguage {
  179. #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
  180. DW_LANG_##NAME = ID,
  181. #include "llvm/BinaryFormat/Dwarf.def"
  182. DW_LANG_lo_user = 0x8000,
  183. DW_LANG_hi_user = 0xffff
  184. };
  185. inline bool isCPlusPlus(SourceLanguage S) {
  186. bool result = false;
  187. // Deliberately enumerate all the language options so we get a warning when
  188. // new language options are added (-Wswitch) that'll hopefully help keep this
  189. // switch up-to-date when new C++ versions are added.
  190. switch (S) {
  191. case DW_LANG_C_plus_plus:
  192. case DW_LANG_C_plus_plus_03:
  193. case DW_LANG_C_plus_plus_11:
  194. case DW_LANG_C_plus_plus_14:
  195. result = true;
  196. break;
  197. case DW_LANG_C89:
  198. case DW_LANG_C:
  199. case DW_LANG_Ada83:
  200. case DW_LANG_Cobol74:
  201. case DW_LANG_Cobol85:
  202. case DW_LANG_Fortran77:
  203. case DW_LANG_Fortran90:
  204. case DW_LANG_Pascal83:
  205. case DW_LANG_Modula2:
  206. case DW_LANG_Java:
  207. case DW_LANG_C99:
  208. case DW_LANG_Ada95:
  209. case DW_LANG_Fortran95:
  210. case DW_LANG_PLI:
  211. case DW_LANG_ObjC:
  212. case DW_LANG_ObjC_plus_plus:
  213. case DW_LANG_UPC:
  214. case DW_LANG_D:
  215. case DW_LANG_Python:
  216. case DW_LANG_OpenCL:
  217. case DW_LANG_Go:
  218. case DW_LANG_Modula3:
  219. case DW_LANG_Haskell:
  220. case DW_LANG_OCaml:
  221. case DW_LANG_Rust:
  222. case DW_LANG_C11:
  223. case DW_LANG_Swift:
  224. case DW_LANG_Julia:
  225. case DW_LANG_Dylan:
  226. case DW_LANG_Fortran03:
  227. case DW_LANG_Fortran08:
  228. case DW_LANG_RenderScript:
  229. case DW_LANG_BLISS:
  230. case DW_LANG_Mips_Assembler:
  231. case DW_LANG_GOOGLE_RenderScript:
  232. case DW_LANG_BORLAND_Delphi:
  233. case DW_LANG_lo_user:
  234. case DW_LANG_hi_user:
  235. result = false;
  236. break;
  237. }
  238. return result;
  239. }
  240. inline bool isFortran(SourceLanguage S) {
  241. bool result = false;
  242. // Deliberately enumerate all the language options so we get a warning when
  243. // new language options are added (-Wswitch) that'll hopefully help keep this
  244. // switch up-to-date when new Fortran versions are added.
  245. switch (S) {
  246. case DW_LANG_Fortran77:
  247. case DW_LANG_Fortran90:
  248. case DW_LANG_Fortran95:
  249. case DW_LANG_Fortran03:
  250. case DW_LANG_Fortran08:
  251. result = true;
  252. break;
  253. case DW_LANG_C89:
  254. case DW_LANG_C:
  255. case DW_LANG_Ada83:
  256. case DW_LANG_C_plus_plus:
  257. case DW_LANG_Cobol74:
  258. case DW_LANG_Cobol85:
  259. case DW_LANG_Pascal83:
  260. case DW_LANG_Modula2:
  261. case DW_LANG_Java:
  262. case DW_LANG_C99:
  263. case DW_LANG_Ada95:
  264. case DW_LANG_PLI:
  265. case DW_LANG_ObjC:
  266. case DW_LANG_ObjC_plus_plus:
  267. case DW_LANG_UPC:
  268. case DW_LANG_D:
  269. case DW_LANG_Python:
  270. case DW_LANG_OpenCL:
  271. case DW_LANG_Go:
  272. case DW_LANG_Modula3:
  273. case DW_LANG_Haskell:
  274. case DW_LANG_C_plus_plus_03:
  275. case DW_LANG_C_plus_plus_11:
  276. case DW_LANG_OCaml:
  277. case DW_LANG_Rust:
  278. case DW_LANG_C11:
  279. case DW_LANG_Swift:
  280. case DW_LANG_Julia:
  281. case DW_LANG_Dylan:
  282. case DW_LANG_C_plus_plus_14:
  283. case DW_LANG_RenderScript:
  284. case DW_LANG_BLISS:
  285. case DW_LANG_Mips_Assembler:
  286. case DW_LANG_GOOGLE_RenderScript:
  287. case DW_LANG_BORLAND_Delphi:
  288. case DW_LANG_lo_user:
  289. case DW_LANG_hi_user:
  290. result = false;
  291. break;
  292. }
  293. return result;
  294. }
  295. enum CaseSensitivity {
  296. // Identifier case codes
  297. DW_ID_case_sensitive = 0x00,
  298. DW_ID_up_case = 0x01,
  299. DW_ID_down_case = 0x02,
  300. DW_ID_case_insensitive = 0x03
  301. };
  302. enum CallingConvention {
  303. // Calling convention codes
  304. #define HANDLE_DW_CC(ID, NAME) DW_CC_##NAME = ID,
  305. #include "llvm/BinaryFormat/Dwarf.def"
  306. DW_CC_lo_user = 0x40,
  307. DW_CC_hi_user = 0xff
  308. };
  309. enum InlineAttribute {
  310. // Inline codes
  311. DW_INL_not_inlined = 0x00,
  312. DW_INL_inlined = 0x01,
  313. DW_INL_declared_not_inlined = 0x02,
  314. DW_INL_declared_inlined = 0x03
  315. };
  316. enum ArrayDimensionOrdering {
  317. // Array ordering
  318. DW_ORD_row_major = 0x00,
  319. DW_ORD_col_major = 0x01
  320. };
  321. enum DiscriminantList {
  322. // Discriminant descriptor values
  323. DW_DSC_label = 0x00,
  324. DW_DSC_range = 0x01
  325. };
  326. /// Line Number Standard Opcode Encodings.
  327. enum LineNumberOps : uint8_t {
  328. #define HANDLE_DW_LNS(ID, NAME) DW_LNS_##NAME = ID,
  329. #include "llvm/BinaryFormat/Dwarf.def"
  330. };
  331. /// Line Number Extended Opcode Encodings.
  332. enum LineNumberExtendedOps {
  333. #define HANDLE_DW_LNE(ID, NAME) DW_LNE_##NAME = ID,
  334. #include "llvm/BinaryFormat/Dwarf.def"
  335. DW_LNE_lo_user = 0x80,
  336. DW_LNE_hi_user = 0xff
  337. };
  338. enum LineNumberEntryFormat {
  339. #define HANDLE_DW_LNCT(ID, NAME) DW_LNCT_##NAME = ID,
  340. #include "llvm/BinaryFormat/Dwarf.def"
  341. DW_LNCT_lo_user = 0x2000,
  342. DW_LNCT_hi_user = 0x3fff,
  343. };
  344. enum MacinfoRecordType {
  345. // Macinfo Type Encodings
  346. DW_MACINFO_define = 0x01,
  347. DW_MACINFO_undef = 0x02,
  348. DW_MACINFO_start_file = 0x03,
  349. DW_MACINFO_end_file = 0x04,
  350. DW_MACINFO_vendor_ext = 0xff
  351. };
  352. /// DWARF v5 macro information entry type encodings.
  353. enum MacroEntryType {
  354. #define HANDLE_DW_MACRO(ID, NAME) DW_MACRO_##NAME = ID,
  355. #include "llvm/BinaryFormat/Dwarf.def"
  356. DW_MACRO_lo_user = 0xe0,
  357. DW_MACRO_hi_user = 0xff
  358. };
  359. /// GNU .debug_macro macro information entry type encodings.
  360. enum GnuMacroEntryType {
  361. #define HANDLE_DW_MACRO_GNU(ID, NAME) DW_MACRO_GNU_##NAME = ID,
  362. #include "llvm/BinaryFormat/Dwarf.def"
  363. DW_MACRO_GNU_lo_user = 0xe0,
  364. DW_MACRO_GNU_hi_user = 0xff
  365. };
  366. /// DWARF v5 range list entry encoding values.
  367. enum RnglistEntries {
  368. #define HANDLE_DW_RLE(ID, NAME) DW_RLE_##NAME = ID,
  369. #include "llvm/BinaryFormat/Dwarf.def"
  370. };
  371. /// DWARF v5 loc list entry encoding values.
  372. enum LoclistEntries {
  373. #define HANDLE_DW_LLE(ID, NAME) DW_LLE_##NAME = ID,
  374. #include "llvm/BinaryFormat/Dwarf.def"
  375. };
  376. /// Call frame instruction encodings.
  377. enum CallFrameInfo {
  378. #define HANDLE_DW_CFA(ID, NAME) DW_CFA_##NAME = ID,
  379. #define HANDLE_DW_CFA_PRED(ID, NAME, ARCH) DW_CFA_##NAME = ID,
  380. #include "llvm/BinaryFormat/Dwarf.def"
  381. DW_CFA_extended = 0x00,
  382. DW_CFA_lo_user = 0x1c,
  383. DW_CFA_hi_user = 0x3f
  384. };
  385. enum Constants {
  386. // Children flag
  387. DW_CHILDREN_no = 0x00,
  388. DW_CHILDREN_yes = 0x01,
  389. DW_EH_PE_absptr = 0x00,
  390. DW_EH_PE_omit = 0xff,
  391. DW_EH_PE_uleb128 = 0x01,
  392. DW_EH_PE_udata2 = 0x02,
  393. DW_EH_PE_udata4 = 0x03,
  394. DW_EH_PE_udata8 = 0x04,
  395. DW_EH_PE_sleb128 = 0x09,
  396. DW_EH_PE_sdata2 = 0x0A,
  397. DW_EH_PE_sdata4 = 0x0B,
  398. DW_EH_PE_sdata8 = 0x0C,
  399. DW_EH_PE_signed = 0x08,
  400. DW_EH_PE_pcrel = 0x10,
  401. DW_EH_PE_textrel = 0x20,
  402. DW_EH_PE_datarel = 0x30,
  403. DW_EH_PE_funcrel = 0x40,
  404. DW_EH_PE_aligned = 0x50,
  405. DW_EH_PE_indirect = 0x80
  406. };
  407. /// Constants for the DW_APPLE_PROPERTY_attributes attribute.
  408. /// Keep this list in sync with clang's DeclObjCCommon.h
  409. /// ObjCPropertyAttribute::Kind!
  410. enum ApplePropertyAttributes {
  411. #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) DW_APPLE_PROPERTY_##NAME = ID,
  412. #include "llvm/BinaryFormat/Dwarf.def"
  413. };
  414. /// Constants for unit types in DWARF v5.
  415. enum UnitType : unsigned char {
  416. #define HANDLE_DW_UT(ID, NAME) DW_UT_##NAME = ID,
  417. #include "llvm/BinaryFormat/Dwarf.def"
  418. DW_UT_lo_user = 0x80,
  419. DW_UT_hi_user = 0xff
  420. };
  421. enum Index {
  422. #define HANDLE_DW_IDX(ID, NAME) DW_IDX_##NAME = ID,
  423. #include "llvm/BinaryFormat/Dwarf.def"
  424. DW_IDX_lo_user = 0x2000,
  425. DW_IDX_hi_user = 0x3fff
  426. };
  427. inline bool isUnitType(uint8_t UnitType) {
  428. switch (UnitType) {
  429. case DW_UT_compile:
  430. case DW_UT_type:
  431. case DW_UT_partial:
  432. case DW_UT_skeleton:
  433. case DW_UT_split_compile:
  434. case DW_UT_split_type:
  435. return true;
  436. default:
  437. return false;
  438. }
  439. }
  440. inline bool isUnitType(dwarf::Tag T) {
  441. switch (T) {
  442. case DW_TAG_compile_unit:
  443. case DW_TAG_type_unit:
  444. case DW_TAG_partial_unit:
  445. case DW_TAG_skeleton_unit:
  446. return true;
  447. default:
  448. return false;
  449. }
  450. }
  451. // Constants for the DWARF v5 Accelerator Table Proposal
  452. enum AcceleratorTable {
  453. // Data layout descriptors.
  454. DW_ATOM_null = 0u, /// Marker as the end of a list of atoms.
  455. DW_ATOM_die_offset = 1u, // DIE offset in the debug_info section.
  456. DW_ATOM_cu_offset = 2u, // Offset of the compile unit header that contains the
  457. // item in question.
  458. DW_ATOM_die_tag = 3u, // A tag entry.
  459. DW_ATOM_type_flags = 4u, // Set of flags for a type.
  460. DW_ATOM_type_type_flags = 5u, // Dsymutil type extension.
  461. DW_ATOM_qual_name_hash = 6u, // Dsymutil qualified hash extension.
  462. // DW_ATOM_type_flags values.
  463. // Always set for C++, only set for ObjC if this is the @implementation for a
  464. // class.
  465. DW_FLAG_type_implementation = 2u,
  466. // Hash functions.
  467. // Daniel J. Bernstein hash.
  468. DW_hash_function_djb = 0u
  469. };
  470. // Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
  471. enum GDBIndexEntryKind {
  472. GIEK_NONE,
  473. GIEK_TYPE,
  474. GIEK_VARIABLE,
  475. GIEK_FUNCTION,
  476. GIEK_OTHER,
  477. GIEK_UNUSED5,
  478. GIEK_UNUSED6,
  479. GIEK_UNUSED7
  480. };
  481. enum GDBIndexEntryLinkage { GIEL_EXTERNAL, GIEL_STATIC };
  482. /// \defgroup DwarfConstantsDumping Dwarf constants dumping functions
  483. ///
  484. /// All these functions map their argument's value back to the
  485. /// corresponding enumerator name or return an empty StringRef if the value
  486. /// isn't known.
  487. ///
  488. /// @{
  489. StringRef TagString(unsigned Tag);
  490. StringRef ChildrenString(unsigned Children);
  491. StringRef AttributeString(unsigned Attribute);
  492. StringRef FormEncodingString(unsigned Encoding);
  493. StringRef OperationEncodingString(unsigned Encoding);
  494. StringRef AttributeEncodingString(unsigned Encoding);
  495. StringRef DecimalSignString(unsigned Sign);
  496. StringRef EndianityString(unsigned Endian);
  497. StringRef AccessibilityString(unsigned Access);
  498. StringRef DefaultedMemberString(unsigned DefaultedEncodings);
  499. StringRef VisibilityString(unsigned Visibility);
  500. StringRef VirtualityString(unsigned Virtuality);
  501. StringRef LanguageString(unsigned Language);
  502. StringRef CaseString(unsigned Case);
  503. StringRef ConventionString(unsigned Convention);
  504. StringRef InlineCodeString(unsigned Code);
  505. StringRef ArrayOrderString(unsigned Order);
  506. StringRef LNStandardString(unsigned Standard);
  507. StringRef LNExtendedString(unsigned Encoding);
  508. StringRef MacinfoString(unsigned Encoding);
  509. StringRef MacroString(unsigned Encoding);
  510. StringRef GnuMacroString(unsigned Encoding);
  511. StringRef RangeListEncodingString(unsigned Encoding);
  512. StringRef LocListEncodingString(unsigned Encoding);
  513. StringRef CallFrameString(unsigned Encoding, Triple::ArchType Arch);
  514. StringRef ApplePropertyString(unsigned);
  515. StringRef UnitTypeString(unsigned);
  516. StringRef AtomTypeString(unsigned Atom);
  517. StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind);
  518. StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
  519. StringRef IndexString(unsigned Idx);
  520. StringRef FormatString(DwarfFormat Format);
  521. StringRef FormatString(bool IsDWARF64);
  522. StringRef RLEString(unsigned RLE);
  523. /// @}
  524. /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
  525. ///
  526. /// These functions map their strings back to the corresponding enumeration
  527. /// value or return 0 if there is none, except for these exceptions:
  528. ///
  529. /// \li \a getTag() returns \a DW_TAG_invalid on invalid input.
  530. /// \li \a getVirtuality() returns \a DW_VIRTUALITY_invalid on invalid input.
  531. /// \li \a getMacinfo() returns \a DW_MACINFO_invalid on invalid input.
  532. ///
  533. /// @{
  534. unsigned getTag(StringRef TagString);
  535. unsigned getOperationEncoding(StringRef OperationEncodingString);
  536. unsigned getVirtuality(StringRef VirtualityString);
  537. unsigned getLanguage(StringRef LanguageString);
  538. unsigned getCallingConvention(StringRef LanguageString);
  539. unsigned getAttributeEncoding(StringRef EncodingString);
  540. unsigned getMacinfo(StringRef MacinfoString);
  541. unsigned getMacro(StringRef MacroString);
  542. /// @}
  543. /// \defgroup DwarfConstantsVersioning Dwarf version for constants
  544. ///
  545. /// For constants defined by DWARF, returns the DWARF version when the constant
  546. /// was first defined. For vendor extensions, if there is a version-related
  547. /// policy for when to emit it, returns a version number for that policy.
  548. /// Otherwise returns 0.
  549. ///
  550. /// @{
  551. unsigned TagVersion(Tag T);
  552. unsigned AttributeVersion(Attribute A);
  553. unsigned FormVersion(Form F);
  554. unsigned OperationVersion(LocationAtom O);
  555. unsigned AttributeEncodingVersion(TypeKind E);
  556. unsigned LanguageVersion(SourceLanguage L);
  557. /// @}
  558. /// \defgroup DwarfConstantsVendor Dwarf "vendor" for constants
  559. ///
  560. /// These functions return an identifier describing "who" defined the constant,
  561. /// either the DWARF standard itself or the vendor who defined the extension.
  562. ///
  563. /// @{
  564. unsigned TagVendor(Tag T);
  565. unsigned AttributeVendor(Attribute A);
  566. unsigned FormVendor(Form F);
  567. unsigned OperationVendor(LocationAtom O);
  568. unsigned AttributeEncodingVendor(TypeKind E);
  569. unsigned LanguageVendor(SourceLanguage L);
  570. /// @}
  571. Optional<unsigned> LanguageLowerBound(SourceLanguage L);
  572. /// The size of a reference determined by the DWARF 32/64-bit format.
  573. inline uint8_t getDwarfOffsetByteSize(DwarfFormat Format) {
  574. switch (Format) {
  575. case DwarfFormat::DWARF32:
  576. return 4;
  577. case DwarfFormat::DWARF64:
  578. return 8;
  579. }
  580. llvm_unreachable("Invalid Format value");
  581. }
  582. /// A helper struct providing information about the byte size of DW_FORM
  583. /// values that vary in size depending on the DWARF version, address byte
  584. /// size, or DWARF32/DWARF64.
  585. struct FormParams {
  586. uint16_t Version;
  587. uint8_t AddrSize;
  588. DwarfFormat Format;
  589. /// True if DWARF v2 output generally uses relocations for references
  590. /// to other .debug_* sections.
  591. bool DwarfUsesRelocationsAcrossSections = false;
  592. /// The definition of the size of form DW_FORM_ref_addr depends on the
  593. /// version. In DWARF v2 it's the size of an address; after that, it's the
  594. /// size of a reference.
  595. uint8_t getRefAddrByteSize() const {
  596. if (Version == 2)
  597. return AddrSize;
  598. return getDwarfOffsetByteSize();
  599. }
  600. /// The size of a reference is determined by the DWARF 32/64-bit format.
  601. uint8_t getDwarfOffsetByteSize() const {
  602. return dwarf::getDwarfOffsetByteSize(Format);
  603. }
  604. explicit operator bool() const { return Version && AddrSize; }
  605. };
  606. /// Get the byte size of the unit length field depending on the DWARF format.
  607. inline uint8_t getUnitLengthFieldByteSize(DwarfFormat Format) {
  608. switch (Format) {
  609. case DwarfFormat::DWARF32:
  610. return 4;
  611. case DwarfFormat::DWARF64:
  612. return 12;
  613. }
  614. llvm_unreachable("Invalid Format value");
  615. }
  616. /// Get the fixed byte size for a given form.
  617. ///
  618. /// If the form has a fixed byte size, then an Optional with a value will be
  619. /// returned. If the form is always encoded using a variable length storage
  620. /// format (ULEB or SLEB numbers or blocks) then None will be returned.
  621. ///
  622. /// \param Form DWARF form to get the fixed byte size for.
  623. /// \param Params DWARF parameters to help interpret forms.
  624. /// \returns Optional<uint8_t> value with the fixed byte size or None if
  625. /// \p Form doesn't have a fixed byte size.
  626. Optional<uint8_t> getFixedFormByteSize(dwarf::Form Form, FormParams Params);
  627. /// Tells whether the specified form is defined in the specified version,
  628. /// or is an extension if extensions are allowed.
  629. bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk = true);
  630. /// Returns the symbolic string representing Val when used as a value
  631. /// for attribute Attr.
  632. StringRef AttributeValueString(uint16_t Attr, unsigned Val);
  633. /// Returns the symbolic string representing Val when used as a value
  634. /// for atom Atom.
  635. StringRef AtomValueString(uint16_t Atom, unsigned Val);
  636. /// Describes an entry of the various gnu_pub* debug sections.
  637. ///
  638. /// The gnu_pub* kind looks like:
  639. ///
  640. /// 0-3 reserved
  641. /// 4-6 symbol kind
  642. /// 7 0 == global, 1 == static
  643. ///
  644. /// A gdb_index descriptor includes the above kind, shifted 24 bits up with the
  645. /// offset of the cu within the debug_info section stored in those 24 bits.
  646. struct PubIndexEntryDescriptor {
  647. GDBIndexEntryKind Kind;
  648. GDBIndexEntryLinkage Linkage;
  649. PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Linkage)
  650. : Kind(Kind), Linkage(Linkage) {}
  651. /* implicit */ PubIndexEntryDescriptor(GDBIndexEntryKind Kind)
  652. : Kind(Kind), Linkage(GIEL_EXTERNAL) {}
  653. explicit PubIndexEntryDescriptor(uint8_t Value)
  654. : Kind(
  655. static_cast<GDBIndexEntryKind>((Value & KIND_MASK) >> KIND_OFFSET)),
  656. Linkage(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
  657. LINKAGE_OFFSET)) {}
  658. uint8_t toBits() const {
  659. return Kind << KIND_OFFSET | Linkage << LINKAGE_OFFSET;
  660. }
  661. private:
  662. enum {
  663. KIND_OFFSET = 4,
  664. KIND_MASK = 7 << KIND_OFFSET,
  665. LINKAGE_OFFSET = 7,
  666. LINKAGE_MASK = 1 << LINKAGE_OFFSET
  667. };
  668. };
  669. template <typename Enum> struct EnumTraits : public std::false_type {};
  670. template <> struct EnumTraits<Attribute> : public std::true_type {
  671. static constexpr char Type[3] = "AT";
  672. static constexpr StringRef (*StringFn)(unsigned) = &AttributeString;
  673. };
  674. template <> struct EnumTraits<Form> : public std::true_type {
  675. static constexpr char Type[5] = "FORM";
  676. static constexpr StringRef (*StringFn)(unsigned) = &FormEncodingString;
  677. };
  678. template <> struct EnumTraits<Index> : public std::true_type {
  679. static constexpr char Type[4] = "IDX";
  680. static constexpr StringRef (*StringFn)(unsigned) = &IndexString;
  681. };
  682. template <> struct EnumTraits<Tag> : public std::true_type {
  683. static constexpr char Type[4] = "TAG";
  684. static constexpr StringRef (*StringFn)(unsigned) = &TagString;
  685. };
  686. template <> struct EnumTraits<LineNumberOps> : public std::true_type {
  687. static constexpr char Type[4] = "LNS";
  688. static constexpr StringRef (*StringFn)(unsigned) = &LNStandardString;
  689. };
  690. template <> struct EnumTraits<LocationAtom> : public std::true_type {
  691. static constexpr char Type[3] = "OP";
  692. static constexpr StringRef (*StringFn)(unsigned) = &OperationEncodingString;
  693. };
  694. inline uint64_t computeTombstoneAddress(uint8_t AddressByteSize) {
  695. return std::numeric_limits<uint64_t>::max() >> (8 - AddressByteSize) * 8;
  696. }
  697. } // End of namespace dwarf
  698. /// Dwarf constants format_provider
  699. ///
  700. /// Specialization of the format_provider template for dwarf enums. Unlike the
  701. /// dumping functions above, these format unknown enumerator values as
  702. /// DW_TYPE_unknown_1234 (e.g. DW_TAG_unknown_ffff).
  703. template <typename Enum>
  704. struct format_provider<Enum, std::enable_if_t<dwarf::EnumTraits<Enum>::value>> {
  705. static void format(const Enum &E, raw_ostream &OS, StringRef Style) {
  706. StringRef Str = dwarf::EnumTraits<Enum>::StringFn(E);
  707. if (Str.empty()) {
  708. OS << "DW_" << dwarf::EnumTraits<Enum>::Type << "_unknown_"
  709. << llvm::format("%x", E);
  710. } else
  711. OS << Str;
  712. }
  713. };
  714. } // End of namespace llvm
  715. #endif
  716. #ifdef __GNUC__
  717. #pragma GCC diagnostic pop
  718. #endif