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