Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- DWARFDebugAbbrev.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/DWARFDebugAbbrev.h"
10
#include "llvm/Support/Format.h"
11
#include "llvm/Support/raw_ostream.h"
12
#include <algorithm>
13
#include <cinttypes>
14
#include <cstdint>
15
16
using namespace llvm;
17
18
1.69k
DWARFAbbreviationDeclarationSet::DWARFAbbreviationDeclarationSet() {
19
1.69k
  clear();
20
1.69k
}
21
22
3.38k
void DWARFAbbreviationDeclarationSet::clear() {
23
3.38k
  Offset = 0;
24
3.38k
  FirstAbbrCode = 0;
25
3.38k
  Decls.clear();
26
3.38k
}
27
28
bool DWARFAbbreviationDeclarationSet::extract(DataExtractor Data,
29
1.69k
                                              uint32_t *OffsetPtr) {
30
1.69k
  clear();
31
1.69k
  const uint32_t BeginOffset = *OffsetPtr;
32
1.69k
  Offset = BeginOffset;
33
1.69k
  DWARFAbbreviationDeclaration AbbrDecl;
34
1.69k
  uint32_t PrevAbbrCode = 0;
35
10.5k
  while (AbbrDecl.extract(Data, OffsetPtr)) {
36
8.90k
    if (FirstAbbrCode == 0) {
37
1.40k
      FirstAbbrCode = AbbrDecl.getCode();
38
7.50k
    } else {
39
7.50k
      if (PrevAbbrCode + 1 != AbbrDecl.getCode()) {
40
5
        // Codes are not consecutive, can't do O(1) lookups.
41
5
        FirstAbbrCode = UINT32_MAX;
42
5
      }
43
7.50k
    }
44
8.90k
    PrevAbbrCode = AbbrDecl.getCode();
45
8.90k
    Decls.push_back(std::move(AbbrDecl));
46
8.90k
  }
47
1.69k
  return BeginOffset != *OffsetPtr;
48
1.69k
}
49
50
234
void DWARFAbbreviationDeclarationSet::dump(raw_ostream &OS) const {
51
234
  for (const auto &Decl : Decls)
52
1.52k
    Decl.dump(OS);
53
234
}
54
55
const DWARFAbbreviationDeclaration *
56
DWARFAbbreviationDeclarationSet::getAbbreviationDeclaration(
57
13.1k
    uint32_t AbbrCode) const {
58
13.1k
  if (FirstAbbrCode == UINT32_MAX) {
59
19
    for (const auto &Decl : Decls) {
60
19
      if (Decl.getCode() == AbbrCode)
61
10
        return &Decl;
62
19
    }
63
10
    
return nullptr0
;
64
13.1k
  }
65
13.1k
  if (AbbrCode < FirstAbbrCode || AbbrCode >= FirstAbbrCode + Decls.size())
66
0
    return nullptr;
67
13.1k
  return &Decls[AbbrCode - FirstAbbrCode];
68
13.1k
}
69
70
1.50k
DWARFDebugAbbrev::DWARFDebugAbbrev() { clear(); }
71
72
3.00k
void DWARFDebugAbbrev::clear() {
73
3.00k
  AbbrDeclSets.clear();
74
3.00k
  PrevAbbrOffsetPos = AbbrDeclSets.end();
75
3.00k
}
76
77
1.50k
void DWARFDebugAbbrev::extract(DataExtractor Data) {
78
1.50k
  clear();
79
1.50k
  this->Data = Data;
80
1.50k
}
81
82
255
void DWARFDebugAbbrev::parse() const {
83
255
  if (!Data)
84
0
    return;
85
255
  uint32_t Offset = 0;
86
255
  auto I = AbbrDeclSets.begin();
87
788
  while (Data->isValidOffset(Offset)) {
88
533
    while (I != AbbrDeclSets.end() && 
I->first < Offset0
)
89
0
      ++I;
90
533
    uint32_t CUAbbrOffset = Offset;
91
533
    DWARFAbbreviationDeclarationSet AbbrDecls;
92
533
    if (!AbbrDecls.extract(*Data, &Offset))
93
0
      break;
94
533
    AbbrDeclSets.insert(I, std::make_pair(CUAbbrOffset, std::move(AbbrDecls)));
95
533
  }
96
255
  Data = None;
97
255
}
98
99
221
void DWARFDebugAbbrev::dump(raw_ostream &OS) const {
100
221
  parse();
101
221
102
221
  if (AbbrDeclSets.empty()) {
103
0
    OS << "< EMPTY >\n";
104
0
    return;
105
0
  }
106
221
107
234
  
for (const auto &I : AbbrDeclSets)221
{
108
234
    OS << format("Abbrev table for offset: 0x%8.8" PRIx64 "\n", I.first);
109
234
    I.second.dump(OS);
110
234
  }
111
221
}
112
113
const DWARFAbbreviationDeclarationSet*
114
2.30k
DWARFDebugAbbrev::getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const {
115
2.30k
  const auto End = AbbrDeclSets.end();
116
2.30k
  if (PrevAbbrOffsetPos != End && 
PrevAbbrOffsetPos->first == CUAbbrOffset1.06k
) {
117
902
    return &(PrevAbbrOffsetPos->second);
118
902
  }
119
1.40k
120
1.40k
  const auto Pos = AbbrDeclSets.find(CUAbbrOffset);
121
1.40k
  if (Pos != End) {
122
241
    PrevAbbrOffsetPos = Pos;
123
241
    return &(Pos->second);
124
241
  }
125
1.16k
126
1.16k
  if (Data && CUAbbrOffset < Data->getData().size()) {
127
1.15k
    uint32_t Offset = CUAbbrOffset;
128
1.15k
    DWARFAbbreviationDeclarationSet AbbrDecls;
129
1.15k
    if (!AbbrDecls.extract(*Data, &Offset))
130
0
      return nullptr;
131
1.15k
    PrevAbbrOffsetPos =
132
1.15k
        AbbrDeclSets.insert(std::make_pair(CUAbbrOffset, std::move(AbbrDecls)))
133
1.15k
            .first;
134
1.15k
    return &PrevAbbrOffsetPos->second;
135
1.15k
  }
136
1
137
1
  return nullptr;
138
1
}