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 /// Extract a debug info entry for a given compile unit from the
54 /// .debug_info and .debug_abbrev data starting at the given offset.
55 /// If compile unit can't be parsed, returns false and doesn't change
57 bool extract(const DWARFUnit *U, uint32_t *OffsetPtr);
59 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
60 bool isNULL() const { return AbbrevDecl == 0; }
62 /// Returns true if DIE represents a subprogram (not inlined).
63 bool isSubprogramDIE() const;
64 /// Returns true if DIE represents a subprogram or an inlined
66 bool isSubroutineDIE() const;
68 uint32_t getOffset() const { return Offset; }
69 uint32_t getNumAttributes() const {
70 return !isNULL() ? AbbrevDecl->getNumAttributes() : 0;
72 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
74 // We know we are kept in a vector of contiguous entries, so we know
75 // our parent will be some index behind "this".
76 DWARFDebugInfoEntryMinimal *getParent() {
77 return ParentIdx > 0 ? this - ParentIdx : 0;
79 const DWARFDebugInfoEntryMinimal *getParent() const {
80 return ParentIdx > 0 ? this - ParentIdx : 0;
82 // We know we are kept in a vector of contiguous entries, so we know
83 // our sibling will be some index after "this".
84 DWARFDebugInfoEntryMinimal *getSibling() {
85 return SiblingIdx > 0 ? this + SiblingIdx : 0;
87 const DWARFDebugInfoEntryMinimal *getSibling() const {
88 return SiblingIdx > 0 ? this + SiblingIdx : 0;
90 // We know we are kept in a vector of contiguous entries, so we know
91 // we don't need to store our child pointer, if we have a child it will
92 // be the next entry in the list...
93 DWARFDebugInfoEntryMinimal *getFirstChild() {
94 return hasChildren() ? this + 1 : 0;
96 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
97 return hasChildren() ? this + 1 : 0;
100 void setParent(DWARFDebugInfoEntryMinimal *parent) {
102 // We know we are kept in a vector of contiguous entries, so we know
103 // our parent will be some index behind "this".
104 ParentIdx = this - parent;
108 void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
110 // We know we are kept in a vector of contiguous entries, so we know
111 // our sibling will be some index after "this".
112 SiblingIdx = sibling - this;
113 sibling->setParent(getParent());
118 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
122 bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr,
123 DWARFFormValue &FormValue) const;
125 const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr,
126 const char *FailValue) const;
128 uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr,
129 uint64_t FailValue) const;
131 uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U,
133 uint64_t FailValue) const;
135 uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr,
136 uint64_t FailValue) const;
138 uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U,
140 uint64_t FailValue) const;
142 /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
143 /// Returns true if both attributes are present.
144 bool getLowAndHighPC(const DWARFUnit *U, uint64_t &LowPC,
145 uint64_t &HighPC) const;
147 void buildAddressRangeTable(const DWARFUnit *U,
148 DWARFDebugAranges *DebugAranges,
149 uint32_t CUOffsetInAranges) const;
151 bool addressRangeContainsAddress(const DWARFUnit *U,
152 const uint64_t Address) const;
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 DWARFUnit *U) const;
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 DWARFUnit *U, uint32_t &CallFile,
163 uint32_t &CallLine, uint32_t &CallColumn) const;
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
168 DWARFDebugInfoEntryInlinedChain
169 getInlinedChainForAddress(const DWARFUnit *U, const uint64_t Address) const;
172 /// DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine
173 /// DIEs, (possibly ending with subprogram DIE), all of which are contained
174 /// in some concrete inlined instance tree. Address range for each DIE
175 /// (except the last DIE) in this chain is contained in address
176 /// range for next DIE in the chain.
177 struct DWARFDebugInfoEntryInlinedChain {
178 DWARFDebugInfoEntryInlinedChain() : U(0) {}
179 SmallVector<DWARFDebugInfoEntryMinimal, 4> DIEs;