LLVM  9.0.0svn
DWARFDataExtractor.h
Go to the documentation of this file.
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 
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.
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, uint32_t *Off,
39  uint64_t *SectionIndex = nullptr) const;
40 
41  /// Extracts an address-sized value and applies a relocation to the result if
42  /// one exists for the given offset.
43  uint64_t getRelocatedAddress(uint32_t *Off, uint64_t *SecIx = nullptr) const {
44  return getRelocatedValue(getAddressSize(), Off, SecIx);
45  }
46 
47  /// Extracts a DWARF-encoded pointer in \p Offset using \p Encoding.
48  /// There is a DWARF encoding that uses a PC-relative adjustment.
49  /// For these values, \p AbsPosOffset is used to fix them, which should
50  /// reflect the absolute address of this pointer.
52  uint64_t AbsPosOffset = 0) const;
53 
54  size_t size() const { return Section == nullptr ? 0 : Section->Data.size(); }
55 };
56 
57 } // end namespace llvm
58 
59 #endif // LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
uint64_t getRelocatedAddress(uint32_t *Off, uint64_t *SecIx=nullptr) const
Extracts an address-sized value and applies a relocation to the result if one exists for the given of...
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:130
DWARFDataExtractor(StringRef Data, bool IsLittleEndian, uint8_t AddressSize)
Constructor for cases when there are no relocations.
uint8_t getAddressSize() const
Get the address size for this extractor.
Definition: DataExtractor.h:58
Optional< uint64_t > getEncodedPointer(uint32_t *Offset, uint8_t Encoding, uint64_t AbsPosOffset=0) const
Extracts a DWARF-encoded pointer in Offset using Encoding.
uint64_t getRelocatedValue(uint32_t Size, uint32_t *Off, uint64_t *SectionIndex=nullptr) const
Extracts a value and applies a relocation to the result if one exists for the given offset...
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
uint32_t Size
Definition: Profile.cpp:46
DWARFDataExtractor(const DWARFObject &Obj, const DWARFSection &Section, bool IsLittleEndian, uint8_t AddressSize)
Constructor for the normal case of extracting data from a DWARF section.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48