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.SetCompileUnit(CompileUnitAtIndex(i));
92 form_value.SetForm(FormAtIndex(i));
93 lldb::offset_t offset = DIEOffsetAtIndex(i);
94 return form_value.ExtractValue(dwarf2Data->get_debug_info_data(), &offset);
98 DWARFDebugInfoEntry::Attributes::FormValueAsUnsigned (SymbolFileDWARF* dwarf2Data, dw_attr_t attr, uint64_t fail_value) const
100 const uint32_t attr_idx = FindAttributeIndex (attr);
101 if (attr_idx != UINT32_MAX)
102 return FormValueAsUnsignedAtIndex (dwarf2Data, attr_idx, fail_value);
107 DWARFDebugInfoEntry::Attributes::FormValueAsUnsignedAtIndex(SymbolFileDWARF* dwarf2Data, uint32_t i, uint64_t fail_value) const
109 DWARFFormValue form_value;
110 if (ExtractFormValueAtIndex(dwarf2Data, i, form_value))
111 return form_value.Reference();
118 DWARFDebugInfoEntry::FastExtract
120 const DWARFDataExtractor& debug_info_data,
121 const DWARFCompileUnit* cu,
122 const uint8_t *fixed_form_sizes,
123 lldb::offset_t *offset_ptr
126 m_offset = *offset_ptr;
129 m_empty_children = false;
130 const uint64_t abbr_idx = debug_info_data.GetULEB128 (offset_ptr);
131 assert (abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
132 m_abbr_idx = abbr_idx;
134 //assert (fixed_form_sizes); // For best performance this should be specified!
138 lldb::offset_t offset = *offset_ptr;
140 const DWARFAbbreviationDeclaration *abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration(m_abbr_idx);
142 if (abbrevDecl == NULL)
144 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",
147 // WE can't parse anymore if the DWARF is borked...
148 *offset_ptr = UINT32_MAX;
151 m_tag = abbrevDecl->Tag();
152 m_has_children = abbrevDecl->HasChildren();
153 // Skip all data in the .debug_info for the attributes
154 const uint32_t numAttributes = abbrevDecl->NumAttributes();
157 for (i=0; i<numAttributes; ++i)
159 form = abbrevDecl->GetFormByIndexUnchecked(i);
161 const uint8_t fixed_skip_size = fixed_form_sizes [form];
163 offset += fixed_skip_size;
166 bool form_is_indirect = false;
169 form_is_indirect = false;
170 uint32_t form_size = 0;
173 // Blocks if inlined data that have a length field and the data bytes
174 // inlined in the .debug_info
175 case DW_FORM_exprloc :
176 case DW_FORM_block : form_size = debug_info_data.GetULEB128 (&offset); break;
177 case DW_FORM_block1 : form_size = debug_info_data.GetU8_unchecked (&offset); break;
178 case DW_FORM_block2 : form_size = debug_info_data.GetU16_unchecked (&offset);break;
179 case DW_FORM_block4 : form_size = debug_info_data.GetU32_unchecked (&offset);break;
181 // Inlined NULL terminated C-strings
182 case DW_FORM_string :
183 debug_info_data.GetCStr (&offset);
186 // Compile unit address sized values
188 form_size = cu->GetAddressByteSize();
190 case DW_FORM_ref_addr :
191 if (cu->GetVersion() <= 2)
192 form_size = cu->GetAddressByteSize();
194 form_size = cu->IsDWARF64() ? 8 : 4;
198 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);
241 case DW_FORM_sec_offset :
242 if (cu->IsDWARF64 ())
243 debug_info_data.GetU64 (offset_ptr);
245 debug_info_data.GetU32 (offset_ptr);
249 *offset_ptr = m_offset;
254 } while (form_is_indirect);
257 *offset_ptr = offset;
263 m_has_children = false;
264 return true; // NULL debug tag entry
270 //----------------------------------------------------------------------
273 // Extract a debug info entry for a given compile unit from the
274 // .debug_info and .debug_abbrev data within the SymbolFileDWARF class
275 // starting at the given offset
276 //----------------------------------------------------------------------
278 DWARFDebugInfoEntry::Extract
280 SymbolFileDWARF* dwarf2Data,
281 const DWARFCompileUnit* cu,
282 lldb::offset_t *offset_ptr
285 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
286 // const DWARFDataExtractor& debug_str_data = dwarf2Data->get_debug_str_data();
287 const uint32_t cu_end_offset = cu->GetNextCompileUnitOffset();
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(cu, form);
323 if (form_value.ExtractValue(debug_info_data, &offset))
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->GetAddressByteSize();
353 case DW_FORM_ref_addr :
354 if (cu->GetVersion() <= 2)
355 form_size = cu->GetAddressByteSize();
357 form_size = cu->IsDWARF64() ? 8 : 4;
361 case DW_FORM_flag_present:
387 case DW_FORM_ref_sig8 :
391 // signed or unsigned LEB 128 values
394 case DW_FORM_ref_udata :
395 debug_info_data.Skip_LEB128(&offset);
398 case DW_FORM_indirect :
399 form = debug_info_data.GetULEB128(&offset);
400 form_is_indirect = true;
404 case DW_FORM_sec_offset :
405 if (cu->IsDWARF64 ())
406 debug_info_data.GetU64 (offset_ptr);
408 debug_info_data.GetU32 (offset_ptr);
412 *offset_ptr = offset;
417 } while (form_is_indirect);
420 *offset_ptr = offset;
427 m_has_children = false;
428 *offset_ptr = offset;
429 return true; // NULL debug tag entry
436 //----------------------------------------------------------------------
439 // Dumps all of a debug information entries parents up until oldest and
440 // all of it's attributes to the specified stream.
441 //----------------------------------------------------------------------
443 DWARFDebugInfoEntry::DumpAncestry
445 SymbolFileDWARF* dwarf2Data,
446 const DWARFCompileUnit* cu,
447 const DWARFDebugInfoEntry* oldest,
449 uint32_t recurse_depth
452 const DWARFDebugInfoEntry* parent = GetParent();
453 if (parent && parent != oldest)
454 parent->DumpAncestry(dwarf2Data, cu, oldest, s, 0);
455 Dump(dwarf2Data, cu, s, recurse_depth);
458 //----------------------------------------------------------------------
459 // Compare two DIE by comparing all their attributes values, and
460 // following all DW_FORM_ref attributes and comparing their contents as
461 // well (except for DW_AT_sibling attributes.
463 // DWARFDebugInfoEntry::CompareState compare_state;
464 // int result = DWARFDebugInfoEntry::Compare(this, 0x00017ccb, 0x0001eb2b, compare_state, false, true);
465 //----------------------------------------------------------------------
467 //DWARFDebugInfoEntry::Compare
469 // SymbolFileDWARF* dwarf2Data,
470 // dw_offset_t a_die_offset,
471 // dw_offset_t b_die_offset,
472 // CompareState &compare_state,
473 // bool compare_siblings,
474 // bool compare_children
477 // if (a_die_offset == b_die_offset)
480 // DWARFCompileUnitSP a_cu_sp;
481 // DWARFCompileUnitSP b_cu_sp;
482 // const DWARFDebugInfoEntry* a_die = dwarf2Data->DebugInfo()->GetDIEPtr(a_die_offset, &a_cu_sp);
483 // const DWARFDebugInfoEntry* b_die = dwarf2Data->DebugInfo()->GetDIEPtr(b_die_offset, &b_cu_sp);
485 // return Compare(dwarf2Data, a_cu_sp.get(), a_die, b_cu_sp.get(), b_die, compare_state, compare_siblings, compare_children);
489 //DWARFDebugInfoEntry::Compare
491 // SymbolFileDWARF* dwarf2Data,
492 // DWARFCompileUnit* a_cu, const DWARFDebugInfoEntry* a_die,
493 // DWARFCompileUnit* b_cu, const DWARFDebugInfoEntry* b_die,
494 // CompareState &compare_state,
495 // bool compare_siblings,
496 // bool compare_children
499 // if (a_die == b_die)
502 // if (!compare_state.AddTypePair(a_die->GetOffset(), b_die->GetOffset()))
504 // // We are already comparing both of these types, so let
505 // // compares complete for the real result
509 // //printf("DWARFDebugInfoEntry::Compare(0x%8.8x, 0x%8.8x)\n", a_die->GetOffset(), b_die->GetOffset());
511 // // Do we have two valid DIEs?
512 // if (a_die && b_die)
514 // // Both DIE are valid
517 // const dw_tag_t a_tag = a_die->Tag();
518 // const dw_tag_t b_tag = b_die->Tag();
519 // if (a_tag == 0 && b_tag == 0)
522 // //printf(" comparing tags: %s and %s\n", DW_TAG_value_to_name(a_tag), DW_TAG_value_to_name(b_tag));
524 // if (a_tag < b_tag)
526 // else if (a_tag > b_tag)
529 // DWARFDebugInfoEntry::Attributes a_attrs;
530 // DWARFDebugInfoEntry::Attributes b_attrs;
531 // size_t a_attr_count = a_die->GetAttributes(dwarf2Data, a_cu, a_attrs);
532 // size_t b_attr_count = b_die->GetAttributes(dwarf2Data, b_cu, b_attrs);
533 // if (a_attr_count != b_attr_count)
535 // a_attrs.RemoveAttribute(DW_AT_sibling);
536 // b_attrs.RemoveAttribute(DW_AT_sibling);
539 // a_attr_count = a_attrs.Size();
540 // b_attr_count = b_attrs.Size();
542 // DWARFFormValue a_form_value;
543 // DWARFFormValue b_form_value;
545 // if (a_attr_count != b_attr_count)
547 // uint32_t is_decl_index = a_attrs.FindAttributeIndex(DW_AT_declaration);
548 // uint32_t a_name_index = UINT32_MAX;
549 // uint32_t b_name_index = UINT32_MAX;
550 // if (is_decl_index != UINT32_MAX)
552 // if (a_attr_count == 2)
554 // a_name_index = a_attrs.FindAttributeIndex(DW_AT_name);
555 // b_name_index = b_attrs.FindAttributeIndex(DW_AT_name);
560 // is_decl_index = b_attrs.FindAttributeIndex(DW_AT_declaration);
561 // if (is_decl_index != UINT32_MAX && a_attr_count == 2)
563 // a_name_index = a_attrs.FindAttributeIndex(DW_AT_name);
564 // b_name_index = b_attrs.FindAttributeIndex(DW_AT_name);
567 // if (a_name_index != UINT32_MAX && b_name_index != UINT32_MAX)
569 // if (a_attrs.ExtractFormValueAtIndex(dwarf2Data, a_name_index, a_form_value) &&
570 // b_attrs.ExtractFormValueAtIndex(dwarf2Data, b_name_index, b_form_value))
572 // result = DWARFFormValue::Compare (a_form_value, b_form_value, a_cu, b_cu, &dwarf2Data->get_debug_str_data());
575 // a_attr_count = b_attr_count = 0;
576 // compare_children = false;
582 // if (a_attr_count < b_attr_count)
584 // if (a_attr_count > b_attr_count)
588 // // The number of attributes are the same...
589 // if (a_attr_count > 0)
591 // const DWARFDataExtractor* debug_str_data_ptr = &dwarf2Data->get_debug_str_data();
594 // for (i=0; i<a_attr_count; ++i)
596 // const dw_attr_t a_attr = a_attrs.AttributeAtIndex(i);
597 // const dw_attr_t b_attr = b_attrs.AttributeAtIndex(i);
598 // //printf(" comparing attributes\n\t\t0x%8.8x: %s %s\t\t0x%8.8x: %s %s\n",
599 // // a_attrs.DIEOffsetAtIndex(i), DW_FORM_value_to_name(a_attrs.FormAtIndex(i)), DW_AT_value_to_name(a_attr),
600 // // b_attrs.DIEOffsetAtIndex(i), DW_FORM_value_to_name(b_attrs.FormAtIndex(i)), DW_AT_value_to_name(b_attr));
602 // if (a_attr < b_attr)
604 // else if (a_attr > b_attr)
609 // // Since we call a form of GetAttributes which inlines the
610 // // attributes from DW_AT_abstract_origin and DW_AT_specification
611 // // we don't care if their values mismatch...
612 // case DW_AT_abstract_origin:
613 // case DW_AT_specification:
614 // case DW_AT_sibling:
615 // case DW_AT_containing_type:
616 // //printf(" action = IGNORE\n");
621 // if (a_attrs.ExtractFormValueAtIndex(dwarf2Data, i, a_form_value) &&
622 // b_attrs.ExtractFormValueAtIndex(dwarf2Data, i, b_form_value))
623 // result = DWARFFormValue::Compare (a_form_value, b_form_value, a_cu, b_cu, debug_str_data_ptr);
627 // //printf("\t result = %i\n", result);
631 // // Attributes weren't equal, lets see if we care?
634 // case DW_AT_decl_file:
635 // // TODO: add the ability to compare files in two different compile units
638 // //printf(" action = RETURN RESULT\n");
639 // return result; // Only return the compare results when the compile units are the same and the decl_file attributes can be compared
644 // //printf(" action = IGNORE\n");
649 // switch (a_attrs.FormAtIndex(i))
651 // case DW_FORM_ref1:
652 // case DW_FORM_ref2:
653 // case DW_FORM_ref4:
654 // case DW_FORM_ref8:
655 // case DW_FORM_ref_udata:
656 // case DW_FORM_ref_addr:
657 // //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));
658 // // These attribute values refer to other DIEs, so lets compare those instead of their DIE offsets...
659 // result = Compare(dwarf2Data, a_form_value.Reference(a_cu), b_form_value.Reference(b_cu), compare_state, false, true);
665 // // We do care that they were different, return this result...
666 // //printf(" action = RETURN RESULT\n");
673 // //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));
675 // if (compare_children)
677 // bool a_has_children = a_die->HasChildren();
678 // bool b_has_children = b_die->HasChildren();
679 // if (a_has_children == b_has_children)
681 // // Both either have kids or don't
682 // if (a_has_children)
683 // result = Compare( dwarf2Data,
684 // a_cu, a_die->GetFirstChild(),
685 // b_cu, b_die->GetFirstChild(),
686 // compare_state, true, compare_children);
690 // else if (!a_has_children)
691 // result = -1; // A doesn't have kids, but B does
693 // result = 1; // A has kids, but B doesn't
696 // if (compare_siblings)
698 // result = Compare( dwarf2Data,
699 // a_cu, a_die->GetSibling(),
700 // b_cu, b_die->GetSibling(),
701 // compare_state, true, compare_children);
707 // if (a_die == NULL)
708 // return -1; // a_die is NULL, yet b_die is non-NULL
710 // return 1; // a_die is non-NULL, yet b_die is NULL
716 //DWARFDebugInfoEntry::Compare
718 // SymbolFileDWARF* dwarf2Data,
719 // const DWARFCompileUnit* cu_a,
720 // const DWARFDebugInfoEntry* die_a,
721 // const DWARFCompileUnit* cu_a,
722 // const DWARFDebugInfoEntry* die_b,
723 // CompareState &compare_state
728 //----------------------------------------------------------------------
729 // GetDIENamesAndRanges
731 // Gets the valid address ranges for a given DIE by looking for a
732 // DW_AT_low_pc/DW_AT_high_pc pair, DW_AT_entry_pc, or DW_AT_ranges
734 //----------------------------------------------------------------------
736 DWARFDebugInfoEntry::GetDIENamesAndRanges
738 SymbolFileDWARF* dwarf2Data,
739 const DWARFCompileUnit* cu,
741 const char * &mangled,
742 DWARFDebugRanges::RangeList& ranges,
749 DWARFExpression *frame_base
752 if (dwarf2Data == NULL)
755 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
756 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
757 std::vector<dw_offset_t> die_offsets;
758 bool set_frame_base_loclist_addr = false;
760 lldb::offset_t offset;
761 const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
763 lldb::ModuleSP module = dwarf2Data->GetObjectFile()->GetModule();
767 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
769 if (!debug_info_data.ValidOffset(offset))
772 const uint32_t numAttributes = abbrevDecl->NumAttributes();
776 bool do_offset = false;
778 for (i=0; i<numAttributes; ++i)
780 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
781 DWARFFormValue form_value(cu, form);
782 if (form_value.ExtractValue(debug_info_data, &offset))
787 lo_pc = form_value.Unsigned();
795 lo_pc = form_value.Unsigned();
799 hi_pc = form_value.Unsigned();
800 if (form_value.Form() != DW_FORM_addr)
802 if (lo_pc == LLDB_INVALID_ADDRESS)
803 do_offset = hi_pc != LLDB_INVALID_ADDRESS;
805 hi_pc += lo_pc; // DWARF 4 introduces <offset-from-lo-pc> to save on relocations
811 const DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
812 debug_ranges->FindRanges(form_value.Unsigned(), ranges);
813 // All DW_AT_ranges are relative to the base address of the
814 // compile unit. We add the compile unit base address to make
815 // sure all the addresses are properly fixed up.
816 ranges.Slide(cu->GetBaseAddress());
822 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
825 case DW_AT_MIPS_linkage_name:
826 case DW_AT_linkage_name:
828 mangled = form_value.AsCString(&dwarf2Data->get_debug_str_data());
831 case DW_AT_abstract_origin:
832 die_offsets.push_back(form_value.Reference());
835 case DW_AT_specification:
836 die_offsets.push_back(form_value.Reference());
839 case DW_AT_decl_file:
841 decl_file = form_value.Unsigned();
844 case DW_AT_decl_line:
846 decl_line = form_value.Unsigned();
849 case DW_AT_decl_column:
850 if (decl_column == 0)
851 decl_column = form_value.Unsigned();
854 case DW_AT_call_file:
856 call_file = form_value.Unsigned();
859 case DW_AT_call_line:
861 call_line = form_value.Unsigned();
864 case DW_AT_call_column:
865 if (call_column == 0)
866 call_column = form_value.Unsigned();
869 case DW_AT_frame_base:
872 if (form_value.BlockData())
874 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
875 uint32_t block_length = form_value.Unsigned();
876 frame_base->SetOpcodeData(module, debug_info_data, block_offset, block_length);
880 const DWARFDataExtractor &debug_loc_data = dwarf2Data->get_debug_loc_data();
881 const dw_offset_t debug_loc_offset = form_value.Unsigned();
883 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
884 if (loc_list_length > 0)
886 frame_base->SetOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
887 if (lo_pc != LLDB_INVALID_ADDRESS)
889 assert (lo_pc >= cu->GetBaseAddress());
890 frame_base->SetLocationListSlide(lo_pc - cu->GetBaseAddress());
894 set_frame_base_loclist_addr = true;
908 if (ranges.IsEmpty())
910 if (lo_pc != LLDB_INVALID_ADDRESS)
912 if (hi_pc != LLDB_INVALID_ADDRESS && hi_pc > lo_pc)
913 ranges.Append(DWARFDebugRanges::Range (lo_pc, hi_pc - lo_pc));
915 ranges.Append(DWARFDebugRanges::Range (lo_pc, 0));
919 if (set_frame_base_loclist_addr)
921 dw_addr_t lowest_range_pc = ranges.GetMinRangeBase(0);
922 assert (lowest_range_pc >= cu->GetBaseAddress());
923 frame_base->SetLocationListSlide (lowest_range_pc - cu->GetBaseAddress());
926 if (ranges.IsEmpty() || name == NULL || mangled == NULL)
928 std::vector<dw_offset_t>::const_iterator pos;
929 std::vector<dw_offset_t>::const_iterator end = die_offsets.end();
930 for (pos = die_offsets.begin(); pos != end; ++pos)
932 DWARFCompileUnitSP cu_sp_ptr;
933 const DWARFDebugInfoEntry* die = NULL;
934 dw_offset_t die_offset = *pos;
935 if (die_offset != DW_INVALID_OFFSET)
937 die = dwarf2Data->DebugInfo()->GetDIEPtr(die_offset, &cu_sp_ptr);
939 die->GetDIENamesAndRanges(dwarf2Data, cu_sp_ptr.get(), name, mangled, ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column);
943 return !ranges.IsEmpty();
946 //----------------------------------------------------------------------
949 // Dumps a debug information entry and all of it's attributes to the
951 //----------------------------------------------------------------------
953 DWARFDebugInfoEntry::Dump
955 SymbolFileDWARF* dwarf2Data,
956 const DWARFCompileUnit* cu,
958 uint32_t recurse_depth
961 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
962 lldb::offset_t offset = m_offset;
964 if (debug_info_data.ValidOffset(offset))
966 dw_uleb128_t abbrCode = debug_info_data.GetULEB128(&offset);
968 s.Printf("\n0x%8.8x: ", m_offset);
970 if (abbrCode != m_abbr_idx)
972 s.Printf( "error: DWARF has been modified\n");
976 const DWARFAbbreviationDeclaration* abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration (abbrCode);
980 s.PutCString(DW_TAG_value_to_name(abbrevDecl->Tag()));
981 s.Printf( " [%u] %c\n", abbrCode, abbrevDecl->HasChildren() ? '*':' ');
983 // Dump all data in the .debug_info for the attributes
984 const uint32_t numAttributes = abbrevDecl->NumAttributes();
988 for (i=0; i<numAttributes; ++i)
990 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
992 DumpAttribute(dwarf2Data, cu, debug_info_data, &offset, s, attr, form);
995 const DWARFDebugInfoEntry* child = GetFirstChild();
996 if (recurse_depth > 0 && child)
1002 child->Dump(dwarf2Data, cu, s, recurse_depth-1);
1003 child = child->GetSibling();
1009 s.Printf( "Abbreviation code note found in 'debug_abbrev' class for code: %u\n", abbrCode);
1013 s.Printf( "NULL\n");
1019 DWARFDebugInfoEntry::DumpLocation
1021 SymbolFileDWARF* dwarf2Data,
1022 DWARFCompileUnit* cu,
1026 const DWARFDebugInfoEntry *cu_die = cu->GetCompileUnitDIEOnly();
1027 const char *cu_name = NULL;
1029 cu_name = cu_die->GetName (dwarf2Data, cu);
1030 const char *obj_file_name = NULL;
1031 ObjectFile *obj_file = dwarf2Data->GetObjectFile();
1033 obj_file_name = obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>");
1034 const char *die_name = GetName (dwarf2Data, cu);
1035 s.Printf ("0x%8.8x/0x%8.8x: %-30s (from %s in %s)",
1038 die_name ? die_name : "",
1039 cu_name ? cu_name : "<NULL>",
1040 obj_file_name ? obj_file_name : "<NULL>");
1043 //----------------------------------------------------------------------
1046 // Dumps a debug information entry attribute along with it's form. Any
1047 // special display of attributes is done (disassemble location lists,
1048 // show enumeration values for attributes, etc).
1049 //----------------------------------------------------------------------
1051 DWARFDebugInfoEntry::DumpAttribute
1053 SymbolFileDWARF* dwarf2Data,
1054 const DWARFCompileUnit* cu,
1055 const DWARFDataExtractor& debug_info_data,
1056 lldb::offset_t *offset_ptr,
1062 bool verbose = s.GetVerbose();
1063 bool show_form = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm);
1065 const DWARFDataExtractor* debug_str_data = dwarf2Data ? &dwarf2Data->get_debug_str_data() : NULL;
1067 s.Offset (*offset_ptr);
1070 s.Indent(DW_AT_value_to_name(attr));
1074 s.Printf( "[%s", DW_FORM_value_to_name(form));
1077 DWARFFormValue form_value(cu, form);
1079 if (!form_value.ExtractValue(debug_info_data, offset_ptr))
1084 if (form == DW_FORM_indirect)
1086 s.Printf( " [%s]", DW_FORM_value_to_name(form_value.Form()));
1094 // Always dump form value if verbose is enabled
1097 form_value.Dump(s, debug_str_data);
1101 // Check to see if we have any special attribute formatters
1104 case DW_AT_stmt_list:
1105 if ( verbose ) s.PutCString(" ( ");
1106 s.Printf( "0x%8.8" PRIx64, form_value.Unsigned());
1107 if ( verbose ) s.PutCString(" )");
1110 case DW_AT_language:
1111 if ( verbose ) s.PutCString(" ( ");
1112 s.PutCString(DW_LANG_value_to_name(form_value.Unsigned()));
1113 if ( verbose ) s.PutCString(" )");
1116 case DW_AT_encoding:
1117 if ( verbose ) s.PutCString(" ( ");
1118 s.PutCString(DW_ATE_value_to_name(form_value.Unsigned()));
1119 if ( verbose ) s.PutCString(" )");
1122 case DW_AT_frame_base:
1123 case DW_AT_location:
1124 case DW_AT_data_member_location:
1126 const uint8_t* blockData = form_value.BlockData();
1130 form_value.Dump(s, debug_str_data);
1132 // Location description is inlined in data in the form value
1133 DWARFDataExtractor locationData(debug_info_data, (*offset_ptr) - form_value.Unsigned(), form_value.Unsigned());
1134 if ( verbose ) s.PutCString(" ( ");
1135 print_dwarf_expression (s, locationData, DWARFCompileUnit::GetAddressByteSize(cu), 4, false);
1136 if ( verbose ) s.PutCString(" )");
1140 // We have a location list offset as the value that is
1141 // the offset into the .debug_loc section that describes
1142 // the value over it's lifetime
1143 uint64_t debug_loc_offset = form_value.Unsigned();
1147 form_value.Dump(s, debug_str_data);
1148 DWARFLocationList::Dump(s, cu, dwarf2Data->get_debug_loc_data(), debug_loc_offset);
1153 form_value.Dump(s, NULL);
1159 case DW_AT_abstract_origin:
1160 case DW_AT_specification:
1162 uint64_t abstract_die_offset = form_value.Reference();
1163 form_value.Dump(s, debug_str_data);
1164 // *ostrm_ptr << HEX32 << abstract_die_offset << " ( ";
1165 if ( verbose ) s.PutCString(" ( ");
1166 GetName(dwarf2Data, cu, abstract_die_offset, s);
1167 if ( verbose ) s.PutCString(" )");
1173 uint64_t type_die_offset = form_value.Reference();
1175 form_value.Dump(s, debug_str_data);
1176 s.PutCString(" ( ");
1177 AppendTypeName(dwarf2Data, cu, type_die_offset, s);
1185 form_value.Dump(s, debug_str_data);
1186 lldb::offset_t ranges_offset = form_value.Unsigned();
1187 dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0;
1189 DWARFDebugRanges::Dump(s, dwarf2Data->get_debug_ranges_data(), &ranges_offset, base_addr);
1195 form_value.Dump(s, debug_str_data);
1199 s.PutCString(" )\n");
1202 //----------------------------------------------------------------------
1203 // Get all attribute values for a given DIE, including following any
1204 // specification or abstract origin attributes and including those in
1205 // the results. Any duplicate attributes will have the first instance
1206 // take precedence (this can happen for declaration attributes).
1207 //----------------------------------------------------------------------
1209 DWARFDebugInfoEntry::GetAttributes
1211 SymbolFileDWARF* dwarf2Data,
1212 const DWARFCompileUnit* cu,
1213 const uint8_t *fixed_form_sizes,
1214 DWARFDebugInfoEntry::Attributes& attributes,
1218 lldb::offset_t offset;
1219 const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1223 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
1225 if (fixed_form_sizes == NULL)
1226 fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(cu->GetAddressByteSize(), cu->IsDWARF64());
1228 const uint32_t num_attributes = abbrevDecl->NumAttributes();
1232 for (i=0; i<num_attributes; ++i)
1234 abbrevDecl->GetAttrAndFormByIndexUnchecked (i, attr, form);
1236 // If we are tracking down DW_AT_specification or DW_AT_abstract_origin
1237 // attributes, the depth will be non-zero. We need to omit certain
1238 // attributes that don't make sense.
1242 case DW_AT_declaration:
1245 // This attribute doesn't make sense when combined with
1246 // the DIE that references this DIE. We know a DIE is
1247 // referencing this DIE because curr_depth is not zero
1252 attributes.Append(cu, offset, attr, form);
1256 if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin))
1258 DWARFFormValue form_value (cu, form);
1259 if (form_value.ExtractValue(debug_info_data, &offset))
1261 const DWARFDebugInfoEntry* die = NULL;
1262 dw_offset_t die_offset = form_value.Reference();
1263 if (cu->ContainsDIEOffset(die_offset))
1265 die = const_cast<DWARFCompileUnit*>(cu)->GetDIEPtr(die_offset);
1267 die->GetAttributes(dwarf2Data, cu, fixed_form_sizes, attributes, curr_depth + 1);
1271 DWARFCompileUnitSP cu_sp_ptr;
1272 die = const_cast<SymbolFileDWARF*>(dwarf2Data)->DebugInfo()->GetDIEPtr(die_offset, &cu_sp_ptr);
1274 die->GetAttributes(dwarf2Data, cu_sp_ptr.get(), fixed_form_sizes, attributes, curr_depth + 1);
1280 const uint8_t fixed_skip_size = fixed_form_sizes [form];
1281 if (fixed_skip_size)
1282 offset += fixed_skip_size;
1284 DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
1292 return attributes.Size();
1296 //----------------------------------------------------------------------
1297 // GetAttributeValue
1299 // Get the value of an attribute and return the .debug_info offset of the
1300 // attribute if it was properly extracted into form_value, or zero
1301 // if we fail since an offset of zero is invalid for an attribute (it
1302 // would be a compile unit header).
1303 //----------------------------------------------------------------------
1305 DWARFDebugInfoEntry::GetAttributeValue
1307 SymbolFileDWARF* dwarf2Data,
1308 const DWARFCompileUnit* cu,
1309 const dw_attr_t attr,
1310 DWARFFormValue& form_value,
1311 dw_offset_t* end_attr_offset_ptr
1314 lldb::offset_t offset;
1315 const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1319 uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
1321 if (attr_idx != DW_INVALID_INDEX)
1323 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
1326 while (idx<attr_idx)
1327 DWARFFormValue::SkipValue(abbrevDecl->GetFormByIndex(idx++), debug_info_data, &offset, cu);
1329 const dw_offset_t attr_offset = offset;
1330 form_value.SetCompileUnit(cu);
1331 form_value.SetForm(abbrevDecl->GetFormByIndex(idx));
1332 if (form_value.ExtractValue(debug_info_data, &offset))
1334 if (end_attr_offset_ptr)
1335 *end_attr_offset_ptr = offset;
1344 //----------------------------------------------------------------------
1345 // GetAttributeValueAsString
1347 // Get the value of an attribute as a string return it. The resulting
1348 // pointer to the string data exists within the supplied SymbolFileDWARF
1349 // and will only be available as long as the SymbolFileDWARF is still around
1350 // and it's content doesn't change.
1351 //----------------------------------------------------------------------
1353 DWARFDebugInfoEntry::GetAttributeValueAsString
1355 SymbolFileDWARF* dwarf2Data,
1356 const DWARFCompileUnit* cu,
1357 const dw_attr_t attr,
1358 const char* fail_value) const
1360 DWARFFormValue form_value;
1361 if (GetAttributeValue(dwarf2Data, cu, attr, form_value))
1362 return form_value.AsCString(&dwarf2Data->get_debug_str_data());
1366 //----------------------------------------------------------------------
1367 // GetAttributeValueAsUnsigned
1369 // Get the value of an attribute as unsigned and return it.
1370 //----------------------------------------------------------------------
1372 DWARFDebugInfoEntry::GetAttributeValueAsUnsigned
1374 SymbolFileDWARF* dwarf2Data,
1375 const DWARFCompileUnit* cu,
1376 const dw_attr_t attr,
1380 DWARFFormValue form_value;
1381 if (GetAttributeValue(dwarf2Data, cu, attr, form_value))
1382 return form_value.Unsigned();
1386 //----------------------------------------------------------------------
1387 // GetAttributeValueAsSigned
1389 // Get the value of an attribute a signed value and return it.
1390 //----------------------------------------------------------------------
1392 DWARFDebugInfoEntry::GetAttributeValueAsSigned
1394 SymbolFileDWARF* dwarf2Data,
1395 const DWARFCompileUnit* cu,
1396 const dw_attr_t attr,
1400 DWARFFormValue form_value;
1401 if (GetAttributeValue(dwarf2Data, cu, attr, form_value))
1402 return form_value.Signed();
1406 //----------------------------------------------------------------------
1407 // GetAttributeValueAsReference
1409 // Get the value of an attribute as reference and fix up and compile
1410 // unit relative offsets as needed.
1411 //----------------------------------------------------------------------
1413 DWARFDebugInfoEntry::GetAttributeValueAsReference
1415 SymbolFileDWARF* dwarf2Data,
1416 const DWARFCompileUnit* cu,
1417 const dw_attr_t attr,
1421 DWARFFormValue form_value;
1422 if (GetAttributeValue(dwarf2Data, cu, attr, form_value))
1423 return form_value.Reference();
1427 //----------------------------------------------------------------------
1428 // GetAttributeHighPC
1430 // Get the hi_pc, adding hi_pc to lo_pc when specified
1431 // as an <offset-from-low-pc>.
1433 // Returns the hi_pc or fail_value.
1434 //----------------------------------------------------------------------
1436 DWARFDebugInfoEntry::GetAttributeHighPC
1438 SymbolFileDWARF* dwarf2Data,
1439 const DWARFCompileUnit* cu,
1444 DWARFFormValue form_value;
1446 if (GetAttributeValue(dwarf2Data, cu, DW_AT_high_pc, form_value))
1448 dw_addr_t hi_pc = form_value.Unsigned();
1449 if (form_value.Form() != DW_FORM_addr)
1450 hi_pc += lo_pc; // DWARF4 can specify the hi_pc as an <offset-from-lowpc>
1456 //----------------------------------------------------------------------
1457 // GetAttributeAddressRange
1459 // Get the lo_pc and hi_pc, adding hi_pc to lo_pc when specified
1460 // as an <offset-from-low-pc>.
1462 // Returns true or sets lo_pc and hi_pc to fail_value.
1463 //----------------------------------------------------------------------
1465 DWARFDebugInfoEntry::GetAttributeAddressRange
1467 SymbolFileDWARF* dwarf2Data,
1468 const DWARFCompileUnit* cu,
1474 lo_pc = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_low_pc, fail_value);
1475 if (lo_pc != fail_value)
1477 hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, fail_value);
1478 if (hi_pc != fail_value)
1487 DWARFDebugInfoEntry::GetAttributeAddressRanges(SymbolFileDWARF* dwarf2Data,
1488 const DWARFCompileUnit* cu,
1489 DWARFDebugRanges::RangeList &ranges,
1490 bool check_hi_lo_pc) const
1494 dw_offset_t ranges_offset = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET);
1495 if (ranges_offset != DW_INVALID_OFFSET)
1497 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET);
1498 if (debug_ranges_offset != DW_INVALID_OFFSET)
1500 DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
1502 debug_ranges->FindRanges(debug_ranges_offset, ranges);
1503 ranges.Slide (cu->GetBaseAddress());
1506 else if (check_hi_lo_pc)
1508 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1509 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1510 if (GetAttributeAddressRange (dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS))
1513 ranges.Append(DWARFDebugRanges::RangeList::Entry(lo_pc, hi_pc - lo_pc));
1516 return ranges.GetSize();
1519 //----------------------------------------------------------------------
1520 // GetAttributeValueAsLocation
1522 // Get the value of an attribute as reference and fix up and compile
1523 // unit relative offsets as needed.
1524 //----------------------------------------------------------------------
1526 DWARFDebugInfoEntry::GetAttributeValueAsLocation
1528 SymbolFileDWARF* dwarf2Data,
1529 const DWARFCompileUnit* cu,
1530 const dw_attr_t attr,
1531 DWARFDataExtractor& location_data,
1532 uint32_t &block_size
1536 DWARFFormValue form_value;
1538 // Empty out data in case we don't find anything
1539 location_data.Clear();
1540 dw_offset_t end_addr_offset = DW_INVALID_OFFSET;
1541 const dw_offset_t attr_offset = GetAttributeValue(dwarf2Data, cu, attr, form_value, &end_addr_offset);
1544 const uint8_t* blockData = form_value.BlockData();
1547 // We have an inlined location list in the .debug_info section
1548 const DWARFDataExtractor& debug_info = dwarf2Data->get_debug_info_data();
1549 dw_offset_t block_offset = blockData - debug_info.GetDataStart();
1550 block_size = (end_addr_offset - attr_offset) - form_value.Unsigned();
1551 location_data.SetData(debug_info, block_offset, block_size);
1555 // We have a location list offset as the value that is
1556 // the offset into the .debug_loc section that describes
1557 // the value over it's lifetime
1558 lldb::offset_t debug_loc_offset = form_value.Unsigned();
1561 assert(dwarf2Data->get_debug_loc_data().GetAddressByteSize() == cu->GetAddressByteSize());
1562 return DWARFLocationList::Extract(dwarf2Data->get_debug_loc_data(), &debug_loc_offset, location_data);
1569 //----------------------------------------------------------------------
1572 // Get value of the DW_AT_name attribute and return it if one exists,
1573 // else return NULL.
1574 //----------------------------------------------------------------------
1576 DWARFDebugInfoEntry::GetName
1578 SymbolFileDWARF* dwarf2Data,
1579 const DWARFCompileUnit* cu
1582 DWARFFormValue form_value;
1583 if (GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1584 return form_value.AsCString(&dwarf2Data->get_debug_str_data());
1587 if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value))
1589 DWARFCompileUnitSP cu_sp_ptr;
1590 const DWARFDebugInfoEntry* die = const_cast<SymbolFileDWARF*>(dwarf2Data)->DebugInfo()->GetDIEPtr(form_value.Reference(), &cu_sp_ptr);
1592 return die->GetName(dwarf2Data, cu_sp_ptr.get());
1599 //----------------------------------------------------------------------
1602 // Get value of the DW_AT_MIPS_linkage_name attribute and return it if
1603 // one exists, else return the value of the DW_AT_name attribute
1604 //----------------------------------------------------------------------
1606 DWARFDebugInfoEntry::GetMangledName
1608 SymbolFileDWARF* dwarf2Data,
1609 const DWARFCompileUnit* cu,
1610 bool substitute_name_allowed
1613 const char* name = NULL;
1614 DWARFFormValue form_value;
1616 if (GetAttributeValue(dwarf2Data, cu, DW_AT_MIPS_linkage_name, form_value))
1617 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1619 if (GetAttributeValue(dwarf2Data, cu, DW_AT_linkage_name, form_value))
1620 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1622 if (substitute_name_allowed && name == NULL)
1624 if (GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1625 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1631 //----------------------------------------------------------------------
1634 // Get value the name for a DIE as it should appear for a
1635 // .debug_pubnames or .debug_pubtypes section.
1636 //----------------------------------------------------------------------
1638 DWARFDebugInfoEntry::GetPubname
1640 SymbolFileDWARF* dwarf2Data,
1641 const DWARFCompileUnit* cu
1644 const char* name = NULL;
1648 DWARFFormValue form_value;
1650 if (GetAttributeValue(dwarf2Data, cu, DW_AT_MIPS_linkage_name, form_value))
1651 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1652 else if (GetAttributeValue(dwarf2Data, cu, DW_AT_linkage_name, form_value))
1653 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1654 else if (GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1655 name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1656 else if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value))
1658 // The specification DIE may be in another compile unit so we need
1659 // to get a die and its compile unit.
1660 DWARFCompileUnitSP cu_sp_ptr;
1661 const DWARFDebugInfoEntry* die = const_cast<SymbolFileDWARF*>(dwarf2Data)->DebugInfo()->GetDIEPtr(form_value.Reference(), &cu_sp_ptr);
1663 return die->GetPubname(dwarf2Data, cu_sp_ptr.get());
1669 //----------------------------------------------------------------------
1672 // Get value of the DW_AT_name attribute for a debug information entry
1673 // that exists at offset "die_offset" and place that value into the
1674 // supplied stream object. If the DIE is a NULL object "NULL" is placed
1675 // into the stream, and if no DW_AT_name attribute exists for the DIE
1676 // then nothing is printed.
1677 //----------------------------------------------------------------------
1679 DWARFDebugInfoEntry::GetName
1681 SymbolFileDWARF* dwarf2Data,
1682 const DWARFCompileUnit* cu,
1683 const dw_offset_t die_offset,
1687 if (dwarf2Data == NULL)
1689 s.PutCString("NULL");
1693 DWARFDebugInfoEntry die;
1694 lldb::offset_t offset = die_offset;
1695 if (die.Extract(dwarf2Data, cu, &offset))
1699 s.PutCString("NULL");
1704 DWARFFormValue form_value;
1705 if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1707 const char* name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1719 //----------------------------------------------------------------------
1722 // Follows the type name definition down through all needed tags to
1723 // end up with a fully qualified type name and dump the results to
1724 // the supplied stream. This is used to show the name of types given
1725 // a type identifier.
1726 //----------------------------------------------------------------------
1728 DWARFDebugInfoEntry::AppendTypeName
1730 SymbolFileDWARF* dwarf2Data,
1731 const DWARFCompileUnit* cu,
1732 const dw_offset_t die_offset,
1736 if (dwarf2Data == NULL)
1738 s.PutCString("NULL");
1742 DWARFDebugInfoEntry die;
1743 lldb::offset_t offset = die_offset;
1744 if (die.Extract(dwarf2Data, cu, &offset))
1748 s.PutCString("NULL");
1753 const char* name = die.GetPubname(dwarf2Data, cu);
1754 // if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_name, form_value))
1755 // name = form_value.AsCString(&dwarf2Data->get_debug_str_data());
1761 const DWARFAbbreviationDeclaration* abbrevDecl = die.GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1763 if (abbrevDecl == NULL)
1766 switch (abbrevDecl->Tag())
1768 case DW_TAG_array_type: break; // print out a "[]" after printing the full type of the element below
1769 case DW_TAG_base_type: s.PutCString("base "); break;
1770 case DW_TAG_class_type: s.PutCString("class "); break;
1771 case DW_TAG_const_type: s.PutCString("const "); break;
1772 case DW_TAG_enumeration_type: s.PutCString("enum "); break;
1773 case DW_TAG_file_type: s.PutCString("file "); break;
1774 case DW_TAG_interface_type: s.PutCString("interface "); break;
1775 case DW_TAG_packed_type: s.PutCString("packed "); break;
1776 case DW_TAG_pointer_type: break; // print out a '*' after printing the full type below
1777 case DW_TAG_ptr_to_member_type: break; // print out a '*' after printing the full type below
1778 case DW_TAG_reference_type: break; // print out a '&' after printing the full type below
1779 case DW_TAG_restrict_type: s.PutCString("restrict "); break;
1780 case DW_TAG_set_type: s.PutCString("set "); break;
1781 case DW_TAG_shared_type: s.PutCString("shared "); break;
1782 case DW_TAG_string_type: s.PutCString("string "); break;
1783 case DW_TAG_structure_type: s.PutCString("struct "); break;
1784 case DW_TAG_subrange_type: s.PutCString("subrange "); break;
1785 case DW_TAG_subroutine_type: s.PutCString("function "); break;
1786 case DW_TAG_thrown_type: s.PutCString("thrown "); break;
1787 case DW_TAG_union_type: s.PutCString("union "); break;
1788 case DW_TAG_unspecified_type: s.PutCString("unspecified "); break;
1789 case DW_TAG_volatile_type: s.PutCString("volatile "); break;
1794 // Follow the DW_AT_type if possible
1795 DWARFFormValue form_value;
1796 if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_type, form_value))
1798 uint64_t next_die_offset = form_value.Reference();
1799 result = AppendTypeName(dwarf2Data, cu, next_die_offset, s);
1802 switch (abbrevDecl->Tag())
1804 case DW_TAG_array_type: s.PutCString("[]"); break;
1805 case DW_TAG_pointer_type: s.PutChar('*'); break;
1806 case DW_TAG_ptr_to_member_type: s.PutChar('*'); break;
1807 case DW_TAG_reference_type: s.PutChar('&'); break;
1819 DWARFDebugInfoEntry::Contains (const DWARFDebugInfoEntry *die) const
1823 const dw_offset_t die_offset = die->GetOffset();
1824 if (die_offset > GetOffset())
1826 const DWARFDebugInfoEntry *sibling = GetSibling();
1827 assert (sibling); // TODO: take this out
1829 return die_offset < sibling->GetOffset();
1835 //----------------------------------------------------------------------
1836 // BuildAddressRangeTable
1837 //----------------------------------------------------------------------
1839 DWARFDebugInfoEntry::BuildAddressRangeTable
1841 SymbolFileDWARF* dwarf2Data,
1842 const DWARFCompileUnit* cu,
1843 DWARFDebugAranges* debug_aranges
1848 if (m_tag == DW_TAG_subprogram)
1850 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1851 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1852 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS))
1854 /// 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);
1855 debug_aranges->AppendRange (cu->GetOffset(), lo_pc, hi_pc);
1860 const DWARFDebugInfoEntry* child = GetFirstChild();
1863 child->BuildAddressRangeTable(dwarf2Data, cu, debug_aranges);
1864 child = child->GetSibling();
1869 //----------------------------------------------------------------------
1870 // BuildFunctionAddressRangeTable
1872 // This function is very similar to the BuildAddressRangeTable function
1873 // except that the actual DIE offset for the function is placed in the
1874 // table instead of the compile unit offset (which is the way the
1875 // standard .debug_aranges section does it).
1876 //----------------------------------------------------------------------
1878 DWARFDebugInfoEntry::BuildFunctionAddressRangeTable
1880 SymbolFileDWARF* dwarf2Data,
1881 const DWARFCompileUnit* cu,
1882 DWARFDebugAranges* debug_aranges
1887 if (m_tag == DW_TAG_subprogram)
1889 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1890 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1891 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS))
1893 // printf("BuildAddressRangeTable() 0x%8.8x: [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n", m_offset, lo_pc, hi_pc); // DEBUG ONLY
1894 debug_aranges->AppendRange (GetOffset(), lo_pc, hi_pc);
1898 const DWARFDebugInfoEntry* child = GetFirstChild();
1901 child->BuildFunctionAddressRangeTable(dwarf2Data, cu, debug_aranges);
1902 child = child->GetSibling();
1908 DWARFDebugInfoEntry::GetDeclContextDIEs (SymbolFileDWARF* dwarf2Data,
1909 DWARFCompileUnit* cu,
1910 DWARFDIECollection &decl_context_dies) const
1912 const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
1913 if (parent_decl_ctx_die && parent_decl_ctx_die != this)
1915 decl_context_dies.Append(parent_decl_ctx_die);
1916 parent_decl_ctx_die->GetDeclContextDIEs (dwarf2Data, cu, decl_context_dies);
1921 DWARFDebugInfoEntry::GetDWARFDeclContext (SymbolFileDWARF* dwarf2Data,
1922 DWARFCompileUnit* cu,
1923 DWARFDeclContext &dwarf_decl_ctx) const
1925 const dw_tag_t tag = Tag();
1926 if (tag != DW_TAG_compile_unit)
1928 dwarf_decl_ctx.AppendDeclContext(tag, GetName(dwarf2Data, cu));
1929 const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
1930 if (parent_decl_ctx_die && parent_decl_ctx_die != this)
1932 if (parent_decl_ctx_die->Tag() != DW_TAG_compile_unit)
1933 parent_decl_ctx_die->GetDWARFDeclContext (dwarf2Data, cu, dwarf_decl_ctx);
1940 DWARFDebugInfoEntry::MatchesDWARFDeclContext (SymbolFileDWARF* dwarf2Data,
1941 DWARFCompileUnit* cu,
1942 const DWARFDeclContext &dwarf_decl_ctx) const
1945 DWARFDeclContext this_dwarf_decl_ctx;
1946 GetDWARFDeclContext (dwarf2Data, cu, this_dwarf_decl_ctx);
1947 return this_dwarf_decl_ctx == dwarf_decl_ctx;
1950 const DWARFDebugInfoEntry *
1951 DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
1952 DWARFCompileUnit* cu) const
1954 DWARFDebugInfoEntry::Attributes attributes;
1955 GetAttributes(dwarf2Data, cu, NULL, attributes);
1956 return GetParentDeclContextDIE (dwarf2Data, cu, attributes);
1959 const DWARFDebugInfoEntry *
1960 DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
1961 DWARFCompileUnit* cu,
1962 const DWARFDebugInfoEntry::Attributes& attributes) const
1964 const DWARFDebugInfoEntry * die = this;
1968 // If this is the original DIE that we are searching for a declaration
1969 // for, then don't look in the cache as we don't want our own decl
1970 // context to be our decl context...
1975 case DW_TAG_compile_unit:
1976 case DW_TAG_namespace:
1977 case DW_TAG_structure_type:
1978 case DW_TAG_union_type:
1979 case DW_TAG_class_type:
1987 dw_offset_t die_offset;
1989 die_offset = attributes.FormValueAsUnsigned(dwarf2Data, DW_AT_specification, DW_INVALID_OFFSET);
1990 if (die_offset != DW_INVALID_OFFSET)
1992 const DWARFDebugInfoEntry *spec_die = cu->GetDIEPtr (die_offset);
1995 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = spec_die->GetParentDeclContextDIE (dwarf2Data, cu);
1996 if (spec_die_decl_ctx_die)
1997 return spec_die_decl_ctx_die;
2001 die_offset = attributes.FormValueAsUnsigned(dwarf2Data, DW_AT_abstract_origin, DW_INVALID_OFFSET);
2002 if (die_offset != DW_INVALID_OFFSET)
2004 const DWARFDebugInfoEntry *abs_die = cu->GetDIEPtr (die_offset);
2007 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = abs_die->GetParentDeclContextDIE (dwarf2Data, cu);
2008 if (abs_die_decl_ctx_die)
2009 return abs_die_decl_ctx_die;
2013 die = die->GetParent();
2020 DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data,
2021 DWARFCompileUnit* cu,
2022 std::string &storage) const
2024 DWARFDebugInfoEntry::Attributes attributes;
2025 GetAttributes(dwarf2Data, cu, NULL, attributes);
2026 return GetQualifiedName (dwarf2Data, cu, attributes, storage);
2030 DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data,
2031 DWARFCompileUnit* cu,
2032 const DWARFDebugInfoEntry::Attributes& attributes,
2033 std::string &storage) const
2036 const char *name = GetName (dwarf2Data, cu);
2040 const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
2042 // TODO: change this to get the correct decl context parent....
2043 while (parent_decl_ctx_die)
2045 const dw_tag_t parent_tag = parent_decl_ctx_die->Tag();
2048 case DW_TAG_namespace:
2050 const char *namespace_name = parent_decl_ctx_die->GetName (dwarf2Data, cu);
2053 storage.insert (0, "::");
2054 storage.insert (0, namespace_name);
2058 storage.insert (0, "(anonymous namespace)::");
2060 parent_decl_ctx_die = parent_decl_ctx_die->GetParentDeclContextDIE(dwarf2Data, cu);
2064 case DW_TAG_class_type:
2065 case DW_TAG_structure_type:
2066 case DW_TAG_union_type:
2068 const char *class_union_struct_name = parent_decl_ctx_die->GetName (dwarf2Data, cu);
2070 if (class_union_struct_name)
2072 storage.insert (0, "::");
2073 storage.insert (0, class_union_struct_name);
2075 parent_decl_ctx_die = parent_decl_ctx_die->GetParentDeclContextDIE(dwarf2Data, cu);
2080 parent_decl_ctx_die = NULL;
2085 if (storage.empty())
2086 storage.append ("::");
2088 storage.append (name);
2090 if (storage.empty())
2092 return storage.c_str();
2096 //----------------------------------------------------------------------
2098 //----------------------------------------------------------------------
2100 DWARFDebugInfoEntry::LookupAddress
2102 const dw_addr_t address,
2103 SymbolFileDWARF* dwarf2Data,
2104 const DWARFCompileUnit* cu,
2105 DWARFDebugInfoEntry** function_die,
2106 DWARFDebugInfoEntry** block_die
2109 bool found_address = false;
2112 bool check_children = false;
2113 bool match_addr_range = false;
2114 // printf("0x%8.8x: %30s: address = 0x%8.8x - ", m_offset, DW_TAG_value_to_name(tag), address);
2117 case DW_TAG_array_type : break;
2118 case DW_TAG_class_type : check_children = true; break;
2119 case DW_TAG_entry_point : break;
2120 case DW_TAG_enumeration_type : break;
2121 case DW_TAG_formal_parameter : break;
2122 case DW_TAG_imported_declaration : break;
2123 case DW_TAG_label : break;
2124 case DW_TAG_lexical_block : check_children = true; match_addr_range = true; break;
2125 case DW_TAG_member : break;
2126 case DW_TAG_pointer_type : break;
2127 case DW_TAG_reference_type : break;
2128 case DW_TAG_compile_unit : match_addr_range = true; break;
2129 case DW_TAG_string_type : break;
2130 case DW_TAG_structure_type : check_children = true; break;
2131 case DW_TAG_subroutine_type : break;
2132 case DW_TAG_typedef : break;
2133 case DW_TAG_union_type : break;
2134 case DW_TAG_unspecified_parameters : break;
2135 case DW_TAG_variant : break;
2136 case DW_TAG_common_block : check_children = true; break;
2137 case DW_TAG_common_inclusion : break;
2138 case DW_TAG_inheritance : break;
2139 case DW_TAG_inlined_subroutine : check_children = true; match_addr_range = true; break;
2140 case DW_TAG_module : match_addr_range = true; break;
2141 case DW_TAG_ptr_to_member_type : break;
2142 case DW_TAG_set_type : break;
2143 case DW_TAG_subrange_type : break;
2144 case DW_TAG_with_stmt : break;
2145 case DW_TAG_access_declaration : break;
2146 case DW_TAG_base_type : break;
2147 case DW_TAG_catch_block : match_addr_range = true; break;
2148 case DW_TAG_const_type : break;
2149 case DW_TAG_constant : break;
2150 case DW_TAG_enumerator : break;
2151 case DW_TAG_file_type : break;
2152 case DW_TAG_friend : break;
2153 case DW_TAG_namelist : break;
2154 case DW_TAG_namelist_item : break;
2155 case DW_TAG_packed_type : break;
2156 case DW_TAG_subprogram : match_addr_range = true; break;
2157 case DW_TAG_template_type_parameter : break;
2158 case DW_TAG_template_value_parameter : break;
2159 case DW_TAG_thrown_type : break;
2160 case DW_TAG_try_block : match_addr_range = true; break;
2161 case DW_TAG_variant_part : break;
2162 case DW_TAG_variable : break;
2163 case DW_TAG_volatile_type : break;
2164 case DW_TAG_dwarf_procedure : break;
2165 case DW_TAG_restrict_type : break;
2166 case DW_TAG_interface_type : break;
2167 case DW_TAG_namespace : check_children = true; break;
2168 case DW_TAG_imported_module : break;
2169 case DW_TAG_unspecified_type : break;
2170 case DW_TAG_partial_unit : break;
2171 case DW_TAG_imported_unit : break;
2172 case DW_TAG_shared_type : break;
2176 if (match_addr_range)
2178 dw_addr_t lo_pc = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
2179 if (lo_pc != LLDB_INVALID_ADDRESS)
2181 dw_addr_t hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, LLDB_INVALID_ADDRESS);
2182 if (hi_pc != LLDB_INVALID_ADDRESS)
2184 // 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);
2185 if ((lo_pc <= address) && (address < hi_pc))
2187 found_address = true;
2188 // puts("***MATCH***");
2191 case DW_TAG_compile_unit: // File
2192 check_children = ((function_die != NULL) || (block_die != NULL));
2195 case DW_TAG_subprogram: // Function
2197 *function_die = this;
2198 check_children = (block_die != NULL);
2201 case DW_TAG_inlined_subroutine: // Inlined Function
2202 case DW_TAG_lexical_block: // Block { } in code
2206 check_children = true;
2211 check_children = true;
2217 { // compile units may not have a valid high/low pc when there
2218 // are address gaps in subroutines so we must always search
2219 // if there is no valid high and low PC
2220 check_children = (m_tag == DW_TAG_compile_unit) && ((function_die != NULL) || (block_die != NULL));
2225 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET);
2226 if (debug_ranges_offset != DW_INVALID_OFFSET)
2228 DWARFDebugRanges::RangeList ranges;
2229 DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
2230 debug_ranges->FindRanges(debug_ranges_offset, ranges);
2231 // All DW_AT_ranges are relative to the base address of the
2232 // compile unit. We add the compile unit base address to make
2233 // sure all the addresses are properly fixed up.
2234 ranges.Slide (cu->GetBaseAddress());
2235 if (ranges.FindEntryThatContains(address))
2237 found_address = true;
2238 // puts("***MATCH***");
2241 case DW_TAG_compile_unit: // File
2242 check_children = ((function_die != NULL) || (block_die != NULL));
2245 case DW_TAG_subprogram: // Function
2247 *function_die = this;
2248 check_children = (block_die != NULL);
2251 case DW_TAG_inlined_subroutine: // Inlined Function
2252 case DW_TAG_lexical_block: // Block { } in code
2256 check_children = true;
2261 check_children = true;
2267 check_children = false;
2276 // printf("checking children\n");
2277 DWARFDebugInfoEntry* child = GetFirstChild();
2280 if (child->LookupAddress(address, dwarf2Data, cu, function_die, block_die))
2282 child = child->GetSibling();
2286 return found_address;
2289 const DWARFAbbreviationDeclaration*
2290 DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr (SymbolFileDWARF* dwarf2Data,
2291 const DWARFCompileUnit *cu,
2292 lldb::offset_t &offset) const
2296 offset = GetOffset();
2298 const DWARFAbbreviationDeclaration* abbrev_decl = cu->GetAbbreviations()->GetAbbreviationDeclaration (m_abbr_idx);
2301 // Make sure the abbreviation code still matches. If it doesn't and
2302 // the DWARF data was mmap'ed, the backing file might have been modified
2303 // which is bad news.
2304 const uint64_t abbrev_code = dwarf2Data->get_debug_info_data().GetULEB128 (&offset);
2306 if (abbrev_decl->Code() == abbrev_code)
2309 dwarf2Data->GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("0x%8.8x: the DWARF debug information has been modified (abbrev code was %u, and is now %u)",
2311 (uint32_t)abbrev_decl->Code(),
2312 (uint32_t)abbrev_code);
2315 offset = DW_INVALID_OFFSET;
2321 DWARFDebugInfoEntry::OffsetLessThan (const DWARFDebugInfoEntry& a, const DWARFDebugInfoEntry& b)
2323 return a.GetOffset() < b.GetOffset();
2327 DWARFDebugInfoEntry::DumpDIECollection (Stream &strm, DWARFDebugInfoEntry::collection &die_collection)
2329 DWARFDebugInfoEntry::const_iterator pos;
2330 DWARFDebugInfoEntry::const_iterator end = die_collection.end();
2331 strm.PutCString("\noffset parent sibling child\n");
2332 strm.PutCString("-------- -------- -------- --------\n");
2333 for (pos = die_collection.begin(); pos != end; ++pos)
2335 const DWARFDebugInfoEntry& die_ref = *pos;
2336 const DWARFDebugInfoEntry* p = die_ref.GetParent();
2337 const DWARFDebugInfoEntry* s = die_ref.GetSibling();
2338 const DWARFDebugInfoEntry* c = die_ref.GetFirstChild();
2339 strm.Printf("%.8x: %.8x %.8x %.8x 0x%4.4x %s%s\n",
2340 die_ref.GetOffset(),
2341 p ? p->GetOffset() : 0,
2342 s ? s->GetOffset() : 0,
2343 c ? c->GetOffset() : 0,
2345 DW_TAG_value_to_name(die_ref.Tag()),
2346 die_ref.HasChildren() ? " *" : "");