Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 1 | //===-- 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 Kramer | 7b97442 | 2011-09-15 04:15:59 +0000 | [diff] [blame] | 12 | #include "llvm/Support/Format.h" |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 13 | #include "llvm/Support/raw_ostream.h" |
| 14 | using namespace llvm; |
| 15 | using namespace dwarf; |
| 16 | |
| 17 | bool |
| 18 | DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr){ |
| 19 | return extract(data, offset_ptr, data.getULEB128(offset_ptr)); |
| 20 | } |
| 21 | |
| 22 | bool |
| 23 | DWARFAbbreviationDeclaration::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 Kramer | 4aa3fea | 2011-09-13 21:47:32 +0000 | [diff] [blame] | 42 | } else { |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 43 | Tag = 0; |
| 44 | HasChildren = false; |
| 45 | } |
| 46 | |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const { |
Benjamin Kramer | 42180e8 | 2011-09-15 04:00:58 +0000 | [diff] [blame] | 51 | const char *tagString = TagString(getTag()); |
Benjamin Kramer | 7b97442 | 2011-09-15 04:15:59 +0000 | [diff] [blame] | 52 | 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 Kramer | 42180e8 | 2011-09-15 04:00:58 +0000 | [diff] [blame] | 58 | for (unsigned i = 0, e = Attributes.size(); i != e; ++i) { |
Benjamin Kramer | 7b97442 | 2011-09-15 04:15:59 +0000 | [diff] [blame] | 59 | OS << '\t'; |
Benjamin Kramer | 42180e8 | 2011-09-15 04:00:58 +0000 | [diff] [blame] | 60 | const char *attrString = AttributeString(Attributes[i].getAttribute()); |
Benjamin Kramer | 7b97442 | 2011-09-15 04:15:59 +0000 | [diff] [blame] | 61 | if (attrString) |
| 62 | OS << attrString; |
| 63 | else |
| 64 | OS << format("DW_AT_Unknown_%x", Attributes[i].getAttribute()); |
| 65 | OS << '\t'; |
Benjamin Kramer | 42180e8 | 2011-09-15 04:00:58 +0000 | [diff] [blame] | 66 | const char *formString = FormEncodingString(Attributes[i].getForm()); |
Benjamin Kramer | 7b97442 | 2011-09-15 04:15:59 +0000 | [diff] [blame] | 67 | if (formString) |
| 68 | OS << formString; |
| 69 | else |
| 70 | OS << format("DW_FORM_Unknown_%x", Attributes[i].getForm()); |
| 71 | OS << '\n'; |
Benjamin Kramer | 42180e8 | 2011-09-15 04:00:58 +0000 | [diff] [blame] | 72 | } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 73 | OS << '\n'; |
| 74 | } |
| 75 | |
| 76 | uint32_t |
| 77 | DWARFAbbreviationDeclaration::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 | } |