Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp
Line
Count
Source
1
//===- DWARFDebugArangeSet.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/DWARFDebugArangeSet.h"
10
#include "llvm/Support/Format.h"
11
#include "llvm/Support/raw_ostream.h"
12
#include <cassert>
13
#include <cinttypes>
14
#include <cstdint>
15
#include <cstring>
16
17
using namespace llvm;
18
19
void DWARFDebugArangeSet::Descriptor::dump(raw_ostream &OS,
20
152
                                           uint32_t AddressSize) const {
21
152
  OS << format("[0x%*.*" PRIx64 ", ", AddressSize * 2, AddressSize * 2, Address)
22
152
     << format(" 0x%*.*" PRIx64 ")", AddressSize * 2, AddressSize * 2,
23
152
               getEndAddress());
24
152
}
25
26
123
void DWARFDebugArangeSet::clear() {
27
123
  Offset = -1U;
28
123
  std::memset(&HeaderData, 0, sizeof(Header));
29
123
  ArangeDescriptors.clear();
30
123
}
31
32
bool
33
281
DWARFDebugArangeSet::extract(DataExtractor data, uint32_t *offset_ptr) {
34
281
  if (data.isValidOffset(*offset_ptr)) {
35
168
    ArangeDescriptors.clear();
36
168
    Offset = *offset_ptr;
37
168
38
168
    // 7.20 Address Range Table
39
168
    //
40
168
    // Each set of entries in the table of address ranges contained in
41
168
    // the .debug_aranges section begins with a header consisting of: a
42
168
    // 4-byte length containing the length of the set of entries for this
43
168
    // compilation unit, not including the length field itself; a 2-byte
44
168
    // version identifier containing the value 2 for DWARF Version 2; a
45
168
    // 4-byte offset into the.debug_infosection; a 1-byte unsigned integer
46
168
    // containing the size in bytes of an address (or the offset portion of
47
168
    // an address for segmented addressing) on the target system; and a
48
168
    // 1-byte unsigned integer containing the size in bytes of a segment
49
168
    // descriptor on the target system. This header is followed by a series
50
168
    // of tuples. Each tuple consists of an address and a length, each in
51
168
    // the size appropriate for an address on the target architecture.
52
168
    HeaderData.Length = data.getU32(offset_ptr);
53
168
    HeaderData.Version = data.getU16(offset_ptr);
54
168
    HeaderData.CuOffset = data.getU32(offset_ptr);
55
168
    HeaderData.AddrSize = data.getU8(offset_ptr);
56
168
    HeaderData.SegSize = data.getU8(offset_ptr);
57
168
58
168
    // Perform basic validation of the header fields.
59
168
    if (!data.isValidOffsetForDataOfSize(Offset, HeaderData.Length) ||
60
168
        
(163
HeaderData.AddrSize != 4163
&&
HeaderData.AddrSize != 8156
)) {
61
5
      clear();
62
5
      return false;
63
5
    }
64
163
65
163
    // The first tuple following the header in each set begins at an offset
66
163
    // that is a multiple of the size of a single tuple (that is, twice the
67
163
    // size of an address). The header is padded, if necessary, to the
68
163
    // appropriate boundary.
69
163
    const uint32_t header_size = *offset_ptr - Offset;
70
163
    const uint32_t tuple_size = HeaderData.AddrSize * 2;
71
163
    uint32_t first_tuple_offset = 0;
72
333
    while (first_tuple_offset < header_size)
73
170
      first_tuple_offset += tuple_size;
74
163
75
163
    *offset_ptr = Offset + first_tuple_offset;
76
163
77
163
    Descriptor arangeDescriptor;
78
163
79
163
    static_assert(sizeof(arangeDescriptor.Address) ==
80
163
                      sizeof(arangeDescriptor.Length),
81
163
                  "Different datatypes for addresses and sizes!");
82
163
    assert(sizeof(arangeDescriptor.Address) >= HeaderData.AddrSize);
83
163
84
370
    while (data.isValidOffset(*offset_ptr)) {
85
370
      arangeDescriptor.Address = data.getUnsigned(offset_ptr, HeaderData.AddrSize);
86
370
      arangeDescriptor.Length = data.getUnsigned(offset_ptr, HeaderData.AddrSize);
87
370
88
370
      // Each set of tuples is terminated by a 0 for the address and 0
89
370
      // for the length.
90
370
      if (arangeDescriptor.Address || 
arangeDescriptor.Length207
)
91
207
        ArangeDescriptors.push_back(arangeDescriptor);
92
163
      else
93
163
        break; // We are done if we get a zero address and length
94
370
    }
95
163
96
163
    return !ArangeDescriptors.empty();
97
163
  }
98
113
  return false;
99
113
}
100
101
110
void DWARFDebugArangeSet::dump(raw_ostream &OS) const {
102
110
  OS << format("Address Range Header: length = 0x%8.8x, version = 0x%4.4x, ",
103
110
               HeaderData.Length, HeaderData.Version)
104
110
     << format("cu_offset = 0x%8.8x, addr_size = 0x%2.2x, seg_size = 0x%2.2x\n",
105
110
               HeaderData.CuOffset, HeaderData.AddrSize, HeaderData.SegSize);
106
110
107
152
  for (const auto &Desc : ArangeDescriptors) {
108
152
    Desc.dump(OS, HeaderData.AddrSize);
109
152
    OS << '\n';
110
152
  }
111
110
}