2011-09-14 03:42:23 +08:00
|
|
|
//===-- DWARFAbbreviationDeclaration.cpp ----------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-01-31 02:07:45 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
|
2011-09-14 03:42:23 +08:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
2011-09-15 12:15:59 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2011-09-14 03:42:23 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace dwarf;
|
|
|
|
|
2013-11-01 01:20:14 +08:00
|
|
|
void DWARFAbbreviationDeclaration::clear() {
|
|
|
|
Code = 0;
|
2016-10-28 00:32:04 +08:00
|
|
|
Tag = DW_TAG_null;
|
2013-11-01 01:20:14 +08:00
|
|
|
HasChildren = false;
|
2014-03-13 15:52:54 +08:00
|
|
|
AttributeSpecs.clear();
|
2011-09-14 03:42:23 +08:00
|
|
|
}
|
|
|
|
|
2013-11-01 01:20:14 +08:00
|
|
|
DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() {
|
|
|
|
clear();
|
|
|
|
}
|
2011-09-14 03:42:23 +08:00
|
|
|
|
2013-11-01 01:20:14 +08:00
|
|
|
bool
|
2016-10-28 00:32:04 +08:00
|
|
|
DWARFAbbreviationDeclaration::extract(DataExtractor Data,
|
|
|
|
uint32_t* OffsetPtr) {
|
2013-11-01 01:20:14 +08:00
|
|
|
clear();
|
|
|
|
Code = Data.getULEB128(OffsetPtr);
|
|
|
|
if (Code == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-28 00:32:04 +08:00
|
|
|
Tag = static_cast<llvm::dwarf::Tag>(Data.getULEB128(OffsetPtr));
|
|
|
|
if (Tag == DW_TAG_null) {
|
|
|
|
clear();
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-01 01:20:14 +08:00
|
|
|
uint8_t ChildrenByte = Data.getU8(OffsetPtr);
|
|
|
|
HasChildren = (ChildrenByte == DW_CHILDREN_yes);
|
2011-09-14 03:42:23 +08:00
|
|
|
|
2013-11-01 01:20:14 +08:00
|
|
|
while (true) {
|
2016-10-28 00:32:04 +08:00
|
|
|
auto A = static_cast<Attribute>(Data.getULEB128(OffsetPtr));
|
|
|
|
auto F = static_cast<Form>(Data.getULEB128(OffsetPtr));
|
|
|
|
if (A && F) {
|
|
|
|
AttributeSpecs.push_back(AttributeSpec(A, F));
|
|
|
|
} else if (A == 0 && F == 0) {
|
|
|
|
// We successfully reached the end of this abbreviation declaration
|
|
|
|
// since both attribute and form are zero.
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
// Attribute and form pairs must either both be non-zero, in which case
|
|
|
|
// they are added to the abbreviation declaration, or both be zero to
|
|
|
|
// terminate the abbrevation declaration. In this case only one was
|
|
|
|
// zero which is an error.
|
2013-11-01 01:20:14 +08:00
|
|
|
clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2011-09-14 03:42:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
|
2016-10-05 13:59:29 +08:00
|
|
|
auto tagString = TagString(getTag());
|
2011-09-15 12:15:59 +08:00
|
|
|
OS << '[' << getCode() << "] ";
|
2016-10-05 13:59:29 +08:00
|
|
|
if (!tagString.empty())
|
2011-09-15 12:15:59 +08:00
|
|
|
OS << tagString;
|
|
|
|
else
|
|
|
|
OS << format("DW_TAG_Unknown_%x", getTag());
|
|
|
|
OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n';
|
2014-03-13 15:52:54 +08:00
|
|
|
for (const AttributeSpec &Spec : AttributeSpecs) {
|
2011-09-15 12:15:59 +08:00
|
|
|
OS << '\t';
|
2016-10-05 13:59:29 +08:00
|
|
|
auto attrString = AttributeString(Spec.Attr);
|
|
|
|
if (!attrString.empty())
|
2011-09-15 12:15:59 +08:00
|
|
|
OS << attrString;
|
|
|
|
else
|
2014-03-13 15:52:54 +08:00
|
|
|
OS << format("DW_AT_Unknown_%x", Spec.Attr);
|
2011-09-15 12:15:59 +08:00
|
|
|
OS << '\t';
|
2016-10-05 13:59:29 +08:00
|
|
|
auto formString = FormEncodingString(Spec.Form);
|
|
|
|
if (!formString.empty())
|
2011-09-15 12:15:59 +08:00
|
|
|
OS << formString;
|
|
|
|
else
|
2014-03-13 15:52:54 +08:00
|
|
|
OS << format("DW_FORM_Unknown_%x", Spec.Form);
|
2011-09-15 12:15:59 +08:00
|
|
|
OS << '\n';
|
2011-09-15 12:00:58 +08:00
|
|
|
}
|
2011-09-14 03:42:23 +08:00
|
|
|
OS << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2016-10-28 00:32:04 +08:00
|
|
|
DWARFAbbreviationDeclaration::findAttributeIndex(dwarf::Attribute attr) const {
|
2014-03-13 15:52:54 +08:00
|
|
|
for (uint32_t i = 0, e = AttributeSpecs.size(); i != e; ++i) {
|
|
|
|
if (AttributeSpecs[i].Attr == attr)
|
2011-09-14 03:42:23 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1U;
|
|
|
|
}
|