1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[DWARF] NFC: DWARFDataExtractor combines relocs with DataExtractor.

Requires callers to directly associate relocations with a DataExtractor
used to read data from a DWARF section, which helps a callee not make
assumptions about which section it is reading.
This is the next step in reducing DWARFFormValue's dependence on DWARFUnit.

Differential Revision: https://reviews.llvm.org/D34704

llvm-svn: 306699
This commit is contained in:
Paul Robinson 2017-06-29 16:52:08 +00:00
parent 8476e6e250
commit d4260a6777
25 changed files with 194 additions and 160 deletions

View File

@ -12,8 +12,8 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/Support/DataExtractor.h"
#include <cstdint>
#include <utility>
@ -41,14 +41,13 @@ class DWARFAcceleratorTable {
struct Header Hdr;
struct HeaderData HdrData;
DataExtractor AccelSection;
DWARFDataExtractor AccelSection;
DataExtractor StringSection;
const RelocAddrMap& Relocs;
public:
DWARFAcceleratorTable(DataExtractor AccelSection, DataExtractor StringSection,
const RelocAddrMap &Relocs)
: AccelSection(AccelSection), StringSection(StringSection), Relocs(Relocs) {}
DWARFAcceleratorTable(const DWARFDataExtractor &AccelSection,
DataExtractor StringSection)
: AccelSection(AccelSection), StringSection(StringSection) {}
bool extract();
uint32_t getNumBuckets();

View File

@ -20,8 +20,8 @@ public:
DWARFCompileUnit(DWARFContext &Context, const DWARFSection &Section,
const DWARFDebugAbbrev *DA, const DWARFSection *RS,
StringRef SS, const DWARFSection &SOS,
const DWARFSection *AOS, StringRef LS, bool LE, bool IsDWO,
const DWARFUnitSectionBase &UnitSection,
const DWARFSection *AOS, const DWARFSection &LS, bool LE,
bool IsDWO, const DWARFUnitSectionBase &UnitSection,
const DWARFUnitIndex::Entry *Entry)
: DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LS, LE, IsDWO,
UnitSection, Entry) {}

View File

@ -45,12 +45,6 @@ class DataExtractor;
class MemoryBuffer;
class raw_ostream;
/// Reads a value from data extractor and applies a relocation to the result if
/// one exists for the given offset.
uint64_t getRelocatedValue(const DataExtractor &Data, uint32_t Size,
uint32_t *Off, const RelocAddrMap *Relocs,
uint64_t *SecNdx = nullptr);
/// DWARFContext
/// This data structure is the top level entity that deals with dwarf debug
/// information parsing. The actual data is supplied through pure virtual

View File

@ -0,0 +1,48 @@
//===- DWARFDataExtractor.h -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H
#define LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H
#include "llvm/DebugInfo/DWARF/DWARFSection.h"
#include "llvm/Support/DataExtractor.h"
namespace llvm {
/// A DataExtractor (typically for an in-memory copy of an object-file section)
/// plus a relocation map for that section, if there is one.
class DWARFDataExtractor : public DataExtractor {
const RelocAddrMap *RelocMap = nullptr;
public:
/// Constructor for the normal case of extracting data from a DWARF section.
/// The DWARFSection's lifetime must be at least as long as the extractor's.
DWARFDataExtractor(const DWARFSection &Section, bool IsLittleEndian,
uint8_t AddressSize)
: DataExtractor(Section.Data, IsLittleEndian, AddressSize),
RelocMap(&Section.Relocs) {}
/// Constructor for cases when there are no relocations.
DWARFDataExtractor(StringRef Data, bool IsLittleEndian, uint8_t AddressSize)
: DataExtractor(Data, IsLittleEndian, AddressSize) {}
/// Extracts a value and applies a relocation to the result if
/// one exists for the given offset.
uint64_t getRelocatedValue(uint32_t Size, uint32_t *Off,
uint64_t *SectionIndex = nullptr) const;
/// Extracts an address-sized value and applies a relocation to the result if
/// one exists for the given offset.
uint64_t getRelocatedAddress(uint32_t *Off, uint64_t *SecIx = nullptr) const {
return getRelocatedValue(getAddressSize(), Off, SecIx);
}
};
} // end namespace llvm
#endif // LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H

View File

