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 const uint64_t abbr_idx = debug_info_data.GetULEB128(offset_ptr);
44 lldbassert(abbr_idx <= UINT16_MAX);
45 m_abbr_idx = abbr_idx;
47 // assert (fixed_form_sizes); // For best performance this should be
51 lldb::offset_t offset = *offset_ptr;
53 const DWARFAbbreviationDeclaration *abbrevDecl =
54 cu->GetAbbreviations()->GetAbbreviationDeclaration(m_abbr_idx);
56 if (abbrevDecl == NULL) {
57 cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError(
58 "{0x%8.8x}: invalid abbreviation code %u, please file a bug and "
59 "attach the file at the start of this error message",
60 m_offset, (unsigned)abbr_idx);
61 // WE can't parse anymore if the DWARF is borked...
62 *offset_ptr = UINT32_MAX;
65 m_tag = abbrevDecl->Tag();
66 m_has_children = abbrevDecl->HasChildren();
67 // Skip all data in the .debug_info for the attributes
68 const uint32_t numAttributes = abbrevDecl->NumAttributes();
71 for (i = 0; i < numAttributes; ++i) {
72 form = abbrevDecl->GetFormByIndexUnchecked(i);
74 const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
76 offset += fixed_skip_size;
78 bool form_is_indirect = false;
80 form_is_indirect = false;
81 uint32_t form_size = 0;
83 // Blocks if inlined data that have a length field and the data bytes
84 // inlined in the .debug_info
87 form_size = debug_info_data.GetULEB128(&offset);
90 form_size = debug_info_data.GetU8_unchecked(&offset);
93 form_size = debug_info_data.GetU16_unchecked(&offset);
96 form_size = debug_info_data.GetU32_unchecked(&offset);
99 // Inlined NULL terminated C-strings
101 debug_info_data.GetCStr(&offset);
104 // Compile unit address sized values
106 form_size = cu->GetAddressByteSize();
108 case DW_FORM_ref_addr:
109 if (cu->GetVersion() <= 2)
110 form_size = cu->GetAddressByteSize();
112 form_size = cu->IsDWARF64() ? 8 : 4;
116 case DW_FORM_flag_present:
154 case DW_FORM_ref_sig8:
158 // signed or unsigned LEB 128 values
160 case DW_FORM_rnglistx:
163 case DW_FORM_ref_udata:
164 case DW_FORM_GNU_addr_index:
165 case DW_FORM_GNU_str_index:
167 debug_info_data.Skip_LEB128(&offset);
170 case DW_FORM_indirect:
171 form_is_indirect = true;
172 form = debug_info_data.GetULEB128(&offset);
176 case DW_FORM_sec_offset:
178 debug_info_data.GetU64(&offset);
180 debug_info_data.GetU32(&offset);
183 case DW_FORM_implicit_const:
188 *offset_ptr = m_offset;
193 } while (form_is_indirect);
196 *offset_ptr = offset;
200 m_has_children = false;
201 return true; // NULL debug tag entry
207 //----------------------------------------------------------------------
210 // Extract a debug info entry for a given compile unit from the .debug_info and
211 // .debug_abbrev data within the SymbolFileDWARF class starting at the given
213 //----------------------------------------------------------------------
214 bool DWARFDebugInfoEntry::Extract(SymbolFileDWARF *dwarf2Data,
216 lldb::offset_t *offset_ptr) {
217 const DWARFDataExtractor &debug_info_data = cu->GetData();
218 // const DWARFDataExtractor& debug_str_data =
219 // dwarf2Data->get_debug_str_data();
220 const uint32_t cu_end_offset = cu->GetNextCompileUnitOffset();
221 lldb::offset_t offset = *offset_ptr;
222 // if (offset >= cu_end_offset)
223 // Log::Status("DIE at offset 0x%8.8x is beyond the end of the current
224 // compile unit (0x%8.8x)", m_offset, cu_end_offset);
225 if ((offset < cu_end_offset) && debug_info_data.ValidOffset(offset)) {
228 const uint64_t abbr_idx = debug_info_data.GetULEB128(&offset);
229 lldbassert(abbr_idx <= UINT16_MAX);
230 m_abbr_idx = abbr_idx;
232 const DWARFAbbreviationDeclaration *abbrevDecl =
233 cu->GetAbbreviations()->GetAbbreviationDeclaration(abbr_idx);
236 m_tag = abbrevDecl->Tag();
237 m_has_children = abbrevDecl->HasChildren();
239 bool isCompileUnitTag = (m_tag == DW_TAG_compile_unit ||
240 m_tag == DW_TAG_partial_unit);
241 if (cu && isCompileUnitTag)
242 const_cast<DWARFUnit *>(cu)->SetBaseAddress(0);
244 // Skip all data in the .debug_info for the attributes
245 const uint32_t numAttributes = abbrevDecl->NumAttributes();
246 for (uint32_t i = 0; i < numAttributes; ++i) {
247 DWARFFormValue form_value(cu);
249 abbrevDecl->GetAttrAndFormValueByIndex(i, attr, form_value);
250 dw_form_t form = form_value.Form();
252 if (isCompileUnitTag &&
253 ((attr == DW_AT_entry_pc) || (attr == DW_AT_low_pc))) {
254 if (form_value.ExtractValue(debug_info_data, &offset)) {
255 if (attr == DW_AT_low_pc || attr == DW_AT_entry_pc)
256 const_cast<DWARFUnit *>(cu)->SetBaseAddress(
257 form_value.Address());
260 bool form_is_indirect = false;
262 form_is_indirect = false;
263 uint32_t form_size = 0;
265 // Blocks if inlined data that have a length field and the data
266 // bytes inlined in the .debug_info
267 case DW_FORM_exprloc:
269 form_size = debug_info_data.GetULEB128(&offset);
272 form_size = debug_info_data.GetU8(&offset);
275 form_size = debug_info_data.GetU16(&offset);
278 form_size = debug_info_data.GetU32(&offset);
281 // Inlined NULL terminated C-strings
283 debug_info_data.GetCStr(&offset);
286 // Compile unit address sized values
288 form_size = cu->GetAddressByteSize();
290 case DW_FORM_ref_addr:
291 if (cu->GetVersion() <= 2)
292 form_size = cu->GetAddressByteSize();
294 form_size = cu->IsDWARF64() ? 8 : 4;
298 case DW_FORM_flag_present:
299 case DW_FORM_implicit_const:
325 case DW_FORM_ref_sig8:
329 // signed or unsigned LEB 128 values
332 case DW_FORM_ref_udata:
333 case DW_FORM_GNU_addr_index:
334 case DW_FORM_GNU_str_index:
335 debug_info_data.Skip_LEB128(&offset);
338 case DW_FORM_indirect:
339 form = debug_info_data.GetULEB128(&offset);
340 form_is_indirect = true;
344 case DW_FORM_sec_offset:
346 debug_info_data.GetU64(&offset);
348 debug_info_data.GetU32(&offset);
352 *offset_ptr = offset;
357 } while (form_is_indirect);
360 *offset_ptr = offset;
365 m_has_children = false;
366 *offset_ptr = offset;
367 return true; // NULL debug tag entry
374 //----------------------------------------------------------------------
377 // Dumps all of a debug information entries parents up until oldest and all of
378 // it's attributes to the specified stream.
379 //----------------------------------------------------------------------
380 void DWARFDebugInfoEntry::DumpAncestry(SymbolFileDWARF *dwarf2Data,
382 const DWARFDebugInfoEntry *oldest,
384 uint32_t recurse_depth) const {
385 const DWARFDebugInfoEntry *parent = GetParent();
386 if (parent && parent != oldest)
387 parent->DumpAncestry(dwarf2Data, cu, oldest, s, 0);
388 Dump(dwarf2Data, cu, s, recurse_depth);
391 static dw_offset_t GetRangesOffset(const DWARFDebugRangesBase *debug_ranges,
392 DWARFFormValue &form_value) {
393 if (form_value.Form() == DW_FORM_rnglistx)
394 return debug_ranges->GetOffset(form_value.Unsigned());
395 return form_value.Unsigned();
398 //----------------------------------------------------------------------
399 // GetDIENamesAndRanges
401 // Gets the valid address ranges for a given DIE by looking for a
402 // DW_AT_low_pc/DW_AT_high_pc pair, DW_AT_entry_pc, or DW_AT_ranges attributes.
403 //----------------------------------------------------------------------
404 bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
405 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, const char *&name,
406 const char *&mangled, DWARFRangeList &ranges, int &decl_file,
407 int &decl_line, int &decl_column, int &call_file, int &call_line,
408 int &call_column, DWARFExpression *frame_base) const {
409 if (dwarf2Data == nullptr)
412 SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
414 return GetDIENamesAndRanges(
415 dwo_symbol_file, dwo_symbol_file->GetCompileUnit(), name, mangled,
416 ranges, decl_file, decl_line, decl_column, call_file, call_line,
417 call_column, frame_base);
419 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
420 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
421 std::vector<DIERef> die_refs;
422 bool set_frame_base_loclist_addr = false;
424 lldb::offset_t offset;
425 const DWARFAbbreviationDeclaration *abbrevDecl =
426 GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
428 lldb::ModuleSP module = dwarf2Data->GetObjectFile()->GetModule();
431 const DWARFDataExtractor &debug_info_data = cu->GetData();
433 if (!debug_info_data.ValidOffset(offset))
436 const uint32_t numAttributes = abbrevDecl->NumAttributes();
437 bool do_offset = false;
439 for (uint32_t i = 0; i < numAttributes; ++i) {
440 DWARFFormValue form_value(cu);
442 abbrevDecl->GetAttrAndFormValueByIndex(i, attr, form_value);
444 if (form_value.ExtractValue(debug_info_data, &offset)) {
447 lo_pc = form_value.Address();
455 lo_pc = form_value.Address();
459 if (form_value.Form() == DW_FORM_addr ||
460 form_value.Form() == DW_FORM_GNU_addr_index) {
461 hi_pc = form_value.Address();
463 hi_pc = form_value.Unsigned();
464 if (lo_pc == LLDB_INVALID_ADDRESS)
465 do_offset = hi_pc != LLDB_INVALID_ADDRESS;
467 hi_pc += lo_pc; // DWARF 4 introduces <offset-from-lo-pc> to save
473 const DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges();
475 debug_ranges->FindRanges(cu, GetRangesOffset(debug_ranges, form_value), ranges);
477 cu->GetSymbolFileDWARF()->GetObjectFile()->GetModule()->ReportError(
478 "{0x%8.8x}: DIE has DW_AT_ranges(0x%" PRIx64
479 ") attribute yet DWARF has no .debug_ranges, please file a bug "
480 "and attach the file at the start of this error message",
481 m_offset, form_value.Unsigned());
486 name = form_value.AsCString();
489 case DW_AT_MIPS_linkage_name:
490 case DW_AT_linkage_name:
492 mangled = form_value.AsCString();
495 case DW_AT_abstract_origin:
496 die_refs.emplace_back(form_value);
499 case DW_AT_specification:
500 die_refs.emplace_back(form_value);
503 case DW_AT_decl_file:
505 decl_file = form_value.Unsigned();
508 case DW_AT_decl_line:
510 decl_line = form_value.Unsigned();
513 case DW_AT_decl_column:
514 if (decl_column == 0)
515 decl_column = form_value.Unsigned();
518 case DW_AT_call_file:
520 call_file = form_value.Unsigned();
523 case DW_AT_call_line:
525 call_line = form_value.Unsigned();
528 case DW_AT_call_column:
529 if (call_column == 0)
530 call_column = form_value.Unsigned();
533 case DW_AT_frame_base:
535 if (form_value.BlockData()) {
536 uint32_t block_offset =
537 form_value.BlockData() - debug_info_data.GetDataStart();
538 uint32_t block_length = form_value.Unsigned();
539 frame_base->SetOpcodeData(module, debug_info_data, block_offset,
542 const DWARFDataExtractor &debug_loc_data =
543 dwarf2Data->DebugLocData();
544 const dw_offset_t debug_loc_offset = form_value.Unsigned();
546 size_t loc_list_length = DWARFExpression::LocationListSize(
547 cu, debug_loc_data, debug_loc_offset);
548 if (loc_list_length > 0) {
549 frame_base->SetOpcodeData(module, debug_loc_data,
550 debug_loc_offset, loc_list_length);
551 if (lo_pc != LLDB_INVALID_ADDRESS) {
552 assert(lo_pc >= cu->GetBaseAddress());
553 frame_base->SetLocationListSlide(lo_pc -
554 cu->GetBaseAddress());
556 set_frame_base_loclist_addr = true;
570 if (ranges.IsEmpty()) {
571 if (lo_pc != LLDB_INVALID_ADDRESS) {
572 if (hi_pc != LLDB_INVALID_ADDRESS && hi_pc > lo_pc)
573 ranges.Append(DWARFRangeList::Entry(lo_pc, hi_pc - lo_pc));
575 ranges.Append(DWARFRangeList::Entry(lo_pc, 0));
579 if (set_frame_base_loclist_addr) {
580 dw_addr_t lowest_range_pc = ranges.GetMinRangeBase(0);
581 assert(lowest_range_pc >= cu->GetBaseAddress());
582 frame_base->SetLocationListSlide(lowest_range_pc - cu->GetBaseAddress());
585 if (ranges.IsEmpty() || name == NULL || mangled == NULL) {
586 for (const DIERef &die_ref : die_refs) {
587 if (die_ref.die_offset != DW_INVALID_OFFSET) {
588 DWARFDIE die = dwarf2Data->GetDIE(die_ref);
590 die.GetDIE()->GetDIENamesAndRanges(
591 die.GetDWARF(), die.GetCU(), name, mangled, ranges, decl_file,
592 decl_line, decl_column, call_file, call_line, call_column);
596 return !ranges.IsEmpty();
599 //----------------------------------------------------------------------
602 // Dumps a debug information entry and all of it's attributes to the specified
604 //----------------------------------------------------------------------
605 void DWARFDebugInfoEntry::Dump(SymbolFileDWARF *dwarf2Data,
606 const DWARFUnit *cu, Stream &s,
607 uint32_t recurse_depth) const {
608 const DWARFDataExtractor &debug_info_data = cu->GetData();
609 lldb::offset_t offset = m_offset;
611 if (debug_info_data.ValidOffset(offset)) {
612 dw_uleb128_t abbrCode = debug_info_data.GetULEB128(&offset);
614 s.Printf("\n0x%8.8x: ", m_offset);
616 if (abbrCode != m_abbr_idx) {
617 s.Printf("error: DWARF has been modified\n");
618 } else if (abbrCode) {
619 const DWARFAbbreviationDeclaration *abbrevDecl =
620 cu->GetAbbreviations()->GetAbbreviationDeclaration(abbrCode);
623 s.PutCString(DW_TAG_value_to_name(abbrevDecl->Tag()));
624 s.Printf(" [%u] %c\n", abbrCode, abbrevDecl->HasChildren() ? '*' : ' ');
626 // Dump all data in the .debug_info for the attributes
627 const uint32_t numAttributes = abbrevDecl->NumAttributes();
628 for (uint32_t i = 0; i < numAttributes; ++i) {
629 DWARFFormValue form_value(cu);
631 abbrevDecl->GetAttrAndFormValueByIndex(i, attr, form_value);
633 DumpAttribute(dwarf2Data, cu, debug_info_data, &offset, s, attr,
637 const DWARFDebugInfoEntry *child = GetFirstChild();
638 if (recurse_depth > 0 && child) {
642 child->Dump(dwarf2Data, cu, s, recurse_depth - 1);
643 child = child->GetSibling();
648 s.Printf("Abbreviation code note found in 'debug_abbrev' class for "
657 void DWARFDebugInfoEntry::DumpLocation(SymbolFileDWARF *dwarf2Data,
658 DWARFUnit *cu, Stream &s) const {
659 const DWARFBaseDIE cu_die = cu->GetUnitDIEOnly();
660 const char *cu_name = NULL;
662 cu_name = cu_die.GetName();
663 const char *obj_file_name = NULL;
664 ObjectFile *obj_file = dwarf2Data->GetObjectFile();
667 obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>");
668 const char *die_name = GetName(dwarf2Data, cu);
669 s.Printf("0x%8.8x/0x%8.8x: %-30s (from %s in %s)", cu->GetOffset(),
670 GetOffset(), die_name ? die_name : "", cu_name ? cu_name : "<NULL>",
671 obj_file_name ? obj_file_name : "<NULL>");
674 //----------------------------------------------------------------------
677 // Dumps a debug information entry attribute along with it's form. Any special
678 // display of attributes is done (disassemble location lists, show enumeration
679 // values for attributes, etc).
680 //----------------------------------------------------------------------
681 void DWARFDebugInfoEntry::DumpAttribute(
682 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
683 const DWARFDataExtractor &debug_info_data, lldb::offset_t *offset_ptr,
684 Stream &s, dw_attr_t attr, DWARFFormValue &form_value) {
685 bool show_form = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm);
688 s.Indent(DW_AT_value_to_name(attr));
691 s.Printf("[%s", DW_FORM_value_to_name(form_value.Form()));
694 if (!form_value.ExtractValue(debug_info_data, offset_ptr))
698 if (form_value.Form() == DW_FORM_indirect) {
699 s.Printf(" [%s]", DW_FORM_value_to_name(form_value.Form()));
707 // Check to see if we have any special attribute formatters
709 case DW_AT_stmt_list:
710 s.Printf("0x%8.8" PRIx64, form_value.Unsigned());
714 s.PutCString(DW_LANG_value_to_name(form_value.Unsigned()));
718 s.PutCString(DW_ATE_value_to_name(form_value.Unsigned()));
721 case DW_AT_frame_base:
723 case DW_AT_data_member_location: {
724 const uint8_t *blockData = form_value.BlockData();
726 // Location description is inlined in data in the form value
727 DWARFDataExtractor locationData(debug_info_data,
728 (*offset_ptr) - form_value.Unsigned(),
729 form_value.Unsigned());
730 DWARFExpression::PrintDWARFExpression(
731 s, locationData, DWARFUnit::GetAddressByteSize(cu), 4, false);
733 // We have a location list offset as the value that is the offset into
734 // the .debug_loc section that describes the value over it's lifetime
735 uint64_t debug_loc_offset = form_value.Unsigned();
737 DWARFExpression::PrintDWARFLocationList(
738 s, cu, dwarf2Data->DebugLocData(), debug_loc_offset);
743 case DW_AT_abstract_origin:
744 case DW_AT_specification: {
745 uint64_t abstract_die_offset = form_value.Reference();
747 // *ostrm_ptr << HEX32 << abstract_die_offset << " ( ";
748 GetName(dwarf2Data, cu, abstract_die_offset, s);
752 uint64_t type_die_offset = form_value.Reference();
754 AppendTypeName(dwarf2Data, cu, type_die_offset, s);
761 lldb::offset_t ranges_offset =
762 GetRangesOffset(dwarf2Data->DebugRanges(), form_value);
763 dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0;
764 DWARFDebugRanges::Dump(s, dwarf2Data->get_debug_ranges_data(),
765 &ranges_offset, base_addr);
772 s.PutCString(" )\n");
775 //----------------------------------------------------------------------
776 // Get all attribute values for a given DIE, including following any
777 // specification or abstract origin attributes and including those in the
778 // results. Any duplicate attributes will have the first instance take
779 // precedence (this can happen for declaration attributes).
780 //----------------------------------------------------------------------
781 size_t DWARFDebugInfoEntry::GetAttributes(
782 const DWARFUnit *cu, DWARFFormValue::FixedFormSizes fixed_form_sizes,
783 DWARFAttributes &attributes, uint32_t curr_depth) const {
784 SymbolFileDWARF *dwarf2Data = nullptr;
785 const DWARFAbbreviationDeclaration *abbrevDecl = nullptr;
786 lldb::offset_t offset = 0;
788 if (m_tag != DW_TAG_compile_unit && m_tag != DW_TAG_partial_unit) {
789 SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
791 return GetAttributes(dwo_symbol_file->GetCompileUnit(),
792 fixed_form_sizes, attributes, curr_depth);
795 dwarf2Data = cu->GetSymbolFileDWARF();
796 abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
800 const DWARFDataExtractor &debug_info_data = cu->GetData();
802 if (fixed_form_sizes.Empty())
803 fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(
804 cu->GetAddressByteSize(), cu->IsDWARF64());
806 const uint32_t num_attributes = abbrevDecl->NumAttributes();
807 for (uint32_t i = 0; i < num_attributes; ++i) {
808 DWARFFormValue form_value(cu);
810 abbrevDecl->GetAttrAndFormValueByIndex(i, attr, form_value);
811 const dw_form_t form = form_value.Form();
813 // If we are tracking down DW_AT_specification or DW_AT_abstract_origin
814 // attributes, the depth will be non-zero. We need to omit certain
815 // attributes that don't make sense.
818 case DW_AT_declaration:
819 if (curr_depth > 0) {
820 // This attribute doesn't make sense when combined with the DIE that
821 // references this DIE. We know a DIE is referencing this DIE because
822 // curr_depth is not zero
827 attributes.Append(cu, offset, attr, form);
831 if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin)) {
832 if (form_value.ExtractValue(debug_info_data, &offset)) {
833 dw_offset_t die_offset = form_value.Reference();
835 const_cast<DWARFUnit *>(cu)->GetDIE(die_offset);
837 spec_die.GetAttributes(attributes, curr_depth + 1);
840 const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
842 offset += fixed_skip_size;
844 DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
850 return attributes.Size();
853 //----------------------------------------------------------------------
856 // Get the value of an attribute and return the .debug_info offset of the
857 // attribute if it was properly extracted into form_value, or zero if we fail
858 // since an offset of zero is invalid for an attribute (it would be a compile
860 //----------------------------------------------------------------------
861 dw_offset_t DWARFDebugInfoEntry::GetAttributeValue(
862 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
863 const dw_attr_t attr, DWARFFormValue &form_value,
864 dw_offset_t *end_attr_offset_ptr,
865 bool check_specification_or_abstract_origin) const {
866 SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
867 if (dwo_symbol_file && m_tag != DW_TAG_compile_unit &&
868 m_tag != DW_TAG_partial_unit)
869 return GetAttributeValue(dwo_symbol_file, dwo_symbol_file->GetCompileUnit(),
870 attr, form_value, end_attr_offset_ptr,
871 check_specification_or_abstract_origin);
873 lldb::offset_t offset;
874 const DWARFAbbreviationDeclaration *abbrevDecl =
875 GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
878 uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
880 if (attr_idx != DW_INVALID_INDEX) {
881 const DWARFDataExtractor &debug_info_data = cu->GetData();
884 while (idx < attr_idx)
885 DWARFFormValue::SkipValue(abbrevDecl->GetFormByIndex(idx++),
886 debug_info_data, &offset, cu);
888 const dw_offset_t attr_offset = offset;
889 form_value.SetCompileUnit(cu);
890 form_value.SetForm(abbrevDecl->GetFormByIndex(idx));
891 if (form_value.ExtractValue(debug_info_data, &offset)) {
892 if (end_attr_offset_ptr)
893 *end_attr_offset_ptr = offset;
899 if (check_specification_or_abstract_origin) {
900 if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value)) {
902 const_cast<DWARFUnit *>(cu)->GetDIE(form_value.Reference());
904 dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(
905 die.GetDWARF(), die.GetCU(), attr, form_value, end_attr_offset_ptr,
912 if (GetAttributeValue(dwarf2Data, cu, DW_AT_abstract_origin, form_value)) {
914 const_cast<DWARFUnit *>(cu)->GetDIE(form_value.Reference());
916 dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(
917 die.GetDWARF(), die.GetCU(), attr, form_value, end_attr_offset_ptr,
925 if (!dwo_symbol_file)
928 DWARFUnit *dwo_cu = dwo_symbol_file->GetCompileUnit();
932 DWARFBaseDIE dwo_cu_die = dwo_cu->GetUnitDIEOnly();
933 if (!dwo_cu_die.IsValid())
936 return dwo_cu_die.GetDIE()->GetAttributeValue(
937 dwo_symbol_file, dwo_cu, attr, form_value, end_attr_offset_ptr,
938 check_specification_or_abstract_origin);
941 //----------------------------------------------------------------------
942 // GetAttributeValueAsString
944 // Get the value of an attribute as a string return it. The resulting pointer
945 // to the string data exists within the supplied SymbolFileDWARF and will only
946 // be available as long as the SymbolFileDWARF is still around and it's content
948 //----------------------------------------------------------------------
949 const char *DWARFDebugInfoEntry::GetAttributeValueAsString(
950 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
951 const dw_attr_t attr, const char *fail_value,
952 bool check_specification_or_abstract_origin) const {
953 DWARFFormValue form_value;
954 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
955 check_specification_or_abstract_origin))
956 return form_value.AsCString();
960 //----------------------------------------------------------------------
961 // GetAttributeValueAsUnsigned
963 // Get the value of an attribute as unsigned and return it.
964 //----------------------------------------------------------------------
965 uint64_t DWARFDebugInfoEntry::GetAttributeValueAsUnsigned(
966 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
967 const dw_attr_t attr, uint64_t fail_value,
968 bool check_specification_or_abstract_origin) const {
969 DWARFFormValue form_value;
970 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
971 check_specification_or_abstract_origin))
972 return form_value.Unsigned();
976 //----------------------------------------------------------------------
977 // GetAttributeValueAsSigned
979 // Get the value of an attribute a signed value and return it.
980 //----------------------------------------------------------------------
981 int64_t DWARFDebugInfoEntry::GetAttributeValueAsSigned(
982 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
983 const dw_attr_t attr, int64_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.Signed();
992 //----------------------------------------------------------------------
993 // GetAttributeValueAsReference
995 // Get the value of an attribute as reference and fix up and compile unit
996 // relative offsets as needed.
997 //----------------------------------------------------------------------
998 uint64_t DWARFDebugInfoEntry::GetAttributeValueAsReference(
999 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
1000 const dw_attr_t attr, uint64_t fail_value,
1001 bool check_specification_or_abstract_origin) const {
1002 DWARFFormValue form_value;
1003 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
1004 check_specification_or_abstract_origin))
1005 return form_value.Reference();
1009 uint64_t DWARFDebugInfoEntry::GetAttributeValueAsAddress(
1010 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
1011 const dw_attr_t attr, uint64_t fail_value,
1012 bool check_specification_or_abstract_origin) const {
1013 DWARFFormValue form_value;
1014 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
1015 check_specification_or_abstract_origin))
1016 return form_value.Address();
1020 //----------------------------------------------------------------------
1021 // GetAttributeHighPC
1023 // Get the hi_pc, adding hi_pc to lo_pc when specified as an <offset-from-low-
1026 // Returns the hi_pc or fail_value.
1027 //----------------------------------------------------------------------
1028 dw_addr_t DWARFDebugInfoEntry::GetAttributeHighPC(
1029 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, dw_addr_t lo_pc,
1030 uint64_t fail_value, bool check_specification_or_abstract_origin) const {
1031 DWARFFormValue form_value;
1032 if (GetAttributeValue(dwarf2Data, cu, DW_AT_high_pc, form_value, nullptr,
1033 check_specification_or_abstract_origin)) {
1034 dw_form_t form = form_value.Form();
1035 if (form == DW_FORM_addr || form == DW_FORM_GNU_addr_index)
1036 return form_value.Address();
1038 // DWARF4 can specify the hi_pc as an <offset-from-lowpc>
1039 return lo_pc + form_value.Unsigned();
1044 //----------------------------------------------------------------------
1045 // GetAttributeAddressRange
1047 // Get the lo_pc and hi_pc, adding hi_pc to lo_pc when specified as an <offset-
1050 // Returns true or sets lo_pc and hi_pc to fail_value.
1051 //----------------------------------------------------------------------
1052 bool DWARFDebugInfoEntry::GetAttributeAddressRange(
1053 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, dw_addr_t &lo_pc,
1054 dw_addr_t &hi_pc, uint64_t fail_value,
1055 bool check_specification_or_abstract_origin) const {
1056 lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc, fail_value,
1057 check_specification_or_abstract_origin);
1058 if (lo_pc != fail_value) {
1059 hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, fail_value,
1060 check_specification_or_abstract_origin);
1061 if (hi_pc != fail_value)
1069 size_t DWARFDebugInfoEntry::GetAttributeAddressRanges(
1070 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
1071 DWARFRangeList &ranges, bool check_hi_lo_pc,
1072 bool check_specification_or_abstract_origin) const {
1075 DWARFFormValue form_value;
1076 if (GetAttributeValue(dwarf2Data, cu, DW_AT_ranges, form_value)) {
1077 if (DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges())
1078 debug_ranges->FindRanges(cu, GetRangesOffset(debug_ranges, form_value),
1080 } else if (check_hi_lo_pc) {
1081 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1082 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1083 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc,
1084 LLDB_INVALID_ADDRESS,
1085 check_specification_or_abstract_origin)) {
1087 ranges.Append(DWARFRangeList::Entry(lo_pc, hi_pc - lo_pc));
1090 return ranges.GetSize();
1093 //----------------------------------------------------------------------
1096 // Get value of the DW_AT_name attribute and return it if one exists, else
1098 //----------------------------------------------------------------------
1099 const char *DWARFDebugInfoEntry::GetName(SymbolFileDWARF *dwarf2Data,
1100 const DWARFUnit *cu) const {
1101 return GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1104 //----------------------------------------------------------------------
1107 // Get value of the DW_AT_MIPS_linkage_name attribute and return it if one
1108 // exists, else return the value of the DW_AT_name attribute
1109 //----------------------------------------------------------------------
1111 DWARFDebugInfoEntry::GetMangledName(SymbolFileDWARF *dwarf2Data,
1112 const DWARFUnit *cu,
1113 bool substitute_name_allowed) const {
1114 const char *name = nullptr;
1116 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name,
1121 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr,
1126 if (!substitute_name_allowed)
1129 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1133 //----------------------------------------------------------------------
1136 // Get value the name for a DIE as it should appear for a .debug_pubnames or
1137 // .debug_pubtypes section.
1138 //----------------------------------------------------------------------
1139 const char *DWARFDebugInfoEntry::GetPubname(SymbolFileDWARF *dwarf2Data,
1140 const DWARFUnit *cu) const {
1141 const char *name = nullptr;
1145 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name,
1150 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr,
1155 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1159 //----------------------------------------------------------------------
1162 // Get value of the DW_AT_name attribute for a debug information entry that
1163 // exists at offset "die_offset" and place that value into the supplied stream
1164 // object. If the DIE is a NULL object "NULL" is placed into the stream, and if
1165 // no DW_AT_name attribute exists for the DIE then nothing is printed.
1166 //----------------------------------------------------------------------
1167 bool DWARFDebugInfoEntry::GetName(SymbolFileDWARF *dwarf2Data,
1168 const DWARFUnit *cu,
1169 const dw_offset_t die_offset, Stream &s) {
1170 if (dwarf2Data == NULL) {
1171 s.PutCString("NULL");
1175 DWARFDebugInfoEntry die;
1176 lldb::offset_t offset = die_offset;
1177 if (die.Extract(dwarf2Data, cu, &offset)) {
1179 s.PutCString("NULL");
1182 const char *name = die.GetAttributeValueAsString(
1183 dwarf2Data, cu, DW_AT_name, nullptr, true);
1193 //----------------------------------------------------------------------
1196 // Follows the type name definition down through all needed tags to end up with
1197 // a fully qualified type name and dump the results to the supplied stream.
1198 // This is used to show the name of types given a type identifier.
1199 //----------------------------------------------------------------------
1200 bool DWARFDebugInfoEntry::AppendTypeName(SymbolFileDWARF *dwarf2Data,
1201 const DWARFUnit *cu,
1202 const dw_offset_t die_offset,
1204 if (dwarf2Data == NULL) {
1205 s.PutCString("NULL");
1209 DWARFDebugInfoEntry die;
1210 lldb::offset_t offset = die_offset;
1211 if (die.Extract(dwarf2Data, cu, &offset)) {
1213 s.PutCString("NULL");
1216 const char *name = die.GetPubname(dwarf2Data, cu);
1221 const DWARFAbbreviationDeclaration *abbrevDecl =
1222 die.GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1224 if (abbrevDecl == NULL)
1227 switch (abbrevDecl->Tag()) {
1228 case DW_TAG_array_type:
1229 break; // print out a "[]" after printing the full type of the element
1231 case DW_TAG_base_type:
1232 s.PutCString("base ");
1234 case DW_TAG_class_type:
1235 s.PutCString("class ");
1237 case DW_TAG_const_type:
1238 s.PutCString("const ");
1240 case DW_TAG_enumeration_type:
1241 s.PutCString("enum ");
1243 case DW_TAG_file_type:
1244 s.PutCString("file ");
1246 case DW_TAG_interface_type:
1247 s.PutCString("interface ");
1249 case DW_TAG_packed_type:
1250 s.PutCString("packed ");
1252 case DW_TAG_pointer_type:
1253 break; // print out a '*' after printing the full type below
1254 case DW_TAG_ptr_to_member_type:
1255 break; // print out a '*' after printing the full type below
1256 case DW_TAG_reference_type:
1257 break; // print out a '&' after printing the full type below
1258 case DW_TAG_restrict_type:
1259 s.PutCString("restrict ");
1261 case DW_TAG_set_type:
1262 s.PutCString("set ");
1264 case DW_TAG_shared_type:
1265 s.PutCString("shared ");
1267 case DW_TAG_string_type:
1268 s.PutCString("string ");
1270 case DW_TAG_structure_type:
1271 s.PutCString("struct ");
1273 case DW_TAG_subrange_type:
1274 s.PutCString("subrange ");
1276 case DW_TAG_subroutine_type:
1277 s.PutCString("function ");
1279 case DW_TAG_thrown_type:
1280 s.PutCString("thrown ");
1282 case DW_TAG_union_type:
1283 s.PutCString("union ");
1285 case DW_TAG_unspecified_type:
1286 s.PutCString("unspecified ");
1288 case DW_TAG_volatile_type:
1289 s.PutCString("volatile ");
1295 // Follow the DW_AT_type if possible
1296 DWARFFormValue form_value;
1297 if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_type, form_value)) {
1298 uint64_t next_die_offset = form_value.Reference();
1299 result = AppendTypeName(dwarf2Data, cu, next_die_offset, s);
1302 switch (abbrevDecl->Tag()) {
1303 case DW_TAG_array_type:
1306 case DW_TAG_pointer_type:
1309 case DW_TAG_ptr_to_member_type:
1312 case DW_TAG_reference_type:
1325 //----------------------------------------------------------------------
1326 // BuildAddressRangeTable
1327 //----------------------------------------------------------------------
1328 void DWARFDebugInfoEntry::BuildAddressRangeTable(
1329 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
1330 DWARFDebugAranges *debug_aranges) const {
1332 if (m_tag == DW_TAG_subprogram) {
1333 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1334 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1335 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc,
1336 LLDB_INVALID_ADDRESS)) {
1337 /// printf("BuildAddressRangeTable() 0x%8.8x: %30s: [0x%8.8x -
1338 /// 0x%8.8x)\n", m_offset, DW_TAG_value_to_name(tag), lo_pc, hi_pc);
1339 debug_aranges->AppendRange(cu->GetOffset(), lo_pc, hi_pc);
1343 const DWARFDebugInfoEntry *child = GetFirstChild();
1345 child->BuildAddressRangeTable(dwarf2Data, cu, debug_aranges);
1346 child = child->GetSibling();
1351 //----------------------------------------------------------------------
1352 // BuildFunctionAddressRangeTable
1354 // This function is very similar to the BuildAddressRangeTable function except
1355 // that the actual DIE offset for the function is placed in the table instead
1356 // of the compile unit offset (which is the way the standard .debug_aranges
1357 // section does it).
1358 //----------------------------------------------------------------------
1359 void DWARFDebugInfoEntry::BuildFunctionAddressRangeTable(
1360 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
1361 DWARFDebugAranges *debug_aranges) const {
1363 if (m_tag == DW_TAG_subprogram) {
1364 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1365 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1366 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc,
1367 LLDB_INVALID_ADDRESS)) {
1368 // printf("BuildAddressRangeTable() 0x%8.8x: [0x%16.16" PRIx64 " -
1369 // 0x%16.16" PRIx64 ")\n", m_offset, lo_pc, hi_pc); // DEBUG ONLY
1370 debug_aranges->AppendRange(GetOffset(), lo_pc, hi_pc);
1374 const DWARFDebugInfoEntry *child = GetFirstChild();
1376 child->BuildFunctionAddressRangeTable(dwarf2Data, cu, debug_aranges);
1377 child = child->GetSibling();
1382 void DWARFDebugInfoEntry::GetDeclContextDIEs(
1383 DWARFUnit *cu, DWARFDIECollection &decl_context_dies) const {
1385 DWARFDIE die(cu, const_cast<DWARFDebugInfoEntry *>(this));
1386 die.GetDeclContextDIEs(decl_context_dies);
1389 void DWARFDebugInfoEntry::GetDWARFDeclContext(
1390 SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
1391 DWARFDeclContext &dwarf_decl_ctx) const {
1392 const dw_tag_t tag = Tag();
1393 if (tag != DW_TAG_compile_unit && tag != DW_TAG_partial_unit) {
1394 dwarf_decl_ctx.AppendDeclContext(tag, GetName(dwarf2Data, cu));
1395 DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE(dwarf2Data, cu);
1396 if (parent_decl_ctx_die && parent_decl_ctx_die.GetDIE() != this) {
1397 if (parent_decl_ctx_die.Tag() != DW_TAG_compile_unit &&
1398 parent_decl_ctx_die.Tag() != DW_TAG_partial_unit)
1399 parent_decl_ctx_die.GetDIE()->GetDWARFDeclContext(
1400 parent_decl_ctx_die.GetDWARF(), parent_decl_ctx_die.GetCU(),
1406 bool DWARFDebugInfoEntry::MatchesDWARFDeclContext(
1407 SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
1408 const DWARFDeclContext &dwarf_decl_ctx) const {
1410 DWARFDeclContext this_dwarf_decl_ctx;
1411 GetDWARFDeclContext(dwarf2Data, cu, this_dwarf_decl_ctx);
1412 return this_dwarf_decl_ctx == dwarf_decl_ctx;
1416 DWARFDebugInfoEntry::GetParentDeclContextDIE(SymbolFileDWARF *dwarf2Data,
1417 DWARFUnit *cu) const {
1418 DWARFAttributes attributes;
1419 GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1420 return GetParentDeclContextDIE(dwarf2Data, cu, attributes);
1424 DWARFDebugInfoEntry::GetParentDeclContextDIE(
1425 SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
1426 const DWARFAttributes &attributes) const {
1427 DWARFDIE die(cu, const_cast<DWARFDebugInfoEntry *>(this));
1430 // If this is the original DIE that we are searching for a declaration for,
1431 // then don't look in the cache as we don't want our own decl context to be
1432 // our decl context...
1433 if (die.GetDIE() != this) {
1434 switch (die.Tag()) {
1435 case DW_TAG_compile_unit:
1436 case DW_TAG_partial_unit:
1437 case DW_TAG_namespace:
1438 case DW_TAG_structure_type:
1439 case DW_TAG_union_type:
1440 case DW_TAG_class_type:
1448 dw_offset_t die_offset;
1451 attributes.FormValueAsUnsigned(DW_AT_specification, DW_INVALID_OFFSET);
1452 if (die_offset != DW_INVALID_OFFSET) {
1453 DWARFDIE spec_die = cu->GetDIE(die_offset);
1455 DWARFDIE decl_ctx_die = spec_die.GetParentDeclContextDIE();
1457 return decl_ctx_die;
1461 die_offset = attributes.FormValueAsUnsigned(DW_AT_abstract_origin,
1463 if (die_offset != DW_INVALID_OFFSET) {
1464 DWARFDIE abs_die = cu->GetDIE(die_offset);
1466 DWARFDIE decl_ctx_die = abs_die.GetParentDeclContextDIE();
1468 return decl_ctx_die;
1472 die = die.GetParent();
1477 const char *DWARFDebugInfoEntry::GetQualifiedName(SymbolFileDWARF *dwarf2Data,
1479 std::string &storage) const {
1480 DWARFAttributes attributes;
1481 GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1482 return GetQualifiedName(dwarf2Data, cu, attributes, storage);
1485 const char *DWARFDebugInfoEntry::GetQualifiedName(
1486 SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
1487 const DWARFAttributes &attributes, std::string &storage) const {
1489 const char *name = GetName(dwarf2Data, cu);
1492 DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE(dwarf2Data, cu);
1494 // TODO: change this to get the correct decl context parent....
1495 while (parent_decl_ctx_die) {
1496 const dw_tag_t parent_tag = parent_decl_ctx_die.Tag();
1497 switch (parent_tag) {
1498 case DW_TAG_namespace: {
1499 const char *namespace_name = parent_decl_ctx_die.GetName();
1500 if (namespace_name) {
1501 storage.insert(0, "::");
1502 storage.insert(0, namespace_name);
1504 storage.insert(0, "(anonymous namespace)::");
1506 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1509 case DW_TAG_class_type:
1510 case DW_TAG_structure_type:
1511 case DW_TAG_union_type: {
1512 const char *class_union_struct_name = parent_decl_ctx_die.GetName();
1514 if (class_union_struct_name) {
1515 storage.insert(0, "::");
1516 storage.insert(0, class_union_struct_name);
1518 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1522 parent_decl_ctx_die.Clear();
1527 if (storage.empty())
1528 storage.append("::");
1530 storage.append(name);
1532 if (storage.empty())
1534 return storage.c_str();
1537 //----------------------------------------------------------------------
1539 //----------------------------------------------------------------------
1540 bool DWARFDebugInfoEntry::LookupAddress(const dw_addr_t address,
1541 SymbolFileDWARF *dwarf2Data,
1542 const DWARFUnit *cu,
1543 DWARFDebugInfoEntry **function_die,
1544 DWARFDebugInfoEntry **block_die) {
1545 bool found_address = false;
1547 bool check_children = false;
1548 bool match_addr_range = false;
1549 // printf("0x%8.8x: %30s: address = 0x%8.8x - ", m_offset,
1550 // DW_TAG_value_to_name(tag), address);
1552 case DW_TAG_array_type:
1554 case DW_TAG_class_type:
1555 check_children = true;
1557 case DW_TAG_entry_point:
1559 case DW_TAG_enumeration_type:
1561 case DW_TAG_formal_parameter:
1563 case DW_TAG_imported_declaration:
1567 case DW_TAG_lexical_block:
1568 check_children = true;
1569 match_addr_range = true;
1573 case DW_TAG_pointer_type:
1575 case DW_TAG_reference_type:
1577 case DW_TAG_compile_unit:
1578 match_addr_range = true;
1580 case DW_TAG_string_type:
1582 case DW_TAG_structure_type:
1583 check_children = true;
1585 case DW_TAG_subroutine_type:
1587 case DW_TAG_typedef:
1589 case DW_TAG_union_type:
1591 case DW_TAG_unspecified_parameters:
1593 case DW_TAG_variant:
1595 case DW_TAG_common_block:
1596 check_children = true;
1598 case DW_TAG_common_inclusion:
1600 case DW_TAG_inheritance:
1602 case DW_TAG_inlined_subroutine:
1603 check_children = true;
1604 match_addr_range = true;
1607 match_addr_range = true;
1609 case DW_TAG_ptr_to_member_type:
1611 case DW_TAG_set_type:
1613 case DW_TAG_subrange_type:
1615 case DW_TAG_with_stmt:
1617 case DW_TAG_access_declaration:
1619 case DW_TAG_base_type:
1621 case DW_TAG_catch_block:
1622 match_addr_range = true;
1624 case DW_TAG_const_type:
1626 case DW_TAG_constant:
1628 case DW_TAG_enumerator:
1630 case DW_TAG_file_type:
1634 case DW_TAG_namelist:
1636 case DW_TAG_namelist_item:
1638 case DW_TAG_packed_type:
1640 case DW_TAG_subprogram:
1641 match_addr_range = true;
1643 case DW_TAG_template_type_parameter:
1645 case DW_TAG_template_value_parameter:
1647 case DW_TAG_GNU_template_parameter_pack:
1649 case DW_TAG_thrown_type:
1651 case DW_TAG_try_block:
1652 match_addr_range = true;
1654 case DW_TAG_variant_part:
1656 case DW_TAG_variable:
1658 case DW_TAG_volatile_type:
1660 case DW_TAG_dwarf_procedure:
1662 case DW_TAG_restrict_type:
1664 case DW_TAG_interface_type:
1666 case DW_TAG_namespace:
1667 check_children = true;
1669 case DW_TAG_imported_module:
1671 case DW_TAG_unspecified_type:
1673 case DW_TAG_partial_unit:
1674 match_addr_range = true;
1676 case DW_TAG_imported_unit:
1678 case DW_TAG_shared_type:
1684 if (match_addr_range) {
1685 dw_addr_t lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc,
1686 LLDB_INVALID_ADDRESS);
1687 if (lo_pc != LLDB_INVALID_ADDRESS) {
1689 GetAttributeHighPC(dwarf2Data, cu, lo_pc, LLDB_INVALID_ADDRESS);
1690 if (hi_pc != LLDB_INVALID_ADDRESS) {
1691 // printf("\n0x%8.8x: %30s: address = 0x%8.8x [0x%8.8x - 0x%8.8x) ",
1692 // m_offset, DW_TAG_value_to_name(tag), address, lo_pc, hi_pc);
1693 if ((lo_pc <= address) && (address < hi_pc)) {
1694 found_address = true;
1695 // puts("***MATCH***");
1697 case DW_TAG_compile_unit: // File
1698 case DW_TAG_partial_unit: // File
1699 check_children = ((function_die != NULL) || (block_die != NULL));
1702 case DW_TAG_subprogram: // Function
1704 *function_die = this;
1705 check_children = (block_die != NULL);
1708 case DW_TAG_inlined_subroutine: // Inlined Function
1709 case DW_TAG_lexical_block: // Block { } in code
1712 check_children = true;
1717 check_children = true;
1722 // 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 m_tag == DW_TAG_partial_unit) &&
1727 ((function_die != NULL) || (block_die != NULL));
1730 DWARFFormValue form_value;
1731 if (GetAttributeValue(dwarf2Data, cu, DW_AT_ranges, form_value)) {
1732 DWARFRangeList ranges;
1733 DWARFDebugRangesBase *debug_ranges = dwarf2Data->DebugRanges();
1734 debug_ranges->FindRanges(
1735 cu, GetRangesOffset(debug_ranges, form_value), ranges);
1737 if (ranges.FindEntryThatContains(address)) {
1738 found_address = true;
1739 // puts("***MATCH***");
1741 case DW_TAG_compile_unit: // File
1742 case DW_TAG_partial_unit: // File
1743 check_children = ((function_die != NULL) || (block_die != NULL));
1746 case DW_TAG_subprogram: // Function
1748 *function_die = this;
1749 check_children = (block_die != NULL);
1752 case DW_TAG_inlined_subroutine: // Inlined Function
1753 case DW_TAG_lexical_block: // Block { } in code
1756 check_children = true;
1761 check_children = true;
1765 check_children = false;
1771 if (check_children) {
1772 // printf("checking children\n");
1773 DWARFDebugInfoEntry *child = GetFirstChild();
1775 if (child->LookupAddress(address, dwarf2Data, cu, function_die,
1778 child = child->GetSibling();
1782 return found_address;
1785 const DWARFAbbreviationDeclaration *
1786 DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr(
1787 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
1788 lldb::offset_t &offset) const {
1790 offset = GetOffset();
1792 const DWARFAbbreviationDeclarationSet *abbrev_set = cu->GetAbbreviations();
1794 const DWARFAbbreviationDeclaration *abbrev_decl =
1795 abbrev_set->GetAbbreviationDeclaration(m_abbr_idx);
1797 // Make sure the abbreviation code still matches. If it doesn't and the
1798 // DWARF data was mmap'ed, the backing file might have been modified
1799 // which is bad news.
1800 const uint64_t abbrev_code = cu->GetData().GetULEB128(&offset);
1802 if (abbrev_decl->Code() == abbrev_code)
1805 dwarf2Data->GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
1806 "0x%8.8x: the DWARF debug information has been modified (abbrev "
1807 "code was %u, and is now %u)",
1808 GetOffset(), (uint32_t)abbrev_decl->Code(), (uint32_t)abbrev_code);
1812 offset = DW_INVALID_OFFSET;
1816 bool DWARFDebugInfoEntry::OffsetLessThan(const DWARFDebugInfoEntry &a,
1817 const DWARFDebugInfoEntry &b) {
1818 return a.GetOffset() < b.GetOffset();
1821 void DWARFDebugInfoEntry::DumpDIECollection(
1822 Stream &strm, DWARFDebugInfoEntry::collection &die_collection) {
1823 DWARFDebugInfoEntry::const_iterator pos;
1824 DWARFDebugInfoEntry::const_iterator end = die_collection.end();
1825 strm.PutCString("\noffset parent sibling child\n");
1826 strm.PutCString("-------- -------- -------- --------\n");
1827 for (pos = die_collection.begin(); pos != end; ++pos) {
1828 const DWARFDebugInfoEntry &die_ref = *pos;
1829 const DWARFDebugInfoEntry *p = die_ref.GetParent();
1830 const DWARFDebugInfoEntry *s = die_ref.GetSibling();
1831 const DWARFDebugInfoEntry *c = die_ref.GetFirstChild();
1832 strm.Printf("%.8x: %.8x %.8x %.8x 0x%4.4x %s%s\n", die_ref.GetOffset(),
1833 p ? p->GetOffset() : 0, s ? s->GetOffset() : 0,
1834 c ? c->GetOffset() : 0, die_ref.Tag(),
1835 DW_TAG_value_to_name(die_ref.Tag()),
1836 die_ref.HasChildren() ? " *" : "");
1840 bool DWARFDebugInfoEntry::operator==(const DWARFDebugInfoEntry &rhs) const {
1841 return m_offset == rhs.m_offset && m_parent_idx == rhs.m_parent_idx &&
1842 m_sibling_idx == rhs.m_sibling_idx &&
1843 m_abbr_idx == rhs.m_abbr_idx && m_has_children == rhs.m_has_children &&
1847 bool DWARFDebugInfoEntry::operator!=(const DWARFDebugInfoEntry &rhs) const {
1848 return !(*this == rhs);