blob: 583e70055c0104e7b9970f6f42f03d8a43ba6fc3 [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"
Stephen Hines37ed9c12014-12-01 14:51:49 -080015#include "llvm/Support/DataTypes.h"
Eric Christopherdd8e9f32013-01-07 19:32:41 +000016#include "llvm/Support/Debug.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000017#include "llvm/Support/Dwarf.h"
18#include "llvm/Support/Format.h"
19#include "llvm/Support/raw_ostream.h"
20using namespace llvm;
21using namespace dwarf;
22
Stephen Hines37ed9c12014-12-01 14:51:49 -080023// Small helper to extract a DIE pointed by a reference
24// attribute. It looks up the Unit containing the DIE and calls
25// DIE.extractFast with the right unit. Returns new unit on success,
26// nullptr otherwise.
27static const DWARFUnit *findUnitAndExtractFast(DWARFDebugInfoEntryMinimal &DIE,
28 const DWARFUnit *Unit,
29 uint32_t *Offset) {
30 Unit = Unit->getUnitSection().getUnitForOffset(*Offset);
31 return (Unit && DIE.extractFast(Unit, Offset)) ? Unit : nullptr;
32}
33
34void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS, DWARFUnit *u,
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000035 unsigned recurseDepth,
36 unsigned indent) const {
David Blaikiecd7c4982013-09-23 22:44:40 +000037 DataExtractor debug_info_data = u->getDebugInfoExtractor();
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000038 uint32_t offset = Offset;
39
40 if (debug_info_data.isValidOffset(offset)) {
Benjamin Kramer80cc2592011-11-05 15:35:00 +000041 uint32_t abbrCode = debug_info_data.getULEB128(&offset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000042
Benjamin Kramer09422552011-09-14 17:54:56 +000043 OS << format("\n0x%8.8x: ", Offset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000044 if (abbrCode) {
45 if (AbbrevDecl) {
Benjamin Kramer75c63082011-09-15 05:43:00 +000046 const char *tagString = TagString(getTag());
47 if (tagString)
48 OS.indent(indent) << tagString;
49 else
50 OS.indent(indent) << format("DW_TAG_Unknown_%x", getTag());
51 OS << format(" [%u] %c\n", abbrCode,
52 AbbrevDecl->hasChildren() ? '*' : ' ');
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000053
Eric Christophere5ef3052013-01-07 03:27:58 +000054 // Dump all data in the DIE for the attributes.
Stephen Hines36b56882014-04-23 16:57:46 -070055 for (const auto &AttrSpec : AbbrevDecl->attributes()) {
56 dumpAttribute(OS, u, &offset, AttrSpec.Attr, AttrSpec.Form, indent);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000057 }
58
59 const DWARFDebugInfoEntryMinimal *child = getFirstChild();
60 if (recurseDepth > 0 && child) {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000061 while (child) {
David Blaikiecd7c4982013-09-23 22:44:40 +000062 child->dump(OS, u, recurseDepth-1, indent+2);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000063 child = child->getSibling();
64 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000065 }
66 } else {
67 OS << "Abbreviation code not found in 'debug_abbrev' class for code: "
68 << abbrCode << '\n';
69 }
70 } else {
Benjamin Kramer09422552011-09-14 17:54:56 +000071 OS.indent(indent) << "NULL\n";
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000072 }
73 }
74}
75
Stephen Hines37ed9c12014-12-01 14:51:49 -080076static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) {
77 OS << " (";
78 do {
79 uint64_t Bit = 1ULL << countTrailingZeros(Val);
80 if (const char *PropName = ApplePropertyString(Bit))
81 OS << PropName;
82 else
83 OS << format("DW_APPLE_PROPERTY_0x%" PRIx64, Bit);
84 if (!(Val ^= Bit))
85 break;
86 OS << ", ";
87 } while (true);
88 OS << ")";
89}
90
91static void dumpRanges(raw_ostream &OS, const DWARFAddressRangesVector& Ranges,
92 unsigned AddressSize, unsigned Indent) {
93 if (Ranges.empty())
94 return;
95
96 for (const auto &Range: Ranges) {
97 OS << '\n';
98 OS.indent(Indent);
99 OS << format("[0x%0*" PRIx64 " - 0x%0*" PRIx64 ")",
100 AddressSize*2, Range.first,
101 AddressSize*2, Range.second);
102 }
103}
104
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000105void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS,
Stephen Hines37ed9c12014-12-01 14:51:49 -0800106 DWARFUnit *u,
David Blaikiecd7c4982013-09-23 22:44:40 +0000107 uint32_t *offset_ptr,
108 uint16_t attr, uint16_t form,
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000109 unsigned indent) const {
Stephen Hines37ed9c12014-12-01 14:51:49 -0800110 const char BaseIndent[] = " ";
111 OS << BaseIndent;
Benjamin Kramer75c63082011-09-15 05:43:00 +0000112 OS.indent(indent+2);
113 const char *attrString = AttributeString(attr);
114 if (attrString)
115 OS << attrString;
116 else
117 OS << format("DW_AT_Unknown_%x", attr);
118 const char *formString = FormEncodingString(form);
119 if (formString)
120 OS << " [" << formString << ']';
121 else
122 OS << format(" [DW_FORM_Unknown_%x]", form);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000123
124 DWARFFormValue formValue(form);
125
David Blaikiecd7c4982013-09-23 22:44:40 +0000126 if (!formValue.extractValue(u->getDebugInfoExtractor(), offset_ptr, u))
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000127 return;
128
129 OS << "\t(";
Stephen Hines37ed9c12014-12-01 14:51:49 -0800130
131 const char *Name = nullptr;
132 std::string File;
133 if (attr == DW_AT_decl_file || attr == DW_AT_call_file) {
134 if (const auto *LT = u->getContext().getLineTableForUnit(u))
135 if (LT->getFileNameByIndex(
136 formValue.getAsUnsignedConstant().getValue(),
137 u->getCompilationDir(),
138 DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, File)) {
139 File = '"' + File + '"';
140 Name = File.c_str();
141 }
142 } else if (Optional<uint64_t> Val = formValue.getAsUnsignedConstant())
143 Name = AttributeValueString(attr, *Val);
144
145 if (Name) {
146 OS << Name;
147 } else if (attr == DW_AT_decl_line || attr == DW_AT_call_line) {
148 OS << *formValue.getAsUnsignedConstant();
149 } else {
150 formValue.dump(OS, u);
151 }
152
153 // We have dumped the attribute raw value. For some attributes
154 // having both the raw value and the pretty-printed value is
155 // interesting. These attributes are handled below.
156 if ((attr == DW_AT_specification || attr == DW_AT_abstract_origin) &&
157 // The signature references aren't handled.
158 formValue.getForm() != DW_FORM_ref_sig8) {
159 uint32_t Ref = formValue.getAsReference(u).getValue();
160 DWARFDebugInfoEntryMinimal DIE;
161 if (const DWARFUnit *RefU = findUnitAndExtractFast(DIE, u, &Ref))
162 if (const char *Ref = DIE.getName(RefU, DINameKind::LinkageName))
163 OS << " \"" << Ref << '\"';
164 } else if (attr == DW_AT_APPLE_property_attribute) {
165 if (Optional<uint64_t> OptVal = formValue.getAsUnsignedConstant())
166 dumpApplePropertyAttribute(OS, *OptVal);
167 } else if (attr == DW_AT_ranges) {
168 dumpRanges(OS, getAddressRanges(u), u->getAddressByteSize(),
169 sizeof(BaseIndent)+indent+4);
170 }
171
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000172 OS << ")\n";
173}
174
David Blaikiecd7c4982013-09-23 22:44:40 +0000175bool DWARFDebugInfoEntryMinimal::extractFast(const DWARFUnit *U,
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000176 uint32_t *OffsetPtr) {
177 Offset = *OffsetPtr;
David Blaikiecd7c4982013-09-23 22:44:40 +0000178 DataExtractor DebugInfoData = U->getDebugInfoExtractor();
Alexey Samsonov39f62fa2013-10-28 23:58:58 +0000179 uint32_t UEndOffset = U->getNextUnitOffset();
180 if (Offset >= UEndOffset || !DebugInfoData.isValidOffset(Offset))
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000181 return false;
182 uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
183 if (0 == AbbrCode) {
184 // NULL debug tag entry.
Stephen Hinesdce4a402014-05-29 02:49:00 -0700185 AbbrevDecl = nullptr;
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000186 return true;
187 }
David Blaikiecd7c4982013-09-23 22:44:40 +0000188 AbbrevDecl = U->getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
Stephen Hinesdce4a402014-05-29 02:49:00 -0700189 if (nullptr == AbbrevDecl) {
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000190 // Restore the original offset.
191 *OffsetPtr = Offset;
192 return false;
193 }
Alexey Samsonov39f62fa2013-10-28 23:58:58 +0000194 ArrayRef<uint8_t> FixedFormSizes = DWARFFormValue::getFixedFormSizes(
195 U->getAddressByteSize(), U->getVersion());
196 assert(FixedFormSizes.size() > 0);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000197
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000198 // Skip all data in the .debug_info for the attributes
Stephen Hines36b56882014-04-23 16:57:46 -0700199 for (const auto &AttrSpec : AbbrevDecl->attributes()) {
200 uint16_t Form = AttrSpec.Form;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000201
Alexey Samsonov39f62fa2013-10-28 23:58:58 +0000202 uint8_t FixedFormSize =
203 (Form < FixedFormSizes.size()) ? FixedFormSizes[Form] : 0;
204 if (FixedFormSize)
205 *OffsetPtr += FixedFormSize;
206 else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, U)) {
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000207 // Restore the original offset.
208 *OffsetPtr = Offset;
209 return false;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000210 }
211 }
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000212 return true;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000213}
214
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000215bool DWARFDebugInfoEntryMinimal::isSubprogramDIE() const {
216 return getTag() == DW_TAG_subprogram;
217}
218
219bool DWARFDebugInfoEntryMinimal::isSubroutineDIE() const {
220 uint32_t Tag = getTag();
221 return Tag == DW_TAG_subprogram ||
222 Tag == DW_TAG_inlined_subroutine;
223}
224
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000225bool DWARFDebugInfoEntryMinimal::getAttributeValue(
226 const DWARFUnit *U, const uint16_t Attr, DWARFFormValue &FormValue) const {
227 if (!AbbrevDecl)
228 return false;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000229
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000230 uint32_t AttrIdx = AbbrevDecl->findAttributeIndex(Attr);
231 if (AttrIdx == -1U)
232 return false;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000233
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000234 DataExtractor DebugInfoData = U->getDebugInfoExtractor();
235 uint32_t DebugInfoOffset = getOffset();
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000236
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000237 // Skip the abbreviation code so we are at the data for the attributes
238 DebugInfoData.getULEB128(&DebugInfoOffset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000239
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000240 // Skip preceding attribute values.
241 for (uint32_t i = 0; i < AttrIdx; ++i) {
242 DWARFFormValue::skipValue(AbbrevDecl->getFormByIndex(i),
243 DebugInfoData, &DebugInfoOffset, U);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000244 }
245
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000246 FormValue = DWARFFormValue(AbbrevDecl->getFormByIndex(AttrIdx));
247 return FormValue.extractValue(DebugInfoData, &DebugInfoOffset, U);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000248}
249
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000250const char *DWARFDebugInfoEntryMinimal::getAttributeValueAsString(
David Blaikiecd7c4982013-09-23 22:44:40 +0000251 const DWARFUnit *U, const uint16_t Attr, const char *FailValue) const {
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000252 DWARFFormValue FormValue;
Alexey Samsonovc5253232013-10-28 23:01:48 +0000253 if (!getAttributeValue(U, Attr, FormValue))
254 return FailValue;
255 Optional<const char *> Result = FormValue.getAsCString(U);
256 return Result.hasValue() ? Result.getValue() : FailValue;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000257}
258
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000259uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsAddress(
David Blaikiecd7c4982013-09-23 22:44:40 +0000260 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000261 DWARFFormValue FormValue;
Alexey Samsonovc5253232013-10-28 23:01:48 +0000262 if (!getAttributeValue(U, Attr, FormValue))
263 return FailValue;
264 Optional<uint64_t> Result = FormValue.getAsAddress(U);
265 return Result.hasValue() ? Result.getValue() : FailValue;
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000266}
267
Alexey Samsonovc5253232013-10-28 23:01:48 +0000268uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsUnsignedConstant(
David Blaikiecd7c4982013-09-23 22:44:40 +0000269 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000270 DWARFFormValue FormValue;
Alexey Samsonovc5253232013-10-28 23:01:48 +0000271 if (!getAttributeValue(U, Attr, FormValue))
272 return FailValue;
273 Optional<uint64_t> Result = FormValue.getAsUnsignedConstant();
274 return Result.hasValue() ? Result.getValue() : FailValue;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000275}
276
David Blaikiecd7c4982013-09-23 22:44:40 +0000277uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsReference(
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000278 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
279 DWARFFormValue FormValue;
Alexey Samsonovc5253232013-10-28 23:01:48 +0000280 if (!getAttributeValue(U, Attr, FormValue))
281 return FailValue;
282 Optional<uint64_t> Result = FormValue.getAsReference(U);
283 return Result.hasValue() ? Result.getValue() : FailValue;
284}
285
286uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsSectionOffset(
287 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
288 DWARFFormValue FormValue;
289 if (!getAttributeValue(U, Attr, FormValue))
290 return FailValue;
291 Optional<uint64_t> Result = FormValue.getAsSectionOffset();
292 return Result.hasValue() ? Result.getValue() : FailValue;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000293}
Benjamin Kramer10df8062011-09-14 20:52:27 +0000294
Stephen Hinesc6a4f5e2014-07-21 00:45:20 -0700295uint64_t
296DWARFDebugInfoEntryMinimal::getRangesBaseAttribute(const DWARFUnit *U,
297 uint64_t FailValue) const {
298 uint64_t Result =
299 getAttributeValueAsSectionOffset(U, DW_AT_ranges_base, -1ULL);
300 if (Result != -1ULL)
301 return Result;
302 return getAttributeValueAsSectionOffset(U, DW_AT_GNU_ranges_base, FailValue);
303}
304
David Blaikiecd7c4982013-09-23 22:44:40 +0000305bool DWARFDebugInfoEntryMinimal::getLowAndHighPC(const DWARFUnit *U,
Eric Christopher203e6f62012-10-30 21:36:43 +0000306 uint64_t &LowPC,
307 uint64_t &HighPC) const {
David Blaikiecd7c4982013-09-23 22:44:40 +0000308 LowPC = getAttributeValueAsAddress(U, DW_AT_low_pc, -1ULL);
Alexey Samsonovd2d54e22013-10-28 23:15:15 +0000309 if (LowPC == -1ULL)
310 return false;
311 HighPC = getAttributeValueAsAddress(U, DW_AT_high_pc, -1ULL);
312 if (HighPC == -1ULL) {
313 // Since DWARF4, DW_AT_high_pc may also be of class constant, in which case
314 // it represents function size.
315 HighPC = getAttributeValueAsUnsignedConstant(U, DW_AT_high_pc, -1ULL);
316 if (HighPC != -1ULL)
317 HighPC += LowPC;
318 }
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000319 return (HighPC != -1ULL);
320}
321
Stephen Hinesdce4a402014-05-29 02:49:00 -0700322DWARFAddressRangesVector
323DWARFDebugInfoEntryMinimal::getAddressRanges(const DWARFUnit *U) const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000324 if (isNULL())
Stephen Hinesdce4a402014-05-29 02:49:00 -0700325 return DWARFAddressRangesVector();
326 // Single range specified by low/high PC.
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000327 uint64_t LowPC, HighPC;
Stephen Hinesdce4a402014-05-29 02:49:00 -0700328 if (getLowAndHighPC(U, LowPC, HighPC)) {
329 return DWARFAddressRangesVector(1, std::make_pair(LowPC, HighPC));
330 }
331 // Multiple ranges from .debug_ranges section.
Alexey Samsonovc5253232013-10-28 23:01:48 +0000332 uint32_t RangesOffset =
333 getAttributeValueAsSectionOffset(U, DW_AT_ranges, -1U);
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000334 if (RangesOffset != -1U) {
335 DWARFDebugRangeList RangeList;
David Blaikiecd7c4982013-09-23 22:44:40 +0000336 if (U->extractRangeList(RangesOffset, RangeList))
Stephen Hinesdce4a402014-05-29 02:49:00 -0700337 return RangeList.getAbsoluteRanges(U->getBaseAddress());
338 }
339 return DWARFAddressRangesVector();
340}
341
342void DWARFDebugInfoEntryMinimal::collectChildrenAddressRanges(
343 const DWARFUnit *U, DWARFAddressRangesVector& Ranges) const {
344 if (isNULL())
345 return;
346 if (isSubprogramDIE()) {
347 const auto &DIERanges = getAddressRanges(U);
348 Ranges.insert(Ranges.end(), DIERanges.begin(), DIERanges.end());
349 }
350
351 const DWARFDebugInfoEntryMinimal *Child = getFirstChild();
352 while (Child) {
353 Child->collectChildrenAddressRanges(U, Ranges);
354 Child = Child->getSibling();
355 }
356}
357
358bool DWARFDebugInfoEntryMinimal::addressRangeContainsAddress(
359 const DWARFUnit *U, const uint64_t Address) const {
360 for (const auto& R : getAddressRanges(U)) {
361 if (R.first <= Address && Address < R.second)
362 return true;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000363 }
364 return false;
365}
366
David Blaikiecd7c4982013-09-23 22:44:40 +0000367const char *
Stephen Hinesdce4a402014-05-29 02:49:00 -0700368DWARFDebugInfoEntryMinimal::getSubroutineName(const DWARFUnit *U,
Stephen Hines37ed9c12014-12-01 14:51:49 -0800369 DINameKind Kind) const {
370 if (!isSubroutineDIE())
371 return nullptr;
372 return getName(U, Kind);
373}
374
375const char *
376DWARFDebugInfoEntryMinimal::getName(const DWARFUnit *U,
377 DINameKind Kind) const {
378 if (Kind == DINameKind::None)
Stephen Hinesdce4a402014-05-29 02:49:00 -0700379 return nullptr;
380 // Try to get mangled name only if it was asked for.
Stephen Hines37ed9c12014-12-01 14:51:49 -0800381 if (Kind == DINameKind::LinkageName) {
Stephen Hinesdce4a402014-05-29 02:49:00 -0700382 if (const char *name =
383 getAttributeValueAsString(U, DW_AT_MIPS_linkage_name, nullptr))
384 return name;
385 if (const char *name =
386 getAttributeValueAsString(U, DW_AT_linkage_name, nullptr))
387 return name;
388 }
389 if (const char *name = getAttributeValueAsString(U, DW_AT_name, nullptr))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000390 return name;
391 // Try to get name from specification DIE.
392 uint32_t spec_ref =
David Blaikiecd7c4982013-09-23 22:44:40 +0000393 getAttributeValueAsReference(U, DW_AT_specification, -1U);
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000394 if (spec_ref != -1U) {
395 DWARFDebugInfoEntryMinimal spec_die;
Stephen Hines37ed9c12014-12-01 14:51:49 -0800396 if (const DWARFUnit *RefU = findUnitAndExtractFast(spec_die, U, &spec_ref)) {
397 if (const char *name = spec_die.getName(RefU, Kind))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000398 return name;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000399 }
400 }
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000401 // Try to get name from abstract origin DIE.
402 uint32_t abs_origin_ref =
David Blaikiecd7c4982013-09-23 22:44:40 +0000403 getAttributeValueAsReference(U, DW_AT_abstract_origin, -1U);
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000404 if (abs_origin_ref != -1U) {
405 DWARFDebugInfoEntryMinimal abs_origin_die;
Stephen Hines37ed9c12014-12-01 14:51:49 -0800406 if (const DWARFUnit *RefU = findUnitAndExtractFast(abs_origin_die, U,
407 &abs_origin_ref)) {
408 if (const char *name = abs_origin_die.getName(RefU, Kind))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000409 return name;
410 }
411 }
Stephen Hinesdce4a402014-05-29 02:49:00 -0700412 return nullptr;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000413}
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000414
David Blaikiecd7c4982013-09-23 22:44:40 +0000415void DWARFDebugInfoEntryMinimal::getCallerFrame(const DWARFUnit *U,
Eric Christopher203e6f62012-10-30 21:36:43 +0000416 uint32_t &CallFile,
417 uint32_t &CallLine,
418 uint32_t &CallColumn) const {
Alexey Samsonovc5253232013-10-28 23:01:48 +0000419 CallFile = getAttributeValueAsUnsignedConstant(U, DW_AT_call_file, 0);
420 CallLine = getAttributeValueAsUnsignedConstant(U, DW_AT_call_line, 0);
421 CallColumn = getAttributeValueAsUnsignedConstant(U, DW_AT_call_column, 0);
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000422}
423
Alexey Samsonove6642902013-08-06 10:49:15 +0000424DWARFDebugInfoEntryInlinedChain
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000425DWARFDebugInfoEntryMinimal::getInlinedChainForAddress(
David Blaikiecd7c4982013-09-23 22:44:40 +0000426 const DWARFUnit *U, const uint64_t Address) const {
Alexey Samsonove6642902013-08-06 10:49:15 +0000427 DWARFDebugInfoEntryInlinedChain InlinedChain;
David Blaikiecd7c4982013-09-23 22:44:40 +0000428 InlinedChain.U = U;
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000429 if (isNULL())
430 return InlinedChain;
431 for (const DWARFDebugInfoEntryMinimal *DIE = this; DIE; ) {
432 // Append current DIE to inlined chain only if it has correct tag
433 // (e.g. it is not a lexical block).
434 if (DIE->isSubroutineDIE()) {
Alexey Samsonove6642902013-08-06 10:49:15 +0000435 InlinedChain.DIEs.push_back(*DIE);
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000436 }
437 // Try to get child which also contains provided address.
438 const DWARFDebugInfoEntryMinimal *Child = DIE->getFirstChild();
439 while (Child) {
David Blaikiecd7c4982013-09-23 22:44:40 +0000440 if (Child->addressRangeContainsAddress(U, Address)) {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000441 // Assume there is only one such child.
442 break;
443 }
444 Child = Child->getSibling();
445 }
446 DIE = Child;
447 }
448 // Reverse the obtained chain to make the root of inlined chain last.
Alexey Samsonove6642902013-08-06 10:49:15 +0000449 std::reverse(InlinedChain.DIEs.begin(), InlinedChain.DIEs.end());
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000450 return InlinedChain;
451}