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 "DWARFDebugAbbrev.h"
23 #include "DWARFDebugAranges.h"
24 #include "DWARFDebugInfo.h"
25 #include "DWARFDeclContext.h"
26 #include "DWARFDIECollection.h"
27 #include "DWARFFormValue.h"
28 #include "DWARFDebugRanges.h"
29 #include "SymbolFileDWARF.h"
30 #include "SymbolFileDWARFDwo.h"
32 using namespace lldb_private;
37 DWARFDebugInfoEntry::FastExtract
39 const DWARFDataExtractor& debug_info_data,
40 const DWARFCompileUnit* cu,
41 const DWARFFormValue::FixedFormSizes& fixed_form_sizes,
42 lldb::offset_t *offset_ptr
45 m_offset = *offset_ptr;
48 m_empty_children = false;
49 const uint64_t abbr_idx = debug_info_data.GetULEB128 (offset_ptr);
50 assert (abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
51 m_abbr_idx = abbr_idx;
53 //assert (fixed_form_sizes); // For best performance this should be specified!
57 lldb::offset_t offset = *offset_ptr;
59 const DWARFAbbreviationDeclaration *abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration(m_abbr_idx);
61 if (abbrevDecl == NULL)
63 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",
66 // WE can't parse anymore if the DWARF is borked...
67 *offset_ptr = UINT32_MAX;
70 m_tag = abbrevDecl->Tag();
71 m_has_children = abbrevDecl->HasChildren();
72 // Skip all data in the .debug_info for the attributes
73 const uint32_t numAttributes = abbrevDecl->NumAttributes();
76 for (i=0; i<numAttributes; ++i)
78 form = abbrevDecl->GetFormByIndexUnchecked(i);
80 const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
82 offset += fixed_skip_size;
85 bool form_is_indirect = false;
88 form_is_indirect = false;
89 uint32_t form_size = 0;
92 // Blocks if inlined data that have a length field and the data bytes
93 // inlined in the .debug_info
94 case DW_FORM_exprloc :
95 case DW_FORM_block : form_size = debug_info_data.GetULEB128 (&offset); break;
96 case DW_FORM_block1 : form_size = debug_info_data.GetU8_unchecked (&offset); break;
97 case DW_FORM_block2 : form_size = debug_info_data.GetU16_unchecked (&offset);break;
98 case DW_FORM_block4 : form_size = debug_info_data.GetU32_unchecked (&offset);break;
100 // Inlined NULL terminated C-strings
101 case DW_FORM_string :
102 debug_info_data.GetCStr (&offset);
105 // Compile unit address sized values
107 form_size = cu->GetAddressByteSize();
109 case DW_FORM_ref_addr :
110 if (cu->GetVersion() <= 2)
111 form_size = cu->GetAddressByteSize();
113 form_size = cu->IsDWARF64() ? 8 : 4;
117 case DW_FORM_flag_present:
143 case DW_FORM_ref_sig8 :
147 // signed or unsigned LEB 128 values
150 case DW_FORM_ref_udata :
151 case DW_FORM_GNU_addr_index:
152 case DW_FORM_GNU_str_index :
153 debug_info_data.Skip_LEB128 (&offset);
156 case DW_FORM_indirect :
157 form_is_indirect = true;
158 form = debug_info_data.GetULEB128 (&offset);
162 case DW_FORM_sec_offset :
163 if (cu->IsDWARF64 ())
164 debug_info_data.GetU64 (offset_ptr);
166 debug_info_data.GetU32 (offset_ptr);
170 *offset_ptr = m_offset;
175 } while (form_is_indirect);
178 *offset_ptr = offset;
184 m_has_children = false;
185 return true; // NULL debug tag entry
191 //----------------------------------------------------------------------
194 // Extract a debug info entry for a given compile unit from the
195 // .debug_info and .debug_abbrev data within the SymbolFileDWARF class
196 // starting at the given offset
197 //----------------------------------------------------------------------
199 DWARFDebugInfoEntry::Extract
201 SymbolFileDWARF* dwarf2Data,
202 const DWARFCompileUnit* cu,
203 lldb::offset_t *offset_ptr
206 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
207 // const DWARFDataExtractor& debug_str_data = dwarf2Data->get_debug_str_data();
208 const uint32_t cu_end_offset = cu->GetNextCompileUnitOffset();
209 lldb::offset_t offset = *offset_ptr;
210 // if (offset >= cu_end_offset)
211 // 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);
212 if ((offset < cu_end_offset) && debug_info_data.ValidOffset(offset))
216 const uint64_t abbr_idx = debug_info_data.GetULEB128(&offset);
217 assert (abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
218 m_abbr_idx = abbr_idx;
221 const DWARFAbbreviationDeclaration *abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration(abbr_idx);
225 m_tag = abbrevDecl->Tag();
226 m_has_children = abbrevDecl->HasChildren();
228 bool isCompileUnitTag = m_tag == DW_TAG_compile_unit;
229 if (cu && isCompileUnitTag)
230 const_cast<DWARFCompileUnit *>(cu)->SetBaseAddress(0);
232 // Skip all data in the .debug_info for the attributes
233 const uint32_t numAttributes = abbrevDecl->NumAttributes();
237 for (i=0; i<numAttributes; ++i)
239 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
241 if (isCompileUnitTag && ((attr == DW_AT_entry_pc) || (attr == DW_AT_low_pc)))
243 DWARFFormValue form_value(cu, form);
244 if (form_value.ExtractValue(debug_info_data, &offset))
246 if (attr == DW_AT_low_pc || attr == DW_AT_entry_pc)
247 const_cast<DWARFCompileUnit*>(cu)->SetBaseAddress(form_value.Address());
252 bool form_is_indirect = false;
255 form_is_indirect = false;
256 uint32_t form_size = 0;
259 // Blocks if inlined data that have a length field and the data bytes
260 // inlined in the .debug_info
261 case DW_FORM_exprloc :
262 case DW_FORM_block : form_size = debug_info_data.GetULEB128(&offset); break;
263 case DW_FORM_block1 : form_size = debug_info_data.GetU8(&offset); break;
264 case DW_FORM_block2 : form_size = debug_info_data.GetU16(&offset); break;
265 case DW_FORM_block4 : form_size = debug_info_data.GetU32(&offset); break;
267 // Inlined NULL terminated C-strings
268 case DW_FORM_string : debug_info_data.GetCStr(&offset); break;
270 // Compile unit address sized values
272 form_size = cu->GetAddressByteSize();
274 case DW_FORM_ref_addr :
275 if (cu->GetVersion() <= 2)
276 form_size = cu->GetAddressByteSize();
278 form_size = cu->IsDWARF64() ? 8 : 4;
282 case DW_FORM_flag_present:
308 case DW_FORM_ref_sig8 :
312 // signed or unsigned LEB 128 values
315 case DW_FORM_ref_udata :
316 case DW_FORM_GNU_addr_index:
317 case DW_FORM_GNU_str_index :
318 debug_info_data.Skip_LEB128(&offset);
321 case DW_FORM_indirect :
322 form = debug_info_data.GetULEB128(&offset);
323 form_is_indirect = true;
327 case DW_FORM_sec_offset :
328 if (cu->IsDWARF64 ())
329 debug_info_data.GetU64 (offset_ptr);
331 debug_info_data.GetU32 (offset_ptr);
335 *offset_ptr = offset;
340 } while (form_is_indirect);
343 *offset_ptr = offset;
350 m_has_children = false;
351 *offset_ptr = offset;
352 return true; // NULL debug tag entry
359 //----------------------------------------------------------------------
362 // Dumps all of a debug information entries parents up until oldest and
363 // all of it's attributes to the specified stream.
364 //----------------------------------------------------------------------
366 DWARFDebugInfoEntry::DumpAncestry
368 SymbolFileDWARF* dwarf2Data,
369 const DWARFCompileUnit* cu,
370 const DWARFDebugInfoEntry* oldest,
372 uint32_t recurse_depth
375 const DWARFDebugInfoEntry* parent = GetParent();
376 if (parent && parent != oldest)
377 parent->DumpAncestry(dwarf2Data, cu, oldest, s, 0);
378 Dump(dwarf2Data, cu, s, recurse_depth);
381 //----------------------------------------------------------------------
382 // GetDIENamesAndRanges
384 // Gets the valid address ranges for a given DIE by looking for a
385 // DW_AT_low_pc/DW_AT_high_pc pair, DW_AT_entry_pc, or DW_AT_ranges
387 //----------------------------------------------------------------------
389 DWARFDebugInfoEntry::GetDIENamesAndRanges
391 SymbolFileDWARF* dwarf2Data,
392 const DWARFCompileUnit* cu,
394 const char * &mangled,
395 DWARFRangeList& ranges,
402 DWARFExpression *frame_base
405 if (dwarf2Data == nullptr)
408 SymbolFileDWARFDwo* dwo_symbol_file = cu->GetDwoSymbolFile();
410 return GetDIENamesAndRanges(dwo_symbol_file,
411 dwo_symbol_file->GetCompileUnit(),
423 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
424 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
425 std::vector<DIERef> die_refs;
426 bool set_frame_base_loclist_addr = false;
428 lldb::offset_t offset;
429 const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
431 lldb::ModuleSP module = dwarf2Data->GetObjectFile()->GetModule();
435 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
437 if (!debug_info_data.ValidOffset(offset))
440 const uint32_t numAttributes = abbrevDecl->NumAttributes();
444 bool do_offset = false;
446 for (i=0; i<numAttributes; ++i)
448 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
449 DWARFFormValue form_value(cu, form);
450 if (form_value.ExtractValue(debug_info_data, &offset))
455 lo_pc = form_value.Address();
463 lo_pc = form_value.Address();
467 if (form_value.Form() == DW_FORM_addr ||
468 form_value.Form() == DW_FORM_GNU_addr_index)
470 hi_pc = form_value.Address();
474 hi_pc = form_value.Unsigned();
475 if (lo_pc == LLDB_INVALID_ADDRESS)
476 do_offset = hi_pc != LLDB_INVALID_ADDRESS;
478 hi_pc += lo_pc; // DWARF 4 introduces <offset-from-lo-pc> to save on relocations
484 const DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
487 debug_ranges->FindRanges(form_value.Unsigned(), ranges);
488 // All DW_AT_ranges are relative to the base address of the
489 // compile unit. We add the compile unit base address to make
490 // sure all the addresses are properly fixed up.
491 ranges.Slide(cu->GetBaseAddress());
495 cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: DIE has DW_AT_ranges(0x%" PRIx64 ") attribute yet DWARF has no .debug_ranges, please file a bug and attach the file at the start of this error message",
496 m_offset, form_value.Unsigned());
503 name = form_value.AsCString();
506 case DW_AT_MIPS_linkage_name:
507 case DW_AT_linkage_name:
509 mangled = form_value.AsCString();
512 case DW_AT_abstract_origin:
513 die_refs.emplace_back(form_value);
516 case DW_AT_specification:
517 die_refs.emplace_back(form_value);
520 case DW_AT_decl_file:
522 decl_file = form_value.Unsigned();
525 case DW_AT_decl_line:
527 decl_line = form_value.Unsigned();
530 case DW_AT_decl_column:
531 if (decl_column == 0)
532 decl_column = form_value.Unsigned();
535 case DW_AT_call_file:
537 call_file = form_value.Unsigned();
540 case DW_AT_call_line:
542 call_line = form_value.Unsigned();
545 case DW_AT_call_column:
546 if (call_column == 0)
547 call_column = form_value.Unsigned();
550 case DW_AT_frame_base:
553 if (form_value.BlockData())
555 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
556 uint32_t block_length = form_value.Unsigned();
557 frame_base->SetOpcodeData(module, debug_info_data, block_offset, block_length);
561 const DWARFDataExtractor &debug_loc_data = dwarf2Data->get_debug_loc_data();
562 const dw_offset_t debug_loc_offset = form_value.Unsigned();
564 size_t loc_list_length = DWARFExpression::LocationListSize(cu, debug_loc_data, debug_loc_offset);
565 if (loc_list_length > 0)
567 frame_base->SetOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
568 if (lo_pc != LLDB_INVALID_ADDRESS)
570 assert (lo_pc >= cu->GetBaseAddress());
571 frame_base->SetLocationListSlide(lo_pc - cu->GetBaseAddress());
575 set_frame_base_loclist_addr = true;
589 if (ranges.IsEmpty())
591 if (lo_pc != LLDB_INVALID_ADDRESS)
593 if (hi_pc != LLDB_INVALID_ADDRESS && hi_pc > lo_pc)
594 ranges.Append(DWARFRangeList::Entry (lo_pc, hi_pc - lo_pc));
596 ranges.Append(DWARFRangeList::Entry (lo_pc, 0));
600 if (set_frame_base_loclist_addr)
602 dw_addr_t lowest_range_pc = ranges.GetMinRangeBase(0);
603 assert (lowest_range_pc >= cu->GetBaseAddress());
604 frame_base->SetLocationListSlide (lowest_range_pc - cu->GetBaseAddress());
607 if (ranges.IsEmpty() || name == NULL || mangled == NULL)
609 for (const DIERef& die_ref : die_refs)
611 if (die_ref.die_offset != DW_INVALID_OFFSET)
613 DWARFDIE die = dwarf2Data->GetDIE(die_ref);
615 die.GetDIE()->GetDIENamesAndRanges(die.GetDWARF(), die.GetCU(), name, mangled, ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column);
619 return !ranges.IsEmpty();
622 //----------------------------------------------------------------------
625 // Dumps a debug information entry and all of it's attributes to the
627 //----------------------------------------------------------------------
629 DWARFDebugInfoEntry::Dump
631 SymbolFileDWARF* dwarf2Data,
632 const DWARFCompileUnit* cu,
634 uint32_t recurse_depth
637 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
638 lldb::offset_t offset = m_offset;
640 if (debug_info_data.ValidOffset(offset))
642 dw_uleb128_t abbrCode = debug_info_data.GetULEB128(&offset);
644 s.Printf("\n0x%8.8x: ", m_offset);
646 if (abbrCode != m_abbr_idx)
648 s.Printf( "error: DWARF has been modified\n");
652 const DWARFAbbreviationDeclaration* abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration (abbrCode);
656 s.PutCString(DW_TAG_value_to_name(abbrevDecl->Tag()));
657 s.Printf( " [%u] %c\n", abbrCode, abbrevDecl->HasChildren() ? '*':' ');
659 // Dump all data in the .debug_info for the attributes
660 const uint32_t numAttributes = abbrevDecl->NumAttributes();
664 for (i=0; i<numAttributes; ++i)
666 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
668 DumpAttribute(dwarf2Data, cu, debug_info_data, &offset, s, attr, form);
671 const DWARFDebugInfoEntry* child = GetFirstChild();
672 if (recurse_depth > 0 && child)
678 child->Dump(dwarf2Data, cu, s, recurse_depth-1);
679 child = child->GetSibling();
685 s.Printf( "Abbreviation code note found in 'debug_abbrev' class for code: %u\n", abbrCode);
695 DWARFDebugInfoEntry::DumpLocation
697 SymbolFileDWARF* dwarf2Data,
698 DWARFCompileUnit* cu,
702 const DWARFDIE cu_die = cu->GetCompileUnitDIEOnly();
703 const char *cu_name = NULL;
705 cu_name = cu_die.GetName ();
706 const char *obj_file_name = NULL;
707 ObjectFile *obj_file = dwarf2Data->GetObjectFile();
709 obj_file_name = obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>");
710 const char *die_name = GetName (dwarf2Data, cu);
711 s.Printf ("0x%8.8x/0x%8.8x: %-30s (from %s in %s)",
714 die_name ? die_name : "",
715 cu_name ? cu_name : "<NULL>",
716 obj_file_name ? obj_file_name : "<NULL>");
719 //----------------------------------------------------------------------
722 // Dumps a debug information entry attribute along with it's form. Any
723 // special display of attributes is done (disassemble location lists,
724 // show enumeration values for attributes, etc).
725 //----------------------------------------------------------------------
727 DWARFDebugInfoEntry::DumpAttribute
729 SymbolFileDWARF* dwarf2Data,
730 const DWARFCompileUnit* cu,
731 const DWARFDataExtractor& debug_info_data,
732 lldb::offset_t *offset_ptr,
738 bool verbose = s.GetVerbose();
739 bool show_form = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm);
742 s.Offset (*offset_ptr);
745 s.Indent(DW_AT_value_to_name(attr));
749 s.Printf( "[%s", DW_FORM_value_to_name(form));
752 DWARFFormValue form_value(cu, form);
754 if (!form_value.ExtractValue(debug_info_data, offset_ptr))
759 if (form == DW_FORM_indirect)
761 s.Printf( " [%s]", DW_FORM_value_to_name(form_value.Form()));
769 // Always dump form value if verbose is enabled
776 // Check to see if we have any special attribute formatters
779 case DW_AT_stmt_list:
780 if ( verbose ) s.PutCString(" ( ");
781 s.Printf( "0x%8.8" PRIx64, form_value.Unsigned());
782 if ( verbose ) s.PutCString(" )");
786 if ( verbose ) s.PutCString(" ( ");
787 s.PutCString(DW_LANG_value_to_name(form_value.Unsigned()));
788 if ( verbose ) s.PutCString(" )");
792 if ( verbose ) s.PutCString(" ( ");
793 s.PutCString(DW_ATE_value_to_name(form_value.Unsigned()));
794 if ( verbose ) s.PutCString(" )");
797 case DW_AT_frame_base:
799 case DW_AT_data_member_location:
801 const uint8_t* blockData = form_value.BlockData();
807 // Location description is inlined in data in the form value
808 DWARFDataExtractor locationData(debug_info_data, (*offset_ptr) - form_value.Unsigned(), form_value.Unsigned());
809 if ( verbose ) s.PutCString(" ( ");
810 DWARFExpression::PrintDWARFExpression(s,
812 DWARFCompileUnit::GetAddressByteSize(cu),
815 if ( verbose ) s.PutCString(" )");
819 // We have a location list offset as the value that is
820 // the offset into the .debug_loc section that describes
821 // the value over it's lifetime
822 uint64_t debug_loc_offset = form_value.Unsigned();
827 DWARFExpression::PrintDWARFLocationList(s,
829 dwarf2Data->get_debug_loc_data(),
841 case DW_AT_abstract_origin:
842 case DW_AT_specification:
844 uint64_t abstract_die_offset = form_value.Reference();
846 // *ostrm_ptr << HEX32 << abstract_die_offset << " ( ";
847 if ( verbose ) s.PutCString(" ( ");
848 GetName(dwarf2Data, cu, abstract_die_offset, s);
849 if ( verbose ) s.PutCString(" )");
855 uint64_t type_die_offset = form_value.Reference();
859 AppendTypeName(dwarf2Data, cu, type_die_offset, s);
868 lldb::offset_t ranges_offset = form_value.Unsigned();
869 dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0;
871 DWARFDebugRanges::Dump(s, dwarf2Data->get_debug_ranges_data(), &ranges_offset, base_addr);
881 s.PutCString(" )\n");
884 //----------------------------------------------------------------------
885 // Get all attribute values for a given DIE, including following any
886 // specification or abstract origin attributes and including those in
887 // the results. Any duplicate attributes will have the first instance
888 // take precedence (this can happen for declaration attributes).
889 //----------------------------------------------------------------------
891 DWARFDebugInfoEntry::GetAttributes (const DWARFCompileUnit* cu,
892 DWARFFormValue::FixedFormSizes fixed_form_sizes,
893 DWARFAttributes& attributes,
894 uint32_t curr_depth) const
896 SymbolFileDWARF* dwarf2Data = nullptr;
897 const DWARFAbbreviationDeclaration* abbrevDecl = nullptr;
898 lldb::offset_t offset = 0;
901 if (m_tag != DW_TAG_compile_unit)
903 SymbolFileDWARFDwo* dwo_symbol_file = cu->GetDwoSymbolFile();
905 return GetAttributes(dwo_symbol_file->GetCompileUnit(),
911 dwarf2Data = cu->GetSymbolFileDWARF();
912 abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
917 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
919 if (fixed_form_sizes.Empty())
920 fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(
921 cu->GetAddressByteSize(), cu->IsDWARF64());
923 const uint32_t num_attributes = abbrevDecl->NumAttributes();
927 for (i=0; i<num_attributes; ++i)
929 abbrevDecl->GetAttrAndFormByIndexUnchecked (i, attr, form);
931 // If we are tracking down DW_AT_specification or DW_AT_abstract_origin
932 // attributes, the depth will be non-zero. We need to omit certain
933 // attributes that don't make sense.
937 case DW_AT_declaration:
940 // This attribute doesn't make sense when combined with
941 // the DIE that references this DIE. We know a DIE is
942 // referencing this DIE because curr_depth is not zero
947 attributes.Append(cu, offset, attr, form);
951 if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin))
953 DWARFFormValue form_value (cu, form);
954 if (form_value.ExtractValue(debug_info_data, &offset))
956 dw_offset_t die_offset = form_value.Reference();
957 DWARFDIE spec_die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(die_offset);
959 spec_die.GetAttributes(attributes, curr_depth + 1);
964 const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
966 offset += fixed_skip_size;
968 DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
976 return attributes.Size();
980 //----------------------------------------------------------------------
983 // Get the value of an attribute and return the .debug_info offset of the
984 // attribute if it was properly extracted into form_value, or zero
985 // if we fail since an offset of zero is invalid for an attribute (it
986 // would be a compile unit header).
987 //----------------------------------------------------------------------
989 DWARFDebugInfoEntry::GetAttributeValue
991 SymbolFileDWARF* dwarf2Data,
992 const DWARFCompileUnit* cu,
993 const dw_attr_t attr,
994 DWARFFormValue& form_value,
995 dw_offset_t* end_attr_offset_ptr,
996 bool check_specification_or_abstract_origin
999 SymbolFileDWARFDwo* dwo_symbol_file = cu->GetDwoSymbolFile();
1000 if (dwo_symbol_file && m_tag != DW_TAG_compile_unit)
1001 return GetAttributeValue(dwo_symbol_file,
1002 dwo_symbol_file->GetCompileUnit(),
1005 end_attr_offset_ptr,
1006 check_specification_or_abstract_origin);
1008 lldb::offset_t offset;
1009 const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1013 uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
1015 if (attr_idx != DW_INVALID_INDEX)
1017 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
1020 while (idx<attr_idx)
1021 DWARFFormValue::SkipValue(abbrevDecl->GetFormByIndex(idx++), debug_info_data, &offset, cu);
1023 const dw_offset_t attr_offset = offset;
1024 form_value.SetCompileUnit(cu);
1025 form_value.SetForm(abbrevDecl->GetFormByIndex(idx));
1026 if (form_value.ExtractValue(debug_info_data, &offset))
1028 if (end_attr_offset_ptr)
1029 *end_attr_offset_ptr = offset;
1035 if (check_specification_or_abstract_origin)
1037 if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value))
1039 DWARFDIE die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(form_value.Reference());
1042 dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(die.GetDWARF(),
1046 end_attr_offset_ptr,
1053 if (GetAttributeValue(dwarf2Data, cu, DW_AT_abstract_origin, form_value))
1055 DWARFDIE die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(form_value.Reference());
1058 dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(die.GetDWARF(),
1062 end_attr_offset_ptr,
1070 if (!dwo_symbol_file)
1073 DWARFCompileUnit* dwo_cu = dwo_symbol_file->GetCompileUnit();
1077 DWARFDIE dwo_cu_die = dwo_cu->GetCompileUnitDIEOnly();
1078 if (!dwo_cu_die.IsValid())
1081 return dwo_cu_die.GetDIE()->GetAttributeValue(dwo_symbol_file,
1085 end_attr_offset_ptr,
1086 check_specification_or_abstract_origin);
1089 //----------------------------------------------------------------------
1090 // GetAttributeValueAsString
1092 // Get the value of an attribute as a string return it. The resulting
1093 // pointer to the string data exists within the supplied SymbolFileDWARF
1094 // and will only be available as long as the SymbolFileDWARF is still around
1095 // and it's content doesn't change.
1096 //----------------------------------------------------------------------
1098 DWARFDebugInfoEntry::GetAttributeValueAsString
1100 SymbolFileDWARF* dwarf2Data,
1101 const DWARFCompileUnit* cu,
1102 const dw_attr_t attr,
1103 const char* fail_value,
1104 bool check_specification_or_abstract_origin) const
1106 DWARFFormValue form_value;
1107 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1108 return form_value.AsCString();
1112 //----------------------------------------------------------------------
1113 // GetAttributeValueAsUnsigned
1115 // Get the value of an attribute as unsigned and return it.
1116 //----------------------------------------------------------------------
1118 DWARFDebugInfoEntry::GetAttributeValueAsUnsigned
1120 SymbolFileDWARF* dwarf2Data,
1121 const DWARFCompileUnit* cu,
1122 const dw_attr_t attr,
1123 uint64_t fail_value,
1124 bool check_specification_or_abstract_origin
1127 DWARFFormValue form_value;
1128 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1129 return form_value.Unsigned();
1133 //----------------------------------------------------------------------
1134 // GetAttributeValueAsSigned
1136 // Get the value of an attribute a signed value and return it.
1137 //----------------------------------------------------------------------
1139 DWARFDebugInfoEntry::GetAttributeValueAsSigned
1141 SymbolFileDWARF* dwarf2Data,
1142 const DWARFCompileUnit* cu,
1143 const dw_attr_t attr,
1145 bool check_specification_or_abstract_origin
1148 DWARFFormValue form_value;
1149 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1150 return form_value.Signed();
1154 //----------------------------------------------------------------------
1155 // GetAttributeValueAsReference
1157 // Get the value of an attribute as reference and fix up and compile
1158 // unit relative offsets as needed.
1159 //----------------------------------------------------------------------
1161 DWARFDebugInfoEntry::GetAttributeValueAsReference
1163 SymbolFileDWARF* dwarf2Data,
1164 const DWARFCompileUnit* cu,
1165 const dw_attr_t attr,
1166 uint64_t fail_value,
1167 bool check_specification_or_abstract_origin
1170 DWARFFormValue form_value;
1171 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1172 return form_value.Reference();
1177 DWARFDebugInfoEntry::GetAttributeValueAsAddress
1179 SymbolFileDWARF* dwarf2Data,
1180 const DWARFCompileUnit* cu,
1181 const dw_attr_t attr,
1182 uint64_t fail_value,
1183 bool check_specification_or_abstract_origin
1186 DWARFFormValue form_value;
1187 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1188 return form_value.Address();
1192 //----------------------------------------------------------------------
1193 // GetAttributeHighPC
1195 // Get the hi_pc, adding hi_pc to lo_pc when specified
1196 // as an <offset-from-low-pc>.
1198 // Returns the hi_pc or fail_value.
1199 //----------------------------------------------------------------------
1201 DWARFDebugInfoEntry::GetAttributeHighPC
1203 SymbolFileDWARF* dwarf2Data,
1204 const DWARFCompileUnit* cu,
1206 uint64_t fail_value,
1207 bool check_specification_or_abstract_origin
1210 DWARFFormValue form_value;
1211 if (GetAttributeValue(dwarf2Data, cu, DW_AT_high_pc, form_value, nullptr, check_specification_or_abstract_origin))
1213 dw_form_t form = form_value.Form();
1214 if (form == DW_FORM_addr || form == DW_FORM_GNU_addr_index)
1215 return form_value.Address();
1217 // DWARF4 can specify the hi_pc as an <offset-from-lowpc>
1218 return lo_pc + form_value.Unsigned();
1223 //----------------------------------------------------------------------
1224 // GetAttributeAddressRange
1226 // Get the lo_pc and hi_pc, adding hi_pc to lo_pc when specified
1227 // as an <offset-from-low-pc>.
1229 // Returns true or sets lo_pc and hi_pc to fail_value.
1230 //----------------------------------------------------------------------
1232 DWARFDebugInfoEntry::GetAttributeAddressRange
1234 SymbolFileDWARF* dwarf2Data,
1235 const DWARFCompileUnit* cu,
1238 uint64_t fail_value,
1239 bool check_specification_or_abstract_origin
1242 lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc, fail_value, check_specification_or_abstract_origin);
1243 if (lo_pc != fail_value)
1245 hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, fail_value, check_specification_or_abstract_origin);
1246 if (hi_pc != fail_value)
1255 DWARFDebugInfoEntry::GetAttributeAddressRanges (SymbolFileDWARF* dwarf2Data,
1256 const DWARFCompileUnit* cu,
1257 DWARFRangeList &ranges,
1258 bool check_hi_lo_pc,
1259 bool check_specification_or_abstract_origin) const
1263 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(dwarf2Data,
1267 check_specification_or_abstract_origin);
1268 if (debug_ranges_offset != DW_INVALID_OFFSET)
1270 DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
1272 debug_ranges->FindRanges(debug_ranges_offset, ranges);
1273 ranges.Slide (cu->GetBaseAddress());
1275 else if (check_hi_lo_pc)
1277 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1278 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1279 if (GetAttributeAddressRange (dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS, check_specification_or_abstract_origin))
1282 ranges.Append(DWARFRangeList::Entry(lo_pc, hi_pc - lo_pc));
1285 return ranges.GetSize();
1288 //----------------------------------------------------------------------
1291 // Get value of the DW_AT_name attribute and return it if one exists,
1292 // else return NULL.
1293 //----------------------------------------------------------------------
1295 DWARFDebugInfoEntry::GetName
1297 SymbolFileDWARF* dwarf2Data,
1298 const DWARFCompileUnit* cu
1301 return GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1304 //----------------------------------------------------------------------
1307 // Get value of the DW_AT_MIPS_linkage_name attribute and return it if
1308 // one exists, else return the value of the DW_AT_name attribute
1309 //----------------------------------------------------------------------
1311 DWARFDebugInfoEntry::GetMangledName
1313 SymbolFileDWARF* dwarf2Data,
1314 const DWARFCompileUnit* cu,
1315 bool substitute_name_allowed
1318 const char* name = nullptr;
1320 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name, nullptr, true);
1324 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr, true);
1328 if (!substitute_name_allowed)
1331 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1336 //----------------------------------------------------------------------
1339 // Get value the name for a DIE as it should appear for a
1340 // .debug_pubnames or .debug_pubtypes section.
1341 //----------------------------------------------------------------------
1343 DWARFDebugInfoEntry::GetPubname
1345 SymbolFileDWARF* dwarf2Data,
1346 const DWARFCompileUnit* cu
1349 const char* name = nullptr;
1353 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name, nullptr, true);
1357 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr, true);
1361 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1366 //----------------------------------------------------------------------
1369 // Get value of the DW_AT_name attribute for a debug information entry
1370 // that exists at offset "die_offset" and place that value into the
1371 // supplied stream object. If the DIE is a NULL object "NULL" is placed
1372 // into the stream, and if no DW_AT_name attribute exists for the DIE
1373 // then nothing is printed.
1374 //----------------------------------------------------------------------
1376 DWARFDebugInfoEntry::GetName
1378 SymbolFileDWARF* dwarf2Data,
1379 const DWARFCompileUnit* cu,
1380 const dw_offset_t die_offset,
1384 if (dwarf2Data == NULL)
1386 s.PutCString("NULL");
1390 DWARFDebugInfoEntry die;
1391 lldb::offset_t offset = die_offset;
1392 if (die.Extract(dwarf2Data, cu, &offset))
1396 s.PutCString("NULL");
1401 const char* name = die.GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1412 //----------------------------------------------------------------------
1415 // Follows the type name definition down through all needed tags to
1416 // end up with a fully qualified type name and dump the results to
1417 // the supplied stream. This is used to show the name of types given
1418 // a type identifier.
1419 //----------------------------------------------------------------------
1421 DWARFDebugInfoEntry::AppendTypeName
1423 SymbolFileDWARF* dwarf2Data,
1424 const DWARFCompileUnit* cu,
1425 const dw_offset_t die_offset,
1429 if (dwarf2Data == NULL)
1431 s.PutCString("NULL");
1435 DWARFDebugInfoEntry die;
1436 lldb::offset_t offset = die_offset;
1437 if (die.Extract(dwarf2Data, cu, &offset))
1441 s.PutCString("NULL");
1446 const char* name = die.GetPubname(dwarf2Data, cu);
1452 const DWARFAbbreviationDeclaration* abbrevDecl = die.GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1454 if (abbrevDecl == NULL)
1457 switch (abbrevDecl->Tag())
1459 case DW_TAG_array_type: break; // print out a "[]" after printing the full type of the element below
1460 case DW_TAG_base_type: s.PutCString("base "); break;
1461 case DW_TAG_class_type: s.PutCString("class "); break;
1462 case DW_TAG_const_type: s.PutCString("const "); break;
1463 case DW_TAG_enumeration_type: s.PutCString("enum "); break;
1464 case DW_TAG_file_type: s.PutCString("file "); break;
1465 case DW_TAG_interface_type: s.PutCString("interface "); break;
1466 case DW_TAG_packed_type: s.PutCString("packed "); break;
1467 case DW_TAG_pointer_type: break; // print out a '*' after printing the full type below
1468 case DW_TAG_ptr_to_member_type: break; // print out a '*' after printing the full type below
1469 case DW_TAG_reference_type: break; // print out a '&' after printing the full type below
1470 case DW_TAG_restrict_type: s.PutCString("restrict "); break;
1471 case DW_TAG_set_type: s.PutCString("set "); break;
1472 case DW_TAG_shared_type: s.PutCString("shared "); break;
1473 case DW_TAG_string_type: s.PutCString("string "); break;
1474 case DW_TAG_structure_type: s.PutCString("struct "); break;
1475 case DW_TAG_subrange_type: s.PutCString("subrange "); break;
1476 case DW_TAG_subroutine_type: s.PutCString("function "); break;
1477 case DW_TAG_thrown_type: s.PutCString("thrown "); break;
1478 case DW_TAG_union_type: s.PutCString("union "); break;
1479 case DW_TAG_unspecified_type: s.PutCString("unspecified "); break;
1480 case DW_TAG_volatile_type: s.PutCString("volatile "); break;
1485 // Follow the DW_AT_type if possible
1486 DWARFFormValue form_value;
1487 if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_type, form_value))
1489 uint64_t next_die_offset = form_value.Reference();
1490 result = AppendTypeName(dwarf2Data, cu, next_die_offset, s);
1493 switch (abbrevDecl->Tag())
1495 case DW_TAG_array_type: s.PutCString("[]"); break;
1496 case DW_TAG_pointer_type: s.PutChar('*'); break;
1497 case DW_TAG_ptr_to_member_type: s.PutChar('*'); break;
1498 case DW_TAG_reference_type: s.PutChar('&'); break;
1510 DWARFDebugInfoEntry::Contains (const DWARFDebugInfoEntry *die) const
1514 const dw_offset_t die_offset = die->GetOffset();
1515 if (die_offset > GetOffset())
1517 const DWARFDebugInfoEntry *sibling = GetSibling();
1518 assert (sibling); // TODO: take this out
1520 return die_offset < sibling->GetOffset();
1526 //----------------------------------------------------------------------
1527 // BuildAddressRangeTable
1528 //----------------------------------------------------------------------
1530 DWARFDebugInfoEntry::BuildAddressRangeTable
1532 SymbolFileDWARF* dwarf2Data,
1533 const DWARFCompileUnit* cu,
1534 DWARFDebugAranges* debug_aranges
1539 if (m_tag == DW_TAG_subprogram)
1541 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1542 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1543 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS))
1545 /// 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);
1546 debug_aranges->AppendRange (cu->GetOffset(), lo_pc, hi_pc);
1551 const DWARFDebugInfoEntry* child = GetFirstChild();
1554 child->BuildAddressRangeTable(dwarf2Data, cu, debug_aranges);
1555 child = child->GetSibling();
1560 //----------------------------------------------------------------------
1561 // BuildFunctionAddressRangeTable
1563 // This function is very similar to the BuildAddressRangeTable function
1564 // except that the actual DIE offset for the function is placed in the
1565 // table instead of the compile unit offset (which is the way the
1566 // standard .debug_aranges section does it).
1567 //----------------------------------------------------------------------
1569 DWARFDebugInfoEntry::BuildFunctionAddressRangeTable
1571 SymbolFileDWARF* dwarf2Data,
1572 const DWARFCompileUnit* cu,
1573 DWARFDebugAranges* debug_aranges
1578 if (m_tag == DW_TAG_subprogram)
1580 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1581 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1582 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS))
1584 // printf("BuildAddressRangeTable() 0x%8.8x: [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n", m_offset, lo_pc, hi_pc); // DEBUG ONLY
1585 debug_aranges->AppendRange (GetOffset(), lo_pc, hi_pc);
1589 const DWARFDebugInfoEntry* child = GetFirstChild();
1592 child->BuildFunctionAddressRangeTable(dwarf2Data, cu, debug_aranges);
1593 child = child->GetSibling();
1599 DWARFDebugInfoEntry::GetDeclContextDIEs (DWARFCompileUnit* cu,
1600 DWARFDIECollection &decl_context_dies) const
1603 DWARFDIE die (cu, const_cast<DWARFDebugInfoEntry *>(this));
1604 die.GetDeclContextDIEs(decl_context_dies);
1608 DWARFDebugInfoEntry::GetDWARFDeclContext (SymbolFileDWARF* dwarf2Data,
1609 DWARFCompileUnit* cu,
1610 DWARFDeclContext &dwarf_decl_ctx) const
1612 const dw_tag_t tag = Tag();
1613 if (tag != DW_TAG_compile_unit)
1615 dwarf_decl_ctx.AppendDeclContext(tag, GetName(dwarf2Data, cu));
1616 DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
1617 if (parent_decl_ctx_die && parent_decl_ctx_die.GetDIE() != this)
1619 if (parent_decl_ctx_die.Tag() != DW_TAG_compile_unit)
1620 parent_decl_ctx_die.GetDIE()->GetDWARFDeclContext (parent_decl_ctx_die.GetDWARF(), parent_decl_ctx_die.GetCU(), dwarf_decl_ctx);
1627 DWARFDebugInfoEntry::MatchesDWARFDeclContext (SymbolFileDWARF* dwarf2Data,
1628 DWARFCompileUnit* cu,
1629 const DWARFDeclContext &dwarf_decl_ctx) const
1632 DWARFDeclContext this_dwarf_decl_ctx;
1633 GetDWARFDeclContext (dwarf2Data, cu, this_dwarf_decl_ctx);
1634 return this_dwarf_decl_ctx == dwarf_decl_ctx;
1638 DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
1639 DWARFCompileUnit* cu) const
1641 DWARFAttributes attributes;
1642 GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1643 return GetParentDeclContextDIE (dwarf2Data, cu, attributes);
1647 DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
1648 DWARFCompileUnit* cu,
1649 const DWARFAttributes& attributes) const
1651 DWARFDIE die (cu, const_cast<DWARFDebugInfoEntry *>(this));
1655 // If this is the original DIE that we are searching for a declaration
1656 // for, then don't look in the cache as we don't want our own decl
1657 // context to be our decl context...
1658 if (die.GetDIE() != this)
1662 case DW_TAG_compile_unit:
1663 case DW_TAG_namespace:
1664 case DW_TAG_structure_type:
1665 case DW_TAG_union_type:
1666 case DW_TAG_class_type:
1674 dw_offset_t die_offset;
1676 die_offset = attributes.FormValueAsUnsigned(DW_AT_specification, DW_INVALID_OFFSET);
1677 if (die_offset != DW_INVALID_OFFSET)
1679 DWARFDIE spec_die = cu->GetDIE (die_offset);
1682 DWARFDIE decl_ctx_die = spec_die.GetParentDeclContextDIE();
1684 return decl_ctx_die;
1688 die_offset = attributes.FormValueAsUnsigned(DW_AT_abstract_origin, DW_INVALID_OFFSET);
1689 if (die_offset != DW_INVALID_OFFSET)
1691 DWARFDIE abs_die = cu->GetDIE (die_offset);
1694 DWARFDIE decl_ctx_die = abs_die.GetParentDeclContextDIE();
1696 return decl_ctx_die;
1700 die = die.GetParent();
1707 DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data,
1708 DWARFCompileUnit* cu,
1709 std::string &storage) const
1711 DWARFAttributes attributes;
1712 GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1713 return GetQualifiedName (dwarf2Data, cu, attributes, storage);
1717 DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data,
1718 DWARFCompileUnit* cu,
1719 const DWARFAttributes& attributes,
1720 std::string &storage) const
1723 const char *name = GetName (dwarf2Data, cu);
1727 DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
1729 // TODO: change this to get the correct decl context parent....
1730 while (parent_decl_ctx_die)
1732 const dw_tag_t parent_tag = parent_decl_ctx_die.Tag();
1735 case DW_TAG_namespace:
1737 const char *namespace_name = parent_decl_ctx_die.GetName ();
1740 storage.insert (0, "::");
1741 storage.insert (0, namespace_name);
1745 storage.insert (0, "(anonymous namespace)::");
1747 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1751 case DW_TAG_class_type:
1752 case DW_TAG_structure_type:
1753 case DW_TAG_union_type:
1755 const char *class_union_struct_name = parent_decl_ctx_die.GetName ();
1757 if (class_union_struct_name)
1759 storage.insert (0, "::");
1760 storage.insert (0, class_union_struct_name);
1762 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1767 parent_decl_ctx_die.Clear();
1772 if (storage.empty())
1773 storage.append ("::");
1775 storage.append (name);
1777 if (storage.empty())
1779 return storage.c_str();
1783 //----------------------------------------------------------------------
1785 //----------------------------------------------------------------------
1787 DWARFDebugInfoEntry::LookupAddress
1789 const dw_addr_t address,
1790 SymbolFileDWARF* dwarf2Data,
1791 const DWARFCompileUnit* cu,
1792 DWARFDebugInfoEntry** function_die,
1793 DWARFDebugInfoEntry** block_die
1796 bool found_address = false;
1799 bool check_children = false;
1800 bool match_addr_range = false;
1801 // printf("0x%8.8x: %30s: address = 0x%8.8x - ", m_offset, DW_TAG_value_to_name(tag), address);
1804 case DW_TAG_array_type : break;
1805 case DW_TAG_class_type : check_children = true; break;
1806 case DW_TAG_entry_point : break;
1807 case DW_TAG_enumeration_type : break;
1808 case DW_TAG_formal_parameter : break;
1809 case DW_TAG_imported_declaration : break;
1810 case DW_TAG_label : break;
1811 case DW_TAG_lexical_block : check_children = true; match_addr_range = true; break;
1812 case DW_TAG_member : break;
1813 case DW_TAG_pointer_type : break;
1814 case DW_TAG_reference_type : break;
1815 case DW_TAG_compile_unit : match_addr_range = true; break;
1816 case DW_TAG_string_type : break;
1817 case DW_TAG_structure_type : check_children = true; break;
1818 case DW_TAG_subroutine_type : break;
1819 case DW_TAG_typedef : break;
1820 case DW_TAG_union_type : break;
1821 case DW_TAG_unspecified_parameters : break;
1822 case DW_TAG_variant : break;
1823 case DW_TAG_common_block : check_children = true; break;
1824 case DW_TAG_common_inclusion : break;
1825 case DW_TAG_inheritance : break;
1826 case DW_TAG_inlined_subroutine : check_children = true; match_addr_range = true; break;
1827 case DW_TAG_module : match_addr_range = true; break;
1828 case DW_TAG_ptr_to_member_type : break;
1829 case DW_TAG_set_type : break;
1830 case DW_TAG_subrange_type : break;
1831 case DW_TAG_with_stmt : break;
1832 case DW_TAG_access_declaration : break;
1833 case DW_TAG_base_type : break;
1834 case DW_TAG_catch_block : match_addr_range = true; break;
1835 case DW_TAG_const_type : break;
1836 case DW_TAG_constant : break;
1837 case DW_TAG_enumerator : break;
1838 case DW_TAG_file_type : break;
1839 case DW_TAG_friend : break;
1840 case DW_TAG_namelist : break;
1841 case DW_TAG_namelist_item : break;
1842 case DW_TAG_packed_type : break;
1843 case DW_TAG_subprogram : match_addr_range = true; break;
1844 case DW_TAG_template_type_parameter : break;
1845 case DW_TAG_template_value_parameter : break;
1846 case DW_TAG_thrown_type : break;
1847 case DW_TAG_try_block : match_addr_range = true; break;
1848 case DW_TAG_variant_part : break;
1849 case DW_TAG_variable : break;
1850 case DW_TAG_volatile_type : break;
1851 case DW_TAG_dwarf_procedure : break;
1852 case DW_TAG_restrict_type : break;
1853 case DW_TAG_interface_type : break;
1854 case DW_TAG_namespace : check_children = true; break;
1855 case DW_TAG_imported_module : break;
1856 case DW_TAG_unspecified_type : break;
1857 case DW_TAG_partial_unit : break;
1858 case DW_TAG_imported_unit : break;
1859 case DW_TAG_shared_type : break;
1863 if (match_addr_range)
1865 dw_addr_t lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
1866 if (lo_pc != LLDB_INVALID_ADDRESS)
1868 dw_addr_t hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, LLDB_INVALID_ADDRESS);
1869 if (hi_pc != LLDB_INVALID_ADDRESS)
1871 // 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);
1872 if ((lo_pc <= address) && (address < hi_pc))
1874 found_address = true;
1875 // puts("***MATCH***");
1878 case DW_TAG_compile_unit: // File
1879 check_children = ((function_die != NULL) || (block_die != NULL));
1882 case DW_TAG_subprogram: // Function
1884 *function_die = this;
1885 check_children = (block_die != NULL);
1888 case DW_TAG_inlined_subroutine: // Inlined Function
1889 case DW_TAG_lexical_block: // Block { } in code
1893 check_children = true;
1898 check_children = true;
1904 { // compile units may not have a valid high/low pc when there
1905 // are address gaps in subroutines so we must always search
1906 // if there is no valid high and low PC
1907 check_children = (m_tag == DW_TAG_compile_unit) && ((function_die != NULL) || (block_die != NULL));
1912 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET);
1913 if (debug_ranges_offset != DW_INVALID_OFFSET)
1915 DWARFRangeList ranges;
1916 DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
1917 debug_ranges->FindRanges(debug_ranges_offset, ranges);
1918 // All DW_AT_ranges are relative to the base address of the
1919 // compile unit. We add the compile unit base address to make
1920 // sure all the addresses are properly fixed up.
1921 ranges.Slide (cu->GetBaseAddress());
1922 if (ranges.FindEntryThatContains(address))
1924 found_address = true;
1925 // puts("***MATCH***");
1928 case DW_TAG_compile_unit: // File
1929 check_children = ((function_die != NULL) || (block_die != NULL));
1932 case DW_TAG_subprogram: // Function
1934 *function_die = this;
1935 check_children = (block_die != NULL);
1938 case DW_TAG_inlined_subroutine: // Inlined Function
1939 case DW_TAG_lexical_block: // Block { } in code
1943 check_children = true;
1948 check_children = true;
1954 check_children = false;
1963 // printf("checking children\n");
1964 DWARFDebugInfoEntry* child = GetFirstChild();
1967 if (child->LookupAddress(address, dwarf2Data, cu, function_die, block_die))
1969 child = child->GetSibling();
1973 return found_address;
1976 const DWARFAbbreviationDeclaration*
1977 DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr (SymbolFileDWARF* dwarf2Data,
1978 const DWARFCompileUnit *cu,
1979 lldb::offset_t &offset) const
1983 offset = GetOffset();
1985 const DWARFAbbreviationDeclarationSet *abbrev_set = cu->GetAbbreviations();
1988 const DWARFAbbreviationDeclaration* abbrev_decl = abbrev_set->GetAbbreviationDeclaration (m_abbr_idx);
1991 // Make sure the abbreviation code still matches. If it doesn't and
1992 // the DWARF data was mmap'ed, the backing file might have been modified
1993 // which is bad news.
1994 const uint64_t abbrev_code = dwarf2Data->get_debug_info_data().GetULEB128 (&offset);
1996 if (abbrev_decl->Code() == abbrev_code)
1999 dwarf2Data->GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("0x%8.8x: the DWARF debug information has been modified (abbrev code was %u, and is now %u)",
2001 (uint32_t)abbrev_decl->Code(),
2002 (uint32_t)abbrev_code);
2006 offset = DW_INVALID_OFFSET;
2012 DWARFDebugInfoEntry::OffsetLessThan (const DWARFDebugInfoEntry& a, const DWARFDebugInfoEntry& b)
2014 return a.GetOffset() < b.GetOffset();
2018 DWARFDebugInfoEntry::DumpDIECollection (Stream &strm, DWARFDebugInfoEntry::collection &die_collection)
2020 DWARFDebugInfoEntry::const_iterator pos;
2021 DWARFDebugInfoEntry::const_iterator end = die_collection.end();
2022 strm.PutCString("\noffset parent sibling child\n");
2023 strm.PutCString("-------- -------- -------- --------\n");
2024 for (pos = die_collection.begin(); pos != end; ++pos)
2026 const DWARFDebugInfoEntry& die_ref = *pos;
2027 const DWARFDebugInfoEntry* p = die_ref.GetParent();
2028 const DWARFDebugInfoEntry* s = die_ref.GetSibling();
2029 const DWARFDebugInfoEntry* c = die_ref.GetFirstChild();
2030 strm.Printf("%.8x: %.8x %.8x %.8x 0x%4.4x %s%s\n",
2031 die_ref.GetOffset(),
2032 p ? p->GetOffset() : 0,
2033 s ? s->GetOffset() : 0,
2034 c ? c->GetOffset() : 0,
2036 DW_TAG_value_to_name(die_ref.Tag()),
2037 die_ref.HasChildren() ? " *" : "");