@ -12,6 +12,7 @@
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include <cstdint>
namespace llvm {
@ -40,8 +41,7 @@ public:
/// High performance extraction should use this call.
bool extractFast(const DWARFUnit &U, uint32_t *OffsetPtr,
const DataExtractor &DebugInfoData,
uint32_t UEndOffset,
const DWARFDataExtractor &DebugInfoData, uint32_t UEndOffset,
uint32_t Depth);
uint32_t getOffset() const { return Offset; }

View File

@ -12,9 +12,9 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/Support/DataExtractor.h"
#include <cstdint>
#include <map>
#include <string>
@ -26,9 +26,6 @@ class raw_ostream;
class DWARFDebugLine {
public:
DWARFDebugLine(const RelocAddrMap *LineInfoRelocMap)
: RelocMap(LineInfoRelocMap) {}
struct FileNameEntry {
FileNameEntry() = default;
@ -98,7 +95,7 @@ public:
void clear();
void dump(raw_ostream &OS) const;
bool parse(DataExtractor DebugLineData, uint32_t *OffsetPtr);
bool parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr);
};
/// Standard .debug_line state machine structure.
@ -220,8 +217,7 @@ public:
void clear();
/// Parse prologue and all rows.
bool parse(DataExtractor DebugLineData, const RelocAddrMap *RMap,
uint32_t *OffsetPtr);
bool parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr);
using RowVector = std::vector<Row>;
using RowIter = RowVector::const_iterator;
@ -238,7 +234,7 @@ public:
};
const LineTable *getLineTable(uint32_t Offset) const;
const LineTable *getOrParseLineTable(DataExtractor DebugLineData,
const LineTable *getOrParseLineTable(const DWARFDataExtractor &DebugLineData,
uint32_t Offset);
private:
@ -261,7 +257,6 @@ private:
using LineTableIter = LineTableMapTy::iterator;
using LineTableConstIter = LineTableMapTy::const_iterator;
const RelocAddrMap *RelocMap;
LineTableMapTy LineTableMap;
};

View File

