LLVM  9.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> Rel = Obj->find(*Section, *Off);
22  if (!Rel)
23  return getUnsigned(Off, Size);
24  if (SecNdx)
25  *SecNdx = Rel->SectionIndex;
26  return getUnsigned(Off, Size) + Rel->Value;
27 }
28 
31  uint64_t PCRelOffset) const {
32  if (Encoding == dwarf::DW_EH_PE_omit)
33  return None;
34 
35  uint64_t Result = 0;
36  uint32_t OldOffset = *Offset;
37  // First get value
38  switch (Encoding & 0x0F) {
40  switch (getAddressSize()) {
41  case 2:
42  case 4:
43  case 8:
44  Result = getUnsigned(Offset, getAddressSize());
45  break;
46  default:
47  return None;
48  }
49  break;
51  Result = getULEB128(Offset);
52  break;
54  Result = getSLEB128(Offset);
55  break;
57  Result = getUnsigned(Offset, 2);
58  break;
60  Result = getUnsigned(Offset, 4);
61  break;
63  Result = getUnsigned(Offset, 8);
64  break;
66  Result = getSigned(Offset, 2);
67  break;
69  Result = getSigned(Offset, 4);
70  break;
72  Result = getSigned(Offset, 8);
73  break;
74  default:
75  return None;
76  }
77  // Then add relative offset, if required
78  switch (Encoding & 0x70) {
80  // do nothing
81  break;
83  Result += PCRelOffset;
84  break;
89  default:
90  *Offset = OldOffset;
91  return None;
92  }
93 
94  return Result;
95 }
uint64_t getULEB128(uint32_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
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:144
int64_t getSLEB128(uint32_t *offset_ptr) const
Extract a signed LEB128 value from *offset_ptr.
uint8_t getAddressSize() const
Get the address size for this extractor.
Definition: DataExtractor.h:58
int64_t getSigned(uint32_t *offset_ptr, uint32_t size) const
Extract an signed integer of size byte_size from *offset_ptr.
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...
This file contains constants used for implementing Dwarf debug support.
uint64_t getUnsigned(uint32_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