You've already forked llvm-project
mirror of
https://github.com/encounter/llvm-project.git
synced 2026-03-30 11:27:19 -07: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:
@@ -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();
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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; }
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -3,6 +3,7 @@ add_llvm_library(LLVMDebugInfoDWARF
|
||||
DWARFAcceleratorTable.cpp
|
||||
DWARFCompileUnit.cpp
|
||||
DWARFContext.cpp
|
||||
DWARFDataExtractor.cpp
|
||||
DWARFDebugAbbrev.cpp
|
||||
DWARFDebugArangeSet.cpp
|
||||
DWARFDebugAranges.cpp
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user