35140d7359444f96ebfa3d3e90d085ebf511535d
[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 add to "this" to get the sibling.
33   uint32_t SiblingIdx;
34
35   const DWARFAbbreviationDeclaration *AbbrevDecl;
36 public:
37   DWARFDebugInfoEntryMinimal()
38     : Offset(0), SiblingIdx(0), AbbrevDecl(nullptr) {}
39
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;
44
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);
49
50   uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
51   bool isNULL() const { return AbbrevDecl == nullptr; }
52
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
56   /// subroutine.
57   bool isSubroutineDIE() const;
58
59   uint32_t getOffset() const { return Offset; }
60   bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
61
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;
66   }
67
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;
73   }
74
75   void setSibling(const DWARFDebugInfoEntryMinimal *Sibling) {
76     if (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;
80     } else
81       SiblingIdx = 0;
82   }
83
84   const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
85     return AbbrevDecl;
86   }
87
88   bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr,
89                          DWARFFormValue &FormValue) const;
90
91   const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr,
92                                         const char *FailValue) const;
93
94   uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr,
95                                       uint64_t FailValue) const;
96
97   uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U,
98                                                const uint16_t Attr,
99                                                uint64_t FailValue) const;
100
101   uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr,
102                                         uint64_t FailValue) const;
103
104   uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U,
105                                             const uint16_t Attr,
106                                             uint64_t FailValue) const;
107
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;
112
113   DWARFAddressRangesVector getAddressRanges(const DWARFUnit *U) const;
114
115   void collectChildrenAddressRanges(const DWARFUnit *U,
116                                     DWARFAddressRangesVector &Ranges) const;
117
118   bool addressRangeContainsAddress(const DWARFUnit *U,
119                                    const uint64_t Address) const;
120
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;
126
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;
131
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
134   /// of current DIE.
135   DWARFDebugInfoEntryInlinedChain
136   getInlinedChainForAddress(const DWARFUnit *U, const uint64_t Address) const;
137 };
138
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;
147   const DWARFUnit *U;
148 };
149
150 }
151
152 #endif