blob: ab67464453880927056a25fb96c4d99d4768c125 [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"
15#include "llvm/Support/Dwarf.h"
16#include "llvm/Support/Format.h"
17#include "llvm/Support/raw_ostream.h"
18using namespace llvm;
19using namespace dwarf;
20
21void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS,
22 const DWARFCompileUnit *cu,
23 unsigned recurseDepth,
24 unsigned indent) const {
25 DataExtractor debug_info_data = cu->getDebugInfoExtractor();
26 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
42 // Dump all data in the .debug_info for the attributes
43 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);
47 dumpAttribute(OS, cu, &offset, attr, form, indent);
48 }
49
50 const DWARFDebugInfoEntryMinimal *child = getFirstChild();
51 if (recurseDepth > 0 && child) {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000052 while (child) {
Benjamin Kramer15ec0852011-09-14 00:15:32 +000053 child->dump(OS, cu, 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,
68 const DWARFCompileUnit *cu,
69 uint32_t* offset_ptr,
70 uint16_t attr,
71 uint16_t form,
72 unsigned indent) const {
Benjamin Kramer09422552011-09-14 17:54:56 +000073 OS << format("0x%8.8x: ", *offset_ptr);
Benjamin Kramer75c63082011-09-15 05:43:00 +000074 OS.indent(indent+2);
75 const char *attrString = AttributeString(attr);
76 if (attrString)
77 OS << attrString;
78 else
79 OS << format("DW_AT_Unknown_%x", attr);
80 const char *formString = FormEncodingString(form);
81 if (formString)
82 OS << " [" << formString << ']';
83 else
84 OS << format(" [DW_FORM_Unknown_%x]", form);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000085
86 DWARFFormValue formValue(form);
87
88 if (!formValue.extractValue(cu->getDebugInfoExtractor(), offset_ptr, cu))
89 return;
90
91 OS << "\t(";
Benjamin Kramer34f864f2011-09-15 16:57:13 +000092 formValue.dump(OS, cu);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000093 OS << ")\n";
94}
95
96bool DWARFDebugInfoEntryMinimal::extractFast(const DWARFCompileUnit *cu,
97 const uint8_t *fixed_form_sizes,
98 uint32_t *offset_ptr) {
99 Offset = *offset_ptr;
100
101 DataExtractor debug_info_data = cu->getDebugInfoExtractor();
102 uint64_t abbrCode = debug_info_data.getULEB128(offset_ptr);
103
Eric Christopher08cdb6e2012-08-24 01:14:21 +0000104 assert(fixed_form_sizes); // For best performance this should be specified!
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000105
106 if (abbrCode) {
107 uint32_t offset = *offset_ptr;
108
109 AbbrevDecl = cu->getAbbreviations()->getAbbreviationDeclaration(abbrCode);
110
111 // Skip all data in the .debug_info for the attributes
112 const uint32_t numAttributes = AbbrevDecl->getNumAttributes();
113 uint32_t i;
114 uint16_t form;
115 for (i=0; i<numAttributes; ++i) {
116 form = AbbrevDecl->getFormByIndex(i);
117
118 const uint8_t fixed_skip_size = fixed_form_sizes[form];
119 if (fixed_skip_size)
120 offset += fixed_skip_size;
121 else {
122 bool form_is_indirect = false;
123 do {
124 form_is_indirect = false;
125 uint32_t form_size = 0;
126 switch (form) {
127 // Blocks if inlined data that have a length field and the data bytes
128 // inlined in the .debug_info.
Eric Christopher3887a902012-08-24 01:14:23 +0000129 case DW_FORM_exprloc:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000130 case DW_FORM_block:
131 form_size = debug_info_data.getULEB128(&offset);
132 break;
133 case DW_FORM_block1:
134 form_size = debug_info_data.getU8(&offset);
135 break;
136 case DW_FORM_block2:
137 form_size = debug_info_data.getU16(&offset);
138 break;
139 case DW_FORM_block4:
140 form_size = debug_info_data.getU32(&offset);
141 break;
142
143 // Inlined NULL terminated C-strings
144 case DW_FORM_string:
145 debug_info_data.getCStr(&offset);
146 break;
147
148 // Compile unit address sized values
149 case DW_FORM_addr:
150 case DW_FORM_ref_addr:
151 form_size = cu->getAddressByteSize();
152 break;
153
Eric Christopher3887a902012-08-24 01:14:23 +0000154 // 0 sized form.
155 case DW_FORM_flag_present:
156 form_size = 0;
157 break;
158
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000159 // 1 byte values
160 case DW_FORM_data1:
161 case DW_FORM_flag:
162 case DW_FORM_ref1:
163 form_size = 1;
164 break;
165
166 // 2 byte values
167 case DW_FORM_data2:
168 case DW_FORM_ref2:
169 form_size = 2;
170 break;
171
172 // 4 byte values
173 case DW_FORM_strp:
174 case DW_FORM_data4:
175 case DW_FORM_ref4:
176 form_size = 4;
177 break;
178
179 // 8 byte values
180 case DW_FORM_data8:
181 case DW_FORM_ref8:
Eric Christopher3887a902012-08-24 01:14:23 +0000182 case DW_FORM_ref_sig8:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000183 form_size = 8;
184 break;
185
186 // signed or unsigned LEB 128 values
187 case DW_FORM_sdata:
188 case DW_FORM_udata:
189 case DW_FORM_ref_udata:
190 debug_info_data.getULEB128(&offset);
191 break;
192
193 case DW_FORM_indirect:
194 form_is_indirect = true;
195 form = debug_info_data.getULEB128(&offset);
196 break;
197
Eric Christopher3887a902012-08-24 01:14:23 +0000198 case DW_FORM_sec_offset:
199 if (cu->getAddressByteSize() == 4)
200 debug_info_data.getU32(offset_ptr);
201 else
202 debug_info_data.getU64(offset_ptr);
203 break;
204
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000205 default:
206 *offset_ptr = Offset;
207 return false;
208 }
209 offset += form_size;
210
211 } while (form_is_indirect);
212 }
213 }
214 *offset_ptr = offset;
215 return true;
216 } else {
217 AbbrevDecl = NULL;
218 return true; // NULL debug tag entry
219 }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000220}
221
222bool
223DWARFDebugInfoEntryMinimal::extract(const DWARFCompileUnit *cu,
224 uint32_t *offset_ptr) {
225 DataExtractor debug_info_data = cu->getDebugInfoExtractor();
226 const uint32_t cu_end_offset = cu->getNextCompileUnitOffset();
227 const uint8_t cu_addr_size = cu->getAddressByteSize();
228 uint32_t offset = *offset_ptr;
229 if ((offset < cu_end_offset) && debug_info_data.isValidOffset(offset)) {
230 Offset = offset;
231
232 uint64_t abbrCode = debug_info_data.getULEB128(&offset);
233
234 if (abbrCode) {
235 AbbrevDecl = cu->getAbbreviations()->getAbbreviationDeclaration(abbrCode);
236
237 if (AbbrevDecl) {
238 uint16_t tag = AbbrevDecl->getTag();
239
240 bool isCompileUnitTag = tag == DW_TAG_compile_unit;
241 if(cu && isCompileUnitTag)
242 const_cast<DWARFCompileUnit*>(cu)->setBaseAddress(0);
243
244 // Skip all data in the .debug_info for the attributes
245 const uint32_t numAttributes = AbbrevDecl->getNumAttributes();
246 for (uint32_t i = 0; i != numAttributes; ++i) {
247 uint16_t attr = AbbrevDecl->getAttrByIndex(i);
248 uint16_t form = AbbrevDecl->getFormByIndex(i);
249
250 if (isCompileUnitTag &&
251 ((attr == DW_AT_entry_pc) || (attr == DW_AT_low_pc))) {
252 DWARFFormValue form_value(form);
253 if (form_value.extractValue(debug_info_data, &offset, cu)) {
254 if (attr == DW_AT_low_pc || attr == DW_AT_entry_pc)
255 const_cast<DWARFCompileUnit*>(cu)
256 ->setBaseAddress(form_value.getUnsigned());
257 }
258 } else {
259 bool form_is_indirect = false;
260 do {
261 form_is_indirect = false;
262 register uint32_t form_size = 0;
263 switch (form) {
264 // Blocks if inlined data that have a length field and the data
265 // bytes // inlined in the .debug_info
Eric Christopher3887a902012-08-24 01:14:23 +0000266 case DW_FORM_exprloc:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000267 case DW_FORM_block:
268 form_size = debug_info_data.getULEB128(&offset);
269 break;
270 case DW_FORM_block1:
271 form_size = debug_info_data.getU8(&offset);
272 break;
273 case DW_FORM_block2:
274 form_size = debug_info_data.getU16(&offset);
275 break;
276 case DW_FORM_block4:
277 form_size = debug_info_data.getU32(&offset);
278 break;
279
280 // Inlined NULL terminated C-strings
281 case DW_FORM_string:
282 debug_info_data.getCStr(&offset);
283 break;
284
285 // Compile unit address sized values
286 case DW_FORM_addr:
287 case DW_FORM_ref_addr:
288 form_size = cu_addr_size;
289 break;
290
Eric Christopher3887a902012-08-24 01:14:23 +0000291 // 0 byte value
292 case DW_FORM_flag_present:
293 form_size = 0;
294 break;
295
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000296 // 1 byte values
297 case DW_FORM_data1:
298 case DW_FORM_flag:
299 case DW_FORM_ref1:
300 form_size = 1;
301 break;
302
303 // 2 byte values
304 case DW_FORM_data2:
305 case DW_FORM_ref2:
306 form_size = 2;
307 break;
308
309 // 4 byte values
310 case DW_FORM_strp:
311 form_size = 4;
312 break;
313
314 case DW_FORM_data4:
315 case DW_FORM_ref4:
316 form_size = 4;
317 break;
318
319 // 8 byte values
320 case DW_FORM_data8:
321 case DW_FORM_ref8:
Eric Christopher3887a902012-08-24 01:14:23 +0000322 case DW_FORM_ref_sig8:
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000323 form_size = 8;
324 break;
325
326 // signed or unsigned LEB 128 values
327 case DW_FORM_sdata:
328 case DW_FORM_udata:
329 case DW_FORM_ref_udata:
330 debug_info_data.getULEB128(&offset);
331 break;
332
333 case DW_FORM_indirect:
334 form = debug_info_data.getULEB128(&offset);
335 form_is_indirect = true;
336 break;
337
Eric Christopher3887a902012-08-24 01:14:23 +0000338 case DW_FORM_sec_offset:
339 if (cu->getAddressByteSize() == 4)
340 debug_info_data.getU32(offset_ptr);
341 else
342 debug_info_data.getU64(offset_ptr);
343 break;
Eric Christopher203e6f62012-10-30 21:36:43 +0000344
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000345 default:
346 *offset_ptr = offset;
347 return false;
348 }
349
350 offset += form_size;
351 } while (form_is_indirect);
352 }
353 }
354 *offset_ptr = offset;
355 return true;
356 }
357 } else {
358 AbbrevDecl = NULL;
359 *offset_ptr = offset;
360 return true; // NULL debug tag entry
361 }
362 }
363
364 return false;
365}
366
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000367bool DWARFDebugInfoEntryMinimal::isSubprogramDIE() const {
368 return getTag() == DW_TAG_subprogram;
369}
370
371bool DWARFDebugInfoEntryMinimal::isSubroutineDIE() const {
372 uint32_t Tag = getTag();
373 return Tag == DW_TAG_subprogram ||
374 Tag == DW_TAG_inlined_subroutine;
375}
376
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000377uint32_t
378DWARFDebugInfoEntryMinimal::getAttributeValue(const DWARFCompileUnit *cu,
379 const uint16_t attr,
380 DWARFFormValue &form_value,
381 uint32_t *end_attr_offset_ptr)
382 const {
383 if (AbbrevDecl) {
384 uint32_t attr_idx = AbbrevDecl->findAttributeIndex(attr);
385
386 if (attr_idx != -1U) {
387 uint32_t offset = getOffset();
388
389 DataExtractor debug_info_data = cu->getDebugInfoExtractor();
390
391 // Skip the abbreviation code so we are at the data for the attributes
392 debug_info_data.getULEB128(&offset);
393
394 uint32_t idx = 0;
395 while (idx < attr_idx)
396 DWARFFormValue::skipValue(AbbrevDecl->getFormByIndex(idx++),
397 debug_info_data, &offset, cu);
398
399 const uint32_t attr_offset = offset;
400 form_value = DWARFFormValue(AbbrevDecl->getFormByIndex(idx));
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +0000401 if (form_value.extractValue(debug_info_data, &offset, cu)) {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000402 if (end_attr_offset_ptr)
403 *end_attr_offset_ptr = offset;
404 return attr_offset;
405 }
406 }
407 }
408
409 return 0;
410}
411
412const char*
413DWARFDebugInfoEntryMinimal::getAttributeValueAsString(
Eric Christopher203e6f62012-10-30 21:36:43 +0000414 const DWARFCompileUnit* cu,
415 const uint16_t attr,
416 const char* fail_value)
417 const {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000418 DWARFFormValue form_value;
419 if (getAttributeValue(cu, attr, form_value)) {
420 DataExtractor stringExtractor(cu->getContext().getStringSection(),
421 false, 0);
422 return form_value.getAsCString(&stringExtractor);
423 }
424 return fail_value;
425}
426
427uint64_t
428DWARFDebugInfoEntryMinimal::getAttributeValueAsUnsigned(
Eric Christopher203e6f62012-10-30 21:36:43 +0000429 const DWARFCompileUnit* cu,
430 const uint16_t attr,
431 uint64_t fail_value) const {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000432 DWARFFormValue form_value;
433 if (getAttributeValue(cu, attr, form_value))
434 return form_value.getUnsigned();
435 return fail_value;
436}
437
438int64_t
439DWARFDebugInfoEntryMinimal::getAttributeValueAsSigned(
Eric Christopher203e6f62012-10-30 21:36:43 +0000440 const DWARFCompileUnit* cu,
441 const uint16_t attr,
442 int64_t fail_value) const {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000443 DWARFFormValue form_value;
444 if (getAttributeValue(cu, attr, form_value))
445 return form_value.getSigned();
446 return fail_value;
447}
448
449uint64_t
Benjamin Kramer10df8062011-09-14 20:52:27 +0000450DWARFDebugInfoEntryMinimal::getAttributeValueAsReference(
Eric Christopher203e6f62012-10-30 21:36:43 +0000451 const DWARFCompileUnit* cu,
452 const uint16_t attr,
453 uint64_t fail_value)
454 const {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000455 DWARFFormValue form_value;
456 if (getAttributeValue(cu, attr, form_value))
457 return form_value.getReference(cu);
458 return fail_value;
459}
Benjamin Kramer10df8062011-09-14 20:52:27 +0000460
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000461bool DWARFDebugInfoEntryMinimal::getLowAndHighPC(const DWARFCompileUnit *CU,
Eric Christopher203e6f62012-10-30 21:36:43 +0000462 uint64_t &LowPC,
463 uint64_t &HighPC) const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000464 HighPC = -1ULL;
465 LowPC = getAttributeValueAsUnsigned(CU, DW_AT_low_pc, -1ULL);
466 if (LowPC != -1ULL)
467 HighPC = getAttributeValueAsUnsigned(CU, DW_AT_high_pc, -1ULL);
468 return (HighPC != -1ULL);
469}
470
Benjamin Kramer10df8062011-09-14 20:52:27 +0000471void
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000472DWARFDebugInfoEntryMinimal::buildAddressRangeTable(const DWARFCompileUnit *CU,
473 DWARFDebugAranges *DebugAranges)
Benjamin Kramer10df8062011-09-14 20:52:27 +0000474 const {
475 if (AbbrevDecl) {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000476 if (isSubprogramDIE()) {
477 uint64_t LowPC, HighPC;
478 if (getLowAndHighPC(CU, LowPC, HighPC)) {
479 DebugAranges->appendRange(CU->getOffset(), LowPC, HighPC);
480 }
481 // FIXME: try to append ranges from .debug_ranges section.
Benjamin Kramer10df8062011-09-14 20:52:27 +0000482 }
483
484 const DWARFDebugInfoEntryMinimal *child = getFirstChild();
485 while (child) {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000486 child->buildAddressRangeTable(CU, DebugAranges);
Benjamin Kramer10df8062011-09-14 20:52:27 +0000487 child = child->getSibling();
488 }
489 }
490}
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000491
492bool
493DWARFDebugInfoEntryMinimal::addressRangeContainsAddress(
Eric Christopher203e6f62012-10-30 21:36:43 +0000494 const DWARFCompileUnit *CU,
495 const uint64_t Address)
496 const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000497 if (isNULL())
498 return false;
499 uint64_t LowPC, HighPC;
500 if (getLowAndHighPC(CU, LowPC, HighPC))
501 return (LowPC <= Address && Address <= HighPC);
502 // Try to get address ranges from .debug_ranges section.
503 uint32_t RangesOffset = getAttributeValueAsReference(CU, DW_AT_ranges, -1U);
504 if (RangesOffset != -1U) {
505 DWARFDebugRangeList RangeList;
506 if (CU->extractRangeList(RangesOffset, RangeList))
507 return RangeList.containsAddress(CU->getBaseAddress(), Address);
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000508 }
509 return false;
510}
511
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000512const char*
Eric Christopher203e6f62012-10-30 21:36:43 +0000513DWARFDebugInfoEntryMinimal::getSubroutineName(const DWARFCompileUnit *CU)
514 const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000515 if (!isSubroutineDIE())
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000516 return 0;
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000517 // Try to get mangled name if possible.
518 if (const char *name =
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000519 getAttributeValueAsString(CU, DW_AT_MIPS_linkage_name, 0))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000520 return name;
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000521 if (const char *name = getAttributeValueAsString(CU, DW_AT_linkage_name, 0))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000522 return name;
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000523 if (const char *name = getAttributeValueAsString(CU, DW_AT_name, 0))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000524 return name;
525 // Try to get name from specification DIE.
526 uint32_t spec_ref =
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000527 getAttributeValueAsReference(CU, DW_AT_specification, -1U);
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000528 if (spec_ref != -1U) {
529 DWARFDebugInfoEntryMinimal spec_die;
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000530 if (spec_die.extract(CU, &spec_ref)) {
531 if (const char *name = spec_die.getSubroutineName(CU))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000532 return name;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000533 }
534 }
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000535 // Try to get name from abstract origin DIE.
536 uint32_t abs_origin_ref =
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000537 getAttributeValueAsReference(CU, DW_AT_abstract_origin, -1U);
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000538 if (abs_origin_ref != -1U) {
539 DWARFDebugInfoEntryMinimal abs_origin_die;
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000540 if (abs_origin_die.extract(CU, &abs_origin_ref)) {
541 if (const char *name = abs_origin_die.getSubroutineName(CU))
Alexey Samsonov9d26b0b2012-07-17 15:28:35 +0000542 return name;
543 }
544 }
545 return 0;
Alexey Samsonov3e25c4a2012-07-02 05:54:45 +0000546}
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000547
Eric Christopher203e6f62012-10-30 21:36:43 +0000548void DWARFDebugInfoEntryMinimal::getCallerFrame(const DWARFCompileUnit *CU,
549 uint32_t &CallFile,
550 uint32_t &CallLine,
551 uint32_t &CallColumn) const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000552 CallFile = getAttributeValueAsUnsigned(CU, DW_AT_call_file, 0);
553 CallLine = getAttributeValueAsUnsigned(CU, DW_AT_call_line, 0);
554 CallColumn = getAttributeValueAsUnsigned(CU, DW_AT_call_column, 0);
555}
556
557DWARFDebugInfoEntryMinimal::InlinedChain
558DWARFDebugInfoEntryMinimal::getInlinedChainForAddress(
Eric Christopher203e6f62012-10-30 21:36:43 +0000559 const DWARFCompileUnit *CU,
560 const uint64_t Address)
561 const {
Alexey Samsonov5eae90d2012-09-04 08:12:33 +0000562 DWARFDebugInfoEntryMinimal::InlinedChain InlinedChain;
563 if (isNULL())
564 return InlinedChain;
565 for (const DWARFDebugInfoEntryMinimal *DIE = this; DIE; ) {
566 // Append current DIE to inlined chain only if it has correct tag
567 // (e.g. it is not a lexical block).
568 if (DIE->isSubroutineDIE()) {
569 InlinedChain.push_back(*DIE);
570 }
571 // Try to get child which also contains provided address.
572 const DWARFDebugInfoEntryMinimal *Child = DIE->getFirstChild();
573 while (Child) {
574 if (Child->addressRangeContainsAddress(CU, Address)) {
575 // Assume there is only one such child.
576 break;
577 }
578 Child = Child->getSibling();
579 }
580 DIE = Child;
581 }
582 // Reverse the obtained chain to make the root of inlined chain last.
583 std::reverse(InlinedChain.begin(), InlinedChain.end());
584 return InlinedChain;
585}