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();
485 debug_ranges->FindRanges(form_value.Unsigned(), ranges);
486 // All DW_AT_ranges are relative to the base address of the
487 // compile unit. We add the compile unit base address to make
488 // sure all the addresses are properly fixed up.
489 ranges.Slide(cu->GetBaseAddress());
495 name = form_value.AsCString();
498 case DW_AT_MIPS_linkage_name:
499 case DW_AT_linkage_name:
501 mangled = form_value.AsCString();
504 case DW_AT_abstract_origin:
505 die_refs.emplace_back(form_value);
508 case DW_AT_specification:
509 die_refs.emplace_back(form_value);
512 case DW_AT_decl_file:
514 decl_file = form_value.Unsigned();
517 case DW_AT_decl_line:
519 decl_line = form_value.Unsigned();
522 case DW_AT_decl_column:
523 if (decl_column == 0)
524 decl_column = form_value.Unsigned();
527 case DW_AT_call_file:
529 call_file = form_value.Unsigned();
532 case DW_AT_call_line:
534 call_line = form_value.Unsigned();
537 case DW_AT_call_column:
538 if (call_column == 0)
539 call_column = form_value.Unsigned();
542 case DW_AT_frame_base:
545 if (form_value.BlockData())
547 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
548 uint32_t block_length = form_value.Unsigned();
549 frame_base->SetOpcodeData(module, debug_info_data, block_offset, block_length);
553 const DWARFDataExtractor &debug_loc_data = dwarf2Data->get_debug_loc_data();
554 const dw_offset_t debug_loc_offset = form_value.Unsigned();
556 size_t loc_list_length = DWARFExpression::LocationListSize(cu, debug_loc_data, debug_loc_offset);
557 if (loc_list_length > 0)
559 frame_base->SetOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
560 if (lo_pc != LLDB_INVALID_ADDRESS)
562 assert (lo_pc >= cu->GetBaseAddress());
563 frame_base->SetLocationListSlide(lo_pc - cu->GetBaseAddress());
567 set_frame_base_loclist_addr = true;
581 if (ranges.IsEmpty())
583 if (lo_pc != LLDB_INVALID_ADDRESS)
585 if (hi_pc != LLDB_INVALID_ADDRESS && hi_pc > lo_pc)
586 ranges.Append(DWARFRangeList::Entry (lo_pc, hi_pc - lo_pc));
588 ranges.Append(DWARFRangeList::Entry (lo_pc, 0));
592 if (set_frame_base_loclist_addr)
594 dw_addr_t lowest_range_pc = ranges.GetMinRangeBase(0);
595 assert (lowest_range_pc >= cu->GetBaseAddress());
596 frame_base->SetLocationListSlide (lowest_range_pc - cu->GetBaseAddress());
599 if (ranges.IsEmpty() || name == NULL || mangled == NULL)
601 for (const DIERef& die_ref : die_refs)
603 if (die_ref.die_offset != DW_INVALID_OFFSET)
605 DWARFDIE die = dwarf2Data->DebugInfo()->GetDIE(die_ref);
607 die.GetDIE()->GetDIENamesAndRanges(die.GetDWARF(), die.GetCU(), name, mangled, ranges, decl_file, decl_line, decl_column, call_file, call_line, call_column);
611 return !ranges.IsEmpty();
614 //----------------------------------------------------------------------
617 // Dumps a debug information entry and all of it's attributes to the
619 //----------------------------------------------------------------------
621 DWARFDebugInfoEntry::Dump
623 SymbolFileDWARF* dwarf2Data,
624 const DWARFCompileUnit* cu,
626 uint32_t recurse_depth
629 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
630 lldb::offset_t offset = m_offset;
632 if (debug_info_data.ValidOffset(offset))
634 dw_uleb128_t abbrCode = debug_info_data.GetULEB128(&offset);
636 s.Printf("\n0x%8.8x: ", m_offset);
638 if (abbrCode != m_abbr_idx)
640 s.Printf( "error: DWARF has been modified\n");
644 const DWARFAbbreviationDeclaration* abbrevDecl = cu->GetAbbreviations()->GetAbbreviationDeclaration (abbrCode);
648 s.PutCString(DW_TAG_value_to_name(abbrevDecl->Tag()));
649 s.Printf( " [%u] %c\n", abbrCode, abbrevDecl->HasChildren() ? '*':' ');
651 // Dump all data in the .debug_info for the attributes
652 const uint32_t numAttributes = abbrevDecl->NumAttributes();
656 for (i=0; i<numAttributes; ++i)
658 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
660 DumpAttribute(dwarf2Data, cu, debug_info_data, &offset, s, attr, form);
663 const DWARFDebugInfoEntry* child = GetFirstChild();
664 if (recurse_depth > 0 && child)
670 child->Dump(dwarf2Data, cu, s, recurse_depth-1);
671 child = child->GetSibling();
677 s.Printf( "Abbreviation code note found in 'debug_abbrev' class for code: %u\n", abbrCode);
687 DWARFDebugInfoEntry::DumpLocation
689 SymbolFileDWARF* dwarf2Data,
690 DWARFCompileUnit* cu,
694 const DWARFDIE cu_die = cu->GetCompileUnitDIEOnly();
695 const char *cu_name = NULL;
697 cu_name = cu_die.GetName ();
698 const char *obj_file_name = NULL;
699 ObjectFile *obj_file = dwarf2Data->GetObjectFile();
701 obj_file_name = obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>");
702 const char *die_name = GetName (dwarf2Data, cu);
703 s.Printf ("0x%8.8x/0x%8.8x: %-30s (from %s in %s)",
706 die_name ? die_name : "",
707 cu_name ? cu_name : "<NULL>",
708 obj_file_name ? obj_file_name : "<NULL>");
711 //----------------------------------------------------------------------
714 // Dumps a debug information entry attribute along with it's form. Any
715 // special display of attributes is done (disassemble location lists,
716 // show enumeration values for attributes, etc).
717 //----------------------------------------------------------------------
719 DWARFDebugInfoEntry::DumpAttribute
721 SymbolFileDWARF* dwarf2Data,
722 const DWARFCompileUnit* cu,
723 const DWARFDataExtractor& debug_info_data,
724 lldb::offset_t *offset_ptr,
730 bool verbose = s.GetVerbose();
731 bool show_form = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm);
734 s.Offset (*offset_ptr);
737 s.Indent(DW_AT_value_to_name(attr));
741 s.Printf( "[%s", DW_FORM_value_to_name(form));
744 DWARFFormValue form_value(cu, form);
746 if (!form_value.ExtractValue(debug_info_data, offset_ptr))
751 if (form == DW_FORM_indirect)
753 s.Printf( " [%s]", DW_FORM_value_to_name(form_value.Form()));
761 // Always dump form value if verbose is enabled
768 // Check to see if we have any special attribute formatters
771 case DW_AT_stmt_list:
772 if ( verbose ) s.PutCString(" ( ");
773 s.Printf( "0x%8.8" PRIx64, form_value.Unsigned());
774 if ( verbose ) s.PutCString(" )");
778 if ( verbose ) s.PutCString(" ( ");
779 s.PutCString(DW_LANG_value_to_name(form_value.Unsigned()));
780 if ( verbose ) s.PutCString(" )");
784 if ( verbose ) s.PutCString(" ( ");
785 s.PutCString(DW_ATE_value_to_name(form_value.Unsigned()));
786 if ( verbose ) s.PutCString(" )");
789 case DW_AT_frame_base:
791 case DW_AT_data_member_location:
793 const uint8_t* blockData = form_value.BlockData();
799 // Location description is inlined in data in the form value
800 DWARFDataExtractor locationData(debug_info_data, (*offset_ptr) - form_value.Unsigned(), form_value.Unsigned());
801 if ( verbose ) s.PutCString(" ( ");
802 DWARFExpression::PrintDWARFExpression(s,
804 DWARFCompileUnit::GetAddressByteSize(cu),
807 if ( verbose ) s.PutCString(" )");
811 // We have a location list offset as the value that is
812 // the offset into the .debug_loc section that describes
813 // the value over it's lifetime
814 uint64_t debug_loc_offset = form_value.Unsigned();
819 DWARFExpression::PrintDWARFLocationList(s,
821 dwarf2Data->get_debug_loc_data(),
833 case DW_AT_abstract_origin:
834 case DW_AT_specification:
836 uint64_t abstract_die_offset = form_value.Reference();
838 // *ostrm_ptr << HEX32 << abstract_die_offset << " ( ";
839 if ( verbose ) s.PutCString(" ( ");
840 GetName(dwarf2Data, cu, abstract_die_offset, s);
841 if ( verbose ) s.PutCString(" )");
847 uint64_t type_die_offset = form_value.Reference();
851 AppendTypeName(dwarf2Data, cu, type_die_offset, s);
860 lldb::offset_t ranges_offset = form_value.Unsigned();
861 dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0;
863 DWARFDebugRanges::Dump(s, dwarf2Data->get_debug_ranges_data(), &ranges_offset, base_addr);
873 s.PutCString(" )\n");
876 //----------------------------------------------------------------------
877 // Get all attribute values for a given DIE, including following any
878 // specification or abstract origin attributes and including those in
879 // the results. Any duplicate attributes will have the first instance
880 // take precedence (this can happen for declaration attributes).
881 //----------------------------------------------------------------------
883 DWARFDebugInfoEntry::GetAttributes (const DWARFCompileUnit* cu,
884 DWARFFormValue::FixedFormSizes fixed_form_sizes,
885 DWARFAttributes& attributes,
886 uint32_t curr_depth) const
888 SymbolFileDWARF* dwarf2Data = nullptr;
889 const DWARFAbbreviationDeclaration* abbrevDecl = nullptr;
890 lldb::offset_t offset = 0;
893 if (m_tag != DW_TAG_compile_unit)
895 SymbolFileDWARFDwo* dwo_symbol_file = cu->GetDwoSymbolFile();
897 return GetAttributes(dwo_symbol_file->GetCompileUnit(),
903 dwarf2Data = cu->GetSymbolFileDWARF();
904 abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
909 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
911 if (fixed_form_sizes.Empty())
912 fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(
913 cu->GetAddressByteSize(), cu->IsDWARF64());
915 const uint32_t num_attributes = abbrevDecl->NumAttributes();
919 for (i=0; i<num_attributes; ++i)
921 abbrevDecl->GetAttrAndFormByIndexUnchecked (i, attr, form);
923 // If we are tracking down DW_AT_specification or DW_AT_abstract_origin
924 // attributes, the depth will be non-zero. We need to omit certain
925 // attributes that don't make sense.
929 case DW_AT_declaration:
932 // This attribute doesn't make sense when combined with
933 // the DIE that references this DIE. We know a DIE is
934 // referencing this DIE because curr_depth is not zero
939 attributes.Append(cu, offset, attr, form);
943 if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin))
945 DWARFFormValue form_value (cu, form);
946 if (form_value.ExtractValue(debug_info_data, &offset))
948 dw_offset_t die_offset = form_value.Reference();
949 DWARFDIE spec_die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(die_offset);
951 spec_die.GetAttributes(attributes, curr_depth + 1);
956 const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
958 offset += fixed_skip_size;
960 DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
968 return attributes.Size();
972 //----------------------------------------------------------------------
975 // Get the value of an attribute and return the .debug_info offset of the
976 // attribute if it was properly extracted into form_value, or zero
977 // if we fail since an offset of zero is invalid for an attribute (it
978 // would be a compile unit header).
979 //----------------------------------------------------------------------
981 DWARFDebugInfoEntry::GetAttributeValue
983 SymbolFileDWARF* dwarf2Data,
984 const DWARFCompileUnit* cu,
985 const dw_attr_t attr,
986 DWARFFormValue& form_value,
987 dw_offset_t* end_attr_offset_ptr,
988 bool check_specification_or_abstract_origin
991 SymbolFileDWARFDwo* dwo_symbol_file = cu->GetDwoSymbolFile();
992 if (dwo_symbol_file && m_tag != DW_TAG_compile_unit)
993 return GetAttributeValue(dwo_symbol_file,
994 dwo_symbol_file->GetCompileUnit(),
998 check_specification_or_abstract_origin);
1000 lldb::offset_t offset;
1001 const DWARFAbbreviationDeclaration* abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1005 uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
1007 if (attr_idx != DW_INVALID_INDEX)
1009 const DWARFDataExtractor& debug_info_data = dwarf2Data->get_debug_info_data();
1012 while (idx<attr_idx)
1013 DWARFFormValue::SkipValue(abbrevDecl->GetFormByIndex(idx++), debug_info_data, &offset, cu);
1015 const dw_offset_t attr_offset = offset;
1016 form_value.SetCompileUnit(cu);
1017 form_value.SetForm(abbrevDecl->GetFormByIndex(idx));
1018 if (form_value.ExtractValue(debug_info_data, &offset))
1020 if (end_attr_offset_ptr)
1021 *end_attr_offset_ptr = offset;
1027 if (check_specification_or_abstract_origin)
1029 if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value))
1031 DWARFDIE die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(form_value.Reference());
1034 dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(die.GetDWARF(),
1038 end_attr_offset_ptr,
1045 if (GetAttributeValue(dwarf2Data, cu, DW_AT_abstract_origin, form_value))
1047 DWARFDIE die = const_cast<DWARFCompileUnit*>(cu)->GetDIE(form_value.Reference());
1050 dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(die.GetDWARF(),
1054 end_attr_offset_ptr,
1062 if (!dwo_symbol_file)
1065 DWARFCompileUnit* dwo_cu = dwo_symbol_file->GetCompileUnit();
1069 DWARFDIE dwo_cu_die = dwo_cu->GetCompileUnitDIEOnly();
1070 if (!dwo_cu_die.IsValid())
1073 return dwo_cu_die.GetDIE()->GetAttributeValue(dwo_symbol_file,
1077 end_attr_offset_ptr,
1078 check_specification_or_abstract_origin);
1081 //----------------------------------------------------------------------
1082 // GetAttributeValueAsString
1084 // Get the value of an attribute as a string return it. The resulting
1085 // pointer to the string data exists within the supplied SymbolFileDWARF
1086 // and will only be available as long as the SymbolFileDWARF is still around
1087 // and it's content doesn't change.
1088 //----------------------------------------------------------------------
1090 DWARFDebugInfoEntry::GetAttributeValueAsString
1092 SymbolFileDWARF* dwarf2Data,
1093 const DWARFCompileUnit* cu,
1094 const dw_attr_t attr,
1095 const char* fail_value,
1096 bool check_specification_or_abstract_origin) const
1098 DWARFFormValue form_value;
1099 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1100 return form_value.AsCString();
1104 //----------------------------------------------------------------------
1105 // GetAttributeValueAsUnsigned
1107 // Get the value of an attribute as unsigned and return it.
1108 //----------------------------------------------------------------------
1110 DWARFDebugInfoEntry::GetAttributeValueAsUnsigned
1112 SymbolFileDWARF* dwarf2Data,
1113 const DWARFCompileUnit* cu,
1114 const dw_attr_t attr,
1115 uint64_t fail_value,
1116 bool check_specification_or_abstract_origin
1119 DWARFFormValue form_value;
1120 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1121 return form_value.Unsigned();
1125 //----------------------------------------------------------------------
1126 // GetAttributeValueAsSigned
1128 // Get the value of an attribute a signed value and return it.
1129 //----------------------------------------------------------------------
1131 DWARFDebugInfoEntry::GetAttributeValueAsSigned
1133 SymbolFileDWARF* dwarf2Data,
1134 const DWARFCompileUnit* cu,
1135 const dw_attr_t attr,
1137 bool check_specification_or_abstract_origin
1140 DWARFFormValue form_value;
1141 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1142 return form_value.Signed();
1146 //----------------------------------------------------------------------
1147 // GetAttributeValueAsReference
1149 // Get the value of an attribute as reference and fix up and compile
1150 // unit relative offsets as needed.
1151 //----------------------------------------------------------------------
1153 DWARFDebugInfoEntry::GetAttributeValueAsReference
1155 SymbolFileDWARF* dwarf2Data,
1156 const DWARFCompileUnit* cu,
1157 const dw_attr_t attr,
1158 uint64_t fail_value,
1159 bool check_specification_or_abstract_origin
1162 DWARFFormValue form_value;
1163 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1164 return form_value.Reference();
1169 DWARFDebugInfoEntry::GetAttributeValueAsAddress
1171 SymbolFileDWARF* dwarf2Data,
1172 const DWARFCompileUnit* cu,
1173 const dw_attr_t attr,
1174 uint64_t fail_value,
1175 bool check_specification_or_abstract_origin
1178 DWARFFormValue form_value;
1179 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr, check_specification_or_abstract_origin))
1180 return form_value.Address();
1184 //----------------------------------------------------------------------
1185 // GetAttributeHighPC
1187 // Get the hi_pc, adding hi_pc to lo_pc when specified
1188 // as an <offset-from-low-pc>.
1190 // Returns the hi_pc or fail_value.
1191 //----------------------------------------------------------------------
1193 DWARFDebugInfoEntry::GetAttributeHighPC
1195 SymbolFileDWARF* dwarf2Data,
1196 const DWARFCompileUnit* cu,
1198 uint64_t fail_value,
1199 bool check_specification_or_abstract_origin
1202 DWARFFormValue form_value;
1203 if (GetAttributeValue(dwarf2Data, cu, DW_AT_high_pc, form_value, nullptr, check_specification_or_abstract_origin))
1205 dw_form_t form = form_value.Form();
1206 if (form == DW_FORM_addr || form == DW_FORM_GNU_addr_index)
1207 return form_value.Address();
1209 // DWARF4 can specify the hi_pc as an <offset-from-lowpc>
1210 return lo_pc + form_value.Unsigned();
1215 //----------------------------------------------------------------------
1216 // GetAttributeAddressRange
1218 // Get the lo_pc and hi_pc, adding hi_pc to lo_pc when specified
1219 // as an <offset-from-low-pc>.
1221 // Returns true or sets lo_pc and hi_pc to fail_value.
1222 //----------------------------------------------------------------------
1224 DWARFDebugInfoEntry::GetAttributeAddressRange
1226 SymbolFileDWARF* dwarf2Data,
1227 const DWARFCompileUnit* cu,
1230 uint64_t fail_value,
1231 bool check_specification_or_abstract_origin
1234 lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc, fail_value, check_specification_or_abstract_origin);
1235 if (lo_pc != fail_value)
1237 hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, fail_value, check_specification_or_abstract_origin);
1238 if (hi_pc != fail_value)
1247 DWARFDebugInfoEntry::GetAttributeAddressRanges (SymbolFileDWARF* dwarf2Data,
1248 const DWARFCompileUnit* cu,
1249 DWARFRangeList &ranges,
1250 bool check_hi_lo_pc,
1251 bool check_specification_or_abstract_origin) const
1255 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(dwarf2Data,
1259 check_specification_or_abstract_origin);
1260 if (debug_ranges_offset != DW_INVALID_OFFSET)
1262 DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
1264 debug_ranges->FindRanges(debug_ranges_offset, ranges);
1265 ranges.Slide (cu->GetBaseAddress());
1267 else if (check_hi_lo_pc)
1269 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1270 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1271 if (GetAttributeAddressRange (dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS, check_specification_or_abstract_origin))
1274 ranges.Append(DWARFRangeList::Entry(lo_pc, hi_pc - lo_pc));
1277 return ranges.GetSize();
1280 //----------------------------------------------------------------------
1283 // Get value of the DW_AT_name attribute and return it if one exists,
1284 // else return NULL.
1285 //----------------------------------------------------------------------
1287 DWARFDebugInfoEntry::GetName
1289 SymbolFileDWARF* dwarf2Data,
1290 const DWARFCompileUnit* cu
1293 return GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1296 //----------------------------------------------------------------------
1299 // Get value of the DW_AT_MIPS_linkage_name attribute and return it if
1300 // one exists, else return the value of the DW_AT_name attribute
1301 //----------------------------------------------------------------------
1303 DWARFDebugInfoEntry::GetMangledName
1305 SymbolFileDWARF* dwarf2Data,
1306 const DWARFCompileUnit* cu,
1307 bool substitute_name_allowed
1310 const char* name = nullptr;
1312 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name, nullptr, true);
1316 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr, true);
1320 if (!substitute_name_allowed)
1323 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1328 //----------------------------------------------------------------------
1331 // Get value the name for a DIE as it should appear for a
1332 // .debug_pubnames or .debug_pubtypes section.
1333 //----------------------------------------------------------------------
1335 DWARFDebugInfoEntry::GetPubname
1337 SymbolFileDWARF* dwarf2Data,
1338 const DWARFCompileUnit* cu
1341 const char* name = nullptr;
1345 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name, nullptr, true);
1349 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr, true);
1353 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1358 //----------------------------------------------------------------------
1361 // Get value of the DW_AT_name attribute for a debug information entry
1362 // that exists at offset "die_offset" and place that value into the
1363 // supplied stream object. If the DIE is a NULL object "NULL" is placed
1364 // into the stream, and if no DW_AT_name attribute exists for the DIE
1365 // then nothing is printed.
1366 //----------------------------------------------------------------------
1368 DWARFDebugInfoEntry::GetName
1370 SymbolFileDWARF* dwarf2Data,
1371 const DWARFCompileUnit* cu,
1372 const dw_offset_t die_offset,
1376 if (dwarf2Data == NULL)
1378 s.PutCString("NULL");
1382 DWARFDebugInfoEntry die;
1383 lldb::offset_t offset = die_offset;
1384 if (die.Extract(dwarf2Data, cu, &offset))
1388 s.PutCString("NULL");
1393 const char* name = die.GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1404 //----------------------------------------------------------------------
1407 // Follows the type name definition down through all needed tags to
1408 // end up with a fully qualified type name and dump the results to
1409 // the supplied stream. This is used to show the name of types given
1410 // a type identifier.
1411 //----------------------------------------------------------------------
1413 DWARFDebugInfoEntry::AppendTypeName
1415 SymbolFileDWARF* dwarf2Data,
1416 const DWARFCompileUnit* cu,
1417 const dw_offset_t die_offset,
1421 if (dwarf2Data == NULL)
1423 s.PutCString("NULL");
1427 DWARFDebugInfoEntry die;
1428 lldb::offset_t offset = die_offset;
1429 if (die.Extract(dwarf2Data, cu, &offset))
1433 s.PutCString("NULL");
1438 const char* name = die.GetPubname(dwarf2Data, cu);
1444 const DWARFAbbreviationDeclaration* abbrevDecl = die.GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1446 if (abbrevDecl == NULL)
1449 switch (abbrevDecl->Tag())
1451 case DW_TAG_array_type: break; // print out a "[]" after printing the full type of the element below
1452 case DW_TAG_base_type: s.PutCString("base "); break;
1453 case DW_TAG_class_type: s.PutCString("class "); break;
1454 case DW_TAG_const_type: s.PutCString("const "); break;
1455 case DW_TAG_enumeration_type: s.PutCString("enum "); break;
1456 case DW_TAG_file_type: s.PutCString("file "); break;
1457 case DW_TAG_interface_type: s.PutCString("interface "); break;
1458 case DW_TAG_packed_type: s.PutCString("packed "); break;
1459 case DW_TAG_pointer_type: break; // print out a '*' after printing the full type below
1460 case DW_TAG_ptr_to_member_type: break; // print out a '*' after printing the full type below
1461 case DW_TAG_reference_type: break; // print out a '&' after printing the full type below
1462 case DW_TAG_restrict_type: s.PutCString("restrict "); break;
1463 case DW_TAG_set_type: s.PutCString("set "); break;
1464 case DW_TAG_shared_type: s.PutCString("shared "); break;
1465 case DW_TAG_string_type: s.PutCString("string "); break;
1466 case DW_TAG_structure_type: s.PutCString("struct "); break;
1467 case DW_TAG_subrange_type: s.PutCString("subrange "); break;
1468 case DW_TAG_subroutine_type: s.PutCString("function "); break;
1469 case DW_TAG_thrown_type: s.PutCString("thrown "); break;
1470 case DW_TAG_union_type: s.PutCString("union "); break;
1471 case DW_TAG_unspecified_type: s.PutCString("unspecified "); break;
1472 case DW_TAG_volatile_type: s.PutCString("volatile "); break;
1477 // Follow the DW_AT_type if possible
1478 DWARFFormValue form_value;
1479 if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_type, form_value))
1481 uint64_t next_die_offset = form_value.Reference();
1482 result = AppendTypeName(dwarf2Data, cu, next_die_offset, s);
1485 switch (abbrevDecl->Tag())
1487 case DW_TAG_array_type: s.PutCString("[]"); break;
1488 case DW_TAG_pointer_type: s.PutChar('*'); break;
1489 case DW_TAG_ptr_to_member_type: s.PutChar('*'); break;
1490 case DW_TAG_reference_type: s.PutChar('&'); break;
1502 DWARFDebugInfoEntry::Contains (const DWARFDebugInfoEntry *die) const
1506 const dw_offset_t die_offset = die->GetOffset();
1507 if (die_offset > GetOffset())
1509 const DWARFDebugInfoEntry *sibling = GetSibling();
1510 assert (sibling); // TODO: take this out
1512 return die_offset < sibling->GetOffset();
1518 //----------------------------------------------------------------------
1519 // BuildAddressRangeTable
1520 //----------------------------------------------------------------------
1522 DWARFDebugInfoEntry::BuildAddressRangeTable
1524 SymbolFileDWARF* dwarf2Data,
1525 const DWARFCompileUnit* cu,
1526 DWARFDebugAranges* debug_aranges
1531 if (m_tag == DW_TAG_subprogram)
1533 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1534 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1535 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS))
1537 /// 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);
1538 debug_aranges->AppendRange (cu->GetOffset(), lo_pc, hi_pc);
1543 const DWARFDebugInfoEntry* child = GetFirstChild();
1546 child->BuildAddressRangeTable(dwarf2Data, cu, debug_aranges);
1547 child = child->GetSibling();
1552 //----------------------------------------------------------------------
1553 // BuildFunctionAddressRangeTable
1555 // This function is very similar to the BuildAddressRangeTable function
1556 // except that the actual DIE offset for the function is placed in the
1557 // table instead of the compile unit offset (which is the way the
1558 // standard .debug_aranges section does it).
1559 //----------------------------------------------------------------------
1561 DWARFDebugInfoEntry::BuildFunctionAddressRangeTable
1563 SymbolFileDWARF* dwarf2Data,
1564 const DWARFCompileUnit* cu,
1565 DWARFDebugAranges* debug_aranges
1570 if (m_tag == DW_TAG_subprogram)
1572 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1573 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1574 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc, LLDB_INVALID_ADDRESS))
1576 // printf("BuildAddressRangeTable() 0x%8.8x: [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n", m_offset, lo_pc, hi_pc); // DEBUG ONLY
1577 debug_aranges->AppendRange (GetOffset(), lo_pc, hi_pc);
1581 const DWARFDebugInfoEntry* child = GetFirstChild();
1584 child->BuildFunctionAddressRangeTable(dwarf2Data, cu, debug_aranges);
1585 child = child->GetSibling();
1591 DWARFDebugInfoEntry::GetDeclContextDIEs (DWARFCompileUnit* cu,
1592 DWARFDIECollection &decl_context_dies) const
1595 DWARFDIE die (cu, const_cast<DWARFDebugInfoEntry *>(this));
1596 die.GetDeclContextDIEs(decl_context_dies);
1600 DWARFDebugInfoEntry::GetDWARFDeclContext (SymbolFileDWARF* dwarf2Data,
1601 DWARFCompileUnit* cu,
1602 DWARFDeclContext &dwarf_decl_ctx) const
1604 const dw_tag_t tag = Tag();
1605 if (tag != DW_TAG_compile_unit)
1607 dwarf_decl_ctx.AppendDeclContext(tag, GetName(dwarf2Data, cu));
1608 DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
1609 if (parent_decl_ctx_die && parent_decl_ctx_die.GetDIE() != this)
1611 if (parent_decl_ctx_die.Tag() != DW_TAG_compile_unit)
1612 parent_decl_ctx_die.GetDIE()->GetDWARFDeclContext (parent_decl_ctx_die.GetDWARF(), parent_decl_ctx_die.GetCU(), dwarf_decl_ctx);
1619 DWARFDebugInfoEntry::MatchesDWARFDeclContext (SymbolFileDWARF* dwarf2Data,
1620 DWARFCompileUnit* cu,
1621 const DWARFDeclContext &dwarf_decl_ctx) const
1624 DWARFDeclContext this_dwarf_decl_ctx;
1625 GetDWARFDeclContext (dwarf2Data, cu, this_dwarf_decl_ctx);
1626 return this_dwarf_decl_ctx == dwarf_decl_ctx;
1630 DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
1631 DWARFCompileUnit* cu) const
1633 DWARFAttributes attributes;
1634 GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1635 return GetParentDeclContextDIE (dwarf2Data, cu, attributes);
1639 DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data,
1640 DWARFCompileUnit* cu,
1641 const DWARFAttributes& attributes) const
1643 DWARFDIE die (cu, const_cast<DWARFDebugInfoEntry *>(this));
1647 // If this is the original DIE that we are searching for a declaration
1648 // for, then don't look in the cache as we don't want our own decl
1649 // context to be our decl context...
1650 if (die.GetDIE() != this)
1654 case DW_TAG_compile_unit:
1655 case DW_TAG_namespace:
1656 case DW_TAG_structure_type:
1657 case DW_TAG_union_type:
1658 case DW_TAG_class_type:
1666 dw_offset_t die_offset;
1668 die_offset = attributes.FormValueAsUnsigned(DW_AT_specification, DW_INVALID_OFFSET);
1669 if (die_offset != DW_INVALID_OFFSET)
1671 DWARFDIE spec_die = cu->GetDIE (die_offset);
1674 DWARFDIE decl_ctx_die = spec_die.GetParentDeclContextDIE();
1676 return decl_ctx_die;
1680 die_offset = attributes.FormValueAsUnsigned(DW_AT_abstract_origin, DW_INVALID_OFFSET);
1681 if (die_offset != DW_INVALID_OFFSET)
1683 DWARFDIE abs_die = cu->GetDIE (die_offset);
1686 DWARFDIE decl_ctx_die = abs_die.GetParentDeclContextDIE();
1688 return decl_ctx_die;
1692 die = die.GetParent();
1699 DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data,
1700 DWARFCompileUnit* cu,
1701 std::string &storage) const
1703 DWARFAttributes attributes;
1704 GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1705 return GetQualifiedName (dwarf2Data, cu, attributes, storage);
1709 DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data,
1710 DWARFCompileUnit* cu,
1711 const DWARFAttributes& attributes,
1712 std::string &storage) const
1715 const char *name = GetName (dwarf2Data, cu);
1719 DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
1721 // TODO: change this to get the correct decl context parent....
1722 while (parent_decl_ctx_die)
1724 const dw_tag_t parent_tag = parent_decl_ctx_die.Tag();
1727 case DW_TAG_namespace:
1729 const char *namespace_name = parent_decl_ctx_die.GetName ();
1732 storage.insert (0, "::");
1733 storage.insert (0, namespace_name);
1737 storage.insert (0, "(anonymous namespace)::");
1739 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1743 case DW_TAG_class_type:
1744 case DW_TAG_structure_type:
1745 case DW_TAG_union_type:
1747 const char *class_union_struct_name = parent_decl_ctx_die.GetName ();
1749 if (class_union_struct_name)
1751 storage.insert (0, "::");
1752 storage.insert (0, class_union_struct_name);
1754 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1759 parent_decl_ctx_die.Clear();
1764 if (storage.empty())
1765 storage.append ("::");
1767 storage.append (name);
1769 if (storage.empty())
1771 return storage.c_str();
1775 //----------------------------------------------------------------------
1777 //----------------------------------------------------------------------
1779 DWARFDebugInfoEntry::LookupAddress
1781 const dw_addr_t address,
1782 SymbolFileDWARF* dwarf2Data,
1783 const DWARFCompileUnit* cu,
1784 DWARFDebugInfoEntry** function_die,
1785 DWARFDebugInfoEntry** block_die
1788 bool found_address = false;
1791 bool check_children = false;
1792 bool match_addr_range = false;
1793 // printf("0x%8.8x: %30s: address = 0x%8.8x - ", m_offset, DW_TAG_value_to_name(tag), address);
1796 case DW_TAG_array_type : break;
1797 case DW_TAG_class_type : check_children = true; break;
1798 case DW_TAG_entry_point : break;
1799 case DW_TAG_enumeration_type : break;
1800 case DW_TAG_formal_parameter : break;
1801 case DW_TAG_imported_declaration : break;
1802 case DW_TAG_label : break;
1803 case DW_TAG_lexical_block : check_children = true; match_addr_range = true; break;
1804 case DW_TAG_member : break;
1805 case DW_TAG_pointer_type : break;
1806 case DW_TAG_reference_type : break;
1807 case DW_TAG_compile_unit : match_addr_range = true; break;
1808 case DW_TAG_string_type : break;
1809 case DW_TAG_structure_type : check_children = true; break;
1810 case DW_TAG_subroutine_type : break;
1811 case DW_TAG_typedef : break;
1812 case DW_TAG_union_type : break;
1813 case DW_TAG_unspecified_parameters : break;
1814 case DW_TAG_variant : break;
1815 case DW_TAG_common_block : check_children = true; break;
1816 case DW_TAG_common_inclusion : break;
1817 case DW_TAG_inheritance : break;
1818 case DW_TAG_inlined_subroutine : check_children = true; match_addr_range = true; break;
1819 case DW_TAG_module : match_addr_range = true; break;
1820 case DW_TAG_ptr_to_member_type : break;
1821 case DW_TAG_set_type : break;
1822 case DW_TAG_subrange_type : break;
1823 case DW_TAG_with_stmt : break;
1824 case DW_TAG_access_declaration : break;
1825 case DW_TAG_base_type : break;
1826 case DW_TAG_catch_block : match_addr_range = true; break;
1827 case DW_TAG_const_type : break;
1828 case DW_TAG_constant : break;
1829 case DW_TAG_enumerator : break;
1830 case DW_TAG_file_type : break;
1831 case DW_TAG_friend : break;
1832 case DW_TAG_namelist : break;
1833 case DW_TAG_namelist_item : break;
1834 case DW_TAG_packed_type : break;
1835 case DW_TAG_subprogram : match_addr_range = true; break;
1836 case DW_TAG_template_type_parameter : break;
1837 case DW_TAG_template_value_parameter : break;
1838 case DW_TAG_thrown_type : break;
1839 case DW_TAG_try_block : match_addr_range = true; break;
1840 case DW_TAG_variant_part : break;
1841 case DW_TAG_variable : break;
1842 case DW_TAG_volatile_type : break;
1843 case DW_TAG_dwarf_procedure : break;
1844 case DW_TAG_restrict_type : break;
1845 case DW_TAG_interface_type : break;
1846 case DW_TAG_namespace : check_children = true; break;
1847 case DW_TAG_imported_module : break;
1848 case DW_TAG_unspecified_type : break;
1849 case DW_TAG_partial_unit : break;
1850 case DW_TAG_imported_unit : break;
1851 case DW_TAG_shared_type : break;
1855 if (match_addr_range)
1857 dw_addr_t lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
1858 if (lo_pc != LLDB_INVALID_ADDRESS)
1860 dw_addr_t hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, LLDB_INVALID_ADDRESS);
1861 if (hi_pc != LLDB_INVALID_ADDRESS)
1863 // 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);
1864 if ((lo_pc <= address) && (address < hi_pc))
1866 found_address = true;
1867 // puts("***MATCH***");
1870 case DW_TAG_compile_unit: // File
1871 check_children = ((function_die != NULL) || (block_die != NULL));
1874 case DW_TAG_subprogram: // Function
1876 *function_die = this;
1877 check_children = (block_die != NULL);
1880 case DW_TAG_inlined_subroutine: // Inlined Function
1881 case DW_TAG_lexical_block: // Block { } in code
1885 check_children = true;
1890 check_children = true;
1896 { // compile units may not have a valid high/low pc when there
1897 // are address gaps in subroutines so we must always search
1898 // if there is no valid high and low PC
1899 check_children = (m_tag == DW_TAG_compile_unit) && ((function_die != NULL) || (block_die != NULL));
1904 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET);
1905 if (debug_ranges_offset != DW_INVALID_OFFSET)
1907 DWARFRangeList ranges;
1908 DWARFDebugRanges* debug_ranges = dwarf2Data->DebugRanges();
1909 debug_ranges->FindRanges(debug_ranges_offset, ranges);
1910 // All DW_AT_ranges are relative to the base address of the
1911 // compile unit. We add the compile unit base address to make
1912 // sure all the addresses are properly fixed up.
1913 ranges.Slide (cu->GetBaseAddress());
1914 if (ranges.FindEntryThatContains(address))
1916 found_address = true;
1917 // puts("***MATCH***");
1920 case DW_TAG_compile_unit: // File
1921 check_children = ((function_die != NULL) || (block_die != NULL));
1924 case DW_TAG_subprogram: // Function
1926 *function_die = this;
1927 check_children = (block_die != NULL);
1930 case DW_TAG_inlined_subroutine: // Inlined Function
1931 case DW_TAG_lexical_block: // Block { } in code
1935 check_children = true;
1940 check_children = true;
1946 check_children = false;
1955 // printf("checking children\n");
1956 DWARFDebugInfoEntry* child = GetFirstChild();
1959 if (child->LookupAddress(address, dwarf2Data, cu, function_die, block_die))
1961 child = child->GetSibling();
1965 return found_address;
1968 const DWARFAbbreviationDeclaration*
1969 DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr (SymbolFileDWARF* dwarf2Data,
1970 const DWARFCompileUnit *cu,
1971 lldb::offset_t &offset) const
1975 offset = GetOffset();
1977 const DWARFAbbreviationDeclarationSet *abbrev_set = cu->GetAbbreviations();
1980 const DWARFAbbreviationDeclaration* abbrev_decl = abbrev_set->GetAbbreviationDeclaration (m_abbr_idx);
1983 // Make sure the abbreviation code still matches. If it doesn't and
1984 // the DWARF data was mmap'ed, the backing file might have been modified
1985 // which is bad news.
1986 const uint64_t abbrev_code = dwarf2Data->get_debug_info_data().GetULEB128 (&offset);
1988 if (abbrev_decl->Code() == abbrev_code)
1991 dwarf2Data->GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("0x%8.8x: the DWARF debug information has been modified (abbrev code was %u, and is now %u)",
1993 (uint32_t)abbrev_decl->Code(),
1994 (uint32_t)abbrev_code);
1998 offset = DW_INVALID_OFFSET;
2004 DWARFDebugInfoEntry::OffsetLessThan (const DWARFDebugInfoEntry& a, const DWARFDebugInfoEntry& b)
2006 return a.GetOffset() < b.GetOffset();
2010 DWARFDebugInfoEntry::DumpDIECollection (Stream &strm, DWARFDebugInfoEntry::collection &die_collection)
2012 DWARFDebugInfoEntry::const_iterator pos;
2013 DWARFDebugInfoEntry::const_iterator end = die_collection.end();
2014 strm.PutCString("\noffset parent sibling child\n");
2015 strm.PutCString("-------- -------- -------- --------\n");
2016 for (pos = die_collection.begin(); pos != end; ++pos)
2018 const DWARFDebugInfoEntry& die_ref = *pos;
2019 const DWARFDebugInfoEntry* p = die_ref.GetParent();
2020 const DWARFDebugInfoEntry* s = die_ref.GetSibling();
2021 const DWARFDebugInfoEntry* c = die_ref.GetFirstChild();
2022 strm.Printf("%.8x: %.8x %.8x %.8x 0x%4.4x %s%s\n",
2023 die_ref.GetOffset(),
2024 p ? p->GetOffset() : 0,
2025 s ? s->GetOffset() : 0,
2026 c ? c->GetOffset() : 0,
2028 DW_TAG_value_to_name(die_ref.Tag()),
2029 die_ref.HasChildren() ? " *" : "");