LLVM  10.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, 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  size_t size() const { return Section == nullptr ? 0 : Section->Data.size(); }
60 };
61 
62 } // end namespace llvm
63 
64 #endif // LLVM_DEBUGINFO_DWARFDATAEXTRACTOR_H
uint64_t CallInst * C
uint64_t getRelocatedAddress(uint64_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...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
uint64_t getRelocatedValue(uint32_t Size, uint64_t *Off, uint64_t *SectionIndex=nullptr, Error *Err=nullptr) const
Extracts a value and applies a relocation to the result if one exists for the given offset...
static uint64_t & getOffset(Cursor &C)
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:144
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:91
A class representing a position in a DataExtractor, as well as any error encountered during extractio...
Definition: DataExtractor.h:54
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
static Error & getError(Cursor &C)
uint32_t Size
Definition: Profile.cpp:46
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
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
uint64_t getRelocatedAddress(Cursor &C, uint64_t *SecIx=nullptr) const
Optional< uint64_t > getEncodedPointer(uint64_t *Offset, uint8_t Encoding, uint64_t AbsPosOffset=0) const
Extracts a DWARF-encoded pointer in Offset using Encoding.