Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/DebugInfo/DWARF/DWARFDataExtractor.cpp
Line
Count
Source (jump to first uncovered line)
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
9
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
10
#include "llvm/BinaryFormat/Dwarf.h"
11
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
12
13
using namespace llvm;
14
15
uint64_t DWARFDataExtractor::getRelocatedValue(uint32_t Size, uint32_t *Off,
16
67.3k
                                               uint64_t *SecNdx) const {
17
67.3k
  if (SecNdx)
18
9.07k
    *SecNdx = object::SectionedAddress::UndefSection;
19
67.3k
  if (!Section)
20
4.48k
    return getUnsigned(Off, Size);
21
62.8k
  Optional<RelocAddrEntry> E = Obj->find(*Section, *Off);
22
62.8k
  uint64_t A = getUnsigned(Off, Size);
23
62.8k
  if (!E)
24
54.0k
    return A;
25
8.75k
  if (SecNdx)
26
1.38k
    *SecNdx = E->SectionIndex;
27
8.75k
  uint64_t R = E->Resolver(E->Reloc, E->SymbolValue, A);
28
8.75k
  if (E->Reloc2)
29
19
    R = E->Resolver(*E->Reloc2, E->SymbolValue2, R);
30
8.75k
  return R;
31
8.75k
}
32
33
Optional<uint64_t>
34
DWARFDataExtractor::getEncodedPointer(uint32_t *Offset, uint8_t Encoding,
35
532
                                      uint64_t PCRelOffset) const {
36
532
  if (Encoding == dwarf::DW_EH_PE_omit)
37
0
    return None;
38
532
39
532
  uint64_t Result = 0;
40
532
  uint32_t OldOffset = *Offset;
41
532
  // First get value
42
532
  switch (Encoding & 0x0F) {
43
532
  case dwarf::DW_EH_PE_absptr:
44
267
    switch (getAddressSize()) {
45
267
    case 2:
46
267
    case 4:
47
267
    case 8:
48
267
      Result = getUnsigned(Offset, getAddressSize());
49
267
      break;
50
267
    default:
51
0
      return None;
52
267
    }
53
267
    break;
54
267
  case dwarf::DW_EH_PE_uleb128:
55
0
    Result = getULEB128(Offset);
56
0
    break;
57
267
  case dwarf::DW_EH_PE_sleb128:
58
0
    Result = getSLEB128(Offset);
59
0
    break;
60
267
  case dwarf::DW_EH_PE_udata2:
61
0
    Result = getUnsigned(Offset, 2);
62
0
    break;
63
267
  case dwarf::DW_EH_PE_udata4:
64
7
    Result = getUnsigned(Offset, 4);
65
7
    break;
66
267
  case dwarf::DW_EH_PE_udata8:
67
0
    Result = getUnsigned(Offset, 8);
68
0
    break;
69
267
  case dwarf::DW_EH_PE_sdata2:
70
2
    Result = getSigned(Offset, 2);
71
2
    break;
72
267
  case dwarf::DW_EH_PE_sdata4:
73
252
    Result = getSigned(Offset, 4);
74
252
    break;
75
267
  case dwarf::DW_EH_PE_sdata8:
76
4
    Result = getSigned(Offset, 8);
77
4
    break;
78
267
  default:
79
0
    return None;
80
532
  }
81
532
  // Then add relative offset, if required
82
532
  switch (Encoding & 0x70) {
83
532
  case dwarf::DW_EH_PE_absptr:
84
32
    // do nothing
85
32
    break;
86
532
  case dwarf::DW_EH_PE_pcrel:
87
500
    Result += PCRelOffset;
88
500
    break;
89
532
  case dwarf::DW_EH_PE_datarel:
90
0
  case dwarf::DW_EH_PE_textrel:
91
0
  case dwarf::DW_EH_PE_funcrel:
92
0
  case dwarf::DW_EH_PE_aligned:
93
0
  default:
94
0
    *Offset = OldOffset;
95
0
    return None;
96
532
  }
97
532
98
532
  return Result;
99
532
}