1 //===-- DWARFDebugInfoEntry.cpp ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "DWARFDebugInfoEntry.h"
16 #include "lldb/Core/Module.h"
17 #include "lldb/Core/Stream.h"
18 #include "lldb/Expression/DWARFExpression.h"
19 #include "lldb/Symbol/ObjectFile.h"
21 #include "DWARFCompileUnit.h"
22 #include "SymbolFileDWARF.h"
23 #include "DWARFDebugAbbrev.h"
24 #include "DWARFDebugAranges.h"
25 #include "DWARFDebugInfo.h"
26 #include "DWARFDeclContext.h"
27 #include "DWARFDIECollection.h"
28 #include "DWARFFormValue.h"
29 #include "DWARFLocationDescription.h"
30 #include "DWARFLocationList.h"
31 #include "DWARFDebugRanges.h"
33 using namespace lldb_private;
39 DWARFDebugInfoEntry::Attributes::Attributes() :
44 DWARFDebugInfoEntry::Attributes::~Attributes()
50 DWARFDebugInfoEntry::Attributes::FindAttributeIndex(dw_attr_t attr) const
52 collection::const_iterator end = m_infos.end();
53 collection::const_iterator beg = m_infos.begin();
54 collection::const_iterator pos;
55 for (pos = beg; pos != end; ++pos)
57 if (pos->attr == attr)
58 return std::distance(beg, pos);
64 DWARFDebugInfoEntry::Attributes::Append(const DWARFCompileUnit *cu, dw_offset_t attr_die_offset, dw_attr_t attr, dw_form_t form)
66 Info info = { cu, attr_die_offset, attr, form };
67 m_infos.push_back(info);
71 DWARFDebugInfoEntry::Attributes::ContainsAttribute(dw_attr_t attr) const
73 return FindAttributeIndex(attr) != UINT32_MAX;
77 DWARFDebugInfoEntry::Attributes::RemoveAttribute(dw_attr_t attr)
79 uint32_t attr_index = FindAttributeIndex(attr);
80 if (attr_index != UINT32_MAX)
82 m_infos.erase(m_infos.begin() + attr_index);
89 DWARFDebugInfoEntry::Attributes::ExtractFormValueAtIndex (SymbolFileDWARF* dwarf2Data, uint32_t i, DWARFFormValue &form_value) const
91 form_value.SetForm(FormAtIndex(i));
92 lldb::offset_t offset = DIEOffsetAtIndex(i);
93 return form_value.ExtractValue(dwarf2Data->get_debug_info_data(), &offset, CompileUnitAtIndex(i));
97 DWARFDebugInfoEntry::Attributes::FormValueAsUnsigned (SymbolFileDWARF* dwarf2Data, dw_attr_t attr, uint64_t fail_value) const
99 const uint32_t attr_idx = FindAttributeIndex (attr);
100 if (attr_idx != UINT32_MAX)
101 return FormValueAsUnsignedAtIndex (dwarf2Data, attr_idx, fail_value);
106 DWARFDebugInfoEntry::Attributes::FormValueAsUnsignedAtIndex(SymbolFileDWARF* dwarf2Data, uint32_t i, uint64_t fail_value) const
108 DWARFFormValue form_value;
109 if (ExtractFormValueAtIndex(dwarf2Data, i, form_value))
110 return form_value.Reference(CompileUnitAtIndex(i));
117 DWARFDebugInfoEntry::FastExtract
119 const DataExtractor& debug_info_data,
120 const DWARFCompileUnit* cu,
121 const uint8_t *fixed_form_sizes,
122 lldb::offset_t *offset_ptr
125 m_offset = *offset_ptr;
128 m_empty_children = false;
129 const uint64_t abbr_idx = debug_info_data.GetULEB128 (offset_ptr);
130 assert (abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
131 m_abbr_idx = abbr_idx;
133 //assert (fixed_form_sizes); // For best performance this should be specified!
137 lldb::offset_t offset = *offset_ptr;
139 const DWARFAbbreviationDeclaration *abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration(m_abbr_idx);
141 if (abbrevDecl == NULL)
143 cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: invalid abbreviation code %u, please file a bug and attach the file at the start of this error message",
146 // WE can't parse anymore if the DWARF is borked...
147 *offset_ptr = UINT32_MAX;
150 m_tag = abbrevDecl->Tag();
151 m_has_children = abbrevDecl->HasChildren();
152 // Skip all data in the .debug_info for the attributes
153 const uint32_t numAttributes = abbrevDecl->NumAttributes();
155 register dw_form_t form;
156 for (i=0; i<numAttributes; ++i)
158 form = abbrevDecl->GetFormByIndexUnchecked(i);
160 const uint8_t fixed_skip_size = fixed_form_sizes [form];
162 offset += fixed_skip_size;
165 bool form_is_indirect = false;
168 form_is_indirect = false;
169 register uint32_t form_size = 0;
172 // Blocks if inlined data that have a length field and the data bytes
173 // inlined in the .debug_info
174 case DW_FORM_exprloc :
175 case DW_FORM_block : form_size = debug_info_data.GetULEB128 (&offset); break;
176 case DW_FORM_block1 : form_size = debug_info_data.GetU8_unchecked (&offset); break;
177 case DW_FORM_block2 : form_size = debug_info_data.GetU16_unchecked (&offset);break;
178 case DW_FORM_block4 : form_size = debug_info_data.GetU32_unchecked (&offset);break;
180 // Inlined NULL terminated C-strings
181 case DW_FORM_string :
182 debug_info_data.GetCStr (&offset);
185 // Compile unit address sized values
187 form_size = cu->GetAddressByteSize();
189 case DW_FORM_ref_addr :
190 if (cu->GetVersion() <= 2)
191 form_size = cu->GetAddressByteSize();
193 form_size = 4; // 4 bytes for DWARF 32, 8 bytes for DWARF 64, but we don't support DWARF64 yet
197 case DW_FORM_flag_present:
224 case DW_FORM_ref_sig8 :
228 // signed or unsigned LEB 128 values
231 case DW_FORM_ref_udata :
232 debug_info_data.Skip_LEB128 (&offset);
235 case DW_FORM_indirect :
236 form_is_indirect = true;
237 form = debug_info_data.GetULEB128 (&offset);
240 case DW_FORM_sec_offset :
241 if (cu->GetAddressByteSize () == 4)
242 debug_info_data.GetU32 (offset_ptr);
244 debug_info_data.GetU64 (offset_ptr);
248 *offset_ptr = m_offset;
253 } while (form_is_indirect);
256 *offset_ptr = offset;
262 m_has_children = false;
263 return true; // NULL debug tag entry
269 //----------------------------------------------------------------------
272 // Extract a debug info entry for a given compile unit from the
273 // .debug_info and .debug_abbrev data within the SymbolFileDWARF class
274 // starting at the given offset
275 //----------------------------------------------------------------------
277 DWARFDebugInfoEntry::Extract
279 SymbolFileDWARF* dwarf2Data,
280 const DWARFCompileUnit* cu,
281 lldb::offset_t *offset_ptr
284 const DataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
285 // const DataExtractor& debug_str_data = dwarf2Data->get_debug_str_data();
286 const uint32_t cu_end_offset = cu->GetNextCompileUnitOffset();
287 const uint8_t cu_addr_size = cu->GetAddressByteSize();
288 lldb::offset_t offset = *offset_ptr;
289 // if (offset >= cu_end_offset)
290 // Log::Error("DIE at offset 0x%8.8x is beyond the end of the current compile unit (0x%8.8x)", m_offset, cu_end_offset);
291 if ((offset < cu_end_offset) && debug_info_data.ValidOffset(offset))
295 const uint64_t abbr_idx = debug_info_data.GetULEB128(&offset);
296 assert (abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
297 m_abbr_idx = abbr_idx;
300 const DWARFAbbreviationDeclaration *abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration(abbr_idx);
304 m_tag = abbrevDecl->Tag();
305 m_has_children = abbrevDecl->HasChildren();
307 bool isCompileUnitTag = m_tag == DW_TAG_compile_unit;
308 if (cu && isCompileUnitTag)
309 ((DWARFCompileUnit*)cu)->SetBaseAddress(0);
311 // Skip all data in the .debug_info for the attributes
312 const uint32_t numAttributes = abbrevDecl->NumAttributes();
316 for (i=0; i<numAttributes; ++i)
318 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
320 if (isCompileUnitTag && ((attr == DW_AT_entry_pc) || (attr == DW_AT_low_pc)))
322 DWARFFormValue form_value(form);
323 if (form_value.ExtractValue(debug_info_data, &offset, cu))
325 if (attr == DW_AT_low_pc || attr == DW_AT_entry_pc)
326 ((DWARFCompileUnit*)cu)->SetBaseAddress(form_value.Unsigned());
331 bool form_is_indirect = false;
334 form_is_indirect = false;
335 register uint32_t form_size = 0;
338 // Blocks if inlined data that have a length field and the data bytes
339 // inlined in the .debug_info
340 case DW_FORM_exprloc :
341 case DW_FORM_block : form_size = debug_info_data.GetULEB128(&offset); break;
342 case DW_FORM_block1 : form_size = debug_info_data.GetU8(&offset); break;
343 case DW_FORM_block2 : form_size = debug_info_data.GetU16(&offset); break;
344 case DW_FORM_block4 : form_size = debug_info_data.GetU32(&offset); break;
346 // Inlined NULL terminated C-strings
347 case DW_FORM_string : debug_info_data.GetCStr(&offset); break;
349 // Compile unit address sized values
351 form_size = cu_addr_size;
353 case DW_FORM_ref_addr :
354 if (cu->GetVersion() <= 2)
355 form_size = cu_addr_size;
357 form_size = 4; // 4 bytes for DWARF 32, 8 bytes for DWARF 64, but we don't support DWARF64 yet
361 case DW_FORM_flag_present:
391 case DW_FORM_ref_sig8 :
395 // signed or unsigned LEB 128 values
398 case DW_FORM_ref_udata :
399 debug_info_data.Skip_LEB128(&offset);
402 case DW_FORM_indirect :
403 form = debug_info_data.GetULEB128(&offset);
404 form_is_indirect = true;
407 case DW_FORM_sec_offset :
408 if (cu->GetAddressByteSize () == 4)
409 debug_info_data.GetU32 (offset_ptr);
411 debug_info_data.GetU64 (offset_ptr);
415 *offset_ptr = offset;
420 } while (form_is_indirect);
423 *offset_ptr = offset;
430 m_has_children = false;
431 *offset_ptr = offset;
432 return true; // NULL debug tag entry
439 //----------------------------------------------------------------------
442 // Dumps all of a debug information entries parents up until oldest and
443 // all of it's attributes to the specified stream.
444 //----------------------------------------------------------------------
446 DWARFDebugInfoEntry::DumpAncestry
448 SymbolFileDWARF* dwarf2Data,
449 const DWARFCompileUnit* cu,
450 const DWARFDebugInfoEntry* oldest,
452 uint32_t recurse_depth
455 const DWARFDebugInfoEntry* parent = GetParent();
456 if (parent && parent != oldest)
457 parent->DumpAncestry(dwarf2Data, cu, oldest, s, 0);
458 Dump(dwarf2Data, cu, s, recurse_depth);
461 //----------------------------------------------------------------------
462 // Compare two DIE by comparing all their attributes values, and
463 // following all DW_FORM_ref attributes and comparing their contents as
464 // well (except for DW_AT_sibling attributes.
466 // DWARFDebugInfoEntry::CompareState compare_state;
467 // int result = DWARFDebugInfoEntry::Compare(this, 0x00017ccb, 0x0001eb2b, compare_state, false, true);
468 //----------------------------------------------------------------------
470 //DWARFDebugInfoEntry::Compare
472 // SymbolFileDWARF* dwarf2Data,
473 // dw_offset_t a_die_offset,
474 // dw_offset_t b_die_offset,
475 // CompareState &compare_state,
476 // bool compare_siblings,
477 // bool compare_children
480 // if (a_die_offset == b_die_offset)
483 // DWARFCompileUnitSP a_cu_sp;
484 // DWARFCompileUnitSP b_cu_sp;
485 // const DWARFDebugInfoEntry* a_die = dwarf2Data->DebugInfo()->GetDIEPtr(a_die_offset, &a_cu_sp);
486 // const DWARFDebugInfoEntry* b_die = dwarf2Data->DebugInfo()->GetDIEPtr(b_die_offset, &b_cu_sp);
488 // return Compare(dwarf2Data, a_cu_sp.get(), a_die, b_cu_sp.get(), b_die, compare_state, compare_siblings, compare_children);
492 //DWARFDebugInfoEntry::Compare
494 // SymbolFileDWARF* dwarf2Data,
495 // DWARFCompileUnit* a_cu, const DWARFDebugInfoEntry* a_die,
496 // DWARFCompileUnit* b_cu, const DWARFDebugInfoEntry* b_die,
497 // CompareState &compare_state,
498 // bool compare_siblings,
499 // bool compare_children
502 // if (a_die == b_die)
505 // if (!compare_state.AddTypePair(a_die->GetOffset(), b_die->GetOffset()))
507 // // We are already comparing both of these types, so let
508 // // compares complete for the real result
512 // //printf("DWARFDebugInfoEntry::Compare(0x%8.8x, 0x%8.8x)\n", a_die->GetOffset(), b_die->GetOffset());
514 // // Do we have two valid DIEs?
515 // if (a_die && b_die)
517 // // Both DIE are valid
520 // const dw_tag_t a_tag = a_die->Tag();
521 // const dw_tag_t b_tag = b_die->Tag();
522 // if (a_tag == 0 && b_tag == 0)
525 // //printf(" comparing tags: %s and %s\n", DW_TAG_value_to_name(a_tag), DW_TAG_value_to_name(b_tag));
527 // if (a_tag < b_tag)
529 // else if (a_tag > b_tag)
532 // DWARFDebugInfoEntry::Attributes a_attrs;
533 // DWARFDebugInfoEntry::Attributes b_attrs;
534 // size_t a_attr_count = a_die->GetAttributes(dwarf2Data, a_cu, a_attrs);
535 // size_t b_attr_count = b_die->GetAttributes(dwarf2Data, b_cu, b_attrs);
536 // if (a_attr_count != b_attr_count)
538 // a_attrs.RemoveAttribute(DW_AT_sibling);
539 // b_attrs.RemoveAttribute(DW_AT_sibling);
542 // a_attr_count = a_attrs.Size();
543 // b_attr_count = b_attrs.Size();
545 // DWARFFormValue a_form_value;
546 // DWARFFormValue b_form_value;
548 // if (a_attr_count != b_attr_count)
550 // uint32_t is_decl_index = a_attrs.FindAttributeIndex(DW_AT_declaration);
551 // uint32_t a_name_index = UINT32_MAX;
552 // uint32_t b_name_index = UINT32_MAX;
553 // if (is_decl_index != UINT32_MAX)
555 // if (a_attr_count == 2)
557 // a_name_index = a_attrs.FindAttributeIndex(DW_AT_name);
558 // b_name_index = b_attrs.FindAttributeIndex(DW_AT_name);
563 // is_decl_index = b_attrs.FindAttributeIndex(DW_AT_declaration);
564 // if (is_decl_index != UINT32_MAX && a_attr_count == 2)
566 // a_name_index = a_attrs.FindAttributeIndex(DW_AT_name);
567 // b_name_index = b_attrs.FindAttributeIndex(DW_AT_name);
570 // if (a_name_index != UINT32_MAX && b_name_index != UINT32_MAX)
572 // if (a_attrs.ExtractFormValueAtIndex(dwarf2Data, a_name_index, a_form_value) &&
573 // b_attrs.ExtractFormValueAtIndex(dwarf2Data, b_name_index, b_form_value))
575 // result = DWARFFormValue::Compare (a_form_value, b_form_value, a_cu, b_cu, &dwarf2Data->get_debug_str_data());
578 // a_attr_count = b_attr_count = 0;
579 // compare_children = false;
585 // if (a_attr_count < b_attr_count)
587 // if (a_attr_count > b_attr_count)
591 // // The number of attributes are the same...
592 // if (a_attr_count > 0)
594 // const DataExtractor* debug_str_data_ptr = &dwarf2Data->get_debug_str_data();
597 // for (i=0; i<a_attr_count; ++i)
599 // const dw_attr_t a_attr = a_attrs.AttributeAtIndex(i);
600 // const dw_attr_t b_attr = b_attrs.AttributeAtIndex(i);
601 // //printf(" comparing attributes\n\t\t0x%8.8x: %s %s\t\t0x%8.8x: %s %s\n",
602 // // a_attrs.DIEOffsetAtIndex(i), DW_FORM_value_to_name(a_attrs.FormAtIndex(i)), DW_AT_value_to_name(a_attr),
603 // // b_attrs.DIEOffsetAtIndex(i), DW_FORM_value_to_name(b_attrs.FormAtIndex(i)), DW_AT_value_to_name(b_attr));
605 // if (a_attr < b_attr)
607 // else if (a_attr > b_attr)
612 // // Since we call a form of GetAttributes which inlines the
613 // // attributes from DW_AT_abstract_origin and DW_AT_specification
614 // // we don't care if their values mismatch...
615 // case DW_AT_abstract_origin:
616 // case DW_AT_specification:
617 // case DW_AT_sibling:
618 // case DW_AT_containing_type:
619 // //printf(" action = IGNORE\n");
624 // if (a_attrs.ExtractFormValueAtIndex(dwarf2Data, i, a_form_value) &&
625 // b_attrs.ExtractFormValueAtIndex(dwarf2Data, i, b_form_value))
626 // result = DWARFFormValue::Compare (a_form_value, b_form_value, a_cu, b_cu, debug_str_data_ptr);
630 // //printf("\t result = %i\n", result);
634 // // Attributes weren't equal, lets see if we care?
637 // case DW_AT_decl_file:
638 // // TODO: add the ability to compare files in two different compile units
641 // //printf(" action = RETURN RESULT\n");
642 // return result; // Only return the compare results when the compile units are the same and the decl_file attributes can be compared
647 // //printf(" action = IGNORE\n");
652 // switch (a_attrs.FormAtIndex(i))
654 // case DW_FORM_ref1:
655 // case DW_FORM_ref2:
656 // case DW_FORM_ref4:
657 // case DW_FORM_ref8:
658 // case DW_FORM_ref_udata:
659 // case DW_FORM_ref_addr:
660 // //printf(" action = COMPARE DIEs 0x%8.8x 0x%8.8x\n", (dw_offset_t)a_form_value.Reference(a_cu), (dw_offset_t)b_form_value.Reference(b_cu));
661 // // These attribute values refer to other DIEs, so lets compare those instead of their DIE offsets...
662 // result = Compare(dwarf2Data, a_form_value.Reference(a_cu), b_form_value.Reference(b_cu), compare_state, false, true);
668 // // We do care that they were different, return this result...
669 // //printf(" action = RETURN RESULT\n");
676 // //printf(" SUCCESS\n\t\t0x%8.8x: %s\n\t\t0x%8.8x: %s\n", a_die->GetOffset(), DW_TAG_value_to_name(a_tag), b_die->GetOffset(), DW_TAG_value_to_name(b_tag));
678 // if (compare_children)
680 // bool a_has_children = a_die->HasChildren();
681 // bool b_has_children = b_die->HasChildren();
682 // if (a_has_children == b_has_children)
684 // // Both either have kids or don't
685 // if (a_has_children)
686 // result = Compare( dwarf2Data,
687 // a_cu, a_die->GetFirstChild(),
688 // b_cu, b_die->GetFirstChild(),
689 // compare_state, true, compare_children);
693 // else if (!a_has_children)
694 // result = -1; // A doesn't have kids, but B does
696 // result = 1; // A has kids, but B doesn't
699 // if (compare_siblings)
701 // result = Compare( dwarf2Data,
702 // a_cu, a_die->GetSibling(),
703 // b_cu, b_die->GetSibling(),
704 // compare_state, true, compare_children);
710 // if (a_die == NULL)
711 // return -1; // a_die is NULL, yet b_die is non-NULL
713 // return 1; // a_die is non-NULL, yet b_die is NULL
719 //DWARFDebugInfoEntry::Compare
721 // SymbolFileDWARF* dwarf2Data,
722 // const DWARFCompileUnit* cu_a,
723 // const DWARFDebugInfoEntry* die_a,
724 // const DWARFCompileUnit* cu_a,
725 // const DWARFDebugInfoEntry* die_b,
726 // CompareState &compare_state
731 //----------------------------------------------------------------------
732 // GetDIENamesAndRanges
734 // Gets the valid address ranges for a given DIE by looking for a
735 // DW_AT_low_pc/DW_AT_high_pc pair, DW_AT_entry_pc, or DW_AT_ranges
737 //----------------------------------------------------------------------
739 DWARFDebugInfoEntry::GetDIENamesAndRanges
741 SymbolFileDWARF* dwarf2Data,
742 const DWARFCompileUnit* cu,
744 const char * &mangled,
745 DWARFDebugRanges::RangeList& ranges,
752 DWARFExpression *frame_base
755 if (dwarf2Data == NULL)
758 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
759 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
760 std::vector<dw_offset_t> die_offsets;
761 bool set_frame_base_loclist_addr = false;
763 lldb::offset_t offset;
764 const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
768 const DataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
770 if (!debug_info_data.ValidOffset(offset))
773 const uint32_t numAttributes = abbrevDecl->NumAttributes();
777 bool do_offset = false;
779 for (i=0; i<numAttributes; ++i)
781 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
782 DWARFFormValue form_value(form);
783 if (form_value.ExtractValue(debug_info_data, &offset, cu))
788 lo_pc = form_value.Unsigned();
796 lo_pc = form_value.Unsigned();
800 hi_pc = form_value.Unsigned();
801 if (form_value.Form() != DW_FORM_addr)
803 if (lo_pc == LLDB_INVALID_ADDRESS)
804 do_offset = hi_pc != LLDB_INVALID_ADDRESS;
806 hi_pc += lo_pc; // DWARF 4 introduces <offset-from-lo-pc> to save on relocations
812 const DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
813 debug_ranges->FindRanges(form_value.Unsigned(), ranges);
814 // All DW_AT_ranges are relative to the base address of the
815 // compile unit. We add the compile unit base address to make
816 // sure all the addresses are properly fixed up.
817 ranges.Slide(cu->GetBaseAddress());
823 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
826 case DW_AT_MIPS_linkage_name:
827 case DW_AT_linkage_name:
829 mangled = form_value.AsCString(&dwarf2Data->get_debug_str_data());
832 case DW_AT_abstract_origin:
833 die_offsets.push_back(form_value.Reference(cu));
836 case DW_AT_specification:
837 die_offsets.push_back(form_value.Reference(cu));
840 case DW_AT_decl_file:
842 decl_file = form_value.Unsigned();
845 case DW_AT_decl_line:
847 decl_line = form_value.Unsigned();
850 case DW_AT_decl_column:
851 if (decl_column == 0)
852 decl_column = form_value.Unsigned();
855 case DW_AT_call_file:
857 call_file = form_value.Unsigned();
860 case DW_AT_call_line:
862 call_line = form_value.Unsigned();
865 case DW_AT_call_column:
866 if (call_column == 0)
867 call_column = form_value.Unsigned();
870 case DW_AT_frame_base:
873 if (form_value.BlockData())
875 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
876 uint32_t block_length = form_value.Unsigned();
877 frame_base->SetOpcodeData(debug_info_data, block_offset, block_length);
881 const DataExtractor &debug_loc_data = dwarf2Data->get_debug_loc_data();
882 const dw_offset_t debug_loc_offset = form_value.Unsigned();
884 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
885 if (loc_list_length > 0)
887 frame_base->SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
888 if (lo_pc != LLDB_INVALID_ADDRESS)
890 assert (lo_pc >= cu->GetBaseAddress());
891 frame_base->SetLocationListSlide(lo_pc - cu->GetBaseAddress());
895 set_frame_base_loclist_addr = true;
909 if (ranges.IsEmpty())
911 if (lo_pc != LLDB_INVALID_ADDRESS)
913 if (hi_pc != LLDB_INVALID_ADDRESS && hi_pc > lo_pc)
914 ranges.Append(DWARFDebugRanges::Range (lo_pc, hi_pc - lo_pc));
916 ranges.Append(DWARFDebugRanges::Range (lo_pc, 0));
920 if (set_frame_base_loclist_addr)
922 dw_addr_t lowest_range_pc = ranges.GetMinRangeBase(0);
923 assert (lowest_range_pc >= cu->GetBaseAddress());
924 frame_base->SetLocationListSlide (lowest_range_pc - cu->GetBaseAddress());
927 if (ranges.IsEmpty() || name == NULL || mangled == NULL)
929 std::vector<dw_offset_t>::const_iterator pos;
930 std::vector<dw_offset_t>::const_iterator end = die_offsets.end();
931 for (pos = die_offsets.begin(); pos != end; ++pos)
933 DWARFCompileUnitSP cu_sp_ptr;
934 const DWARFDebugInfoEntry* die = NULL;
935 dw_offset_t die_offset = *pos;
936 if (die_offset != DW_INVALID_OFFSET)
938 die = dwarf2Data->DebugInfo()->GetDIEPtr(die_offset, &cu_sp_ptr);
940 die->GetDIENamesAndRanges(dwarf2Data, cu_sp_ptr.get(), name, mangled, ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column);
944 return !ranges.IsEmpty();
947 //----------------------------------------------------------------------
950 // Dumps a debug information entry and all of it's attributes to the
952 //----------------------------------------------------------------------
954 DWARFDebugInfoEntry::Dump
956 SymbolFileDWARF* dwarf2Data,
957 const DWARFCompileUnit* cu,
959 uint32_t recurse_depth
962 const DataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
963 lldb::offset_t offset = m_offset;
965 if (debug_info_data.ValidOffset(offset))
967 dw_uleb128_t abbrCode = debug_info_data.GetULEB128(&offset);
969 s.Printf("\n0x%8.8x: ", m_offset);
971 if (abbrCode != m_abbr_idx)
973 s.Printf( "error: DWARF has been modified\n");
977 const DWARFAbbreviationDeclaration* abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration (abbrCode);
981 s.PutCString(DW_TAG_value_to_name(abbrevDecl->Tag()));
982 s.Printf( " [%u] %c\n", abbrCode, abbrevDecl->HasChildren() ? '*':' ');
984 // Dump all data in the .debug_info for the attributes
985 const uint32_t numAttributes = abbrevDecl->NumAttributes();
989 for (i=0; i<numAttributes; ++i)
991 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
993 DumpAttribute(dwarf2Data, cu, debug_info_data, &offset, s, attr, form);
996 const DWARFDebugInfoEntry* child = GetFirstChild();
997 if (recurse_depth > 0 && child)
1003 child->Dump(dwarf2Data, cu, s, recurse_depth-1);
1004 child = child->GetSibling();
1010 s.Printf( "Abbreviation code note found in 'debug_abbrev' class for code: %u\n", abbrCode);
1014 s.Printf( "NULL\n");
1020 DWARFDebugInfoEntry::DumpLocation
1022 SymbolFileDWARF* dwarf2Data,
1023 DWARFCompileUnit* cu,
1027 const DWARFDebugInfoEntry *cu_die = cu->GetCompileUnitDIEOnly();
1028 const char *cu_name = NULL;
1030 cu_name = cu_die->GetName (dwarf2Data, cu);
1031 const char *obj_file_name = NULL;
1032 ObjectFile *obj_file = dwarf2Data->GetObjectFile();
1034 obj_file_name = obj_file->GetFileSpec().GetFilename().AsCString();
1035 const char *die_name = GetName (dwarf2Data, cu);
1036 s.Printf ("0x%8.8x/0x%8.8x: %-30s (from %s in %s)",
1039 die_name ? die_name : "",
1040 cu_name ? cu_name : "<NULL>",
1041 obj_file_name ? obj_file_name : "<NULL>");
1044 //----------------------------------------------------------------------
1047 // Dumps a debug information entry attribute along with it's form. Any
1048 // special display of attributes is done (disassemble location lists,
1049 // show enumeration values for attributes, etc).
1050 //----------------------------------------------------------------------
1052 DWARFDebugInfoEntry::DumpAttribute
1054 SymbolFileDWARF* dwarf2Data,
1055 const DWARFCompileUnit* cu,
1056 const DataExtractor& debug_info_data,
1057 lldb::offset_t *offset_ptr,
1063 bool verbose = s.GetVerbose();
1064 bool show_form = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm);
1066 const DataExtractor* debug_str_data = dwarf2Data ? &dwarf2Data->get_debug_str_data() : NULL;
1068 s.Offset (*offset_ptr);
1071 s.Indent(DW_AT_value_to_name(attr));
1075 s.Printf( "[%s", DW_FORM_value_to_name(form));
1078 DWARFFormValue form_value(form);
1080 if (!form_value.ExtractValue(debug_info_data, offset_ptr, cu))
1085 if (form == DW_FORM_indirect)
1087 s.Printf( " [%s]", DW_FORM_value_to_name(form_value.Form()));
1095 // Always dump form value if verbose is enabled
1098 form_value.Dump(s, debug_str_data, cu);
1102 // Check to see if we have any special attribute formatters
1105 case DW_AT_stmt_list:
1106 if ( verbose ) s.PutCString(" ( ");
1107 s.Printf( "0x%8.8" PRIx64, form_value.Unsigned());
1108 if ( verbose ) s.PutCString(" )");
1111 case DW_AT_language:
1112 if ( verbose ) s.PutCString(" ( ");
1113 s.PutCString(DW_LANG_value_to_name(form_value.Unsigned()));
1114 if ( verbose ) s.PutCString(" )");
1117 case DW_AT_encoding:
1118 if ( verbose ) s.PutCString(" ( ");
1119 s.PutCString(DW_ATE_value_to_name(form_value.Unsigned()));
1120 if ( verbose ) s.PutCString(" )");
1123 case DW_AT_frame_base:
1124 case DW_AT_location:
1125 case DW_AT_data_member_location:
1127 const uint8_t* blockData = form_value.BlockData();
1131 form_value.Dump(s, debug_str_data, cu);
1133 // Location description is inlined in data in the form value
1134 DataExtractor locationData(debug_info_data, (*offset_ptr) - form_value.Unsigned(), form_value.Unsigned());
1135 if ( verbose ) s.PutCString(" ( ");
1136 print_dwarf_expression (s, locationData, DWARFCompileUnit::GetAddressByteSize(cu), 4, false);
1137 if ( verbose ) s.PutCString(" )");
1141 // We have a location list offset as the value that is
1142 // the offset into the .debug_loc section that describes
1143 // the value over it's lifetime
1144 uint64_t debug_loc_offset = form_value.Unsigned();
1148 form_value.Dump(s, debug_str_data, cu);
1149 DWARFLocationList::Dump(s, cu, dwarf2Data->get_debug_loc_data(), debug_loc_offset);
1154 form_value.Dump(s, NULL, cu);
1160 case DW_AT_abstract_origin:
1161 case DW_AT_specification:
1163 uint64_t abstract_die_offset = form_value.Reference(cu);
1164 form_value.Dump(s, debug_str_data, cu);
1165 // *ostrm_ptr << HEX32 << abstract_die_offset << " ( ";
1166 if ( verbose ) s.PutCString(" ( ");
1167 GetName(dwarf2Data, cu, abstract_die_offset, s);
1168 if ( verbose ) s.PutCString(" )");
1174 uint64_t type_die_offset = form_value.Reference(cu);
1176 form_value.Dump(s, debug_str_data, cu);
1177 s.PutCString(" ( ");
1178 AppendTypeName(dwarf2Data, cu, type_die_offset, s);
1186 form_value.Dump(s, debug_str_data, cu);
1187 lldb::offset_t ranges_offset = form_value.Unsigned();
1188 dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0;
1190 DWARFDebugRanges::Dump(s, dwarf2Data->get_debug_ranges_data(), &ranges_offset, base_addr);
1196 form_value.Dump(s, debug_str_data, cu);
1200 s.PutCString(" )\n");
1203 //----------------------------------------------------------------------
1204 // Get all attribute values for a given DIE, including following any
1205 // specification or abstract origin attributes and including those in
1206 // the results. Any duplicate attributes will have the first instance
1207 // take precedence (this can happen for declaration attributes).
1208 //----------------------------------------------------------------------
1210 DWARFDebugInfoEntry::GetAttributes
1212 SymbolFileDWARF* dwarf2Data,
1213 const DWARFCompileUnit* cu,
1214 const uint8_t *fixed_form_sizes,
1215 DWARFDebugInfoEntry::Attributes& attributes,
1219 lldb::offset_t offset;
1220 const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1224 const DataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
1226 if (fixed_form_sizes == NULL)
1227 fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(cu->GetAddressByteSize());
1229 const uint32_t num_attributes = abbrevDecl->NumAttributes();
1233 DWARFFormValue form_value;
1234 for (i=0; i<num_attributes; ++i)
1236 abbrevDecl->GetAttrAndFormByIndexUnchecked (i, attr, form);
1238 // If we are tracking down DW_AT_specification or DW_AT_abstract_origin
1239 // attributes, the depth will be non-zero. We need to omit certain
1240 // attributes that don't make sense.
1244 case DW_AT_declaration:
1247 // This attribute doesn't make sense when combined with
1248 // the DIE that references this DIE. We know a DIE is
1249 // referencing this DIE because curr_depth is not zero
1254 attributes.Append(cu, offset, attr, form);
1258 if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin))
1260 form_value.SetForm(form);
1261 if (form_value.ExtractValue(debug_info_data, &offset, cu))
1263 const DWARFDebugInfoEntry* die = NULL;
1264 dw_offset_t die_offset = form_value.Reference(cu);
1265 if (cu->ContainsDIEOffset(die_offset))
1267 die = const_cast<DWARFCompileUnit*>(cu)->GetDIEPtr(die_offset);
1269 die->GetAttributes(dwarf2Data, cu, fixed_form_sizes, attributes, curr_depth + 1);
1273 DWARFCompileUnitSP cu_sp_ptr;
1274 die = const_cast<SymbolFileDWARF*>(dwarf2Data)->DebugInfo()->GetDIEPtr(die_offset, &cu_sp_ptr);
1276 die->GetAttributes(dwarf2Data, cu_sp_ptr.get(), fixed_form_sizes, attributes, curr_depth + 1);
1282 const uint8_t fixed_skip_size = fixed_form_sizes [form];
1283 if (fixed_skip_size)
1284 offset += fixed_skip_size;
1286 DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
1294 return attributes.Size();
1298 //----------------------------------------------------------------------
1299 // GetAttributeValue
1301 // Get the value of an attribute and return the .debug_info offset of the
1302 // attribute if it was properly extracted into form_value, or zero
1303 // if we fail since an offset of zero is invalid for an attribute (it
1304 // would be a compile unit header).
1305 //----------------------------------------------------------------------
1307 DWARFDebugInfoEntry::GetAttributeValue
1309 SymbolFileDWARF* dwarf2Data,
1310 const DWARFCompileUnit* cu,
1311 const dw_attr_t attr,
1312 DWARFFormValue& form_value,
1313 dw_offset_t* end_attr_offset_ptr
1316 lldb::offset_t offset;
1317 const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1321 uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
1323 if (attr_idx != DW_INVALID_INDEX)
1325 const DataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
1328 while (idx<attr_idx)
1329 DWARFFormValue::SkipValue(abbrevDecl->GetFormByIndex(idx++), debug_info_data, &offset, cu);
1331 const dw_offset_t attr_offset = offset;
1332 form_value.SetForm(abbrevDecl->GetFormByIndex(idx));
1333 if (form_value.ExtractValue(debug_info_data, &offset, cu))
1335 if (end_attr_offset_ptr)
1336 *end_attr_offset_ptr = offset;
1345 //----------------------------------------------------------------------
1346 // GetAttributeValueAsString
1348 // Get the value of an attribute as a string return it. The resulting
1349 // pointer to the string data exists within the supplied SymbolFileDWARF
1350 // and will only be available as long as the SymbolFileDWARF is still around
1351 // and it's content doesn't change.
1352 //----------------------------------------------------------------------
1354 DWARFDebugInfoEntry::GetAttributeValueAsString
1356 SymbolFileDWARF* dwarf2Data,
1357 const DWARFCompileUnit* cu,
1358 const dw_attr_t attr,
1359 const char* fail_value) const
1361 DWARFFormValue form_value;
1362 if (GetAttributeValue(dwarf2Data, cu, attr, form_value))
1363 return form_value.AsCString(&dwarf2Data->get_debug_str_data());
1367 //----------------------------------------------------------------------
1368 // GetAttributeValueAsUnsigned
1370 // Get the value of an attribute as unsigned and return it.
1371 //----------------------------------------------------------------------
1373 DWARFDebugInfoEntry::GetAttributeValueAsUnsigned
1375 SymbolFileDWARF* dwarf2Data,
1376 const DWARFCompileUnit* cu,
1377 const dw_attr_t attr,
1381 DWARFFormValue form_value;
1382 if (GetAttributeValue(dwarf2Data, cu, attr, form_value))
1383 return form_value.Unsigned();
1387 //----------------------------------------------------------------------
1388 // GetAttributeValueAsSigned
1390 // Get the value of an attribute a signed value and return it.
1391 //----------------------------------------------------------------------
1393 DWARFDebugInfoEntry::GetAttributeValueAsSigned
1395 SymbolFileDWARF* dwarf2Data,
1396 const DWARFCompileUnit* cu,
1397 const dw_attr_t attr,
1401 DWARFFormValue form_value;
1402 if (GetAttributeValue(dwarf2Data, cu, attr, form_value))
1403 return form_value.Signed();
1407 //----------------------------------------------------------------------
1408 // GetAttributeValueAsReference
1410 // Get the value of an attribute as reference and fix up and compile
1411 // unit relative offsets as needed.
1412 //----------------------------------------------------------------------
1414 DWARFDebugInfoEntry::GetAttributeValueAsReference
1416 SymbolFileDWARF* dwarf2Data,
1417 const DWARFCompileUnit* cu,
1418 const dw_attr_t attr,
1422 DWARFFormValue form_value;
1423 if (GetAttributeValue(dwarf2Data, cu, attr, form_value))
1424 return form_value.Reference(cu);
1428 //----------------------------------------------------------------------
1429 // GetAttributeHighPC
1431 // Get the hi_pc, adding hi_pc to lo_pc when specified
1432 // as an <offset-from-low-pc>.
1434 // Returns the hi_pc or fail_value.
1435 //----------------------------------------------------------------------
1437 DWARFDebugInfoEntry::GetAttributeHighPC
1439 SymbolFileDWARF* dwarf2Data,
1440 const DWARFCompileUnit* cu,
1445 DWARFFormValue form_value;
1447 if (GetAttributeValue(dwarf2Data, cu, DW_AT_high_pc, form_value))
1449 dw_addr_t hi_pc = form_value.Unsigned();
1450 if (form_value.Form() != DW_FORM_addr)
1451 hi_pc += lo_pc; // DWARF4 can specify the hi_pc as an <offset-from-lowpc>
1457 //----------------------------------------------------------------------
1458 // GetAttributeAddressRange
1460 // Get the lo_pc and hi_pc, adding hi_pc to lo_pc when specified
1461 // as an <offset-from-low-pc>.
1463 // Returns true or sets lo_pc and hi_pc to fail_value.
1464 //----------------------------------------------------------------------
1466 DWARFDebugInfoEntry::GetAttributeAddressRange
1468 SymbolFileDWARF* dwarf2Data,
1469 const DWARFCompileUnit* cu,
1475 lo_pc = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_low_pc, fail_value);
1476 if (lo_pc != fail_value)
1478 hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, fail_value);
1479 if (hi_pc != fail_value)
1486 //----------------------------------------------------------------------
1487 // GetAttributeValueAsLocation
1489 // Get the value of an attribute as reference and fix up and compile
1490 // unit relative offsets as needed.
1491 //----------------------------------------------------------------------
1493 DWARFDebugInfoEntry::GetAttributeValueAsLocation
1495 SymbolFileDWARF* dwarf2Data,
1496 const DWARFCompileUnit* cu,
1497 const dw_attr_t attr,
1498 DataExtractor& location_data,
1499 uint32_t &block_size
1503 DWARFFormValue form_value;
1505 // Empty out data in case we don't find anything
1506 location_data.Clear();
1507 dw_offset_t end_addr_offset = DW_INVALID_OFFSET;
1508 const dw_offset_t attr_offset = GetAttributeValue(dwarf2Data, cu, attr, form_value, &end_addr_offset);
1511 const uint8_t* blockData = form_value.BlockData();
1514 // We have an inlined location list in the .debug_info section
1515 const DataExtractor& debug_info = dwarf2Data->get_debug_info_data();
1516 dw_offset_t block_offset = blockData - debug_info.GetDataStart();
1517 block_size = (end_addr_offset - attr_offset) - form_value.Unsigned();
1518 location_data.SetData(debug_info, block_offset, block_size);
1522 // We have a location list offset as the value that is
1523 // the offset into the .debug_loc section that describes
1524 // the value over it's lifetime
1525 lldb::offset_t debug_loc_offset = form_value.Unsigned();
1528 assert(dwarf2Data->get_debug_loc_data().GetAddressByteSize() == cu->GetAddressByteSize());
1529 return DWARFLocationList::Extract(dwarf2Data->get_debug_loc_data(), &debug_loc_offset, location_data);
1536 //----------------------------------------------------------------------
1539 // Get value of the DW_AT_name attribute and return it if one exists,
1540 // else return NULL.
1541 //----------------------------------------------------------------------
1543 DWARFDebugInfoEntry::GetName
1545 SymbolFileDWARF* dwarf2Data,
1546 const DWARFCompileUnit* cu
1549 DWARFFormValue form_value;
1550 if (GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1551 return form_value.AsCString(&dwarf2Data->get_debug_str_data());
1554 if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value))
1556 DWARFCompileUnitSP cu_sp_ptr;
1557 const DWARFDebugInfoEntry* die = const_cast<SymbolFileDWARF*>(dwarf2Data)->DebugInfo()->GetDIEPtr(form_value.Reference(cu), &cu_sp_ptr);
1559 return die->GetName(dwarf2Data, cu_sp_ptr.get());
1566 //----------------------------------------------------------------------
1569 // Get value of the DW_AT_MIPS_linkage_name attribute and return it if
1570 // one exists, else return the value of the DW_AT_name attribute
1571 //----------------------------------------------------------------------
1573 DWARFDebugInfoEntry::GetMangledName
1575 SymbolFileDWARF* dwarf2Data,
1576 const DWARFCompileUnit* cu,
1577 bool substitute_name_allowed
1580 const char* name = NULL;
1581 DWARFFormValue form_value;
1583 if (GetAttributeValue(dwarf2Data, cu, DW_AT_MIPS_linkage_name, form_value))
1584 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1586 if (GetAttributeValue(dwarf2Data, cu, DW_AT_linkage_name, form_value))
1587 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1589 if (substitute_name_allowed && name == NULL)
1591 if (GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1592 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1598 //----------------------------------------------------------------------
1601 // Get value the name for a DIE as it should appear for a
1602 // .debug_pubnames or .debug_pubtypes section.
1603 //----------------------------------------------------------------------
1605 DWARFDebugInfoEntry::GetPubname
1607 SymbolFileDWARF* dwarf2Data,
1608 const DWARFCompileUnit* cu
1611 const char* name = NULL;
1615 DWARFFormValue form_value;
1617 if (GetAttributeValue(dwarf2Data, cu, DW_AT_MIPS_linkage_name, form_value))
1618 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1619 else if (GetAttributeValue(dwarf2Data, cu, DW_AT_linkage_name, form_value))
1620 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1621 else if (GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1622 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1623 else if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value))
1625 // The specification DIE may be in another compile unit so we need
1626 // to get a die and its compile unit.
1627 DWARFCompileUnitSP cu_sp_ptr;
1628 const DWARFDebugInfoEntry* die = const_cast<SymbolFileDWARF*>(dwarf2Data)->DebugInfo()->GetDIEPtr(form_value.Reference(cu), &cu_sp_ptr);
1630 return die->GetPubname(dwarf2Data, cu_sp_ptr.get());
1636 //----------------------------------------------------------------------
1639 // Get value of the DW_AT_name attribute for a debug information entry
1640 // that exists at offset "die_offset" and place that value into the
1641 // supplied stream object. If the DIE is a NULL object "NULL" is placed
1642 // into the stream, and if no DW_AT_name attribute exists for the DIE
1643 // then nothing is printed.
1644 //----------------------------------------------------------------------
1646 DWARFDebugInfoEntry::GetName
1648 SymbolFileDWARF* dwarf2Data,
1649 const DWARFCompileUnit* cu,
1650 const dw_offset_t die_offset,
1654 if (dwarf2Data == NULL)
1656 s.PutCString("NULL");
1660 DWARFDebugInfoEntry die;
1661 lldb::offset_t offset = die_offset;
1662 if (die.Extract(dwarf2Data, cu, &offset))
1666 s.PutCString("NULL");
1671 DWARFFormValue form_value;
1672 if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1674 const char* name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1686 //----------------------------------------------------------------------
1689 // Follows the type name definition down through all needed tags to
1690 // end up with a fully qualified type name and dump the results to
1691 // the supplied stream. This is used to show the name of types given
1692 // a type identifier.
1693 //----------------------------------------------------------------------
1695 DWARFDebugInfoEntry::AppendTypeName
1697 SymbolFileDWARF* dwarf2Data,
1698 const DWARFCompileUnit* cu,
1699 const dw_offset_t die_offset,
1703 if (dwarf2Data == NULL)
1705 s.PutCString("NULL");
1709 DWARFDebugInfoEntry die;
1710 lldb::offset_t offset = die_offset;
1711 if (die.Extract(dwarf2Data, cu, &offset))
1715 s.PutCString("NULL");
1720 const char* name = die.GetPubname(dwarf2Data, cu);
1721 // if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1722 // name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1728 const DWARFAbbreviationDeclaration* abbrevDecl = die.GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1730 if (abbrevDecl == NULL)
1733 switch (abbrevDecl->Tag())
1735 case DW_TAG_array_type: break; // print out a "[]" after printing the full type of the element below
1736 case DW_TAG_base_type: s.PutCString("base "); break;
1737 case DW_TAG_class_type: s.PutCString("class "); break;
1738 case DW_TAG_const_type: s.PutCString("const "); break;
1739 case DW_TAG_enumeration_type: s.PutCString("enum "); break;
1740 case DW_TAG_file_type: s.PutCString("file "); break;
1741 case DW_TAG_interface_type: s.PutCString("interface "); break;
1742 case DW_TAG_packed_type: s.PutCString("packed "); break;
1743 case DW_TAG_pointer_type: break; // print out a '*' after printing the full type below
1744 case DW_TAG_ptr_to_member_type: break; // print out a '*' after printing the full type below
1745 case DW_TAG_reference_type: break; // print out a '&' after printing the full type below
1746 case DW_TAG_restrict_type: s.PutCString("restrict "); break;
1747 case DW_TAG_set_type: s.PutCString("set "); break;
1748 case DW_TAG_shared_type: s.PutCString("shared "); break;
1749 case DW_TAG_string_type: s.PutCString("string "); break;
1750 case DW_TAG_structure_type: s.PutCString("struct "); break;
1751 case DW_TAG_subrange_type: s.PutCString("subrange "); break;
1752 case DW_TAG_subroutine_type: s.PutCString("function "); break;
1753 case DW_TAG_thrown_type: s.PutCString("thrown "); break;
1754 case DW_TAG_union_type: s.PutCString("union "); break;
1755 case DW_TAG_unspecified_type: s.PutCString("unspecified "); break;
1756 case DW_TAG_volatile_type: s.PutCString("volatile "); break;
1761 // Follow the DW_AT_type if possible
1762 DWARFFormValue form_value;
1763 if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_type, form_value))
1765 uint64_t next_die_offset = form_value.Reference(cu);
1766 result = AppendTypeName(dwarf2Data, cu, next_die_offset, s);
1769 switch (abbrevDecl->Tag())
1771 case DW_TAG_array_type: s.PutCString("[]"); break;
1772 case DW_TAG_pointer_type: s.PutChar('*'); break;
1773 case DW_TAG_ptr_to_member_type: s.PutChar('*'); break;
1774 case DW_TAG_reference_type: s.PutChar('&'); break;
1786 DWARFDebugInfoEntry::Contains (const DWARFDebugInfoEntry *die) const
1790 const dw_offset_t die_offset = die->GetOffset();
1791 if (die_offset > GetOffset())
1793 const DWARFDebugInfoEntry *sibling = GetSibling();
1794 assert (sibling); // TODO: take this out
1796 return die_offset < sibling->GetOffset();
1802 //----------------------------------------------------------------------
1803 // BuildAddressRangeTable
1804 //----------------------------------------------------------------------
1806 DWARFDebugInfoEntry::BuildAddressRangeTable
1808 SymbolFileDWARF* dwarf2Data,
1809 const DWARFCompileUnit* cu,
1810 DWARFDebugAranges* debug_aranges
1815 if (m_tag == DW_TAG_subprogram)
1817 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1818 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1819 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS))
1821 /// printf("BuildAddressRangeTable() 0x%8.8x: %30s: [0x%8.8x - 0x%8.8x)\n", m_offset, DW_TAG_value_to_name(tag), lo_pc, hi_pc);
1822 debug_aranges->AppendRange (cu->GetOffset(), lo_pc, hi_pc);
1827 const DWARFDebugInfoEntry* child = GetFirstChild();
1830 child->BuildAddressRangeTable(dwarf2Data, cu, debug_aranges);
1831 child = child->GetSibling();
1836 //----------------------------------------------------------------------
1837 // BuildFunctionAddressRangeTable
1839 // This function is very similar to the BuildAddressRangeTable function
1840 // except that the actual DIE offset for the function is placed in the
1841 // table instead of the compile unit offset (which is the way the
1842 // standard .debug_aranges section does it).
1843 //----------------------------------------------------------------------
1845 DWARFDebugInfoEntry::BuildFunctionAddressRangeTable
1847 SymbolFileDWARF* dwarf2Data,
1848 const DWARFCompileUnit* cu,
1849 DWARFDebugAranges* debug_aranges
1854 if (m_tag == DW_TAG_subprogram)
1856 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1857 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1858 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS))
1860 // printf("BuildAddressRangeTable() 0x%8.8x: [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n", m_offset, lo_pc, hi_pc); // DEBUG ONLY
1861 debug_aranges->AppendRange (GetOffset(), lo_pc, hi_pc);
1865 const DWARFDebugInfoEntry* child = GetFirstChild();
1868 child->BuildFunctionAddressRangeTable(dwarf2Data, cu, debug_aranges);
1869 child = child->GetSibling();
1875 DWARFDebugInfoEntry::GetDeclContextDIEs (SymbolFileDWARF* dwarf2Data,
1876 DWARFCompileUnit* cu,
1877 DWARFDIECollection &decl_context_dies) const
1879 const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
1880 if (parent_decl_ctx_die && parent_decl_ctx_die != this)
1882 decl_context_dies.Append(parent_decl_ctx_die);
1883 parent_decl_ctx_die->GetDeclContextDIEs (dwarf2Data, cu, decl_context_dies);
1888 DWARFDebugInfoEntry::GetDWARFDeclContext (SymbolFileDWARF* dwarf2Data,
1889 DWARFCompileUnit* cu,
1890 DWARFDeclContext &dwarf_decl_ctx) const
1892 const dw_tag_t tag = Tag();
1893 if (tag != DW_TAG_compile_unit)
1895 dwarf_decl_ctx.AppendDeclContext(tag, GetName(dwarf2Data, cu));
1896 const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
1897 if (parent_decl_ctx_die && parent_decl_ctx_die != this)
1899 if (parent_decl_ctx_die->Tag() != DW_TAG_compile_unit)
1900 parent_decl_ctx_die->GetDWARFDeclContext (dwarf2Data, cu, dwarf_decl_ctx);
1907 DWARFDebugInfoEntry::MatchesDWARFDeclContext (SymbolFileDWARF* dwarf2Data,
1908 DWARFCompileUnit* cu,
1909 const DWARFDeclContext &dwarf_decl_ctx) const
1912 DWARFDeclContext this_dwarf_decl_ctx;
1913 GetDWARFDeclContext (dwarf2Data, cu, this_dwarf_decl_ctx);
1914 return this_dwarf_decl_ctx == dwarf_decl_ctx;
1917 const DWARFDebugInfoEntry *
1918 DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
1919 DWARFCompileUnit* cu) const
1921 DWARFDebugInfoEntry::Attributes attributes;
1922 GetAttributes(dwarf2Data, cu, NULL, attributes);
1923 return GetParentDeclContextDIE (dwarf2Data, cu, attributes);
1926 const DWARFDebugInfoEntry *
1927 DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
1928 DWARFCompileUnit* cu,
1929 const DWARFDebugInfoEntry::Attributes& attributes) const
1931 const DWARFDebugInfoEntry * die = this;
1935 // If this is the original DIE that we are searching for a declaration
1936 // for, then don't look in the cache as we don't want our own decl
1937 // context to be our decl context...
1942 case DW_TAG_compile_unit:
1943 case DW_TAG_namespace:
1944 case DW_TAG_structure_type:
1945 case DW_TAG_union_type:
1946 case DW_TAG_class_type:
1954 dw_offset_t die_offset;
1956 die_offset = attributes.FormValueAsUnsigned(dwarf2Data, DW_AT_specification, DW_INVALID_OFFSET);
1957 if (die_offset != DW_INVALID_OFFSET)
1959 const DWARFDebugInfoEntry *spec_die = cu->GetDIEPtr (die_offset);
1962 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = spec_die->GetParentDeclContextDIE (dwarf2Data, cu);
1963 if (spec_die_decl_ctx_die)
1964 return spec_die_decl_ctx_die;
1968 die_offset = attributes.FormValueAsUnsigned(dwarf2Data, DW_AT_abstract_origin, DW_INVALID_OFFSET);
1969 if (die_offset != DW_INVALID_OFFSET)
1971 const DWARFDebugInfoEntry *abs_die = cu->GetDIEPtr (die_offset);
1974 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = abs_die->GetParentDeclContextDIE (dwarf2Data, cu);
1975 if (abs_die_decl_ctx_die)
1976 return abs_die_decl_ctx_die;
1980 die = die->GetParent();
1987 DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data,
1988 DWARFCompileUnit* cu,
1989 std::string &storage) const
1991 DWARFDebugInfoEntry::Attributes attributes;
1992 GetAttributes(dwarf2Data, cu, NULL, attributes);
1993 return GetQualifiedName (dwarf2Data, cu, attributes, storage);
1997 DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data,
1998 DWARFCompileUnit* cu,
1999 const DWARFDebugInfoEntry::Attributes& attributes,
2000 std::string &storage) const
2003 const char *name = GetName (dwarf2Data, cu);
2007 const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
2009 // TODO: change this to get the correct decl context parent....
2010 while (parent_decl_ctx_die)
2012 const dw_tag_t parent_tag = parent_decl_ctx_die->Tag();
2015 case DW_TAG_namespace:
2017 const char *namespace_name = parent_decl_ctx_die->GetName (dwarf2Data, cu);
2020 storage.insert (0, "::");
2021 storage.insert (0, namespace_name);
2025 storage.insert (0, "(anonymous namespace)::");
2027 parent_decl_ctx_die = parent_decl_ctx_die->GetParentDeclContextDIE(dwarf2Data, cu);
2031 case DW_TAG_class_type:
2032 case DW_TAG_structure_type:
2033 case DW_TAG_union_type:
2035 const char *class_union_struct_name = parent_decl_ctx_die->GetName (dwarf2Data, cu);
2037 if (class_union_struct_name)
2039 storage.insert (0, "::");
2040 storage.insert (0, class_union_struct_name);
2042 parent_decl_ctx_die = parent_decl_ctx_die->GetParentDeclContextDIE(dwarf2Data, cu);
2047 parent_decl_ctx_die = NULL;
2052 if (storage.empty())
2053 storage.append ("::");
2055 storage.append (name);
2057 if (storage.empty())
2059 return storage.c_str();
2063 //----------------------------------------------------------------------
2065 //----------------------------------------------------------------------
2067 DWARFDebugInfoEntry::LookupAddress
2069 const dw_addr_t address,
2070 SymbolFileDWARF* dwarf2Data,
2071 const DWARFCompileUnit* cu,
2072 DWARFDebugInfoEntry** function_die,
2073 DWARFDebugInfoEntry** block_die
2076 bool found_address = false;
2079 bool check_children = false;
2080 bool match_addr_range = false;
2081 // printf("0x%8.8x: %30s: address = 0x%8.8x - ", m_offset, DW_TAG_value_to_name(tag), address);
2084 case DW_TAG_array_type : break;
2085 case DW_TAG_class_type : check_children = true; break;
2086 case DW_TAG_entry_point : break;
2087 case DW_TAG_enumeration_type : break;
2088 case DW_TAG_formal_parameter : break;
2089 case DW_TAG_imported_declaration : break;
2090 case DW_TAG_label : break;
2091 case DW_TAG_lexical_block : check_children = true; match_addr_range = true; break;
2092 case DW_TAG_member : break;
2093 case DW_TAG_pointer_type : break;
2094 case DW_TAG_reference_type : break;
2095 case DW_TAG_compile_unit : match_addr_range = true; break;
2096 case DW_TAG_string_type : break;
2097 case DW_TAG_structure_type : check_children = true; break;
2098 case DW_TAG_subroutine_type : break;
2099 case DW_TAG_typedef : break;
2100 case DW_TAG_union_type : break;
2101 case DW_TAG_unspecified_parameters : break;
2102 case DW_TAG_variant : break;
2103 case DW_TAG_common_block : check_children = true; break;
2104 case DW_TAG_common_inclusion : break;
2105 case DW_TAG_inheritance : break;
2106 case DW_TAG_inlined_subroutine : check_children = true; match_addr_range = true; break;
2107 case DW_TAG_module : match_addr_range = true; break;
2108 case DW_TAG_ptr_to_member_type : break;
2109 case DW_TAG_set_type : break;
2110 case DW_TAG_subrange_type : break;
2111 case DW_TAG_with_stmt : break;
2112 case DW_TAG_access_declaration : break;
2113 case DW_TAG_base_type : break;
2114 case DW_TAG_catch_block : match_addr_range = true; break;
2115 case DW_TAG_const_type : break;
2116 case DW_TAG_constant : break;
2117 case DW_TAG_enumerator : break;
2118 case DW_TAG_file_type : break;
2119 case DW_TAG_friend : break;
2120 case DW_TAG_namelist : break;
2121 case DW_TAG_namelist_item : break;
2122 case DW_TAG_packed_type : break;
2123 case DW_TAG_subprogram : match_addr_range = true; break;
2124 case DW_TAG_template_type_parameter : break;
2125 case DW_TAG_template_value_parameter : break;
2126 case DW_TAG_thrown_type : break;
2127 case DW_TAG_try_block : match_addr_range = true; break;
2128 case DW_TAG_variant_part : break;
2129 case DW_TAG_variable : break;
2130 case DW_TAG_volatile_type : break;
2131 case DW_TAG_dwarf_procedure : break;
2132 case DW_TAG_restrict_type : break;
2133 case DW_TAG_interface_type : break;
2134 case DW_TAG_namespace : check_children = true; break;
2135 case DW_TAG_imported_module : break;
2136 case DW_TAG_unspecified_type : break;
2137 case DW_TAG_partial_unit : break;
2138 case DW_TAG_imported_unit : break;
2139 case DW_TAG_shared_type : break;
2143 if (match_addr_range)
2145 dw_addr_t lo_pc = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
2146 if (lo_pc != LLDB_INVALID_ADDRESS)
2148 dw_addr_t hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, LLDB_INVALID_ADDRESS);
2149 if (hi_pc != LLDB_INVALID_ADDRESS)
2151 // printf("\n0x%8.8x: %30s: address = 0x%8.8x [0x%8.8x - 0x%8.8x) ", m_offset, DW_TAG_value_to_name(tag), address, lo_pc, hi_pc);
2152 if ((lo_pc <= address) && (address < hi_pc))
2154 found_address = true;
2155 // puts("***MATCH***");
2158 case DW_TAG_compile_unit: // File
2159 check_children = ((function_die != NULL) || (block_die != NULL));
2162 case DW_TAG_subprogram: // Function
2164 *function_die = this;
2165 check_children = (block_die != NULL);
2168 case DW_TAG_inlined_subroutine: // Inlined Function
2169 case DW_TAG_lexical_block: // Block { } in code
2173 check_children = true;
2178 check_children = true;
2184 { // compile units may not have a valid high/low pc when there
2185 // are address gaps in subroutines so we must always search
2186 // if there is no valid high and low PC
2187 check_children = (m_tag == DW_TAG_compile_unit) && ((function_die != NULL) || (block_die != NULL));
2192 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET);
2193 if (debug_ranges_offset != DW_INVALID_OFFSET)
2195 DWARFDebugRanges::RangeList ranges;
2196 DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
2197 debug_ranges->FindRanges(debug_ranges_offset, ranges);
2198 // All DW_AT_ranges are relative to the base address of the
2199 // compile unit. We add the compile unit base address to make
2200 // sure all the addresses are properly fixed up.
2201 ranges.Slide (cu->GetBaseAddress());
2202 if (ranges.FindEntryThatContains(address))
2204 found_address = true;
2205 // puts("***MATCH***");
2208 case DW_TAG_compile_unit: // File
2209 check_children = ((function_die != NULL) || (block_die != NULL));
2212 case DW_TAG_subprogram: // Function
2214 *function_die = this;
2215 check_children = (block_die != NULL);
2218 case DW_TAG_inlined_subroutine: // Inlined Function
2219 case DW_TAG_lexical_block: // Block { } in code
2223 check_children = true;
2228 check_children = true;
2234 check_children = false;
2243 // printf("checking children\n");
2244 DWARFDebugInfoEntry* child = GetFirstChild();
2247 if (child->LookupAddress(address, dwarf2Data, cu, function_die, block_die))
2249 child = child->GetSibling();
2253 return found_address;
2256 const DWARFAbbreviationDeclaration*
2257 DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr (SymbolFileDWARF* dwarf2Data,
2258 const DWARFCompileUnit *cu,
2259 lldb::offset_t &offset) const
2263 offset = GetOffset();
2265 const DWARFAbbreviationDeclaration* abbrev_decl = cu->GetAbbreviations()->GetAbbreviationDeclaration (m_abbr_idx);
2268 // Make sure the abbreviation code still matches. If it doesn't and
2269 // the DWARF data was mmap'ed, the backing file might have been modified
2270 // which is bad news.
2271 const uint64_t abbrev_code = dwarf2Data->get_debug_info_data().GetULEB128 (&offset);
2273 if (abbrev_decl->Code() == abbrev_code)
2276 dwarf2Data->GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("0x%8.8x: the DWARF debug information has been modified (abbrev code was %u, and is now %u)",
2278 (uint32_t)abbrev_decl->Code(),
2279 (uint32_t)abbrev_code);
2282 offset = DW_INVALID_OFFSET;
2288 DWARFDebugInfoEntry::OffsetLessThan (const DWARFDebugInfoEntry& a, const DWARFDebugInfoEntry& b)
2290 return a.GetOffset() < b.GetOffset();
2294 DWARFDebugInfoEntry::DumpDIECollection (Stream &strm, DWARFDebugInfoEntry::collection &die_collection)
2296 DWARFDebugInfoEntry::const_iterator pos;
2297 DWARFDebugInfoEntry::const_iterator end = die_collection.end();
2298 strm.PutCString("\noffset parent sibling child\n");
2299 strm.PutCString("-------- -------- -------- --------\n");
2300 for (pos = die_collection.begin(); pos != end; ++pos)
2302 const DWARFDebugInfoEntry& die_ref = *pos;
2303 const DWARFDebugInfoEntry* p = die_ref.GetParent();
2304 const DWARFDebugInfoEntry* s = die_ref.GetSibling();
2305 const DWARFDebugInfoEntry* c = die_ref.GetFirstChild();
2306 strm.Printf("%.8x: %.8x %.8x %.8x 0x%4.4x %s%s\n",
2307 die_ref.GetOffset(),
2308 p ? p->GetOffset() : 0,
2309 s ? s->GetOffset() : 0,
2310 c ? c->GetOffset() : 0,
2312 DW_TAG_value_to_name(die_ref.Tag()),
2313 die_ref.HasChildren() ? " *" : "");