blob: e073d87b2b5e6154526d76e99f18a114cccbeb08 [file] [log] [blame]
Benjamin Krameraa2f78f2011-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 Samsonovc942e6b2012-09-04 08:12:33 +000014#include "llvm/ADT/SmallVector.h"
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000015#include "llvm/Support/DataTypes.h"
16
17namespace llvm {
18
Benjamin Kramer32664932011-09-14 20:52:27 +000019class DWARFDebugAranges;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000020class DWARFCompileUnit;
David Blaikie07e22442013-09-23 22:44:40 +000021class DWARFUnit;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000022class DWARFContext;
23class DWARFFormValue;
Alexey Samsonov3211e612013-08-06 10:49:15 +000024struct DWARFDebugInfoEntryInlinedChain;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000025
26/// DWARFDebugInfoEntryMinimal - A DIE with only the minimum required data.
27class DWARFDebugInfoEntryMinimal {
28 /// Offset within the .debug_info of the start of this entry.
Benjamin Kramerf7e0a312011-11-05 15:35:00 +000029 uint32_t Offset;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000030
31 /// How many to subtract from "this" to get the parent.
32 /// If zero this die has no parent.
33 uint32_t ParentIdx;
34
35 /// How many to add to "this" to get the sibling.
36 uint32_t SiblingIdx;
37
38 const DWARFAbbreviationDeclaration *AbbrevDecl;
39public:
Benjamin Kramer1b2a65c2011-09-14 00:15:32 +000040 DWARFDebugInfoEntryMinimal()
41 : Offset(0), ParentIdx(0), SiblingIdx(0), AbbrevDecl(0) {}
42
David Blaikie07e22442013-09-23 22:44:40 +000043 void dump(raw_ostream &OS, const DWARFUnit *u, unsigned recurseDepth,
44 unsigned indent = 0) const;
45 void dumpAttribute(raw_ostream &OS, const DWARFUnit *u, uint32_t *offset_ptr,
46 uint16_t attr, uint16_t form, unsigned indent = 0) const;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000047
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000048 /// Extracts a debug info entry, which is a child of a given compile unit,
49 /// starting at a given offset. If DIE can't be extracted, returns false and
50 /// doesn't change OffsetPtr.
David Blaikie07e22442013-09-23 22:44:40 +000051 bool extractFast(const DWARFUnit *U, const uint8_t *FixedFormSizes,
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000052 uint32_t *OffsetPtr);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000053
54 /// Extract a debug info entry for a given compile unit from the
55 /// .debug_info and .debug_abbrev data starting at the given offset.
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000056 /// If compile unit can't be parsed, returns false and doesn't change
57 /// OffsetPtr.
David Blaikie07e22442013-09-23 22:44:40 +000058 bool extract(const DWARFUnit *U, uint32_t *OffsetPtr);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000059
60 uint32_t getTag() const { return AbbrevDecl ? AbbrevDecl->getTag() : 0; }
61 bool isNULL() const { return AbbrevDecl == 0; }
Alexey Samsonovc942e6b2012-09-04 08:12:33 +000062
63 /// Returns true if DIE represents a subprogram (not inlined).
64 bool isSubprogramDIE() const;
65 /// Returns true if DIE represents a subprogram or an inlined
66 /// subroutine.
67 bool isSubroutineDIE() const;
68
Benjamin Kramerf7e0a312011-11-05 15:35:00 +000069 uint32_t getOffset() const { return Offset; }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000070 uint32_t getNumAttributes() const {
71 return !isNULL() ? AbbrevDecl->getNumAttributes() : 0;
72 }
73 bool hasChildren() const { return !isNULL() && AbbrevDecl->hasChildren(); }
74
75 // We know we are kept in a vector of contiguous entries, so we know
76 // our parent will be some index behind "this".
77 DWARFDebugInfoEntryMinimal *getParent() {
78 return ParentIdx > 0 ? this - ParentIdx : 0;
79 }
80 const DWARFDebugInfoEntryMinimal *getParent() const {
81 return ParentIdx > 0 ? this - ParentIdx : 0;
82 }
83 // We know we are kept in a vector of contiguous entries, so we know
84 // our sibling will be some index after "this".
85 DWARFDebugInfoEntryMinimal *getSibling() {
86 return SiblingIdx > 0 ? this + SiblingIdx : 0;
87 }
88 const DWARFDebugInfoEntryMinimal *getSibling() const {
89 return SiblingIdx > 0 ? this + SiblingIdx : 0;
90 }
91 // We know we are kept in a vector of contiguous entries, so we know
92 // we don't need to store our child pointer, if we have a child it will
93 // be the next entry in the list...
94 DWARFDebugInfoEntryMinimal *getFirstChild() {
95 return hasChildren() ? this + 1 : 0;
96 }
97 const DWARFDebugInfoEntryMinimal *getFirstChild() const {
98 return hasChildren() ? this + 1 : 0;
99 }
100
101 void setParent(DWARFDebugInfoEntryMinimal *parent) {
102 if (parent) {
103 // We know we are kept in a vector of contiguous entries, so we know
104 // our parent will be some index behind "this".
105 ParentIdx = this - parent;
Benjamin Kramereaa74332011-09-13 21:47:32 +0000106 } else
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000107 ParentIdx = 0;
108 }
109 void setSibling(DWARFDebugInfoEntryMinimal *sibling) {
Benjamin Kramereaa74332011-09-13 21:47:32 +0000110 if (sibling) {
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000111 // We know we are kept in a vector of contiguous entries, so we know
112 // our sibling will be some index after "this".
113 SiblingIdx = sibling - this;
114 sibling->setParent(getParent());
Benjamin Kramereaa74332011-09-13 21:47:32 +0000115 } else
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000116 SiblingIdx = 0;
117 }
118
119 const DWARFAbbreviationDeclaration *getAbbreviationDeclarationPtr() const {
120 return AbbrevDecl;
121 }
122
Alexey Samsonovcaabb0e2013-10-17 13:28:16 +0000123 bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr,
124 DWARFFormValue &FormValue) const;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000125
Alexey Samsonovcaabb0e2013-10-17 13:28:16 +0000126 const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr,
127 const char *FailValue) const;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000128
David Blaikie07e22442013-09-23 22:44:40 +0000129 uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr,
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000130 uint64_t FailValue) const;
131
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000132 uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U,
133 const uint16_t Attr,
134 uint64_t FailValue) const;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000135
Alexey Samsonovcaabb0e2013-10-17 13:28:16 +0000136 uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr,
137 uint64_t FailValue) const;
Benjamin Kramer32664932011-09-14 20:52:27 +0000138
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000139 uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U,
140 const uint16_t Attr,
141 uint64_t FailValue) const;
142
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000143 /// Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
144 /// Returns true if both attributes are present.
David Blaikie07e22442013-09-23 22:44:40 +0000145 bool getLowAndHighPC(const DWARFUnit *U, uint64_t &LowPC,
146 uint64_t &HighPC) const;
Alexey Samsonovf4462fa2012-07-02 05:54:45 +0000147
David Blaikie07e22442013-09-23 22:44:40 +0000148 void buildAddressRangeTable(const DWARFUnit *U,
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000149 DWARFDebugAranges *DebugAranges,
150 uint32_t CUOffsetInAranges) const;
Alexey Samsonovf4462fa2012-07-02 05:54:45 +0000151
David Blaikie07e22442013-09-23 22:44:40 +0000152 bool addressRangeContainsAddress(const DWARFUnit *U,
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000153 const uint64_t Address) const;
154
155 /// If a DIE represents a subprogram (or inlined subroutine),
156 /// returns its mangled name (or short name, if mangled is missing).
157 /// This name may be fetched from specification or abstract origin
158 /// for this subprogram. Returns null if no name is found.
David Blaikie07e22442013-09-23 22:44:40 +0000159 const char *getSubroutineName(const DWARFUnit *U) const;
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000160
161 /// Retrieves values of DW_AT_call_file, DW_AT_call_line and
162 /// DW_AT_call_column from DIE (or zeroes if they are missing).
David Blaikie07e22442013-09-23 22:44:40 +0000163 void getCallerFrame(const DWARFUnit *U, uint32_t &CallFile,
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000164 uint32_t &CallLine, uint32_t &CallColumn) const;
165
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000166 /// Get inlined chain for a given address, rooted at the current DIE.
167 /// Returns empty chain if address is not contained in address range
168 /// of current DIE.
Alexey Samsonov3211e612013-08-06 10:49:15 +0000169 DWARFDebugInfoEntryInlinedChain
David Blaikie07e22442013-09-23 22:44:40 +0000170 getInlinedChainForAddress(const DWARFUnit *U, const uint64_t Address) const;
Alexey Samsonov3211e612013-08-06 10:49:15 +0000171};
172
173/// DWARFDebugInfoEntryInlinedChain - represents a chain of inlined_subroutine
174/// DIEs, (possibly ending with subprogram DIE), all of which are contained
175/// in some concrete inlined instance tree. Address range for each DIE
176/// (except the last DIE) in this chain is contained in address
177/// range for next DIE in the chain.
178struct DWARFDebugInfoEntryInlinedChain {
David Blaikie07e22442013-09-23 22:44:40 +0000179 DWARFDebugInfoEntryInlinedChain() : U(0) {}
Alexey Samsonov3211e612013-08-06 10:49:15 +0000180 SmallVector<DWARFDebugInfoEntryMinimal, 4> DIEs;
David Blaikie07e22442013-09-23 22:44:40 +0000181 const DWARFUnit *U;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000182};
183
184}
185
186#endif