[llvm] r327486 - DWARF: Unify form size handling code
Pavel Labath via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 14 02:39:54 PDT 2018
Author: labath
Date: Wed Mar 14 02:39:54 2018
New Revision: 327486
URL: http://llvm.org/viewvc/llvm-project?rev=327486&view=rev
Log:
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
Modified:
llvm/trunk/include/llvm/BinaryFormat/Dwarf.h
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
llvm/trunk/lib/BinaryFormat/Dwarf.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp
llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
llvm/trunk/unittests/BinaryFormat/DwarfTest.cpp
llvm/trunk/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp
Modified: llvm/trunk/include/llvm/BinaryFormat/Dwarf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BinaryFormat/Dwarf.h?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/include/llvm/BinaryFormat/Dwarf.h (original)
+++ llvm/trunk/include/llvm/BinaryFormat/Dwarf.h Wed Mar 14 02:39:54 2018
@@ -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 @@ enum LLVMConstants : uint32_t {
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 AttributeEncodingVendor(TypeKin
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<uint8_t> value with the fixed byte size or None if
+/// \p Form doesn't have a fixed byte size.
+Optional<uint8_t> 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 @@ private:
};
};
-/// 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
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h Wed Mar 14 02:39:54 2018
@@ -67,7 +67,7 @@ public:
/// 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 @@ public:
std::vector<DWARFFormValue> IncludeDirectories;
std::vector<FileNameEntry> 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; }
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFFormValue.h Wed Mar 14 02:39:54 2018
@@ -24,37 +24,6 @@ class DWARFContext;
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 @@ public:
/// \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 @@ public:
Optional<uint64_t> getAsCStringOffset() const;
Optional<uint64_t> 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<uint8_t> value with the fixed byte size or None if
- /// \p Form doesn't have a fixed byte size.
- static Optional<uint8_t> 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 @@ public:
/// \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 @@ public:
/// \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;
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h Wed Mar 14 02:39:54 2018
@@ -170,7 +170,7 @@ struct StrOffsetsContributionDescriptor
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 @@ class DWARFUnit {
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<StrOffsetsContributionDescriptor> StringOffsetsTableContribution;
@@ -315,7 +315,7 @@ public:
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; }
Modified: llvm/trunk/lib/BinaryFormat/Dwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/BinaryFormat/Dwarf.cpp?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/lib/BinaryFormat/Dwarf.cpp (original)
+++ llvm/trunk/lib/BinaryFormat/Dwarf.cpp Wed Mar 14 02:39:54 2018
@@ -580,6 +580,93 @@ StringRef llvm::dwarf::IndexString(unsig
}
}
+Optional<uint8_t> 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) {
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp Wed Mar 14 02:39:54 2018
@@ -425,51 +425,15 @@ void DIEInteger::EmitValue(const AsmPrin
/// 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<uint8_t> 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 @@ unsigned DIEInteger::SizeOf(const AsmPri
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");
}
}
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp Wed Mar 14 02:39:54 2018
@@ -96,8 +96,7 @@ DWARFAbbreviationDeclaration::extract(Da
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> DWARFAbbreviationDecla
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;
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp Wed Mar 14 02:39:54 2018
@@ -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
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(uin
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",
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp Wed Mar 14 02:39:54 2018
@@ -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 DWARFDataExtrac
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) {
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp Wed Mar 14 02:39:54 2018
@@ -78,97 +78,9 @@ static const DWARFFormValue::FormClass D
};
-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::Fo
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(DWARFFo
}
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)
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp Wed Mar 14 02:39:54 2018
@@ -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;
Modified: llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Wed Mar 14 02:39:54 2018
@@ -183,7 +183,7 @@ static Expected<CompileUnitIdentifiers>
break;
default:
DWARFFormValue::skipValue(Form, InfoData, &Offset,
- DWARFFormParams({Version, AddrSize, Format}));
+ dwarf::FormParams({Version, AddrSize, Format}));
}
}
return ID;
Modified: llvm/trunk/unittests/BinaryFormat/DwarfTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/BinaryFormat/DwarfTest.cpp?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/unittests/BinaryFormat/DwarfTest.cpp (original)
+++ llvm/trunk/unittests/BinaryFormat/DwarfTest.cpp Wed Mar 14 02:39:54 2018
@@ -139,4 +139,57 @@ TEST(DwarfTest, getVirtuality) {
EXPECT_EQ(DW_VIRTUALITY_invalid, getVirtuality("something else"));
}
+TEST(DwarfTest, FixedFormSizes) {
+ Optional<uint8_t> RefSize;
+ Optional<uint8_t> 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
Modified: llvm/trunk/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp?rev=327486&r1=327485&r2=327486&view=diff
==============================================================================
--- llvm/trunk/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp (original)
+++ llvm/trunk/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp Wed Mar 14 02:39:54 2018
@@ -20,59 +20,6 @@ using namespace dwarf;
namespace {
-TEST(DWARFFormValue, FixedFormSizes) {
- Optional<uint8_t> RefSize;
- Optional<uint8_t> 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);
}
More information about the llvm-commits
mailing list