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/ADT/SmallVector.h" 15 #include "llvm/Support/DataTypes.h" 16 17 namespace llvm { 18 19 class DWARFDebugAranges; 20 class DWARFCompileUnit; 21 class DWARFContext; 22 class DWARFFormValue; 23 struct DWARFDebugInfoEntryInlinedChain; 24 25 /// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data. 26 class DWARFDebugInfoEntryMinimal { 27 /// Offset within the .debug_info of the start of this entry. 28 uint32_t Offset; 29 30 /// How many to subtract from "this" to get the parent. 31 /// If zero this die has no parent. 32 uint32_t ParentIdx; 33 34 /// How many to add to "this" to get the sibling. 35 uint32_t SiblingIdx; 36 37 const DWARFAbbreviationDeclaration *AbbrevDecl; 38 public: 39 DWARFDebugInfoEntryMinimal() 40 : Offset(0), ParentIdx(0), SiblingIdx(0), AbbrevDecl(0) {} 41 42 void dump(raw_ostream &OS, const DWARFCompileUnit *cu, 43 unsigned recurseDepth, unsigned indent = 0) const; 44 void dumpAttribute(raw_ostream &OS, const DWARFCompileUnit *cu, 45 uint32_t *offset_ptr, uint16_t attr, uint16_t form, 46 unsigned indent = 0) const; 47 48 /// Extracts a debug info entry, which is a child of a given compile unit, 49 /// starting at a given offset. If DIE can't be extracted, returns false and 50 /// doesn't change OffsetPtr. 51 bool extractFast(const DWARFCompileUnit *CU, const uint8_t *FixedFormSizes, 52 uint32_t *OffsetPtr); 53 54 /// Extract a debug info entry for a given compile unit from the 55 /// .debug_info and .debug_abbrev data starting at the given offset. 56 /// If compile unit can't be parsed, returns false and doesn't change 57 /// OffsetPtr. 58 bool extract(const DWARFCompileUnit *CU, uint32_t *OffsetPtr); 59 60 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; } 61 bool isNULL() const { return AbbrevDecl == 0; } 62 63 /// Returns true if DIE represents a subprogram (not inlined). 64 bool isSubprogramDIE() const; 65 /// Returns true if DIE represents a subprogram or an inlined 66 /// subroutine. 67 bool isSubroutineDIE() const; 68 69 uint32_t getOffset() const { return Offset; } 70 uint32_t getNumAttributes() const { 71 return !isNULL() ? AbbrevDecl->getNumAttributes() : 0; 72 } 73 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); } 74 75 // We know we are kept in a vector of contiguous entries, so we know 76 // our parent will be some index behind "this". 77 DWARFDebugInfoEntryMinimal *getParent() { 78 return ParentIdx > 0 ? this - ParentIdx : 0; 79 } 80 const DWARFDebugInfoEntryMinimal *getParent() const { 81 return ParentIdx > 0 ? this - ParentIdx : 0; 82 } 83 // We know we are kept in a vector of contiguous entries, so we know 84 // our sibling will be some index after "this". 85 DWARFDebugInfoEntryMinimal *getSibling() { 86 return SiblingIdx > 0 ? this + SiblingIdx : 0; 87 } 88 const DWARFDebugInfoEntryMinimal *getSibling() const { 89 return SiblingIdx > 0 ? this + SiblingIdx : 0; 90 } 91 // We know we are kept in a vector of contiguous entries, so we know 92 // we don't need to store our child pointer, if we have a child it will 93 // be the next entry in the list... 94 DWARFDebugInfoEntryMinimal *getFirstChild() { 95 return hasChildren() ? this + 1 : 0; 96 } 97 const DWARFDebugInfoEntryMinimal *getFirstChild() const { 98 return hasChildren() ? this + 1 : 0; 99 } 100 101 void setParent(DWARFDebugInfoEntryMinimal *parent) { 102 if (parent) { 103 // We know we are kept in a vector of contiguous entries, so we know 104 // our parent will be some index behind "this". 105 ParentIdx = this - parent; 106 } else 107 ParentIdx = 0; 108 } 109 void setSibling(DWARFDebugInfoEntryMinimal *sibling) { 110 if (sibling) { 111 // We know we are kept in a vector of contiguous entries, so we know 112 // our sibling will be some index after "this". 113 SiblingIdx = sibling - this; 114 sibling->setParent(getParent()); 115 } else 116 SiblingIdx = 0; 117 } 118 119 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const { 120 return AbbrevDecl; 121 } 122 123 uint32_t getAttributeValue(const DWARFCompileUnit *cu, 124 const uint16_t attr, DWARFFormValue &formValue, 125 uint32_t *end_attr_offset_ptr = 0) const; 126 127 const char* getAttributeValueAsString(const DWARFCompileUnit* cu, 128 const uint16_t attr, 129 const char *fail_value) const; 130 131 uint64_t getAttributeValueAsUnsigned(const DWARFCompileUnit *cu, 132 const uint16_t attr, 133 uint64_t fail_value) const; 134 135 uint64_t getAttributeValueAsReference(const DWARFCompileUnit *cu, 136 const uint16_t attr, 137 uint64_t fail_value) const; 138 139 int64_t getAttributeValueAsSigned(const DWARFCompileUnit* cu, 140 const uint16_t attr, 141 int64_t fail_value) const; 142 143 /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU. 144 /// Returns true if both attributes are present. 145 bool getLowAndHighPC(const DWARFCompileUnit *CU, 146 uint64_t &LowPC, uint64_t &HighPC) const; 147 148 void buildAddressRangeTable(const DWARFCompileUnit *CU, 149 DWARFDebugAranges *DebugAranges) const; 150 151 bool addressRangeContainsAddress(const DWARFCompileUnit *CU, 152 const uint64_t Address) const; 153 154 /// If a DIE represents a subprogram (or inlined subroutine), 155 /// returns its mangled name (or short name, if mangled is missing). 156 /// This name may be fetched from specification or abstract origin 157 /// for this subprogram. Returns null if no name is found. 158 const char* getSubroutineName(const DWARFCompileUnit *CU) const; 159 160 /// Retrieves values of DW_AT_call_file, DW_AT_call_line and 161 /// DW_AT_call_column from DIE (or zeroes if they are missing). 162 void getCallerFrame(const DWARFCompileUnit *CU, uint32_t &CallFile, 163 uint32_t &CallLine, uint32_t &CallColumn) const; 164 165 /// Get inlined chain for a given address, rooted at the current DIE. 166 /// Returns empty chain if address is not contained in address range 167 /// of current DIE. 168 DWARFDebugInfoEntryInlinedChain 169 getInlinedChainForAddress(const DWARFCompileUnit *CU, 170 const uint64_t Address) const; 171 }; 172 173 /// DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine 174 /// DIEs, (possibly ending with subprogram DIE), all of which are contained 175 /// in some concrete inlined instance tree. Address range for each DIE 176 /// (except the last DIE) in this chain is contained in address 177 /// range for next DIE in the chain. 178 struct DWARFDebugInfoEntryInlinedChain { 179 DWARFDebugInfoEntryInlinedChain() : CU(0) {} 180 SmallVector<DWARFDebugInfoEntryMinimal, 4> DIEs; 181 const DWARFCompileUnit *CU; 182 }; 183 184 } 185 186 #endif 187