blob: 9c1b2be0a71fa184375121fdfd04df4b91f3f0fb [file] [log] [blame]
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +00001//===-- 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"
Alexey Samsonov5eae90d2012-09-04 08:12:33 +000014#include "llvm/ADT/SmallVector.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000015#include "llvm/Support/DataTypes.h"
16
17namespace llvm {
18
Benjamin Kramer10df8062011-09-14 20:52:27 +000019class DWARFDebugAranges;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000020class DWARFCompileUnit;
21class DWARFContext;
22class DWARFFormValue;
Alexey Samsonov5eae90d2012-09-04 08:12:33 +000023class DWARFInlinedSubroutineChain;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000024
25/// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
26class DWARFDebugInfoEntryMinimal {
27 /// Offset within the .debug_info of the start of this entry.
Benjamin Kramer80cc2592011-11-05 15:35:00 +000028 uint32_t Offset;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000029
30 /// How many to subtract from "this" to get the parent.
31 /// If zero this die has no parent.
32 uint32_t ParentIdx;
33
34 /// How many to add to "this" to get the sibling.
35 uint32_t SiblingIdx;
36
37 const DWARFAbbreviationDeclaration *AbbrevDecl;
38public:
Benjamin Kramer15ec0852011-09-14 00:15:32 +000039 DWARFDebugInfoEntryMinimal()
40 : Offset(0), ParentIdx(0), SiblingIdx(0), AbbrevDecl(0) {}
41
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000042 void dump(raw_ostream &OS, const DWARFCompileUnit *cu,
43 unsigned recurseDepth, unsigned indent = 0) const;
44 void dumpAttribute(raw_ostream &OS, const DWARFCompileUnit *cu,
45 uint32_t *offset_ptr, uint16_t attr, uint16_t form,
46 unsigned indent = 0) const;
47
48 bool extractFast(const DWARFCompileUnit *cu, const uint8_t *fixed_form_sizes,
49 uint32_t *offset_ptr);
50
51 /// Extract a debug info entry for a given compile unit from the
52 /// .debug_info and .debug_abbrev data starting at the given offset.
53 bool extract(const DWARFCompileUnit *cu, uint32_t *offset_ptr);
54
55 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
56 bool isNULL() const { return AbbrevDecl == 0; }
Alexey Samsonov5eae90d2012-09-04 08:12:33 +000057
58 /// Returns true if DIE represents a subprogram (not inlined).
59 bool isSubprogramDIE() const;
60 /// Returns true if DIE represents a subprogram or an inlined
61 /// subroutine.
62 bool isSubroutineDIE() const;
63
Benjamin Kramer80cc2592011-11-05 15:35:00 +000064 uint32_t getOffset() const { return Offset; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000065 uint32_t getNumAttributes() const {
66 return !isNULL() ? AbbrevDecl->getNumAttributes() : 0;
67 }
68 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
69
70 // We know we are kept in a vector of contiguous entries, so we know
71 // our parent will be some index behind "this".
72 DWARFDebugInfoEntryMinimal *getParent() {
73 return ParentIdx > 0 ? this - ParentIdx : 0;
74 }
75 const DWARFDebugInfoEntryMinimal *getParent() const {
76 return ParentIdx > 0 ? this - ParentIdx : 0;
77 }
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 DWARFDebugInfoEntryMinimal *getSibling() {
81 return SiblingIdx > 0 ? this + SiblingIdx : 0;
82 }
83 const DWARFDebugInfoEntryMinimal *getSibling() const {
84 return SiblingIdx > 0 ? this + SiblingIdx : 0;
85 }
86 // We know we are kept in a vector of contiguous entries, so we know
87 // we don't need to store our child pointer, if we have a child it will
88 // be the next entry in the list...
89 DWARFDebugInfoEntryMinimal *getFirstChild() {
90 return hasChildren() ? this + 1 : 0;
91 }
92 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
93 return hasChildren() ? this + 1 : 0;
94 }
95
96 void setParent(DWARFDebugInfoEntryMinimal *parent) {
97 if (parent) {
98 // We know we are kept in a vector of contiguous entries, so we know
99 // our parent will be some index behind "this".
100 ParentIdx = this - parent;
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000101 } else
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000102 ParentIdx = 0;
103 }
104 void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000105 if (sibling) {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000106 // We know we are kept in a vector of contiguous entries, so we know
107 // our sibling will be some index after "this".
108 SiblingIdx = sibling - this;
109 sibling->setParent(getParent());
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000110 } else
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000111 SiblingIdx = 0;
112 }
113
114 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
115 return AbbrevDecl;
116 }
117
118 uint32_t getAttributeValue(const DWARFCompileUnit *cu,
119 const uint16_t attr, DWARFFormValue &formValue,
120 uint32_t *end_attr_offset_ptr = 0) const;
121
122 const char* getAttributeValueAsString(const DWARFCompileUnit* cu,
123 const uint16_t attr,
124 const char *fail_value) const;
125
126 uint64_t getAttributeValueAsUnsigned(const DWARFCompileUnit *cu,
127 const uint16_t attr,
128 uint64_t fail_value) const;
129
130 uint64_t getAttributeValueAsReference(const DWARFCompileUnit *cu,
131 const uint16_t attr,
132 uint64_t fail_value) const;
133
134 int64_t getAttributeValueAsSigned(const DWARFCompileUnit* cu,
135 const uint16_t attr,
136 int64_t fail_value) const;
Benjamin Kramer10df8062011-09-14 20:52:27 +0000137
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000138 /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
139 /// Returns true if both attributes are present.
140 bool getLowAndHighPC(const DWARFCompileUnit *CU,
141 uint64_t &LowPC, uint64_t &HighPC) const;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000142
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000143 void buildAddressRangeTable(const DWARFCompileUnit *CU,
144 DWARFDebugAranges *DebugAranges) const;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000145
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000146 bool addressRangeContainsAddress(const DWARFCompileUnit *CU,
147 const uint64_t Address) const;
148
149 /// If a DIE represents a subprogram (or inlined subroutine),
150 /// returns its mangled name (or short name, if mangled is missing).
151 /// This name may be fetched from specification or abstract origin
152 /// for this subprogram. Returns null if no name is found.
153 const char* getSubroutineName(const DWARFCompileUnit *CU) const;
154
155 /// Retrieves values of DW_AT_call_file, DW_AT_call_line and
156 /// DW_AT_call_column from DIE (or zeroes if they are missing).
157 void getCallerFrame(const DWARFCompileUnit *CU, uint32_t &CallFile,
158 uint32_t &CallLine, uint32_t &CallColumn) const;
159
160 /// InlinedChain - represents a chain of inlined_subroutine
161 /// DIEs, (possibly ending with subprogram DIE), all of which are contained
162 /// in some concrete inlined instance tree. Address range for each DIE
163 /// (except the last DIE) in this chain is contained in address
164 /// range for next DIE in the chain.
165 typedef SmallVector<DWARFDebugInfoEntryMinimal, 4> InlinedChain;
166
167 /// Get inlined chain for a given address, rooted at the current DIE.
168 /// Returns empty chain if address is not contained in address range
169 /// of current DIE.
170 InlinedChain getInlinedChainForAddress(const DWARFCompileUnit *CU,
171 const uint64_t Address) const;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000172};
173
174}
175
176#endif