diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h @@ -11,47 +11,50 @@ #include "Plugins/SymbolFile/DWARF/DWARFIndex.h" #include "Plugins/SymbolFile/DWARF/HashedNameToDIE.h" +#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" +#include "lldb/Symbol/ObjectFile.h" namespace lldb_private { class AppleDWARFIndex : public DWARFIndex { public: static std::unique_ptr - Create(Module &module, DWARFDataExtractor apple_names, + Create(SymbolFileDWARF &dwarf, DWARFDataExtractor apple_names, DWARFDataExtractor apple_namespaces, DWARFDataExtractor apple_types, DWARFDataExtractor apple_objc, DWARFDataExtractor debug_str); AppleDWARFIndex( - Module &module, std::unique_ptr apple_names, + SymbolFileDWARF &dwarf, std::unique_ptr apple_names, std::unique_ptr apple_namespaces, std::unique_ptr apple_types, std::unique_ptr apple_objc) - : DWARFIndex(module), m_apple_names_up(std::move(apple_names)), + : DWARFIndex(*dwarf.GetObjectFile()->GetModule()), m_dwarf(dwarf), m_apple_names_up(std::move(apple_names)), m_apple_namespaces_up(std::move(apple_namespaces)), m_apple_types_up(std::move(apple_types)), m_apple_objc_up(std::move(apple_objc)) {} void Preload() override {} - void GetGlobalVariables(ConstString basename, DIEArray &offsets) override; + void GetGlobalVariables(ConstString basename, std::vector &offsets) override; void GetGlobalVariables(const RegularExpression ®ex, - DIEArray &offsets) override; - void GetGlobalVariables(const DWARFUnit &cu, DIEArray &offsets) override; - void GetObjCMethods(ConstString class_name, DIEArray &offsets) override; + std::vector &offsets) override; + void GetGlobalVariables(const DWARFUnit &cu, std::vector &offsets) override; + void GetObjCMethods(ConstString class_name, std::vector &offsets) override; void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, - DIEArray &offsets) override; - void GetTypes(ConstString name, DIEArray &offsets) override; - void GetTypes(const DWARFDeclContext &context, DIEArray &offsets) override; - void GetNamespaces(ConstString name, DIEArray &offsets) override; + std::vector &offsets) override; + void GetTypes(ConstString name, std::vector &offsets) override; + void GetTypes(const DWARFDeclContext &context, std::vector &offsets) override; + void GetNamespaces(ConstString name, std::vector &offsets) override; void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - std::vector &dies) override; - void GetFunctions(const RegularExpression ®ex, DIEArray &offsets) override; + std::vector> &dies) override; + void GetFunctions(const RegularExpression ®ex, std::vector &offsets) override; - void ReportInvalidDIERef(const DIERef &ref, llvm::StringRef name) override; + void ReportInvalidDIEID(lldb::user_id_t uid, llvm::StringRef name) override; void Dump(Stream &s) override; private: + SymbolFileDWARF &m_dwarf; std::unique_ptr m_apple_names_up; std::unique_ptr m_apple_namespaces_up; std::unique_ptr m_apple_types_up; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp @@ -18,7 +18,7 @@ using namespace lldb; std::unique_ptr AppleDWARFIndex::Create( - Module &module, DWARFDataExtractor apple_names, + SymbolFileDWARF &dwarf, DWARFDataExtractor apple_names, DWARFDataExtractor apple_namespaces, DWARFDataExtractor apple_types, DWARFDataExtractor apple_objc, DWARFDataExtractor debug_str) { auto apple_names_table_up = std::make_unique( @@ -45,61 +45,94 @@ if (apple_names_table_up || apple_names_table_up || apple_types_table_up || apple_objc_table_up) return std::make_unique( - module, std::move(apple_names_table_up), + dwarf, std::move(apple_names_table_up), std::move(apple_namespaces_table_up), std::move(apple_types_table_up), std::move(apple_objc_table_up)); return nullptr; } -void AppleDWARFIndex::GetGlobalVariables(ConstString basename, DIEArray &offsets) { - if (m_apple_names_up) - m_apple_names_up->FindByName(basename.GetStringRef(), offsets); +void AppleDWARFIndex::GetGlobalVariables(ConstString basename, std::vector &offsets) { + if (!m_apple_names_up) + return; + DIEArray refs; + m_apple_names_up->FindByName(basename.GetStringRef(), refs); + offsets.reserve(offsets.size() + refs.size()); + for (const auto ref : refs) + offsets.push_back(m_dwarf.GetUID(nullptr/* main_unit */, ref)); } void AppleDWARFIndex::GetGlobalVariables(const RegularExpression ®ex, - DIEArray &offsets) { + std::vector &offsets) { if (!m_apple_names_up) return; DWARFMappedHash::DIEInfoArray hash_data; - if (m_apple_names_up->AppendAllDIEsThatMatchingRegex(regex, hash_data)) - DWARFMappedHash::ExtractDIEArray(hash_data, offsets); + if (!m_apple_names_up->AppendAllDIEsThatMatchingRegex(regex, hash_data)) + return; + + DIEArray refs; + DWARFMappedHash::ExtractDIEArray(hash_data, refs); + offsets.reserve(offsets.size() + refs.size()); + for (const auto ref : refs) + offsets.push_back(m_dwarf.GetUID(nullptr/* main_unit */, ref)); } void AppleDWARFIndex::GetGlobalVariables(const DWARFUnit &cu, - DIEArray &offsets) { + std::vector &offsets) { if (!m_apple_names_up) return; DWARFMappedHash::DIEInfoArray hash_data; - if (m_apple_names_up->AppendAllDIEsInRange(cu.GetOffset(), + if (!m_apple_names_up->AppendAllDIEsInRange(cu.GetOffset(), cu.GetNextUnitOffset(), hash_data)) - DWARFMappedHash::ExtractDIEArray(hash_data, offsets); + return; + DIEArray refs; + DWARFMappedHash::ExtractDIEArray(hash_data, refs); + offsets.reserve(offsets.size() + refs.size()); + for (const auto ref : refs) + offsets.push_back(m_dwarf.GetUID(nullptr/* main_unit */, ref)); } void AppleDWARFIndex::GetObjCMethods(ConstString class_name, - DIEArray &offsets) { - if (m_apple_objc_up) - m_apple_objc_up->FindByName(class_name.GetStringRef(), offsets); + std::vector &offsets) { + if (!m_apple_objc_up) + return; + + DIEArray refs; + m_apple_objc_up->FindByName(class_name.GetStringRef(), refs); + offsets.reserve(offsets.size() + refs.size()); + for (const auto ref : refs) + offsets.push_back(m_dwarf.GetUID(nullptr/* main_unit */, ref)); } void AppleDWARFIndex::GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, - DIEArray &offsets) { - if (m_apple_types_up) { - m_apple_types_up->FindCompleteObjCClassByName( - class_name.GetStringRef(), offsets, must_be_implementation); - } + std::vector &offsets) { + if (!m_apple_types_up) + return; + + DIEArray refs; + m_apple_types_up->FindCompleteObjCClassByName( + class_name.GetStringRef(), refs, must_be_implementation); + offsets.reserve(offsets.size() + refs.size()); + for (const auto ref : refs) + offsets.push_back(m_dwarf.GetUID(nullptr/* main_unit */, ref)); } -void AppleDWARFIndex::GetTypes(ConstString name, DIEArray &offsets) { - if (m_apple_types_up) - m_apple_types_up->FindByName(name.GetStringRef(), offsets); +void AppleDWARFIndex::GetTypes(ConstString name, std::vector &offsets) { + if (!m_apple_types_up) + return; + + DIEArray refs; + m_apple_types_up->FindByName(name.GetStringRef(), refs); + offsets.reserve(offsets.size() + refs.size()); + for (const auto ref : refs) + offsets.push_back(m_dwarf.GetUID(nullptr/* main_unit */, ref)); } void AppleDWARFIndex::GetTypes(const DWARFDeclContext &context, - DIEArray &offsets) { + std::vector &offsets) { if (!m_apple_types_up) return; @@ -110,6 +143,7 @@ const bool has_qualified_name_hash = m_apple_types_up->GetHeader().header_data.ContainsAtom( DWARFMappedHash::eAtomTypeQualNameHash); + DIEArray refs; const ConstString type_name(context[0].name); const dw_tag_t tag = context[0].tag; @@ -119,11 +153,8 @@ if (log) m_module.LogMessage(log, "FindByNameAndTagAndQualifiedNameHash()"); m_apple_types_up->FindByNameAndTagAndQualifiedNameHash( - type_name.GetStringRef(), tag, qualified_name_hash, offsets); - return; - } - - if (has_tag) { + type_name.GetStringRef(), tag, qualified_name_hash, refs); + } else if (has_tag) { // When searching for a scoped type (for example, // "std::vector::const_iterator") searching for the innermost // name alone ("const_iterator") could yield many false @@ -141,46 +172,60 @@ if (log) m_module.LogMessage(log, "FindByNameAndTag()"); - m_apple_types_up->FindByNameAndTag(type_name.GetStringRef(), tag, offsets); - return; - } - - m_apple_types_up->FindByName(type_name.GetStringRef(), offsets); + DIEArray refs; + m_apple_types_up->FindByNameAndTag(type_name.GetStringRef(), tag, refs); + } else + m_apple_types_up->FindByName(type_name.GetStringRef(), refs); + offsets.reserve(offsets.size() + refs.size()); + for (const auto ref : refs) + offsets.push_back(m_dwarf.GetUID(nullptr/* main_unit */, ref)); } -void AppleDWARFIndex::GetNamespaces(ConstString name, DIEArray &offsets) { - if (m_apple_namespaces_up) - m_apple_namespaces_up->FindByName(name.GetStringRef(), offsets); +void AppleDWARFIndex::GetNamespaces(ConstString name, std::vector &offsets) { + if (!m_apple_namespaces_up) + return; + + DIEArray refs; + m_apple_namespaces_up->FindByName(name.GetStringRef(), refs); + offsets.reserve(offsets.size() + refs.size()); + for (const auto ref : refs) + offsets.push_back(m_dwarf.GetUID(nullptr/* main_unit */, ref)); } void AppleDWARFIndex::GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - std::vector &dies) { + std::vector> &dies) { DIEArray offsets; m_apple_names_up->FindByName(name.GetStringRef(), offsets); for (const DIERef &die_ref : offsets) { - ProcessFunctionDIE(name.GetStringRef(), die_ref, dwarf, parent_decl_ctx, + ProcessFunctionDIE(name.GetStringRef(), dwarf.GetUID(nullptr/*main_unit*/, die_ref), dwarf, parent_decl_ctx, name_type_mask, dies); } } void AppleDWARFIndex::GetFunctions(const RegularExpression ®ex, - DIEArray &offsets) { + std::vector &offsets) { if (!m_apple_names_up) return; DWARFMappedHash::DIEInfoArray hash_data; - if (m_apple_names_up->AppendAllDIEsThatMatchingRegex(regex, hash_data)) - DWARFMappedHash::ExtractDIEArray(hash_data, offsets); + if (!m_apple_names_up->AppendAllDIEsThatMatchingRegex(regex, hash_data)) + return; + + DIEArray refs; + DWARFMappedHash::ExtractDIEArray(hash_data, refs); + offsets.reserve(offsets.size() + refs.size()); + for (const auto ref : refs) + offsets.push_back(m_dwarf.GetUID(nullptr/* main_unit */, ref)); } -void AppleDWARFIndex::ReportInvalidDIERef(const DIERef &ref, +void AppleDWARFIndex::ReportInvalidDIEID(user_id_t uid, llvm::StringRef name) { m_module.ReportErrorIfModifyDetected( "the DWARF debug information has been modified (accelerator table had " - "bad die 0x%8.8x for '%s')\n", - ref.die_offset(), name.str().c_str()); + "bad die 0x%8.8lx for '%s')\n", + uid, name.str().c_str()); } void AppleDWARFIndex::Dump(Stream &s) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h b/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h @@ -54,6 +54,16 @@ return m_die_offset < other.m_die_offset; } + bool operator==(DIERef other) const { + if (m_dwo_num_valid != other.m_dwo_num_valid + || m_section != other.m_section + || m_die_offset != other.m_die_offset) + return false; + if (m_dwo_num_valid && m_dwo_num != other.m_dwo_num) + return false; + return true; + } + private: uint32_t m_dwo_num : 30; uint32_t m_dwo_num_valid : 1; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h @@ -21,6 +21,7 @@ class ExecutionContext; } class SymbolFileDWARF; +class DWARFCompileUnit; class DWARFASTParser { public: @@ -39,13 +40,13 @@ lldb_private::CompilerType &compiler_type) = 0; virtual lldb_private::CompilerDecl - GetDeclForUIDFromDWARF(const DWARFDIE &die) = 0; + GetDeclForUIDFromDWARF(DWARFCompileUnit *main_unit, const DWARFDIE &die) = 0; virtual lldb_private::CompilerDeclContext - GetDeclContextForUIDFromDWARF(const DWARFDIE &die) = 0; + GetDeclContextForUIDFromDWARF(DWARFCompileUnit *main_unit, const DWARFDIE &die) = 0; virtual lldb_private::CompilerDeclContext - GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) = 0; + GetDeclContextContainingUIDFromDWARF(DWARFCompileUnit *main_unit, const DWARFDIE &die) = 0; virtual void EnsureAllDIEsInDeclContextHaveBeenParsed( lldb_private::CompilerDeclContext decl_context) = 0; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h @@ -11,7 +11,7 @@ #include "clang/AST/CharUnits.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" #include "DWARFASTParser.h" @@ -54,16 +54,16 @@ lldb_private::CompilerType &compiler_type) override; lldb_private::CompilerDecl - GetDeclForUIDFromDWARF(const DWARFDIE &die) override; + GetDeclForUIDFromDWARF(DWARFCompileUnit *main_unit, const DWARFDIE &die) override; void EnsureAllDIEsInDeclContextHaveBeenParsed( lldb_private::CompilerDeclContext decl_context) override; lldb_private::CompilerDeclContext - GetDeclContextForUIDFromDWARF(const DWARFDIE &die) override; + GetDeclContextForUIDFromDWARF(DWARFCompileUnit *main_unit, const DWARFDIE &die) override; lldb_private::CompilerDeclContext - GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) override; + GetDeclContextContainingUIDFromDWARF(DWARFCompileUnit *main_unit, const DWARFDIE &die) override; lldb_private::ClangASTImporter &GetClangASTImporter(); @@ -73,12 +73,12 @@ class DelayedAddObjCClassProperty; typedef std::vector DelayedPropertyList; - typedef llvm::SmallPtrSet DIEPointerSet; - typedef llvm::DenseMap + typedef llvm::SmallSet, 4> DIEPointerSet; + typedef llvm::DenseMap, clang::DeclContext *> DIEToDeclContextMap; - typedef std::multimap + typedef std::multimap> DeclContextToDIEMap; - typedef llvm::DenseMap + typedef llvm::DenseMap, clang::Decl *> DIEToDeclMap; typedef llvm::DenseMap DeclToDIEMap; @@ -90,21 +90,21 @@ std::unique_ptr m_clang_ast_importer_up; /// @} - clang::DeclContext *GetDeclContextForBlock(const DWARFDIE &die); + clang::DeclContext *GetDeclContextForBlock(DWARFCompileUnit *main_unit, const DWARFDIE &die); - clang::BlockDecl *ResolveBlockDIE(const DWARFDIE &die); + clang::BlockDecl *ResolveBlockDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die); - clang::NamespaceDecl *ResolveNamespaceDIE(const DWARFDIE &die); + clang::NamespaceDecl *ResolveNamespaceDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die); - bool ParseTemplateDIE(const DWARFDIE &die, + bool ParseTemplateDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die, lldb_private::TypeSystemClang::TemplateParameterInfos &template_param_infos); - bool ParseTemplateParameterInfos( + bool ParseTemplateParameterInfos(DWARFCompileUnit *main_unit, const DWARFDIE &parent_die, lldb_private::TypeSystemClang::TemplateParameterInfos &template_param_infos); - bool ParseChildMembers( + bool ParseChildMembers(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, lldb_private::CompilerType &class_compiler_type, const lldb::LanguageType class_language, std::vector> &base_classes, @@ -115,7 +115,7 @@ lldb_private::ClangASTImporter::LayoutInfo &layout_info); size_t - ParseChildParameters(clang::DeclContext *containing_decl_ctx, + ParseChildParameters(lldb_private::CompileUnit *comp_unit, clang::DeclContext *containing_decl_ctx, const DWARFDIE &parent_die, bool skip_artificial, bool &is_static, bool &is_variadic, bool &has_template_params, @@ -132,23 +132,23 @@ const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs); - lldb_private::Type *GetTypeForDIE(const DWARFDIE &die); + lldb_private::Type *GetTypeForDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die); - clang::Decl *GetClangDeclForDIE(const DWARFDIE &die); + clang::Decl *GetClangDeclForDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die); - clang::DeclContext *GetClangDeclContextForDIE(const DWARFDIE &die); + clang::DeclContext *GetClangDeclContextForDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die); - clang::DeclContext *GetClangDeclContextContainingDIE(const DWARFDIE &die, + clang::DeclContext *GetClangDeclContextContainingDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die, DWARFDIE *decl_ctx_die); - bool CopyUniqueClassMethodTypes(const DWARFDIE &src_class_die, + bool CopyUniqueClassMethodTypes(DWARFCompileUnit *main_unit, const DWARFDIE &src_class_die, const DWARFDIE &dst_class_die, lldb_private::Type *class_type, std::vector &failures); - clang::DeclContext *GetCachedClangDeclContextForDIE(const DWARFDIE &die); + clang::DeclContext *GetCachedClangDeclContextForDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die); - void LinkDeclContextToDIE(clang::DeclContext *decl_ctx, const DWARFDIE &die); + void LinkDeclContextToDIE(clang::DeclContext *decl_ctx, DWARFCompileUnit *main_unit, const DWARFDIE &die); void LinkDeclToDIE(clang::Decl *decl, const DWARFDIE &die); @@ -188,7 +188,7 @@ }; void - ParseSingleMember(const DWARFDIE &die, const DWARFDIE &parent_die, + ParseSingleMember(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, const DWARFDIE &parent_die, lldb_private::CompilerType &class_clang_type, const lldb::LanguageType class_language, std::vector &member_accessibilities, @@ -207,12 +207,12 @@ ParsedDWARFTypeAttributes &attrs); lldb::TypeSP ParseEnum(const lldb_private::SymbolContext &sc, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs); - lldb::TypeSP ParseSubroutine(const DWARFDIE &die, + lldb::TypeSP ParseSubroutine(const lldb_private::SymbolContext &sc, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs); // FIXME: attrs should be passed as a const reference. - lldb::TypeSP ParseArrayType(const DWARFDIE &die, + lldb::TypeSP ParseArrayType(const lldb_private::SymbolContext &sc, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs); - lldb::TypeSP ParsePointerToMemberType(const DWARFDIE &die, + lldb::TypeSP ParsePointerToMemberType(const lldb_private::SymbolContext &sc, const DWARFDIE &die, const ParsedDWARFTypeAttributes &attrs); }; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -12,6 +12,7 @@ #include "DWARFDebugInfo.h" #include "DWARFDeclContext.h" #include "DWARFDefines.h" +#include "DWARFCompileUnit.h" #include "SymbolFileDWARF.h" #include "SymbolFileDWARFDwo.h" #include "SymbolFileDWARFDebugMap.h" @@ -208,21 +209,22 @@ if (pcm_type.IsDefined()) GetClangASTImporter().RequireCompleteType(ClangUtil::GetQualType(type)); - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = llvm::cast(sc.module_sp->GetSymbolFile()); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); TypeSP type_sp(new Type( - die.GetID(), dwarf, pcm_type_sp->GetName(), pcm_type_sp->GetByteSize(), - nullptr, LLDB_INVALID_UID, Type::eEncodingInvalid, + die.GetID(main_unit), dwarf, pcm_type_sp->GetName(), pcm_type_sp->GetByteSize(), + sc.comp_unit, LLDB_INVALID_UID, Type::eEncodingInvalid, &pcm_type_sp->GetDeclaration(), type, Type::ResolveState::Forward)); dwarf->GetTypeList().Insert(type_sp); - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); clang::TagDecl *tag_decl = TypeSystemClang::GetAsTagDecl(type); if (tag_decl) - LinkDeclContextToDIE(tag_decl, die); + LinkDeclContextToDIE(tag_decl, main_unit, die); else { - clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE(die); + clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE(main_unit, die); if (defn_decl_ctx) - LinkDeclContextToDIE(defn_decl_ctx, die); + LinkDeclContextToDIE(defn_decl_ctx, main_unit, die); } return type_sp; @@ -400,11 +402,12 @@ Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION | DWARF_LOG_LOOKUPS)); - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = llvm::cast(sc.module_sp->GetSymbolFile()); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); if (log) { DWARFDIE context_die; clang::DeclContext *context = - GetClangDeclContextContainingDIE(die, &context_die); + GetClangDeclContextContainingDIE(main_unit, die, &context_die); dwarf->GetObjectFile()->GetModule()->LogMessage( log, @@ -414,23 +417,23 @@ die.GetTagAsCString(), die.GetName()); } - Type *type_ptr = dwarf->GetDIEToType().lookup(die.GetDIE()); + Type *type_ptr = dwarf->GetDIEToType().lookup(die.MainCUtoDIEPair(main_unit)); if (type_ptr == DIE_IS_BEING_PARSED) return nullptr; if (type_ptr) return type_ptr->shared_from_this(); // Set a bit that lets us know that we are currently parsing this - dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED; + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = DIE_IS_BEING_PARSED; ParsedDWARFTypeAttributes attrs(die); if (DWARFDIE signature_die = attrs.signature.Reference()) { if (TypeSP type_sp = ParseTypeFromDWARF(sc, signature_die, type_is_new_ptr)) { - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); if (clang::DeclContext *decl_ctx = - GetCachedClangDeclContextForDIE(signature_die)) - LinkDeclContextToDIE(decl_ctx, die); + GetCachedClangDeclContextForDIE(main_unit, signature_die)) + LinkDeclContextToDIE(decl_ctx, main_unit, die); return type_sp; } return nullptr; @@ -473,15 +476,15 @@ case DW_TAG_inlined_subroutine: case DW_TAG_subprogram: case DW_TAG_subroutine_type: { - type_sp = ParseSubroutine(die, attrs); + type_sp = ParseSubroutine(sc, die, attrs); break; } case DW_TAG_array_type: { - type_sp = ParseArrayType(die, attrs); + type_sp = ParseArrayType(sc, die, attrs); break; } case DW_TAG_ptr_to_member_type: { - type_sp = ParsePointerToMemberType(die, attrs); + type_sp = ParsePointerToMemberType(sc, die, attrs); break; } default: @@ -504,9 +507,10 @@ ParsedDWARFTypeAttributes &attrs) { Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION | DWARF_LOG_LOOKUPS)); - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = llvm::cast(sc.module_sp->GetSymbolFile()); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); const dw_tag_t tag = die.Tag(); - LanguageType cu_language = SymbolFileDWARF::GetLanguage(*die.GetCU()); + LanguageType cu_language = SymbolFileDWARF::GetLanguage(*die.MainDWARFUnit(main_unit)); Type::ResolveState resolve_state = Type::ResolveState::Unresolved; Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; TypeSP type_sp; @@ -706,11 +710,11 @@ } type_sp = std::make_shared( - die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr, - dwarf->GetUID(attrs.type.Reference()), encoding_data_type, &attrs.decl, + die.GetID(main_unit), dwarf, attrs.name, attrs.byte_size, sc.comp_unit, + dwarf->GetUID(main_unit, attrs.type.Reference()), encoding_data_type, &attrs.decl, clang_type, resolve_state); - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); return type_sp; } @@ -719,10 +723,11 @@ ParsedDWARFTypeAttributes &attrs) { Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION | DWARF_LOG_LOOKUPS)); - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = llvm::cast(sc.module_sp->GetSymbolFile()); const dw_tag_t tag = die.Tag(); TypeSP type_sp; + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); if (attrs.is_forward_declaration) { type_sp = ParseTypeFromClangModule(sc, die, log); if (type_sp) @@ -756,11 +761,11 @@ // We found a real definition for this type elsewhere so lets use // it and cache the fact that we found a complete type for this // die - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); clang::DeclContext *defn_decl_ctx = - GetCachedClangDeclContextForDIE(dwarf->GetDIE(type_sp->GetID())); + GetCachedClangDeclContextForDIE(main_unit, dwarf->GetDIE(type_sp->GetID())); if (defn_decl_ctx) - LinkDeclContextToDIE(defn_decl_ctx, die); + LinkDeclContextToDIE(defn_decl_ctx, main_unit, die); return type_sp; } } @@ -770,11 +775,11 @@ CompilerType enumerator_clang_type; CompilerType clang_type; clang_type.SetCompilerType( - &m_ast, dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE())); + &m_ast, dwarf->GetForwardDeclDieToClangType().lookup(die.MainCUtoDIEPair(main_unit))); if (!clang_type) { if (attrs.type.IsValid()) { Type *enumerator_type = - dwarf->ResolveTypeUID(attrs.type.Reference(), true); + dwarf->ResolveTypeUID(main_unit, attrs.type.Reference(), true); if (enumerator_type) enumerator_clang_type = enumerator_type->GetFullCompilerType(); } @@ -789,17 +794,17 @@ } clang_type = m_ast.CreateEnumerationType( - attrs.name.GetCString(), GetClangDeclContextContainingDIE(die, nullptr), + attrs.name.GetCString(), GetClangDeclContextContainingDIE(main_unit, die, nullptr), attrs.decl, enumerator_clang_type, attrs.is_scoped_enum); } else { enumerator_clang_type = m_ast.GetEnumerationIntegerType(clang_type); } - LinkDeclContextToDIE(TypeSystemClang::GetDeclContextForType(clang_type), die); + LinkDeclContextToDIE(TypeSystemClang::GetDeclContextForType(clang_type), main_unit, die); type_sp = std::make_shared( - die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr, - dwarf->GetUID(attrs.type.Reference()), Type::eEncodingIsUID, &attrs.decl, + die.GetID(main_unit), dwarf, attrs.name, attrs.byte_size, sc.comp_unit, + dwarf->GetUID(main_unit, attrs.type.Reference()), Type::eEncodingIsUID, &attrs.decl, clang_type, Type::ResolveState::Forward); if (TypeSystemClang::StartTagDeclarationDefinition(clang_type)) { @@ -820,12 +825,13 @@ return type_sp; } -TypeSP DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die, +TypeSP DWARFASTParserClang::ParseSubroutine(const SymbolContext &sc, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs) { Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION | DWARF_LOG_LOOKUPS)); - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = llvm::cast(sc.module_sp->GetSymbolFile()); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); const dw_tag_t tag = die.Tag(); bool is_variadic = false; @@ -848,7 +854,7 @@ Type *func_type = NULL; if (attrs.type.IsValid()) - func_type = dwarf->ResolveTypeUID(attrs.type.Reference(), true); + func_type = dwarf->ResolveTypeUID(main_unit, attrs.type.Reference(), true); if (func_type) return_clang_type = func_type->GetForwardCompilerType(); @@ -862,7 +868,7 @@ DWARFDIE decl_ctx_die; clang::DeclContext *containing_decl_ctx = - GetClangDeclContextContainingDIE(die, &decl_ctx_die); + GetClangDeclContextContainingDIE(main_unit, die, &decl_ctx_die); const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); @@ -876,7 +882,7 @@ if (die.HasChildren()) { bool skip_artificial = true; - ParseChildParameters(containing_decl_ctx, die, skip_artificial, is_static, + ParseChildParameters(sc.comp_unit, containing_decl_ctx, die, skip_artificial, is_static, is_variadic, has_template_params, function_param_types, function_param_decls, type_quals); @@ -938,8 +944,8 @@ attrs.is_objc_direct_call); type_handled = objc_method_decl != NULL; if (type_handled) { - LinkDeclContextToDIE(objc_method_decl, die); - m_ast.SetMetadataAsUserID(objc_method_decl, die.GetID()); + LinkDeclContextToDIE(objc_method_decl, main_unit, die); + m_ast.SetMetadataAsUserID(objc_method_decl, die.GetID(main_unit)); } else { dwarf->GetObjectFile()->GetModule()->ReportError( "{0x%8.8x}: invalid Objective-C method 0x%4.4x (%s), " @@ -951,10 +957,10 @@ } else if (is_cxx_method) { // Look at the parent of this DIE and see if is is a class or // struct and see if this is actually a C++ method - Type *class_type = dwarf->ResolveType(decl_ctx_die); + Type *class_type = dwarf->ResolveType(main_unit, decl_ctx_die); if (class_type) { bool alternate_defn = false; - if (class_type->GetID() != decl_ctx_die.GetID() || + if (class_type->GetID() != decl_ctx_die.GetID(main_unit) || IsClangModuleFwdDecl(decl_ctx_die)) { alternate_defn = true; @@ -966,7 +972,7 @@ if (class_type_die) { std::vector failures; - CopyUniqueClassMethodTypes(decl_ctx_die, class_type_die, + CopyUniqueClassMethodTypes(main_unit, decl_ctx_die, class_type_die, class_type, failures); // FIXME do something with these failures that's @@ -974,7 +980,7 @@ // Unfortunately classes don't like having stuff added // to them after their definitions are complete... - Type *type_ptr = dwarf->GetDIEToType()[die.GetDIE()]; + Type *type_ptr = dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)]; if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) { return type_ptr->shared_from_this(); } @@ -992,14 +998,14 @@ // die. DWARFDIE spec_die = attrs.specification.Reference(); clang::DeclContext *spec_clang_decl_ctx = - GetClangDeclContextForDIE(spec_die); + GetClangDeclContextForDIE(main_unit, spec_die); if (spec_clang_decl_ctx) { - LinkDeclContextToDIE(spec_clang_decl_ctx, die); + LinkDeclContextToDIE(spec_clang_decl_ctx, main_unit, die); } else { dwarf->GetObjectFile()->GetModule()->ReportWarning( "0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x" ") has no decl\n", - die.GetID(), spec_die.GetOffset()); + die.GetID(main_unit), spec_die.GetOffset()); } type_handled = true; } else if (attrs.abstract_origin.IsValid()) { @@ -1011,14 +1017,14 @@ DWARFDIE abs_die = attrs.abstract_origin.Reference(); clang::DeclContext *abs_clang_decl_ctx = - GetClangDeclContextForDIE(abs_die); + GetClangDeclContextForDIE(main_unit, abs_die); if (abs_clang_decl_ctx) { - LinkDeclContextToDIE(abs_clang_decl_ctx, die); + LinkDeclContextToDIE(abs_clang_decl_ctx, main_unit, die); } else { dwarf->GetObjectFile()->GetModule()->ReportWarning( "0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8x" ") has no decl\n", - die.GetID(), abs_die.GetOffset()); + die.GetID(main_unit), abs_die.GetOffset()); } type_handled = true; } else { @@ -1051,7 +1057,7 @@ if (method_decl->getType() == ClangUtil::GetQualType(clang_type)) { add_method = false; - LinkDeclContextToDIE(method_decl, die); + LinkDeclContextToDIE(method_decl, main_unit, die); type_handled = true; break; @@ -1066,7 +1072,7 @@ "SymbolFileDWARF::ParseType() is adding a method " "%s to class %s in DIE 0x%8.8" PRIx64 " from %s", attrs.name.GetCString(), - class_type->GetName().GetCString(), die.GetID(), + class_type->GetName().GetCString(), die.GetID(main_unit), dwarf->GetObjectFile() ->GetFileSpec() .GetPath() @@ -1093,10 +1099,10 @@ type_handled |= attrs.is_artificial; if (cxx_method_decl) { - LinkDeclContextToDIE(cxx_method_decl, die); + LinkDeclContextToDIE(cxx_method_decl, main_unit, die); ClangASTMetadata metadata; - metadata.SetUserID(die.GetID()); + metadata.SetUserID(die.GetID(main_unit)); if (!object_pointer_name.empty()) { metadata.SetObjectPtrName( @@ -1124,7 +1130,7 @@ // we need to modify the dwarf->GetDIEToType() so it // doesn't think we are trying to parse this DIE // anymore... - dwarf->GetDIEToType()[die.GetDIE()] = NULL; + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = NULL; // Now we get the full type to force our class type to // complete itself using the clang::ExternalASTSource @@ -1134,7 +1140,7 @@ // The type for this DIE should have been filled in the // function call above - Type *type_ptr = dwarf->GetDIEToType()[die.GetDIE()]; + Type *type_ptr = dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)]; if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) { return type_ptr->shared_from_this(); } @@ -1158,12 +1164,12 @@ if (attrs.abstract_origin.IsValid()) { DWARFDIE abs_die = attrs.abstract_origin.Reference(); - if (dwarf->ResolveType(abs_die)) { + if (dwarf->ResolveType(main_unit, abs_die)) { function_decl = llvm::dyn_cast_or_null( - GetCachedClangDeclContextForDIE(abs_die)); + GetCachedClangDeclContextForDIE(main_unit, abs_die)); if (function_decl) { - LinkDeclContextToDIE(function_decl, die); + LinkDeclContextToDIE(function_decl, main_unit, die); } } } @@ -1188,7 +1194,7 @@ if (has_template_params) { TypeSystemClang::TemplateParameterInfos template_param_infos; - ParseTemplateParameterInfos(die, template_param_infos); + ParseTemplateParameterInfos(main_unit, die, template_param_infos); template_function_decl = m_ast.CreateFunctionDeclaration( ignore_containing_context ? m_ast.GetTranslationUnitDecl() : containing_decl_ctx, @@ -1205,7 +1211,7 @@ lldbassert(function_decl); if (function_decl) { - LinkDeclContextToDIE(function_decl, die); + LinkDeclContextToDIE(function_decl, main_unit, die); if (!function_param_decls.empty()) { m_ast.SetFunctionParameters(function_decl, @@ -1218,7 +1224,7 @@ } ClangASTMetadata metadata; - metadata.SetUserID(die.GetID()); + metadata.SetUserID(die.GetID(main_unit)); if (!object_pointer_name.empty()) { metadata.SetObjectPtrName(object_pointer_name.c_str()); @@ -1234,19 +1240,20 @@ } } return std::make_shared( - die.GetID(), dwarf, attrs.name, llvm::None, nullptr, LLDB_INVALID_UID, + die.GetID(main_unit), dwarf, attrs.name, llvm::None, sc.comp_unit, LLDB_INVALID_UID, Type::eEncodingIsUID, &attrs.decl, clang_type, Type::ResolveState::Full); } -TypeSP DWARFASTParserClang::ParseArrayType(const DWARFDIE &die, +TypeSP DWARFASTParserClang::ParseArrayType(const SymbolContext &sc, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs) { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = llvm::cast(sc.module_sp->GetSymbolFile()); DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); DWARFDIE type_die = attrs.type.Reference(); - Type *element_type = dwarf->ResolveTypeUID(type_die, true); + Type *element_type = dwarf->ResolveTypeUID(main_unit, type_die, true); if (!element_type) return nullptr; @@ -1319,21 +1326,22 @@ } ConstString empty_name; TypeSP type_sp = std::make_shared( - die.GetID(), dwarf, empty_name, array_element_bit_stride / 8, nullptr, - dwarf->GetUID(type_die), Type::eEncodingIsUID, &attrs.decl, clang_type, + die.GetID(main_unit), dwarf, empty_name, array_element_bit_stride / 8, sc.comp_unit, + dwarf->GetUID(main_unit, type_die), Type::eEncodingIsUID, &attrs.decl, clang_type, Type::ResolveState::Full); type_sp->SetEncodingType(element_type); const clang::Type *type = ClangUtil::GetQualType(clang_type).getTypePtr(); - m_ast.SetMetadataAsUserID(type, die.GetID()); + m_ast.SetMetadataAsUserID(type, die.GetID(main_unit)); return type_sp; } -TypeSP DWARFASTParserClang::ParsePointerToMemberType( +TypeSP DWARFASTParserClang::ParsePointerToMemberType(const SymbolContext &sc, const DWARFDIE &die, const ParsedDWARFTypeAttributes &attrs) { - SymbolFileDWARF *dwarf = die.GetDWARF(); - Type *pointee_type = dwarf->ResolveTypeUID(attrs.type.Reference(), true); + SymbolFileDWARF *dwarf = llvm::cast(sc.module_sp->GetSymbolFile()); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); + Type *pointee_type = dwarf->ResolveTypeUID(main_unit, attrs.type.Reference(), true); Type *class_type = - dwarf->ResolveTypeUID(attrs.containing_type.Reference(), true); + dwarf->ResolveTypeUID(main_unit, attrs.containing_type.Reference(), true); CompilerType pointee_clang_type = pointee_type->GetForwardCompilerType(); CompilerType class_clang_type = class_type->GetLayoutCompilerType(); @@ -1342,12 +1350,11 @@ class_clang_type, pointee_clang_type); if (llvm::Optional clang_type_size = - clang_type.GetByteSize(nullptr)) { - return std::make_shared(die.GetID(), dwarf, attrs.name, - *clang_type_size, nullptr, LLDB_INVALID_UID, + clang_type.GetByteSize(nullptr)) + return std::make_shared(die.GetID(main_unit), dwarf, attrs.name, + *clang_type_size, sc.comp_unit, LLDB_INVALID_UID, Type::eEncodingIsUID, nullptr, clang_type, Type::ResolveState::Forward); - } return nullptr; } @@ -1356,23 +1363,25 @@ if (!type_sp) return type_sp; - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = llvm::cast(sc.module_sp->GetSymbolFile()); TypeList &type_list = dwarf->GetTypeList(); DWARFDIE sc_parent_die = SymbolFileDWARF::GetParentSymbolContextDIE(die); dw_tag_t sc_parent_tag = sc_parent_die.Tag(); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); SymbolContextScope *symbol_context_scope = nullptr; if (sc_parent_tag == DW_TAG_compile_unit || sc_parent_tag == DW_TAG_partial_unit) { symbol_context_scope = sc.comp_unit; } else if (sc.function != nullptr && sc_parent_die) { symbol_context_scope = - sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID()); + sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID(main_unit)); if (symbol_context_scope == nullptr) symbol_context_scope = sc.function; } else { symbol_context_scope = sc.module_sp.get(); } + lldbassert(symbol_context_scope); if (symbol_context_scope != nullptr) type_sp->SetSymbolContextScope(symbol_context_scope); @@ -1381,7 +1390,7 @@ // level. type_list.Insert(type_sp); - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); return type_sp; } @@ -1392,7 +1401,7 @@ TypeSP type_sp; CompilerType clang_type; const dw_tag_t tag = die.Tag(); - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = llvm::cast(sc.module_sp->GetSymbolFile()); LanguageType cu_language = SymbolFileDWARF::GetLanguage(*die.GetCU()); Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_TYPE_COMPLETION | DWARF_LOG_LOOKUPS); @@ -1422,9 +1431,10 @@ *unique_ast_entry_up)) { type_sp = unique_ast_entry_up->m_type_sp; if (type_sp) { - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); LinkDeclContextToDIE( - GetCachedClangDeclContextForDIE(unique_ast_entry_up->m_die), die); + GetCachedClangDeclContextForDIE(main_unit, unique_ast_entry_up->m_die), main_unit, die); return type_sp; } } @@ -1461,6 +1471,8 @@ attrs.is_forward_declaration = true; } + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); + if (attrs.class_language == eLanguageTypeObjC || attrs.class_language == eLanguageTypeObjC_plus_plus) { if (!attrs.is_complete_objc_class && @@ -1498,7 +1510,7 @@ // We found a real definition for this type elsewhere so lets use // it and cache the fact that we found a complete type for this // die - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); return type_sp; } } @@ -1554,21 +1566,23 @@ // We found a real definition for this type elsewhere so lets use // it and cache the fact that we found a complete type for this die - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); + DWARFCompileUnit *main_unit; + DWARFDIE die = dwarf->GetDIEUnlocked(type_sp->GetID(), &main_unit); clang::DeclContext *defn_decl_ctx = - GetCachedClangDeclContextForDIE(dwarf->GetDIE(type_sp->GetID())); + GetCachedClangDeclContextForDIE(main_unit, die); if (defn_decl_ctx) - LinkDeclContextToDIE(defn_decl_ctx, die); + LinkDeclContextToDIE(defn_decl_ctx, main_unit, die); return type_sp; } } assert(tag_decl_kind != -1); bool clang_type_was_created = false; clang_type.SetCompilerType( - &m_ast, dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE())); + &m_ast, dwarf->GetForwardDeclDieToClangType().lookup(die.MainCUtoDIEPair(main_unit))); if (!clang_type) { clang::DeclContext *decl_ctx = - GetClangDeclContextContainingDIE(die, nullptr); + GetClangDeclContextContainingDIE(main_unit, die, nullptr); // If your decl context is a record that was imported from another // AST context (in the gmodules case), we need to make sure the type @@ -1587,12 +1601,12 @@ } ClangASTMetadata metadata; - metadata.SetUserID(die.GetID()); + metadata.SetUserID(die.GetID(main_unit)); metadata.SetIsDynamicCXXType(dwarf->ClassOrStructIsVirtual(die)); if (attrs.name.GetStringRef().contains('<')) { TypeSystemClang::TemplateParameterInfos template_param_infos; - if (ParseTemplateParameterInfos(die, template_param_infos)) { + if (ParseTemplateParameterInfos(main_unit, die, template_param_infos)) { clang::ClassTemplateDecl *class_template_decl = m_ast.ParseClassTemplateDecl(decl_ctx, attrs.accessibility, attrs.name.GetCString(), tag_decl_kind, @@ -1633,9 +1647,9 @@ // Store a forward declaration to this class type in case any // parameters in any class methods need it for the clang types for // function prototypes. - LinkDeclContextToDIE(m_ast.GetDeclContextForType(clang_type), die); - type_sp = std::make_shared(die.GetID(), dwarf, attrs.name, - attrs.byte_size, nullptr, LLDB_INVALID_UID, + LinkDeclContextToDIE(m_ast.GetDeclContextForType(clang_type), main_unit, die); + type_sp = std::make_shared(die.GetID(main_unit), dwarf, attrs.name, + attrs.byte_size, sc.comp_unit, LLDB_INVALID_UID, Type::eEncodingIsUID, &attrs.decl, clang_type, Type::ResolveState::Forward); @@ -1730,11 +1744,11 @@ // Can't assume m_ast.GetSymbolFile() is actually a // SymbolFileDWARF, it can be a SymbolFileDWARFDebugMap for Apple // binaries. - dwarf->GetForwardDeclDieToClangType()[die.GetDIE()] = + dwarf->GetForwardDeclDieToClangType()[die.MainCUtoDIEPair(main_unit)] = clang_type.GetOpaqueQualType(); dwarf->GetForwardDeclClangTypeToDie().try_emplace( ClangUtil::RemoveFastQualifiers(clang_type).GetOpaqueQualType(), - *die.GetDIERef()); + die.GetID(main_unit)); m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true); } } @@ -1823,7 +1837,7 @@ std::unique_ptr m_metadata_up; }; -bool DWARFASTParserClang::ParseTemplateDIE( +bool DWARFASTParserClang::ParseTemplateDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die, TypeSystemClang::TemplateParameterInfos &template_param_infos) { const dw_tag_t tag = die.Tag(); @@ -1835,7 +1849,7 @@ new TypeSystemClang::TemplateParameterInfos); for (DWARFDIE child_die = die.GetFirstChild(); child_die.IsValid(); child_die = child_die.GetSibling()) { - if (!ParseTemplateDIE(child_die, *template_param_infos.packed_args)) + if (!ParseTemplateDIE(main_unit, child_die, *template_param_infos.packed_args)) return false; } if (const char *name = die.GetName()) { @@ -1873,7 +1887,7 @@ case DW_AT_type: if (attributes.ExtractFormValueAtIndex(i, form_value)) { - Type *lldb_type = die.ResolveTypeUID(form_value.Reference()); + Type *lldb_type = die.ResolveTypeUID(main_unit, form_value.Reference()); if (lldb_type) clang_type = lldb_type->GetForwardCompilerType(); } @@ -1932,7 +1946,7 @@ return false; } -bool DWARFASTParserClang::ParseTemplateParameterInfos( +bool DWARFASTParserClang::ParseTemplateParameterInfos(DWARFCompileUnit *main_unit, const DWARFDIE &parent_die, TypeSystemClang::TemplateParameterInfos &template_param_infos) { @@ -1948,7 +1962,7 @@ case DW_TAG_template_value_parameter: case DW_TAG_GNU_template_parameter_pack: case DW_TAG_GNU_template_template_param: - ParseTemplateDIE(die, template_param_infos); + ParseTemplateDIE(main_unit, die, template_param_infos); break; default: @@ -1964,7 +1978,8 @@ lldb_private::Type *type, CompilerType &clang_type) { const dw_tag_t tag = die.Tag(); - SymbolFileDWARF *dwarf = die.GetDWARF(); + CompileUnit *comp_unit = type->GetSymbolContextScope()->CalculateSymbolContextCompileUnit(); + SymbolFileDWARF *dwarf = llvm::cast(type->GetSymbolContextScope()->CalculateSymbolContextModule()->GetSymbolFile()); ClangASTImporter::LayoutInfo layout_info; @@ -1995,33 +2010,32 @@ bool is_a_class = false; // Parse members and base classes first std::vector member_function_dies; + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(comp_unit); DelayedPropertyList delayed_properties; - ParseChildMembers(die, clang_type, class_language, bases, + ParseChildMembers(comp_unit, die, clang_type, class_language, bases, member_accessibilities, member_function_dies, delayed_properties, default_accessibility, is_a_class, layout_info); // Now parse any methods if there were any... for (const DWARFDIE &die : member_function_dies) - dwarf->ResolveType(die); + dwarf->ResolveType(main_unit, die); if (class_language == eLanguageTypeObjC) { ConstString class_name(clang_type.GetTypeName()); if (class_name) { - DIEArray method_die_offsets; + std::vector method_die_offsets; dwarf->GetObjCMethodDIEOffsets(class_name, method_die_offsets); if (!method_die_offsets.empty()) { - DWARFDebugInfo &debug_info = dwarf->DebugInfo(); - const size_t num_matches = method_die_offsets.size(); for (size_t i = 0; i < num_matches; ++i) { - const DIERef &die_ref = method_die_offsets[i]; - DWARFDIE method_die = debug_info.GetDIE(die_ref); + user_id_t uid = method_die_offsets[i]; + DWARFDIE method_die = dwarf->GetDIEUnlocked(uid); if (method_die) - method_die.ResolveType(); + method_die.ResolveType(main_unit); } } @@ -2137,7 +2151,7 @@ bool DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type, CompilerType &clang_type) { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = llvm::cast(type->GetSymbolContextScope()->CalculateSymbolContextModule()->GetSymbolFile()); std::lock_guard guard( dwarf->GetObjectFile()->GetModule()->GetMutex()); @@ -2156,7 +2170,7 @@ if (log) dwarf->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace( log, "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", - die.GetID(), die.GetTagAsCString(), type->GetName().AsCString()); + die.GetID(nullptr), die.GetTagAsCString(), type->GetName().AsCString()); assert(clang_type); DWARFAttributes attributes; switch (tag) { @@ -2180,31 +2194,33 @@ (clang::DeclContext *)decl_context.GetOpaqueDeclContext(); for (auto it = m_decl_ctx_to_die.find(opaque_decl_ctx); it != m_decl_ctx_to_die.end() && it->first == opaque_decl_ctx; - it = m_decl_ctx_to_die.erase(it)) - for (DWARFDIE decl = it->second.GetFirstChild(); decl; + it = m_decl_ctx_to_die.erase(it)) { + DWARFCompileUnit *main_unit = it->second.first; + for (DWARFDIE decl = it->second.second.GetFirstChild(); decl; decl = decl.GetSibling()) - GetClangDeclForDIE(decl); + GetClangDeclForDIE(main_unit, decl); + } } -CompilerDecl DWARFASTParserClang::GetDeclForUIDFromDWARF(const DWARFDIE &die) { - clang::Decl *clang_decl = GetClangDeclForDIE(die); +CompilerDecl DWARFASTParserClang::GetDeclForUIDFromDWARF(DWARFCompileUnit *main_unit, const DWARFDIE &die) { + clang::Decl *clang_decl = GetClangDeclForDIE(main_unit, die); if (clang_decl != nullptr) return m_ast.GetCompilerDecl(clang_decl); return CompilerDecl(); } CompilerDeclContext -DWARFASTParserClang::GetDeclContextForUIDFromDWARF(const DWARFDIE &die) { - clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE(die); +DWARFASTParserClang::GetDeclContextForUIDFromDWARF(DWARFCompileUnit *main_unit, const DWARFDIE &die) { + clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE(main_unit, die); if (clang_decl_ctx) return m_ast.CreateDeclContext(clang_decl_ctx); return CompilerDeclContext(); } CompilerDeclContext -DWARFASTParserClang::GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) { +DWARFASTParserClang::GetDeclContextContainingUIDFromDWARF(DWARFCompileUnit *main_unit, const DWARFDIE &die) { clang::DeclContext *clang_decl_ctx = - GetClangDeclContextContainingDIE(die, nullptr); + GetClangDeclContextContainingDIE(main_unit, die, nullptr); if (clang_decl_ctx) return m_ast.CreateDeclContext(clang_decl_ctx); return CompilerDeclContext(); @@ -2313,6 +2329,8 @@ } if (func_range.GetBaseAddress().IsValid()) { + SymbolFileDWARF *dwarf = llvm::cast(comp_unit.GetModule()->GetSymbolFile()); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(&comp_unit); Mangled func_name; if (mangled) func_name.SetValue(ConstString(mangled), true); @@ -2338,8 +2356,8 @@ sstr << decl_ctx.GetQualifiedName(); clang::DeclContext *containing_decl_ctx = - GetClangDeclContextContainingDIE(die, nullptr); - ParseChildParameters(containing_decl_ctx, die, true, is_static, + GetClangDeclContextContainingDIE(main_unit, die, nullptr); + ParseChildParameters(&comp_unit, containing_decl_ctx, die, true, is_static, is_variadic, has_template_params, param_types, param_decls, type_quals); sstr << "("; @@ -2364,14 +2382,13 @@ decl_up.reset(new Declaration(die.GetCU()->GetFile(decl_file), decl_line, decl_column)); - SymbolFileDWARF *dwarf = die.GetDWARF(); // Supply the type _only_ if it has already been parsed - Type *func_type = dwarf->GetDIEToType().lookup(die.GetDIE()); + Type *func_type = dwarf->GetDIEToType().lookup(die.MainCUtoDIEPair(main_unit)); assert(func_type == nullptr || func_type != DIE_IS_BEING_PARSED); if (dwarf->FixupAddress(func_range.GetBaseAddress())) { - const user_id_t func_user_id = die.GetID(); + const user_id_t func_user_id = die.GetID(main_unit); func_sp = std::make_shared(&comp_unit, func_user_id, // UserID is the DIE offset @@ -2390,7 +2407,7 @@ return nullptr; } -void DWARFASTParserClang::ParseSingleMember( +void DWARFASTParserClang::ParseSingleMember(CompileUnit *comp_unit, const DWARFDIE &die, const DWARFDIE &parent_die, lldb_private::CompilerType &class_clang_type, const lldb::LanguageType class_language, @@ -2572,9 +2589,14 @@ class_language == eLanguageTypeObjC_plus_plus) accessibility = eAccessNone; + DWARFCompileUnit *main_unit = nullptr; + if (comp_unit) { + SymbolFileDWARF *dwarf = llvm::cast(comp_unit->GetModule()->GetSymbolFile()); + main_unit = dwarf->GetDWARFCompileUnit(comp_unit); + } // Handle static members if (is_external && member_byte_offset == UINT32_MAX) { - Type *var_type = die.ResolveTypeUID(encoding_form.Reference()); + Type *var_type = die.ResolveTypeUID(main_unit, encoding_form.Reference()); if (var_type) { if (accessibility == eAccessNone) @@ -2587,7 +2609,7 @@ } if (!is_artificial) { - Type *member_type = die.ResolveTypeUID(encoding_form.Reference()); + Type *member_type = die.ResolveTypeUID(main_unit, encoding_form.Reference()); clang::FieldDecl *field_decl = nullptr; const uint64_t character_width = 8; @@ -2633,7 +2655,7 @@ "bit offset (0x%8.8" PRIx64 ") member will be ignored. Please file a bug against the " "compiler and include the preprocessed output for %s\n", - die.GetID(), DW_TAG_value_to_name(tag), name, + die.GetID(main_unit), DW_TAG_value_to_name(tag), name, this_field_info.bit_offset, GetUnitName(parent_die).c_str()); return; } @@ -2743,8 +2765,8 @@ "0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8x" " which extends beyond the bounds of 0x%8.8" PRIx64, - die.GetID(), name, encoding_form.Reference().GetOffset(), - parent_die.GetID()); + die.GetID(main_unit), name, encoding_form.Reference().GetOffset(), + parent_die.GetID(main_unit)); } member_clang_type = @@ -2796,7 +2818,7 @@ class_clang_type, name, member_clang_type, accessibility, bit_size); - m_ast.SetMetadataAsUserID(field_decl, die.GetID()); + m_ast.SetMetadataAsUserID(field_decl, die.GetID(main_unit)); layout_info.field_offsets.insert( std::make_pair(field_decl, field_bit_offset)); @@ -2805,12 +2827,12 @@ module_sp->ReportError( "0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8x" " which was unable to be parsed", - die.GetID(), name, encoding_form.Reference().GetOffset()); + die.GetID(main_unit), name, encoding_form.Reference().GetOffset()); else module_sp->ReportError( "0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8x" " which was unable to be parsed", - die.GetID(), encoding_form.Reference().GetOffset()); + die.GetID(main_unit), encoding_form.Reference().GetOffset()); } } @@ -2823,20 +2845,20 @@ } ClangASTMetadata metadata; - metadata.SetUserID(die.GetID()); + metadata.SetUserID(die.GetID(main_unit)); delayed_properties.push_back(DelayedAddObjCClassProperty( class_clang_type, prop_name, member_type->GetLayoutCompilerType(), ivar_decl, prop_setter_name, prop_getter_name, prop_attributes, &metadata)); if (ivar_decl) - m_ast.SetMetadataAsUserID(ivar_decl, die.GetID()); + m_ast.SetMetadataAsUserID(ivar_decl, die.GetID(main_unit)); } } } } -bool DWARFASTParserClang::ParseChildMembers( +bool DWARFASTParserClang::ParseChildMembers(CompileUnit *comp_unit, const DWARFDIE &parent_die, CompilerType &class_clang_type, const LanguageType class_language, std::vector> &base_classes, @@ -2855,6 +2877,12 @@ if (ast == nullptr) return false; + DWARFCompileUnit *main_unit = nullptr; + if (comp_unit) { + SymbolFileDWARF *dwarf = llvm::cast(comp_unit->GetModule()->GetSymbolFile()); + main_unit = dwarf->GetDWARFCompileUnit(comp_unit); + } + for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling()) { dw_tag_t tag = die.Tag(); @@ -2862,7 +2890,7 @@ switch (tag) { case DW_TAG_member: case DW_TAG_APPLE_property: - ParseSingleMember(die, parent_die, class_clang_type, class_language, + ParseSingleMember(comp_unit, die, parent_die, class_clang_type, class_language, member_accessibilities, default_accessibility, delayed_properties, layout_info, last_field_info); break; @@ -2936,7 +2964,7 @@ } } - Type *base_class_type = die.ResolveTypeUID(encoding_form.Reference()); + Type *base_class_type = die.ResolveTypeUID(main_unit, encoding_form.Reference()); if (base_class_type == nullptr) { module_sp->ReportError("0x%8.8x: DW_TAG_inheritance failed to " "resolve the base class at 0x%8.8x" @@ -2995,7 +3023,7 @@ return true; } -size_t DWARFASTParserClang::ParseChildParameters( +size_t DWARFASTParserClang::ParseChildParameters(CompileUnit *comp_unit, clang::DeclContext *containing_decl_ctx, const DWARFDIE &parent_die, bool skip_artificial, bool &is_static, bool &is_variadic, bool &has_template_params, std::vector &function_param_types, @@ -3004,6 +3032,12 @@ if (!parent_die) return 0; + DWARFCompileUnit *main_unit = nullptr; + if (comp_unit) { + SymbolFileDWARF *dwarf = llvm::cast(comp_unit->GetModule()->GetSymbolFile()); + main_unit = dwarf->GetDWARFCompileUnit(comp_unit); + } + size_t arg_idx = 0; for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling()) { @@ -3061,7 +3095,7 @@ // the formal parameter DIE... (name == nullptr || ::strcmp(name, "this") == 0)) { Type *this_type = - die.ResolveTypeUID(param_type_die_form.Reference()); + die.ResolveTypeUID(main_unit, param_type_die_form.Reference()); if (this_type) { uint32_t encoding_mask = this_type->GetEncodingMask(); if (encoding_mask & Type::eEncodingIsPointerUID) { @@ -3078,7 +3112,7 @@ } if (!skip) { - Type *type = die.ResolveTypeUID(param_type_die_form.Reference()); + Type *type = die.ResolveTypeUID(main_unit, param_type_die_form.Reference()); if (type) { function_param_types.push_back(type->GetForwardCompilerType()); @@ -3089,7 +3123,7 @@ assert(param_var_decl); function_param_decls.push_back(param_var_decl); - m_ast.SetMetadataAsUserID(param_var_decl, die.GetID()); + m_ast.SetMetadataAsUserID(param_var_decl, die.GetID(main_unit)); } } } @@ -3215,9 +3249,9 @@ return array_info; } -Type *DWARFASTParserClang::GetTypeForDIE(const DWARFDIE &die) { +Type *DWARFASTParserClang::GetTypeForDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die) { if (die) { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = &die.MainDWARFUnit(main_unit)->GetSymbolFileDWARF(); DWARFAttributes attributes; const size_t num_attributes = die.GetAttributes(attributes); if (num_attributes > 0) { @@ -3228,7 +3262,7 @@ if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, form_value)) - return dwarf->ResolveTypeUID(form_value.Reference(), true); + return dwarf->ResolveTypeUID(main_unit, form_value.Reference(), true); } } } @@ -3236,7 +3270,7 @@ return nullptr; } -clang::Decl *DWARFASTParserClang::GetClangDeclForDIE(const DWARFDIE &die) { +clang::Decl *DWARFASTParserClang::GetClangDeclForDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die) { if (!die) return nullptr; @@ -3251,37 +3285,39 @@ return nullptr; } - DIEToDeclMap::iterator cache_pos = m_die_to_decl.find(die.GetDIE()); + auto diepair = die.MainCUtoDIEPair(main_unit); + DIEToDeclMap::iterator cache_pos = m_die_to_decl.find(diepair); if (cache_pos != m_die_to_decl.end()) return cache_pos->second; if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification)) { - clang::Decl *decl = GetClangDeclForDIE(spec_die); - m_die_to_decl[die.GetDIE()] = decl; - m_decl_to_die[decl].insert(die.GetDIE()); + clang::Decl *decl = GetClangDeclForDIE(main_unit, spec_die); + m_die_to_decl[diepair] = decl; + m_decl_to_die[decl].insert(diepair); return decl; } if (DWARFDIE abstract_origin_die = die.GetReferencedDIE(DW_AT_abstract_origin)) { - clang::Decl *decl = GetClangDeclForDIE(abstract_origin_die); - m_die_to_decl[die.GetDIE()] = decl; - m_decl_to_die[decl].insert(die.GetDIE()); + clang::Decl *decl = GetClangDeclForDIE(main_unit, abstract_origin_die); + m_die_to_decl[diepair] = decl; + m_decl_to_die[decl].insert(diepair); return decl; } + SymbolFileDWARF *dwarf = &die.MainDWARFUnit(main_unit)->GetSymbolFileDWARF(); + clang::Decl *decl = nullptr; switch (die.Tag()) { case DW_TAG_variable: case DW_TAG_constant: case DW_TAG_formal_parameter: { - SymbolFileDWARF *dwarf = die.GetDWARF(); - Type *type = GetTypeForDIE(die); + Type *type = GetTypeForDIE(main_unit, die); if (dwarf && type) { const char *name = die.GetName(); clang::DeclContext *decl_context = TypeSystemClang::DeclContextGetAsDeclContext( - dwarf->GetDeclContextContainingUID(die.GetID())); + dwarf->GetDeclContextContainingUID(die.GetID(main_unit))); decl = m_ast.CreateVariableDeclaration( decl_context, name, ClangUtil::GetQualType(type->GetForwardCompilerType())); @@ -3289,14 +3325,13 @@ break; } case DW_TAG_imported_declaration: { - SymbolFileDWARF *dwarf = die.GetDWARF(); DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import); if (imported_uid) { - CompilerDecl imported_decl = SymbolFileDWARF::GetDecl(imported_uid); + CompilerDecl imported_decl = SymbolFileDWARF::GetDecl(main_unit, imported_uid); if (imported_decl) { clang::DeclContext *decl_context = TypeSystemClang::DeclContextGetAsDeclContext( - dwarf->GetDeclContextContainingUID(die.GetID())); + dwarf->GetDeclContextContainingUID(die.GetID(main_unit))); if (clang::NamedDecl *clang_imported_decl = llvm::dyn_cast( (clang::Decl *)imported_decl.GetOpaqueDecl())) @@ -3307,16 +3342,15 @@ break; } case DW_TAG_imported_module: { - SymbolFileDWARF *dwarf = die.GetDWARF(); DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import); if (imported_uid) { CompilerDeclContext imported_decl_ctx = - SymbolFileDWARF::GetDeclContext(imported_uid); + SymbolFileDWARF::GetDeclContext(main_unit, imported_uid); if (imported_decl_ctx) { clang::DeclContext *decl_context = TypeSystemClang::DeclContextGetAsDeclContext( - dwarf->GetDeclContextContainingUID(die.GetID())); + dwarf->GetDeclContextContainingUID(die.GetID(main_unit))); if (clang::NamespaceDecl *ns_decl = TypeSystemClang::DeclContextGetAsNamespaceDecl( imported_decl_ctx)) @@ -3329,16 +3363,16 @@ break; } - m_die_to_decl[die.GetDIE()] = decl; - m_decl_to_die[decl].insert(die.GetDIE()); + m_die_to_decl[diepair] = decl; + m_decl_to_die[decl].insert(diepair); return decl; } clang::DeclContext * -DWARFASTParserClang::GetClangDeclContextForDIE(const DWARFDIE &die) { +DWARFASTParserClang::GetClangDeclContextForDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die) { if (die) { - clang::DeclContext *decl_ctx = GetCachedClangDeclContextForDIE(die); + clang::DeclContext *decl_ctx = GetCachedClangDeclContextForDIE(main_unit, die); if (decl_ctx) return decl_ctx; @@ -3351,12 +3385,12 @@ break; case DW_TAG_namespace: - decl_ctx = ResolveNamespaceDIE(die); + decl_ctx = ResolveNamespaceDIE(main_unit, die); try_parsing_type = false; break; case DW_TAG_lexical_block: - decl_ctx = GetDeclContextForBlock(die); + decl_ctx = GetDeclContextForBlock(main_unit, die); try_parsing_type = false; break; @@ -3365,13 +3399,13 @@ } if (decl_ctx == nullptr && try_parsing_type) { - Type *type = die.GetDWARF()->ResolveType(die); + Type *type = die.MainDWARFUnit(main_unit)->GetSymbolFileDWARF().ResolveType(main_unit, die); if (type) - decl_ctx = GetCachedClangDeclContextForDIE(die); + decl_ctx = GetCachedClangDeclContextForDIE(main_unit, die); } if (decl_ctx) { - LinkDeclContextToDIE(decl_ctx, die); + LinkDeclContextToDIE(decl_ctx, main_unit, die); return decl_ctx; } } @@ -3427,33 +3461,33 @@ } clang::DeclContext * -DWARFASTParserClang::GetDeclContextForBlock(const DWARFDIE &die) { +DWARFASTParserClang::GetDeclContextForBlock(DWARFCompileUnit *main_unit, const DWARFDIE &die) { assert(die.Tag() == DW_TAG_lexical_block); DWARFDIE containing_function_with_abstract_origin = GetContainingFunctionWithAbstractOrigin(die); if (!containing_function_with_abstract_origin) { - return (clang::DeclContext *)ResolveBlockDIE(die); + return (clang::DeclContext *)ResolveBlockDIE(main_unit, die); } DWARFDIE child = FindFirstChildWithAbstractOrigin( die, containing_function_with_abstract_origin); CompilerDeclContext decl_context = - GetDeclContextContainingUIDFromDWARF(child); + GetDeclContextContainingUIDFromDWARF(main_unit, child); return (clang::DeclContext *)decl_context.GetOpaqueDeclContext(); } -clang::BlockDecl *DWARFASTParserClang::ResolveBlockDIE(const DWARFDIE &die) { +clang::BlockDecl *DWARFASTParserClang::ResolveBlockDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die) { if (die && die.Tag() == DW_TAG_lexical_block) { clang::BlockDecl *decl = - llvm::cast_or_null(m_die_to_decl_ctx[die.GetDIE()]); + llvm::cast_or_null(m_die_to_decl_ctx[die.MainCUtoDIEPair(main_unit)]); if (!decl) { DWARFDIE decl_context_die; clang::DeclContext *decl_context = - GetClangDeclContextContainingDIE(die, &decl_context_die); + GetClangDeclContextContainingDIE(main_unit, die, &decl_context_die); decl = m_ast.CreateBlockDeclaration(decl_context); if (decl) - LinkDeclContextToDIE((clang::DeclContext *)decl, die); + LinkDeclContextToDIE((clang::DeclContext *)decl, main_unit, die); } return decl; @@ -3462,18 +3496,18 @@ } clang::NamespaceDecl * -DWARFASTParserClang::ResolveNamespaceDIE(const DWARFDIE &die) { +DWARFASTParserClang::ResolveNamespaceDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die) { if (die && die.Tag() == DW_TAG_namespace) { // See if we already parsed this namespace DIE and associated it with a // uniqued namespace declaration clang::NamespaceDecl *namespace_decl = - static_cast(m_die_to_decl_ctx[die.GetDIE()]); + static_cast(m_die_to_decl_ctx[die.MainCUtoDIEPair(main_unit)]); if (namespace_decl) return namespace_decl; else { const char *namespace_name = die.GetName(); clang::DeclContext *containing_decl_ctx = - GetClangDeclContextContainingDIE(die, nullptr); + GetClangDeclContextContainingDIE(main_unit, die, nullptr); bool is_inline = die.GetAttributeValueAsUnsigned(DW_AT_export_symbols, 0) != 0; @@ -3482,14 +3516,14 @@ Log *log = nullptr; // (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); if (log) { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = &die.MainDWARFUnit(main_unit)->GetSymbolFileDWARF(); if (namespace_name) { dwarf->GetObjectFile()->GetModule()->LogMessage( log, "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => " "clang::NamespaceDecl *%p (original = %p)", - static_cast(&m_ast.getASTContext()), die.GetID(), + static_cast(&m_ast.getASTContext()), die.GetID(main_unit), namespace_name, static_cast(namespace_decl), static_cast(namespace_decl->getOriginalNamespace())); } else { @@ -3498,23 +3532,23 @@ "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p " "(original = %p)", - static_cast(&m_ast.getASTContext()), die.GetID(), + static_cast(&m_ast.getASTContext()), die.GetID(main_unit), static_cast(namespace_decl), static_cast(namespace_decl->getOriginalNamespace())); } } if (namespace_decl) - LinkDeclContextToDIE((clang::DeclContext *)namespace_decl, die); + LinkDeclContextToDIE((clang::DeclContext *)namespace_decl, main_unit, die); return namespace_decl; } } return nullptr; } -clang::DeclContext *DWARFASTParserClang::GetClangDeclContextContainingDIE( +clang::DeclContext *DWARFASTParserClang::GetClangDeclContextContainingDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die, DWARFDIE *decl_ctx_die_copy) { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = &die.MainDWARFUnit(main_unit)->GetSymbolFileDWARF(); DWARFDIE decl_ctx_die = dwarf->GetDeclContextDIEContainingDIE(die); @@ -3523,7 +3557,7 @@ if (decl_ctx_die) { clang::DeclContext *clang_decl_ctx = - GetClangDeclContextForDIE(decl_ctx_die); + GetClangDeclContextForDIE(main_unit, decl_ctx_die); if (clang_decl_ctx) return clang_decl_ctx; } @@ -3531,9 +3565,9 @@ } clang::DeclContext * -DWARFASTParserClang::GetCachedClangDeclContextForDIE(const DWARFDIE &die) { +DWARFASTParserClang::GetCachedClangDeclContextForDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die) { if (die) { - DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die.GetDIE()); + DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die.MainCUtoDIEPair(main_unit)); if (pos != m_die_to_decl_ctx.end()) return pos->second; } @@ -3541,14 +3575,14 @@ } void DWARFASTParserClang::LinkDeclContextToDIE(clang::DeclContext *decl_ctx, - const DWARFDIE &die) { - m_die_to_decl_ctx[die.GetDIE()] = decl_ctx; + DWARFCompileUnit *main_unit, const DWARFDIE &die) { + m_die_to_decl_ctx[die.MainCUtoDIEPair(main_unit)] = decl_ctx; // There can be many DIEs for a single decl context // m_decl_ctx_to_die[decl_ctx].insert(die.GetDIE()); - m_decl_ctx_to_die.insert(std::make_pair(decl_ctx, die)); + m_decl_ctx_to_die.insert(std::make_pair(decl_ctx, die.MainCUtoDWARFDIEPair(main_unit))); } -bool DWARFASTParserClang::CopyUniqueClassMethodTypes( +bool DWARFASTParserClang::CopyUniqueClassMethodTypes(DWARFCompileUnit *main_unit, const DWARFDIE &src_class_die, const DWARFDIE &dst_class_die, lldb_private::Type *class_type, std::vector &failures) { if (!class_type || !src_class_die || !dst_class_die) @@ -3675,12 +3709,12 @@ dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); clang::DeclContext *src_decl_ctx = - src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; + src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.MainCUtoDIEPair(main_unit)]; if (src_decl_ctx) { LLDB_LOGF(log, "uniquing decl context %p from 0x%8.8x for 0x%8.8x", static_cast(src_decl_ctx), src_die.GetOffset(), dst_die.GetOffset()); - dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, dst_die); + dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, main_unit, dst_die); } else { LLDB_LOGF(log, "warning: tried to unique decl context from 0x%8.8x for " @@ -3689,14 +3723,14 @@ } Type *src_child_type = - dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; + dst_die.GetDWARF()->GetDIEToType()[src_die.MainCUtoDIEPair(main_unit)]; if (src_child_type) { LLDB_LOGF(log, "uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", static_cast(src_child_type), src_child_type->GetID(), src_die.GetOffset(), dst_die.GetOffset()); - dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type; + dst_die.GetDWARF()->GetDIEToType()[dst_die.MainCUtoDIEPair(main_unit)] = src_child_type; } else { LLDB_LOGF(log, "warning: tried to unique lldb_private::Type from " @@ -3719,12 +3753,12 @@ if (src_die && (src_die.Tag() == dst_die.Tag())) { clang::DeclContext *src_decl_ctx = - src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; + src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.MainCUtoDIEPair(main_unit)]; if (src_decl_ctx) { LLDB_LOGF(log, "uniquing decl context %p from 0x%8.8x for 0x%8.8x", static_cast(src_decl_ctx), src_die.GetOffset(), dst_die.GetOffset()); - dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, dst_die); + dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, main_unit, dst_die); } else { LLDB_LOGF(log, "warning: tried to unique decl context from 0x%8.8x " @@ -3733,14 +3767,14 @@ } Type *src_child_type = - dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; + dst_die.GetDWARF()->GetDIEToType()[src_die.MainCUtoDIEPair(main_unit)]; if (src_child_type) { LLDB_LOGF( log, "uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", static_cast(src_child_type), src_child_type->GetID(), src_die.GetOffset(), dst_die.GetOffset()); - dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = + dst_die.GetDWARF()->GetDIEToType()[dst_die.MainCUtoDIEPair(main_unit)] = src_child_type; } else { LLDB_LOGF(log, @@ -3774,12 +3808,12 @@ if (dst_die) { // Both classes have the artificial types, link them clang::DeclContext *src_decl_ctx = - src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; + src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.MainCUtoDIEPair(main_unit)]; if (src_decl_ctx) { LLDB_LOGF(log, "uniquing decl context %p from 0x%8.8x for 0x%8.8x", static_cast(src_decl_ctx), src_die.GetOffset(), dst_die.GetOffset()); - dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, dst_die); + dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, main_unit, dst_die); } else { LLDB_LOGF(log, "warning: tried to unique decl context from 0x%8.8x " @@ -3788,14 +3822,14 @@ } Type *src_child_type = - dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; + dst_die.GetDWARF()->GetDIEToType()[src_die.MainCUtoDIEPair(main_unit)]; if (src_child_type) { LLDB_LOGF( log, "uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", static_cast(src_child_type), src_child_type->GetID(), src_die.GetOffset(), dst_die.GetOffset()); - dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type; + dst_die.GetDWARF()->GetDIEToType()[dst_die.MainCUtoDIEPair(main_unit)] = src_child_type; } else { LLDB_LOGF(log, "warning: tried to unique lldb_private::Type from " diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h @@ -17,10 +17,12 @@ class DIERef; class DWARFASTParser; class DWARFAttributes; +class DWARFCompileUnit; class DWARFUnit; class DWARFDebugInfoEntry; class DWARFDeclContext; class SymbolFileDWARF; +class DWARFCompileUnit; class DWARFBaseDIE { public: @@ -90,7 +92,7 @@ // but it might have a SymbolFileDWARF::GetID() in the high 32 bits if // we are doing Darwin DWARF in .o file, or DWARF stand alone debug // info. - lldb::user_id_t GetID() const; + lldb::user_id_t GetID(DWARFCompileUnit *main_unit) const; const char *GetName() const; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp @@ -61,9 +61,9 @@ return fail_value; } -lldb::user_id_t DWARFBaseDIE::GetID() const { +lldb::user_id_t DWARFBaseDIE::GetID(DWARFCompileUnit *main_unit) const { if (IsValid()) - return GetDWARF()->GetUID(*this); + return GetDWARF()->GetUID(main_unit, *this); return LLDB_INVALID_UID; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h @@ -20,6 +20,8 @@ static bool classof(const DWARFUnit *unit) { return !unit->IsTypeUnit(); } + DWARFCompileUnit &GetNonSkeletonUnit(); + private: DWARFCompileUnit(SymbolFileDWARF &dwarf, lldb::user_id_t uid, const DWARFUnitHeader &header, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp @@ -113,3 +113,7 @@ } } } + +DWARFCompileUnit &DWARFCompileUnit::GetNonSkeletonUnit() { + return llvm::cast(DWARFUnit::GetNonSkeletonUnit()); +} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h @@ -35,10 +35,10 @@ void AppendTypeName(lldb_private::Stream &s) const; - lldb_private::Type *ResolveType() const; + lldb_private::Type *ResolveType(DWARFCompileUnit *main_unit) const; // Resolve a type by UID using this DIE's DWARF file - lldb_private::Type *ResolveTypeUID(const DWARFDIE &die) const; + lldb_private::Type *ResolveTypeUID(DWARFCompileUnit *main_unit, const DWARFDIE &die) const; // Functions for obtaining DIE relations and references @@ -88,6 +88,14 @@ int &decl_line, int &decl_column, int &call_file, int &call_line, int &call_column, lldb_private::DWARFExpression *frame_base) const; + + DWARFCompileUnit *MainDWARFCompileUnit(DWARFCompileUnit *main_unit) const; + DWARFUnit *MainDWARFUnit(DWARFCompileUnit *main_unit) const; + std::pair MainCUtoDWARFDIEPair(DWARFCompileUnit *main_unit) const; + std::pair MainCUtoDIEPair(DWARFCompileUnit *main_unit) const; + +protected: + DWARFCompileUnit *MainDWARFCompileUnitOrNull(DWARFCompileUnit *main_unit) const; }; #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDIE_H diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp @@ -12,7 +12,8 @@ #include "DWARFDebugInfo.h" #include "DWARFDebugInfoEntry.h" #include "DWARFDeclContext.h" -#include "DWARFUnit.h" +#include "DWARFCompileUnit.h" +#include "SymbolFileDWARFDwo.h" using namespace lldb_private; @@ -345,16 +346,16 @@ } } -lldb_private::Type *DWARFDIE::ResolveType() const { +lldb_private::Type *DWARFDIE::ResolveType(DWARFCompileUnit *main_unit) const { if (IsValid()) - return GetDWARF()->ResolveType(*this, true); + return MainDWARFUnit(main_unit)->GetSymbolFileDWARF().ResolveType(main_unit, *this, true); else return nullptr; } -lldb_private::Type *DWARFDIE::ResolveTypeUID(const DWARFDIE &die) const { - if (SymbolFileDWARF *dwarf = GetDWARF()) - return dwarf->ResolveTypeUID(die, true); +lldb_private::Type *DWARFDIE::ResolveTypeUID(DWARFCompileUnit *main_unit, const DWARFDIE &die) const { + if (SymbolFileDWARF *dwarf = &MainDWARFUnit(main_unit)->GetSymbolFileDWARF()) + return dwarf->ResolveTypeUID(main_unit, die, true); return nullptr; } @@ -448,3 +449,40 @@ } else return false; } + +DWARFCompileUnit *DWARFDIE::MainDWARFCompileUnit(DWARFCompileUnit *main_unit) const { + if (llvm::isa(GetCU())) + return nullptr; + if (!main_unit) + main_unit = llvm::dyn_cast(GetCU()); + lldbassert(main_unit); +#if 0 + if (main_unit) + main_unit = &main_unit->GetNonSkeletonUnit(); +#endif + return main_unit; +} + +DWARFUnit *DWARFDIE::MainDWARFUnit(DWARFCompileUnit *main_unit) const { + main_unit = MainDWARFCompileUnit(main_unit); + if (main_unit) + return main_unit; + return GetCU(); +} + +// FIXME: Is it possible to unify it with MainDWARFCompileUnit()? +DWARFCompileUnit *DWARFDIE::MainDWARFCompileUnitOrNull(DWARFCompileUnit *main_unit) const { + if (GetCU()->GetDwoSymbolFile()) + return nullptr; + if (llvm::isa(&GetCU()->GetSymbolFileDWARF())) + return nullptr; + return MainDWARFCompileUnit(main_unit); +} + +std::pair DWARFDIE::MainCUtoDWARFDIEPair(DWARFCompileUnit *main_unit) const { + return std::make_pair(MainDWARFCompileUnitOrNull(main_unit), *this); +} + +std::pair DWARFDIE::MainCUtoDIEPair(DWARFCompileUnit *main_unit) const { + return std::make_pair(MainDWARFCompileUnitOrNull(main_unit), GetDIE()); +} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h @@ -56,6 +56,8 @@ llvm::Expected GetCompileUnitAranges(); + lldb::user_id_t GetUID(DWARFCompileUnit *main_unit, DIERef ref) const { return m_dwarf.GetUID(main_unit, ref); } + protected: typedef std::vector UnitColl; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h @@ -27,26 +27,26 @@ /// Finds global variables with the given base name. Any additional filtering /// (e.g., to only retrieve variables from a given context) should be done by /// the consumer. - virtual void GetGlobalVariables(ConstString basename, DIEArray &offsets) = 0; + virtual void GetGlobalVariables(ConstString basename, std::vector &offsets) = 0; virtual void GetGlobalVariables(const RegularExpression ®ex, - DIEArray &offsets) = 0; - virtual void GetGlobalVariables(const DWARFUnit &cu, DIEArray &offsets) = 0; - virtual void GetObjCMethods(ConstString class_name, DIEArray &offsets) = 0; + std::vector &offsets) = 0; + virtual void GetGlobalVariables(const DWARFUnit &cu, std::vector &offsets) = 0; + virtual void GetObjCMethods(ConstString class_name, std::vector &offsets) = 0; virtual void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, - DIEArray &offsets) = 0; - virtual void GetTypes(ConstString name, DIEArray &offsets) = 0; - virtual void GetTypes(const DWARFDeclContext &context, DIEArray &offsets) = 0; - virtual void GetNamespaces(ConstString name, DIEArray &offsets) = 0; + std::vector &offsets) = 0; + virtual void GetTypes(ConstString name, std::vector &offsets) = 0; + virtual void GetTypes(const DWARFDeclContext &context, std::vector &offsets) = 0; + virtual void GetNamespaces(ConstString name, std::vector &offsets) = 0; virtual void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - std::vector &dies) = 0; + std::vector> &dies) = 0; virtual void GetFunctions(const RegularExpression ®ex, - DIEArray &offsets) = 0; + std::vector &offsets) = 0; - virtual void ReportInvalidDIERef(const DIERef &ref, llvm::StringRef name) = 0; + virtual void ReportInvalidDIEID(lldb::user_id_t uid, llvm::StringRef name) = 0; virtual void Dump(Stream &s) = 0; protected: @@ -56,10 +56,10 @@ /// the function given by "ref" matches search criteria given by /// "parent_decl_ctx" and "name_type_mask", it is inserted into the "dies" /// vector. - void ProcessFunctionDIE(llvm::StringRef name, DIERef ref, + void ProcessFunctionDIE(llvm::StringRef name, lldb::user_id_t uid, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, - uint32_t name_type_mask, std::vector &dies); + uint32_t name_type_mask, std::vector> &dies); }; } // namespace lldb_private diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp @@ -10,20 +10,22 @@ #include "Plugins/Language/ObjC/ObjCLanguage.h" #include "Plugins/SymbolFile/DWARF/DWARFDIE.h" #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" +#include "Plugins/SymbolFile/DWARF/DWARFCompileUnit.h" using namespace lldb_private; using namespace lldb; DWARFIndex::~DWARFIndex() = default; -void DWARFIndex::ProcessFunctionDIE(llvm::StringRef name, DIERef ref, +void DWARFIndex::ProcessFunctionDIE(llvm::StringRef name, user_id_t uid, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - std::vector &dies) { - DWARFDIE die = dwarf.GetDIE(ref); + std::vector> &dies) { + DWARFCompileUnit *main_unit; + DWARFDIE die = dwarf.GetDIEUnlocked(uid, &main_unit); if (!die) { - ReportInvalidDIERef(ref, name); + ReportInvalidDIEID(uid, name); return; } @@ -36,12 +38,14 @@ // Otherwise, we need to also check that the context matches. If it does not // match, we do nothing. - if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) + if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, main_unit, die)) return; + auto diepair = die.MainCUtoDWARFDIEPair(main_unit); + // In case of a full match, we just insert everything we find. if (name_type_mask & eFunctionNameTypeFull) { - dies.push_back(die); + dies.push_back(diepair); return; } @@ -49,7 +53,7 @@ // possible selector. if (name_type_mask & eFunctionNameTypeSelector && ObjCLanguage::IsPossibleObjCMethodName(die.GetName())) { - dies.push_back(die); + dies.push_back(diepair); return; } @@ -61,6 +65,6 @@ // searching for. if ((looking_for_methods && looking_for_functions) || looking_for_methods == die.IsMethod()) - dies.push_back(die); + dies.push_back(diepair); } } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h @@ -25,24 +25,24 @@ void Preload() override { m_fallback.Preload(); } - void GetGlobalVariables(ConstString basename, DIEArray &offsets) override; + void GetGlobalVariables(ConstString basename, std::vector &offsets) override; void GetGlobalVariables(const RegularExpression ®ex, - DIEArray &offsets) override; - void GetGlobalVariables(const DWARFUnit &cu, DIEArray &offsets) override; - void GetObjCMethods(ConstString class_name, DIEArray &offsets) override {} + std::vector &offsets) override; + void GetGlobalVariables(const DWARFUnit &cu, std::vector &offsets) override; + void GetObjCMethods(ConstString class_name, std::vector &offsets) override {} void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, - DIEArray &offsets) override; - void GetTypes(ConstString name, DIEArray &offsets) override; - void GetTypes(const DWARFDeclContext &context, DIEArray &offsets) override; - void GetNamespaces(ConstString name, DIEArray &offsets) override; + std::vector &offsets) override; + void GetTypes(ConstString name, std::vector &offsets) override; + void GetTypes(const DWARFDeclContext &context, std::vector &offsets) override; + void GetNamespaces(ConstString name, std::vector &offsets) override; void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - std::vector &dies) override; + std::vector> &dies) override; void GetFunctions(const RegularExpression ®ex, - DIEArray &offsets) override; + std::vector &offsets) override; - void ReportInvalidDIERef(const DIERef &ref, llvm::StringRef name) override {} + void ReportInvalidDIEID(lldb::user_id_t uid, llvm::StringRef name) override {} void Dump(Stream &s) override; private: @@ -68,7 +68,7 @@ ManualDWARFIndex m_fallback; llvm::Optional ToDIERef(const DebugNames::Entry &entry); - void Append(const DebugNames::Entry &entry, DIEArray &offsets); + void Append(const DebugNames::Entry &entry, std::vector &offsets); static void MaybeLogLookupError(llvm::Error error, const DebugNames::NameIndex &ni, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -58,9 +58,10 @@ } void DebugNamesDWARFIndex::Append(const DebugNames::Entry &entry, - DIEArray &offsets) { + std::vector &offsets) { if (llvm::Optional ref = ToDIERef(entry)) - offsets.push_back(*ref); + // FIXME: DWZ + offsets.push_back(m_debug_info.GetUID(nullptr/*main_unit*/,*ref)); } void DebugNamesDWARFIndex::MaybeLogLookupError(llvm::Error error, @@ -75,7 +76,7 @@ } void DebugNamesDWARFIndex::GetGlobalVariables(ConstString basename, - DIEArray &offsets) { + std::vector &offsets) { m_fallback.GetGlobalVariables(basename, offsets); for (const DebugNames::Entry &entry : @@ -88,7 +89,7 @@ } void DebugNamesDWARFIndex::GetGlobalVariables(const RegularExpression ®ex, - DIEArray &offsets) { + std::vector &offsets) { m_fallback.GetGlobalVariables(regex, offsets); for (const DebugNames::NameIndex &ni: *m_debug_names_up) { @@ -110,7 +111,7 @@ } void DebugNamesDWARFIndex::GetGlobalVariables(const DWARFUnit &cu, - DIEArray &offsets) { + std::vector &offsets) { m_fallback.GetGlobalVariables(cu, offsets); uint64_t cu_offset = cu.GetOffset(); @@ -133,11 +134,12 @@ void DebugNamesDWARFIndex::GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, - DIEArray &offsets) { + std::vector &offsets) { m_fallback.GetCompleteObjCClass(class_name, must_be_implementation, offsets); // Keep a list of incomplete types as fallback for when we don't find the // complete type. + // FIXME: DWZ DIEArray incomplete_types; for (const DebugNames::Entry &entry : @@ -163,18 +165,21 @@ if (die.GetAttributeValueAsUnsigned(DW_AT_APPLE_objc_complete_type, 0)) { // If we find the complete version we're done. - offsets.push_back(*ref); + // FIXME: DWZ + offsets.push_back(m_debug_info.GetUID(nullptr/*main_unit*/,*ref)); return; } else { incomplete_types.push_back(*ref); } } - offsets.insert(offsets.end(), incomplete_types.begin(), - incomplete_types.end()); + offsets.reserve(offsets.size() + incomplete_types.size()); + for (const auto ref : incomplete_types) + // FIXME: DWZ + offsets.push_back(m_debug_info.GetUID(nullptr/*main_unit*/,ref)); } -void DebugNamesDWARFIndex::GetTypes(ConstString name, DIEArray &offsets) { +void DebugNamesDWARFIndex::GetTypes(ConstString name, std::vector &offsets) { m_fallback.GetTypes(name, offsets); for (const DebugNames::Entry &entry : @@ -185,7 +190,7 @@ } void DebugNamesDWARFIndex::GetTypes(const DWARFDeclContext &context, - DIEArray &offsets) { + std::vector &offsets) { m_fallback.GetTypes(context, offsets); for (const DebugNames::Entry &entry : @@ -195,7 +200,7 @@ } } -void DebugNamesDWARFIndex::GetNamespaces(ConstString name, DIEArray &offsets) { +void DebugNamesDWARFIndex::GetNamespaces(ConstString name, std::vector &offsets) { m_fallback.GetNamespaces(name, offsets); for (const DebugNames::Entry &entry : @@ -208,9 +213,9 @@ void DebugNamesDWARFIndex::GetFunctions( ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - std::vector &dies) { + std::vector> &dies) { - std::vector v; + std::vector> v; m_fallback.GetFunctions(name, dwarf, parent_decl_ctx, name_type_mask, v); for (const DebugNames::Entry &entry : @@ -220,18 +225,20 @@ continue; if (llvm::Optional ref = ToDIERef(entry)) - ProcessFunctionDIE(name.GetStringRef(), *ref, dwarf, parent_decl_ctx, + // FIXME: DWZ + ProcessFunctionDIE(name.GetStringRef(), dwarf.GetUID(nullptr/*main_unit*/, *ref), dwarf, parent_decl_ctx, name_type_mask, v); } - std::set seen; - for (DWARFDIE die : v) - if (seen.insert(die.GetDIE()).second) - dies.push_back(die); + std::set> seen; + for (const auto &diepair : v) + if (seen.insert(std::make_pair(diepair.first, diepair.second.GetDIE())).second) + // FIXME: DWZ + dies.push_back(std::make_pair(diepair.first, diepair.second)); } void DebugNamesDWARFIndex::GetFunctions(const RegularExpression ®ex, - DIEArray &offsets) { + std::vector &offsets) { m_fallback.GetFunctions(regex, offsets); for (const DebugNames::NameIndex &ni: *m_debug_names_up) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h --- a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h @@ -19,6 +19,7 @@ #include "DWARFDefines.h" #include "DWARFFormValue.h" #include "NameToDIE.h" +#include "DIERef.h" class DWARFMappedHash { public: diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h @@ -26,23 +26,23 @@ void Preload() override { Index(); } - void GetGlobalVariables(ConstString basename, DIEArray &offsets) override; + void GetGlobalVariables(ConstString basename, std::vector &offsets) override; void GetGlobalVariables(const RegularExpression ®ex, - DIEArray &offsets) override; - void GetGlobalVariables(const DWARFUnit &unit, DIEArray &offsets) override; - void GetObjCMethods(ConstString class_name, DIEArray &offsets) override; + std::vector &offsets) override; + void GetGlobalVariables(const DWARFUnit &unit, std::vector &offsets) override; + void GetObjCMethods(ConstString class_name, std::vector &offsets) override; void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, - DIEArray &offsets) override; - void GetTypes(ConstString name, DIEArray &offsets) override; - void GetTypes(const DWARFDeclContext &context, DIEArray &offsets) override; - void GetNamespaces(ConstString name, DIEArray &offsets) override; + std::vector &offsets) override; + void GetTypes(ConstString name, std::vector &offsets) override; + void GetTypes(const DWARFDeclContext &context, std::vector &offsets) override; + void GetNamespaces(ConstString name, std::vector &offsets) override; void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - std::vector &dies) override; - void GetFunctions(const RegularExpression ®ex, DIEArray &offsets) override; + std::vector> &dies) override; + void GetFunctions(const RegularExpression ®ex, std::vector &offsets) override; - void ReportInvalidDIERef(const DIERef &ref, llvm::StringRef name) override {} + void ReportInvalidDIEID(lldb::user_id_t uid, llvm::StringRef name) override {} void Dump(Stream &s) override; private: @@ -59,7 +59,7 @@ void Index(); void IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp, IndexSet &set); - static void IndexUnitImpl(DWARFUnit &unit, + static void IndexUnitImpl(DWARFUnit &unit, DWARFCompileUnit *main_unit, const lldb::LanguageType cu_language, IndexSet &set); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -12,6 +12,7 @@ #include "Plugins/SymbolFile/DWARF/DWARFDeclContext.h" #include "Plugins/SymbolFile/DWARF/LogChannelDWARF.h" #include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h" +#include "Plugins/SymbolFile/DWARF/DWARFCompileUnit.h" #include "lldb/Core/Module.h" #include "lldb/Host/TaskPool.h" #include "lldb/Symbol/ObjectFile.h" @@ -114,24 +115,25 @@ } const LanguageType cu_language = SymbolFileDWARF::GetLanguage(unit); + DWARFCompileUnit *main_unit = llvm::dyn_cast(&unit); - IndexUnitImpl(unit, cu_language, set); + IndexUnitImpl(unit, main_unit, cu_language, set); if (SymbolFileDWARFDwo *dwo_symbol_file = unit.GetDwoSymbolFile()) { // Type units in a dwp file are indexed separately, so we just need to // process the split unit here. However, if the split unit is in a dwo file, // then we need to process type units here. if (dwo_symbol_file == dwp) { - IndexUnitImpl(unit.GetNonSkeletonUnit(), cu_language, set); + IndexUnitImpl(unit.GetNonSkeletonUnit(), main_unit, cu_language, set); } else { DWARFDebugInfo &dwo_info = dwo_symbol_file->DebugInfo(); for (size_t i = 0; i < dwo_info.GetNumUnits(); ++i) - IndexUnitImpl(*dwo_info.GetUnitAtIndex(i), cu_language, set); + IndexUnitImpl(*dwo_info.GetUnitAtIndex(i), main_unit, cu_language, set); } } } -void ManualDWARFIndex::IndexUnitImpl(DWARFUnit &unit, +void ManualDWARFIndex::IndexUnitImpl(DWARFUnit &unit, DWARFCompileUnit *main_unit, const LanguageType cu_language, IndexSet &set) { for (const DWARFDebugInfoEntry &die : unit.dies()) { @@ -263,7 +265,7 @@ } } - DIERef ref = *DWARFDIE(&unit, &die).GetDIERef(); + user_id_t uid = DWARFDIE(&unit, &die).GetID(main_unit); switch (tag) { case DW_TAG_inlined_subroutine: case DW_TAG_subprogram: @@ -281,17 +283,17 @@ ConstString objc_fullname_no_category_name( objc_method.GetFullNameWithoutCategory(true)); ConstString class_name_no_category(objc_method.GetClassName()); - set.function_fullnames.Insert(ConstString(name), ref); + set.function_fullnames.Insert(ConstString(name), uid); if (class_name_with_category) - set.objc_class_selectors.Insert(class_name_with_category, ref); + set.objc_class_selectors.Insert(class_name_with_category, uid); if (class_name_no_category && class_name_no_category != class_name_with_category) - set.objc_class_selectors.Insert(class_name_no_category, ref); + set.objc_class_selectors.Insert(class_name_no_category, uid); if (objc_selector_name) - set.function_selectors.Insert(objc_selector_name, ref); + set.function_selectors.Insert(objc_selector_name, uid); if (objc_fullname_no_category_name) set.function_fullnames.Insert(objc_fullname_no_category_name, - ref); + uid); } } // If we have a mangled name, then the DW_AT_name attribute is @@ -299,12 +301,12 @@ bool is_method = DWARFDIE(&unit, &die).IsMethod(); if (is_method) - set.function_methods.Insert(ConstString(name), ref); + set.function_methods.Insert(ConstString(name), uid); else - set.function_basenames.Insert(ConstString(name), ref); + set.function_basenames.Insert(ConstString(name), uid); if (!is_method && !mangled_cstr && !is_objc_method) - set.function_fullnames.Insert(ConstString(name), ref); + set.function_fullnames.Insert(ConstString(name), uid); } if (mangled_cstr) { // Make sure our mangled name isn't the same string table entry as @@ -314,7 +316,7 @@ if (name && name != mangled_cstr && ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0))) { - set.function_fullnames.Insert(ConstString(mangled_cstr), ref); + set.function_fullnames.Insert(ConstString(mangled_cstr), uid); } } } @@ -332,19 +334,19 @@ case DW_TAG_union_type: case DW_TAG_unspecified_type: if (name && !is_declaration) - set.types.Insert(ConstString(name), ref); + set.types.Insert(ConstString(name), uid); if (mangled_cstr && !is_declaration) - set.types.Insert(ConstString(mangled_cstr), ref); + set.types.Insert(ConstString(mangled_cstr), uid); break; case DW_TAG_namespace: if (name) - set.namespaces.Insert(ConstString(name), ref); + set.namespaces.Insert(ConstString(name), uid); break; case DW_TAG_variable: if (name && has_location_or_const_value && is_global_or_static_variable) { - set.globals.Insert(ConstString(name), ref); + set.globals.Insert(ConstString(name), uid); // Be sure to include variables by their mangled and demangled names if // they have any since a variable can have a basename "i", a mangled // named "_ZN12_GLOBAL__N_11iE" and a demangled mangled name @@ -356,7 +358,7 @@ // entries if (mangled_cstr && name != mangled_cstr && ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0))) { - set.globals.Insert(ConstString(mangled_cstr), ref); + set.globals.Insert(ConstString(mangled_cstr), uid); } } break; @@ -367,48 +369,48 @@ } } -void ManualDWARFIndex::GetGlobalVariables(ConstString basename, DIEArray &offsets) { +void ManualDWARFIndex::GetGlobalVariables(ConstString basename, std::vector &offsets) { Index(); m_set.globals.Find(basename, offsets); } void ManualDWARFIndex::GetGlobalVariables(const RegularExpression ®ex, - DIEArray &offsets) { + std::vector &offsets) { Index(); m_set.globals.Find(regex, offsets); } void ManualDWARFIndex::GetGlobalVariables(const DWARFUnit &unit, - DIEArray &offsets) { + std::vector &offsets) { Index(); m_set.globals.FindAllEntriesForUnit(unit, offsets); } void ManualDWARFIndex::GetObjCMethods(ConstString class_name, - DIEArray &offsets) { + std::vector &offsets) { Index(); m_set.objc_class_selectors.Find(class_name, offsets); } void ManualDWARFIndex::GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, - DIEArray &offsets) { + std::vector &offsets) { Index(); m_set.types.Find(class_name, offsets); } -void ManualDWARFIndex::GetTypes(ConstString name, DIEArray &offsets) { +void ManualDWARFIndex::GetTypes(ConstString name, std::vector &offsets) { Index(); m_set.types.Find(name, offsets); } void ManualDWARFIndex::GetTypes(const DWARFDeclContext &context, - DIEArray &offsets) { + std::vector &offsets) { Index(); m_set.types.Find(ConstString(context[0].name), offsets); } -void ManualDWARFIndex::GetNamespaces(ConstString name, DIEArray &offsets) { +void ManualDWARFIndex::GetNamespaces(ConstString name, std::vector &offsets) { Index(); m_set.namespaces.Find(name, offsets); } @@ -416,55 +418,59 @@ void ManualDWARFIndex::GetFunctions(ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - std::vector &dies) { + std::vector> &dies) { Index(); if (name_type_mask & eFunctionNameTypeFull) { - DIEArray offsets; + std::vector offsets; m_set.function_fullnames.Find(name, offsets); - for (const DIERef &die_ref: offsets) { - DWARFDIE die = dwarf.GetDIE(die_ref); + for (user_id_t uid : offsets) { + DWARFCompileUnit *main_unit; + DWARFDIE die = dwarf.GetDIEUnlocked(uid, &main_unit); if (!die) continue; - if (SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) - dies.push_back(die); + if (SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, main_unit, die)) + dies.push_back(die.MainCUtoDWARFDIEPair(main_unit)); } } if (name_type_mask & eFunctionNameTypeBase) { - DIEArray offsets; + std::vector offsets; m_set.function_basenames.Find(name, offsets); - for (const DIERef &die_ref: offsets) { - DWARFDIE die = dwarf.GetDIE(die_ref); + for (user_id_t uid : offsets) { + DWARFCompileUnit *main_unit; + DWARFDIE die = dwarf.GetDIEUnlocked(uid, &main_unit); if (!die) continue; - if (SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) - dies.push_back(die); + if (SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, main_unit, die)) + dies.push_back(die.MainCUtoDWARFDIEPair(main_unit)); } offsets.clear(); } if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.IsValid()) { - DIEArray offsets; + std::vector offsets; m_set.function_methods.Find(name, offsets); - for (const DIERef &die_ref: offsets) { - if (DWARFDIE die = dwarf.GetDIE(die_ref)) - dies.push_back(die); + for (user_id_t uid : offsets) { + DWARFCompileUnit *main_unit; + if (DWARFDIE die = dwarf.GetDIEUnlocked(uid, &main_unit)) + dies.push_back(die.MainCUtoDWARFDIEPair(main_unit)); } } if (name_type_mask & eFunctionNameTypeSelector && !parent_decl_ctx.IsValid()) { - DIEArray offsets; + std::vector offsets; m_set.function_selectors.Find(name, offsets); - for (const DIERef &die_ref: offsets) { - if (DWARFDIE die = dwarf.GetDIE(die_ref)) - dies.push_back(die); + for (user_id_t uid : offsets) { + DWARFCompileUnit *main_unit; + if (DWARFDIE die = dwarf.GetDIEUnlocked(uid, &main_unit)) + dies.push_back(die.MainCUtoDWARFDIEPair(main_unit)); } } } void ManualDWARFIndex::GetFunctions(const RegularExpression ®ex, - DIEArray &offsets) { + std::vector &offsets) { Index(); m_set.function_basenames.Find(regex, offsets); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h --- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h @@ -11,7 +11,6 @@ #include -#include "DIERef.h" #include "lldb/Core/UniqueCStringMap.h" #include "lldb/Core/dwarf.h" #include "lldb/lldb-defines.h" @@ -26,28 +25,28 @@ void Dump(lldb_private::Stream *s); - void Insert(lldb_private::ConstString name, const DIERef &die_ref); + void Insert(lldb_private::ConstString name, lldb::user_id_t uid); void Append(const NameToDIE &other); void Finalize(); size_t Find(lldb_private::ConstString name, - DIEArray &info_array) const; + std::vector &info_array) const; size_t Find(const lldb_private::RegularExpression ®ex, - DIEArray &info_array) const; + std::vector &info_array) const; size_t FindAllEntriesForUnit(const DWARFUnit &unit, - DIEArray &info_array) const; + std::vector &info_array) const; void ForEach(std::function const + lldb::user_id_t uid)> const &callback) const; protected: - lldb_private::UniqueCStringMap m_map; + lldb_private::UniqueCStringMap m_map; }; #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_NAMETODIE_H diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp @@ -22,44 +22,57 @@ m_map.SizeToFit(); } -void NameToDIE::Insert(ConstString name, const DIERef &die_ref) { - m_map.Append(name, die_ref); +void NameToDIE::Insert(ConstString name, user_id_t uid) { + m_map.Append(name, uid); } -size_t NameToDIE::Find(ConstString name, DIEArray &info_array) const { +size_t NameToDIE::Find(ConstString name, std::vector &info_array) const { return m_map.GetValues(name, info_array); } size_t NameToDIE::Find(const RegularExpression ®ex, - DIEArray &info_array) const { + std::vector &info_array) const { return m_map.GetValues(regex, info_array); } size_t NameToDIE::FindAllEntriesForUnit(const DWARFUnit &unit, - DIEArray &info_array) const { + std::vector &info_array) const { const size_t initial_size = info_array.size(); const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { - const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i); + user_id_t uid = m_map.GetValueAtIndexUnchecked(i); + llvm::Optional die_ref_opt = unit.GetSymbolFileDWARF().GetDIERef(uid); + if (!die_ref_opt) + continue; + DIERef die_ref = *die_ref_opt; if (unit.GetSymbolFileDWARF().GetDwoNum() == die_ref.dwo_num() && unit.GetDebugSection() == die_ref.section() && unit.GetOffset() <= die_ref.die_offset() && die_ref.die_offset() < unit.GetNextUnitOffset()) - info_array.push_back(die_ref); + info_array.push_back(uid); } return info_array.size() - initial_size; } void NameToDIE::Dump(Stream *s) { + llvm::raw_ostream &OS = s->AsRawOstream(); const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { - s->Format("{0} \"{1}\"\n", m_map.GetValueAtIndexUnchecked(i), - m_map.GetCStringAtIndexUnchecked(i)); + user_id_t uid = m_map.GetValueAtIndexUnchecked(i); + uint32_t upper = (uid >> 32) & 0x1fffffff; + if (upper != 0x1fffffff) + OS << llvm::format_hex_no_prefix(upper, 8) << "/"; + OS << (uid & (1ULL << 63) ? "TYPE" : "INFO"); + if (uid & (1ULL << 61)) + OS << "/DWZCOMMON"; + else if (uid & (1ULL << 62)) + OS << "/DWZ"; + OS << "/" << llvm::format_hex_no_prefix(uid & 0xffffffff, 8) << " \"" << m_map.GetCStringAtIndexUnchecked(i).GetStringRef() << "\"\n"; } } void NameToDIE::ForEach( - std::function const + std::function const &callback) const { const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -139,7 +139,7 @@ bool CompleteType(lldb_private::CompilerType &compiler_type) override; - lldb_private::Type *ResolveType(const DWARFDIE &die, + lldb_private::Type *ResolveType(DWARFCompileUnit *main_unit, const DWARFDIE &die, bool assert_not_being_parsed = true, bool resolve_function_context = false); @@ -238,7 +238,7 @@ GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu); virtual size_t GetObjCMethodDIEOffsets(lldb_private::ConstString class_name, - DIEArray &method_die_offsets); + std::vector &method_die_offsets); bool Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu); @@ -260,15 +260,15 @@ DWARFDIE GetDIE(lldb::user_id_t uid); - lldb::user_id_t GetUID(const DWARFBaseDIE &die) { - return GetUID(die.GetDIERef()); - } + DWARFDIE GetDIEUnlocked(lldb::user_id_t uid, DWARFCompileUnit **main_unit_return = nullptr); + + lldb::user_id_t GetUID(DWARFCompileUnit *main_unit, const DWARFBaseDIE &die); - lldb::user_id_t GetUID(const llvm::Optional &ref) { - return ref ? GetUID(*ref) : LLDB_INVALID_UID; + lldb::user_id_t GetUID(DWARFCompileUnit *main_unit, const llvm::Optional &ref) { + return ref ? GetUID(main_unit, *ref) : LLDB_INVALID_UID; } - lldb::user_id_t GetUID(DIERef ref); + lldb::user_id_t GetUID(DWARFCompileUnit *main_unit, DIERef ref); std::shared_ptr GetDwoSymbolFileForCompileUnit(DWARFUnit &dwarf_cu, @@ -280,7 +280,7 @@ llvm::Optional GetDWOId(); static bool - DIEInDeclContext(const lldb_private::CompilerDeclContext &parent_decl_ctx, + DIEInDeclContext(const lldb_private::CompilerDeclContext &parent_decl_ctx, DWARFCompileUnit *main_unit, const DWARFDIE &die); std::vector> @@ -303,12 +303,12 @@ // CompilerDecl related functions - static lldb_private::CompilerDecl GetDecl(const DWARFDIE &die); + static lldb_private::CompilerDecl GetDecl(DWARFCompileUnit *main_unit, const DWARFDIE &die); - static lldb_private::CompilerDeclContext GetDeclContext(const DWARFDIE &die); + static lldb_private::CompilerDeclContext GetDeclContext(DWARFCompileUnit *main_unit, const DWARFDIE &die); static lldb_private::CompilerDeclContext - GetContainingDeclContext(const DWARFDIE &die); + GetContainingDeclContext(DWARFCompileUnit *main_unit, const DWARFDIE &die); static DWARFDeclContext GetDWARFDeclContext(const DWARFDIE &die); @@ -316,15 +316,23 @@ static lldb::LanguageType GetLanguage(DWARFUnit &unit); + llvm::Optional GetDIERef(lldb::user_id_t uid) { + llvm::Optional decoded = DecodeUID(uid); + if (!decoded) + return {}; + lldbassert(&decoded->dwarf==this); // FIXME:DWZ + return decoded->ref; + } + protected: - typedef llvm::DenseMap + typedef llvm::DenseMap, lldb_private::Type *> DIEToTypePtr; - typedef llvm::DenseMap + typedef llvm::DenseMap, lldb::VariableSP> DIEToVariableSP; - typedef llvm::DenseMap, lldb::opaque_compiler_type_t> DIEToClangType; - typedef llvm::DenseMap ClangTypeToDIE; + typedef llvm::DenseMap ClangTypeToDIE; DISALLOW_COPY_AND_ASSIGN(SymbolFileDWARF); @@ -342,12 +350,12 @@ lldb::CompUnitSP ParseCompileUnit(DWARFCompileUnit &dwarf_cu); - virtual DWARFUnit * + DWARFCompileUnit * GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit); DWARFUnit *GetNextUnparsedDWARFCompileUnit(DWARFUnit *prev_cu); - bool GetFunction(const DWARFDIE &die, lldb_private::SymbolContext &sc); + bool GetFunction(DWARFCompileUnit *main_unit, const DWARFDIE &die, lldb_private::SymbolContext &sc); lldb_private::Function *ParseFunction(lldb_private::CompileUnit &comp_unit, const DWARFDIE &die); @@ -363,10 +371,10 @@ lldb::TypeSP ParseType(const lldb_private::SymbolContext &sc, const DWARFDIE &die, bool *type_is_new); - lldb_private::Type *ResolveTypeUID(const DWARFDIE &die, + lldb_private::Type *ResolveTypeUID(DWARFCompileUnit *main_unit, const DWARFDIE &die, bool assert_not_being_parsed); - lldb_private::Type *ResolveTypeUID(const DIERef &die_ref); + lldb_private::Type *ResolveTypeUID(DWARFCompileUnit *main_unit, const DIERef &die_ref); lldb::VariableSP ParseVariableDIE(const lldb_private::SymbolContext &sc, const DWARFDIE &die, @@ -381,7 +389,7 @@ bool ClassOrStructIsVirtual(const DWARFDIE &die); // Given a die_offset, figure out the symbol context representing that die. - bool ResolveFunction(const DWARFDIE &die, bool include_inlines, + bool ResolveFunction(DWARFCompileUnit *main_unit, const DWARFDIE &die, bool include_inlines, lldb_private::SymbolContextList &sc_list); /// Resolve functions and (possibly) blocks for the given file address and a @@ -401,7 +409,7 @@ lldb_private::Symbol * GetObjCClassSymbol(lldb_private::ConstString objc_class_name); - lldb::TypeSP GetTypeForDIE(const DWARFDIE &die, + lldb::TypeSP GetTypeForDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die, bool resolve_function_context = false); void SetDebugMapModule(const lldb::ModuleSP &module_sp) { @@ -441,7 +449,7 @@ typedef llvm::SetVector TypeSet; - void GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset, + void GetTypes(DWARFCompileUnit *main_unit, const DWARFDIE &die, dw_offset_t min_die_offset, dw_offset_t max_die_offset, uint32_t type_mask, TypeSet &type_set); @@ -470,8 +478,11 @@ struct DecodedUID { SymbolFileDWARF &dwarf; + // FIXME: DWZ + uint32_t main_cu; DIERef ref; }; + llvm::Optional DecodeUIDUnlocked(lldb::user_id_t uid); llvm::Optional DecodeUID(lldb::user_id_t uid); void FindDwpSymbolFile(); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -265,7 +265,7 @@ return debug_map_symfile->GetTypeList(); return SymbolFile::GetTypeList(); } -void SymbolFileDWARF::GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset, +void SymbolFileDWARF::GetTypes(DWARFCompileUnit *main_unit, const DWARFDIE &die, dw_offset_t min_die_offset, dw_offset_t max_die_offset, uint32_t type_mask, TypeSet &type_set) { if (die) { @@ -323,7 +323,7 @@ if (add_type) { const bool assert_not_being_parsed = true; - Type *type = ResolveTypeUID(die, assert_not_being_parsed); + Type *type = ResolveTypeUID(main_unit, die, assert_not_being_parsed); if (type) type_set.insert(type); } @@ -331,7 +331,7 @@ for (DWARFDIE child_die = die.GetFirstChild(); child_die.IsValid(); child_die = child_die.GetSibling()) { - GetTypes(child_die, min_die_offset, max_die_offset, type_mask, type_set); + GetTypes(main_unit, child_die, min_die_offset, max_die_offset, type_mask, type_set); } } } @@ -344,23 +344,22 @@ TypeSet type_set; CompileUnit *comp_unit = nullptr; - DWARFUnit *dwarf_cu = nullptr; if (sc_scope) comp_unit = sc_scope->CalculateSymbolContextCompileUnit(); if (comp_unit) { - dwarf_cu = GetDWARFCompileUnit(comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit); if (!dwarf_cu) return; - GetTypes(dwarf_cu->DIE(), dwarf_cu->GetOffset(), + GetTypes(dwarf_cu, dwarf_cu->DIE(), dwarf_cu->GetOffset(), dwarf_cu->GetNextUnitOffset(), type_mask, type_set); } else { DWARFDebugInfo &info = DebugInfo(); const size_t num_cus = info.GetNumUnits(); for (size_t cu_idx = 0; cu_idx < num_cus; ++cu_idx) { - dwarf_cu = info.GetUnitAtIndex(cu_idx); + DWARFCompileUnit *dwarf_cu = llvm::dyn_cast_or_null(info.GetUnitAtIndex(cu_idx)); if (dwarf_cu) - GetTypes(dwarf_cu->DIE(), 0, UINT32_MAX, type_mask, type_set); + GetTypes(dwarf_cu, dwarf_cu->DIE(), 0, UINT32_MAX, type_mask, type_set); } } @@ -446,7 +445,7 @@ LoadSectionData(eSectionTypeDWARFAppleObjC, apple_objc); m_index = AppleDWARFIndex::Create( - *GetObjectFile()->GetModule(), apple_names, apple_namespaces, + *this, apple_names, apple_namespaces, apple_types, apple_objc, m_context.getOrLoadStrData()); if (m_index) @@ -604,16 +603,24 @@ return *m_info; } -DWARFUnit * +DWARFCompileUnit * SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) { if (!comp_unit) return nullptr; + if (SymbolFileDWARFDwo *dwo = llvm::dyn_cast(this)) + return dwo->GetBaseSymbolFile().GetDWARFCompileUnit(comp_unit); + // The compile unit ID is the index of the DWARF unit. DWARFUnit *dwarf_cu = DebugInfo().GetUnitAtIndex(comp_unit->GetID()); - if (dwarf_cu && dwarf_cu->GetUserData() == nullptr) + if (!dwarf_cu) + return nullptr; + + if (dwarf_cu->GetUserData() == nullptr) dwarf_cu->SetUserData(comp_unit); - return dwarf_cu; + else + lldbassert(dwarf_cu->GetUserData() == comp_unit); + return llvm::cast(dwarf_cu); } DWARFDebugRanges *SymbolFileDWARF::GetDebugRanges() { @@ -765,7 +772,7 @@ } lldb::LanguageType SymbolFileDWARF::ParseLanguage(CompileUnit &comp_unit) { std::lock_guard guard(GetModuleMutex()); - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); if (dwarf_cu) return GetLanguage(*dwarf_cu); else @@ -776,7 +783,7 @@ static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer(func_cat, "SymbolFileDWARF::ParseFunctions"); std::lock_guard guard(GetModuleMutex()); - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); if (!dwarf_cu) return 0; @@ -787,7 +794,7 @@ continue; DWARFDIE die(dwarf_cu, &entry); - if (comp_unit.FindFunctionByUID(die.GetID())) + if (comp_unit.FindFunctionByUID(die.GetID(dwarf_cu))) continue; if (ParseFunction(comp_unit, die)) ++functions_added; @@ -880,7 +887,7 @@ bool SymbolFileDWARF::ParseIsOptimized(CompileUnit &comp_unit) { std::lock_guard guard(GetModuleMutex()); - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); if (dwarf_cu) return dwarf_cu->GetIsOptimized(); return false; @@ -891,7 +898,7 @@ std::vector &imported_modules) { std::lock_guard guard(GetModuleMutex()); assert(sc.comp_unit); - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); if (!dwarf_cu) return false; if (!ClangModulesDeclVendor::LanguageSupportsClangModules( @@ -946,7 +953,7 @@ if (comp_unit.GetLineTable() != nullptr) return true; - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); if (!dwarf_cu) return false; @@ -1028,7 +1035,7 @@ bool SymbolFileDWARF::ParseDebugMacros(CompileUnit &comp_unit) { std::lock_guard guard(GetModuleMutex()); - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); if (dwarf_cu == nullptr) return false; @@ -1072,7 +1079,8 @@ block = parent_block; } else { - BlockSP block_sp(new Block(die.GetID())); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + BlockSP block_sp(new Block(die.GetID(dwarf_cu))); parent_block->AddChild(block_sp); block = block_sp.get(); } @@ -1198,20 +1206,43 @@ decl_ctx); } -user_id_t SymbolFileDWARF::GetUID(DIERef ref) { +user_id_t SymbolFileDWARF::GetUID(DWARFCompileUnit *main_unit, const DWARFBaseDIE &die) { + return GetUID(die.IsValid() && llvm::isa(die.GetCU()) ? main_unit : nullptr, die.GetDIERef()); +} + +user_id_t SymbolFileDWARF::GetUID(DWARFCompileUnit *main_unit, DIERef ref) { if (GetDebugMapSymfile()) return GetID() | ref.die_offset(); - return user_id_t(GetDwoNum().getValueOr(0x7fffffff)) << 32 | +// FIXME: Expensive +DWARFDIE dwarfdie_check=GetDIE(ref); +lldbassert(dwarfdie_check.IsValid()); +lldbassert(*dwarfdie_check.GetDIERef() == ref); + + // WARNING: Use ref.dwo_num(), GetDwoNum() may not be valid in 'this'. + bool has_main_cu = main_unit && (&main_unit->GetSymbolFileDWARF() != this || !main_unit->ContainsDIEOffset(ref.die_offset())); + bool is_dwz = has_main_cu && !ref.dwo_num().hasValue(); + bool is_dwz_common = is_dwz && &main_unit->GetSymbolFileDWARF() != this; + lldbassert(!ref.dwo_num().hasValue() || *ref.dwo_num() < 0x1fffffff); + static_assert(sizeof(ref.die_offset()) * 8 == 32, ""); + + user_id_t retval = user_id_t(is_dwz ? main_unit->GetID() : ref.dwo_num().getValueOr(0x1fffffff)) << 32 | ref.die_offset() | + user_id_t(is_dwz_common) << 61 | + user_id_t(is_dwz) << 62 | (lldb::user_id_t(ref.section() == DIERef::Section::DebugTypes) << 63); + +// FIXME: Expensive +DWARFCompileUnit *main_unit_check; +lldbassert(GetDIEUnlocked(retval, &main_unit_check)==dwarfdie_check); +lldbassert(main_unit_check==main_unit||main_unit_check==nullptr); +lldbassert(!!main_unit_check==is_dwz); + + return retval; } llvm::Optional -SymbolFileDWARF::DecodeUID(lldb::user_id_t uid) { - // This method can be called without going through the symbol vendor so we - // need to lock the module. - std::lock_guard guard(GetModuleMutex()); +SymbolFileDWARF::DecodeUIDUnlocked(lldb::user_id_t uid) { // Anytime we get a "lldb::user_id_t" from an lldb_private::SymbolFile API we // must make sure we use the correct DWARF file when resolving things. On // MacOSX, when using SymbolFileDWARFDebugMap, we will use multiple @@ -1223,7 +1254,7 @@ SymbolFileDWARF *dwarf = debug_map->GetSymbolFileByOSOIndex( debug_map->GetOSOIndexFromUserID(uid)); return DecodedUID{ - *dwarf, {llvm::None, DIERef::Section::DebugInfo, dw_offset_t(uid)}}; + *dwarf, 0xffffffff/*main_cu*/, {llvm::None, DIERef::Section::DebugInfo, dw_offset_t(uid)}}; } dw_offset_t die_offset = uid; if (die_offset == DW_INVALID_OFFSET) @@ -1232,27 +1263,55 @@ DIERef::Section section = uid >> 63 ? DIERef::Section::DebugTypes : DIERef::Section::DebugInfo; - llvm::Optional dwo_num = uid >> 32 & 0x7fffffff; - if (*dwo_num == 0x7fffffff) + bool is_dwz = (uid >> 62) & 1; + // FIXME: DWZ + __attribute__((unused)) bool is_dwz_common = (uid >> 61) & 1; + + llvm::Optional dwo_num = uid >> 32 & 0x1fffffff; + if (*dwo_num == 0x1fffffff || is_dwz) dwo_num = llvm::None; - return DecodedUID{*this, {dwo_num, section, die_offset}}; + llvm::Optional main_cu = uid >> 32 & 0x1fffffff; + if (*main_cu == 0x1fffffff || !is_dwz) + main_cu = llvm::None; + + return DecodedUID{*this, main_cu.hasValue() ? *main_cu : 0xffffffff, {dwo_num, section, die_offset}}; } -DWARFDIE -SymbolFileDWARF::GetDIE(lldb::user_id_t uid) { +llvm::Optional +SymbolFileDWARF::DecodeUID(lldb::user_id_t uid) { // This method can be called without going through the symbol vendor so we // need to lock the module. std::lock_guard guard(GetModuleMutex()); - llvm::Optional decoded = DecodeUID(uid); + return DecodeUIDUnlocked(uid); +} - if (decoded) - return decoded->dwarf.GetDIE(decoded->ref); +DWARFDIE +SymbolFileDWARF::GetDIEUnlocked(lldb::user_id_t uid, DWARFCompileUnit **main_unit_return) { + llvm::Optional decoded = DecodeUIDUnlocked(uid); + + if (decoded) { + DWARFDIE die = decoded->dwarf.GetDIE(decoded->ref); + if (main_unit_return) { + // FIXME: DWZ + *main_unit_return = decoded->main_cu == 0xffffffff ? nullptr : llvm::cast(DebugInfo().GetUnitAtIndex(decoded->main_cu)); + } + return die; + } return DWARFDIE(); } +DWARFDIE +SymbolFileDWARF::GetDIE(lldb::user_id_t uid) { + // This method can be called without going through the symbol vendor so we + // need to lock the module. + std::lock_guard guard(GetModuleMutex()); + + return GetDIEUnlocked(uid); +} + CompilerDecl SymbolFileDWARF::GetDeclForUID(lldb::user_id_t type_uid) { // This method can be called without going through the symbol vendor so we // need to lock the module. @@ -1260,8 +1319,9 @@ // Anytime we have a lldb::user_id_t, we must get the DIE by calling // SymbolFileDWARF::GetDIE(). See comments inside the // SymbolFileDWARF::GetDIE() for details. - if (DWARFDIE die = GetDIE(type_uid)) - return GetDecl(die); + DWARFCompileUnit *main_unit; + if (DWARFDIE die = GetDIEUnlocked(type_uid, &main_unit)) + return GetDecl(main_unit, die); return CompilerDecl(); } @@ -1273,8 +1333,9 @@ // Anytime we have a lldb::user_id_t, we must get the DIE by calling // SymbolFileDWARF::GetDIE(). See comments inside the // SymbolFileDWARF::GetDIE() for details. - if (DWARFDIE die = GetDIE(type_uid)) - return GetDeclContext(die); + DWARFCompileUnit *main_unit; + if (DWARFDIE die = GetDIEUnlocked(type_uid, &main_unit)) + return GetDeclContext(main_unit, die); return CompilerDeclContext(); } @@ -1284,8 +1345,9 @@ // Anytime we have a lldb::user_id_t, we must get the DIE by calling // SymbolFileDWARF::GetDIE(). See comments inside the // SymbolFileDWARF::GetDIE() for details. - if (DWARFDIE die = GetDIE(type_uid)) - return GetContainingDeclContext(die); + DWARFCompileUnit *main_unit; + if (DWARFDIE die = GetDIEUnlocked(type_uid, &main_unit)) + return GetContainingDeclContext(main_unit, die); return CompilerDeclContext(); } @@ -1294,8 +1356,9 @@ // Anytime we have a lldb::user_id_t, we must get the DIE by calling // SymbolFileDWARF::GetDIE(). See comments inside the // SymbolFileDWARF::GetDIE() for details. - if (DWARFDIE type_die = GetDIE(type_uid)) - return type_die.ResolveType(); + DWARFCompileUnit *main_unit; + if (DWARFDIE type_die = GetDIEUnlocked(type_uid, &main_unit)) + return type_die.ResolveType(main_unit); else return nullptr; } @@ -1310,11 +1373,11 @@ return llvm::None; } -Type *SymbolFileDWARF::ResolveTypeUID(const DIERef &die_ref) { - return ResolveType(GetDIE(die_ref), true); +Type *SymbolFileDWARF::ResolveTypeUID(DWARFCompileUnit *main_unit, const DIERef &die_ref) { + return ResolveType(main_unit, GetDIE(die_ref), true); } -Type *SymbolFileDWARF::ResolveTypeUID(const DWARFDIE &die, +Type *SymbolFileDWARF::ResolveTypeUID(DWARFCompileUnit *main_unit, const DWARFDIE &die, bool assert_not_being_parsed) { if (die) { Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); @@ -1348,7 +1411,7 @@ } } } - return ResolveType(die); + return ResolveType(main_unit, die); } return nullptr; } @@ -1398,7 +1461,8 @@ return true; } - DWARFDIE dwarf_die = GetDIE(die_it->getSecond()); + DWARFCompileUnit *main_unit; + DWARFDIE dwarf_die = GetDIEUnlocked(die_it->getSecond(), &main_unit); if (dwarf_die) { // Once we start resolving this type, remove it from the forward // declaration map in case anyone child members or other types require this @@ -1406,14 +1470,15 @@ // to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition are done. GetForwardDeclClangTypeToDie().erase(die_it); - Type *type = GetDIEToType().lookup(dwarf_die.GetDIE()); + Type *type = GetDIEToType().lookup(dwarf_die.MainCUtoDIEPair(main_unit)); + lldbassert(type); Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); if (log) GetObjectFile()->GetModule()->LogMessageVerboseBacktrace( log, "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", - dwarf_die.GetID(), dwarf_die.GetTagAsCString(), + dwarf_die.GetID(nullptr), dwarf_die.GetTagAsCString(), type->GetName().AsCString()); assert(compiler_type); if (DWARFASTParser *dwarf_ast = GetDWARFParser(*dwarf_die.GetCU())) @@ -1422,11 +1487,11 @@ return false; } -Type *SymbolFileDWARF::ResolveType(const DWARFDIE &die, +Type *SymbolFileDWARF::ResolveType(DWARFCompileUnit *main_unit, const DWARFDIE &die, bool assert_not_being_parsed, bool resolve_function_context) { if (die) { - Type *type = GetTypeForDIE(die, resolve_function_context).get(); + Type *type = GetTypeForDIE(main_unit, die, resolve_function_context).get(); if (assert_not_being_parsed) { if (type != DIE_IS_BEING_PARSED) @@ -1458,21 +1523,21 @@ } size_t SymbolFileDWARF::GetObjCMethodDIEOffsets(ConstString class_name, - DIEArray &method_die_offsets) { + std::vector &method_die_offsets) { method_die_offsets.clear(); m_index->GetObjCMethods(class_name, method_die_offsets); return method_die_offsets.size(); } -bool SymbolFileDWARF::GetFunction(const DWARFDIE &die, SymbolContext &sc) { +bool SymbolFileDWARF::GetFunction(DWARFCompileUnit *main_unit, const DWARFDIE &die, SymbolContext &sc) { sc.Clear(false); - if (die && llvm::isa(die.GetCU())) { + if (die && die.MainDWARFCompileUnit(main_unit)) { // Check if the symbol vendor already knows about this compile unit? sc.comp_unit = - GetCompUnitForDWARFCompUnit(llvm::cast(*die.GetCU())); + GetCompUnitForDWARFCompUnit(*die.MainDWARFCompileUnit(main_unit)); - sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get(); + sc.function = sc.comp_unit->FindFunctionByUID(die.GetID(main_unit)).get(); if (sc.function == nullptr) sc.function = ParseFunction(*sc.comp_unit, die); @@ -1497,7 +1562,7 @@ DWARFDIE SymbolFileDWARF::GetDIE(const DIERef &die_ref) { if (die_ref.dwo_num()) { - SymbolFileDWARF *dwarf = *die_ref.dwo_num() == 0x3fffffff + SymbolFileDWARF *dwarf = *die_ref.dwo_num() == 0x1ffffffe ? m_dwp_symfile.get() : this->DebugInfo() .GetUnitAtIndex(*die_ref.dwo_num()) @@ -1745,11 +1810,11 @@ bool lookup_block, SymbolContext &sc) { assert(sc.comp_unit); - DWARFUnit &cu = GetDWARFCompileUnit(sc.comp_unit)->GetNonSkeletonUnit(); + DWARFCompileUnit &cu = GetDWARFCompileUnit(sc.comp_unit)->GetNonSkeletonUnit(); DWARFDIE function_die = cu.LookupAddress(file_vm_addr); DWARFDIE block_die; if (function_die) { - sc.function = sc.comp_unit->FindFunctionByUID(function_die.GetID()).get(); + sc.function = sc.comp_unit->FindFunctionByUID(function_die.GetID(&cu)).get(); if (sc.function == nullptr) sc.function = ParseFunction(*sc.comp_unit, function_die); @@ -1762,9 +1827,9 @@ Block &block = sc.function->GetBlock(true); if (block_die) - sc.block = block.FindBlockByID(block_die.GetID()); + sc.block = block.FindBlockByID(block_die.GetID(&cu)); else - sc.block = block.FindBlockByID(function_die.GetID()); + sc.block = block.FindBlockByID(function_die.GetID(&cu)); } uint32_t SymbolFileDWARF::ResolveSymbolContext(const Address &so_addr, @@ -2042,7 +2107,7 @@ context, basename)) basename = name.GetStringRef(); - DIEArray die_offsets; + std::vector die_offsets; m_index->GetGlobalVariables(ConstString(basename), die_offsets); const size_t num_die_matches = die_offsets.size(); if (num_die_matches) { @@ -2056,8 +2121,9 @@ bool done = false; for (size_t i = 0; i < num_die_matches && !done; ++i) { - const DIERef &die_ref = die_offsets[i]; - DWARFDIE die = GetDIE(die_ref); + user_id_t uid = die_offsets[i]; + DWARFCompileUnit *main_unit; + DWARFDIE die = GetDIEUnlocked(uid, &main_unit); if (die) { switch (die.Tag()) { @@ -2077,7 +2143,7 @@ if (parent_decl_ctx) { if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) { CompilerDeclContext actual_parent_decl_ctx = - dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); + dwarf_ast->GetDeclContextContainingUIDFromDWARF(main_unit, die); if (!actual_parent_decl_ctx || actual_parent_decl_ctx != parent_decl_ctx) continue; @@ -2100,7 +2166,7 @@ } break; } } else { - m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); + m_index->ReportInvalidDIEID(uid, name.GetStringRef()); } } } @@ -2134,7 +2200,7 @@ // Remember how many variables are in the list before we search. const uint32_t original_size = variables.GetSize(); - DIEArray die_offsets; + std::vector die_offsets; m_index->GetGlobalVariables(regex, die_offsets); SymbolContext sc; @@ -2144,8 +2210,8 @@ const size_t num_matches = die_offsets.size(); if (num_matches) { for (size_t i = 0; i < num_matches; ++i) { - const DIERef &die_ref = die_offsets[i]; - DWARFDIE die = GetDIE(die_ref); + user_id_t uid = die_offsets[i]; + DWARFDIE die = GetDIE(uid); if (die) { DWARFCompileUnit *dwarf_cu = @@ -2159,12 +2225,12 @@ if (variables.GetSize() - original_size >= max_matches) break; } else - m_index->ReportInvalidDIERef(die_ref, regex.GetText()); + m_index->ReportInvalidDIEID(uid, regex.GetText()); } } } -bool SymbolFileDWARF::ResolveFunction(const DWARFDIE &orig_die, +bool SymbolFileDWARF::ResolveFunction(DWARFCompileUnit *main_unit, const DWARFDIE &orig_die, bool include_inlines, SymbolContextList &sc_list) { SymbolContext sc; @@ -2193,12 +2259,12 @@ } } assert(die && die.Tag() == DW_TAG_subprogram); - if (GetFunction(die, sc)) { + if (GetFunction(main_unit, die, sc)) { Address addr; // Parse all blocks if needed if (inlined_die) { Block &function_block = sc.function->GetBlock(true); - sc.block = function_block.FindBlockByID(inlined_die.GetID()); + sc.block = function_block.FindBlockByID(inlined_die.GetID(main_unit)); if (sc.block == nullptr) sc.block = function_block.FindBlockByID(inlined_die.GetOffset()); if (sc.block == nullptr || !sc.block->GetStartAddress(addr)) @@ -2220,7 +2286,7 @@ return false; } -bool SymbolFileDWARF::DIEInDeclContext(const CompilerDeclContext &decl_ctx, +bool SymbolFileDWARF::DIEInDeclContext(const CompilerDeclContext &decl_ctx, DWARFCompileUnit *main_unit, const DWARFDIE &die) { // If we have no parent decl context to match this DIE matches, and if the // parent decl context isn't valid, we aren't trying to look for any @@ -2229,9 +2295,9 @@ return true; if (die) { - if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) { + if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.MainDWARFUnit(main_unit))) { if (CompilerDeclContext actual_decl_ctx = - dwarf_ast->GetDeclContextContainingUIDFromDWARF(die)) + dwarf_ast->GetDeclContextContainingUIDFromDWARF(main_unit, die)) return decl_ctx.IsContainedInLookup(actual_decl_ctx); } } @@ -2273,14 +2339,14 @@ const uint32_t original_size = sc_list.GetSize(); - llvm::DenseSet resolved_dies; + llvm::DenseSet> resolved_dies; DIEArray offsets; - std::vector dies; + std::vector> dies; m_index->GetFunctions(name, *this, parent_decl_ctx, name_type_mask, dies); - for (const DWARFDIE &die : dies) { - if (resolved_dies.insert(die.GetDIE()).second) - ResolveFunction(die, include_inlines, sc_list); + for (const auto &diepair : dies) { + if (resolved_dies.insert(std::make_pair(diepair.first,diepair.second.GetDIE())).second) + ResolveFunction(diepair.first, diepair.second, include_inlines, sc_list); } // Return the number of variable that were appended to the list @@ -2312,19 +2378,19 @@ regex.GetText().str().c_str()); } - DWARFDebugInfo &info = DebugInfo(); - DIEArray offsets; + std::vector offsets; m_index->GetFunctions(regex, offsets); - llvm::DenseSet resolved_dies; - for (DIERef ref : offsets) { - DWARFDIE die = info.GetDIE(ref); + llvm::DenseSet> resolved_dies; + for (user_id_t uid : offsets) { + DWARFCompileUnit *main_unit; + DWARFDIE die = GetDIEUnlocked(uid, &main_unit); if (!die) { - m_index->ReportInvalidDIERef(ref, regex.GetText()); + m_index->ReportInvalidDIEID(uid, regex.GetText()); continue; } - if (resolved_dies.insert(die.GetDIE()).second) - ResolveFunction(die, include_inlines, sc_list); + if (resolved_dies.insert(die.MainCUtoDIEPair(main_unit)).second) + ResolveFunction(main_unit, die, include_inlines, sc_list); } } @@ -2381,18 +2447,19 @@ if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) return; - DIEArray die_offsets; + std::vector die_offsets; m_index->GetTypes(name, die_offsets); const size_t num_die_matches = die_offsets.size(); for (size_t i = 0; i < num_die_matches; ++i) { - const DIERef &die_ref = die_offsets[i]; - DWARFDIE die = GetDIE(die_ref); + user_id_t uid = die_offsets[i]; + DWARFCompileUnit *main_unit; + DWARFDIE die = GetDIEUnlocked(uid, &main_unit); if (die) { - if (!DIEInDeclContext(parent_decl_ctx, die)) + if (!DIEInDeclContext(parent_decl_ctx, main_unit, die)) continue; // The containing decl contexts don't match - Type *matching_type = ResolveType(die, true, true); + Type *matching_type = ResolveType(main_unit, die, true, true); if (matching_type) { // We found a type pointer, now find the shared pointer form our type // list @@ -2401,7 +2468,7 @@ break; } } else { - m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); + m_index->ReportInvalidDIEID(uid, name.GetStringRef()); } } @@ -2453,16 +2520,17 @@ if (!name) return; - DIEArray die_offsets; + std::vector die_offsets; m_index->GetTypes(name, die_offsets); const size_t num_die_matches = die_offsets.size(); for (size_t i = 0; i < num_die_matches; ++i) { - const DIERef &die_ref = die_offsets[i]; - DWARFDIE die = GetDIE(die_ref); + user_id_t uid = die_offsets[i]; + DWARFCompileUnit *main_unit; + DWARFDIE die = GetDIEUnlocked(uid, &main_unit); if (!die) { - m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); + m_index->ReportInvalidDIEID(uid, name.GetStringRef()); continue; } if (!languages[GetLanguage(*die.GetCU())]) @@ -2473,7 +2541,7 @@ if (!contextMatches(die_context, pattern)) continue; - if (Type *matching_type = ResolveType(die, true, true)) { + if (Type *matching_type = ResolveType(main_unit, die, true, true)) { // We found a type pointer, now find the shared pointer form our type // list. types.InsertUnique(matching_type->shared_from_this()); @@ -2508,25 +2576,26 @@ if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) return namespace_decl_ctx; - DIEArray die_offsets; + std::vector die_offsets; m_index->GetNamespaces(name, die_offsets); const size_t num_matches = die_offsets.size(); if (num_matches) { for (size_t i = 0; i < num_matches; ++i) { - const DIERef &die_ref = die_offsets[i]; - DWARFDIE die = GetDIE(die_ref); + user_id_t uid = die_offsets[i]; + DWARFCompileUnit *main_unit; + DWARFDIE die = GetDIEUnlocked(uid, &main_unit); if (die) { - if (!DIEInDeclContext(parent_decl_ctx, die)) + if (!DIEInDeclContext(parent_decl_ctx, main_unit, die)) continue; // The containing decl contexts don't match - if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) { - namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(die); + if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.MainDWARFUnit(main_unit))) { + namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(main_unit, die); if (namespace_decl_ctx) break; } } else { - m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); + m_index->ReportInvalidDIEID(uid, name.GetStringRef()); } } } @@ -2544,14 +2613,14 @@ return namespace_decl_ctx; } -TypeSP SymbolFileDWARF::GetTypeForDIE(const DWARFDIE &die, +TypeSP SymbolFileDWARF::GetTypeForDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die, bool resolve_function_context) { TypeSP type_sp; if (die) { - Type *type_ptr = GetDIEToType().lookup(die.GetDIE()); + Type *type_ptr = GetDIEToType().lookup(die.MainCUtoDIEPair(main_unit)); if (type_ptr == nullptr) { SymbolContextScope *scope; - if (auto *dwarf_cu = llvm::dyn_cast(die.GetCU())) + if (auto *dwarf_cu = die.MainDWARFCompileUnit(main_unit)) scope = GetCompUnitForDWARFCompUnit(*dwarf_cu); else scope = GetObjectFile()->GetModule().get(); @@ -2565,7 +2634,7 @@ } SymbolContext sc_backup = sc; if (resolve_function_context && parent_die != nullptr && - !GetFunction(DWARFDIE(die.GetCU(), parent_die), sc)) + !GetFunction(main_unit, DWARFDIE(die.GetCU(), parent_die), sc)) sc = sc_backup; type_sp = ParseType(sc, die, nullptr); @@ -2683,15 +2752,16 @@ if (!type_name || (must_be_implementation && !GetObjCClassSymbol(type_name))) return type_sp; - DIEArray die_offsets; + std::vector die_offsets; m_index->GetCompleteObjCClass(type_name, must_be_implementation, die_offsets); const size_t num_matches = die_offsets.size(); if (num_matches) { for (size_t i = 0; i < num_matches; ++i) { - const DIERef &die_ref = die_offsets[i]; - DWARFDIE type_die = GetDIE(die_ref); + DWARFCompileUnit *main_unit; + user_id_t uid = die_offsets[i]; + DWARFDIE type_die = GetDIEUnlocked(uid, &main_unit); if (type_die) { bool try_resolving_type = false; @@ -2716,7 +2786,7 @@ DW_AT_APPLE_objc_complete_type, 0); if (try_resolving_type) { - Type *resolved_type = ResolveType(type_die, false, true); + Type *resolved_type = ResolveType(main_unit, type_die, false, true); if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) { DEBUG_PRINTF("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n", @@ -2726,14 +2796,14 @@ type_die.GetID(), type_cu->GetID()); if (die) - GetDIEToType()[die.GetDIE()] = resolved_type; + GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = resolved_type; type_sp = resolved_type->shared_from_this(); break; } } } } else { - m_index->ReportInvalidDIERef(die_ref, type_name.GetStringRef()); + m_index->ReportInvalidDIEID(uid, type_name.GetStringRef()); } } } @@ -2850,7 +2920,7 @@ dwarf_decl_ctx.GetQualifiedName()); } - DIEArray die_offsets; + std::vector die_offsets; m_index->GetTypes(dwarf_decl_ctx, die_offsets); const size_t num_matches = die_offsets.size(); @@ -2872,8 +2942,9 @@ } if (num_matches) { for (size_t i = 0; i < num_matches; ++i) { - const DIERef &die_ref = die_offsets[i]; - DWARFDIE type_die = GetDIE(die_ref); + DWARFCompileUnit *main_unit; + user_id_t uid = die_offsets[i]; + DWARFDIE type_die = GetDIEUnlocked(uid, &main_unit); if (type_die) { // Make sure type_die's langauge matches the type system we are @@ -2930,7 +3001,7 @@ // Make sure the decl contexts match all the way up if (dwarf_decl_ctx == type_dwarf_decl_ctx) { - Type *resolved_type = ResolveType(type_die, false); + Type *resolved_type = ResolveType(main_unit, type_die, false); if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) { type_sp = resolved_type->shared_from_this(); break; @@ -2951,7 +3022,7 @@ } } } else { - m_index->ReportInvalidDIERef(die_ref, type_name.GetStringRef()); + m_index->ReportInvalidDIEID(uid, type_name.GetStringRef()); } } } @@ -2981,7 +3052,8 @@ GetTypeList().Insert(type_sp); if (die.Tag() == DW_TAG_subprogram) { - std::string scope_qualified_name(GetDeclContextForUID(die.GetID()) + DWARFCompileUnit *main_unit = GetDWARFCompileUnit(sc.comp_unit); + std::string scope_qualified_name(GetDeclContextForUID(die.GetID(main_unit)) .GetScopeQualifiedName() .AsCString("")); if (scope_qualified_name.size()) { @@ -3017,8 +3089,9 @@ if (parse_children && die.HasChildren()) { if (die.Tag() == DW_TAG_subprogram) { + DWARFCompileUnit *main_unit = GetDWARFCompileUnit(sc.comp_unit); SymbolContext child_sc(sc); - child_sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get(); + child_sc.function = sc.comp_unit->FindFunctionByUID(die.GetID(main_unit)).get(); types_added += ParseTypes(child_sc, die.GetFirstChild(), true, true); } else types_added += ParseTypes(sc, die.GetFirstChild(), true, true); @@ -3037,7 +3110,7 @@ CompileUnit *comp_unit = func.GetCompileUnit(); lldbassert(comp_unit); - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit); if (!dwarf_cu) return 0; @@ -3056,12 +3129,13 @@ size_t SymbolFileDWARF::ParseTypes(CompileUnit &comp_unit) { std::lock_guard guard(GetModuleMutex()); size_t types_added = 0; - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); if (dwarf_cu) { DWARFDIE dwarf_cu_die = dwarf_cu->DIE(); if (dwarf_cu_die && dwarf_cu_die.HasChildren()) { SymbolContext sc; sc.comp_unit = &comp_unit; + sc.module_sp = sc.comp_unit->GetModule(); types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true); } } @@ -3098,14 +3172,14 @@ variables = std::make_shared(); sc.comp_unit->SetVariableList(variables); - DIEArray die_offsets; + std::vector die_offsets; m_index->GetGlobalVariables(dwarf_cu->GetNonSkeletonUnit(), die_offsets); const size_t num_matches = die_offsets.size(); if (num_matches) { for (size_t i = 0; i < num_matches; ++i) { - const DIERef &die_ref = die_offsets[i]; - DWARFDIE die = GetDIE(die_ref); + user_id_t uid = die_offsets[i]; + DWARFDIE die = GetDIE(uid); if (die) { VariableSP var_sp( ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS)); @@ -3114,7 +3188,7 @@ ++vars_added; } } else - m_index->ReportInvalidDIERef(die_ref, ""); + m_index->ReportInvalidDIEID(uid, ""); } } } @@ -3127,14 +3201,16 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc, const DWARFDIE &die, const lldb::addr_t func_low_pc) { - if (die.GetDWARF() != this) - return die.GetDWARF()->ParseVariableDIE(sc, die, func_low_pc); +// if (die.GetDWARF() != this) +// return die.GetDWARF()->ParseVariableDIE(sc, die, func_low_pc); VariableSP var_sp; if (!die) return var_sp; - var_sp = GetDIEToVariable()[die.GetDIE()]; + DWARFCompileUnit *main_unit = GetDWARFCompileUnit(sc.comp_unit); + + var_sp = GetDIEToVariable()[die.MainCUtoDIEPair(main_unit)]; if (var_sp) return var_sp; // Already been parsed! @@ -3466,7 +3542,7 @@ case DW_TAG_lexical_block: if (sc.function) { symbol_context_scope = sc.function->GetBlock(true).FindBlockByID( - sc_parent_die.GetID()); + sc_parent_die.GetID(main_unit)); if (symbol_context_scope == nullptr) symbol_context_scope = sc.function; } @@ -3480,7 +3556,7 @@ if (symbol_context_scope) { SymbolFileTypeSP type_sp( - new SymbolFileType(*this, GetUID(type_die_form.Reference()))); + new SymbolFileType(*this, GetUID(main_unit, type_die_form.Reference()))); if (const_value.Form() && type_sp && type_sp->GetType()) location.UpdateValue(const_value.Unsigned(), @@ -3488,7 +3564,7 @@ die.GetCU()->GetAddressByteSize()); var_sp = std::make_shared( - die.GetID(), name, mangled, type_sp, scope, symbol_context_scope, + die.GetID(main_unit), name, mangled, type_sp, scope, symbol_context_scope, scope_ranges, &decl, location, is_external, is_artificial, is_static_member); @@ -3504,9 +3580,9 @@ // missing vital information to be able to be displayed in the debugger // (missing location due to optimization, etc)) so we don't re-parse this // DIE over and over later... - GetDIEToVariable()[die.GetDIE()] = var_sp; + GetDIEToVariable()[die.MainCUtoDIEPair(main_unit)] = var_sp; if (spec_die) - GetDIEToVariable()[spec_die.GetDIE()] = var_sp; + GetDIEToVariable()[spec_die.MainCUtoDIEPair(main_unit)] = var_sp; } return var_sp; } @@ -3565,6 +3641,7 @@ return 0; VariableListSP variable_list_sp; + DWARFCompileUnit *main_unit = GetDWARFCompileUnit(sc.comp_unit); size_t vars_added = 0; DWARFDIE die = orig_die; @@ -3572,7 +3649,7 @@ dw_tag_t tag = die.Tag(); // Check to see if we have already parsed this variable or constant? - VariableSP var_sp = GetDIEToVariable()[die.GetDIE()]; + VariableSP var_sp = GetDIEToVariable()[die.MainCUtoDIEPair(main_unit)]; if (var_sp) { if (cc_variable_list) cc_variable_list->AddVariableIfUnique(var_sp); @@ -3595,8 +3672,8 @@ GetObjectFile()->GetModule()->ReportError( "parent 0x%8.8" PRIx64 " %s with no valid compile unit in " "symbol context for 0x%8.8" PRIx64 " %s.\n", - sc_parent_die.GetID(), sc_parent_die.GetTagAsCString(), - orig_die.GetID(), orig_die.GetTagAsCString()); + sc_parent_die.GetID(nullptr), sc_parent_die.GetTagAsCString(), + orig_die.GetID(nullptr), orig_die.GetTagAsCString()); } break; @@ -3608,7 +3685,7 @@ // given scope Block *block = sc.function->GetBlock(true).FindBlockByID( - sc_parent_die.GetID()); + sc_parent_die.GetID(main_unit)); if (block == nullptr) { // This must be a specification or abstract origin with a // concrete block counterpart in the current function. We need @@ -3620,7 +3697,7 @@ sc_parent_die.GetOffset()); if (concrete_block_die) block = sc.function->GetBlock(true).FindBlockByID( - concrete_block_die.GetID()); + concrete_block_die.GetID(main_unit)); } if (block != nullptr) { @@ -3638,7 +3715,7 @@ GetObjectFile()->GetModule()->ReportError( "didn't find appropriate parent DIE for variable list for " "0x%8.8" PRIx64 " %s.\n", - orig_die.GetID(), orig_die.GetTagAsCString()); + orig_die.GetID(nullptr), orig_die.GetTagAsCString()); break; } } @@ -3913,7 +3990,7 @@ if (!dwp_obj_file) return; m_dwp_symfile = - std::make_shared(*this, dwp_obj_file, 0x3fffffff); + std::make_shared(*this, dwp_obj_file, 0x1ffffffe); } }); return m_dwp_symfile; @@ -3933,22 +4010,22 @@ return type_system_or_err->GetDWARFParser(); } -CompilerDecl SymbolFileDWARF::GetDecl(const DWARFDIE &die) { - if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) - return dwarf_ast->GetDeclForUIDFromDWARF(die); +CompilerDecl SymbolFileDWARF::GetDecl(DWARFCompileUnit *main_unit, const DWARFDIE &die) { + if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.MainDWARFUnit(main_unit))) + return dwarf_ast->GetDeclForUIDFromDWARF(main_unit, die); return CompilerDecl(); } -CompilerDeclContext SymbolFileDWARF::GetDeclContext(const DWARFDIE &die) { - if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) - return dwarf_ast->GetDeclContextForUIDFromDWARF(die); +CompilerDeclContext SymbolFileDWARF::GetDeclContext(DWARFCompileUnit *main_unit, const DWARFDIE &die) { + if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.MainDWARFUnit(main_unit))) + return dwarf_ast->GetDeclContextForUIDFromDWARF(main_unit, die); return CompilerDeclContext(); } CompilerDeclContext -SymbolFileDWARF::GetContainingDeclContext(const DWARFDIE &die) { - if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) - return dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); +SymbolFileDWARF::GetContainingDeclContext(DWARFCompileUnit *main_unit, const DWARFDIE &die) { + if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.MainDWARFUnit(main_unit))) + return dwarf_ast->GetDeclContextContainingUIDFromDWARF(main_unit, die); return CompilerDeclContext(); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h @@ -32,7 +32,7 @@ DWARFCompileUnit *GetDWOCompileUnitForHash(uint64_t hash); size_t GetObjCMethodDIEOffsets(lldb_private::ConstString class_name, - DIEArray &method_die_offsets) override; + std::vector &method_die_offsets) override; llvm::Expected GetTypeSystemForLanguage(lldb::LanguageType language) override; @@ -42,6 +42,8 @@ llvm::Optional GetDwoNum() override { return GetID() >> 32; } + SymbolFileDWARF &GetBaseSymbolFile() { return m_base_symbol_file; } + protected: DIEToTypePtr &GetDIEToType() override; @@ -60,8 +62,6 @@ const DWARFDIE &die, lldb_private::ConstString type_name, bool must_be_implementation) override; - SymbolFileDWARF &GetBaseSymbolFile() { return m_base_symbol_file; } - /// If this file contains exactly one compile unit, this function will return /// it. Otherwise it returns nullptr. DWARFCompileUnit *FindSingleCompileUnit(); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp @@ -96,7 +96,7 @@ } size_t SymbolFileDWARFDwo::GetObjCMethodDIEOffsets( - lldb_private::ConstString class_name, DIEArray &method_die_offsets) { + lldb_private::ConstString class_name, std::vector &method_die_offsets) { return GetBaseSymbolFile().GetObjCMethodDIEOffsets(class_name, method_die_offsets); } diff --git a/lldb/test/Shell/SymbolFile/DWARF/DW_AT_low_pc-addrx.s b/lldb/test/Shell/SymbolFile/DWARF/DW_AT_low_pc-addrx.s --- a/lldb/test/Shell/SymbolFile/DWARF/DW_AT_low_pc-addrx.s +++ b/lldb/test/Shell/SymbolFile/DWARF/DW_AT_low_pc-addrx.s @@ -5,9 +5,9 @@ # RUN: -o exit | FileCheck %s # CHECK-LABEL: image lookup -v -s lookup_rnglists -# CHECK: Function: id = {0x7fffffff0000002d}, name = "rnglists", range = [0x0000000000000000-0x0000000000000003) -# CHECK: Blocks: id = {0x7fffffff0000002d}, range = [0x00000000-0x00000003) -# CHECK-NEXT: id = {0x7fffffff00000043}, range = [0x00000001-0x00000002) +# CHECK: Function: id = {0x1fffffff0000002d}, name = "rnglists", range = [0x0000000000000000-0x0000000000000003) +# CHECK: Blocks: id = {0x1fffffff0000002d}, range = [0x00000000-0x00000003) +# CHECK-NEXT: id = {0x1fffffff00000043}, range = [0x00000001-0x00000002) .text rnglists: diff --git a/lldb/test/Shell/SymbolFile/DWARF/array-sizes.s b/lldb/test/Shell/SymbolFile/DWARF/array-sizes.s --- a/lldb/test/Shell/SymbolFile/DWARF/array-sizes.s +++ b/lldb/test/Shell/SymbolFile/DWARF/array-sizes.s @@ -9,8 +9,8 @@ # RUN: ld.lld %t.o -o %t # RUN: lldb-test symbols %t | FileCheck %s -# CHECK: Variable{0x7fffffff0000001e}, name = "X" -# CHECK-SAME: type = {7fffffff00000033} 0x{{[0-9A-F]*}} (char [56]) +# CHECK: Variable{0x1fffffff0000001e}, name = "X" +# CHECK-SAME: type = {1fffffff00000033} 0x{{[0-9A-F]*}} (char [56]) # Generated from "char X[47];" diff --git a/lldb/test/Shell/SymbolFile/DWARF/debug-types-address-ranges.s b/lldb/test/Shell/SymbolFile/DWARF/debug-types-address-ranges.s --- a/lldb/test/Shell/SymbolFile/DWARF/debug-types-address-ranges.s +++ b/lldb/test/Shell/SymbolFile/DWARF/debug-types-address-ranges.s @@ -11,11 +11,11 @@ # RUN: %lldb %t -o "image lookup -a 0x48000 -v" -o exit | FileCheck %s # CHECK: CompileUnit: id = {0x00000001}, file = "/tmp/a.cc", language = "c++" -# CHECK: Function: id = {0x7fffffff0000006a}, name = "::_start({{.*}})", range = [0x0000000000048000-0x000000000004800c) +# CHECK: Function: id = {0x1fffffff0000006a}, name = "::_start({{.*}})", range = [0x0000000000048000-0x000000000004800c) # CHECK: LineEntry: [0x0000000000048000-0x000000000004800a): /tmp/a.cc:4 # CHECK: Symbol: id = {0x00000002}, range = [0x0000000000048000-0x000000000004800c), name="_start" -# CHECK: Variable: id = {0x7fffffff00000075}, name = "v1", {{.*}} decl = a.cc:4 -# CHECK: Variable: id = {0x7fffffff00000080}, name = "v2", {{.*}} decl = a.cc:4 +# CHECK: Variable: id = {0x1fffffff00000075}, name = "v1", {{.*}} decl = a.cc:4 +# CHECK: Variable: id = {0x1fffffff00000080}, name = "v2", {{.*}} decl = a.cc:4 # Output generated via diff --git a/lldb/test/Shell/SymbolFile/DWARF/debug-types-dwarf5.s b/lldb/test/Shell/SymbolFile/DWARF/debug-types-dwarf5.s --- a/lldb/test/Shell/SymbolFile/DWARF/debug-types-dwarf5.s +++ b/lldb/test/Shell/SymbolFile/DWARF/debug-types-dwarf5.s @@ -1,8 +1,8 @@ # RUN: llvm-mc -triple=x86_64-pc-linux -filetype=obj %s > %t # RUN: %lldb %t -o "image lookup -v -s f1" -o exit | FileCheck %s -# CHECK: Function: id = {0x7fffffff0000003c}, name = "f1", range = [0x0000000000000000-0x0000000000000001) -# CHECK: Blocks: id = {0x7fffffff0000003c}, range = [0x00000000-0x00000001) +# CHECK: Function: id = {0x1fffffff0000003c}, name = "f1", range = [0x0000000000000000-0x0000000000000001) +# CHECK: Blocks: id = {0x1fffffff0000003c}, range = [0x00000000-0x00000001) .text diff --git a/lldb/test/Shell/SymbolFile/DWARF/debug_ranges-missing-section.s b/lldb/test/Shell/SymbolFile/DWARF/debug_ranges-missing-section.s --- a/lldb/test/Shell/SymbolFile/DWARF/debug_ranges-missing-section.s +++ b/lldb/test/Shell/SymbolFile/DWARF/debug_ranges-missing-section.s @@ -4,8 +4,8 @@ # RUN: %lldb %t -o "image lookup -v -s lookup_ranges" -o exit 2>&1 | FileCheck %s # CHECK: DIE has DW_AT_ranges(0x47) attribute, but range extraction failed (No debug_ranges section), -# CHECK: Function: id = {0x7fffffff0000001c}, name = "ranges", range = [0x0000000000000000-0x0000000000000004) -# CHECK: Blocks: id = {0x7fffffff0000001c}, range = [0x00000000-0x00000004) +# CHECK: Function: id = {0x1fffffff0000001c}, name = "ranges", range = [0x0000000000000000-0x0000000000000004) +# CHECK: Blocks: id = {0x1fffffff0000001c}, range = [0x00000000-0x00000004) .text .p2align 12 diff --git a/lldb/test/Shell/SymbolFile/DWARF/debug_ranges.s b/lldb/test/Shell/SymbolFile/DWARF/debug_ranges.s --- a/lldb/test/Shell/SymbolFile/DWARF/debug_ranges.s +++ b/lldb/test/Shell/SymbolFile/DWARF/debug_ranges.s @@ -3,9 +3,9 @@ # RUN: llvm-mc -triple=x86_64-pc-linux -filetype=obj %s > %t # RUN: %lldb %t -o "image lookup -v -s lookup_ranges" -o exit | FileCheck %s -# CHECK: Function: id = {0x7fffffff0000002b}, name = "ranges", range = [0x0000000000000000-0x0000000000000004) -# CHECK: Blocks: id = {0x7fffffff0000002b}, range = [0x00000000-0x00000004) -# CHECK-NEXT: id = {0x7fffffff0000003f}, ranges = [0x00000001-0x00000002)[0x00000003-0x00000004) +# CHECK: Function: id = {0x1fffffff0000002b}, name = "ranges", range = [0x0000000000000000-0x0000000000000004) +# CHECK: Blocks: id = {0x1fffffff0000002b}, range = [0x00000000-0x00000004) +# CHECK-NEXT: id = {0x1fffffff0000003f}, ranges = [0x00000001-0x00000002)[0x00000003-0x00000004) .text .p2align 12 diff --git a/lldb/test/Shell/SymbolFile/DWARF/debug_rnglists.s b/lldb/test/Shell/SymbolFile/DWARF/debug_rnglists.s --- a/lldb/test/Shell/SymbolFile/DWARF/debug_rnglists.s +++ b/lldb/test/Shell/SymbolFile/DWARF/debug_rnglists.s @@ -5,14 +5,14 @@ # RUN: -o "image lookup -v -s lookup_rnglists2" -o exit | FileCheck %s # CHECK-LABEL: image lookup -v -s lookup_rnglists -# CHECK: Function: id = {0x7fffffff00000030}, name = "rnglists", range = [0x0000000000000000-0x0000000000000004) -# CHECK: Blocks: id = {0x7fffffff00000030}, range = [0x00000000-0x00000004) -# CHECK-NEXT: id = {0x7fffffff00000046}, ranges = [0x00000001-0x00000002)[0x00000003-0x00000004) +# CHECK: Function: id = {0x1fffffff00000030}, name = "rnglists", range = [0x0000000000000000-0x0000000000000004) +# CHECK: Blocks: id = {0x1fffffff00000030}, range = [0x00000000-0x00000004) +# CHECK-NEXT: id = {0x1fffffff00000046}, ranges = [0x00000001-0x00000002)[0x00000003-0x00000004) # CHECK-LABEL: image lookup -v -s lookup_rnglists2 -# CHECK: Function: id = {0x7fffffff0000007a}, name = "rnglists2", range = [0x0000000000000004-0x0000000000000007) -# CHECK: Blocks: id = {0x7fffffff0000007a}, range = [0x00000004-0x00000007) -# CHECK-NEXT: id = {0x7fffffff00000091}, range = [0x00000005-0x00000007) +# CHECK: Function: id = {0x1fffffff0000007a}, name = "rnglists2", range = [0x0000000000000004-0x0000000000000007) +# CHECK: Blocks: id = {0x1fffffff0000007a}, range = [0x00000004-0x00000007) +# CHECK-NEXT: id = {0x1fffffff00000091}, range = [0x00000005-0x00000007) .text .p2align 12 diff --git a/lldb/test/Shell/SymbolFile/DWARF/dwarf5_locations.s b/lldb/test/Shell/SymbolFile/DWARF/dwarf5_locations.s --- a/lldb/test/Shell/SymbolFile/DWARF/dwarf5_locations.s +++ b/lldb/test/Shell/SymbolFile/DWARF/dwarf5_locations.s @@ -6,7 +6,7 @@ # RUN: ld.lld -m elf_x86_64 %t.o -o %t # RUN: lldb-test symbols %t | FileCheck %s -# CHECK: Variable{0x7fffffff00000011}, name = "color" +# CHECK: Variable{0x1fffffff00000011}, name = "color" # CHECK-SAME: location = DW_OP_addrx 0x0 .text diff --git a/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s b/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s --- a/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s +++ b/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s @@ -16,15 +16,15 @@ # Make sure each entity is present in the index only once. # SYMBOLS: Globals and statics: -# SYMBOLS-DAG: 3fffffff/INFO/00000023 "A" -# SYMBOLS-DAG: 3fffffff/INFO/0000005a "A" +# SYMBOLS-DAG: 1ffffffe/INFO/00000023 "A" +# SYMBOLS-DAG: 1ffffffe/INFO/0000005a "A" # SYMBOLS-EMPTY: # SYMBOLS: Types: -# SYMBOLS-DAG: 3fffffff/TYPE/00000018 "ENUM0" -# SYMBOLS-DAG: 3fffffff/TYPE/0000004d "ENUM1" -# SYMBOLS-DAG: 3fffffff/TYPE/0000002d "int" -# SYMBOLS-DAG: 3fffffff/TYPE/00000062 "int" +# SYMBOLS-DAG: 1ffffffe/TYPE/00000018 "ENUM0" +# SYMBOLS-DAG: 1ffffffe/TYPE/0000004d "ENUM1" +# SYMBOLS-DAG: 1ffffffe/TYPE/0000002d "int" +# SYMBOLS-DAG: 1ffffffe/TYPE/00000062 "int" # SYMBOLS-EMPTY: .ifdef MAIN diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp --- a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp +++ b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp @@ -8,6 +8,7 @@ #include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h" #include "Plugins/SymbolFile/DWARF/DWARFDIE.h" +#include "Plugins/SymbolFile/DWARF/DWARFCompileUnit.h" #include "TestingSupport/Symbol/YAMLModuleTester.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -94,7 +95,7 @@ TypeSystemClang ast_ctx("dummy ASTContext", HostInfoBase::GetTargetTriple()); DWARFASTParserClangStub ast_parser(ast_ctx); - DWARFUnit *unit = t.GetDwarfUnit().get(); + DWARFCompileUnit *unit = llvm::cast(t.GetDwarfUnit().get()); const DWARFDebugInfoEntry *die_first = unit->DIE().GetDIE(); const DWARFDebugInfoEntry *die_child0 = die_first->GetFirstChild(); const DWARFDebugInfoEntry *die_child1 = die_child0->GetSibling(); @@ -107,7 +108,7 @@ (clang::DeclContext *)1LL, (clang::DeclContext *)2LL, (clang::DeclContext *)2LL, (clang::DeclContext *)3LL}; for (int i = 0; i < 4; ++i) - ast_parser.LinkDeclContextToDIE(decl_ctxs[i], dies[i]); + ast_parser.LinkDeclContextToDIE(decl_ctxs[i], unit, dies[i]); ast_parser.EnsureAllDIEsInDeclContextHaveBeenParsed( CompilerDeclContext(nullptr, decl_ctxs[1]));