1 //===-- DWARFAbbreviationDeclaration.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 "DWARFAbbreviationDeclaration.h"
11 #include "llvm/Support/Dwarf.h"
12 #include "llvm/Support/Format.h"
13 #include "llvm/Support/raw_ostream.h"
15 using namespace dwarf;
17 void DWARFAbbreviationDeclaration::clear() {
21 AttributeSpecs.clear();
24 DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() {
29 DWARFAbbreviationDeclaration::extract(DataExtractor Data, uint32_t* OffsetPtr) {
31 Code = Data.getULEB128(OffsetPtr);
35 Tag = Data.getULEB128(OffsetPtr);
36 uint8_t ChildrenByte = Data.getU8(OffsetPtr);
37 HasChildren = (ChildrenByte == DW_CHILDREN_yes);
40 uint32_t CurOffset = *OffsetPtr;
41 uint16_t Attr = Data.getULEB128(OffsetPtr);
42 if (CurOffset == *OffsetPtr) {
46 CurOffset = *OffsetPtr;
47 uint16_t Form = Data.getULEB128(OffsetPtr);
48 if (CurOffset == *OffsetPtr) {
52 if (Attr == 0 && Form == 0)
54 AttributeSpecs.push_back(AttributeSpec(Attr, Form));
64 void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
65 const char *tagString = TagString(getTag());
66 OS << '[' << getCode() << "] ";
70 OS << format("DW_TAG_Unknown_%x", getTag());
71 OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n';
72 for (const AttributeSpec &Spec : AttributeSpecs) {
74 const char *attrString = AttributeString(Spec.Attr);
78 OS << format("DW_AT_Unknown_%x", Spec.Attr);
80 const char *formString = FormEncodingString(Spec.Form);
84 OS << format("DW_FORM_Unknown_%x", Spec.Form);
91 DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const {
92 for (uint32_t i = 0, e = AttributeSpecs.size(); i != e; ++i) {
93 if (AttributeSpecs[i].Attr == attr)