1 //===-- DWARFDebugInfoEntry.h -----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H
11 #define LLVM_DEBUGINFO_DWARFDEBUGINFOENTRY_H
13 #include "DWARFAbbreviationDeclaration.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/Support/DataTypes.h"
19 class DWARFDebugAranges;
20 class DWARFCompileUnit;
24 struct DWARFDebugInfoEntryInlinedChain;
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.
31 /// How many to subtract from "this" to get the parent.
32 /// If zero this die has no parent.
35 /// How many to add to "this" to get the sibling.
38 const DWARFAbbreviationDeclaration *AbbrevDecl;
40 DWARFDebugInfoEntryMinimal()
41 : Offset(0), ParentIdx(0), SiblingIdx(0), AbbrevDecl(0) {}
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;
48 /// Extracts a debug info entry, which is a child of a given 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 DWARFUnit *U, uint32_t *OffsetPtr);
53 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
54 bool isNULL() const { return AbbrevDecl == 0; }
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
60 bool isSubroutineDIE() const;
62 uint32_t getOffset() const { return Offset; }
63 uint32_t getNumAttributes() const {
64 return !isNULL() ? AbbrevDecl->getNumAttributes() : 0;
66 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
68 // We know we are kept in a vector of contiguous entries, so we know
69 // our parent will be some index behind "this".
70 DWARFDebugInfoEntryMinimal *getParent() {
71 return ParentIdx > 0 ? this - ParentIdx : 0;
73 const DWARFDebugInfoEntryMinimal *getParent() const {
74 return ParentIdx > 0 ? this - ParentIdx : 0;
76 // We know we are kept in a vector of contiguous entries, so we know
77 // our sibling will be some index after "this".
78 DWARFDebugInfoEntryMinimal *getSibling() {
79 return SiblingIdx > 0 ? this + SiblingIdx : 0;
81 const DWARFDebugInfoEntryMinimal *getSibling() const {
82 return SiblingIdx > 0 ? this + SiblingIdx : 0;
84 // We know we are kept in a vector of contiguous entries, so we know
85 // we don't need to store our child pointer, if we have a child it will
86 // be the next entry in the list...
87 DWARFDebugInfoEntryMinimal *getFirstChild() {
88 return hasChildren() ? this + 1 : 0;
90 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
91 return hasChildren() ? this + 1 : 0;
94 void setParent(DWARFDebugInfoEntryMinimal *parent) {
96 // We know we are kept in a vector of contiguous entries, so we know
97 // our parent will be some index behind "this".
98 ParentIdx = this - parent;
102 void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
104 // We know we are kept in a vector of contiguous entries, so we know
105 // our sibling will be some index after "this".
106 SiblingIdx = sibling - this;
107 sibling->setParent(getParent());
112 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
116 bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr,
117 DWARFFormValue &FormValue) const;
119 const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr,
120 const char *FailValue) const;
122 uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr,
123 uint64_t FailValue) const;
125 uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U,
127 uint64_t FailValue) const;
129 uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr,
130 uint64_t FailValue) const;
132 uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U,
134 uint64_t FailValue) const;
136 /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
137 /// Returns true if both attributes are present.
138 bool getLowAndHighPC(const DWARFUnit *U, uint64_t &LowPC,
139 uint64_t &HighPC) const;
141 void buildAddressRangeTable(const DWARFUnit *U,
142 DWARFDebugAranges *DebugAranges,
143 uint32_t CUOffsetInAranges) const;
145 bool addressRangeContainsAddress(const DWARFUnit *U,
146 const uint64_t Address) const;
148 /// If a DIE represents a subprogram (or inlined subroutine),
149 /// returns its mangled name (or short name, if mangled is missing).
150 /// This name may be fetched from specification or abstract origin
151 /// for this subprogram. Returns null if no name is found.
152 const char *getSubroutineName(const DWARFUnit *U) const;
154 /// Retrieves values of DW_AT_call_file, DW_AT_call_line and
155 /// DW_AT_call_column from DIE (or zeroes if they are missing).
156 void getCallerFrame(const DWARFUnit *U, uint32_t &CallFile,
157 uint32_t &CallLine, uint32_t &CallColumn) const;
159 /// Get inlined chain for a given address, rooted at the current DIE.
160 /// Returns empty chain if address is not contained in address range
162 DWARFDebugInfoEntryInlinedChain
163 getInlinedChainForAddress(const DWARFUnit *U, const uint64_t Address) const;
166 /// DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine
167 /// DIEs, (possibly ending with subprogram DIE), all of which are contained
168 /// in some concrete inlined instance tree. Address range for each DIE
169 /// (except the last DIE) in this chain is contained in address
170 /// range for next DIE in the chain.
171 struct DWARFDebugInfoEntryInlinedChain {
172 DWARFDebugInfoEntryInlinedChain() : U(0) {}
173 SmallVector<DWARFDebugInfoEntryMinimal, 4> DIEs;