llvm.org GIT mirror llvm / 502fd5d
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306699 91177308-0d34-0410-b5e6-96231b3b80d8 Paul Robinson 2 years ago
25 changed file(s) with 195 addition(s) and 161 deletion(s). Raw diff Collapse all Expand all
1111
1212 #include "llvm/ADT/SmallVector.h"
1313 #include "llvm/BinaryFormat/Dwarf.h"
14 #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
1415 #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
15 #include "llvm/Support/DataExtractor.h"
1616 #include
1717 #include
1818
4040
4141 struct Header Hdr;
4242 struct HeaderData HdrData;
43 DataExtractor AccelSection;
43 DWARFDataExtractor AccelSection;
4444 DataExtractor StringSection;
45 const RelocAddrMap& Relocs;
4645
4746 public:
48 DWARFAcceleratorTable(DataExtractor AccelSection, DataExtractor StringSection,
49 const RelocAddrMap &Relocs)
50 : AccelSection(AccelSection), StringSection(StringSection), Relocs(Relocs) {}
47 DWARFAcceleratorTable(const DWARFDataExtractor &AccelSection,
48 DataExtractor StringSection)
49 : AccelSection(AccelSection), StringSection(StringSection) {}
5150
5251 bool extract();
5352 uint32_t getNumBuckets();
1919 DWARFCompileUnit(DWARFContext &Context, const DWARFSection &Section,
2020 const DWARFDebugAbbrev *DA, const DWARFSection *RS,
2121 StringRef SS, const DWARFSection &SOS,
22 const DWARFSection *AOS, StringRef LS, bool LE, bool IsDWO,
23 const DWARFUnitSectionBase &UnitSection,
22 const DWARFSection *AOS, const DWARFSection &LS, bool LE,
23 bool IsDWO, const DWARFUnitSectionBase &UnitSection,
2424 const DWARFUnitIndex::Entry *Entry)
2525 : DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LS, LE, IsDWO,
2626 UnitSection, Entry) {}
4444 class MemoryBuffer;
4545 class raw_ostream;
4646
47 /// Reads a value from data extractor and applies a relocation to the result if
48 /// one exists for the given offset.
49 uint64_t getRelocatedValue(const DataExtractor &Data, uint32_t Size,
50 uint32_t *Off, const RelocAddrMap *Relocs,
51 uint64_t *SecNdx = nullptr);
52
5347 /// DWARFContext
5448 /// This data structure is the top level entity that deals with dwarf debug
5549 /// information parsing. The actual data is supplied through pure virtual
0 //===- DWARFDataExtractor.h -------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H
10 #define LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H
11
12 #include "llvm/DebugInfo/DWARF/DWARFSection.h"
13 #include "llvm/Support/DataExtractor.h"
14
15 namespace llvm {
16
17 /// A DataExtractor (typically for an in-memory copy of an object-file section)
18 /// plus a relocation map for that section, if there is one.
19 class DWARFDataExtractor : public DataExtractor {
20 const RelocAddrMap *RelocMap = nullptr;
21 public:
22 /// Constructor for the normal case of extracting data from a DWARF section.
23 /// The DWARFSection's lifetime must be at least as long as the extractor's.
24 DWARFDataExtractor(const DWARFSection &Section, bool IsLittleEndian,
25 uint8_t AddressSize)
26 : DataExtractor(Section.Data, IsLittleEndian, AddressSize),
27 RelocMap(&Section.Relocs) {}
28
29 /// Constructor for cases when there are no relocations.
30 DWARFDataExtractor(StringRef Data, bool IsLittleEndian, uint8_t AddressSize)
31 : DataExtractor(Data, IsLittleEndian, AddressSize) {}
32
33 /// Extracts a value and applies a relocation to the result if
34 /// one exists for the given offset.
35 uint64_t getRelocatedValue(uint32_t Size, uint32_t *Off,
36 uint64_t *SectionIndex = nullptr) const;
37
38 /// Extracts an address-sized value and applies a relocation to the result if
39 /// one exists for the given offset.
40 uint64_t getRelocatedAddress(uint32_t *Off, uint64_t *SecIx = nullptr) const {
41 return getRelocatedValue(getAddressSize(), Off, SecIx);
42 }
43 };
44
45 } // end namespace llvm
46
47 #endif // LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H
1111
1212 #include "llvm/BinaryFormat/Dwarf.h"
1313 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
14 #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
1415 #include
1516
1617 namespace llvm {
3940
4041 /// High performance extraction should use this call.
4142 bool extractFast(const DWARFUnit &U, uint32_t *OffsetPtr,
42 const DataExtractor &DebugInfoData,
43 uint32_t UEndOffset,
43 const DWARFDataExtractor &DebugInfoData, uint32_t UEndOffset,
4444 uint32_t Depth);
4545
4646 uint32_t getOffset() const { return Offset; }
1111
1212 #include "llvm/ADT/StringRef.h"
1313 #include "llvm/DebugInfo/DIContext.h"
14 #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
1415 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
1516 #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
16 #include "llvm/Support/DataExtractor.h"
1717 #include
1818 #include
1919 #include
2525
2626 class DWARFDebugLine {
2727 public:
28 DWARFDebugLine(const RelocAddrMap *LineInfoRelocMap)
29 : RelocMap(LineInfoRelocMap) {}
30
3128 struct FileNameEntry {
3229 FileNameEntry() = default;
3330
9794
9895 void clear();
9996 void dump(raw_ostream &OS) const;
100 bool parse(DataExtractor DebugLineData, uint32_t *OffsetPtr);
97 bool parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr);
10198 };
10299
103100 /// Standard .debug_line state machine structure.
219216 void clear();
220217
221218 /// Parse prologue and all rows.
222 bool parse(DataExtractor DebugLineData, const RelocAddrMap *RMap,
223 uint32_t *OffsetPtr);
219 bool parse(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr);
224220
225221 using RowVector = std::vector;
226222 using RowIter = RowVector::const_iterator;
237233 };
238234
239235 const LineTable *getLineTable(uint32_t Offset) const;
240 const LineTable *getOrParseLineTable(DataExtractor DebugLineData,
236 const LineTable *getOrParseLineTable(const DWARFDataExtractor &DebugLineData,
241237 uint32_t Offset);
242238
243239 private:
260256 using LineTableIter = LineTableMapTy::iterator;
261257 using LineTableConstIter = LineTableMapTy::const_iterator;
262258
263 const RelocAddrMap *RelocMap;
264259 LineTableMapTy LineTableMap;
265260 };
266261
1010 #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGLOC_H
1111
1212 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
1314 #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
14 #include "llvm/Support/DataExtractor.h"
1515 #include
1616
1717 namespace llvm {
4444 /// the locations in which the variable is stored.
4545 LocationLists Locations;
4646
47 /// A map used to resolve binary relocations.
48 const RelocAddrMap &RelocMap;
49
5047 public:
51 DWARFDebugLoc(const RelocAddrMap &LocRelocMap) : RelocMap(LocRelocMap) {}
52
5348 /// Print the location lists found within the debug_loc section.
5449 void dump(raw_ostream &OS) const;
5550
5651 /// Parse the debug_loc section accessible via the 'data' parameter using the
57 /// specified address size to interpret the address ranges.
58 void parse(DataExtractor data, unsigned AddressSize);
52 /// address size also given in 'data' to interpret the address ranges.
53 void parse(const DWARFDataExtractor &data);
5954 };
6055
6156 class DWARFDebugLocDWO {
99 #ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGRANGELIST_H
1010 #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGRANGELIST_H
1111
12 #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
1213 #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
13 #include "llvm/Support/DataExtractor.h"
1414 #include
1515 #include
1616 #include
7878
7979 void clear();
8080 void dump(raw_ostream &OS) const;
81 bool extract(DataExtractor data, uint32_t *offset_ptr, const RelocAddrMap& Relocs);
81 bool extract(const DWARFDataExtractor &data, uint32_t *offset_ptr);
8282 const std::vector &getEntries() { return Entries; }
8383
8484 /// getAbsoluteRanges - Returns absolute address ranges defined by this range
1313 #include "llvm/ADT/None.h"
1414 #include "llvm/ADT/Optional.h"
1515 #include "llvm/BinaryFormat/Dwarf.h"
16 #include "llvm/Support/DataExtractor.h"
16 #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
1717 #include
1818
1919 namespace llvm {
104104
105105 /// Extracts a value in \p Data at offset \p *OffsetPtr.
106106 ///
107 /// The passed DWARFUnit is allowed to be nullptr, in which
108 /// case no relocation processing will be performed and some
107 /// The passed DWARFUnit is allowed to be nullptr, in which case some
109108 /// kind of forms that depend on Unit information are disallowed.
110 /// \param Data The DataExtractor to use.
111 /// \param OffsetPtr The offset within DataExtractor where the data starts.
109 /// \param Data The DWARFDataExtractor to use.
110 /// \param OffsetPtr The offset within \p Data where the data starts.
112111 /// \param U The optional DWARFUnit supplying information for some forms.
113112 /// \returns whether the extraction succeeded.
114 bool extractValue(const DataExtractor &Data, uint32_t *OffsetPtr,
113 bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr,
115114 const DWARFUnit *U);
116115
117116 bool isInlinedCStr() const {
3131 DWARFTypeUnit(DWARFContext &Context, const DWARFSection &Section,
3232 const DWARFDebugAbbrev *DA, const DWARFSection *RS,
3333 StringRef SS, const DWARFSection &SOS, const DWARFSection *AOS,
34 StringRef LS, bool LE, bool IsDWO,
34 const DWARFSection &LS, bool LE, bool IsDWO,
3535 const DWARFUnitSectionBase &UnitSection,
3636 const DWARFUnitIndex::Entry *Entry)
3737 : DWARFUnit(Context, Section, DA, RS, SS, SOS, AOS, LS, LE, IsDWO,
5757 virtual void parseImpl(DWARFContext &Context, const DWARFSection &Section,
5858 const DWARFDebugAbbrev *DA, const DWARFSection *RS,
5959 StringRef SS, const DWARFSection &SOS,
60 const DWARFSection *AOS, StringRef LS,
60 const DWARFSection *AOS, const DWARFSection &LS,
6161 bool isLittleEndian, bool isDWO) = 0;
6262 };
6363
9090 void parseImpl(DWARFContext &Context, const DWARFSection &Section,
9191 const DWARFDebugAbbrev *DA, const DWARFSection *RS,
9292 StringRef SS, const DWARFSection &SOS, const DWARFSection *AOS,
93 StringRef LS, bool LE, bool IsDWO) override {
93 const DWARFSection &LS, bool LE, bool IsDWO) override {
9494 if (Parsed)
9595 return;
9696 const auto &Index = getDWARFUnitIndex(Context, UnitType::Section);
117117 const DWARFDebugAbbrev *Abbrev;
118118 const DWARFSection *RangeSection;
119119 uint32_t RangeSectionBase;
120 StringRef LineSection;
120 const DWARFSection &LineSection;
121121 StringRef StringSection;
122122 const DWARFSection &StringOffsetSection;
123123 uint64_t StringOffsetSectionBase = 0;
165165 public:
166166 DWARFUnit(DWARFContext &Context, const DWARFSection &Section,
167167 const DWARFDebugAbbrev *DA, const DWARFSection *RS, StringRef SS,
168 const DWARFSection &SOS, const DWARFSection *AOS, StringRef LS,
169 bool LE, bool IsDWO, const DWARFUnitSectionBase &UnitSection,
168 const DWARFSection &SOS, const DWARFSection *AOS,
169 const DWARFSection &LS, bool LE, bool IsDWO,
170 const DWARFUnitSectionBase &UnitSection,
170171 const DWARFUnitIndex::Entry *IndexEntry = nullptr);
171172
172173 virtual ~DWARFUnit();
173174
174175 DWARFContext& getContext() const { return Context; }
175176
176 StringRef getLineSection() const { return LineSection; }
177 const DWARFSection &getLineSection() const { return LineSection; }
177178 StringRef getStringSection() const { return StringSection; }
178179 const DWARFSection &getStringOffsetSection() const {
179180 return StringOffsetSection;
195196 bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
196197 bool getStringOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
197198
198 DataExtractor getDebugInfoExtractor() const {
199 return DataExtractor(InfoSection.Data, isLittleEndian,
200 getAddressByteSize());
199 DWARFDataExtractor getDebugInfoExtractor() const {
200 return DWARFDataExtractor(InfoSection, isLittleEndian,
201 getAddressByteSize());
201202 }
202203
203204 DataExtractor getStringExtractor() const {
22 DWARFAcceleratorTable.cpp
33 DWARFCompileUnit.cpp
44 DWARFContext.cpp
5 DWARFDataExtractor.cpp
56 DWARFDebugAbbrev.cpp
67 DWARFDebugArangeSet.cpp
78 DWARFDebugAranges.cpp
120120 continue;
121121 }
122122 while (AccelSection.isValidOffsetForDataOfSize(DataOffset, 4)) {
123 unsigned StringOffset =
124 getRelocatedValue(AccelSection, 4, &DataOffset, &Relocs);
123 unsigned StringOffset = AccelSection.getRelocatedValue(4, &DataOffset);
125124 if (!StringOffset)
126125 break;
127126 OS << format(" Name: %08x \"%s\"\n", StringOffset,
5858 using FileLineInfoKind = DILineInfoSpecifier::FileLineInfoKind;
5959 using FunctionNameKind = DILineInfoSpecifier::FunctionNameKind;
6060
61 uint64_t llvm::getRelocatedValue(const DataExtractor &Data, uint32_t Size,
62 uint32_t *Off, const RelocAddrMap *Relocs,
63 uint64_t *SectionIndex) {
64 if (!Relocs)
65 return Data.getUnsigned(Off, Size);
66 RelocAddrMap::const_iterator AI = Relocs->find(*Off);
67 if (AI == Relocs->end())
68 return Data.getUnsigned(Off, Size);
69 if (SectionIndex)
70 *SectionIndex = AI->second.SectionIndex;
71 return Data.getUnsigned(Off, Size) + AI->second.Value;
72 }
73
7461 static void dumpAccelSection(raw_ostream &OS, StringRef Name,
7562 const DWARFSection& Section, StringRef StringSection,
7663 bool LittleEndian) {
77 DataExtractor AccelSection(Section.Data, LittleEndian, 0);
64 DWARFDataExtractor AccelSection(Section, LittleEndian, 0);
7865 DataExtractor StrData(StringSection, LittleEndian, 0);
7966 OS << "\n." << Name << " contents:\n";
80 DWARFAcceleratorTable Accel(AccelSection, StrData, Section.Relocs);
67 DWARFAcceleratorTable Accel(AccelSection, StrData);
8168 if (!Accel.extract())
8269 return;
8370 Accel.dump(OS);
8774 dumpDWARFv5StringOffsetsSection(raw_ostream &OS, StringRef SectionName,
8875 const DWARFSection &StringOffsetsSection,
8976 StringRef StringSection, bool LittleEndian) {
90 DataExtractor StrOffsetExt(StringOffsetsSection.Data, LittleEndian, 0);
77 DWARFDataExtractor StrOffsetExt(StringOffsetsSection, LittleEndian, 0);
9178 uint32_t Offset = 0;
9279 uint64_t SectionSize = StringOffsetsSection.Data.size();
9380
143130 while (Offset - ContributionBase < ContributionSize) {
144131 OS << format("0x%8.8x: ", Offset);
145132 // FIXME: We can only extract strings in DWARF32 format at the moment.
146 uint64_t StringOffset = getRelocatedValue(
147 StrOffsetExt, EntrySize, &Offset, &StringOffsetsSection.Relocs);
133 uint64_t StringOffset =
134 StrOffsetExt.getRelocatedValue(EntrySize, &Offset);
148135 if (Format == DWARF32) {
149136 OS << format("%8.8x ", StringOffset);
150137 uint32_t StringOffset32 = (uint32_t)StringOffset;
286273 if (!CUDIE)
287274 continue;
288275 if (auto StmtOffset = toSectionOffset(CUDIE.find(DW_AT_stmt_list))) {
289 DataExtractor lineData(getLineSection().Data, isLittleEndian(),
290 savedAddressByteSize);
276 DWARFDataExtractor lineData(getLineSection(), isLittleEndian(),
277 savedAddressByteSize);
291278 DWARFDebugLine::LineTable LineTable;
292279 uint32_t Offset = *StmtOffset;
293 LineTable.parse(lineData, &getLineSection().Relocs, &Offset);
280 LineTable.parse(lineData, &Offset);
294281 LineTable.dump(OS);
295282 }
296283 }
309296 if (DumpType == DIDT_All || DumpType == DIDT_LineDwo) {
310297 OS << "\n.debug_line.dwo contents:\n";
311298 unsigned stmtOffset = 0;
312 DataExtractor lineData(getLineDWOSection().Data, isLittleEndian(),
313 savedAddressByteSize);
299 DWARFDataExtractor lineData(getLineDWOSection(), isLittleEndian(),
300 savedAddressByteSize);
314301 DWARFDebugLine::LineTable LineTable;
315302 while (LineTable.Prologue.parse(lineData, &stmtOffset)) {
316303 LineTable.dump(OS);
347334 // sizes, but for simplicity we just use the address byte size of the last
348335 // compile unit (there is no easy and fast way to associate address range
349336 // list and the compile unit it describes).
350 DataExtractor rangesData(getRangeSection().Data, isLittleEndian(),
351 savedAddressByteSize);
337 DWARFDataExtractor rangesData(getRangeSection(), isLittleEndian(),
338 savedAddressByteSize);
352339 offset = 0;
353340 DWARFDebugRangeList rangeList;
354 while (rangeList.extract(rangesData, &offset, getRangeSection().Relocs))
341 while (rangeList.extract(rangesData, &offset))
355342 rangeList.dump(OS);
356343 }
357344
498485 if (Loc)
499486 return Loc.get();
500487
501 DataExtractor LocData(getLocSection().Data, isLittleEndian(), 0);
502 Loc.reset(new DWARFDebugLoc(getLocSection().Relocs));
488 Loc.reset(new DWARFDebugLoc);
503489 // assume all compile units have the same address byte size
504 if (getNumCompileUnits())
505 Loc->parse(LocData, getCompileUnitAtIndex(0)->getAddressByteSize());
490 if (getNumCompileUnits()) {
491 DWARFDataExtractor LocData(getLocSection(), isLittleEndian(),
492 getCompileUnitAtIndex(0)->getAddressByteSize());
493 Loc->parse(LocData);
494 }
506495 return Loc.get();
507496 }
508497
569558 const DWARFLineTable *
570559 DWARFContext::getLineTableForUnit(DWARFUnit *U) {
571560 if (!Line)
572 Line.reset(new DWARFDebugLine(&getLineSection().Relocs));
561 Line.reset(new DWARFDebugLine);
573562
574563 auto UnitDIE = U->getUnitDIE();
575564 if (!UnitDIE)
585574 return lt;
586575
587576 // Make sure the offset is good before we try to parse.
588 if (stmtOffset >= U->getLineSection().size())
577 if (stmtOffset >= U->getLineSection().Data.size())
589578 return nullptr;
590579
591580 // We have to parse it first.
592 DataExtractor lineData(U->getLineSection(), isLittleEndian(),
593 U->getAddressByteSize());
581 DWARFDataExtractor lineData(U->getLineSection(), isLittleEndian(),
582 U->getAddressByteSize());
594583 return Line->getOrParseLineTable(lineData, stmtOffset);
595584 }
596585
0 //===- DWARFDataExtractor.cpp ---------------------------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
10
11 using namespace llvm;
12
13 uint64_t DWARFDataExtractor::getRelocatedValue(uint32_t Size, uint32_t *Off,
14 uint64_t *SecNdx) const {
15 if (!RelocMap)
16 return getUnsigned(Off, Size);
17 RelocAddrMap::const_iterator AI = RelocMap->find(*Off);
18 if (AI == RelocMap->end())
19 return getUnsigned(Off, Size);
20 if (SecNdx)
21 *SecNdx = AI->second.SectionIndex;
22 return getUnsigned(Off, Size) + AI->second.Value;
23 }
2020
2121 bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U,
2222 uint32_t *OffsetPtr) {
23 DataExtractor DebugInfoData = U.getDebugInfoExtractor();
23 DWARFDataExtractor DebugInfoData = U.getDebugInfoExtractor();
2424 const uint32_t UEndOffset = U.getNextUnitOffset();
2525 return extractFast(U, OffsetPtr, DebugInfoData, UEndOffset, 0);
2626 }
2727
2828 bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint32_t *OffsetPtr,
29 const DataExtractor &DebugInfoData,
29 const DWARFDataExtractor &DebugInfoData,
3030 uint32_t UEndOffset, uint32_t D) {
3131 Offset = *OffsetPtr;
3232 Depth = D;
9393
9494 // Parse v2-v4 directory and file tables.
9595 static void
96 parseV2DirFileTables(DataExtractor DebugLineData, uint32_t *OffsetPtr,
97 uint64_t EndPrologueOffset,
96 parseV2DirFileTables(const DWARFDataExtractor &DebugLineData,
97 uint32_t *OffsetPtr, uint64_t EndPrologueOffset,
9898 std::vector &IncludeDirectories,
9999 std::vector &FileNames) {
100100 while (*OffsetPtr < EndPrologueOffset) {
121121 // Returns the descriptors, or an empty vector if we did not find a path or
122122 // ran off the end of the prologue.
123123 static ContentDescriptors
124 parseV5EntryFormat(DataExtractor DebugLineData, uint32_t *OffsetPtr,
124 parseV5EntryFormat(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr,
125125 uint64_t EndPrologueOffset) {
126126 ContentDescriptors Descriptors;
127127 int FormatCount = DebugLineData.getU8(OffsetPtr);
141141 }
142142
143143 static bool
144 parseV5DirFileTables(DataExtractor DebugLineData, uint32_t *OffsetPtr,
145 uint64_t EndPrologueOffset,
144 parseV5DirFileTables(const DWARFDataExtractor &DebugLineData,
145 uint32_t *OffsetPtr, uint64_t EndPrologueOffset,
146146 const DWARFFormParams &FormParams,
147147 std::vector &IncludeDirectories,
148148 std::vector &FileNames) {
211211 return true;
212212 }
213213
214 bool DWARFDebugLine::Prologue::parse(DataExtractor DebugLineData,
214 bool DWARFDebugLine::Prologue::parse(const DWARFDataExtractor &DebugLineData,
215215 uint32_t *OffsetPtr) {
216216 const uint64_t PrologueOffset = *OffsetPtr;
217217
380380 }
381381
382382 const DWARFDebugLine::LineTable *
383 DWARFDebugLine::getOrParseLineTable(DataExtractor DebugLineData,
383 DWARFDebugLine::getOrParseLineTable(const DWARFDataExtractor &DebugLineData,
384384 uint32_t Offset) {
385385 std::pair Pos =
386386 LineTableMap.insert(LineTableMapTy::value_type(Offset, LineTable()));
387387 LineTable *LT = &Pos.first->second;
388388 if (Pos.second) {
389 if (!LT->parse(DebugLineData, RelocMap, &Offset))
389 if (!LT->parse(DebugLineData, &Offset))
390390 return nullptr;
391391 }
392392 return LT;
393393 }
394394
395 bool DWARFDebugLine::LineTable::parse(DataExtractor DebugLineData,
396 const RelocAddrMap *RMap,
395 bool DWARFDebugLine::LineTable::parse(const DWARFDataExtractor &DebugLineData,
397396 uint32_t *OffsetPtr) {
398397 const uint32_t DebugLineOffset = *OffsetPtr;
399398
442441 // relocatable address. All of the other statement program opcodes
443442 // that affect the address register add a delta to it. This instruction
444443 // stores a relocatable value into it instead.
445 State.Row.Address = getRelocatedValue(
446 DebugLineData, DebugLineData.getAddressSize(), OffsetPtr, RMap);
444 State.Row.Address = DebugLineData.getRelocatedAddress(OffsetPtr);
447445 break;
448446
449447 case DW_LNE_define_file:
3939 }
4040 }
4141
42 void DWARFDebugLoc::parse(DataExtractor data, unsigned AddressSize) {
42 void DWARFDebugLoc::parse(const DWARFDataExtractor &data) {
4343 uint32_t Offset = 0;
44 while (data.isValidOffset(Offset+AddressSize-1)) {
44 while (data.isValidOffset(Offset+data.getAddressSize()-1)) {
4545 Locations.resize(Locations.size() + 1);
4646 LocationList &Loc = Locations.back();
4747 Loc.Offset = Offset;
5050 while (true) {
5151 // A beginning and ending address offsets.
5252 Entry E;
53 E.Begin = getRelocatedValue(data, AddressSize, &Offset, &RelocMap);
54 E.End = getRelocatedValue(data, AddressSize, &Offset, &RelocMap);
53 E.Begin = data.getRelocatedAddress(&Offset);
54 E.End = data.getRelocatedAddress(&Offset);
5555
5656 // The end of any given location list is marked by an end of list entry,
5757 // which consists of a 0 for the beginning address offset and a 0 for the
2222 Entries.clear();
2323 }
2424
25 bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr,
26 const RelocAddrMap &Relocs) {
25 bool DWARFDebugRangeList::extract(const DWARFDataExtractor &data,
26 uint32_t *offset_ptr) {
2727 clear();
2828 if (!data.isValidOffset(*offset_ptr))
2929 return false;
3434 while (true) {
3535 RangeListEntry entry;
3636 uint32_t prev_offset = *offset_ptr;
37 entry.StartAddress = getRelocatedValue(data, AddressSize, offset_ptr,
38 &Relocs, &entry.SectionIndex);
39 entry.EndAddress =
40 getRelocatedValue(data, AddressSize, offset_ptr, &Relocs);
37 entry.StartAddress =
38 data.getRelocatedAddress(offset_ptr, &entry.SectionIndex);
39 entry.EndAddress = data.getRelocatedAddress(offset_ptr);
4140
4241 // Check that both values were extracted correctly.
4342 if (*offset_ptr != prev_offset + 2 * AddressSize) {
307307 DIDumpOptions DumpOpts) const {
308308 if (!isValid())
309309 return;
310 DataExtractor debug_info_data = U->getDebugInfoExtractor();
310 DWARFDataExtractor debug_info_data = U->getDebugInfoExtractor();
311311 const uint32_t Offset = getOffset();
312312 uint32_t offset = Offset;
313313
274274 FC == FC_SectionOffset;
275275 }
276276
277 bool DWARFFormValue::extractValue(const DataExtractor &Data,
277 bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data,
278278 uint32_t *OffsetPtr, const DWARFUnit *CU) {
279279 U = CU;
280280 bool Indirect = false;
289289 case DW_FORM_ref_addr: {
290290 if (!U)
291291 return false;
292 uint16_t AddrSize = (Form == DW_FORM_addr) ? U->getAddressByteSize()
293 : U->getRefAddrByteSize();
294 Value.uval = getRelocatedValue(Data, AddrSize, OffsetPtr,
295 U->getRelocMap(), &Value.SectionIndex);
292 uint16_t Size = (Form == DW_FORM_addr) ? U->getAddressByteSize()
293 : U->getRefAddrByteSize();
294 Value.uval = Data.getRelocatedValue(Size, OffsetPtr, &Value.SectionIndex);
296295 break;
297296 }
298297 case DW_FORM_exprloc:
332331 case DW_FORM_ref4:
333332 case DW_FORM_ref_sup4:
334333 case DW_FORM_strx4:
335 case DW_FORM_addrx4: {
336 const RelocAddrMap *RelocMap = U ? U->getRelocMap() : nullptr;
337 Value.uval = getRelocatedValue(Data, 4, OffsetPtr, RelocMap);
338 break;
339 }
334 case DW_FORM_addrx4:
335 Value.uval = Data.getRelocatedValue(4, OffsetPtr);
336 break;
340337 case DW_FORM_data8:
341338 case DW_FORM_ref8:
342339 case DW_FORM_ref_sup8:
364361 case DW_FORM_strp_sup: {
365362 if (!U)
366363 return false;
367 Value.uval = getRelocatedValue(Data, U->getDwarfOffsetByteSize(),
368 OffsetPtr, U->getRelocMap());
364 Value.uval =
365 Data.getRelocatedValue(U->getDwarfOffsetByteSize(), OffsetPtr);
369366 break;
370367 }
371368 case DW_FORM_flag_present:
3131 void DWARFUnitSectionBase::parse(DWARFContext &C, const DWARFSection &Section) {
3232 parseImpl(C, Section, C.getDebugAbbrev(), &C.getRangeSection(),
3333 C.getStringSection(), C.getStringOffsetSection(),
34 &C.getAddrSection(), C.getLineSection().Data, C.isLittleEndian(),
35 false);
34 &C.getAddrSection(), C.getLineSection(), C.isLittleEndian(), false);
3635 }
3736
3837 void DWARFUnitSectionBase::parseDWO(DWARFContext &C,
4039 DWARFUnitIndex *Index) {
4140 parseImpl(C, DWOSection, C.getDebugAbbrevDWO(), &C.getRangeDWOSection(),
4241 C.getStringDWOSection(), C.getStringOffsetDWOSection(),
43 &C.getAddrSection(), C.getLineDWOSection().Data, C.isLittleEndian(),
42 &C.getAddrSection(), C.getLineDWOSection(), C.isLittleEndian(),
4443 true);
4544 }
4645
4746 DWARFUnit::DWARFUnit(DWARFContext &DC, const DWARFSection &Section,
4847 const DWARFDebugAbbrev *DA, const DWARFSection *RS,
4948 StringRef SS, const DWARFSection &SOS,
50 const DWARFSection *AOS, StringRef LS, bool LE, bool IsDWO,
51 const DWARFUnitSectionBase &UnitSection,
49 const DWARFSection *AOS, const DWARFSection &LS, bool LE,
50 bool IsDWO, const DWARFUnitSectionBase &UnitSection,
5251 const DWARFUnitIndex::Entry *IndexEntry)
5352 : Context(DC), InfoSection(Section), Abbrev(DA), RangeSection(RS),
5453 LineSection(LS), StringSection(SS), StringOffsetSection(SOS),
6463 uint32_t Offset = AddrOffsetSectionBase + Index * getAddressByteSize();
6564 if (AddrOffsetSection->Data.size() < Offset + getAddressByteSize())
6665 return false;
67 DataExtractor DA(AddrOffsetSection->Data, isLittleEndian,
68 getAddressByteSize());
69 Result = getRelocatedValue(DA, getAddressByteSize(), &Offset,
70 &AddrOffsetSection->Relocs);
66 DWARFDataExtractor DA(*AddrOffsetSection, isLittleEndian,
67 getAddressByteSize());
68 Result = DA.getRelocatedAddress(&Offset);
7169 return true;
7270 }
7371
7775 uint32_t Offset = StringOffsetSectionBase + Index * ItemSize;
7876 if (StringOffsetSection.Data.size() < Offset + ItemSize)
7977 return false;
80 DataExtractor DA(StringOffsetSection.Data, isLittleEndian, 0);
81 Result = getRelocatedValue(DA, ItemSize, &Offset,
82 &StringOffsetSection.Relocs);
78 DWARFDataExtractor DA(StringOffsetSection, isLittleEndian, 0);
79 Result = DA.getRelocatedValue(ItemSize, &Offset);
8380 return true;
8481 }
8582
140137 }
141138
142139 bool DWARFUnit::extractRangeList(uint32_t RangeListOffset,
143 DWARFDebugRangeList &RangeList) const {
140 DWARFDebugRangeList &RangeList) const {
144141 // Require that compile unit is extracted.
145142 assert(!DieArray.empty());
146 DataExtractor RangesData(RangeSection->Data, isLittleEndian,
147 getAddressByteSize());
143 DWARFDataExtractor RangesData(*RangeSection, isLittleEndian,
144 getAddressByteSize());
148145 uint32_t ActualRangeListOffset = RangeSectionBase + RangeListOffset;
149 return RangeList.extract(RangesData, &ActualRangeListOffset,
150 RangeSection->Relocs);
146 return RangeList.extract(RangesData, &ActualRangeListOffset);
151147 }
152148
153149 void DWARFUnit::clear() {
181177 uint32_t DIEOffset = Offset + getHeaderSize();
182178 uint32_t NextCUOffset = getNextUnitOffset();
183179 DWARFDebugInfoEntry DIE;
184 DataExtractor DebugInfoData = getDebugInfoExtractor();
180 DWARFDataExtractor DebugInfoData = getDebugInfoExtractor();
185181 uint32_t Depth = 0;
186182 bool IsCUDie = true;
187183
279279 bool DWARFVerifier::handleAppleNames() {
280280 NumAppleNamesErrors = 0;
281281
282 DataExtractor AppleNamesSection(DCtx.getAppleNamesSection().Data,
283 DCtx.isLittleEndian(), 0);
282 DWARFDataExtractor AppleNamesSection(DCtx.getAppleNamesSection(),
283 DCtx.isLittleEndian(), 0);
284284 DataExtractor StrData(DCtx.getStringSection(), DCtx.isLittleEndian(), 0);
285 DWARFAcceleratorTable AppleNames(AppleNamesSection, StrData,
286 DCtx.getAppleNamesSection().Relocs);
285 DWARFAcceleratorTable AppleNames(AppleNamesSection, StrData);
287286
288287 if (!AppleNames.extract()) {
289288 return true;
22112211
22122212 // Then we need to mark all the DIEs referenced by this DIE's
22132213 // attributes as kept.
2214 DataExtractor Data = Unit.getDebugInfoExtractor();
2214 DWARFDataExtractor Data = Unit.getDebugInfoExtractor();
22152215 const auto *Abbrev = Die.getAbbreviationDeclarationPtr();
22162216 uint32_t Offset = Die.getOffset() + getULEB128Size(Abbrev->getCode());
22172217
27282728 }
27292729
27302730 // Extract and clone every attribute.
2731 DataExtractor Data = U.getDebugInfoExtractor();
2731 DWARFDataExtractor Data = U.getDebugInfoExtractor();
27322732 // Point to the next DIE (generally there is always at least a NULL
27332733 // entry after the current one). If this is a lone
27342734 // DW_TAG_compile_unit without any children, point to the next unit.
27422742 // it. After testing, it seems there is no performance downside to
27432743 // doing the copy unconditionally, and it makes the code simpler.
27442744 SmallString<40> DIECopy(Data.getData().substr(Offset, NextOffset - Offset));
2745 Data = DataExtractor(DIECopy, Data.isLittleEndian(), Data.getAddressSize());
2745 Data =
2746 DWARFDataExtractor(DIECopy, Data.isLittleEndian(), Data.getAddressSize());
27462747 // Modify the copy with relocated addresses.
27472748 if (RelocMgr.applyValidRelocs(DIECopy, Offset, Data.isLittleEndian())) {
27482749 // If we applied relocations, we store the value of high_pc that was
28712872 DWARFDebugRangeList RangeList;
28722873 const auto &FunctionRanges = Unit.getFunctionRanges();
28732874 unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
2874 DataExtractor RangeExtractor(OrigDwarf.getRangeSection().Data,
2875 OrigDwarf.isLittleEndian(), AddressSize);
2875 DWARFDataExtractor RangeExtractor(OrigDwarf.getRangeSection(),
2876 OrigDwarf.isLittleEndian(), AddressSize);
28762877 auto InvalidRange = FunctionRanges.end(), CurrRange = InvalidRange;
28772878 DWARFUnit &OrigUnit = Unit.getOrigUnit();
28782879 auto OrigUnitDie = OrigUnit.getUnitDIE(false);
28862887 for (const auto &RangeAttribute : Unit.getRangesAttributes()) {
28872888 uint32_t Offset = RangeAttribute.get();
28882889 RangeAttribute.set(Streamer->getRangesSectionSize());
2889 RangeList.extract(RangeExtractor, &Offset, OrigDwarf.getRangeSection().Relocs);
2890 RangeList.extract(RangeExtractor, &Offset);
28902891 const auto &Entries = RangeList.getEntries();
28912892 if (!Entries.empty()) {
28922893 const DWARFDebugRangeList::RangeListEntry &First = Entries.front();
29822983 // Parse the original line info for the unit.
29832984 DWARFDebugLine::LineTable LineTable;
29842985 uint32_t StmtOffset = *StmtList;
2985 StringRef LineData = OrigDwarf.getLineSection().Data;
2986 DataExtractor LineExtractor(LineData, OrigDwarf.isLittleEndian(),
2987 Unit.getOrigUnit().getAddressByteSize());
2988 LineTable.parse(LineExtractor, &OrigDwarf.getLineSection().Relocs,
2989 &StmtOffset);
2986 DWARFDataExtractor LineExtractor(OrigDwarf.getLineSection(),
2987 OrigDwarf.isLittleEndian(),
2988 Unit.getOrigUnit().getAddressByteSize());
2989 LineTable.parse(LineExtractor, &StmtOffset);
29902990
29912991 // This vector is the output line table.
29922992 std::vector NewRows;
30853085 LineTable.Prologue.OpcodeBase > 13)
30863086 reportWarning("line table parameters mismatch. Cannot emit.");
30873087 else {
3088 StringRef LineData = OrigDwarf.getLineSection().Data;
30883089 MCDwarfLineTableParams Params;
30893090 Params.DWARF2LineOpcodeBase = LineTable.Prologue.OpcodeBase;
30903091 Params.DWARF2LineBase = LineTable.Prologue.LineBase;
9696 memcpy(Raw, &Value, sizeof(RawTypeT));
9797 uint32_t Offset = 0;
9898 DWARFFormValue Result(Form);
99 DataExtractor Data(StringRef(Raw, sizeof(RawTypeT)),
100 sys::IsLittleEndianHost, sizeof(void*));
99 DWARFDataExtractor Data(StringRef(Raw, sizeof(RawTypeT)),
100 sys::IsLittleEndianHost, sizeof(void *));
101101 Result.extractValue(Data, &Offset, nullptr);
102102 return Result;
103103 }
108108 encodeULEB128(Value, OS);
109109 uint32_t Offset = 0;
110110 DWARFFormValue Result(DW_FORM_udata);
111 DataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void*));
111 DWARFDataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void *));
112112 Result.extractValue(Data, &Offset, nullptr);
113113 return Result;
114114 }
119119 encodeSLEB128(Value, OS);
120120 uint32_t Offset = 0;
121121 DWARFFormValue Result(DW_FORM_sdata);
122 DataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void*));
122 DWARFDataExtractor Data(OS.str(), sys::IsLittleEndianHost, sizeof(void *));
123123 Result.extractValue(Data, &Offset, nullptr);
124124 return Result;
125125 }