blob: bb118501c11ab793ac74260acd8fe5aa774bdfda [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"
14#include "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
22void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS,
23 const DWARFCompileUnit *cu,
24 unsigned recurseDepth,
25 unsigned indent) const {
26 DataExtractor debug_info_data = cu->getDebugInfoExtractor();
27 uint32_t offset = Offset;
28
29 if (debug_info_data.isValidOffset(offset)) {
Benjamin Kramer80cc2592011-11-05 15:35:00 +000030 uint32_t abbrCode = debug_info_data.getULEB128(&offset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000031
Benjamin Kramer09422552011-09-14 17:54:56 +000032 OS << format("\n0x%8.8x: ", Offset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000033 if (abbrCode) {
34 if (AbbrevDecl) {
Benjamin Kramer75c63082011-09-15 05:43:00 +000035 const char *tagString = TagString(getTag());
36 if (tagString)
37 OS.indent(indent) << tagString;
38 else
39 OS.indent(indent) << format("DW_TAG_Unknown_%x", getTag());
40 OS << format(" [%u] %c\n", abbrCode,
41 AbbrevDecl->hasChildren() ? '*' : ' ');
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000042
Eric Christophere5ef3052013-01-07 03:27:58 +000043 // Dump all data in the DIE for the attributes.
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000044 const uint32_t numAttributes = AbbrevDecl->getNumAttributes();
45 for (uint32_t i = 0; i != numAttributes; ++i) {
46 uint16_t attr = AbbrevDecl->getAttrByIndex(i);
47 uint16_t form = AbbrevDecl->getFormByIndex(i);
48 dumpAttribute(OS, cu, &offset, attr, form, indent);
49 }
50
51 const DWARFDebugInfoEntryMinimal *child = getFirstChild();
52 if (recurseDepth > 0 && child) {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000053 while (child) {
Benjamin Kramer15ec0852011-09-14 00:15:32 +000054 child->dump(OS, cu, recurseDepth-1, indent+2);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000055 child = child->getSibling();
56 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000057 }
58 } else {
59 OS << "Abbreviation code not found in 'debug_abbrev' class for code: "
60 << abbrCode << '\n';
61 }
62 } else {
Benjamin Kramer09422552011-09-14 17:54:56 +000063 OS.indent(indent) << "NULL\n";
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000064 }
65 }
66}
67
68void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS,
69 const DWARFCompileUnit *cu,
70 uint32_t* offset_ptr,
71 uint16_t attr,
72 uint16_t form,
73 unsigned indent) const {
Benjamin Kramer09422552011-09-14 17:54:56 +000074 OS << format("0x%8.8x: ", *offset_ptr);
Benjamin Kramer75c63082011-09-15 05:43:00 +000075 OS.indent(indent+2);
76 const char *attrString = AttributeString(attr);
77 if (attrString)
78 OS << attrString;
79 else
80 OS << format("DW_AT_Unknown_%x", attr);
81 const char *formString = FormEncodingString(form);
82 if (formString)
83 OS << " [" << formString << ']';
84 else
85 OS << format(" [DW_FORM_Unknown_%x]", form);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000086
87 DWARFFormValue formValue(form);
88
89 if (!formValue.extractValue(cu->getDebugInfoExtractor(), offset_ptr, cu))
90 return;
91
92 OS << "\t(";
Benjamin Kramer34f864f2011-09-15 16:57:13 +000093 formValue.dump(OS, cu);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000094 OS << ")\n";
95}
96
97bool DWARFDebugInfoEntryMinimal::extractFast(const DWARFCompileUnit *cu,
98 const uint8_t *fixed_form_sizes,
99 uint32_t *offset_ptr) {
100 Offset = *offset_ptr;
101
102 DataExtractor debug_info_data = cu->getDebugInfoExtractor();
103 uint64_t abbrCode = debug_info_data.getULEB128(offset_ptr);
104
Eric Christopher08cdb6e2012-08-24 01:14:21 +0000105 assert(fixed_form_sizes); // For best performance this should be specified!
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000106
107 if (abbrCode) {
108 uint32_t offset = *offset_ptr;
109
110 AbbrevDecl = cu->getAbbreviations()->getAbbreviationDeclaration(abbrCode);
111
112 // Skip all data in the .debug_info for the attributes
113 const uint32_t numAttributes = AbbrevDecl->getNumAttributes();
114 uint32_t i;
115 uint16_t form;
116 for (i=0; i<numAttributes; ++i) {
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000117
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000118 form = AbbrevDecl->getFormByIndex(i);
119
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000120 // FIXME: Currently we're checking if this is less than the last
121 // entry in the fixed_form_sizes table, but this should be changed
122 // to use dynamic dispatch.
123 const uint8_t fixed_skip_size = (form < DW_FORM_ref_sig8) ?
124 fixed_form_sizes[form] : 0;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000125 if (fixed_skip_size)
126 offset += fixed_skip_size;
127 else {
128 bool form_is_indirect = false;
129 do {
130 form_is_indirect = false;
131 uint32_t form_size = 0;
132 switch (form) {
133 // Blocks if inlined data that have a length field and the data bytes
134 // inlined in the .debug_info.
Eric Christopher3887a902012-08-24 01:14:23 +0000135 case DW_FORM_exprloc:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000136 case DW_FORM_block:
137 form_size = debug_info_data.getULEB128(&offset);
138 break;
139 case DW_FORM_block1:
140 form_size = debug_info_data.getU8(&offset);
141 break;
142 case DW_FORM_block2:
143 form_size = debug_info_data.getU16(&offset);
144 break;
145 case DW_FORM_block4:
146 form_size = debug_info_data.getU32(&offset);
147 break;
148
149 // Inlined NULL terminated C-strings
150 case DW_FORM_string:
151 debug_info_data.getCStr(&offset);
152 break;
153
154 // Compile unit address sized values
155 case DW_FORM_addr:
156 case DW_FORM_ref_addr:
157 form_size = cu->getAddressByteSize();
158 break;
159
Eric Christopher3887a902012-08-24 01:14:23 +0000160 // 0 sized form.
161 case DW_FORM_flag_present:
162 form_size = 0;
163 break;
164
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000165 // 1 byte values
166 case DW_FORM_data1:
167 case DW_FORM_flag:
168 case DW_FORM_ref1:
169 form_size = 1;
170 break;
171
172 // 2 byte values
173 case DW_FORM_data2:
174 case DW_FORM_ref2:
175 form_size = 2;
176 break;
177
178 // 4 byte values
179 case DW_FORM_strp:
180 case DW_FORM_data4:
181 case DW_FORM_ref4:
182 form_size = 4;
183 break;
184
185 // 8 byte values
186 case DW_FORM_data8:
187 case DW_FORM_ref8:
Eric Christopher3887a902012-08-24 01:14:23 +0000188 case DW_FORM_ref_sig8:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000189 form_size = 8;
190 break;
191
192 // signed or unsigned LEB 128 values
193 case DW_FORM_sdata:
194 case DW_FORM_udata:
195 case DW_FORM_ref_udata:
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000196 case DW_FORM_GNU_str_index:
197 case DW_FORM_GNU_addr_index:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000198 debug_info_data.getULEB128(&offset);
199 break;
200
201 case DW_FORM_indirect:
202 form_is_indirect = true;
203 form = debug_info_data.getULEB128(&offset);
204 break;
205
Eric Christopher3887a902012-08-24 01:14:23 +0000206 case DW_FORM_sec_offset:
207 if (cu->getAddressByteSize() == 4)
208 debug_info_data.getU32(offset_ptr);
209 else
210 debug_info_data.getU64(offset_ptr);
211 break;
212
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000213 default:
214 *offset_ptr = Offset;
215 return false;
216 }
217 offset += form_size;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000218 } while (form_is_indirect);
219 }
220 }
221 *offset_ptr = offset;
222 return true;
223 } else {
224 AbbrevDecl = NULL;
225 return true; // NULL debug tag entry
226 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000227}
228
229bool
230DWARFDebugInfoEntryMinimal::extract(const DWARFCompileUnit *cu,
231 uint32_t *offset_ptr) {
232 DataExtractor debug_info_data = cu->getDebugInfoExtractor();
233 const uint32_t cu_end_offset = cu->getNextCompileUnitOffset();
234 const uint8_t cu_addr_size = cu->getAddressByteSize();
235 uint32_t offset = *offset_ptr;
236 if ((offset < cu_end_offset) && debug_info_data.isValidOffset(offset)) {
237 Offset = offset;
238
239 uint64_t abbrCode = debug_info_data.getULEB128(&offset);
240
241 if (abbrCode) {
242 AbbrevDecl = cu->getAbbreviations()->getAbbreviationDeclaration(abbrCode);
243
244 if (AbbrevDecl) {
245 uint16_t tag = AbbrevDecl->getTag();
246
247 bool isCompileUnitTag = tag == DW_TAG_compile_unit;
248 if(cu && isCompileUnitTag)
249 const_cast<DWARFCompileUnit*>(cu)->setBaseAddress(0);
250
251 // Skip all data in the .debug_info for the attributes
252 const uint32_t numAttributes = AbbrevDecl->getNumAttributes();
253 for (uint32_t i = 0; i != numAttributes; ++i) {
254 uint16_t attr = AbbrevDecl->getAttrByIndex(i);
255 uint16_t form = AbbrevDecl->getFormByIndex(i);
256
257 if (isCompileUnitTag &&
258 ((attr == DW_AT_entry_pc) || (attr == DW_AT_low_pc))) {
259 DWARFFormValue form_value(form);
260 if (form_value.extractValue(debug_info_data, &offset, cu)) {
261 if (attr == DW_AT_low_pc || attr == DW_AT_entry_pc)
262 const_cast<DWARFCompileUnit*>(cu)
263 ->setBaseAddress(form_value.getUnsigned());
264 }
265 } else {
266 bool form_is_indirect = false;
267 do {
268 form_is_indirect = false;
269 register uint32_t form_size = 0;
270 switch (form) {
271 // Blocks if inlined data that have a length field and the data
272 // bytes // inlined in the .debug_info
Eric Christopher3887a902012-08-24 01:14:23 +0000273 case DW_FORM_exprloc:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000274 case DW_FORM_block:
275 form_size = debug_info_data.getULEB128(&offset);
276 break;
277 case DW_FORM_block1:
278 form_size = debug_info_data.getU8(&offset);
279 break;
280 case DW_FORM_block2:
281 form_size = debug_info_data.getU16(&offset);
282 break;
283 case DW_FORM_block4:
284 form_size = debug_info_data.getU32(&offset);
285 break;
286
287 // Inlined NULL terminated C-strings
288 case DW_FORM_string:
289 debug_info_data.getCStr(&offset);
290 break;
291
292 // Compile unit address sized values
293 case DW_FORM_addr:
294 case DW_FORM_ref_addr:
295 form_size = cu_addr_size;
296 break;
297
Eric Christopher3887a902012-08-24 01:14:23 +0000298 // 0 byte value
299 case DW_FORM_flag_present:
300 form_size = 0;
301 break;
302
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000303 // 1 byte values
304 case DW_FORM_data1:
305 case DW_FORM_flag:
306 case DW_FORM_ref1:
307 form_size = 1;
308 break;
309
310 // 2 byte values
311 case DW_FORM_data2:
312 case DW_FORM_ref2:
313 form_size = 2;
314 break;
315
316 // 4 byte values
317 case DW_FORM_strp:
318 form_size = 4;
319 break;
320
321 case DW_FORM_data4:
322 case DW_FORM_ref4:
323 form_size = 4;
324 break;
325
326 // 8 byte values
327 case DW_FORM_data8:
328 case DW_FORM_ref8:
Eric Christopher3887a902012-08-24 01:14:23 +0000329 case DW_FORM_ref_sig8:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000330 form_size = 8;
331 break;
332
333 // signed or unsigned LEB 128 values
334 case DW_FORM_sdata:
335 case DW_FORM_udata:
336 case DW_FORM_ref_udata:
Eric Christopherdd8e9f32013-01-07 19:32:41 +0000337 case DW_FORM_GNU_str_index:
338 case DW_FORM_GNU_addr_index:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000339 debug_info_data.getULEB128(&offset);
340 break;
341
342 case DW_FORM_indirect:
343 form = debug_info_data.getULEB128(&offset);
344 form_is_indirect = true;
345 break;
346
Eric Christopher3887a902012-08-24 01:14:23 +0000347 case DW_FORM_sec_offset:
348 if (cu->getAddressByteSize() == 4)
349 debug_info_data.getU32(offset_ptr);
350 else
351 debug_info_data.getU64(offset_ptr);
352 break;
Eric Christopher203e6f62012-10-30 21:36:43 +0000353
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000354 default:
355 *offset_ptr = offset;
356 return false;
357 }
358
359 offset += form_size;
360 } while (form_is_indirect);
361 }
362 }
363 *offset_ptr = offset;
364 return true;
365 }
366 } else {
367 AbbrevDecl = NULL;
368 *offset_ptr = offset;
369 return true; // NULL debug tag entry
370 }
371 }
372
373 return false;
374}
375
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000376bool DWARFDebugInfoEntryMinimal::isSubprogramDIE() const {
377 return getTag() == DW_TAG_subprogram;
378}
379
380bool DWARFDebugInfoEntryMinimal::isSubroutineDIE() const {
381 uint32_t Tag = getTag();
382 return Tag == DW_TAG_subprogram ||
383 Tag == DW_TAG_inlined_subroutine;
384}
385
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000386uint32_t
387DWARFDebugInfoEntryMinimal::getAttributeValue(const DWARFCompileUnit *cu,
388 const uint16_t attr,
389 DWARFFormValue &form_value,
390 uint32_t *end_attr_offset_ptr)
391 const {
392 if (AbbrevDecl) {
393 uint32_t attr_idx = AbbrevDecl->findAttributeIndex(attr);
394
395 if (attr_idx != -1U) {
396 uint32_t offset = getOffset();
397
398 DataExtractor debug_info_data = cu->getDebugInfoExtractor();
399
400 // Skip the abbreviation code so we are at the data for the attributes
401 debug_info_data.getULEB128(&offset);
402
403 uint32_t idx = 0;
404 while (idx < attr_idx)
405 DWARFFormValue::skipValue(AbbrevDecl->getFormByIndex(idx++),
406 debug_info_data, &offset, cu);
407
408 const uint32_t attr_offset = offset;
409 form_value = DWARFFormValue(AbbrevDecl->getFormByIndex(idx));
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000410 if (form_value.extractValue(debug_info_data, &offset, cu)) {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000411 if (end_attr_offset_ptr)
412 *end_attr_offset_ptr = offset;
413 return attr_offset;
414 }
415 }
416 }
417
418 return 0;
419}
420
421const char*
422DWARFDebugInfoEntryMinimal::getAttributeValueAsString(
Eric Christopher203e6f62012-10-30 21:36:43 +0000423 const DWARFCompileUnit* cu,
424 const uint16_t attr,
425 const char* fail_value)
426 const {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000427 DWARFFormValue form_value;
428 if (getAttributeValue(cu, attr, form_value)) {
Eric Christopher82de10a2013-01-02 23:52:13 +0000429 DataExtractor stringExtractor(cu->getStringSection(), false, 0);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000430 return form_value.getAsCString(&stringExtractor);
431 }
432 return fail_value;
433}
434
435uint64_t
436DWARFDebugInfoEntryMinimal::getAttributeValueAsUnsigned(
Eric Christopher203e6f62012-10-30 21:36:43 +0000437 const DWARFCompileUnit* cu,
438 const uint16_t attr,
439 uint64_t fail_value) const {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000440 DWARFFormValue form_value;
441 if (getAttributeValue(cu, attr, form_value))
442 return form_value.getUnsigned();
443 return fail_value;
444}
445
446int64_t
447DWARFDebugInfoEntryMinimal::getAttributeValueAsSigned(
Eric Christopher203e6f62012-10-30 21:36:43 +0000448 const DWARFCompileUnit* cu,
449 const uint16_t attr,
450 int64_t fail_value) const {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000451 DWARFFormValue form_value;
452 if (getAttributeValue(cu, attr, form_value))
453 return form_value.getSigned();
454 return fail_value;
455}
456
457uint64_t
Benjamin Kramer10df8062011-09-14 20:52:27 +0000458DWARFDebugInfoEntryMinimal::getAttributeValueAsReference(
Eric Christopher203e6f62012-10-30 21:36:43 +0000459 const DWARFCompileUnit* cu,
460 const uint16_t attr,
461 uint64_t fail_value)
462 const {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000463 DWARFFormValue form_value;
464 if (getAttributeValue(cu, attr, form_value))
465 return form_value.getReference(cu);
466 return fail_value;
467}
Benjamin Kramer10df8062011-09-14 20:52:27 +0000468
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000469bool DWARFDebugInfoEntryMinimal::getLowAndHighPC(const DWARFCompileUnit *CU,
Eric Christopher203e6f62012-10-30 21:36:43 +0000470 uint64_t &LowPC,
471 uint64_t &HighPC) const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000472 HighPC = -1ULL;
473 LowPC = getAttributeValueAsUnsigned(CU, DW_AT_low_pc, -1ULL);
474 if (LowPC != -1ULL)
475 HighPC = getAttributeValueAsUnsigned(CU, DW_AT_high_pc, -1ULL);
476 return (HighPC != -1ULL);
477}
478
Benjamin Kramer10df8062011-09-14 20:52:27 +0000479void
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000480DWARFDebugInfoEntryMinimal::buildAddressRangeTable(const DWARFCompileUnit *CU,
481 DWARFDebugAranges *DebugAranges)
Benjamin Kramer10df8062011-09-14 20:52:27 +0000482 const {
483 if (AbbrevDecl) {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000484 if (isSubprogramDIE()) {
485 uint64_t LowPC, HighPC;
486 if (getLowAndHighPC(CU, LowPC, HighPC)) {
487 DebugAranges->appendRange(CU->getOffset(), LowPC, HighPC);
488 }
489 // FIXME: try to append ranges from .debug_ranges section.
Benjamin Kramer10df8062011-09-14 20:52:27 +0000490 }
491
492 const DWARFDebugInfoEntryMinimal *child = getFirstChild();
493 while (child) {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000494 child->buildAddressRangeTable(CU, DebugAranges);
Benjamin Kramer10df8062011-09-14 20:52:27 +0000495 child = child->getSibling();
496 }
497 }
498}
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000499
500bool
501DWARFDebugInfoEntryMinimal::addressRangeContainsAddress(
Eric Christopher203e6f62012-10-30 21:36:43 +0000502 const DWARFCompileUnit *CU,
503 const uint64_t Address)
504 const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000505 if (isNULL())
506 return false;
507 uint64_t LowPC, HighPC;
508 if (getLowAndHighPC(CU, LowPC, HighPC))
509 return (LowPC <= Address && Address <= HighPC);
510 // Try to get address ranges from .debug_ranges section.
511 uint32_t RangesOffset = getAttributeValueAsReference(CU, DW_AT_ranges, -1U);
512 if (RangesOffset != -1U) {
513 DWARFDebugRangeList RangeList;
514 if (CU->extractRangeList(RangesOffset, RangeList))
515 return RangeList.containsAddress(CU->getBaseAddress(), Address);
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000516 }
517 return false;
518}
519
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000520const char*
Eric Christopher203e6f62012-10-30 21:36:43 +0000521DWARFDebugInfoEntryMinimal::getSubroutineName(const DWARFCompileUnit *CU)
522 const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000523 if (!isSubroutineDIE())
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000524 return 0;
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000525 // Try to get mangled name if possible.
526 if (const char *name =
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000527 getAttributeValueAsString(CU, DW_AT_MIPS_linkage_name, 0))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000528 return name;
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000529 if (const char *name = getAttributeValueAsString(CU, DW_AT_linkage_name, 0))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000530 return name;
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000531 if (const char *name = getAttributeValueAsString(CU, DW_AT_name, 0))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000532 return name;
533 // Try to get name from specification DIE.
534 uint32_t spec_ref =
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000535 getAttributeValueAsReference(CU, DW_AT_specification, -1U);
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000536 if (spec_ref != -1U) {
537 DWARFDebugInfoEntryMinimal spec_die;
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000538 if (spec_die.extract(CU, &spec_ref)) {
539 if (const char *name = spec_die.getSubroutineName(CU))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000540 return name;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000541 }
542 }
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000543 // Try to get name from abstract origin DIE.
544 uint32_t abs_origin_ref =
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000545 getAttributeValueAsReference(CU, DW_AT_abstract_origin, -1U);
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000546 if (abs_origin_ref != -1U) {
547 DWARFDebugInfoEntryMinimal abs_origin_die;
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000548 if (abs_origin_die.extract(CU, &abs_origin_ref)) {
549 if (const char *name = abs_origin_die.getSubroutineName(CU))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000550 return name;
551 }
552 }
553 return 0;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000554}
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000555
Eric Christopher203e6f62012-10-30 21:36:43 +0000556void DWARFDebugInfoEntryMinimal::getCallerFrame(const DWARFCompileUnit *CU,
557 uint32_t &CallFile,
558 uint32_t &CallLine,
559 uint32_t &CallColumn) const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000560 CallFile = getAttributeValueAsUnsigned(CU, DW_AT_call_file, 0);
561 CallLine = getAttributeValueAsUnsigned(CU, DW_AT_call_line, 0);
562 CallColumn = getAttributeValueAsUnsigned(CU, DW_AT_call_column, 0);
563}
564
565DWARFDebugInfoEntryMinimal::InlinedChain
566DWARFDebugInfoEntryMinimal::getInlinedChainForAddress(
Eric Christopher203e6f62012-10-30 21:36:43 +0000567 const DWARFCompileUnit *CU,
568 const uint64_t Address)
569 const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000570 DWARFDebugInfoEntryMinimal::InlinedChain InlinedChain;
571 if (isNULL())
572 return InlinedChain;
573 for (const DWARFDebugInfoEntryMinimal *DIE = this; DIE; ) {
574 // Append current DIE to inlined chain only if it has correct tag
575 // (e.g. it is not a lexical block).
576 if (DIE->isSubroutineDIE()) {
577 InlinedChain.push_back(*DIE);
578 }
579 // Try to get child which also contains provided address.
580 const DWARFDebugInfoEntryMinimal *Child = DIE->getFirstChild();
581 while (Child) {
582 if (Child->addressRangeContainsAddress(CU, Address)) {
583 // Assume there is only one such child.
584 break;
585 }
586 Child = Child->getSibling();
587 }
588 DIE = Child;
589 }
590 // Reverse the obtained chain to make the root of inlined chain last.
591 std::reverse(InlinedChain.begin(), InlinedChain.end());
592 return InlinedChain;
593}