@ -11,8 +11,8 @@
#define LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/Support/DataExtractor.h"
#include <cstdint>
namespace llvm {
@ -45,18 +45,13 @@ class DWARFDebugLoc {
/// the locations in which the variable is stored.
LocationLists Locations;
/// A map used to resolve binary relocations.
const RelocAddrMap &RelocMap;
public:
DWARFDebugLoc(const RelocAddrMap &LocRelocMap) : RelocMap(LocRelocMap) {}
/// Print the location lists found within the debug_loc section.
void dump(raw_ostream &OS) const;
/// Parse the debug_loc section accessible via the 'data' parameter using the
/// specified address size to interpret the address ranges.
void parse(DataExtractor data, unsigned AddressSize);
/// address size also given in 'data' to interpret the address ranges.
void parse(const DWARFDataExtractor &data);
};
class DWARFDebugLocDWO {

View File

@ -10,8 +10,8 @@
#ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGRANGELIST_H
#define LLVM_DEBUGINFO_DWARF_DWARFDEBUGRANGELIST_H
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/Support/DataExtractor.h"
#include <cassert>
#include <cstdint>
#include <vector>
@ -79,7 +79,7 @@ public:
void clear();
void dump(raw_ostream &OS) const;
bool extract(DataExtractor data, uint32_t *offset_ptr, const RelocAddrMap& Relocs);
bool extract(const DWARFDataExtractor &data, uint32_t *offset_ptr);
const std::vector<RangeListEntry> &getEntries() { return Entries; }
/// getAbsoluteRanges - Returns absolute address ranges defined by this range

View File

@ -14,7 +14,7 @@
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include <cstdint>
namespace llvm {
@ -105,14 +105,13 @@ public:
/// Extracts a value in \p Data at offset \p *OffsetPtr.
///
/// The passed DWARFUnit is allowed to be nullptr, in which
/// case no relocation processing will be performed and some
/// The passed DWARFUnit is allowed to be nullptr, in which case some
/// kind of forms that depend on Unit information are disallowed.
/// \param Data The DataExtractor to use.
/// \param OffsetPtr The offset within DataExtractor where the data starts.
/// \param Data The DWARFDataExtractor to use.
/// \param OffsetPtr The offset within \p Data where the data starts.
/// \param U The optional DWARFUnit supplying information for some forms.
/// \returns whether the extraction succeeded.
bool extractValue(const DataExtractor &Data, uint32_t *OffsetPtr,
bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr,
const DWARFUnit *U);
bool isInlinedCStr() const {

View File

@ -32,7 +32,7 @@ public:
DWARFTypeUnit(DWARFContext &Context, const DWARFSection &Section,
const DWARFDebugAbbrev *DA, const DWARFSection *RS,
StringRef SS, const DWARFSection &SOS, const DWARFSection *AOS,
StringRef LS, bool LE, bool IsDWO,
const DWARFSection &LS, bool LE, bool IsDWO,
const DWARFUnitSectionBase &UnitSection,
const DWARFUnitIndex::Entry *Entry)
: DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LS, LE, IsDWO,

View File

@ -58,7 +58,7 @@ protected:
virtual void parseImpl(DWARFContext &Context, const DWARFSection &Section,
const DWARFDebugAbbrev *DA, const DWARFSection *RS,
StringRef SS, const DWARFSection &SOS,
const DWARFSection *AOS, StringRef LS,
const DWARFSection *AOS, const DWARFSection &LS,
bool isLittleEndian, bool isDWO) = 0;
};
@ -91,7 +91,7 @@ private:
void parseImpl(DWARFContext &Context, const DWARFSection &Section,
const DWARFDebugAbbrev *DA, const DWARFSection *RS,
StringRef SS, const DWARFSection &SOS, const DWARFSection *AOS,
StringRef LS, bool LE, bool IsDWO) override {
const DWARFSection &LS, bool LE, bool IsDWO) override {
if (Parsed)
return;
const auto &Index = getDWARFUnitIndex(Context, UnitType::Section);
@ -118,7 +118,7 @@ class DWARFUnit {
const DWARFDebugAbbrev *Abbrev;
const DWARFSection *RangeSection;
uint32_t RangeSectionBase;
StringRef LineSection;
const DWARFSection &LineSection;
StringRef StringSection;
const DWARFSection &StringOffsetSection;
uint64_t StringOffsetSectionBase = 0;
@ -166,15 +166,16 @@ protected:
public:
DWARFUnit(DWARFContext &Context, const DWARFSection &Section,
const DWARFDebugAbbrev *DA, const DWARFSection *RS, StringRef SS,
const DWARFSection &SOS, const DWARFSection *AOS, StringRef LS,
bool LE, bool IsDWO, const DWARFUnitSectionBase &UnitSection,
const DWARFSection &SOS, const DWARFSection *AOS,
const DWARFSection &LS, bool LE, bool IsDWO,
const DWARFUnitSectionBase &UnitSection,
const DWARFUnitIndex::Entry *IndexEntry = nullptr);
virtual ~DWARFUnit();
DWARFContext& getContext() const { return Context; }
StringRef getLineSection() const { return LineSection; }
const DWARFSection &getLineSection() const { return LineSection; }
StringRef getStringSection() const { return StringSection; }
const DWARFSection &getStringOffsetSection() const {
return StringOffsetSection;
@ -196,9 +197,9 @@ public:
bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
bool getStringOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
DataExtractor getDebugInfoExtractor() const {
return DataExtractor(InfoSection.Data, isLittleEndian,
getAddressByteSize());
DWARFDataExtractor getDebugInfoExtractor() const {
return DWARFDataExtractor(InfoSection, isLittleEndian,
getAddressByteSize());
}
DataExtractor getStringExtractor() const {

View File

@ -3,6 +3,7 @@ add_llvm_library(LLVMDebugInfoDWARF
DWARFAcceleratorTable.cpp
DWARFCompileUnit.cpp
DWARFContext.cpp
DWARFDataExtractor.cpp
DWARFDebugAbbrev.cpp
DWARFDebugArangeSet.cpp
DWARFDebugAranges.cpp

View File

@ -121,8 +121,7 @@ LLVM_DUMP_METHOD void DWARFAcceleratorTable::dump(raw_ostream &OS) const {
continue;
}
while (AccelSection.isValidOffsetForDataOfSize(DataOffset, 4)) {
unsigned StringOffset =
getRelocatedValue(AccelSection, 4, &DataOffset, &Relocs);
unsigned StringOffset = AccelSection.getRelocatedValue(4, &DataOffset);
if (!StringOffset)
break;
OS << format(" Name: %08x \"%s\"\n", StringOffset,

View File

@ -59,26 +59,13 @@ using DWARFLineTable = DWARFDebugLine::LineTable;
using FileLineInfoKind = DILineInfoSpecifier::FileLineInfoKind;
using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
uint64_t llvm::getRelocatedValue(const DataExtractor &Data, uint32_t Size,
uint32_t *Off, const RelocAddrMap *Relocs,
uint64_t *SectionIndex) {
if (!Relocs)
return Data.getUnsigned(Off, Size);
RelocAddrMap::const_iterator AI = Relocs->find(*Off);
if (AI == Relocs->end())
return Data.getUnsigned(Off, Size);
if (SectionIndex)
*SectionIndex = AI->second.SectionIndex;
return Data.getUnsigned(Off, Size) + AI->second.Value;
}
static void dumpAccelSection(raw_ostream &OS, StringRef Name,
const DWARFSection& Section, StringRef StringSection,
bool LittleEndian) {
DataExtractor AccelSection(Section.Data, LittleEndian, 0);
DWARFDataExtractor AccelSection(Section, LittleEndian, 0);
DataExtractor StrData(StringSection, LittleEndian, 0);
OS << "\n." << Name << " contents:\n";
DWARFAcceleratorTable Accel(AccelSection, StrData, Section.Relocs);
DWARFAcceleratorTable Accel(AccelSection, StrData);
if (!Accel.extract())
return;
Accel.dump(OS);
@ -88,7 +75,7 @@ static void
dumpDWARFv5StringOffsetsSection(raw_ostream &OS, StringRef SectionName,
const DWARFSection &StringOffsetsSection,
StringRef StringSection, bool LittleEndian) {
DataExtractor StrOffsetExt(StringOffsetsSection.Data, LittleEndian, 0);
DWARFDataExtractor StrOffsetExt(StringOffsetsSection, LittleEndian, 0);
uint32_t Offset = 0;
uint64_t SectionSize = StringOffsetsSection.Data.size();
@ -144,8 +131,8 @@ dumpDWARFv5StringOffsetsSection(raw_ostream &OS, StringRef SectionName,
while (Offset - ContributionBase < ContributionSize) {
OS << format("0x%8.8x: ", Offset);
// FIXME: We can only extract strings in DWARF32 format at the moment.
uint64_t StringOffset = getRelocatedValue(
StrOffsetExt, EntrySize, &Offset, &StringOffsetsSection.Relocs);
uint64_t StringOffset =
StrOffsetExt.getRelocatedValue(EntrySize, &Offset);
if (Format == DWARF32) {
OS << format("%8.8x ", StringOffset);
uint32_t StringOffset32 = (uint32_t)StringOffset;
@ -287,11 +274,11 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
if (!CUDIE)
continue;
if (auto StmtOffset = toSectionOffset(CUDIE.find(DW_AT_stmt_list))) {
DataExtractor lineData(getLineSection().Data, isLittleEndian(),
savedAddressByteSize);
DWARFDataExtractor lineData(getLineSection(), isLittleEndian(),
savedAddressByteSize);
DWARFDebugLine::LineTable LineTable;
uint32_t Offset = *StmtOffset;
LineTable.parse(lineData, &getLineSection().Relocs, &Offset);
LineTable.parse(lineData, &Offset);
LineTable.dump(OS);
}
}
@ -310,8 +297,8 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
if (DumpType == DIDT_All || DumpType == DIDT_LineDwo) {
OS << "\n.debug_line.dwo contents:\n";
unsigned stmtOffset = 0;
DataExtractor lineData(getLineDWOSection().Data, isLittleEndian(),
savedAddressByteSize);
DWARFDataExtractor lineData(getLineDWOSection(), isLittleEndian(),
savedAddressByteSize);
DWARFDebugLine::LineTable LineTable;
while (LineTable.Prologue.parse(lineData, &stmtOffset)) {
LineTable.dump(OS);
@ -348,11 +335,11 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
// sizes, but for simplicity we just use the address byte size of the last
// compile unit (there is no easy and fast way to associate address range
// list and the compile unit it describes).
DataExtractor rangesData(getRangeSection().Data, isLittleEndian(),
savedAddressByteSize);
DWARFDataExtractor rangesData(getRangeSection(), isLittleEndian(),
savedAddressByteSize);
offset = 0;
DWARFDebugRangeList rangeList;
while (rangeList.extract(rangesData, &offset, getRangeSection().Relocs))
while (rangeList.extract(rangesData, &offset))
rangeList.dump(OS);
}
@ -499,11 +486,13 @@ const DWARFDebugLoc *DWARFContext::getDebugLoc() {
if (Loc)
return Loc.get();
DataExtractor LocData(getLocSection().Data, isLittleEndian(), 0);
Loc.reset(new DWARFDebugLoc(getLocSection().Relocs));
Loc.reset(new DWARFDebugLoc);
// assume all compile units have the same address byte size
if (getNumCompileUnits())
Loc->parse(LocData, getCompileUnitAtIndex(0)->getAddressByteSize());
if (getNumCompileUnits()) {
DWARFDataExtractor LocData(getLocSection(), isLittleEndian(),
getCompileUnitAtIndex(0)->getAddressByteSize());
Loc->parse(LocData);
}
return Loc.get();
}
@ -570,7 +559,7 @@ const DWARFDebugMacro *DWARFContext::getDebugMacro() {
const DWARFLineTable *
DWARFContext::getLineTableForUnit(DWARFUnit *U) {
if (!Line)
Line.reset(new DWARFDebugLine(&getLineSection().Relocs));
Line.reset(new DWARFDebugLine);
auto UnitDIE = U->getUnitDIE();
if (!UnitDIE)
@ -586,12 +575,12 @@ DWARFContext::getLineTableForUnit(DWARFUnit *U) {
return lt;
// Make sure the offset is good before we try to parse.
if (stmtOffset >= U->getLineSection().size())
if (stmtOffset >= U->getLineSection().Data.size())
return nullptr;
// We have to parse it first.
DataExtractor lineData(U->getLineSection(), isLittleEndian(),
U->getAddressByteSize());
DWARFDataExtractor lineData(U->getLineSection(), isLittleEndian(),
U->getAddressByteSize());
return Line->getOrParseLineTable(lineData, stmtOffset);
}

View File

@ -0,0 +1,24 @@
//===- DWARFDataExtractor.cpp ---------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
using namespace llvm;
uint64_t DWARFDataExtractor::getRelocatedValue(uint32_t Size, uint32_t *Off,
uint64_t *SecNdx) const {
if (!RelocMap)
return getUnsigned(Off, Size);
RelocAddrMap::const_iterator AI = RelocMap->find(*Off);
if (AI == RelocMap->end())
return getUnsigned(Off, Size);
if (SecNdx)
*SecNdx = AI->second.SectionIndex;
return getUnsigned(Off, Size) + AI->second.Value;
}

View File

@ -21,13 +21,13 @@ using namespace dwarf;
bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U,
uint32_t *OffsetPtr) {
DataExtractor DebugInfoData = U.getDebugInfoExtractor();
DWARFDataExtractor DebugInfoData = U.getDebugInfoExtractor();
const uint32_t UEndOffset = U.getNextUnitOffset();
return extractFast(U, OffsetPtr, DebugInfoData, UEndOffset, 0);
}
bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint32_t *OffsetPtr,
const DataExtractor &DebugInfoData,
const DWARFDataExtractor &DebugInfoData,
uint32_t UEndOffset, uint32_t D) {
Offset = *OffsetPtr;
Depth = D;

View File

@ -94,8 +94,8 @@ void DWARFDebugLine::Prologue::dump(raw_ostream &OS) const {
// Parse v2-v4 directory and file tables.
static void
parseV2DirFileTables(DataExtractor DebugLineData, uint32_t *OffsetPtr,
uint64_t EndPrologueOffset,
parseV2DirFileTables(const DWARFDataExtractor &DebugLineData,
uint32_t *OffsetPtr, uint64_t EndPrologueOffset,
std::vector<StringRef> &IncludeDirectories,
std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {
while (*OffsetPtr < EndPrologueOffset) {
@ -122,7 +122,7 @@ parseV2DirFileTables(DataExtractor DebugLineData, uint32_t *OffsetPtr,
// Returns the descriptors, or an empty vector if we did not find a path or
// ran off the end of the prologue.
static ContentDescriptors
parseV5EntryFormat(DataExtractor DebugLineData, uint32_t *OffsetPtr,
parseV5EntryFormat(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr,
uint64_t EndPrologueOffset) {
ContentDescriptors Descriptors;
int FormatCount = DebugLineData.getU8(OffsetPtr);
@ -142,8 +142,8 @@ parseV5EntryFormat(DataExtractor DebugLineData, uint32_t *OffsetPtr,
}
static bool
parseV5DirFileTables(DataExtractor DebugLineData, uint32_t *OffsetPtr,
uint64_t EndPrologueOffset,
parseV5DirFileTables(const DWARFDataExtractor &DebugLineData,
uint32_t *OffsetPtr, uint64_t EndPrologueOffset,
const DWARFFormParams &FormParams,
std::vector<StringRef> &IncludeDirectories,
std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {
@ -212,7 +212,7 @@ parseV5DirFileTables(DataExtractor DebugLineData, uint32_t *OffsetPtr,
return true;
}
bool DWARFDebugLine::Prologue::parse(DataExtractor DebugLineData,
bool DWARFDebugLine::Prologue::parse(const DWARFDataExtractor &DebugLineData,
uint32_t *OffsetPtr) {
const uint64_t PrologueOffset = *OffsetPtr;
@ -381,20 +381,19 @@ DWARFDebugLine::getLineTable(uint32_t Offset) const {
}
const DWARFDebugLine::LineTable *
DWARFDebugLine::getOrParseLineTable(DataExtractor DebugLineData,
DWARFDebugLine::getOrParseLineTable(const DWARFDataExtractor &DebugLineData,
uint32_t Offset) {
std::pair<LineTableIter, bool> Pos =
LineTableMap.insert(LineTableMapTy::value_type(Offset, LineTable()));
LineTable *LT = &Pos.first->second;
if (Pos.second) {
if (!LT->parse(DebugLineData, RelocMap, &Offset))
if (!LT->parse(DebugLineData, &Offset))
return nullptr;
}
return LT;
}
bool DWARFDebugLine::LineTable::parse(DataExtractor DebugLineData,
const RelocAddrMap *RMap,
bool DWARFDebugLine::LineTable::parse(const DWARFDataExtractor &DebugLineData,
uint32_t *OffsetPtr) {
const uint32_t DebugLineOffset = *OffsetPtr;
@ -443,8 +442,7 @@ bool DWARFDebugLine::LineTable::parse(DataExtractor DebugLineData,
// relocatable address. All of the other statement program opcodes
// that affect the address register add a delta to it. This instruction
// stores a relocatable value into it instead.
State.Row.Address = getRelocatedValue(
DebugLineData, DebugLineData.getAddressSize(), OffsetPtr, RMap);
State.Row.Address = DebugLineData.getRelocatedAddress(OffsetPtr);
break;
case DW_LNE_define_file:

View File

@ -40,9 +40,9 @@ void DWARFDebugLoc::dump(raw_ostream &OS) const {
}
}
void DWARFDebugLoc::parse(DataExtractor data, unsigned AddressSize) {
void DWARFDebugLoc::parse(const DWARFDataExtractor &data) {
uint32_t Offset = 0;
while (data.isValidOffset(Offset+AddressSize-1)) {
while (data.isValidOffset(Offset+data.getAddressSize()-1)) {
Locations.resize(Locations.size() + 1);
LocationList &Loc = Locations.back();
Loc.Offset = Offset;
@ -51,8 +51,8 @@ void DWARFDebugLoc::parse(DataExtractor data, unsigned AddressSize) {
while (true) {
// A beginning and ending address offsets.
Entry E;
E.Begin = getRelocatedValue(data, AddressSize, &Offset, &RelocMap);
E.End = getRelocatedValue(data, AddressSize, &Offset, &RelocMap);
E.Begin = data.getRelocatedAddress(&Offset);
E.End = data.getRelocatedAddress(&Offset);
// The end of any given location list is marked by an end of list entry,
// which consists of a 0 for the beginning address offset and a 0 for the

View File

@ -23,8 +23,8 @@ void DWARFDebugRangeList::clear() {
Entries.clear();
}
bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr,
const RelocAddrMap &Relocs) {
bool DWARFDebugRangeList::extract(const DWARFDataExtractor &data,
uint32_t *offset_ptr) {
clear();
if (!data.isValidOffset(*offset_ptr))
return false;
@ -35,10 +35,9 @@ bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr,
while (true) {
RangeListEntry entry;
uint32_t prev_offset = *offset_ptr;
entry.StartAddress = getRelocatedValue(data, AddressSize, offset_ptr,
&Relocs, &entry.SectionIndex);
entry.EndAddress =
getRelocatedValue(data, AddressSize, offset_ptr, &Relocs);
entry.StartAddress =
data.getRelocatedAddress(offset_ptr, &entry.SectionIndex);
entry.EndAddress = data.getRelocatedAddress(offset_ptr);
// Check that both values were extracted correctly.
if (*offset_ptr != prev_offset + 2 * AddressSize) {

View File

@ -308,7 +308,7 @@ void DWARFDie::dump(raw_ostream &OS, unsigned RecurseDepth, unsigned Indent,
DIDumpOptions DumpOpts) const {
if (!isValid())
return;
DataExtractor debug_info_data = U->getDebugInfoExtractor();
DWARFDataExtractor debug_info_data = U->getDebugInfoExtractor();
const uint32_t Offset = getOffset();
uint32_t offset = Offset;

View File

@ -275,7 +275,7 @@ bool DWARFFormValue::isFormClass(DWARFFormValue::FormClass FC) const {
FC == FC_SectionOffset;
}
bool DWARFFormValue::extractValue(const DataExtractor &Data,
bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data,
uint32_t *OffsetPtr, const DWARFUnit *CU) {
U = CU;
bool Indirect = false;
@ -290,10 +290,9 @@ bool DWARFFormValue::extractValue(const DataExtractor &Data,
case DW_FORM_ref_addr: {
if (!U)
return false;
uint16_t AddrSize = (Form == DW_FORM_addr) ? U->getAddressByteSize()
: U->getRefAddrByteSize();
Value.uval = getRelocatedValue(Data, AddrSize, OffsetPtr,
U->getRelocMap(), &Value.SectionIndex);
uint16_t Size = (Form == DW_FORM_addr) ? U->getAddressByteSize()
: U->getRefAddrByteSize();
Value.uval = Data.getRelocatedValue(Size, OffsetPtr, &Value.SectionIndex);
break;
}
case DW_FORM_exprloc:
@ -333,11 +332,9 @@ bool DWARFFormValue::extractValue(const DataExtractor &Data,
case DW_FORM_ref4:
case DW_FORM_ref_sup4:
case DW_FORM_strx4:
case DW_FORM_addrx4: {
const RelocAddrMap *RelocMap = U ? U->getRelocMap() : nullptr;
Value.uval = getRelocatedValue(Data, 4, OffsetPtr, RelocMap);
case DW_FORM_addrx4:
Value.uval = Data.getRelocatedValue(4, OffsetPtr);
break;
}
case DW_FORM_data8:
case DW_FORM_ref8:
case DW_FORM_ref_sup8:
@ -365,8 +362,8 @@ bool DWARFFormValue::extractValue(const DataExtractor &Data,
case DW_FORM_strp_sup: {
if (!U)
return false;
Value.uval = getRelocatedValue(Data, U->getDwarfOffsetByteSize(),
OffsetPtr, U->getRelocMap());
Value.uval =
Data.getRelocatedValue(U->getDwarfOffsetByteSize(), OffsetPtr);
break;
}
case DW_FORM_flag_present:

View File

@ -32,8 +32,7 @@ using namespace dwarf;
void DWARFUnitSectionBase::parse(DWARFContext &C, const DWARFSection &Section) {
parseImpl(C, Section, C.getDebugAbbrev(), &C.getRangeSection(),
C.getStringSection(), C.getStringOffsetSection(),
&C.getAddrSection(), C.getLineSection().Data, C.isLittleEndian(),
false);
&C.getAddrSection(), C.getLineSection(), C.isLittleEndian(), false);
}
void DWARFUnitSectionBase::parseDWO(DWARFContext &C,
@ -41,15 +40,15 @@ void DWARFUnitSectionBase::parseDWO(DWARFContext &C,
DWARFUnitIndex *Index) {
parseImpl(C, DWOSection, C.getDebugAbbrevDWO(), &C.getRangeDWOSection(),
C.getStringDWOSection(), C.getStringOffsetDWOSection(),
&C.getAddrSection(), C.getLineDWOSection().Data, C.isLittleEndian(),
&C.getAddrSection(), C.getLineDWOSection(), C.isLittleEndian(),
true);
}
DWARFUnit::DWARFUnit(DWARFContext &DC, const DWARFSection &Section,
const DWARFDebugAbbrev *DA, const DWARFSection *RS,
StringRef SS, const DWARFSection &SOS,
const DWARFSection *AOS, StringRef LS, bool LE, bool IsDWO,
const DWARFUnitSectionBase &UnitSection,
const DWARFSection *AOS, const DWARFSection &LS, bool LE,
bool IsDWO, const DWARFUnitSectionBase &UnitSection,
const DWARFUnitIndex::Entry *IndexEntry)
: Context(DC), InfoSection(Section), Abbrev(DA), RangeSection(RS),
LineSection(LS), StringSection(SS), StringOffsetSection(SOS),
@ -65,10 +64,9 @@ bool DWARFUnit::getAddrOffsetSectionItem(uint32_t Index,
uint32_t Offset = AddrOffsetSectionBase + Index * getAddressByteSize();
if (AddrOffsetSection->Data.size() < Offset + getAddressByteSize())
return false;
DataExtractor DA(AddrOffsetSection->Data, isLittleEndian,
getAddressByteSize());
Result = getRelocatedValue(DA, getAddressByteSize(), &Offset,
&AddrOffsetSection->Relocs);
DWARFDataExtractor DA(*AddrOffsetSection, isLittleEndian,
getAddressByteSize());
Result = DA.getRelocatedAddress(&Offset);
return true;
}
@ -78,9 +76,8 @@ bool DWARFUnit::getStringOffsetSectionItem(uint32_t Index,
uint32_t Offset = StringOffsetSectionBase + Index * ItemSize;
if (StringOffsetSection.Data.size() < Offset + ItemSize)
return false;
DataExtractor DA(StringOffsetSection.Data, isLittleEndian, 0);
Result = getRelocatedValue(DA, ItemSize, &Offset,
&StringOffsetSection.Relocs);
DWARFDataExtractor DA(StringOffsetSection, isLittleEndian, 0);
Result = DA.getRelocatedValue(ItemSize, &Offset);
return true;
}
@ -141,14 +138,13 @@ bool DWARFUnit::extract(DataExtractor debug_info, uint32_t *offset_ptr) {
}
bool DWARFUnit::extractRangeList(uint32_t RangeListOffset,
DWARFDebugRangeList &RangeList) const {
DWARFDebugRangeList &RangeList) const {
// Require that compile unit is extracted.
assert(!DieArray.empty());
DataExtractor RangesData(RangeSection->Data, isLittleEndian,
getAddressByteSize());
DWARFDataExtractor RangesData(*RangeSection, isLittleEndian,
getAddressByteSize());
uint32_t ActualRangeListOffset = RangeSectionBase + RangeListOffset;
return RangeList.extract(RangesData, &ActualRangeListOffset,
RangeSection->Relocs);
return RangeList.extract(RangesData, &ActualRangeListOffset);
}
void DWARFUnit::clear() {
@ -182,7 +178,7 @@ void DWARFUnit::extractDIEsToVector(
uint32_t DIEOffset = Offset + getHeaderSize();
uint32_t NextCUOffset = getNextUnitOffset();
DWARFDebugInfoEntry DIE;
DataExtractor DebugInfoData = getDebugInfoExtractor();
DWARFDataExtractor DebugInfoData = getDebugInfoExtractor();
uint32_t Depth = 0;
bool IsCUDie = true;

View File

@ -280,11 +280,10 @@ bool DWARFVerifier::handleDebugLine() {
bool DWARFVerifier::handleAppleNames() {
NumAppleNamesErrors = 0;
DataExtractor AppleNamesSection(DCtx.getAppleNamesSection().Data,
DCtx.isLittleEndian(), 0);
DWARFDataExtractor AppleNamesSection(DCtx.getAppleNamesSection(),
DCtx.isLittleEndian(), 0);
DataExtractor StrData(DCtx.getStringSection(), DCtx.isLittleEndian(), 0);
DWARFAcceleratorTable AppleNames(AppleNamesSection, StrData,
DCtx.getAppleNamesSection().Relocs);
DWARFAcceleratorTable AppleNames(AppleNamesSection, StrData);
if (!AppleNames.extract()) {
return true;

View File

@ -2212,7 +2212,7 @@ void DwarfLinker::keepDIEAndDependencies(RelocationManager &RelocMgr,
// Then we need to mark all the DIEs referenced by this DIE's
// attributes as kept.
DataExtractor Data = Unit.getDebugInfoExtractor();
DWARFDataExtractor Data = Unit.getDebugInfoExtractor();
const auto *Abbrev = Die.getAbbreviationDeclarationPtr();
uint32_t Offset = Die.getOffset() + getULEB128Size(Abbrev->getCode());
@ -2729,7 +2729,7 @@ DIE *DwarfLinker::DIECloner::cloneDIE(
}
// Extract and clone every attribute.
DataExtractor Data = U.getDebugInfoExtractor();
DWARFDataExtractor Data = U.getDebugInfoExtractor();
// Point to the next DIE (generally there is always at least a NULL
// entry after the current one). If this is a lone
// DW_TAG_compile_unit without any children, point to the next unit.
@ -2743,7 +2743,8 @@ DIE *DwarfLinker::DIECloner::cloneDIE(
// it. After testing, it seems there is no performance downside to
// doing the copy unconditionally, and it makes the code simpler.
SmallString<40> DIECopy(Data.getData().substr(Offset, NextOffset - Offset));
Data = DataExtractor(DIECopy, Data.isLittleEndian(), Data.getAddressSize());
Data =
DWARFDataExtractor(DIECopy, Data.isLittleEndian(), Data.getAddressSize());
// Modify the copy with relocated addresses.
if (RelocMgr.applyValidRelocs(DIECopy, Offset, Data.isLittleEndian())) {
// If we applied relocations, we store the value of high_pc that was
@ -2872,8 +2873,8 @@ void DwarfLinker::patchRangesForUnit(const CompileUnit &Unit,
DWARFDebugRangeList RangeList;
const auto &FunctionRanges = Unit.getFunctionRanges();
unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
DataExtractor RangeExtractor(OrigDwarf.getRangeSection().Data,
OrigDwarf.isLittleEndian(), AddressSize);
DWARFDataExtractor RangeExtractor(OrigDwarf.getRangeSection(),
OrigDwarf.isLittleEndian(), AddressSize);
auto InvalidRange = FunctionRanges.end(), CurrRange = InvalidRange;
DWARFUnit &OrigUnit = Unit.getOrigUnit();
auto OrigUnitDie = OrigUnit.getUnitDIE(false);
@ -2887,7 +2888,7 @@ void DwarfLinker::patchRangesForUnit(const CompileUnit &Unit,
for (const auto &RangeAttribute : Unit.getRangesAttributes()) {
uint32_t Offset = RangeAttribute.get();
RangeAttribute.set(Streamer->getRangesSectionSize());
RangeList.extract(RangeExtractor, &Offset, OrigDwarf.getRangeSection().Relocs);
RangeList.extract(RangeExtractor, &Offset);
const auto &Entries = RangeList.getEntries();
if (!Entries.empty()) {
const DWARFDebugRangeList::RangeListEntry &First = Entries.front();
@ -2983,11 +2984,10 @@ void DwarfLinker::patchLineTableForUnit(CompileUnit &Unit,
// Parse the original line info for the unit.
DWARFDebugLine::LineTable LineTable;
uint32_t StmtOffset = *StmtList;
StringRef LineData = OrigDwarf.getLineSection().Data;
DataExtractor LineExtractor(LineData, OrigDwarf.isLittleEndian(),
Unit.getOrigUnit().getAddressByteSize());
LineTable.parse(LineExtractor, &OrigDwarf.getLineSection().Relocs,
&StmtOffset);
DWARFDataExtractor LineExtractor(OrigDwarf.getLineSection(),
OrigDwarf.isLittleEndian(),
Unit.getOrigUnit().getAddressByteSize());
LineTable.parse(LineExtractor, &StmtOffset);
// This vector is the output line table.
std::vector<DWARFDebugLine::Row> NewRows;
@ -3086,6 +3086,7 @@ void DwarfLinker::patchLineTableForUnit(CompileUnit &Unit,
LineTable.Prologue.OpcodeBase > 13)
reportWarning("line table parameters mismatch. Cannot emit.");
else {
StringRef LineData = OrigDwarf.getLineSection().Data;
MCDwarfLineTableParams Params;
Params.DWARF2LineOpcodeBase = LineTable.Prologue.OpcodeBase;
Params.DWARF2LineBase = LineTable.Prologue.LineBase;

View File

@ -97,8 +97,8 @@ DWARFFormValue createDataXFormValue(dwarf::Form Form, RawTypeT Value) {
memcpy(Raw, &Value, sizeof(RawTypeT));
uint32_t Offset = 0;
DWARFFormValue Result(Form);
DataExtractor Data(StringRef(Raw, sizeof(RawTypeT)),
sys::IsLittleEndianHost, sizeof(void*));
DWARFDataExtractor Data(StringRef(Raw, sizeof(RawTypeT)),
sys::IsLittleEndianHost, sizeof(void *));
Result.extractValue(Data, &Offset, nullptr);
return Result;
}
@ -109,7 +109,7 @@ DWARFFormValue createULEBFormValue(uint64_t Value) {
encodeULEB128(Value, OS);
uint32_t Offset = 0;
DWARFFormValue Result(DW_FORM_udata);
DataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void*));
DWARFDataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void *));
Result.extractValue(Data, &Offset, nullptr);
return Result;
}
@ -120,7 +120,7 @@ DWARFFormValue createSLEBFormValue(int64_t Value) {
encodeSLEB128(Value, OS);
uint32_t Offset = 0;
DWARFFormValue Result(DW_FORM_sdata);
DataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void*));
DWARFDataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void *));
Result.extractValue(Data, &Offset, nullptr);
return Result;
}