Dwarf.h 23 KB

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