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 DWARFDataExtractor &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::ClearDIEs(bool keep_compile_unit_die)
109 if (m_die_array.size() > 1)
111 // std::vectors never get any smaller when resized to a smaller size,
112 // or when clear() or erase() are called, the size will report that it
113 // is smaller, but the memory allocated remains intact (call capacity()
114 // to see this). So we need to create a temporary vector and swap the
115 // contents which will cause just the internal pointers to be swapped
116 // so that when "tmp_array" goes out of scope, it will destroy the
119 // Save at least the compile unit DIE
120 DWARFDebugInfoEntry::collection tmp_array;
121 m_die_array.swap(tmp_array);
122 if (keep_compile_unit_die)
123 m_die_array.push_back(tmp_array.front());
127 //----------------------------------------------------------------------
128 // ParseCompileUnitDIEsIfNeeded
130 // Parses a compile unit and indexes its DIEs if it hasn't already been
132 //----------------------------------------------------------------------
134 DWARFCompileUnit::ExtractDIEsIfNeeded (bool cu_die_only)
136 const size_t initial_die_array_size = m_die_array.size();
137 if ((cu_die_only && initial_die_array_size > 0) || initial_die_array_size > 1)
138 return 0; // Already parsed
140 Timer scoped_timer (__PRETTY_FUNCTION__,
141 "%8.8x: DWARFCompileUnit::ExtractDIEsIfNeeded( cu_die_only = %i )",
145 // Set the offset to that of the first DIE and calculate the start of the
146 // next compilation unit header.
147 lldb::offset_t offset = GetFirstDIEOffset();
148 lldb::offset_t next_cu_offset = GetNextCompileUnitOffset();
150 DWARFDebugInfoEntry die;
151 // Keep a flat array of the DIE for binary lookup by DIE offset
154 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_LOOKUPS));
157 m_dwarf2Data->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
158 "DWARFCompileUnit::ExtractDIEsIfNeeded () for compile unit at .debug_info[0x%8.8x]",
164 // We are in our compile unit, parse starting at the offset
165 // we were told to parse
166 const DWARFDataExtractor& debug_info_data = m_dwarf2Data->get_debug_info_data();
167 std::vector<uint32_t> die_index_stack;
168 die_index_stack.reserve(32);
169 die_index_stack.push_back(0);
170 bool prev_die_had_children = false;
171 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize());
172 while (offset < next_cu_offset &&
173 die.FastExtract (debug_info_data, this, fixed_form_sizes, &offset))
176 // log->Printf("0x%8.8x: %*.*s%s%s",
178 // depth * 2, depth * 2, "",
179 // DW_TAG_value_to_name (die.Tag()),
180 // die.HasChildren() ? " *" : "");
182 const bool null_die = die.IsNULL();
185 uint64_t base_addr = die.GetAttributeValueAsUnsigned(m_dwarf2Data, this, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
186 if (base_addr == LLDB_INVALID_ADDRESS)
187 base_addr = die.GetAttributeValueAsUnsigned(m_dwarf2Data, this, DW_AT_entry_pc, 0);
188 SetBaseAddress (base_addr);
189 if (initial_die_array_size == 0)
198 if (prev_die_had_children)
200 // This will only happen if a DIE says is has children
201 // but all it contains is a NULL tag. Since we are removing
202 // the NULL DIEs from the list (saves up to 25% in C++ code),
203 // we need a way to let the DIE know that it actually doesn't
205 if (!m_die_array.empty())
206 m_die_array.back().SetEmptyChildren(true);
211 die.SetParentIndex(m_die_array.size() - die_index_stack[depth-1]);
213 if (die_index_stack.back())
214 m_die_array[die_index_stack.back()].SetSiblingIndex(m_die_array.size()-die_index_stack.back());
216 // Only push the DIE if it isn't a NULL DIE
217 m_die_array.push_back(die);
224 if (!die_index_stack.empty())
225 die_index_stack.pop_back();
230 break; // We are done with this compile unit!
232 prev_die_had_children = false;
236 die_index_stack.back() = m_die_array.size() - 1;
238 const bool die_has_children = die.HasChildren();
239 if (die_has_children)
241 die_index_stack.push_back(0);
244 prev_die_had_children = die_has_children;
248 // Give a little bit of info if we encounter corrupt DWARF (our offset
249 // should always terminate at or before the start of the next compilation
251 if (offset > next_cu_offset)
253 m_dwarf2Data->GetObjectFile()->GetModule()->ReportWarning ("DWARF compile unit extends beyond its bounds cu 0x%8.8x at 0x%8.8" PRIx64 "\n",
258 // Since std::vector objects will double their size, we really need to
259 // make a new array with the perfect size so we don't end up wasting
260 // space. So here we copy and swap to make sure we don't have any extra
263 if (m_die_array.size () < m_die_array.capacity())
265 DWARFDebugInfoEntry::collection exact_size_die_array (m_die_array.begin(), m_die_array.end());
266 exact_size_die_array.swap (m_die_array);
268 Log *log (LogChannelDWARF::GetLogIfAll (DWARF_LOG_DEBUG_INFO | DWARF_LOG_VERBOSE));
272 DWARFDebugInfoEntry::DumpDIECollection (strm, m_die_array);
273 log->PutCString (strm.GetString().c_str());
276 return m_die_array.size();
281 DWARFCompileUnit::GetAbbrevOffset() const
283 return m_abbrevs ? m_abbrevs->GetOffset() : DW_INVALID_OFFSET;
289 DWARFCompileUnit::Verify(Stream *s) const
291 const DWARFDataExtractor& debug_info = m_dwarf2Data->get_debug_info_data();
292 bool valid_offset = debug_info.ValidOffset(m_offset);
293 bool length_OK = debug_info.ValidOffset(GetNextCompileUnitOffset()-1);
294 bool version_OK = SymbolFileDWARF::SupportedVersion(m_version);
295 bool abbr_offset_OK = m_dwarf2Data->get_debug_abbrev_data().ValidOffset(GetAbbrevOffset());
296 bool addr_size_OK = ((m_addr_size == 4) || (m_addr_size == 8));
297 bool verbose = s->GetVerbose();
298 if (valid_offset && length_OK && version_OK && addr_size_OK && abbr_offset_OK)
301 s->Printf(" 0x%8.8x: OK\n", m_offset);
306 s->Printf(" 0x%8.8x: ", m_offset);
308 m_dwarf2Data->get_debug_info_data().Dump (s, m_offset, lldb::eFormatHex, 1, Size(), 32, LLDB_INVALID_ADDRESS, 0, 0);
313 s->Printf(" The length (0x%8.8x) for this compile unit is too large for the .debug_info provided.\n", m_length);
315 s->Printf(" The 16 bit compile unit header version is not supported.\n");
317 s->Printf(" The offset into the .debug_abbrev section (0x%8.8x) is not valid.\n", GetAbbrevOffset());
319 s->Printf(" The address size is unsupported: 0x%2.2x\n", m_addr_size);
322 s->Printf(" The start offset of the compile unit header in the .debug_info is invalid.\n");
329 DWARFCompileUnit::Dump(Stream *s) const
331 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",
332 m_offset, m_length, m_version, GetAbbrevOffset(), m_addr_size, GetNextCompileUnitOffset());
336 static uint8_t g_default_addr_size = 4;
339 DWARFCompileUnit::GetAddressByteSize(const DWARFCompileUnit* cu)
342 return cu->GetAddressByteSize();
343 return DWARFCompileUnit::GetDefaultAddressSize();
347 DWARFCompileUnit::GetDefaultAddressSize()
349 return g_default_addr_size;
353 DWARFCompileUnit::SetDefaultAddressSize(uint8_t addr_size)
355 g_default_addr_size = addr_size;
359 DWARFCompileUnit::BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data,
360 DWARFDebugAranges* debug_aranges,
361 bool clear_dies_if_already_not_parsed)
363 // This function is usually called if there in no .debug_aranges section
364 // in order to produce a compile unit level set of address ranges that
365 // is accurate. If the DIEs weren't parsed, then we don't want all dies for
366 // all compile units to stay loaded when they weren't needed. So we can end
367 // up parsing the DWARF and then throwing them all away to keep memory usage
369 const bool clear_dies = ExtractDIEsIfNeeded (false) > 1;
371 const DWARFDebugInfoEntry* die = DIE();
373 die->BuildAddressRangeTable(dwarf2Data, this, debug_aranges);
375 if (debug_aranges->IsEmpty())
377 // We got nothing from the functions, maybe we have a line tables only
378 // situation. Check the line tables and build the arange table from this.
380 sc.comp_unit = dwarf2Data->GetCompUnitForDWARFCompUnit(this);
383 SymbolFileDWARFDebugMap *debug_map_sym_file = m_dwarf2Data->GetDebugMapSymfile();
384 if (debug_map_sym_file == NULL)
386 LineTable *line_table = sc.comp_unit->GetLineTable();
390 LineTable::FileAddressRanges file_ranges;
391 const bool append = true;
392 const size_t num_ranges = line_table->GetContiguousFileAddressRanges (file_ranges, append);
393 for (uint32_t idx=0; idx<num_ranges; ++idx)
395 const LineTable::FileAddressRanges::Entry &range = file_ranges.GetEntryRef(idx);
396 debug_aranges->AppendRange(GetOffset(), range.GetRangeBase(), range.GetRangeEnd());
397 printf ("0x%8.8x: [0x%16.16" PRIx64 " - 0x%16.16" PRIx64 ")\n", GetOffset(), range.GetRangeBase(), range.GetRangeEnd());
402 debug_map_sym_file->AddOSOARanges(dwarf2Data,debug_aranges);
406 // Keep memory down by clearing DIEs if this generate function
407 // caused them to be parsed
414 const DWARFDebugAranges &
415 DWARFCompileUnit::GetFunctionAranges ()
417 if (m_func_aranges_ap.get() == NULL)
419 m_func_aranges_ap.reset (new DWARFDebugAranges());
420 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES));
424 m_dwarf2Data->GetObjectFile()->GetModule()->LogMessage (log,
425 "DWARFCompileUnit::GetFunctionAranges() for compile unit at .debug_info[0x%8.8x]",
428 const DWARFDebugInfoEntry* die = DIE();
430 die->BuildFunctionAddressRangeTable (m_dwarf2Data, this, m_func_aranges_ap.get());
431 const bool minimize = false;
432 m_func_aranges_ap->Sort(minimize);
434 return *m_func_aranges_ap.get();
438 DWARFCompileUnit::LookupAddress
440 const dw_addr_t address,
441 DWARFDebugInfoEntry** function_die_handle,
442 DWARFDebugInfoEntry** block_die_handle
445 bool success = false;
447 if (function_die_handle != NULL && DIE())
450 const DWARFDebugAranges &func_aranges = GetFunctionAranges ();
452 // Re-check the aranges auto pointer contents in case it was created above
453 if (!func_aranges.IsEmpty())
455 *function_die_handle = GetDIEPtr(func_aranges.FindAddress(address));
456 if (*function_die_handle != NULL)
459 if (block_die_handle != NULL)
461 DWARFDebugInfoEntry* child = (*function_die_handle)->GetFirstChild();
464 if (child->LookupAddress(address, m_dwarf2Data, this, NULL, block_die_handle))
466 child = child->GetSibling();
475 //----------------------------------------------------------------------
476 // Compare function DWARFDebugAranges::Range structures
477 //----------------------------------------------------------------------
478 static bool CompareDIEOffset (const DWARFDebugInfoEntry& die1, const DWARFDebugInfoEntry& die2)
480 return die1.GetOffset() < die2.GetOffset();
483 //----------------------------------------------------------------------
486 // Get the DIE (Debug Information Entry) with the specified offset.
487 //----------------------------------------------------------------------
489 DWARFCompileUnit::GetDIEPtr(dw_offset_t die_offset)
491 if (die_offset != DW_INVALID_OFFSET)
493 ExtractDIEsIfNeeded (false);
494 DWARFDebugInfoEntry compare_die;
495 compare_die.SetOffset(die_offset);
496 DWARFDebugInfoEntry::iterator end = m_die_array.end();
497 DWARFDebugInfoEntry::iterator pos = lower_bound(m_die_array.begin(), end, compare_die, CompareDIEOffset);
500 if (die_offset == (*pos).GetOffset())
504 return NULL; // Not found in any compile units
507 //----------------------------------------------------------------------
508 // GetDIEPtrContainingOffset()
510 // Get the DIE (Debug Information Entry) that contains the specified
511 // .debug_info offset.
512 //----------------------------------------------------------------------
513 const DWARFDebugInfoEntry*
514 DWARFCompileUnit::GetDIEPtrContainingOffset(dw_offset_t die_offset)
516 if (die_offset != DW_INVALID_OFFSET)
518 ExtractDIEsIfNeeded (false);
519 DWARFDebugInfoEntry compare_die;
520 compare_die.SetOffset(die_offset);
521 DWARFDebugInfoEntry::iterator end = m_die_array.end();
522 DWARFDebugInfoEntry::iterator pos = lower_bound(m_die_array.begin(), end, compare_die, CompareDIEOffset);
525 if (die_offset >= (*pos).GetOffset())
527 DWARFDebugInfoEntry::iterator next = pos + 1;
530 if (die_offset < (*next).GetOffset())
536 return NULL; // Not found in any compile units
542 DWARFCompileUnit::AppendDIEsWithTag (const dw_tag_t tag, DWARFDIECollection& dies, uint32_t depth) const
544 size_t old_size = dies.Size();
545 DWARFDebugInfoEntry::const_iterator pos;
546 DWARFDebugInfoEntry::const_iterator end = m_die_array.end();
547 for (pos = m_die_array.begin(); pos != end; ++pos)
549 if (pos->Tag() == tag)
550 dies.Append (&(*pos));
553 // Return the number of DIEs added to the collection
554 return dies.Size() - old_size;
558 //DWARFCompileUnit::AddGlobalDIEByIndex (uint32_t die_idx)
560 // m_global_die_indexes.push_back (die_idx);
565 //DWARFCompileUnit::AddGlobal (const DWARFDebugInfoEntry* die)
567 // // Indexes to all file level global and static variables
568 // m_global_die_indexes;
570 // if (m_die_array.empty())
573 // const DWARFDebugInfoEntry* first_die = &m_die_array[0];
574 // const DWARFDebugInfoEntry* end = first_die + m_die_array.size();
575 // if (first_die <= die && die < end)
576 // m_global_die_indexes.push_back (die - first_die);
581 DWARFCompileUnit::Index (const uint32_t cu_idx,
582 NameToDIE& func_basenames,
583 NameToDIE& func_fullnames,
584 NameToDIE& func_methods,
585 NameToDIE& func_selectors,
586 NameToDIE& objc_class_selectors,
589 NameToDIE& namespaces)
591 const DWARFDataExtractor* debug_str = &m_dwarf2Data->get_debug_str_data();
593 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize());
595 Log *log (LogChannelDWARF::GetLogIfAll (DWARF_LOG_LOOKUPS));
599 m_dwarf2Data->GetObjectFile()->GetModule()->LogMessage (log,
600 "DWARFCompileUnit::Index() for compile unit at .debug_info[0x%8.8x]",
604 DWARFDebugInfoEntry::const_iterator pos;
605 DWARFDebugInfoEntry::const_iterator begin = m_die_array.begin();
606 DWARFDebugInfoEntry::const_iterator end = m_die_array.end();
607 for (pos = begin; pos != end; ++pos)
609 const DWARFDebugInfoEntry &die = *pos;
611 const dw_tag_t tag = die.Tag();
615 case DW_TAG_subprogram:
616 case DW_TAG_inlined_subroutine:
617 case DW_TAG_base_type:
618 case DW_TAG_class_type:
619 case DW_TAG_constant:
620 case DW_TAG_enumeration_type:
621 case DW_TAG_string_type:
622 case DW_TAG_subroutine_type:
623 case DW_TAG_structure_type:
624 case DW_TAG_union_type:
626 case DW_TAG_namespace:
627 case DW_TAG_variable:
628 case DW_TAG_unspecified_type:
635 DWARFDebugInfoEntry::Attributes attributes;
636 const char *name = NULL;
637 const char *mangled_cstr = NULL;
638 bool is_declaration = false;
639 //bool is_artificial = false;
640 bool has_address = false;
641 bool has_location = false;
642 bool is_global_or_static_variable = false;
644 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
645 const size_t num_attributes = die.GetAttributes(m_dwarf2Data, this, fixed_form_sizes, attributes);
646 if (num_attributes > 0)
648 for (uint32_t i=0; i<num_attributes; ++i)
650 dw_attr_t attr = attributes.AttributeAtIndex(i);
651 DWARFFormValue form_value;
655 if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value))
656 name = form_value.AsCString(debug_str);
659 case DW_AT_declaration:
660 if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value))
661 is_declaration = form_value.Unsigned() != 0;
664 // case DW_AT_artificial:
665 // if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value))
666 // is_artificial = form_value.Unsigned() != 0;
669 case DW_AT_MIPS_linkage_name:
670 case DW_AT_linkage_name:
671 if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value))
672 mangled_cstr = form_value.AsCString(debug_str);
687 if (tag == DW_TAG_variable)
689 const DWARFDebugInfoEntry* parent_die = die.GetParent();
690 while ( parent_die != NULL )
692 switch (parent_die->Tag())
694 case DW_TAG_subprogram:
695 case DW_TAG_lexical_block:
696 case DW_TAG_inlined_subroutine:
697 // Even if this is a function level static, we don't add it. We could theoretically
698 // add these if we wanted to by introspecting into the DW_AT_location and seeing
699 // if the location describes a hard coded address, but we dont want the performance
700 // penalty of that right now.
701 is_global_or_static_variable = false;
702 // if (attributes.ExtractFormValueAtIndex(dwarf2Data, i, form_value))
704 // // If we have valid block data, then we have location expression bytes
705 // // that are fixed (not a location list).
706 // const uint8_t *block_data = form_value.BlockData();
709 // uint32_t block_length = form_value.Unsigned();
710 // if (block_length == 1 + attributes.CompileUnitAtIndex(i)->GetAddressByteSize())
712 // if (block_data[0] == DW_OP_addr)
717 parent_die = NULL; // Terminate the while loop.
720 case DW_TAG_compile_unit:
721 is_global_or_static_variable = true;
722 parent_die = NULL; // Terminate the while loop.
726 parent_die = parent_die->GetParent(); // Keep going in the while loop.
733 case DW_AT_specification:
734 if (attributes.ExtractFormValueAtIndex(m_dwarf2Data, i, form_value))
735 specification_die_offset = form_value.Reference(this);
743 case DW_TAG_subprogram:
748 // Note, this check is also done in ParseMethodName, but since this is a hot loop, we do the
749 // simple inlined check outside the call.
750 ObjCLanguageRuntime::MethodName objc_method(name, true);
751 if (objc_method.IsValid(true))
753 ConstString objc_class_name_with_category (objc_method.GetClassNameWithCategory());
754 ConstString objc_selector_name (objc_method.GetSelector());
755 ConstString objc_fullname_no_category_name (objc_method.GetFullNameWithoutCategory(true));
756 ConstString objc_class_name_no_category (objc_method.GetClassName());
757 func_fullnames.Insert (ConstString(name), die.GetOffset());
758 if (objc_class_name_with_category)
759 objc_class_selectors.Insert(objc_class_name_with_category, die.GetOffset());
760 if (objc_class_name_no_category && objc_class_name_no_category != objc_class_name_with_category)
761 objc_class_selectors.Insert(objc_class_name_no_category, die.GetOffset());
762 if (objc_selector_name)
763 func_selectors.Insert (objc_selector_name, die.GetOffset());
764 if (objc_fullname_no_category_name)
765 func_fullnames.Insert (objc_fullname_no_category_name, die.GetOffset());
767 // If we have a mangled name, then the DW_AT_name attribute
768 // is usually the method name without the class or any parameters
769 const DWARFDebugInfoEntry *parent = die.GetParent();
770 bool is_method = false;
773 dw_tag_t parent_tag = parent->Tag();
774 if (parent_tag == DW_TAG_class_type || parent_tag == DW_TAG_structure_type)
780 if (specification_die_offset != DW_INVALID_OFFSET)
782 const DWARFDebugInfoEntry *specification_die = m_dwarf2Data->DebugInfo()->GetDIEPtr (specification_die_offset, NULL);
783 if (specification_die)
785 parent = specification_die->GetParent();
788 parent_tag = parent->Tag();
790 if (parent_tag == DW_TAG_class_type || parent_tag == DW_TAG_structure_type)
800 func_methods.Insert (ConstString(name), die.GetOffset());
802 func_basenames.Insert (ConstString(name), die.GetOffset());
804 if (!is_method && !mangled_cstr && !objc_method.IsValid(true))
805 func_fullnames.Insert (ConstString(name), die.GetOffset());
809 // Make sure our mangled name isn't the same string table entry
810 // as our name. If it starts with '_', then it is ok, else compare
811 // the string to make sure it isn't the same and we don't end up
812 // with duplicate entries
813 if (name != mangled_cstr && ((mangled_cstr[0] == '_') || (name && ::strcmp(name, mangled_cstr) != 0)))
815 Mangled mangled (ConstString(mangled_cstr), true);
816 func_fullnames.Insert (mangled.GetMangledName(), die.GetOffset());
817 if (mangled.GetDemangledName())
818 func_fullnames.Insert (mangled.GetDemangledName(), die.GetOffset());
824 case DW_TAG_inlined_subroutine:
828 func_basenames.Insert (ConstString(name), die.GetOffset());
831 // Make sure our mangled name isn't the same string table entry
832 // as our name. If it starts with '_', then it is ok, else compare
833 // the string to make sure it isn't the same and we don't end up
834 // with duplicate entries
835 if (name != mangled_cstr && ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0)))
837 Mangled mangled (ConstString(mangled_cstr), true);
838 func_fullnames.Insert (mangled.GetMangledName(), die.GetOffset());
839 if (mangled.GetDemangledName())
840 func_fullnames.Insert (mangled.GetDemangledName(), die.GetOffset());
844 func_fullnames.Insert (ConstString(name), die.GetOffset());
848 case DW_TAG_base_type:
849 case DW_TAG_class_type:
850 case DW_TAG_constant:
851 case DW_TAG_enumeration_type:
852 case DW_TAG_string_type:
853 case DW_TAG_subroutine_type:
854 case DW_TAG_structure_type:
855 case DW_TAG_union_type:
857 case DW_TAG_unspecified_type:
858 if (name && is_declaration == false)
860 types.Insert (ConstString(name), die.GetOffset());
864 case DW_TAG_namespace:
866 namespaces.Insert (ConstString(name), die.GetOffset());
869 case DW_TAG_variable:
870 if (name && has_location && is_global_or_static_variable)
872 globals.Insert (ConstString(name), die.GetOffset());
873 // Be sure to include variables by their mangled and demangled
874 // names if they have any since a variable can have a basename
875 // "i", a mangled named "_ZN12_GLOBAL__N_11iE" and a demangled
876 // mangled name "(anonymous namespace)::i"...
878 // Make sure our mangled name isn't the same string table entry
879 // as our name. If it starts with '_', then it is ok, else compare
880 // the string to make sure it isn't the same and we don't end up
881 // with duplicate entries
882 if (mangled_cstr && name != mangled_cstr && ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0)))
884 Mangled mangled (ConstString(mangled_cstr), true);
885 globals.Insert (mangled.GetMangledName(), die.GetOffset());
886 if (mangled.GetDemangledName())
887 globals.Insert (mangled.GetDemangledName(), die.GetOffset());
899 DWARFCompileUnit::Supports_unnamed_objc_bitfields ()
901 if (GetProducer() == eProducerClang)
903 const uint32_t major_version = GetProducerVersionMajor();
904 if (major_version > 425 || (major_version == 425 && GetProducerVersionUpdate() >= 13))
909 return true; // Assume all other compilers didn't have incorrect ObjC bitfield info
913 DWARFCompileUnit::Supports_DW_AT_APPLE_objc_complete_type ()
915 if (GetProducer() == eProducerLLVMGCC)
921 DWARFCompileUnit::DW_AT_decl_file_attributes_are_invalid()
923 // llvm-gcc makes completely invalid decl file attributes and won't ever
924 // be fixed, so we need to know to ignore these.
925 return GetProducer() == eProducerLLVMGCC;
929 DWARFCompileUnit::ParseProducerInfo ()
931 m_producer_version_major = UINT32_MAX;
932 m_producer_version_minor = UINT32_MAX;
933 m_producer_version_update = UINT32_MAX;
935 const DWARFDebugInfoEntry *die = GetCompileUnitDIEOnly();
939 const char *producer_cstr = die->GetAttributeValueAsString(m_dwarf2Data, this, DW_AT_producer, NULL);
942 RegularExpression llvm_gcc_regex("^4\\.[012]\\.[01] \\(Based on Apple Inc\\. build [0-9]+\\) \\(LLVM build [\\.0-9]+\\)$");
943 if (llvm_gcc_regex.Execute (producer_cstr))
945 m_producer = eProducerLLVMGCC;
947 else if (strstr(producer_cstr, "clang"))
949 static RegularExpression g_clang_version_regex("clang-([0-9]+)\\.([0-9]+)\\.([0-9]+)");
950 RegularExpression::Match regex_match(3);
951 if (g_clang_version_regex.Execute (producer_cstr, ®ex_match))
954 if (regex_match.GetMatchAtIndex (producer_cstr, 1, str))
955 m_producer_version_major = Args::StringToUInt32(str.c_str(), UINT32_MAX, 10);
956 if (regex_match.GetMatchAtIndex (producer_cstr, 2, str))
957 m_producer_version_minor = Args::StringToUInt32(str.c_str(), UINT32_MAX, 10);
958 if (regex_match.GetMatchAtIndex (producer_cstr, 3, str))
959 m_producer_version_update = Args::StringToUInt32(str.c_str(), UINT32_MAX, 10);
961 m_producer = eProducerClang;
963 else if (strstr(producer_cstr, "GNU"))
964 m_producer = eProducerGCC;
967 if (m_producer == eProducerInvalid)
968 m_producer = eProcucerOther;
971 DWARFCompileUnit::Producer
972 DWARFCompileUnit::GetProducer ()
974 if (m_producer == eProducerInvalid)
975 ParseProducerInfo ();
981 DWARFCompileUnit::GetProducerVersionMajor()
983 if (m_producer_version_major == 0)
984 ParseProducerInfo ();
985 return m_producer_version_major;
989 DWARFCompileUnit::GetProducerVersionMinor()
991 if (m_producer_version_minor == 0)
992 ParseProducerInfo ();
993 return m_producer_version_minor;
997 DWARFCompileUnit::GetProducerVersionUpdate()
999 if (m_producer_version_update == 0)
1000 ParseProducerInfo ();
1001 return m_producer_version_update;