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