2011-09-13 19:42:23 +00:00
|
|
|
//===-- DWARFAbbreviationDeclaration.cpp ----------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DWARFAbbreviationDeclaration.h"
|
|
|
|
#include "llvm/Support/Dwarf.h"
|
2011-09-15 04:15:59 +00:00
|
|
|
#include "llvm/Support/Format.h"
|
2011-09-13 19:42:23 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace dwarf;
|
|
|
|
|
2013-10-31 17:20:14 +00:00
|
|
|
void DWARFAbbreviationDeclaration::clear() {
|
|
|
|
Code = 0;
|
|
|
|
Tag = 0;
|
|
|
|
HasChildren = false;
|
2014-03-13 07:52:54 +00:00
|
|
|
AttributeSpecs.clear();
|
2011-09-13 19:42:23 +00:00
|
|
|
}
|
|
|
|
|
2013-10-31 17:20:14 +00:00
|
|
|
DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() {
|
|
|
|
clear();
|
|
|
|
}
|
2011-09-13 19:42:23 +00:00
|
|
|
|
2013-10-31 17:20:14 +00:00
|
|
|
bool
|
|
|
|
DWARFAbbreviationDeclaration::extract(DataExtractor Data, uint32_t* OffsetPtr) {
|
|
|
|
clear();
|
|
|
|
Code = Data.getULEB128(OffsetPtr);
|
|
|
|
if (Code == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Tag = Data.getULEB128(OffsetPtr);
|
|
|
|
uint8_t ChildrenByte = Data.getU8(OffsetPtr);
|
|
|
|
HasChildren = (ChildrenByte == DW_CHILDREN_yes);
|
2011-09-13 19:42:23 +00:00
|
|
|
|
2013-10-31 17:20:14 +00:00
|
|
|
while (true) {
|
|
|
|
uint32_t CurOffset = *OffsetPtr;
|
|
|
|
uint16_t Attr = Data.getULEB128(OffsetPtr);
|
|
|
|
if (CurOffset == *OffsetPtr) {
|
|
|
|
clear();
|
|
|
|
return false;
|
2011-09-13 19:42:23 +00:00
|
|
|
}
|
2013-10-31 17:20:14 +00:00
|
|
|
CurOffset = *OffsetPtr;
|
|
|
|
uint16_t Form = Data.getULEB128(OffsetPtr);
|
|
|
|
if (CurOffset == *OffsetPtr) {
|
|
|
|
clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Attr == 0 && Form == 0)
|
|
|
|
break;
|
2014-03-14 10:37:36 +00:00
|
|
|
AttributeSpecs.push_back(AttributeSpec(Attr, Form));
|
2011-09-13 19:42:23 +00:00
|
|
|
}
|
|
|
|
|
2013-10-31 17:20:14 +00:00
|
|
|
if (Tag == 0) {
|
|
|
|
clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2011-09-13 19:42:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
|
2011-09-15 04:00:58 +00:00
|
|
|
const char *tagString = TagString(getTag());
|
2011-09-15 04:15:59 +00:00
|
|
|
OS << '[' << getCode() << "] ";
|
|
|
|
if (tagString)
|
|
|
|
OS << tagString;
|
|
|
|
else
|
|
|
|
OS << format("DW_TAG_Unknown_%x", getTag());
|
|
|
|
OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n';
|
2014-03-13 07:52:54 +00:00
|
|
|
for (const AttributeSpec &Spec : AttributeSpecs) {
|
2011-09-15 04:15:59 +00:00
|
|
|
OS << '\t';
|
2014-03-13 07:52:54 +00:00
|
|
|
const char *attrString = AttributeString(Spec.Attr);
|
2011-09-15 04:15:59 +00:00
|
|
|
if (attrString)
|
|
|
|
OS << attrString;
|
|
|
|
else
|
2014-03-13 07:52:54 +00:00
|
|
|
OS << format("DW_AT_Unknown_%x", Spec.Attr);
|
2011-09-15 04:15:59 +00:00
|
|
|
OS << '\t';
|
2014-03-13 07:52:54 +00:00
|
|
|
const char *formString = FormEncodingString(Spec.Form);
|
2011-09-15 04:15:59 +00:00
|
|
|
if (formString)
|
|
|
|
OS << formString;
|
|
|
|
else
|
2014-03-13 07:52:54 +00:00
|
|
|
OS << format("DW_FORM_Unknown_%x", Spec.Form);
|
2011-09-15 04:15:59 +00:00
|
|
|
OS << '\n';
|
2011-09-15 04:00:58 +00:00
|
|
|
}
|
2011-09-13 19:42:23 +00:00
|
|
|
OS << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const {
|
2014-03-13 07:52:54 +00:00
|
|
|
for (uint32_t i = 0, e = AttributeSpecs.size(); i != e; ++i) {
|
|
|
|
if (AttributeSpecs[i].Attr == attr)
|
2011-09-13 19:42:23 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1U;
|
|
|
|
}
|