Dwarf.h 26 KB

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