Index: llvm/trunk/include/llvm/BinaryFormat/Dwarf.h =================================================================== --- llvm/trunk/include/llvm/BinaryFormat/Dwarf.h +++ llvm/trunk/include/llvm/BinaryFormat/Dwarf.h @@ -20,8 +20,10 @@ #ifndef LLVM_BINARYFORMAT_DWARF_H #define LLVM_BINARYFORMAT_DWARF_H +#include "llvm/ADT/Optional.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/DataTypes.h" +#include "llvm/Support/ErrorHandling.h" namespace llvm { class StringRef; @@ -57,6 +59,9 @@ DWARF_VENDOR_MIPS = 6 }; +/// Constants that define the DWARF format as 32 or 64 bit. +enum DwarfFormat : uint8_t { DWARF32, DWARF64 }; + /// Special ID values that distinguish a CIE from a FDE in DWARF CFI. /// Not inside an enum because a 64-bit value is needed. /// @{ @@ -482,6 +487,49 @@ unsigned LanguageVendor(SourceLanguage L); /// @} +/// A helper struct providing information about the byte size of DW_FORM +/// values that vary in size depending on the DWARF version, address byte +/// size, or DWARF32/DWARF64. +struct FormParams { + uint16_t Version; + uint8_t AddrSize; + DwarfFormat Format; + + /// The definition of the size of form DW_FORM_ref_addr depends on the + /// version. In DWARF v2 it's the size of an address; after that, it's the + /// size of a reference. + uint8_t getRefAddrByteSize() const { + if (Version == 2) + return AddrSize; + return getDwarfOffsetByteSize(); + } + + /// The size of a reference is determined by the DWARF 32/64-bit format. + uint8_t getDwarfOffsetByteSize() const { + switch (Format) { + case DwarfFormat::DWARF32: + return 4; + case DwarfFormat::DWARF64: + return 8; + } + llvm_unreachable("Invalid Format value"); + } + + explicit operator bool() const { return Version && AddrSize; } +}; + +/// Get the fixed byte size for a given form. +/// +/// If the form has a fixed byte size, then an Optional with a value will be +/// returned. If the form is always encoded using a variable length storage +/// format (ULEB or SLEB numbers or blocks) then None will be returned. +/// +/// \param Form DWARF form to get the fixed byte size for. +/// \param Params DWARF parameters to help interpret forms. +/// \returns Optional value with the fixed byte size or None if +/// \p Form doesn't have a fixed byte size. +Optional getFixedFormByteSize(dwarf::Form Form, FormParams Params); + /// Tells whether the specified form is defined in the specified version, /// or is an extension if extensions are allowed. bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk = true); @@ -525,9 +573,6 @@ }; }; -/// Constants that define the DWARF format as 32 or 64 bit. -enum DwarfFormat : uint8_t { DWARF32, DWARF64 }; - } // End of namespace dwarf } // End of namespace llvm Index: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h +++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h @@ -67,7 +67,7 @@ /// Version, address size (starting in v5), and DWARF32/64 format; these /// parameters affect interpretation of forms (used in the directory and /// file tables starting with v5). - DWARFFormParams FormParams; + dwarf::FormParams FormParams; /// The number of bytes following the prologue_length field to the beginning /// of the first byte of the statement program itself. uint64_t PrologueLength; @@ -94,7 +94,7 @@ std::vector IncludeDirectories; std::vector FileNames; - const DWARFFormParams getFormParams() const { return FormParams; } + const dwarf::FormParams getFormParams() const { return FormParams; } uint16_t getVersion() const { return FormParams.Version; } uint8_t getAddressSize() const { return FormParams.AddrSize; } bool isDWARF64() const { return FormParams.Format == dwarf::DWARF64; } Index: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h +++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h @@ -24,37 +24,6 @@ class DWARFUnit; class raw_ostream; -/// A helper struct for DWARFFormValue methods, providing information that -/// allows it to know the byte size of DW_FORM values that vary in size -/// depending on the DWARF version, address byte size, or DWARF32/DWARF64. -struct DWARFFormParams { - uint16_t Version; - uint8_t AddrSize; - dwarf::DwarfFormat Format; - - /// The definition of the size of form DW_FORM_ref_addr depends on the - /// version. In DWARF v2 it's the size of an address; after that, it's the - /// size of a reference. - uint8_t getRefAddrByteSize() const { - if (Version == 2) - return AddrSize; - return getDwarfOffsetByteSize(); - } - - /// The size of a reference is determined by the DWARF 32/64-bit format. - uint8_t getDwarfOffsetByteSize() const { - switch (Format) { - case dwarf::DwarfFormat::DWARF32: - return 4; - case dwarf::DwarfFormat::DWARF64: - return 8; - } - llvm_unreachable("Invalid Format value"); - } - - explicit operator bool() const { return Version && AddrSize; } -}; - class DWARFFormValue { public: enum FormClass { @@ -112,12 +81,12 @@ /// \p Context and \p Unit allows extracting information if the form refers /// to other sections (e.g., .debug_str). bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr, - DWARFFormParams FormParams, + dwarf::FormParams FormParams, const DWARFContext *Context = nullptr, const DWARFUnit *Unit = nullptr); bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr, - DWARFFormParams FormParams, const DWARFUnit *U) { + dwarf::FormParams FormParams, const DWARFUnit *U) { return extractValue(Data, OffsetPtr, FormParams, nullptr, U); } @@ -137,19 +106,6 @@ Optional getAsCStringOffset() const; Optional getAsReferenceUVal() const; - /// Get the fixed byte size for a given form. - /// - /// If the form has a fixed byte size, then an Optional with a value will be - /// returned. If the form is always encoded using a variable length storage - /// format (ULEB or SLEB numbers or blocks) then None will be returned. - /// - /// \param Form DWARF form to get the fixed byte size for. - /// \param FormParams DWARF parameters to help interpret forms. - /// \returns Optional value with the fixed byte size or None if - /// \p Form doesn't have a fixed byte size. - static Optional getFixedByteSize(dwarf::Form Form, - const DWARFFormParams FormParams); - /// Skip a form's value in \p DebugInfoData at the offset specified by /// \p OffsetPtr. /// @@ -160,7 +116,7 @@ /// \param Params DWARF parameters to help interpret forms. /// \returns true on success, false if the form was not skipped. bool skipValue(DataExtractor DebugInfoData, uint32_t *OffsetPtr, - const DWARFFormParams Params) const { + const dwarf::FormParams Params) const { return DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, Params); } @@ -175,7 +131,8 @@ /// \param FormParams DWARF parameters to help interpret forms. /// \returns true on success, false if the form was not skipped. static bool skipValue(dwarf::Form Form, DataExtractor DebugInfoData, - uint32_t *OffsetPtr, const DWARFFormParams FormParams); + uint32_t *OffsetPtr, + const dwarf::FormParams FormParams); private: void dumpString(raw_ostream &OS) const; Index: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h +++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h @@ -170,7 +170,7 @@ uint64_t Base = 0; uint64_t Size = 0; /// Format and version. - DWARFFormParams FormParams = {0, 0, dwarf::DwarfFormat::DWARF32}; + dwarf::FormParams FormParams = {0, 0, dwarf::DwarfFormat::DWARF32}; StrOffsetsContributionDescriptor(uint64_t Base, uint64_t Size, uint8_t Version, dwarf::DwarfFormat Format) @@ -206,7 +206,7 @@ const DWARFUnitSectionBase &UnitSection; // Version, address size, and DWARF format. - DWARFFormParams FormParams; + dwarf::FormParams FormParams; /// Start, length, and DWARF format of the unit's contribution to the string /// offsets table (DWARF v5). Optional StringOffsetsTableContribution; @@ -315,7 +315,7 @@ getStringOffsetsTableContribution() const { return StringOffsetsTableContribution; } - const DWARFFormParams &getFormParams() const { return FormParams; } + const dwarf::FormParams &getFormParams() const { return FormParams; } uint16_t getVersion() const { return FormParams.Version; } dwarf::DwarfFormat getFormat() const { return FormParams.Format; } uint8_t getAddressByteSize() const { return FormParams.AddrSize; } Index: llvm/trunk/lib/BinaryFormat/Dwarf.cpp =================================================================== --- llvm/trunk/lib/BinaryFormat/Dwarf.cpp +++ llvm/trunk/lib/BinaryFormat/Dwarf.cpp @@ -580,6 +580,93 @@ } } +Optional llvm::dwarf::getFixedFormByteSize(dwarf::Form Form, + FormParams Params) { + switch (Form) { + case DW_FORM_addr: + if (Params) + return Params.AddrSize; + return None; + + case DW_FORM_block: // ULEB128 length L followed by L bytes. + case DW_FORM_block1: // 1 byte length L followed by L bytes. + case DW_FORM_block2: // 2 byte length L followed by L bytes. + case DW_FORM_block4: // 4 byte length L followed by L bytes. + case DW_FORM_string: // C-string with null terminator. + case DW_FORM_sdata: // SLEB128. + case DW_FORM_udata: // ULEB128. + case DW_FORM_ref_udata: // ULEB128. + case DW_FORM_indirect: // ULEB128. + case DW_FORM_exprloc: // ULEB128 length L followed by L bytes. + case DW_FORM_strx: // ULEB128. + case DW_FORM_addrx: // ULEB128. + case DW_FORM_loclistx: // ULEB128. + case DW_FORM_rnglistx: // ULEB128. + case DW_FORM_GNU_addr_index: // ULEB128. + case DW_FORM_GNU_str_index: // ULEB128. + return None; + + case DW_FORM_ref_addr: + if (Params) + return Params.getRefAddrByteSize(); + return None; + + case DW_FORM_flag: + case DW_FORM_data1: + case DW_FORM_ref1: + case DW_FORM_strx1: + case DW_FORM_addrx1: + return 1; + + case DW_FORM_data2: + case DW_FORM_ref2: + case DW_FORM_strx2: + case DW_FORM_addrx2: + return 2; + + case DW_FORM_strx3: + return 3; + + case DW_FORM_data4: + case DW_FORM_ref4: + case DW_FORM_ref_sup4: + case DW_FORM_strx4: + case DW_FORM_addrx4: + return 4; + + case DW_FORM_strp: + case DW_FORM_GNU_ref_alt: + case DW_FORM_GNU_strp_alt: + case DW_FORM_line_strp: + case DW_FORM_sec_offset: + case DW_FORM_strp_sup: + if (Params) + return Params.getDwarfOffsetByteSize(); + return None; + + case DW_FORM_data8: + case DW_FORM_ref8: + case DW_FORM_ref_sig8: + case DW_FORM_ref_sup8: + return 8; + + case DW_FORM_flag_present: + return 0; + + case DW_FORM_data16: + return 16; + + case DW_FORM_implicit_const: + // The implicit value is stored in the abbreviation as a SLEB128, and + // there no data in debug info. + return 0; + + default: + break; + } + return None; +} + bool llvm::dwarf::isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk) { if (FormVendor(F) == DWARF_VENDOR_DWARF) { Index: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp @@ -425,51 +425,15 @@ /// SizeOf - Determine size of integer value in bytes. /// unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const { + dwarf::FormParams Params; + if (AP) + Params = {AP->getDwarfVersion(), uint8_t(AP->getPointerSize()), + AP->OutStreamer->getContext().getDwarfFormat()}; + + if (Optional FixedSize = dwarf::getFixedFormByteSize(Form, Params)) + return *FixedSize; + switch (Form) { - case dwarf::DW_FORM_implicit_const: - case dwarf::DW_FORM_flag_present: - return 0; - case dwarf::DW_FORM_flag: - case dwarf::DW_FORM_ref1: - case dwarf::DW_FORM_data1: - case dwarf::DW_FORM_strx1: - case dwarf::DW_FORM_addrx1: - return sizeof(int8_t); - case dwarf::DW_FORM_ref2: - case dwarf::DW_FORM_data2: - case dwarf::DW_FORM_strx2: - case dwarf::DW_FORM_addrx2: - return sizeof(int16_t); - case dwarf::DW_FORM_strx3: - return 3; - case dwarf::DW_FORM_ref4: - case dwarf::DW_FORM_data4: - case dwarf::DW_FORM_ref_sup4: - case dwarf::DW_FORM_strx4: - case dwarf::DW_FORM_addrx4: - return sizeof(int32_t); - case dwarf::DW_FORM_ref8: - case dwarf::DW_FORM_ref_sig8: - case dwarf::DW_FORM_data8: - case dwarf::DW_FORM_ref_sup8: - return sizeof(int64_t); - case dwarf::DW_FORM_ref_addr: - if (AP->getDwarfVersion() == 2) - return AP->getPointerSize(); - LLVM_FALLTHROUGH; - case dwarf::DW_FORM_strp: - case dwarf::DW_FORM_GNU_ref_alt: - case dwarf::DW_FORM_GNU_strp_alt: - case dwarf::DW_FORM_line_strp: - case dwarf::DW_FORM_sec_offset: - case dwarf::DW_FORM_strp_sup: - switch (AP->OutStreamer->getContext().getDwarfFormat()) { - case dwarf::DWARF32: - return 4; - case dwarf::DWARF64: - return 8; - } - llvm_unreachable("Invalid DWARF format"); case dwarf::DW_FORM_GNU_str_index: case dwarf::DW_FORM_GNU_addr_index: case dwarf::DW_FORM_ref_udata: @@ -478,8 +442,6 @@ return getULEB128Size(Integer); case dwarf::DW_FORM_sdata: return getSLEB128Size(Integer); - case dwarf::DW_FORM_addr: - return AP->getPointerSize(); default: llvm_unreachable("DIE Value form not supported yet"); } } Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp @@ -96,8 +96,7 @@ default: // The form has a byte size that doesn't depend on Params. // If it's a fixed size, keep track of it. - if ((ByteSize = - DWARFFormValue::getFixedByteSize(F, DWARFFormParams()))) { + if ((ByteSize = dwarf::getFixedFormByteSize(F, dwarf::FormParams()))) { if (FixedAttributeSize) FixedAttributeSize->NumBytes += *ByteSize; break; @@ -217,8 +216,7 @@ if (ByteSize.HasByteSize) return ByteSize.ByteSize; Optional S; - auto FixedByteSize = - DWARFFormValue::getFixedByteSize(Form, U.getFormParams()); + auto FixedByteSize = dwarf::getFixedFormByteSize(Form, U.getFormParams()); if (FixedByteSize) S = *FixedByteSize; return S; Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp @@ -130,7 +130,7 @@ AppleAcceleratorTable::readAtoms(uint32_t &HashDataOffset) { uint32_t DieOffset = dwarf::DW_INVALID_OFFSET; dwarf::Tag DieTag = dwarf::DW_TAG_null; - DWARFFormParams FormParams = {Hdr.Version, 0, dwarf::DwarfFormat::DWARF32}; + dwarf::FormParams FormParams = {Hdr.Version, 0, dwarf::DwarfFormat::DWARF32}; for (auto Atom : getAtomsDesc()) { DWARFFormValue FormValue(Atom.second); @@ -179,7 +179,7 @@ bool AppleAcceleratorTable::dumpName(ScopedPrinter &W, SmallVectorImpl &AtomForms, uint32_t *DataOffset) const { - DWARFFormParams FormParams = {Hdr.Version, 0, dwarf::DwarfFormat::DWARF32}; + dwarf::FormParams FormParams = {Hdr.Version, 0, dwarf::DwarfFormat::DWARF32}; uint32_t NameOffset = *DataOffset; if (!AccelSection.isValidOffsetForDataOfSize(*DataOffset, 4)) { W.printString("Incorrectly terminated list."); @@ -276,8 +276,8 @@ void AppleAcceleratorTable::Entry::extract( const AppleAcceleratorTable &AccelTable, uint32_t *Offset) { - DWARFFormParams FormParams = {AccelTable.Hdr.Version, 0, - dwarf::DwarfFormat::DWARF32}; + dwarf::FormParams FormParams = {AccelTable.Hdr.Version, 0, + dwarf::DwarfFormat::DWARF32}; for (auto &Atom : Values) Atom.extractValue(AccelTable.AccelSection, Offset, FormParams); } @@ -634,7 +634,7 @@ Entry E(*this, *AbbrevIt); - DWARFFormParams FormParams = {Hdr.Version, 0, dwarf::DwarfFormat::DWARF32}; + dwarf::FormParams FormParams = {Hdr.Version, 0, dwarf::DwarfFormat::DWARF32}; for (auto &Value : E.Values) { if (!Value.extractValue(AS, Offset, FormParams)) return make_error("Error extracting index attribute values", Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -70,7 +70,7 @@ SegSelectorSize = 0; MinInstLength = MaxOpsPerInst = DefaultIsStmt = LineBase = LineRange = 0; OpcodeBase = 0; - FormParams = DWARFFormParams({0, 0, DWARF32}); + FormParams = dwarf::FormParams({0, 0, DWARF32}); ContentTypes = ContentTypeTracker(); StandardOpcodeLengths.clear(); IncludeDirectories.clear(); @@ -194,8 +194,8 @@ static bool parseV5DirFileTables(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, uint64_t EndPrologueOffset, - const DWARFFormParams &FormParams, const DWARFContext - &Ctx, const DWARFUnit *U, + const dwarf::FormParams &FormParams, + const DWARFContext &Ctx, const DWARFUnit *U, DWARFDebugLine::ContentTypeTracker &ContentTypes, std::vector &IncludeDirectories, std::vector &FileNames) { Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp @@ -78,97 +78,9 @@ }; -Optional -DWARFFormValue::getFixedByteSize(dwarf::Form Form, - const DWARFFormParams Params) { - switch (Form) { - case DW_FORM_addr: - if (Params) - return Params.AddrSize; - return None; - - case DW_FORM_block: // ULEB128 length L followed by L bytes. - case DW_FORM_block1: // 1 byte length L followed by L bytes. - case DW_FORM_block2: // 2 byte length L followed by L bytes. - case DW_FORM_block4: // 4 byte length L followed by L bytes. - case DW_FORM_string: // C-string with null terminator. - case DW_FORM_sdata: // SLEB128. - case DW_FORM_udata: // ULEB128. - case DW_FORM_ref_udata: // ULEB128. - case DW_FORM_indirect: // ULEB128. - case DW_FORM_exprloc: // ULEB128 length L followed by L bytes. - case DW_FORM_strx: // ULEB128. - case DW_FORM_addrx: // ULEB128. - case DW_FORM_loclistx: // ULEB128. - case DW_FORM_rnglistx: // ULEB128. - case DW_FORM_GNU_addr_index: // ULEB128. - case DW_FORM_GNU_str_index: // ULEB128. - return None; - - case DW_FORM_ref_addr: - if (Params) - return Params.getRefAddrByteSize(); - return None; - - case DW_FORM_flag: - case DW_FORM_data1: - case DW_FORM_ref1: - case DW_FORM_strx1: - case DW_FORM_addrx1: - return 1; - - case DW_FORM_data2: - case DW_FORM_ref2: - case DW_FORM_strx2: - case DW_FORM_addrx2: - return 2; - - case DW_FORM_strx3: - return 3; - - case DW_FORM_data4: - case DW_FORM_ref4: - case DW_FORM_ref_sup4: - case DW_FORM_strx4: - case DW_FORM_addrx4: - return 4; - - case DW_FORM_strp: - case DW_FORM_GNU_ref_alt: - case DW_FORM_GNU_strp_alt: - case DW_FORM_line_strp: - case DW_FORM_sec_offset: - case DW_FORM_strp_sup: - if (Params) - return Params.getDwarfOffsetByteSize(); - return None; - - case DW_FORM_data8: - case DW_FORM_ref8: - case DW_FORM_ref_sig8: - case DW_FORM_ref_sup8: - return 8; - - case DW_FORM_flag_present: - return 0; - - case DW_FORM_data16: - return 16; - - case DW_FORM_implicit_const: - // The implicit value is stored in the abbreviation as a SLEB128, and - // there no data in debug info. - return 0; - - default: - break; - } - return None; -} - bool DWARFFormValue::skipValue(dwarf::Form Form, DataExtractor DebugInfoData, uint32_t *OffsetPtr, - const DWARFFormParams Params) { + const dwarf::FormParams Params) { bool Indirect = false; do { switch (Form) { @@ -230,7 +142,7 @@ case DW_FORM_GNU_ref_alt: case DW_FORM_GNU_strp_alt: if (Optional FixedSize = - DWARFFormValue::getFixedByteSize(Form, Params)) { + dwarf::getFixedFormByteSize(Form, Params)) { *OffsetPtr += *FixedSize; return true; } @@ -291,7 +203,7 @@ } bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data, - uint32_t *OffsetPtr, DWARFFormParams FP, + uint32_t *OffsetPtr, dwarf::FormParams FP, const DWARFContext *Ctx, const DWARFUnit *CU) { if (!Ctx && CU) Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -158,7 +158,7 @@ Offset = 0; Length = 0; Abbrevs = nullptr; - FormParams = DWARFFormParams({0, 0, DWARF32}); + FormParams = dwarf::FormParams({0, 0, DWARF32}); BaseAddr.reset(); RangeSectionBase = 0; AddrOffsetSectionBase = 0; Index: llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp =================================================================== --- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp +++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp @@ -183,7 +183,7 @@ break; default: DWARFFormValue::skipValue(Form, InfoData, &Offset, - DWARFFormParams({Version, AddrSize, Format})); + dwarf::FormParams({Version, AddrSize, Format})); } } return ID; Index: llvm/trunk/unittests/BinaryFormat/DwarfTest.cpp =================================================================== --- llvm/trunk/unittests/BinaryFormat/DwarfTest.cpp +++ llvm/trunk/unittests/BinaryFormat/DwarfTest.cpp @@ -139,4 +139,57 @@ EXPECT_EQ(DW_VIRTUALITY_invalid, getVirtuality("something else")); } +TEST(DwarfTest, FixedFormSizes) { + Optional RefSize; + Optional AddrSize; + + // Test 32 bit DWARF version 2 with 4 byte addresses. + FormParams Params_2_4_32 = {2, 4, DWARF32}; + RefSize = getFixedFormByteSize(DW_FORM_ref_addr, Params_2_4_32); + AddrSize = getFixedFormByteSize(DW_FORM_ref_addr, Params_2_4_32); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_TRUE(AddrSize.hasValue()); + EXPECT_EQ(*RefSize, *AddrSize); + + // Test 32 bit DWARF version 2 with 8 byte addresses. + FormParams Params_2_8_32 = {2, 8, DWARF32}; + RefSize = getFixedFormByteSize(DW_FORM_ref_addr, Params_2_8_32); + AddrSize = getFixedFormByteSize(DW_FORM_ref_addr, Params_2_8_32); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_TRUE(AddrSize.hasValue()); + EXPECT_EQ(*RefSize, *AddrSize); + + // DW_FORM_ref_addr is 4 bytes in DWARF 32 in DWARF version 3 and beyond. + FormParams Params_3_4_32 = {3, 4, DWARF32}; + RefSize = getFixedFormByteSize(DW_FORM_ref_addr, Params_3_4_32); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_EQ(*RefSize, 4); + + FormParams Params_4_4_32 = {4, 4, DWARF32}; + RefSize = getFixedFormByteSize(DW_FORM_ref_addr, Params_4_4_32); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_EQ(*RefSize, 4); + + FormParams Params_5_4_32 = {5, 4, DWARF32}; + RefSize = getFixedFormByteSize(DW_FORM_ref_addr, Params_5_4_32); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_EQ(*RefSize, 4); + + // DW_FORM_ref_addr is 8 bytes in DWARF 64 in DWARF version 3 and beyond. + FormParams Params_3_8_64 = {3, 8, DWARF64}; + RefSize = getFixedFormByteSize(DW_FORM_ref_addr, Params_3_8_64); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_EQ(*RefSize, 8); + + FormParams Params_4_8_64 = {4, 8, DWARF64}; + RefSize = getFixedFormByteSize(DW_FORM_ref_addr, Params_4_8_64); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_EQ(*RefSize, 8); + + FormParams Params_5_8_64 = {5, 8, DWARF64}; + RefSize = getFixedFormByteSize(DW_FORM_ref_addr, Params_5_8_64); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_EQ(*RefSize, 8); +} + } // end namespace Index: llvm/trunk/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp =================================================================== --- llvm/trunk/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp +++ llvm/trunk/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp @@ -20,59 +20,6 @@ namespace { -TEST(DWARFFormValue, FixedFormSizes) { - Optional RefSize; - Optional AddrSize; - - // Test 32 bit DWARF version 2 with 4 byte addresses. - DWARFFormParams Params_2_4_32 = {2, 4, DWARF32}; - RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, Params_2_4_32); - AddrSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, Params_2_4_32); - EXPECT_TRUE(RefSize.hasValue()); - EXPECT_TRUE(AddrSize.hasValue()); - EXPECT_EQ(*RefSize, *AddrSize); - - // Test 32 bit DWARF version 2 with 8 byte addresses. - DWARFFormParams Params_2_8_32 = {2, 8, DWARF32}; - RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, Params_2_8_32); - AddrSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, Params_2_8_32); - EXPECT_TRUE(RefSize.hasValue()); - EXPECT_TRUE(AddrSize.hasValue()); - EXPECT_EQ(*RefSize, *AddrSize); - - // DW_FORM_ref_addr is 4 bytes in DWARF 32 in DWARF version 3 and beyond. - DWARFFormParams Params_3_4_32 = {3, 4, DWARF32}; - RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, Params_3_4_32); - EXPECT_TRUE(RefSize.hasValue()); - EXPECT_EQ(*RefSize, 4); - - DWARFFormParams Params_4_4_32 = {4, 4, DWARF32}; - RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, Params_4_4_32); - EXPECT_TRUE(RefSize.hasValue()); - EXPECT_EQ(*RefSize, 4); - - DWARFFormParams Params_5_4_32 = {5, 4, DWARF32}; - RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, Params_5_4_32); - EXPECT_TRUE(RefSize.hasValue()); - EXPECT_EQ(*RefSize, 4); - - // DW_FORM_ref_addr is 8 bytes in DWARF 64 in DWARF version 3 and beyond. - DWARFFormParams Params_3_8_64 = {3, 8, DWARF64}; - RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, Params_3_8_64); - EXPECT_TRUE(RefSize.hasValue()); - EXPECT_EQ(*RefSize, 8); - - DWARFFormParams Params_4_8_64 = {4, 8, DWARF64}; - RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, Params_4_8_64); - EXPECT_TRUE(RefSize.hasValue()); - EXPECT_EQ(*RefSize, 8); - - DWARFFormParams Params_5_8_64 = {5, 8, DWARF64}; - RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, Params_5_8_64); - EXPECT_TRUE(RefSize.hasValue()); - EXPECT_EQ(*RefSize, 8); -} - bool isFormClass(dwarf::Form Form, DWARFFormValue::FormClass FC) { return DWARFFormValue(Form).isFormClass(FC); }