1 //===-- DWARFDebugInfoEntry.h -----------------------------------*- C++ -*-===// 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 #ifndef LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H 11 #define LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H 12 13 #include "DWARFAbbreviationDeclaration.h" 14 #include "llvm/Support/DataTypes.h" 15 16 namespace llvm { 17 18 class DWARFDebugAranges; 19 class DWARFCompileUnit; 20 class DWARFContext; 21 class DWARFFormValue; 22 23 /// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data. 24 class DWARFDebugInfoEntryMinimal { 25 /// Offset within the .debug_info of the start of this entry. 26 uint64_t Offset; 27 28 /// How many to subtract from "this" to get the parent. 29 /// If zero this die has no parent. 30 uint32_t ParentIdx; 31 32 /// How many to add to "this" to get the sibling. 33 uint32_t SiblingIdx; 34 35 const DWARFAbbreviationDeclaration *AbbrevDecl; 36 public: DWARFDebugInfoEntryMinimal()37 DWARFDebugInfoEntryMinimal() 38 : Offset(0), ParentIdx(0), SiblingIdx(0), AbbrevDecl(0) {} 39 40 void dump(raw_ostream &OS, const DWARFCompileUnit *cu, 41 unsigned recurseDepth, unsigned indent = 0) const; 42 void dumpAttribute(raw_ostream &OS, const DWARFCompileUnit *cu, 43 uint32_t *offset_ptr, uint16_t attr, uint16_t form, 44 unsigned indent = 0) const; 45 46 bool extractFast(const DWARFCompileUnit *cu, const uint8_t *fixed_form_sizes, 47 uint32_t *offset_ptr); 48 49 /// Extract a debug info entry for a given compile unit from the 50 /// .debug_info and .debug_abbrev data starting at the given offset. 51 bool extract(const DWARFCompileUnit *cu, uint32_t *offset_ptr); 52 getTag()53 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; } isNULL()54 bool isNULL() const { return AbbrevDecl == 0; } getOffset()55 uint64_t getOffset() const { return Offset; } getNumAttributes()56 uint32_t getNumAttributes() const { 57 return !isNULL() ? AbbrevDecl->getNumAttributes() : 0; 58 } hasChildren()59 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); } 60 61 // We know we are kept in a vector of contiguous entries, so we know 62 // our parent will be some index behind "this". getParent()63 DWARFDebugInfoEntryMinimal *getParent() { 64 return ParentIdx > 0 ? this - ParentIdx : 0; 65 } getParent()66 const DWARFDebugInfoEntryMinimal *getParent() const { 67 return ParentIdx > 0 ? this - ParentIdx : 0; 68 } 69 // We know we are kept in a vector of contiguous entries, so we know 70 // our sibling will be some index after "this". getSibling()71 DWARFDebugInfoEntryMinimal *getSibling() { 72 return SiblingIdx > 0 ? this + SiblingIdx : 0; 73 } getSibling()74 const DWARFDebugInfoEntryMinimal *getSibling() const { 75 return SiblingIdx > 0 ? this + SiblingIdx : 0; 76 } 77 // We know we are kept in a vector of contiguous entries, so we know 78 // we don't need to store our child pointer, if we have a child it will 79 // be the next entry in the list... getFirstChild()80 DWARFDebugInfoEntryMinimal *getFirstChild() { 81 return hasChildren() ? this + 1 : 0; 82 } getFirstChild()83 const DWARFDebugInfoEntryMinimal *getFirstChild() const { 84 return hasChildren() ? this + 1 : 0; 85 } 86 setParent(DWARFDebugInfoEntryMinimal * parent)87 void setParent(DWARFDebugInfoEntryMinimal *parent) { 88 if (parent) { 89 // We know we are kept in a vector of contiguous entries, so we know 90 // our parent will be some index behind "this". 91 ParentIdx = this - parent; 92 } else 93 ParentIdx = 0; 94 } setSibling(DWARFDebugInfoEntryMinimal * sibling)95 void setSibling(DWARFDebugInfoEntryMinimal *sibling) { 96 if (sibling) { 97 // We know we are kept in a vector of contiguous entries, so we know 98 // our sibling will be some index after "this". 99 SiblingIdx = sibling - this; 100 sibling->setParent(getParent()); 101 } else 102 SiblingIdx = 0; 103 } 104 getAbbreviationDeclarationPtr()105 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const { 106 return AbbrevDecl; 107 } 108 109 uint32_t getAttributeValue(const DWARFCompileUnit *cu, 110 const uint16_t attr, DWARFFormValue &formValue, 111 uint32_t *end_attr_offset_ptr = 0) const; 112 113 const char* getAttributeValueAsString(const DWARFCompileUnit* cu, 114 const uint16_t attr, 115 const char *fail_value) const; 116 117 uint64_t getAttributeValueAsUnsigned(const DWARFCompileUnit *cu, 118 const uint16_t attr, 119 uint64_t fail_value) const; 120 121 uint64_t getAttributeValueAsReference(const DWARFCompileUnit *cu, 122 const uint16_t attr, 123 uint64_t fail_value) const; 124 125 int64_t getAttributeValueAsSigned(const DWARFCompileUnit* cu, 126 const uint16_t attr, 127 int64_t fail_value) const; 128 129 void buildAddressRangeTable(const DWARFCompileUnit *cu, 130 DWARFDebugAranges *debug_aranges) const; 131 }; 132 133 } 134 135 #endif 136