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 "DWARFCompileUnit.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 DWARFCompileUnit *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_ptr);
166 debug_info_data.GetU32(offset_ptr);
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
193 // .debug_info and .debug_abbrev data within the SymbolFileDWARF class
194 // starting at the given offset
195 //----------------------------------------------------------------------
196 bool DWARFDebugInfoEntry::Extract(SymbolFileDWARF *dwarf2Data,
197 const DWARFCompileUnit *cu,
198 lldb::offset_t *offset_ptr) {
199 const DWARFDataExtractor &debug_info_data = dwarf2Data->get_debug_info_data();
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 if (cu && isCompileUnitTag)
223 const_cast<DWARFCompileUnit *>(cu)->SetBaseAddress(0);
225 // Skip all data in the .debug_info for the attributes
226 const uint32_t numAttributes = abbrevDecl->NumAttributes();
230 for (i = 0; i < numAttributes; ++i) {
231 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
233 if (isCompileUnitTag &&
234 ((attr == DW_AT_entry_pc) || (attr == DW_AT_low_pc))) {
235 DWARFFormValue form_value(cu, form);
236 if (form_value.ExtractValue(debug_info_data, &offset)) {
237 if (attr == DW_AT_low_pc || attr == DW_AT_entry_pc)
238 const_cast<DWARFCompileUnit *>(cu)->SetBaseAddress(
239 form_value.Address());
242 bool form_is_indirect = false;
244 form_is_indirect = false;
245 uint32_t form_size = 0;
247 // Blocks if inlined data that have a length field and the data
249 // 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_ptr);
330 debug_info_data.GetU32(offset_ptr);
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
360 // all of it's attributes to the specified stream.
361 //----------------------------------------------------------------------
362 void DWARFDebugInfoEntry::DumpAncestry(SymbolFileDWARF *dwarf2Data,
363 const DWARFCompileUnit *cu,
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
379 //----------------------------------------------------------------------
380 bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
381 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu, const char *&name,
382 const char *&mangled, DWARFRangeList &ranges, int &decl_file,
383 int &decl_line, int &decl_column, int &call_file, int &call_line,
384 int &call_column, DWARFExpression *frame_base) const {
385 if (dwarf2Data == nullptr)
388 SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
390 return GetDIENamesAndRanges(
391 dwo_symbol_file, dwo_symbol_file->GetCompileUnit(), name, mangled,
392 ranges, decl_file, decl_line, decl_column, call_file, call_line,
393 call_column, frame_base);
395 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
396 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
397 std::vector<DIERef> die_refs;
398 bool set_frame_base_loclist_addr = false;
400 lldb::offset_t offset;
401 const DWARFAbbreviationDeclaration *abbrevDecl =
402 GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
404 lldb::ModuleSP module = dwarf2Data->GetObjectFile()->GetModule();
407 const DWARFDataExtractor &debug_info_data =
408 dwarf2Data->get_debug_info_data();
410 if (!debug_info_data.ValidOffset(offset))
413 const uint32_t numAttributes = abbrevDecl->NumAttributes();
417 bool do_offset = false;
419 for (i = 0; i < numAttributes; ++i) {
420 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
421 DWARFFormValue form_value(cu, form);
422 if (form_value.ExtractValue(debug_info_data, &offset)) {
425 lo_pc = form_value.Address();
433 lo_pc = form_value.Address();
437 if (form_value.Form() == DW_FORM_addr ||
438 form_value.Form() == DW_FORM_GNU_addr_index) {
439 hi_pc = form_value.Address();
441 hi_pc = form_value.Unsigned();
442 if (lo_pc == LLDB_INVALID_ADDRESS)
443 do_offset = hi_pc != LLDB_INVALID_ADDRESS;
445 hi_pc += lo_pc; // DWARF 4 introduces <offset-from-lo-pc> to save
451 const DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges();
453 debug_ranges->FindRanges(cu->GetRangesBase(), form_value.Unsigned(), ranges);
454 // All DW_AT_ranges are relative to the base address of the
455 // compile unit. We add the compile unit base address to make
456 // sure all the addresses are properly fixed up.
457 ranges.Slide(cu->GetBaseAddress());
459 cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError(
460 "{0x%8.8x}: DIE has DW_AT_ranges(0x%" PRIx64
461 ") attribute yet DWARF has no .debug_ranges, please file a bug "
462 "and attach the file at the start of this error message",
463 m_offset, form_value.Unsigned());
469 name = form_value.AsCString();
472 case DW_AT_MIPS_linkage_name:
473 case DW_AT_linkage_name:
475 mangled = form_value.AsCString();
478 case DW_AT_abstract_origin:
479 die_refs.emplace_back(form_value);
482 case DW_AT_specification:
483 die_refs.emplace_back(form_value);
486 case DW_AT_decl_file:
488 decl_file = form_value.Unsigned();
491 case DW_AT_decl_line:
493 decl_line = form_value.Unsigned();
496 case DW_AT_decl_column:
497 if (decl_column == 0)
498 decl_column = form_value.Unsigned();
501 case DW_AT_call_file:
503 call_file = form_value.Unsigned();
506 case DW_AT_call_line:
508 call_line = form_value.Unsigned();
511 case DW_AT_call_column:
512 if (call_column == 0)
513 call_column = form_value.Unsigned();
516 case DW_AT_frame_base:
518 if (form_value.BlockData()) {
519 uint32_t block_offset =
520 form_value.BlockData() - debug_info_data.GetDataStart();
521 uint32_t block_length = form_value.Unsigned();
522 frame_base->SetOpcodeData(module, debug_info_data, block_offset,
525 const DWARFDataExtractor &debug_loc_data =
526 dwarf2Data->get_debug_loc_data();
527 const dw_offset_t debug_loc_offset = form_value.Unsigned();
529 size_t loc_list_length = DWARFExpression::LocationListSize(
530 cu, debug_loc_data, debug_loc_offset);
531 if (loc_list_length > 0) {
532 frame_base->SetOpcodeData(module, debug_loc_data,
533 debug_loc_offset, loc_list_length);
534 if (lo_pc != LLDB_INVALID_ADDRESS) {
535 assert(lo_pc >= cu->GetBaseAddress());
536 frame_base->SetLocationListSlide(lo_pc -
537 cu->GetBaseAddress());
539 set_frame_base_loclist_addr = true;
553 if (ranges.IsEmpty()) {
554 if (lo_pc != LLDB_INVALID_ADDRESS) {
555 if (hi_pc != LLDB_INVALID_ADDRESS && hi_pc > lo_pc)
556 ranges.Append(DWARFRangeList::Entry(lo_pc, hi_pc - lo_pc));
558 ranges.Append(DWARFRangeList::Entry(lo_pc, 0));
562 if (set_frame_base_loclist_addr) {
563 dw_addr_t lowest_range_pc = ranges.GetMinRangeBase(0);
564 assert(lowest_range_pc >= cu->GetBaseAddress());
565 frame_base->SetLocationListSlide(lowest_range_pc - cu->GetBaseAddress());
568 if (ranges.IsEmpty() || name == NULL || mangled == NULL) {
569 for (const DIERef &die_ref : die_refs) {
570 if (die_ref.die_offset != DW_INVALID_OFFSET) {
571 DWARFDIE die = dwarf2Data->GetDIE(die_ref);
573 die.GetDIE()->GetDIENamesAndRanges(
574 die.GetDWARF(), die.GetCU(), name, mangled, ranges, decl_file,
575 decl_line, decl_column, call_file, call_line, call_column);
579 return !ranges.IsEmpty();
582 //----------------------------------------------------------------------
585 // Dumps a debug information entry and all of it's attributes to the
587 //----------------------------------------------------------------------
588 void DWARFDebugInfoEntry::Dump(SymbolFileDWARF *dwarf2Data,
589 const DWARFCompileUnit *cu, Stream &s,
590 uint32_t recurse_depth) const {
591 const DWARFDataExtractor &debug_info_data = dwarf2Data->get_debug_info_data();
592 lldb::offset_t offset = m_offset;
594 if (debug_info_data.ValidOffset(offset)) {
595 dw_uleb128_t abbrCode = debug_info_data.GetULEB128(&offset);
597 s.Printf("\n0x%8.8x: ", m_offset);
599 if (abbrCode != m_abbr_idx) {
600 s.Printf("error: DWARF has been modified\n");
601 } else if (abbrCode) {
602 const DWARFAbbreviationDeclaration *abbrevDecl =
603 cu->GetAbbreviations()->GetAbbreviationDeclaration(abbrCode);
606 s.PutCString(DW_TAG_value_to_name(abbrevDecl->Tag()));
607 s.Printf(" [%u] %c\n", abbrCode, abbrevDecl->HasChildren() ? '*' : ' ');
609 // Dump all data in the .debug_info for the attributes
610 const uint32_t numAttributes = abbrevDecl->NumAttributes();
614 for (i = 0; i < numAttributes; ++i) {
615 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
617 DumpAttribute(dwarf2Data, cu, debug_info_data, &offset, s, attr,
621 const DWARFDebugInfoEntry *child = GetFirstChild();
622 if (recurse_depth > 0 && child) {
626 child->Dump(dwarf2Data, cu, s, recurse_depth - 1);
627 child = child->GetSibling();
632 s.Printf("Abbreviation code note found in 'debug_abbrev' class for "
641 void DWARFDebugInfoEntry::DumpLocation(SymbolFileDWARF *dwarf2Data,
642 DWARFCompileUnit *cu, Stream &s) const {
643 const DWARFDIE cu_die = cu->GetCompileUnitDIEOnly();
644 const char *cu_name = NULL;
646 cu_name = cu_die.GetName();
647 const char *obj_file_name = NULL;
648 ObjectFile *obj_file = dwarf2Data->GetObjectFile();
651 obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>");
652 const char *die_name = GetName(dwarf2Data, cu);
653 s.Printf("0x%8.8x/0x%8.8x: %-30s (from %s in %s)", cu->GetOffset(),
654 GetOffset(), die_name ? die_name : "", cu_name ? cu_name : "<NULL>",
655 obj_file_name ? obj_file_name : "<NULL>");
658 //----------------------------------------------------------------------
661 // Dumps a debug information entry attribute along with it's form. Any
662 // special display of attributes is done (disassemble location lists,
663 // show enumeration values for attributes, etc).
664 //----------------------------------------------------------------------
665 void DWARFDebugInfoEntry::DumpAttribute(
666 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
667 const DWARFDataExtractor &debug_info_data, lldb::offset_t *offset_ptr,
668 Stream &s, dw_attr_t attr, dw_form_t form) {
669 bool show_form = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm);
672 s.Indent(DW_AT_value_to_name(attr));
675 s.Printf("[%s", DW_FORM_value_to_name(form));
678 DWARFFormValue form_value(cu, form);
680 if (!form_value.ExtractValue(debug_info_data, offset_ptr))
684 if (form == DW_FORM_indirect) {
685 s.Printf(" [%s]", DW_FORM_value_to_name(form_value.Form()));
693 // Check to see if we have any special attribute formatters
695 case DW_AT_stmt_list:
696 s.Printf("0x%8.8" PRIx64, form_value.Unsigned());
700 s.PutCString(DW_LANG_value_to_name(form_value.Unsigned()));
704 s.PutCString(DW_ATE_value_to_name(form_value.Unsigned()));
707 case DW_AT_frame_base:
709 case DW_AT_data_member_location: {
710 const uint8_t *blockData = form_value.BlockData();
712 // Location description is inlined in data in the form value
713 DWARFDataExtractor locationData(debug_info_data,
714 (*offset_ptr) - form_value.Unsigned(),
715 form_value.Unsigned());
716 DWARFExpression::PrintDWARFExpression(
717 s, locationData, DWARFCompileUnit::GetAddressByteSize(cu), 4, false);
719 // We have a location list offset as the value that is
720 // the offset into the .debug_loc section that describes
721 // the value over it's lifetime
722 uint64_t debug_loc_offset = form_value.Unsigned();
724 DWARFExpression::PrintDWARFLocationList(
725 s, cu, dwarf2Data->get_debug_loc_data(), debug_loc_offset);
730 case DW_AT_abstract_origin:
731 case DW_AT_specification: {
732 uint64_t abstract_die_offset = form_value.Reference();
734 // *ostrm_ptr << HEX32 << abstract_die_offset << " ( ";
735 GetName(dwarf2Data, cu, abstract_die_offset, s);
739 uint64_t type_die_offset = form_value.Reference();
741 AppendTypeName(dwarf2Data, cu, type_die_offset, s);
746 lldb::offset_t ranges_offset = form_value.Unsigned();
747 dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0;
749 DWARFDebugRanges::Dump(s, dwarf2Data->get_debug_ranges_data(),
750 &ranges_offset, base_addr);
757 s.PutCString(" )\n");
760 //----------------------------------------------------------------------
761 // Get all attribute values for a given DIE, including following any
762 // specification or abstract origin attributes and including those in
763 // the results. Any duplicate attributes will have the first instance
764 // take precedence (this can happen for declaration attributes).
765 //----------------------------------------------------------------------
766 size_t DWARFDebugInfoEntry::GetAttributes(
767 const DWARFCompileUnit *cu, DWARFFormValue::FixedFormSizes fixed_form_sizes,
768 DWARFAttributes &attributes, uint32_t curr_depth) const {
769 SymbolFileDWARF *dwarf2Data = nullptr;
770 const DWARFAbbreviationDeclaration *abbrevDecl = nullptr;
771 lldb::offset_t offset = 0;
773 if (m_tag != DW_TAG_compile_unit) {
774 SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
776 return GetAttributes(dwo_symbol_file->GetCompileUnit(),
777 fixed_form_sizes, attributes, curr_depth);
780 dwarf2Data = cu->GetSymbolFileDWARF();
781 abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
785 const DWARFDataExtractor &debug_info_data =
786 dwarf2Data->get_debug_info_data();
788 if (fixed_form_sizes.Empty())
789 fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(
790 cu->GetAddressByteSize(), cu->IsDWARF64());
792 const uint32_t num_attributes = abbrevDecl->NumAttributes();
796 for (i = 0; i < num_attributes; ++i) {
797 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
799 // If we are tracking down DW_AT_specification or DW_AT_abstract_origin
800 // attributes, the depth will be non-zero. We need to omit certain
801 // attributes that don't make sense.
804 case DW_AT_declaration:
805 if (curr_depth > 0) {
806 // This attribute doesn't make sense when combined with
807 // the DIE that references this DIE. We know a DIE is
808 // referencing this DIE because curr_depth is not zero
813 attributes.Append(cu, offset, attr, form);
817 if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin)) {
818 DWARFFormValue form_value(cu, form);
819 if (form_value.ExtractValue(debug_info_data, &offset)) {
820 dw_offset_t die_offset = form_value.Reference();
822 const_cast<DWARFCompileUnit *>(cu)->GetDIE(die_offset);
824 spec_die.GetAttributes(attributes, curr_depth + 1);
827 const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
829 offset += fixed_skip_size;
831 DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
837 return attributes.Size();
840 //----------------------------------------------------------------------
843 // Get the value of an attribute and return the .debug_info offset of the
844 // attribute if it was properly extracted into form_value, or zero
845 // if we fail since an offset of zero is invalid for an attribute (it
846 // would be a compile unit header).
847 //----------------------------------------------------------------------
848 dw_offset_t DWARFDebugInfoEntry::GetAttributeValue(
849 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
850 const dw_attr_t attr, DWARFFormValue &form_value,
851 dw_offset_t *end_attr_offset_ptr,
852 bool check_specification_or_abstract_origin) const {
853 SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
854 if (dwo_symbol_file && m_tag != DW_TAG_compile_unit)
855 return GetAttributeValue(dwo_symbol_file, dwo_symbol_file->GetCompileUnit(),
856 attr, form_value, end_attr_offset_ptr,
857 check_specification_or_abstract_origin);
859 lldb::offset_t offset;
860 const DWARFAbbreviationDeclaration *abbrevDecl =
861 GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
864 uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
866 if (attr_idx != DW_INVALID_INDEX) {
867 const DWARFDataExtractor &debug_info_data =
868 dwarf2Data->get_debug_info_data();
871 while (idx < attr_idx)
872 DWARFFormValue::SkipValue(abbrevDecl->GetFormByIndex(idx++),
873 debug_info_data, &offset, cu);
875 const dw_offset_t attr_offset = offset;
876 form_value.SetCompileUnit(cu);
877 form_value.SetForm(abbrevDecl->GetFormByIndex(idx));
878 if (form_value.ExtractValue(debug_info_data, &offset)) {
879 if (end_attr_offset_ptr)
880 *end_attr_offset_ptr = offset;
886 if (check_specification_or_abstract_origin) {
887 if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value)) {
889 const_cast<DWARFCompileUnit *>(cu)->GetDIE(form_value.Reference());
891 dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(
892 die.GetDWARF(), die.GetCU(), attr, form_value, end_attr_offset_ptr,
899 if (GetAttributeValue(dwarf2Data, cu, DW_AT_abstract_origin, form_value)) {
901 const_cast<DWARFCompileUnit *>(cu)->GetDIE(form_value.Reference());
903 dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(
904 die.GetDWARF(), die.GetCU(), attr, form_value, end_attr_offset_ptr,
912 if (!dwo_symbol_file)
915 DWARFCompileUnit *dwo_cu = dwo_symbol_file->GetCompileUnit();
919 DWARFDIE dwo_cu_die = dwo_cu->GetCompileUnitDIEOnly();
920 if (!dwo_cu_die.IsValid())
923 return dwo_cu_die.GetDIE()->GetAttributeValue(
924 dwo_symbol_file, dwo_cu, attr, form_value, end_attr_offset_ptr,
925 check_specification_or_abstract_origin);
928 //----------------------------------------------------------------------
929 // GetAttributeValueAsString
931 // Get the value of an attribute as a string return it. The resulting
932 // pointer to the string data exists within the supplied SymbolFileDWARF
933 // and will only be available as long as the SymbolFileDWARF is still around
934 // and it's content doesn't change.
935 //----------------------------------------------------------------------
936 const char *DWARFDebugInfoEntry::GetAttributeValueAsString(
937 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
938 const dw_attr_t attr, const char *fail_value,
939 bool check_specification_or_abstract_origin) const {
940 DWARFFormValue form_value;
941 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
942 check_specification_or_abstract_origin))
943 return form_value.AsCString();
947 //----------------------------------------------------------------------
948 // GetAttributeValueAsUnsigned
950 // Get the value of an attribute as unsigned and return it.
951 //----------------------------------------------------------------------
952 uint64_t DWARFDebugInfoEntry::GetAttributeValueAsUnsigned(
953 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
954 const dw_attr_t attr, uint64_t fail_value,
955 bool check_specification_or_abstract_origin) const {
956 DWARFFormValue form_value;
957 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
958 check_specification_or_abstract_origin))
959 return form_value.Unsigned();
963 //----------------------------------------------------------------------
964 // GetAttributeValueAsSigned
966 // Get the value of an attribute a signed value and return it.
967 //----------------------------------------------------------------------
968 int64_t DWARFDebugInfoEntry::GetAttributeValueAsSigned(
969 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
970 const dw_attr_t attr, int64_t fail_value,
971 bool check_specification_or_abstract_origin) const {
972 DWARFFormValue form_value;
973 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
974 check_specification_or_abstract_origin))
975 return form_value.Signed();
979 //----------------------------------------------------------------------
980 // GetAttributeValueAsReference
982 // Get the value of an attribute as reference and fix up and compile
983 // unit relative offsets as needed.
984 //----------------------------------------------------------------------
985 uint64_t DWARFDebugInfoEntry::GetAttributeValueAsReference(
986 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
987 const dw_attr_t attr, uint64_t fail_value,
988 bool check_specification_or_abstract_origin) const {
989 DWARFFormValue form_value;
990 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
991 check_specification_or_abstract_origin))
992 return form_value.Reference();
996 uint64_t DWARFDebugInfoEntry::GetAttributeValueAsAddress(
997 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
998 const dw_attr_t attr, uint64_t fail_value,
999 bool check_specification_or_abstract_origin) const {
1000 DWARFFormValue form_value;
1001 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
1002 check_specification_or_abstract_origin))
1003 return form_value.Address();
1007 //----------------------------------------------------------------------
1008 // GetAttributeHighPC
1010 // Get the hi_pc, adding hi_pc to lo_pc when specified
1011 // as an <offset-from-low-pc>.
1013 // Returns the hi_pc or fail_value.
1014 //----------------------------------------------------------------------
1015 dw_addr_t DWARFDebugInfoEntry::GetAttributeHighPC(
1016 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu, dw_addr_t lo_pc,
1017 uint64_t fail_value, bool check_specification_or_abstract_origin) const {
1018 DWARFFormValue form_value;
1019 if (GetAttributeValue(dwarf2Data, cu, DW_AT_high_pc, form_value, nullptr,
1020 check_specification_or_abstract_origin)) {
1021 dw_form_t form = form_value.Form();
1022 if (form == DW_FORM_addr || form == DW_FORM_GNU_addr_index)
1023 return form_value.Address();
1025 // DWARF4 can specify the hi_pc as an <offset-from-lowpc>
1026 return lo_pc + form_value.Unsigned();
1031 //----------------------------------------------------------------------
1032 // GetAttributeAddressRange
1034 // Get the lo_pc and hi_pc, adding hi_pc to lo_pc when specified
1035 // as an <offset-from-low-pc>.
1037 // Returns true or sets lo_pc and hi_pc to fail_value.
1038 //----------------------------------------------------------------------
1039 bool DWARFDebugInfoEntry::GetAttributeAddressRange(
1040 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu, dw_addr_t &lo_pc,
1041 dw_addr_t &hi_pc, uint64_t fail_value,
1042 bool check_specification_or_abstract_origin) const {
1043 lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc, fail_value,
1044 check_specification_or_abstract_origin);
1045 if (lo_pc != fail_value) {
1046 hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, fail_value,
1047 check_specification_or_abstract_origin);
1048 if (hi_pc != fail_value)
1056 size_t DWARFDebugInfoEntry::GetAttributeAddressRanges(
1057 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
1058 DWARFRangeList &ranges, bool check_hi_lo_pc,
1059 bool check_specification_or_abstract_origin) const {
1062 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(
1063 dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET,
1064 check_specification_or_abstract_origin);
1065 if (debug_ranges_offset != DW_INVALID_OFFSET) {
1066 DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges();
1068 debug_ranges->FindRanges(cu->GetRangesBase(), debug_ranges_offset, ranges);
1069 ranges.Slide(cu->GetBaseAddress());
1070 } else if (check_hi_lo_pc) {
1071 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1072 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1073 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc,
1074 LLDB_INVALID_ADDRESS,
1075 check_specification_or_abstract_origin)) {
1077 ranges.Append(DWARFRangeList::Entry(lo_pc, hi_pc - lo_pc));
1080 return ranges.GetSize();
1083 //----------------------------------------------------------------------
1086 // Get value of the DW_AT_name attribute and return it if one exists,
1087 // else return NULL.
1088 //----------------------------------------------------------------------
1089 const char *DWARFDebugInfoEntry::GetName(SymbolFileDWARF *dwarf2Data,
1090 const DWARFCompileUnit *cu) const {
1091 return GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1094 //----------------------------------------------------------------------
1097 // Get value of the DW_AT_MIPS_linkage_name attribute and return it if
1098 // one exists, else return the value of the DW_AT_name attribute
1099 //----------------------------------------------------------------------
1101 DWARFDebugInfoEntry::GetMangledName(SymbolFileDWARF *dwarf2Data,
1102 const DWARFCompileUnit *cu,
1103 bool substitute_name_allowed) const {
1104 const char *name = nullptr;
1106 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name,
1111 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr,
1116 if (!substitute_name_allowed)
1119 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1123 //----------------------------------------------------------------------
1126 // Get value the name for a DIE as it should appear for a
1127 // .debug_pubnames or .debug_pubtypes section.
1128 //----------------------------------------------------------------------
1129 const char *DWARFDebugInfoEntry::GetPubname(SymbolFileDWARF *dwarf2Data,
1130 const DWARFCompileUnit *cu) const {
1131 const char *name = nullptr;
1135 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name,
1140 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr,
1145 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1149 //----------------------------------------------------------------------
1152 // Get value of the DW_AT_name attribute for a debug information entry
1153 // that exists at offset "die_offset" and place that value into the
1154 // supplied stream object. If the DIE is a NULL object "NULL" is placed
1155 // into the stream, and if no DW_AT_name attribute exists for the DIE
1156 // then nothing is printed.
1157 //----------------------------------------------------------------------
1158 bool DWARFDebugInfoEntry::GetName(SymbolFileDWARF *dwarf2Data,
1159 const DWARFCompileUnit *cu,
1160 const dw_offset_t die_offset, Stream &s) {
1161 if (dwarf2Data == NULL) {
1162 s.PutCString("NULL");
1166 DWARFDebugInfoEntry die;
1167 lldb::offset_t offset = die_offset;
1168 if (die.Extract(dwarf2Data, cu, &offset)) {
1170 s.PutCString("NULL");
1173 const char *name = die.GetAttributeValueAsString(
1174 dwarf2Data, cu, DW_AT_name, nullptr, true);
1184 //----------------------------------------------------------------------
1187 // Follows the type name definition down through all needed tags to
1188 // end up with a fully qualified type name and dump the results to
1189 // the supplied stream. This is used to show the name of types given
1190 // a type identifier.
1191 //----------------------------------------------------------------------
1192 bool DWARFDebugInfoEntry::AppendTypeName(SymbolFileDWARF *dwarf2Data,
1193 const DWARFCompileUnit *cu,
1194 const dw_offset_t die_offset,
1196 if (dwarf2Data == NULL) {
1197 s.PutCString("NULL");
1201 DWARFDebugInfoEntry die;
1202 lldb::offset_t offset = die_offset;
1203 if (die.Extract(dwarf2Data, cu, &offset)) {
1205 s.PutCString("NULL");
1208 const char *name = die.GetPubname(dwarf2Data, cu);
1213 const DWARFAbbreviationDeclaration *abbrevDecl =
1214 die.GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1216 if (abbrevDecl == NULL)
1219 switch (abbrevDecl->Tag()) {
1220 case DW_TAG_array_type:
1221 break; // print out a "[]" after printing the full type of the element
1223 case DW_TAG_base_type:
1224 s.PutCString("base ");
1226 case DW_TAG_class_type:
1227 s.PutCString("class ");
1229 case DW_TAG_const_type:
1230 s.PutCString("const ");
1232 case DW_TAG_enumeration_type:
1233 s.PutCString("enum ");
1235 case DW_TAG_file_type:
1236 s.PutCString("file ");
1238 case DW_TAG_interface_type:
1239 s.PutCString("interface ");
1241 case DW_TAG_packed_type:
1242 s.PutCString("packed ");
1244 case DW_TAG_pointer_type:
1245 break; // print out a '*' after printing the full type below
1246 case DW_TAG_ptr_to_member_type:
1247 break; // print out a '*' after printing the full type below
1248 case DW_TAG_reference_type:
1249 break; // print out a '&' after printing the full type below
1250 case DW_TAG_restrict_type:
1251 s.PutCString("restrict ");
1253 case DW_TAG_set_type:
1254 s.PutCString("set ");
1256 case DW_TAG_shared_type:
1257 s.PutCString("shared ");
1259 case DW_TAG_string_type:
1260 s.PutCString("string ");
1262 case DW_TAG_structure_type:
1263 s.PutCString("struct ");
1265 case DW_TAG_subrange_type:
1266 s.PutCString("subrange ");
1268 case DW_TAG_subroutine_type:
1269 s.PutCString("function ");
1271 case DW_TAG_thrown_type:
1272 s.PutCString("thrown ");
1274 case DW_TAG_union_type:
1275 s.PutCString("union ");
1277 case DW_TAG_unspecified_type:
1278 s.PutCString("unspecified ");
1280 case DW_TAG_volatile_type:
1281 s.PutCString("volatile ");
1287 // Follow the DW_AT_type if possible
1288 DWARFFormValue form_value;
1289 if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_type, form_value)) {
1290 uint64_t next_die_offset = form_value.Reference();
1291 result = AppendTypeName(dwarf2Data, cu, next_die_offset, s);
1294 switch (abbrevDecl->Tag()) {
1295 case DW_TAG_array_type:
1298 case DW_TAG_pointer_type:
1301 case DW_TAG_ptr_to_member_type:
1304 case DW_TAG_reference_type:
1317 bool DWARFDebugInfoEntry::Contains(const DWARFDebugInfoEntry *die) const {
1319 const dw_offset_t die_offset = die->GetOffset();
1320 if (die_offset > GetOffset()) {
1321 const DWARFDebugInfoEntry *sibling = GetSibling();
1322 assert(sibling); // TODO: take this out
1324 return die_offset < sibling->GetOffset();
1330 //----------------------------------------------------------------------
1331 // BuildAddressRangeTable
1332 //----------------------------------------------------------------------
1333 void DWARFDebugInfoEntry::BuildAddressRangeTable(
1334 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
1335 DWARFDebugAranges *debug_aranges) const {
1337 if (m_tag == DW_TAG_subprogram) {
1338 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1339 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1340 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc,
1341 LLDB_INVALID_ADDRESS)) {
1342 /// printf("BuildAddressRangeTable() 0x%8.8x: %30s: [0x%8.8x -
1343 /// 0x%8.8x)\n", m_offset, DW_TAG_value_to_name(tag), lo_pc, hi_pc);
1344 debug_aranges->AppendRange(cu->GetOffset(), lo_pc, hi_pc);
1348 const DWARFDebugInfoEntry *child = GetFirstChild();
1350 child->BuildAddressRangeTable(dwarf2Data, cu, debug_aranges);
1351 child = child->GetSibling();
1356 //----------------------------------------------------------------------
1357 // BuildFunctionAddressRangeTable
1359 // This function is very similar to the BuildAddressRangeTable function
1360 // except that the actual DIE offset for the function is placed in the
1361 // table instead of the compile unit offset (which is the way the
1362 // standard .debug_aranges section does it).
1363 //----------------------------------------------------------------------
1364 void DWARFDebugInfoEntry::BuildFunctionAddressRangeTable(
1365 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
1366 DWARFDebugAranges *debug_aranges) const {
1368 if (m_tag == DW_TAG_subprogram) {
1369 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1370 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1371 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc,
1372 LLDB_INVALID_ADDRESS)) {
1373 // printf("BuildAddressRangeTable() 0x%8.8x: [0x%16.16" PRIx64 " -
1374 // 0x%16.16" PRIx64 ")\n", m_offset, lo_pc, hi_pc); // DEBUG ONLY
1375 debug_aranges->AppendRange(GetOffset(), lo_pc, hi_pc);
1379 const DWARFDebugInfoEntry *child = GetFirstChild();
1381 child->BuildFunctionAddressRangeTable(dwarf2Data, cu, debug_aranges);
1382 child = child->GetSibling();
1387 void DWARFDebugInfoEntry::GetDeclContextDIEs(
1388 DWARFCompileUnit *cu, DWARFDIECollection &decl_context_dies) const {
1390 DWARFDIE die(cu, const_cast<DWARFDebugInfoEntry *>(this));
1391 die.GetDeclContextDIEs(decl_context_dies);
1394 void DWARFDebugInfoEntry::GetDWARFDeclContext(
1395 SymbolFileDWARF *dwarf2Data, DWARFCompileUnit *cu,
1396 DWARFDeclContext &dwarf_decl_ctx) const {
1397 const dw_tag_t tag = Tag();
1398 if (tag != DW_TAG_compile_unit) {
1399 dwarf_decl_ctx.AppendDeclContext(tag, GetName(dwarf2Data, cu));
1400 DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE(dwarf2Data, cu);
1401 if (parent_decl_ctx_die && parent_decl_ctx_die.GetDIE() != this) {
1402 if (parent_decl_ctx_die.Tag() != DW_TAG_compile_unit)
1403 parent_decl_ctx_die.GetDIE()->GetDWARFDeclContext(
1404 parent_decl_ctx_die.GetDWARF(), parent_decl_ctx_die.GetCU(),
1410 bool DWARFDebugInfoEntry::MatchesDWARFDeclContext(
1411 SymbolFileDWARF *dwarf2Data, DWARFCompileUnit *cu,
1412 const DWARFDeclContext &dwarf_decl_ctx) const {
1414 DWARFDeclContext this_dwarf_decl_ctx;
1415 GetDWARFDeclContext(dwarf2Data, cu, this_dwarf_decl_ctx);
1416 return this_dwarf_decl_ctx == dwarf_decl_ctx;
1420 DWARFDebugInfoEntry::GetParentDeclContextDIE(SymbolFileDWARF *dwarf2Data,
1421 DWARFCompileUnit *cu) const {
1422 DWARFAttributes attributes;
1423 GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1424 return GetParentDeclContextDIE(dwarf2Data, cu, attributes);
1428 DWARFDebugInfoEntry::GetParentDeclContextDIE(
1429 SymbolFileDWARF *dwarf2Data, DWARFCompileUnit *cu,
1430 const DWARFAttributes &attributes) const {
1431 DWARFDIE die(cu, const_cast<DWARFDebugInfoEntry *>(this));
1434 // If this is the original DIE that we are searching for a declaration
1435 // for, then don't look in the cache as we don't want our own decl
1436 // context to be our decl context...
1437 if (die.GetDIE() != this) {
1438 switch (die.Tag()) {
1439 case DW_TAG_compile_unit:
1440 case DW_TAG_namespace:
1441 case DW_TAG_structure_type:
1442 case DW_TAG_union_type:
1443 case DW_TAG_class_type:
1451 dw_offset_t die_offset;
1454 attributes.FormValueAsUnsigned(DW_AT_specification, DW_INVALID_OFFSET);
1455 if (die_offset != DW_INVALID_OFFSET) {
1456 DWARFDIE spec_die = cu->GetDIE(die_offset);
1458 DWARFDIE decl_ctx_die = spec_die.GetParentDeclContextDIE();
1460 return decl_ctx_die;
1464 die_offset = attributes.FormValueAsUnsigned(DW_AT_abstract_origin,
1466 if (die_offset != DW_INVALID_OFFSET) {
1467 DWARFDIE abs_die = cu->GetDIE(die_offset);
1469 DWARFDIE decl_ctx_die = abs_die.GetParentDeclContextDIE();
1471 return decl_ctx_die;
1475 die = die.GetParent();
1480 const char *DWARFDebugInfoEntry::GetQualifiedName(SymbolFileDWARF *dwarf2Data,
1481 DWARFCompileUnit *cu,
1482 std::string &storage) const {
1483 DWARFAttributes attributes;
1484 GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1485 return GetQualifiedName(dwarf2Data, cu, attributes, storage);
1488 const char *DWARFDebugInfoEntry::GetQualifiedName(
1489 SymbolFileDWARF *dwarf2Data, DWARFCompileUnit *cu,
1490 const DWARFAttributes &attributes, std::string &storage) const {
1492 const char *name = GetName(dwarf2Data, cu);
1495 DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE(dwarf2Data, cu);
1497 // TODO: change this to get the correct decl context parent....
1498 while (parent_decl_ctx_die) {
1499 const dw_tag_t parent_tag = parent_decl_ctx_die.Tag();
1500 switch (parent_tag) {
1501 case DW_TAG_namespace: {
1502 const char *namespace_name = parent_decl_ctx_die.GetName();
1503 if (namespace_name) {
1504 storage.insert(0, "::");
1505 storage.insert(0, namespace_name);
1507 storage.insert(0, "(anonymous namespace)::");
1509 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1512 case DW_TAG_class_type:
1513 case DW_TAG_structure_type:
1514 case DW_TAG_union_type: {
1515 const char *class_union_struct_name = parent_decl_ctx_die.GetName();
1517 if (class_union_struct_name) {
1518 storage.insert(0, "::");
1519 storage.insert(0, class_union_struct_name);
1521 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1525 parent_decl_ctx_die.Clear();
1530 if (storage.empty())
1531 storage.append("::");
1533 storage.append(name);
1535 if (storage.empty())
1537 return storage.c_str();
1540 //----------------------------------------------------------------------
1542 //----------------------------------------------------------------------
1543 bool DWARFDebugInfoEntry::LookupAddress(const dw_addr_t address,
1544 SymbolFileDWARF *dwarf2Data,
1545 const DWARFCompileUnit *cu,
1546 DWARFDebugInfoEntry **function_die,
1547 DWARFDebugInfoEntry **block_die) {
1548 bool found_address = false;
1550 bool check_children = false;
1551 bool match_addr_range = false;
1552 // printf("0x%8.8x: %30s: address = 0x%8.8x - ", m_offset,
1553 // DW_TAG_value_to_name(tag), address);
1555 case DW_TAG_array_type:
1557 case DW_TAG_class_type:
1558 check_children = true;
1560 case DW_TAG_entry_point:
1562 case DW_TAG_enumeration_type:
1564 case DW_TAG_formal_parameter:
1566 case DW_TAG_imported_declaration:
1570 case DW_TAG_lexical_block:
1571 check_children = true;
1572 match_addr_range = true;
1576 case DW_TAG_pointer_type:
1578 case DW_TAG_reference_type:
1580 case DW_TAG_compile_unit:
1581 match_addr_range = true;
1583 case DW_TAG_string_type:
1585 case DW_TAG_structure_type:
1586 check_children = true;
1588 case DW_TAG_subroutine_type:
1590 case DW_TAG_typedef:
1592 case DW_TAG_union_type:
1594 case DW_TAG_unspecified_parameters:
1596 case DW_TAG_variant:
1598 case DW_TAG_common_block:
1599 check_children = true;
1601 case DW_TAG_common_inclusion:
1603 case DW_TAG_inheritance:
1605 case DW_TAG_inlined_subroutine:
1606 check_children = true;
1607 match_addr_range = true;
1610 match_addr_range = true;
1612 case DW_TAG_ptr_to_member_type:
1614 case DW_TAG_set_type:
1616 case DW_TAG_subrange_type:
1618 case DW_TAG_with_stmt:
1620 case DW_TAG_access_declaration:
1622 case DW_TAG_base_type:
1624 case DW_TAG_catch_block:
1625 match_addr_range = true;
1627 case DW_TAG_const_type:
1629 case DW_TAG_constant:
1631 case DW_TAG_enumerator:
1633 case DW_TAG_file_type:
1637 case DW_TAG_namelist:
1639 case DW_TAG_namelist_item:
1641 case DW_TAG_packed_type:
1643 case DW_TAG_subprogram:
1644 match_addr_range = true;
1646 case DW_TAG_template_type_parameter:
1648 case DW_TAG_template_value_parameter:
1650 case DW_TAG_GNU_template_parameter_pack:
1652 case DW_TAG_thrown_type:
1654 case DW_TAG_try_block:
1655 match_addr_range = true;
1657 case DW_TAG_variant_part:
1659 case DW_TAG_variable:
1661 case DW_TAG_volatile_type:
1663 case DW_TAG_dwarf_procedure:
1665 case DW_TAG_restrict_type:
1667 case DW_TAG_interface_type:
1669 case DW_TAG_namespace:
1670 check_children = true;
1672 case DW_TAG_imported_module:
1674 case DW_TAG_unspecified_type:
1676 case DW_TAG_partial_unit:
1678 case DW_TAG_imported_unit:
1680 case DW_TAG_shared_type:
1686 if (match_addr_range) {
1687 dw_addr_t lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc,
1688 LLDB_INVALID_ADDRESS);
1689 if (lo_pc != LLDB_INVALID_ADDRESS) {
1691 GetAttributeHighPC(dwarf2Data, cu, lo_pc, LLDB_INVALID_ADDRESS);
1692 if (hi_pc != LLDB_INVALID_ADDRESS) {
1693 // printf("\n0x%8.8x: %30s: address = 0x%8.8x [0x%8.8x - 0x%8.8x) ",
1694 // m_offset, DW_TAG_value_to_name(tag), address, lo_pc, hi_pc);
1695 if ((lo_pc <= address) && (address < hi_pc)) {
1696 found_address = true;
1697 // puts("***MATCH***");
1699 case DW_TAG_compile_unit: // File
1700 check_children = ((function_die != NULL) || (block_die != NULL));
1703 case DW_TAG_subprogram: // Function
1705 *function_die = this;
1706 check_children = (block_die != NULL);
1709 case DW_TAG_inlined_subroutine: // Inlined Function
1710 case DW_TAG_lexical_block: // Block { } in code
1713 check_children = true;
1718 check_children = true;
1722 } else { // compile units may not have a valid high/low pc when there
1723 // are address gaps in subroutines so we must always search
1724 // if there is no valid high and low PC
1725 check_children = (m_tag == DW_TAG_compile_unit) &&
1726 ((function_die != NULL) || (block_die != NULL));
1729 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(
1730 dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET);
1731 if (debug_ranges_offset != DW_INVALID_OFFSET) {
1732 DWARFRangeList ranges;
1733 DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges();
1734 debug_ranges->FindRanges(cu->GetRangesBase(), debug_ranges_offset, ranges);
1735 // All DW_AT_ranges are relative to the base address of the
1736 // compile unit. We add the compile unit base address to make
1737 // sure all the addresses are properly fixed up.
1738 ranges.Slide(cu->GetBaseAddress());
1739 if (ranges.FindEntryThatContains(address)) {
1740 found_address = true;
1741 // puts("***MATCH***");
1743 case DW_TAG_compile_unit: // File
1744 check_children = ((function_die != NULL) || (block_die != NULL));
1747 case DW_TAG_subprogram: // Function
1749 *function_die = this;
1750 check_children = (block_die != NULL);
1753 case DW_TAG_inlined_subroutine: // Inlined Function
1754 case DW_TAG_lexical_block: // Block { } in code
1757 check_children = true;
1762 check_children = true;
1766 check_children = false;
1772 if (check_children) {
1773 // printf("checking children\n");
1774 DWARFDebugInfoEntry *child = GetFirstChild();
1776 if (child->LookupAddress(address, dwarf2Data, cu, function_die,
1779 child = child->GetSibling();
1783 return found_address;
1786 const DWARFAbbreviationDeclaration *
1787 DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr(
1788 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
1789 lldb::offset_t &offset) const {
1791 offset = GetOffset();
1793 const DWARFAbbreviationDeclarationSet *abbrev_set = cu->GetAbbreviations();
1795 const DWARFAbbreviationDeclaration *abbrev_decl =
1796 abbrev_set->GetAbbreviationDeclaration(m_abbr_idx);
1798 // Make sure the abbreviation code still matches. If it doesn't and
1799 // the DWARF data was mmap'ed, the backing file might have been modified
1800 // which is bad news.
1801 const uint64_t abbrev_code =
1802 dwarf2Data->get_debug_info_data().GetULEB128(&offset);
1804 if (abbrev_decl->Code() == abbrev_code)
1807 dwarf2Data->GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
1808 "0x%8.8x: the DWARF debug information has been modified (abbrev "
1809 "code was %u, and is now %u)",
1810 GetOffset(), (uint32_t)abbrev_decl->Code(), (uint32_t)abbrev_code);
1814 offset = DW_INVALID_OFFSET;
1818 bool DWARFDebugInfoEntry::OffsetLessThan(const DWARFDebugInfoEntry &a,
1819 const DWARFDebugInfoEntry &b) {
1820 return a.GetOffset() < b.GetOffset();
1823 void DWARFDebugInfoEntry::DumpDIECollection(
1824 Stream &strm, DWARFDebugInfoEntry::collection &die_collection) {
1825 DWARFDebugInfoEntry::const_iterator pos;
1826 DWARFDebugInfoEntry::const_iterator end = die_collection.end();
1827 strm.PutCString("\noffset parent sibling child\n");
1828 strm.PutCString("-------- -------- -------- --------\n");
1829 for (pos = die_collection.begin(); pos != end; ++pos) {
1830 const DWARFDebugInfoEntry &die_ref = *pos;
1831 const DWARFDebugInfoEntry *p = die_ref.GetParent();
1832 const DWARFDebugInfoEntry *s = die_ref.GetSibling();
1833 const DWARFDebugInfoEntry *c = die_ref.GetFirstChild();
1834 strm.Printf("%.8x: %.8x %.8x %.8x 0x%4.4x %s%s\n", die_ref.GetOffset(),
1835 p ? p->GetOffset() : 0, s ? s->GetOffset() : 0,
1836 c ? c->GetOffset() : 0, die_ref.Tag(),
1837 DW_TAG_value_to_name(die_ref.Tag()),
1838 die_ref.HasChildren() ? " *" : "");