LLVM  6.0.0svn
DWARFDebugAbbrev.cpp
Go to the documentation of this file.
1 //===- DWARFDebugAbbrev.cpp -----------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/Support/Format.h"
13 #include <algorithm>
14 #include <cinttypes>
15 #include <cstdint>
16 
17 using namespace llvm;
18 
20  clear();
21 }
22 
23 void DWARFAbbreviationDeclarationSet::clear() {
24  Offset = 0;
25  FirstAbbrCode = 0;
26  Decls.clear();
27 }
28 
30  uint32_t *OffsetPtr) {
31  clear();
32  const uint32_t BeginOffset = *OffsetPtr;
33  Offset = BeginOffset;
35  uint32_t PrevAbbrCode = 0;
36  while (AbbrDecl.extract(Data, OffsetPtr)) {
37  if (FirstAbbrCode == 0) {
38  FirstAbbrCode = AbbrDecl.getCode();
39  } else {
40  if (PrevAbbrCode + 1 != AbbrDecl.getCode()) {
41  // Codes are not consecutive, can't do O(1) lookups.
42  FirstAbbrCode = UINT32_MAX;
43  }
44  }
45  PrevAbbrCode = AbbrDecl.getCode();
46  Decls.push_back(std::move(AbbrDecl));
47  }
48  return BeginOffset != *OffsetPtr;
49 }
50 
52  for (const auto &Decl : Decls)
53  Decl.dump(OS);
54 }
55 
58  uint32_t AbbrCode) const {
59  if (FirstAbbrCode == UINT32_MAX) {
60  for (const auto &Decl : Decls) {
61  if (Decl.getCode() == AbbrCode)
62  return &Decl;
63  }
64  return nullptr;
65  }
66  if (AbbrCode < FirstAbbrCode || AbbrCode >= FirstAbbrCode + Decls.size())
67  return nullptr;
68  return &Decls[AbbrCode - FirstAbbrCode];
69 }
70 
72 
73 void DWARFDebugAbbrev::clear() {
74  AbbrDeclSets.clear();
75  PrevAbbrOffsetPos = AbbrDeclSets.end();
76 }
77 
79  clear();
80  this->Data = Data;
81 }
82 
84  if (!Data)
85  return;
86  uint32_t Offset = 0;
88  auto I = AbbrDeclSets.begin();
89  while (Data->isValidOffset(Offset)) {
90  while (I != AbbrDeclSets.end() && I->first < Offset)
91  ++I;
92  uint32_t CUAbbrOffset = Offset;
93  if (!AbbrDecls.extract(*Data, &Offset))
94  break;
95  AbbrDeclSets.insert(I, std::make_pair(CUAbbrOffset, std::move(AbbrDecls)));
96  }
97  Data = None;
98 }
99 
101  parse();
102 
103  if (AbbrDeclSets.empty()) {
104  OS << "< EMPTY >\n";
105  return;
106  }
107 
108  for (const auto &I : AbbrDeclSets) {
109  OS << format("Abbrev table for offset: 0x%8.8" PRIx64 "\n", I.first);
110  I.second.dump(OS);
111  }
112 }
113 
116  const auto End = AbbrDeclSets.end();
117  if (PrevAbbrOffsetPos != End && PrevAbbrOffsetPos->first == CUAbbrOffset) {
118  return &(PrevAbbrOffsetPos->second);
119  }
120 
121  const auto Pos = AbbrDeclSets.find(CUAbbrOffset);
122  if (Pos != End) {
123  PrevAbbrOffsetPos = Pos;
124  return &(Pos->second);
125  }
126 
127  if (Data && CUAbbrOffset < Data->getData().size()) {
128  uint32_t Offset = CUAbbrOffset;
130  if (!AbbrDecls.extract(*Data, &Offset))
131  return nullptr;
132  PrevAbbrOffsetPos =
133  AbbrDeclSets.insert(std::make_pair(CUAbbrOffset, std::move(AbbrDecls)))
134  .first;
135  return &PrevAbbrOffsetPos->second;
136  }
137 
138  return nullptr;
139 }
bool extract(DataExtractor Data, uint32_t *OffsetPtr)
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
void extract(DataExtractor Data)
bool extract(DataExtractor Data, uint32_t *OffsetPtr)
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
void dump(raw_ostream &OS) const
Definition: regcomp.c:196
const DWARFAbbreviationDeclaration * getAbbreviationDeclaration(uint32_t AbbrCode) const
void dump(raw_ostream &OS) const
const DWARFAbbreviationDeclarationSet * getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const
static const unsigned End
#define I(x, y, z)
Definition: MD5.cpp:58
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44