2011-09-13 19:42:23 +00:00
|
|
|
//===-- DWARFDebugAbbrev.cpp ----------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DWARFDebugAbbrev.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
bool DWARFAbbreviationDeclarationSet::extract(DataExtractor data,
|
|
|
|
uint32_t* offset_ptr) {
|
|
|
|
const uint32_t beginOffset = *offset_ptr;
|
|
|
|
Offset = beginOffset;
|
|
|
|
clear();
|
|
|
|
DWARFAbbreviationDeclaration abbrevDeclaration;
|
|
|
|
uint32_t prevAbbrAode = 0;
|
|
|
|
while (abbrevDeclaration.extract(data, offset_ptr)) {
|
|
|
|
Decls.push_back(abbrevDeclaration);
|
|
|
|
if (IdxOffset == 0) {
|
|
|
|
IdxOffset = abbrevDeclaration.getCode();
|
|
|
|
} else {
|
|
|
|
if (prevAbbrAode + 1 != abbrevDeclaration.getCode())
|
|
|
|
IdxOffset = UINT32_MAX;// Out of order indexes, we can't do O(1) lookups
|
|
|
|
}
|
|
|
|
prevAbbrAode = abbrevDeclaration.getCode();
|
|
|
|
}
|
|
|
|
return beginOffset != *offset_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DWARFAbbreviationDeclarationSet::dump(raw_ostream &OS) const {
|
2014-03-13 07:52:54 +00:00
|
|
|
for (const auto &Decl : Decls)
|
|
|
|
Decl.dump(OS);
|
2011-09-13 19:42:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const DWARFAbbreviationDeclaration*
|
|
|
|
DWARFAbbreviationDeclarationSet::getAbbreviationDeclaration(uint32_t abbrCode)
|
|
|
|
const {
|
|
|
|
if (IdxOffset == UINT32_MAX) {
|
2014-03-13 07:52:54 +00:00
|
|
|
for (const auto &Decl : Decls) {
|
|
|
|
if (Decl.getCode() == abbrCode)
|
|
|
|
return &Decl;
|
2011-09-13 19:42:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uint32_t idx = abbrCode - IdxOffset;
|
|
|
|
if (idx < Decls.size())
|
|
|
|
return &Decls[idx];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWARFDebugAbbrev::DWARFDebugAbbrev() :
|
2011-09-13 21:47:32 +00:00
|
|
|
AbbrevCollMap(),
|
|
|
|
PrevAbbrOffsetPos(AbbrevCollMap.end()) {}
|
2011-09-13 19:42:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DWARFDebugAbbrev::parse(DataExtractor data) {
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
|
|
|
while (data.isValidOffset(offset)) {
|
|
|
|
uint32_t initial_cu_offset = offset;
|
|
|
|
DWARFAbbreviationDeclarationSet abbrevDeclSet;
|
|
|
|
|
|
|
|
if (abbrevDeclSet.extract(data, &offset))
|
2011-09-13 21:47:32 +00:00
|
|
|
AbbrevCollMap[initial_cu_offset] = abbrevDeclSet;
|
2011-09-13 19:42:23 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2011-09-13 21:47:32 +00:00
|
|
|
PrevAbbrOffsetPos = AbbrevCollMap.end();
|
2011-09-13 19:42:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DWARFDebugAbbrev::dump(raw_ostream &OS) const {
|
2011-09-13 21:47:32 +00:00
|
|
|
if (AbbrevCollMap.empty()) {
|
2011-09-13 19:42:23 +00:00
|
|
|
OS << "< EMPTY >\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-13 07:52:54 +00:00
|
|
|
for (const auto &I : AbbrevCollMap) {
|
|
|
|
OS << format("Abbrev table for offset: 0x%8.8" PRIx64 "\n", I.first);
|
|
|
|
I.second.dump(OS);
|
2011-09-13 19:42:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const DWARFAbbreviationDeclarationSet*
|
|
|
|
DWARFDebugAbbrev::getAbbreviationDeclarationSet(uint64_t cu_abbr_offset) const {
|
2011-09-13 21:47:32 +00:00
|
|
|
DWARFAbbreviationDeclarationCollMapConstIter end = AbbrevCollMap.end();
|
2011-09-13 19:42:23 +00:00
|
|
|
DWARFAbbreviationDeclarationCollMapConstIter pos;
|
2011-09-13 21:47:32 +00:00
|
|
|
if (PrevAbbrOffsetPos != end &&
|
|
|
|
PrevAbbrOffsetPos->first == cu_abbr_offset) {
|
|
|
|
return &(PrevAbbrOffsetPos->second);
|
2011-09-13 19:42:23 +00:00
|
|
|
} else {
|
2011-09-13 21:47:32 +00:00
|
|
|
pos = AbbrevCollMap.find(cu_abbr_offset);
|
|
|
|
PrevAbbrOffsetPos = pos;
|
2011-09-13 19:42:23 +00:00
|
|
|
}
|
|
|
|
|
2011-09-13 21:47:32 +00:00
|
|
|
if (pos != AbbrevCollMap.end())
|
2011-09-13 19:42:23 +00:00
|
|
|
return &(pos->second);
|
|
|
|
return NULL;
|
|
|
|
}
|