LLVM  10.0.0svn
DWARFDataExtractor.cpp
Go to the documentation of this file.
1 //===- DWARFDataExtractor.cpp ---------------------------------------------===//
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 
12 
13 using namespace llvm;
14 
16  uint64_t *SecNdx,
17  Error *Err) const {
18  if (SecNdx)
20  if (!Section)
21  return getUnsigned(Off, Size, Err);
22  Optional<RelocAddrEntry> E = Obj->find(*Section, *Off);
23  uint64_t A = getUnsigned(Off, Size, Err);
24  if (!E)
25  return A;
26  if (SecNdx)
27  *SecNdx = E->SectionIndex;
28  uint64_t R = E->Resolver(E->Reloc, E->SymbolValue, A);
29  if (E->Reloc2)
30  R = E->Resolver(*E->Reloc2, E->SymbolValue2, R);
31  return R;
32 }
33 
35 DWARFDataExtractor::getEncodedPointer(uint64_t *Offset, uint8_t Encoding,
36  uint64_t PCRelOffset) const {
37  if (Encoding == dwarf::DW_EH_PE_omit)
38  return None;
39 
40  uint64_t Result = 0;
41  uint64_t OldOffset = *Offset;
42  // First get value
43  switch (Encoding & 0x0F) {
45  switch (getAddressSize()) {
46  case 2:
47  case 4:
48  case 8:
49  Result = getUnsigned(Offset, getAddressSize());
50  break;
51  default:
52  return None;
53  }
54  break;
56  Result = getULEB128(Offset);
57  break;
59  Result = getSLEB128(Offset);
60  break;
62  Result = getUnsigned(Offset, 2);
63  break;
65  Result = getUnsigned(Offset, 4);
66  break;
68  Result = getUnsigned(Offset, 8);
69  break;
71  Result = getSigned(Offset, 2);
72  break;
74  Result = getSigned(Offset, 4);
75  break;
77  Result = getSigned(Offset, 8);
78  break;
79  default:
80  return None;
81  }
82  // Then add relative offset, if required
83  switch (Encoding & 0x70) {
85  // do nothing
86  break;
88  Result += PCRelOffset;
89  break;
94  default:
95  *Offset = OldOffset;
96  return None;
97  }
98 
99  return Result;
100 }
object::RelocationResolver Resolver
Definition: DWARFRelocMap.h:26
This class represents lattice values for constants.
Definition: AllocatorList.h:23
virtual Optional< RelocAddrEntry > find(const DWARFSection &Sec, uint64_t Pos) const =0
static const uint64_t UndefSection
Definition: ObjectFile.h:140
Optional< object::RelocationRef > Reloc2
Definition: DWARFRelocMap.h:24
int64_t getSLEB128(uint64_t *offset_ptr) const
Extract a signed LEB128 value from *offset_ptr.
object::RelocationRef Reloc
Definition: DWARFRelocMap.h:22
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...
uint64_t getUnsigned(uint64_t *offset_ptr, uint32_t byte_size, Error *Err=nullptr) const
Extract an unsigned integer of size byte_size from *offset_ptr.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
uint8_t getAddressSize() const
Get the address size for this extractor.
Definition: DataExtractor.h:96
uint64_t getULEB128(uint64_t *offset_ptr, llvm::Error *Err=nullptr) const
Extract a unsigned LEB128 value from *offset_ptr.
This file contains constants used for implementing Dwarf debug support.
uint32_t Size
Definition: Profile.cpp:46
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
Optional< uint64_t > getEncodedPointer(uint64_t *Offset, uint8_t Encoding, uint64_t AbsPosOffset=0) const
Extracts a DWARF-encoded pointer in Offset using Encoding.
int64_t getSigned(uint64_t *offset_ptr, uint32_t size) const
Extract an signed integer of size byte_size from *offset_ptr.