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