Dwarf.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. //===-- llvm/BinaryFormat/Dwarf.cpp - Dwarf Framework ------------*- C++-*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file contains support for generic dwarf information.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "llvm/BinaryFormat/Dwarf.h"
  13. #include "llvm/ADT/StringSwitch.h"
  14. #include "llvm/ADT/Triple.h"
  15. #include "llvm/Support/ErrorHandling.h"
  16. using namespace llvm;
  17. using namespace dwarf;
  18. StringRef llvm::dwarf::TagString(unsigned Tag) {
  19. switch (Tag) {
  20. default:
  21. return StringRef();
  22. #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \
  23. case DW_TAG_##NAME: \
  24. return "DW_TAG_" #NAME;
  25. #include "llvm/BinaryFormat/Dwarf.def"
  26. }
  27. }
  28. unsigned llvm::dwarf::getTag(StringRef TagString) {
  29. return StringSwitch<unsigned>(TagString)
  30. #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \
  31. .Case("DW_TAG_" #NAME, DW_TAG_##NAME)
  32. #include "llvm/BinaryFormat/Dwarf.def"
  33. .Default(DW_TAG_invalid);
  34. }
  35. unsigned llvm::dwarf::TagVersion(dwarf::Tag Tag) {
  36. switch (Tag) {
  37. default:
  38. return 0;
  39. #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \
  40. case DW_TAG_##NAME: \
  41. return VERSION;
  42. #include "llvm/BinaryFormat/Dwarf.def"
  43. }
  44. }
  45. unsigned llvm::dwarf::TagVendor(dwarf::Tag Tag) {
  46. switch (Tag) {
  47. default:
  48. return 0;
  49. #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR, KIND) \
  50. case DW_TAG_##NAME: \
  51. return DWARF_VENDOR_##VENDOR;
  52. #include "llvm/BinaryFormat/Dwarf.def"
  53. }
  54. }
  55. StringRef llvm::dwarf::ChildrenString(unsigned Children) {
  56. switch (Children) {
  57. case DW_CHILDREN_no:
  58. return "DW_CHILDREN_no";
  59. case DW_CHILDREN_yes:
  60. return "DW_CHILDREN_yes";
  61. }
  62. return StringRef();
  63. }
  64. StringRef llvm::dwarf::AttributeString(unsigned Attribute) {
  65. switch (Attribute) {
  66. default:
  67. return StringRef();
  68. #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
  69. case DW_AT_##NAME: \
  70. return "DW_AT_" #NAME;
  71. #include "llvm/BinaryFormat/Dwarf.def"
  72. }
  73. }
  74. unsigned llvm::dwarf::AttributeVersion(dwarf::Attribute Attribute) {
  75. switch (Attribute) {
  76. default:
  77. return 0;
  78. #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
  79. case DW_AT_##NAME: \
  80. return VERSION;
  81. #include "llvm/BinaryFormat/Dwarf.def"
  82. }
  83. }
  84. unsigned llvm::dwarf::AttributeVendor(dwarf::Attribute Attribute) {
  85. switch (Attribute) {
  86. default:
  87. return 0;
  88. #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
  89. case DW_AT_##NAME: \
  90. return DWARF_VENDOR_##VENDOR;
  91. #include "llvm/BinaryFormat/Dwarf.def"
  92. }
  93. }
  94. StringRef llvm::dwarf::FormEncodingString(unsigned Encoding) {
  95. switch (Encoding) {
  96. default:
  97. return StringRef();
  98. #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \
  99. case DW_FORM_##NAME: \
  100. return "DW_FORM_" #NAME;
  101. #include "llvm/BinaryFormat/Dwarf.def"
  102. }
  103. }
  104. unsigned llvm::dwarf::FormVersion(dwarf::Form Form) {
  105. switch (Form) {
  106. default:
  107. return 0;
  108. #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \
  109. case DW_FORM_##NAME: \
  110. return VERSION;
  111. #include "llvm/BinaryFormat/Dwarf.def"
  112. }
  113. }
  114. unsigned llvm::dwarf::FormVendor(dwarf::Form Form) {
  115. switch (Form) {
  116. default:
  117. return 0;
  118. #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \
  119. case DW_FORM_##NAME: \
  120. return DWARF_VENDOR_##VENDOR;
  121. #include "llvm/BinaryFormat/Dwarf.def"
  122. }
  123. }
  124. StringRef llvm::dwarf::OperationEncodingString(unsigned Encoding) {
  125. switch (Encoding) {
  126. default:
  127. return StringRef();
  128. #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
  129. case DW_OP_##NAME: \
  130. return "DW_OP_" #NAME;
  131. #include "llvm/BinaryFormat/Dwarf.def"
  132. case DW_OP_LLVM_convert:
  133. return "DW_OP_LLVM_convert";
  134. case DW_OP_LLVM_fragment:
  135. return "DW_OP_LLVM_fragment";
  136. case DW_OP_LLVM_tag_offset:
  137. return "DW_OP_LLVM_tag_offset";
  138. case DW_OP_LLVM_entry_value:
  139. return "DW_OP_LLVM_entry_value";
  140. case DW_OP_LLVM_implicit_pointer:
  141. return "DW_OP_LLVM_implicit_pointer";
  142. case DW_OP_LLVM_arg:
  143. return "DW_OP_LLVM_arg";
  144. }
  145. }
  146. unsigned llvm::dwarf::getOperationEncoding(StringRef OperationEncodingString) {
  147. return StringSwitch<unsigned>(OperationEncodingString)
  148. #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
  149. .Case("DW_OP_" #NAME, DW_OP_##NAME)
  150. #include "llvm/BinaryFormat/Dwarf.def"
  151. .Case("DW_OP_LLVM_convert", DW_OP_LLVM_convert)
  152. .Case("DW_OP_LLVM_fragment", DW_OP_LLVM_fragment)
  153. .Case("DW_OP_LLVM_tag_offset", DW_OP_LLVM_tag_offset)
  154. .Case("DW_OP_LLVM_entry_value", DW_OP_LLVM_entry_value)
  155. .Case("DW_OP_LLVM_implicit_pointer", DW_OP_LLVM_implicit_pointer)
  156. .Case("DW_OP_LLVM_arg", DW_OP_LLVM_arg)
  157. .Default(0);
  158. }
  159. unsigned llvm::dwarf::OperationVersion(dwarf::LocationAtom Op) {
  160. switch (Op) {
  161. default:
  162. return 0;
  163. #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
  164. case DW_OP_##NAME: \
  165. return VERSION;
  166. #include "llvm/BinaryFormat/Dwarf.def"
  167. }
  168. }
  169. unsigned llvm::dwarf::OperationVendor(dwarf::LocationAtom Op) {
  170. switch (Op) {
  171. default:
  172. return 0;
  173. #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
  174. case DW_OP_##NAME: \
  175. return DWARF_VENDOR_##VENDOR;
  176. #include "llvm/BinaryFormat/Dwarf.def"
  177. }
  178. }
  179. StringRef llvm::dwarf::AttributeEncodingString(unsigned Encoding) {
  180. switch (Encoding) {
  181. default:
  182. return StringRef();
  183. #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
  184. case DW_ATE_##NAME: \
  185. return "DW_ATE_" #NAME;
  186. #include "llvm/BinaryFormat/Dwarf.def"
  187. }
  188. }
  189. unsigned llvm::dwarf::getAttributeEncoding(StringRef EncodingString) {
  190. return StringSwitch<unsigned>(EncodingString)
  191. #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
  192. .Case("DW_ATE_" #NAME, DW_ATE_##NAME)
  193. #include "llvm/BinaryFormat/Dwarf.def"
  194. .Default(0);
  195. }
  196. unsigned llvm::dwarf::AttributeEncodingVersion(dwarf::TypeKind ATE) {
  197. switch (ATE) {
  198. default:
  199. return 0;
  200. #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
  201. case DW_ATE_##NAME: \
  202. return VERSION;
  203. #include "llvm/BinaryFormat/Dwarf.def"
  204. }
  205. }
  206. unsigned llvm::dwarf::AttributeEncodingVendor(dwarf::TypeKind ATE) {
  207. switch (ATE) {
  208. default:
  209. return 0;
  210. #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
  211. case DW_ATE_##NAME: \
  212. return DWARF_VENDOR_##VENDOR;
  213. #include "llvm/BinaryFormat/Dwarf.def"
  214. }
  215. }
  216. StringRef llvm::dwarf::DecimalSignString(unsigned Sign) {
  217. switch (Sign) {
  218. case DW_DS_unsigned:
  219. return "DW_DS_unsigned";
  220. case DW_DS_leading_overpunch:
  221. return "DW_DS_leading_overpunch";
  222. case DW_DS_trailing_overpunch:
  223. return "DW_DS_trailing_overpunch";
  224. case DW_DS_leading_separate:
  225. return "DW_DS_leading_separate";
  226. case DW_DS_trailing_separate:
  227. return "DW_DS_trailing_separate";
  228. }
  229. return StringRef();
  230. }
  231. StringRef llvm::dwarf::EndianityString(unsigned Endian) {
  232. switch (Endian) {
  233. case DW_END_default:
  234. return "DW_END_default";
  235. case DW_END_big:
  236. return "DW_END_big";
  237. case DW_END_little:
  238. return "DW_END_little";
  239. case DW_END_lo_user:
  240. return "DW_END_lo_user";
  241. case DW_END_hi_user:
  242. return "DW_END_hi_user";
  243. }
  244. return StringRef();
  245. }
  246. StringRef llvm::dwarf::AccessibilityString(unsigned Access) {
  247. switch (Access) {
  248. // Accessibility codes
  249. case DW_ACCESS_public:
  250. return "DW_ACCESS_public";
  251. case DW_ACCESS_protected:
  252. return "DW_ACCESS_protected";
  253. case DW_ACCESS_private:
  254. return "DW_ACCESS_private";
  255. }
  256. return StringRef();
  257. }
  258. StringRef llvm::dwarf::DefaultedMemberString(unsigned DefaultedEncodings) {
  259. switch (DefaultedEncodings) {
  260. // Defaulted Member Encodings codes
  261. case DW_DEFAULTED_no:
  262. return "DW_DEFAULTED_no";
  263. case DW_DEFAULTED_in_class:
  264. return "DW_DEFAULTED_in_class";
  265. case DW_DEFAULTED_out_of_class:
  266. return "DW_DEFAULTED_out_of_class";
  267. }
  268. return StringRef();
  269. }
  270. StringRef llvm::dwarf::VisibilityString(unsigned Visibility) {
  271. switch (Visibility) {
  272. case DW_VIS_local:
  273. return "DW_VIS_local";
  274. case DW_VIS_exported:
  275. return "DW_VIS_exported";
  276. case DW_VIS_qualified:
  277. return "DW_VIS_qualified";
  278. }
  279. return StringRef();
  280. }
  281. StringRef llvm::dwarf::VirtualityString(unsigned Virtuality) {
  282. switch (Virtuality) {
  283. default:
  284. return StringRef();
  285. #define HANDLE_DW_VIRTUALITY(ID, NAME) \
  286. case DW_VIRTUALITY_##NAME: \
  287. return "DW_VIRTUALITY_" #NAME;
  288. #include "llvm/BinaryFormat/Dwarf.def"
  289. }
  290. }
  291. unsigned llvm::dwarf::getVirtuality(StringRef VirtualityString) {
  292. return StringSwitch<unsigned>(VirtualityString)
  293. #define HANDLE_DW_VIRTUALITY(ID, NAME) \
  294. .Case("DW_VIRTUALITY_" #NAME, DW_VIRTUALITY_##NAME)
  295. #include "llvm/BinaryFormat/Dwarf.def"
  296. .Default(DW_VIRTUALITY_invalid);
  297. }
  298. StringRef llvm::dwarf::LanguageString(unsigned Language) {
  299. switch (Language) {
  300. default:
  301. return StringRef();
  302. #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
  303. case DW_LANG_##NAME: \
  304. return "DW_LANG_" #NAME;
  305. #include "llvm/BinaryFormat/Dwarf.def"
  306. }
  307. }
  308. unsigned llvm::dwarf::getLanguage(StringRef LanguageString) {
  309. return StringSwitch<unsigned>(LanguageString)
  310. #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
  311. .Case("DW_LANG_" #NAME, DW_LANG_##NAME)
  312. #include "llvm/BinaryFormat/Dwarf.def"
  313. .Default(0);
  314. }
  315. unsigned llvm::dwarf::LanguageVersion(dwarf::SourceLanguage Lang) {
  316. switch (Lang) {
  317. default:
  318. return 0;
  319. #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
  320. case DW_LANG_##NAME: \
  321. return VERSION;
  322. #include "llvm/BinaryFormat/Dwarf.def"
  323. }
  324. }
  325. unsigned llvm::dwarf::LanguageVendor(dwarf::SourceLanguage Lang) {
  326. switch (Lang) {
  327. default:
  328. return 0;
  329. #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
  330. case DW_LANG_##NAME: \
  331. return DWARF_VENDOR_##VENDOR;
  332. #include "llvm/BinaryFormat/Dwarf.def"
  333. }
  334. }
  335. std::optional<unsigned>
  336. llvm::dwarf::LanguageLowerBound(dwarf::SourceLanguage Lang) {
  337. switch (Lang) {
  338. default:
  339. return std::nullopt;
  340. #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
  341. case DW_LANG_##NAME: \
  342. return LOWER_BOUND;
  343. #include "llvm/BinaryFormat/Dwarf.def"
  344. }
  345. }
  346. StringRef llvm::dwarf::CaseString(unsigned Case) {
  347. switch (Case) {
  348. case DW_ID_case_sensitive:
  349. return "DW_ID_case_sensitive";
  350. case DW_ID_up_case:
  351. return "DW_ID_up_case";
  352. case DW_ID_down_case:
  353. return "DW_ID_down_case";
  354. case DW_ID_case_insensitive:
  355. return "DW_ID_case_insensitive";
  356. }
  357. return StringRef();
  358. }
  359. StringRef llvm::dwarf::ConventionString(unsigned CC) {
  360. switch (CC) {
  361. default:
  362. return StringRef();
  363. #define HANDLE_DW_CC(ID, NAME) \
  364. case DW_CC_##NAME: \
  365. return "DW_CC_" #NAME;
  366. #include "llvm/BinaryFormat/Dwarf.def"
  367. }
  368. }
  369. unsigned llvm::dwarf::getCallingConvention(StringRef CCString) {
  370. return StringSwitch<unsigned>(CCString)
  371. #define HANDLE_DW_CC(ID, NAME) .Case("DW_CC_" #NAME, DW_CC_##NAME)
  372. #include "llvm/BinaryFormat/Dwarf.def"
  373. .Default(0);
  374. }
  375. StringRef llvm::dwarf::InlineCodeString(unsigned Code) {
  376. switch (Code) {
  377. case DW_INL_not_inlined:
  378. return "DW_INL_not_inlined";
  379. case DW_INL_inlined:
  380. return "DW_INL_inlined";
  381. case DW_INL_declared_not_inlined:
  382. return "DW_INL_declared_not_inlined";
  383. case DW_INL_declared_inlined:
  384. return "DW_INL_declared_inlined";
  385. }
  386. return StringRef();
  387. }
  388. StringRef llvm::dwarf::ArrayOrderString(unsigned Order) {
  389. switch (Order) {
  390. case DW_ORD_row_major:
  391. return "DW_ORD_row_major";
  392. case DW_ORD_col_major:
  393. return "DW_ORD_col_major";
  394. }
  395. return StringRef();
  396. }
  397. StringRef llvm::dwarf::LNStandardString(unsigned Standard) {
  398. switch (Standard) {
  399. default:
  400. return StringRef();
  401. #define HANDLE_DW_LNS(ID, NAME) \
  402. case DW_LNS_##NAME: \
  403. return "DW_LNS_" #NAME;
  404. #include "llvm/BinaryFormat/Dwarf.def"
  405. }
  406. }
  407. StringRef llvm::dwarf::LNExtendedString(unsigned Encoding) {
  408. switch (Encoding) {
  409. default:
  410. return StringRef();
  411. #define HANDLE_DW_LNE(ID, NAME) \
  412. case DW_LNE_##NAME: \
  413. return "DW_LNE_" #NAME;
  414. #include "llvm/BinaryFormat/Dwarf.def"
  415. }
  416. }
  417. StringRef llvm::dwarf::MacinfoString(unsigned Encoding) {
  418. switch (Encoding) {
  419. // Macinfo Type Encodings
  420. case DW_MACINFO_define:
  421. return "DW_MACINFO_define";
  422. case DW_MACINFO_undef:
  423. return "DW_MACINFO_undef";
  424. case DW_MACINFO_start_file:
  425. return "DW_MACINFO_start_file";
  426. case DW_MACINFO_end_file:
  427. return "DW_MACINFO_end_file";
  428. case DW_MACINFO_vendor_ext:
  429. return "DW_MACINFO_vendor_ext";
  430. case DW_MACINFO_invalid:
  431. return "DW_MACINFO_invalid";
  432. }
  433. return StringRef();
  434. }
  435. unsigned llvm::dwarf::getMacinfo(StringRef MacinfoString) {
  436. return StringSwitch<unsigned>(MacinfoString)
  437. .Case("DW_MACINFO_define", DW_MACINFO_define)
  438. .Case("DW_MACINFO_undef", DW_MACINFO_undef)
  439. .Case("DW_MACINFO_start_file", DW_MACINFO_start_file)
  440. .Case("DW_MACINFO_end_file", DW_MACINFO_end_file)
  441. .Case("DW_MACINFO_vendor_ext", DW_MACINFO_vendor_ext)
  442. .Default(DW_MACINFO_invalid);
  443. }
  444. StringRef llvm::dwarf::MacroString(unsigned Encoding) {
  445. switch (Encoding) {
  446. default:
  447. return StringRef();
  448. #define HANDLE_DW_MACRO(ID, NAME) \
  449. case DW_MACRO_##NAME: \
  450. return "DW_MACRO_" #NAME;
  451. #include "llvm/BinaryFormat/Dwarf.def"
  452. }
  453. }
  454. StringRef llvm::dwarf::GnuMacroString(unsigned Encoding) {
  455. switch (Encoding) {
  456. default:
  457. return StringRef();
  458. #define HANDLE_DW_MACRO_GNU(ID, NAME) \
  459. case DW_MACRO_GNU_##NAME: \
  460. return "DW_MACRO_GNU_" #NAME;
  461. #include "llvm/BinaryFormat/Dwarf.def"
  462. }
  463. }
  464. unsigned llvm::dwarf::getMacro(StringRef MacroString) {
  465. return StringSwitch<unsigned>(MacroString)
  466. #define HANDLE_DW_MACRO(ID, NAME) .Case("DW_MACRO_" #NAME, ID)
  467. #include "llvm/BinaryFormat/Dwarf.def"
  468. .Default(DW_MACINFO_invalid);
  469. }
  470. StringRef llvm::dwarf::RangeListEncodingString(unsigned Encoding) {
  471. switch (Encoding) {
  472. default:
  473. return StringRef();
  474. #define HANDLE_DW_RLE(ID, NAME) \
  475. case DW_RLE_##NAME: \
  476. return "DW_RLE_" #NAME;
  477. #include "llvm/BinaryFormat/Dwarf.def"
  478. }
  479. }
  480. StringRef llvm::dwarf::LocListEncodingString(unsigned Encoding) {
  481. switch (Encoding) {
  482. default:
  483. return StringRef();
  484. #define HANDLE_DW_LLE(ID, NAME) \
  485. case DW_LLE_##NAME: \
  486. return "DW_LLE_" #NAME;
  487. #include "llvm/BinaryFormat/Dwarf.def"
  488. }
  489. }
  490. StringRef llvm::dwarf::CallFrameString(unsigned Encoding,
  491. Triple::ArchType Arch) {
  492. assert(Arch != llvm::Triple::ArchType::UnknownArch);
  493. #define SELECT_AARCH64 (Arch == llvm::Triple::aarch64_be || Arch == llvm::Triple::aarch64)
  494. #define SELECT_MIPS64 Arch == llvm::Triple::mips64
  495. #define SELECT_SPARC (Arch == llvm::Triple::sparc || Arch == llvm::Triple::sparcv9)
  496. #define SELECT_X86 (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64)
  497. #define HANDLE_DW_CFA(ID, NAME)
  498. #define HANDLE_DW_CFA_PRED(ID, NAME, PRED) \
  499. if (ID == Encoding && PRED) \
  500. return "DW_CFA_" #NAME;
  501. #include "llvm/BinaryFormat/Dwarf.def"
  502. switch (Encoding) {
  503. default:
  504. return StringRef();
  505. #define HANDLE_DW_CFA_PRED(ID, NAME, PRED)
  506. #define HANDLE_DW_CFA(ID, NAME) \
  507. case DW_CFA_##NAME: \
  508. return "DW_CFA_" #NAME;
  509. #include "llvm/BinaryFormat/Dwarf.def"
  510. #undef SELECT_X86
  511. #undef SELECT_SPARC
  512. #undef SELECT_MIPS64
  513. #undef SELECT_AARCH64
  514. }
  515. }
  516. StringRef llvm::dwarf::ApplePropertyString(unsigned Prop) {
  517. switch (Prop) {
  518. default:
  519. return StringRef();
  520. #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) \
  521. case DW_APPLE_PROPERTY_##NAME: \
  522. return "DW_APPLE_PROPERTY_" #NAME;
  523. #include "llvm/BinaryFormat/Dwarf.def"
  524. }
  525. }
  526. StringRef llvm::dwarf::UnitTypeString(unsigned UT) {
  527. switch (UT) {
  528. default:
  529. return StringRef();
  530. #define HANDLE_DW_UT(ID, NAME) \
  531. case DW_UT_##NAME: \
  532. return "DW_UT_" #NAME;
  533. #include "llvm/BinaryFormat/Dwarf.def"
  534. }
  535. }
  536. StringRef llvm::dwarf::AtomTypeString(unsigned AT) {
  537. switch (AT) {
  538. case dwarf::DW_ATOM_null:
  539. return "DW_ATOM_null";
  540. case dwarf::DW_ATOM_die_offset:
  541. return "DW_ATOM_die_offset";
  542. case DW_ATOM_cu_offset:
  543. return "DW_ATOM_cu_offset";
  544. case DW_ATOM_die_tag:
  545. return "DW_ATOM_die_tag";
  546. case DW_ATOM_type_flags:
  547. case DW_ATOM_type_type_flags:
  548. return "DW_ATOM_type_flags";
  549. case DW_ATOM_qual_name_hash:
  550. return "DW_ATOM_qual_name_hash";
  551. }
  552. return StringRef();
  553. }
  554. StringRef llvm::dwarf::GDBIndexEntryKindString(GDBIndexEntryKind Kind) {
  555. switch (Kind) {
  556. case GIEK_NONE:
  557. return "NONE";
  558. case GIEK_TYPE:
  559. return "TYPE";
  560. case GIEK_VARIABLE:
  561. return "VARIABLE";
  562. case GIEK_FUNCTION:
  563. return "FUNCTION";
  564. case GIEK_OTHER:
  565. return "OTHER";
  566. case GIEK_UNUSED5:
  567. return "UNUSED5";
  568. case GIEK_UNUSED6:
  569. return "UNUSED6";
  570. case GIEK_UNUSED7:
  571. return "UNUSED7";
  572. }
  573. llvm_unreachable("Unknown GDBIndexEntryKind value");
  574. }
  575. StringRef
  576. llvm::dwarf::GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage) {
  577. switch (Linkage) {
  578. case GIEL_EXTERNAL:
  579. return "EXTERNAL";
  580. case GIEL_STATIC:
  581. return "STATIC";
  582. }
  583. llvm_unreachable("Unknown GDBIndexEntryLinkage value");
  584. }
  585. StringRef llvm::dwarf::AttributeValueString(uint16_t Attr, unsigned Val) {
  586. switch (Attr) {
  587. case DW_AT_accessibility:
  588. return AccessibilityString(Val);
  589. case DW_AT_virtuality:
  590. return VirtualityString(Val);
  591. case DW_AT_language:
  592. return LanguageString(Val);
  593. case DW_AT_encoding:
  594. return AttributeEncodingString(Val);
  595. case DW_AT_decimal_sign:
  596. return DecimalSignString(Val);
  597. case DW_AT_endianity:
  598. return EndianityString(Val);
  599. case DW_AT_visibility:
  600. return VisibilityString(Val);
  601. case DW_AT_identifier_case:
  602. return CaseString(Val);
  603. case DW_AT_calling_convention:
  604. return ConventionString(Val);
  605. case DW_AT_inline:
  606. return InlineCodeString(Val);
  607. case DW_AT_ordering:
  608. return ArrayOrderString(Val);
  609. case DW_AT_APPLE_runtime_class:
  610. return LanguageString(Val);
  611. case DW_AT_defaulted:
  612. return DefaultedMemberString(Val);
  613. }
  614. return StringRef();
  615. }
  616. StringRef llvm::dwarf::AtomValueString(uint16_t Atom, unsigned Val) {
  617. switch (Atom) {
  618. case DW_ATOM_null:
  619. return "NULL";
  620. case DW_ATOM_die_tag:
  621. return TagString(Val);
  622. }
  623. return StringRef();
  624. }
  625. StringRef llvm::dwarf::IndexString(unsigned Idx) {
  626. switch (Idx) {
  627. default:
  628. return StringRef();
  629. #define HANDLE_DW_IDX(ID, NAME) \
  630. case DW_IDX_##NAME: \
  631. return "DW_IDX_" #NAME;
  632. #include "llvm/BinaryFormat/Dwarf.def"
  633. }
  634. }
  635. std::optional<uint8_t> llvm::dwarf::getFixedFormByteSize(dwarf::Form Form,
  636. FormParams Params) {
  637. switch (Form) {
  638. case DW_FORM_addr:
  639. if (Params)
  640. return Params.AddrSize;
  641. return std::nullopt;
  642. case DW_FORM_block: // ULEB128 length L followed by L bytes.
  643. case DW_FORM_block1: // 1 byte length L followed by L bytes.
  644. case DW_FORM_block2: // 2 byte length L followed by L bytes.
  645. case DW_FORM_block4: // 4 byte length L followed by L bytes.
  646. case DW_FORM_string: // C-string with null terminator.
  647. case DW_FORM_sdata: // SLEB128.
  648. case DW_FORM_udata: // ULEB128.
  649. case DW_FORM_ref_udata: // ULEB128.
  650. case DW_FORM_indirect: // ULEB128.
  651. case DW_FORM_exprloc: // ULEB128 length L followed by L bytes.
  652. case DW_FORM_strx: // ULEB128.
  653. case DW_FORM_addrx: // ULEB128.
  654. case DW_FORM_loclistx: // ULEB128.
  655. case DW_FORM_rnglistx: // ULEB128.
  656. case DW_FORM_GNU_addr_index: // ULEB128.
  657. case DW_FORM_GNU_str_index: // ULEB128.
  658. return std::nullopt;
  659. case DW_FORM_ref_addr:
  660. if (Params)
  661. return Params.getRefAddrByteSize();
  662. return std::nullopt;
  663. case DW_FORM_flag:
  664. case DW_FORM_data1:
  665. case DW_FORM_ref1:
  666. case DW_FORM_strx1:
  667. case DW_FORM_addrx1:
  668. return 1;
  669. case DW_FORM_data2:
  670. case DW_FORM_ref2:
  671. case DW_FORM_strx2:
  672. case DW_FORM_addrx2:
  673. return 2;
  674. case DW_FORM_strx3:
  675. return 3;
  676. case DW_FORM_data4:
  677. case DW_FORM_ref4:
  678. case DW_FORM_ref_sup4:
  679. case DW_FORM_strx4:
  680. case DW_FORM_addrx4:
  681. return 4;
  682. case DW_FORM_strp:
  683. case DW_FORM_GNU_ref_alt:
  684. case DW_FORM_GNU_strp_alt:
  685. case DW_FORM_line_strp:
  686. case DW_FORM_sec_offset:
  687. case DW_FORM_strp_sup:
  688. if (Params)
  689. return Params.getDwarfOffsetByteSize();
  690. return std::nullopt;
  691. case DW_FORM_data8:
  692. case DW_FORM_ref8:
  693. case DW_FORM_ref_sig8:
  694. case DW_FORM_ref_sup8:
  695. return 8;
  696. case DW_FORM_flag_present:
  697. return 0;
  698. case DW_FORM_data16:
  699. return 16;
  700. case DW_FORM_implicit_const:
  701. // The implicit value is stored in the abbreviation as a SLEB128, and
  702. // there no data in debug info.
  703. return 0;
  704. default:
  705. break;
  706. }
  707. return std::nullopt;
  708. }
  709. bool llvm::dwarf::isValidFormForVersion(Form F, unsigned Version,
  710. bool ExtensionsOk) {
  711. if (FormVendor(F) == DWARF_VENDOR_DWARF) {
  712. unsigned FV = FormVersion(F);
  713. return FV > 0 && FV <= Version;
  714. }
  715. return ExtensionsOk;
  716. }
  717. StringRef llvm::dwarf::FormatString(DwarfFormat Format) {
  718. switch (Format) {
  719. case DWARF32:
  720. return "DWARF32";
  721. case DWARF64:
  722. return "DWARF64";
  723. }
  724. return StringRef();
  725. }
  726. StringRef llvm::dwarf::FormatString(bool IsDWARF64) {
  727. return FormatString(IsDWARF64 ? DWARF64 : DWARF32);
  728. }
  729. StringRef llvm::dwarf::RLEString(unsigned RLE) {
  730. switch (RLE) {
  731. default:
  732. return StringRef();
  733. #define HANDLE_DW_RLE(ID, NAME) \
  734. case DW_RLE_##NAME: \
  735. return "DW_RLE_" #NAME;
  736. #include "llvm/BinaryFormat/Dwarf.def"
  737. }
  738. }
  739. constexpr char llvm::dwarf::EnumTraits<Attribute>::Type[];
  740. constexpr char llvm::dwarf::EnumTraits<Form>::Type[];
  741. constexpr char llvm::dwarf::EnumTraits<Index>::Type[];
  742. constexpr char llvm::dwarf::EnumTraits<Tag>::Type[];
  743. constexpr char llvm::dwarf::EnumTraits<LineNumberOps>::Type[];
  744. constexpr char llvm::dwarf::EnumTraits<LocationAtom>::Type[];