Skip to content

Commit

Permalink
[DWARF] NFC: DWARFDataExtractor combines relocs with DataExtractor.
Browse files Browse the repository at this point in the history
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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306699 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
pogo59 committed Jun 29, 2017
1 parent a70a8a0 commit 502fd5d
Show file tree
Hide file tree
Showing 25 changed files with 194 additions and 160 deletions.
11 changes: 5 additions & 6 deletions include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/DebugInfo/DWARF/DWARFCompileUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class DWARFCompileUnit : public DWARFUnit {
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) {}
Expand Down
6 changes: 0 additions & 6 deletions include/llvm/DebugInfo/DWARF/DWARFContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions include/llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -40,8 +41,7 @@ class DWARFDebugInfoEntry {

/// 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; }
Expand Down
13 changes: 4 additions & 9 deletions include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -26,9 +26,6 @@ class raw_ostream;

class DWARFDebugLine {
public:
DWARFDebugLine(const RelocAddrMap *LineInfoRelocMap)
: RelocMap(LineInfoRelocMap) {}

struct FileNameEntry {
FileNameEntry() = default;

Expand Down Expand Up @@ -98,7 +95,7 @@ class DWARFDebugLine {

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.
Expand Down Expand Up @@ -220,8 +217,7 @@ class DWARFDebugLine {
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;
Expand All @@ -238,7 +234,7 @@ class DWARFDebugLine {
};

const LineTable *getLineTable(uint32_t Offset) const;
const LineTable *getOrParseLineTable(DataExtractor DebugLineData,
const LineTable *getOrParseLineTable(const DWARFDataExtractor &DebugLineData,
uint32_t Offset);

private:
Expand All @@ -261,7 +257,6 @@ class DWARFDebugLine {
using LineTableIter = LineTableMapTy::iterator;
using LineTableConstIter = LineTableMapTy::const_iterator;

const RelocAddrMap *RelocMap;
LineTableMapTy LineTableMap;
};

Expand Down
11 changes: 3 additions & 8 deletions include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -79,7 +79,7 @@ class DWARFDebugRangeList {

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
Expand Down
11 changes: 5 additions & 6 deletions include/llvm/DebugInfo/DWARF/DWARFFormValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -105,14 +105,13 @@ class DWARFFormValue {

/// 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 {
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/DebugInfo/DWARF/DWARFTypeUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DWARFTypeUnit : public DWARFUnit {
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,
Expand Down
19 changes: 10 additions & 9 deletions include/llvm/DebugInfo/DWARF/DWARFUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class DWARFUnitSectionBase {
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;
};

Expand Down Expand Up @@ -91,7 +91,7 @@ class DWARFUnitSection final : public SmallVector<std::unique_ptr<UnitType>, 1>,
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);
Expand All @@ -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;
Expand Down Expand Up @@ -166,15 +166,16 @@ class DWARFUnit {
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;
Expand All @@ -196,9 +197,9 @@ class DWARFUnit {
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 {
Expand Down
1 change: 1 addition & 0 deletions lib/DebugInfo/DWARF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_llvm_library(LLVMDebugInfoDWARF
DWARFAcceleratorTable.cpp
DWARFCompileUnit.cpp
DWARFContext.cpp
DWARFDataExtractor.cpp
DWARFDebugAbbrev.cpp
DWARFDebugArangeSet.cpp
DWARFDebugAranges.cpp
Expand Down
3 changes: 1 addition & 2 deletions lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 502fd5d

Please sign in to comment.