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) const {
17  if (SecNdx)
19  if (!Section)
20  return getUnsigned(Off, Size);
21  Optional<RelocAddrEntry> E = Obj->find(*Section, *Off);
22  uint64_t A = getUnsigned(Off, Size);
23  if (!E)
24  return A;
25  if (SecNdx)
26  *SecNdx = E->SectionIndex;
27  uint64_t R = E->Resolver(E->Reloc, E->SymbolValue, A);
28  if (E->Reloc2)
29  R = E->Resolver(*E->Reloc2, E->SymbolValue2, R);
30  return R;
31 }
32 
34 DWARFDataExtractor::getEncodedPointer(uint64_t *Offset, uint8_t Encoding,
35  uint64_t PCRelOffset) const {
36  if (Encoding == dwarf::DW_EH_PE_omit)
37  return None;
38 
39  uint64_t Result = 0;
40  uint64_t OldOffset = *Offset;
41  // First get value
42  switch (Encoding & 0x0F) {
44  switch (getAddressSize()) {
45  case 2:
46  case 4:
47  case 8:
48  Result = getUnsigned(Offset, getAddressSize());
49  break;
50  default:
51  return None;
52  }
53  break;
55  Result = getULEB128(Offset);
56  break;
58  Result = getSLEB128(Offset);
59  break;
61  Result = getUnsigned(Offset, 2);
62  break;
64  Result = getUnsigned(Offset, 4);
65  break;
67  Result = getUnsigned(Offset, 8);
68  break;
70  Result = getSigned(Offset, 2);
71  break;
73  Result = getSigned(Offset, 4);
74  break;
76  Result = getSigned(Offset, 8);
77  break;
78  default:
79  return None;
80  }
81  // Then add relative offset, if required
82  switch (Encoding & 0x70) {
84  // do nothing
85  break;
87  Result += PCRelOffset;
88  break;
93  default:
94  *Offset = OldOffset;
95  return None;
96  }
97 
98  return Result;
99 }
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
uint64_t getULEB128(uint64_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
static const uint64_t UndefSection
Definition: ObjectFile.h:145
Optional< object::RelocationRef > Reloc2
Definition: DWARFRelocMap.h:24
int64_t getSLEB128(uint64_t *offset_ptr) const
Extract a signed LEB128 value from *offset_ptr.
uint64_t getRelocatedValue(uint32_t Size, uint64_t *Off, uint64_t *SectionIndex=nullptr) const
Extracts a value and applies a relocation to the result if one exists for the given offset...
object::RelocationRef Reloc
Definition: DWARFRelocMap.h:22
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
uint8_t getAddressSize() const
Get the address size for this extractor.
Definition: DataExtractor.h:58
This file contains constants used for implementing Dwarf debug support.
uint64_t getUnsigned(uint64_t *offset_ptr, uint32_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
uint32_t Size
Definition: Profile.cpp:46
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.