1 //===-- DWARFDebugInfoEntry.cpp ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "DWARFDebugInfoEntry.h"
16 #include "lldb/Core/Module.h"
17 #include "lldb/Core/Stream.h"
18 #include "lldb/Expression/DWARFExpression.h"
19 #include "lldb/Symbol/ObjectFile.h"
21 #include "DWARFCompileUnit.h"
22 #include "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::Error("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 verbose = s.GetVerbose();
670 bool show_form = s.GetFlags().Test(DWARFDebugInfo::eDumpFlag_ShowForm);
673 s.Offset(*offset_ptr);
676 s.Indent(DW_AT_value_to_name(attr));
679 s.Printf("[%s", DW_FORM_value_to_name(form));
682 DWARFFormValue form_value(cu, form);
684 if (!form_value.ExtractValue(debug_info_data, offset_ptr))
688 if (form == DW_FORM_indirect) {
689 s.Printf(" [%s]", DW_FORM_value_to_name(form_value.Form()));
697 // Always dump form value if verbose is enabled
702 // Check to see if we have any special attribute formatters
704 case DW_AT_stmt_list:
707 s.Printf("0x%8.8" PRIx64, form_value.Unsigned());
715 s.PutCString(DW_LANG_value_to_name(form_value.Unsigned()));
723 s.PutCString(DW_ATE_value_to_name(form_value.Unsigned()));
728 case DW_AT_frame_base:
730 case DW_AT_data_member_location: {
731 const uint8_t *blockData = form_value.BlockData();
736 // Location description is inlined in data in the form value
737 DWARFDataExtractor locationData(debug_info_data,
738 (*offset_ptr) - form_value.Unsigned(),
739 form_value.Unsigned());
742 DWARFExpression::PrintDWARFExpression(
743 s, locationData, DWARFCompileUnit::GetAddressByteSize(cu), 4, false);
747 // We have a location list offset as the value that is
748 // the offset into the .debug_loc section that describes
749 // the value over it's lifetime
750 uint64_t debug_loc_offset = form_value.Unsigned();
754 DWARFExpression::PrintDWARFLocationList(
755 s, cu, dwarf2Data->get_debug_loc_data(), debug_loc_offset);
763 case DW_AT_abstract_origin:
764 case DW_AT_specification: {
765 uint64_t abstract_die_offset = form_value.Reference();
767 // *ostrm_ptr << HEX32 << abstract_die_offset << " ( ";
770 GetName(dwarf2Data, cu, abstract_die_offset, s);
776 uint64_t type_die_offset = form_value.Reference();
780 AppendTypeName(dwarf2Data, cu, type_die_offset, s);
787 lldb::offset_t ranges_offset = form_value.Unsigned();
788 dw_addr_t base_addr = cu ? cu->GetBaseAddress() : 0;
790 DWARFDebugRanges::Dump(s, dwarf2Data->get_debug_ranges_data(),
791 &ranges_offset, base_addr);
800 s.PutCString(" )\n");
803 //----------------------------------------------------------------------
804 // Get all attribute values for a given DIE, including following any
805 // specification or abstract origin attributes and including those in
806 // the results. Any duplicate attributes will have the first instance
807 // take precedence (this can happen for declaration attributes).
808 //----------------------------------------------------------------------
809 size_t DWARFDebugInfoEntry::GetAttributes(
810 const DWARFCompileUnit *cu, DWARFFormValue::FixedFormSizes fixed_form_sizes,
811 DWARFAttributes &attributes, uint32_t curr_depth) const {
812 SymbolFileDWARF *dwarf2Data = nullptr;
813 const DWARFAbbreviationDeclaration *abbrevDecl = nullptr;
814 lldb::offset_t offset = 0;
816 if (m_tag != DW_TAG_compile_unit) {
817 SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
819 return GetAttributes(dwo_symbol_file->GetCompileUnit(),
820 fixed_form_sizes, attributes, curr_depth);
823 dwarf2Data = cu->GetSymbolFileDWARF();
824 abbrevDecl = GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
828 const DWARFDataExtractor &debug_info_data =
829 dwarf2Data->get_debug_info_data();
831 if (fixed_form_sizes.Empty())
832 fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(
833 cu->GetAddressByteSize(), cu->IsDWARF64());
835 const uint32_t num_attributes = abbrevDecl->NumAttributes();
839 for (i = 0; i < num_attributes; ++i) {
840 abbrevDecl->GetAttrAndFormByIndexUnchecked(i, attr, form);
842 // If we are tracking down DW_AT_specification or DW_AT_abstract_origin
843 // attributes, the depth will be non-zero. We need to omit certain
844 // attributes that don't make sense.
847 case DW_AT_declaration:
848 if (curr_depth > 0) {
849 // This attribute doesn't make sense when combined with
850 // the DIE that references this DIE. We know a DIE is
851 // referencing this DIE because curr_depth is not zero
856 attributes.Append(cu, offset, attr, form);
860 if ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin)) {
861 DWARFFormValue form_value(cu, form);
862 if (form_value.ExtractValue(debug_info_data, &offset)) {
863 dw_offset_t die_offset = form_value.Reference();
865 const_cast<DWARFCompileUnit *>(cu)->GetDIE(die_offset);
867 spec_die.GetAttributes(attributes, curr_depth + 1);
870 const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
872 offset += fixed_skip_size;
874 DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
880 return attributes.Size();
883 //----------------------------------------------------------------------
886 // Get the value of an attribute and return the .debug_info offset of the
887 // attribute if it was properly extracted into form_value, or zero
888 // if we fail since an offset of zero is invalid for an attribute (it
889 // would be a compile unit header).
890 //----------------------------------------------------------------------
891 dw_offset_t DWARFDebugInfoEntry::GetAttributeValue(
892 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
893 const dw_attr_t attr, DWARFFormValue &form_value,
894 dw_offset_t *end_attr_offset_ptr,
895 bool check_specification_or_abstract_origin) const {
896 SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
897 if (dwo_symbol_file && m_tag != DW_TAG_compile_unit)
898 return GetAttributeValue(dwo_symbol_file, dwo_symbol_file->GetCompileUnit(),
899 attr, form_value, end_attr_offset_ptr,
900 check_specification_or_abstract_origin);
902 lldb::offset_t offset;
903 const DWARFAbbreviationDeclaration *abbrevDecl =
904 GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
907 uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
909 if (attr_idx != DW_INVALID_INDEX) {
910 const DWARFDataExtractor &debug_info_data =
911 dwarf2Data->get_debug_info_data();
914 while (idx < attr_idx)
915 DWARFFormValue::SkipValue(abbrevDecl->GetFormByIndex(idx++),
916 debug_info_data, &offset, cu);
918 const dw_offset_t attr_offset = offset;
919 form_value.SetCompileUnit(cu);
920 form_value.SetForm(abbrevDecl->GetFormByIndex(idx));
921 if (form_value.ExtractValue(debug_info_data, &offset)) {
922 if (end_attr_offset_ptr)
923 *end_attr_offset_ptr = offset;
929 if (check_specification_or_abstract_origin) {
930 if (GetAttributeValue(dwarf2Data, cu, DW_AT_specification, form_value)) {
932 const_cast<DWARFCompileUnit *>(cu)->GetDIE(form_value.Reference());
934 dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(
935 die.GetDWARF(), die.GetCU(), attr, form_value, end_attr_offset_ptr,
942 if (GetAttributeValue(dwarf2Data, cu, DW_AT_abstract_origin, form_value)) {
944 const_cast<DWARFCompileUnit *>(cu)->GetDIE(form_value.Reference());
946 dw_offset_t die_offset = die.GetDIE()->GetAttributeValue(
947 die.GetDWARF(), die.GetCU(), attr, form_value, end_attr_offset_ptr,
955 if (!dwo_symbol_file)
958 DWARFCompileUnit *dwo_cu = dwo_symbol_file->GetCompileUnit();
962 DWARFDIE dwo_cu_die = dwo_cu->GetCompileUnitDIEOnly();
963 if (!dwo_cu_die.IsValid())
966 return dwo_cu_die.GetDIE()->GetAttributeValue(
967 dwo_symbol_file, dwo_cu, attr, form_value, end_attr_offset_ptr,
968 check_specification_or_abstract_origin);
971 //----------------------------------------------------------------------
972 // GetAttributeValueAsString
974 // Get the value of an attribute as a string return it. The resulting
975 // pointer to the string data exists within the supplied SymbolFileDWARF
976 // and will only be available as long as the SymbolFileDWARF is still around
977 // and it's content doesn't change.
978 //----------------------------------------------------------------------
979 const char *DWARFDebugInfoEntry::GetAttributeValueAsString(
980 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
981 const dw_attr_t attr, const char *fail_value,
982 bool check_specification_or_abstract_origin) const {
983 DWARFFormValue form_value;
984 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
985 check_specification_or_abstract_origin))
986 return form_value.AsCString();
990 //----------------------------------------------------------------------
991 // GetAttributeValueAsUnsigned
993 // Get the value of an attribute as unsigned and return it.
994 //----------------------------------------------------------------------
995 uint64_t DWARFDebugInfoEntry::GetAttributeValueAsUnsigned(
996 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
997 const dw_attr_t attr, uint64_t fail_value,
998 bool check_specification_or_abstract_origin) const {
999 DWARFFormValue form_value;
1000 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
1001 check_specification_or_abstract_origin))
1002 return form_value.Unsigned();
1006 //----------------------------------------------------------------------
1007 // GetAttributeValueAsSigned
1009 // Get the value of an attribute a signed value and return it.
1010 //----------------------------------------------------------------------
1011 int64_t DWARFDebugInfoEntry::GetAttributeValueAsSigned(
1012 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
1013 const dw_attr_t attr, int64_t fail_value,
1014 bool check_specification_or_abstract_origin) const {
1015 DWARFFormValue form_value;
1016 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
1017 check_specification_or_abstract_origin))
1018 return form_value.Signed();
1022 //----------------------------------------------------------------------
1023 // GetAttributeValueAsReference
1025 // Get the value of an attribute as reference and fix up and compile
1026 // unit relative offsets as needed.
1027 //----------------------------------------------------------------------
1028 uint64_t DWARFDebugInfoEntry::GetAttributeValueAsReference(
1029 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
1030 const dw_attr_t attr, uint64_t fail_value,
1031 bool check_specification_or_abstract_origin) const {
1032 DWARFFormValue form_value;
1033 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
1034 check_specification_or_abstract_origin))
1035 return form_value.Reference();
1039 uint64_t DWARFDebugInfoEntry::GetAttributeValueAsAddress(
1040 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
1041 const dw_attr_t attr, uint64_t fail_value,
1042 bool check_specification_or_abstract_origin) const {
1043 DWARFFormValue form_value;
1044 if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
1045 check_specification_or_abstract_origin))
1046 return form_value.Address();
1050 //----------------------------------------------------------------------
1051 // GetAttributeHighPC
1053 // Get the hi_pc, adding hi_pc to lo_pc when specified
1054 // as an <offset-from-low-pc>.
1056 // Returns the hi_pc or fail_value.
1057 //----------------------------------------------------------------------
1058 dw_addr_t DWARFDebugInfoEntry::GetAttributeHighPC(
1059 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu, dw_addr_t lo_pc,
1060 uint64_t fail_value, bool check_specification_or_abstract_origin) const {
1061 DWARFFormValue form_value;
1062 if (GetAttributeValue(dwarf2Data, cu, DW_AT_high_pc, form_value, nullptr,
1063 check_specification_or_abstract_origin)) {
1064 dw_form_t form = form_value.Form();
1065 if (form == DW_FORM_addr || form == DW_FORM_GNU_addr_index)
1066 return form_value.Address();
1068 // DWARF4 can specify the hi_pc as an <offset-from-lowpc>
1069 return lo_pc + form_value.Unsigned();
1074 //----------------------------------------------------------------------
1075 // GetAttributeAddressRange
1077 // Get the lo_pc and hi_pc, adding hi_pc to lo_pc when specified
1078 // as an <offset-from-low-pc>.
1080 // Returns true or sets lo_pc and hi_pc to fail_value.
1081 //----------------------------------------------------------------------
1082 bool DWARFDebugInfoEntry::GetAttributeAddressRange(
1083 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu, dw_addr_t &lo_pc,
1084 dw_addr_t &hi_pc, uint64_t fail_value,
1085 bool check_specification_or_abstract_origin) const {
1086 lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc, fail_value,
1087 check_specification_or_abstract_origin);
1088 if (lo_pc != fail_value) {
1089 hi_pc = GetAttributeHighPC(dwarf2Data, cu, lo_pc, fail_value,
1090 check_specification_or_abstract_origin);
1091 if (hi_pc != fail_value)
1099 size_t DWARFDebugInfoEntry::GetAttributeAddressRanges(
1100 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
1101 DWARFRangeList &ranges, bool check_hi_lo_pc,
1102 bool check_specification_or_abstract_origin) const {
1105 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(
1106 dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET,
1107 check_specification_or_abstract_origin);
1108 if (debug_ranges_offset != DW_INVALID_OFFSET) {
1109 DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges();
1111 debug_ranges->FindRanges(cu->GetRangesBase(), debug_ranges_offset, ranges);
1112 ranges.Slide(cu->GetBaseAddress());
1113 } else if (check_hi_lo_pc) {
1114 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1115 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1116 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc,
1117 LLDB_INVALID_ADDRESS,
1118 check_specification_or_abstract_origin)) {
1120 ranges.Append(DWARFRangeList::Entry(lo_pc, hi_pc - lo_pc));
1123 return ranges.GetSize();
1126 //----------------------------------------------------------------------
1129 // Get value of the DW_AT_name attribute and return it if one exists,
1130 // else return NULL.
1131 //----------------------------------------------------------------------
1132 const char *DWARFDebugInfoEntry::GetName(SymbolFileDWARF *dwarf2Data,
1133 const DWARFCompileUnit *cu) const {
1134 return GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1137 //----------------------------------------------------------------------
1140 // Get value of the DW_AT_MIPS_linkage_name attribute and return it if
1141 // one exists, else return the value of the DW_AT_name attribute
1142 //----------------------------------------------------------------------
1144 DWARFDebugInfoEntry::GetMangledName(SymbolFileDWARF *dwarf2Data,
1145 const DWARFCompileUnit *cu,
1146 bool substitute_name_allowed) const {
1147 const char *name = nullptr;
1149 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name,
1154 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr,
1159 if (!substitute_name_allowed)
1162 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1166 //----------------------------------------------------------------------
1169 // Get value the name for a DIE as it should appear for a
1170 // .debug_pubnames or .debug_pubtypes section.
1171 //----------------------------------------------------------------------
1172 const char *DWARFDebugInfoEntry::GetPubname(SymbolFileDWARF *dwarf2Data,
1173 const DWARFCompileUnit *cu) const {
1174 const char *name = nullptr;
1178 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_MIPS_linkage_name,
1183 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_linkage_name, nullptr,
1188 name = GetAttributeValueAsString(dwarf2Data, cu, DW_AT_name, nullptr, true);
1192 //----------------------------------------------------------------------
1195 // Get value of the DW_AT_name attribute for a debug information entry
1196 // that exists at offset "die_offset" and place that value into the
1197 // supplied stream object. If the DIE is a NULL object "NULL" is placed
1198 // into the stream, and if no DW_AT_name attribute exists for the DIE
1199 // then nothing is printed.
1200 //----------------------------------------------------------------------
1201 bool DWARFDebugInfoEntry::GetName(SymbolFileDWARF *dwarf2Data,
1202 const DWARFCompileUnit *cu,
1203 const dw_offset_t die_offset, Stream &s) {
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.GetAttributeValueAsString(
1217 dwarf2Data, cu, DW_AT_name, nullptr, true);
1227 //----------------------------------------------------------------------
1230 // Follows the type name definition down through all needed tags to
1231 // end up with a fully qualified type name and dump the results to
1232 // the supplied stream. This is used to show the name of types given
1233 // a type identifier.
1234 //----------------------------------------------------------------------
1235 bool DWARFDebugInfoEntry::AppendTypeName(SymbolFileDWARF *dwarf2Data,
1236 const DWARFCompileUnit *cu,
1237 const dw_offset_t die_offset,
1239 if (dwarf2Data == NULL) {
1240 s.PutCString("NULL");
1244 DWARFDebugInfoEntry die;
1245 lldb::offset_t offset = die_offset;
1246 if (die.Extract(dwarf2Data, cu, &offset)) {
1248 s.PutCString("NULL");
1251 const char *name = die.GetPubname(dwarf2Data, cu);
1256 const DWARFAbbreviationDeclaration *abbrevDecl =
1257 die.GetAbbreviationDeclarationPtr(dwarf2Data, cu, offset);
1259 if (abbrevDecl == NULL)
1262 switch (abbrevDecl->Tag()) {
1263 case DW_TAG_array_type:
1264 break; // print out a "[]" after printing the full type of the element
1266 case DW_TAG_base_type:
1267 s.PutCString("base ");
1269 case DW_TAG_class_type:
1270 s.PutCString("class ");
1272 case DW_TAG_const_type:
1273 s.PutCString("const ");
1275 case DW_TAG_enumeration_type:
1276 s.PutCString("enum ");
1278 case DW_TAG_file_type:
1279 s.PutCString("file ");
1281 case DW_TAG_interface_type:
1282 s.PutCString("interface ");
1284 case DW_TAG_packed_type:
1285 s.PutCString("packed ");
1287 case DW_TAG_pointer_type:
1288 break; // print out a '*' after printing the full type below
1289 case DW_TAG_ptr_to_member_type:
1290 break; // print out a '*' after printing the full type below
1291 case DW_TAG_reference_type:
1292 break; // print out a '&' after printing the full type below
1293 case DW_TAG_restrict_type:
1294 s.PutCString("restrict ");
1296 case DW_TAG_set_type:
1297 s.PutCString("set ");
1299 case DW_TAG_shared_type:
1300 s.PutCString("shared ");
1302 case DW_TAG_string_type:
1303 s.PutCString("string ");
1305 case DW_TAG_structure_type:
1306 s.PutCString("struct ");
1308 case DW_TAG_subrange_type:
1309 s.PutCString("subrange ");
1311 case DW_TAG_subroutine_type:
1312 s.PutCString("function ");
1314 case DW_TAG_thrown_type:
1315 s.PutCString("thrown ");
1317 case DW_TAG_union_type:
1318 s.PutCString("union ");
1320 case DW_TAG_unspecified_type:
1321 s.PutCString("unspecified ");
1323 case DW_TAG_volatile_type:
1324 s.PutCString("volatile ");
1330 // Follow the DW_AT_type if possible
1331 DWARFFormValue form_value;
1332 if (die.GetAttributeValue(dwarf2Data, cu, DW_AT_type, form_value)) {
1333 uint64_t next_die_offset = form_value.Reference();
1334 result = AppendTypeName(dwarf2Data, cu, next_die_offset, s);
1337 switch (abbrevDecl->Tag()) {
1338 case DW_TAG_array_type:
1341 case DW_TAG_pointer_type:
1344 case DW_TAG_ptr_to_member_type:
1347 case DW_TAG_reference_type:
1360 bool DWARFDebugInfoEntry::Contains(const DWARFDebugInfoEntry *die) const {
1362 const dw_offset_t die_offset = die->GetOffset();
1363 if (die_offset > GetOffset()) {
1364 const DWARFDebugInfoEntry *sibling = GetSibling();
1365 assert(sibling); // TODO: take this out
1367 return die_offset < sibling->GetOffset();
1373 //----------------------------------------------------------------------
1374 // BuildAddressRangeTable
1375 //----------------------------------------------------------------------
1376 void DWARFDebugInfoEntry::BuildAddressRangeTable(
1377 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
1378 DWARFDebugAranges *debug_aranges) const {
1380 if (m_tag == DW_TAG_subprogram) {
1381 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1382 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1383 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc,
1384 LLDB_INVALID_ADDRESS)) {
1385 /// printf("BuildAddressRangeTable() 0x%8.8x: %30s: [0x%8.8x -
1386 /// 0x%8.8x)\n", m_offset, DW_TAG_value_to_name(tag), lo_pc, hi_pc);
1387 debug_aranges->AppendRange(cu->GetOffset(), lo_pc, hi_pc);
1391 const DWARFDebugInfoEntry *child = GetFirstChild();
1393 child->BuildAddressRangeTable(dwarf2Data, cu, debug_aranges);
1394 child = child->GetSibling();
1399 //----------------------------------------------------------------------
1400 // BuildFunctionAddressRangeTable
1402 // This function is very similar to the BuildAddressRangeTable function
1403 // except that the actual DIE offset for the function is placed in the
1404 // table instead of the compile unit offset (which is the way the
1405 // standard .debug_aranges section does it).
1406 //----------------------------------------------------------------------
1407 void DWARFDebugInfoEntry::BuildFunctionAddressRangeTable(
1408 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
1409 DWARFDebugAranges *debug_aranges) const {
1411 if (m_tag == DW_TAG_subprogram) {
1412 dw_addr_t lo_pc = LLDB_INVALID_ADDRESS;
1413 dw_addr_t hi_pc = LLDB_INVALID_ADDRESS;
1414 if (GetAttributeAddressRange(dwarf2Data, cu, lo_pc, hi_pc,
1415 LLDB_INVALID_ADDRESS)) {
1416 // printf("BuildAddressRangeTable() 0x%8.8x: [0x%16.16" PRIx64 " -
1417 // 0x%16.16" PRIx64 ")\n", m_offset, lo_pc, hi_pc); // DEBUG ONLY
1418 debug_aranges->AppendRange(GetOffset(), lo_pc, hi_pc);
1422 const DWARFDebugInfoEntry *child = GetFirstChild();
1424 child->BuildFunctionAddressRangeTable(dwarf2Data, cu, debug_aranges);
1425 child = child->GetSibling();
1430 void DWARFDebugInfoEntry::GetDeclContextDIEs(
1431 DWARFCompileUnit *cu, DWARFDIECollection &decl_context_dies) const {
1433 DWARFDIE die(cu, const_cast<DWARFDebugInfoEntry *>(this));
1434 die.GetDeclContextDIEs(decl_context_dies);
1437 void DWARFDebugInfoEntry::GetDWARFDeclContext(
1438 SymbolFileDWARF *dwarf2Data, DWARFCompileUnit *cu,
1439 DWARFDeclContext &dwarf_decl_ctx) const {
1440 const dw_tag_t tag = Tag();
1441 if (tag != DW_TAG_compile_unit) {
1442 dwarf_decl_ctx.AppendDeclContext(tag, GetName(dwarf2Data, cu));
1443 DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE(dwarf2Data, cu);
1444 if (parent_decl_ctx_die && parent_decl_ctx_die.GetDIE() != this) {
1445 if (parent_decl_ctx_die.Tag() != DW_TAG_compile_unit)
1446 parent_decl_ctx_die.GetDIE()->GetDWARFDeclContext(
1447 parent_decl_ctx_die.GetDWARF(), parent_decl_ctx_die.GetCU(),
1453 bool DWARFDebugInfoEntry::MatchesDWARFDeclContext(
1454 SymbolFileDWARF *dwarf2Data, DWARFCompileUnit *cu,
1455 const DWARFDeclContext &dwarf_decl_ctx) const {
1457 DWARFDeclContext this_dwarf_decl_ctx;
1458 GetDWARFDeclContext(dwarf2Data, cu, this_dwarf_decl_ctx);
1459 return this_dwarf_decl_ctx == dwarf_decl_ctx;
1463 DWARFDebugInfoEntry::GetParentDeclContextDIE(SymbolFileDWARF *dwarf2Data,
1464 DWARFCompileUnit *cu) const {
1465 DWARFAttributes attributes;
1466 GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1467 return GetParentDeclContextDIE(dwarf2Data, cu, attributes);
1471 DWARFDebugInfoEntry::GetParentDeclContextDIE(
1472 SymbolFileDWARF *dwarf2Data, DWARFCompileUnit *cu,
1473 const DWARFAttributes &attributes) const {
1474 DWARFDIE die(cu, const_cast<DWARFDebugInfoEntry *>(this));
1477 // If this is the original DIE that we are searching for a declaration
1478 // for, then don't look in the cache as we don't want our own decl
1479 // context to be our decl context...
1480 if (die.GetDIE() != this) {
1481 switch (die.Tag()) {
1482 case DW_TAG_compile_unit:
1483 case DW_TAG_namespace:
1484 case DW_TAG_structure_type:
1485 case DW_TAG_union_type:
1486 case DW_TAG_class_type:
1494 dw_offset_t die_offset;
1497 attributes.FormValueAsUnsigned(DW_AT_specification, DW_INVALID_OFFSET);
1498 if (die_offset != DW_INVALID_OFFSET) {
1499 DWARFDIE spec_die = cu->GetDIE(die_offset);
1501 DWARFDIE decl_ctx_die = spec_die.GetParentDeclContextDIE();
1503 return decl_ctx_die;
1507 die_offset = attributes.FormValueAsUnsigned(DW_AT_abstract_origin,
1509 if (die_offset != DW_INVALID_OFFSET) {
1510 DWARFDIE abs_die = cu->GetDIE(die_offset);
1512 DWARFDIE decl_ctx_die = abs_die.GetParentDeclContextDIE();
1514 return decl_ctx_die;
1518 die = die.GetParent();
1523 const char *DWARFDebugInfoEntry::GetQualifiedName(SymbolFileDWARF *dwarf2Data,
1524 DWARFCompileUnit *cu,
1525 std::string &storage) const {
1526 DWARFAttributes attributes;
1527 GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1528 return GetQualifiedName(dwarf2Data, cu, attributes, storage);
1531 const char *DWARFDebugInfoEntry::GetQualifiedName(
1532 SymbolFileDWARF *dwarf2Data, DWARFCompileUnit *cu,
1533 const DWARFAttributes &attributes, std::string &storage) const {
1535 const char *name = GetName(dwarf2Data, cu);
1538 DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE(dwarf2Data, cu);
1540 // TODO: change this to get the correct decl context parent....
1541 while (parent_decl_ctx_die) {
1542 const dw_tag_t parent_tag = parent_decl_ctx_die.Tag();
1543 switch (parent_tag) {
1544 case DW_TAG_namespace: {
1545 const char *namespace_name = parent_decl_ctx_die.GetName();
1546 if (namespace_name) {
1547 storage.insert(0, "::");
1548 storage.insert(0, namespace_name);
1550 storage.insert(0, "(anonymous namespace)::");
1552 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1555 case DW_TAG_class_type:
1556 case DW_TAG_structure_type:
1557 case DW_TAG_union_type: {
1558 const char *class_union_struct_name = parent_decl_ctx_die.GetName();
1560 if (class_union_struct_name) {
1561 storage.insert(0, "::");
1562 storage.insert(0, class_union_struct_name);
1564 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1568 parent_decl_ctx_die.Clear();
1573 if (storage.empty())
1574 storage.append("::");
1576 storage.append(name);
1578 if (storage.empty())
1580 return storage.c_str();
1583 //----------------------------------------------------------------------
1585 //----------------------------------------------------------------------
1586 bool DWARFDebugInfoEntry::LookupAddress(const dw_addr_t address,
1587 SymbolFileDWARF *dwarf2Data,
1588 const DWARFCompileUnit *cu,
1589 DWARFDebugInfoEntry **function_die,
1590 DWARFDebugInfoEntry **block_die) {
1591 bool found_address = false;
1593 bool check_children = false;
1594 bool match_addr_range = false;
1595 // printf("0x%8.8x: %30s: address = 0x%8.8x - ", m_offset,
1596 // DW_TAG_value_to_name(tag), address);
1598 case DW_TAG_array_type:
1600 case DW_TAG_class_type:
1601 check_children = true;
1603 case DW_TAG_entry_point:
1605 case DW_TAG_enumeration_type:
1607 case DW_TAG_formal_parameter:
1609 case DW_TAG_imported_declaration:
1613 case DW_TAG_lexical_block:
1614 check_children = true;
1615 match_addr_range = true;
1619 case DW_TAG_pointer_type:
1621 case DW_TAG_reference_type:
1623 case DW_TAG_compile_unit:
1624 match_addr_range = true;
1626 case DW_TAG_string_type:
1628 case DW_TAG_structure_type:
1629 check_children = true;
1631 case DW_TAG_subroutine_type:
1633 case DW_TAG_typedef:
1635 case DW_TAG_union_type:
1637 case DW_TAG_unspecified_parameters:
1639 case DW_TAG_variant:
1641 case DW_TAG_common_block:
1642 check_children = true;
1644 case DW_TAG_common_inclusion:
1646 case DW_TAG_inheritance:
1648 case DW_TAG_inlined_subroutine:
1649 check_children = true;
1650 match_addr_range = true;
1653 match_addr_range = true;
1655 case DW_TAG_ptr_to_member_type:
1657 case DW_TAG_set_type:
1659 case DW_TAG_subrange_type:
1661 case DW_TAG_with_stmt:
1663 case DW_TAG_access_declaration:
1665 case DW_TAG_base_type:
1667 case DW_TAG_catch_block:
1668 match_addr_range = true;
1670 case DW_TAG_const_type:
1672 case DW_TAG_constant:
1674 case DW_TAG_enumerator:
1676 case DW_TAG_file_type:
1680 case DW_TAG_namelist:
1682 case DW_TAG_namelist_item:
1684 case DW_TAG_packed_type:
1686 case DW_TAG_subprogram:
1687 match_addr_range = true;
1689 case DW_TAG_template_type_parameter:
1691 case DW_TAG_template_value_parameter:
1693 case DW_TAG_thrown_type:
1695 case DW_TAG_try_block:
1696 match_addr_range = true;
1698 case DW_TAG_variant_part:
1700 case DW_TAG_variable:
1702 case DW_TAG_volatile_type:
1704 case DW_TAG_dwarf_procedure:
1706 case DW_TAG_restrict_type:
1708 case DW_TAG_interface_type:
1710 case DW_TAG_namespace:
1711 check_children = true;
1713 case DW_TAG_imported_module:
1715 case DW_TAG_unspecified_type:
1717 case DW_TAG_partial_unit:
1719 case DW_TAG_imported_unit:
1721 case DW_TAG_shared_type:
1727 if (match_addr_range) {
1728 dw_addr_t lo_pc = GetAttributeValueAsAddress(dwarf2Data, cu, DW_AT_low_pc,
1729 LLDB_INVALID_ADDRESS);
1730 if (lo_pc != LLDB_INVALID_ADDRESS) {
1732 GetAttributeHighPC(dwarf2Data, cu, lo_pc, LLDB_INVALID_ADDRESS);
1733 if (hi_pc != LLDB_INVALID_ADDRESS) {
1734 // printf("\n0x%8.8x: %30s: address = 0x%8.8x [0x%8.8x - 0x%8.8x) ",
1735 // m_offset, DW_TAG_value_to_name(tag), address, lo_pc, hi_pc);
1736 if ((lo_pc <= address) && (address < hi_pc)) {
1737 found_address = true;
1738 // puts("***MATCH***");
1740 case DW_TAG_compile_unit: // File
1741 check_children = ((function_die != NULL) || (block_die != NULL));
1744 case DW_TAG_subprogram: // Function
1746 *function_die = this;
1747 check_children = (block_die != NULL);
1750 case DW_TAG_inlined_subroutine: // Inlined Function
1751 case DW_TAG_lexical_block: // Block { } in code
1754 check_children = true;
1759 check_children = true;
1763 } else { // compile units may not have a valid high/low pc when there
1764 // are address gaps in subroutines so we must always search
1765 // if there is no valid high and low PC
1766 check_children = (m_tag == DW_TAG_compile_unit) &&
1767 ((function_die != NULL) || (block_die != NULL));
1770 dw_offset_t debug_ranges_offset = GetAttributeValueAsUnsigned(
1771 dwarf2Data, cu, DW_AT_ranges, DW_INVALID_OFFSET);
1772 if (debug_ranges_offset != DW_INVALID_OFFSET) {
1773 DWARFRangeList ranges;
1774 DWARFDebugRanges *debug_ranges = dwarf2Data->DebugRanges();
1775 debug_ranges->FindRanges(cu->GetRangesBase(), debug_ranges_offset, ranges);
1776 // All DW_AT_ranges are relative to the base address of the
1777 // compile unit. We add the compile unit base address to make
1778 // sure all the addresses are properly fixed up.
1779 ranges.Slide(cu->GetBaseAddress());
1780 if (ranges.FindEntryThatContains(address)) {
1781 found_address = true;
1782 // puts("***MATCH***");
1784 case DW_TAG_compile_unit: // File
1785 check_children = ((function_die != NULL) || (block_die != NULL));
1788 case DW_TAG_subprogram: // Function
1790 *function_die = this;
1791 check_children = (block_die != NULL);
1794 case DW_TAG_inlined_subroutine: // Inlined Function
1795 case DW_TAG_lexical_block: // Block { } in code
1798 check_children = true;
1803 check_children = true;
1807 check_children = false;
1813 if (check_children) {
1814 // printf("checking children\n");
1815 DWARFDebugInfoEntry *child = GetFirstChild();
1817 if (child->LookupAddress(address, dwarf2Data, cu, function_die,
1820 child = child->GetSibling();
1824 return found_address;
1827 const DWARFAbbreviationDeclaration *
1828 DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr(
1829 SymbolFileDWARF *dwarf2Data, const DWARFCompileUnit *cu,
1830 lldb::offset_t &offset) const {
1832 offset = GetOffset();
1834 const DWARFAbbreviationDeclarationSet *abbrev_set = cu->GetAbbreviations();
1836 const DWARFAbbreviationDeclaration *abbrev_decl =
1837 abbrev_set->GetAbbreviationDeclaration(m_abbr_idx);
1839 // Make sure the abbreviation code still matches. If it doesn't and
1840 // the DWARF data was mmap'ed, the backing file might have been modified
1841 // which is bad news.
1842 const uint64_t abbrev_code =
1843 dwarf2Data->get_debug_info_data().GetULEB128(&offset);
1845 if (abbrev_decl->Code() == abbrev_code)
1848 dwarf2Data->GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
1849 "0x%8.8x: the DWARF debug information has been modified (abbrev "
1850 "code was %u, and is now %u)",
1851 GetOffset(), (uint32_t)abbrev_decl->Code(), (uint32_t)abbrev_code);
1855 offset = DW_INVALID_OFFSET;
1859 bool DWARFDebugInfoEntry::OffsetLessThan(const DWARFDebugInfoEntry &a,
1860 const DWARFDebugInfoEntry &b) {
1861 return a.GetOffset() < b.GetOffset();
1864 void DWARFDebugInfoEntry::DumpDIECollection(
1865 Stream &strm, DWARFDebugInfoEntry::collection &die_collection) {
1866 DWARFDebugInfoEntry::const_iterator pos;
1867 DWARFDebugInfoEntry::const_iterator end = die_collection.end();
1868 strm.PutCString("\noffset parent sibling child\n");
1869 strm.PutCString("-------- -------- -------- --------\n");
1870 for (pos = die_collection.begin(); pos != end; ++pos) {
1871 const DWARFDebugInfoEntry &die_ref = *pos;
1872 const DWARFDebugInfoEntry *p = die_ref.GetParent();
1873 const DWARFDebugInfoEntry *s = die_ref.GetSibling();
1874 const DWARFDebugInfoEntry *c = die_ref.GetFirstChild();
1875 strm.Printf("%.8x: %.8x %.8x %.8x 0x%4.4x %s%s\n", die_ref.GetOffset(),
1876 p ? p->GetOffset() : 0, s ? s->GetOffset() : 0,
1877 c ? c->GetOffset() : 0, die_ref.Tag(),
1878 DW_TAG_value_to_name(die_ref.Tag()),
1879 die_ref.HasChildren() ? " *" : "");