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 DWARFDataExtractor& 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();
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 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 DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
285 // const DWARFDataExtractor& 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 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 DWARFDataExtractor* 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);
766 lldb::ModuleSP module = dwarf2Data->GetObjectFile()->GetModule();
770 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
772 if (!debug_info_data.ValidOffset(offset))
775 const uint32_t numAttributes = abbrevDecl->NumAttributes();
779 bool do_offset = false;
781 for (i=0; i<numAttributes; ++i)
783 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
784 DWARFFormValue form_value(form);
785 if (form_value.ExtractValue(debug_info_data, &offset, cu))
790 lo_pc = form_value.Unsigned();
798 lo_pc = form_value.Unsigned();
802 hi_pc = form_value.Unsigned();
803 if (form_value.Form() != DW_FORM_addr)
805 if (lo_pc == LLDB_INVALID_ADDRESS)
806 do_offset = hi_pc != LLDB_INVALID_ADDRESS;
808 hi_pc += lo_pc; // DWARF 4 introduces <offset-from-lo-pc> to save on relocations
814 const DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
815 debug_ranges->FindRanges(form_value.Unsigned(), ranges);
816 // All DW_AT_ranges are relative to the base address of the
817 // compile unit. We add the compile unit base address to make
818 // sure all the addresses are properly fixed up.
819 ranges.Slide(cu->GetBaseAddress());
825 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
828 case DW_AT_MIPS_linkage_name:
829 case DW_AT_linkage_name:
831 mangled = form_value.AsCString(&dwarf2Data->get_debug_str_data());
834 case DW_AT_abstract_origin:
835 die_offsets.push_back(form_value.Reference(cu));
838 case DW_AT_specification:
839 die_offsets.push_back(form_value.Reference(cu));
842 case DW_AT_decl_file:
844 decl_file = form_value.Unsigned();
847 case DW_AT_decl_line:
849 decl_line = form_value.Unsigned();
852 case DW_AT_decl_column:
853 if (decl_column == 0)
854 decl_column = form_value.Unsigned();
857 case DW_AT_call_file:
859 call_file = form_value.Unsigned();
862 case DW_AT_call_line:
864 call_line = form_value.Unsigned();
867 case DW_AT_call_column:
868 if (call_column == 0)
869 call_column = form_value.Unsigned();
872 case DW_AT_frame_base:
875 if (form_value.BlockData())
877 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
878 uint32_t block_length = form_value.Unsigned();
879 frame_base->SetOpcodeData(module, debug_info_data, block_offset, block_length);
883 const DWARFDataExtractor &debug_loc_data = dwarf2Data->get_debug_loc_data();
884 const dw_offset_t debug_loc_offset = form_value.Unsigned();
886 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
887 if (loc_list_length > 0)
889 frame_base->SetOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
890 if (lo_pc != LLDB_INVALID_ADDRESS)
892 assert (lo_pc >= cu->GetBaseAddress());
893 frame_base->SetLocationListSlide(lo_pc - cu->GetBaseAddress());
897 set_frame_base_loclist_addr = true;
911 if (ranges.IsEmpty())
913 if (lo_pc != LLDB_INVALID_ADDRESS)
915 if (hi_pc != LLDB_INVALID_ADDRESS && hi_pc > lo_pc)
916 ranges.Append(DWARFDebugRanges::Range (lo_pc, hi_pc - lo_pc));
918 ranges.Append(DWARFDebugRanges::Range (lo_pc, 0));
922 if (set_frame_base_loclist_addr)
924 dw_addr_t lowest_range_pc = ranges.GetMinRangeBase(0);
925 assert (lowest_range_pc >= cu->GetBaseAddress());
926 frame_base->SetLocationListSlide (lowest_range_pc - cu->GetBaseAddress());
929 if (ranges.IsEmpty() || name == NULL || mangled == NULL)
931 std::vector<dw_offset_t>::const_iterator pos;
932 std::vector<dw_offset_t>::const_iterator end = die_offsets.end();
933 for (pos = die_offsets.begin(); pos != end; ++pos)
935 DWARFCompileUnitSP cu_sp_ptr;
936 const DWARFDebugInfoEntry* die = NULL;
937 dw_offset_t die_offset = *pos;
938 if (die_offset != DW_INVALID_OFFSET)
940 die = dwarf2Data->DebugInfo()->GetDIEPtr(die_offset, &cu_sp_ptr);
942 die->GetDIENamesAndRanges(dwarf2Data, cu_sp_ptr.get(), name, mangled, ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column);
946 return !ranges.IsEmpty();
949 //----------------------------------------------------------------------
952 // Dumps a debug information entry and all of it's attributes to the
954 //----------------------------------------------------------------------
956 DWARFDebugInfoEntry::Dump
958 SymbolFileDWARF* dwarf2Data,
959 const DWARFCompileUnit* cu,
961 uint32_t recurse_depth
964 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
965 lldb::offset_t offset = m_offset;
967 if (debug_info_data.ValidOffset(offset))
969 dw_uleb128_t abbrCode = debug_info_data.GetULEB128(&offset);
971 s.Printf("\n0x%8.8x: ", m_offset);
973 if (abbrCode != m_abbr_idx)
975 s.Printf( "error: DWARF has been modified\n");
979 const DWARFAbbreviationDeclaration* abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration (abbrCode);
983 s.PutCString(DW_TAG_value_to_name(abbrevDecl->Tag()));
984 s.Printf( " [%u] %c\n", abbrCode, abbrevDecl->HasChildren() ? '*':' ');
986 // Dump all data in the .debug_info for the attributes
987 const uint32_t numAttributes = abbrevDecl->NumAttributes();
991 for (i=0; i<numAttributes; ++i)
993 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
995 DumpAttribute(dwarf2Data, cu, debug_info_data, &offset, s, attr, form);
998 const DWARFDebugInfoEntry* child = GetFirstChild();
999 if (recurse_depth > 0 && child)
1005 child->Dump(dwarf2Data, cu, s, recurse_depth-1);
1006 child = child->GetSibling();
1012 s.Printf( "Abbreviation code note found in 'debug_abbrev' class for code: %u\n", abbrCode);
1016 s.Printf( "NULL\n");
1022 DWARFDebugInfoEntry::DumpLocation
1024 SymbolFileDWARF* dwarf2Data,
1025 DWARFCompileUnit* cu,
1029 const DWARFDebugInfoEntry *cu_die = cu->GetCompileUnitDIEOnly();
1030 const char *cu_name = NULL;
1032 cu_name = cu_die->GetName (dwarf2Data, cu);
1033 const char *obj_file_name = NULL;
1034 ObjectFile *obj_file = dwarf2Data->GetObjectFile();
1036 obj_file_name = obj_file->GetFileSpec().GetFilename().AsCString();
1037 const char *die_name = GetName (dwarf2Data, cu);
1038 s.Printf ("0x%8.8x/0x%8.8x: %-30s (from %s in %s)",
1041 die_name ? die_name : "",
1042 cu_name ? cu_name : "<NULL>",
1043 obj_file_name ? obj_file_name : "<NULL>");
1046 //----------------------------------------------------------------------
1049 // Dumps a debug information entry attribute along with it's form. Any
1050 // special display of attributes is done (disassemble location lists,
1051 // show enumeration values for attributes, etc).
1052 //----------------------------------------------------------------------
1054 DWARFDebugInfoEntry::DumpAttribute
1056 SymbolFileDWARF* dwarf2Data,
1057 const DWARFCompileUnit* cu,
1058 const DWARFDataExtractor& debug_info_data,
1059 lldb::offset_t *offset_ptr,
1065 bool verbose = s.GetVerbose();
1066 bool show_form = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm);
1068 const DWARFDataExtractor* debug_str_data = dwarf2Data ? &dwarf2Data->get_debug_str_data() : NULL;
1070 s.Offset (*offset_ptr);
1073 s.Indent(DW_AT_value_to_name(attr));
1077 s.Printf( "[%s", DW_FORM_value_to_name(form));
1080 DWARFFormValue form_value(form);
1082 if (!form_value.ExtractValue(debug_info_data, offset_ptr, cu))
1087 if (form == DW_FORM_indirect)
1089 s.Printf( " [%s]", DW_FORM_value_to_name(form_value.Form()));
1097 // Always dump form value if verbose is enabled
1100 form_value.Dump(s, debug_str_data, cu);
1104 // Check to see if we have any special attribute formatters
1107 case DW_AT_stmt_list:
1108 if ( verbose ) s.PutCString(" ( ");
1109 s.Printf( "0x%8.8" PRIx64, form_value.Unsigned());
1110 if ( verbose ) s.PutCString(" )");
1113 case DW_AT_language:
1114 if ( verbose ) s.PutCString(" ( ");
1115 s.PutCString(DW_LANG_value_to_name(form_value.Unsigned()));
1116 if ( verbose ) s.PutCString(" )");
1119 case DW_AT_encoding:
1120 if ( verbose ) s.PutCString(" ( ");
1121 s.PutCString(DW_ATE_value_to_name(form_value.Unsigned()));
1122 if ( verbose ) s.PutCString(" )");
1125 case DW_AT_frame_base:
1126 case DW_AT_location:
1127 case DW_AT_data_member_location:
1129 const uint8_t* blockData = form_value.BlockData();
1133 form_value.Dump(s, debug_str_data, cu);
1135 // Location description is inlined in data in the form value
1136 DWARFDataExtractor locationData(debug_info_data, (*offset_ptr) - form_value.Unsigned(), form_value.Unsigned());
1137 if ( verbose ) s.PutCString(" ( ");
1138 print_dwarf_expression (s, locationData, DWARFCompileUnit::GetAddressByteSize(cu), 4, false);
1139 if ( verbose ) s.PutCString(" )");
1143 // We have a location list offset as the value that is
1144 // the offset into the .debug_loc section that describes
1145 // the value over it's lifetime
1146 uint64_t debug_loc_offset = form_value.Unsigned();
1150 form_value.Dump(s, debug_str_data, cu);
1151 DWARFLocationList::Dump(s, cu, dwarf2Data->get_debug_loc_data(), debug_loc_offset);
1156 form_value.Dump(s, NULL, cu);
1162 case DW_AT_abstract_origin:
1163 case DW_AT_specification:
1165 uint64_t abstract_die_offset = form_value.Reference(cu);
1166 form_value.Dump(s, debug_str_data, cu);
1167 // *ostrm_ptr << HEX32 << abstract_die_offset << " ( ";
1168 if ( verbose ) s.PutCString(" ( ");
1169 GetName(dwarf2Data, cu, abstract_die_offset, s);
1170 if ( verbose ) s.PutCString(" )");
1176 uint64_t type_die_offset = form_value.Reference(cu);
1178 form_value.Dump(s, debug_str_data, cu);
1179 s.PutCString(" ( ");
1180 AppendTypeName(dwarf2Data, cu, type_die_offset, s);
1188 form_value.Dump(s, debug_str_data, cu);
1189 lldb::offset_t ranges_offset = form_value.Unsigned();
1190 dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0;
1192 DWARFDebugRanges::Dump(s, dwarf2Data->get_debug_ranges_data(), &ranges_offset, base_addr);
1198 form_value.Dump(s, debug_str_data, cu);
1202 s.PutCString(" )\n");
1205 //----------------------------------------------------------------------
1206 // Get all attribute values for a given DIE, including following any
1207 // specification or abstract origin attributes and including those in
1208 // the results. Any duplicate attributes will have the first instance
1209 // take precedence (this can happen for declaration attributes).
1210 //----------------------------------------------------------------------
1212 DWARFDebugInfoEntry::GetAttributes
1214 SymbolFileDWARF* dwarf2Data,
1215 const DWARFCompileUnit* cu,
1216 const uint8_t *fixed_form_sizes,
1217 DWARFDebugInfoEntry::Attributes& attributes,
1221 lldb::offset_t offset;
1222 const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1226 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
1228 if (fixed_form_sizes == NULL)
1229 fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(cu->GetAddressByteSize());
1231 const uint32_t num_attributes = abbrevDecl->NumAttributes();
1235 DWARFFormValue form_value;
1236 for (i=0; i<num_attributes; ++i)
1238 abbrevDecl->GetAttrAndFormByIndexUnchecked (i, attr, form);
1240 // If we are tracking down DW_AT_specification or DW_AT_abstract_origin
1241 // attributes, the depth will be non-zero. We need to omit certain
1242 // attributes that don't make sense.
1246 case DW_AT_declaration:
1249 // This attribute doesn't make sense when combined with
1250 // the DIE that references this DIE. We know a DIE is
1251 // referencing this DIE because curr_depth is not zero
1256 attributes.Append(cu, offset, attr, form);
1260 if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin))
1262 form_value.SetForm(form);
1263 if (form_value.ExtractValue(debug_info_data, &offset, cu))
1265 const DWARFDebugInfoEntry* die = NULL;
1266 dw_offset_t die_offset = form_value.Reference(cu);
1267 if (cu->ContainsDIEOffset(die_offset))
1269 die = const_cast<DWARFCompileUnit*>(cu)->GetDIEPtr(die_offset);
1271 die->GetAttributes(dwarf2Data, cu, fixed_form_sizes, attributes, curr_depth + 1);
1275 DWARFCompileUnitSP cu_sp_ptr;
1276 die = const_cast<SymbolFileDWARF*>(dwarf2Data)->DebugInfo()->GetDIEPtr(die_offset, &cu_sp_ptr);
1278 die->GetAttributes(dwarf2Data, cu_sp_ptr.get(), fixed_form_sizes, attributes, curr_depth + 1);
1284 const uint8_t fixed_skip_size = fixed_form_sizes [form];
1285 if (fixed_skip_size)
1286 offset += fixed_skip_size;
1288 DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
1296 return attributes.Size();
1300 //----------------------------------------------------------------------
1301 // GetAttributeValue
1303 // Get the value of an attribute and return the .debug_info offset of the
1304 // attribute if it was properly extracted into form_value, or zero
1305 // if we fail since an offset of zero is invalid for an attribute (it
1306 // would be a compile unit header).
1307 //----------------------------------------------------------------------
1309 DWARFDebugInfoEntry::GetAttributeValue
1311 SymbolFileDWARF* dwarf2Data,
1312 const DWARFCompileUnit* cu,
1313 const dw_attr_t attr,
1314 DWARFFormValue& form_value,
1315 dw_offset_t* end_attr_offset_ptr
1318 lldb::offset_t offset;
1319 const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1323 uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
1325 if (attr_idx != DW_INVALID_INDEX)
1327 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
1330 while (idx<attr_idx)
1331 DWARFFormValue::SkipValue(abbrevDecl->GetFormByIndex(idx++), debug_info_data, &offset, cu);
1333 const dw_offset_t attr_offset = offset;
1334 form_value.SetForm(abbrevDecl->GetFormByIndex(idx));
1335 if (form_value.ExtractValue(debug_info_data, &offset, cu))
1337 if (end_attr_offset_ptr)
1338 *end_attr_offset_ptr = offset;
1347 //----------------------------------------------------------------------
1348 // GetAttributeValueAsString
1350 // Get the value of an attribute as a string return it. The resulting
1351 // pointer to the string data exists within the supplied SymbolFileDWARF
1352 // and will only be available as long as the SymbolFileDWARF is still around
1353 // and it's content doesn't change.
1354 //----------------------------------------------------------------------
1356 DWARFDebugInfoEntry::GetAttributeValueAsString
1358 SymbolFileDWARF* dwarf2Data,
1359 const DWARFCompileUnit* cu,
1360 const dw_attr_t attr,
1361 const char* fail_value) const
1363 DWARFFormValue form_value;
1364 if (GetAttributeValue(dwarf2Data, cu, attr, form_value))
1365 return form_value.AsCString(&dwarf2Data->get_debug_str_data());
1369 //----------------------------------------------------------------------
1370 // GetAttributeValueAsUnsigned
1372 // Get the value of an attribute as unsigned and return it.
1373 //----------------------------------------------------------------------
1375 DWARFDebugInfoEntry::GetAttributeValueAsUnsigned
1377 SymbolFileDWARF* dwarf2Data,
1378 const DWARFCompileUnit* cu,
1379 const dw_attr_t attr,
1383 DWARFFormValue form_value;
1384 if (GetAttributeValue(dwarf2Data, cu, attr, form_value))
1385 return form_value.Unsigned();
1389 //----------------------------------------------------------------------
1390 // GetAttributeValueAsSigned
1392 // Get the value of an attribute a signed value and return it.
1393 //----------------------------------------------------------------------
1395 DWARFDebugInfoEntry::GetAttributeValueAsSigned
1397 SymbolFileDWARF* dwarf2Data,
1398 const DWARFCompileUnit* cu,
1399 const dw_attr_t attr,
1403 DWARFFormValue form_value;
1404 if (GetAttributeValue(dwarf2Data, cu, attr, form_value))
1405 return form_value.Signed();
1409 //----------------------------------------------------------------------
1410 // GetAttributeValueAsReference
1412 // Get the value of an attribute as reference and fix up and compile
1413 // unit relative offsets as needed.
1414 //----------------------------------------------------------------------
1416 DWARFDebugInfoEntry::GetAttributeValueAsReference
1418 SymbolFileDWARF* dwarf2Data,
1419 const DWARFCompileUnit* cu,
1420 const dw_attr_t attr,
1424 DWARFFormValue form_value;
1425 if (GetAttributeValue(dwarf2Data, cu, attr, form_value))
1426 return form_value.Reference(cu);
1430 //----------------------------------------------------------------------
1431 // GetAttributeHighPC
1433 // Get the hi_pc, adding hi_pc to lo_pc when specified
1434 // as an <offset-from-low-pc>.
1436 // Returns the hi_pc or fail_value.
1437 //----------------------------------------------------------------------
1439 DWARFDebugInfoEntry::GetAttributeHighPC
1441 SymbolFileDWARF* dwarf2Data,
1442 const DWARFCompileUnit* cu,
1447 DWARFFormValue form_value;
1449 if (GetAttributeValue(dwarf2Data, cu, DW_AT_high_pc, form_value))
1451 dw_addr_t hi_pc = form_value.Unsigned();
1452 if (form_value.Form() != DW_FORM_addr)
1453 hi_pc += lo_pc; // DWARF4 can specify the hi_pc as an <offset-from-lowpc>
1459 //----------------------------------------------------------------------
1460 // GetAttributeAddressRange
1462 // Get the lo_pc and hi_pc, adding hi_pc to lo_pc when specified
1463 // as an <offset-from-low-pc>.
1465 // Returns true or sets lo_pc and hi_pc to fail_value.
1466 //----------------------------------------------------------------------
1468 DWARFDebugInfoEntry::GetAttributeAddressRange
1470 SymbolFileDWARF* dwarf2Data,
1471 const DWARFCompileUnit* cu,
1477 lo_pc = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_low_pc, fail_value);
1478 if (lo_pc != fail_value)
1480 hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, fail_value);
1481 if (hi_pc != fail_value)
1488 //----------------------------------------------------------------------
1489 // GetAttributeValueAsLocation
1491 // Get the value of an attribute as reference and fix up and compile
1492 // unit relative offsets as needed.
1493 //----------------------------------------------------------------------
1495 DWARFDebugInfoEntry::GetAttributeValueAsLocation
1497 SymbolFileDWARF* dwarf2Data,
1498 const DWARFCompileUnit* cu,
1499 const dw_attr_t attr,
1500 DWARFDataExtractor& location_data,
1501 uint32_t &block_size
1505 DWARFFormValue form_value;
1507 // Empty out data in case we don't find anything
1508 location_data.Clear();
1509 dw_offset_t end_addr_offset = DW_INVALID_OFFSET;
1510 const dw_offset_t attr_offset = GetAttributeValue(dwarf2Data, cu, attr, form_value, &end_addr_offset);
1513 const uint8_t* blockData = form_value.BlockData();
1516 // We have an inlined location list in the .debug_info section
1517 const DWARFDataExtractor& debug_info = dwarf2Data->get_debug_info_data();
1518 dw_offset_t block_offset = blockData - debug_info.GetDataStart();
1519 block_size = (end_addr_offset - attr_offset) - form_value.Unsigned();
1520 location_data.SetData(debug_info, block_offset, block_size);
1524 // We have a location list offset as the value that is
1525 // the offset into the .debug_loc section that describes
1526 // the value over it's lifetime
1527 lldb::offset_t debug_loc_offset = form_value.Unsigned();
1530 assert(dwarf2Data->get_debug_loc_data().GetAddressByteSize() == cu->GetAddressByteSize());
1531 return DWARFLocationList::Extract(dwarf2Data->get_debug_loc_data(), &debug_loc_offset, location_data);
1538 //----------------------------------------------------------------------
1541 // Get value of the DW_AT_name attribute and return it if one exists,
1542 // else return NULL.
1543 //----------------------------------------------------------------------
1545 DWARFDebugInfoEntry::GetName
1547 SymbolFileDWARF* dwarf2Data,
1548 const DWARFCompileUnit* cu
1551 DWARFFormValue form_value;
1552 if (GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1553 return form_value.AsCString(&dwarf2Data->get_debug_str_data());
1556 if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value))
1558 DWARFCompileUnitSP cu_sp_ptr;
1559 const DWARFDebugInfoEntry* die = const_cast<SymbolFileDWARF*>(dwarf2Data)->DebugInfo()->GetDIEPtr(form_value.Reference(cu), &cu_sp_ptr);
1561 return die->GetName(dwarf2Data, cu_sp_ptr.get());
1568 //----------------------------------------------------------------------
1571 // Get value of the DW_AT_MIPS_linkage_name attribute and return it if
1572 // one exists, else return the value of the DW_AT_name attribute
1573 //----------------------------------------------------------------------
1575 DWARFDebugInfoEntry::GetMangledName
1577 SymbolFileDWARF* dwarf2Data,
1578 const DWARFCompileUnit* cu,
1579 bool substitute_name_allowed
1582 const char* name = NULL;
1583 DWARFFormValue form_value;
1585 if (GetAttributeValue(dwarf2Data, cu, DW_AT_MIPS_linkage_name, form_value))
1586 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1588 if (GetAttributeValue(dwarf2Data, cu, DW_AT_linkage_name, form_value))
1589 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1591 if (substitute_name_allowed && name == NULL)
1593 if (GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1594 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1600 //----------------------------------------------------------------------
1603 // Get value the name for a DIE as it should appear for a
1604 // .debug_pubnames or .debug_pubtypes section.
1605 //----------------------------------------------------------------------
1607 DWARFDebugInfoEntry::GetPubname
1609 SymbolFileDWARF* dwarf2Data,
1610 const DWARFCompileUnit* cu
1613 const char* name = NULL;
1617 DWARFFormValue form_value;
1619 if (GetAttributeValue(dwarf2Data, cu, DW_AT_MIPS_linkage_name, form_value))
1620 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1621 else if (GetAttributeValue(dwarf2Data, cu, DW_AT_linkage_name, form_value))
1622 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1623 else if (GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1624 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1625 else if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value))
1627 // The specification DIE may be in another compile unit so we need
1628 // to get a die and its compile unit.
1629 DWARFCompileUnitSP cu_sp_ptr;
1630 const DWARFDebugInfoEntry* die = const_cast<SymbolFileDWARF*>(dwarf2Data)->DebugInfo()->GetDIEPtr(form_value.Reference(cu), &cu_sp_ptr);
1632 return die->GetPubname(dwarf2Data, cu_sp_ptr.get());
1638 //----------------------------------------------------------------------
1641 // Get value of the DW_AT_name attribute for a debug information entry
1642 // that exists at offset "die_offset" and place that value into the
1643 // supplied stream object. If the DIE is a NULL object "NULL" is placed
1644 // into the stream, and if no DW_AT_name attribute exists for the DIE
1645 // then nothing is printed.
1646 //----------------------------------------------------------------------
1648 DWARFDebugInfoEntry::GetName
1650 SymbolFileDWARF* dwarf2Data,
1651 const DWARFCompileUnit* cu,
1652 const dw_offset_t die_offset,
1656 if (dwarf2Data == NULL)
1658 s.PutCString("NULL");
1662 DWARFDebugInfoEntry die;
1663 lldb::offset_t offset = die_offset;
1664 if (die.Extract(dwarf2Data, cu, &offset))
1668 s.PutCString("NULL");
1673 DWARFFormValue form_value;
1674 if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1676 const char* name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1688 //----------------------------------------------------------------------
1691 // Follows the type name definition down through all needed tags to
1692 // end up with a fully qualified type name and dump the results to
1693 // the supplied stream. This is used to show the name of types given
1694 // a type identifier.
1695 //----------------------------------------------------------------------
1697 DWARFDebugInfoEntry::AppendTypeName
1699 SymbolFileDWARF* dwarf2Data,
1700 const DWARFCompileUnit* cu,
1701 const dw_offset_t die_offset,
1705 if (dwarf2Data == NULL)
1707 s.PutCString("NULL");
1711 DWARFDebugInfoEntry die;
1712 lldb::offset_t offset = die_offset;
1713 if (die.Extract(dwarf2Data, cu, &offset))
1717 s.PutCString("NULL");
1722 const char* name = die.GetPubname(dwarf2Data, cu);
1723 // if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1724 // name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1730 const DWARFAbbreviationDeclaration* abbrevDecl = die.GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1732 if (abbrevDecl == NULL)
1735 switch (abbrevDecl->Tag())
1737 case DW_TAG_array_type: break; // print out a "[]" after printing the full type of the element below
1738 case DW_TAG_base_type: s.PutCString("base "); break;
1739 case DW_TAG_class_type: s.PutCString("class "); break;
1740 case DW_TAG_const_type: s.PutCString("const "); break;
1741 case DW_TAG_enumeration_type: s.PutCString("enum "); break;
1742 case DW_TAG_file_type: s.PutCString("file "); break;
1743 case DW_TAG_interface_type: s.PutCString("interface "); break;
1744 case DW_TAG_packed_type: s.PutCString("packed "); break;
1745 case DW_TAG_pointer_type: break; // print out a '*' after printing the full type below
1746 case DW_TAG_ptr_to_member_type: break; // print out a '*' after printing the full type below
1747 case DW_TAG_reference_type: break; // print out a '&' after printing the full type below
1748 case DW_TAG_restrict_type: s.PutCString("restrict "); break;
1749 case DW_TAG_set_type: s.PutCString("set "); break;
1750 case DW_TAG_shared_type: s.PutCString("shared "); break;
1751 case DW_TAG_string_type: s.PutCString("string "); break;
1752 case DW_TAG_structure_type: s.PutCString("struct "); break;
1753 case DW_TAG_subrange_type: s.PutCString("subrange "); break;
1754 case DW_TAG_subroutine_type: s.PutCString("function "); break;
1755 case DW_TAG_thrown_type: s.PutCString("thrown "); break;
1756 case DW_TAG_union_type: s.PutCString("union "); break;
1757 case DW_TAG_unspecified_type: s.PutCString("unspecified "); break;
1758 case DW_TAG_volatile_type: s.PutCString("volatile "); break;
1763 // Follow the DW_AT_type if possible
1764 DWARFFormValue form_value;
1765 if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_type, form_value))
1767 uint64_t next_die_offset = form_value.Reference(cu);
1768 result = AppendTypeName(dwarf2Data, cu, next_die_offset, s);
1771 switch (abbrevDecl->Tag())
1773 case DW_TAG_array_type: s.PutCString("[]"); break;
1774 case DW_TAG_pointer_type: s.PutChar('*'); break;
1775 case DW_TAG_ptr_to_member_type: s.PutChar('*'); break;
1776 case DW_TAG_reference_type: s.PutChar('&'); break;
1788 DWARFDebugInfoEntry::Contains (const DWARFDebugInfoEntry *die) const
1792 const dw_offset_t die_offset = die->GetOffset();
1793 if (die_offset > GetOffset())
1795 const DWARFDebugInfoEntry *sibling = GetSibling();
1796 assert (sibling); // TODO: take this out
1798 return die_offset < sibling->GetOffset();
1804 //----------------------------------------------------------------------
1805 // BuildAddressRangeTable
1806 //----------------------------------------------------------------------
1808 DWARFDebugInfoEntry::BuildAddressRangeTable
1810 SymbolFileDWARF* dwarf2Data,
1811 const DWARFCompileUnit* cu,
1812 DWARFDebugAranges* debug_aranges
1817 if (m_tag == DW_TAG_subprogram)
1819 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1820 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1821 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS))
1823 /// 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);
1824 debug_aranges->AppendRange (cu->GetOffset(), lo_pc, hi_pc);
1829 const DWARFDebugInfoEntry* child = GetFirstChild();
1832 child->BuildAddressRangeTable(dwarf2Data, cu, debug_aranges);
1833 child = child->GetSibling();
1838 //----------------------------------------------------------------------
1839 // BuildFunctionAddressRangeTable
1841 // This function is very similar to the BuildAddressRangeTable function
1842 // except that the actual DIE offset for the function is placed in the
1843 // table instead of the compile unit offset (which is the way the
1844 // standard .debug_aranges section does it).
1845 //----------------------------------------------------------------------
1847 DWARFDebugInfoEntry::BuildFunctionAddressRangeTable
1849 SymbolFileDWARF* dwarf2Data,
1850 const DWARFCompileUnit* cu,
1851 DWARFDebugAranges* debug_aranges
1856 if (m_tag == DW_TAG_subprogram)
1858 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1859 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1860 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS))
1862 // printf("BuildAddressRangeTable() 0x%8.8x: [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n", m_offset, lo_pc, hi_pc); // DEBUG ONLY
1863 debug_aranges->AppendRange (GetOffset(), lo_pc, hi_pc);
1867 const DWARFDebugInfoEntry* child = GetFirstChild();
1870 child->BuildFunctionAddressRangeTable(dwarf2Data, cu, debug_aranges);
1871 child = child->GetSibling();
1877 DWARFDebugInfoEntry::GetDeclContextDIEs (SymbolFileDWARF* dwarf2Data,
1878 DWARFCompileUnit* cu,
1879 DWARFDIECollection &decl_context_dies) const
1881 const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
1882 if (parent_decl_ctx_die && parent_decl_ctx_die != this)
1884 decl_context_dies.Append(parent_decl_ctx_die);
1885 parent_decl_ctx_die->GetDeclContextDIEs (dwarf2Data, cu, decl_context_dies);
1890 DWARFDebugInfoEntry::GetDWARFDeclContext (SymbolFileDWARF* dwarf2Data,
1891 DWARFCompileUnit* cu,
1892 DWARFDeclContext &dwarf_decl_ctx) const
1894 const dw_tag_t tag = Tag();
1895 if (tag != DW_TAG_compile_unit)
1897 dwarf_decl_ctx.AppendDeclContext(tag, GetName(dwarf2Data, cu));
1898 const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
1899 if (parent_decl_ctx_die && parent_decl_ctx_die != this)
1901 if (parent_decl_ctx_die->Tag() != DW_TAG_compile_unit)
1902 parent_decl_ctx_die->GetDWARFDeclContext (dwarf2Data, cu, dwarf_decl_ctx);
1909 DWARFDebugInfoEntry::MatchesDWARFDeclContext (SymbolFileDWARF* dwarf2Data,
1910 DWARFCompileUnit* cu,
1911 const DWARFDeclContext &dwarf_decl_ctx) const
1914 DWARFDeclContext this_dwarf_decl_ctx;
1915 GetDWARFDeclContext (dwarf2Data, cu, this_dwarf_decl_ctx);
1916 return this_dwarf_decl_ctx == dwarf_decl_ctx;
1919 const DWARFDebugInfoEntry *
1920 DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
1921 DWARFCompileUnit* cu) const
1923 DWARFDebugInfoEntry::Attributes attributes;
1924 GetAttributes(dwarf2Data, cu, NULL, attributes);
1925 return GetParentDeclContextDIE (dwarf2Data, cu, attributes);
1928 const DWARFDebugInfoEntry *
1929 DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
1930 DWARFCompileUnit* cu,
1931 const DWARFDebugInfoEntry::Attributes& attributes) const
1933 const DWARFDebugInfoEntry * die = this;
1937 // If this is the original DIE that we are searching for a declaration
1938 // for, then don't look in the cache as we don't want our own decl
1939 // context to be our decl context...
1944 case DW_TAG_compile_unit:
1945 case DW_TAG_namespace:
1946 case DW_TAG_structure_type:
1947 case DW_TAG_union_type:
1948 case DW_TAG_class_type:
1956 dw_offset_t die_offset;
1958 die_offset = attributes.FormValueAsUnsigned(dwarf2Data, DW_AT_specification, DW_INVALID_OFFSET);
1959 if (die_offset != DW_INVALID_OFFSET)
1961 const DWARFDebugInfoEntry *spec_die = cu->GetDIEPtr (die_offset);
1964 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = spec_die->GetParentDeclContextDIE (dwarf2Data, cu);
1965 if (spec_die_decl_ctx_die)
1966 return spec_die_decl_ctx_die;
1970 die_offset = attributes.FormValueAsUnsigned(dwarf2Data, DW_AT_abstract_origin, DW_INVALID_OFFSET);
1971 if (die_offset != DW_INVALID_OFFSET)
1973 const DWARFDebugInfoEntry *abs_die = cu->GetDIEPtr (die_offset);
1976 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = abs_die->GetParentDeclContextDIE (dwarf2Data, cu);
1977 if (abs_die_decl_ctx_die)
1978 return abs_die_decl_ctx_die;
1982 die = die->GetParent();
1989 DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data,
1990 DWARFCompileUnit* cu,
1991 std::string &storage) const
1993 DWARFDebugInfoEntry::Attributes attributes;
1994 GetAttributes(dwarf2Data, cu, NULL, attributes);
1995 return GetQualifiedName (dwarf2Data, cu, attributes, storage);
1999 DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data,
2000 DWARFCompileUnit* cu,
2001 const DWARFDebugInfoEntry::Attributes& attributes,
2002 std::string &storage) const
2005 const char *name = GetName (dwarf2Data, cu);
2009 const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
2011 // TODO: change this to get the correct decl context parent....
2012 while (parent_decl_ctx_die)
2014 const dw_tag_t parent_tag = parent_decl_ctx_die->Tag();
2017 case DW_TAG_namespace:
2019 const char *namespace_name = parent_decl_ctx_die->GetName (dwarf2Data, cu);
2022 storage.insert (0, "::");
2023 storage.insert (0, namespace_name);
2027 storage.insert (0, "(anonymous namespace)::");
2029 parent_decl_ctx_die = parent_decl_ctx_die->GetParentDeclContextDIE(dwarf2Data, cu);
2033 case DW_TAG_class_type:
2034 case DW_TAG_structure_type:
2035 case DW_TAG_union_type:
2037 const char *class_union_struct_name = parent_decl_ctx_die->GetName (dwarf2Data, cu);
2039 if (class_union_struct_name)
2041 storage.insert (0, "::");
2042 storage.insert (0, class_union_struct_name);
2044 parent_decl_ctx_die = parent_decl_ctx_die->GetParentDeclContextDIE(dwarf2Data, cu);
2049 parent_decl_ctx_die = NULL;
2054 if (storage.empty())
2055 storage.append ("::");
2057 storage.append (name);
2059 if (storage.empty())
2061 return storage.c_str();
2065 //----------------------------------------------------------------------
2067 //----------------------------------------------------------------------
2069 DWARFDebugInfoEntry::LookupAddress
2071 const dw_addr_t address,
2072 SymbolFileDWARF* dwarf2Data,
2073 const DWARFCompileUnit* cu,
2074 DWARFDebugInfoEntry** function_die,
2075 DWARFDebugInfoEntry** block_die
2078 bool found_address = false;
2081 bool check_children = false;
2082 bool match_addr_range = false;
2083 // printf("0x%8.8x: %30s: address = 0x%8.8x - ", m_offset, DW_TAG_value_to_name(tag), address);
2086 case DW_TAG_array_type : break;
2087 case DW_TAG_class_type : check_children = true; break;
2088 case DW_TAG_entry_point : break;
2089 case DW_TAG_enumeration_type : break;
2090 case DW_TAG_formal_parameter : break;
2091 case DW_TAG_imported_declaration : break;
2092 case DW_TAG_label : break;
2093 case DW_TAG_lexical_block : check_children = true; match_addr_range = true; break;
2094 case DW_TAG_member : break;
2095 case DW_TAG_pointer_type : break;
2096 case DW_TAG_reference_type : break;
2097 case DW_TAG_compile_unit : match_addr_range = true; break;
2098 case DW_TAG_string_type : break;
2099 case DW_TAG_structure_type : check_children = true; break;
2100 case DW_TAG_subroutine_type : break;
2101 case DW_TAG_typedef : break;
2102 case DW_TAG_union_type : break;
2103 case DW_TAG_unspecified_parameters : break;
2104 case DW_TAG_variant : break;
2105 case DW_TAG_common_block : check_children = true; break;
2106 case DW_TAG_common_inclusion : break;
2107 case DW_TAG_inheritance : break;
2108 case DW_TAG_inlined_subroutine : check_children = true; match_addr_range = true; break;
2109 case DW_TAG_module : match_addr_range = true; break;
2110 case DW_TAG_ptr_to_member_type : break;
2111 case DW_TAG_set_type : break;
2112 case DW_TAG_subrange_type : break;
2113 case DW_TAG_with_stmt : break;
2114 case DW_TAG_access_declaration : break;
2115 case DW_TAG_base_type : break;
2116 case DW_TAG_catch_block : match_addr_range = true; break;
2117 case DW_TAG_const_type : break;
2118 case DW_TAG_constant : break;
2119 case DW_TAG_enumerator : break;
2120 case DW_TAG_file_type : break;
2121 case DW_TAG_friend : break;
2122 case DW_TAG_namelist : break;
2123 case DW_TAG_namelist_item : break;
2124 case DW_TAG_packed_type : break;
2125 case DW_TAG_subprogram : match_addr_range = true; break;
2126 case DW_TAG_template_type_parameter : break;
2127 case DW_TAG_template_value_parameter : break;
2128 case DW_TAG_thrown_type : break;
2129 case DW_TAG_try_block : match_addr_range = true; break;
2130 case DW_TAG_variant_part : break;
2131 case DW_TAG_variable : break;
2132 case DW_TAG_volatile_type : break;
2133 case DW_TAG_dwarf_procedure : break;
2134 case DW_TAG_restrict_type : break;
2135 case DW_TAG_interface_type : break;
2136 case DW_TAG_namespace : check_children = true; break;
2137 case DW_TAG_imported_module : break;
2138 case DW_TAG_unspecified_type : break;
2139 case DW_TAG_partial_unit : break;
2140 case DW_TAG_imported_unit : break;
2141 case DW_TAG_shared_type : break;
2145 if (match_addr_range)
2147 dw_addr_t lo_pc = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
2148 if (lo_pc != LLDB_INVALID_ADDRESS)
2150 dw_addr_t hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, LLDB_INVALID_ADDRESS);
2151 if (hi_pc != LLDB_INVALID_ADDRESS)
2153 // 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);
2154 if ((lo_pc <= address) && (address < hi_pc))
2156 found_address = true;
2157 // puts("***MATCH***");
2160 case DW_TAG_compile_unit: // File
2161 check_children = ((function_die != NULL) || (block_die != NULL));
2164 case DW_TAG_subprogram: // Function
2166 *function_die = this;
2167 check_children = (block_die != NULL);
2170 case DW_TAG_inlined_subroutine: // Inlined Function
2171 case DW_TAG_lexical_block: // Block { } in code
2175 check_children = true;
2180 check_children = true;
2186 { // compile units may not have a valid high/low pc when there
2187 // are address gaps in subroutines so we must always search
2188 // if there is no valid high and low PC
2189 check_children = (m_tag == DW_TAG_compile_unit) && ((function_die != NULL) || (block_die != NULL));
2194 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET);
2195 if (debug_ranges_offset != DW_INVALID_OFFSET)
2197 DWARFDebugRanges::RangeList ranges;
2198 DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
2199 debug_ranges->FindRanges(debug_ranges_offset, ranges);
2200 // All DW_AT_ranges are relative to the base address of the
2201 // compile unit. We add the compile unit base address to make
2202 // sure all the addresses are properly fixed up.
2203 ranges.Slide (cu->GetBaseAddress());
2204 if (ranges.FindEntryThatContains(address))
2206 found_address = true;
2207 // puts("***MATCH***");
2210 case DW_TAG_compile_unit: // File
2211 check_children = ((function_die != NULL) || (block_die != NULL));
2214 case DW_TAG_subprogram: // Function
2216 *function_die = this;
2217 check_children = (block_die != NULL);
2220 case DW_TAG_inlined_subroutine: // Inlined Function
2221 case DW_TAG_lexical_block: // Block { } in code
2225 check_children = true;
2230 check_children = true;
2236 check_children = false;
2245 // printf("checking children\n");
2246 DWARFDebugInfoEntry* child = GetFirstChild();
2249 if (child->LookupAddress(address, dwarf2Data, cu, function_die, block_die))
2251 child = child->GetSibling();
2255 return found_address;
2258 const DWARFAbbreviationDeclaration*
2259 DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr (SymbolFileDWARF* dwarf2Data,
2260 const DWARFCompileUnit *cu,
2261 lldb::offset_t &offset) const
2265 offset = GetOffset();
2267 const DWARFAbbreviationDeclaration* abbrev_decl = cu->GetAbbreviations()->GetAbbreviationDeclaration (m_abbr_idx);
2270 // Make sure the abbreviation code still matches. If it doesn't and
2271 // the DWARF data was mmap'ed, the backing file might have been modified
2272 // which is bad news.
2273 const uint64_t abbrev_code = dwarf2Data->get_debug_info_data().GetULEB128 (&offset);
2275 if (abbrev_decl->Code() == abbrev_code)
2278 dwarf2Data->GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("0x%8.8x: the DWARF debug information has been modified (abbrev code was %u, and is now %u)",
2280 (uint32_t)abbrev_decl->Code(),
2281 (uint32_t)abbrev_code);
2284 offset = DW_INVALID_OFFSET;
2290 DWARFDebugInfoEntry::OffsetLessThan (const DWARFDebugInfoEntry& a, const DWARFDebugInfoEntry& b)
2292 return a.GetOffset() < b.GetOffset();
2296 DWARFDebugInfoEntry::DumpDIECollection (Stream &strm, DWARFDebugInfoEntry::collection &die_collection)
2298 DWARFDebugInfoEntry::const_iterator pos;
2299 DWARFDebugInfoEntry::const_iterator end = die_collection.end();
2300 strm.PutCString("\noffset parent sibling child\n");
2301 strm.PutCString("-------- -------- -------- --------\n");
2302 for (pos = die_collection.begin(); pos != end; ++pos)
2304 const DWARFDebugInfoEntry& die_ref = *pos;
2305 const DWARFDebugInfoEntry* p = die_ref.GetParent();
2306 const DWARFDebugInfoEntry* s = die_ref.GetSibling();
2307 const DWARFDebugInfoEntry* c = die_ref.GetFirstChild();
2308 strm.Printf("%.8x: %.8x %.8x %.8x 0x%4.4x %s%s\n",
2309 die_ref.GetOffset(),
2310 p ? p->GetOffset() : 0,
2311 s ? s->GetOffset() : 0,
2312 c ? c->GetOffset() : 0,
2314 DW_TAG_value_to_name(die_ref.Tag()),
2315 die_ref.HasChildren() ? " *" : "");