blob: 0df692c3a3b7f3d4a92a1977e72683e4a198eba4 [file] [log] [blame]
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +00001//===-- DWARFAbbreviationDeclaration.cpp ----------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "DWARFAbbreviationDeclaration.h"
11#include "llvm/Support/Dwarf.h"
Benjamin Kramer7b974422011-09-15 04:15:59 +000012#include "llvm/Support/Format.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000013#include "llvm/Support/raw_ostream.h"
14using namespace llvm;
15using namespace dwarf;
16
17bool
18DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr){
19 return extract(data, offset_ptr, data.getULEB128(offset_ptr));
20}
21
22bool
23DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr,
24 uint32_t code) {
25 Code = code;
26 Attributes.clear();
27 if (Code) {
28 Tag = data.getULEB128(offset_ptr);
29 HasChildren = data.getU8(offset_ptr);
30
31 while (data.isValidOffset(*offset_ptr)) {
32 uint16_t attr = data.getULEB128(offset_ptr);
33 uint16_t form = data.getULEB128(offset_ptr);
34
35 if (attr && form)
36 Attributes.push_back(DWARFAttribute(attr, form));
37 else
38 break;
39 }
40
41 return Tag != 0;
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +000042 } else {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000043 Tag = 0;
44 HasChildren = false;
45 }
46
47 return false;
48}
49
50void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
Benjamin Kramer42180e82011-09-15 04:00:58 +000051 const char *tagString = TagString(getTag());
Benjamin Kramer7b974422011-09-15 04:15:59 +000052 OS << '[' << getCode() << "] ";
53 if (tagString)
54 OS << tagString;
55 else
56 OS << format("DW_TAG_Unknown_%x", getTag());
57 OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n';
Benjamin Kramer42180e82011-09-15 04:00:58 +000058 for (unsigned i = 0, e = Attributes.size(); i != e; ++i) {
Benjamin Kramer7b974422011-09-15 04:15:59 +000059 OS << '\t';
Benjamin Kramer42180e82011-09-15 04:00:58 +000060 const char *attrString = AttributeString(Attributes[i].getAttribute());
Benjamin Kramer7b974422011-09-15 04:15:59 +000061 if (attrString)
62 OS << attrString;
63 else
64 OS << format("DW_AT_Unknown_%x", Attributes[i].getAttribute());
65 OS << '\t';
Benjamin Kramer42180e82011-09-15 04:00:58 +000066 const char *formString = FormEncodingString(Attributes[i].getForm());
Benjamin Kramer7b974422011-09-15 04:15:59 +000067 if (formString)
68 OS << formString;
69 else
70 OS << format("DW_FORM_Unknown_%x", Attributes[i].getForm());
71 OS << '\n';
Benjamin Kramer42180e82011-09-15 04:00:58 +000072 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000073 OS << '\n';
74}
75
76uint32_t
77DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const {
78 for (uint32_t i = 0, e = Attributes.size(); i != e; ++i) {
79 if (Attributes[i].getAttribute() == attr)
80 return i;
81 }
82 return -1U;
83}