1 //===-- DWARFCompileUnit.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 "DWARFCompileUnit.h"
12 #include "lldb/Core/Mangled.h"
13 #include "lldb/Core/Module.h"
14 #include "lldb/Core/Stream.h"
15 #include "lldb/Core/Timer.h"
16 #include "lldb/Symbol/CompileUnit.h"
17 #include "lldb/Symbol/LineTable.h"
18 #include "lldb/Symbol/ObjectFile.h"
19 #include "lldb/Target/ObjCLanguageRuntime.h"
21 #include "DWARFDebugAbbrev.h"
22 #include "DWARFDebugAranges.h"
23 #include "DWARFDebugInfo.h"
24 #include "DWARFDIECollection.h"
25 #include "DWARFFormValue.h"
26 #include "LogChannelDWARF.h"
27 #include "NameToDIE.h"
28 #include "SymbolFileDWARF.h"
29 #include "SymbolFileDWARFDebugMap.h"
32 using namespace lldb_private;
38 DWARFCompileUnit::DWARFCompileUnit(SymbolFileDWARF* dwarf2Data) :
39 m_dwarf2Data (dwarf2Data),
45 m_offset (DW_INVALID_OFFSET),
48 m_addr_size (DWARFCompileUnit::GetDefaultAddressSize()),
49 m_producer (eProducerInvalid),
50 m_producer_version_major (0),
51 m_producer_version_minor (0),
52 m_producer_version_update (0)
57 DWARFCompileUnit::Clear()
59 m_offset = DW_INVALID_OFFSET;
63 m_addr_size = DWARFCompileUnit::GetDefaultAddressSize();
66 m_func_aranges_ap.reset();
68 m_producer = eProducerInvalid;
72 DWARFCompileUnit::Extract(const DataExtractor &debug_info, lldb::offset_t *offset_ptr)
76 m_offset = *offset_ptr;
78 if (debug_info.ValidOffset(*offset_ptr))
80 dw_offset_t abbr_offset;
81 const DWARFDebugAbbrev *abbr = m_dwarf2Data->DebugAbbrev();
82 m_length = debug_info.GetU32(offset_ptr);
83 m_version = debug_info.GetU16(offset_ptr);
84 abbr_offset = debug_info.GetU32(offset_ptr);
85 m_addr_size = debug_info.GetU8 (offset_ptr);
87 bool length_OK = debug_info.ValidOffset(GetNextCompileUnitOffset()-1);
88 bool version_OK = SymbolFileDWARF::SupportedVersion(m_version);
89 bool abbr_offset_OK = m_dwarf2Data->get_debug_abbrev_data().ValidOffset(abbr_offset);
90 bool addr_size_OK = ((m_addr_size == 4) || (m_addr_size == 8));
92 if (length_OK && version_OK && addr_size_OK && abbr_offset_OK && abbr != NULL)
94 m_abbrevs = abbr->GetAbbreviationDeclarationSet(abbr_offset);
98 // reset the offset to where we tried to parse from if anything went wrong
99 *offset_ptr = m_offset;
107 DWARFCompileUnit::Extract(lldb::offset_t offset, const DataExtractor& debug_info_data, const DWARFAbbreviationDeclarationSet* abbrevs)
113 if (debug_info_data.ValidOffset(offset))
115 m_length = debug_info_data.GetU32(&offset);
116 m_version = debug_info_data.GetU16(&offset);
117 bool abbrevs_OK = debug_info_data.GetU32(&offset) == abbrevs->GetOffset();
119 m_addr_size = debug_info_data.GetU8 (&offset);
121 bool version_OK = SymbolFileDWARF::SupportedVersion(m_version);
122 bool addr_size_OK = ((m_addr_size == 4) || (m_addr_size == 8));
124 if (version_OK && addr_size_OK && abbrevs_OK && debug_info_data.ValidOffset(offset))
127 return DW_INVALID_OFFSET;
131 DWARFCompileUnit::ClearDIEs(bool keep_compile_unit_die)
133 if (m_die_array.size() > 1)
135 // std::vectors never get any smaller when resized to a smaller size,
136 // or when clear() or erase() are called, the size will report that it
137 // is smaller, but the memory allocated remains intact (call capacity()
138 // to see this). So we need to create a temporary vector and swap the
139 // contents which will cause just the internal pointers to be swapped
140 // so that when "tmp_array" goes out of scope, it will destroy the
143 // Save at least the compile unit DIE
144 DWARFDebugInfoEntry::collection tmp_array;
145 m_die_array.swap(tmp_array);
146 if (keep_compile_unit_die)
147 m_die_array.push_back(tmp_array.front());
151 //----------------------------------------------------------------------
152 // ParseCompileUnitDIEsIfNeeded
154 // Parses a compile unit and indexes its DIEs if it hasn't already been
156 //----------------------------------------------------------------------
158 DWARFCompileUnit::ExtractDIEsIfNeeded (bool cu_die_only)
160 const size_t initial_die_array_size = m_die_array.size();
161 if ((cu_die_only && initial_die_array_size > 0) || initial_die_array_size > 1)
162 return 0; // Already parsed
164 Timer scoped_timer (__PRETTY_FUNCTION__,
165 "%8.8x: DWARFCompileUnit::ExtractDIEsIfNeeded( cu_die_only = %i )",
169 // Set the offset to that of the first DIE and calculate the start of the
170 // next compilation unit header.
171 lldb::offset_t offset = GetFirstDIEOffset();
172 lldb::offset_t next_cu_offset = GetNextCompileUnitOffset();
174 DWARFDebugInfoEntry die;
175 // Keep a flat array of the DIE for binary lookup by DIE offset
178 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_LOOKUPS));
181 m_dwarf2Data->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
182 "DWARFCompileUnit::ExtractDIEsIfNeeded () for compile unit at .debug_info[0x%8.8x]",
188 // We are in our compile unit, parse starting at the offset
189 // we were told to parse
190 const DataExtractor& debug_info_data = m_dwarf2Data->get_debug_info_data();
191 std::vector<uint32_t> die_index_stack;
192 die_index_stack.reserve(32);
193 die_index_stack.push_back(0);
194 bool prev_die_had_children = false;
195 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize());
196 while (offset < next_cu_offset &&
197 die.FastExtract (debug_info_data, this, fixed_form_sizes, &offset))
200 // log->Printf("0x%8.8x: %*.*s%s%s",
202 // depth * 2, depth * 2, "",
203 // DW_TAG_value_to_name (die.Tag()),
204 // die.HasChildren() ? " *" : "");
206 const bool null_die = die.IsNULL();
209 uint64_t base_addr = die.GetAttributeValueAsUnsigned(m_dwarf2Data, this, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
210 if (base_addr == LLDB_INVALID_ADDRESS)
211 base_addr = die.GetAttributeValueAsUnsigned(m_dwarf2Data, this, DW_AT_entry_pc, 0);
212 SetBaseAddress (base_addr);
213 if (initial_die_array_size == 0)
222 if (prev_die_had_children)
224 // This will only happen if a DIE says is has children
225 // but all it contains is a NULL tag. Since we are removing
226 // the NULL DIEs from the list (saves up to 25% in C++ code),
227 // we need a way to let the DIE know that it actually doesn't
229 if (!m_die_array.empty())
230 m_die_array.back().SetEmptyChildren(true);
235 die.SetParentIndex(m_die_array.size() - die_index_stack[depth-1]);
237 if (die_index_stack.back())
238 m_die_array[die_index_stack.back()].SetSiblingIndex(m_die_array.size()-die_index_stack.back());
240 // Only push the DIE if it isn't a NULL DIE
241 m_die_array.push_back(die);
248 if (!die_index_stack.empty())
249 die_index_stack.pop_back();
254 break; // We are done with this compile unit!
256 prev_die_had_children = false;
260 die_index_stack.back() = m_die_array.size() - 1;
262 const bool die_has_children = die.HasChildren();
263 if (die_has_children)
265 die_index_stack.push_back(0);
268 prev_die_had_children = die_has_children;
272 // Give a little bit of info if we encounter corrupt DWARF (our offset
273 // should always terminate at or before the start of the next compilation
275 if (offset > next_cu_offset)
277 m_dwarf2Data->GetObjectFile()->GetModule()->ReportWarning ("DWARF compile unit extends beyond its bounds cu 0x%8.8x at 0x%8.8" PRIx64 "\n",
282 // Since std::vector objects will double their size, we really need to
283 // make a new array with the perfect size so we don't end up wasting
284 // space. So here we copy and swap to make sure we don't have any extra
287 if (m_die_array.size () < m_die_array.capacity())
289 DWARFDebugInfoEntry::collection exact_size_die_array (m_die_array.begin(), m_die_array.end());
290 exact_size_die_array.swap (m_die_array);
292 Log *log (LogChannelDWARF::GetLogIfAll (DWARF_LOG_DEBUG_INFO | DWARF_LOG_VERBOSE));
296 DWARFDebugInfoEntry::DumpDIECollection (strm, m_die_array);
297 log->PutCString (strm.GetString().c_str());
300 return m_die_array.size();
305 DWARFCompileUnit::GetAbbrevOffset() const
307 return m_abbrevs ? m_abbrevs->GetOffset() : DW_INVALID_OFFSET;
313 DWARFCompileUnit::Verify(Stream *s) const
315 const DataExtractor& debug_info = m_dwarf2Data->get_debug_info_data();
316 bool valid_offset = debug_info.ValidOffset(m_offset);
317 bool length_OK = debug_info.ValidOffset(GetNextCompileUnitOffset()-1);
318 bool version_OK = SymbolFileDWARF::SupportedVersion(m_version);
319 bool abbr_offset_OK = m_dwarf2Data->get_debug_abbrev_data().ValidOffset(GetAbbrevOffset());
320 bool addr_size_OK = ((m_addr_size == 4) || (m_addr_size == 8));
321 bool verbose = s->GetVerbose();
322 if (valid_offset && length_OK && version_OK && addr_size_OK && abbr_offset_OK)
325 s->Printf(" 0x%8.8x: OK\n", m_offset);
330 s->Printf(" 0x%8.8x: ", m_offset);
332 m_dwarf2Data->get_debug_info_data().Dump (s, m_offset, lldb::eFormatHex, 1, Size(), 32, LLDB_INVALID_ADDRESS, 0, 0);
337 s->Printf(" The length (0x%8.8x) for this compile unit is too large for the .debug_info provided.\n", m_length);
339 s->Printf(" The 16 bit compile unit header version is not supported.\n");
341 s->Printf(" The offset into the .debug_abbrev section (0x%8.8x) is not valid.\n", GetAbbrevOffset());
343 s->Printf(" The address size is unsupported: 0x%2.2x\n", m_addr_size);
346 s->Printf(" The start offset of the compile unit header in the .debug_info is invalid.\n");
353 DWARFCompileUnit::Dump(Stream *s) const
355 s->Printf("0x%8.8x: Compile Unit: length = 0x%8.8x, version = 0x%4.4x, abbr_offset = 0x%8.8x, addr_size = 0x%2.2x (next CU at {0x%8.8x})\n",
356 m_offset, m_length, m_version, GetAbbrevOffset(), m_addr_size, GetNextCompileUnitOffset());
360 static uint8_t g_default_addr_size = 4;
363 DWARFCompileUnit::GetAddressByteSize(const DWARFCompileUnit* cu)
366 return cu->GetAddressByteSize();
367 return DWARFCompileUnit::GetDefaultAddressSize();
371 DWARFCompileUnit::GetDefaultAddressSize()
373 return g_default_addr_size;
377 DWARFCompileUnit::SetDefaultAddressSize(uint8_t addr_size)
379 g_default_addr_size = addr_size;
383 DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data,
384 DWARFDebugAranges* debug_aranges,
385 bool clear_dies_if_already_not_parsed)
387 // This function is usually called if there in no .debug_aranges section
388 // in order to produce a compile unit level set of address ranges that
389 // is accurate. If the DIEs weren't parsed, then we don't want all dies for
390 // all compile units to stay loaded when they weren't needed. So we can end
391 // up parsing the DWARF and then throwing them all away to keep memory usage
393 const bool clear_dies = ExtractDIEsIfNeeded (false) > 1;
395 const DWARFDebugInfoEntry* die = DIE();
397 die->BuildAddressRangeTable(dwarf2Data, this, debug_aranges);
399 if (debug_aranges->IsEmpty())
401 // We got nothing from the functions, maybe we have a line tables only
402 // situation. Check the line tables and build the arange table from this.
404 sc.comp_unit = dwarf2Data->GetCompUnitForDWARFCompUnit(this);
407 SymbolFileDWARFDebugMap *debug_map_sym_file = m_dwarf2Data->GetDebugMapSymfile();
408 if (debug_map_sym_file == NULL)
410 LineTable *line_table = sc.comp_unit->GetLineTable();
414 LineTable::FileAddressRanges file_ranges;
415 const bool append = true;
416 const size_t num_ranges = line_table->GetContiguousFileAddressRanges (file_ranges, append);
417 for (uint32_t idx=0; idx<num_ranges; ++idx)
419 const LineTable::FileAddressRanges::Entry &range = file_ranges.GetEntryRef(idx);
420 debug_aranges->AppendRange(GetOffset(), range.GetRangeBase(), range.GetRangeEnd());
421 printf ("0x%8.8x: [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n", GetOffset(), range.GetRangeBase(), range.GetRangeEnd());
426 debug_map_sym_file->AddOSOARanges(dwarf2Data,debug_aranges);
430 // Keep memory down by clearing DIEs if this generate function
431 // caused them to be parsed
438 const DWARFDebugAranges &
439 DWARFCompileUnit::GetFunctionAranges ()
441 if (m_func_aranges_ap.get() == NULL)
443 m_func_aranges_ap.reset (new DWARFDebugAranges());
444 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES));
448 m_dwarf2Data->GetObjectFile()->GetModule()->LogMessage (log,
449 "DWARFCompileUnit::GetFunctionAranges() for compile unit at .debug_info[0x%8.8x]",
452 const DWARFDebugInfoEntry* die = DIE();
454 die->BuildFunctionAddressRangeTable (m_dwarf2Data, this, m_func_aranges_ap.get());
455 const bool minimize = false;
456 m_func_aranges_ap->Sort(minimize);
458 return *m_func_aranges_ap.get();
462 DWARFCompileUnit::LookupAddress
464 const dw_addr_t address,
465 DWARFDebugInfoEntry** function_die_handle,
466 DWARFDebugInfoEntry** block_die_handle
469 bool success = false;
471 if (function_die_handle != NULL && DIE())
474 const DWARFDebugAranges &func_aranges = GetFunctionAranges ();
476 // Re-check the aranges auto pointer contents in case it was created above
477 if (!func_aranges.IsEmpty())
479 *function_die_handle = GetDIEPtr(func_aranges.FindAddress(address));
480 if (*function_die_handle != NULL)
483 if (block_die_handle != NULL)
485 DWARFDebugInfoEntry* child = (*function_die_handle)->GetFirstChild();
488 if (child->LookupAddress(address, m_dwarf2Data, this, NULL, block_die_handle))
490 child = child->GetSibling();
499 //----------------------------------------------------------------------
500 // Compare function DWARFDebugAranges::Range structures
501 //----------------------------------------------------------------------
502 static bool CompareDIEOffset (const DWARFDebugInfoEntry& die1, const DWARFDebugInfoEntry& die2)
504 return die1.GetOffset() < die2.GetOffset();
507 //----------------------------------------------------------------------
510 // Get the DIE (Debug Information Entry) with the specified offset.
511 //----------------------------------------------------------------------
513 DWARFCompileUnit::GetDIEPtr(dw_offset_t die_offset)
515 if (die_offset != DW_INVALID_OFFSET)
517 ExtractDIEsIfNeeded (false);
518 DWARFDebugInfoEntry compare_die;
519 compare_die.SetOffset(die_offset);
520 DWARFDebugInfoEntry::iterator end = m_die_array.end();
521 DWARFDebugInfoEntry::iterator pos = lower_bound(m_die_array.begin(), end, compare_die, CompareDIEOffset);
524 if (die_offset == (*pos).GetOffset())
528 return NULL; // Not found in any compile units
531 //----------------------------------------------------------------------
532 // GetDIEPtrContainingOffset()
534 // Get the DIE (Debug Information Entry) that contains the specified
535 // .debug_info offset.
536 //----------------------------------------------------------------------
537 const DWARFDebugInfoEntry*
538 DWARFCompileUnit::GetDIEPtrContainingOffset(dw_offset_t die_offset)
540 if (die_offset != DW_INVALID_OFFSET)
542 ExtractDIEsIfNeeded (false);
543 DWARFDebugInfoEntry compare_die;
544 compare_die.SetOffset(die_offset);
545 DWARFDebugInfoEntry::iterator end = m_die_array.end();
546 DWARFDebugInfoEntry::iterator pos = lower_bound(m_die_array.begin(), end, compare_die, CompareDIEOffset);
549 if (die_offset >= (*pos).GetOffset())
551 DWARFDebugInfoEntry::iterator next = pos + 1;
554 if (die_offset < (*next).GetOffset())
560 return NULL; // Not found in any compile units
566 DWARFCompileUnit::AppendDIEsWithTag (const dw_tag_t tag, DWARFDIECollection& dies, uint32_t depth) const
568 size_t old_size = dies.Size();
569 DWARFDebugInfoEntry::const_iterator pos;
570 DWARFDebugInfoEntry::const_iterator end = m_die_array.end();
571 for (pos = m_die_array.begin(); pos != end; ++pos)
573 if (pos->Tag() == tag)
574 dies.Append (&(*pos));
577 // Return the number of DIEs added to the collection
578 return dies.Size() - old_size;
582 //DWARFCompileUnit::AddGlobalDIEByIndex (uint32_t die_idx)
584 // m_global_die_indexes.push_back (die_idx);
589 //DWARFCompileUnit::AddGlobal (const DWARFDebugInfoEntry* die)
591 // // Indexes to all file level global and static variables
592 // m_global_die_indexes;
594 // if (m_die_array.empty())
597 // const DWARFDebugInfoEntry* first_die = &m_die_array[0];
598 // const DWARFDebugInfoEntry* end = first_die + m_die_array.size();
599 // if (first_die <= die && die < end)
600 // m_global_die_indexes.push_back (die - first_die);
605 DWARFCompileUnit::Index (const uint32_t cu_idx,
606 NameToDIE& func_basenames,
607 NameToDIE& func_fullnames,
608 NameToDIE& func_methods,
609 NameToDIE& func_selectors,
610 NameToDIE& objc_class_selectors,
613 NameToDIE& namespaces)
615 const DataExtractor* debug_str = &m_dwarf2Data->get_debug_str_data();
617 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize());
619 Log *log (LogChannelDWARF::GetLogIfAll (DWARF_LOG_LOOKUPS));
623 m_dwarf2Data->GetObjectFile()->GetModule()->LogMessage (log,
624 "DWARFCompileUnit::Index() for compile unit at .debug_info[0x%8.8x]",
628 DWARFDebugInfoEntry::const_iterator pos;
629 DWARFDebugInfoEntry::const_iterator begin = m_die_array.begin();
630 DWARFDebugInfoEntry::const_iterator end = m_die_array.end();
631 for (pos = begin; pos != end; ++pos)
633 const DWARFDebugInfoEntry &die = *pos;
635 const dw_tag_t tag = die.Tag();
639 case DW_TAG_subprogram:
640 case DW_TAG_inlined_subroutine:
641 case DW_TAG_base_type:
642 case DW_TAG_class_type:
643 case DW_TAG_constant:
644 case DW_TAG_enumeration_type:
645 case DW_TAG_string_type:
646 case DW_TAG_subroutine_type:
647 case DW_TAG_structure_type:
648 case DW_TAG_union_type:
650 case DW_TAG_namespace:
651 case DW_TAG_variable:
652 case DW_TAG_unspecified_type:
659 DWARFDebugInfoEntry::Attributes attributes;
660 const char *name = NULL;
661 const char *mangled_cstr = NULL;
662 bool is_declaration = false;
663 //bool is_artificial = false;
664 bool has_address = false;
665 bool has_location = false;
666 bool is_global_or_static_variable = false;
668 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
669 const size_t num_attributes = die.GetAttributes(m_dwarf2Data, this, fixed_form_sizes, attributes);
670 if (num_attributes > 0)
672 for (uint32_t i=0; i<num_attributes; ++i)
674 dw_attr_t attr = attributes.AttributeAtIndex(i);
675 DWARFFormValue form_value;
679 if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value))
680 name = form_value.AsCString(debug_str);
683 case DW_AT_declaration:
684 if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value))
685 is_declaration = form_value.Unsigned() != 0;
688 // case DW_AT_artificial:
689 // if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value))
690 // is_artificial = form_value.Unsigned() != 0;
693 case DW_AT_MIPS_linkage_name:
694 case DW_AT_linkage_name:
695 if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value))
696 mangled_cstr = form_value.AsCString(debug_str);
711 if (tag == DW_TAG_variable)
713 const DWARFDebugInfoEntry* parent_die = die.GetParent();
714 while ( parent_die != NULL )
716 switch (parent_die->Tag())
718 case DW_TAG_subprogram:
719 case DW_TAG_lexical_block:
720 case DW_TAG_inlined_subroutine:
721 // Even if this is a function level static, we don't add it. We could theoretically
722 // add these if we wanted to by introspecting into the DW_AT_location and seeing
723 // if the location describes a hard coded address, but we dont want the performance
724 // penalty of that right now.
725 is_global_or_static_variable = false;
726 // if (attributes.ExtractFormValueAtIndex(dwarf2Data, i, form_value))
728 // // If we have valid block data, then we have location expression bytes
729 // // that are fixed (not a location list).
730 // const uint8_t *block_data = form_value.BlockData();
733 // uint32_t block_length = form_value.Unsigned();
734 // if (block_length == 1 + attributes.CompileUnitAtIndex(i)->GetAddressByteSize())
736 // if (block_data[0] == DW_OP_addr)
741 parent_die = NULL; // Terminate the while loop.
744 case DW_TAG_compile_unit:
745 is_global_or_static_variable = true;
746 parent_die = NULL; // Terminate the while loop.
750 parent_die = parent_die->GetParent(); // Keep going in the while loop.
757 case DW_AT_specification:
758 if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value))
759 specification_die_offset = form_value.Reference(this);
767 case DW_TAG_subprogram:
772 // Note, this check is also done in ParseMethodName, but since this is a hot loop, we do the
773 // simple inlined check outside the call.
774 ObjCLanguageRuntime::MethodName objc_method(name, true);
775 if (objc_method.IsValid(true))
777 ConstString objc_class_name_with_category (objc_method.GetClassNameWithCategory());
778 ConstString objc_selector_name (objc_method.GetSelector());
779 ConstString objc_fullname_no_category_name (objc_method.GetFullNameWithoutCategory(true));
780 ConstString objc_class_name_no_category (objc_method.GetClassName());
781 func_fullnames.Insert (ConstString(name), die.GetOffset());
782 if (objc_class_name_with_category)
783 objc_class_selectors.Insert(objc_class_name_with_category, die.GetOffset());
784 if (objc_class_name_no_category && objc_class_name_no_category != objc_class_name_with_category)
785 objc_class_selectors.Insert(objc_class_name_no_category, die.GetOffset());
786 if (objc_selector_name)
787 func_selectors.Insert (objc_selector_name, die.GetOffset());
788 if (objc_fullname_no_category_name)
789 func_fullnames.Insert (objc_fullname_no_category_name, die.GetOffset());
791 // If we have a mangled name, then the DW_AT_name attribute
792 // is usually the method name without the class or any parameters
793 const DWARFDebugInfoEntry *parent = die.GetParent();
794 bool is_method = false;
797 dw_tag_t parent_tag = parent->Tag();
798 if (parent_tag == DW_TAG_class_type || parent_tag == DW_TAG_structure_type)
804 if (specification_die_offset != DW_INVALID_OFFSET)
806 const DWARFDebugInfoEntry *specification_die = m_dwarf2Data->DebugInfo()->GetDIEPtr (specification_die_offset, NULL);
807 if (specification_die)
809 parent = specification_die->GetParent();
812 parent_tag = parent->Tag();
814 if (parent_tag == DW_TAG_class_type || parent_tag == DW_TAG_structure_type)
824 func_methods.Insert (ConstString(name), die.GetOffset());
826 func_basenames.Insert (ConstString(name), die.GetOffset());
828 if (!is_method && !mangled_cstr && !objc_method.IsValid(true))
829 func_fullnames.Insert (ConstString(name), die.GetOffset());
833 // Make sure our mangled name isn't the same string table entry
834 // as our name. If it starts with '_', then it is ok, else compare
835 // the string to make sure it isn't the same and we don't end up
836 // with duplicate entries
837 if (name != mangled_cstr && ((mangled_cstr[0] == '_') || (name && ::strcmp(name, mangled_cstr) != 0)))
839 Mangled mangled (ConstString(mangled_cstr), true);
840 func_fullnames.Insert (mangled.GetMangledName(), die.GetOffset());
841 if (mangled.GetDemangledName())
842 func_fullnames.Insert (mangled.GetDemangledName(), die.GetOffset());
848 case DW_TAG_inlined_subroutine:
852 func_basenames.Insert (ConstString(name), die.GetOffset());
855 // Make sure our mangled name isn't the same string table entry
856 // as our name. If it starts with '_', then it is ok, else compare
857 // the string to make sure it isn't the same and we don't end up
858 // with duplicate entries
859 if (name != mangled_cstr && ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0)))
861 Mangled mangled (ConstString(mangled_cstr), true);
862 func_fullnames.Insert (mangled.GetMangledName(), die.GetOffset());
863 if (mangled.GetDemangledName())
864 func_fullnames.Insert (mangled.GetDemangledName(), die.GetOffset());
868 func_fullnames.Insert (ConstString(name), die.GetOffset());
872 case DW_TAG_base_type:
873 case DW_TAG_class_type:
874 case DW_TAG_constant:
875 case DW_TAG_enumeration_type:
876 case DW_TAG_string_type:
877 case DW_TAG_subroutine_type:
878 case DW_TAG_structure_type:
879 case DW_TAG_union_type:
881 case DW_TAG_unspecified_type:
882 if (name && is_declaration == false)
884 types.Insert (ConstString(name), die.GetOffset());
888 case DW_TAG_namespace:
890 namespaces.Insert (ConstString(name), die.GetOffset());
893 case DW_TAG_variable:
894 if (name && has_location && is_global_or_static_variable)
896 globals.Insert (ConstString(name), die.GetOffset());
897 // Be sure to include variables by their mangled and demangled
898 // names if they have any since a variable can have a basename
899 // "i", a mangled named "_ZN12_GLOBAL__N_11iE" and a demangled
900 // mangled name "(anonymous namespace)::i"...
902 // Make sure our mangled name isn't the same string table entry
903 // as our name. If it starts with '_', then it is ok, else compare
904 // the string to make sure it isn't the same and we don't end up
905 // with duplicate entries
906 if (mangled_cstr && name != mangled_cstr && ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0)))
908 Mangled mangled (ConstString(mangled_cstr), true);
909 globals.Insert (mangled.GetMangledName(), die.GetOffset());
910 if (mangled.GetDemangledName())
911 globals.Insert (mangled.GetDemangledName(), die.GetOffset());
923 DWARFCompileUnit::Supports_unnamed_objc_bitfields ()
925 if (GetProducer() == eProducerClang)
927 const uint32_t major_version = GetProducerVersionMajor();
928 if (major_version > 425 || (major_version == 425 && GetProducerVersionUpdate() >= 13))
933 return true; // Assume all other compilers didn't have incorrect ObjC bitfield info
937 DWARFCompileUnit::Supports_DW_AT_APPLE_objc_complete_type ()
939 if (GetProducer() == eProducerLLVMGCC)
945 DWARFCompileUnit::DW_AT_decl_file_attributes_are_invalid()
947 // llvm-gcc makes completely invalid decl file attributes and won't ever
948 // be fixed, so we need to know to ignore these.
949 return GetProducer() == eProducerLLVMGCC;
953 DWARFCompileUnit::ParseProducerInfo ()
955 m_producer_version_major = UINT32_MAX;
956 m_producer_version_minor = UINT32_MAX;
957 m_producer_version_update = UINT32_MAX;
959 const DWARFDebugInfoEntry *die = GetCompileUnitDIEOnly();
963 const char *producer_cstr = die->GetAttributeValueAsString(m_dwarf2Data, this, DW_AT_producer, NULL);
966 RegularExpression llvm_gcc_regex("^4\\.[012]\\.[01] \\(Based on Apple Inc\\. build [0-9]+\\) \\(LLVM build [\\.0-9]+\\)$");
967 if (llvm_gcc_regex.Execute (producer_cstr))
969 m_producer = eProducerLLVMGCC;
971 else if (strstr(producer_cstr, "clang"))
973 static RegularExpression g_clang_version_regex("clang-([0-9]+)\\.([0-9]+)\\.([0-9]+)");
974 RegularExpression::Match regex_match(3);
975 if (g_clang_version_regex.Execute (producer_cstr, ®ex_match))
978 if (regex_match.GetMatchAtIndex (producer_cstr, 1, str))
979 m_producer_version_major = Args::StringToUInt32(str.c_str(), UINT32_MAX, 10);
980 if (regex_match.GetMatchAtIndex (producer_cstr, 2, str))
981 m_producer_version_minor = Args::StringToUInt32(str.c_str(), UINT32_MAX, 10);
982 if (regex_match.GetMatchAtIndex (producer_cstr, 3, str))
983 m_producer_version_update = Args::StringToUInt32(str.c_str(), UINT32_MAX, 10);
985 m_producer = eProducerClang;
987 else if (strstr(producer_cstr, "GNU"))
988 m_producer = eProducerGCC;
991 if (m_producer == eProducerInvalid)
992 m_producer = eProcucerOther;
995 DWARFCompileUnit::Producer
996 DWARFCompileUnit::GetProducer ()
998 if (m_producer == eProducerInvalid)
999 ParseProducerInfo ();
1005 DWARFCompileUnit::GetProducerVersionMajor()
1007 if (m_producer_version_major == 0)
1008 ParseProducerInfo ();
1009 return m_producer_version_major;
1013 DWARFCompileUnit::GetProducerVersionMinor()
1015 if (m_producer_version_minor == 0)
1016 ParseProducerInfo ();
1017 return m_producer_version_minor;
1021 DWARFCompileUnit::GetProducerVersionUpdate()
1023 if (m_producer_version_update == 0)
1024 ParseProducerInfo ();
1025 return m_producer_version_update;