1 //===-- llvm/BinaryFormat/Dwarf.cpp - Dwarf Framework ------------*- C++-*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for generic dwarf information.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/BinaryFormat/Dwarf.h"
15 #include "llvm/ADT/StringSwitch.h"
16 #include "llvm/Support/ErrorHandling.h"
19 using namespace dwarf
;
21 StringRef
llvm::dwarf::TagString(unsigned Tag
) {
25 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) \
27 return "DW_TAG_" #NAME;
28 #include "llvm/BinaryFormat/Dwarf.def"
32 unsigned llvm::dwarf::getTag(StringRef TagString
) {
33 return StringSwitch
<unsigned>(TagString
)
34 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) \
35 .Case("DW_TAG_" #NAME, DW_TAG_##NAME)
36 #include "llvm/BinaryFormat/Dwarf.def"
37 .Default(DW_TAG_invalid
);
40 unsigned llvm::dwarf::TagVersion(dwarf::Tag Tag
) {
44 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) \
47 #include "llvm/BinaryFormat/Dwarf.def"
51 unsigned llvm::dwarf::TagVendor(dwarf::Tag Tag
) {
55 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) \
57 return DWARF_VENDOR_##VENDOR;
58 #include "llvm/BinaryFormat/Dwarf.def"
62 StringRef
llvm::dwarf::ChildrenString(unsigned Children
) {
65 return "DW_CHILDREN_no";
67 return "DW_CHILDREN_yes";
72 StringRef
llvm::dwarf::AttributeString(unsigned Attribute
) {
76 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
78 return "DW_AT_" #NAME;
79 #include "llvm/BinaryFormat/Dwarf.def"
83 unsigned llvm::dwarf::AttributeVersion(dwarf::Attribute Attribute
) {
87 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
90 #include "llvm/BinaryFormat/Dwarf.def"
94 unsigned llvm::dwarf::AttributeVendor(dwarf::Attribute Attribute
) {
98 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
100 return DWARF_VENDOR_##VENDOR;
101 #include "llvm/BinaryFormat/Dwarf.def"
105 StringRef
llvm::dwarf::FormEncodingString(unsigned Encoding
) {
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"
116 unsigned llvm::dwarf::FormVersion(dwarf::Form Form
) {
120 #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \
121 case DW_FORM_##NAME: \
123 #include "llvm/BinaryFormat/Dwarf.def"
127 unsigned llvm::dwarf::FormVendor(dwarf::Form Form
) {
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"
138 StringRef
llvm::dwarf::OperationEncodingString(unsigned Encoding
) {
142 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
144 return "DW_OP_" #NAME;
145 #include "llvm/BinaryFormat/Dwarf.def"
146 case DW_OP_LLVM_fragment
:
147 return "DW_OP_LLVM_fragment";
151 unsigned llvm::dwarf::getOperationEncoding(StringRef OperationEncodingString
) {
152 return StringSwitch
<unsigned>(OperationEncodingString
)
153 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
154 .Case("DW_OP_" #NAME, DW_OP_##NAME)
155 #include "llvm/BinaryFormat/Dwarf.def"
156 .Case("DW_OP_LLVM_fragment", DW_OP_LLVM_fragment
)
160 unsigned llvm::dwarf::OperationVersion(dwarf::LocationAtom Op
) {
164 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
167 #include "llvm/BinaryFormat/Dwarf.def"
171 unsigned llvm::dwarf::OperationVendor(dwarf::LocationAtom Op
) {
175 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
177 return DWARF_VENDOR_##VENDOR;
178 #include "llvm/BinaryFormat/Dwarf.def"
182 StringRef
llvm::dwarf::AttributeEncodingString(unsigned Encoding
) {
186 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
187 case DW_ATE_##NAME: \
188 return "DW_ATE_" #NAME;
189 #include "llvm/BinaryFormat/Dwarf.def"
193 unsigned llvm::dwarf::getAttributeEncoding(StringRef EncodingString
) {
194 return StringSwitch
<unsigned>(EncodingString
)
195 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
196 .Case("DW_ATE_" #NAME, DW_ATE_##NAME)
197 #include "llvm/BinaryFormat/Dwarf.def"
201 unsigned llvm::dwarf::AttributeEncodingVersion(dwarf::TypeKind ATE
) {
205 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
206 case DW_ATE_##NAME: \
208 #include "llvm/BinaryFormat/Dwarf.def"
212 unsigned llvm::dwarf::AttributeEncodingVendor(dwarf::TypeKind ATE
) {
216 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
217 case DW_ATE_##NAME: \
218 return DWARF_VENDOR_##VENDOR;
219 #include "llvm/BinaryFormat/Dwarf.def"
223 StringRef
llvm::dwarf::DecimalSignString(unsigned Sign
) {
226 return "DW_DS_unsigned";
227 case DW_DS_leading_overpunch
:
228 return "DW_DS_leading_overpunch";
229 case DW_DS_trailing_overpunch
:
230 return "DW_DS_trailing_overpunch";
231 case DW_DS_leading_separate
:
232 return "DW_DS_leading_separate";
233 case DW_DS_trailing_separate
:
234 return "DW_DS_trailing_separate";
239 StringRef
llvm::dwarf::EndianityString(unsigned Endian
) {
242 return "DW_END_default";
246 return "DW_END_little";
248 return "DW_END_lo_user";
250 return "DW_END_hi_user";
255 StringRef
llvm::dwarf::AccessibilityString(unsigned Access
) {
257 // Accessibility codes
258 case DW_ACCESS_public
:
259 return "DW_ACCESS_public";
260 case DW_ACCESS_protected
:
261 return "DW_ACCESS_protected";
262 case DW_ACCESS_private
:
263 return "DW_ACCESS_private";
268 StringRef
llvm::dwarf::VisibilityString(unsigned Visibility
) {
269 switch (Visibility
) {
271 return "DW_VIS_local";
272 case DW_VIS_exported
:
273 return "DW_VIS_exported";
274 case DW_VIS_qualified
:
275 return "DW_VIS_qualified";
280 StringRef
llvm::dwarf::VirtualityString(unsigned Virtuality
) {
281 switch (Virtuality
) {
284 #define HANDLE_DW_VIRTUALITY(ID, NAME) \
285 case DW_VIRTUALITY_##NAME: \
286 return "DW_VIRTUALITY_" #NAME;
287 #include "llvm/BinaryFormat/Dwarf.def"
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
);
299 StringRef
llvm::dwarf::LanguageString(unsigned Language
) {
303 #define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \
304 case DW_LANG_##NAME: \
305 return "DW_LANG_" #NAME;
306 #include "llvm/BinaryFormat/Dwarf.def"
310 unsigned llvm::dwarf::getLanguage(StringRef LanguageString
) {
311 return StringSwitch
<unsigned>(LanguageString
)
312 #define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \
313 .Case("DW_LANG_" #NAME, DW_LANG_##NAME)
314 #include "llvm/BinaryFormat/Dwarf.def"
318 unsigned llvm::dwarf::LanguageVersion(dwarf::SourceLanguage Lang
) {
322 #define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \
323 case DW_LANG_##NAME: \
325 #include "llvm/BinaryFormat/Dwarf.def"
329 unsigned llvm::dwarf::LanguageVendor(dwarf::SourceLanguage Lang
) {
333 #define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \
334 case DW_LANG_##NAME: \
335 return DWARF_VENDOR_##VENDOR;
336 #include "llvm/BinaryFormat/Dwarf.def"
340 StringRef
llvm::dwarf::CaseString(unsigned Case
) {
342 case DW_ID_case_sensitive
:
343 return "DW_ID_case_sensitive";
345 return "DW_ID_up_case";
346 case DW_ID_down_case
:
347 return "DW_ID_down_case";
348 case DW_ID_case_insensitive
:
349 return "DW_ID_case_insensitive";
354 StringRef
llvm::dwarf::ConventionString(unsigned CC
) {
358 #define HANDLE_DW_CC(ID, NAME) \
360 return "DW_CC_" #NAME;
361 #include "llvm/BinaryFormat/Dwarf.def"
365 unsigned llvm::dwarf::getCallingConvention(StringRef CCString
) {
366 return StringSwitch
<unsigned>(CCString
)
367 #define HANDLE_DW_CC(ID, NAME) .Case("DW_CC_" #NAME, DW_CC_##NAME)
368 #include "llvm/BinaryFormat/Dwarf.def"
372 StringRef
llvm::dwarf::InlineCodeString(unsigned Code
) {
374 case DW_INL_not_inlined
:
375 return "DW_INL_not_inlined";
377 return "DW_INL_inlined";
378 case DW_INL_declared_not_inlined
:
379 return "DW_INL_declared_not_inlined";
380 case DW_INL_declared_inlined
:
381 return "DW_INL_declared_inlined";
386 StringRef
llvm::dwarf::ArrayOrderString(unsigned Order
) {
388 case DW_ORD_row_major
:
389 return "DW_ORD_row_major";
390 case DW_ORD_col_major
:
391 return "DW_ORD_col_major";
396 StringRef
llvm::dwarf::LNStandardString(unsigned Standard
) {
400 #define HANDLE_DW_LNS(ID, NAME) \
401 case DW_LNS_##NAME: \
402 return "DW_LNS_" #NAME;
403 #include "llvm/BinaryFormat/Dwarf.def"
407 StringRef
llvm::dwarf::LNExtendedString(unsigned Encoding
) {
411 #define HANDLE_DW_LNE(ID, NAME) \
412 case DW_LNE_##NAME: \
413 return "DW_LNE_" #NAME;
414 #include "llvm/BinaryFormat/Dwarf.def"
418 StringRef
llvm::dwarf::MacinfoString(unsigned Encoding
) {
420 // Macinfo Type Encodings
421 case DW_MACINFO_define
:
422 return "DW_MACINFO_define";
423 case DW_MACINFO_undef
:
424 return "DW_MACINFO_undef";
425 case DW_MACINFO_start_file
:
426 return "DW_MACINFO_start_file";
427 case DW_MACINFO_end_file
:
428 return "DW_MACINFO_end_file";
429 case DW_MACINFO_vendor_ext
:
430 return "DW_MACINFO_vendor_ext";
431 case DW_MACINFO_invalid
:
432 return "DW_MACINFO_invalid";
437 unsigned llvm::dwarf::getMacinfo(StringRef MacinfoString
) {
438 return StringSwitch
<unsigned>(MacinfoString
)
439 .Case("DW_MACINFO_define", DW_MACINFO_define
)
440 .Case("DW_MACINFO_undef", DW_MACINFO_undef
)
441 .Case("DW_MACINFO_start_file", DW_MACINFO_start_file
)
442 .Case("DW_MACINFO_end_file", DW_MACINFO_end_file
)
443 .Case("DW_MACINFO_vendor_ext", DW_MACINFO_vendor_ext
)
444 .Default(DW_MACINFO_invalid
);
447 StringRef
llvm::dwarf::RangeListEncodingString(unsigned Encoding
) {
451 #define HANDLE_DW_RLE(ID, NAME) \
452 case DW_RLE_##NAME: \
453 return "DW_RLE_" #NAME;
454 #include "llvm/BinaryFormat/Dwarf.def"
458 StringRef
llvm::dwarf::CallFrameString(unsigned Encoding
) {
462 #define HANDLE_DW_CFA(ID, NAME) \
463 case DW_CFA_##NAME: \
464 return "DW_CFA_" #NAME;
465 #include "llvm/BinaryFormat/Dwarf.def"
469 StringRef
llvm::dwarf::ApplePropertyString(unsigned Prop
) {
473 #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) \
474 case DW_APPLE_PROPERTY_##NAME: \
475 return "DW_APPLE_PROPERTY_" #NAME;
476 #include "llvm/BinaryFormat/Dwarf.def"
480 StringRef
llvm::dwarf::UnitTypeString(unsigned UT
) {
484 #define HANDLE_DW_UT(ID, NAME) \
486 return "DW_UT_" #NAME;
487 #include "llvm/BinaryFormat/Dwarf.def"
491 StringRef
llvm::dwarf::AtomTypeString(unsigned AT
) {
493 case dwarf::DW_ATOM_null
:
494 return "DW_ATOM_null";
495 case dwarf::DW_ATOM_die_offset
:
496 return "DW_ATOM_die_offset";
497 case DW_ATOM_cu_offset
:
498 return "DW_ATOM_cu_offset";
499 case DW_ATOM_die_tag
:
500 return "DW_ATOM_die_tag";
501 case DW_ATOM_type_flags
:
502 case DW_ATOM_type_type_flags
:
503 return "DW_ATOM_type_flags";
504 case DW_ATOM_qual_name_hash
:
505 return "DW_ATOM_qual_name_hash";
510 StringRef
llvm::dwarf::GDBIndexEntryKindString(GDBIndexEntryKind Kind
) {
529 llvm_unreachable("Unknown GDBIndexEntryKind value");
533 llvm::dwarf::GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage
) {
540 llvm_unreachable("Unknown GDBIndexEntryLinkage value");
543 StringRef
llvm::dwarf::AttributeValueString(uint16_t Attr
, unsigned Val
) {
545 case DW_AT_accessibility
:
546 return AccessibilityString(Val
);
547 case DW_AT_virtuality
:
548 return VirtualityString(Val
);
550 return LanguageString(Val
);
552 return AttributeEncodingString(Val
);
553 case DW_AT_decimal_sign
:
554 return DecimalSignString(Val
);
555 case DW_AT_endianity
:
556 return EndianityString(Val
);
557 case DW_AT_visibility
:
558 return VisibilityString(Val
);
559 case DW_AT_identifier_case
:
560 return CaseString(Val
);
561 case DW_AT_calling_convention
:
562 return ConventionString(Val
);
564 return InlineCodeString(Val
);
566 return ArrayOrderString(Val
);
567 case DW_AT_APPLE_runtime_class
:
568 return LanguageString(Val
);
574 StringRef
llvm::dwarf::AtomValueString(uint16_t Atom
, unsigned Val
) {
578 case DW_ATOM_die_tag
:
579 return TagString(Val
);
585 StringRef
llvm::dwarf::IndexString(unsigned Idx
) {
589 #define HANDLE_DW_IDX(ID, NAME) \
590 case DW_IDX_##NAME: \
591 return "DW_IDX_" #NAME;
592 #include "llvm/BinaryFormat/Dwarf.def"
596 Optional
<uint8_t> llvm::dwarf::getFixedFormByteSize(dwarf::Form Form
,
601 return Params
.AddrSize
;
604 case DW_FORM_block
: // ULEB128 length L followed by L bytes.
605 case DW_FORM_block1
: // 1 byte length L followed by L bytes.
606 case DW_FORM_block2
: // 2 byte length L followed by L bytes.
607 case DW_FORM_block4
: // 4 byte length L followed by L bytes.
608 case DW_FORM_string
: // C-string with null terminator.
609 case DW_FORM_sdata
: // SLEB128.
610 case DW_FORM_udata
: // ULEB128.
611 case DW_FORM_ref_udata
: // ULEB128.
612 case DW_FORM_indirect
: // ULEB128.
613 case DW_FORM_exprloc
: // ULEB128 length L followed by L bytes.
614 case DW_FORM_strx
: // ULEB128.
615 case DW_FORM_addrx
: // ULEB128.
616 case DW_FORM_loclistx
: // ULEB128.
617 case DW_FORM_rnglistx
: // ULEB128.
618 case DW_FORM_GNU_addr_index
: // ULEB128.
619 case DW_FORM_GNU_str_index
: // ULEB128.
622 case DW_FORM_ref_addr
:
624 return Params
.getRefAddrByteSize();
645 case DW_FORM_ref_sup4
:
651 case DW_FORM_GNU_ref_alt
:
652 case DW_FORM_GNU_strp_alt
:
653 case DW_FORM_line_strp
:
654 case DW_FORM_sec_offset
:
655 case DW_FORM_strp_sup
:
657 return Params
.getDwarfOffsetByteSize();
662 case DW_FORM_ref_sig8
:
663 case DW_FORM_ref_sup8
:
666 case DW_FORM_flag_present
:
672 case DW_FORM_implicit_const
:
673 // The implicit value is stored in the abbreviation as a SLEB128, and
674 // there no data in debug info.
683 bool llvm::dwarf::isValidFormForVersion(Form F
, unsigned Version
,
685 if (FormVendor(F
) == DWARF_VENDOR_DWARF
) {
686 unsigned FV
= FormVersion(F
);
687 return FV
> 0 && FV
<= Version
;
692 constexpr char llvm::dwarf::EnumTraits
<Attribute
>::Type
[];
693 constexpr char llvm::dwarf::EnumTraits
<Form
>::Type
[];
694 constexpr char llvm::dwarf::EnumTraits
<Index
>::Type
[];
695 constexpr char llvm::dwarf::EnumTraits
<Tag
>::Type
[];