blob: 15c04cb949bb662a69c37aa5bb0a5d60f2e1bae1 [file] [log] [blame]
Eric Christopherc2ce0042012-08-23 00:52:51 +00001//===-- DWARFDebugInfoEntry.cpp -------------------------------------------===//
Benjamin Krameraa2f78f2011-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 Samsonov045c6c52013-04-17 08:29:02 +000014#include "llvm/DebugInfo/DWARFFormValue.h"
Frederic Rissb3c99122014-10-10 15:51:10 +000015#include "llvm/Support/DataTypes.h"
Eric Christopher2cbd5762013-01-07 19:32:41 +000016#include "llvm/Support/Debug.h"
Benjamin Krameraa2f78f2011-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
Frederic Riss58ed53c2014-09-22 12:35:53 +000023// 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
Frederic Riss955724e2014-09-22 12:36:04 +000034void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS, DWARFUnit *u,
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000035 unsigned recurseDepth,
36 unsigned indent) const {
David Blaikie07e22442013-09-23 22:44:40 +000037 DataExtractor debug_info_data = u->getDebugInfoExtractor();
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000038 uint32_t offset = Offset;
39
40 if (debug_info_data.isValidOffset(offset)) {
Benjamin Kramerf7e0a312011-11-05 15:35:00 +000041 uint32_t abbrCode = debug_info_data.getULEB128(&offset);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000042
Benjamin Kramerf915acc2011-09-14 17:54:56 +000043 OS << format("\n0x%8.8x: ", Offset);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000044 if (abbrCode) {
45 if (AbbrevDecl) {
Benjamin Kramer9bca64f2011-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 Krameraa2f78f2011-09-13 19:42:23 +000053
Eric Christopher7f5870c2013-01-07 03:27:58 +000054 // Dump all data in the DIE for the attributes.
Alexey Samsonov1eabf982014-03-13 07:52:54 +000055 for (const auto &AttrSpec : AbbrevDecl->attributes()) {
56 dumpAttribute(OS, u, &offset, AttrSpec.Attr, AttrSpec.Form, indent);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000057 }
58
59 const DWARFDebugInfoEntryMinimal *child = getFirstChild();
60 if (recurseDepth > 0 && child) {
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000061 while (child) {
David Blaikie07e22442013-09-23 22:44:40 +000062 child->dump(OS, u, recurseDepth-1, indent+2);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000063 child = child->getSibling();
64 }
Benjamin Krameraa2f78f2011-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 Kramerf915acc2011-09-14 17:54:56 +000071 OS.indent(indent) << "NULL\n";
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000072 }
73 }
74}
75
Frederic Rissb3c99122014-10-10 15:51:10 +000076static 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
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000091void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS,
Frederic Riss955724e2014-09-22 12:36:04 +000092 DWARFUnit *u,
David Blaikie07e22442013-09-23 22:44:40 +000093 uint32_t *offset_ptr,
94 uint16_t attr, uint16_t form,
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000095 unsigned indent) const {
David Blaikie175b0b92013-08-19 03:36:23 +000096 OS << " ";
Benjamin Kramer9bca64f2011-09-15 05:43:00 +000097 OS.indent(indent+2);
98 const char *attrString = AttributeString(attr);
99 if (attrString)
100 OS << attrString;
101 else
102 OS << format("DW_AT_Unknown_%x", attr);
103 const char *formString = FormEncodingString(form);
104 if (formString)
105 OS << " [" << formString << ']';
106 else
107 OS << format(" [DW_FORM_Unknown_%x]", form);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000108
109 DWARFFormValue formValue(form);
110
David Blaikie07e22442013-09-23 22:44:40 +0000111 if (!formValue.extractValue(u->getDebugInfoExtractor(), offset_ptr, u))
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000112 return;
113
114 OS << "\t(";
Frederic Riss878065b2014-09-04 19:39:20 +0000115
116 const char *Name = nullptr;
Frederic Riss955724e2014-09-22 12:36:04 +0000117 std::string File;
118 if (attr == DW_AT_decl_file || attr == DW_AT_call_file) {
119 if (const auto *LT = u->getContext().getLineTableForUnit(u))
120 if (LT->getFileNameByIndex(
121 formValue.getAsUnsignedConstant().getValue(),
122 u->getCompilationDir(),
123 DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, File)) {
124 File = '"' + File + '"';
125 Name = File.c_str();
126 }
127 } else if (Optional<uint64_t> Val = formValue.getAsUnsignedConstant())
Frederic Riss878065b2014-09-04 19:39:20 +0000128 Name = AttributeValueString(attr, *Val);
129
130 if (Name) {
131 OS << Name;
Frederic Riss0982e692014-09-05 07:21:50 +0000132 } else if (attr == DW_AT_decl_line || attr == DW_AT_call_line) {
133 OS << *formValue.getAsUnsignedConstant();
Frederic Riss878065b2014-09-04 19:39:20 +0000134 } else {
135 formValue.dump(OS, u);
136 }
137
Frederic Rissd1cfc3c2014-10-06 03:36:31 +0000138 // We have dumped the attribute raw value. For some attributes
139 // having both the raw value and the pretty-printed value is
140 // interesting. These attributes are handled below.
141 if ((attr == DW_AT_specification || attr == DW_AT_abstract_origin) &&
142 // The signature references aren't handled.
143 formValue.getForm() != DW_FORM_ref_sig8) {
144 uint32_t Ref = formValue.getAsReference(u).getValue();
145 DWARFDebugInfoEntryMinimal DIE;
146 if (const DWARFUnit *RefU = findUnitAndExtractFast(DIE, u, &Ref))
Frederic Rissd4de1802014-10-10 15:51:02 +0000147 if (const char *Ref = DIE.getName(RefU, DINameKind::LinkageName))
Frederic Rissd1cfc3c2014-10-06 03:36:31 +0000148 OS << " \"" << Ref << '\"';
Frederic Rissb3c99122014-10-10 15:51:10 +0000149 } else if (attr == DW_AT_APPLE_property_attribute) {
150 if (Optional<uint64_t> OptVal = formValue.getAsUnsignedConstant())
151 dumpApplePropertyAttribute(OS, *OptVal);
Frederic Rissd1cfc3c2014-10-06 03:36:31 +0000152 }
153
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000154 OS << ")\n";
155}
156
David Blaikie07e22442013-09-23 22:44:40 +0000157bool DWARFDebugInfoEntryMinimal::extractFast(const DWARFUnit *U,
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +0000158 uint32_t *OffsetPtr) {
159 Offset = *OffsetPtr;
David Blaikie07e22442013-09-23 22:44:40 +0000160 DataExtractor DebugInfoData = U->getDebugInfoExtractor();
Alexey Samsonov330b8932013-10-28 23:58:58 +0000161 uint32_t UEndOffset = U->getNextUnitOffset();
162 if (Offset >= UEndOffset || !DebugInfoData.isValidOffset(Offset))
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +0000163 return false;
164 uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
165 if (0 == AbbrCode) {
166 // NULL debug tag entry.
Craig Topper2617dcc2014-04-15 06:32:26 +0000167 AbbrevDecl = nullptr;
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +0000168 return true;
169 }
David Blaikie07e22442013-09-23 22:44:40 +0000170 AbbrevDecl = U->getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
Craig Topper2617dcc2014-04-15 06:32:26 +0000171 if (nullptr == AbbrevDecl) {
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +0000172 // Restore the original offset.
173 *OffsetPtr = Offset;
174 return false;
175 }
Alexey Samsonov330b8932013-10-28 23:58:58 +0000176 ArrayRef<uint8_t> FixedFormSizes = DWARFFormValue::getFixedFormSizes(
177 U->getAddressByteSize(), U->getVersion());
178 assert(FixedFormSizes.size() > 0);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000179
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +0000180 // Skip all data in the .debug_info for the attributes
Alexey Samsonov1eabf982014-03-13 07:52:54 +0000181 for (const auto &AttrSpec : AbbrevDecl->attributes()) {
182 uint16_t Form = AttrSpec.Form;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000183
Alexey Samsonov330b8932013-10-28 23:58:58 +0000184 uint8_t FixedFormSize =
185 (Form < FixedFormSizes.size()) ? FixedFormSizes[Form] : 0;
186 if (FixedFormSize)
187 *OffsetPtr += FixedFormSize;
188 else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, U)) {
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +0000189 // Restore the original offset.
190 *OffsetPtr = Offset;
191 return false;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000192 }
193 }
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +0000194 return true;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000195}
196
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000197bool DWARFDebugInfoEntryMinimal::isSubprogramDIE() const {
198 return getTag() == DW_TAG_subprogram;
199}
200
201bool DWARFDebugInfoEntryMinimal::isSubroutineDIE() const {
202 uint32_t Tag = getTag();
203 return Tag == DW_TAG_subprogram ||
204 Tag == DW_TAG_inlined_subroutine;
205}
206
Alexey Samsonovcaabb0e2013-10-17 13:28:16 +0000207bool DWARFDebugInfoEntryMinimal::getAttributeValue(
208 const DWARFUnit *U, const uint16_t Attr, DWARFFormValue &FormValue) const {
209 if (!AbbrevDecl)
210 return false;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000211
Alexey Samsonovcaabb0e2013-10-17 13:28:16 +0000212 uint32_t AttrIdx = AbbrevDecl->findAttributeIndex(Attr);
213 if (AttrIdx == -1U)
214 return false;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000215
Alexey Samsonovcaabb0e2013-10-17 13:28:16 +0000216 DataExtractor DebugInfoData = U->getDebugInfoExtractor();
217 uint32_t DebugInfoOffset = getOffset();
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000218
Alexey Samsonovcaabb0e2013-10-17 13:28:16 +0000219 // Skip the abbreviation code so we are at the data for the attributes
220 DebugInfoData.getULEB128(&DebugInfoOffset);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000221
Alexey Samsonovcaabb0e2013-10-17 13:28:16 +0000222 // Skip preceding attribute values.
223 for (uint32_t i = 0; i < AttrIdx; ++i) {
224 DWARFFormValue::skipValue(AbbrevDecl->getFormByIndex(i),
225 DebugInfoData, &DebugInfoOffset, U);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000226 }
227
Alexey Samsonovcaabb0e2013-10-17 13:28:16 +0000228 FormValue = DWARFFormValue(AbbrevDecl->getFormByIndex(AttrIdx));
229 return FormValue.extractValue(DebugInfoData, &DebugInfoOffset, U);
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000230}
231
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000232const char *DWARFDebugInfoEntryMinimal::getAttributeValueAsString(
David Blaikie07e22442013-09-23 22:44:40 +0000233 const DWARFUnit *U, const uint16_t Attr, const char *FailValue) const {
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000234 DWARFFormValue FormValue;
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000235 if (!getAttributeValue(U, Attr, FormValue))
236 return FailValue;
237 Optional<const char *> Result = FormValue.getAsCString(U);
238 return Result.hasValue() ? Result.getValue() : FailValue;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000239}
240
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000241uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsAddress(
David Blaikie07e22442013-09-23 22:44:40 +0000242 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000243 DWARFFormValue FormValue;
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000244 if (!getAttributeValue(U, Attr, FormValue))
245 return FailValue;
246 Optional<uint64_t> Result = FormValue.getAsAddress(U);
247 return Result.hasValue() ? Result.getValue() : FailValue;
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000248}
249
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000250uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsUnsignedConstant(
David Blaikie07e22442013-09-23 22:44:40 +0000251 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
Alexey Samsonove3ba81b2013-08-27 09:20:22 +0000252 DWARFFormValue FormValue;
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000253 if (!getAttributeValue(U, Attr, FormValue))
254 return FailValue;
255 Optional<uint64_t> Result = FormValue.getAsUnsignedConstant();
256 return Result.hasValue() ? Result.getValue() : FailValue;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000257}
258
David Blaikie07e22442013-09-23 22:44:40 +0000259uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsReference(
Alexey Samsonovcaabb0e2013-10-17 13:28:16 +0000260 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
261 DWARFFormValue FormValue;
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000262 if (!getAttributeValue(U, Attr, FormValue))
263 return FailValue;
264 Optional<uint64_t> Result = FormValue.getAsReference(U);
265 return Result.hasValue() ? Result.getValue() : FailValue;
266}
267
268uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsSectionOffset(
269 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
270 DWARFFormValue FormValue;
271 if (!getAttributeValue(U, Attr, FormValue))
272 return FailValue;
273 Optional<uint64_t> Result = FormValue.getAsSectionOffset();
274 return Result.hasValue() ? Result.getValue() : FailValue;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +0000275}
Benjamin Kramer32664932011-09-14 20:52:27 +0000276
Alexey Samsonovaa909982014-06-13 22:31:03 +0000277uint64_t
278DWARFDebugInfoEntryMinimal::getRangesBaseAttribute(const DWARFUnit *U,
279 uint64_t FailValue) const {
280 uint64_t Result =
281 getAttributeValueAsSectionOffset(U, DW_AT_ranges_base, -1ULL);
282 if (Result != -1ULL)
283 return Result;
284 return getAttributeValueAsSectionOffset(U, DW_AT_GNU_ranges_base, FailValue);
285}
286
David Blaikie07e22442013-09-23 22:44:40 +0000287bool DWARFDebugInfoEntryMinimal::getLowAndHighPC(const DWARFUnit *U,
Eric Christopher206cf642012-10-30 21:36:43 +0000288 uint64_t &LowPC,
289 uint64_t &HighPC) const {
David Blaikie07e22442013-09-23 22:44:40 +0000290 LowPC = getAttributeValueAsAddress(U, DW_AT_low_pc, -1ULL);
Alexey Samsonov76142122013-10-28 23:15:15 +0000291 if (LowPC == -1ULL)
292 return false;
293 HighPC = getAttributeValueAsAddress(U, DW_AT_high_pc, -1ULL);
294 if (HighPC == -1ULL) {
295 // Since DWARF4, DW_AT_high_pc may also be of class constant, in which case
296 // it represents function size.
297 HighPC = getAttributeValueAsUnsignedConstant(U, DW_AT_high_pc, -1ULL);
298 if (HighPC != -1ULL)
299 HighPC += LowPC;
300 }
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000301 return (HighPC != -1ULL);
302}
303
Alexey Samsonov762343d2014-04-18 17:25:46 +0000304DWARFAddressRangesVector
305DWARFDebugInfoEntryMinimal::getAddressRanges(const DWARFUnit *U) const {
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000306 if (isNULL())
Benjamin Krameree26b622014-04-18 19:01:53 +0000307 return DWARFAddressRangesVector();
Alexey Samsonov762343d2014-04-18 17:25:46 +0000308 // Single range specified by low/high PC.
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000309 uint64_t LowPC, HighPC;
Alexey Samsonov762343d2014-04-18 17:25:46 +0000310 if (getLowAndHighPC(U, LowPC, HighPC)) {
Benjamin Krameree26b622014-04-18 19:01:53 +0000311 return DWARFAddressRangesVector(1, std::make_pair(LowPC, HighPC));
Alexey Samsonov762343d2014-04-18 17:25:46 +0000312 }
313 // Multiple ranges from .debug_ranges section.
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000314 uint32_t RangesOffset =
315 getAttributeValueAsSectionOffset(U, DW_AT_ranges, -1U);
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000316 if (RangesOffset != -1U) {
317 DWARFDebugRangeList RangeList;
David Blaikie07e22442013-09-23 22:44:40 +0000318 if (U->extractRangeList(RangesOffset, RangeList))
Alexey Samsonov762343d2014-04-18 17:25:46 +0000319 return RangeList.getAbsoluteRanges(U->getBaseAddress());
320 }
Benjamin Krameree26b622014-04-18 19:01:53 +0000321 return DWARFAddressRangesVector();
Alexey Samsonov762343d2014-04-18 17:25:46 +0000322}
323
324void DWARFDebugInfoEntryMinimal::collectChildrenAddressRanges(
325 const DWARFUnit *U, DWARFAddressRangesVector& Ranges) const {
326 if (isNULL())
327 return;
328 if (isSubprogramDIE()) {
329 const auto &DIERanges = getAddressRanges(U);
330 Ranges.insert(Ranges.end(), DIERanges.begin(), DIERanges.end());
331 }
332
333 const DWARFDebugInfoEntryMinimal *Child = getFirstChild();
334 while (Child) {
335 Child->collectChildrenAddressRanges(U, Ranges);
336 Child = Child->getSibling();
337 }
338}
339
340bool DWARFDebugInfoEntryMinimal::addressRangeContainsAddress(
341 const DWARFUnit *U, const uint64_t Address) const {
342 for (const auto& R : getAddressRanges(U)) {
343 if (R.first <= Address && Address < R.second)
344 return true;
Alexey Samsonovf4462fa2012-07-02 05:54:45 +0000345 }
346 return false;
347}
348
David Blaikie07e22442013-09-23 22:44:40 +0000349const char *
Alexey Samsonovdce67342014-05-15 21:24:32 +0000350DWARFDebugInfoEntryMinimal::getSubroutineName(const DWARFUnit *U,
Frederic Rissd4de1802014-10-10 15:51:02 +0000351 DINameKind Kind) const {
352 if (!isSubroutineDIE())
353 return nullptr;
354 return getName(U, Kind);
355}
356
357const char *
358DWARFDebugInfoEntryMinimal::getName(const DWARFUnit *U,
359 DINameKind Kind) const {
360 if (Kind == DINameKind::None)
Craig Topper2617dcc2014-04-15 06:32:26 +0000361 return nullptr;
Alexey Samsonovcd014722014-05-17 00:07:48 +0000362 // Try to get mangled name only if it was asked for.
Frederic Rissd4de1802014-10-10 15:51:02 +0000363 if (Kind == DINameKind::LinkageName) {
Alexey Samsonovcd014722014-05-17 00:07:48 +0000364 if (const char *name =
365 getAttributeValueAsString(U, DW_AT_MIPS_linkage_name, nullptr))
366 return name;
367 if (const char *name =
368 getAttributeValueAsString(U, DW_AT_linkage_name, nullptr))
369 return name;
370 }
Craig Topper2617dcc2014-04-15 06:32:26 +0000371 if (const char *name = getAttributeValueAsString(U, DW_AT_name, nullptr))
Alexey Samsonovb604ff22012-07-17 15:28:35 +0000372 return name;
373 // Try to get name from specification DIE.
374 uint32_t spec_ref =
David Blaikie07e22442013-09-23 22:44:40 +0000375 getAttributeValueAsReference(U, DW_AT_specification, -1U);
Alexey Samsonovb604ff22012-07-17 15:28:35 +0000376 if (spec_ref != -1U) {
377 DWARFDebugInfoEntryMinimal spec_die;
Frederic Riss58ed53c2014-09-22 12:35:53 +0000378 if (const DWARFUnit *RefU = findUnitAndExtractFast(spec_die, U, &spec_ref)) {
Frederic Rissd4de1802014-10-10 15:51:02 +0000379 if (const char *name = spec_die.getName(RefU, Kind))
Alexey Samsonovb604ff22012-07-17 15:28:35 +0000380 return name;
Alexey Samsonovf4462fa2012-07-02 05:54:45 +0000381 }
382 }
Alexey Samsonovb604ff22012-07-17 15:28:35 +0000383 // Try to get name from abstract origin DIE.
384 uint32_t abs_origin_ref =
David Blaikie07e22442013-09-23 22:44:40 +0000385 getAttributeValueAsReference(U, DW_AT_abstract_origin, -1U);
Alexey Samsonovb604ff22012-07-17 15:28:35 +0000386 if (abs_origin_ref != -1U) {
387 DWARFDebugInfoEntryMinimal abs_origin_die;
Frederic Riss58ed53c2014-09-22 12:35:53 +0000388 if (const DWARFUnit *RefU = findUnitAndExtractFast(abs_origin_die, U,
389 &abs_origin_ref)) {
Frederic Rissd4de1802014-10-10 15:51:02 +0000390 if (const char *name = abs_origin_die.getName(RefU, Kind))
Alexey Samsonovb604ff22012-07-17 15:28:35 +0000391 return name;
392 }
393 }
Craig Topper2617dcc2014-04-15 06:32:26 +0000394 return nullptr;
Alexey Samsonovf4462fa2012-07-02 05:54:45 +0000395}
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000396
David Blaikie07e22442013-09-23 22:44:40 +0000397void DWARFDebugInfoEntryMinimal::getCallerFrame(const DWARFUnit *U,
Eric Christopher206cf642012-10-30 21:36:43 +0000398 uint32_t &CallFile,
399 uint32_t &CallLine,
400 uint32_t &CallColumn) const {
Alexey Samsonov48cbda52013-10-28 23:01:48 +0000401 CallFile = getAttributeValueAsUnsignedConstant(U, DW_AT_call_file, 0);
402 CallLine = getAttributeValueAsUnsignedConstant(U, DW_AT_call_line, 0);
403 CallColumn = getAttributeValueAsUnsignedConstant(U, DW_AT_call_column, 0);
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000404}
405
Alexey Samsonov3211e612013-08-06 10:49:15 +0000406DWARFDebugInfoEntryInlinedChain
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000407DWARFDebugInfoEntryMinimal::getInlinedChainForAddress(
David Blaikie07e22442013-09-23 22:44:40 +0000408 const DWARFUnit *U, const uint64_t Address) const {
Alexey Samsonov3211e612013-08-06 10:49:15 +0000409 DWARFDebugInfoEntryInlinedChain InlinedChain;
David Blaikie07e22442013-09-23 22:44:40 +0000410 InlinedChain.U = U;
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000411 if (isNULL())
412 return InlinedChain;
413 for (const DWARFDebugInfoEntryMinimal *DIE = this; DIE; ) {
414 // Append current DIE to inlined chain only if it has correct tag
415 // (e.g. it is not a lexical block).
416 if (DIE->isSubroutineDIE()) {
Alexey Samsonov3211e612013-08-06 10:49:15 +0000417 InlinedChain.DIEs.push_back(*DIE);
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000418 }
419 // Try to get child which also contains provided address.
420 const DWARFDebugInfoEntryMinimal *Child = DIE->getFirstChild();
421 while (Child) {
David Blaikie07e22442013-09-23 22:44:40 +0000422 if (Child->addressRangeContainsAddress(U, Address)) {
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000423 // Assume there is only one such child.
424 break;
425 }
426 Child = Child->getSibling();
427 }
428 DIE = Child;
429 }
430 // Reverse the obtained chain to make the root of inlined chain last.
Alexey Samsonov3211e612013-08-06 10:49:15 +0000431 std::reverse(InlinedChain.DIEs.begin(), InlinedChain.DIEs.end());
Alexey Samsonovc942e6b2012-09-04 08:12:33 +0000432 return InlinedChain;
433}