[llvm] [cmake] Add possibility to use ChooseMSVCCRT.cmake when include LLVM library
[llvm-core.git] / include / llvm / DebugInfo / DWARF / DWARFDataExtractor.h
blob980724c525d2fa84283539e5661f4f0f5ce9771d
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H
10 #define LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H
12 #include "llvm/DebugInfo/DWARF/DWARFSection.h"
13 #include "llvm/Support/DataExtractor.h"
15 namespace llvm {
16 class DWARFObject;
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;
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) {}
32 /// Constructor for cases when there are no relocations.
33 DWARFDataExtractor(StringRef Data, bool IsLittleEndian, uint8_t AddressSize)
34 : DataExtractor(Data, IsLittleEndian, AddressSize) {}
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;
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);
47 uint64_t getRelocatedAddress(Cursor &C, uint64_t *SecIx = nullptr) const {
48 return getRelocatedValue(getAddressSize(), &getOffset(C), SecIx,
49 &getError(C));
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;
59 size_t size() const { return Section == nullptr ? 0 : Section->Data.size(); }
62 } // end namespace llvm
64 #endif // LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H