Dwarf.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  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. Optional<unsigned> llvm::dwarf::LanguageLowerBound(dwarf::SourceLanguage Lang) {
  336. switch (Lang) {
  337. default:
  338. return None;
  339. #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
  340. case DW_LANG_##NAME: \
  341. return LOWER_BOUND;
  342. #include "llvm/BinaryFormat/Dwarf.def"
  343. }
  344. }
  345. StringRef llvm::dwarf::CaseString(unsigned Case) {
  346. switch (Case) {
  347. case DW_ID_case_sensitive:
  348. return "DW_ID_case_sensitive";
  349. case DW_ID_up_case:
  350. return "DW_ID_up_case";
  351. case DW_ID_down_case:
  352. return "DW_ID_down_case";
  353. case DW_ID_case_insensitive:
  354. return "DW_ID_case_insensitive";
  355. }
  356. return StringRef();
  357. }
  358. StringRef llvm::dwarf::ConventionString(unsigned CC) {
  359. switch (CC) {
  360. default:
  361. return StringRef();
  362. #define HANDLE_DW_CC(ID, NAME) \
  363. case DW_CC_##NAME: \
  364. return "DW_CC_" #NAME;
  365. #include "llvm/BinaryFormat/Dwarf.def"
  366. }
  367. }
  368. unsigned llvm::dwarf::getCallingConvention(StringRef CCString) {
  369. return StringSwitch<unsigned>(CCString)
  370. #define HANDLE_DW_CC(ID, NAME) .Case("DW_CC_" #NAME, DW_CC_##NAME)
  371. #include "llvm/BinaryFormat/Dwarf.def"
  372. .Default(0);
  373. }
  374. StringRef llvm::dwarf::InlineCodeString(unsigned Code) {
  375. switch (Code) {
  376. case DW_INL_not_inlined:
  377. return "DW_INL_not_inlined";
  378. case DW_INL_inlined:
  379. return "DW_INL_inlined";
  380. case DW_INL_declared_not_inlined:
  381. return "DW_INL_declared_not_inlined";
  382. case DW_INL_declared_inlined:
  383. return "DW_INL_declared_inlined";
  384. }
  385. return StringRef();
  386. }
  387. StringRef llvm::dwarf::ArrayOrderString(unsigned Order) {
  388. switch (Order) {
  389. case DW_ORD_row_major:
  390. return "DW_ORD_row_major";
  391. case DW_ORD_col_major:
  392. return "DW_ORD_col_major";
  393. }
  394. return StringRef();
  395. }
  396. StringRef llvm::dwarf::LNStandardString(unsigned Standard) {
  397. switch (Standard) {
  398. default:
  399. return StringRef();
  400. #define HANDLE_DW_LNS(ID, NAME) \
  401. case DW_LNS_##NAME: \
  402. return "DW_LNS_" #NAME;
  403. #include "llvm/BinaryFormat/Dwarf.def"
  404. }
  405. }
  406. StringRef llvm::dwarf::LNExtendedString(unsigned Encoding) {
  407. switch (Encoding) {
  408. default:
  409. return StringRef();
  410. #define HANDLE_DW_LNE(ID, NAME) \
  411. case DW_LNE_##NAME: \
  412. return "DW_LNE_" #NAME;
  413. #include "llvm/BinaryFormat/Dwarf.def"
  414. }
  415. }
  416. StringRef llvm::dwarf::MacinfoString(unsigned Encoding) {
  417. switch (Encoding) {
  418. // Macinfo Type Encodings
  419. case DW_MACINFO_define:
  420. return "DW_MACINFO_define";
  421. case DW_MACINFO_undef:
  422. return "DW_MACINFO_undef";
  423. case DW_MACINFO_start_file:
  424. return "DW_MACINFO_start_file";
  425. case DW_MACINFO_end_file:
  426. return "DW_MACINFO_end_file";
  427. case DW_MACINFO_vendor_ext:
  428. return "DW_MACINFO_vendor_ext";
  429. case DW_MACINFO_invalid:
  430. return "DW_MACINFO_invalid";
  431. }
  432. return StringRef();
  433. }
  434. unsigned llvm::dwarf::getMacinfo(StringRef MacinfoString) {
  435. return StringSwitch<unsigned>(MacinfoString)
  436. .Case("DW_MACINFO_define", DW_MACINFO_define)
  437. .Case("DW_MACINFO_undef", DW_MACINFO_undef)
  438. .Case("DW_MACINFO_start_file", DW_MACINFO_start_file)
  439. .Case("DW_MACINFO_end_file", DW_MACINFO_end_file)
  440. .Case("DW_MACINFO_vendor_ext", DW_MACINFO_vendor_ext)
  441. .Default(DW_MACINFO_invalid);
  442. }
  443. StringRef llvm::dwarf::MacroString(unsigned Encoding) {
  444. switch (Encoding) {
  445. default:
  446. return StringRef();
  447. #define HANDLE_DW_MACRO(ID, NAME) \
  448. case DW_MACRO_##NAME: \
  449. return "DW_MACRO_" #NAME;
  450. #include "llvm/BinaryFormat/Dwarf.def"
  451. }
  452. }
  453. StringRef llvm::dwarf::GnuMacroString(unsigned Encoding) {
  454. switch (Encoding) {
  455. default:
  456. return StringRef();
  457. #define HANDLE_DW_MACRO_GNU(ID, NAME) \
  458. case DW_MACRO_GNU_##NAME: \
  459. return "DW_MACRO_GNU_" #NAME;
  460. #include "llvm/BinaryFormat/Dwarf.def"
  461. }
  462. }
  463. unsigned llvm::dwarf::getMacro(StringRef MacroString) {
  464. return StringSwitch<unsigned>(MacroString)
  465. #define HANDLE_DW_MACRO(ID, NAME) .Case("DW_MACRO_" #NAME, ID)
  466. #include "llvm/BinaryFormat/Dwarf.def"
  467. .Default(DW_MACINFO_invalid);
  468. }
  469. StringRef llvm::dwarf::RangeListEncodingString(unsigned Encoding) {
  470. switch (Encoding) {
  471. default:
  472. return StringRef();
  473. #define HANDLE_DW_RLE(ID, NAME) \
  474. case DW_RLE_##NAME: \
  475. return "DW_RLE_" #NAME;
  476. #include "llvm/BinaryFormat/Dwarf.def"
  477. }
  478. }
  479. StringRef llvm::dwarf::LocListEncodingString(unsigned Encoding) {
  480. switch (Encoding) {
  481. default:
  482. return StringRef();
  483. #define HANDLE_DW_LLE(ID, NAME) \
  484. case DW_LLE_##NAME: \
  485. return "DW_LLE_" #NAME;
  486. #include "llvm/BinaryFormat/Dwarf.def"
  487. }
  488. }
  489. StringRef llvm::dwarf::CallFrameString(unsigned Encoding,
  490. Triple::ArchType Arch) {
  491. assert(Arch != llvm::Triple::ArchType::UnknownArch);
  492. #define SELECT_AARCH64 (Arch == llvm::Triple::aarch64_be || Arch == llvm::Triple::aarch64)
  493. #define SELECT_MIPS64 Arch == llvm::Triple::mips64
  494. #define SELECT_SPARC (Arch == llvm::Triple::sparc || Arch == llvm::Triple::sparcv9)
  495. #define SELECT_X86 (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64)
  496. #define HANDLE_DW_CFA(ID, NAME)
  497. #define HANDLE_DW_CFA_PRED(ID, NAME, PRED) \
  498. if (ID == Encoding && PRED) \
  499. return "DW_CFA_" #NAME;
  500. #include "llvm/BinaryFormat/Dwarf.def"
  501. switch (Encoding) {
  502. default:
  503. return StringRef();
  504. #define HANDLE_DW_CFA_PRED(ID, NAME, PRED)
  505. #define HANDLE_DW_CFA(ID, NAME) \
  506. case DW_CFA_##NAME: \
  507. return "DW_CFA_" #NAME;
  508. #include "llvm/BinaryFormat/Dwarf.def"
  509. #undef SELECT_X86
  510. #undef SELECT_SPARC
  511. #undef SELECT_MIPS64
  512. #undef SELECT_AARCH64
  513. }
  514. }
  515. StringRef llvm::dwarf::ApplePropertyString(unsigned Prop) {
  516. switch (Prop) {
  517. default:
  518. return StringRef();
  519. #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) \
  520. case DW_APPLE_PROPERTY_##NAME: \
  521. return "DW_APPLE_PROPERTY_" #NAME;
  522. #include "llvm/BinaryFormat/Dwarf.def"
  523. }
  524. }
  525. StringRef llvm::dwarf::UnitTypeString(unsigned UT) {
  526. switch (UT) {
  527. default:
  528. return StringRef();
  529. #define HANDLE_DW_UT(ID, NAME) \
  530. case DW_UT_##NAME: \
  531. return "DW_UT_" #NAME;
  532. #include "llvm/BinaryFormat/Dwarf.def"
  533. }
  534. }
  535. StringRef llvm::dwarf::AtomTypeString(unsigned AT) {
  536. switch (AT) {
  537. case dwarf::DW_ATOM_null:
  538. return "DW_ATOM_null";
  539. case dwarf::DW_ATOM_die_offset:
  540. return "DW_ATOM_die_offset";
  541. case DW_ATOM_cu_offset:
  542. return "DW_ATOM_cu_offset";
  543. case DW_ATOM_die_tag:
  544. return "DW_ATOM_die_tag";
  545. case DW_ATOM_type_flags:
  546. case DW_ATOM_type_type_flags:
  547. return "DW_ATOM_type_flags";
  548. case DW_ATOM_qual_name_hash:
  549. return "DW_ATOM_qual_name_hash";
  550. }
  551. return StringRef();
  552. }
  553. StringRef llvm::dwarf::GDBIndexEntryKindString(GDBIndexEntryKind Kind) {
  554. switch (Kind) {
  555. case GIEK_NONE:
  556. return "NONE";
  557. case GIEK_TYPE:
  558. return "TYPE";
  559. case GIEK_VARIABLE:
  560. return "VARIABLE";
  561. case GIEK_FUNCTION:
  562. return "FUNCTION";
  563. case GIEK_OTHER:
  564. return "OTHER";
  565. case GIEK_UNUSED5:
  566. return "UNUSED5";
  567. case GIEK_UNUSED6:
  568. return "UNUSED6";
  569. case GIEK_UNUSED7:
  570. return "UNUSED7";
  571. }
  572. llvm_unreachable("Unknown GDBIndexEntryKind value");
  573. }
  574. StringRef
  575. llvm::dwarf::GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage) {
  576. switch (Linkage) {
  577. case GIEL_EXTERNAL:
  578. return "EXTERNAL";
  579. case GIEL_STATIC:
  580. return "STATIC";
  581. }
  582. llvm_unreachable("Unknown GDBIndexEntryLinkage value");
  583. }
  584. StringRef llvm::dwarf::AttributeValueString(uint16_t Attr, unsigned Val) {
  585. switch (Attr) {
  586. case DW_AT_accessibility:
  587. return AccessibilityString(Val);
  588. case DW_AT_virtuality:
  589. return VirtualityString(Val);
  590. case DW_AT_language:
  591. return LanguageString(Val);
  592. case DW_AT_encoding:
  593. return AttributeEncodingString(Val);
  594. case DW_AT_decimal_sign:
  595. return DecimalSignString(Val);
  596. case DW_AT_endianity:
  597. return EndianityString(Val);
  598. case DW_AT_visibility:
  599. return VisibilityString(Val);
  600. case DW_AT_identifier_case:
  601. return CaseString(Val);
  602. case DW_AT_calling_convention:
  603. return ConventionString(Val);
  604. case DW_AT_inline:
  605. return InlineCodeString(Val);
  606. case DW_AT_ordering:
  607. return ArrayOrderString(Val);
  608. case DW_AT_APPLE_runtime_class:
  609. return LanguageString(Val);
  610. case DW_AT_defaulted:
  611. return DefaultedMemberString(Val);
  612. }
  613. return StringRef();
  614. }
  615. StringRef llvm::dwarf::AtomValueString(uint16_t Atom, unsigned Val) {
  616. switch (Atom) {
  617. case DW_ATOM_null:
  618. return "NULL";
  619. case DW_ATOM_die_tag:
  620. return TagString(Val);
  621. }
  622. return StringRef();
  623. }
  624. StringRef llvm::dwarf::IndexString(unsigned Idx) {
  625. switch (Idx) {
  626. default:
  627. return StringRef();
  628. #define HANDLE_DW_IDX(ID, NAME) \
  629. case DW_IDX_##NAME: \
  630. return "DW_IDX_" #NAME;
  631. #include "llvm/BinaryFormat/Dwarf.def"
  632. }
  633. }
  634. Optional<uint8_t> llvm::dwarf::getFixedFormByteSize(dwarf::Form Form,
  635. FormParams Params) {
  636. switch (Form) {
  637. case DW_FORM_addr:
  638. if (Params)
  639. return Params.AddrSize;
  640. return None;
  641. case DW_FORM_block: // ULEB128 length L followed by L bytes.
  642. case DW_FORM_block1: // 1 byte length L followed by L bytes.
  643. case DW_FORM_block2: // 2 byte length L followed by L bytes.
  644. case DW_FORM_block4: // 4 byte length L followed by L bytes.
  645. case DW_FORM_string: // C-string with null terminator.
  646. case DW_FORM_sdata: // SLEB128.
  647. case DW_FORM_udata: // ULEB128.
  648. case DW_FORM_ref_udata: // ULEB128.
  649. case DW_FORM_indirect: // ULEB128.
  650. case DW_FORM_exprloc: // ULEB128 length L followed by L bytes.
  651. case DW_FORM_strx: // ULEB128.
  652. case DW_FORM_addrx: // ULEB128.
  653. case DW_FORM_loclistx: // ULEB128.
  654. case DW_FORM_rnglistx: // ULEB128.
  655. case DW_FORM_GNU_addr_index: // ULEB128.
  656. case DW_FORM_GNU_str_index: // ULEB128.
  657. return None;
  658. case DW_FORM_ref_addr:
  659. if (Params)
  660. return Params.getRefAddrByteSize();
  661. return None;
  662. case DW_FORM_flag:
  663. case DW_FORM_data1:
  664. case DW_FORM_ref1:
  665. case DW_FORM_strx1:
  666. case DW_FORM_addrx1:
  667. return 1;
  668. case DW_FORM_data2:
  669. case DW_FORM_ref2:
  670. case DW_FORM_strx2:
  671. case DW_FORM_addrx2:
  672. return 2;
  673. case DW_FORM_strx3:
  674. return 3;
  675. case DW_FORM_data4:
  676. case DW_FORM_ref4:
  677. case DW_FORM_ref_sup4:
  678. case DW_FORM_strx4:
  679. case DW_FORM_addrx4:
  680. return 4;
  681. case DW_FORM_strp:
  682. case DW_FORM_GNU_ref_alt:
  683. case DW_FORM_GNU_strp_alt:
  684. case DW_FORM_line_strp:
  685. case DW_FORM_sec_offset:
  686. case DW_FORM_strp_sup:
  687. if (Params)
  688. return Params.getDwarfOffsetByteSize();
  689. return None;
  690. case DW_FORM_data8:
  691. case DW_FORM_ref8:
  692. case DW_FORM_ref_sig8:
  693. case DW_FORM_ref_sup8:
  694. return 8;
  695. case DW_FORM_flag_present:
  696. return 0;
  697. case DW_FORM_data16:
  698. return 16;
  699. case DW_FORM_implicit_const:
  700. // The implicit value is stored in the abbreviation as a SLEB128, and
  701. // there no data in debug info.
  702. return 0;
  703. default:
  704. break;
  705. }
  706. return None;
  707. }
  708. bool llvm::dwarf::isValidFormForVersion(Form F, unsigned Version,
  709. bool ExtensionsOk) {
  710. if (FormVendor(F) == DWARF_VENDOR_DWARF) {
  711. unsigned FV = FormVersion(F);
  712. return FV > 0 && FV <= Version;
  713. }
  714. return ExtensionsOk;
  715. }
  716. StringRef llvm::dwarf::FormatString(DwarfFormat Format) {
  717. switch (Format) {
  718. case DWARF32:
  719. return "DWARF32";
  720. case DWARF64:
  721. return "DWARF64";
  722. }
  723. return StringRef();
  724. }
  725. StringRef llvm::dwarf::FormatString(bool IsDWARF64) {
  726. return FormatString(IsDWARF64 ? DWARF64 : DWARF32);
  727. }
  728. StringRef llvm::dwarf::RLEString(unsigned RLE) {
  729. switch (RLE) {
  730. default:
  731. return StringRef();
  732. #define HANDLE_DW_RLE(ID, NAME) \
  733. case DW_RLE_##NAME: \
  734. return "DW_RLE_" #NAME;
  735. #include "llvm/BinaryFormat/Dwarf.def"
  736. }
  737. }
  738. constexpr char llvm::dwarf::EnumTraits<Attribute>::Type[];
  739. constexpr char llvm::dwarf::EnumTraits<Form>::Type[];
  740. constexpr char llvm::dwarf::EnumTraits<Index>::Type[];
  741. constexpr char llvm::dwarf::EnumTraits<Tag>::Type[];
  742. constexpr char llvm::dwarf::EnumTraits<LineNumberOps>::Type[];
  743. constexpr char llvm::dwarf::EnumTraits<LocationAtom>::Type[];