Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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" |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/SmallVector.h" |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 15 | #include "llvm/Support/DataTypes.h" |
| 16 | |
| 17 | namespace llvm { |
| 18 | |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 19 | class DWARFDebugAranges; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 20 | class DWARFCompileUnit; |
| 21 | class DWARFContext; |
| 22 | class DWARFFormValue; |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 23 | class DWARFInlinedSubroutineChain; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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. |
Benjamin Kramer | 80cc259 | 2011-11-05 15:35:00 +0000 | [diff] [blame] | 28 | uint32_t Offset; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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: |
Benjamin Kramer | 15ec085 | 2011-09-14 00:15:32 +0000 | [diff] [blame] | 39 | DWARFDebugInfoEntryMinimal() |
| 40 | : Offset(0), ParentIdx(0), SiblingIdx(0), AbbrevDecl(0) {} |
| 41 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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 | |
Alexey Samsonov | d6b89ef | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 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); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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. |
Alexey Samsonov | d6b89ef | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 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); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 59 | |
| 60 | uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; } |
| 61 | bool isNULL() const { return AbbrevDecl == 0; } |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | 80cc259 | 2011-11-05 15:35:00 +0000 | [diff] [blame] | 69 | uint32_t getOffset() const { return Offset; } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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; |
Benjamin Kramer | 4aa3fea | 2011-09-13 21:47:32 +0000 | [diff] [blame] | 106 | } else |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 107 | ParentIdx = 0; |
| 108 | } |
| 109 | void setSibling(DWARFDebugInfoEntryMinimal *sibling) { |
Benjamin Kramer | 4aa3fea | 2011-09-13 21:47:32 +0000 | [diff] [blame] | 110 | if (sibling) { |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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()); |
Benjamin Kramer | 4aa3fea | 2011-09-13 21:47:32 +0000 | [diff] [blame] | 115 | } else |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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; |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 142 | |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 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; |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 147 | |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 148 | void buildAddressRangeTable(const DWARFCompileUnit *CU, |
| 149 | DWARFDebugAranges *DebugAranges) const; |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 150 | |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 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 | /// InlinedChain - represents a chain of inlined_subroutine |
| 166 | /// DIEs, (possibly ending with subprogram DIE), all of which are contained |
| 167 | /// in some concrete inlined instance tree. Address range for each DIE |
| 168 | /// (except the last DIE) in this chain is contained in address |
| 169 | /// range for next DIE in the chain. |
| 170 | typedef SmallVector<DWARFDebugInfoEntryMinimal, 4> InlinedChain; |
| 171 | |
| 172 | /// Get inlined chain for a given address, rooted at the current DIE. |
| 173 | /// Returns empty chain if address is not contained in address range |
| 174 | /// of current DIE. |
| 175 | InlinedChain getInlinedChainForAddress(const DWARFCompileUnit *CU, |
| 176 | const uint64_t Address) const; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | } |
| 180 | |
| 181 | #endif |