blob: fd801a22c215ee040da6a1c6decd884083b6ec10 [file] [log] [blame]
Eric Christopherbd5bc212012-08-23 00:52:51 +00001//===-- DWARFDebugInfoEntry.cpp -------------------------------------------===//
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +00002//
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#include "DWARFDebugInfoEntry.h"
11#include "DWARFCompileUnit.h"
12#include "DWARFContext.h"
13#include "DWARFDebugAbbrev.h"
Alexey Samsonovcd614552013-04-17 08:29:02 +000014#include "llvm/DebugInfo/DWARFFormValue.h"
Eric Christopherdd8e9f32013-01-07 19:32:41 +000015#include "llvm/Support/Debug.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000016#include "llvm/Support/Dwarf.h"
17#include "llvm/Support/Format.h"
18#include "llvm/Support/raw_ostream.h"
19using namespace llvm;
20using namespace dwarf;
21
David Blaikiecd7c4982013-09-23 22:44:40 +000022void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS, const DWARFUnit *u,
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000023 unsigned recurseDepth,
24 unsigned indent) const {
David Blaikiecd7c4982013-09-23 22:44:40 +000025 DataExtractor debug_info_data = u->getDebugInfoExtractor();
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000026 uint32_t offset = Offset;
27
28 if (debug_info_data.isValidOffset(offset)) {
Benjamin Kramer80cc2592011-11-05 15:35:00 +000029 uint32_t abbrCode = debug_info_data.getULEB128(&offset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000030
Benjamin Kramer09422552011-09-14 17:54:56 +000031 OS << format("\n0x%8.8x: ", Offset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000032 if (abbrCode) {
33 if (AbbrevDecl) {
Benjamin Kramer75c63082011-09-15 05:43:00 +000034 const char *tagString = TagString(getTag());
35 if (tagString)
36 OS.indent(indent) << tagString;
37 else
38 OS.indent(indent) << format("DW_TAG_Unknown_%x", getTag());
39 OS << format(" [%u] %c\n", abbrCode,
40 AbbrevDecl->hasChildren() ? '*' : ' ');
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000041
Eric Christophere5ef3052013-01-07 03:27:58 +000042 // Dump all data in the DIE for the attributes.
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000043 const uint32_t numAttributes = AbbrevDecl->getNumAttributes();
44 for (uint32_t i = 0; i != numAttributes; ++i) {
45 uint16_t attr = AbbrevDecl->getAttrByIndex(i);
46 uint16_t form = AbbrevDecl->getFormByIndex(i);
David Blaikiecd7c4982013-09-23 22:44:40 +000047 dumpAttribute(OS, u, &offset, attr, form, indent);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000048 }
49
50 const DWARFDebugInfoEntryMinimal *child = getFirstChild();
51 if (recurseDepth > 0 && child) {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000052 while (child) {
David Blaikiecd7c4982013-09-23 22:44:40 +000053 child->dump(OS, u, recurseDepth-1, indent+2);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000054 child = child->getSibling();
55 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000056 }
57 } else {
58 OS << "Abbreviation code not found in 'debug_abbrev' class for code: "
59 << abbrCode << '\n';
60 }
61 } else {
Benjamin Kramer09422552011-09-14 17:54:56 +000062 OS.indent(indent) << "NULL\n";
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000063 }
64 }
65}
66
67void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS,
David Blaikiecd7c4982013-09-23 22:44:40 +000068 const DWARFUnit *u,
69 uint32_t *offset_ptr,
70 uint16_t attr, uint16_t form,
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000071 unsigned indent) const {
David Blaikiea9b69792013-08-19 03:36:23 +000072 OS << " ";
Benjamin Kramer75c63082011-09-15 05:43:00 +000073 OS.indent(indent+2);
74 const char *attrString = AttributeString(attr);
75 if (attrString)
76 OS << attrString;
77 else
78 OS << format("DW_AT_Unknown_%x", attr);
79 const char *formString = FormEncodingString(form);
80 if (formString)
81 OS << " [" << formString << ']';
82 else
83 OS << format(" [DW_FORM_Unknown_%x]", form);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000084
85 DWARFFormValue formValue(form);
86
David Blaikiecd7c4982013-09-23 22:44:40 +000087 if (!formValue.extractValue(u->getDebugInfoExtractor(), offset_ptr, u))
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000088 return;
89
90 OS << "\t(";
David Blaikiecd7c4982013-09-23 22:44:40 +000091 formValue.dump(OS, u);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000092 OS << ")\n";
93}
94
David Blaikiecd7c4982013-09-23 22:44:40 +000095bool DWARFDebugInfoEntryMinimal::extractFast(const DWARFUnit *U,
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +000096 const uint8_t *FixedFormSizes,
97 uint32_t *OffsetPtr) {
98 Offset = *OffsetPtr;
David Blaikiecd7c4982013-09-23 22:44:40 +000099 DataExtractor DebugInfoData = U->getDebugInfoExtractor();
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000100 uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
101 if (0 == AbbrCode) {
102 // NULL debug tag entry.
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000103 AbbrevDecl = NULL;
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000104 return true;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000105 }
David Blaikiecd7c4982013-09-23 22:44:40 +0000106 AbbrevDecl = U->getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000107 assert(AbbrevDecl);
108 assert(FixedFormSizes); // For best performance this should be specified!
109
110 // Skip all data in the .debug_info for the attributes
111 for (uint32_t i = 0, n = AbbrevDecl->getNumAttributes(); i < n; ++i) {
112 uint16_t Form = AbbrevDecl->getFormByIndex(i);
113
114 // FIXME: Currently we're checking if this is less than the last
115 // entry in the fixed_form_sizes table, but this should be changed
116 // to use dynamic dispatch.
117 uint8_t FixedFormSize =
118 (Form < DW_FORM_ref_sig8) ? FixedFormSizes[Form] : 0;
119 if (FixedFormSize)
120 *OffsetPtr += FixedFormSize;
121 else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr,
David Blaikiecd7c4982013-09-23 22:44:40 +0000122 U)) {
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000123 // Restore the original offset.
124 *OffsetPtr = Offset;
125 return false;
126 }
127 }
128 return true;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000129}
130
David Blaikiecd7c4982013-09-23 22:44:40 +0000131bool DWARFDebugInfoEntryMinimal::extract(const DWARFUnit *U,
132 uint32_t *OffsetPtr) {
133 DataExtractor DebugInfoData = U->getDebugInfoExtractor();
134 const uint32_t UEndOffset = U->getNextUnitOffset();
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000135 Offset = *OffsetPtr;
David Blaikiecd7c4982013-09-23 22:44:40 +0000136 if ((Offset >= UEndOffset) || !DebugInfoData.isValidOffset(Offset))
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000137 return false;
138 uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
139 if (0 == AbbrCode) {
140 // NULL debug tag entry.
141 AbbrevDecl = NULL;
142 return true;
143 }
David Blaikiecd7c4982013-09-23 22:44:40 +0000144 AbbrevDecl = U->getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000145 if (0 == AbbrevDecl) {
146 // Restore the original offset.
147 *OffsetPtr = Offset;
148 return false;
149 }
150 bool IsCompileUnitTag = (AbbrevDecl->getTag() == DW_TAG_compile_unit);
151 if (IsCompileUnitTag)
David Blaikiecd7c4982013-09-23 22:44:40 +0000152 const_cast<DWARFUnit *>(U)->setBaseAddress(0);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000153
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000154 // Skip all data in the .debug_info for the attributes
155 for (uint32_t i = 0, n = AbbrevDecl->getNumAttributes(); i < n; ++i) {
156 uint16_t Attr = AbbrevDecl->getAttrByIndex(i);
157 uint16_t Form = AbbrevDecl->getFormByIndex(i);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000158
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000159 if (IsCompileUnitTag &&
160 ((Attr == DW_AT_entry_pc) || (Attr == DW_AT_low_pc))) {
161 DWARFFormValue FormValue(Form);
David Blaikiecd7c4982013-09-23 22:44:40 +0000162 if (FormValue.extractValue(DebugInfoData, OffsetPtr, U)) {
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000163 if (Attr == DW_AT_low_pc || Attr == DW_AT_entry_pc)
David Blaikiecd7c4982013-09-23 22:44:40 +0000164 const_cast<DWARFUnit *>(U)->setBaseAddress(FormValue.getUnsigned());
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000165 }
David Blaikiecd7c4982013-09-23 22:44:40 +0000166 } else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, U)) {
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000167 // Restore the original offset.
168 *OffsetPtr = Offset;
169 return false;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000170 }
171 }
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000172 return true;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000173}
174
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000175bool DWARFDebugInfoEntryMinimal::isSubprogramDIE() const {
176 return getTag() == DW_TAG_subprogram;
177}
178
179bool DWARFDebugInfoEntryMinimal::isSubroutineDIE() const {
180 uint32_t Tag = getTag();
181 return Tag == DW_TAG_subprogram ||
182 Tag == DW_TAG_inlined_subroutine;
183}
184
David Blaikiecd7c4982013-09-23 22:44:40 +0000185uint32_t DWARFDebugInfoEntryMinimal::getAttributeValue(
186 const DWARFUnit *u, const uint16_t attr, DWARFFormValue &form_value,
187 uint32_t *end_attr_offset_ptr) const {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000188 if (AbbrevDecl) {
189 uint32_t attr_idx = AbbrevDecl->findAttributeIndex(attr);
190
191 if (attr_idx != -1U) {
192 uint32_t offset = getOffset();
193
David Blaikiecd7c4982013-09-23 22:44:40 +0000194 DataExtractor debug_info_data = u->getDebugInfoExtractor();
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000195
196 // Skip the abbreviation code so we are at the data for the attributes
197 debug_info_data.getULEB128(&offset);
198
199 uint32_t idx = 0;
200 while (idx < attr_idx)
201 DWARFFormValue::skipValue(AbbrevDecl->getFormByIndex(idx++),
David Blaikiecd7c4982013-09-23 22:44:40 +0000202 debug_info_data, &offset, u);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000203
204 const uint32_t attr_offset = offset;
205 form_value = DWARFFormValue(AbbrevDecl->getFormByIndex(idx));
David Blaikiecd7c4982013-09-23 22:44:40 +0000206 if (form_value.extractValue(debug_info_data, &offset, u)) {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000207 if (end_attr_offset_ptr)
208 *end_attr_offset_ptr = offset;
209 return attr_offset;
210 }
211 }
212 }
213
214 return 0;
215}
216
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000217const char *DWARFDebugInfoEntryMinimal::getAttributeValueAsString(
David Blaikiecd7c4982013-09-23 22:44:40 +0000218 const DWARFUnit *U, const uint16_t Attr, const char *FailValue) const {
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000219 DWARFFormValue FormValue;
David Blaikiecd7c4982013-09-23 22:44:40 +0000220 if (getAttributeValue(U, Attr, FormValue))
221 return FormValue.getAsCString(U);
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000222 return FailValue;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000223}
224
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000225uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsAddress(
David Blaikiecd7c4982013-09-23 22:44:40 +0000226 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000227 DWARFFormValue FormValue;
David Blaikiecd7c4982013-09-23 22:44:40 +0000228 if (getAttributeValue(U, Attr, FormValue))
229 return FormValue.getAsAddress(U);
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000230 return FailValue;
231}
232
233uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsUnsigned(
David Blaikiecd7c4982013-09-23 22:44:40 +0000234 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000235 DWARFFormValue FormValue;
David Blaikiecd7c4982013-09-23 22:44:40 +0000236 if (getAttributeValue(U, Attr, FormValue))
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000237 return FormValue.getUnsigned();
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000238 return FailValue;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000239}
240
David Blaikiecd7c4982013-09-23 22:44:40 +0000241int64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsSigned(
242 const DWARFUnit *u, const uint16_t attr, int64_t fail_value) const {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000243 DWARFFormValue form_value;
David Blaikiecd7c4982013-09-23 22:44:40 +0000244 if (getAttributeValue(u, attr, form_value))
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000245 return form_value.getSigned();
246 return fail_value;
247}
248
David Blaikiecd7c4982013-09-23 22:44:40 +0000249uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsReference(
250 const DWARFUnit *u, const uint16_t attr, uint64_t fail_value) const {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000251 DWARFFormValue form_value;
David Blaikiecd7c4982013-09-23 22:44:40 +0000252 if (getAttributeValue(u, attr, form_value))
253 return form_value.getReference(u);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000254 return fail_value;
255}
Benjamin Kramer10df8062011-09-14 20:52:27 +0000256
David Blaikiecd7c4982013-09-23 22:44:40 +0000257bool DWARFDebugInfoEntryMinimal::getLowAndHighPC(const DWARFUnit *U,
Eric Christopher203e6f62012-10-30 21:36:43 +0000258 uint64_t &LowPC,
259 uint64_t &HighPC) const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000260 HighPC = -1ULL;
David Blaikiecd7c4982013-09-23 22:44:40 +0000261 LowPC = getAttributeValueAsAddress(U, DW_AT_low_pc, -1ULL);
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000262 if (LowPC != -1ULL)
David Blaikiecd7c4982013-09-23 22:44:40 +0000263 HighPC = getAttributeValueAsAddress(U, DW_AT_high_pc, -1ULL);
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000264 return (HighPC != -1ULL);
265}
266
David Blaikiecd7c4982013-09-23 22:44:40 +0000267void DWARFDebugInfoEntryMinimal::buildAddressRangeTable(
268 const DWARFUnit *U, DWARFDebugAranges *DebugAranges,
269 uint32_t UOffsetInAranges) const {
Benjamin Kramer10df8062011-09-14 20:52:27 +0000270 if (AbbrevDecl) {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000271 if (isSubprogramDIE()) {
272 uint64_t LowPC, HighPC;
David Blaikiecd7c4982013-09-23 22:44:40 +0000273 if (getLowAndHighPC(U, LowPC, HighPC))
274 DebugAranges->appendRange(UOffsetInAranges, LowPC, HighPC);
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000275 // FIXME: try to append ranges from .debug_ranges section.
Benjamin Kramer10df8062011-09-14 20:52:27 +0000276 }
277
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000278 const DWARFDebugInfoEntryMinimal *Child = getFirstChild();
279 while (Child) {
David Blaikiecd7c4982013-09-23 22:44:40 +0000280 Child->buildAddressRangeTable(U, DebugAranges, UOffsetInAranges);
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000281 Child = Child->getSibling();
Benjamin Kramer10df8062011-09-14 20:52:27 +0000282 }
283 }
284}
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000285
David Blaikiecd7c4982013-09-23 22:44:40 +0000286bool DWARFDebugInfoEntryMinimal::addressRangeContainsAddress(
287 const DWARFUnit *U, const uint64_t Address) const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000288 if (isNULL())
289 return false;
290 uint64_t LowPC, HighPC;
David Blaikiecd7c4982013-09-23 22:44:40 +0000291 if (getLowAndHighPC(U, LowPC, HighPC))
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000292 return (LowPC <= Address && Address <= HighPC);
293 // Try to get address ranges from .debug_ranges section.
David Blaikiecd7c4982013-09-23 22:44:40 +0000294 uint32_t RangesOffset = getAttributeValueAsReference(U, DW_AT_ranges, -1U);
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000295 if (RangesOffset != -1U) {
296 DWARFDebugRangeList RangeList;
David Blaikiecd7c4982013-09-23 22:44:40 +0000297 if (U->extractRangeList(RangesOffset, RangeList))
298 return RangeList.containsAddress(U->getBaseAddress(), Address);
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000299 }
300 return false;
301}
302
David Blaikiecd7c4982013-09-23 22:44:40 +0000303const char *
304DWARFDebugInfoEntryMinimal::getSubroutineName(const DWARFUnit *U) const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000305 if (!isSubroutineDIE())
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000306 return 0;
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000307 // Try to get mangled name if possible.
308 if (const char *name =
David Blaikiecd7c4982013-09-23 22:44:40 +0000309 getAttributeValueAsString(U, DW_AT_MIPS_linkage_name, 0))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000310 return name;
David Blaikiecd7c4982013-09-23 22:44:40 +0000311 if (const char *name = getAttributeValueAsString(U, DW_AT_linkage_name, 0))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000312 return name;
David Blaikiecd7c4982013-09-23 22:44:40 +0000313 if (const char *name = getAttributeValueAsString(U, DW_AT_name, 0))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000314 return name;
315 // Try to get name from specification DIE.
316 uint32_t spec_ref =
David Blaikiecd7c4982013-09-23 22:44:40 +0000317 getAttributeValueAsReference(U, DW_AT_specification, -1U);
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000318 if (spec_ref != -1U) {
319 DWARFDebugInfoEntryMinimal spec_die;
David Blaikiecd7c4982013-09-23 22:44:40 +0000320 if (spec_die.extract(U, &spec_ref)) {
321 if (const char *name = spec_die.getSubroutineName(U))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000322 return name;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000323 }
324 }
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000325 // Try to get name from abstract origin DIE.
326 uint32_t abs_origin_ref =
David Blaikiecd7c4982013-09-23 22:44:40 +0000327 getAttributeValueAsReference(U, DW_AT_abstract_origin, -1U);
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000328 if (abs_origin_ref != -1U) {
329 DWARFDebugInfoEntryMinimal abs_origin_die;
David Blaikiecd7c4982013-09-23 22:44:40 +0000330 if (abs_origin_die.extract(U, &abs_origin_ref)) {
331 if (const char *name = abs_origin_die.getSubroutineName(U))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000332 return name;
333 }
334 }
335 return 0;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000336}
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000337
David Blaikiecd7c4982013-09-23 22:44:40 +0000338void DWARFDebugInfoEntryMinimal::getCallerFrame(const DWARFUnit *U,
Eric Christopher203e6f62012-10-30 21:36:43 +0000339 uint32_t &CallFile,
340 uint32_t &CallLine,
341 uint32_t &CallColumn) const {
David Blaikiecd7c4982013-09-23 22:44:40 +0000342 CallFile = getAttributeValueAsUnsigned(U, DW_AT_call_file, 0);
343 CallLine = getAttributeValueAsUnsigned(U, DW_AT_call_line, 0);
344 CallColumn = getAttributeValueAsUnsigned(U, DW_AT_call_column, 0);
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000345}
346
Alexey Samsonove6642902013-08-06 10:49:15 +0000347DWARFDebugInfoEntryInlinedChain
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000348DWARFDebugInfoEntryMinimal::getInlinedChainForAddress(
David Blaikiecd7c4982013-09-23 22:44:40 +0000349 const DWARFUnit *U, const uint64_t Address) const {
Alexey Samsonove6642902013-08-06 10:49:15 +0000350 DWARFDebugInfoEntryInlinedChain InlinedChain;
David Blaikiecd7c4982013-09-23 22:44:40 +0000351 InlinedChain.U = U;
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000352 if (isNULL())
353 return InlinedChain;
354 for (const DWARFDebugInfoEntryMinimal *DIE = this; DIE; ) {
355 // Append current DIE to inlined chain only if it has correct tag
356 // (e.g. it is not a lexical block).
357 if (DIE->isSubroutineDIE()) {
Alexey Samsonove6642902013-08-06 10:49:15 +0000358 InlinedChain.DIEs.push_back(*DIE);
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000359 }
360 // Try to get child which also contains provided address.
361 const DWARFDebugInfoEntryMinimal *Child = DIE->getFirstChild();
362 while (Child) {
David Blaikiecd7c4982013-09-23 22:44:40 +0000363 if (Child->addressRangeContainsAddress(U, Address)) {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000364 // Assume there is only one such child.
365 break;
366 }
367 Child = Child->getSibling();
368 }
369 DIE = Child;
370 }
371 // Reverse the obtained chain to make the root of inlined chain last.
Alexey Samsonove6642902013-08-06 10:49:15 +0000372 std::reverse(InlinedChain.DIEs.begin(), InlinedChain.DIEs.end());
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000373 return InlinedChain;
374}