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/Expression/DWARFExpression.h"
18 #include "lldb/Symbol/ObjectFile.h"
19 #include "lldb/Utility/Stream.h"
21 #include "DWARFUnit.h"
22 #include "DWARFDIECollection.h"
23 #include "DWARFDebugAbbrev.h"
24 #include "DWARFDebugAranges.h"
25 #include "DWARFDebugInfo.h"
26 #include "DWARFDebugRanges.h"
27 #include "DWARFDeclContext.h"
28 #include "DWARFFormValue.h"
29 #include "SymbolFileDWARF.h"
30 #include "SymbolFileDWARFDwo.h"
32 using namespace lldb_private;
36 bool DWARFDebugInfoEntry::FastExtract(
37 const DWARFDataExtractor &debug_info_data, const DWARFUnit *cu,
38 const DWARFFormValue::FixedFormSizes &fixed_form_sizes,
39 lldb::offset_t *offset_ptr) {
40 m_offset = *offset_ptr;
43 m_empty_children = false;
44 const uint64_t abbr_idx = debug_info_data.GetULEB128(offset_ptr);
45 assert(abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
46 m_abbr_idx = abbr_idx;
48 // assert (fixed_form_sizes); // For best performance this should be
52 lldb::offset_t offset = *offset_ptr;
54 const DWARFAbbreviationDeclaration *abbrevDecl =
55 cu->GetAbbreviations()->GetAbbreviationDeclaration(m_abbr_idx);
57 if (abbrevDecl == NULL) {
58 cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError(
59 "{0x%8.8x}: invalid abbreviation code %u, please file a bug and "
60 "attach the file at the start of this error message",
61 m_offset, (unsigned)abbr_idx);
62 // WE can't parse anymore if the DWARF is borked...
63 *offset_ptr = UINT32_MAX;
66 m_tag = abbrevDecl->Tag();
67 m_has_children = abbrevDecl->HasChildren();
68 // Skip all data in the .debug_info for the attributes
69 const uint32_t numAttributes = abbrevDecl->NumAttributes();
72 for (i = 0; i < numAttributes; ++i) {
73 form = abbrevDecl->GetFormByIndexUnchecked(i);
75 const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
77 offset += fixed_skip_size;
79 bool form_is_indirect = false;
81 form_is_indirect = false;
82 uint32_t form_size = 0;
84 // Blocks if inlined data that have a length field and the data bytes
85 // inlined in the .debug_info
88 form_size = debug_info_data.GetULEB128(&offset);
91 form_size = debug_info_data.GetU8_unchecked(&offset);
94 form_size = debug_info_data.GetU16_unchecked(&offset);
97 form_size = debug_info_data.GetU32_unchecked(&offset);
100 // Inlined NULL terminated C-strings
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:
164 debug_info_data.GetU64(&offset);
166 debug_info_data.GetU32(&offset);
170 *offset_ptr = m_offset;
175 } while (form_is_indirect);
178 *offset_ptr = offset;
182 m_has_children = false;
183 return true; // NULL debug tag entry
189 //----------------------------------------------------------------------
192 // Extract a debug info entry for a given compile unit from the .debug_info and
193 // .debug_abbrev data within the SymbolFileDWARF class starting at the given
195 //----------------------------------------------------------------------
196 bool DWARFDebugInfoEntry::Extract(SymbolFileDWARF *dwarf2Data,
198 lldb::offset_t *offset_ptr) {
199 const DWARFDataExtractor &debug_info_data = cu->GetData();
200 // const DWARFDataExtractor& debug_str_data =
201 // dwarf2Data->get_debug_str_data();
202 const uint32_t cu_end_offset = cu->GetNextCompileUnitOffset();
203 lldb::offset_t offset = *offset_ptr;
204 // if (offset >= cu_end_offset)
205 // Log::Status("DIE at offset 0x%8.8x is beyond the end of the current
206 // compile unit (0x%8.8x)", m_offset, cu_end_offset);
207 if ((offset < cu_end_offset) && debug_info_data.ValidOffset(offset)) {
210 const uint64_t abbr_idx = debug_info_data.GetULEB128(&offset);
211 assert(abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
212 m_abbr_idx = abbr_idx;
214 const DWARFAbbreviationDeclaration *abbrevDecl =
215 cu->GetAbbreviations()->GetAbbreviationDeclaration(abbr_idx);
218 m_tag = abbrevDecl->Tag();
219 m_has_children = abbrevDecl->HasChildren();
221 bool isCompileUnitTag = (m_tag == DW_TAG_compile_unit ||
222 m_tag == DW_TAG_partial_unit);
223 if (cu && isCompileUnitTag)
224 const_cast<DWARFUnit *>(cu)->SetBaseAddress(0);
226 // Skip all data in the .debug_info for the attributes
227 const uint32_t numAttributes = abbrevDecl->NumAttributes();
231 for (i = 0; i < numAttributes; ++i) {
232 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
234 if (isCompileUnitTag &&
235 ((attr == DW_AT_entry_pc) || (attr == DW_AT_low_pc))) {
236 DWARFFormValue form_value(cu, form);
237 if (form_value.ExtractValue(debug_info_data, &offset)) {
238 if (attr == DW_AT_low_pc || attr == DW_AT_entry_pc)
239 const_cast<DWARFUnit *>(cu)->SetBaseAddress(
240 form_value.Address());
243 bool form_is_indirect = false;
245 form_is_indirect = false;
246 uint32_t form_size = 0;
248 // Blocks if inlined data that have a length field and the data
249 // bytes inlined in the .debug_info
250 case DW_FORM_exprloc:
252 form_size = debug_info_data.GetULEB128(&offset);
255 form_size = debug_info_data.GetU8(&offset);
258 form_size = debug_info_data.GetU16(&offset);
261 form_size = debug_info_data.GetU32(&offset);
264 // Inlined NULL terminated C-strings
266 debug_info_data.GetCStr(&offset);
269 // Compile unit address sized values
271 form_size = cu->GetAddressByteSize();
273 case DW_FORM_ref_addr:
274 if (cu->GetVersion() <= 2)
275 form_size = cu->GetAddressByteSize();
277 form_size = cu->IsDWARF64() ? 8 : 4;
281 case DW_FORM_flag_present:
307 case DW_FORM_ref_sig8:
311 // signed or unsigned LEB 128 values
314 case DW_FORM_ref_udata:
315 case DW_FORM_GNU_addr_index:
316 case DW_FORM_GNU_str_index:
317 debug_info_data.Skip_LEB128(&offset);
320 case DW_FORM_indirect:
321 form = debug_info_data.GetULEB128(&offset);
322 form_is_indirect = true;
326 case DW_FORM_sec_offset:
328 debug_info_data.GetU64(&offset);
330 debug_info_data.GetU32(&offset);
334 *offset_ptr = offset;
339 } while (form_is_indirect);
342 *offset_ptr = offset;
347 m_has_children = false;
348 *offset_ptr = offset;
349 return true; // NULL debug tag entry
356 //----------------------------------------------------------------------
359 // Dumps all of a debug information entries parents up until oldest and all of
360 // it's attributes to the specified stream.
361 //----------------------------------------------------------------------
362 void DWARFDebugInfoEntry::DumpAncestry(SymbolFileDWARF *dwarf2Data,
364 const DWARFDebugInfoEntry *oldest,
366 uint32_t recurse_depth) const {
367 const DWARFDebugInfoEntry *parent = GetParent();
368 if (parent && parent != oldest)
369 parent->DumpAncestry(dwarf2Data, cu, oldest, s, 0);
370 Dump(dwarf2Data, cu, s, recurse_depth);
373 //----------------------------------------------------------------------
374 // GetDIENamesAndRanges
376 // Gets the valid address ranges for a given DIE by looking for a
377 // DW_AT_low_pc/DW_AT_high_pc pair, DW_AT_entry_pc, or DW_AT_ranges attributes.
378 //----------------------------------------------------------------------
379 bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
380 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, const char *&name,
381 const char *&mangled, DWARFRangeList &ranges, int &decl_file,
382 int &decl_line, int &decl_column, int &call_file, int &call_line,
383 int &call_column, DWARFExpression *frame_base) const {
384 if (dwarf2Data == nullptr)
387 SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
389 return GetDIENamesAndRanges(
390 dwo_symbol_file, dwo_symbol_file->GetCompileUnit(), name, mangled,
391 ranges, decl_file, decl_line, decl_column, call_file, call_line,
392 call_column, frame_base);
394 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
395 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
396 std::vector<DIERef> die_refs;
397 bool set_frame_base_loclist_addr = false;
399 lldb::offset_t offset;
400 const DWARFAbbreviationDeclaration *abbrevDecl =
401 GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
403 lldb::ModuleSP module = dwarf2Data->GetObjectFile()->GetModule();
406 const DWARFDataExtractor &debug_info_data = cu->GetData();
408 if (!debug_info_data.ValidOffset(offset))
411 const uint32_t numAttributes = abbrevDecl->NumAttributes();
415 bool do_offset = false;
417 for (i = 0; i < numAttributes; ++i) {
418 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
419 DWARFFormValue form_value(cu, form);
420 if (form_value.ExtractValue(debug_info_data, &offset)) {
423 lo_pc = form_value.Address();
431 lo_pc = form_value.Address();
435 if (form_value.Form() == DW_FORM_addr ||
436 form_value.Form() == DW_FORM_GNU_addr_index) {
437 hi_pc = form_value.Address();
439 hi_pc = form_value.Unsigned();
440 if (lo_pc == LLDB_INVALID_ADDRESS)
441 do_offset = hi_pc != LLDB_INVALID_ADDRESS;
443 hi_pc += lo_pc; // DWARF 4 introduces <offset-from-lo-pc> to save
449 const DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges();
451 debug_ranges->FindRanges(cu->GetRangesBase(), form_value.Unsigned(), ranges);
452 // All DW_AT_ranges are relative to the base address of the compile
453 // unit. We add the compile unit base address to make sure all the
454 // addresses are properly fixed up.
455 ranges.Slide(cu->GetBaseAddress());
457 cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError(
458 "{0x%8.8x}: DIE has DW_AT_ranges(0x%" PRIx64
459 ") attribute yet DWARF has no .debug_ranges, please file a bug "
460 "and attach the file at the start of this error message",
461 m_offset, form_value.Unsigned());
467 name = form_value.AsCString();
470 case DW_AT_MIPS_linkage_name:
471 case DW_AT_linkage_name:
473 mangled = form_value.AsCString();
476 case DW_AT_abstract_origin:
477 die_refs.emplace_back(form_value);
480 case DW_AT_specification:
481 die_refs.emplace_back(form_value);
484 case DW_AT_decl_file:
486 decl_file = form_value.Unsigned();
489 case DW_AT_decl_line:
491 decl_line = form_value.Unsigned();
494 case DW_AT_decl_column:
495 if (decl_column == 0)
496 decl_column = form_value.Unsigned();
499 case DW_AT_call_file:
501 call_file = form_value.Unsigned();
504 case DW_AT_call_line:
506 call_line = form_value.Unsigned();
509 case DW_AT_call_column:
510 if (call_column == 0)
511 call_column = form_value.Unsigned();
514 case DW_AT_frame_base:
516 if (form_value.BlockData()) {
517 uint32_t block_offset =
518 form_value.BlockData() - debug_info_data.GetDataStart();
519 uint32_t block_length = form_value.Unsigned();
520 frame_base->SetOpcodeData(module, debug_info_data, block_offset,
523 const DWARFDataExtractor &debug_loc_data =
524 dwarf2Data->get_debug_loc_data();
525 const dw_offset_t debug_loc_offset = form_value.Unsigned();
527 size_t loc_list_length = DWARFExpression::LocationListSize(
528 cu, debug_loc_data, debug_loc_offset);
529 if (loc_list_length > 0) {
530 frame_base->SetOpcodeData(module, debug_loc_data,
531 debug_loc_offset, loc_list_length);
532 if (lo_pc != LLDB_INVALID_ADDRESS) {
533 assert(lo_pc >= cu->GetBaseAddress());
534 frame_base->SetLocationListSlide(lo_pc -
535 cu->GetBaseAddress());
537 set_frame_base_loclist_addr = true;
551 if (ranges.IsEmpty()) {
552 if (lo_pc != LLDB_INVALID_ADDRESS) {
553 if (hi_pc != LLDB_INVALID_ADDRESS && hi_pc > lo_pc)
554 ranges.Append(DWARFRangeList::Entry(lo_pc, hi_pc - lo_pc));
556 ranges.Append(DWARFRangeList::Entry(lo_pc, 0));
560 if (set_frame_base_loclist_addr) {
561 dw_addr_t lowest_range_pc = ranges.GetMinRangeBase(0);
562 assert(lowest_range_pc >= cu->GetBaseAddress());
563 frame_base->SetLocationListSlide(lowest_range_pc - cu->GetBaseAddress());
566 if (ranges.IsEmpty() || name == NULL || mangled == NULL) {
567 for (const DIERef &die_ref : die_refs) {
568 if (die_ref.die_offset != DW_INVALID_OFFSET) {
569 DWARFDIE die = dwarf2Data->GetDIE(die_ref);
571 die.GetDIE()->GetDIENamesAndRanges(
572 die.GetDWARF(), die.GetCU(), name, mangled, ranges, decl_file,
573 decl_line, decl_column, call_file, call_line, call_column);
577 return !ranges.IsEmpty();
580 //----------------------------------------------------------------------
583 // Dumps a debug information entry and all of it's attributes to the specified
585 //----------------------------------------------------------------------
586 void DWARFDebugInfoEntry::Dump(SymbolFileDWARF *dwarf2Data,
587 const DWARFUnit *cu, Stream &s,
588 uint32_t recurse_depth) const {
589 const DWARFDataExtractor &debug_info_data = cu->GetData();
590 lldb::offset_t offset = m_offset;
592 if (debug_info_data.ValidOffset(offset)) {
593 dw_uleb128_t abbrCode = debug_info_data.GetULEB128(&offset);
595 s.Printf("\n0x%8.8x: ", m_offset);
597 if (abbrCode != m_abbr_idx) {
598 s.Printf("error: DWARF has been modified\n");
599 } else if (abbrCode) {
600 const DWARFAbbreviationDeclaration *abbrevDecl =
601 cu->GetAbbreviations()->GetAbbreviationDeclaration(abbrCode);
604 s.PutCString(DW_TAG_value_to_name(abbrevDecl->Tag()));
605 s.Printf(" [%u] %c\n", abbrCode, abbrevDecl->HasChildren() ? '*' : ' ');
607 // Dump all data in the .debug_info for the attributes
608 const uint32_t numAttributes = abbrevDecl->NumAttributes();
612 for (i = 0; i < numAttributes; ++i) {
613 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
615 DumpAttribute(dwarf2Data, cu, debug_info_data, &offset, s, attr,
619 const DWARFDebugInfoEntry *child = GetFirstChild();
620 if (recurse_depth > 0 && child) {
624 child->Dump(dwarf2Data, cu, s, recurse_depth - 1);
625 child = child->GetSibling();
630 s.Printf("Abbreviation code note found in 'debug_abbrev' class for "
639 void DWARFDebugInfoEntry::DumpLocation(SymbolFileDWARF *dwarf2Data,
640 DWARFUnit *cu, Stream &s) const {
641 const DWARFBaseDIE cu_die = cu->GetUnitDIEOnly();
642 const char *cu_name = NULL;
644 cu_name = cu_die.GetName();
645 const char *obj_file_name = NULL;
646 ObjectFile *obj_file = dwarf2Data->GetObjectFile();
649 obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>");
650 const char *die_name = GetName(dwarf2Data, cu);
651 s.Printf("0x%8.8x/0x%8.8x: %-30s (from %s in %s)", cu->GetOffset(),
652 GetOffset(), die_name ? die_name : "", cu_name ? cu_name : "<NULL>",
653 obj_file_name ? obj_file_name : "<NULL>");
656 //----------------------------------------------------------------------
659 // Dumps a debug information entry attribute along with it's form. Any special
660 // display of attributes is done (disassemble location lists, show enumeration
661 // values for attributes, etc).
662 //----------------------------------------------------------------------
663 void DWARFDebugInfoEntry::DumpAttribute(
664 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
665 const DWARFDataExtractor &debug_info_data, lldb::offset_t *offset_ptr,
666 Stream &s, dw_attr_t attr, dw_form_t form) {
667 bool show_form = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm);
670 s.Indent(DW_AT_value_to_name(attr));
673 s.Printf("[%s", DW_FORM_value_to_name(form));
676 DWARFFormValue form_value(cu, form);
678 if (!form_value.ExtractValue(debug_info_data, offset_ptr))
682 if (form == DW_FORM_indirect) {
683 s.Printf(" [%s]", DW_FORM_value_to_name(form_value.Form()));
691 // Check to see if we have any special attribute formatters
693 case DW_AT_stmt_list:
694 s.Printf("0x%8.8" PRIx64, form_value.Unsigned());
698 s.PutCString(DW_LANG_value_to_name(form_value.Unsigned()));
702 s.PutCString(DW_ATE_value_to_name(form_value.Unsigned()));
705 case DW_AT_frame_base:
707 case DW_AT_data_member_location: {
708 const uint8_t *blockData = form_value.BlockData();
710 // Location description is inlined in data in the form value
711 DWARFDataExtractor locationData(debug_info_data,
712 (*offset_ptr) - form_value.Unsigned(),
713 form_value.Unsigned());
714 DWARFExpression::PrintDWARFExpression(
715 s, locationData, DWARFUnit::GetAddressByteSize(cu), 4, false);
717 // We have a location list offset as the value that is the offset into
718 // the .debug_loc section that describes the value over it's lifetime
719 uint64_t debug_loc_offset = form_value.Unsigned();
721 DWARFExpression::PrintDWARFLocationList(
722 s, cu, dwarf2Data->get_debug_loc_data(), debug_loc_offset);
727 case DW_AT_abstract_origin:
728 case DW_AT_specification: {
729 uint64_t abstract_die_offset = form_value.Reference();
731 // *ostrm_ptr << HEX32 << abstract_die_offset << " ( ";
732 GetName(dwarf2Data, cu, abstract_die_offset, s);
736 uint64_t type_die_offset = form_value.Reference();
738 AppendTypeName(dwarf2Data, cu, type_die_offset, s);
743 lldb::offset_t ranges_offset = form_value.Unsigned();
744 dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0;
746 DWARFDebugRanges::Dump(s, dwarf2Data->get_debug_ranges_data(),
747 &ranges_offset, base_addr);
754 s.PutCString(" )\n");
757 //----------------------------------------------------------------------
758 // Get all attribute values for a given DIE, including following any
759 // specification or abstract origin attributes and including those in the
760 // results. Any duplicate attributes will have the first instance take
761 // precedence (this can happen for declaration attributes).
762 //----------------------------------------------------------------------
763 size_t DWARFDebugInfoEntry::GetAttributes(
764 const DWARFUnit *cu, DWARFFormValue::FixedFormSizes fixed_form_sizes,
765 DWARFAttributes &attributes, uint32_t curr_depth) const {
766 SymbolFileDWARF *dwarf2Data = nullptr;
767 const DWARFAbbreviationDeclaration *abbrevDecl = nullptr;
768 lldb::offset_t offset = 0;
770 if (m_tag != DW_TAG_compile_unit && m_tag != DW_TAG_partial_unit) {
771 SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
773 return GetAttributes(dwo_symbol_file->GetCompileUnit(),
774 fixed_form_sizes, attributes, curr_depth);
777 dwarf2Data = cu->GetSymbolFileDWARF();
778 abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
782 const DWARFDataExtractor &debug_info_data = cu->GetData();
784 if (fixed_form_sizes.Empty())
785 fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(
786 cu->GetAddressByteSize(), cu->IsDWARF64());
788 const uint32_t num_attributes = abbrevDecl->NumAttributes();
792 for (i = 0; i < num_attributes; ++i) {
793 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
795 // If we are tracking down DW_AT_specification or DW_AT_abstract_origin
796 // attributes, the depth will be non-zero. We need to omit certain
797 // attributes that don't make sense.
800 case DW_AT_declaration:
801 if (curr_depth > 0) {
802 // This attribute doesn't make sense when combined with the DIE that
803 // references this DIE. We know a DIE is referencing this DIE because
804 // curr_depth is not zero
809 attributes.Append(cu, offset, attr, form);
813 if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin)) {
814 DWARFFormValue form_value(cu, form);
815 if (form_value.ExtractValue(debug_info_data, &offset)) {
816 dw_offset_t die_offset = form_value.Reference();
818 const_cast<DWARFUnit *>(cu)->GetDIE(die_offset);
820 spec_die.GetAttributes(attributes, curr_depth + 1);
823 const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
825 offset += fixed_skip_size;
827 DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
833 return attributes.Size();
836 //----------------------------------------------------------------------
839 // Get the value of an attribute and return the .debug_info offset of the
840 // attribute if it was properly extracted into form_value, or zero if we fail
841 // since an offset of zero is invalid for an attribute (it would be a compile
843 //----------------------------------------------------------------------
844 dw_offset_t DWARFDebugInfoEntry::GetAttributeValue(
845 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
846 const dw_attr_t attr, DWARFFormValue &form_value,
847 dw_offset_t *end_attr_offset_ptr,
848 bool check_specification_or_abstract_origin) const {
849 SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
850 if (dwo_symbol_file && m_tag != DW_TAG_compile_unit &&
851 m_tag != DW_TAG_partial_unit)
852 return GetAttributeValue(dwo_symbol_file, dwo_symbol_file->GetCompileUnit(),
853 attr, form_value, end_attr_offset_ptr,
854 check_specification_or_abstract_origin);
856 lldb::offset_t offset;
857 const DWARFAbbreviationDeclaration *abbrevDecl =
858 GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
861 uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
863 if (attr_idx != DW_INVALID_INDEX) {
864 const DWARFDataExtractor &debug_info_data = cu->GetData();
867 while (idx < attr_idx)
868 DWARFFormValue::SkipValue(abbrevDecl->GetFormByIndex(idx++),
869 debug_info_data, &offset, cu);
871 const dw_offset_t attr_offset = offset;
872 form_value.SetCompileUnit(cu);
873 form_value.SetForm(abbrevDecl->GetFormByIndex(idx));
874 if (form_value.ExtractValue(debug_info_data, &offset)) {
875 if (end_attr_offset_ptr)
876 *end_attr_offset_ptr = offset;
882 if (check_specification_or_abstract_origin) {
883 if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value)) {
885 const_cast<DWARFUnit *>(cu)->GetDIE(form_value.Reference());
887 dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(
888 die.GetDWARF(), die.GetCU(), attr, form_value, end_attr_offset_ptr,
895 if (GetAttributeValue(dwarf2Data, cu, DW_AT_abstract_origin, form_value)) {
897 const_cast<DWARFUnit *>(cu)->GetDIE(form_value.Reference());
899 dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(
900 die.GetDWARF(), die.GetCU(), attr, form_value, end_attr_offset_ptr,
908 if (!dwo_symbol_file)
911 DWARFUnit *dwo_cu = dwo_symbol_file->GetCompileUnit();
915 DWARFBaseDIE dwo_cu_die = dwo_cu->GetUnitDIEOnly();
916 if (!dwo_cu_die.IsValid())
919 return dwo_cu_die.GetDIE()->GetAttributeValue(
920 dwo_symbol_file, dwo_cu, attr, form_value, end_attr_offset_ptr,
921 check_specification_or_abstract_origin);
924 //----------------------------------------------------------------------
925 // GetAttributeValueAsString
927 // Get the value of an attribute as a string return it. The resulting pointer
928 // to the string data exists within the supplied SymbolFileDWARF and will only
929 // be available as long as the SymbolFileDWARF is still around and it's content
931 //----------------------------------------------------------------------
932 const char *DWARFDebugInfoEntry::GetAttributeValueAsString(
933 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
934 const dw_attr_t attr, const char *fail_value,
935 bool check_specification_or_abstract_origin) const {
936 DWARFFormValue form_value;
937 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
938 check_specification_or_abstract_origin))
939 return form_value.AsCString();
943 //----------------------------------------------------------------------
944 // GetAttributeValueAsUnsigned
946 // Get the value of an attribute as unsigned and return it.
947 //----------------------------------------------------------------------
948 uint64_t DWARFDebugInfoEntry::GetAttributeValueAsUnsigned(
949 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
950 const dw_attr_t attr, uint64_t fail_value,
951 bool check_specification_or_abstract_origin) const {
952 DWARFFormValue form_value;
953 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
954 check_specification_or_abstract_origin))
955 return form_value.Unsigned();
959 //----------------------------------------------------------------------
960 // GetAttributeValueAsSigned
962 // Get the value of an attribute a signed value and return it.
963 //----------------------------------------------------------------------
964 int64_t DWARFDebugInfoEntry::GetAttributeValueAsSigned(
965 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
966 const dw_attr_t attr, int64_t fail_value,
967 bool check_specification_or_abstract_origin) const {
968 DWARFFormValue form_value;
969 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
970 check_specification_or_abstract_origin))
971 return form_value.Signed();
975 //----------------------------------------------------------------------
976 // GetAttributeValueAsReference
978 // Get the value of an attribute as reference and fix up and compile unit
979 // relative offsets as needed.
980 //----------------------------------------------------------------------
981 uint64_t DWARFDebugInfoEntry::GetAttributeValueAsReference(
982 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
983 const dw_attr_t attr, uint64_t fail_value,
984 bool check_specification_or_abstract_origin) const {
985 DWARFFormValue form_value;
986 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
987 check_specification_or_abstract_origin))
988 return form_value.Reference();
992 uint64_t DWARFDebugInfoEntry::GetAttributeValueAsAddress(
993 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
994 const dw_attr_t attr, uint64_t fail_value,
995 bool check_specification_or_abstract_origin) const {
996 DWARFFormValue form_value;
997 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
998 check_specification_or_abstract_origin))
999 return form_value.Address();
1003 //----------------------------------------------------------------------
1004 // GetAttributeHighPC
1006 // Get the hi_pc, adding hi_pc to lo_pc when specified as an <offset-from-low-
1009 // Returns the hi_pc or fail_value.
1010 //----------------------------------------------------------------------
1011 dw_addr_t DWARFDebugInfoEntry::GetAttributeHighPC(
1012 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, dw_addr_t lo_pc,
1013 uint64_t fail_value, bool check_specification_or_abstract_origin) const {
1014 DWARFFormValue form_value;
1015 if (GetAttributeValue(dwarf2Data, cu, DW_AT_high_pc, form_value, nullptr,
1016 check_specification_or_abstract_origin)) {
1017 dw_form_t form = form_value.Form();
1018 if (form == DW_FORM_addr || form == DW_FORM_GNU_addr_index)
1019 return form_value.Address();
1021 // DWARF4 can specify the hi_pc as an <offset-from-lowpc>
1022 return lo_pc + form_value.Unsigned();
1027 //----------------------------------------------------------------------
1028 // GetAttributeAddressRange
1030 // Get the lo_pc and hi_pc, adding hi_pc to lo_pc when specified as an <offset-
1033 // Returns true or sets lo_pc and hi_pc to fail_value.
1034 //----------------------------------------------------------------------
1035 bool DWARFDebugInfoEntry::GetAttributeAddressRange(
1036 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, dw_addr_t &lo_pc,
1037 dw_addr_t &hi_pc, uint64_t fail_value,
1038 bool check_specification_or_abstract_origin) const {
1039 lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc, fail_value,
1040 check_specification_or_abstract_origin);
1041 if (lo_pc != fail_value) {
1042 hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, fail_value,
1043 check_specification_or_abstract_origin);
1044 if (hi_pc != fail_value)
1052 size_t DWARFDebugInfoEntry::GetAttributeAddressRanges(
1053 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
1054 DWARFRangeList &ranges, bool check_hi_lo_pc,
1055 bool check_specification_or_abstract_origin) const {
1058 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(
1059 dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET,
1060 check_specification_or_abstract_origin);
1061 if (debug_ranges_offset != DW_INVALID_OFFSET) {
1062 DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges();
1064 debug_ranges->FindRanges(cu->GetRangesBase(), debug_ranges_offset, ranges);
1065 ranges.Slide(cu->GetBaseAddress());
1066 } else if (check_hi_lo_pc) {
1067 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1068 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1069 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc,
1070 LLDB_INVALID_ADDRESS,
1071 check_specification_or_abstract_origin)) {
1073 ranges.Append(DWARFRangeList::Entry(lo_pc, hi_pc - lo_pc));
1076 return ranges.GetSize();
1079 //----------------------------------------------------------------------
1082 // Get value of the DW_AT_name attribute and return it if one exists, else
1084 //----------------------------------------------------------------------
1085 const char *DWARFDebugInfoEntry::GetName(SymbolFileDWARF *dwarf2Data,
1086 const DWARFUnit *cu) const {
1087 return GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1090 //----------------------------------------------------------------------
1093 // Get value of the DW_AT_MIPS_linkage_name attribute and return it if one
1094 // exists, else return the value of the DW_AT_name attribute
1095 //----------------------------------------------------------------------
1097 DWARFDebugInfoEntry::GetMangledName(SymbolFileDWARF *dwarf2Data,
1098 const DWARFUnit *cu,
1099 bool substitute_name_allowed) const {
1100 const char *name = nullptr;
1102 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name,
1107 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr,
1112 if (!substitute_name_allowed)
1115 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1119 //----------------------------------------------------------------------
1122 // Get value the name for a DIE as it should appear for a .debug_pubnames or
1123 // .debug_pubtypes section.
1124 //----------------------------------------------------------------------
1125 const char *DWARFDebugInfoEntry::GetPubname(SymbolFileDWARF *dwarf2Data,
1126 const DWARFUnit *cu) const {
1127 const char *name = nullptr;
1131 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name,
1136 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr,
1141 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1145 //----------------------------------------------------------------------
1148 // Get value of the DW_AT_name attribute for a debug information entry that
1149 // exists at offset "die_offset" and place that value into the supplied stream
1150 // object. If the DIE is a NULL object "NULL" is placed into the stream, and if
1151 // no DW_AT_name attribute exists for the DIE then nothing is printed.
1152 //----------------------------------------------------------------------
1153 bool DWARFDebugInfoEntry::GetName(SymbolFileDWARF *dwarf2Data,
1154 const DWARFUnit *cu,
1155 const dw_offset_t die_offset, Stream &s) {
1156 if (dwarf2Data == NULL) {
1157 s.PutCString("NULL");
1161 DWARFDebugInfoEntry die;
1162 lldb::offset_t offset = die_offset;
1163 if (die.Extract(dwarf2Data, cu, &offset)) {
1165 s.PutCString("NULL");
1168 const char *name = die.GetAttributeValueAsString(
1169 dwarf2Data, cu, DW_AT_name, nullptr, true);
1179 //----------------------------------------------------------------------
1182 // Follows the type name definition down through all needed tags to end up with
1183 // a fully qualified type name and dump the results to the supplied stream.
1184 // This is used to show the name of types given a type identifier.
1185 //----------------------------------------------------------------------
1186 bool DWARFDebugInfoEntry::AppendTypeName(SymbolFileDWARF *dwarf2Data,
1187 const DWARFUnit *cu,
1188 const dw_offset_t die_offset,
1190 if (dwarf2Data == NULL) {
1191 s.PutCString("NULL");
1195 DWARFDebugInfoEntry die;
1196 lldb::offset_t offset = die_offset;
1197 if (die.Extract(dwarf2Data, cu, &offset)) {
1199 s.PutCString("NULL");
1202 const char *name = die.GetPubname(dwarf2Data, cu);
1207 const DWARFAbbreviationDeclaration *abbrevDecl =
1208 die.GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1210 if (abbrevDecl == NULL)
1213 switch (abbrevDecl->Tag()) {
1214 case DW_TAG_array_type:
1215 break; // print out a "[]" after printing the full type of the element
1217 case DW_TAG_base_type:
1218 s.PutCString("base ");
1220 case DW_TAG_class_type:
1221 s.PutCString("class ");
1223 case DW_TAG_const_type:
1224 s.PutCString("const ");
1226 case DW_TAG_enumeration_type:
1227 s.PutCString("enum ");
1229 case DW_TAG_file_type:
1230 s.PutCString("file ");
1232 case DW_TAG_interface_type:
1233 s.PutCString("interface ");
1235 case DW_TAG_packed_type:
1236 s.PutCString("packed ");
1238 case DW_TAG_pointer_type:
1239 break; // print out a '*' after printing the full type below
1240 case DW_TAG_ptr_to_member_type:
1241 break; // print out a '*' after printing the full type below
1242 case DW_TAG_reference_type:
1243 break; // print out a '&' after printing the full type below
1244 case DW_TAG_restrict_type:
1245 s.PutCString("restrict ");
1247 case DW_TAG_set_type:
1248 s.PutCString("set ");
1250 case DW_TAG_shared_type:
1251 s.PutCString("shared ");
1253 case DW_TAG_string_type:
1254 s.PutCString("string ");
1256 case DW_TAG_structure_type:
1257 s.PutCString("struct ");
1259 case DW_TAG_subrange_type:
1260 s.PutCString("subrange ");
1262 case DW_TAG_subroutine_type:
1263 s.PutCString("function ");
1265 case DW_TAG_thrown_type:
1266 s.PutCString("thrown ");
1268 case DW_TAG_union_type:
1269 s.PutCString("union ");
1271 case DW_TAG_unspecified_type:
1272 s.PutCString("unspecified ");
1274 case DW_TAG_volatile_type:
1275 s.PutCString("volatile ");
1281 // Follow the DW_AT_type if possible
1282 DWARFFormValue form_value;
1283 if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_type, form_value)) {
1284 uint64_t next_die_offset = form_value.Reference();
1285 result = AppendTypeName(dwarf2Data, cu, next_die_offset, s);
1288 switch (abbrevDecl->Tag()) {
1289 case DW_TAG_array_type:
1292 case DW_TAG_pointer_type:
1295 case DW_TAG_ptr_to_member_type:
1298 case DW_TAG_reference_type:
1311 //----------------------------------------------------------------------
1312 // BuildAddressRangeTable
1313 //----------------------------------------------------------------------
1314 void DWARFDebugInfoEntry::BuildAddressRangeTable(
1315 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
1316 DWARFDebugAranges *debug_aranges) const {
1318 if (m_tag == DW_TAG_subprogram) {
1319 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1320 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1321 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc,
1322 LLDB_INVALID_ADDRESS)) {
1323 /// printf("BuildAddressRangeTable() 0x%8.8x: %30s: [0x%8.8x -
1324 /// 0x%8.8x)\n", m_offset, DW_TAG_value_to_name(tag), lo_pc, hi_pc);
1325 debug_aranges->AppendRange(cu->GetOffset(), lo_pc, hi_pc);
1329 const DWARFDebugInfoEntry *child = GetFirstChild();
1331 child->BuildAddressRangeTable(dwarf2Data, cu, debug_aranges);
1332 child = child->GetSibling();
1337 //----------------------------------------------------------------------
1338 // BuildFunctionAddressRangeTable
1340 // This function is very similar to the BuildAddressRangeTable function except
1341 // that the actual DIE offset for the function is placed in the table instead
1342 // of the compile unit offset (which is the way the standard .debug_aranges
1343 // section does it).
1344 //----------------------------------------------------------------------
1345 void DWARFDebugInfoEntry::BuildFunctionAddressRangeTable(
1346 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
1347 DWARFDebugAranges *debug_aranges) const {
1349 if (m_tag == DW_TAG_subprogram) {
1350 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1351 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1352 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc,
1353 LLDB_INVALID_ADDRESS)) {
1354 // printf("BuildAddressRangeTable() 0x%8.8x: [0x%16.16" PRIx64 " -
1355 // 0x%16.16" PRIx64 ")\n", m_offset, lo_pc, hi_pc); // DEBUG ONLY
1356 debug_aranges->AppendRange(GetOffset(), lo_pc, hi_pc);
1360 const DWARFDebugInfoEntry *child = GetFirstChild();
1362 child->BuildFunctionAddressRangeTable(dwarf2Data, cu, debug_aranges);
1363 child = child->GetSibling();
1368 void DWARFDebugInfoEntry::GetDeclContextDIEs(
1369 DWARFUnit *cu, DWARFDIECollection &decl_context_dies) const {
1371 DWARFDIE die(cu, const_cast<DWARFDebugInfoEntry *>(this));
1372 die.GetDeclContextDIEs(decl_context_dies);
1375 void DWARFDebugInfoEntry::GetDWARFDeclContext(
1376 SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
1377 DWARFDeclContext &dwarf_decl_ctx) const {
1378 const dw_tag_t tag = Tag();
1379 if (tag != DW_TAG_compile_unit && tag != DW_TAG_partial_unit) {
1380 dwarf_decl_ctx.AppendDeclContext(tag, GetName(dwarf2Data, cu));
1381 DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE(dwarf2Data, cu);
1382 if (parent_decl_ctx_die && parent_decl_ctx_die.GetDIE() != this) {
1383 if (parent_decl_ctx_die.Tag() != DW_TAG_compile_unit &&
1384 parent_decl_ctx_die.Tag() != DW_TAG_partial_unit)
1385 parent_decl_ctx_die.GetDIE()->GetDWARFDeclContext(
1386 parent_decl_ctx_die.GetDWARF(), parent_decl_ctx_die.GetCU(),
1392 bool DWARFDebugInfoEntry::MatchesDWARFDeclContext(
1393 SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
1394 const DWARFDeclContext &dwarf_decl_ctx) const {
1396 DWARFDeclContext this_dwarf_decl_ctx;
1397 GetDWARFDeclContext(dwarf2Data, cu, this_dwarf_decl_ctx);
1398 return this_dwarf_decl_ctx == dwarf_decl_ctx;
1402 DWARFDebugInfoEntry::GetParentDeclContextDIE(SymbolFileDWARF *dwarf2Data,
1403 DWARFUnit *cu) const {
1404 DWARFAttributes attributes;
1405 GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1406 return GetParentDeclContextDIE(dwarf2Data, cu, attributes);
1410 DWARFDebugInfoEntry::GetParentDeclContextDIE(
1411 SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
1412 const DWARFAttributes &attributes) const {
1413 DWARFDIE die(cu, const_cast<DWARFDebugInfoEntry *>(this));
1416 // If this is the original DIE that we are searching for a declaration for,
1417 // then don't look in the cache as we don't want our own decl context to be
1418 // our decl context...
1419 if (die.GetDIE() != this) {
1420 switch (die.Tag()) {
1421 case DW_TAG_compile_unit:
1422 case DW_TAG_partial_unit:
1423 case DW_TAG_namespace:
1424 case DW_TAG_structure_type:
1425 case DW_TAG_union_type:
1426 case DW_TAG_class_type:
1434 dw_offset_t die_offset;
1437 attributes.FormValueAsUnsigned(DW_AT_specification, DW_INVALID_OFFSET);
1438 if (die_offset != DW_INVALID_OFFSET) {
1439 DWARFDIE spec_die = cu->GetDIE(die_offset);
1441 DWARFDIE decl_ctx_die = spec_die.GetParentDeclContextDIE();
1443 return decl_ctx_die;
1447 die_offset = attributes.FormValueAsUnsigned(DW_AT_abstract_origin,
1449 if (die_offset != DW_INVALID_OFFSET) {
1450 DWARFDIE abs_die = cu->GetDIE(die_offset);
1452 DWARFDIE decl_ctx_die = abs_die.GetParentDeclContextDIE();
1454 return decl_ctx_die;
1458 die = die.GetParent();
1463 const char *DWARFDebugInfoEntry::GetQualifiedName(SymbolFileDWARF *dwarf2Data,
1465 std::string &storage) const {
1466 DWARFAttributes attributes;
1467 GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1468 return GetQualifiedName(dwarf2Data, cu, attributes, storage);
1471 const char *DWARFDebugInfoEntry::GetQualifiedName(
1472 SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
1473 const DWARFAttributes &attributes, std::string &storage) const {
1475 const char *name = GetName(dwarf2Data, cu);
1478 DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE(dwarf2Data, cu);
1480 // TODO: change this to get the correct decl context parent....
1481 while (parent_decl_ctx_die) {
1482 const dw_tag_t parent_tag = parent_decl_ctx_die.Tag();
1483 switch (parent_tag) {
1484 case DW_TAG_namespace: {
1485 const char *namespace_name = parent_decl_ctx_die.GetName();
1486 if (namespace_name) {
1487 storage.insert(0, "::");
1488 storage.insert(0, namespace_name);
1490 storage.insert(0, "(anonymous namespace)::");
1492 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1495 case DW_TAG_class_type:
1496 case DW_TAG_structure_type:
1497 case DW_TAG_union_type: {
1498 const char *class_union_struct_name = parent_decl_ctx_die.GetName();
1500 if (class_union_struct_name) {
1501 storage.insert(0, "::");
1502 storage.insert(0, class_union_struct_name);
1504 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1508 parent_decl_ctx_die.Clear();
1513 if (storage.empty())
1514 storage.append("::");
1516 storage.append(name);
1518 if (storage.empty())
1520 return storage.c_str();
1523 //----------------------------------------------------------------------
1525 //----------------------------------------------------------------------
1526 bool DWARFDebugInfoEntry::LookupAddress(const dw_addr_t address,
1527 SymbolFileDWARF *dwarf2Data,
1528 const DWARFUnit *cu,
1529 DWARFDebugInfoEntry **function_die,
1530 DWARFDebugInfoEntry **block_die) {
1531 bool found_address = false;
1533 bool check_children = false;
1534 bool match_addr_range = false;
1535 // printf("0x%8.8x: %30s: address = 0x%8.8x - ", m_offset,
1536 // DW_TAG_value_to_name(tag), address);
1538 case DW_TAG_array_type:
1540 case DW_TAG_class_type:
1541 check_children = true;
1543 case DW_TAG_entry_point:
1545 case DW_TAG_enumeration_type:
1547 case DW_TAG_formal_parameter:
1549 case DW_TAG_imported_declaration:
1553 case DW_TAG_lexical_block:
1554 check_children = true;
1555 match_addr_range = true;
1559 case DW_TAG_pointer_type:
1561 case DW_TAG_reference_type:
1563 case DW_TAG_compile_unit:
1564 match_addr_range = true;
1566 case DW_TAG_string_type:
1568 case DW_TAG_structure_type:
1569 check_children = true;
1571 case DW_TAG_subroutine_type:
1573 case DW_TAG_typedef:
1575 case DW_TAG_union_type:
1577 case DW_TAG_unspecified_parameters:
1579 case DW_TAG_variant:
1581 case DW_TAG_common_block:
1582 check_children = true;
1584 case DW_TAG_common_inclusion:
1586 case DW_TAG_inheritance:
1588 case DW_TAG_inlined_subroutine:
1589 check_children = true;
1590 match_addr_range = true;
1593 match_addr_range = true;
1595 case DW_TAG_ptr_to_member_type:
1597 case DW_TAG_set_type:
1599 case DW_TAG_subrange_type:
1601 case DW_TAG_with_stmt:
1603 case DW_TAG_access_declaration:
1605 case DW_TAG_base_type:
1607 case DW_TAG_catch_block:
1608 match_addr_range = true;
1610 case DW_TAG_const_type:
1612 case DW_TAG_constant:
1614 case DW_TAG_enumerator:
1616 case DW_TAG_file_type:
1620 case DW_TAG_namelist:
1622 case DW_TAG_namelist_item:
1624 case DW_TAG_packed_type:
1626 case DW_TAG_subprogram:
1627 match_addr_range = true;
1629 case DW_TAG_template_type_parameter:
1631 case DW_TAG_template_value_parameter:
1633 case DW_TAG_GNU_template_parameter_pack:
1635 case DW_TAG_thrown_type:
1637 case DW_TAG_try_block:
1638 match_addr_range = true;
1640 case DW_TAG_variant_part:
1642 case DW_TAG_variable:
1644 case DW_TAG_volatile_type:
1646 case DW_TAG_dwarf_procedure:
1648 case DW_TAG_restrict_type:
1650 case DW_TAG_interface_type:
1652 case DW_TAG_namespace:
1653 check_children = true;
1655 case DW_TAG_imported_module:
1657 case DW_TAG_unspecified_type:
1659 case DW_TAG_partial_unit:
1660 match_addr_range = true;
1662 case DW_TAG_imported_unit:
1664 case DW_TAG_shared_type:
1670 if (match_addr_range) {
1671 dw_addr_t lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc,
1672 LLDB_INVALID_ADDRESS);
1673 if (lo_pc != LLDB_INVALID_ADDRESS) {
1675 GetAttributeHighPC(dwarf2Data, cu, lo_pc, LLDB_INVALID_ADDRESS);
1676 if (hi_pc != LLDB_INVALID_ADDRESS) {
1677 // printf("\n0x%8.8x: %30s: address = 0x%8.8x [0x%8.8x - 0x%8.8x) ",
1678 // m_offset, DW_TAG_value_to_name(tag), address, lo_pc, hi_pc);
1679 if ((lo_pc <= address) && (address < hi_pc)) {
1680 found_address = true;
1681 // puts("***MATCH***");
1683 case DW_TAG_compile_unit: // File
1684 case DW_TAG_partial_unit: // File
1685 check_children = ((function_die != NULL) || (block_die != NULL));
1688 case DW_TAG_subprogram: // Function
1690 *function_die = this;
1691 check_children = (block_die != NULL);
1694 case DW_TAG_inlined_subroutine: // Inlined Function
1695 case DW_TAG_lexical_block: // Block { } in code
1698 check_children = true;
1703 check_children = true;
1708 // Compile units may not have a valid high/low pc when there
1709 // are address gaps in subroutines so we must always search
1710 // if there is no valid high and low PC.
1711 check_children = (m_tag == DW_TAG_compile_unit ||
1712 m_tag == DW_TAG_partial_unit) &&
1713 ((function_die != NULL) || (block_die != NULL));
1716 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(
1717 dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET);
1718 if (debug_ranges_offset != DW_INVALID_OFFSET) {
1719 DWARFRangeList ranges;
1720 DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges();
1721 debug_ranges->FindRanges(cu->GetRangesBase(), debug_ranges_offset, ranges);
1722 // All DW_AT_ranges are relative to the base address of the compile
1723 // unit. We add the compile unit base address to make sure all the
1724 // addresses are properly fixed up.
1725 ranges.Slide(cu->GetBaseAddress());
1726 if (ranges.FindEntryThatContains(address)) {
1727 found_address = true;
1728 // puts("***MATCH***");
1730 case DW_TAG_compile_unit: // File
1731 case DW_TAG_partial_unit: // File
1732 check_children = ((function_die != NULL) || (block_die != NULL));
1735 case DW_TAG_subprogram: // Function
1737 *function_die = this;
1738 check_children = (block_die != NULL);
1741 case DW_TAG_inlined_subroutine: // Inlined Function
1742 case DW_TAG_lexical_block: // Block { } in code
1745 check_children = true;
1750 check_children = true;
1754 check_children = false;
1760 if (check_children) {
1761 // printf("checking children\n");
1762 DWARFDebugInfoEntry *child = GetFirstChild();
1764 if (child->LookupAddress(address, dwarf2Data, cu, function_die,
1767 child = child->GetSibling();
1771 return found_address;
1774 const DWARFAbbreviationDeclaration *
1775 DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr(
1776 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
1777 lldb::offset_t &offset) const {
1779 offset = GetOffset();
1781 const DWARFAbbreviationDeclarationSet *abbrev_set = cu->GetAbbreviations();
1783 const DWARFAbbreviationDeclaration *abbrev_decl =
1784 abbrev_set->GetAbbreviationDeclaration(m_abbr_idx);
1786 // Make sure the abbreviation code still matches. If it doesn't and the
1787 // DWARF data was mmap'ed, the backing file might have been modified
1788 // which is bad news.
1789 const uint64_t abbrev_code = cu->GetData().GetULEB128(&offset);
1791 if (abbrev_decl->Code() == abbrev_code)
1794 dwarf2Data->GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
1795 "0x%8.8x: the DWARF debug information has been modified (abbrev "
1796 "code was %u, and is now %u)",
1797 GetOffset(), (uint32_t)abbrev_decl->Code(), (uint32_t)abbrev_code);
1801 offset = DW_INVALID_OFFSET;
1805 bool DWARFDebugInfoEntry::OffsetLessThan(const DWARFDebugInfoEntry &a,
1806 const DWARFDebugInfoEntry &b) {
1807 return a.GetOffset() < b.GetOffset();
1810 void DWARFDebugInfoEntry::DumpDIECollection(
1811 Stream &strm, DWARFDebugInfoEntry::collection &die_collection) {
1812 DWARFDebugInfoEntry::const_iterator pos;
1813 DWARFDebugInfoEntry::const_iterator end = die_collection.end();
1814 strm.PutCString("\noffset parent sibling child\n");
1815 strm.PutCString("-------- -------- -------- --------\n");
1816 for (pos = die_collection.begin(); pos != end; ++pos) {
1817 const DWARFDebugInfoEntry &die_ref = *pos;
1818 const DWARFDebugInfoEntry *p = die_ref.GetParent();
1819 const DWARFDebugInfoEntry *s = die_ref.GetSibling();
1820 const DWARFDebugInfoEntry *c = die_ref.GetFirstChild();
1821 strm.Printf("%.8x: %.8x %.8x %.8x 0x%4.4x %s%s\n", die_ref.GetOffset(),
1822 p ? p->GetOffset() : 0, s ? s->GetOffset() : 0,
1823 c ? c->GetOffset() : 0, die_ref.Tag(),
1824 DW_TAG_value_to_name(die_ref.Tag()),
1825 die_ref.HasChildren() ? " *" : "");
1829 bool DWARFDebugInfoEntry::operator==(const DWARFDebugInfoEntry &rhs) const {
1830 return m_offset == rhs.m_offset && m_parent_idx == rhs.m_parent_idx &&
1831 m_sibling_idx == rhs.m_sibling_idx &&
1832 m_empty_children == rhs.m_empty_children &&
1833 m_abbr_idx == rhs.m_abbr_idx && m_has_children == rhs.m_has_children &&
1837 bool DWARFDebugInfoEntry::operator!=(const DWARFDebugInfoEntry &rhs) const {
1838 return !(*this == rhs);