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() {
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 Attributes.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 (unsigned i = 0, e = Attributes.size(); i != e; ++i) {
74 const char *attrString = AttributeString(Attributes[i].Attr);
78 OS << format("DW_AT_Unknown_%x", Attributes[i].Attr);
80 const char *formString = FormEncodingString(Attributes[i].Form);
84 OS << format("DW_FORM_Unknown_%x", Attributes[i].Form);
91 DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const {
92 for (uint32_t i = 0, e = Attributes.size(); i != e; ++i) {
93 if (Attributes[i].Attr == attr)