]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / include / llvm / DebugInfo / DWARF / DWARFDataExtractor.h
1 //===- DWARFDataExtractor.h -------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
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 class DWARFObject;
17
18 /// A DataExtractor (typically for an in-memory copy of an object-file section)
19 /// plus a relocation map for that section, if there is one.
20 class DWARFDataExtractor : public DataExtractor {
21   const DWARFObject *Obj = nullptr;
22   const DWARFSection *Section = nullptr;
23
24 public:
25   /// Constructor for the normal case of extracting data from a DWARF section.
26   /// The DWARFSection's lifetime must be at least as long as the extractor's.
27   DWARFDataExtractor(const DWARFObject &Obj, const DWARFSection &Section,
28                      bool IsLittleEndian, uint8_t AddressSize)
29       : DataExtractor(Section.Data, IsLittleEndian, AddressSize), Obj(&Obj),
30         Section(&Section) {}
31
32   /// Constructor for cases when there are no relocations.
33   DWARFDataExtractor(StringRef Data, bool IsLittleEndian, uint8_t AddressSize)
34     : DataExtractor(Data, IsLittleEndian, AddressSize) {}
35
36   /// Extracts a value and applies a relocation to the result if
37   /// one exists for the given offset.
38   uint64_t getRelocatedValue(uint32_t Size, uint64_t *Off,
39                              uint64_t *SectionIndex = nullptr,
40                              Error *Err = nullptr) const;
41
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(uint64_t *Off, uint64_t *SecIx = nullptr) const {
45     return getRelocatedValue(getAddressSize(), Off, SecIx);
46   }
47   uint64_t getRelocatedAddress(Cursor &C, uint64_t *SecIx = nullptr) const {
48     return getRelocatedValue(getAddressSize(), &getOffset(C), SecIx,
49                              &getError(C));
50   }
51
52   /// Extracts a DWARF-encoded pointer in \p Offset using \p Encoding.
53   /// There is a DWARF encoding that uses a PC-relative adjustment.
54   /// For these values, \p AbsPosOffset is used to fix them, which should
55   /// reflect the absolute address of this pointer.
56   Optional<uint64_t> getEncodedPointer(uint64_t *Offset, uint8_t Encoding,
57                                        uint64_t AbsPosOffset = 0) const;
58 };
59
60 } // end namespace llvm
61
62 #endif // LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H