1 //===-- DWARFDebugAbbrev.cpp ----------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "DWARFDebugAbbrev.h"
11 #include "llvm/Support/Format.h"
12 #include "llvm/Support/raw_ostream.h"
15 bool DWARFAbbreviationDeclarationSet::extract(DataExtractor data,
16 uint32_t* offset_ptr) {
17 const uint32_t beginOffset = *offset_ptr;
20 DWARFAbbreviationDeclaration abbrevDeclaration;
21 uint32_t prevAbbrAode = 0;
22 while (abbrevDeclaration.extract(data, offset_ptr)) {
23 Decls.push_back(abbrevDeclaration);
25 IdxOffset = abbrevDeclaration.getCode();
27 if (prevAbbrAode + 1 != abbrevDeclaration.getCode())
28 IdxOffset = UINT32_MAX;// Out of order indexes, we can't do O(1) lookups
30 prevAbbrAode = abbrevDeclaration.getCode();
32 return beginOffset != *offset_ptr;
35 void DWARFAbbreviationDeclarationSet::dump(raw_ostream &OS) const {
36 for (const auto &Decl : Decls)
40 const DWARFAbbreviationDeclaration*
41 DWARFAbbreviationDeclarationSet::getAbbreviationDeclaration(uint32_t abbrCode)
43 if (IdxOffset == UINT32_MAX) {
44 for (const auto &Decl : Decls) {
45 if (Decl.getCode() == abbrCode)
49 uint32_t idx = abbrCode - IdxOffset;
50 if (idx < Decls.size())
56 DWARFDebugAbbrev::DWARFDebugAbbrev() :
58 PrevAbbrOffsetPos(AbbrevCollMap.end()) {}
61 void DWARFDebugAbbrev::parse(DataExtractor data) {
64 while (data.isValidOffset(offset)) {
65 uint32_t initial_cu_offset = offset;
66 DWARFAbbreviationDeclarationSet abbrevDeclSet;
68 if (abbrevDeclSet.extract(data, &offset))
69 AbbrevCollMap[initial_cu_offset] = abbrevDeclSet;
73 PrevAbbrOffsetPos = AbbrevCollMap.end();
76 void DWARFDebugAbbrev::dump(raw_ostream &OS) const {
77 if (AbbrevCollMap.empty()) {
82 for (const auto &I : AbbrevCollMap) {
83 OS << format("Abbrev table for offset: 0x%8.8" PRIx64 "\n", I.first);
88 const DWARFAbbreviationDeclarationSet*
89 DWARFDebugAbbrev::getAbbreviationDeclarationSet(uint64_t cu_abbr_offset) const {
90 DWARFAbbreviationDeclarationCollMapConstIter end = AbbrevCollMap.end();
91 DWARFAbbreviationDeclarationCollMapConstIter pos;
92 if (PrevAbbrOffsetPos != end &&
93 PrevAbbrOffsetPos->first == cu_abbr_offset) {
94 return &(PrevAbbrOffsetPos->second);
96 pos = AbbrevCollMap.find(cu_abbr_offset);
97 PrevAbbrOffsetPos = pos;
100 if (pos != AbbrevCollMap.end())
101 return &(pos->second);