1 //===-- SymbolFileDWARF.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 "SymbolFileDWARF.h"
12 // Other libraries and framework includes
13 #include "clang/AST/ASTConsumer.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Decl.h"
16 #include "clang/AST/DeclGroup.h"
17 #include "clang/AST/DeclObjC.h"
18 #include "clang/AST/DeclTemplate.h"
19 #include "clang/Basic/Builtins.h"
20 #include "clang/Basic/IdentifierTable.h"
21 #include "clang/Basic/LangOptions.h"
22 #include "clang/Basic/SourceManager.h"
23 #include "clang/Basic/TargetInfo.h"
24 #include "clang/Basic/Specifiers.h"
25 #include "clang/Sema/DeclSpec.h"
27 #include "llvm/Support/Casting.h"
29 #include "lldb/Core/Module.h"
30 #include "lldb/Core/PluginManager.h"
31 #include "lldb/Core/RegularExpression.h"
32 #include "lldb/Core/Scalar.h"
33 #include "lldb/Core/Section.h"
34 #include "lldb/Core/StreamFile.h"
35 #include "lldb/Core/StreamString.h"
36 #include "lldb/Core/Timer.h"
37 #include "lldb/Core/Value.h"
39 #include "lldb/Host/Host.h"
41 #include "lldb/Symbol/Block.h"
42 #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
43 #include "lldb/Symbol/CompileUnit.h"
44 #include "lldb/Symbol/LineTable.h"
45 #include "lldb/Symbol/ObjectFile.h"
46 #include "lldb/Symbol/SymbolVendor.h"
47 #include "lldb/Symbol/VariableList.h"
49 #include "lldb/Target/ObjCLanguageRuntime.h"
50 #include "lldb/Target/CPPLanguageRuntime.h"
52 #include "DWARFCompileUnit.h"
53 #include "DWARFDebugAbbrev.h"
54 #include "DWARFDebugAranges.h"
55 #include "DWARFDebugInfo.h"
56 #include "DWARFDebugInfoEntry.h"
57 #include "DWARFDebugLine.h"
58 #include "DWARFDebugPubnames.h"
59 #include "DWARFDebugRanges.h"
60 #include "DWARFDeclContext.h"
61 #include "DWARFDIECollection.h"
62 #include "DWARFFormValue.h"
63 #include "DWARFLocationList.h"
64 #include "LogChannelDWARF.h"
65 #include "SymbolFileDWARFDebugMap.h"
69 //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
71 #ifdef ENABLE_DEBUG_PRINTF
73 #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
75 #define DEBUG_PRINTF(fmt, ...)
78 #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
81 using namespace lldb_private;
84 //child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
90 // case DW_TAG_subprogram:
91 // case DW_TAG_inlined_subroutine:
92 // case DW_TAG_class_type:
93 // case DW_TAG_structure_type:
94 // case DW_TAG_union_type:
101 DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
103 switch (dwarf_accessibility)
105 case DW_ACCESS_public: return eAccessPublic;
106 case DW_ACCESS_private: return eAccessPrivate;
107 case DW_ACCESS_protected: return eAccessProtected;
113 #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
119 void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
121 m_dies.push_back (DIEInfo(cu, die));
125 void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
127 StreamString log_strm;
128 const size_t n = m_dies.size();
129 log_strm.Printf("DIEStack[%" PRIu64 "]:\n", (uint64_t)n);
130 for (size_t i=0; i<n; i++)
132 DWARFCompileUnit *cu = m_dies[i].cu;
133 const DWARFDebugInfoEntry *die = m_dies[i].die;
134 std::string qualified_name;
135 die->GetQualifiedName(dwarf, cu, qualified_name);
136 log_strm.Printf ("[%" PRIu64 "] 0x%8.8x: %s name='%s'\n",
139 DW_TAG_value_to_name(die->Tag()),
140 qualified_name.c_str());
142 log->PutCString(log_strm.GetData());
152 ScopedPopper (DIEStack &die_stack) :
153 m_die_stack (die_stack),
159 Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
162 m_die_stack.Push (cu, die);
174 DIEStack &m_die_stack;
180 DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
185 DWARFCompileUnit *cu;
186 const DWARFDebugInfoEntry *die;
188 typedef std::vector<DIEInfo> Stack;
194 SymbolFileDWARF::Initialize()
196 LogChannelDWARF::Initialize();
197 PluginManager::RegisterPlugin (GetPluginNameStatic(),
198 GetPluginDescriptionStatic(),
203 SymbolFileDWARF::Terminate()
205 PluginManager::UnregisterPlugin (CreateInstance);
206 LogChannelDWARF::Initialize();
210 lldb_private::ConstString
211 SymbolFileDWARF::GetPluginNameStatic()
213 static ConstString g_name("dwarf");
218 SymbolFileDWARF::GetPluginDescriptionStatic()
220 return "DWARF and DWARF3 debug symbol file reader.";
225 SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
227 return new SymbolFileDWARF(obj_file);
231 SymbolFileDWARF::GetTypeList ()
233 if (GetDebugMapSymfile ())
234 return m_debug_map_symfile->GetTypeList();
235 return m_obj_file->GetModule()->GetTypeList();
239 SymbolFileDWARF::GetTypes (DWARFCompileUnit* cu,
240 const DWARFDebugInfoEntry *die,
241 dw_offset_t min_die_offset,
242 dw_offset_t max_die_offset,
250 const dw_offset_t die_offset = die->GetOffset();
252 if (die_offset >= max_die_offset)
255 if (die_offset >= min_die_offset)
257 const dw_tag_t tag = die->Tag();
259 bool add_type = false;
263 case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break;
264 case DW_TAG_unspecified_type:
265 case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break;
266 case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break;
267 case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break;
268 case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break;
269 case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break;
270 case DW_TAG_subroutine_type:
271 case DW_TAG_subprogram:
272 case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break;
273 case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break;
274 case DW_TAG_rvalue_reference_type:
275 case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break;
276 case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break;
277 case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break;
282 const bool assert_not_being_parsed = true;
283 Type *type = ResolveTypeUID (cu, die, assert_not_being_parsed);
286 if (type_set.find(type) == type_set.end())
287 type_set.insert(type);
292 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
294 child_die = child_die->GetSibling())
296 GetTypes (cu, child_die, min_die_offset, max_die_offset, type_mask, type_set);
303 SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope,
310 CompileUnit *comp_unit = NULL;
311 DWARFCompileUnit* dwarf_cu = NULL;
313 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
317 dwarf_cu = GetDWARFCompileUnit(comp_unit);
322 dwarf_cu->GetOffset(),
323 dwarf_cu->GetNextCompileUnitOffset(),
329 DWARFDebugInfo* info = DebugInfo();
332 const size_t num_cus = info->GetNumCompileUnits();
333 for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx)
335 dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
348 // if (m_using_apple_tables)
350 // DWARFMappedHash::MemoryTable *apple_types = m_apple_types_ap.get();
353 // apple_types->ForEach([this, &type_set, apple_types, type_mask](const DWARFMappedHash::DIEInfoArray &die_info_array) -> bool {
355 // for (auto die_info: die_info_array)
357 // bool add_type = TagMatchesTypeMask (type_mask, 0);
360 // dw_tag_t tag = die_info.tag;
363 // const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_info.offset, NULL);
366 // add_type = TagMatchesTypeMask (type_mask, tag);
370 // Type *type = ResolveTypeUID(die_info.offset);
372 // if (type_set.find(type) == type_set.end())
373 // type_set.insert(type);
376 // return true; // Keep iterating
385 // m_type_index.ForEach([this, &type_set, type_mask](const char *name, uint32_t die_offset) -> bool {
387 // bool add_type = TagMatchesTypeMask (type_mask, 0);
391 // const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtr(die_offset, NULL);
394 // const dw_tag_t tag = die->Tag();
395 // add_type = TagMatchesTypeMask (type_mask, tag);
401 // Type *type = ResolveTypeUID(die_offset);
403 // if (type_set.find(type) == type_set.end())
404 // type_set.insert(type);
406 // return true; // Keep iterating
410 std::set<ClangASTType> clang_type_set;
411 size_t num_types_added = 0;
412 for (Type *type : type_set)
414 ClangASTType clang_type = type->GetClangForwardType();
415 if (clang_type_set.find(clang_type) == clang_type_set.end())
417 clang_type_set.insert(clang_type);
418 type_list.Insert (type->shared_from_this());
422 return num_types_added;
426 //----------------------------------------------------------------------
427 // Gets the first parent that is a lexical block, function or inlined
428 // subroutine, or compile unit.
429 //----------------------------------------------------------------------
430 static const DWARFDebugInfoEntry *
431 GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
433 const DWARFDebugInfoEntry *die;
434 for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
436 dw_tag_t tag = die->Tag();
440 case DW_TAG_compile_unit:
441 case DW_TAG_subprogram:
442 case DW_TAG_inlined_subroutine:
443 case DW_TAG_lexical_block:
451 SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
452 SymbolFile (objfile),
453 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
454 m_debug_map_module_wp (),
455 m_debug_map_symfile (NULL),
456 m_clang_tu_decl (NULL),
458 m_data_debug_abbrev (),
459 m_data_debug_aranges (),
460 m_data_debug_frame (),
461 m_data_debug_info (),
462 m_data_debug_line (),
464 m_data_debug_ranges (),
466 m_data_apple_names (),
467 m_data_apple_types (),
468 m_data_apple_namespaces (),
474 m_apple_namespaces_ap (),
476 m_function_basename_index(),
477 m_function_fullname_index(),
478 m_function_method_index(),
479 m_function_selector_index(),
480 m_objc_class_selectors_index(),
485 m_is_external_ast_source (false),
486 m_using_apple_tables (false),
487 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
489 m_unique_ast_type_map ()
493 SymbolFileDWARF::~SymbolFileDWARF()
495 if (m_is_external_ast_source)
497 ModuleSP module_sp (m_obj_file->GetModule());
499 module_sp->GetClangASTContext().RemoveExternalSource ();
503 static const ConstString &
504 GetDWARFMachOSegmentName ()
506 static ConstString g_dwarf_section_name ("__DWARF");
507 return g_dwarf_section_name;
510 UniqueDWARFASTTypeMap &
511 SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
513 if (GetDebugMapSymfile ())
514 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
515 return m_unique_ast_type_map;
519 SymbolFileDWARF::GetClangASTContext ()
521 if (GetDebugMapSymfile ())
522 return m_debug_map_symfile->GetClangASTContext ();
524 ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
525 if (!m_is_external_ast_source)
527 m_is_external_ast_source = true;
528 llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
529 new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
530 SymbolFileDWARF::CompleteObjCInterfaceDecl,
531 SymbolFileDWARF::FindExternalVisibleDeclsByName,
532 SymbolFileDWARF::LayoutRecordType,
534 ast.SetExternalSource (ast_source_ap);
540 SymbolFileDWARF::InitializeObject()
542 // Install our external AST source callbacks so we can complete Clang types.
543 ModuleSP module_sp (m_obj_file->GetModule());
546 const SectionList *section_list = module_sp->GetSectionList();
548 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
550 // Memory map the DWARF mach-o segment so we have everything mmap'ed
551 // to keep our heap memory usage down.
553 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
555 get_apple_names_data();
556 if (m_data_apple_names.GetByteSize() > 0)
558 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
559 if (m_apple_names_ap->IsValid())
560 m_using_apple_tables = true;
562 m_apple_names_ap.reset();
564 get_apple_types_data();
565 if (m_data_apple_types.GetByteSize() > 0)
567 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
568 if (m_apple_types_ap->IsValid())
569 m_using_apple_tables = true;
571 m_apple_types_ap.reset();
574 get_apple_namespaces_data();
575 if (m_data_apple_namespaces.GetByteSize() > 0)
577 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
578 if (m_apple_namespaces_ap->IsValid())
579 m_using_apple_tables = true;
581 m_apple_namespaces_ap.reset();
584 get_apple_objc_data();
585 if (m_data_apple_objc.GetByteSize() > 0)
587 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
588 if (m_apple_objc_ap->IsValid())
589 m_using_apple_tables = true;
591 m_apple_objc_ap.reset();
596 SymbolFileDWARF::SupportedVersion(uint16_t version)
598 return version == 2 || version == 3 || version == 4;
602 SymbolFileDWARF::CalculateAbilities ()
604 uint32_t abilities = 0;
605 if (m_obj_file != NULL)
607 const Section* section = NULL;
608 const SectionList *section_list = m_obj_file->GetSectionList();
609 if (section_list == NULL)
612 uint64_t debug_abbrev_file_size = 0;
613 uint64_t debug_info_file_size = 0;
614 uint64_t debug_line_file_size = 0;
616 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
619 section_list = §ion->GetChildren ();
621 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
624 debug_info_file_size = section->GetFileSize();
626 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
628 debug_abbrev_file_size = section->GetFileSize();
630 m_flags.Set (flagsGotDebugAbbrevData);
632 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
634 m_flags.Set (flagsGotDebugArangesData);
636 section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
638 m_flags.Set (flagsGotDebugFrameData);
640 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
642 debug_line_file_size = section->GetFileSize();
644 m_flags.Set (flagsGotDebugLineData);
646 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
648 m_flags.Set (flagsGotDebugLocData);
650 section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
652 m_flags.Set (flagsGotDebugMacInfoData);
654 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
656 m_flags.Set (flagsGotDebugPubNamesData);
658 section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
660 m_flags.Set (flagsGotDebugPubTypesData);
662 section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
664 m_flags.Set (flagsGotDebugRangesData);
666 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
668 m_flags.Set (flagsGotDebugStrData);
672 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
673 if (symfile_dir_cstr)
675 if (strcasestr(symfile_dir_cstr, ".dsym"))
677 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
679 // We have a dSYM file that didn't have a any debug info.
680 // If the string table has a size of 1, then it was made from
681 // an executable with no debug info, or from an executable that
683 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
684 if (section && section->GetFileSize() == 1)
686 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
693 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
694 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
696 if (debug_line_file_size > 0)
697 abilities |= LineTables;
702 const DWARFDataExtractor&
703 SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DWARFDataExtractor &data)
705 if (m_flags.IsClear (got_flag))
707 ModuleSP module_sp (m_obj_file->GetModule());
708 m_flags.Set (got_flag);
709 const SectionList *section_list = module_sp->GetSectionList();
712 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
715 // See if we memory mapped the DWARF segment?
716 if (m_dwarf_data.GetByteSize())
718 data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
722 if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
731 const DWARFDataExtractor&
732 SymbolFileDWARF::get_debug_abbrev_data()
734 return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
737 const DWARFDataExtractor&
738 SymbolFileDWARF::get_debug_aranges_data()
740 return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
743 const DWARFDataExtractor&
744 SymbolFileDWARF::get_debug_frame_data()
746 return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
749 const DWARFDataExtractor&
750 SymbolFileDWARF::get_debug_info_data()
752 return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
755 const DWARFDataExtractor&
756 SymbolFileDWARF::get_debug_line_data()
758 return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
761 const DWARFDataExtractor&
762 SymbolFileDWARF::get_debug_loc_data()
764 return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
767 const DWARFDataExtractor&
768 SymbolFileDWARF::get_debug_ranges_data()
770 return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
773 const DWARFDataExtractor&
774 SymbolFileDWARF::get_debug_str_data()
776 return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
779 const DWARFDataExtractor&
780 SymbolFileDWARF::get_apple_names_data()
782 return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
785 const DWARFDataExtractor&
786 SymbolFileDWARF::get_apple_types_data()
788 return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
791 const DWARFDataExtractor&
792 SymbolFileDWARF::get_apple_namespaces_data()
794 return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
797 const DWARFDataExtractor&
798 SymbolFileDWARF::get_apple_objc_data()
800 return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
805 SymbolFileDWARF::DebugAbbrev()
807 if (m_abbr.get() == NULL)
809 const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data();
810 if (debug_abbrev_data.GetByteSize() > 0)
812 m_abbr.reset(new DWARFDebugAbbrev());
814 m_abbr->Parse(debug_abbrev_data);
820 const DWARFDebugAbbrev*
821 SymbolFileDWARF::DebugAbbrev() const
828 SymbolFileDWARF::DebugInfo()
830 if (m_info.get() == NULL)
832 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
833 if (get_debug_info_data().GetByteSize() > 0)
835 m_info.reset(new DWARFDebugInfo());
838 m_info->SetDwarfData(this);
845 const DWARFDebugInfo*
846 SymbolFileDWARF::DebugInfo() const
852 SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
854 DWARFDebugInfo* info = DebugInfo();
857 if (GetDebugMapSymfile ())
859 // The debug map symbol file made the compile units for this DWARF
860 // file which is .o file with DWARF in it, and we should have
861 // only 1 compile unit which is at offset zero in the DWARF.
862 // TODO: modify to support LTO .o files where each .o file might
863 // have multiple DW_TAG_compile_unit tags.
864 return info->GetCompileUnit(0).get();
868 // Just a normal DWARF file whose user ID for the compile unit is
869 // the DWARF offset itself
870 return info->GetCompileUnit((dw_offset_t)comp_unit->GetID()).get();
878 SymbolFileDWARF::DebugRanges()
880 if (m_ranges.get() == NULL)
882 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
883 if (get_debug_ranges_data().GetByteSize() > 0)
885 m_ranges.reset(new DWARFDebugRanges());
887 m_ranges->Extract(this);
890 return m_ranges.get();
893 const DWARFDebugRanges*
894 SymbolFileDWARF::DebugRanges() const
896 return m_ranges.get();
900 SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
905 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
908 // We already parsed this compile unit, had out a shared pointer to it
909 cu_sp = comp_unit->shared_from_this();
913 if (GetDebugMapSymfile ())
915 // Let the debug map create the compile unit
916 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
917 dwarf_cu->SetUserData(cu_sp.get());
921 ModuleSP module_sp (m_obj_file->GetModule());
924 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
927 const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
928 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
929 LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
932 std::string ramapped_file;
933 FileSpec cu_file_spec;
935 if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
937 // If we have a full path to the compile unit, we don't need to resolve
938 // the file. This can be expensive e.g. when the source files are NFS mounted.
939 if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
940 cu_file_spec.SetFile (ramapped_file.c_str(), false);
942 cu_file_spec.SetFile (cu_die_name, false);
946 std::string fullpath(cu_comp_dir);
947 if (*fullpath.rbegin() != '/')
949 fullpath += cu_die_name;
950 if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
951 cu_file_spec.SetFile (ramapped_file.c_str(), false);
953 cu_file_spec.SetFile (fullpath.c_str(), false);
956 cu_sp.reset(new CompileUnit (module_sp,
959 MakeUserID(dwarf_cu->GetOffset()),
963 dwarf_cu->SetUserData(cu_sp.get());
965 // Figure out the compile unit index if we weren't given one
966 if (cu_idx == UINT32_MAX)
967 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
969 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
981 SymbolFileDWARF::GetNumCompileUnits()
983 DWARFDebugInfo* info = DebugInfo();
985 return info->GetNumCompileUnits();
990 SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
993 DWARFDebugInfo* info = DebugInfo();
996 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
998 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
1004 AddRangesToBlock (Block& block,
1005 DWARFDebugRanges::RangeList& ranges,
1006 addr_t block_base_addr)
1008 const size_t num_ranges = ranges.GetSize();
1009 for (size_t i = 0; i<num_ranges; ++i)
1011 const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
1012 const addr_t range_base = range.GetRangeBase();
1013 assert (range_base >= block_base_addr);
1014 block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
1016 block.FinalizeRanges ();
1021 SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
1023 DWARFDebugRanges::RangeList func_ranges;
1024 const char *name = NULL;
1025 const char *mangled = NULL;
1028 int decl_column = 0;
1031 int call_column = 0;
1032 DWARFExpression frame_base;
1034 assert (die->Tag() == DW_TAG_subprogram);
1036 if (die->Tag() != DW_TAG_subprogram)
1039 if (die->GetDIENamesAndRanges (this,
1052 // Union of all ranges in the function DIE (if the function is discontiguous)
1053 AddressRange func_range;
1054 lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
1055 lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
1056 if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
1058 ModuleSP module_sp (m_obj_file->GetModule());
1059 func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, module_sp->GetSectionList());
1060 if (func_range.GetBaseAddress().IsValid())
1061 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
1064 if (func_range.GetBaseAddress().IsValid())
1068 func_name.SetValue(ConstString(mangled), true);
1070 func_name.SetValue(ConstString(name), false);
1073 std::unique_ptr<Declaration> decl_ap;
1074 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
1075 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1079 // Supply the type _only_ if it has already been parsed
1080 Type *func_type = m_die_to_type.lookup (die);
1082 assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
1084 if (FixupAddress (func_range.GetBaseAddress()))
1086 const user_id_t func_user_id = MakeUserID(die->GetOffset());
1087 func_sp.reset(new Function (sc.comp_unit,
1088 MakeUserID(func_user_id), // UserID is the DIE offset
1089 MakeUserID(func_user_id),
1092 func_range)); // first address range
1094 if (func_sp.get() != NULL)
1096 if (frame_base.IsValid())
1097 func_sp->GetFrameBaseExpression() = frame_base;
1098 sc.comp_unit->AddFunction(func_sp);
1099 return func_sp.get();
1108 SymbolFileDWARF::FixupAddress (Address &addr)
1110 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
1111 if (debug_map_symfile)
1113 return debug_map_symfile->LinkOSOAddress(addr);
1115 // This is a normal DWARF file, no address fixups need to happen
1119 SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
1121 assert (sc.comp_unit);
1122 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1125 const DWARFDebugInfoEntry *die = dwarf_cu->GetCompileUnitDIEOnly();
1128 const uint32_t language = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
1130 return (lldb::LanguageType)language;
1133 return eLanguageTypeUnknown;
1137 SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1139 assert (sc.comp_unit);
1140 size_t functions_added = 0;
1141 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1144 DWARFDIECollection function_dies;
1145 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
1147 for (func_idx = 0; func_idx < num_functions; ++func_idx)
1149 const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
1150 if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
1152 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
1158 return functions_added;
1162 SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1164 assert (sc.comp_unit);
1165 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1168 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
1172 const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
1173 dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1175 // All file indexes in DWARF are one based and a file of index zero is
1176 // supposed to be the compile unit itself.
1177 support_files.Append (*sc.comp_unit);
1179 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
1185 struct ParseDWARFLineTableCallbackInfo
1187 LineTable* line_table;
1188 std::unique_ptr<LineSequence> sequence_ap;
1191 //----------------------------------------------------------------------
1192 // ParseStatementTableCallback
1193 //----------------------------------------------------------------------
1195 ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1197 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1199 // Just started parsing the line table
1201 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1203 // Done parsing line table, nothing to do for the cleanup
1207 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
1208 LineTable* line_table = info->line_table;
1210 // If this is our first time here, we need to create a
1211 // sequence container.
1212 if (!info->sequence_ap.get())
1214 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1215 assert(info->sequence_ap.get());
1217 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1225 state.epilogue_begin,
1226 state.end_sequence);
1227 if (state.end_sequence)
1229 // First, put the current sequence into the line table.
1230 line_table->InsertSequence(info->sequence_ap.get());
1231 // Then, empty it to prepare for the next sequence.
1232 info->sequence_ap->Clear();
1238 SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1240 assert (sc.comp_unit);
1241 if (sc.comp_unit->GetLineTable() != NULL)
1244 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1247 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
1250 const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1251 if (cu_line_offset != DW_INVALID_OFFSET)
1253 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1254 if (line_table_ap.get())
1256 ParseDWARFLineTableCallbackInfo info;
1257 info.line_table = line_table_ap.get();
1258 lldb::offset_t offset = cu_line_offset;
1259 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1260 if (m_debug_map_symfile)
1262 // We have an object file that has a line table with addresses
1263 // that are not linked. We need to link the line table and convert
1264 // the addresses that are relative to the .o file into addresses
1265 // for the main executable.
1266 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1270 sc.comp_unit->SetLineTable(line_table_ap.release());
1281 SymbolFileDWARF::ParseFunctionBlocks
1283 const SymbolContext& sc,
1284 Block *parent_block,
1285 DWARFCompileUnit* dwarf_cu,
1286 const DWARFDebugInfoEntry *die,
1287 addr_t subprogram_low_pc,
1291 size_t blocks_added = 0;
1294 dw_tag_t tag = die->Tag();
1298 case DW_TAG_inlined_subroutine:
1299 case DW_TAG_subprogram:
1300 case DW_TAG_lexical_block:
1302 Block *block = NULL;
1303 if (tag == DW_TAG_subprogram)
1305 // Skip any DW_TAG_subprogram DIEs that are inside
1306 // of a normal or inlined functions. These will be
1307 // parsed on their own as separate entities.
1312 block = parent_block;
1316 BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
1317 parent_block->AddChild(block_sp);
1318 block = block_sp.get();
1320 DWARFDebugRanges::RangeList ranges;
1321 const char *name = NULL;
1322 const char *mangled_name = NULL;
1326 int decl_column = 0;
1329 int call_column = 0;
1330 if (die->GetDIENamesAndRanges (this,
1335 decl_file, decl_line, decl_column,
1336 call_file, call_line, call_column))
1338 if (tag == DW_TAG_subprogram)
1340 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
1341 subprogram_low_pc = ranges.GetMinRangeBase(0);
1343 else if (tag == DW_TAG_inlined_subroutine)
1345 // We get called here for inlined subroutines in two ways.
1346 // The first time is when we are making the Function object
1347 // for this inlined concrete instance. Since we're creating a top level block at
1348 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1349 // adjust the containing address.
1350 // The second time is when we are parsing the blocks inside the function that contains
1351 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1352 // function the offset will be for that function.
1353 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1355 subprogram_low_pc = ranges.GetMinRangeBase(0);
1359 AddRangesToBlock (*block, ranges, subprogram_low_pc);
1361 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1363 std::unique_ptr<Declaration> decl_ap;
1364 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
1365 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1366 decl_line, decl_column));
1368 std::unique_ptr<Declaration> call_ap;
1369 if (call_file != 0 || call_line != 0 || call_column != 0)
1370 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1371 call_line, call_column));
1373 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
1378 if (die->HasChildren())
1380 blocks_added += ParseFunctionBlocks (sc,
1383 die->GetFirstChild(),
1394 // Only parse siblings of the block if we are not at depth zero. A depth
1395 // of zero indicates we are currently parsing the top level
1396 // DW_TAG_subprogram DIE
1401 die = die->GetSibling();
1403 return blocks_added;
1407 SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1408 const DWARFDebugInfoEntry *die,
1409 ClangASTContext::TemplateParameterInfos &template_param_infos)
1411 const dw_tag_t tag = die->Tag();
1415 case DW_TAG_template_type_parameter:
1416 case DW_TAG_template_value_parameter:
1418 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1420 DWARFDebugInfoEntry::Attributes attributes;
1421 const size_t num_attributes = die->GetAttributes (this,
1425 const char *name = NULL;
1426 Type *lldb_type = NULL;
1427 ClangASTType clang_type;
1428 uint64_t uval64 = 0;
1429 bool uval64_valid = false;
1430 if (num_attributes > 0)
1432 DWARFFormValue form_value;
1433 for (size_t i=0; i<num_attributes; ++i)
1435 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1440 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1441 name = form_value.AsCString(&get_debug_str_data());
1445 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1447 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1448 lldb_type = ResolveTypeUID(type_die_offset);
1450 clang_type = lldb_type->GetClangForwardType();
1454 case DW_AT_const_value:
1455 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1457 uval64_valid = true;
1458 uval64 = form_value.Unsigned();
1466 clang::ASTContext *ast = GetClangASTContext().getASTContext();
1468 clang_type = GetClangASTContext().GetBasicType(eBasicTypeVoid);
1472 bool is_signed = false;
1473 if (name && name[0])
1474 template_param_infos.names.push_back(name);
1476 template_param_infos.names.push_back(NULL);
1478 if (tag == DW_TAG_template_value_parameter &&
1479 lldb_type != NULL &&
1480 clang_type.IsIntegerType (is_signed) &&
1483 llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
1484 template_param_infos.args.push_back (clang::TemplateArgument (*ast,
1485 llvm::APSInt(apint),
1486 clang_type.GetQualType()));
1490 template_param_infos.args.push_back (clang::TemplateArgument (clang_type.GetQualType()));
1509 SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1510 const DWARFDebugInfoEntry *parent_die,
1511 ClangASTContext::TemplateParameterInfos &template_param_infos)
1514 if (parent_die == NULL)
1517 Args template_parameter_names;
1518 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1520 die = die->GetSibling())
1522 const dw_tag_t tag = die->Tag();
1526 case DW_TAG_template_type_parameter:
1527 case DW_TAG_template_value_parameter:
1528 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
1535 if (template_param_infos.args.empty())
1537 return template_param_infos.args.size() == template_param_infos.names.size();
1540 clang::ClassTemplateDecl *
1541 SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
1542 lldb::AccessType access_type,
1543 const char *parent_name,
1545 const ClangASTContext::TemplateParameterInfos &template_param_infos)
1547 if (template_param_infos.IsValid())
1549 std::string template_basename(parent_name);
1550 template_basename.erase (template_basename.find('<'));
1551 ClangASTContext &ast = GetClangASTContext();
1553 return ast.CreateClassTemplateDecl (decl_ctx,
1555 template_basename.c_str(),
1557 template_param_infos);
1562 class SymbolFileDWARF::DelayedAddObjCClassProperty
1565 DelayedAddObjCClassProperty
1567 const ClangASTType &class_opaque_type,
1568 const char *property_name,
1569 const ClangASTType &property_opaque_type, // The property type is only required if you don't have an ivar decl
1570 clang::ObjCIvarDecl *ivar_decl,
1571 const char *property_setter_name,
1572 const char *property_getter_name,
1573 uint32_t property_attributes,
1574 const ClangASTMetadata *metadata
1576 m_class_opaque_type (class_opaque_type),
1577 m_property_name (property_name),
1578 m_property_opaque_type (property_opaque_type),
1579 m_ivar_decl (ivar_decl),
1580 m_property_setter_name (property_setter_name),
1581 m_property_getter_name (property_getter_name),
1582 m_property_attributes (property_attributes)
1584 if (metadata != NULL)
1586 m_metadata_ap.reset(new ClangASTMetadata());
1587 *m_metadata_ap = *metadata;
1591 DelayedAddObjCClassProperty (const DelayedAddObjCClassProperty &rhs)
1596 DelayedAddObjCClassProperty& operator= (const DelayedAddObjCClassProperty &rhs)
1598 m_class_opaque_type = rhs.m_class_opaque_type;
1599 m_property_name = rhs.m_property_name;
1600 m_property_opaque_type = rhs.m_property_opaque_type;
1601 m_ivar_decl = rhs.m_ivar_decl;
1602 m_property_setter_name = rhs.m_property_setter_name;
1603 m_property_getter_name = rhs.m_property_getter_name;
1604 m_property_attributes = rhs.m_property_attributes;
1606 if (rhs.m_metadata_ap.get())
1608 m_metadata_ap.reset (new ClangASTMetadata());
1609 *m_metadata_ap = *rhs.m_metadata_ap;
1617 return m_class_opaque_type.AddObjCClassProperty (m_property_name,
1618 m_property_opaque_type,
1620 m_property_setter_name,
1621 m_property_getter_name,
1622 m_property_attributes,
1623 m_metadata_ap.get());
1626 ClangASTType m_class_opaque_type;
1627 const char *m_property_name;
1628 ClangASTType m_property_opaque_type;
1629 clang::ObjCIvarDecl *m_ivar_decl;
1630 const char *m_property_setter_name;
1631 const char *m_property_getter_name;
1632 uint32_t m_property_attributes;
1633 std::unique_ptr<ClangASTMetadata> m_metadata_ap;
1639 uint64_t bit_offset;
1642 bit_size (LLDB_INVALID_ADDRESS),
1643 bit_offset (LLDB_INVALID_ADDRESS)
1650 bit_size = LLDB_INVALID_ADDRESS;
1651 bit_offset = LLDB_INVALID_ADDRESS;
1656 return (bit_size != LLDB_INVALID_ADDRESS) &&
1657 (bit_offset != LLDB_INVALID_ADDRESS);
1663 SymbolFileDWARF::ClassOrStructIsVirtual (DWARFCompileUnit* dwarf_cu,
1664 const DWARFDebugInfoEntry *parent_die)
1668 for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1670 dw_tag_t tag = die->Tag();
1671 bool check_virtuality = false;
1674 case DW_TAG_inheritance:
1675 case DW_TAG_subprogram:
1676 check_virtuality = true;
1681 if (check_virtuality)
1683 if (die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_virtuality, 0) != 0)
1692 SymbolFileDWARF::ParseChildMembers
1694 const SymbolContext& sc,
1695 DWARFCompileUnit* dwarf_cu,
1696 const DWARFDebugInfoEntry *parent_die,
1697 ClangASTType &class_clang_type,
1698 const LanguageType class_language,
1699 std::vector<clang::CXXBaseSpecifier *>& base_classes,
1700 std::vector<int>& member_accessibilities,
1701 DWARFDIECollection& member_function_dies,
1702 DelayedPropertyList& delayed_properties,
1703 AccessType& default_accessibility,
1705 LayoutInfo &layout_info
1708 if (parent_die == NULL)
1712 const DWARFDebugInfoEntry *die;
1713 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1714 uint32_t member_idx = 0;
1715 BitfieldInfo last_field_info;
1716 ModuleSP module = GetObjectFile()->GetModule();
1718 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1720 dw_tag_t tag = die->Tag();
1725 case DW_TAG_APPLE_property:
1727 DWARFDebugInfoEntry::Attributes attributes;
1728 const size_t num_attributes = die->GetAttributes (this,
1732 if (num_attributes > 0)
1735 //DWARFExpression location;
1736 const char *name = NULL;
1737 const char *prop_name = NULL;
1738 const char *prop_getter_name = NULL;
1739 const char *prop_setter_name = NULL;
1740 uint32_t prop_attributes = 0;
1743 bool is_artificial = false;
1744 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
1745 AccessType accessibility = eAccessNone;
1746 uint32_t member_byte_offset = UINT32_MAX;
1747 size_t byte_size = 0;
1748 size_t bit_offset = 0;
1749 size_t bit_size = 0;
1750 bool is_external = false; // On DW_TAG_members, this means the member is static
1752 for (i=0; i<num_attributes && !is_artificial; ++i)
1754 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1755 DWARFFormValue form_value;
1756 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1760 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1761 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
1762 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1763 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
1764 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
1765 case DW_AT_bit_offset: bit_offset = form_value.Unsigned(); break;
1766 case DW_AT_bit_size: bit_size = form_value.Unsigned(); break;
1767 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
1768 case DW_AT_data_member_location:
1769 if (form_value.BlockData())
1771 Value initialValue(0);
1772 Value memberOffset(0);
1773 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
1774 uint32_t block_length = form_value.Unsigned();
1775 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1776 if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1777 NULL, // ClangExpressionVariableList *
1778 NULL, // ClangExpressionDeclMap *
1779 NULL, // RegisterContext *
1789 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
1794 // With DWARF 3 and later, if the value is an integer constant,
1795 // this form value is the offset in bytes from the beginning
1796 // of the containing entity.
1797 member_byte_offset = form_value.Unsigned();
1801 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
1802 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
1803 case DW_AT_APPLE_property_name: prop_name = form_value.AsCString(&get_debug_str_data()); break;
1804 case DW_AT_APPLE_property_getter: prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1805 case DW_AT_APPLE_property_setter: prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1806 case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
1807 case DW_AT_external: is_external = form_value.Boolean(); break;
1810 case DW_AT_declaration:
1811 case DW_AT_description:
1813 case DW_AT_visibility:
1822 ConstString fixed_getter;
1823 ConstString fixed_setter;
1825 // Check if the property getter/setter were provided as full
1826 // names. We want basenames, so we extract them.
1828 if (prop_getter_name && prop_getter_name[0] == '-')
1830 ObjCLanguageRuntime::MethodName prop_getter_method(prop_getter_name, true);
1831 prop_getter_name = prop_getter_method.GetSelector().GetCString();
1834 if (prop_setter_name && prop_setter_name[0] == '-')
1836 ObjCLanguageRuntime::MethodName prop_setter_method(prop_setter_name, true);
1837 prop_setter_name = prop_setter_method.GetSelector().GetCString();
1840 // If the names haven't been provided, they need to be
1843 if (!prop_getter_name)
1845 prop_getter_name = prop_name;
1847 if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1851 ss.Printf("set%c%s:",
1852 toupper(prop_name[0]),
1855 fixed_setter.SetCString(ss.GetData());
1856 prop_setter_name = fixed_setter.GetCString();
1860 // Clang has a DWARF generation bug where sometimes it
1861 // represents fields that are references with bad byte size
1862 // and bit size/offset information such as:
1864 // DW_AT_byte_size( 0x00 )
1865 // DW_AT_bit_size( 0x40 )
1866 // DW_AT_bit_offset( 0xffffffffffffffc0 )
1868 // So check the bit offset to make sure it is sane, and if
1869 // the values are not sane, remove them. If we don't do this
1870 // then we will end up with a crash if we try to use this
1871 // type in an expression when clang becomes unhappy with its
1872 // recycled debug info.
1874 if (bit_offset > 128)
1880 // FIXME: Make Clang ignore Objective-C accessibility for expressions
1881 if (class_language == eLanguageTypeObjC ||
1882 class_language == eLanguageTypeObjC_plus_plus)
1883 accessibility = eAccessNone;
1885 if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1887 // Not all compilers will mark the vtable pointer
1888 // member as artificial (llvm-gcc). We can't have
1889 // the virtual members in our classes otherwise it
1890 // throws off all child offsets since we end up
1891 // having and extra pointer sized member in our
1893 is_artificial = true;
1896 // Handle static members
1897 if (is_external && member_byte_offset == UINT32_MAX)
1899 Type *var_type = ResolveTypeUID(encoding_uid);
1903 if (accessibility == eAccessNone)
1904 accessibility = eAccessPublic;
1905 class_clang_type.AddVariableToRecordType (name,
1906 var_type->GetClangLayoutType(),
1912 if (is_artificial == false)
1914 Type *member_type = ResolveTypeUID(encoding_uid);
1916 clang::FieldDecl *field_decl = NULL;
1917 if (tag == DW_TAG_member)
1921 if (accessibility == eAccessNone)
1922 accessibility = default_accessibility;
1923 member_accessibilities.push_back(accessibility);
1925 uint64_t field_bit_offset = (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1929 BitfieldInfo this_field_info;
1930 this_field_info.bit_offset = field_bit_offset;
1931 this_field_info.bit_size = bit_size;
1933 /////////////////////////////////////////////////////////////
1934 // How to locate a field given the DWARF debug information
1936 // AT_byte_size indicates the size of the word in which the
1937 // bit offset must be interpreted.
1939 // AT_data_member_location indicates the byte offset of the
1940 // word from the base address of the structure.
1942 // AT_bit_offset indicates how many bits into the word
1943 // (according to the host endianness) the low-order bit of
1944 // the field starts. AT_bit_offset can be negative.
1946 // AT_bit_size indicates the size of the field in bits.
1947 /////////////////////////////////////////////////////////////
1950 byte_size = member_type->GetByteSize();
1952 if (GetObjectFile()->GetByteOrder() == eByteOrderLittle)
1954 this_field_info.bit_offset += byte_size * 8;
1955 this_field_info.bit_offset -= (bit_offset + bit_size);
1959 this_field_info.bit_offset += bit_offset;
1962 // Update the field bit offset we will report for layout
1963 field_bit_offset = this_field_info.bit_offset;
1965 // If the member to be emitted did not start on a character boundary and there is
1966 // empty space between the last field and this one, then we need to emit an
1967 // anonymous member filling up the space up to its start. There are three cases
1970 // 1 If the previous member ended on a character boundary, then we can emit an
1971 // anonymous member starting at the most recent character boundary.
1973 // 2 If the previous member did not end on a character boundary and the distance
1974 // from the end of the previous member to the current member is less than a
1975 // word width, then we can emit an anonymous member starting right after the
1976 // previous member and right before this member.
1978 // 3 If the previous member did not end on a character boundary and the distance
1979 // from the end of the previous member to the current member is greater than
1980 // or equal a word width, then we act as in Case 1.
1982 const uint64_t character_width = 8;
1983 const uint64_t word_width = 32;
1985 // Objective-C has invalid DW_AT_bit_offset values in older versions
1986 // of clang, so we have to be careful and only insert unnammed bitfields
1987 // if we have a new enough clang.
1988 bool detect_unnamed_bitfields = true;
1990 if (class_language == eLanguageTypeObjC || class_language == eLanguageTypeObjC_plus_plus)
1991 detect_unnamed_bitfields = dwarf_cu->Supports_unnamed_objc_bitfields ();
1993 if (detect_unnamed_bitfields)
1995 BitfieldInfo anon_field_info;
1997 if ((this_field_info.bit_offset % character_width) != 0) // not char aligned
1999 uint64_t last_field_end = 0;
2001 if (last_field_info.IsValid())
2002 last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
2004 if (this_field_info.bit_offset != last_field_end)
2006 if (((last_field_end % character_width) == 0) || // case 1
2007 (this_field_info.bit_offset - last_field_end >= word_width)) // case 3
2009 anon_field_info.bit_size = this_field_info.bit_offset % character_width;
2010 anon_field_info.bit_offset = this_field_info.bit_offset - anon_field_info.bit_size;
2014 anon_field_info.bit_size = this_field_info.bit_offset - last_field_end;
2015 anon_field_info.bit_offset = last_field_end;
2020 if (anon_field_info.IsValid())
2022 clang::FieldDecl *unnamed_bitfield_decl = class_clang_type.AddFieldToRecordType (NULL,
2023 GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
2025 anon_field_info.bit_size);
2027 layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset));
2030 last_field_info = this_field_info;
2034 last_field_info.Clear();
2037 ClangASTType member_clang_type = member_type->GetClangLayoutType();
2040 // Older versions of clang emit array[0] and array[1] in the same way (<rdar://problem/12566646>).
2041 // If the current field is at the end of the structure, then there is definitely no room for extra
2042 // elements and we override the type to array[0].
2044 ClangASTType member_array_element_type;
2045 uint64_t member_array_size;
2046 bool member_array_is_incomplete;
2048 if (member_clang_type.IsArrayType(&member_array_element_type,
2050 &member_array_is_incomplete) &&
2051 !member_array_is_incomplete)
2053 uint64_t parent_byte_size = parent_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, UINT64_MAX);
2055 if (member_byte_offset >= parent_byte_size)
2057 if (member_array_size != 1)
2059 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which extends beyond the bounds of 0x%8.8" PRIx64,
2060 MakeUserID(die->GetOffset()),
2063 MakeUserID(parent_die->GetOffset()));
2066 member_clang_type = GetClangASTContext().CreateArrayType(member_array_element_type, 0, false);
2071 field_decl = class_clang_type.AddFieldToRecordType (name,
2076 GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset()));
2078 layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset));
2084 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64 " which was unable to be parsed",
2085 MakeUserID(die->GetOffset()),
2089 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8" PRIx64 " which was unable to be parsed",
2090 MakeUserID(die->GetOffset()),
2095 if (prop_name != NULL)
2097 clang::ObjCIvarDecl *ivar_decl = NULL;
2101 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
2102 assert (ivar_decl != NULL);
2105 ClangASTMetadata metadata;
2106 metadata.SetUserID (MakeUserID(die->GetOffset()));
2107 delayed_properties.push_back(DelayedAddObjCClassProperty(class_clang_type,
2109 member_type->GetClangLayoutType(),
2117 GetClangASTContext().SetMetadataAsUserID (ivar_decl, MakeUserID(die->GetOffset()));
2125 case DW_TAG_subprogram:
2126 // Let the type parsing code handle this one for us.
2127 member_function_dies.Append (die);
2130 case DW_TAG_inheritance:
2133 if (default_accessibility == eAccessNone)
2134 default_accessibility = eAccessPrivate;
2135 // TODO: implement DW_TAG_inheritance type parsing
2136 DWARFDebugInfoEntry::Attributes attributes;
2137 const size_t num_attributes = die->GetAttributes (this,
2141 if (num_attributes > 0)
2144 DWARFExpression location;
2145 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
2146 AccessType accessibility = default_accessibility;
2147 bool is_virtual = false;
2148 bool is_base_of_class = true;
2149 off_t member_byte_offset = 0;
2151 for (i=0; i<num_attributes; ++i)
2153 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2154 DWARFFormValue form_value;
2155 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
2159 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
2160 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
2161 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
2162 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
2163 case DW_AT_data_member_location:
2164 if (form_value.BlockData())
2166 Value initialValue(0);
2167 Value memberOffset(0);
2168 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
2169 uint32_t block_length = form_value.Unsigned();
2170 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
2171 if (DWARFExpression::Evaluate (NULL,
2184 member_byte_offset = memberOffset.ResolveValue(NULL).UInt();
2189 // With DWARF 3 and later, if the value is an integer constant,
2190 // this form value is the offset in bytes from the beginning
2191 // of the containing entity.
2192 member_byte_offset = form_value.Unsigned();
2196 case DW_AT_accessibility:
2197 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
2200 case DW_AT_virtuality:
2201 is_virtual = form_value.Boolean();
2213 Type *base_class_type = ResolveTypeUID(encoding_uid);
2214 assert(base_class_type);
2216 ClangASTType base_class_clang_type = base_class_type->GetClangFullType();
2217 assert (base_class_clang_type);
2218 if (class_language == eLanguageTypeObjC)
2220 class_clang_type.SetObjCSuperClass(base_class_clang_type);
2224 base_classes.push_back (base_class_clang_type.CreateBaseClassSpecifier (accessibility,
2230 // Do not specify any offset for virtual inheritance. The DWARF produced by clang doesn't
2231 // give us a constant offset, but gives us a DWARF expressions that requires an actual object
2232 // in memory. the DW_AT_data_member_location for a virtual base class looks like:
2233 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, DW_OP_plus )
2234 // Given this, there is really no valid response we can give to clang for virtual base
2235 // class offsets, and this should eventually be removed from LayoutRecordType() in the external
2236 // AST source in clang.
2240 layout_info.base_offsets.insert(std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(),
2241 clang::CharUnits::fromQuantity(member_byte_offset)));
2258 SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
2260 DWARFDebugInfo* debug_info = DebugInfo();
2261 if (debug_info && UserIDMatches(type_uid))
2263 DWARFCompileUnitSP cu_sp;
2264 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2266 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
2272 SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
2274 if (UserIDMatches(type_uid))
2275 return GetClangDeclContextForDIEOffset (sc, type_uid);
2280 SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
2282 if (UserIDMatches(type_uid))
2284 DWARFDebugInfo* debug_info = DebugInfo();
2287 DWARFCompileUnitSP cu_sp;
2288 const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
2289 const bool assert_not_being_parsed = true;
2290 return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
2297 SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
2301 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
2303 GetObjectFile()->GetModule()->LogMessage (log,
2304 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
2306 DW_TAG_value_to_name(die->Tag()),
2307 die->GetName(this, cu));
2309 // We might be coming in in the middle of a type tree (a class
2310 // withing a class, an enum within a class), so parse any needed
2311 // parent DIEs before we get to this one...
2312 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2313 switch (decl_ctx_die->Tag())
2315 case DW_TAG_structure_type:
2316 case DW_TAG_union_type:
2317 case DW_TAG_class_type:
2319 // Get the type, which could be a forward declaration
2321 GetObjectFile()->GetModule()->LogMessage (log,
2322 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
2324 DW_TAG_value_to_name(die->Tag()),
2325 die->GetName(this, cu),
2326 decl_ctx_die->GetOffset());
2328 // Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
2329 // if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
2332 // GetObjectFile()->GetModule()->LogMessage (log,
2333 // "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
2334 // die->GetOffset(),
2335 // DW_TAG_value_to_name(die->Tag()),
2336 // die->GetName(this, cu),
2337 // decl_ctx_die->GetOffset());
2338 // // Ask the type to complete itself if it already hasn't since if we
2339 // // want a function (method or static) from a class, the class must
2340 // // create itself and add it's own methods and class functions.
2342 // parent_type->GetClangFullType();
2350 return ResolveType (cu, die);
2355 // This function is used when SymbolFileDWARFDebugMap owns a bunch of
2356 // SymbolFileDWARF objects to detect if this DWARF file is the one that
2357 // can resolve a clang_type.
2359 SymbolFileDWARF::HasForwardDeclForClangType (const ClangASTType &clang_type)
2361 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2362 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
2368 SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type)
2370 // We have a struct/union/class/enum that needs to be fully resolved.
2371 ClangASTType clang_type_no_qualifiers = clang_type.RemoveFastQualifiers();
2372 const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers.GetOpaqueQualType());
2375 // We have already resolved this type...
2378 // Once we start resolving this type, remove it from the forward declaration
2379 // map in case anyone child members or other types require this type to get resolved.
2380 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
2382 m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers.GetOpaqueQualType());
2385 // Disable external storage for this type so we don't get anymore
2386 // clang::ExternalASTSource queries for this type.
2387 clang_type.SetHasExternalStorage (false);
2389 DWARFDebugInfo* debug_info = DebugInfo();
2391 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
2392 Type *type = m_die_to_type.lookup (die);
2394 const dw_tag_t tag = die->Tag();
2396 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
2399 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
2400 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
2401 MakeUserID(die->GetOffset()),
2402 DW_TAG_value_to_name(tag),
2403 type->GetName().AsCString());
2406 assert (clang_type);
2407 DWARFDebugInfoEntry::Attributes attributes;
2411 case DW_TAG_structure_type:
2412 case DW_TAG_union_type:
2413 case DW_TAG_class_type:
2415 LayoutInfo layout_info;
2418 if (die->HasChildren())
2421 LanguageType class_language = eLanguageTypeUnknown;
2422 if (clang_type.IsObjCObjectOrInterfaceType())
2424 class_language = eLanguageTypeObjC;
2425 // For objective C we don't start the definition when
2426 // the class is created.
2427 clang_type.StartTagDeclarationDefinition ();
2430 int tag_decl_kind = -1;
2431 AccessType default_accessibility = eAccessNone;
2432 if (tag == DW_TAG_structure_type)
2434 tag_decl_kind = clang::TTK_Struct;
2435 default_accessibility = eAccessPublic;
2437 else if (tag == DW_TAG_union_type)
2439 tag_decl_kind = clang::TTK_Union;
2440 default_accessibility = eAccessPublic;
2442 else if (tag == DW_TAG_class_type)
2444 tag_decl_kind = clang::TTK_Class;
2445 default_accessibility = eAccessPrivate;
2448 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
2449 std::vector<clang::CXXBaseSpecifier *> base_classes;
2450 std::vector<int> member_accessibilities;
2451 bool is_a_class = false;
2452 // Parse members and base classes first
2453 DWARFDIECollection member_function_dies;
2455 DelayedPropertyList delayed_properties;
2456 ParseChildMembers (sc,
2462 member_accessibilities,
2463 member_function_dies,
2465 default_accessibility,
2469 // Now parse any methods if there were any...
2470 size_t num_functions = member_function_dies.Size();
2471 if (num_functions > 0)
2473 for (size_t i=0; i<num_functions; ++i)
2475 ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
2479 if (class_language == eLanguageTypeObjC)
2481 ConstString class_name (clang_type.GetTypeName());
2485 DIEArray method_die_offsets;
2486 if (m_using_apple_tables)
2488 if (m_apple_objc_ap.get())
2489 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
2496 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2499 if (!method_die_offsets.empty())
2501 DWARFDebugInfo* debug_info = DebugInfo();
2503 DWARFCompileUnit* method_cu = NULL;
2504 const size_t num_matches = method_die_offsets.size();
2505 for (size_t i=0; i<num_matches; ++i)
2507 const dw_offset_t die_offset = method_die_offsets[i];
2508 DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2511 ResolveType (method_cu, method_die);
2514 if (m_using_apple_tables)
2516 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2517 die_offset, class_name.GetCString());
2523 for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end();
2530 // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2531 // need to tell the clang type it is actually a class.
2532 if (class_language != eLanguageTypeObjC)
2534 if (is_a_class && tag_decl_kind != clang::TTK_Class)
2535 clang_type.SetTagTypeKind (clang::TTK_Class);
2538 // Since DW_TAG_structure_type gets used for both classes
2539 // and structures, we may need to set any DW_TAG_member
2540 // fields to have a "private" access if none was specified.
2541 // When we parsed the child members we tracked that actual
2542 // accessibility value for each DW_TAG_member in the
2543 // "member_accessibilities" array. If the value for the
2544 // member is zero, then it was set to the "default_accessibility"
2545 // which for structs was "public". Below we correct this
2546 // by setting any fields to "private" that weren't correctly
2548 if (is_a_class && !member_accessibilities.empty())
2550 // This is a class and all members that didn't have
2551 // their access specified are private.
2552 clang_type.SetDefaultAccessForRecordFields (eAccessPrivate,
2553 &member_accessibilities.front(),
2554 member_accessibilities.size());
2557 if (!base_classes.empty())
2559 // Make sure all base classes refer to complete types and not
2560 // forward declarations. If we don't do this, clang will crash
2561 // with an assertion in the call to clang_type.SetBaseClassesForClassType()
2562 bool base_class_error = false;
2563 for (auto &base_class : base_classes)
2565 clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo();
2566 if (type_source_info)
2568 ClangASTType base_class_type (GetClangASTContext().getASTContext(), type_source_info->getType());
2569 if (base_class_type.GetCompleteType() == false)
2571 if (!base_class_error)
2573 GetObjectFile()->GetModule()->ReportError ("DWARF DIE at 0x%8.8x for class '%s' has a base class '%s' that is a forward declaration, not a complete definition.\nPlease file a bug against the compiler and include the preprocessed output for %s",
2575 die->GetName(this, dwarf_cu),
2576 base_class_type.GetTypeName().GetCString(),
2577 sc.comp_unit ? sc.comp_unit->GetPath().c_str() : "the source file");
2579 // We have no choice other than to pretend that the base class
2580 // is complete. If we don't do this, clang will crash when we
2581 // call setBases() inside of "clang_type.SetBaseClassesForClassType()"
2582 // below. Since we provide layout assistance, all ivars in this
2583 // class and other classe will be fine, this is the best we can do
2584 // short of crashing.
2585 base_class_type.StartTagDeclarationDefinition ();
2586 base_class_type.CompleteTagDeclarationDefinition ();
2590 clang_type.SetBaseClassesForClassType (&base_classes.front(),
2591 base_classes.size());
2593 // Clang will copy each CXXBaseSpecifier in "base_classes"
2594 // so we have to free them all.
2595 ClangASTType::DeleteBaseClassSpecifiers (&base_classes.front(),
2596 base_classes.size());
2601 clang_type.BuildIndirectFields ();
2602 clang_type.CompleteTagDeclarationDefinition ();
2604 if (!layout_info.field_offsets.empty() ||
2605 !layout_info.base_offsets.empty() ||
2606 !layout_info.vbase_offsets.empty() )
2609 layout_info.bit_size = type->GetByteSize() * 8;
2610 if (layout_info.bit_size == 0)
2611 layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
2613 clang::CXXRecordDecl *record_decl = clang_type.GetAsCXXRecordDecl();
2618 GetObjectFile()->GetModule()->LogMessage (log,
2619 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])",
2620 clang_type.GetOpaqueQualType(),
2622 layout_info.bit_size,
2623 layout_info.alignment,
2624 (uint32_t)layout_info.field_offsets.size(),
2625 (uint32_t)layout_info.base_offsets.size(),
2626 (uint32_t)layout_info.vbase_offsets.size());
2630 llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
2631 for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx)
2633 GetObjectFile()->GetModule()->LogMessage (log,
2634 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }",
2635 clang_type.GetOpaqueQualType(),
2637 (uint32_t)pos->second,
2638 pos->first->getNameAsString().c_str());
2643 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end();
2644 for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx)
2646 GetObjectFile()->GetModule()->LogMessage (log,
2647 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }",
2648 clang_type.GetOpaqueQualType(),
2650 (uint32_t)base_pos->second.getQuantity(),
2651 base_pos->first->getNameAsString().c_str());
2655 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end();
2656 for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx)
2658 GetObjectFile()->GetModule()->LogMessage (log,
2659 "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }",
2660 clang_type.GetOpaqueQualType(),
2662 (uint32_t)vbase_pos->second.getQuantity(),
2663 vbase_pos->first->getNameAsString().c_str());
2667 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2672 return (bool)clang_type;
2674 case DW_TAG_enumeration_type:
2675 clang_type.StartTagDeclarationDefinition ();
2676 if (die->HasChildren())
2678 SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
2679 bool is_signed = false;
2680 clang_type.IsIntegerType(is_signed);
2681 ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), dwarf_cu, die);
2683 clang_type.CompleteTagDeclarationDefinition ();
2684 return (bool)clang_type;
2687 assert(false && "not a forward clang type decl!");
2694 SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
2696 if (type_die != NULL)
2698 Type *type = m_die_to_type.lookup (type_die);
2701 type = GetTypeForDIE (dwarf_cu, type_die).get();
2703 if (assert_not_being_parsed)
2705 if (type != DIE_IS_BEING_PARSED)
2708 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
2709 type_die->GetOffset(),
2710 DW_TAG_value_to_name(type_die->Tag()),
2711 type_die->GetName(this, dwarf_cu));
2721 SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
2723 // Check if the symbol vendor already knows about this compile unit?
2724 if (dwarf_cu->GetUserData() == NULL)
2726 // The symbol vendor doesn't know about this compile unit, we
2727 // need to parse and add it to the symbol vendor object.
2728 return ParseCompileUnit(dwarf_cu, cu_idx).get();
2730 return (CompileUnit*)dwarf_cu->GetUserData();
2734 SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
2737 // Check if the symbol vendor already knows about this compile unit?
2738 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2740 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
2741 if (sc.function == NULL)
2742 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
2746 sc.module_sp = sc.function->CalculateSymbolContextModule();
2754 SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2756 Timer scoped_timer(__PRETTY_FUNCTION__,
2757 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
2758 so_addr.GetSection().get(),
2759 so_addr.GetOffset(),
2761 uint32_t resolved = 0;
2762 if (resolve_scope & ( eSymbolContextCompUnit |
2763 eSymbolContextFunction |
2764 eSymbolContextBlock |
2765 eSymbolContextLineEntry))
2767 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2769 DWARFDebugInfo* debug_info = DebugInfo();
2772 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
2773 if (cu_offset != DW_INVALID_OFFSET)
2775 uint32_t cu_idx = DW_INVALID_INDEX;
2776 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2779 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
2782 resolved |= eSymbolContextCompUnit;
2784 bool force_check_line_table = false;
2785 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2787 DWARFDebugInfoEntry *function_die = NULL;
2788 DWARFDebugInfoEntry *block_die = NULL;
2789 if (resolve_scope & eSymbolContextBlock)
2791 dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2795 dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2798 if (function_die != NULL)
2800 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2801 if (sc.function == NULL)
2802 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2806 // We might have had a compile unit that had discontiguous
2807 // address ranges where the gaps are symbols that don't have
2808 // any debug info. Discontiguous compile unit address ranges
2809 // should only happen when there aren't other functions from
2810 // other compile units in these gaps. This helps keep the size
2811 // of the aranges down.
2812 force_check_line_table = true;
2815 if (sc.function != NULL)
2817 resolved |= eSymbolContextFunction;
2819 if (resolve_scope & eSymbolContextBlock)
2821 Block& block = sc.function->GetBlock (true);
2823 if (block_die != NULL)
2824 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2826 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2828 resolved |= eSymbolContextBlock;
2833 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
2835 LineTable *line_table = sc.comp_unit->GetLineTable();
2836 if (line_table != NULL)
2838 // And address that makes it into this function should be in terms
2839 // of this debug file if there is no debug map, or it will be an
2840 // address in the .o file which needs to be fixed up to be in terms
2841 // of the debug map executable. Either way, calling FixupAddress()
2842 // will work for us.
2843 Address exe_so_addr (so_addr);
2844 if (FixupAddress(exe_so_addr))
2846 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
2848 resolved |= eSymbolContextLineEntry;
2854 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
2856 // We might have had a compile unit that had discontiguous
2857 // address ranges where the gaps are symbols that don't have
2858 // any debug info. Discontiguous compile unit address ranges
2859 // should only happen when there aren't other functions from
2860 // other compile units in these gaps. This helps keep the size
2861 // of the aranges down.
2862 sc.comp_unit = NULL;
2863 resolved &= ~eSymbolContextCompUnit;
2868 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
2882 SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2884 const uint32_t prev_size = sc_list.GetSize();
2885 if (resolve_scope & eSymbolContextCompUnit)
2887 DWARFDebugInfo* debug_info = DebugInfo();
2891 DWARFCompileUnit* dwarf_cu = NULL;
2893 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
2895 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
2896 const bool full_match = (bool)file_spec.GetDirectory();
2897 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Equal(file_spec, *dc_cu, full_match);
2898 if (check_inlines || file_spec_matches_cu_file_spec)
2900 SymbolContext sc (m_obj_file->GetModule());
2901 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
2904 uint32_t file_idx = UINT32_MAX;
2906 // If we are looking for inline functions only and we don't
2907 // find it in the support files, we are done.
2910 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2911 if (file_idx == UINT32_MAX)
2917 LineTable *line_table = sc.comp_unit->GetLineTable();
2919 if (line_table != NULL && line != 0)
2921 // We will have already looked up the file index if
2922 // we are searching for inline entries.
2924 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2926 if (file_idx != UINT32_MAX)
2928 uint32_t found_line;
2929 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2930 found_line = sc.line_entry.line;
2932 while (line_idx != UINT32_MAX)
2936 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2938 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2939 if (file_vm_addr != LLDB_INVALID_ADDRESS)
2941 DWARFDebugInfoEntry *function_die = NULL;
2942 DWARFDebugInfoEntry *block_die = NULL;
2943 dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
2945 if (function_die != NULL)
2947 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2948 if (sc.function == NULL)
2949 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2952 if (sc.function != NULL)
2954 Block& block = sc.function->GetBlock (true);
2956 if (block_die != NULL)
2957 sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2959 sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2965 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2969 else if (file_spec_matches_cu_file_spec && !check_inlines)
2971 // only append the context if we aren't looking for inline call sites
2972 // by file and line and if the file spec matches that of the compile unit
2976 else if (file_spec_matches_cu_file_spec && !check_inlines)
2978 // only append the context if we aren't looking for inline call sites
2979 // by file and line and if the file spec matches that of the compile unit
2990 return sc_list.GetSize() - prev_size;
2994 SymbolFileDWARF::Index ()
2999 Timer scoped_timer (__PRETTY_FUNCTION__,
3000 "SymbolFileDWARF::Index (%s)",
3001 GetObjectFile()->GetFileSpec().GetFilename().AsCString());
3003 DWARFDebugInfo* debug_info = DebugInfo();
3006 uint32_t cu_idx = 0;
3007 const uint32_t num_compile_units = GetNumCompileUnits();
3008 for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3010 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
3012 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
3014 dwarf_cu->Index (cu_idx,
3015 m_function_basename_index,
3016 m_function_fullname_index,
3017 m_function_method_index,
3018 m_function_selector_index,
3019 m_objc_class_selectors_index,
3024 // Keep memory down by clearing DIEs if this generate function
3025 // caused them to be parsed
3027 dwarf_cu->ClearDIEs (true);
3030 m_function_basename_index.Finalize();
3031 m_function_fullname_index.Finalize();
3032 m_function_method_index.Finalize();
3033 m_function_selector_index.Finalize();
3034 m_objc_class_selectors_index.Finalize();
3035 m_global_index.Finalize();
3036 m_type_index.Finalize();
3037 m_namespace_index.Finalize();
3039 #if defined (ENABLE_DEBUG_PRINTF)
3040 StreamFile s(stdout, false);
3041 s.Printf ("DWARF index for '%s':",
3042 GetObjectFile()->GetFileSpec().GetPath().c_str());
3043 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
3044 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
3045 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
3046 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
3047 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
3048 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
3049 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
3050 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
3056 SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
3058 if (namespace_decl == NULL)
3060 // Invalid namespace decl which means we aren't matching only things
3061 // in this symbol file, so return true to indicate it matches this
3066 clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
3068 if (namespace_ast == NULL)
3069 return true; // No AST in the "namespace_decl", return true since it
3070 // could then match any symbol file, including this one
3072 if (namespace_ast == GetClangASTContext().getASTContext())
3073 return true; // The ASTs match, return true
3075 // The namespace AST was valid, and it does not match...
3076 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3079 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
3085 SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
3086 DWARFCompileUnit* cu,
3087 const DWARFDebugInfoEntry* die)
3089 // No namespace specified, so the answesr i
3090 if (namespace_decl == NULL)
3093 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3095 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
3096 clang::DeclContext *die_clang_decl_ctx = GetClangDeclContextContainingDIE (cu, die, &decl_ctx_die);
3099 clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
3101 if (clang_namespace_decl)
3103 if (decl_ctx_die->Tag() != DW_TAG_namespace)
3106 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent is not a namespace");
3110 if (clang_namespace_decl == die_clang_decl_ctx)
3117 // We have a namespace_decl that was not NULL but it contained
3118 // a NULL "clang::NamespaceDecl", so this means the global namespace
3119 // So as long the the contained decl context DIE isn't a namespace
3121 if (decl_ctx_die->Tag() != DW_TAG_namespace)
3127 GetObjectFile()->GetModule()->LogMessage(log, "Found a match, but its parent doesn't exist");
3132 SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables)
3134 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3138 GetObjectFile()->GetModule()->LogMessage (log,
3139 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
3146 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3149 DWARFDebugInfo* info = DebugInfo();
3153 // If we aren't appending the results to this list, then clear the list
3157 // Remember how many variables are in the list before we search in case
3158 // we are appending the results to a variable list.
3159 const uint32_t original_size = variables.GetSize();
3161 DIEArray die_offsets;
3163 if (m_using_apple_tables)
3165 if (m_apple_names_ap.get())
3167 const char *name_cstr = name.GetCString();
3168 const char *base_name_start;
3169 const char *base_name_end = NULL;
3171 if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
3172 base_name_start = name_cstr;
3174 m_apple_names_ap->FindByName (base_name_start, die_offsets);
3179 // Index the DWARF if we haven't already
3183 m_global_index.Find (name, die_offsets);
3186 const size_t num_die_matches = die_offsets.size();
3187 if (num_die_matches)
3190 sc.module_sp = m_obj_file->GetModule();
3191 assert (sc.module_sp);
3193 DWARFDebugInfo* debug_info = DebugInfo();
3194 DWARFCompileUnit* dwarf_cu = NULL;
3195 const DWARFDebugInfoEntry* die = NULL;
3197 for (size_t i=0; i<num_die_matches && !done; ++i)
3199 const dw_offset_t die_offset = die_offsets[i];
3200 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3207 case DW_TAG_subprogram:
3208 case DW_TAG_inlined_subroutine:
3209 case DW_TAG_try_block:
3210 case DW_TAG_catch_block:
3213 case DW_TAG_variable:
3215 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3217 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3220 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
3222 if (variables.GetSize() - original_size >= max_matches)
3230 if (m_using_apple_tables)
3232 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
3233 die_offset, name.GetCString());
3239 // Return the number of variable that were appended to the list
3240 const uint32_t num_matches = variables.GetSize() - original_size;
3241 if (log && num_matches > 0)
3243 GetObjectFile()->GetModule()->LogMessage (log,
3244 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables) => %u",
3255 SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
3257 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3261 GetObjectFile()->GetModule()->LogMessage (log,
3262 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
3268 DWARFDebugInfo* info = DebugInfo();
3272 // If we aren't appending the results to this list, then clear the list
3276 // Remember how many variables are in the list before we search in case
3277 // we are appending the results to a variable list.
3278 const uint32_t original_size = variables.GetSize();
3280 DIEArray die_offsets;
3282 if (m_using_apple_tables)
3284 if (m_apple_names_ap.get())
3286 DWARFMappedHash::DIEInfoArray hash_data_array;
3287 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3288 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3293 // Index the DWARF if we haven't already
3297 m_global_index.Find (regex, die_offsets);
3301 sc.module_sp = m_obj_file->GetModule();
3302 assert (sc.module_sp);
3304 DWARFCompileUnit* dwarf_cu = NULL;
3305 const DWARFDebugInfoEntry* die = NULL;
3306 const size_t num_matches = die_offsets.size();
3309 DWARFDebugInfo* debug_info = DebugInfo();
3310 for (size_t i=0; i<num_matches; ++i)
3312 const dw_offset_t die_offset = die_offsets[i];
3313 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3317 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3319 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
3321 if (variables.GetSize() - original_size >= max_matches)
3326 if (m_using_apple_tables)
3328 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
3329 die_offset, regex.GetText());
3335 // Return the number of variable that were appended to the list
3336 return variables.GetSize() - original_size;
3341 SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
3342 DWARFCompileUnit *&dwarf_cu,
3343 SymbolContextList& sc_list)
3345 const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3346 return ResolveFunction (dwarf_cu, die, sc_list);
3351 SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
3352 const DWARFDebugInfoEntry *die,
3353 SymbolContextList& sc_list)
3360 // If we were passed a die that is not a function, just return false...
3361 if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
3364 const DWARFDebugInfoEntry* inlined_die = NULL;
3365 if (die->Tag() == DW_TAG_inlined_subroutine)
3369 while ((die = die->GetParent()) != NULL)
3371 if (die->Tag() == DW_TAG_subprogram)
3375 assert (die->Tag() == DW_TAG_subprogram);
3376 if (GetFunction (cu, die, sc))
3379 // Parse all blocks if needed
3382 sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
3383 assert (sc.block != NULL);
3384 if (sc.block->GetStartAddress (addr) == false)
3390 addr = sc.function->GetAddressRange().GetBaseAddress();
3404 SymbolFileDWARF::FindFunctions (const ConstString &name,
3405 const NameToDIE &name_to_die,
3406 SymbolContextList& sc_list)
3408 DIEArray die_offsets;
3409 if (name_to_die.Find (name, die_offsets))
3411 ParseFunctions (die_offsets, sc_list);
3417 SymbolFileDWARF::FindFunctions (const RegularExpression ®ex,
3418 const NameToDIE &name_to_die,
3419 SymbolContextList& sc_list)
3421 DIEArray die_offsets;
3422 if (name_to_die.Find (regex, die_offsets))
3424 ParseFunctions (die_offsets, sc_list);
3430 SymbolFileDWARF::FindFunctions (const RegularExpression ®ex,
3431 const DWARFMappedHash::MemoryTable &memory_table,
3432 SymbolContextList& sc_list)
3434 DIEArray die_offsets;
3435 DWARFMappedHash::DIEInfoArray hash_data_array;
3436 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
3438 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3439 ParseFunctions (die_offsets, sc_list);
3444 SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
3445 SymbolContextList& sc_list)
3447 const size_t num_matches = die_offsets.size();
3452 DWARFCompileUnit* dwarf_cu = NULL;
3453 for (size_t i=0; i<num_matches; ++i)
3455 const dw_offset_t die_offset = die_offsets[i];
3456 ResolveFunction (die_offset, dwarf_cu, sc_list);
3462 SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
3463 const DWARFCompileUnit *dwarf_cu,
3464 uint32_t name_type_mask,
3465 const char *partial_name,
3466 const char *base_name_start,
3467 const char *base_name_end)
3469 // If we are looking only for methods, throw away all the ones that are or aren't in C++ classes:
3470 if (name_type_mask == eFunctionNameTypeMethod || name_type_mask == eFunctionNameTypeBase)
3472 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
3473 if (!containing_decl_ctx)
3476 bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
3478 if (name_type_mask == eFunctionNameTypeMethod)
3480 if (is_cxx_method == false)
3484 if (name_type_mask == eFunctionNameTypeBase)
3486 if (is_cxx_method == true)
3491 // Now we need to check whether the name we got back for this type matches the extra specifications
3492 // that were in the name we're looking up:
3493 if (base_name_start != partial_name || *base_name_end != '\0')
3495 // First see if the stuff to the left matches the full name. To do that let's see if
3496 // we can pull out the mips linkage name attribute:
3499 DWARFDebugInfoEntry::Attributes attributes;
3500 DWARFFormValue form_value;
3501 die->GetAttributes(this, dwarf_cu, NULL, attributes);
3502 uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
3503 if (idx == UINT32_MAX)
3504 idx = attributes.FindAttributeIndex(DW_AT_linkage_name);
3505 if (idx != UINT32_MAX)
3507 if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
3509 const char *mangled_name = form_value.AsCString(&get_debug_str_data());
3511 best_name.SetValue (ConstString(mangled_name), true);
3517 idx = attributes.FindAttributeIndex(DW_AT_name);
3518 if (idx != UINT32_MAX && attributes.ExtractFormValueAtIndex(this, idx, form_value))
3520 const char *name = form_value.AsCString(&get_debug_str_data());
3521 best_name.SetValue (ConstString(name), false);
3525 if (best_name.GetDemangledName())
3527 const char *demangled = best_name.GetDemangledName().GetCString();
3530 std::string name_no_parens(partial_name, base_name_end - partial_name);
3531 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3532 if (partial_in_demangled == NULL)
3536 // Sort out the case where our name is something like "Process::Destroy" and the match is
3537 // "SBProcess::Destroy" - that shouldn't be a match. We should really always match on
3538 // namespace boundaries...
3540 if (partial_name[0] == ':' && partial_name[1] == ':')
3542 // The partial name was already on a namespace boundary so all matches are good.
3545 else if (partial_in_demangled == demangled)
3547 // They both start the same, so this is an good match.
3552 if (partial_in_demangled - demangled == 1)
3554 // Only one character difference, can't be a namespace boundary...
3557 else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3559 // We are on a namespace boundary, so this is also good.
3574 SymbolFileDWARF::FindFunctions (const ConstString &name,
3575 const lldb_private::ClangNamespaceDecl *namespace_decl,
3576 uint32_t name_type_mask,
3577 bool include_inlines,
3579 SymbolContextList& sc_list)
3581 Timer scoped_timer (__PRETTY_FUNCTION__,
3582 "SymbolFileDWARF::FindFunctions (name = '%s')",
3585 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
3586 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
3588 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3592 GetObjectFile()->GetModule()->LogMessage (log,
3593 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3599 // If we aren't appending the results to this list, then clear the list
3603 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3606 // If name is empty then we won't find anything.
3610 // Remember how many sc_list are in the list before we search in case
3611 // we are appending the results to a variable list.
3613 const char *name_cstr = name.GetCString();
3615 const uint32_t original_size = sc_list.GetSize();
3617 DWARFDebugInfo* info = DebugInfo();
3621 DWARFCompileUnit *dwarf_cu = NULL;
3622 std::set<const DWARFDebugInfoEntry *> resolved_dies;
3623 if (m_using_apple_tables)
3625 if (m_apple_names_ap.get())
3628 DIEArray die_offsets;
3630 uint32_t num_matches = 0;
3632 if (name_type_mask & eFunctionNameTypeFull)
3634 // If they asked for the full name, match what they typed. At some point we may
3635 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
3636 // dies that we find by exact match.
3637 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3638 for (uint32_t i = 0; i < num_matches; i++)
3640 const dw_offset_t die_offset = die_offsets[i];
3641 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3644 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3647 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3650 if (resolved_dies.find(die) == resolved_dies.end())
3652 if (ResolveFunction (dwarf_cu, die, sc_list))
3653 resolved_dies.insert(die);
3658 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3659 die_offset, name_cstr);
3664 if (name_type_mask & eFunctionNameTypeSelector)
3666 if (namespace_decl && *namespace_decl)
3667 return 0; // no selectors in namespaces
3669 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3670 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
3671 // and if it is an ObjC method name, we're good.
3673 for (uint32_t i = 0; i < num_matches; i++)
3675 const dw_offset_t die_offset = die_offsets[i];
3676 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3679 const char *die_name = die->GetName(this, dwarf_cu);
3680 if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
3682 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3685 if (resolved_dies.find(die) == resolved_dies.end())
3687 if (ResolveFunction (dwarf_cu, die, sc_list))
3688 resolved_dies.insert(die);
3694 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3695 die_offset, name_cstr);
3698 die_offsets.clear();
3701 if (((name_type_mask & eFunctionNameTypeMethod) && !namespace_decl) || name_type_mask & eFunctionNameTypeBase)
3703 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
3704 // extract the base name, look that up, and if there is any other information in the name we were
3705 // passed in we have to post-filter based on that.
3707 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3708 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3710 for (uint32_t i = 0; i < num_matches; i++)
3712 const dw_offset_t die_offset = die_offsets[i];
3713 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3716 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3719 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3722 // If we get to here, the die is good, and we should add it:
3723 if (resolved_dies.find(die) == resolved_dies.end())
3724 if (ResolveFunction (dwarf_cu, die, sc_list))
3726 bool keep_die = true;
3727 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
3729 // We are looking for either basenames or methods, so we need to
3730 // trim out the ones we won't want by looking at the type
3732 if (sc_list.GetLastContext(sc))
3736 // We have an inlined function
3738 else if (sc.function)
3740 Type *type = sc.function->GetType();
3744 clang::DeclContext* decl_ctx = GetClangDeclContextContainingTypeUID (type->GetID());
3745 if (decl_ctx->isRecord())
3747 if (name_type_mask & eFunctionNameTypeBase)
3749 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3755 if (name_type_mask & eFunctionNameTypeMethod)
3757 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
3764 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
3771 resolved_dies.insert(die);
3776 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3777 die_offset, name_cstr);
3780 die_offsets.clear();
3787 // Index the DWARF if we haven't already
3791 if (name_type_mask & eFunctionNameTypeFull)
3793 FindFunctions (name, m_function_fullname_index, sc_list);
3795 // FIXME Temporary workaround for global/anonymous namespace
3796 // functions on FreeBSD and Linux
3797 #if defined (__FreeBSD__) || defined (__linux__)
3798 // If we didn't find any functions in the global namespace try
3799 // looking in the basename index but ignore any returned
3800 // functions that have a namespace (ie. mangled names starting with
3801 // '_ZN') but keep functions which have an anonymous namespace
3802 if (sc_list.GetSize() == 0)
3804 SymbolContextList temp_sc_list;
3805 FindFunctions (name, m_function_basename_index, temp_sc_list);
3806 if (!namespace_decl)
3809 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
3811 if (temp_sc_list.GetContextAtIndex(i, sc))
3813 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
3814 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
3815 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
3816 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
3826 DIEArray die_offsets;
3827 DWARFCompileUnit *dwarf_cu = NULL;
3829 if (name_type_mask & eFunctionNameTypeBase)
3831 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
3832 for (uint32_t i = 0; i < num_base; i++)
3834 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3837 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3840 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3843 // If we get to here, the die is good, and we should add it:
3844 if (resolved_dies.find(die) == resolved_dies.end())
3846 if (ResolveFunction (dwarf_cu, die, sc_list))
3847 resolved_dies.insert(die);
3851 die_offsets.clear();
3854 if (name_type_mask & eFunctionNameTypeMethod)
3856 if (namespace_decl && *namespace_decl)
3857 return 0; // no methods in namespaces
3859 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
3861 for (uint32_t i = 0; i < num_base; i++)
3863 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3866 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3869 // If we get to here, the die is good, and we should add it:
3870 if (resolved_dies.find(die) == resolved_dies.end())
3872 if (ResolveFunction (dwarf_cu, die, sc_list))
3873 resolved_dies.insert(die);
3878 die_offsets.clear();
3881 if ((name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
3883 FindFunctions (name, m_function_selector_index, sc_list);
3888 // Return the number of variable that were appended to the list
3889 const uint32_t num_matches = sc_list.GetSize() - original_size;
3891 if (log && num_matches > 0)
3893 GetObjectFile()->GetModule()->LogMessage (log,
3894 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list) => %u",
3904 SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
3906 Timer scoped_timer (__PRETTY_FUNCTION__,
3907 "SymbolFileDWARF::FindFunctions (regex = '%s')",
3910 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3914 GetObjectFile()->GetModule()->LogMessage (log,
3915 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3921 // If we aren't appending the results to this list, then clear the list
3925 // Remember how many sc_list are in the list before we search in case
3926 // we are appending the results to a variable list.
3927 uint32_t original_size = sc_list.GetSize();
3929 if (m_using_apple_tables)
3931 if (m_apple_names_ap.get())
3932 FindFunctions (regex, *m_apple_names_ap, sc_list);
3936 // Index the DWARF if we haven't already
3940 FindFunctions (regex, m_function_basename_index, sc_list);
3942 FindFunctions (regex, m_function_fullname_index, sc_list);
3945 // Return the number of variable that were appended to the list
3946 return sc_list.GetSize() - original_size;
3950 SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3951 const ConstString &name,
3952 const lldb_private::ClangNamespaceDecl *namespace_decl,
3954 uint32_t max_matches,
3957 DWARFDebugInfo* info = DebugInfo();
3961 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3967 GetObjectFile()->GetModule()->LogMessage (log,
3968 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list)",
3970 namespace_decl->GetNamespaceDecl(),
3971 namespace_decl->GetQualifiedName().c_str(),
3977 GetObjectFile()->GetModule()->LogMessage (log,
3978 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list)",
3985 // If we aren't appending the results to this list, then clear the list
3989 if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3992 DIEArray die_offsets;
3994 if (m_using_apple_tables)
3996 if (m_apple_types_ap.get())
3998 const char *name_cstr = name.GetCString();
3999 m_apple_types_ap->FindByName (name_cstr, die_offsets);
4007 m_type_index.Find (name, die_offsets);
4010 const size_t num_die_matches = die_offsets.size();
4012 if (num_die_matches)
4014 const uint32_t initial_types_size = types.GetSize();
4015 DWARFCompileUnit* dwarf_cu = NULL;
4016 const DWARFDebugInfoEntry* die = NULL;
4017 DWARFDebugInfo* debug_info = DebugInfo();
4018 for (size_t i=0; i<num_die_matches; ++i)
4020 const dw_offset_t die_offset = die_offsets[i];
4021 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4025 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
4028 Type *matching_type = ResolveType (dwarf_cu, die);
4031 // We found a type pointer, now find the shared pointer form our type list
4032 types.InsertUnique (matching_type->shared_from_this());
4033 if (types.GetSize() >= max_matches)
4039 if (m_using_apple_tables)
4041 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4042 die_offset, name.GetCString());
4047 const uint32_t num_matches = types.GetSize() - initial_types_size;
4048 if (log && num_matches)
4052 GetObjectFile()->GetModule()->LogMessage (log,
4053 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(%p) \"%s\", append=%u, max_matches=%u, type_list) => %u",
4055 namespace_decl->GetNamespaceDecl(),
4056 namespace_decl->GetQualifiedName().c_str(),
4063 GetObjectFile()->GetModule()->LogMessage (log,
4064 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", clang::NamespaceDecl(NULL), append=%u, max_matches=%u, type_list) => %u",
4078 SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
4079 const ConstString &name,
4080 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
4082 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
4086 GetObjectFile()->GetModule()->LogMessage (log,
4087 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
4091 if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
4092 return ClangNamespaceDecl();
4094 ClangNamespaceDecl namespace_decl;
4095 DWARFDebugInfo* info = DebugInfo();
4098 DIEArray die_offsets;
4100 // Index if we already haven't to make sure the compile units
4101 // get indexed and make their global DIE index list
4102 if (m_using_apple_tables)
4104 if (m_apple_namespaces_ap.get())
4106 const char *name_cstr = name.GetCString();
4107 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
4115 m_namespace_index.Find (name, die_offsets);
4118 DWARFCompileUnit* dwarf_cu = NULL;
4119 const DWARFDebugInfoEntry* die = NULL;
4120 const size_t num_matches = die_offsets.size();
4123 DWARFDebugInfo* debug_info = DebugInfo();
4124 for (size_t i=0; i<num_matches; ++i)
4126 const dw_offset_t die_offset = die_offsets[i];
4127 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
4131 if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
4134 clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
4135 if (clang_namespace_decl)
4137 namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
4138 namespace_decl.SetNamespaceDecl (clang_namespace_decl);
4144 if (m_using_apple_tables)
4146 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
4147 die_offset, name.GetCString());
4154 if (log && namespace_decl.GetNamespaceDecl())
4156 GetObjectFile()->GetModule()->LogMessage (log,
4157 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => clang::NamespaceDecl(%p) \"%s\"",
4159 namespace_decl.GetNamespaceDecl(),
4160 namespace_decl.GetQualifiedName().c_str());
4163 return namespace_decl;
4167 SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
4169 // Remember how many sc_list are in the list before we search in case
4170 // we are appending the results to a variable list.
4171 uint32_t original_size = types.GetSize();
4173 const uint32_t num_die_offsets = die_offsets.size();
4174 // Parse all of the types we found from the pubtypes matches
4176 uint32_t num_matches = 0;
4177 for (i = 0; i < num_die_offsets; ++i)
4179 Type *matching_type = ResolveTypeUID (die_offsets[i]);
4182 // We found a type pointer, now find the shared pointer form our type list
4183 types.InsertUnique (matching_type->shared_from_this());
4185 if (num_matches >= max_matches)
4190 // Return the number of variable that were appended to the list
4191 return types.GetSize() - original_size;
4196 SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
4197 clang::DeclContext *containing_decl_ctx,
4198 DWARFCompileUnit* dwarf_cu,
4199 const DWARFDebugInfoEntry *parent_die,
4200 bool skip_artificial,
4203 TypeList* type_list,
4204 std::vector<ClangASTType>& function_param_types,
4205 std::vector<clang::ParmVarDecl*>& function_param_decls,
4206 unsigned &type_quals,
4207 ClangASTContext::TemplateParameterInfos &template_param_infos)
4209 if (parent_die == NULL)
4212 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4215 const DWARFDebugInfoEntry *die;
4216 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4218 dw_tag_t tag = die->Tag();
4221 case DW_TAG_formal_parameter:
4223 DWARFDebugInfoEntry::Attributes attributes;
4224 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
4225 if (num_attributes > 0)
4227 const char *name = NULL;
4229 dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
4230 bool is_artificial = false;
4231 // one of None, Auto, Register, Extern, Static, PrivateExtern
4233 clang::StorageClass storage = clang::SC_None;
4235 for (i=0; i<num_attributes; ++i)
4237 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4238 DWARFFormValue form_value;
4239 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4243 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4244 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4245 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4246 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
4247 case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break;
4248 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
4249 case DW_AT_location:
4250 // if (form_value.BlockData())
4252 // const DWARFDataExtractor& debug_info_data = debug_info();
4253 // uint32_t block_length = form_value.Unsigned();
4254 // DWARFDataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
4260 case DW_AT_const_value:
4261 case DW_AT_default_value:
4262 case DW_AT_description:
4263 case DW_AT_endianity:
4264 case DW_AT_is_optional:
4266 case DW_AT_variable_parameter:
4268 case DW_AT_abstract_origin:
4276 if (skip_artificial)
4280 // In order to determine if a C++ member function is
4281 // "const" we have to look at the const-ness of "this"...
4285 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
4287 // Often times compilers omit the "this" name for the
4288 // specification DIEs, so we can't rely upon the name
4289 // being in the formal parameter DIE...
4290 if (name == NULL || ::strcmp(name, "this")==0)
4292 Type *this_type = ResolveTypeUID (param_type_die_offset);
4295 uint32_t encoding_mask = this_type->GetEncodingMask();
4296 if (encoding_mask & Type::eEncodingIsPointerUID)
4300 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
4301 type_quals |= clang::Qualifiers::Const;
4302 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
4303 type_quals |= clang::Qualifiers::Volatile;
4314 // HACK: Objective C formal parameters "self" and "_cmd"
4315 // are not marked as artificial in the DWARF...
4316 CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
4319 switch (comp_unit->GetLanguage())
4321 case eLanguageTypeObjC:
4322 case eLanguageTypeObjC_plus_plus:
4323 if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
4335 Type *type = ResolveTypeUID(param_type_die_offset);
4338 function_param_types.push_back (type->GetClangForwardType());
4340 clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
4341 type->GetClangForwardType(),
4343 assert(param_var_decl);
4344 function_param_decls.push_back(param_var_decl);
4346 GetClangASTContext().SetMetadataAsUserID (param_var_decl, MakeUserID(die->GetOffset()));
4354 case DW_TAG_unspecified_parameters:
4358 case DW_TAG_template_type_parameter:
4359 case DW_TAG_template_value_parameter:
4360 ParseTemplateDIE (dwarf_cu, die,template_param_infos);
4371 SymbolFileDWARF::ParseChildEnumerators
4373 const SymbolContext& sc,
4374 lldb_private::ClangASTType &clang_type,
4376 uint32_t enumerator_byte_size,
4377 DWARFCompileUnit* dwarf_cu,
4378 const DWARFDebugInfoEntry *parent_die
4381 if (parent_die == NULL)
4384 size_t enumerators_added = 0;
4385 const DWARFDebugInfoEntry *die;
4386 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4388 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4390 const dw_tag_t tag = die->Tag();
4391 if (tag == DW_TAG_enumerator)
4393 DWARFDebugInfoEntry::Attributes attributes;
4394 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
4395 if (num_child_attributes > 0)
4397 const char *name = NULL;
4398 bool got_value = false;
4399 int64_t enum_value = 0;
4403 for (i=0; i<num_child_attributes; ++i)
4405 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4406 DWARFFormValue form_value;
4407 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4411 case DW_AT_const_value:
4414 enum_value = form_value.Signed();
4416 enum_value = form_value.Unsigned();
4420 name = form_value.AsCString(&get_debug_str_data());
4423 case DW_AT_description:
4425 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4426 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4427 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4434 if (name && name[0] && got_value)
4436 clang_type.AddEnumerationValueToEnumerationType (clang_type.GetEnumerationIntegerType(),
4440 enumerator_byte_size * 8);
4441 ++enumerators_added;
4446 return enumerators_added;
4450 SymbolFileDWARF::ParseChildArrayInfo
4452 const SymbolContext& sc,
4453 DWARFCompileUnit* dwarf_cu,
4454 const DWARFDebugInfoEntry *parent_die,
4455 int64_t& first_index,
4456 std::vector<uint64_t>& element_orders,
4457 uint32_t& byte_stride,
4458 uint32_t& bit_stride
4461 if (parent_die == NULL)
4464 const DWARFDebugInfoEntry *die;
4465 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
4466 for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
4468 const dw_tag_t tag = die->Tag();
4471 case DW_TAG_subrange_type:
4473 DWARFDebugInfoEntry::Attributes attributes;
4474 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
4475 if (num_child_attributes > 0)
4477 uint64_t num_elements = 0;
4478 uint64_t lower_bound = 0;
4479 uint64_t upper_bound = 0;
4480 bool upper_bound_valid = false;
4482 for (i=0; i<num_child_attributes; ++i)
4484 const dw_attr_t attr = attributes.AttributeAtIndex(i);
4485 DWARFFormValue form_value;
4486 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4494 num_elements = form_value.Unsigned();
4497 case DW_AT_bit_stride:
4498 bit_stride = form_value.Unsigned();
4501 case DW_AT_byte_stride:
4502 byte_stride = form_value.Unsigned();
4505 case DW_AT_lower_bound:
4506 lower_bound = form_value.Unsigned();
4509 case DW_AT_upper_bound:
4510 upper_bound_valid = true;
4511 upper_bound = form_value.Unsigned();
4515 case DW_AT_abstract_origin:
4516 case DW_AT_accessibility:
4517 case DW_AT_allocated:
4518 case DW_AT_associated:
4519 case DW_AT_data_location:
4520 case DW_AT_declaration:
4521 case DW_AT_description:
4523 case DW_AT_threads_scaled:
4525 case DW_AT_visibility:
4531 if (num_elements == 0)
4533 if (upper_bound_valid && upper_bound >= lower_bound)
4534 num_elements = upper_bound - lower_bound + 1;
4537 element_orders.push_back (num_elements);
4546 SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
4551 assert(dwarf_cu != NULL);
4552 Type *type_ptr = m_die_to_type.lookup (die);
4553 if (type_ptr == NULL)
4555 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
4557 SymbolContext sc(lldb_cu);
4558 type_sp = ParseType(sc, dwarf_cu, die, NULL);
4560 else if (type_ptr != DIE_IS_BEING_PARSED)
4562 // Grab the existing type from the master types lists
4563 type_sp = type_ptr->shared_from_this();
4570 clang::DeclContext *
4571 SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
4573 if (die_offset != DW_INVALID_OFFSET)
4575 DWARFCompileUnitSP cu_sp;
4576 const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
4577 return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
4582 clang::DeclContext *
4583 SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4585 if (die_offset != DW_INVALID_OFFSET)
4587 DWARFDebugInfo* debug_info = DebugInfo();
4590 DWARFCompileUnitSP cu_sp;
4591 const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4593 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4599 clang::NamespaceDecl *
4600 SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
4602 if (die && die->Tag() == DW_TAG_namespace)
4604 // See if we already parsed this namespace DIE and associated it with a
4605 // uniqued namespace declaration
4606 clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4608 return namespace_decl;
4611 const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4612 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
4613 namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
4614 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4619 GetObjectFile()->GetModule()->LogMessage (log,
4620 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
4621 GetClangASTContext().getASTContext(),
4622 MakeUserID(die->GetOffset()),
4625 namespace_decl->getOriginalNamespace());
4629 GetObjectFile()->GetModule()->LogMessage (log,
4630 "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
4631 GetClangASTContext().getASTContext(),
4632 MakeUserID(die->GetOffset()),
4634 namespace_decl->getOriginalNamespace());
4639 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4640 return namespace_decl;
4646 clang::DeclContext *
4647 SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4649 clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4651 return clang_decl_ctx;
4652 // If this DIE has a specification, or an abstract origin, then trace to those.
4654 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4655 if (die_offset != DW_INVALID_OFFSET)
4656 return GetClangDeclContextForDIEOffset (sc, die_offset);
4658 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4659 if (die_offset != DW_INVALID_OFFSET)
4660 return GetClangDeclContextForDIEOffset (sc, die_offset);
4662 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4664 GetObjectFile()->GetModule()->LogMessage(log, "SymbolFileDWARF::GetClangDeclContextForDIE (die = 0x%8.8x) %s '%s'", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), die->GetName(this, cu));
4665 // This is the DIE we want. Parse it, then query our map.
4666 bool assert_not_being_parsed = true;
4667 ResolveTypeUID (cu, die, assert_not_being_parsed);
4669 clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4671 return clang_decl_ctx;
4674 clang::DeclContext *
4675 SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
4677 if (m_clang_tu_decl == NULL)
4678 m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
4680 const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
4682 if (decl_ctx_die_copy)
4683 *decl_ctx_die_copy = decl_ctx_die;
4688 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4689 if (pos != m_die_to_decl_ctx.end())
4692 switch (decl_ctx_die->Tag())
4694 case DW_TAG_compile_unit:
4695 return m_clang_tu_decl;
4697 case DW_TAG_namespace:
4698 return ResolveNamespaceDIE (cu, decl_ctx_die);
4701 case DW_TAG_structure_type:
4702 case DW_TAG_union_type:
4703 case DW_TAG_class_type:
4705 Type* type = ResolveType (cu, decl_ctx_die);
4708 clang::DeclContext *decl_ctx = type->GetClangForwardType().GetDeclContextForType ();
4711 LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4723 return m_clang_tu_decl;
4727 const DWARFDebugInfoEntry *
4728 SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4732 const DWARFDebugInfoEntry * const decl_die = die;
4736 // If this is the original DIE that we are searching for a declaration
4737 // for, then don't look in the cache as we don't want our own decl
4738 // context to be our decl context...
4739 if (decl_die != die)
4743 case DW_TAG_compile_unit:
4744 case DW_TAG_namespace:
4745 case DW_TAG_structure_type:
4746 case DW_TAG_union_type:
4747 case DW_TAG_class_type:
4755 dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4756 if (die_offset != DW_INVALID_OFFSET)
4758 DWARFCompileUnit *spec_cu = cu;
4759 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4760 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4761 if (spec_die_decl_ctx_die)
4762 return spec_die_decl_ctx_die;
4765 die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4766 if (die_offset != DW_INVALID_OFFSET)
4768 DWARFCompileUnit *abs_cu = cu;
4769 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4770 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4771 if (abs_die_decl_ctx_die)
4772 return abs_die_decl_ctx_die;
4775 die = die->GetParent();
4783 SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4785 Symbol *objc_class_symbol = NULL;
4788 Symtab *symtab = m_obj_file->GetSymtab ();
4791 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4792 eSymbolTypeObjCClass,
4794 Symtab::eVisibilityAny);
4797 return objc_class_symbol;
4800 // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4801 // then we can end up looking through all class types for a complete type and never find
4802 // the full definition. We need to know if this attribute is supported, so we determine
4803 // this here and cache th result. We also need to worry about the debug map DWARF file
4804 // if we are doing darwin DWARF in .o file debugging.
4806 SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4808 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4810 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4811 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4812 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4815 DWARFDebugInfo* debug_info = DebugInfo();
4816 const uint32_t num_compile_units = GetNumCompileUnits();
4817 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4819 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4820 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
4822 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4827 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
4828 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4830 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4833 // This function can be used when a DIE is found that is a forward declaration
4834 // DIE and we want to try and find a type that has the complete definition.
4836 SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4837 const ConstString &type_name,
4838 bool must_be_implementation)
4843 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
4846 DIEArray die_offsets;
4848 if (m_using_apple_tables)
4850 if (m_apple_types_ap.get())
4852 const char *name_cstr = type_name.GetCString();
4853 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
4861 m_type_index.Find (type_name, die_offsets);
4864 const size_t num_matches = die_offsets.size();
4866 DWARFCompileUnit* type_cu = NULL;
4867 const DWARFDebugInfoEntry* type_die = NULL;
4870 DWARFDebugInfo* debug_info = DebugInfo();
4871 for (size_t i=0; i<num_matches; ++i)
4873 const dw_offset_t die_offset = die_offsets[i];
4874 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4878 bool try_resolving_type = false;
4880 // Don't try and resolve the DIE we are looking for with the DIE itself!
4881 if (type_die != die)
4883 switch (type_die->Tag())
4885 case DW_TAG_class_type:
4886 case DW_TAG_structure_type:
4887 try_resolving_type = true;
4894 if (try_resolving_type)
4896 if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
4897 try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
4899 if (try_resolving_type)
4901 Type *resolved_type = ResolveType (type_cu, type_die, false);
4902 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4904 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n",
4905 MakeUserID(die->GetOffset()),
4906 m_obj_file->GetFileSpec().GetFilename().AsCString(),
4907 MakeUserID(type_die->GetOffset()),
4908 MakeUserID(type_cu->GetOffset()));
4911 m_die_to_type[die] = resolved_type;
4912 type_sp = resolved_type->shared_from_this();
4920 if (m_using_apple_tables)
4922 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4923 die_offset, type_name.GetCString());
4933 //----------------------------------------------------------------------
4934 // This function helps to ensure that the declaration contexts match for
4935 // two different DIEs. Often times debug information will refer to a
4936 // forward declaration of a type (the equivalent of "struct my_struct;".
4937 // There will often be a declaration of that type elsewhere that has the
4938 // full definition. When we go looking for the full type "my_struct", we
4939 // will find one or more matches in the accelerator tables and we will
4940 // then need to make sure the type was in the same declaration context
4941 // as the original DIE. This function can efficiently compare two DIEs
4942 // and will return true when the declaration context matches, and false
4944 //----------------------------------------------------------------------
4946 SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4947 DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4952 #if defined (LLDB_CONFIGURATION_DEBUG)
4953 // You can't and shouldn't call this function with a compile unit from
4954 // two different SymbolFileDWARF instances.
4955 assert (DebugInfo()->ContainsCompileUnit (cu1));
4956 assert (DebugInfo()->ContainsCompileUnit (cu2));
4959 DWARFDIECollection decl_ctx_1;
4960 DWARFDIECollection decl_ctx_2;
4961 //The declaration DIE stack is a stack of the declaration context
4962 // DIEs all the way back to the compile unit. If a type "T" is
4963 // declared inside a class "B", and class "B" is declared inside
4964 // a class "A" and class "A" is in a namespace "lldb", and the
4965 // namespace is in a compile unit, there will be a stack of DIEs:
4967 // [0] DW_TAG_class_type for "B"
4968 // [1] DW_TAG_class_type for "A"
4969 // [2] DW_TAG_namespace for "lldb"
4970 // [3] DW_TAG_compile_unit for the source file.
4972 // We grab both contexts and make sure that everything matches
4973 // all the way back to the compiler unit.
4975 // First lets grab the decl contexts for both DIEs
4976 die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
4977 die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
4978 // Make sure the context arrays have the same size, otherwise
4980 const size_t count1 = decl_ctx_1.Size();
4981 const size_t count2 = decl_ctx_2.Size();
4982 if (count1 != count2)
4985 // Make sure the DW_TAG values match all the way back up the the
4986 // compile unit. If they don't, then we are done.
4987 const DWARFDebugInfoEntry *decl_ctx_die1;
4988 const DWARFDebugInfoEntry *decl_ctx_die2;
4990 for (i=0; i<count1; i++)
4992 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4993 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4994 if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4997 #if defined LLDB_CONFIGURATION_DEBUG
4999 // Make sure the top item in the decl context die array is always
5000 // DW_TAG_compile_unit. If it isn't then something went wrong in
5001 // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
5002 assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
5005 // Always skip the compile unit when comparing by only iterating up to
5006 // "count - 1". Here we compare the names as we go.
5007 for (i=0; i<count1 - 1; i++)
5009 decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
5010 decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
5011 const char *name1 = decl_ctx_die1->GetName(this, cu1);
5012 const char *name2 = decl_ctx_die2->GetName(this, cu2);
5013 // If the string was from a DW_FORM_strp, then the pointer will often
5018 // Name pointers are not equal, so only compare the strings
5019 // if both are not NULL.
5022 // If the strings don't compare, we are done...
5023 if (strcmp(name1, name2) != 0)
5028 // One name was NULL while the other wasn't
5032 // We made it through all of the checks and the declaration contexts
5037 // This function can be used when a DIE is found that is a forward declaration
5038 // DIE and we want to try and find a type that has the complete definition.
5039 // "cu" and "die" must be from this SymbolFileDWARF
5041 SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
5042 const DWARFDebugInfoEntry *die,
5043 const ConstString &type_name)
5047 #if defined (LLDB_CONFIGURATION_DEBUG)
5048 // You can't and shouldn't call this function with a compile unit from
5049 // another SymbolFileDWARF instance.
5050 assert (DebugInfo()->ContainsCompileUnit (cu));
5053 if (cu == NULL || die == NULL || !type_name)
5056 std::string qualified_name;
5058 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
5061 die->GetQualifiedName(this, cu, qualified_name);
5062 GetObjectFile()->GetModule()->LogMessage (log,
5063 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x (%s), name='%s')",
5065 qualified_name.c_str(),
5066 type_name.GetCString());
5069 DIEArray die_offsets;
5071 if (m_using_apple_tables)
5073 if (m_apple_types_ap.get())
5075 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5076 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5077 if (has_tag && has_qualified_name_hash)
5079 if (qualified_name.empty())
5080 die->GetQualifiedName(this, cu, qualified_name);
5082 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name.c_str());
5084 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
5085 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), die->Tag(), qualified_name_hash, die_offsets);
5087 else if (has_tag > 1)
5090 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
5091 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
5095 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5104 m_type_index.Find (type_name, die_offsets);
5107 const size_t num_matches = die_offsets.size();
5109 const dw_tag_t die_tag = die->Tag();
5111 DWARFCompileUnit* type_cu = NULL;
5112 const DWARFDebugInfoEntry* type_die = NULL;
5115 DWARFDebugInfo* debug_info = DebugInfo();
5116 for (size_t i=0; i<num_matches; ++i)
5118 const dw_offset_t die_offset = die_offsets[i];
5119 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5123 bool try_resolving_type = false;
5125 // Don't try and resolve the DIE we are looking for with the DIE itself!
5126 if (type_die != die)
5128 const dw_tag_t type_die_tag = type_die->Tag();
5129 // Make sure the tags match
5130 if (type_die_tag == die_tag)
5132 // The tags match, lets try resolving this type
5133 try_resolving_type = true;
5137 // The tags don't match, but we need to watch our for a
5138 // forward declaration for a struct and ("struct foo")
5139 // ends up being a class ("class foo { ... };") or
5141 switch (type_die_tag)
5143 case DW_TAG_class_type:
5144 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5145 try_resolving_type = (die_tag == DW_TAG_structure_type);
5147 case DW_TAG_structure_type:
5148 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5149 try_resolving_type = (die_tag == DW_TAG_class_type);
5152 // Tags don't match, don't event try to resolve
5153 // using this type whose name matches....
5159 if (try_resolving_type)
5163 std::string qualified_name;
5164 type_die->GetQualifiedName(this, cu, qualified_name);
5165 GetObjectFile()->GetModule()->LogMessage (log,
5166 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') trying die=0x%8.8x (%s)",
5168 type_name.GetCString(),
5169 type_die->GetOffset(),
5170 qualified_name.c_str());
5173 // Make sure the decl contexts match all the way up
5174 if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
5176 Type *resolved_type = ResolveType (type_cu, type_die, false);
5177 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5179 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ") from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n",
5180 MakeUserID(die->GetOffset()),
5181 MakeUserID(cu->GetOffset()),
5182 m_obj_file->GetFileSpec().GetFilename().AsCString(),
5183 MakeUserID(type_die->GetOffset()),
5184 MakeUserID(type_cu->GetOffset()));
5186 m_die_to_type[die] = resolved_type;
5187 type_sp = resolved_type->shared_from_this();
5196 std::string qualified_name;
5197 type_die->GetQualifiedName(this, cu, qualified_name);
5198 GetObjectFile()->GetModule()->LogMessage (log,
5199 "SymbolFileDWARF::FindDefinitionTypeForDIE(die=0x%8.8x, name='%s') ignoring die=0x%8.8x (%s)",
5201 type_name.GetCString(),
5202 type_die->GetOffset(),
5203 qualified_name.c_str());
5209 if (m_using_apple_tables)
5211 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5212 die_offset, type_name.GetCString());
5222 SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
5226 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
5227 if (dwarf_decl_ctx_count > 0)
5229 const ConstString type_name(dwarf_decl_ctx[0].name);
5230 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
5234 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
5237 GetObjectFile()->GetModule()->LogMessage (log,
5238 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
5239 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5240 dwarf_decl_ctx.GetQualifiedName());
5243 DIEArray die_offsets;
5245 if (m_using_apple_tables)
5247 if (m_apple_types_ap.get())
5249 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
5250 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
5251 if (has_tag && has_qualified_name_hash)
5253 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
5254 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
5256 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
5257 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
5262 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
5263 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
5267 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
5276 m_type_index.Find (type_name, die_offsets);
5279 const size_t num_matches = die_offsets.size();
5282 DWARFCompileUnit* type_cu = NULL;
5283 const DWARFDebugInfoEntry* type_die = NULL;
5286 DWARFDebugInfo* debug_info = DebugInfo();
5287 for (size_t i=0; i<num_matches; ++i)
5289 const dw_offset_t die_offset = die_offsets[i];
5290 type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
5294 bool try_resolving_type = false;
5296 // Don't try and resolve the DIE we are looking for with the DIE itself!
5297 const dw_tag_t type_tag = type_die->Tag();
5298 // Make sure the tags match
5299 if (type_tag == tag)
5301 // The tags match, lets try resolving this type
5302 try_resolving_type = true;
5306 // The tags don't match, but we need to watch our for a
5307 // forward declaration for a struct and ("struct foo")
5308 // ends up being a class ("class foo { ... };") or
5312 case DW_TAG_class_type:
5313 // We had a "class foo", see if we ended up with a "struct foo { ... };"
5314 try_resolving_type = (tag == DW_TAG_structure_type);
5316 case DW_TAG_structure_type:
5317 // We had a "struct foo", see if we ended up with a "class foo { ... };"
5318 try_resolving_type = (tag == DW_TAG_class_type);
5321 // Tags don't match, don't event try to resolve
5322 // using this type whose name matches....
5327 if (try_resolving_type)
5329 DWARFDeclContext type_dwarf_decl_ctx;
5330 type_die->GetDWARFDeclContext (this, type_cu, type_dwarf_decl_ctx);
5334 GetObjectFile()->GetModule()->LogMessage (log,
5335 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
5336 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5337 dwarf_decl_ctx.GetQualifiedName(),
5338 type_die->GetOffset(),
5339 type_dwarf_decl_ctx.GetQualifiedName());
5342 // Make sure the decl contexts match all the way up
5343 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
5345 Type *resolved_type = ResolveType (type_cu, type_die, false);
5346 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
5348 type_sp = resolved_type->shared_from_this();
5357 std::string qualified_name;
5358 type_die->GetQualifiedName(this, type_cu, qualified_name);
5359 GetObjectFile()->GetModule()->LogMessage (log,
5360 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
5361 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
5362 dwarf_decl_ctx.GetQualifiedName(),
5363 type_die->GetOffset(),
5364 qualified_name.c_str());
5370 if (m_using_apple_tables)
5372 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
5373 die_offset, type_name.GetCString());
5385 SymbolFileDWARF::CopyUniqueClassMethodTypes (SymbolFileDWARF *src_symfile,
5387 DWARFCompileUnit* src_cu,
5388 const DWARFDebugInfoEntry *src_class_die,
5389 DWARFCompileUnit* dst_cu,
5390 const DWARFDebugInfoEntry *dst_class_die,
5391 llvm::SmallVectorImpl <const DWARFDebugInfoEntry *> &failures)
5393 if (!class_type || !src_cu || !src_class_die || !dst_cu || !dst_class_die)
5395 if (src_class_die->Tag() != dst_class_die->Tag())
5398 // We need to complete the class type so we can get all of the method types
5399 // parsed so we can then unique those types to their equivalent counterparts
5400 // in "dst_cu" and "dst_class_die"
5401 class_type->GetClangFullType();
5403 const DWARFDebugInfoEntry *src_die;
5404 const DWARFDebugInfoEntry *dst_die;
5405 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die;
5406 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die;
5407 UniqueCStringMap<const DWARFDebugInfoEntry *> src_name_to_die_artificial;
5408 UniqueCStringMap<const DWARFDebugInfoEntry *> dst_name_to_die_artificial;
5409 for (src_die = src_class_die->GetFirstChild(); src_die != NULL; src_die = src_die->GetSibling())
5411 if (src_die->Tag() == DW_TAG_subprogram)
5413 // Make sure this is a declaration and not a concrete instance by looking
5414 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5415 // are placed inside the class definitions and shouldn't be included in
5416 // the list of things are are tracking here.
5417 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_declaration, 0) == 1)
5419 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
5422 ConstString src_const_name(src_name);
5423 if (src_die->GetAttributeValueAsUnsigned(src_symfile, src_cu, DW_AT_artificial, 0))
5424 src_name_to_die_artificial.Append(src_const_name.GetCString(), src_die);
5426 src_name_to_die.Append(src_const_name.GetCString(), src_die);
5431 for (dst_die = dst_class_die->GetFirstChild(); dst_die != NULL; dst_die = dst_die->GetSibling())
5433 if (dst_die->Tag() == DW_TAG_subprogram)
5435 // Make sure this is a declaration and not a concrete instance by looking
5436 // for DW_AT_declaration set to 1. Sometimes concrete function instances
5437 // are placed inside the class definitions and shouldn't be included in
5438 // the list of things are are tracking here.
5439 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_declaration, 0) == 1)
5441 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5444 ConstString dst_const_name(dst_name);
5445 if (dst_die->GetAttributeValueAsUnsigned(this, dst_cu, DW_AT_artificial, 0))
5446 dst_name_to_die_artificial.Append(dst_const_name.GetCString(), dst_die);
5448 dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
5453 const uint32_t src_size = src_name_to_die.GetSize ();
5454 const uint32_t dst_size = dst_name_to_die.GetSize ();
5455 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION));
5457 // Is everything kosher so we can go through the members at top speed?
5458 bool fast_path = true;
5460 if (src_size != dst_size)
5462 if (src_size != 0 && dst_size != 0)
5465 log->Printf("warning: trying to unique class DIE 0x%8.8x to 0x%8.8x, but they didn't have the same size (src=%d, dst=%d)",
5466 src_class_die->GetOffset(),
5467 dst_class_die->GetOffset(),
5479 for (idx = 0; idx < src_size; ++idx)
5481 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5482 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5484 if (src_die->Tag() != dst_die->Tag())
5487 log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) tags didn't match 0x%8.8x (%s)",
5488 src_class_die->GetOffset(),
5489 dst_class_die->GetOffset(),
5490 src_die->GetOffset(),
5491 DW_TAG_value_to_name(src_die->Tag()),
5492 dst_die->GetOffset(),
5493 DW_TAG_value_to_name(src_die->Tag()));
5497 const char *src_name = src_die->GetMangledName (src_symfile, src_cu);
5498 const char *dst_name = dst_die->GetMangledName (this, dst_cu);
5500 // Make sure the names match
5501 if (src_name == dst_name || (strcmp (src_name, dst_name) == 0))
5505 log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, but 0x%8.8x (%s) names didn't match 0x%8.8x (%s)",
5506 src_class_die->GetOffset(),
5507 dst_class_die->GetOffset(),
5508 src_die->GetOffset(),
5510 dst_die->GetOffset(),
5517 // Now do the work of linking the DeclContexts and Types.
5520 // We can do this quickly. Just run across the tables index-for-index since
5521 // we know each node has matching names and tags.
5522 for (idx = 0; idx < src_size; ++idx)
5524 src_die = src_name_to_die.GetValueAtIndexUnchecked (idx);
5525 dst_die = dst_name_to_die.GetValueAtIndexUnchecked (idx);
5527 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
5531 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5532 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5537 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
5540 Type *src_child_type = m_die_to_type[src_die];
5544 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
5545 m_die_to_type[dst_die] = src_child_type;
5550 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
5556 // We must do this slowly. For each member of the destination, look
5557 // up a member in the source with the same name, check its tag, and
5558 // unique them if everything matches up. Report failures.
5560 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty())
5562 src_name_to_die.Sort();
5564 for (idx = 0; idx < dst_size; ++idx)
5566 const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
5567 dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
5568 src_die = src_name_to_die.Find(dst_name, NULL);
5570 if (src_die && (src_die->Tag() == dst_die->Tag()))
5572 clang::DeclContext *src_decl_ctx = src_symfile->m_die_to_decl_ctx[src_die];
5576 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5577 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5582 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
5585 Type *src_child_type = m_die_to_type[src_die];
5589 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
5590 m_die_to_type[dst_die] = src_child_type;
5595 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
5601 log->Printf ("warning: couldn't find a match for 0x%8.8x", dst_die->GetOffset());
5603 failures.push_back(dst_die);
5609 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize ();
5610 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize ();
5612 UniqueCStringMap<const DWARFDebugInfoEntry *> name_to_die_artificial_not_in_src;
5614 if (src_size_artificial && dst_size_artificial)
5616 dst_name_to_die_artificial.Sort();
5618 for (idx = 0; idx < src_size_artificial; ++idx)
5620 const char *src_name_artificial = src_name_to_die_artificial.GetCStringAtIndex(idx);
5621 src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5622 dst_die = dst_name_to_die_artificial.Find(src_name_artificial, NULL);
5626 // Both classes have the artificial types, link them
5627 clang::DeclContext *src_decl_ctx = m_die_to_decl_ctx[src_die];
5631 log->Printf ("uniquing decl context %p from 0x%8.8x for 0x%8.8x", src_decl_ctx, src_die->GetOffset(), dst_die->GetOffset());
5632 LinkDeclContextToDIE (src_decl_ctx, dst_die);
5637 log->Printf ("warning: tried to unique decl context from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
5640 Type *src_child_type = m_die_to_type[src_die];
5644 log->Printf ("uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", src_child_type, src_child_type->GetID(), src_die->GetOffset(), dst_die->GetOffset());
5645 m_die_to_type[dst_die] = src_child_type;
5650 log->Printf ("warning: tried to unique lldb_private::Type from 0x%8.8x for 0x%8.8x, but none was found", src_die->GetOffset(), dst_die->GetOffset());
5656 if (dst_size_artificial)
5658 for (idx = 0; idx < dst_size_artificial; ++idx)
5660 const char *dst_name_artificial = dst_name_to_die_artificial.GetCStringAtIndex(idx);
5661 dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked (idx);
5663 log->Printf ("warning: need to create artificial method for 0x%8.8x for method '%s'", dst_die->GetOffset(), dst_name_artificial);
5665 failures.push_back(dst_die);
5669 return (failures.size() != 0);
5673 SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
5677 if (type_is_new_ptr)
5678 *type_is_new_ptr = false;
5680 #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5681 static DIEStack g_die_stack;
5682 DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
5685 AccessType accessibility = eAccessNone;
5688 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
5691 const DWARFDebugInfoEntry *context_die;
5692 clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
5694 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')",
5697 context_die->GetOffset(),
5698 DW_TAG_value_to_name(die->Tag()),
5699 die->GetName(this, dwarf_cu));
5701 #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
5702 scoped_die_logger.Push (dwarf_cu, die);
5703 g_die_stack.LogDIEs(log, this);
5707 // Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
5708 // if (log && dwarf_cu)
5711 // die->DumpLocation (this, dwarf_cu, s);
5712 // GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
5716 Type *type_ptr = m_die_to_type.lookup (die);
5717 TypeList* type_list = GetTypeList();
5718 if (type_ptr == NULL)
5720 ClangASTContext &ast = GetClangASTContext();
5721 if (type_is_new_ptr)
5722 *type_is_new_ptr = true;
5724 const dw_tag_t tag = die->Tag();
5726 bool is_forward_declaration = false;
5727 DWARFDebugInfoEntry::Attributes attributes;
5728 const char *type_name_cstr = NULL;
5729 ConstString type_name_const_str;
5730 Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
5731 uint64_t byte_size = 0;
5734 Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
5735 ClangASTType clang_type;
5741 case DW_TAG_base_type:
5742 case DW_TAG_pointer_type:
5743 case DW_TAG_reference_type:
5744 case DW_TAG_rvalue_reference_type:
5745 case DW_TAG_typedef:
5746 case DW_TAG_const_type:
5747 case DW_TAG_restrict_type:
5748 case DW_TAG_volatile_type:
5749 case DW_TAG_unspecified_type:
5751 // Set a bit that lets us know that we are currently parsing this
5752 m_die_to_type[die] = DIE_IS_BEING_PARSED;
5754 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
5755 uint32_t encoding = 0;
5756 lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
5758 if (num_attributes > 0)
5761 for (i=0; i<num_attributes; ++i)
5763 attr = attributes.AttributeAtIndex(i);
5764 DWARFFormValue form_value;
5765 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5769 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5770 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
5771 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5774 type_name_cstr = form_value.AsCString(&get_debug_str_data());
5775 // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
5776 // include the "&"...
5777 if (tag == DW_TAG_reference_type)
5779 if (strchr (type_name_cstr, '&') == NULL)
5780 type_name_cstr = NULL;
5783 type_name_const_str.SetCString(type_name_cstr);
5785 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
5786 case DW_AT_encoding: encoding = form_value.Unsigned(); break;
5787 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
5796 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8lx\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid);
5803 case DW_TAG_unspecified_type:
5804 if (strcmp(type_name_cstr, "nullptr_t") == 0 ||
5805 strcmp(type_name_cstr, "decltype(nullptr)") == 0 )
5807 resolve_state = Type::eResolveStateFull;
5808 clang_type = ast.GetBasicType(eBasicTypeNullPtr);
5811 // Fall through to base type below in case we can handle the type there...
5813 case DW_TAG_base_type:
5814 resolve_state = Type::eResolveStateFull;
5815 clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
5820 case DW_TAG_pointer_type: encoding_data_type = Type::eEncodingIsPointerUID; break;
5821 case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID; break;
5822 case DW_TAG_rvalue_reference_type: encoding_data_type = Type::eEncodingIsRValueReferenceUID; break;
5823 case DW_TAG_typedef: encoding_data_type = Type::eEncodingIsTypedefUID; break;
5824 case DW_TAG_const_type: encoding_data_type = Type::eEncodingIsConstUID; break;
5825 case DW_TAG_restrict_type: encoding_data_type = Type::eEncodingIsRestrictUID; break;
5826 case DW_TAG_volatile_type: encoding_data_type = Type::eEncodingIsVolatileUID; break;
5829 if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID) && sc.comp_unit != NULL)
5831 bool translation_unit_is_objc = (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus);
5833 if (translation_unit_is_objc)
5835 if (type_name_cstr != NULL)
5837 static ConstString g_objc_type_name_id("id");
5838 static ConstString g_objc_type_name_Class("Class");
5839 static ConstString g_objc_type_name_selector("SEL");
5841 if (type_name_const_str == g_objc_type_name_id)
5844 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
5846 DW_TAG_value_to_name(die->Tag()),
5847 die->GetName(this, dwarf_cu));
5848 clang_type = ast.GetBasicType(eBasicTypeObjCID);
5849 encoding_data_type = Type::eEncodingIsUID;
5850 encoding_uid = LLDB_INVALID_UID;
5851 resolve_state = Type::eResolveStateFull;
5854 else if (type_name_const_str == g_objc_type_name_Class)
5857 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
5859 DW_TAG_value_to_name(die->Tag()),
5860 die->GetName(this, dwarf_cu));
5861 clang_type = ast.GetBasicType(eBasicTypeObjCClass);
5862 encoding_data_type = Type::eEncodingIsUID;
5863 encoding_uid = LLDB_INVALID_UID;
5864 resolve_state = Type::eResolveStateFull;
5866 else if (type_name_const_str == g_objc_type_name_selector)
5869 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
5871 DW_TAG_value_to_name(die->Tag()),
5872 die->GetName(this, dwarf_cu));
5873 clang_type = ast.GetBasicType(eBasicTypeObjCSel);
5874 encoding_data_type = Type::eEncodingIsUID;
5875 encoding_uid = LLDB_INVALID_UID;
5876 resolve_state = Type::eResolveStateFull;
5879 else if (encoding_data_type == Type::eEncodingIsPointerUID && encoding_uid != LLDB_INVALID_UID)
5881 // Clang sometimes erroneously emits id as objc_object*. In that case we fix up the type to "id".
5883 DWARFDebugInfoEntry* encoding_die = dwarf_cu->GetDIEPtr(encoding_uid);
5885 if (encoding_die && encoding_die->Tag() == DW_TAG_structure_type)
5887 if (const char *struct_name = encoding_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL))
5889 if (!strcmp(struct_name, "objc_object"))
5892 GetObjectFile()->GetModule()->LogMessage (log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is 'objc_object*', which we overrode to 'id'.",
5894 DW_TAG_value_to_name(die->Tag()),
5895 die->GetName(this, dwarf_cu));
5896 clang_type = ast.GetBasicType(eBasicTypeObjCID);
5897 encoding_data_type = Type::eEncodingIsUID;
5898 encoding_uid = LLDB_INVALID_UID;
5899 resolve_state = Type::eResolveStateFull;
5907 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
5909 type_name_const_str,
5918 m_die_to_type[die] = type_sp.get();
5920 // Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
5921 // if (encoding_type != NULL)
5923 // if (encoding_type != DIE_IS_BEING_PARSED)
5924 // type_sp->SetEncodingType(encoding_type);
5926 // m_indirect_fixups.push_back(type_sp.get());
5931 case DW_TAG_structure_type:
5932 case DW_TAG_union_type:
5933 case DW_TAG_class_type:
5935 // Set a bit that lets us know that we are currently parsing this
5936 m_die_to_type[die] = DIE_IS_BEING_PARSED;
5937 bool byte_size_valid = false;
5939 LanguageType class_language = eLanguageTypeUnknown;
5940 bool is_complete_objc_class = false;
5941 //bool struct_is_class = false;
5942 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
5943 if (num_attributes > 0)
5946 for (i=0; i<num_attributes; ++i)
5948 attr = attributes.AttributeAtIndex(i);
5949 DWARFFormValue form_value;
5950 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5954 case DW_AT_decl_file:
5955 if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
5957 // llvm-gcc outputs invalid DW_AT_decl_file attributes that always
5958 // point to the compile unit file, so we clear this invalid value
5959 // so that we can still unique types efficiently.
5960 decl.SetFile(FileSpec ("<invalid>", false));
5963 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
5966 case DW_AT_decl_line:
5967 decl.SetLine(form_value.Unsigned());
5970 case DW_AT_decl_column:
5971 decl.SetColumn(form_value.Unsigned());
5975 type_name_cstr = form_value.AsCString(&get_debug_str_data());
5976 type_name_const_str.SetCString(type_name_cstr);
5979 case DW_AT_byte_size:
5980 byte_size = form_value.Unsigned();
5981 byte_size_valid = true;
5984 case DW_AT_accessibility:
5985 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
5988 case DW_AT_declaration:
5989 is_forward_declaration = form_value.Boolean();
5992 case DW_AT_APPLE_runtime_class:
5993 class_language = (LanguageType)form_value.Signed();
5996 case DW_AT_APPLE_objc_complete_type:
5997 is_complete_objc_class = form_value.Signed();
6000 case DW_AT_allocated:
6001 case DW_AT_associated:
6002 case DW_AT_data_location:
6003 case DW_AT_description:
6004 case DW_AT_start_scope:
6005 case DW_AT_visibility:
6014 UniqueDWARFASTType unique_ast_entry;
6016 // Only try and unique the type if it has a name.
6017 if (type_name_const_str &&
6018 GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
6023 byte_size_valid ? byte_size : -1,
6026 // We have already parsed this type or from another
6027 // compile unit. GCC loves to use the "one definition
6028 // rule" which can result in multiple definitions
6029 // of the same class over and over in each compile
6031 type_sp = unique_ast_entry.m_type_sp;
6034 m_die_to_type[die] = type_sp.get();
6039 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
6041 int tag_decl_kind = -1;
6042 AccessType default_accessibility = eAccessNone;
6043 if (tag == DW_TAG_structure_type)
6045 tag_decl_kind = clang::TTK_Struct;
6046 default_accessibility = eAccessPublic;
6048 else if (tag == DW_TAG_union_type)
6050 tag_decl_kind = clang::TTK_Union;
6051 default_accessibility = eAccessPublic;
6053 else if (tag == DW_TAG_class_type)
6055 tag_decl_kind = clang::TTK_Class;
6056 default_accessibility = eAccessPrivate;
6059 if (byte_size_valid && byte_size == 0 && type_name_cstr &&
6060 die->HasChildren() == false &&
6061 sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
6063 // Work around an issue with clang at the moment where
6064 // forward declarations for objective C classes are emitted
6066 // DW_TAG_structure_type [2]
6067 // DW_AT_name( "ForwardObjcClass" )
6068 // DW_AT_byte_size( 0x00 )
6069 // DW_AT_decl_file( "..." )
6070 // DW_AT_decl_line( 1 )
6072 // Note that there is no DW_AT_declaration and there are
6073 // no children, and the byte size is zero.
6074 is_forward_declaration = true;
6077 if (class_language == eLanguageTypeObjC ||
6078 class_language == eLanguageTypeObjC_plus_plus)
6080 if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
6082 // We have a valid eSymbolTypeObjCClass class symbol whose
6083 // name matches the current objective C class that we
6084 // are trying to find and this DIE isn't the complete
6085 // definition (we checked is_complete_objc_class above and
6086 // know it is false), so the real definition is in here somewhere
6087 type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
6089 if (!type_sp && GetDebugMapSymfile ())
6091 // We weren't able to find a full declaration in
6092 // this DWARF, see if we have a declaration anywhere
6094 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
6101 GetObjectFile()->GetModule()->LogMessage (log,
6102 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8" PRIx64,
6105 DW_TAG_value_to_name(tag),
6110 // We found a real definition for this type elsewhere
6111 // so lets use it and cache the fact that we found
6112 // a complete type for this die
6113 m_die_to_type[die] = type_sp.get();
6120 if (is_forward_declaration)
6122 // We have a forward declaration to a type and we need
6123 // to try and find a full declaration. We look in the
6124 // current type index just in case we have a forward
6125 // declaration followed by an actual declarations in the
6126 // DWARF. If this fails, we need to look elsewhere...
6129 GetObjectFile()->GetModule()->LogMessage (log,
6130 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
6133 DW_TAG_value_to_name(tag),
6137 DWARFDeclContext die_decl_ctx;
6138 die->GetDWARFDeclContext(this, dwarf_cu, die_decl_ctx);
6140 //type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
6141 type_sp = FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
6143 if (!type_sp && GetDebugMapSymfile ())
6145 // We weren't able to find a full declaration in
6146 // this DWARF, see if we have a declaration anywhere
6148 type_sp = m_debug_map_symfile->FindDefinitionTypeForDWARFDeclContext (die_decl_ctx);
6155 GetObjectFile()->GetModule()->LogMessage (log,
6156 "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8" PRIx64,
6159 DW_TAG_value_to_name(tag),
6164 // We found a real definition for this type elsewhere
6165 // so lets use it and cache the fact that we found
6166 // a complete type for this die
6167 m_die_to_type[die] = type_sp.get();
6171 assert (tag_decl_kind != -1);
6172 bool clang_type_was_created = false;
6173 clang_type.SetClangType(ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6176 const DWARFDebugInfoEntry *decl_ctx_die;
6178 clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
6179 if (accessibility == eAccessNone && decl_ctx)
6181 // Check the decl context that contains this class/struct/union.
6182 // If it is a class we must give it an accessability.
6183 const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
6184 if (DeclKindIsCXXClass (containing_decl_kind))
6185 accessibility = default_accessibility;
6188 ClangASTMetadata metadata;
6189 metadata.SetUserID(MakeUserID(die->GetOffset()));
6190 metadata.SetIsDynamicCXXType(ClassOrStructIsVirtual (dwarf_cu, die));
6192 if (type_name_cstr && strchr (type_name_cstr, '<'))
6194 ClangASTContext::TemplateParameterInfos template_param_infos;
6195 if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
6197 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
6201 template_param_infos);
6203 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
6204 class_template_decl,
6206 template_param_infos);
6207 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
6208 clang_type_was_created = true;
6210 GetClangASTContext().SetMetadata (class_template_decl, metadata);
6211 GetClangASTContext().SetMetadata (class_specialization_decl, metadata);
6215 if (!clang_type_was_created)
6217 clang_type_was_created = true;
6218 clang_type = ast.CreateRecordType (decl_ctx,
6227 // Store a forward declaration to this class type in case any
6228 // parameters in any class methods need it for the clang
6229 // types for function prototypes.
6230 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
6231 type_sp.reset (new Type (MakeUserID(die->GetOffset()),
6233 type_name_const_str,
6237 Type::eEncodingIsUID,
6240 Type::eResolveStateForward));
6242 type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
6245 // Add our type to the unique type map so we don't
6246 // end up creating many copies of the same type over
6247 // and over in the ASTContext for our module
6248 unique_ast_entry.m_type_sp = type_sp;
6249 unique_ast_entry.m_symfile = this;
6250 unique_ast_entry.m_cu = dwarf_cu;
6251 unique_ast_entry.m_die = die;
6252 unique_ast_entry.m_declaration = decl;
6253 unique_ast_entry.m_byte_size = byte_size;
6254 GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
6257 if (is_forward_declaration && die->HasChildren())
6259 // Check to see if the DIE actually has a definition, some version of GCC will
6260 // emit DIEs with DW_AT_declaration set to true, but yet still have subprogram,
6261 // members, or inheritance, so we can't trust it
6262 const DWARFDebugInfoEntry *child_die = die->GetFirstChild();
6265 switch (child_die->Tag())
6267 case DW_TAG_inheritance:
6268 case DW_TAG_subprogram:
6270 case DW_TAG_APPLE_property:
6271 case DW_TAG_class_type:
6272 case DW_TAG_structure_type:
6273 case DW_TAG_enumeration_type:
6274 case DW_TAG_typedef:
6275 case DW_TAG_union_type:
6277 is_forward_declaration = false;
6280 child_die = child_die->GetSibling();
6286 if (!is_forward_declaration)
6288 // Always start the definition for a class type so that
6289 // if the class has child classes or types that require
6290 // the class to be created for use as their decl contexts
6291 // the class will be ready to accept these child definitions.
6292 if (die->HasChildren() == false)
6294 // No children for this struct/union/class, lets finish it
6295 clang_type.StartTagDeclarationDefinition ();
6296 clang_type.CompleteTagDeclarationDefinition ();
6298 if (tag == DW_TAG_structure_type) // this only applies in C
6300 clang::RecordDecl *record_decl = clang_type.GetAsRecordDecl();
6304 LayoutInfo layout_info;
6306 layout_info.alignment = 0;
6307 layout_info.bit_size = 0;
6309 m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
6313 else if (clang_type_was_created)
6315 // Start the definition if the class is not objective C since
6316 // the underlying decls respond to isCompleteDefinition(). Objective
6317 // C decls dont' respond to isCompleteDefinition() so we can't
6318 // start the declaration definition right away. For C++ classs/union/structs
6319 // we want to start the definition in case the class is needed as the
6320 // declaration context for a contained class or type without the need
6321 // to complete that type..
6323 if (class_language != eLanguageTypeObjC &&
6324 class_language != eLanguageTypeObjC_plus_plus)
6325 clang_type.StartTagDeclarationDefinition ();
6327 // Leave this as a forward declaration until we need
6328 // to know the details of the type. lldb_private::Type
6329 // will automatically call the SymbolFile virtual function
6330 // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
6331 // When the definition needs to be defined.
6332 m_forward_decl_die_to_clang_type[die] = clang_type.GetOpaqueQualType();
6333 m_forward_decl_clang_type_to_die[clang_type.RemoveFastQualifiers().GetOpaqueQualType()] = die;
6334 clang_type.SetHasExternalStorage (true);
6341 case DW_TAG_enumeration_type:
6343 // Set a bit that lets us know that we are currently parsing this
6344 m_die_to_type[die] = DIE_IS_BEING_PARSED;
6346 lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
6348 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
6349 if (num_attributes > 0)
6353 for (i=0; i<num_attributes; ++i)
6355 attr = attributes.AttributeAtIndex(i);
6356 DWARFFormValue form_value;
6357 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6361 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6362 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6363 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6365 type_name_cstr = form_value.AsCString(&get_debug_str_data());
6366 type_name_const_str.SetCString(type_name_cstr);
6368 case DW_AT_type: encoding_uid = form_value.Reference(dwarf_cu); break;
6369 case DW_AT_byte_size: byte_size = form_value.Unsigned(); break;
6370 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6371 case DW_AT_declaration: break; //is_forward_declaration = form_value.Boolean(); break;
6372 case DW_AT_allocated:
6373 case DW_AT_associated:
6374 case DW_AT_bit_stride:
6375 case DW_AT_byte_stride:
6376 case DW_AT_data_location:
6377 case DW_AT_description:
6378 case DW_AT_start_scope:
6379 case DW_AT_visibility:
6380 case DW_AT_specification:
6381 case DW_AT_abstract_origin:
6388 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
6390 ClangASTType enumerator_clang_type;
6391 clang_type.SetClangType (ast.getASTContext(), m_forward_decl_die_to_clang_type.lookup (die));
6394 if (encoding_uid != DW_INVALID_OFFSET)
6396 Type *enumerator_type = ResolveTypeUID(encoding_uid);
6397 if (enumerator_type)
6398 enumerator_clang_type = enumerator_type->GetClangFullType();
6401 if (!enumerator_clang_type)
6402 enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
6406 clang_type = ast.CreateEnumerationType (type_name_cstr,
6407 GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
6409 enumerator_clang_type);
6413 enumerator_clang_type = clang_type.GetEnumerationIntegerType ();
6416 LinkDeclContextToDIE(clang_type.GetDeclContextForType(), die);
6418 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
6420 type_name_const_str,
6424 Type::eEncodingIsUID,
6427 Type::eResolveStateForward));
6429 clang_type.StartTagDeclarationDefinition ();
6430 if (die->HasChildren())
6432 SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
6433 bool is_signed = false;
6434 enumerator_clang_type.IsIntegerType(is_signed);
6435 ParseChildEnumerators(cu_sc, clang_type, is_signed, type_sp->GetByteSize(), dwarf_cu, die);
6437 clang_type.CompleteTagDeclarationDefinition ();
6442 case DW_TAG_inlined_subroutine:
6443 case DW_TAG_subprogram:
6444 case DW_TAG_subroutine_type:
6446 // Set a bit that lets us know that we are currently parsing this
6447 m_die_to_type[die] = DIE_IS_BEING_PARSED;
6449 //const char *mangled = NULL;
6450 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
6451 bool is_variadic = false;
6452 bool is_inline = false;
6453 bool is_static = false;
6454 bool is_virtual = false;
6455 bool is_explicit = false;
6456 bool is_artificial = false;
6457 dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
6458 dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
6459 dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET;
6461 unsigned type_quals = 0;
6462 clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
6465 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
6466 if (num_attributes > 0)
6469 for (i=0; i<num_attributes; ++i)
6471 attr = attributes.AttributeAtIndex(i);
6472 DWARFFormValue form_value;
6473 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6477 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6478 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6479 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6481 type_name_cstr = form_value.AsCString(&get_debug_str_data());
6482 type_name_const_str.SetCString(type_name_cstr);
6485 case DW_AT_linkage_name:
6486 case DW_AT_MIPS_linkage_name: break; // mangled = form_value.AsCString(&get_debug_str_data()); break;
6487 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
6488 case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6489 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6490 case DW_AT_inline: is_inline = form_value.Boolean(); break;
6491 case DW_AT_virtuality: is_virtual = form_value.Boolean(); break;
6492 case DW_AT_explicit: is_explicit = form_value.Boolean(); break;
6493 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
6496 case DW_AT_external:
6497 if (form_value.Unsigned())
6499 if (storage == clang::SC_None)
6500 storage = clang::SC_Extern;
6502 storage = clang::SC_PrivateExtern;
6506 case DW_AT_specification:
6507 specification_die_offset = form_value.Reference(dwarf_cu);
6510 case DW_AT_abstract_origin:
6511 abstract_origin_die_offset = form_value.Reference(dwarf_cu);
6514 case DW_AT_object_pointer:
6515 object_pointer_die_offset = form_value.Reference(dwarf_cu);
6518 case DW_AT_allocated:
6519 case DW_AT_associated:
6520 case DW_AT_address_class:
6521 case DW_AT_calling_convention:
6522 case DW_AT_data_location:
6523 case DW_AT_elemental:
6524 case DW_AT_entry_pc:
6525 case DW_AT_frame_base:
6528 case DW_AT_prototyped:
6531 case DW_AT_recursive:
6532 case DW_AT_return_addr:
6534 case DW_AT_start_scope:
6535 case DW_AT_static_link:
6536 case DW_AT_trampoline:
6537 case DW_AT_visibility:
6538 case DW_AT_vtable_elem_location:
6539 case DW_AT_description:
6547 std::string object_pointer_name;
6548 if (object_pointer_die_offset != DW_INVALID_OFFSET)
6550 // Get the name from the object pointer die
6552 if (DWARFDebugInfoEntry::GetName (this, dwarf_cu, object_pointer_die_offset, s))
6554 object_pointer_name.assign(s.GetData());
6558 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
6560 ClangASTType return_clang_type;
6561 Type *func_type = NULL;
6563 if (type_die_offset != DW_INVALID_OFFSET)
6564 func_type = ResolveTypeUID(type_die_offset);
6567 return_clang_type = func_type->GetClangForwardType();
6569 return_clang_type = ast.GetBasicType(eBasicTypeVoid);
6572 std::vector<ClangASTType> function_param_types;
6573 std::vector<clang::ParmVarDecl*> function_param_decls;
6575 // Parse the function children for the parameters
6577 const DWARFDebugInfoEntry *decl_ctx_die = NULL;
6578 clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
6579 const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
6581 const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
6582 // Start off static. This will be set to false in ParseChildParameters(...)
6583 // if we find a "this" paramters as the first parameter
6586 ClangASTContext::TemplateParameterInfos template_param_infos;
6588 if (die->HasChildren())
6590 bool skip_artificial = true;
6591 ParseChildParameters (sc,
6592 containing_decl_ctx,
6599 function_param_types,
6600 function_param_decls,
6602 template_param_infos);
6605 // clang_type will get the function prototype clang type after this call
6606 clang_type = ast.CreateFunctionType (return_clang_type,
6607 function_param_types.data(),
6608 function_param_types.size(),
6612 bool ignore_containing_context = false;
6616 bool type_handled = false;
6617 if (tag == DW_TAG_subprogram)
6619 ObjCLanguageRuntime::MethodName objc_method (type_name_cstr, true);
6620 if (objc_method.IsValid(true))
6622 SymbolContext empty_sc;
6623 ClangASTType class_opaque_type;
6624 ConstString class_name(objc_method.GetClassName());
6628 TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
6630 if (complete_objc_class_type_sp)
6632 ClangASTType type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
6633 if (type_clang_forward_type.IsObjCObjectOrInterfaceType ())
6634 class_opaque_type = type_clang_forward_type;
6638 if (class_opaque_type)
6640 // If accessibility isn't set to anything valid, assume public for
6642 if (accessibility == eAccessNone)
6643 accessibility = eAccessPublic;
6645 clang::ObjCMethodDecl *objc_method_decl = class_opaque_type.AddMethodToObjCObjectType (type_name_cstr,
6649 type_handled = objc_method_decl != NULL;
6652 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
6653 GetClangASTContext().SetMetadataAsUserID (objc_method_decl, MakeUserID(die->GetOffset()));
6657 GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: invalid Objective-C method 0x%4.4x (%s), please file a bug and attach the file at the start of this error message",
6660 DW_TAG_value_to_name(tag));
6664 else if (is_cxx_method)
6666 // Look at the parent of this DIE and see if is is
6667 // a class or struct and see if this is actually a
6669 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
6672 if (class_type->GetID() != MakeUserID(decl_ctx_die->GetOffset()))
6674 // We uniqued the parent class of this function to another class
6675 // so we now need to associate all dies under "decl_ctx_die" to
6676 // DIEs in the DIE for "class_type"...
6677 SymbolFileDWARF *class_symfile = NULL;
6678 DWARFCompileUnitSP class_type_cu_sp;
6679 const DWARFDebugInfoEntry *class_type_die = NULL;
6681 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
6682 if (debug_map_symfile)
6684 class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex(SymbolFileDWARFDebugMap::GetOSOIndexFromUserID(class_type->GetID()));
6685 class_type_die = class_symfile->DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6689 class_symfile = this;
6690 class_type_die = DebugInfo()->GetDIEPtr(class_type->GetID(), &class_type_cu_sp);
6694 llvm::SmallVector<const DWARFDebugInfoEntry *, 0> failures;
6696 CopyUniqueClassMethodTypes (class_symfile,
6698 class_type_cu_sp.get(),
6704 // FIXME do something with these failures that's smarter than
6705 // just dropping them on the ground. Unfortunately classes don't
6706 // like having stuff added to them after their definitions are
6709 type_ptr = m_die_to_type[die];
6710 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
6712 type_sp = type_ptr->shared_from_this();
6718 if (specification_die_offset != DW_INVALID_OFFSET)
6720 // We have a specification which we are going to base our function
6721 // prototype off of, so we need this type to be completed so that the
6722 // m_die_to_decl_ctx for the method in the specification has a valid
6723 // clang decl context.
6724 class_type->GetClangForwardType();
6725 // If we have a specification, then the function type should have been
6726 // made with the specification and not with this die.
6727 DWARFCompileUnitSP spec_cu_sp;
6728 const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
6729 clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
6730 if (spec_clang_decl_ctx)
6732 LinkDeclContextToDIE(spec_clang_decl_ctx, die);
6736 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x) has no decl\n",
6737 MakeUserID(die->GetOffset()),
6738 specification_die_offset);
6740 type_handled = true;
6742 else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
6744 // We have a specification which we are going to base our function
6745 // prototype off of, so we need this type to be completed so that the
6746 // m_die_to_decl_ctx for the method in the abstract origin has a valid
6747 // clang decl context.
6748 class_type->GetClangForwardType();
6750 DWARFCompileUnitSP abs_cu_sp;
6751 const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
6752 clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
6753 if (abs_clang_decl_ctx)
6755 LinkDeclContextToDIE (abs_clang_decl_ctx, die);
6759 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8x) has no decl\n",
6760 MakeUserID(die->GetOffset()),
6761 abstract_origin_die_offset);
6763 type_handled = true;
6767 ClangASTType class_opaque_type = class_type->GetClangForwardType();
6768 if (class_opaque_type.IsCXXClassType ())
6770 if (class_opaque_type.IsBeingDefined ())
6772 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
6773 // in the DWARF for C++ methods... Default to public for now...
6774 if (accessibility == eAccessNone)
6775 accessibility = eAccessPublic;
6777 if (!is_static && !die->HasChildren())
6779 // We have a C++ member function with no children (this pointer!)
6780 // and clang will get mad if we try and make a function that isn't
6781 // well formed in the DWARF, so we will just skip it...
6782 type_handled = true;
6786 clang::CXXMethodDecl *cxx_method_decl;
6787 // REMOVE THE CRASH DESCRIPTION BELOW
6788 Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8" PRIx64 " from %s",
6790 class_type->GetName().GetCString(),
6791 MakeUserID(die->GetOffset()),
6792 m_obj_file->GetFileSpec().GetPath().c_str());
6794 const bool is_attr_used = false;
6796 cxx_method_decl = class_opaque_type.AddMethodToCXXRecordType (type_name_cstr,
6806 type_handled = cxx_method_decl != NULL;
6810 LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
6812 Host::SetCrashDescription (NULL);
6815 ClangASTMetadata metadata;
6816 metadata.SetUserID(MakeUserID(die->GetOffset()));
6818 if (!object_pointer_name.empty())
6820 metadata.SetObjectPtrName(object_pointer_name.c_str());
6822 log->Printf ("Setting object pointer name: %s on method object %p.\n",
6823 object_pointer_name.c_str(),
6826 GetClangASTContext().SetMetadata (cxx_method_decl, metadata);
6830 ignore_containing_context = true;
6836 // We were asked to parse the type for a method in a class, yet the
6837 // class hasn't been asked to complete itself through the
6838 // clang::ExternalASTSource protocol, so we need to just have the
6839 // class complete itself and do things the right way, then our
6840 // DIE should then have an entry in the m_die_to_type map. First
6841 // we need to modify the m_die_to_type so it doesn't think we are
6842 // trying to parse this DIE anymore...
6843 m_die_to_type[die] = NULL;
6845 // Now we get the full type to force our class type to complete itself
6846 // using the clang::ExternalASTSource protocol which will parse all
6847 // base classes and all methods (including the method for this DIE).
6848 class_type->GetClangFullType();
6850 // The type for this DIE should have been filled in the function call above
6851 type_ptr = m_die_to_type[die];
6852 if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
6854 type_sp = type_ptr->shared_from_this();
6858 // FIXME This is fixing some even uglier behavior but we really need to
6859 // uniq the methods of each class as well as the class itself.
6860 // <rdar://problem/11240464>
6861 type_handled = true;
6871 // We just have a function that isn't part of a class
6872 clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (ignore_containing_context ? GetClangASTContext().GetTranslationUnitDecl() : containing_decl_ctx,
6878 // if (template_param_infos.GetSize() > 0)
6880 // clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
6883 // template_param_infos);
6885 // ast.CreateFunctionTemplateSpecializationInfo (function_decl,
6886 // func_template_decl,
6887 // template_param_infos);
6889 // Add the decl to our DIE to decl context map
6890 assert (function_decl);
6891 LinkDeclContextToDIE(function_decl, die);
6892 if (!function_param_decls.empty())
6893 ast.SetFunctionParameters (function_decl,
6894 &function_param_decls.front(),
6895 function_param_decls.size());
6897 ClangASTMetadata metadata;
6898 metadata.SetUserID(MakeUserID(die->GetOffset()));
6900 if (!object_pointer_name.empty())
6902 metadata.SetObjectPtrName(object_pointer_name.c_str());
6904 log->Printf ("Setting object pointer name: %s on function object %p.",
6905 object_pointer_name.c_str(),
6908 GetClangASTContext().SetMetadata (function_decl, metadata);
6911 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
6913 type_name_const_str,
6917 Type::eEncodingIsUID,
6920 Type::eResolveStateFull));
6921 assert(type_sp.get());
6925 case DW_TAG_array_type:
6927 // Set a bit that lets us know that we are currently parsing this
6928 m_die_to_type[die] = DIE_IS_BEING_PARSED;
6930 lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
6931 int64_t first_index = 0;
6932 uint32_t byte_stride = 0;
6933 uint32_t bit_stride = 0;
6934 bool is_vector = false;
6935 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
6937 if (num_attributes > 0)
6940 for (i=0; i<num_attributes; ++i)
6942 attr = attributes.AttributeAtIndex(i);
6943 DWARFFormValue form_value;
6944 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6948 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6949 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
6950 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6952 type_name_cstr = form_value.AsCString(&get_debug_str_data());
6953 type_name_const_str.SetCString(type_name_cstr);
6956 case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break;
6957 case DW_AT_byte_size: break; // byte_size = form_value.Unsigned(); break;
6958 case DW_AT_byte_stride: byte_stride = form_value.Unsigned(); break;
6959 case DW_AT_bit_stride: bit_stride = form_value.Unsigned(); break;
6960 case DW_AT_GNU_vector: is_vector = form_value.Boolean(); break;
6961 case DW_AT_accessibility: break; // accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6962 case DW_AT_declaration: break; // is_forward_declaration = form_value.Boolean(); break;
6963 case DW_AT_allocated:
6964 case DW_AT_associated:
6965 case DW_AT_data_location:
6966 case DW_AT_description:
6967 case DW_AT_ordering:
6968 case DW_AT_start_scope:
6969 case DW_AT_visibility:
6970 case DW_AT_specification:
6971 case DW_AT_abstract_origin:
6978 DEBUG_PRINTF ("0x%8.8" PRIx64 ": %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
6980 Type *element_type = ResolveTypeUID(type_die_offset);
6984 std::vector<uint64_t> element_orders;
6985 ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
6986 if (byte_stride == 0 && bit_stride == 0)
6987 byte_stride = element_type->GetByteSize();
6988 ClangASTType array_element_type = element_type->GetClangForwardType();
6989 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
6990 uint64_t num_elements = 0;
6991 std::vector<uint64_t>::const_reverse_iterator pos;
6992 std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
6993 for (pos = element_orders.rbegin(); pos != end; ++pos)
6995 num_elements = *pos;
6996 clang_type = ast.CreateArrayType (array_element_type,
6999 array_element_type = clang_type;
7000 array_element_bit_stride = num_elements ? array_element_bit_stride * num_elements : array_element_bit_stride;
7002 ConstString empty_name;
7003 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
7006 array_element_bit_stride / 8,
7009 Type::eEncodingIsUID,
7012 Type::eResolveStateFull));
7013 type_sp->SetEncodingType (element_type);
7019 case DW_TAG_ptr_to_member_type:
7021 dw_offset_t type_die_offset = DW_INVALID_OFFSET;
7022 dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
7024 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7026 if (num_attributes > 0) {
7028 for (i=0; i<num_attributes; ++i)
7030 attr = attributes.AttributeAtIndex(i);
7031 DWARFFormValue form_value;
7032 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
7037 type_die_offset = form_value.Reference(dwarf_cu); break;
7038 case DW_AT_containing_type:
7039 containing_type_die_offset = form_value.Reference(dwarf_cu); break;
7044 Type *pointee_type = ResolveTypeUID(type_die_offset);
7045 Type *class_type = ResolveTypeUID(containing_type_die_offset);
7047 ClangASTType pointee_clang_type = pointee_type->GetClangForwardType();
7048 ClangASTType class_clang_type = class_type->GetClangLayoutType();
7050 clang_type = pointee_clang_type.CreateMemberPointerType(class_clang_type);
7052 byte_size = clang_type.GetByteSize();
7054 type_sp.reset( new Type (MakeUserID(die->GetOffset()),
7056 type_name_const_str,
7060 Type::eEncodingIsUID,
7063 Type::eResolveStateForward));
7069 GetObjectFile()->GetModule()->ReportError ("{0x%8.8x}: unhandled type tag 0x%4.4x (%s), please file a bug and attach the file at the start of this error message",
7072 DW_TAG_value_to_name(tag));
7078 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7079 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7081 SymbolContextScope * symbol_context_scope = NULL;
7082 if (sc_parent_tag == DW_TAG_compile_unit)
7084 symbol_context_scope = sc.comp_unit;
7086 else if (sc.function != NULL)
7088 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7089 if (symbol_context_scope == NULL)
7090 symbol_context_scope = sc.function;
7093 if (symbol_context_scope != NULL)
7095 type_sp->SetSymbolContextScope(symbol_context_scope);
7098 // We are ready to put this type into the uniqued list up at the module level
7099 type_list->Insert (type_sp);
7101 m_die_to_type[die] = type_sp.get();
7104 else if (type_ptr != DIE_IS_BEING_PARSED)
7106 type_sp = type_ptr->shared_from_this();
7113 SymbolFileDWARF::ParseTypes
7115 const SymbolContext& sc,
7116 DWARFCompileUnit* dwarf_cu,
7117 const DWARFDebugInfoEntry *die,
7118 bool parse_siblings,
7122 size_t types_added = 0;
7125 bool type_is_new = false;
7126 if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
7132 if (parse_children && die->HasChildren())
7134 if (die->Tag() == DW_TAG_subprogram)
7136 SymbolContext child_sc(sc);
7137 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
7138 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
7141 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
7145 die = die->GetSibling();
7154 SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
7156 assert(sc.comp_unit && sc.function);
7157 size_t functions_added = 0;
7158 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
7161 dw_offset_t function_die_offset = sc.function->GetID();
7162 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
7165 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
7169 return functions_added;
7174 SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
7176 // At least a compile unit must be valid
7177 assert(sc.comp_unit);
7178 size_t types_added = 0;
7179 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
7184 dw_offset_t function_die_offset = sc.function->GetID();
7185 const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
7186 if (func_die && func_die->HasChildren())
7188 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
7193 const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
7194 if (dwarf_cu_die && dwarf_cu_die->HasChildren())
7196 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
7205 SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
7207 if (sc.comp_unit != NULL)
7209 DWARFDebugInfo* info = DebugInfo();
7215 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitContainingDIE(sc.function->GetID()).get();
7217 if (dwarf_cu == NULL)
7220 const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
7222 dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, LLDB_INVALID_ADDRESS);
7223 if (func_lo_pc != LLDB_INVALID_ADDRESS)
7225 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
7227 // Let all blocks know they have parse all their variables
7228 sc.function->GetBlock (false).SetDidParseVariables (true, true);
7229 return num_variables;
7232 else if (sc.comp_unit)
7234 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID()).get();
7236 if (dwarf_cu == NULL)
7239 uint32_t vars_added = 0;
7240 VariableListSP variables (sc.comp_unit->GetVariableList(false));
7242 if (variables.get() == NULL)
7244 variables.reset(new VariableList());
7245 sc.comp_unit->SetVariableList(variables);
7247 DWARFCompileUnit* match_dwarf_cu = NULL;
7248 const DWARFDebugInfoEntry* die = NULL;
7249 DIEArray die_offsets;
7250 if (m_using_apple_tables)
7252 if (m_apple_names_ap.get())
7254 DWARFMappedHash::DIEInfoArray hash_data_array;
7255 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
7256 dwarf_cu->GetNextCompileUnitOffset(),
7259 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
7265 // Index if we already haven't to make sure the compile units
7266 // get indexed and make their global DIE index list
7270 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
7271 dwarf_cu->GetNextCompileUnitOffset(),
7275 const size_t num_matches = die_offsets.size();
7278 DWARFDebugInfo* debug_info = DebugInfo();
7279 for (size_t i=0; i<num_matches; ++i)
7281 const dw_offset_t die_offset = die_offsets[i];
7282 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
7285 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
7288 variables->AddVariableIfUnique (var_sp);
7294 if (m_using_apple_tables)
7296 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x)\n", die_offset);
7311 SymbolFileDWARF::ParseVariableDIE
7313 const SymbolContext& sc,
7314 DWARFCompileUnit* dwarf_cu,
7315 const DWARFDebugInfoEntry *die,
7316 const lldb::addr_t func_low_pc
7320 VariableSP var_sp (m_die_to_variable_sp[die]);
7322 return var_sp; // Already been parsed!
7324 const dw_tag_t tag = die->Tag();
7325 ModuleSP module = GetObjectFile()->GetModule();
7327 if ((tag == DW_TAG_variable) ||
7328 (tag == DW_TAG_constant) ||
7329 (tag == DW_TAG_formal_parameter && sc.function))
7331 DWARFDebugInfoEntry::Attributes attributes;
7332 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
7333 if (num_attributes > 0)
7335 const char *name = NULL;
7336 const char *mangled = NULL;
7339 lldb::user_id_t type_uid = LLDB_INVALID_UID;
7340 DWARFExpression location;
7341 bool is_external = false;
7342 bool is_artificial = false;
7343 bool location_is_const_value_data = false;
7344 bool has_explicit_location = false;
7345 //AccessType accessibility = eAccessNone;
7347 for (i=0; i<num_attributes; ++i)
7349 dw_attr_t attr = attributes.AttributeAtIndex(i);
7350 DWARFFormValue form_value;
7351 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
7355 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
7356 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
7357 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
7358 case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break;
7359 case DW_AT_linkage_name:
7360 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
7361 case DW_AT_type: type_uid = form_value.Reference(dwarf_cu); break;
7362 case DW_AT_external: is_external = form_value.Boolean(); break;
7363 case DW_AT_const_value:
7364 // If we have already found a DW_AT_location attribute, ignore this attribute.
7365 if (!has_explicit_location)
7367 location_is_const_value_data = true;
7368 // The constant value will be either a block, a data value or a string.
7369 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
7370 if (DWARFFormValue::IsBlockForm(form_value.Form()))
7372 // Retrieve the value as a block expression.
7373 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7374 uint32_t block_length = form_value.Unsigned();
7375 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
7377 else if (DWARFFormValue::IsDataForm(form_value.Form()))
7379 // Retrieve the value as a data expression.
7380 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7381 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7382 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7383 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
7387 // Retrieve the value as a string expression.
7388 if (form_value.Form() == DW_FORM_strp)
7390 const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
7391 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
7392 uint32_t data_length = fixed_form_sizes[form_value.Form()];
7393 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
7397 const char *str = form_value.AsCString(&debug_info_data);
7398 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
7399 uint32_t string_length = strlen(str) + 1;
7400 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
7405 case DW_AT_location:
7407 location_is_const_value_data = false;
7408 has_explicit_location = true;
7409 if (form_value.BlockData())
7411 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
7413 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
7414 uint32_t block_length = form_value.Unsigned();
7415 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
7419 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
7420 const dw_offset_t debug_loc_offset = form_value.Unsigned();
7422 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
7423 if (loc_list_length > 0)
7425 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
7426 assert (func_low_pc != LLDB_INVALID_ADDRESS);
7427 location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
7433 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
7434 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
7435 case DW_AT_declaration:
7436 case DW_AT_description:
7437 case DW_AT_endianity:
7439 case DW_AT_start_scope:
7440 case DW_AT_visibility:
7442 case DW_AT_abstract_origin:
7444 case DW_AT_specification:
7450 ValueType scope = eValueTypeInvalid;
7452 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
7453 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7454 SymbolContextScope * symbol_context_scope = NULL;
7456 // DWARF doesn't specify if a DW_TAG_variable is a local, global
7457 // or static variable, so we have to do a little digging by
7458 // looking at the location of a varaible to see if it contains
7459 // a DW_OP_addr opcode _somewhere_ in the definition. I say
7460 // somewhere because clang likes to combine small global variables
7461 // into the same symbol and have locations like:
7462 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
7463 // So if we don't have a DW_TAG_formal_parameter, we can look at
7464 // the location to see if it contains a DW_OP_addr opcode, and
7465 // then we can correctly classify our variables.
7466 if (tag == DW_TAG_formal_parameter)
7467 scope = eValueTypeVariableArgument;
7470 bool op_error = false;
7471 // Check if the location has a DW_OP_addr with any address value...
7472 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
7473 if (!location_is_const_value_data)
7475 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
7479 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
7480 GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), strm.GetString().c_str());
7484 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
7487 scope = eValueTypeVariableGlobal;
7489 scope = eValueTypeVariableStatic;
7492 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
7494 if (debug_map_symfile)
7496 // When leaving the DWARF in the .o files on darwin,
7497 // when we have a global variable that wasn't initialized,
7498 // the .o file might not have allocated a virtual
7499 // address for the global variable. In this case it will
7500 // have created a symbol for the global variable
7501 // that is undefined/data and external and the value will
7502 // be the byte size of the variable. When we do the
7503 // address map in SymbolFileDWARFDebugMap we rely on
7504 // having an address, we need to do some magic here
7505 // so we can get the correct address for our global
7506 // variable. The address for all of these entries
7507 // will be zero, and there will be an undefined symbol
7508 // in this object file, and the executable will have
7509 // a matching symbol with a good address. So here we
7510 // dig up the correct address and replace it in the
7511 // location for the variable, and set the variable's
7512 // symbol context scope to be that of the main executable
7513 // so the file address will resolve correctly.
7514 bool linked_oso_file_addr = false;
7515 if (is_external && location_DW_OP_addr == 0)
7517 // we have a possible uninitialized extern global
7518 ConstString const_name(mangled ? mangled : name);
7519 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
7520 if (debug_map_objfile)
7522 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
7523 if (debug_map_symtab)
7525 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
7528 Symtab::eVisibilityExtern);
7531 if (exe_symbol->ValueIsAddress())
7533 const addr_t exe_file_addr = exe_symbol->GetAddress().GetFileAddress();
7534 if (exe_file_addr != LLDB_INVALID_ADDRESS)
7536 if (location.Update_DW_OP_addr (exe_file_addr))
7538 linked_oso_file_addr = true;
7539 symbol_context_scope = exe_symbol;
7548 if (!linked_oso_file_addr)
7550 // The DW_OP_addr is not zero, but it contains a .o file address which
7551 // needs to be linked up correctly.
7552 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
7553 if (exe_file_addr != LLDB_INVALID_ADDRESS)
7555 // Update the file address for this variable
7556 location.Update_DW_OP_addr (exe_file_addr);
7560 // Variable didn't make it into the final executable
7568 scope = eValueTypeVariableLocal;
7572 if (symbol_context_scope == NULL)
7576 case DW_TAG_subprogram:
7577 case DW_TAG_inlined_subroutine:
7578 case DW_TAG_lexical_block:
7581 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7582 if (symbol_context_scope == NULL)
7583 symbol_context_scope = sc.function;
7588 symbol_context_scope = sc.comp_unit;
7593 if (symbol_context_scope)
7595 var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
7598 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
7600 symbol_context_scope,
7606 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
7610 // Not ready to parse this variable yet. It might be a global
7611 // or static variable that is in a function scope and the function
7612 // in the symbol context wasn't filled in yet
7616 // Cache var_sp even if NULL (the variable was just a specification or
7617 // was missing vital information to be able to be displayed in the debugger
7618 // (missing location due to optimization, etc)) so we don't re-parse
7619 // this DIE over and over later...
7620 m_die_to_variable_sp[die] = var_sp;
7626 const DWARFDebugInfoEntry *
7627 SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
7628 dw_offset_t spec_block_die_offset,
7629 DWARFCompileUnit **result_die_cu_handle)
7631 // Give the concrete function die specified by "func_die_offset", find the
7632 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7633 // to "spec_block_die_offset"
7634 DWARFDebugInfo* info = DebugInfo();
7636 const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
7639 assert (*result_die_cu_handle);
7640 return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
7646 const DWARFDebugInfoEntry *
7647 SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
7648 const DWARFDebugInfoEntry *die,
7649 dw_offset_t spec_block_die_offset,
7650 DWARFCompileUnit **result_die_cu_handle)
7656 case DW_TAG_subprogram:
7657 case DW_TAG_inlined_subroutine:
7658 case DW_TAG_lexical_block:
7660 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
7662 *result_die_cu_handle = dwarf_cu;
7666 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
7668 *result_die_cu_handle = dwarf_cu;
7675 // Give the concrete function die specified by "func_die_offset", find the
7676 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
7677 // to "spec_block_die_offset"
7678 for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
7680 const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
7682 spec_block_die_offset,
7683 result_die_cu_handle);
7689 *result_die_cu_handle = NULL;
7694 SymbolFileDWARF::ParseVariables
7696 const SymbolContext& sc,
7697 DWARFCompileUnit* dwarf_cu,
7698 const lldb::addr_t func_low_pc,
7699 const DWARFDebugInfoEntry *orig_die,
7700 bool parse_siblings,
7701 bool parse_children,
7702 VariableList* cc_variable_list
7705 if (orig_die == NULL)
7708 VariableListSP variable_list_sp;
7710 size_t vars_added = 0;
7711 const DWARFDebugInfoEntry *die = orig_die;
7714 dw_tag_t tag = die->Tag();
7716 // Check to see if we have already parsed this variable or constant?
7717 if (m_die_to_variable_sp[die])
7719 if (cc_variable_list)
7720 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
7724 // We haven't already parsed it, lets do that now.
7725 if ((tag == DW_TAG_variable) ||
7726 (tag == DW_TAG_constant) ||
7727 (tag == DW_TAG_formal_parameter && sc.function))
7729 if (variable_list_sp.get() == NULL)
7731 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
7732 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
7735 case DW_TAG_compile_unit:
7736 if (sc.comp_unit != NULL)
7738 variable_list_sp = sc.comp_unit->GetVariableList(false);
7739 if (variable_list_sp.get() == NULL)
7741 variable_list_sp.reset(new VariableList());
7742 sc.comp_unit->SetVariableList(variable_list_sp);
7747 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8" PRIx64 " %s with no valid compile unit in symbol context for 0x%8.8" PRIx64 " %s.\n",
7748 MakeUserID(sc_parent_die->GetOffset()),
7749 DW_TAG_value_to_name (parent_tag),
7750 MakeUserID(orig_die->GetOffset()),
7751 DW_TAG_value_to_name (orig_die->Tag()));
7755 case DW_TAG_subprogram:
7756 case DW_TAG_inlined_subroutine:
7757 case DW_TAG_lexical_block:
7758 if (sc.function != NULL)
7760 // Check to see if we already have parsed the variables for the given scope
7762 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
7765 // This must be a specification or abstract origin with
7766 // a concrete block couterpart in the current function. We need
7767 // to find the concrete block so we can correctly add the
7769 DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
7770 const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
7771 sc_parent_die->GetOffset(),
7772 &concrete_block_die_cu);
7773 if (concrete_block_die)
7774 block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
7779 const bool can_create = false;
7780 variable_list_sp = block->GetBlockVariableList (can_create);
7781 if (variable_list_sp.get() == NULL)
7783 variable_list_sp.reset(new VariableList());
7784 block->SetVariableList(variable_list_sp);
7791 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8" PRIx64 " %s.\n",
7792 MakeUserID(orig_die->GetOffset()),
7793 DW_TAG_value_to_name (orig_die->Tag()));
7798 if (variable_list_sp)
7800 VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
7803 variable_list_sp->AddVariableIfUnique (var_sp);
7804 if (cc_variable_list)
7805 cc_variable_list->AddVariableIfUnique (var_sp);
7812 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
7814 if (!skip_children && parse_children && die->HasChildren())
7816 vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
7820 die = die->GetSibling();
7827 //------------------------------------------------------------------
7828 // PluginInterface protocol
7829 //------------------------------------------------------------------
7831 SymbolFileDWARF::GetPluginName()
7833 return GetPluginNameStatic();
7837 SymbolFileDWARF::GetPluginVersion()
7843 SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
7845 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7846 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7848 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7852 SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
7854 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7855 ClangASTType clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
7857 symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
7861 SymbolFileDWARF::DumpIndexes ()
7863 StreamFile s(stdout, false);
7865 s.Printf ("DWARF index for (%s) '%s':",
7866 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
7867 GetObjectFile()->GetFileSpec().GetPath().c_str());
7868 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
7869 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
7870 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
7871 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
7872 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
7873 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
7874 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
7875 s.Printf("\nNamepaces:\n"); m_namespace_index.Dump (&s);
7879 SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
7881 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7883 DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
7885 if (iter == m_decl_ctx_to_die.end())
7888 for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
7890 const DWARFDebugInfoEntry *context_die = *pos;
7895 DWARFDebugInfo* info = DebugInfo();
7897 DIEArray die_offsets;
7899 DWARFCompileUnit* dwarf_cu = NULL;
7900 const DWARFDebugInfoEntry* die = NULL;
7902 if (m_using_apple_tables)
7904 if (m_apple_types_ap.get())
7905 m_apple_types_ap->FindByName (name, die_offsets);
7912 m_type_index.Find (ConstString(name), die_offsets);
7915 const size_t num_matches = die_offsets.size();
7919 for (size_t i = 0; i < num_matches; ++i)
7921 const dw_offset_t die_offset = die_offsets[i];
7922 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
7924 if (die->GetParent() != context_die)
7927 Type *matching_type = ResolveType (dwarf_cu, die);
7929 clang::QualType qual_type = matching_type->GetClangForwardType().GetQualType();
7931 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
7933 clang::TagDecl *tag_decl = tag_type->getDecl();
7934 results->push_back(tag_decl);
7936 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
7938 clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
7939 results->push_back(typedef_decl);
7947 SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
7948 const clang::DeclContext *decl_context,
7949 clang::DeclarationName decl_name,
7950 llvm::SmallVectorImpl <clang::NamedDecl *> *results)
7953 switch (decl_context->getDeclKind())
7955 case clang::Decl::Namespace:
7956 case clang::Decl::TranslationUnit:
7958 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7959 symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
7968 SymbolFileDWARF::LayoutRecordType (void *baton,
7969 const clang::RecordDecl *record_decl,
7971 uint64_t &alignment,
7972 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7973 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7974 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7976 SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
7977 return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
7982 SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
7984 uint64_t &alignment,
7985 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
7986 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
7987 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
7989 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
7990 RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
7991 bool success = false;
7992 base_offsets.clear();
7993 vbase_offsets.clear();
7994 if (pos != m_record_decl_to_layout_map.end())
7996 bit_size = pos->second.bit_size;
7997 alignment = pos->second.alignment;
7998 field_offsets.swap(pos->second.field_offsets);
7999 base_offsets.swap (pos->second.base_offsets);
8000 vbase_offsets.swap (pos->second.vbase_offsets);
8001 m_record_decl_to_layout_map.erase(pos);
8008 field_offsets.clear();
8012 GetObjectFile()->GetModule()->LogMessage (log,
8013 "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %" PRIu64 ", alignment = %" PRIu64 ", field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
8017 (uint32_t)field_offsets.size(),
8018 (uint32_t)base_offsets.size(),
8019 (uint32_t)vbase_offsets.size(),
8025 SymbolFileDWARFDebugMap *
8026 SymbolFileDWARF::GetDebugMapSymfile ()
8028 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
8030 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
8033 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
8035 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
8038 return m_debug_map_symfile;