Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- DWARFDebugRangesList.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/DWARFDebugRangeList.h"
10
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
11
#include "llvm/Support/Errc.h"
12
#include "llvm/Support/Format.h"
13
#include "llvm/Support/raw_ostream.h"
14
#include <cinttypes>
15
#include <cstdint>
16
17
using namespace llvm;
18
19
578
void DWARFDebugRangeList::clear() {
20
578
  Offset = -1U;
21
578
  AddressSize = 0;
22
578
  Entries.clear();
23
578
}
24
25
Error DWARFDebugRangeList::extract(const DWARFDataExtractor &data,
26
199
                                   uint32_t *offset_ptr) {
27
199
  clear();
28
199
  if (!data.isValidOffset(*offset_ptr))
29
3
    return createStringError(errc::invalid_argument,
30
3
                       "invalid range list offset 0x%" PRIx32, *offset_ptr);
31
196
32
196
  AddressSize = data.getAddressSize();
33
196
  if (AddressSize != 4 && 
AddressSize != 8184
)
34
0
    return createStringError(errc::invalid_argument,
35
0
                       "invalid address size: %" PRIu8, AddressSize);
36
196
  Offset = *offset_ptr;
37
950
  while (true) {
38
950
    RangeListEntry Entry;
39
950
    Entry.SectionIndex = -1ULL;
40
950
41
950
    uint32_t prev_offset = *offset_ptr;
42
950
    Entry.StartAddress = data.getRelocatedAddress(offset_ptr);
43
950
    Entry.EndAddress =
44
950
        data.getRelocatedAddress(offset_ptr, &Entry.SectionIndex);
45
950
46
950
    // Check that both values were extracted correctly.
47
950
    if (*offset_ptr != prev_offset + 2 * AddressSize) {
48
5
      clear();
49
5
      return createStringError(errc::invalid_argument,
50
5
                         "invalid range list entry at offset 0x%" PRIx32,
51
5
                         prev_offset);
52
5
    }
53
945
    if (Entry.isEndOfListEntry())
54
191
      break;
55
754
    Entries.push_back(Entry);
56
754
  }
57
196
  
return Error::success()191
;
58
196
}
59
60
34
void DWARFDebugRangeList::dump(raw_ostream &OS) const {
61
104
  for (const RangeListEntry &RLE : Entries) {
62
104
    const char *format_str = (AddressSize == 4
63
104
                              ? 
"%08x %08" PRIx64 " %08" PRIx64 "\n"20
64
104
                              : 
"%08x %016" PRIx64 " %016" PRIx64 "\n"84
);
65
104
    OS << format(format_str, Offset, RLE.StartAddress, RLE.EndAddress);
66
104
  }
67
34
  OS << format("%08x <End of list>\n", Offset);
68
34
}
69
70
DWARFAddressRangesVector DWARFDebugRangeList::getAbsoluteRanges(
71
145
    llvm::Optional<object::SectionedAddress> BaseAddr) const {
72
145
  DWARFAddressRangesVector Res;
73
624
  for (const RangeListEntry &RLE : Entries) {
74
624
    if (RLE.isBaseAddressSelectionEntry(AddressSize)) {
75
6
      BaseAddr = {RLE.EndAddress, RLE.SectionIndex};
76
6
      continue;
77
6
    }
78
618
79
618
    DWARFAddressRange E;
80
618
    E.LowPC = RLE.StartAddress;
81
618
    E.HighPC = RLE.EndAddress;
82
618
    E.SectionIndex = RLE.SectionIndex;
83
618
    // Base address of a range list entry is determined by the closest preceding
84
618
    // base address selection entry in the same range list. It defaults to the
85
618
    // base address of the compilation unit if there is no such entry.
86
618
    if (BaseAddr) {
87
597
      E.LowPC += BaseAddr->Address;
88
597
      E.HighPC += BaseAddr->Address;
89
597
      if (E.SectionIndex == -1ULL)
90
548
        E.SectionIndex = BaseAddr->SectionIndex;
91
597
    }
92
618
    Res.push_back(E);
93
618
  }
94
145
  return Res;
95
145
}