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_LIB_DEBUGINFO_DWARFDEBUGINFOENTRY_H
11 #define LLVM_LIB_DEBUGINFO_DWARFDEBUGINFOENTRY_H
13 #include "DWARFAbbreviationDeclaration.h"
14 #include "DWARFDebugRangeList.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/DebugInfo/DIContext.h"
17 #include "llvm/Support/DataTypes.h"
21 class DWARFDebugAranges;
22 class DWARFCompileUnit;
26 struct DWARFDebugInfoEntryInlinedChain;
28 /// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
29 class DWARFDebugInfoEntryMinimal {
30 /// Offset within the .debug_info of the start of this entry.
33 /// How many to add to "this" to get the sibling.
36 const DWARFAbbreviationDeclaration *AbbrevDecl;
38 DWARFDebugInfoEntryMinimal()
39 : Offset(0), SiblingIdx(0), AbbrevDecl(nullptr) {}
41 void dump(raw_ostream &OS, const DWARFUnit *u, unsigned recurseDepth,
42 unsigned indent = 0) const;
43 void dumpAttribute(raw_ostream &OS, const DWARFUnit *u, uint32_t *offset_ptr,
44 uint16_t attr, uint16_t form, unsigned indent = 0) const;
46 /// Extracts a debug info entry, which is a child of a given unit,
47 /// starting at a given offset. If DIE can't be extracted, returns false and
48 /// doesn't change OffsetPtr.
49 bool extractFast(const DWARFUnit *U, uint32_t *OffsetPtr);
51 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
52 bool isNULL() const { return AbbrevDecl == nullptr; }
54 /// Returns true if DIE represents a subprogram (not inlined).
55 bool isSubprogramDIE() const;
56 /// Returns true if DIE represents a subprogram or an inlined
58 bool isSubroutineDIE() const;
60 uint32_t getOffset() const { return Offset; }
61 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
63 // We know we are kept in a vector of contiguous entries, so we know
64 // our sibling will be some index after "this".
65 const DWARFDebugInfoEntryMinimal *getSibling() const {
66 return SiblingIdx > 0 ? this + SiblingIdx : nullptr;
69 // We know we are kept in a vector of contiguous entries, so we know
70 // we don't need to store our child pointer, if we have a child it will
71 // be the next entry in the list...
72 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
73 return hasChildren() ? this + 1 : nullptr;
76 void setSibling(const DWARFDebugInfoEntryMinimal *Sibling) {
78 // We know we are kept in a vector of contiguous entries, so we know
79 // our sibling will be some index after "this".
80 SiblingIdx = Sibling - this;
85 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
89 bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr,
90 DWARFFormValue &FormValue) const;
92 const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr,
93 const char *FailValue) const;
95 uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr,
96 uint64_t FailValue) const;
98 uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U,
100 uint64_t FailValue) const;
102 uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr,
103 uint64_t FailValue) const;
105 uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U,
107 uint64_t FailValue) const;
109 uint64_t getRangesBaseAttribute(const DWARFUnit *U, uint64_t FailValue) const;
111 /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
112 /// Returns true if both attributes are present.
113 bool getLowAndHighPC(const DWARFUnit *U, uint64_t &LowPC,
114 uint64_t &HighPC) const;
116 DWARFAddressRangesVector getAddressRanges(const DWARFUnit *U) const;
118 void collectChildrenAddressRanges(const DWARFUnit *U,
119 DWARFAddressRangesVector &Ranges) const;
121 bool addressRangeContainsAddress(const DWARFUnit *U,
122 const uint64_t Address) const;
124 /// If a DIE represents a subprogram (or inlined subroutine),
125 /// returns its mangled name (or short name, if mangled is missing).
126 /// This name may be fetched from specification or abstract origin
127 /// for this subprogram. Returns null if no name is found.
129 getSubroutineName(const DWARFUnit *U,
130 DILineInfoSpecifier::FunctionNameKind Kind) const;
132 /// Retrieves values of DW_AT_call_file, DW_AT_call_line and
133 /// DW_AT_call_column from DIE (or zeroes if they are missing).
134 void getCallerFrame(const DWARFUnit *U, uint32_t &CallFile,
135 uint32_t &CallLine, uint32_t &CallColumn) const;
137 /// Get inlined chain for a given address, rooted at the current DIE.
138 /// Returns empty chain if address is not contained in address range
140 DWARFDebugInfoEntryInlinedChain
141 getInlinedChainForAddress(const DWARFUnit *U, const uint64_t Address) const;
144 /// DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine
145 /// DIEs, (possibly ending with subprogram DIE), all of which are contained
146 /// in some concrete inlined instance tree. Address range for each DIE
147 /// (except the last DIE) in this chain is contained in address
148 /// range for next DIE in the chain.
149 struct DWARFDebugInfoEntryInlinedChain {
150 DWARFDebugInfoEntryInlinedChain() : U(nullptr) {}
151 SmallVector<DWARFDebugInfoEntryMinimal, 4> DIEs;