diff options
author | Pavel Labath <labath@google.com> | 2018-03-14 09:39:54 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2018-03-14 09:39:54 +0000 |
commit | 322711f5290715b1e6f3da6c215e91760e93b408 (patch) | |
tree | d22f7cc01859a2789548c625f27bbb6d0ccfb3e8 /llvm/lib/DebugInfo | |
parent | bc683cced825ac6fc31c73cc7a539021c9c14284 (diff) | |
download | bcm5719-llvm-322711f5290715b1e6f3da6c215e91760e93b408.tar.gz bcm5719-llvm-322711f5290715b1e6f3da6c215e91760e93b408.zip |
DWARF: Unify form size handling code
Summary:
This patch replaces the two switches which are deducing the size of
various forms with a single implementation. I have put the new
implementation into BinaryFormat, to avoid introducing dependencies
between the two independent libraries (DebugInfo and CodeGen) that need
this functionality.
Reviewers: aprantl, JDevlieghere, dblaikie
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D44418
llvm-svn: 327486
Diffstat (limited to 'llvm/lib/DebugInfo')
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp | 94 | ||||
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp | 2 |
5 files changed, 14 insertions, 104 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp index f593953c62f..688a85c9da3 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp @@ -96,8 +96,7 @@ DWARFAbbreviationDeclaration::extract(DataExtractor Data, 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 @@ Optional<int64_t> DWARFAbbreviationDeclaration::AttributeSpec::getByteSize( if (ByteSize.HasByteSize) return ByteSize.ByteSize; Optional<int64_t> S; - auto FixedByteSize = - DWARFFormValue::getFixedByteSize(Form, U.getFormParams()); + auto FixedByteSize = dwarf::getFixedFormByteSize(Form, U.getFormParams()); if (FixedByteSize) S = *FixedByteSize; return S; diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp index 4771d213741..2bde3d6d034 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp @@ -130,7 +130,7 @@ std::pair<uint32_t, dwarf::Tag> 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 @@ Optional<uint64_t> AppleAcceleratorTable::HeaderData::extractOffset( bool AppleAcceleratorTable::dumpName(ScopedPrinter &W, SmallVectorImpl<DWARFFormValue> &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 @@ AppleAcceleratorTable::Entry::Entry( 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 @@ DWARFDebugNames::NameIndex::getEntry(uint32_t *Offset) const { 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<StringError>("Error extracting index attribute values", diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp index c91b95cbc11..69a6e7f4a94 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -70,7 +70,7 @@ void DWARFDebugLine::Prologue::clear() { 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 @@ parseV5EntryFormat(const DWARFDataExtractor &DebugLineData, uint32_t 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<DWARFFormValue> &IncludeDirectories, std::vector<DWARFDebugLine::FileNameEntry> &FileNames) { diff --git a/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp b/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp index ff3f880cdbb..b3ecf8e2dab 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp @@ -78,97 +78,9 @@ static const DWARFFormValue::FormClass DWARF5FormClasses[] = { }; -Optional<uint8_t> -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 @@ bool DWARFFormValue::skipValue(dwarf::Form Form, DataExtractor DebugInfoData, case DW_FORM_GNU_ref_alt: case DW_FORM_GNU_strp_alt: if (Optional<uint8_t> FixedSize = - DWARFFormValue::getFixedByteSize(Form, Params)) { + dwarf::getFixedFormByteSize(Form, Params)) { *OffsetPtr += *FixedSize; return true; } @@ -291,7 +203,7 @@ bool DWARFFormValue::isFormClass(DWARFFormValue::FormClass FC) const { } 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) diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp index e24ef90dd52..f85c0946f8d 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -158,7 +158,7 @@ void DWARFUnit::clear() { Offset = 0; Length = 0; Abbrevs = nullptr; - FormParams = DWARFFormParams({0, 0, DWARF32}); + FormParams = dwarf::FormParams({0, 0, DWARF32}); BaseAddr.reset(); RangeSectionBase = 0; AddrOffsetSectionBase = 0; |