Index: include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h +++ include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h @@ -12,6 +12,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/Support/DataExtractor.h" +#include "llvm/Support/Dwarf.h" namespace llvm { @@ -20,16 +21,16 @@ class DWARFAbbreviationDeclaration { public: struct AttributeSpec { - AttributeSpec(uint16_t Attr, uint16_t Form) : Attr(Attr), Form(Form) {} - uint16_t Attr; - uint16_t Form; + AttributeSpec(dwarf::Attribute A, dwarf::Form F) : Attr(A), Form(F) {} + dwarf::Attribute Attr; + dwarf::Form Form; }; typedef SmallVector AttributeSpecVector; DWARFAbbreviationDeclaration(); uint32_t getCode() const { return Code; } - uint32_t getTag() const { return Tag; } + dwarf::Tag getTag() const { return Tag; } bool hasChildren() const { return HasChildren; } typedef iterator_range @@ -39,11 +40,13 @@ return attr_iterator_range(AttributeSpecs.begin(), AttributeSpecs.end()); } - uint16_t getFormByIndex(uint32_t idx) const { - return idx < AttributeSpecs.size() ? AttributeSpecs[idx].Form : 0; + dwarf::Form getFormByIndex(uint32_t idx) const { + if (idx < AttributeSpecs.size()) + return AttributeSpecs[idx].Form; + return dwarf::Form(0); } - uint32_t findAttributeIndex(uint16_t attr) const; + uint32_t findAttributeIndex(dwarf::Attribute attr) const; bool extract(DataExtractor Data, uint32_t* OffsetPtr); void dump(raw_ostream &OS) const; @@ -51,7 +54,7 @@ void clear(); uint32_t Code; - uint32_t Tag; + dwarf::Tag Tag; bool HasChildren; AttributeSpecVector AttributeSpecs; Index: include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h +++ include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h @@ -13,6 +13,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h" +#include "llvm/Support/Dwarf.h" #include namespace llvm { @@ -30,7 +31,7 @@ struct HeaderData { typedef uint16_t AtomType; - typedef uint16_t Form; + typedef dwarf::Form Form; uint32_t DIEOffsetBase; SmallVector, 3> Atoms; }; Index: include/llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h +++ include/llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h @@ -41,7 +41,8 @@ void dump(raw_ostream &OS, DWARFUnit *u, unsigned recurseDepth, unsigned indent = 0) const; void dumpAttribute(raw_ostream &OS, DWARFUnit *u, uint32_t *offset_ptr, - uint16_t attr, uint16_t form, unsigned indent = 0) const; + dwarf::Attribute attr, dwarf::Form form, + unsigned indent = 0) const; /// Extracts a debug info entry, which is a child of a given unit, /// starting at a given offset. If DIE can't be extracted, returns false and @@ -86,24 +87,27 @@ return AbbrevDecl; } - bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr, + bool getAttributeValue(const DWARFUnit *U, dwarf::Attribute Attr, DWARFFormValue &FormValue) const; - const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr, + const char *getAttributeValueAsString(const DWARFUnit *U, + dwarf::Attribute Attr, const char *FailValue) const; - uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr, + uint64_t getAttributeValueAsAddress(const DWARFUnit *U, + dwarf::Attribute Attr, uint64_t FailValue) const; uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U, - const uint16_t Attr, + dwarf::Attribute Attr, uint64_t FailValue) const; - uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr, + uint64_t getAttributeValueAsReference(const DWARFUnit *U, + dwarf::Attribute Attr, uint64_t FailValue) const; uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U, - const uint16_t Attr, + dwarf::Attribute Attr, uint64_t FailValue) const; uint64_t getRangesBaseAttribute(const DWARFUnit *U, uint64_t FailValue) const; Index: include/llvm/DebugInfo/DWARF/DWARFFormValue.h =================================================================== --- include/llvm/DebugInfo/DWARF/DWARFFormValue.h +++ include/llvm/DebugInfo/DWARF/DWARFFormValue.h @@ -12,6 +12,7 @@ #include "llvm/ADT/Optional.h" #include "llvm/Support/DataExtractor.h" +#include "llvm/Support/Dwarf.h" namespace llvm { @@ -48,12 +49,12 @@ const uint8_t* data; }; - uint16_t Form; // Form for this value. + dwarf::Form Form; // Form for this value. ValueType Value; // Contains all data for the form. public: - DWARFFormValue(uint16_t Form = 0) : Form(Form) {} - uint16_t getForm() const { return Form; } + DWARFFormValue(dwarf::Form F = dwarf::Form(0)) : Form(F) {} + dwarf::Form getForm() const { return Form; } bool isFormClass(FormClass FC) const; void dump(raw_ostream &OS, const DWARFUnit *U) const; @@ -82,9 +83,9 @@ bool skipValue(DataExtractor debug_info_data, uint32_t *offset_ptr, const DWARFUnit *u) const; - static bool skipValue(uint16_t form, DataExtractor debug_info_data, + static bool skipValue(dwarf::Form form, DataExtractor debug_info_data, uint32_t *offset_ptr, const DWARFUnit *u); - static bool skipValue(uint16_t form, DataExtractor debug_info_data, + static bool skipValue(dwarf::Form form, DataExtractor debug_info_data, uint32_t *offset_ptr, uint16_t Version, uint8_t AddrSize); Index: include/llvm/Support/Dwarf.h =================================================================== --- include/llvm/Support/Dwarf.h +++ include/llvm/Support/Dwarf.h @@ -312,7 +312,8 @@ DW_FORM_exprloc = 0x18, DW_FORM_flag_present = 0x19, DW_FORM_ref_sig8 = 0x20, - + + DW_FORM_lo_user = 0x1f00, // Extensions for Fission proposal DW_FORM_GNU_addr_index = 0x1f01, DW_FORM_GNU_str_index = 0x1f02, Index: include/llvm/Support/Dwarf.def =================================================================== --- include/llvm/Support/Dwarf.def +++ include/llvm/Support/Dwarf.def @@ -42,7 +42,7 @@ #define HANDLE_DW_CC(ID, NAME) #endif - +HANDLE_DW_TAG(0x0000, null) HANDLE_DW_TAG(0x0001, array_type) HANDLE_DW_TAG(0x0002, class_type) HANDLE_DW_TAG(0x0003, entry_point) Index: lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp +++ lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp @@ -16,7 +16,7 @@ void DWARFAbbreviationDeclaration::clear() { Code = 0; - Tag = 0; + Tag = DW_TAG_null; HasChildren = false; AttributeSpecs.clear(); } @@ -26,38 +26,39 @@ } bool -DWARFAbbreviationDeclaration::extract(DataExtractor Data, uint32_t* OffsetPtr) { +DWARFAbbreviationDeclaration::extract(DataExtractor Data, + uint32_t* OffsetPtr) { clear(); Code = Data.getULEB128(OffsetPtr); if (Code == 0) { return false; } - Tag = Data.getULEB128(OffsetPtr); + Tag = static_cast(Data.getULEB128(OffsetPtr)); + if (Tag == DW_TAG_null) { + clear(); + return false; + } uint8_t ChildrenByte = Data.getU8(OffsetPtr); HasChildren = (ChildrenByte == DW_CHILDREN_yes); while (true) { - uint32_t CurOffset = *OffsetPtr; - uint16_t Attr = Data.getULEB128(OffsetPtr); - if (CurOffset == *OffsetPtr) { + auto A = static_cast(Data.getULEB128(OffsetPtr)); + auto F = static_cast
(Data.getULEB128(OffsetPtr)); + if (A && F) { + AttributeSpecs.push_back(AttributeSpec(A, F)); + } else if (A == 0 && F == 0) { + // We successfully reached the end of this abbreviation declaration + // since both attribute and form are zero. + break; + } else { + // Attribute and form pairs must either both be non-zero, in which case + // they are added to the abbreviation declaration, or both be zero to + // terminate the abbrevation declaration. In this case only one was + // zero which is an error. clear(); return false; } - CurOffset = *OffsetPtr; - uint16_t Form = Data.getULEB128(OffsetPtr); - if (CurOffset == *OffsetPtr) { - clear(); - return false; - } - if (Attr == 0 && Form == 0) - break; - AttributeSpecs.push_back(AttributeSpec(Attr, Form)); } - - if (Tag == 0) { - clear(); - return false; - } return true; } @@ -88,7 +89,7 @@ } uint32_t -DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const { +DWARFAbbreviationDeclaration::findAttributeIndex(dwarf::Attribute attr) const { for (uint32_t i = 0, e = AttributeSpecs.size(); i != e; ++i) { if (AttributeSpecs[i].Attr == attr) return i; Index: lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp +++ lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp @@ -39,7 +39,7 @@ for (unsigned i = 0; i < NumAtoms; ++i) { uint16_t AtomType = AccelSection.getU16(&Offset); - uint16_t AtomForm = AccelSection.getU16(&Offset); + auto AtomForm = static_cast(AccelSection.getU16(&Offset)); HdrData.Atoms.push_back(std::make_pair(AtomType, AtomForm)); } Index: lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp +++ lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp @@ -112,7 +112,8 @@ void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS, DWARFUnit *u, uint32_t *offset_ptr, - uint16_t attr, uint16_t form, + dwarf::Attribute attr, + dwarf::Form form, unsigned indent) const { const char BaseIndent[] = " "; OS << BaseIndent; @@ -207,7 +208,7 @@ // Skip all data in the .debug_info for the attributes for (const auto &AttrSpec : AbbrevDecl->attributes()) { - uint16_t Form = AttrSpec.Form; + auto Form = AttrSpec.Form; uint8_t FixedFormSize = (Form < FixedFormSizes.size()) ? FixedFormSizes[Form] : 0; @@ -232,8 +233,8 @@ Tag == DW_TAG_inlined_subroutine; } -bool DWARFDebugInfoEntryMinimal::getAttributeValue( - const DWARFUnit *U, const uint16_t Attr, DWARFFormValue &FormValue) const { +bool DWARFDebugInfoEntryMinimal::getAttributeValue(const DWARFUnit *U, + dwarf::Attribute Attr, DWARFFormValue &FormValue) const { if (!AbbrevDecl) return false; @@ -258,7 +259,8 @@ } const char *DWARFDebugInfoEntryMinimal::getAttributeValueAsString( - const DWARFUnit *U, const uint16_t Attr, const char *FailValue) const { + const DWARFUnit *U, dwarf::Attribute Attr, + const char *FailValue) const { DWARFFormValue FormValue; if (!getAttributeValue(U, Attr, FormValue)) return FailValue; @@ -267,7 +269,8 @@ } uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsAddress( - const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const { + const DWARFUnit *U, dwarf::Attribute Attr, + uint64_t FailValue) const { DWARFFormValue FormValue; if (!getAttributeValue(U, Attr, FormValue)) return FailValue; @@ -276,7 +279,8 @@ } uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsUnsignedConstant( - const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const { + const DWARFUnit *U, dwarf::Attribute Attr, + uint64_t FailValue) const { DWARFFormValue FormValue; if (!getAttributeValue(U, Attr, FormValue)) return FailValue; @@ -285,7 +289,8 @@ } uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsReference( - const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const { + const DWARFUnit *U, dwarf::Attribute Attr, + uint64_t FailValue) const { DWARFFormValue FormValue; if (!getAttributeValue(U, Attr, FormValue)) return FailValue; @@ -294,7 +299,8 @@ } uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsSectionOffset( - const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const { + const DWARFUnit *U, dwarf::Attribute Attr, + uint64_t FailValue) const { DWARFFormValue FormValue; if (!getAttributeValue(U, Attr, FormValue)) return FailValue; Index: lib/DebugInfo/DWARF/DWARFFormValue.cpp =================================================================== --- lib/DebugInfo/DWARF/DWARFFormValue.cpp +++ lib/DebugInfo/DWARF/DWARFFormValue.cpp @@ -123,6 +123,8 @@ case DW_FORM_GNU_str_index: case DW_FORM_GNU_strp_alt: return (FC == FC_String); + default: + break; } // In DWARF3 DW_FORM_data4 and DW_FORM_data8 served also as a section offset. // Don't check for DWARF version here, as some producers may still do this @@ -208,7 +210,7 @@ Value.cstr = data.getCStr(offset_ptr); break; case DW_FORM_indirect: - Form = data.getULEB128(offset_ptr); + Form = static_cast(data.getULEB128(offset_ptr)); indirect = true; break; case DW_FORM_sec_offset: @@ -259,14 +261,15 @@ } bool -DWARFFormValue::skipValue(uint16_t form, DataExtractor debug_info_data, +DWARFFormValue::skipValue(dwarf::Form form, DataExtractor debug_info_data, uint32_t *offset_ptr, const DWARFUnit *cu) { return skipValue(form, debug_info_data, offset_ptr, cu->getVersion(), cu->getAddressByteSize()); } -bool DWARFFormValue::skipValue(uint16_t form, DataExtractor debug_info_data, - uint32_t *offset_ptr, uint16_t Version, - uint8_t AddrSize) { +bool +DWARFFormValue::skipValue(dwarf::Form form, DataExtractor debug_info_data, + uint32_t *offset_ptr, uint16_t Version, + uint8_t AddrSize) { bool indirect = false; do { switch (form) { @@ -349,7 +352,7 @@ case DW_FORM_indirect: indirect = true; - form = debug_info_data.getULEB128(offset_ptr); + form = static_cast(debug_info_data.getULEB128(offset_ptr)); break; // FIXME: 4 for DWARF32, 8 for DWARF64. Index: tools/llvm-dwp/llvm-dwp.cpp =================================================================== --- tools/llvm-dwp/llvm-dwp.cpp +++ tools/llvm-dwp/llvm-dwp.cpp @@ -112,8 +112,8 @@ }; static Expected -getIndexedString(uint32_t Form, DataExtractor InfoData, uint32_t &InfoOffset, - StringRef StrOffsets, StringRef Str) { +getIndexedString(dwarf::Form Form, DataExtractor InfoData, + uint32_t &InfoOffset, StringRef StrOffsets, StringRef Str) { if (Form == dwarf::DW_FORM_string) return InfoData.getCStr(&InfoOffset); if (Form != dwarf::DW_FORM_GNU_str_index) @@ -142,16 +142,16 @@ DataExtractor AbbrevData(Abbrev, true, 0); uint32_t AbbrevOffset = getCUAbbrev(Abbrev, AbbrCode); - uint64_t Tag = AbbrevData.getULEB128(&AbbrevOffset); + auto Tag = static_cast(AbbrevData.getULEB128(&AbbrevOffset)); if (Tag != dwarf::DW_TAG_compile_unit) return make_error("top level DIE is not a compile unit"); // DW_CHILDREN AbbrevData.getU8(&AbbrevOffset); uint32_t Name; - uint32_t Form; + dwarf::Form Form; CompileUnitIdentifiers ID; while ((Name = AbbrevData.getULEB128(&AbbrevOffset)) | - (Form = AbbrevData.getULEB128(&AbbrevOffset)) && + (Form = static_cast(AbbrevData.getULEB128(&AbbrevOffset))) && (Name != 0 || Form != 0)) { switch (Name) { case dwarf::DW_AT_name: { Index: unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp =================================================================== --- unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp +++ unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp @@ -33,7 +33,7 @@ EXPECT_EQ(0U, DWARFFormValue::getFixedFormSizes(16, 2).size()); } -bool isFormClass(uint16_t Form, DWARFFormValue::FormClass FC) { +bool isFormClass(dwarf::Form Form, DWARFFormValue::FormClass FC) { return DWARFFormValue(Form).isFormClass(FC); } @@ -52,7 +52,7 @@ } template -DWARFFormValue createDataXFormValue(uint16_t Form, RawTypeT Value) { +DWARFFormValue createDataXFormValue(dwarf::Form Form, RawTypeT Value) { char Raw[sizeof(RawTypeT)]; memcpy(Raw, &Value, sizeof(RawTypeT)); uint32_t Offset = 0;