diff --git a/lldb/include/lldb/Symbol/SymbolFile.h b/lldb/include/lldb/Symbol/SymbolFile.h --- a/lldb/include/lldb/Symbol/SymbolFile.h +++ b/lldb/include/lldb/Symbol/SymbolFile.h @@ -170,7 +170,7 @@ std::vector &imported_modules) = 0; virtual size_t ParseBlocksRecursive(Function &func) = 0; virtual size_t ParseVariablesForContext(const SymbolContext &sc) = 0; - virtual Type *ResolveTypeUID(lldb::user_id_t type_uid) = 0; + virtual Type *ResolveTypeUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t type_uid) = 0; /// The characteristics of an array type. @@ -189,14 +189,14 @@ const lldb_private::ExecutionContext *exe_ctx) = 0; virtual bool CompleteType(CompilerType &compiler_type) = 0; - virtual void ParseDeclsForContext(CompilerDeclContext decl_ctx) {} - virtual CompilerDecl GetDeclForUID(lldb::user_id_t uid) { + virtual void ParseDeclsForContext(lldb_private::CompileUnit *comp_unit, CompilerDeclContext decl_ctx) {} + virtual CompilerDecl GetDeclForUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) { return CompilerDecl(); } - virtual CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) { + virtual CompilerDeclContext GetDeclContextForUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) { return CompilerDeclContext(); } - virtual CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) { + virtual CompilerDeclContext GetDeclContextContainingUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) { return CompilerDeclContext(); } virtual uint32_t ResolveSymbolContext(const Address &so_addr, diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp --- a/lldb/source/API/SBModule.cpp +++ b/lldb/source/API/SBModule.cpp @@ -530,7 +530,7 @@ ModuleSP module_sp(GetSP()); if (module_sp) { if (SymbolFile *symfile = module_sp->GetSymbolFile()) { - Type *type_ptr = symfile->ResolveTypeUID(uid); + Type *type_ptr = symfile->ResolveTypeUID(nullptr/*FIXMETypeuser_id_t*/,uid); if (type_ptr) return LLDB_RECORD_RESULT(SBType(type_ptr->shared_from_this())); } diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -2356,7 +2356,7 @@ type = Scalar::GetBestTypeForBitSize(bit_size, false); } else { // Retrieve the type DIE that the value is being converted to. - DWARFDIE die = dwarf_cu.GetCU()->GetDIE(dwarf_cu.GetMainCU(), die_offset); + DWARFDIE die = dwarf_cu.GetCU()->GetDIE(nullptr, die_offset); if (!die) { if (error_ptr) error_ptr->SetErrorString("Cannot resolve DW_OP_convert type DIE"); diff --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h --- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h +++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h @@ -89,7 +89,7 @@ size_t ParseVariablesForContext(const SymbolContext &sc) override { return 0; } - Type *ResolveTypeUID(lldb::user_id_t type_uid) override { return nullptr; } + Type *ResolveTypeUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t type_uid) override { return nullptr; } llvm::Optional GetDynamicArrayInfoForUID( lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) override { 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 @@ -159,8 +159,10 @@ 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, + for (const auto &item : offsets) { + CompileUnit *comp_unit = item.first; + const DIERef &die_ref = item.second; + ProcessFunctionDIE(comp_unit, name.GetStringRef(), die_ref, dwarf, parent_decl_ctx, name_type_mask, dies); } } 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 @@ -67,7 +67,7 @@ }; static_assert(sizeof(DIERef) == 8, ""); -typedef std::vector DIEArray; +typedef std::vector> DIEArray; namespace llvm { template<> struct format_provider { 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 @@ -35,19 +35,19 @@ const DWARFDIE &die) = 0; virtual bool - CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type, + CompleteTypeFromDWARF(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, lldb_private::Type *type, lldb_private::CompilerType &compiler_type) = 0; virtual lldb_private::CompilerDecl - GetDeclForUIDFromDWARF(const DWARFDIE &die) = 0; + GetDeclForUIDFromDWARF(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die) = 0; virtual lldb_private::CompilerDeclContext - GetDeclContextForUIDFromDWARF(const DWARFDIE &die) = 0; + GetDeclContextForUIDFromDWARF(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die) = 0; virtual lldb_private::CompilerDeclContext - GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) = 0; + GetDeclContextContainingUIDFromDWARF(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die) = 0; - virtual void EnsureAllDIEsInDeclContextHaveBeenParsed( + virtual void EnsureAllDIEsInDeclContextHaveBeenParsed(lldb_private::CompileUnit *comp_unit, lldb_private::CompilerDeclContext decl_context) = 0; static llvm::Optional 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 @@ -51,20 +51,20 @@ const DWARFDIE &die) override; bool - CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type, + CompleteTypeFromDWARF(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, lldb_private::Type *type, lldb_private::CompilerType &compiler_type) override; lldb_private::CompilerDecl - GetDeclForUIDFromDWARF(const DWARFDIE &die) override; + GetDeclForUIDFromDWARF(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die) override; - void EnsureAllDIEsInDeclContextHaveBeenParsed( + void EnsureAllDIEsInDeclContextHaveBeenParsed(lldb_private::CompileUnit *comp_unit, lldb_private::CompilerDeclContext decl_context) override; lldb_private::CompilerDeclContext - GetDeclContextForUIDFromDWARF(const DWARFDIE &die) override; + GetDeclContextForUIDFromDWARF(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die) override; lldb_private::CompilerDeclContext - GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) override; + GetDeclContextContainingUIDFromDWARF(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die) override; lldb_private::ClangASTImporter &GetClangASTImporter(); @@ -91,21 +91,21 @@ std::unique_ptr m_clang_ast_importer_up; /// @} - clang::DeclContext *GetDeclContextForBlock(const DWARFDIE &die); + clang::DeclContext *GetDeclContextForBlock(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die); - clang::BlockDecl *ResolveBlockDIE(const DWARFDIE &die); + clang::BlockDecl *ResolveBlockDIE(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die); - clang::NamespaceDecl *ResolveNamespaceDIE(const DWARFDIE &die); + clang::NamespaceDecl *ResolveNamespaceDIE(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die); - bool ParseTemplateDIE(const DWARFDIE &die, + bool ParseTemplateDIE(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, lldb_private::TypeSystemClang::TemplateParameterInfos &template_param_infos); - bool ParseTemplateParameterInfos( + bool ParseTemplateParameterInfos(lldb_private::CompileUnit *comp_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, @@ -116,7 +116,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, @@ -133,16 +133,16 @@ const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs); - lldb_private::Type *GetTypeForDIE(const DWARFDIE &die); + lldb_private::Type *GetTypeForDIE(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die); - clang::Decl *GetClangDeclForDIE(const DWARFDIE &die); + clang::Decl *GetClangDeclForDIE(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die); - clang::DeclContext *GetClangDeclContextForDIE(const DWARFDIE &die); + clang::DeclContext *GetClangDeclContextForDIE(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die); - clang::DeclContext *GetClangDeclContextContainingDIE(const DWARFDIE &die, + clang::DeclContext *GetClangDeclContextContainingDIE(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, DWARFDIE *decl_ctx_die); - bool CopyUniqueClassMethodTypes(const DWARFDIE &src_class_die, + bool CopyUniqueClassMethodTypes(lldb_private::CompileUnit *comp_unit, const DWARFDIE &src_class_die, const DWARFDIE &dst_class_die, lldb_private::Type *class_type, std::vector &failures); @@ -189,7 +189,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, @@ -198,7 +198,7 @@ lldb_private::ClangASTImporter::LayoutInfo &layout_info, FieldInfo &last_field_info); - bool CompleteRecordType(const DWARFDIE &die, lldb_private::Type *type, + bool CompleteRecordType(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, lldb_private::Type *type, lldb_private::CompilerType &clang_type); bool CompleteEnumType(const DWARFDIE &die, lldb_private::Type *type, lldb_private::CompilerType &clang_type); @@ -208,12 +208,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(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs); // FIXME: attrs should be passed as a const reference. - lldb::TypeSP ParseArrayType(const DWARFDIE &die, + lldb::TypeSP ParseArrayType(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs); - lldb::TypeSP ParsePointerToMemberType(const DWARFDIE &die, + lldb::TypeSP ParsePointerToMemberType(lldb_private::CompileUnit *comp_unit, 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 @@ -341,7 +341,7 @@ break; case DW_AT_object_pointer: - object_pointer = form_value.Reference(die.GetMainCU()); + object_pointer = form_value.Reference(nullptr); break; case DW_AT_signature: @@ -404,7 +404,7 @@ if (log) { DWARFDIE context_die; clang::DeclContext *context = - GetClangDeclContextContainingDIE(die, &context_die); + GetClangDeclContextContainingDIE(sc.comp_unit, die, &context_die); dwarf->GetObjectFile()->GetModule()->LogMessage( log, @@ -424,9 +424,9 @@ ParsedDWARFTypeAttributes attrs(die); - if (DWARFDIE signature_die = attrs.signature.Reference(die.GetMainCU())) { + if (DWARFDIE signature_die = attrs.signature.Reference(nullptr)) { if (TypeSP type_sp = - ParseTypeFromDWARF(sc, signature_die, type_is_new_ptr)) { + ParseTypeFromDWARF(sc, signature_die, type_is_new_ptr)) { // main_cu==cu as it is DW_AT_signature dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); if (clang::DeclContext *decl_ctx = GetCachedClangDeclContextForDIE(signature_die)) @@ -473,15 +473,15 @@ case DW_TAG_inlined_subroutine: case DW_TAG_subprogram: case DW_TAG_subroutine_type: { - type_sp = ParseSubroutine(die, attrs); + type_sp = ParseSubroutine(sc.comp_unit, die, attrs); break; } case DW_TAG_array_type: { - type_sp = ParseArrayType(die, attrs); + type_sp = ParseArrayType(sc.comp_unit, die, attrs); break; } case DW_TAG_ptr_to_member_type: { - type_sp = ParsePointerToMemberType(die, attrs); + type_sp = ParsePointerToMemberType(sc.comp_unit, die, attrs); break; } default: @@ -536,7 +536,7 @@ // unnammed structure type in the module debug info, so we make // sure we don't get into this situation by always resolving // typedefs from the module. - const DWARFDIE encoding_die = attrs.type.Reference(die.GetMainCU()); + const DWARFDIE encoding_die = attrs.type.Reference(nullptr); // First make sure that the die that this is typedef'ed to _is_ // just a declaration (DW_AT_declaration == 1), not a full @@ -683,7 +683,7 @@ // Clang sometimes erroneously emits id as objc_object*. In that // case we fix up the type to "id". - const DWARFDIE encoding_die = attrs.type.Reference(die.GetMainCU()); + const DWARFDIE encoding_die = attrs.type.Reference(nullptr); if (encoding_die && encoding_die.Tag() == DW_TAG_structure_type) { llvm::StringRef struct_name = encoding_die.GetName(); @@ -707,7 +707,7 @@ type_sp = std::make_shared( die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr, - dwarf->GetUID(attrs.type.Reference(die.GetMainCU())), encoding_data_type, &attrs.decl, + dwarf->GetUID(attrs.type.Reference(nullptr)), encoding_data_type, &attrs.decl, clang_type, resolve_state); dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); @@ -775,7 +775,7 @@ if (!clang_type) { if (attrs.type.IsValid()) { Type *enumerator_type = - dwarf->ResolveTypeUID(attrs.type.Reference(die.GetMainCU()), true); + dwarf->ResolveTypeUID(sc.comp_unit, attrs.type.Reference(nullptr), true); if (enumerator_type) enumerator_clang_type = enumerator_type->GetFullCompilerType(); } @@ -790,7 +790,7 @@ } clang_type = m_ast.CreateEnumerationType( - attrs.name.GetCString(), GetClangDeclContextContainingDIE(die, nullptr), + attrs.name.GetCString(), GetClangDeclContextContainingDIE(sc.comp_unit, die, nullptr), attrs.decl, enumerator_clang_type, attrs.is_scoped_enum); } else { enumerator_clang_type = @@ -801,7 +801,7 @@ type_sp = std::make_shared( die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr, - dwarf->GetUID(attrs.type.Reference(die.GetMainCU())), Type::eEncodingIsUID, &attrs.decl, + dwarf->GetUID(attrs.type.Reference(nullptr)), Type::eEncodingIsUID, &attrs.decl, clang_type, Type::ResolveState::Forward); if (TypeSystemClang::StartTagDeclarationDefinition(clang_type)) { @@ -822,7 +822,7 @@ return type_sp; } -TypeSP DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die, +TypeSP DWARFASTParserClang::ParseSubroutine(CompileUnit *comp_unit, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs) { Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION | DWARF_LOG_LOOKUPS)); @@ -850,7 +850,7 @@ Type *func_type = NULL; if (attrs.type.IsValid()) - func_type = dwarf->ResolveTypeUID(attrs.type.Reference(die.GetMainCU()), true); + func_type = dwarf->ResolveTypeUID(comp_unit, attrs.type.Reference(nullptr), true); if (func_type) return_clang_type = func_type->GetForwardCompilerType(); @@ -864,7 +864,7 @@ DWARFDIE decl_ctx_die; clang::DeclContext *containing_decl_ctx = - GetClangDeclContextContainingDIE(die, &decl_ctx_die); + GetClangDeclContextContainingDIE(comp_unit, die, &decl_ctx_die); const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); @@ -878,7 +878,7 @@ if (die.HasChildren()) { bool skip_artificial = true; - ParseChildParameters(containing_decl_ctx, die, skip_artificial, is_static, + ParseChildParameters(comp_unit, containing_decl_ctx, die, skip_artificial, is_static, is_variadic, has_template_params, function_param_types, function_param_decls, type_quals); @@ -953,7 +953,7 @@ } 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(comp_unit, decl_ctx_die); if (class_type) { bool alternate_defn = false; if (class_type->GetID() != decl_ctx_die.GetID() || @@ -968,7 +968,7 @@ if (class_type_die) { std::vector failures; - CopyUniqueClassMethodTypes(decl_ctx_die, class_type_die, + CopyUniqueClassMethodTypes(comp_unit, decl_ctx_die, class_type_die, class_type, failures); // FIXME do something with these failures that's @@ -992,9 +992,9 @@ // If we have a specification, then the function type should // have been made with the specification and not with this // die. - DWARFDIE spec_die = attrs.specification.Reference(die.GetMainCU()); + DWARFDIE spec_die = attrs.specification.Reference(nullptr); clang::DeclContext *spec_clang_decl_ctx = - GetClangDeclContextForDIE(spec_die); + GetClangDeclContextForDIE(comp_unit, spec_die); if (spec_clang_decl_ctx) { LinkDeclContextToDIE(spec_clang_decl_ctx, die); } else { @@ -1011,9 +1011,9 @@ // the abstract origin has a valid clang decl context. class_type->GetForwardCompilerType(); - DWARFDIE abs_die = attrs.abstract_origin.Reference(die.GetMainCU()); + DWARFDIE abs_die = attrs.abstract_origin.Reference(nullptr); clang::DeclContext *abs_clang_decl_ctx = - GetClangDeclContextForDIE(abs_die); + GetClangDeclContextForDIE(comp_unit, abs_die); if (abs_clang_decl_ctx) { LinkDeclContextToDIE(abs_clang_decl_ctx, die); } else { @@ -1158,9 +1158,9 @@ clang::FunctionDecl *template_function_decl = nullptr; if (attrs.abstract_origin.IsValid()) { - DWARFDIE abs_die = attrs.abstract_origin.Reference(die.GetMainCU()); + DWARFDIE abs_die = attrs.abstract_origin.Reference(nullptr); - if (dwarf->ResolveType(abs_die)) { + if (dwarf->ResolveType(comp_unit, abs_die)) { function_decl = llvm::dyn_cast_or_null( GetCachedClangDeclContextForDIE(abs_die)); @@ -1180,7 +1180,7 @@ if (has_template_params) { TypeSystemClang::TemplateParameterInfos template_param_infos; - ParseTemplateParameterInfos(die, template_param_infos); + ParseTemplateParameterInfos(comp_unit, die, template_param_infos); template_function_decl = m_ast.CreateFunctionDeclaration( ignore_containing_context ? m_ast.GetTranslationUnitDecl() : containing_decl_ctx, @@ -1230,15 +1230,15 @@ Type::eEncodingIsUID, &attrs.decl, clang_type, Type::ResolveState::Full); } -TypeSP DWARFASTParserClang::ParseArrayType(const DWARFDIE &die, +TypeSP DWARFASTParserClang::ParseArrayType(CompileUnit *comp_unit, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs) { SymbolFileDWARF *dwarf = die.GetMainDWARF(); DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr); - DWARFDIE type_die = attrs.type.Reference(die.GetMainCU()); - Type *element_type = dwarf->ResolveTypeUID(type_die, true); + DWARFDIE type_die = attrs.type.Reference(nullptr); + Type *element_type = dwarf->ResolveTypeUID(comp_unit, type_die, true); if (!element_type) return nullptr; @@ -1320,12 +1320,12 @@ return type_sp; } -TypeSP DWARFASTParserClang::ParsePointerToMemberType( +TypeSP DWARFASTParserClang::ParsePointerToMemberType(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, const ParsedDWARFTypeAttributes &attrs) { SymbolFileDWARF *dwarf = die.GetMainDWARF(); - Type *pointee_type = dwarf->ResolveTypeUID(attrs.type.Reference(die.GetMainCU()), true); + Type *pointee_type = dwarf->ResolveTypeUID(comp_unit, attrs.type.Reference(nullptr), true); Type *class_type = - dwarf->ResolveTypeUID(attrs.containing_type.Reference(die.GetMainCU()), true); + dwarf->ResolveTypeUID(comp_unit, attrs.containing_type.Reference(nullptr), true); CompilerType pointee_clang_type = pointee_type->GetForwardCompilerType(); CompilerType class_clang_type = class_type->GetLayoutCompilerType(); @@ -1520,7 +1520,7 @@ DWARFDeclContext die_decl_ctx; SymbolFileDWARF::GetDWARFDeclContext(die, die_decl_ctx); - // type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, + // type_sp = FindDefinitionTypeForDIE (comp_unit, die, // type_name_const_str); type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx); @@ -1561,7 +1561,7 @@ &m_ast, dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE())); if (!clang_type) { clang::DeclContext *decl_ctx = - GetClangDeclContextContainingDIE(die, nullptr); + GetClangDeclContextContainingDIE(sc.comp_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 @@ -1585,7 +1585,7 @@ if (attrs.name.GetStringRef().contains('<')) { TypeSystemClang::TemplateParameterInfos template_param_infos; - if (ParseTemplateParameterInfos(die, template_param_infos)) { + if (ParseTemplateParameterInfos(sc.comp_unit, die, template_param_infos)) { clang::ClassTemplateDecl *class_template_decl = m_ast.ParseClassTemplateDecl(decl_ctx, attrs.accessibility, attrs.name.GetCString(), tag_decl_kind, @@ -1727,7 +1727,7 @@ clang_type.GetOpaqueQualType(); dwarf->GetForwardDeclClangTypeToDie() [ClangUtil::RemoveFastQualifiers(clang_type).GetOpaqueQualType()] = - die.GetID(); + std::make_pair(sc.comp_unit, die.GetID()); m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true); } } @@ -1816,7 +1816,7 @@ std::unique_ptr m_metadata_up; }; -bool DWARFASTParserClang::ParseTemplateDIE( +bool DWARFASTParserClang::ParseTemplateDIE(CompileUnit *comp_unit, const DWARFDIE &die, TypeSystemClang::TemplateParameterInfos &template_param_infos) { const dw_tag_t tag = die.Tag(); @@ -1828,7 +1828,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(comp_unit, child_die, *template_param_infos.packed_args)) return false; } if (const char *name = die.GetName()) { @@ -1866,7 +1866,7 @@ case DW_AT_type: if (attributes.ExtractFormValueAtIndex(i, form_value)) { - Type *lldb_type = die.ResolveTypeUID(form_value.Reference(die.GetMainCU())); + Type *lldb_type = die.ResolveTypeUID(comp_unit, form_value.Reference(nullptr)); if (lldb_type) clang_type = lldb_type->GetForwardCompilerType(); } @@ -1925,7 +1925,7 @@ return false; } -bool DWARFASTParserClang::ParseTemplateParameterInfos( +bool DWARFASTParserClang::ParseTemplateParameterInfos(CompileUnit *comp_unit, const DWARFDIE &parent_die, TypeSystemClang::TemplateParameterInfos &template_param_infos) { @@ -1941,7 +1941,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(comp_unit, die, template_param_infos); break; default: @@ -1953,7 +1953,7 @@ return template_param_infos.args.size() == template_param_infos.names.size(); } -bool DWARFASTParserClang::CompleteRecordType(const DWARFDIE &die, +bool DWARFASTParserClang::CompleteRecordType(CompileUnit *comp_unit, const DWARFDIE &die, lldb_private::Type *type, CompilerType &clang_type) { const dw_tag_t tag = die.Tag(); @@ -1991,14 +1991,14 @@ std::vector member_function_dies; 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(comp_unit, die); if (class_language == eLanguageTypeObjC) { ConstString class_name(clang_type.GetTypeName()); @@ -2011,11 +2011,11 @@ 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]; + const DIERef &die_ref = method_die_offsets[i].second; DWARFDIE method_die = debug_info->GetDIE(die_ref); if (method_die) - method_die.ResolveType(*dwarf); + method_die.ResolveType(comp_unit, *dwarf); } } @@ -2129,7 +2129,7 @@ return (bool)clang_type; } -bool DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die, +bool DWARFASTParserClang::CompleteTypeFromDWARF(CompileUnit *comp_unit, const DWARFDIE &die, lldb_private::Type *type, CompilerType &clang_type) { SymbolFileDWARF *dwarf = die.GetDWARF(); @@ -2158,7 +2158,7 @@ case DW_TAG_structure_type: case DW_TAG_union_type: case DW_TAG_class_type: - return CompleteRecordType(die, type, clang_type); + return CompleteRecordType(comp_unit, die, type, clang_type); case DW_TAG_enumeration_type: return CompleteEnumType(die, type, clang_type); default: @@ -2169,7 +2169,7 @@ return false; } -void DWARFASTParserClang::EnsureAllDIEsInDeclContextHaveBeenParsed( +void DWARFASTParserClang::EnsureAllDIEsInDeclContextHaveBeenParsed(lldb_private::CompileUnit *comp_unit, lldb_private::CompilerDeclContext decl_context) { auto opaque_decl_ctx = (clang::DeclContext *)decl_context.GetOpaqueDeclContext(); @@ -2178,28 +2178,28 @@ it = m_decl_ctx_to_die.erase(it)) for (DWARFDIE decl = it->second.GetFirstChild(); decl; decl = decl.GetSibling()) - GetClangDeclForDIE(decl); + GetClangDeclForDIE(comp_unit, decl); } -CompilerDecl DWARFASTParserClang::GetDeclForUIDFromDWARF(const DWARFDIE &die) { - clang::Decl *clang_decl = GetClangDeclForDIE(die); +CompilerDecl DWARFASTParserClang::GetDeclForUIDFromDWARF(CompileUnit *comp_unit, const DWARFDIE &die) { + clang::Decl *clang_decl = GetClangDeclForDIE(comp_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(CompileUnit *comp_unit, const DWARFDIE &die) { + clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE(comp_unit, die); if (clang_decl_ctx) return m_ast.CreateDeclContext(clang_decl_ctx); return CompilerDeclContext(); } CompilerDeclContext -DWARFASTParserClang::GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) { +DWARFASTParserClang::GetDeclContextContainingUIDFromDWARF(CompileUnit *comp_unit, const DWARFDIE &die) { clang::DeclContext *clang_decl_ctx = - GetClangDeclContextContainingDIE(die, nullptr); + GetClangDeclContextContainingDIE(comp_unit, die, nullptr); if (clang_decl_ctx) return m_ast.CreateDeclContext(clang_decl_ctx); return CompilerDeclContext(); @@ -2334,8 +2334,8 @@ sstr << decl_ctx.GetQualifiedName(); clang::DeclContext *containing_decl_ctx = - GetClangDeclContextContainingDIE(die, nullptr); - ParseChildParameters(containing_decl_ctx, die, true, is_static, + GetClangDeclContextContainingDIE(&comp_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 << "("; @@ -2386,7 +2386,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, @@ -2570,7 +2570,7 @@ // Handle static members if (is_external && member_byte_offset == UINT32_MAX) { - Type *var_type = die.ResolveTypeUID(encoding_form.Reference(die.GetMainCU())); + Type *var_type = die.ResolveTypeUID(comp_unit, encoding_form.Reference(nullptr)); if (var_type) { if (accessibility == eAccessNone) @@ -2583,7 +2583,7 @@ } if (!is_artificial) { - Type *member_type = die.ResolveTypeUID(encoding_form.Reference(die.GetMainCU())); + Type *member_type = die.ResolveTypeUID(comp_unit, encoding_form.Reference(nullptr)); clang::FieldDecl *field_decl = nullptr; const uint64_t character_width = 8; @@ -2822,7 +2822,7 @@ } } -bool DWARFASTParserClang::ParseChildMembers( +bool DWARFASTParserClang::ParseChildMembers(lldb_private::CompileUnit *comp_unit, const DWARFDIE &parent_die, CompilerType &class_clang_type, const LanguageType class_language, std::vector> &base_classes, @@ -2848,7 +2848,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; @@ -2922,7 +2922,7 @@ } } - Type *base_class_type = die.ResolveTypeUID(encoding_form.Reference(die.GetMainCU())); + Type *base_class_type = die.ResolveTypeUID(comp_unit, encoding_form.Reference(nullptr)); if (base_class_type == nullptr) { module_sp->ReportError("0x%8.8x: DW_TAG_inheritance failed to " "resolve the base class at 0x%8.8x" @@ -2981,7 +2981,7 @@ return true; } -size_t DWARFASTParserClang::ParseChildParameters( +size_t DWARFASTParserClang::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, std::vector &function_param_types, @@ -3047,7 +3047,7 @@ // the formal parameter DIE... (name == nullptr || ::strcmp(name, "this") == 0)) { Type *this_type = - die.ResolveTypeUID(param_type_die_form.Reference(die.GetMainCU())); + die.ResolveTypeUID(comp_unit, param_type_die_form.Reference(nullptr)); if (this_type) { uint32_t encoding_mask = this_type->GetEncodingMask(); if (encoding_mask & Type::eEncodingIsPointerUID) { @@ -3064,7 +3064,7 @@ } if (!skip) { - Type *type = die.ResolveTypeUID(param_type_die_form.Reference(die.GetMainCU())); + Type *type = die.ResolveTypeUID(comp_unit, param_type_die_form.Reference(nullptr)); if (type) { function_param_types.push_back(type->GetForwardCompilerType()); @@ -3201,7 +3201,7 @@ return array_info; } -Type *DWARFASTParserClang::GetTypeForDIE(const DWARFDIE &die) { +Type *DWARFASTParserClang::GetTypeForDIE(CompileUnit *comp_unit, const DWARFDIE &die) { if (die) { SymbolFileDWARF *dwarf = die.GetMainDWARF(); DWARFAttributes attributes; @@ -3214,7 +3214,7 @@ if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, form_value)) - return dwarf->ResolveTypeUID(form_value.Reference(die.GetMainCU()), true); + return dwarf->ResolveTypeUID(comp_unit, form_value.Reference(nullptr), true); } } } @@ -3222,7 +3222,7 @@ return nullptr; } -clang::Decl *DWARFASTParserClang::GetClangDeclForDIE(const DWARFDIE &die) { +clang::Decl *DWARFASTParserClang::GetClangDeclForDIE(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die) { if (!die) return nullptr; @@ -3242,7 +3242,7 @@ return cache_pos->second; if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification)) { - clang::Decl *decl = GetClangDeclForDIE(spec_die); + clang::Decl *decl = GetClangDeclForDIE(comp_unit, spec_die); m_die_to_decl[die.GetDIE()] = decl; m_decl_to_die[decl].insert(die.GetDIE()); return decl; @@ -3250,7 +3250,7 @@ if (DWARFDIE abstract_origin_die = die.GetReferencedDIE(DW_AT_abstract_origin)) { - clang::Decl *decl = GetClangDeclForDIE(abstract_origin_die); + clang::Decl *decl = GetClangDeclForDIE(comp_unit, abstract_origin_die); m_die_to_decl[die.GetDIE()] = decl; m_decl_to_die[decl].insert(die.GetDIE()); return decl; @@ -3262,12 +3262,12 @@ case DW_TAG_constant: case DW_TAG_formal_parameter: { SymbolFileDWARF *dwarf = die.GetMainDWARF(); - Type *type = GetTypeForDIE(die); + Type *type = GetTypeForDIE(comp_unit, die); if (dwarf && type) { const char *name = die.GetName(); clang::DeclContext *decl_context = TypeSystemClang::DeclContextGetAsDeclContext( - dwarf->GetDeclContextContainingUID(die.GetID())); + dwarf->GetDeclContextContainingUID(comp_unit, die.GetID())); decl = m_ast.CreateVariableDeclaration( decl_context, name, ClangUtil::GetQualType(type->GetForwardCompilerType())); @@ -3278,11 +3278,11 @@ SymbolFileDWARF *dwarf = die.GetMainDWARF(); DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import); if (imported_uid) { - CompilerDecl imported_decl = SymbolFileDWARF::GetDecl(imported_uid); + CompilerDecl imported_decl = SymbolFileDWARF::GetDecl(comp_unit, imported_uid); if (imported_decl) { clang::DeclContext *decl_context = TypeSystemClang::DeclContextGetAsDeclContext( - dwarf->GetDeclContextContainingUID(die.GetID())); + dwarf->GetDeclContextContainingUID(comp_unit, die.GetID())); if (clang::NamedDecl *clang_imported_decl = llvm::dyn_cast( (clang::Decl *)imported_decl.GetOpaqueDecl())) @@ -3298,11 +3298,11 @@ if (imported_uid) { CompilerDeclContext imported_decl_ctx = - SymbolFileDWARF::GetDeclContext(imported_uid); + SymbolFileDWARF::GetDeclContext(comp_unit, imported_uid); if (imported_decl_ctx) { clang::DeclContext *decl_context = TypeSystemClang::DeclContextGetAsDeclContext( - dwarf->GetDeclContextContainingUID(die.GetID())); + dwarf->GetDeclContextContainingUID(comp_unit, die.GetID())); if (clang::NamespaceDecl *ns_decl = TypeSystemClang::DeclContextGetAsNamespaceDecl( imported_decl_ctx)) @@ -3322,7 +3322,7 @@ } clang::DeclContext * -DWARFASTParserClang::GetClangDeclContextForDIE(const DWARFDIE &die) { +DWARFASTParserClang::GetClangDeclContextForDIE(CompileUnit *comp_unit, const DWARFDIE &die) { if (die) { clang::DeclContext *decl_ctx = GetCachedClangDeclContextForDIE(die); if (decl_ctx) @@ -3337,12 +3337,12 @@ break; case DW_TAG_namespace: - decl_ctx = ResolveNamespaceDIE(die); + decl_ctx = ResolveNamespaceDIE(comp_unit, die); try_parsing_type = false; break; case DW_TAG_lexical_block: - decl_ctx = GetDeclContextForBlock(die); + decl_ctx = GetDeclContextForBlock(comp_unit, die); try_parsing_type = false; break; @@ -3351,7 +3351,7 @@ } if (decl_ctx == nullptr && try_parsing_type) { - Type *type = die.GetMainDWARF()->ResolveType(die); + Type *type = die.GetMainDWARF()->ResolveType(comp_unit, die); if (type) decl_ctx = GetCachedClangDeclContextForDIE(die); } @@ -3413,21 +3413,21 @@ } clang::DeclContext * -DWARFASTParserClang::GetDeclContextForBlock(const DWARFDIE &die) { +DWARFASTParserClang::GetDeclContextForBlock(CompileUnit *comp_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(comp_unit, die); } DWARFDIE child = FindFirstChildWithAbstractOrigin( die, containing_function_with_abstract_origin); CompilerDeclContext decl_context = - GetDeclContextContainingUIDFromDWARF(child); + GetDeclContextContainingUIDFromDWARF(comp_unit, child); return (clang::DeclContext *)decl_context.GetOpaqueDeclContext(); } -clang::BlockDecl *DWARFASTParserClang::ResolveBlockDIE(const DWARFDIE &die) { +clang::BlockDecl *DWARFASTParserClang::ResolveBlockDIE(CompileUnit *comp_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()]); @@ -3435,7 +3435,7 @@ if (!decl) { DWARFDIE decl_context_die; clang::DeclContext *decl_context = - GetClangDeclContextContainingDIE(die, &decl_context_die); + GetClangDeclContextContainingDIE(comp_unit, die, &decl_context_die); decl = m_ast.CreateBlockDeclaration(decl_context); if (decl) @@ -3448,7 +3448,7 @@ } clang::NamespaceDecl * -DWARFASTParserClang::ResolveNamespaceDIE(const DWARFDIE &die) { +DWARFASTParserClang::ResolveNamespaceDIE(lldb_private::CompileUnit *comp_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 @@ -3459,7 +3459,7 @@ else { const char *namespace_name = die.GetName(); clang::DeclContext *containing_decl_ctx = - GetClangDeclContextContainingDIE(die, nullptr); + GetClangDeclContextContainingDIE(comp_unit, die, nullptr); bool is_inline = die.GetAttributeValueAsUnsigned(DW_AT_export_symbols, 0) != 0; @@ -3498,7 +3498,7 @@ return nullptr; } -clang::DeclContext *DWARFASTParserClang::GetClangDeclContextContainingDIE( +clang::DeclContext *DWARFASTParserClang::GetClangDeclContextContainingDIE(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, DWARFDIE *decl_ctx_die_copy) { SymbolFileDWARF *dwarf = die.GetMainDWARF(); @@ -3509,7 +3509,7 @@ if (decl_ctx_die) { clang::DeclContext *clang_decl_ctx = - GetClangDeclContextForDIE(decl_ctx_die); + GetClangDeclContextForDIE(comp_unit, decl_ctx_die); if (clang_decl_ctx) return clang_decl_ctx; } @@ -3534,7 +3534,7 @@ m_decl_ctx_to_die.insert(std::make_pair(decl_ctx, die)); } -bool DWARFASTParserClang::CopyUniqueClassMethodTypes( +bool DWARFASTParserClang::CopyUniqueClassMethodTypes(CompileUnit *comp_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) @@ -3646,9 +3646,9 @@ } DWARFASTParserClang *src_dwarf_ast_parser = - (DWARFASTParserClang *)SymbolFileDWARF::GetDWARFParser(src_die.GetCU()); + (DWARFASTParserClang *)SymbolFileDWARF::GetDWARFParser(comp_unit); DWARFASTParserClang *dst_dwarf_ast_parser = - (DWARFASTParserClang *)SymbolFileDWARF::GetDWARFParser(dst_die.GetCU()); + (DWARFASTParserClang *)SymbolFileDWARF::GetDWARFParser(comp_unit); // Now do the work of linking the DeclContexts and Types. if (fast_path) { 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 @@ -47,7 +47,7 @@ SymbolFileDWARF *GetMainDWARF() const; DWARFUnitPair GetCU() const { return m_cu; } - DWARFCompileUnit *GetMainCU() const { return m_cu.GetMainCU(); } +// DWARFCompileUnit *GetMainCU() const { return m_cu.GetMainCU(); } DWARFDebugInfoEntry *GetDIE() const { return m_die; } 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 @@ -23,7 +23,7 @@ if (!IsValid()) return llvm::None; - return DIERef(m_cu->GetSymbolFileDWARF().GetDwoNum(), (!m_cu.GetMainCUOrNull() ? llvm::None : llvm::Optional(m_cu.GetMainCU()->GetID())), + return DIERef(m_cu->GetSymbolFileDWARF().GetDwoNum(), (false/*!m_cu.GetMainCUOrNull()*/ ? llvm::None : llvm::Optional(0/*m_cu.GetMainCU()->GetID()*/)), GetCU()->GetSymbolFileDWARF().GetIsDwz() ? DIERef::CommonDwz : DIERef::MainDwz, m_cu->GetDebugSection(), m_die->GetOffset()); @@ -100,8 +100,10 @@ } SymbolFileDWARF *DWARFBaseDIE::GetMainDWARF() const { +#if 0 if (m_cu.GetMainCU()) return &m_cu.GetMainCU()->GetSymbolFileDWARF(); +#endif return GetDWARF(); } 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(SymbolFileDWARF &dwarf) const; + lldb_private::Type *ResolveType(lldb_private::CompileUnit *comp_unit, SymbolFileDWARF &dwarf) const; // Resolve a type by UID using this DIE's DWARF file - lldb_private::Type *ResolveTypeUID(const DWARFDIE &die) const; + lldb_private::Type *ResolveTypeUID(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die) const; // Functions for obtaining DIE relations and references 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 @@ -122,7 +122,7 @@ DWARFDIE DWARFDIE::GetDIE(dw_offset_t die_offset) const { if (IsValid()) - return m_cu->GetDIE(GetMainCU(), die_offset); + return m_cu->GetDIE(nullptr, die_offset); else return DWARFDIE(); } @@ -135,7 +135,7 @@ DWARFFormValue form_value; if (m_die->GetAttributeValue(cu, attr, form_value, nullptr, check_specification_or_abstract_origin)) - return form_value.Reference(cu.GetMainCU()); + return form_value.Reference(nullptr); } return DWARFDIE(); } @@ -346,16 +346,16 @@ } } -lldb_private::Type *DWARFDIE::ResolveType(SymbolFileDWARF &dwarf) const { +lldb_private::Type *DWARFDIE::ResolveType(CompileUnit *comp_unit, SymbolFileDWARF &dwarf) const { if (IsValid()) - return dwarf.ResolveType(*this, true); + return dwarf.ResolveType(comp_unit, *this, true); else return nullptr; } -lldb_private::Type *DWARFDIE::ResolveTypeUID(const DWARFDIE &die) const { +lldb_private::Type *DWARFDIE::ResolveTypeUID(CompileUnit *comp_unit, const DWARFDIE &die) const { if (SymbolFileDWARF *dwarf = GetDWARF()) - return dwarf->ResolveTypeUID(die, true); + return dwarf->ResolveTypeUID(comp_unit, die, true); return nullptr; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -302,11 +302,11 @@ break; case DW_AT_abstract_origin: - dies.push_back(form_value.Reference(cu.GetMainCU())); + dies.push_back(form_value.Reference(nullptr)); break; case DW_AT_specification: - dies.push_back(form_value.Reference(cu.GetMainCU())); + dies.push_back(form_value.Reference(nullptr)); break; case DW_AT_decl_file: @@ -518,14 +518,14 @@ case DW_AT_abstract_origin: case DW_AT_specification: { - DWARFDIE abstract_die = form_value.Reference(cu.GetMainCU()); + DWARFDIE abstract_die = form_value.Reference(nullptr); form_value.Dump(s); // *ostrm_ptr << HEX32 << abstract_die.GetOffset() << " ( "; abstract_die.GetName(s); } break; case DW_AT_type: { - DWARFDIE type_die = form_value.Reference(cu.GetMainCU()); + DWARFDIE type_die = form_value.Reference(nullptr); s.PutCString(" ( "); type_die.AppendTypeName(s); s.PutCString(" )"); @@ -701,7 +701,7 @@ DWARFSimpleDIE die = GetAttributeValueAsReference(cu.GetCU(), attr, check_specification_or_abstract_origin); if (!die.IsValid()) return {}; - return {{die.GetCU(),cu.GetMainCU()},die.GetDIE()}; + return {{die.GetCU(),nullptr},die.GetDIE()}; } uint64_t DWARFDebugInfoEntry::GetAttributeValueAsAddress( @@ -927,14 +927,14 @@ } } - DWARFDIE spec_die = attributes.FormValueAsReference(DW_AT_specification, cu.GetMainCU()); + DWARFDIE spec_die = attributes.FormValueAsReference(DW_AT_specification, nullptr); if (spec_die) { DWARFDIE decl_ctx_die = spec_die.GetParentDeclContextDIE(); if (decl_ctx_die) return decl_ctx_die; } - DWARFDIE abs_die = attributes.FormValueAsReference(DW_AT_abstract_origin, cu.GetMainCU()); + DWARFDIE abs_die = attributes.FormValueAsReference(DW_AT_abstract_origin, nullptr); if (abs_die) { DWARFDIE decl_ctx_die = abs_die.GetParentDeclContextDIE(); if (decl_ctx_die) 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 @@ -56,7 +56,7 @@ /// 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(lldb_private::CompileUnit *comp_unit, llvm::StringRef name, DIERef ref, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, std::vector &dies); 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 @@ -16,7 +16,7 @@ DWARFIndex::~DWARFIndex() = default; -void DWARFIndex::ProcessFunctionDIE(llvm::StringRef name, DIERef ref, +void DWARFIndex::ProcessFunctionDIE(CompileUnit *comp_unit, llvm::StringRef name, DIERef ref, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, @@ -36,7 +36,7 @@ // 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(comp_unit, &parent_decl_ctx, die)) return; // In case of a full match, we just insert everything we find. diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnitPair.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnitPair.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnitPair.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnitPair.h @@ -26,8 +26,8 @@ DWARFUnit *operator ->() const; DWARFUnit &operator *() const; DWARFUnit *GetCU() const; - DWARFCompileUnit *GetMainCU() const; - DWARFCompileUnit *GetMainCUOrNull() const; +// DWARFCompileUnit *GetMainCU() const; +// DWARFCompileUnit *GetMainCUOrNull() const; explicit operator bool() const; operator DWARFUnit *() const; operator DWARFUnit &() const; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnitPair.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnitPair.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnitPair.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnitPair.cpp @@ -21,8 +21,8 @@ DWARFUnit *DWARFUnitPair::operator ->() const { assert(m_cu); return m_cu; } DWARFUnit &DWARFUnitPair::operator *() const { assert(m_cu); return *m_cu; } DWARFUnit *DWARFUnitPair::GetCU() const { assert(m_cu); return m_cu; } -DWARFCompileUnit *DWARFUnitPair::GetMainCU() const { return m_main_cu; } -DWARFCompileUnit *DWARFUnitPair::GetMainCUOrNull() const { if (m_main_cu == m_cu) return nullptr; return m_main_cu; } +//DWARFCompileUnit *DWARFUnitPair::GetMainCU() const { return m_main_cu; } +//DWARFCompileUnit *DWARFUnitPair::GetMainCUOrNull() const { if (m_main_cu == m_cu) return nullptr; return m_main_cu; } DWARFUnitPair::operator bool() const{ return m_cu != nullptr; } DWARFUnitPair::operator DWARFUnit *() const { assert(m_cu); return m_cu; } 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 @@ -67,7 +67,7 @@ void DebugNamesDWARFIndex::Append(const DebugNames::Entry &entry, DIEArray &offsets) { if (llvm::Optional ref = ToDIERef(entry)) - offsets.push_back(*ref); + offsets.push_back({nullptr/*FIXMEindex*/,*ref}); } void DebugNamesDWARFIndex::MaybeLogLookupError(llvm::Error error, @@ -160,7 +160,7 @@ // FIXME: .debug_names have no DWZ support yet. DWARFUnit *cu = m_debug_info.GetUnit(*ref); if (!cu || !cu->Supports_DW_AT_APPLE_objc_complete_type()) { - incomplete_types.push_back(*ref); + incomplete_types.push_back({nullptr/*FIXMEindex*/,*ref}); continue; } @@ -171,10 +171,10 @@ if (die.GetAttributeValueAsUnsigned(DW_AT_APPLE_objc_complete_type, 0)) { // If we find the complete version we're done. - offsets.push_back(*ref); + offsets.push_back({nullptr/*FIXMEindex*/,*ref}); return; } else { - incomplete_types.push_back(*ref); + incomplete_types.push_back({nullptr/*FIXMEindex*/,*ref}); } } @@ -228,7 +228,7 @@ continue; if (llvm::Optional ref = ToDIERef(entry)) - ProcessFunctionDIE(name.GetStringRef(), *ref, dwarf, parent_decl_ctx, + ProcessFunctionDIE(nullptr/*FIXMEindex*/, name.GetStringRef(), *ref, dwarf, parent_decl_ctx, name_type_mask, v); } 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 @@ -20,6 +20,10 @@ #include "DWARFFormValue.h" #include "NameToDIE.h" +namespace lldb_private { + class CompileUnit; +} + class DWARFMappedHash { public: enum AtomType : uint16_t { @@ -61,12 +65,17 @@ /// A 32 bit hash of the fully qualified name. uint32_t qualified_name_hash = 0; + lldb_private::CompileUnit *comp_unit = nullptr; + DIEInfo() = default; - DIEInfo(dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h); + DIEInfo(dw_offset_t o, dw_tag_t t, uint32_t f, uint32_t h, lldb_private::CompileUnit *comp_unit_); explicit operator DIERef() const { return DIERef(llvm::None, llvm::None, DIERef::MainDwz, DIERef::Section::DebugInfo, die_offset); } + explicit operator std::pair() const { + return std::pair{comp_unit,*this}; + } }; struct Atom { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp @@ -118,8 +118,8 @@ } DWARFMappedHash::DIEInfo::DIEInfo(dw_offset_t o, dw_tag_t t, uint32_t f, - uint32_t h) - : die_offset(o), tag(t), type_flags(f), qualified_name_hash(h) {} + uint32_t h, lldb_private::CompileUnit *comp_unit_) + : die_offset(o), tag(t), type_flags(f), qualified_name_hash(h),comp_unit(comp_unit_) {} DWARFMappedHash::Prologue::Prologue(dw_offset_t _die_base_offset) : die_base_offset(_die_base_offset), atoms(), atom_mask(0), 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 @@ -110,13 +110,13 @@ if (log) { m_module.LogMessage( log, "ManualDWARFIndex::IndexUnit for unit at .debug_info[0x%8.8x] from .debug_info[0x%8.8x]", - unit->GetOffset(), unit.GetMainCU()->GetOffset()); + unit->GetOffset(), unit.GetCU()->GetOffset()); } IndexUnitImpl(unit, set); if (SymbolFileDWARFDwo *dwo_symbol_file = unit->GetDwoSymbolFile()) { - assert(unit.GetCU() == unit.GetMainCU()); +// assert(unit.GetCU() == unit.GetMainCU()); DWARFDebugInfo &dwo_info = *dwo_symbol_file->DebugInfo(); for (size_t i = 0; i < dwo_info.GetNumUnits(); ++i) { // Separate main CU is not used for DWO CUs. @@ -285,16 +285,16 @@ 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(nullptr/*FIXMEindex*/, ConstString(name), ref); if (class_name_with_category) - set.objc_class_selectors.Insert(class_name_with_category, ref); + set.objc_class_selectors.Insert(nullptr/*FIXMEindex*/, class_name_with_category, ref); 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(nullptr/*FIXMEindex*/, class_name_no_category, ref); if (objc_selector_name) - set.function_selectors.Insert(objc_selector_name, ref); + set.function_selectors.Insert(nullptr/*FIXMEindex*/, objc_selector_name, ref); if (objc_fullname_no_category_name) - set.function_fullnames.Insert(objc_fullname_no_category_name, + set.function_fullnames.Insert(nullptr/*FIXMEindex*/, objc_fullname_no_category_name, ref); } } @@ -303,12 +303,12 @@ bool is_method = DWARFDIE(unitpair, &die).IsMethod(); if (is_method) - set.function_methods.Insert(ConstString(name), ref); + set.function_methods.Insert(nullptr/*FIXMEindex*/, ConstString(name), ref); else - set.function_basenames.Insert(ConstString(name), ref); + set.function_basenames.Insert(nullptr/*FIXMEindex*/, ConstString(name), ref); if (!is_method && !mangled_cstr && !is_objc_method) - set.function_fullnames.Insert(ConstString(name), ref); + set.function_fullnames.Insert(nullptr/*FIXMEindex*/, ConstString(name), ref); } if (mangled_cstr) { // Make sure our mangled name isn't the same string table entry as @@ -318,7 +318,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(nullptr/*FIXMEindex*/, ConstString(mangled_cstr), ref); } } } @@ -336,19 +336,19 @@ case DW_TAG_union_type: case DW_TAG_unspecified_type: if (name && !is_declaration) - set.types.Insert(ConstString(name), ref); + set.types.Insert(nullptr/*FIXMEindex*/, ConstString(name), ref); if (mangled_cstr && !is_declaration) - set.types.Insert(ConstString(mangled_cstr), ref); + set.types.Insert(nullptr/*FIXMEindex*/, ConstString(mangled_cstr), ref); break; case DW_TAG_namespace: if (name) - set.namespaces.Insert(ConstString(name), ref); + set.namespaces.Insert(nullptr/*FIXMEindex*/, ConstString(name), ref); 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(nullptr/*FIXMEindex*/, ConstString(name), ref); // 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 @@ -360,7 +360,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(nullptr/*FIXMEindex*/, ConstString(mangled_cstr), ref); } } break; @@ -400,7 +400,7 @@ import_cu->SetMainCU(unitpair.GetMainCU()); // FIXME #endif AddExtractedPU(unit, *import_cu); - IndexUnit({import_cu,unitpair.GetMainCU()}, set); + IndexUnit({import_cu,nullptr}, set); } break; @@ -491,22 +491,26 @@ if (name_type_mask & eFunctionNameTypeFull) { DIEArray offsets; m_set.function_fullnames.Find(name, offsets); - for (const DIERef &die_ref: offsets) { + for (const auto &item : offsets) { + CompileUnit *comp_unit = item.first; + const DIERef die_ref = item.second; DWARFDIE die = dwarf.GetDIE(die_ref); if (!die) continue; - if (SymbolFileDWARF::DIEInDeclContext(&parent_decl_ctx, die)) + if (SymbolFileDWARF::DIEInDeclContext(comp_unit, &parent_decl_ctx, die)) dies.push_back(die); } } if (name_type_mask & eFunctionNameTypeBase) { DIEArray offsets; m_set.function_basenames.Find(name, offsets); - for (const DIERef &die_ref: offsets) { + for (const auto &item : offsets) { + CompileUnit *comp_unit = item.first; + const DIERef die_ref = item.second; DWARFDIE die = dwarf.GetDIE(die_ref); if (!die) continue; - if (SymbolFileDWARF::DIEInDeclContext(&parent_decl_ctx, die)) + if (SymbolFileDWARF::DIEInDeclContext(comp_unit, &parent_decl_ctx, die)) dies.push_back(die); } offsets.clear(); @@ -515,7 +519,8 @@ if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.IsValid()) { DIEArray offsets; m_set.function_methods.Find(name, offsets); - for (const DIERef &die_ref: offsets) { + for (const auto &item : offsets) { + const DIERef die_ref = item.second; if (DWARFDIE die = dwarf.GetDIE(die_ref)) dies.push_back(die); } @@ -525,7 +530,8 @@ !parent_decl_ctx.IsValid()) { DIEArray offsets; m_set.function_selectors.Find(name, offsets); - for (const DIERef &die_ref: offsets) { + for (const auto &item : offsets) { + const DIERef die_ref = item.second; if (DWARFDIE die = dwarf.GetDIE(die_ref)) dies.push_back(die); } 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 @@ -27,7 +27,7 @@ void Dump(lldb_private::Stream *s); - void Insert(lldb_private::ConstString name, const DIERef &die_ref); + void Insert(lldb_private::CompileUnit *comp_unit, lldb_private::ConstString name, const DIERef &die_ref); void Append(const NameToDIE &other); @@ -55,7 +55,7 @@ &callback) const; protected: - lldb_private::UniqueCStringMap m_map; + lldb_private::UniqueCStringMap> m_map; }; #endif // SymbolFileDWARF_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,8 +22,8 @@ m_map.SizeToFit(); } -void NameToDIE::Insert(ConstString name, const DIERef &die_ref) { - m_map.Append(name, die_ref); +void NameToDIE::Insert(lldb_private::CompileUnit *comp_unit, ConstString name, const DIERef &die_ref) { + m_map.Append(name, {comp_unit,die_ref}); } size_t NameToDIE::Find(ConstString name, DIEArray &info_array) const { @@ -40,9 +40,11 @@ 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); + const auto &item = m_map.GetValueRefAtIndexUnchecked(i); + //lldb_private::CompileUnit *comp_unit = item.first; + const DIERef die_ref = item.second; if (compare(die_ref)) - info_array.push_back(die_ref); + info_array.push_back(item); } return info_array.size() - initial_size; } @@ -77,7 +79,7 @@ void NameToDIE::Dump(Stream *s) { const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { - s->Format("{0} \"{1}\"\n", m_map.GetValueAtIndexUnchecked(i), + s->Format("{0} \"{1}\"\n", m_map.GetValueAtIndexUnchecked(i).second, m_map.GetCStringAtIndexUnchecked(i)); } } @@ -88,7 +90,7 @@ const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { if (!callback(m_map.GetCStringAtIndexUnchecked(i), - m_map.GetValueAtIndexUnchecked(i))) + m_map.GetValueAtIndexUnchecked(i).second)) break; } } 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 @@ -136,27 +136,27 @@ size_t ParseVariablesForContext(const lldb_private::SymbolContext &sc) override; - lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override; + lldb_private::Type *ResolveTypeUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t type_uid) override; llvm::Optional GetDynamicArrayInfoForUID( lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) override; bool CompleteType(lldb_private::CompilerType &compiler_type) override; - lldb_private::Type *ResolveType(const DWARFDIE &die, + lldb_private::Type *ResolveType(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, bool assert_not_being_parsed = true, bool resolve_function_context = false); - lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override; + lldb_private::CompilerDecl GetDeclForUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) override; lldb_private::CompilerDeclContext - GetDeclContextForUID(lldb::user_id_t uid) override; + GetDeclContextForUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) override; lldb_private::CompilerDeclContext - GetDeclContextContainingUID(lldb::user_id_t uid) override; + GetDeclContextContainingUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) override; void - ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override; + ParseDeclsForContext(lldb_private::CompileUnit *comp_unit, lldb_private::CompilerDeclContext decl_ctx) override; uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, lldb::SymbolContextItem resolve_scope, @@ -291,7 +291,7 @@ llvm::Optional GetDWOId(); static bool - DIEInDeclContext(const lldb_private::CompilerDeclContext *parent_decl_ctx, + DIEInDeclContext(lldb_private::CompileUnit *comp_unit, const lldb_private::CompilerDeclContext *parent_decl_ctx, const DWARFDIE &die); std::vector> @@ -305,19 +305,21 @@ lldb_private::FileSpec GetFile(DWARFUnit &unit, size_t file_idx); + static SymbolFileDWARF &dwarf_from_comp_unit(lldb_private::CompileUnit *comp_unit); + static llvm::Expected - GetTypeSystem(DWARFUnitPair unitpair); + GetTypeSystem(lldb_private::CompileUnit *comp_unit); - static DWARFASTParser *GetDWARFParser(DWARFUnitPair unitpair); + static DWARFASTParser *GetDWARFParser(lldb_private::CompileUnit *comp_unit); // CompilerDecl related functions - static lldb_private::CompilerDecl GetDecl(const DWARFDIE &die); + static lldb_private::CompilerDecl GetDecl(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die); - static lldb_private::CompilerDeclContext GetDeclContext(const DWARFDIE &die); + static lldb_private::CompilerDeclContext GetDeclContext(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die); static lldb_private::CompilerDeclContext - GetContainingDeclContext(const DWARFDIE &die); + GetContainingDeclContext(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die); static void GetDWARFDeclContext(const DWARFDIE &die, DWARFDeclContext &dwarf_decl_ctx); @@ -325,6 +327,7 @@ static lldb::LanguageType LanguageTypeFromDWARF(uint64_t val); static lldb::LanguageType GetLanguage(DWARFUnitPair unitpair); + static lldb::LanguageType GetLanguage(lldb_private::CompileUnit *comp_unit); SymbolFileDWARFDwz *GetDwzSymbolFile() const { return m_dwz_symfile; @@ -339,7 +342,7 @@ typedef llvm::DenseMap DIEToClangType; - typedef llvm::DenseMap + typedef llvm::DenseMap> ClangTypeToDIE; DISALLOW_COPY_AND_ASSIGN(SymbolFileDWARF); @@ -377,10 +380,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(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, bool assert_not_being_parsed); - lldb_private::Type *ResolveTypeUID(const DIERef &die_ref); + lldb_private::Type *ResolveTypeUID(lldb_private::CompileUnit *comp_unit, const DIERef &die_ref); lldb::VariableSP ParseVariableDIE(const lldb_private::SymbolContext &sc, const DWARFDIE &die, @@ -415,7 +418,7 @@ lldb_private::Symbol * GetObjCClassSymbol(lldb_private::ConstString objc_class_name); - lldb::TypeSP GetTypeForDIE(const DWARFDIE &die, + lldb::TypeSP GetTypeForDIE(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, bool resolve_function_context = false); void SetDebugMapModule(const lldb::ModuleSP &module_sp) { @@ -455,7 +458,7 @@ typedef std::set TypeSet; - void GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset, + void GetTypes(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, dw_offset_t min_die_offset, dw_offset_t max_die_offset, uint32_t type_mask, TypeSet &type_set); 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 @@ -263,7 +263,7 @@ return debug_map_symfile->GetTypeList(); return SymbolFile::GetTypeList(); } -void SymbolFileDWARF::GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset, +void SymbolFileDWARF::GetTypes(CompileUnit *comp_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) { @@ -321,7 +321,7 @@ if (add_type) { const bool assert_not_being_parsed = true; - Type *type = ResolveTypeUID(die, assert_not_being_parsed); + Type *type = ResolveTypeUID(comp_unit, die, assert_not_being_parsed); if (type) { if (type_set.find(type) == type_set.end()) 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(comp_unit, child_die, min_die_offset, max_die_offset, type_mask, type_set); } } } @@ -352,7 +352,7 @@ dwarf_cu = GetDWARFCompileUnit(comp_unit); if (!dwarf_cu) return; - GetTypes(dwarf_cu->DIE(), dwarf_cu->GetOffset(), + GetTypes(comp_unit, dwarf_cu->DIE(), dwarf_cu->GetOffset(), dwarf_cu->GetNextUnitOffset(), type_mask, type_set); } else { DWARFDebugInfo *info = DebugInfo(); @@ -361,7 +361,7 @@ for (size_t cu_idx = 0; cu_idx < num_cus; ++cu_idx) { dwarf_cu = llvm::dyn_cast(info->GetUnitAtIndex(cu_idx)); if (dwarf_cu) { - GetTypes(dwarf_cu->DIE(), 0, UINT32_MAX, type_mask, type_set); + GetTypes(comp_unit, dwarf_cu->DIE(), 0, UINT32_MAX, type_mask, type_set); } } } @@ -621,6 +621,7 @@ if (!comp_unit) return nullptr; + assert(this==&dwarf_from_comp_unit(comp_unit)); DWARFDebugInfo *info = DebugInfo(); if (info) { // The compile unit ID is the index of the DWARF unit. @@ -1217,10 +1218,10 @@ return false; } -void SymbolFileDWARF::ParseDeclsForContext(CompilerDeclContext decl_ctx) { +void SymbolFileDWARF::ParseDeclsForContext(lldb_private::CompileUnit *comp_unit, CompilerDeclContext decl_ctx) { auto *type_system = decl_ctx.GetTypeSystem(); if (type_system != nullptr) - type_system->GetDWARFParser()->EnsureAllDIEsInDeclContextHaveBeenParsed( + type_system->GetDWARFParser()->EnsureAllDIEsInDeclContextHaveBeenParsed(comp_unit, decl_ctx); } @@ -1288,7 +1289,7 @@ return DWARFDIE(); } -CompilerDecl SymbolFileDWARF::GetDeclForUID(lldb::user_id_t type_uid) { +CompilerDecl SymbolFileDWARF::GetDeclForUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t type_uid) { // This method can be called without going through the symbol vendor so we // need to lock the module. std::lock_guard guard(GetModuleMutex()); @@ -1296,12 +1297,12 @@ // SymbolFileDWARF::GetDIE(). See comments inside the // SymbolFileDWARF::GetDIE() for details. if (DWARFDIE die = GetDIE(type_uid)) - return GetDecl(die); + return GetDecl(comp_unit, die); return CompilerDecl(); } CompilerDeclContext -SymbolFileDWARF::GetDeclContextForUID(lldb::user_id_t type_uid) { +SymbolFileDWARF::GetDeclContextForUID(CompileUnit *comp_unit, lldb::user_id_t type_uid) { // This method can be called without going through the symbol vendor so we // need to lock the module. std::lock_guard guard(GetModuleMutex()); @@ -1309,28 +1310,28 @@ // SymbolFileDWARF::GetDIE(). See comments inside the // SymbolFileDWARF::GetDIE() for details. if (DWARFDIE die = GetDIE(type_uid)) - return GetDeclContext(die); + return GetDeclContext(comp_unit, die); return CompilerDeclContext(); } CompilerDeclContext -SymbolFileDWARF::GetDeclContextContainingUID(lldb::user_id_t type_uid) { +SymbolFileDWARF::GetDeclContextContainingUID(CompileUnit *comp_unit, lldb::user_id_t type_uid) { std::lock_guard guard(GetModuleMutex()); // 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); + return GetContainingDeclContext(comp_unit, die); return CompilerDeclContext(); } -Type *SymbolFileDWARF::ResolveTypeUID(lldb::user_id_t type_uid) { +Type *SymbolFileDWARF::ResolveTypeUID(CompileUnit *comp_unit, lldb::user_id_t type_uid) { std::lock_guard guard(GetModuleMutex()); // 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(*this); + return type_die.ResolveType(comp_unit, *this); else return nullptr; } @@ -1345,11 +1346,11 @@ return llvm::None; } -Type *SymbolFileDWARF::ResolveTypeUID(const DIERef &die_ref) { - return ResolveType(GetDIE(die_ref), true); +Type *SymbolFileDWARF::ResolveTypeUID(lldb_private::CompileUnit *comp_unit, const DIERef &die_ref) { + return ResolveType(comp_unit, GetDIE(die_ref), true); } -Type *SymbolFileDWARF::ResolveTypeUID(const DWARFDIE &die, +Type *SymbolFileDWARF::ResolveTypeUID(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, bool assert_not_being_parsed) { if (die) { Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); @@ -1383,7 +1384,7 @@ } } } - return ResolveType(die); + return ResolveType(comp_unit, die); } return nullptr; } @@ -1433,7 +1434,9 @@ return true; } - DWARFDIE dwarf_die = GetDIE(die_it->getSecond()); + const auto &item = die_it->getSecond(); + CompileUnit *comp_unit = item.first; + DWARFDIE dwarf_die = GetDIE(item.second); 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 @@ -1451,17 +1454,17 @@ dwarf_die.GetID(), dwarf_die.GetTagAsCString(), type->GetName().AsCString()); assert(compiler_type); - if (DWARFASTParser *dwarf_ast = GetDWARFParser(dwarf_die.GetCU())) - return dwarf_ast->CompleteTypeFromDWARF(dwarf_die, type, compiler_type); + if (DWARFASTParser *dwarf_ast = GetDWARFParser(comp_unit)) + return dwarf_ast->CompleteTypeFromDWARF(comp_unit, dwarf_die, type, compiler_type); } return false; } -Type *SymbolFileDWARF::ResolveType(const DWARFDIE &die, +Type *SymbolFileDWARF::ResolveType(CompileUnit *comp_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(comp_unit, die, resolve_function_context).get(); if (assert_not_being_parsed) { if (type != DIE_IS_BEING_PARSED) @@ -2107,7 +2110,8 @@ bool done = false; for (size_t i = 0; i < num_die_matches && !done; ++i) { - const DIERef &die_ref = die_offsets[i]; + CompileUnit *comp_unit = die_offsets[i].first; + const DIERef die_ref = die_offsets[i].second; DWARFDIE die = GetDIE(die_ref); if (die) { @@ -2120,15 +2124,12 @@ break; case DW_TAG_variable: { - auto *dwarf_cu = die.GetMainCU(); - if (!dwarf_cu) - continue; - sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); + sc.comp_unit = comp_unit; if (parent_decl_ctx) { - if (DWARFASTParser *dwarf_ast = GetDWARFParser(die.GetCU())) { + if (DWARFASTParser *dwarf_ast = GetDWARFParser(comp_unit)) { CompilerDeclContext actual_parent_decl_ctx = - dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); + dwarf_ast->GetDeclContextContainingUIDFromDWARF(comp_unit, die); if (!actual_parent_decl_ctx || actual_parent_decl_ctx != *parent_decl_ctx) continue; @@ -2199,15 +2200,12 @@ 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]; + CompileUnit *comp_unit = die_offsets[i].first; + const DIERef die_ref = die_offsets[i].second; DWARFDIE die = GetDIE(die_ref); if (die) { - DWARFCompileUnit *dwarf_cu = - die.GetMainCU(); - if (!dwarf_cu) - continue; - sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); + sc.comp_unit = comp_unit; ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables); @@ -2275,7 +2273,7 @@ return false; } -bool SymbolFileDWARF::DIEInDeclContext(const CompilerDeclContext *decl_ctx, +bool SymbolFileDWARF::DIEInDeclContext(CompileUnit *comp_unit, const CompilerDeclContext *decl_ctx, 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 @@ -2284,9 +2282,9 @@ return true; if (die) { - if (DWARFASTParser *dwarf_ast = GetDWARFParser(die.GetCU())) { + if (DWARFASTParser *dwarf_ast = GetDWARFParser(comp_unit)) { if (CompilerDeclContext actual_decl_ctx = - dwarf_ast->GetDeclContextContainingUIDFromDWARF(die)) + dwarf_ast->GetDeclContextContainingUIDFromDWARF(comp_unit, die)) return decl_ctx->IsContainedInLookup(actual_decl_ctx); } } @@ -2378,7 +2376,8 @@ m_index->GetFunctions(regex, offsets); llvm::DenseSet resolved_dies; - for (DIERef ref : offsets) { + for (const auto &item : offsets) { + const DIERef ref = item.second; DWARFDIE die = info->GetDIE(ref); if (!die) { m_index->ReportInvalidDIERef(ref, regex.GetText()); @@ -2454,13 +2453,14 @@ 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]; + CompileUnit *comp_unit = die_offsets[i].first; + const DIERef &die_ref = die_offsets[i].second; DWARFDIE die = GetDIE(die_ref); if (die) { - if (!DIEInDeclContext(parent_decl_ctx, die)) + if (!DIEInDeclContext(comp_unit, parent_decl_ctx, die)) continue; // The containing decl contexts don't match - Type *matching_type = ResolveType(die, true, true); + Type *matching_type = ResolveType(comp_unit, die, true, true); if (matching_type) { // We found a type pointer, now find the shared pointer form our type // list @@ -2526,7 +2526,8 @@ 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]; + CompileUnit *comp_unit = die_offsets[i].first; + const DIERef &die_ref = die_offsets[i].second; DWARFDIE die = GetDIE(die_ref); if (!die) { @@ -2541,7 +2542,7 @@ if (!contextMatches(die_context, pattern)) continue; - if (Type *matching_type = ResolveType(die, true, true)) { + if (Type *matching_type = ResolveType(comp_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()); @@ -2583,15 +2584,16 @@ 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]; + CompileUnit *comp_unit = die_offsets[i].first; + const DIERef &die_ref = die_offsets[i].second; DWARFDIE die = GetDIE(die_ref); if (die) { - if (!DIEInDeclContext(parent_decl_ctx, die)) + if (!DIEInDeclContext(comp_unit, parent_decl_ctx, 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(comp_unit)) { + namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(comp_unit, die); if (namespace_decl_ctx) break; } @@ -2615,17 +2617,21 @@ return namespace_decl_ctx; } -TypeSP SymbolFileDWARF::GetTypeForDIE(const DWARFDIE &die, +TypeSP SymbolFileDWARF::GetTypeForDIE(lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, bool resolve_function_context) { +lldbassert(!GetIsDwz()); TypeSP type_sp; if (die) { Type *type_ptr = GetDIEToType().lookup(die.GetDIE()); if (type_ptr == nullptr) { + SymbolContextScope *scope=comp_unit; +#if 0 SymbolContextScope *scope; if (auto *dwarf_cu = die.GetMainCU()) scope = GetCompUnitForDWARFCompUnit(*dwarf_cu); else scope = GetObjectFile()->GetModule().get(); +#endif assert(scope); SymbolContext sc(scope); const DWARFDebugInfoEntry *parent_die = die.GetParent().GetDIE(); @@ -2761,7 +2767,8 @@ if (num_matches) { for (size_t i = 0; i < num_matches; ++i) { - const DIERef &die_ref = die_offsets[i]; + CompileUnit *comp_unit = die_offsets[i].first; + const DIERef &die_ref = die_offsets[i].second; DWARFDIE type_die = GetDIE(die_ref); if (type_die) { @@ -2787,7 +2794,7 @@ DW_AT_APPLE_objc_complete_type, 0); if (try_resolving_type) { - Type *resolved_type = ResolveType(type_die, false, true); + Type *resolved_type = ResolveType(comp_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", @@ -2943,7 +2950,8 @@ } if (num_matches) { for (size_t i = 0; i < num_matches; ++i) { - const DIERef &die_ref = die_offsets[i]; + CompileUnit *comp_unit = die_offsets[i].first; + const DIERef &die_ref = die_offsets[i].second; DWARFDIE type_die = GetDIE(die_ref); if (type_die) { @@ -3001,7 +3009,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(comp_unit, type_die, false); if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) { type_sp = resolved_type->shared_from_this(); break; @@ -3056,7 +3064,7 @@ GetTypeList().Insert(type_sp); if (die.Tag() == DW_TAG_subprogram) { - std::string scope_qualified_name(GetDeclContextForUID(die.GetID()) + std::string scope_qualified_name(GetDeclContextForUID(sc.comp_unit, die.GetID()) .GetScopeQualifiedName() .AsCString("")); if (scope_qualified_name.size()) { @@ -3183,7 +3191,7 @@ 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]; + const DIERef die_ref = die_offsets[i].second; DWARFDIE die = GetDIE(die_ref); if (die) { VariableSP var_sp( @@ -3356,7 +3364,7 @@ } } break; case DW_AT_specification: - spec_die = form_value.Reference(die.GetMainCU()); + spec_die = form_value.Reference(nullptr); break; case DW_AT_start_scope: // TODO: Implement this. @@ -3561,7 +3569,7 @@ if (symbol_context_scope) { SymbolFileTypeSP type_sp( - new SymbolFileType(*this, GetUID(type_die_form.Reference(die.GetMainCU())))); + new SymbolFileType(*this, GetUID(type_die_form.Reference(nullptr)))); if (const_value.Form() && type_sp && type_sp->GetType()) location.UpdateValue(const_value.Unsigned(), @@ -3841,7 +3849,7 @@ // Extract DW_AT_call_origin (the call target's DIE). if (attr == DW_AT_call_origin) { - call_origin = form_value.Reference(child.GetMainCU()); + call_origin = form_value.Reference(nullptr); if (!call_origin->IsValid()) { LLDB_LOG(log, "CollectCallEdges: Invalid call origin in {0}", function_die.GetPubname()); @@ -3981,15 +3989,17 @@ return m_dwp_symfile.get(); } -llvm::Expected SymbolFileDWARF::GetTypeSystem(DWARFUnitPair unitpair) { - DWARFUnit *unit = unitpair.GetMainCU(); - if (!unit) - unit = unitpair.GetCU(); - return unit->GetSymbolFileDWARF().GetTypeSystemForLanguage(GetLanguage(unitpair)); +SymbolFileDWARF &SymbolFileDWARF::dwarf_from_comp_unit(CompileUnit *comp_unit) { + SymbolFile *symfile = comp_unit->GetModule()->GetSymbolFile(false/*can_create*/); + return *llvm::cast(symfile); } -DWARFASTParser *SymbolFileDWARF::GetDWARFParser(DWARFUnitPair unitpair) { - auto type_system_or_err = GetTypeSystem(unitpair); +llvm::Expected SymbolFileDWARF::GetTypeSystem(CompileUnit *comp_unit) { + return dwarf_from_comp_unit(comp_unit).GetTypeSystemForLanguage(GetLanguage(comp_unit)); +} + +DWARFASTParser *SymbolFileDWARF::GetDWARFParser(CompileUnit *comp_unit) { + auto type_system_or_err = GetTypeSystem(comp_unit); if (auto err = type_system_or_err.takeError()) { LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), std::move(err), "Unable to get DWARFASTParser"); @@ -3998,22 +4008,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(CompileUnit *comp_unit, const DWARFDIE &die) { + if (DWARFASTParser *dwarf_ast = GetDWARFParser(comp_unit)) + return dwarf_ast->GetDeclForUIDFromDWARF(comp_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(CompileUnit *comp_unit, const DWARFDIE &die) { + if (DWARFASTParser *dwarf_ast = GetDWARFParser(comp_unit)) + return dwarf_ast->GetDeclContextForUIDFromDWARF(comp_unit, die); return CompilerDeclContext(); } CompilerDeclContext -SymbolFileDWARF::GetContainingDeclContext(const DWARFDIE &die) { - if (DWARFASTParser *dwarf_ast = GetDWARFParser(die.GetCU())) - return dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); +SymbolFileDWARF::GetContainingDeclContext(CompileUnit *comp_unit, const DWARFDIE &die) { + if (DWARFASTParser *dwarf_ast = GetDWARFParser(comp_unit)) + return dwarf_ast->GetDeclContextContainingUIDFromDWARF(comp_unit, die); return CompilerDeclContext(); } @@ -4043,3 +4053,8 @@ LanguageType SymbolFileDWARF::GetLanguage(DWARFUnitPair unitpair) { return LanguageTypeFromDWARF(unitpair.GetDWARFLanguageType()); } + +LanguageType SymbolFileDWARF::GetLanguage(CompileUnit *comp_unit) { + DWARFCompileUnit &dwarf_cu = *dwarf_from_comp_unit(comp_unit).GetDWARFCompileUnit(comp_unit); + return LanguageTypeFromDWARF(dwarf_cu.GetDWARFLanguageType()); +} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h @@ -82,17 +82,17 @@ size_t ParseVariablesForContext(const lldb_private::SymbolContext &sc) override; - lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override; + lldb_private::Type *ResolveTypeUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t type_uid) override; llvm::Optional GetDynamicArrayInfoForUID( lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) override; lldb_private::CompilerDeclContext - GetDeclContextForUID(lldb::user_id_t uid) override; + GetDeclContextForUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) override; lldb_private::CompilerDeclContext - GetDeclContextContainingUID(lldb::user_id_t uid) override; + GetDeclContextContainingUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) override; void - ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override; + ParseDeclsForContext(lldb_private::CompileUnit *comp_unit, lldb_private::CompilerDeclContext decl_ctx) override; bool CompleteType(lldb_private::CompilerType &compiler_type) override; uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -718,12 +718,12 @@ return 0; } -Type *SymbolFileDWARFDebugMap::ResolveTypeUID(lldb::user_id_t type_uid) { +Type *SymbolFileDWARFDebugMap::ResolveTypeUID(CompileUnit *comp_unit, lldb::user_id_t type_uid) { std::lock_guard guard(GetModuleMutex()); const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid); SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx); if (oso_dwarf) - return oso_dwarf->ResolveTypeUID(type_uid); + return oso_dwarf->ResolveTypeUID(comp_unit, type_uid); return nullptr; } @@ -1292,27 +1292,27 @@ } CompilerDeclContext -SymbolFileDWARFDebugMap::GetDeclContextForUID(lldb::user_id_t type_uid) { +SymbolFileDWARFDebugMap::GetDeclContextForUID(CompileUnit *comp_unit, lldb::user_id_t type_uid) { const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid); SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx); if (oso_dwarf) - return oso_dwarf->GetDeclContextForUID(type_uid); + return oso_dwarf->GetDeclContextForUID(comp_unit,type_uid); return CompilerDeclContext(); } CompilerDeclContext -SymbolFileDWARFDebugMap::GetDeclContextContainingUID(lldb::user_id_t type_uid) { +SymbolFileDWARFDebugMap::GetDeclContextContainingUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t type_uid) { const uint64_t oso_idx = GetOSOIndexFromUserID(type_uid); SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx); if (oso_dwarf) - return oso_dwarf->GetDeclContextContainingUID(type_uid); + return oso_dwarf->GetDeclContextContainingUID(comp_unit, type_uid); return CompilerDeclContext(); } -void SymbolFileDWARFDebugMap::ParseDeclsForContext( +void SymbolFileDWARFDebugMap::ParseDeclsForContext(CompileUnit *comp_unit, lldb_private::CompilerDeclContext decl_ctx) { ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { - oso_dwarf->ParseDeclsForContext(decl_ctx); + oso_dwarf->ParseDeclsForContext(comp_unit, decl_ctx); return true; // Keep iterating }); } diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h @@ -78,7 +78,9 @@ // Compile Unit function calls void - ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override; + ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx); + void + ParseDeclsForContext(lldb_private::CompileUnit *comp_unit, lldb_private::CompilerDeclContext decl_ctx) override { ParseDeclsForContext(decl_ctx); } lldb::LanguageType ParseLanguage(lldb_private::CompileUnit &comp_unit) override; @@ -108,10 +110,15 @@ void AddSymbols(Symtab &symtab) override; - CompilerDecl GetDeclForUID(lldb::user_id_t uid) override; - CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override; - CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override; - Type *ResolveTypeUID(lldb::user_id_t type_uid) override; + CompilerDecl GetDeclForUID(lldb::user_id_t uid); + CompilerDecl GetDeclForUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) override { return GetDeclForUID(uid); } + CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid); + lldb_private::CompilerDeclContext + GetDeclContextForUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) override { return GetDeclContextForUID(uid); } + CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid); + CompilerDeclContext GetDeclContextContainingUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) override { return GetDeclContextContainingUID(uid); } + Type *ResolveTypeUID(lldb::user_id_t type_uid); + Type *ResolveTypeUID(CompileUnit *comp_unit, lldb::user_id_t type_uid) override { return ResolveTypeUID(type_uid); } llvm::Optional GetDynamicArrayInfoForUID( lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) override; diff --git a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp --- a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp +++ b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp @@ -367,7 +367,7 @@ if (!symbol_file) return nullptr; - auto ty = symbol_file->ResolveTypeUID(type.getRawSymbol().getTypeId()); + auto ty = symbol_file->ResolveTypeUID(nullptr/*FIXMEunused*/,type.getRawSymbol().getTypeId()); return ty ? ty->shared_from_this() : nullptr; } break; case PDB_SymType::UDT: { @@ -534,7 +534,7 @@ assert(type_def); lldb_private::Type *target_type = - m_ast.GetSymbolFile()->ResolveTypeUID(type_def->getTypeId()); + m_ast.GetSymbolFile()->ResolveTypeUID(nullptr/*FIXMEunused*/,type_def->getTypeId()); if (!target_type) return nullptr; @@ -609,7 +609,7 @@ if (!arg) break; lldb_private::Type *arg_type = - m_ast.GetSymbolFile()->ResolveTypeUID(arg->getSymIndexId()); + m_ast.GetSymbolFile()->ResolveTypeUID(nullptr/*FIXMEunused*/,arg->getSymIndexId()); // If there's some error looking up one of the dependent types of this // function signature, bail. if (!arg_type) @@ -621,7 +621,7 @@ auto pdb_return_type = func_sig->getReturnType(); lldb_private::Type *return_type = - m_ast.GetSymbolFile()->ResolveTypeUID(pdb_return_type->getSymIndexId()); + m_ast.GetSymbolFile()->ResolveTypeUID(nullptr/*FIXMEunused*/,pdb_return_type->getSymIndexId()); // If there's some error looking up one of the dependent types of this // function signature, bail. if (!return_type) @@ -656,7 +656,7 @@ // If array rank > 0, PDB gives the element type at N=0. So element type // will parsed in the order N=0, N=1,..., N=rank sequentially. lldb_private::Type *element_type = - m_ast.GetSymbolFile()->ResolveTypeUID(element_uid); + m_ast.GetSymbolFile()->ResolveTypeUID(nullptr/*FIXMEunused*/,element_uid); if (!element_type) return nullptr; @@ -710,7 +710,7 @@ case PDB_SymType::PointerType: { auto *pointer_type = llvm::dyn_cast(&type); assert(pointer_type); - Type *pointee_type = m_ast.GetSymbolFile()->ResolveTypeUID( + Type *pointee_type = m_ast.GetSymbolFile()->ResolveTypeUID(nullptr/*FIXMEunused*/, pointer_type->getPointeeType()->getSymIndexId()); if (!pointee_type) return nullptr; @@ -719,7 +719,7 @@ pointer_type->isPointerToMemberFunction()) { auto class_parent_uid = pointer_type->getRawSymbol().getClassParentId(); auto class_parent_type = - m_ast.GetSymbolFile()->ResolveTypeUID(class_parent_uid); + m_ast.GetSymbolFile()->ResolveTypeUID(nullptr/*FIXMEunused*/,class_parent_uid); assert(class_parent_type); CompilerType pointer_ast_type; @@ -1178,7 +1178,7 @@ auto nested_enums = udt.findAllChildren(); if (nested_enums) while (auto nested = nested_enums->getNext()) - symbol_file.ResolveTypeUID(nested->getSymIndexId()); + symbol_file.ResolveTypeUID(nullptr/*FIXMEunused*/,nested->getSymIndexId()); auto bases_enum = udt.findAllChildren(); if (bases_enum) @@ -1219,7 +1219,7 @@ auto member_name = member->getName(); - auto member_type = symbol_file.ResolveTypeUID(member->getTypeId()); + auto member_type = symbol_file.ResolveTypeUID(nullptr/*FIXMEunused*/,member->getTypeId()); if (!member_type) continue; @@ -1283,7 +1283,7 @@ std::vector> base_classes; while (auto base = bases_enum.getNext()) { - auto base_type = symbol_file.ResolveTypeUID(base->getTypeId()); + auto base_type = symbol_file.ResolveTypeUID(nullptr/*FIXMEunused*/,base->getTypeId()); if (!base_type) continue; @@ -1341,7 +1341,7 @@ std::string name = std::string(MSVCUndecoratedNameParser::DropScope(method.getName())); - Type *method_type = symbol_file.ResolveTypeUID(method.getSymIndexId()); + Type *method_type = symbol_file.ResolveTypeUID(nullptr/*FIXMEunused*/,method.getSymIndexId()); // MSVC specific __vecDelDtor. if (!method_type) return nullptr; diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h --- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h +++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h @@ -82,23 +82,31 @@ size_t ParseVariablesForContext(const lldb_private::SymbolContext &sc) override; - lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override; + lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid); + lldb_private::Type *ResolveTypeUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t type_uid) override { return ResolveTypeUID(type_uid); } llvm::Optional GetDynamicArrayInfoForUID( lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) override; bool CompleteType(lldb_private::CompilerType &compiler_type) override; - lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override; + lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid); + lldb_private::CompilerDecl GetDeclForUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) override { return GetDeclForUID(uid); } lldb_private::CompilerDeclContext - GetDeclContextForUID(lldb::user_id_t uid) override; + GetDeclContextForUID(lldb::user_id_t uid); + lldb_private::CompilerDeclContext + GetDeclContextForUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) override { return GetDeclContextForUID(uid); } lldb_private::CompilerDeclContext - GetDeclContextContainingUID(lldb::user_id_t uid) override; + GetDeclContextContainingUID(lldb::user_id_t uid); + lldb_private::CompilerDeclContext + GetDeclContextContainingUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t uid) override { return GetDeclContextContainingUID(uid); } void - ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override; + ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx); + void + ParseDeclsForContext(lldb_private::CompileUnit *comp_unit, lldb_private::CompilerDeclContext decl_ctx) override { ParseDeclsForContext(decl_ctx); } uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, lldb::SymbolContextItem resolve_scope, diff --git a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h --- a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h +++ b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h @@ -71,7 +71,8 @@ size_t ParseVariablesForContext(const lldb_private::SymbolContext &sc) override; - lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override; + lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid); + lldb_private::Type *ResolveTypeUID(lldb_private::CompileUnit *comp_unit, lldb::user_id_t type_uid) override { return ResolveTypeUID(type_uid); } llvm::Optional GetDynamicArrayInfoForUID( lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) override; diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -8955,7 +8955,7 @@ it++) { if (!searched.insert(it->second).second) continue; - symbol_file->ParseDeclsForContext( + symbol_file->ParseDeclsForContext(nullptr/*FIXMEDeclContext*/, CreateDeclContext(it->second)); for (clang::Decl *child : it->second->decls()) { @@ -9070,7 +9070,7 @@ continue; searched.insert(it->second); - symbol_file->ParseDeclsForContext( + symbol_file->ParseDeclsForContext(nullptr/*FIXMEDeclContext*/, CreateDeclContext(it->second)); for (clang::Decl *child : it->second->decls()) { diff --git a/lldb/source/Symbol/Block.cpp b/lldb/source/Symbol/Block.cpp --- a/lldb/source/Symbol/Block.cpp +++ b/lldb/source/Symbol/Block.cpp @@ -468,7 +468,7 @@ CompilerDeclContext Block::GetDeclContext() { if (SymbolFile *sym_file = GetSymbolFile()) - return sym_file->GetDeclContextForUID(GetID()); + return sym_file->GetDeclContextForUID(CalculateSymbolContextCompileUnit(),GetID()); return CompilerDeclContext(); } diff --git a/lldb/source/Symbol/Function.cpp b/lldb/source/Symbol/Function.cpp --- a/lldb/source/Symbol/Function.cpp +++ b/lldb/source/Symbol/Function.cpp @@ -489,7 +489,7 @@ if (module_sp) { if (SymbolFile *sym_file = module_sp->GetSymbolFile()) - return sym_file->GetDeclContextForUID(GetID()); + return sym_file->GetDeclContextForUID(CalculateSymbolContextCompileUnit(),GetID()); } return CompilerDeclContext(); } @@ -508,7 +508,7 @@ if (sym_file == nullptr) return nullptr; - m_type = sym_file->ResolveTypeUID(m_type_uid); + m_type = sym_file->ResolveTypeUID(sc.comp_unit, m_type_uid); } return m_type; } diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp --- a/lldb/source/Symbol/Type.cpp +++ b/lldb/source/Symbol/Type.cpp @@ -132,7 +132,7 @@ Type *SymbolFileType::GetType() { if (!m_type_sp) { - Type *resolved_type = m_symbol_file.ResolveTypeUID(GetID()); + Type *resolved_type = m_symbol_file.ResolveTypeUID(nullptr, GetID()); if (resolved_type) m_type_sp = resolved_type->shared_from_this(); } @@ -337,7 +337,7 @@ Type *Type::GetEncodingType() { if (m_encoding_type == nullptr && m_encoding_uid != LLDB_INVALID_UID) - m_encoding_type = m_symbol_file->ResolveTypeUID(m_encoding_uid); + m_encoding_type = m_symbol_file->ResolveTypeUID(m_context->CalculateSymbolContextCompileUnit(), m_encoding_uid); return m_encoding_type; } @@ -395,7 +395,7 @@ lldb::TypeSP Type::GetTypedefType() { lldb::TypeSP type_sp; if (IsTypedef()) { - Type *typedef_type = m_symbol_file->ResolveTypeUID(m_encoding_uid); + Type *typedef_type = m_symbol_file->ResolveTypeUID(m_context->CalculateSymbolContextCompileUnit(), m_encoding_uid); if (typedef_type) type_sp = typedef_type->shared_from_this(); } @@ -510,7 +510,7 @@ case eEncodingIsTypedefUID: m_compiler_type = encoding_type->GetForwardCompilerType().CreateTypedef( m_name.AsCString("__lldb_invalid_typedef_name"), - GetSymbolFile()->GetDeclContextContainingUID(GetID())); + GetSymbolFile()->GetDeclContextContainingUID(GetSymbolContextScope()->CalculateSymbolContextCompileUnit(), GetID())); m_name.Clear(); break; @@ -568,7 +568,7 @@ case eEncodingIsTypedefUID: m_compiler_type = void_compiler_type.CreateTypedef( m_name.AsCString("__lldb_invalid_typedef_name"), - GetSymbolFile()->GetDeclContextContainingUID(GetID())); + GetSymbolFile()->GetDeclContextContainingUID(GetSymbolContextScope()->CalculateSymbolContextCompileUnit(),GetID())); break; case eEncodingIsPointerUID: diff --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp --- a/lldb/source/Symbol/Variable.cpp +++ b/lldb/source/Symbol/Variable.cpp @@ -203,7 +203,7 @@ CompilerDeclContext Variable::GetDeclContext() { Type *type = GetType(); if (type) - return type->GetSymbolFile()->GetDeclContextContainingUID(GetID()); + return type->GetSymbolFile()->GetDeclContextContainingUID(GetSymbolContextScope()->CalculateSymbolContextCompileUnit(),GetID()); return CompilerDeclContext(); } @@ -212,7 +212,7 @@ return {}; // GetType()->GetSymbolFile() may be a different file - the file where type // of this variable is defined but not the file of this variable definition. - return m_symfile_type_sp->GetSymbolFile().GetDeclForUID(GetID()); + return m_symfile_type_sp->GetSymbolFile().GetDeclForUID(GetSymbolContextScope()->CalculateSymbolContextCompileUnit(),GetID()); } void Variable::CalculateSymbolContext(SymbolContext *sc) { 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 @@ -52,7 +52,7 @@ (clang::DeclContext *)2LL, (clang::DeclContext *)3LL}; for (int i = 0; i < 4; ++i) ast_parser.LinkDeclContextToDIE(decl_ctxs[i], dies[i]); - ast_parser.EnsureAllDIEsInDeclContextHaveBeenParsed( + ast_parser.EnsureAllDIEsInDeclContextHaveBeenParsed(nullptr/*FIXMEDeclContext*/, CompilerDeclContext(nullptr, decl_ctxs[1])); EXPECT_THAT(ast_parser.GetDeclContextToDIEMapKeys(),