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 "DWARFDebugRangeList.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/Support/DataTypes.h"
20 class DWARFDebugAranges;
21 class DWARFCompileUnit;
25 struct DWARFDebugInfoEntryInlinedChain;
27 /// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
28 class DWARFDebugInfoEntryMinimal {
29 /// Offset within the .debug_info of the start of this entry.
32 /// How many to add to "this" to get the sibling.
35 const DWARFAbbreviationDeclaration *AbbrevDecl;
37 DWARFDebugInfoEntryMinimal()
38 : Offset(0), SiblingIdx(0), AbbrevDecl(nullptr) {}
40 void dump(raw_ostream &OS, const DWARFUnit *u, unsigned recurseDepth,
41 unsigned indent = 0) const;
42 void dumpAttribute(raw_ostream &OS, const DWARFUnit *u, uint32_t *offset_ptr,
43 uint16_t attr, uint16_t form, unsigned indent = 0) const;
45 /// Extracts a debug info entry, which is a child of a given unit,
46 /// starting at a given offset. If DIE can't be extracted, returns false and
47 /// doesn't change OffsetPtr.
48 bool extractFast(const DWARFUnit *U, uint32_t *OffsetPtr);
50 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
51 bool isNULL() const { return AbbrevDecl == nullptr; }
53 /// Returns true if DIE represents a subprogram (not inlined).
54 bool isSubprogramDIE() const;
55 /// Returns true if DIE represents a subprogram or an inlined
57 bool isSubroutineDIE() const;
59 uint32_t getOffset() const { return Offset; }
60 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
62 // We know we are kept in a vector of contiguous entries, so we know
63 // our sibling will be some index after "this".
64 const DWARFDebugInfoEntryMinimal *getSibling() const {
65 return SiblingIdx > 0 ? this + SiblingIdx : nullptr;
68 // We know we are kept in a vector of contiguous entries, so we know
69 // we don't need to store our child pointer, if we have a child it will
70 // be the next entry in the list...
71 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
72 return hasChildren() ? this + 1 : nullptr;
75 void setSibling(const DWARFDebugInfoEntryMinimal *Sibling) {
77 // We know we are kept in a vector of contiguous entries, so we know
78 // our sibling will be some index after "this".
79 SiblingIdx = Sibling - this;
84 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
88 bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr,
89 DWARFFormValue &FormValue) const;
91 const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr,
92 const char *FailValue) const;
94 uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr,
95 uint64_t FailValue) const;
97 uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U,
99 uint64_t FailValue) const;
101 uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr,
102 uint64_t FailValue) const;
104 uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U,
106 uint64_t FailValue) const;
108 /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
109 /// Returns true if both attributes are present.
110 bool getLowAndHighPC(const DWARFUnit *U, uint64_t &LowPC,
111 uint64_t &HighPC) const;
113 DWARFAddressRangesVector getAddressRanges(const DWARFUnit *U) const;
115 void collectChildrenAddressRanges(const DWARFUnit *U,
116 DWARFAddressRangesVector &Ranges) const;
118 bool addressRangeContainsAddress(const DWARFUnit *U,
119 const uint64_t Address) const;
121 /// If a DIE represents a subprogram (or inlined subroutine),
122 /// returns its mangled name (or short name, if mangled is missing).
123 /// This name may be fetched from specification or abstract origin
124 /// for this subprogram. Returns null if no name is found.
125 const char *getSubroutineName(const DWARFUnit *U) const;
127 /// Retrieves values of DW_AT_call_file, DW_AT_call_line and
128 /// DW_AT_call_column from DIE (or zeroes if they are missing).
129 void getCallerFrame(const DWARFUnit *U, uint32_t &CallFile,
130 uint32_t &CallLine, uint32_t &CallColumn) const;
132 /// Get inlined chain for a given address, rooted at the current DIE.
133 /// Returns empty chain if address is not contained in address range
135 DWARFDebugInfoEntryInlinedChain
136 getInlinedChainForAddress(const DWARFUnit *U, const uint64_t Address) const;
139 /// DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine
140 /// DIEs, (possibly ending with subprogram DIE), all of which are contained
141 /// in some concrete inlined instance tree. Address range for each DIE
142 /// (except the last DIE) in this chain is contained in address
143 /// range for next DIE in the chain.
144 struct DWARFDebugInfoEntryInlinedChain {
145 DWARFDebugInfoEntryInlinedChain() : U(nullptr) {}
146 SmallVector<DWARFDebugInfoEntryMinimal, 4> DIEs;