|
10 | 10 | #define LLVM_DEBUGINFO_DWARF_DWARFDATAEXTRACTOR_H |
11 | 11 |
|
12 | 12 | #include "llvm/BinaryFormat/Dwarf.h" |
| 13 | +#include "llvm/DebugInfo/DWARF/DWARFDataExtractorSimple.h" |
13 | 14 | #include "llvm/DebugInfo/DWARF/DWARFSection.h" |
14 | | -#include "llvm/Support/DataExtractor.h" |
15 | 15 |
|
16 | 16 | namespace llvm { |
17 | 17 | class DWARFObject; |
18 | 18 |
|
19 | | -/// A DataExtractor (typically for an in-memory copy of an object-file section) |
20 | | -/// plus a relocation map for that section, if there is one. |
21 | | -class DWARFDataExtractor : public DataExtractor { |
| 19 | +/// A DWARFDataExtractorSimple (typically for an in-memory copy of an |
| 20 | +/// object-file section) plus a relocation map for that section, if there is |
| 21 | +/// one. |
| 22 | +class DWARFDataExtractor : public DWARFDataExtractorSimple { |
22 | 23 | const DWARFObject *Obj = nullptr; |
23 | 24 | const DWARFSection *Section = nullptr; |
24 | 25 |
|
25 | 26 | public: |
| 27 | + using DWARFDataExtractorSimple::DWARFDataExtractorSimple; |
| 28 | + |
26 | 29 | /// Constructor for the normal case of extracting data from a DWARF section. |
27 | 30 | /// The DWARFSection's lifetime must be at least as long as the extractor's. |
28 | 31 | DWARFDataExtractor(const DWARFObject &Obj, const DWARFSection &Section, |
29 | 32 | bool IsLittleEndian, uint8_t AddressSize) |
30 | | - : DataExtractor(Section.Data, IsLittleEndian, AddressSize), Obj(&Obj), |
31 | | - Section(&Section) {} |
32 | | - |
33 | | - /// Constructor for cases when there are no relocations. |
34 | | - DWARFDataExtractor(StringRef Data, bool IsLittleEndian, uint8_t AddressSize) |
35 | | - : DataExtractor(Data, IsLittleEndian, AddressSize) {} |
36 | | - DWARFDataExtractor(ArrayRef<uint8_t> Data, bool IsLittleEndian, |
37 | | - uint8_t AddressSize) |
38 | | - : DataExtractor( |
39 | | - StringRef(reinterpret_cast<const char *>(Data.data()), Data.size()), |
40 | | - IsLittleEndian, AddressSize) {} |
| 33 | + : DWARFDataExtractorSimple(Section.Data, IsLittleEndian, AddressSize), |
| 34 | + Obj(&Obj), Section(&Section) {} |
41 | 35 |
|
42 | 36 | /// Truncating constructor |
43 | 37 | DWARFDataExtractor(const DWARFDataExtractor &Other, size_t Length) |
44 | | - : DataExtractor(Other.getData().substr(0, Length), Other.isLittleEndian(), |
45 | | - Other.getAddressSize()), |
| 38 | + : DWARFDataExtractorSimple(Other.getData().substr(0, Length), |
| 39 | + Other.isLittleEndian(), |
| 40 | + Other.getAddressSize()), |
46 | 41 | Obj(Other.Obj), Section(Other.Section) {} |
47 | 42 |
|
48 | | - /// Extracts the DWARF "initial length" field, which can either be a 32-bit |
49 | | - /// value smaller than 0xfffffff0, or the value 0xffffffff followed by a |
50 | | - /// 64-bit length. Returns the actual length, and the DWARF format which is |
51 | | - /// encoded in the field. In case of errors, it returns {0, DWARF32} and |
52 | | - /// leaves the offset unchanged. |
53 | | - std::pair<uint64_t, dwarf::DwarfFormat> |
54 | | - getInitialLength(uint64_t *Off, Error *Err = nullptr) const; |
55 | | - |
56 | | - std::pair<uint64_t, dwarf::DwarfFormat> getInitialLength(Cursor &C) const { |
57 | | - return getInitialLength(&getOffset(C), &getError(C)); |
58 | | - } |
59 | | - |
60 | 43 | /// Extracts a value and applies a relocation to the result if |
61 | 44 | /// one exists for the given offset. |
62 | 45 | uint64_t getRelocatedValue(uint32_t Size, uint64_t *Off, |
63 | 46 | uint64_t *SectionIndex = nullptr, |
64 | | - Error *Err = nullptr) const; |
| 47 | + Error *Err = nullptr) const override; |
| 48 | + |
65 | 49 | uint64_t getRelocatedValue(Cursor &C, uint32_t Size, |
66 | | - uint64_t *SectionIndex = nullptr) const { |
| 50 | + uint64_t *SectionIndex = nullptr) const override { |
67 | 51 | return getRelocatedValue(Size, &getOffset(C), SectionIndex, &getError(C)); |
68 | 52 | } |
69 | | - |
70 | | - /// Extracts an address-sized value and applies a relocation to the result if |
71 | | - /// one exists for the given offset. |
72 | | - uint64_t getRelocatedAddress(uint64_t *Off, uint64_t *SecIx = nullptr) const { |
73 | | - return getRelocatedValue(getAddressSize(), Off, SecIx); |
74 | | - } |
75 | | - uint64_t getRelocatedAddress(Cursor &C, uint64_t *SecIx = nullptr) const { |
76 | | - return getRelocatedValue(getAddressSize(), &getOffset(C), SecIx, |
77 | | - &getError(C)); |
78 | | - } |
79 | | - |
80 | | - /// Extracts a DWARF-encoded pointer in \p Offset using \p Encoding. |
81 | | - /// There is a DWARF encoding that uses a PC-relative adjustment. |
82 | | - /// For these values, \p AbsPosOffset is used to fix them, which should |
83 | | - /// reflect the absolute address of this pointer. |
84 | | - std::optional<uint64_t> getEncodedPointer(uint64_t *Offset, uint8_t Encoding, |
85 | | - uint64_t AbsPosOffset = 0) const; |
86 | 53 | }; |
87 | 54 |
|
88 | 55 | } // end namespace llvm |
|
0 commit comments