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" |
| 14 | #include "llvm/Support/DataTypes.h" |
| 15 | |
| 16 | namespace llvm { |
| 17 | |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 18 | class DWARFDebugAranges; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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. |
Benjamin Kramer | 80cc259 | 2011-11-05 15:35:00 +0000 | [diff] [blame] | 26 | uint32_t Offset; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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: |
Benjamin Kramer | 15ec085 | 2011-09-14 00:15:32 +0000 | [diff] [blame] | 37 | DWARFDebugInfoEntryMinimal() |
| 38 | : Offset(0), ParentIdx(0), SiblingIdx(0), AbbrevDecl(0) {} |
| 39 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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 | |
| 53 | uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; } |
| 54 | bool isNULL() const { return AbbrevDecl == 0; } |
Benjamin Kramer | 80cc259 | 2011-11-05 15:35:00 +0000 | [diff] [blame] | 55 | uint32_t getOffset() const { return Offset; } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 56 | uint32_t getNumAttributes() const { |
| 57 | return !isNULL() ? AbbrevDecl->getNumAttributes() : 0; |
| 58 | } |
| 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". |
| 63 | DWARFDebugInfoEntryMinimal *getParent() { |
| 64 | return ParentIdx > 0 ? this - ParentIdx : 0; |
| 65 | } |
| 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". |
| 71 | DWARFDebugInfoEntryMinimal *getSibling() { |
| 72 | return SiblingIdx > 0 ? this + SiblingIdx : 0; |
| 73 | } |
| 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... |
| 80 | DWARFDebugInfoEntryMinimal *getFirstChild() { |
| 81 | return hasChildren() ? this + 1 : 0; |
| 82 | } |
| 83 | const DWARFDebugInfoEntryMinimal *getFirstChild() const { |
| 84 | return hasChildren() ? this + 1 : 0; |
| 85 | } |
| 86 | |
| 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; |
Benjamin Kramer | 4aa3fea | 2011-09-13 21:47:32 +0000 | [diff] [blame] | 92 | } else |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 93 | ParentIdx = 0; |
| 94 | } |
| 95 | void setSibling(DWARFDebugInfoEntryMinimal *sibling) { |
Benjamin Kramer | 4aa3fea | 2011-09-13 21:47:32 +0000 | [diff] [blame] | 96 | if (sibling) { |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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()); |
Benjamin Kramer | 4aa3fea | 2011-09-13 21:47:32 +0000 | [diff] [blame] | 101 | } else |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 102 | SiblingIdx = 0; |
| 103 | } |
| 104 | |
| 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; |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 128 | |
| 129 | void buildAddressRangeTable(const DWARFCompileUnit *cu, |
| 130 | DWARFDebugAranges *debug_aranges) const; |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 131 | |
| 132 | bool addressRangeContainsAddress(const DWARFCompileUnit *cu, |
| 133 | const uint64_t address) const; |
| 134 | |
Alexey Samsonov | 9d26b0b | 2012-07-17 15:28:35 +0000 | [diff] [blame] | 135 | // If a DIE represents a subprogram, returns its mangled name |
| 136 | // (or short name, if mangled is missing). This name may be fetched |
| 137 | // from specification or abstract origin for this subprogram. |
| 138 | // Returns null if no name is found. |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 139 | const char* getSubprogramName(const DWARFCompileUnit *cu) const; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | } |
| 143 | |
| 144 | #endif |