1 //===- DWARFDataExtractor.h -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H
11 #define LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H
13 #include "llvm/DebugInfo/DWARF/DWARFSection.h"
14 #include "llvm/Support/DataExtractor.h"
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 {
22 const DWARFObject *Obj = nullptr;
23 const DWARFSection *Section = nullptr;
26 /// Constructor for the normal case of extracting data from a DWARF section.
27 /// The DWARFSection's lifetime must be at least as long as the extractor's.
28 DWARFDataExtractor(const DWARFObject &Obj, const DWARFSection &Section,
29 bool IsLittleEndian, uint8_t AddressSize)
30 : DataExtractor(Section.Data, IsLittleEndian, AddressSize), Obj(&Obj),
33 /// Constructor for cases when there are no relocations.
34 DWARFDataExtractor(StringRef Data, bool IsLittleEndian, uint8_t AddressSize)
35 : DataExtractor(Data, IsLittleEndian, AddressSize) {}
37 /// Extracts a value and applies a relocation to the result if
38 /// one exists for the given offset.
39 uint64_t getRelocatedValue(uint32_t Size, uint32_t *Off,
40 uint64_t *SectionIndex = nullptr) const;
42 /// Extracts an address-sized value and applies a relocation to the result if
43 /// one exists for the given offset.
44 uint64_t getRelocatedAddress(uint32_t *Off, uint64_t *SecIx = nullptr) const {
45 return getRelocatedValue(getAddressSize(), Off, SecIx);
48 /// Extracts a DWARF-encoded pointer in \p Offset using \p Encoding.
49 /// There is a DWARF encoding that uses a PC-relative adjustment.
50 /// For these values, \p AbsPosOffset is used to fix them, which should
51 /// reflect the absolute address of this pointer.
52 Optional<uint64_t> getEncodedPointer(uint32_t *Offset, uint8_t Encoding,
53 uint64_t AbsPosOffset = 0) const;
55 size_t size() const { return Section == nullptr ? 0 : Section->Data.size(); }
58 } // end namespace llvm
60 #endif // LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H