blob: 39d8e3e918961b14caf51df74fb34ba38edff4b0 [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 uint32_t *OffsetPtr) {
97 Offset = *OffsetPtr;
David Blaikiecd7c4982013-09-23 22:44:40 +000098 DataExtractor DebugInfoData = U->getDebugInfoExtractor();
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +000099 uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
100 if (0 == AbbrCode) {
101 // NULL debug tag entry.
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000102 AbbrevDecl = NULL;
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000103 return true;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000104 }
David Blaikiecd7c4982013-09-23 22:44:40 +0000105 AbbrevDecl = U->getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000106 assert(AbbrevDecl);
Alexey Samsonov6faff482013-10-28 23:41:49 +0000107 ArrayRef<uint8_t> FixedFormSizes = DWARFFormValue::getFixedFormSizes(
108 U->getAddressByteSize(), U->getVersion());
109 assert(FixedFormSizes.size() > 0);
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000110
111 // Skip all data in the .debug_info for the attributes
112 for (uint32_t i = 0, n = AbbrevDecl->getNumAttributes(); i < n; ++i) {
113 uint16_t Form = AbbrevDecl->getFormByIndex(i);
114
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000115 uint8_t FixedFormSize =
Alexey Samsonov6faff482013-10-28 23:41:49 +0000116 (Form < FixedFormSizes.size()) ? FixedFormSizes[Form] : 0;
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000117 if (FixedFormSize)
118 *OffsetPtr += FixedFormSize;
Alexey Samsonov6faff482013-10-28 23:41:49 +0000119 else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, U)) {
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000120 // Restore the original offset.
121 *OffsetPtr = Offset;
122 return false;
123 }
124 }
125 return true;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000126}
127
David Blaikiecd7c4982013-09-23 22:44:40 +0000128bool DWARFDebugInfoEntryMinimal::extract(const DWARFUnit *U,
129 uint32_t *OffsetPtr) {
130 DataExtractor DebugInfoData = U->getDebugInfoExtractor();
131 const uint32_t UEndOffset = U->getNextUnitOffset();
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000132 Offset = *OffsetPtr;
David Blaikiecd7c4982013-09-23 22:44:40 +0000133 if ((Offset >= UEndOffset) || !DebugInfoData.isValidOffset(Offset))
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000134 return false;
135 uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
136 if (0 == AbbrCode) {
137 // NULL debug tag entry.
138 AbbrevDecl = NULL;
139 return true;
140 }
David Blaikiecd7c4982013-09-23 22:44:40 +0000141 AbbrevDecl = U->getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000142 if (0 == AbbrevDecl) {
143 // Restore the original offset.
144 *OffsetPtr = Offset;
145 return false;
146 }
147 bool IsCompileUnitTag = (AbbrevDecl->getTag() == DW_TAG_compile_unit);
148 if (IsCompileUnitTag)
David Blaikiecd7c4982013-09-23 22:44:40 +0000149 const_cast<DWARFUnit *>(U)->setBaseAddress(0);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000150
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000151 // Skip all data in the .debug_info for the attributes
152 for (uint32_t i = 0, n = AbbrevDecl->getNumAttributes(); i < n; ++i) {
153 uint16_t Attr = AbbrevDecl->getAttrByIndex(i);
154 uint16_t Form = AbbrevDecl->getFormByIndex(i);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000155
Alexey Samsonovd6b89ef2013-04-08 14:37:16 +0000156 if (IsCompileUnitTag &&
157 ((Attr == DW_AT_entry_pc) || (Attr == DW_AT_low_pc))) {
158 DWARFFormValue FormValue(Form);
David Blaikiecd7c4982013-09-23 22:44:40 +0000159 if (FormValue.extractValue(DebugInfoData, OffsetPtr, U)) {
Alexey Samsonovc5253232013-10-28 23:01:48 +0000160 if (Attr == DW_AT_low_pc || Attr == DW_AT_entry_pc) {
161 Optional<uint64_t> BaseAddr = FormValue.getAsAddress(U);
162 if (BaseAddr.hasValue())
163 const_cast<DWARFUnit *>(U)->setBaseAddress(BaseAddr.getValue());
164 }
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
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000185bool DWARFDebugInfoEntryMinimal::getAttributeValue(
186 const DWARFUnit *U, const uint16_t Attr, DWARFFormValue &FormValue) const {
187 if (!AbbrevDecl)
188 return false;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000189
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000190 uint32_t AttrIdx = AbbrevDecl->findAttributeIndex(Attr);
191 if (AttrIdx == -1U)
192 return false;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000193
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000194 DataExtractor DebugInfoData = U->getDebugInfoExtractor();
195 uint32_t DebugInfoOffset = getOffset();
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000196
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000197 // Skip the abbreviation code so we are at the data for the attributes
198 DebugInfoData.getULEB128(&DebugInfoOffset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000199
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000200 // Skip preceding attribute values.
201 for (uint32_t i = 0; i < AttrIdx; ++i) {
202 DWARFFormValue::skipValue(AbbrevDecl->getFormByIndex(i),
203 DebugInfoData, &DebugInfoOffset, U);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000204 }
205
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000206 FormValue = DWARFFormValue(AbbrevDecl->getFormByIndex(AttrIdx));
207 return FormValue.extractValue(DebugInfoData, &DebugInfoOffset, U);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000208}
209
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000210const char *DWARFDebugInfoEntryMinimal::getAttributeValueAsString(
David Blaikiecd7c4982013-09-23 22:44:40 +0000211 const DWARFUnit *U, const uint16_t Attr, const char *FailValue) const {
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000212 DWARFFormValue FormValue;
Alexey Samsonovc5253232013-10-28 23:01:48 +0000213 if (!getAttributeValue(U, Attr, FormValue))
214 return FailValue;
215 Optional<const char *> Result = FormValue.getAsCString(U);
216 return Result.hasValue() ? Result.getValue() : FailValue;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000217}
218
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000219uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsAddress(
David Blaikiecd7c4982013-09-23 22:44:40 +0000220 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000221 DWARFFormValue FormValue;
Alexey Samsonovc5253232013-10-28 23:01:48 +0000222 if (!getAttributeValue(U, Attr, FormValue))
223 return FailValue;
224 Optional<uint64_t> Result = FormValue.getAsAddress(U);
225 return Result.hasValue() ? Result.getValue() : FailValue;
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000226}
227
Alexey Samsonovc5253232013-10-28 23:01:48 +0000228uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsUnsignedConstant(
David Blaikiecd7c4982013-09-23 22:44:40 +0000229 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000230 DWARFFormValue FormValue;
Alexey Samsonovc5253232013-10-28 23:01:48 +0000231 if (!getAttributeValue(U, Attr, FormValue))
232 return FailValue;
233 Optional<uint64_t> Result = FormValue.getAsUnsignedConstant();
234 return Result.hasValue() ? Result.getValue() : FailValue;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000235}
236
David Blaikiecd7c4982013-09-23 22:44:40 +0000237uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsReference(
Alexey Samsonov2e56d572013-10-17 13:28:16 +0000238 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
239 DWARFFormValue FormValue;
Alexey Samsonovc5253232013-10-28 23:01:48 +0000240 if (!getAttributeValue(U, Attr, FormValue))
241 return FailValue;
242 Optional<uint64_t> Result = FormValue.getAsReference(U);
243 return Result.hasValue() ? Result.getValue() : FailValue;
244}
245
246uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsSectionOffset(
247 const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
248 DWARFFormValue FormValue;
249 if (!getAttributeValue(U, Attr, FormValue))
250 return FailValue;
251 Optional<uint64_t> Result = FormValue.getAsSectionOffset();
252 return Result.hasValue() ? Result.getValue() : FailValue;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000253}
Benjamin Kramer10df8062011-09-14 20:52:27 +0000254
David Blaikiecd7c4982013-09-23 22:44:40 +0000255bool DWARFDebugInfoEntryMinimal::getLowAndHighPC(const DWARFUnit *U,
Eric Christopher203e6f62012-10-30 21:36:43 +0000256 uint64_t &LowPC,
257 uint64_t &HighPC) const {
David Blaikiecd7c4982013-09-23 22:44:40 +0000258 LowPC = getAttributeValueAsAddress(U, DW_AT_low_pc, -1ULL);
Alexey Samsonovd2d54e22013-10-28 23:15:15 +0000259 if (LowPC == -1ULL)
260 return false;
261 HighPC = getAttributeValueAsAddress(U, DW_AT_high_pc, -1ULL);
262 if (HighPC == -1ULL) {
263 // Since DWARF4, DW_AT_high_pc may also be of class constant, in which case
264 // it represents function size.
265 HighPC = getAttributeValueAsUnsignedConstant(U, DW_AT_high_pc, -1ULL);
266 if (HighPC != -1ULL)
267 HighPC += LowPC;
268 }
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000269 return (HighPC != -1ULL);
270}
271
David Blaikiecd7c4982013-09-23 22:44:40 +0000272void DWARFDebugInfoEntryMinimal::buildAddressRangeTable(
273 const DWARFUnit *U, DWARFDebugAranges *DebugAranges,
274 uint32_t UOffsetInAranges) const {
Benjamin Kramer10df8062011-09-14 20:52:27 +0000275 if (AbbrevDecl) {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000276 if (isSubprogramDIE()) {
277 uint64_t LowPC, HighPC;
David Blaikiecd7c4982013-09-23 22:44:40 +0000278 if (getLowAndHighPC(U, LowPC, HighPC))
279 DebugAranges->appendRange(UOffsetInAranges, LowPC, HighPC);
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000280 // FIXME: try to append ranges from .debug_ranges section.
Benjamin Kramer10df8062011-09-14 20:52:27 +0000281 }
282
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000283 const DWARFDebugInfoEntryMinimal *Child = getFirstChild();
284 while (Child) {
David Blaikiecd7c4982013-09-23 22:44:40 +0000285 Child->buildAddressRangeTable(U, DebugAranges, UOffsetInAranges);
Alexey Samsonov63fd2af2013-08-27 09:20:22 +0000286 Child = Child->getSibling();
Benjamin Kramer10df8062011-09-14 20:52:27 +0000287 }
288 }
289}
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000290
David Blaikiecd7c4982013-09-23 22:44:40 +0000291bool DWARFDebugInfoEntryMinimal::addressRangeContainsAddress(
292 const DWARFUnit *U, const uint64_t Address) const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000293 if (isNULL())
294 return false;
295 uint64_t LowPC, HighPC;
David Blaikiecd7c4982013-09-23 22:44:40 +0000296 if (getLowAndHighPC(U, LowPC, HighPC))
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000297 return (LowPC <= Address && Address <= HighPC);
298 // Try to get address ranges from .debug_ranges section.
Alexey Samsonovc5253232013-10-28 23:01:48 +0000299 uint32_t RangesOffset =
300 getAttributeValueAsSectionOffset(U, DW_AT_ranges, -1U);
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000301 if (RangesOffset != -1U) {
302 DWARFDebugRangeList RangeList;
David Blaikiecd7c4982013-09-23 22:44:40 +0000303 if (U->extractRangeList(RangesOffset, RangeList))
304 return RangeList.containsAddress(U->getBaseAddress(), Address);
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000305 }
306 return false;
307}
308
David Blaikiecd7c4982013-09-23 22:44:40 +0000309const char *
310DWARFDebugInfoEntryMinimal::getSubroutineName(const DWARFUnit *U) const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000311 if (!isSubroutineDIE())
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000312 return 0;
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000313 // Try to get mangled name if possible.
314 if (const char *name =
David Blaikiecd7c4982013-09-23 22:44:40 +0000315 getAttributeValueAsString(U, DW_AT_MIPS_linkage_name, 0))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000316 return name;
David Blaikiecd7c4982013-09-23 22:44:40 +0000317 if (const char *name = getAttributeValueAsString(U, DW_AT_linkage_name, 0))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000318 return name;
David Blaikiecd7c4982013-09-23 22:44:40 +0000319 if (const char *name = getAttributeValueAsString(U, DW_AT_name, 0))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000320 return name;
321 // Try to get name from specification DIE.
322 uint32_t spec_ref =
David Blaikiecd7c4982013-09-23 22:44:40 +0000323 getAttributeValueAsReference(U, DW_AT_specification, -1U);
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000324 if (spec_ref != -1U) {
325 DWARFDebugInfoEntryMinimal spec_die;
David Blaikiecd7c4982013-09-23 22:44:40 +0000326 if (spec_die.extract(U, &spec_ref)) {
327 if (const char *name = spec_die.getSubroutineName(U))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000328 return name;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000329 }
330 }
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000331 // Try to get name from abstract origin DIE.
332 uint32_t abs_origin_ref =
David Blaikiecd7c4982013-09-23 22:44:40 +0000333 getAttributeValueAsReference(U, DW_AT_abstract_origin, -1U);
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000334 if (abs_origin_ref != -1U) {
335 DWARFDebugInfoEntryMinimal abs_origin_die;
David Blaikiecd7c4982013-09-23 22:44:40 +0000336 if (abs_origin_die.extract(U, &abs_origin_ref)) {
337 if (const char *name = abs_origin_die.getSubroutineName(U))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000338 return name;
339 }
340 }
341 return 0;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000342}
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000343
David Blaikiecd7c4982013-09-23 22:44:40 +0000344void DWARFDebugInfoEntryMinimal::getCallerFrame(const DWARFUnit *U,
Eric Christopher203e6f62012-10-30 21:36:43 +0000345 uint32_t &CallFile,
346 uint32_t &CallLine,
347 uint32_t &CallColumn) const {
Alexey Samsonovc5253232013-10-28 23:01:48 +0000348 CallFile = getAttributeValueAsUnsignedConstant(U, DW_AT_call_file, 0);
349 CallLine = getAttributeValueAsUnsignedConstant(U, DW_AT_call_line, 0);
350 CallColumn = getAttributeValueAsUnsignedConstant(U, DW_AT_call_column, 0);
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000351}
352
Alexey Samsonove6642902013-08-06 10:49:15 +0000353DWARFDebugInfoEntryInlinedChain
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000354DWARFDebugInfoEntryMinimal::getInlinedChainForAddress(
David Blaikiecd7c4982013-09-23 22:44:40 +0000355 const DWARFUnit *U, const uint64_t Address) const {
Alexey Samsonove6642902013-08-06 10:49:15 +0000356 DWARFDebugInfoEntryInlinedChain InlinedChain;
David Blaikiecd7c4982013-09-23 22:44:40 +0000357 InlinedChain.U = U;
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000358 if (isNULL())
359 return InlinedChain;
360 for (const DWARFDebugInfoEntryMinimal *DIE = this; DIE; ) {
361 // Append current DIE to inlined chain only if it has correct tag
362 // (e.g. it is not a lexical block).
363 if (DIE->isSubroutineDIE()) {
Alexey Samsonove6642902013-08-06 10:49:15 +0000364 InlinedChain.DIEs.push_back(*DIE);
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000365 }
366 // Try to get child which also contains provided address.
367 const DWARFDebugInfoEntryMinimal *Child = DIE->getFirstChild();
368 while (Child) {
David Blaikiecd7c4982013-09-23 22:44:40 +0000369 if (Child->addressRangeContainsAddress(U, Address)) {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000370 // Assume there is only one such child.
371 break;
372 }
373 Child = Child->getSibling();
374 }
375 DIE = Child;
376 }
377 // Reverse the obtained chain to make the root of inlined chain last.
Alexey Samsonove6642902013-08-06 10:49:15 +0000378 std::reverse(InlinedChain.DIEs.begin(), InlinedChain.DIEs.end());
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000379 return InlinedChain;
380}