diff --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h --- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.h @@ -11,53 +11,72 @@ #include "Plugins/SymbolFile/DWARF/DWARFIndex.h" #include "Plugins/SymbolFile/DWARF/HashedNameToDIE.h" +#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" +#include "lldb/Symbol/ObjectFile.h" namespace lldb_private { class AppleDWARFIndex : public DWARFIndex { public: static std::unique_ptr - Create(Module &module, DWARFDataExtractor apple_names, + Create(SymbolFileDWARF &dwarf, DWARFDataExtractor apple_names, DWARFDataExtractor apple_namespaces, DWARFDataExtractor apple_types, DWARFDataExtractor apple_objc, DWARFDataExtractor debug_str); AppleDWARFIndex( - Module &module, std::unique_ptr apple_names, + SymbolFileDWARF &dwarf, + std::unique_ptr apple_names, std::unique_ptr apple_namespaces, std::unique_ptr apple_types, std::unique_ptr apple_objc) - : DWARFIndex(module), m_apple_names_up(std::move(apple_names)), + : DWARFIndex(*dwarf.GetObjectFile()->GetModule()), + m_apple_names_up(std::move(apple_names)), m_apple_namespaces_up(std::move(apple_namespaces)), m_apple_types_up(std::move(apple_types)), m_apple_objc_up(std::move(apple_objc)) {} void Preload() override {} - void - GetGlobalVariables(ConstString basename, - llvm::function_ref callback) override; - void - GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref callback) override; - void - GetGlobalVariables(const DWARFUnit &cu, - llvm::function_ref callback) override; - void GetObjCMethods(ConstString class_name, - llvm::function_ref callback) override; + void GetGlobalVariables( + ConstString basename, + llvm::function_ref + callback) override; + void GetGlobalVariables( + const RegularExpression ®ex, + llvm::function_ref + callback) override; + void GetGlobalVariables( + const DWARFUnit &cu, + llvm::function_ref + callback) override; + void GetObjCMethods( + ConstString class_name, + llvm::function_ref + callback) override; void GetCompleteObjCClass( ConstString class_name, bool must_be_implementation, - llvm::function_ref callback) override; - void GetTypes(ConstString name, - llvm::function_ref callback) override; - void GetTypes(const DWARFDeclContext &context, - llvm::function_ref callback) override; - void GetNamespaces(ConstString name, - llvm::function_ref callback) override; - void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, - const CompilerDeclContext &parent_decl_ctx, - uint32_t name_type_mask, - llvm::function_ref callback) override; - void GetFunctions(const RegularExpression ®ex, - llvm::function_ref callback) override; + llvm::function_ref + callback) override; + void + GetTypes(ConstString name, + llvm::function_ref + callback) override; + void + GetTypes(const DWARFDeclContext &context, + llvm::function_ref + callback) override; + void GetNamespaces( + ConstString name, + llvm::function_ref + callback) override; + void GetFunctions( + ConstString name, SymbolFileDWARF &dwarf, + const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, + llvm::function_ref + callback) override; + void GetFunctions( + const RegularExpression ®ex, + llvm::function_ref + callback) override; void Dump(Stream &s) 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 @@ -18,7 +18,7 @@ using namespace lldb; std::unique_ptr AppleDWARFIndex::Create( - Module &module, DWARFDataExtractor apple_names, + SymbolFileDWARF &dwarf, DWARFDataExtractor apple_names, DWARFDataExtractor apple_namespaces, DWARFDataExtractor apple_types, DWARFDataExtractor apple_objc, DWARFDataExtractor debug_str) { auto apple_names_table_up = std::make_unique( @@ -45,7 +45,7 @@ if (apple_names_table_up || apple_names_table_up || apple_types_table_up || apple_objc_table_up) return std::make_unique( - module, std::move(apple_names_table_up), + dwarf, std::move(apple_names_table_up), std::move(apple_namespaces_table_up), std::move(apple_types_table_up), std::move(apple_objc_table_up)); @@ -53,7 +53,9 @@ } void AppleDWARFIndex::GetGlobalVariables( - ConstString basename, llvm::function_ref callback) { + ConstString basename, + llvm::function_ref + callback) { if (!m_apple_names_up) return; m_apple_names_up->FindByName( @@ -63,7 +65,8 @@ void AppleDWARFIndex::GetGlobalVariables( const RegularExpression ®ex, - llvm::function_ref callback) { + llvm::function_ref + callback) { if (!m_apple_names_up) return; @@ -75,7 +78,9 @@ } void AppleDWARFIndex::GetGlobalVariables( - const DWARFUnit &cu, llvm::function_ref callback) { + const DWARFUnit &cu, + llvm::function_ref + callback) { if (!m_apple_names_up) return; @@ -86,7 +91,9 @@ } void AppleDWARFIndex::GetObjCMethods( - ConstString class_name, llvm::function_ref callback) { + ConstString class_name, + llvm::function_ref + callback) { if (!m_apple_objc_up) return; m_apple_objc_up->FindByName( @@ -96,9 +103,12 @@ void AppleDWARFIndex::GetCompleteObjCClass( ConstString class_name, bool must_be_implementation, - llvm::function_ref callback) { + llvm::function_ref + callback) { if (!m_apple_types_up) return; + + DIEArray refs; m_apple_types_up->FindCompleteObjCClassByName( class_name.GetStringRef(), DIERefCallback(callback, class_name.GetStringRef()), @@ -106,7 +116,9 @@ } void AppleDWARFIndex::GetTypes( - ConstString name, llvm::function_ref callback) { + ConstString name, + llvm::function_ref + callback) { if (!m_apple_types_up) return; m_apple_types_up->FindByName(name.GetStringRef(), @@ -115,7 +127,8 @@ void AppleDWARFIndex::GetTypes( const DWARFDeclContext &context, - llvm::function_ref callback) { + llvm::function_ref + callback) { if (!m_apple_types_up) return; @@ -126,6 +139,7 @@ const bool has_qualified_name_hash = m_apple_types_up->GetHeader().header_data.ContainsAtom( DWARFMappedHash::eAtomTypeQualNameHash); + DIEArray refs; const ConstString type_name(context[0].name); const dw_tag_t tag = context[0].tag; @@ -169,7 +183,9 @@ } void AppleDWARFIndex::GetNamespaces( - ConstString name, llvm::function_ref callback) { + ConstString name, + llvm::function_ref + callback) { if (!m_apple_namespaces_up) return; m_apple_namespaces_up->FindByName( @@ -179,16 +195,19 @@ void AppleDWARFIndex::GetFunctions( ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - llvm::function_ref callback) { + llvm::function_ref + callback) { m_apple_names_up->FindByName(name.GetStringRef(), [&](DIERef die_ref) { - return ProcessFunctionDIE(name.GetStringRef(), die_ref, dwarf, - parent_decl_ctx, name_type_mask, callback); + return ProcessFunctionDIE(name.GetStringRef(), nullptr /* main_unit */, + die_ref, dwarf, parent_decl_ctx, name_type_mask, + callback); }); } void AppleDWARFIndex::GetFunctions( const RegularExpression ®ex, - llvm::function_ref callback) { + llvm::function_ref + callback) { if (!m_apple_names_up) return; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h b/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DIERef.h @@ -54,6 +54,15 @@ return m_die_offset < other.m_die_offset; } + bool operator==(DIERef other) const { + if (m_dwo_num_valid != other.m_dwo_num_valid || + m_section != other.m_section || m_die_offset != other.m_die_offset) + return false; + if (m_dwo_num_valid && m_dwo_num != other.m_dwo_num) + return false; + return true; + } + private: uint32_t m_dwo_num : 30; uint32_t m_dwo_num_valid : 1; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h @@ -21,6 +21,7 @@ class ExecutionContext; } class SymbolFileDWARF; +class DWARFCompileUnit; class DWARFASTParser { public: @@ -39,13 +40,15 @@ lldb_private::CompilerType &compiler_type) = 0; virtual lldb_private::CompilerDecl - GetDeclForUIDFromDWARF(const DWARFDIE &die) = 0; + GetDeclForUIDFromDWARF(DWARFCompileUnit *main_unit, const DWARFDIE &die) = 0; virtual lldb_private::CompilerDeclContext - GetDeclContextForUIDFromDWARF(const DWARFDIE &die) = 0; + GetDeclContextForUIDFromDWARF(DWARFCompileUnit *main_unit, + const DWARFDIE &die) = 0; virtual lldb_private::CompilerDeclContext - GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) = 0; + GetDeclContextContainingUIDFromDWARF(DWARFCompileUnit *main_unit, + const DWARFDIE &die) = 0; virtual void EnsureAllDIEsInDeclContextHaveBeenParsed( lldb_private::CompilerDeclContext decl_context) = 0; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h @@ -11,7 +11,7 @@ #include "clang/AST/CharUnits.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" #include "DWARFASTParser.h" @@ -54,16 +54,19 @@ lldb_private::CompilerType &compiler_type) override; lldb_private::CompilerDecl - GetDeclForUIDFromDWARF(const DWARFDIE &die) override; + GetDeclForUIDFromDWARF(DWARFCompileUnit *main_unit, + const DWARFDIE &die) override; void EnsureAllDIEsInDeclContextHaveBeenParsed( lldb_private::CompilerDeclContext decl_context) override; lldb_private::CompilerDeclContext - GetDeclContextForUIDFromDWARF(const DWARFDIE &die) override; + GetDeclContextForUIDFromDWARF(DWARFCompileUnit *main_unit, + const DWARFDIE &die) override; lldb_private::CompilerDeclContext - GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) override; + GetDeclContextContainingUIDFromDWARF(DWARFCompileUnit *main_unit, + const DWARFDIE &die) override; lldb_private::ClangASTImporter &GetClangASTImporter(); @@ -73,15 +76,22 @@ class DelayedAddObjCClassProperty; typedef std::vector DelayedPropertyList; - typedef llvm::SmallPtrSet DIEPointerSet; - typedef llvm::DenseMap + typedef llvm::SmallSet< + std::pair, 4> + DIEPointerSet; + typedef llvm::DenseMap< + std::pair, + clang::DeclContext *> DIEToDeclContextMap; - typedef std::multimap + typedef std::multimap> DeclContextToDIEMap; - typedef llvm::DenseMap + typedef llvm::DenseMap< + std::pair, + lldb_private::OptionalClangModuleID> DIEToModuleMap; - typedef llvm::DenseMap + typedef llvm::DenseMap< + std::pair, clang::Decl *> DIEToDeclMap; typedef llvm::DenseMap DeclToDIEMap; @@ -94,22 +104,26 @@ std::unique_ptr m_clang_ast_importer_up; /// @} - clang::DeclContext *GetDeclContextForBlock(const DWARFDIE &die); + clang::DeclContext *GetDeclContextForBlock(DWARFCompileUnit *main_unit, + const DWARFDIE &die); - clang::BlockDecl *ResolveBlockDIE(const DWARFDIE &die); + clang::BlockDecl *ResolveBlockDIE(DWARFCompileUnit *main_unit, + const DWARFDIE &die); - clang::NamespaceDecl *ResolveNamespaceDIE(const DWARFDIE &die); + clang::NamespaceDecl *ResolveNamespaceDIE(DWARFCompileUnit *main_unit, + const DWARFDIE &die); - bool ParseTemplateDIE(const DWARFDIE &die, + bool ParseTemplateDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die, lldb_private::TypeSystemClang::TemplateParameterInfos &template_param_infos); bool ParseTemplateParameterInfos( - const DWARFDIE &parent_die, + DWARFCompileUnit *main_unit, const DWARFDIE &parent_die, lldb_private::TypeSystemClang::TemplateParameterInfos &template_param_infos); bool ParseChildMembers( - const DWARFDIE &die, lldb_private::CompilerType &class_compiler_type, + lldb_private::CompileUnit *comp_unit, const DWARFDIE &die, + lldb_private::CompilerType &class_compiler_type, const lldb::LanguageType class_language, std::vector> &base_classes, std::vector &member_accessibilities, @@ -119,7 +133,8 @@ 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, @@ -136,24 +151,33 @@ const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs); - lldb_private::Type *GetTypeForDIE(const DWARFDIE &die); + lldb_private::Type *GetTypeForDIE(DWARFCompileUnit *main_unit, + const DWARFDIE &die); - clang::Decl *GetClangDeclForDIE(const DWARFDIE &die); + clang::Decl *GetClangDeclForDIE(DWARFCompileUnit *main_unit, + const DWARFDIE &die); - clang::DeclContext *GetClangDeclContextForDIE(const DWARFDIE &die); + clang::DeclContext *GetClangDeclContextForDIE(DWARFCompileUnit *main_unit, + const DWARFDIE &die); - clang::DeclContext *GetClangDeclContextContainingDIE(const DWARFDIE &die, - DWARFDIE *decl_ctx_die); - lldb_private::OptionalClangModuleID GetOwningClangModule(const DWARFDIE &die); + clang::DeclContext * + GetClangDeclContextContainingDIE(DWARFCompileUnit *main_unit, + const DWARFDIE &die, DWARFDIE *decl_ctx_die); + lldb_private::OptionalClangModuleID + GetOwningClangModule(DWARFCompileUnit *main_unit, const DWARFDIE &die); - bool CopyUniqueClassMethodTypes(const DWARFDIE &src_class_die, + bool CopyUniqueClassMethodTypes(DWARFCompileUnit *main_unit, + const DWARFDIE &src_class_die, const DWARFDIE &dst_class_die, lldb_private::Type *class_type, std::vector &failures); - clang::DeclContext *GetCachedClangDeclContextForDIE(const DWARFDIE &die); + clang::DeclContext * + GetCachedClangDeclContextForDIE(DWARFCompileUnit *main_unit, + const DWARFDIE &die); - void LinkDeclContextToDIE(clang::DeclContext *decl_ctx, const DWARFDIE &die); + void LinkDeclContextToDIE(clang::DeclContext *decl_ctx, + DWARFCompileUnit *main_unit, const DWARFDIE &die); void LinkDeclToDIE(clang::Decl *decl, const DWARFDIE &die); @@ -193,7 +217,8 @@ }; 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, @@ -212,12 +237,15 @@ ParsedDWARFTypeAttributes &attrs); lldb::TypeSP ParseEnum(const lldb_private::SymbolContext &sc, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs); - lldb::TypeSP ParseSubroutine(const DWARFDIE &die, + lldb::TypeSP ParseSubroutine(const lldb_private::SymbolContext &sc, + const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs); // FIXME: attrs should be passed as a const reference. - lldb::TypeSP ParseArrayType(const DWARFDIE &die, + lldb::TypeSP ParseArrayType(const lldb_private::SymbolContext &sc, + const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs); - lldb::TypeSP ParsePointerToMemberType(const DWARFDIE &die, + lldb::TypeSP ParsePointerToMemberType(const lldb_private::SymbolContext &sc, + const DWARFDIE &die, const ParsedDWARFTypeAttributes &attrs); }; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -9,12 +9,13 @@ #include #include "DWARFASTParserClang.h" +#include "DWARFCompileUnit.h" #include "DWARFDebugInfo.h" #include "DWARFDeclContext.h" #include "DWARFDefines.h" #include "SymbolFileDWARF.h" -#include "SymbolFileDWARFDwo.h" #include "SymbolFileDWARFDebugMap.h" +#include "SymbolFileDWARFDwo.h" #include "UniqueDWARFASTType.h" #include "Plugins/ExpressionParser/Clang/ClangASTImporter.h" @@ -208,22 +209,26 @@ if (pcm_type.IsDefined()) GetClangASTImporter().RequireCompleteType(ClangUtil::GetQualType(type)); - SymbolFileDWARF *dwarf = die.GetDWARF(); - TypeSP type_sp(new Type( - die.GetID(), dwarf, pcm_type_sp->GetName(), pcm_type_sp->GetByteSize(), - nullptr, LLDB_INVALID_UID, Type::eEncodingInvalid, - &pcm_type_sp->GetDeclaration(), type, Type::ResolveState::Forward, - TypePayloadClang(GetOwningClangModule(die)))); + SymbolFileDWARF *dwarf = + llvm::cast(sc.module_sp->GetSymbolFile()); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); + TypeSP type_sp( + new Type(die.GetID(main_unit), dwarf, pcm_type_sp->GetName(), + pcm_type_sp->GetByteSize(), sc.comp_unit, LLDB_INVALID_UID, + Type::eEncodingInvalid, &pcm_type_sp->GetDeclaration(), type, + Type::ResolveState::Forward, + TypePayloadClang(GetOwningClangModule(main_unit, die)))); dwarf->GetTypeList().Insert(type_sp); - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); clang::TagDecl *tag_decl = TypeSystemClang::GetAsTagDecl(type); if (tag_decl) { - LinkDeclContextToDIE(tag_decl, die); + LinkDeclContextToDIE(tag_decl, main_unit, die); } else { - clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE(die); + clang::DeclContext *defn_decl_ctx = + GetCachedClangDeclContextForDIE(main_unit, die); if (defn_decl_ctx) - LinkDeclContextToDIE(defn_decl_ctx, die); + LinkDeclContextToDIE(defn_decl_ctx, main_unit, die); } return type_sp; @@ -401,11 +406,13 @@ Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION | DWARF_LOG_LOOKUPS)); - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = + llvm::cast(sc.module_sp->GetSymbolFile()); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); if (log) { DWARFDIE context_die; clang::DeclContext *context = - GetClangDeclContextContainingDIE(die, &context_die); + GetClangDeclContextContainingDIE(main_unit, die, &context_die); dwarf->GetObjectFile()->GetModule()->LogMessage( log, @@ -415,23 +422,23 @@ die.GetTagAsCString(), die.GetName()); } - Type *type_ptr = dwarf->GetDIEToType().lookup(die.GetDIE()); + Type *type_ptr = dwarf->GetDIEToType().lookup(die.MainCUtoDIEPair(main_unit)); if (type_ptr == DIE_IS_BEING_PARSED) return nullptr; if (type_ptr) return type_ptr->shared_from_this(); // Set a bit that lets us know that we are currently parsing this - dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED; + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = DIE_IS_BEING_PARSED; ParsedDWARFTypeAttributes attrs(die); if (DWARFDIE signature_die = attrs.signature.Reference()) { if (TypeSP type_sp = ParseTypeFromDWARF(sc, signature_die, type_is_new_ptr)) { - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); if (clang::DeclContext *decl_ctx = - GetCachedClangDeclContextForDIE(signature_die)) - LinkDeclContextToDIE(decl_ctx, die); + GetCachedClangDeclContextForDIE(main_unit, signature_die)) + LinkDeclContextToDIE(decl_ctx, main_unit, die); return type_sp; } return nullptr; @@ -474,15 +481,15 @@ case DW_TAG_inlined_subroutine: case DW_TAG_subprogram: case DW_TAG_subroutine_type: { - type_sp = ParseSubroutine(die, attrs); + type_sp = ParseSubroutine(sc, die, attrs); break; } case DW_TAG_array_type: { - type_sp = ParseArrayType(die, attrs); + type_sp = ParseArrayType(sc, die, attrs); break; } case DW_TAG_ptr_to_member_type: { - type_sp = ParsePointerToMemberType(die, attrs); + type_sp = ParsePointerToMemberType(sc, die, attrs); break; } default: @@ -505,9 +512,12 @@ ParsedDWARFTypeAttributes &attrs) { Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION | DWARF_LOG_LOOKUPS)); - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = + llvm::cast(sc.module_sp->GetSymbolFile()); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); const dw_tag_t tag = die.Tag(); - LanguageType cu_language = SymbolFileDWARF::GetLanguage(*die.GetCU()); + LanguageType cu_language = + SymbolFileDWARF::GetLanguage(*die.MainDWARFUnit(main_unit)); Type::ResolveState resolve_state = Type::ResolveState::Unresolved; Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; TypeSP type_sp; @@ -707,11 +717,12 @@ } type_sp = std::make_shared( - die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr, - dwarf->GetUID(attrs.type.Reference()), encoding_data_type, &attrs.decl, - clang_type, resolve_state, TypePayloadClang(GetOwningClangModule(die))); + die.GetID(main_unit), dwarf, attrs.name, attrs.byte_size, sc.comp_unit, + dwarf->GetUID(main_unit, attrs.type.Reference()), encoding_data_type, + &attrs.decl, clang_type, resolve_state, + TypePayloadClang(GetOwningClangModule(main_unit, die))); - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); return type_sp; } @@ -720,10 +731,12 @@ ParsedDWARFTypeAttributes &attrs) { Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION | DWARF_LOG_LOOKUPS)); - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = + llvm::cast(sc.module_sp->GetSymbolFile()); const dw_tag_t tag = die.Tag(); TypeSP type_sp; + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); if (attrs.is_forward_declaration) { type_sp = ParseTypeFromClangModule(sc, die, log); if (type_sp) @@ -757,11 +770,11 @@ // We found a real definition for this type elsewhere so lets use // it and cache the fact that we found a complete type for this // die - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); - clang::DeclContext *defn_decl_ctx = - GetCachedClangDeclContextForDIE(dwarf->GetDIE(type_sp->GetID())); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); + clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE( + main_unit, dwarf->GetDIE(type_sp->GetID())); if (defn_decl_ctx) - LinkDeclContextToDIE(defn_decl_ctx, die); + LinkDeclContextToDIE(defn_decl_ctx, main_unit, die); return type_sp; } } @@ -770,12 +783,13 @@ CompilerType enumerator_clang_type; CompilerType clang_type; - clang_type.SetCompilerType( - &m_ast, dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE())); + clang_type.SetCompilerType(&m_ast, + dwarf->GetForwardDeclDieToClangType().lookup( + die.MainCUtoDIEPair(main_unit))); if (!clang_type) { if (attrs.type.IsValid()) { Type *enumerator_type = - dwarf->ResolveTypeUID(attrs.type.Reference(), true); + dwarf->ResolveTypeUID(main_unit, attrs.type.Reference(), true); if (enumerator_type) enumerator_clang_type = enumerator_type->GetFullCompilerType(); } @@ -790,20 +804,22 @@ } clang_type = m_ast.CreateEnumerationType( - attrs.name.GetCString(), GetClangDeclContextContainingDIE(die, nullptr), - GetOwningClangModule(die), attrs.decl, enumerator_clang_type, + attrs.name.GetCString(), + GetClangDeclContextContainingDIE(main_unit, die, nullptr), + GetOwningClangModule(main_unit, die), attrs.decl, enumerator_clang_type, attrs.is_scoped_enum); } else { enumerator_clang_type = m_ast.GetEnumerationIntegerType(clang_type); } - LinkDeclContextToDIE(TypeSystemClang::GetDeclContextForType(clang_type), die); + LinkDeclContextToDIE(TypeSystemClang::GetDeclContextForType(clang_type), + main_unit, die); type_sp = std::make_shared( - die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr, - dwarf->GetUID(attrs.type.Reference()), Type::eEncodingIsUID, &attrs.decl, - clang_type, Type::ResolveState::Forward, - TypePayloadClang(GetOwningClangModule(die))); + die.GetID(main_unit), dwarf, attrs.name, attrs.byte_size, sc.comp_unit, + dwarf->GetUID(main_unit, attrs.type.Reference()), Type::eEncodingIsUID, + &attrs.decl, clang_type, Type::ResolveState::Forward, + TypePayloadClang(GetOwningClangModule(main_unit, die))); if (TypeSystemClang::StartTagDeclarationDefinition(clang_type)) { if (die.HasChildren()) { @@ -823,12 +839,15 @@ return type_sp; } -TypeSP DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die, - ParsedDWARFTypeAttributes &attrs) { +TypeSP DWARFASTParserClang::ParseSubroutine(const SymbolContext &sc, + const DWARFDIE &die, + ParsedDWARFTypeAttributes &attrs) { Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION | DWARF_LOG_LOOKUPS)); - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = + llvm::cast(sc.module_sp->GetSymbolFile()); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); const dw_tag_t tag = die.Tag(); bool is_variadic = false; @@ -851,7 +870,7 @@ Type *func_type = NULL; if (attrs.type.IsValid()) - func_type = dwarf->ResolveTypeUID(attrs.type.Reference(), true); + func_type = dwarf->ResolveTypeUID(main_unit, attrs.type.Reference(), true); if (func_type) return_clang_type = func_type->GetForwardCompilerType(); @@ -865,7 +884,7 @@ DWARFDIE decl_ctx_die; clang::DeclContext *containing_decl_ctx = - GetClangDeclContextContainingDIE(die, &decl_ctx_die); + GetClangDeclContextContainingDIE(main_unit, die, &decl_ctx_die); const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind(); @@ -879,10 +898,10 @@ if (die.HasChildren()) { bool skip_artificial = true; - ParseChildParameters(containing_decl_ctx, die, skip_artificial, is_static, - is_variadic, has_template_params, - function_param_types, function_param_decls, - type_quals); + ParseChildParameters(sc.comp_unit, containing_decl_ctx, die, + skip_artificial, is_static, is_variadic, + has_template_params, function_param_types, + function_param_decls, type_quals); } bool ignore_containing_context = false; @@ -941,8 +960,8 @@ attrs.is_objc_direct_call); type_handled = objc_method_decl != NULL; if (type_handled) { - LinkDeclContextToDIE(objc_method_decl, die); - m_ast.SetMetadataAsUserID(objc_method_decl, die.GetID()); + LinkDeclContextToDIE(objc_method_decl, main_unit, die); + m_ast.SetMetadataAsUserID(objc_method_decl, die.GetID(main_unit)); } else { dwarf->GetObjectFile()->GetModule()->ReportError( "{0x%8.8x}: invalid Objective-C method 0x%4.4x (%s), " @@ -954,10 +973,10 @@ } else if (is_cxx_method) { // Look at the parent of this DIE and see if is is a class or // struct and see if this is actually a C++ method - Type *class_type = dwarf->ResolveType(decl_ctx_die); + Type *class_type = dwarf->ResolveType(main_unit, decl_ctx_die); if (class_type) { bool alternate_defn = false; - if (class_type->GetID() != decl_ctx_die.GetID() || + if (class_type->GetID() != decl_ctx_die.GetID(main_unit) || IsClangModuleFwdDecl(decl_ctx_die)) { alternate_defn = true; @@ -969,15 +988,16 @@ if (class_type_die) { std::vector failures; - CopyUniqueClassMethodTypes(decl_ctx_die, class_type_die, - class_type, failures); + CopyUniqueClassMethodTypes(main_unit, decl_ctx_die, + class_type_die, class_type, failures); // FIXME do something with these failures that's // smarter than just dropping them on the ground. // Unfortunately classes don't like having stuff added // to them after their definitions are complete... - Type *type_ptr = dwarf->GetDIEToType()[die.GetDIE()]; + Type *type_ptr = + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)]; if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) { return type_ptr->shared_from_this(); } @@ -995,14 +1015,14 @@ // die. DWARFDIE spec_die = attrs.specification.Reference(); clang::DeclContext *spec_clang_decl_ctx = - GetClangDeclContextForDIE(spec_die); + GetClangDeclContextForDIE(main_unit, spec_die); if (spec_clang_decl_ctx) { - LinkDeclContextToDIE(spec_clang_decl_ctx, die); + LinkDeclContextToDIE(spec_clang_decl_ctx, main_unit, die); } else { dwarf->GetObjectFile()->GetModule()->ReportWarning( "0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x" ") has no decl\n", - die.GetID(), spec_die.GetOffset()); + die.GetID(main_unit), spec_die.GetOffset()); } type_handled = true; } else if (attrs.abstract_origin.IsValid()) { @@ -1014,14 +1034,14 @@ DWARFDIE abs_die = attrs.abstract_origin.Reference(); clang::DeclContext *abs_clang_decl_ctx = - GetClangDeclContextForDIE(abs_die); + GetClangDeclContextForDIE(main_unit, abs_die); if (abs_clang_decl_ctx) { - LinkDeclContextToDIE(abs_clang_decl_ctx, die); + LinkDeclContextToDIE(abs_clang_decl_ctx, main_unit, die); } else { dwarf->GetObjectFile()->GetModule()->ReportWarning( "0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8x" ") has no decl\n", - die.GetID(), abs_die.GetOffset()); + die.GetID(main_unit), abs_die.GetOffset()); } type_handled = true; } else { @@ -1054,7 +1074,7 @@ if (method_decl->getType() == ClangUtil::GetQualType(clang_type)) { add_method = false; - LinkDeclContextToDIE(method_decl, die); + LinkDeclContextToDIE(method_decl, main_unit, die); type_handled = true; break; @@ -1069,7 +1089,8 @@ "SymbolFileDWARF::ParseType() is adding a method " "%s to class %s in DIE 0x%8.8" PRIx64 " from %s", attrs.name.GetCString(), - class_type->GetName().GetCString(), die.GetID(), + class_type->GetName().GetCString(), + die.GetID(main_unit), dwarf->GetObjectFile() ->GetFileSpec() .GetPath() @@ -1096,10 +1117,10 @@ type_handled |= attrs.is_artificial; if (cxx_method_decl) { - LinkDeclContextToDIE(cxx_method_decl, die); + LinkDeclContextToDIE(cxx_method_decl, main_unit, die); ClangASTMetadata metadata; - metadata.SetUserID(die.GetID()); + metadata.SetUserID(die.GetID(main_unit)); if (!object_pointer_name.empty()) { metadata.SetObjectPtrName( @@ -1127,7 +1148,7 @@ // we need to modify the dwarf->GetDIEToType() so it // doesn't think we are trying to parse this DIE // anymore... - dwarf->GetDIEToType()[die.GetDIE()] = NULL; + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = NULL; // Now we get the full type to force our class type to // complete itself using the clang::ExternalASTSource @@ -1137,7 +1158,8 @@ // The type for this DIE should have been filled in the // function call above - Type *type_ptr = dwarf->GetDIEToType()[die.GetDIE()]; + Type *type_ptr = + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)]; if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) { return type_ptr->shared_from_this(); } @@ -1161,12 +1183,12 @@ if (attrs.abstract_origin.IsValid()) { DWARFDIE abs_die = attrs.abstract_origin.Reference(); - if (dwarf->ResolveType(abs_die)) { + if (dwarf->ResolveType(main_unit, abs_die)) { function_decl = llvm::dyn_cast_or_null( - GetCachedClangDeclContextForDIE(abs_die)); + GetCachedClangDeclContextForDIE(main_unit, abs_die)); if (function_decl) { - LinkDeclContextToDIE(function_decl, die); + LinkDeclContextToDIE(function_decl, main_unit, die); } } } @@ -1187,20 +1209,20 @@ function_decl = m_ast.CreateFunctionDeclaration( ignore_containing_context ? m_ast.GetTranslationUnitDecl() : containing_decl_ctx, - GetOwningClangModule(die), name, clang_type, attrs.storage, - attrs.is_inline); + GetOwningClangModule(main_unit, die), name, clang_type, + attrs.storage, attrs.is_inline); if (has_template_params) { TypeSystemClang::TemplateParameterInfos template_param_infos; - ParseTemplateParameterInfos(die, template_param_infos); + ParseTemplateParameterInfos(main_unit, die, template_param_infos); template_function_decl = m_ast.CreateFunctionDeclaration( ignore_containing_context ? m_ast.GetTranslationUnitDecl() : containing_decl_ctx, - GetOwningClangModule(die), attrs.name.GetCString(), clang_type, - attrs.storage, attrs.is_inline); + GetOwningClangModule(main_unit, die), attrs.name.GetCString(), + clang_type, attrs.storage, attrs.is_inline); clang::FunctionTemplateDecl *func_template_decl = m_ast.CreateFunctionTemplateDecl( - containing_decl_ctx, GetOwningClangModule(die), + containing_decl_ctx, GetOwningClangModule(main_unit, die), template_function_decl, name, template_param_infos); m_ast.CreateFunctionTemplateSpecializationInfo( template_function_decl, func_template_decl, template_param_infos); @@ -1209,7 +1231,7 @@ lldbassert(function_decl); if (function_decl) { - LinkDeclContextToDIE(function_decl, die); + LinkDeclContextToDIE(function_decl, main_unit, die); if (!function_param_decls.empty()) { m_ast.SetFunctionParameters(function_decl, @@ -1222,7 +1244,7 @@ } ClangASTMetadata metadata; - metadata.SetUserID(die.GetID()); + metadata.SetUserID(die.GetID(main_unit)); if (!object_pointer_name.empty()) { metadata.SetObjectPtrName(object_pointer_name.c_str()); @@ -1237,20 +1259,24 @@ } } } - return std::make_shared( - die.GetID(), dwarf, attrs.name, llvm::None, nullptr, LLDB_INVALID_UID, - Type::eEncodingIsUID, &attrs.decl, clang_type, Type::ResolveState::Full); + return std::make_shared(die.GetID(main_unit), dwarf, attrs.name, + llvm::None, sc.comp_unit, LLDB_INVALID_UID, + Type::eEncodingIsUID, &attrs.decl, clang_type, + Type::ResolveState::Full); } -TypeSP DWARFASTParserClang::ParseArrayType(const DWARFDIE &die, +TypeSP DWARFASTParserClang::ParseArrayType(const SymbolContext &sc, + const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs) { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = + llvm::cast(sc.module_sp->GetSymbolFile()); DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); DWARFDIE type_die = attrs.type.Reference(); - Type *element_type = dwarf->ResolveTypeUID(type_die, true); + Type *element_type = dwarf->ResolveTypeUID(main_unit, type_die, true); if (!element_type) return nullptr; @@ -1323,21 +1349,25 @@ } ConstString empty_name; TypeSP type_sp = std::make_shared( - die.GetID(), dwarf, empty_name, array_element_bit_stride / 8, nullptr, - dwarf->GetUID(type_die), Type::eEncodingIsUID, &attrs.decl, clang_type, - Type::ResolveState::Full); + die.GetID(main_unit), dwarf, empty_name, array_element_bit_stride / 8, + sc.comp_unit, dwarf->GetUID(main_unit, type_die), Type::eEncodingIsUID, + &attrs.decl, clang_type, Type::ResolveState::Full); type_sp->SetEncodingType(element_type); const clang::Type *type = ClangUtil::GetQualType(clang_type).getTypePtr(); - m_ast.SetMetadataAsUserID(type, die.GetID()); + m_ast.SetMetadataAsUserID(type, die.GetID(main_unit)); return type_sp; } TypeSP DWARFASTParserClang::ParsePointerToMemberType( - const DWARFDIE &die, const ParsedDWARFTypeAttributes &attrs) { - SymbolFileDWARF *dwarf = die.GetDWARF(); - Type *pointee_type = dwarf->ResolveTypeUID(attrs.type.Reference(), true); + const SymbolContext &sc, const DWARFDIE &die, + const ParsedDWARFTypeAttributes &attrs) { + SymbolFileDWARF *dwarf = + llvm::cast(sc.module_sp->GetSymbolFile()); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); + Type *pointee_type = + dwarf->ResolveTypeUID(main_unit, attrs.type.Reference(), true); Type *class_type = - dwarf->ResolveTypeUID(attrs.containing_type.Reference(), true); + dwarf->ResolveTypeUID(main_unit, attrs.containing_type.Reference(), true); CompilerType pointee_clang_type = pointee_type->GetForwardCompilerType(); CompilerType class_clang_type = class_type->GetLayoutCompilerType(); @@ -1346,12 +1376,11 @@ class_clang_type, pointee_clang_type); if (llvm::Optional clang_type_size = - clang_type.GetByteSize(nullptr)) { - return std::make_shared(die.GetID(), dwarf, attrs.name, - *clang_type_size, nullptr, LLDB_INVALID_UID, - Type::eEncodingIsUID, nullptr, clang_type, - Type::ResolveState::Forward); - } + clang_type.GetByteSize(nullptr)) + return std::make_shared( + die.GetID(main_unit), dwarf, attrs.name, *clang_type_size, sc.comp_unit, + LLDB_INVALID_UID, Type::eEncodingIsUID, nullptr, clang_type, + Type::ResolveState::Forward); return nullptr; } @@ -1360,23 +1389,26 @@ if (!type_sp) return type_sp; - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = + llvm::cast(sc.module_sp->GetSymbolFile()); TypeList &type_list = dwarf->GetTypeList(); DWARFDIE sc_parent_die = SymbolFileDWARF::GetParentSymbolContextDIE(die); dw_tag_t sc_parent_tag = sc_parent_die.Tag(); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); SymbolContextScope *symbol_context_scope = nullptr; if (sc_parent_tag == DW_TAG_compile_unit || sc_parent_tag == DW_TAG_partial_unit) { symbol_context_scope = sc.comp_unit; } else if (sc.function != nullptr && sc_parent_die) { - symbol_context_scope = - sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID()); + symbol_context_scope = sc.function->GetBlock(true).FindBlockByID( + sc_parent_die.GetID(main_unit)); if (symbol_context_scope == nullptr) symbol_context_scope = sc.function; } else { symbol_context_scope = sc.module_sp.get(); } + lldbassert(symbol_context_scope); if (symbol_context_scope != nullptr) type_sp->SetSymbolContextScope(symbol_context_scope); @@ -1385,7 +1417,7 @@ // level. type_list.Insert(type_sp); - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); return type_sp; } @@ -1396,7 +1428,8 @@ TypeSP type_sp; CompilerType clang_type; const dw_tag_t tag = die.Tag(); - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = + llvm::cast(sc.module_sp->GetSymbolFile()); LanguageType cu_language = SymbolFileDWARF::GetLanguage(*die.GetCU()); Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_TYPE_COMPLETION | DWARF_LOG_LOOKUPS); @@ -1426,9 +1459,11 @@ *unique_ast_entry_up)) { type_sp = unique_ast_entry_up->m_type_sp; if (type_sp) { - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); - LinkDeclContextToDIE( - GetCachedClangDeclContextForDIE(unique_ast_entry_up->m_die), die); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); + LinkDeclContextToDIE(GetCachedClangDeclContextForDIE( + main_unit, unique_ast_entry_up->m_die), + main_unit, die); return type_sp; } } @@ -1465,6 +1500,8 @@ attrs.is_forward_declaration = true; } + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(sc.comp_unit); + if (attrs.class_language == eLanguageTypeObjC || attrs.class_language == eLanguageTypeObjC_plus_plus) { if (!attrs.is_complete_objc_class && @@ -1502,7 +1539,7 @@ // We found a real definition for this type elsewhere so lets use // it and cache the fact that we found a complete type for this // die - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); return type_sp; } } @@ -1558,21 +1595,24 @@ // We found a real definition for this type elsewhere so lets use // it and cache the fact that we found a complete type for this die - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); + dwarf->GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = type_sp.get(); + DWARFCompileUnit *main_unit; + DWARFDIE die = dwarf->GetDIEUnlocked(type_sp->GetID(), &main_unit); clang::DeclContext *defn_decl_ctx = - GetCachedClangDeclContextForDIE(dwarf->GetDIE(type_sp->GetID())); + GetCachedClangDeclContextForDIE(main_unit, die); if (defn_decl_ctx) - LinkDeclContextToDIE(defn_decl_ctx, die); + LinkDeclContextToDIE(defn_decl_ctx, main_unit, die); return type_sp; } } assert(tag_decl_kind != -1); bool clang_type_was_created = false; - clang_type.SetCompilerType( - &m_ast, dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE())); + clang_type.SetCompilerType(&m_ast, + dwarf->GetForwardDeclDieToClangType().lookup( + die.MainCUtoDIEPair(main_unit))); if (!clang_type) { clang::DeclContext *decl_ctx = - GetClangDeclContextContainingDIE(die, nullptr); + GetClangDeclContextContainingDIE(main_unit, die, nullptr); // If your decl context is a record that was imported from another // AST context (in the gmodules case), we need to make sure the type @@ -1591,16 +1631,17 @@ } ClangASTMetadata metadata; - metadata.SetUserID(die.GetID()); + metadata.SetUserID(die.GetID(main_unit)); metadata.SetIsDynamicCXXType(dwarf->ClassOrStructIsVirtual(die)); if (attrs.name.GetStringRef().contains('<')) { TypeSystemClang::TemplateParameterInfos template_param_infos; - if (ParseTemplateParameterInfos(die, template_param_infos)) { + if (ParseTemplateParameterInfos(main_unit, die, template_param_infos)) { clang::ClassTemplateDecl *class_template_decl = m_ast.ParseClassTemplateDecl( - decl_ctx, GetOwningClangModule(die), attrs.accessibility, - attrs.name.GetCString(), tag_decl_kind, template_param_infos); + decl_ctx, GetOwningClangModule(main_unit, die), + attrs.accessibility, attrs.name.GetCString(), tag_decl_kind, + template_param_infos); if (!class_template_decl) { if (log) { dwarf->GetObjectFile()->GetModule()->LogMessage( @@ -1615,8 +1656,8 @@ clang::ClassTemplateSpecializationDecl *class_specialization_decl = m_ast.CreateClassTemplateSpecializationDecl( - decl_ctx, GetOwningClangModule(die), class_template_decl, - tag_decl_kind, template_param_infos); + decl_ctx, GetOwningClangModule(main_unit, die), + class_template_decl, tag_decl_kind, template_param_infos); clang_type = m_ast.CreateClassTemplateSpecializationType( class_specialization_decl); clang_type_was_created = true; @@ -1629,7 +1670,7 @@ if (!clang_type_was_created) { clang_type_was_created = true; clang_type = m_ast.CreateRecordType( - decl_ctx, GetOwningClangModule(die), attrs.accessibility, + decl_ctx, GetOwningClangModule(main_unit, die), attrs.accessibility, attrs.name.GetCString(), tag_decl_kind, attrs.class_language, &metadata, attrs.exports_symbols); } @@ -1638,9 +1679,9 @@ // Store a forward declaration to this class type in case any // parameters in any class methods need it for the clang types for // function prototypes. - LinkDeclContextToDIE(m_ast.GetDeclContextForType(clang_type), die); + LinkDeclContextToDIE(m_ast.GetDeclContextForType(clang_type), main_unit, die); type_sp = std::make_shared( - die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr, + die.GetID(main_unit), dwarf, attrs.name, attrs.byte_size, sc.comp_unit, LLDB_INVALID_UID, Type::eEncodingIsUID, &attrs.decl, clang_type, Type::ResolveState::Forward, TypePayloadClang(OptionalClangModuleID(), attrs.is_complete_objc_class)); @@ -1734,11 +1775,11 @@ // Can't assume m_ast.GetSymbolFile() is actually a // SymbolFileDWARF, it can be a SymbolFileDWARFDebugMap for Apple // binaries. - dwarf->GetForwardDeclDieToClangType()[die.GetDIE()] = + dwarf->GetForwardDeclDieToClangType()[die.MainCUtoDIEPair(main_unit)] = clang_type.GetOpaqueQualType(); dwarf->GetForwardDeclClangTypeToDie().try_emplace( ClangUtil::RemoveFastQualifiers(clang_type).GetOpaqueQualType(), - *die.GetDIERef()); + die.GetID(main_unit)); m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true); } } @@ -1828,7 +1869,7 @@ }; bool DWARFASTParserClang::ParseTemplateDIE( - const DWARFDIE &die, + DWARFCompileUnit *main_unit, const DWARFDIE &die, TypeSystemClang::TemplateParameterInfos &template_param_infos) { const dw_tag_t tag = die.Tag(); bool is_template_template_argument = false; @@ -1839,7 +1880,8 @@ new TypeSystemClang::TemplateParameterInfos); for (DWARFDIE child_die = die.GetFirstChild(); child_die.IsValid(); child_die = child_die.GetSibling()) { - if (!ParseTemplateDIE(child_die, *template_param_infos.packed_args)) + if (!ParseTemplateDIE(main_unit, child_die, + *template_param_infos.packed_args)) return false; } if (const char *name = die.GetName()) { @@ -1877,7 +1919,8 @@ case DW_AT_type: if (attributes.ExtractFormValueAtIndex(i, form_value)) { - Type *lldb_type = die.ResolveTypeUID(form_value.Reference()); + Type *lldb_type = + die.ResolveTypeUID(main_unit, form_value.Reference()); if (lldb_type) clang_type = lldb_type->GetForwardCompilerType(); } @@ -1937,7 +1980,7 @@ } bool DWARFASTParserClang::ParseTemplateParameterInfos( - const DWARFDIE &parent_die, + DWARFCompileUnit *main_unit, const DWARFDIE &parent_die, TypeSystemClang::TemplateParameterInfos &template_param_infos) { if (!parent_die) @@ -1952,7 +1995,7 @@ case DW_TAG_template_value_parameter: case DW_TAG_GNU_template_parameter_pack: case DW_TAG_GNU_template_template_param: - ParseTemplateDIE(die, template_param_infos); + ParseTemplateDIE(main_unit, die, template_param_infos); break; default: @@ -1968,7 +2011,12 @@ lldb_private::Type *type, CompilerType &clang_type) { const dw_tag_t tag = die.Tag(); - SymbolFileDWARF *dwarf = die.GetDWARF(); + CompileUnit *comp_unit = + type->GetSymbolContextScope()->CalculateSymbolContextCompileUnit(); + SymbolFileDWARF *dwarf = + llvm::cast(type->GetSymbolContextScope() + ->CalculateSymbolContextModule() + ->GetSymbolFile()); ClangASTImporter::LayoutInfo layout_info; @@ -1999,24 +2047,26 @@ bool is_a_class = false; // Parse members and base classes first std::vector member_function_dies; + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(comp_unit); DelayedPropertyList delayed_properties; - ParseChildMembers(die, clang_type, class_language, bases, + ParseChildMembers(comp_unit, die, clang_type, class_language, bases, member_accessibilities, member_function_dies, delayed_properties, default_accessibility, is_a_class, layout_info); // Now parse any methods if there were any... for (const DWARFDIE &die : member_function_dies) - dwarf->ResolveType(die); + dwarf->ResolveType(main_unit, die); if (class_language == eLanguageTypeObjC) { ConstString class_name(clang_type.GetTypeName()); if (class_name) { - dwarf->GetObjCMethods(class_name, [&](DWARFDIE method_die) { - method_die.ResolveType(); - return true; - }); + dwarf->GetObjCMethods( + class_name, [&](DWARFCompileUnit *main_unit, DWARFDIE method_die) { + method_die.ResolveType(main_unit); + return true; + }); for (DelayedPropertyList::iterator pi = delayed_properties.begin(), pe = delayed_properties.end(); @@ -2130,7 +2180,10 @@ bool DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type, CompilerType &clang_type) { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = + llvm::cast(type->GetSymbolContextScope() + ->CalculateSymbolContextModule() + ->GetSymbolFile()); std::lock_guard guard( dwarf->GetObjectFile()->GetModule()->GetMutex()); @@ -2149,7 +2202,7 @@ if (log) dwarf->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace( log, "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", - die.GetID(), die.GetTagAsCString(), type->GetName().AsCString()); + die.GetID(nullptr), die.GetTagAsCString(), type->GetName().AsCString()); assert(clang_type); DWARFAttributes attributes; switch (tag) { @@ -2173,31 +2226,37 @@ (clang::DeclContext *)decl_context.GetOpaqueDeclContext(); for (auto it = m_decl_ctx_to_die.find(opaque_decl_ctx); it != m_decl_ctx_to_die.end() && it->first == opaque_decl_ctx; - it = m_decl_ctx_to_die.erase(it)) - for (DWARFDIE decl = it->second.GetFirstChild(); decl; + it = m_decl_ctx_to_die.erase(it)) { + DWARFCompileUnit *main_unit = it->second.first; + for (DWARFDIE decl = it->second.second.GetFirstChild(); decl; decl = decl.GetSibling()) - GetClangDeclForDIE(decl); + GetClangDeclForDIE(main_unit, decl); + } } -CompilerDecl DWARFASTParserClang::GetDeclForUIDFromDWARF(const DWARFDIE &die) { - clang::Decl *clang_decl = GetClangDeclForDIE(die); +CompilerDecl +DWARFASTParserClang::GetDeclForUIDFromDWARF(DWARFCompileUnit *main_unit, + const DWARFDIE &die) { + clang::Decl *clang_decl = GetClangDeclForDIE(main_unit, die); if (clang_decl != nullptr) return m_ast.GetCompilerDecl(clang_decl); return CompilerDecl(); } CompilerDeclContext -DWARFASTParserClang::GetDeclContextForUIDFromDWARF(const DWARFDIE &die) { - clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE(die); +DWARFASTParserClang::GetDeclContextForUIDFromDWARF(DWARFCompileUnit *main_unit, + const DWARFDIE &die) { + clang::DeclContext *clang_decl_ctx = + GetClangDeclContextForDIE(main_unit, die); if (clang_decl_ctx) return m_ast.CreateDeclContext(clang_decl_ctx); return CompilerDeclContext(); } -CompilerDeclContext -DWARFASTParserClang::GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) { +CompilerDeclContext DWARFASTParserClang::GetDeclContextContainingUIDFromDWARF( + DWARFCompileUnit *main_unit, const DWARFDIE &die) { clang::DeclContext *clang_decl_ctx = - GetClangDeclContextContainingDIE(die, nullptr); + GetClangDeclContextContainingDIE(main_unit, die, nullptr); if (clang_decl_ctx) return m_ast.CreateDeclContext(clang_decl_ctx); return CompilerDeclContext(); @@ -2306,6 +2365,9 @@ } if (func_range.GetBaseAddress().IsValid()) { + SymbolFileDWARF *dwarf = + llvm::cast(comp_unit.GetModule()->GetSymbolFile()); + DWARFCompileUnit *main_unit = dwarf->GetDWARFCompileUnit(&comp_unit); Mangled func_name; if (mangled) func_name.SetValue(ConstString(mangled), true); @@ -2331,10 +2393,10 @@ sstr << decl_ctx.GetQualifiedName(); clang::DeclContext *containing_decl_ctx = - GetClangDeclContextContainingDIE(die, nullptr); - ParseChildParameters(containing_decl_ctx, die, true, is_static, - is_variadic, has_template_params, param_types, - param_decls, type_quals); + GetClangDeclContextContainingDIE(main_unit, die, nullptr); + ParseChildParameters(&comp_unit, containing_decl_ctx, die, true, + is_static, is_variadic, has_template_params, + param_types, param_decls, type_quals); sstr << "("; for (size_t i = 0; i < param_types.size(); i++) { if (i > 0) @@ -2357,14 +2419,14 @@ decl_up.reset(new Declaration(die.GetCU()->GetFile(decl_file), decl_line, decl_column)); - SymbolFileDWARF *dwarf = die.GetDWARF(); // Supply the type _only_ if it has already been parsed - Type *func_type = dwarf->GetDIEToType().lookup(die.GetDIE()); + Type *func_type = + dwarf->GetDIEToType().lookup(die.MainCUtoDIEPair(main_unit)); assert(func_type == nullptr || func_type != DIE_IS_BEING_PARSED); if (dwarf->FixupAddress(func_range.GetBaseAddress())) { - const user_id_t func_user_id = die.GetID(); + const user_id_t func_user_id = die.GetID(main_unit); func_sp = std::make_shared(&comp_unit, func_user_id, // UserID is the DIE offset @@ -2384,7 +2446,7 @@ } void DWARFASTParserClang::ParseSingleMember( - const DWARFDIE &die, const DWARFDIE &parent_die, + 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, @@ -2565,9 +2627,15 @@ class_language == eLanguageTypeObjC_plus_plus) accessibility = eAccessNone; + DWARFCompileUnit *main_unit = nullptr; + if (comp_unit) { + SymbolFileDWARF *dwarf = + llvm::cast(comp_unit->GetModule()->GetSymbolFile()); + main_unit = dwarf->GetDWARFCompileUnit(comp_unit); + } // Handle static members if (is_external && member_byte_offset == UINT32_MAX) { - Type *var_type = die.ResolveTypeUID(encoding_form.Reference()); + Type *var_type = die.ResolveTypeUID(main_unit, encoding_form.Reference()); if (var_type) { if (accessibility == eAccessNone) @@ -2580,7 +2648,8 @@ } if (!is_artificial) { - Type *member_type = die.ResolveTypeUID(encoding_form.Reference()); + Type *member_type = + die.ResolveTypeUID(main_unit, encoding_form.Reference()); clang::FieldDecl *field_decl = nullptr; const uint64_t character_width = 8; @@ -2626,7 +2695,7 @@ "bit offset (0x%8.8" PRIx64 ") member will be ignored. Please file a bug against the " "compiler and include the preprocessed output for %s\n", - die.GetID(), DW_TAG_value_to_name(tag), name, + die.GetID(main_unit), DW_TAG_value_to_name(tag), name, this_field_info.bit_offset, GetUnitName(parent_die).c_str()); return; } @@ -2736,8 +2805,9 @@ "0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8x" " which extends beyond the bounds of 0x%8.8" PRIx64, - die.GetID(), name, encoding_form.Reference().GetOffset(), - parent_die.GetID()); + die.GetID(main_unit), name, + encoding_form.Reference().GetOffset(), + parent_die.GetID(main_unit)); } member_clang_type = @@ -2789,21 +2859,22 @@ class_clang_type, name, member_clang_type, accessibility, bit_size); - m_ast.SetMetadataAsUserID(field_decl, die.GetID()); + m_ast.SetMetadataAsUserID(field_decl, die.GetID(main_unit)); layout_info.field_offsets.insert( std::make_pair(field_decl, field_bit_offset)); } else { if (name) - module_sp->ReportError( - "0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8x" - " which was unable to be parsed", - die.GetID(), name, encoding_form.Reference().GetOffset()); + module_sp->ReportError("0x%8.8" PRIx64 + ": DW_TAG_member '%s' refers to type 0x%8.8x" + " which was unable to be parsed", + die.GetID(main_unit), name, + encoding_form.Reference().GetOffset()); else module_sp->ReportError( "0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8x" " which was unable to be parsed", - die.GetID(), encoding_form.Reference().GetOffset()); + die.GetID(main_unit), encoding_form.Reference().GetOffset()); } } @@ -2816,22 +2887,22 @@ } ClangASTMetadata metadata; - metadata.SetUserID(die.GetID()); + metadata.SetUserID(die.GetID(main_unit)); delayed_properties.push_back(DelayedAddObjCClassProperty( class_clang_type, prop_name, member_type->GetLayoutCompilerType(), ivar_decl, prop_setter_name, prop_getter_name, prop_attributes, &metadata)); if (ivar_decl) - m_ast.SetMetadataAsUserID(ivar_decl, die.GetID()); + m_ast.SetMetadataAsUserID(ivar_decl, die.GetID(main_unit)); } } } } bool DWARFASTParserClang::ParseChildMembers( - const DWARFDIE &parent_die, CompilerType &class_clang_type, - const LanguageType class_language, + CompileUnit *comp_unit, const DWARFDIE &parent_die, + CompilerType &class_clang_type, const LanguageType class_language, std::vector> &base_classes, std::vector &member_accessibilities, std::vector &member_function_dies, @@ -2848,6 +2919,13 @@ if (ast == nullptr) return false; + DWARFCompileUnit *main_unit = nullptr; + if (comp_unit) { + SymbolFileDWARF *dwarf = + llvm::cast(comp_unit->GetModule()->GetSymbolFile()); + main_unit = dwarf->GetDWARFCompileUnit(comp_unit); + } + for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling()) { dw_tag_t tag = die.Tag(); @@ -2855,9 +2933,10 @@ switch (tag) { case DW_TAG_member: case DW_TAG_APPLE_property: - ParseSingleMember(die, parent_die, class_clang_type, class_language, - member_accessibilities, default_accessibility, - delayed_properties, layout_info, last_field_info); + ParseSingleMember(comp_unit, die, parent_die, class_clang_type, + class_language, member_accessibilities, + default_accessibility, delayed_properties, layout_info, + last_field_info); break; case DW_TAG_subprogram: @@ -2929,7 +3008,8 @@ } } - Type *base_class_type = die.ResolveTypeUID(encoding_form.Reference()); + Type *base_class_type = + die.ResolveTypeUID(main_unit, encoding_form.Reference()); if (base_class_type == nullptr) { module_sp->ReportError("0x%8.8x: DW_TAG_inheritance failed to " "resolve the base class at 0x%8.8x" @@ -2989,14 +3069,22 @@ } size_t DWARFASTParserClang::ParseChildParameters( - 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, + 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, std::vector &function_param_decls, unsigned &type_quals) { if (!parent_die) return 0; + DWARFCompileUnit *main_unit = nullptr; + if (comp_unit) { + SymbolFileDWARF *dwarf = + llvm::cast(comp_unit->GetModule()->GetSymbolFile()); + main_unit = dwarf->GetDWARFCompileUnit(comp_unit); + } + size_t arg_idx = 0; for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); die = die.GetSibling()) { @@ -3054,7 +3142,7 @@ // the formal parameter DIE... (name == nullptr || ::strcmp(name, "this") == 0)) { Type *this_type = - die.ResolveTypeUID(param_type_die_form.Reference()); + die.ResolveTypeUID(main_unit, param_type_die_form.Reference()); if (this_type) { uint32_t encoding_mask = this_type->GetEncodingMask(); if (encoding_mask & Type::eEncodingIsPointerUID) { @@ -3071,18 +3159,19 @@ } if (!skip) { - Type *type = die.ResolveTypeUID(param_type_die_form.Reference()); + Type *type = + die.ResolveTypeUID(main_unit, param_type_die_form.Reference()); if (type) { function_param_types.push_back(type->GetForwardCompilerType()); clang::ParmVarDecl *param_var_decl = m_ast.CreateParameterDeclaration( - containing_decl_ctx, GetOwningClangModule(die), name, - type->GetForwardCompilerType(), storage); + containing_decl_ctx, GetOwningClangModule(main_unit, die), + name, type->GetForwardCompilerType(), storage); assert(param_var_decl); function_param_decls.push_back(param_var_decl); - m_ast.SetMetadataAsUserID(param_var_decl, die.GetID()); + m_ast.SetMetadataAsUserID(param_var_decl, die.GetID(main_unit)); } } } @@ -3208,9 +3297,11 @@ return array_info; } -Type *DWARFASTParserClang::GetTypeForDIE(const DWARFDIE &die) { +Type *DWARFASTParserClang::GetTypeForDIE(DWARFCompileUnit *main_unit, + const DWARFDIE &die) { if (die) { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = + &die.MainDWARFUnit(main_unit)->GetSymbolFileDWARF(); DWARFAttributes attributes; const size_t num_attributes = die.GetAttributes(attributes); if (num_attributes > 0) { @@ -3221,7 +3312,7 @@ if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, form_value)) - return dwarf->ResolveTypeUID(form_value.Reference(), true); + return dwarf->ResolveTypeUID(main_unit, form_value.Reference(), true); } } } @@ -3229,7 +3320,9 @@ return nullptr; } -clang::Decl *DWARFASTParserClang::GetClangDeclForDIE(const DWARFDIE &die) { +clang::Decl * +DWARFASTParserClang::GetClangDeclForDIE(DWARFCompileUnit *main_unit, + const DWARFDIE &die) { if (!die) return nullptr; @@ -3244,52 +3337,54 @@ return nullptr; } - DIEToDeclMap::iterator cache_pos = m_die_to_decl.find(die.GetDIE()); + auto diepair = die.MainCUtoDIEPair(main_unit); + DIEToDeclMap::iterator cache_pos = m_die_to_decl.find(diepair); if (cache_pos != m_die_to_decl.end()) return cache_pos->second; if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification)) { - clang::Decl *decl = GetClangDeclForDIE(spec_die); - m_die_to_decl[die.GetDIE()] = decl; - m_decl_to_die[decl].insert(die.GetDIE()); + clang::Decl *decl = GetClangDeclForDIE(main_unit, spec_die); + m_die_to_decl[diepair] = decl; + m_decl_to_die[decl].insert(diepair); return decl; } if (DWARFDIE abstract_origin_die = die.GetReferencedDIE(DW_AT_abstract_origin)) { - clang::Decl *decl = GetClangDeclForDIE(abstract_origin_die); - m_die_to_decl[die.GetDIE()] = decl; - m_decl_to_die[decl].insert(die.GetDIE()); + clang::Decl *decl = GetClangDeclForDIE(main_unit, abstract_origin_die); + m_die_to_decl[diepair] = decl; + m_decl_to_die[decl].insert(diepair); return decl; } + SymbolFileDWARF *dwarf = &die.MainDWARFUnit(main_unit)->GetSymbolFileDWARF(); + clang::Decl *decl = nullptr; switch (die.Tag()) { case DW_TAG_variable: case DW_TAG_constant: case DW_TAG_formal_parameter: { - SymbolFileDWARF *dwarf = die.GetDWARF(); - Type *type = GetTypeForDIE(die); + Type *type = GetTypeForDIE(main_unit, die); if (dwarf && type) { const char *name = die.GetName(); clang::DeclContext *decl_context = TypeSystemClang::DeclContextGetAsDeclContext( - dwarf->GetDeclContextContainingUID(die.GetID())); + dwarf->GetDeclContextContainingUID(die.GetID(main_unit))); decl = m_ast.CreateVariableDeclaration( - decl_context, GetOwningClangModule(die), name, + decl_context, GetOwningClangModule(main_unit, die), name, ClangUtil::GetQualType(type->GetForwardCompilerType())); } break; } case DW_TAG_imported_declaration: { - SymbolFileDWARF *dwarf = die.GetDWARF(); DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import); if (imported_uid) { - CompilerDecl imported_decl = SymbolFileDWARF::GetDecl(imported_uid); + CompilerDecl imported_decl = + SymbolFileDWARF::GetDecl(main_unit, imported_uid); if (imported_decl) { clang::DeclContext *decl_context = TypeSystemClang::DeclContextGetAsDeclContext( - dwarf->GetDeclContextContainingUID(die.GetID())); + dwarf->GetDeclContextContainingUID(die.GetID(main_unit))); if (clang::NamedDecl *clang_imported_decl = llvm::dyn_cast( (clang::Decl *)imported_decl.GetOpaqueDecl())) @@ -3300,16 +3395,15 @@ break; } case DW_TAG_imported_module: { - SymbolFileDWARF *dwarf = die.GetDWARF(); DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import); if (imported_uid) { CompilerDeclContext imported_decl_ctx = - SymbolFileDWARF::GetDeclContext(imported_uid); + SymbolFileDWARF::GetDeclContext(main_unit, imported_uid); if (imported_decl_ctx) { clang::DeclContext *decl_context = TypeSystemClang::DeclContextGetAsDeclContext( - dwarf->GetDeclContextContainingUID(die.GetID())); + dwarf->GetDeclContextContainingUID(die.GetID(main_unit))); if (clang::NamespaceDecl *ns_decl = TypeSystemClang::DeclContextGetAsNamespaceDecl( imported_decl_ctx)) @@ -3323,16 +3417,18 @@ break; } - m_die_to_decl[die.GetDIE()] = decl; - m_decl_to_die[decl].insert(die.GetDIE()); + m_die_to_decl[diepair] = decl; + m_decl_to_die[decl].insert(diepair); return decl; } clang::DeclContext * -DWARFASTParserClang::GetClangDeclContextForDIE(const DWARFDIE &die) { +DWARFASTParserClang::GetClangDeclContextForDIE(DWARFCompileUnit *main_unit, + const DWARFDIE &die) { if (die) { - clang::DeclContext *decl_ctx = GetCachedClangDeclContextForDIE(die); + clang::DeclContext *decl_ctx = + GetCachedClangDeclContextForDIE(main_unit, die); if (decl_ctx) return decl_ctx; @@ -3345,12 +3441,12 @@ break; case DW_TAG_namespace: - decl_ctx = ResolveNamespaceDIE(die); + decl_ctx = ResolveNamespaceDIE(main_unit, die); try_parsing_type = false; break; case DW_TAG_lexical_block: - decl_ctx = GetDeclContextForBlock(die); + decl_ctx = GetDeclContextForBlock(main_unit, die); try_parsing_type = false; break; @@ -3359,13 +3455,15 @@ } if (decl_ctx == nullptr && try_parsing_type) { - Type *type = die.GetDWARF()->ResolveType(die); + Type *type = + die.MainDWARFUnit(main_unit)->GetSymbolFileDWARF().ResolveType( + main_unit, die); if (type) - decl_ctx = GetCachedClangDeclContextForDIE(die); + decl_ctx = GetCachedClangDeclContextForDIE(main_unit, die); } if (decl_ctx) { - LinkDeclContextToDIE(decl_ctx, die); + LinkDeclContextToDIE(decl_ctx, main_unit, die); return decl_ctx; } } @@ -3373,7 +3471,8 @@ } OptionalClangModuleID -DWARFASTParserClang::GetOwningClangModule(const DWARFDIE &die) { +DWARFASTParserClang::GetOwningClangModule(DWARFCompileUnit *main_unit, + const DWARFDIE &die) { if (!die.IsValid()) return {}; @@ -3382,16 +3481,16 @@ const dw_tag_t tag = parent.Tag(); if (tag == DW_TAG_module) { DWARFDIE module_die = parent; - auto it = m_die_to_module.find(module_die.GetDIE()); + auto it = m_die_to_module.find(module_die.MainCUtoDIEPair(main_unit)); if (it != m_die_to_module.end()) return it->second; const char *name = module_die.GetAttributeValueAsString(DW_AT_name, 0); if (!name) return {}; - OptionalClangModuleID id = - m_ast.GetOrCreateClangModule(name, GetOwningClangModule(module_die)); - m_die_to_module.insert({module_die.GetDIE(), id}); + OptionalClangModuleID id = m_ast.GetOrCreateClangModule( + name, GetOwningClangModule(main_unit, module_die)); + m_die_to_module.insert({module_die.MainCUtoDIEPair(main_unit), id}); return id; } } @@ -3447,34 +3546,37 @@ } clang::DeclContext * -DWARFASTParserClang::GetDeclContextForBlock(const DWARFDIE &die) { +DWARFASTParserClang::GetDeclContextForBlock(DWARFCompileUnit *main_unit, + const DWARFDIE &die) { assert(die.Tag() == DW_TAG_lexical_block); DWARFDIE containing_function_with_abstract_origin = GetContainingFunctionWithAbstractOrigin(die); if (!containing_function_with_abstract_origin) { - return (clang::DeclContext *)ResolveBlockDIE(die); + return (clang::DeclContext *)ResolveBlockDIE(main_unit, die); } DWARFDIE child = FindFirstChildWithAbstractOrigin( die, containing_function_with_abstract_origin); CompilerDeclContext decl_context = - GetDeclContextContainingUIDFromDWARF(child); + GetDeclContextContainingUIDFromDWARF(main_unit, child); return (clang::DeclContext *)decl_context.GetOpaqueDeclContext(); } -clang::BlockDecl *DWARFASTParserClang::ResolveBlockDIE(const DWARFDIE &die) { +clang::BlockDecl * +DWARFASTParserClang::ResolveBlockDIE(DWARFCompileUnit *main_unit, + const DWARFDIE &die) { if (die && die.Tag() == DW_TAG_lexical_block) { - clang::BlockDecl *decl = - llvm::cast_or_null(m_die_to_decl_ctx[die.GetDIE()]); + clang::BlockDecl *decl = llvm::cast_or_null( + m_die_to_decl_ctx[die.MainCUtoDIEPair(main_unit)]); if (!decl) { DWARFDIE decl_context_die; clang::DeclContext *decl_context = - GetClangDeclContextContainingDIE(die, &decl_context_die); - decl = - m_ast.CreateBlockDeclaration(decl_context, GetOwningClangModule(die)); + GetClangDeclContextContainingDIE(main_unit, die, &decl_context_die); + decl = m_ast.CreateBlockDeclaration(decl_context, + GetOwningClangModule(main_unit, die)); if (decl) - LinkDeclContextToDIE((clang::DeclContext *)decl, die); + LinkDeclContextToDIE((clang::DeclContext *)decl, main_unit, die); } return decl; @@ -3483,35 +3585,37 @@ } clang::NamespaceDecl * -DWARFASTParserClang::ResolveNamespaceDIE(const DWARFDIE &die) { +DWARFASTParserClang::ResolveNamespaceDIE(DWARFCompileUnit *main_unit, + const DWARFDIE &die) { if (die && die.Tag() == DW_TAG_namespace) { // See if we already parsed this namespace DIE and associated it with a // uniqued namespace declaration - clang::NamespaceDecl *namespace_decl = - static_cast(m_die_to_decl_ctx[die.GetDIE()]); + clang::NamespaceDecl *namespace_decl = static_cast( + m_die_to_decl_ctx[die.MainCUtoDIEPair(main_unit)]); if (namespace_decl) return namespace_decl; else { const char *namespace_name = die.GetName(); clang::DeclContext *containing_decl_ctx = - GetClangDeclContextContainingDIE(die, nullptr); + GetClangDeclContextContainingDIE(main_unit, die, nullptr); bool is_inline = die.GetAttributeValueAsUnsigned(DW_AT_export_symbols, 0) != 0; namespace_decl = m_ast.GetUniqueNamespaceDeclaration( - namespace_name, containing_decl_ctx, GetOwningClangModule(die), - is_inline); + namespace_name, containing_decl_ctx, + GetOwningClangModule(main_unit, die), is_inline); Log *log = nullptr; // (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); if (log) { - SymbolFileDWARF *dwarf = die.GetDWARF(); + SymbolFileDWARF *dwarf = + &die.MainDWARFUnit(main_unit)->GetSymbolFileDWARF(); if (namespace_name) { dwarf->GetObjectFile()->GetModule()->LogMessage( log, "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace with DW_AT_name(\"%s\") => " "clang::NamespaceDecl *%p (original = %p)", - static_cast(&m_ast.getASTContext()), die.GetID(), + static_cast(&m_ast.getASTContext()), die.GetID(main_unit), namespace_name, static_cast(namespace_decl), static_cast(namespace_decl->getOriginalNamespace())); } else { @@ -3520,14 +3624,15 @@ "ASTContext => %p: 0x%8.8" PRIx64 ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p " "(original = %p)", - static_cast(&m_ast.getASTContext()), die.GetID(), + static_cast(&m_ast.getASTContext()), die.GetID(main_unit), static_cast(namespace_decl), static_cast(namespace_decl->getOriginalNamespace())); } } if (namespace_decl) - LinkDeclContextToDIE((clang::DeclContext *)namespace_decl, die); + LinkDeclContextToDIE((clang::DeclContext *)namespace_decl, main_unit, + die); return namespace_decl; } } @@ -3535,8 +3640,9 @@ } clang::DeclContext *DWARFASTParserClang::GetClangDeclContextContainingDIE( - const DWARFDIE &die, DWARFDIE *decl_ctx_die_copy) { - SymbolFileDWARF *dwarf = die.GetDWARF(); + DWARFCompileUnit *main_unit, const DWARFDIE &die, + DWARFDIE *decl_ctx_die_copy) { + SymbolFileDWARF *dwarf = &die.MainDWARFUnit(main_unit)->GetSymbolFileDWARF(); DWARFDIE decl_ctx_die = dwarf->GetDeclContextDIEContainingDIE(die); @@ -3545,17 +3651,18 @@ if (decl_ctx_die) { clang::DeclContext *clang_decl_ctx = - GetClangDeclContextForDIE(decl_ctx_die); + GetClangDeclContextForDIE(main_unit, decl_ctx_die); if (clang_decl_ctx) return clang_decl_ctx; } return m_ast.GetTranslationUnitDecl(); } -clang::DeclContext * -DWARFASTParserClang::GetCachedClangDeclContextForDIE(const DWARFDIE &die) { +clang::DeclContext *DWARFASTParserClang::GetCachedClangDeclContextForDIE( + DWARFCompileUnit *main_unit, const DWARFDIE &die) { if (die) { - DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die.GetDIE()); + DIEToDeclContextMap::iterator pos = + m_die_to_decl_ctx.find(die.MainCUtoDIEPair(main_unit)); if (pos != m_die_to_decl_ctx.end()) return pos->second; } @@ -3563,16 +3670,19 @@ } void DWARFASTParserClang::LinkDeclContextToDIE(clang::DeclContext *decl_ctx, + DWARFCompileUnit *main_unit, const DWARFDIE &die) { - m_die_to_decl_ctx[die.GetDIE()] = decl_ctx; + m_die_to_decl_ctx[die.MainCUtoDIEPair(main_unit)] = decl_ctx; // There can be many DIEs for a single decl context // m_decl_ctx_to_die[decl_ctx].insert(die.GetDIE()); - m_decl_ctx_to_die.insert(std::make_pair(decl_ctx, die)); + m_decl_ctx_to_die.insert( + std::make_pair(decl_ctx, die.MainCUtoDWARFDIEPair(main_unit))); } bool DWARFASTParserClang::CopyUniqueClassMethodTypes( - const DWARFDIE &src_class_die, const DWARFDIE &dst_class_die, - lldb_private::Type *class_type, std::vector &failures) { + DWARFCompileUnit *main_unit, const DWARFDIE &src_class_die, + const DWARFDIE &dst_class_die, lldb_private::Type *class_type, + std::vector &failures) { if (!class_type || !src_class_die || !dst_class_die) return false; if (src_class_die.Tag() != dst_class_die.Tag()) @@ -3697,12 +3807,14 @@ dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); clang::DeclContext *src_decl_ctx = - src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; + src_dwarf_ast_parser + ->m_die_to_decl_ctx[src_die.MainCUtoDIEPair(main_unit)]; if (src_decl_ctx) { LLDB_LOGF(log, "uniquing decl context %p from 0x%8.8x for 0x%8.8x", static_cast(src_decl_ctx), src_die.GetOffset(), dst_die.GetOffset()); - dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, dst_die); + dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, main_unit, + dst_die); } else { LLDB_LOGF(log, "warning: tried to unique decl context from 0x%8.8x for " @@ -3711,14 +3823,16 @@ } Type *src_child_type = - dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; + dst_die.GetDWARF() + ->GetDIEToType()[src_die.MainCUtoDIEPair(main_unit)]; if (src_child_type) { LLDB_LOGF(log, "uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", static_cast(src_child_type), src_child_type->GetID(), src_die.GetOffset(), dst_die.GetOffset()); - dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type; + dst_die.GetDWARF()->GetDIEToType()[dst_die.MainCUtoDIEPair(main_unit)] = + src_child_type; } else { LLDB_LOGF(log, "warning: tried to unique lldb_private::Type from " @@ -3741,12 +3855,14 @@ if (src_die && (src_die.Tag() == dst_die.Tag())) { clang::DeclContext *src_decl_ctx = - src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; + src_dwarf_ast_parser + ->m_die_to_decl_ctx[src_die.MainCUtoDIEPair(main_unit)]; if (src_decl_ctx) { LLDB_LOGF(log, "uniquing decl context %p from 0x%8.8x for 0x%8.8x", static_cast(src_decl_ctx), src_die.GetOffset(), dst_die.GetOffset()); - dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, dst_die); + dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, main_unit, + dst_die); } else { LLDB_LOGF(log, "warning: tried to unique decl context from 0x%8.8x " @@ -3755,14 +3871,16 @@ } Type *src_child_type = - dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; + dst_die.GetDWARF() + ->GetDIEToType()[src_die.MainCUtoDIEPair(main_unit)]; if (src_child_type) { LLDB_LOGF( log, "uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", static_cast(src_child_type), src_child_type->GetID(), src_die.GetOffset(), dst_die.GetOffset()); - dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = + dst_die.GetDWARF() + ->GetDIEToType()[dst_die.MainCUtoDIEPair(main_unit)] = src_child_type; } else { LLDB_LOGF(log, @@ -3796,12 +3914,14 @@ if (dst_die) { // Both classes have the artificial types, link them clang::DeclContext *src_decl_ctx = - src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; + src_dwarf_ast_parser + ->m_die_to_decl_ctx[src_die.MainCUtoDIEPair(main_unit)]; if (src_decl_ctx) { LLDB_LOGF(log, "uniquing decl context %p from 0x%8.8x for 0x%8.8x", static_cast(src_decl_ctx), src_die.GetOffset(), dst_die.GetOffset()); - dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, dst_die); + dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, main_unit, + dst_die); } else { LLDB_LOGF(log, "warning: tried to unique decl context from 0x%8.8x " @@ -3810,14 +3930,17 @@ } Type *src_child_type = - dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; + dst_die.GetDWARF() + ->GetDIEToType()[src_die.MainCUtoDIEPair(main_unit)]; if (src_child_type) { LLDB_LOGF( log, "uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x", static_cast(src_child_type), src_child_type->GetID(), src_die.GetOffset(), dst_die.GetOffset()); - dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type; + dst_die.GetDWARF() + ->GetDIEToType()[dst_die.MainCUtoDIEPair(main_unit)] = + src_child_type; } else { LLDB_LOGF(log, "warning: tried to unique lldb_private::Type from " diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h @@ -17,10 +17,12 @@ class DIERef; class DWARFASTParser; class DWARFAttributes; +class DWARFCompileUnit; class DWARFUnit; class DWARFDebugInfoEntry; class DWARFDeclContext; class SymbolFileDWARF; +class DWARFCompileUnit; class DWARFBaseDIE { public: @@ -86,12 +88,6 @@ dw_offset_t GetOffset() const; - // Get the LLDB user ID for this DIE. This is often just the DIE offset, - // but it might have a SymbolFileDWARF::GetID() in the high 32 bits if - // we are doing Darwin DWARF in .o file, or DWARF stand alone debug - // info. - lldb::user_id_t GetID() const; - const char *GetName() const; lldb::ModuleSP GetModule() const; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp @@ -8,8 +8,10 @@ #include "DWARFBaseDIE.h" -#include "DWARFUnit.h" +#include "DWARFCompileUnit.h" #include "DWARFDebugInfoEntry.h" +#include "DWARFTypeUnit.h" +#include "DWARFUnit.h" #include "SymbolFileDWARF.h" #include "lldb/Core/Module.h" @@ -61,12 +63,6 @@ return fail_value; } -lldb::user_id_t DWARFBaseDIE::GetID() const { - if (IsValid()) - return GetDWARF()->GetUID(*this); - return LLDB_INVALID_UID; -} - const char *DWARFBaseDIE::GetName() const { if (IsValid()) return m_die->GetName(m_cu); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h @@ -20,6 +20,8 @@ static bool classof(const DWARFUnit *unit) { return !unit->IsTypeUnit(); } + DWARFCompileUnit &GetNonSkeletonUnit(); + private: DWARFCompileUnit(SymbolFileDWARF &dwarf, lldb::user_id_t uid, const DWARFUnitHeader &header, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp @@ -99,3 +99,7 @@ } } } + +DWARFCompileUnit &DWARFCompileUnit::GetNonSkeletonUnit() { + return llvm::cast(DWARFUnit::GetNonSkeletonUnit()); +} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h @@ -23,6 +23,12 @@ // Accessors + // Get the LLDB user ID for this DIE. This is often just the DIE offset, + // but it might have a SymbolFileDWARF::GetID() in the high 32 bits if + // we are doing Darwin DWARF in .o file, or DWARF stand alone debug + // info. + lldb::user_id_t GetID(DWARFCompileUnit *main_unit) const; + // Accessing information about a DIE const char *GetMangledName() const; @@ -35,10 +41,11 @@ void AppendTypeName(lldb_private::Stream &s) const; - lldb_private::Type *ResolveType() const; + lldb_private::Type *ResolveType(DWARFCompileUnit *main_unit) const; // Resolve a type by UID using this DIE's DWARF file - lldb_private::Type *ResolveTypeUID(const DWARFDIE &die) const; + lldb_private::Type *ResolveTypeUID(DWARFCompileUnit *main_unit, + const DWARFDIE &die) const; // Functions for obtaining DIE relations and references @@ -88,6 +95,18 @@ int &decl_line, int &decl_column, int &call_file, int &call_line, int &call_column, lldb_private::DWARFExpression *frame_base) const; + + DWARFCompileUnit *MainDWARFCompileUnit(DWARFCompileUnit *main_unit) const; + DWARFUnit *MainDWARFUnit(DWARFCompileUnit *main_unit) const; + std::pair + MainCUtoDWARFDIEPair(DWARFCompileUnit *main_unit) const; + std::pair + MainCUtoDIEPair(DWARFCompileUnit *main_unit) const; + bool MainUnitIsValid(DWARFCompileUnit *main_unit) const; + +protected: + DWARFCompileUnit * + MainDWARFCompileUnitOrNull(DWARFCompileUnit *main_unit) const; }; #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDIE_H diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp @@ -9,10 +9,11 @@ #include "DWARFDIE.h" #include "DWARFASTParser.h" +#include "DWARFCompileUnit.h" #include "DWARFDebugInfo.h" #include "DWARFDebugInfoEntry.h" #include "DWARFDeclContext.h" -#include "DWARFUnit.h" +#include "SymbolFileDWARFDwo.h" using namespace lldb_private; @@ -200,6 +201,12 @@ return result; } +lldb::user_id_t DWARFDIE::GetID(DWARFCompileUnit *main_unit) const { + if (IsValid()) + return GetDWARF()->GetUID(main_unit, *this); + return LLDB_INVALID_UID; +} + const char *DWARFDIE::GetMangledName() const { if (IsValid()) return m_die->GetMangledName(m_cu); @@ -345,16 +352,18 @@ } } -lldb_private::Type *DWARFDIE::ResolveType() const { +lldb_private::Type *DWARFDIE::ResolveType(DWARFCompileUnit *main_unit) const { if (IsValid()) - return GetDWARF()->ResolveType(*this, true); + return MainDWARFUnit(main_unit)->GetSymbolFileDWARF().ResolveType( + main_unit, *this, true); else return nullptr; } -lldb_private::Type *DWARFDIE::ResolveTypeUID(const DWARFDIE &die) const { - if (SymbolFileDWARF *dwarf = GetDWARF()) - return dwarf->ResolveTypeUID(die, true); +lldb_private::Type *DWARFDIE::ResolveTypeUID(DWARFCompileUnit *main_unit, + const DWARFDIE &die) const { + if (SymbolFileDWARF *dwarf = &MainDWARFUnit(main_unit)->GetSymbolFileDWARF()) + return dwarf->ResolveTypeUID(main_unit, die, true); return nullptr; } @@ -448,3 +457,50 @@ } else return false; } + +DWARFCompileUnit * +DWARFDIE::MainDWARFCompileUnit(DWARFCompileUnit *main_unit) const { + if (!IsValid()) + return nullptr; + if (llvm::isa(GetCU())) + return nullptr; + if (!main_unit) + main_unit = llvm::dyn_cast(GetCU()); + lldbassert(main_unit); +#if 0 + if (main_unit) + main_unit = &main_unit->GetNonSkeletonUnit(); +#endif + return main_unit; +} + +DWARFUnit *DWARFDIE::MainDWARFUnit(DWARFCompileUnit *main_unit) const { + main_unit = MainDWARFCompileUnit(main_unit); + if (main_unit) + return main_unit; + return GetCU(); +} + +DWARFCompileUnit * +DWARFDIE::MainDWARFCompileUnitOrNull(DWARFCompileUnit *main_unit) const { + lldbassert(IsValid()); + if (!MainUnitIsValid(main_unit)) + return nullptr; + return MainDWARFCompileUnit(main_unit); +} + +std::pair +DWARFDIE::MainCUtoDWARFDIEPair(DWARFCompileUnit *main_unit) const { + return std::make_pair(MainDWARFCompileUnitOrNull(main_unit), *this); +} + +std::pair +DWARFDIE::MainCUtoDIEPair(DWARFCompileUnit *main_unit) const { + return std::make_pair(MainDWARFCompileUnitOrNull(main_unit), GetDIE()); +} + +bool DWARFDIE::MainUnitIsValid(DWARFCompileUnit *main_unit) const { + if (!IsValid()) + return false; + return GetCU()->MainUnitIsValid(main_unit); +} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h @@ -56,6 +56,10 @@ llvm::Expected GetCompileUnitAranges(); + lldb::user_id_t GetUID(DWARFCompileUnit *main_unit, DIERef ref) const { + return m_dwarf.GetUID(main_unit, ref); + } + protected: typedef std::vector UnitColl; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -58,6 +58,8 @@ for (size_t idx = 0; idx < num_units; ++idx) { DWARFUnit *cu = GetUnitAtIndex(idx); + if (cu->GetUnitDIEOnly().Tag() == DW_TAG_partial_unit) + continue; dw_offset_t offset = cu->GetOffset(); if (cus_with_data.find(offset) == cus_with_data.end()) cu->BuildAddressRangeTable(m_cu_aranges_up.get()); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h @@ -27,37 +27,48 @@ /// Finds global variables with the given base name. Any additional filtering /// (e.g., to only retrieve variables from a given context) should be done by /// the consumer. - virtual void - GetGlobalVariables(ConstString basename, - llvm::function_ref callback) = 0; + virtual void GetGlobalVariables( + ConstString basename, + llvm::function_ref + callback) = 0; + virtual void GetGlobalVariables( + const RegularExpression ®ex, + llvm::function_ref + callback) = 0; + virtual void GetGlobalVariables( + const DWARFUnit &cu, + llvm::function_ref + callback) = 0; + virtual void GetObjCMethods( + ConstString class_name, + llvm::function_ref + callback) = 0; + virtual void GetCompleteObjCClass( + ConstString class_name, bool must_be_implementation, + llvm::function_ref + callback) = 0; virtual void - GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref callback) = 0; - virtual void - GetGlobalVariables(const DWARFUnit &cu, - llvm::function_ref callback) = 0; - virtual void - GetObjCMethods(ConstString class_name, - llvm::function_ref callback) = 0; - virtual void - GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, - llvm::function_ref callback) = 0; - virtual void GetTypes(ConstString name, - llvm::function_ref callback) = 0; - virtual void GetTypes(const DWARFDeclContext &context, - llvm::function_ref callback) = 0; + GetTypes(ConstString name, + llvm::function_ref + callback) = 0; virtual void - GetNamespaces(ConstString name, - llvm::function_ref callback) = 0; - virtual void - GetFunctions(ConstString name, SymbolFileDWARF &dwarf, - const CompilerDeclContext &parent_decl_ctx, - uint32_t name_type_mask, - llvm::function_ref callback) = 0; - virtual void - GetFunctions(const RegularExpression ®ex, - llvm::function_ref callback) = 0; + GetTypes(const DWARFDeclContext &context, + llvm::function_ref + callback) = 0; + virtual void GetNamespaces( + ConstString name, + llvm::function_ref + callback) = 0; + virtual void GetFunctions( + ConstString name, SymbolFileDWARF &dwarf, + const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, + llvm::function_ref + callback) = 0; + virtual void GetFunctions( + const RegularExpression ®ex, + llvm::function_ref + callback) = 0; virtual void Dump(Stream &s) = 0; @@ -68,32 +79,53 @@ /// the function given by "ref" matches search criteria given by /// "parent_decl_ctx" and "name_type_mask", it is inserted into the "dies" /// vector. - bool ProcessFunctionDIE(llvm::StringRef name, DIERef ref, - SymbolFileDWARF &dwarf, - const CompilerDeclContext &parent_decl_ctx, - uint32_t name_type_mask, - llvm::function_ref callback); + bool ProcessFunctionDIE( + llvm::StringRef name, DWARFCompileUnit *main_unit, DIERef ref, + SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, + uint32_t name_type_mask, + llvm::function_ref + callback); - class DIERefCallbackImpl { + class DIECallbackImpl { public: - DIERefCallbackImpl(const DWARFIndex &index, - llvm::function_ref callback, - llvm::StringRef name); - bool operator()(DIERef ref) const; + DIECallbackImpl( + const DWARFIndex &index, + llvm::function_ref + callback, + llvm::StringRef name); - private: + protected: const DWARFIndex &m_index; SymbolFileDWARF &m_dwarf; - const llvm::function_ref m_callback; + const llvm::function_ref + m_callback; const llvm::StringRef m_name; }; - DIERefCallbackImpl - DIERefCallback(llvm::function_ref callback, - llvm::StringRef name = {}) const { + class DIERefCallbackImpl : protected DIECallbackImpl { + public: + using DIECallbackImpl::DIECallbackImpl; + bool operator()(DIERef ref) const; + }; + class DIEUIDCallbackImpl : protected DIECallbackImpl { + public: + using DIECallbackImpl::DIECallbackImpl; + bool operator()(lldb::user_id_t uid) const; + }; + DIERefCallbackImpl DIERefCallback( + llvm::function_ref + callback, + llvm::StringRef name = {}) const { return DIERefCallbackImpl(*this, callback, name); } + DIEUIDCallbackImpl DIEUIDCallback( + llvm::function_ref + callback, + llvm::StringRef name = {}) const { + return DIEUIDCallbackImpl(*this, callback, name); + } void ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const; + void ReportInvalidDIEUID(lldb::user_id_t, llvm::StringRef name) const; }; } // namespace lldb_private diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp @@ -8,6 +8,7 @@ #include "Plugins/SymbolFile/DWARF/DWARFIndex.h" #include "Plugins/Language/ObjC/ObjCLanguage.h" +#include "Plugins/SymbolFile/DWARF/DWARFCompileUnit.h" #include "Plugins/SymbolFile/DWARF/DWARFDIE.h" #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" @@ -19,9 +20,11 @@ DWARFIndex::~DWARFIndex() = default; bool DWARFIndex::ProcessFunctionDIE( - llvm::StringRef name, DIERef ref, SymbolFileDWARF &dwarf, - const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - llvm::function_ref callback) { + llvm::StringRef name, DWARFCompileUnit *main_unit, DIERef ref, + SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, + uint32_t name_type_mask, + llvm::function_ref + callback) { DWARFDIE die = dwarf.GetDIE(ref); if (!die) { ReportInvalidDIERef(ref, name); @@ -37,18 +40,18 @@ // Otherwise, we need to also check that the context matches. If it does not // match, we do nothing. - if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, die)) + if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, main_unit, die)) return true; // In case of a full match, we just insert everything we find. if (name_type_mask & eFunctionNameTypeFull) - return callback(die); + return callback(main_unit, die); // If looking for ObjC selectors, we need to also check if the name is a // possible selector. if (name_type_mask & eFunctionNameTypeSelector && ObjCLanguage::IsPossibleObjCMethodName(die.GetName())) - return callback(die); + return callback(main_unit, die); bool looking_for_methods = name_type_mask & lldb::eFunctionNameTypeMethod; bool looking_for_functions = name_type_mask & lldb::eFunctionNameTypeBase; @@ -58,14 +61,16 @@ // searching for. if ((looking_for_methods && looking_for_functions) || looking_for_methods == die.IsMethod()) - return callback(die); + return callback(main_unit, die); } return true; } -DWARFIndex::DIERefCallbackImpl::DIERefCallbackImpl( - const DWARFIndex &index, llvm::function_ref callback, +DWARFIndex::DIECallbackImpl::DIECallbackImpl( + const DWARFIndex &index, + llvm::function_ref + callback, llvm::StringRef name) : m_index(index), m_dwarf(*llvm::cast(index.m_module.GetSymbolFile())), @@ -73,14 +78,30 @@ bool DWARFIndex::DIERefCallbackImpl::operator()(DIERef ref) const { if (DWARFDIE die = m_dwarf.GetDIE(ref)) - return m_callback(die); + return m_callback(nullptr /* main_unit */, die); m_index.ReportInvalidDIERef(ref, m_name); return true; } +bool DWARFIndex::DIEUIDCallbackImpl::operator()(user_id_t uid) const { + DWARFCompileUnit *main_unit; + if (DWARFDIE die = m_dwarf.GetDIEUnlocked(uid, &main_unit)) + return m_callback(main_unit, die); + m_index.ReportInvalidDIEUID(uid, m_name); + return true; +} + void DWARFIndex::ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const { m_module.ReportErrorIfModifyDetected( "the DWARF debug information has been modified (accelerator table had " - "bad die 0x%8.8x for '%s')\n", + "bad DIERef 0x%8.8x for '%s')\n", ref.die_offset(), name.str().c_str()); } + +void DWARFIndex::ReportInvalidDIEUID(user_id_t uid, + llvm::StringRef name) const { + m_module.ReportErrorIfModifyDetected( + "the DWARF debug information has been modified (accelerator table had " + "bad user_id_t 0x%8.8lx for '%s')\n", + uid, name.str().c_str()); +} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h @@ -137,6 +137,8 @@ return die_offset >= GetFirstDIEOffset() && die_offset < GetNextUnitOffset(); } + bool ContainsDIERef(DIERef die_ref) const; + bool ContainsUID(lldb::user_id_t uid) const; dw_offset_t GetFirstDIEOffset() const { return GetOffset() + GetHeaderByteSize(); } @@ -258,6 +260,8 @@ lldb_private::DWARFDataExtractor GetLocationData() const; + bool MainUnitIsValid(DWARFCompileUnit *main_unit); + protected: DWARFUnit(SymbolFileDWARF &dwarf, lldb::user_id_t uid, const DWARFUnitHeader &header, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -976,3 +976,38 @@ return llvm::createStringError(errc::invalid_argument, "missing or invalid range list table"); } + +bool DWARFUnit::ContainsDIERef(DIERef die_ref) const { + if (m_dwarf.GetDwoNum() != die_ref.dwo_num()) + return false; + if (m_section != die_ref.section()) + return false; + lldbassert(ContainsDIEOffset(die_ref.die_offset()) == + (GetOffset() <= die_ref.die_offset() && + die_ref.die_offset() < GetNextUnitOffset())); + return ContainsDIEOffset(die_ref.die_offset()); +} + +bool DWARFUnit::ContainsUID(user_id_t uid) const { + llvm::Optional decoded = + m_dwarf.DecodeUIDUnlocked(uid); + if (!decoded) + return false; + if (&decoded->dwarf != &m_dwarf) + return false; + // FIXME: DWZ: main_cu + return ContainsDIERef(decoded->ref); +} + +bool DWARFUnit::MainUnitIsValid(DWARFCompileUnit *main_unit) { + switch (GetUnitDIEOnly().Tag()) { + case DW_TAG_compile_unit: + return false; + case DW_TAG_partial_unit: + // FIXME: DWZ + lldbassert(0); + return true; + default: + return false; + } +} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h @@ -25,33 +25,47 @@ void Preload() override { m_fallback.Preload(); } - void - GetGlobalVariables(ConstString basename, - llvm::function_ref callback) override; - void - GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref callback) override; - void - GetGlobalVariables(const DWARFUnit &cu, - llvm::function_ref callback) override; - void - GetObjCMethods(ConstString class_name, - llvm::function_ref callback) override {} + void GetGlobalVariables( + ConstString basename, + llvm::function_ref + callback) override; + void GetGlobalVariables( + const RegularExpression ®ex, + llvm::function_ref + callback) override; + void GetGlobalVariables( + const DWARFUnit &cu, + llvm::function_ref + callback) override; + void GetObjCMethods( + ConstString class_name, + llvm::function_ref + callback) override {} void GetCompleteObjCClass( ConstString class_name, bool must_be_implementation, - llvm::function_ref callback) override; - void GetTypes(ConstString name, - llvm::function_ref callback) override; - void GetTypes(const DWARFDeclContext &context, - llvm::function_ref callback) override; - void GetNamespaces(ConstString name, - llvm::function_ref callback) override; - void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, - const CompilerDeclContext &parent_decl_ctx, - uint32_t name_type_mask, - llvm::function_ref callback) override; - void GetFunctions(const RegularExpression ®ex, - llvm::function_ref callback) override; + llvm::function_ref + callback) override; + void + GetTypes(ConstString name, + llvm::function_ref + callback) override; + void + GetTypes(const DWARFDeclContext &context, + llvm::function_ref + callback) override; + void GetNamespaces( + ConstString name, + llvm::function_ref + callback) override; + void GetFunctions( + ConstString name, SymbolFileDWARF &dwarf, + const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, + llvm::function_ref + callback) override; + void GetFunctions( + const RegularExpression ®ex, + llvm::function_ref + callback) override; void Dump(Stream &s) override; @@ -78,9 +92,11 @@ ManualDWARFIndex m_fallback; llvm::Optional ToDIERef(const DebugNames::Entry &entry); - bool ProcessEntry(const DebugNames::Entry &entry, - llvm::function_ref callback, - llvm::StringRef name); + bool ProcessEntry( + const DebugNames::Entry &entry, + llvm::function_ref + callback, + llvm::StringRef name); static void MaybeLogLookupError(llvm::Error error, const DebugNames::NameIndex &ni, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp @@ -60,7 +60,9 @@ bool DebugNamesDWARFIndex::ProcessEntry( const DebugNames::Entry &entry, - llvm::function_ref callback, llvm::StringRef name) { + llvm::function_ref + callback, + llvm::StringRef name) { llvm::Optional ref = ToDIERef(entry); if (!ref) return true; @@ -69,7 +71,8 @@ DWARFDIE die = dwarf.GetDIE(*ref); if (!die) return true; - return callback(die); + // FIXME: DWZ + return callback(nullptr /* main_unit */, die); } void DebugNamesDWARFIndex::MaybeLogLookupError(llvm::Error error, @@ -84,7 +87,9 @@ } void DebugNamesDWARFIndex::GetGlobalVariables( - ConstString basename, llvm::function_ref callback) { + ConstString basename, + llvm::function_ref + callback) { for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(basename.GetStringRef())) { if (entry.tag() != DW_TAG_variable) @@ -99,7 +104,8 @@ void DebugNamesDWARFIndex::GetGlobalVariables( const RegularExpression ®ex, - llvm::function_ref callback) { + llvm::function_ref + callback) { for (const DebugNames::NameIndex &ni: *m_debug_names_up) { for (DebugNames::NameTableEntry nte: ni) { if (!regex.Execute(nte.getString())) @@ -123,7 +129,9 @@ } void DebugNamesDWARFIndex::GetGlobalVariables( - const DWARFUnit &cu, llvm::function_ref callback) { + const DWARFUnit &cu, + llvm::function_ref + callback) { uint64_t cu_offset = cu.GetOffset(); for (const DebugNames::NameIndex &ni: *m_debug_names_up) { for (DebugNames::NameTableEntry nte: ni) { @@ -148,9 +156,11 @@ void DebugNamesDWARFIndex::GetCompleteObjCClass( ConstString class_name, bool must_be_implementation, - llvm::function_ref callback) { + llvm::function_ref + callback) { // Keep a list of incomplete types as fallback for when we don't find the // complete type. + // FIXME: DWZ DIEArray incomplete_types; for (const DebugNames::Entry &entry : @@ -177,12 +187,14 @@ if (die.GetAttributeValueAsUnsigned(DW_AT_APPLE_objc_complete_type, 0)) { // If we find the complete version we're done. - callback(die); + // FIXME: DWZ + callback(nullptr /* main_unit */, die); return; } incomplete_types.push_back(*ref); } + // FIXME: DWZ auto dierefcallback = DIERefCallback(callback, class_name.GetStringRef()); for (DIERef ref : incomplete_types) if (!dierefcallback(ref)) @@ -192,7 +204,9 @@ } void DebugNamesDWARFIndex::GetTypes( - ConstString name, llvm::function_ref callback) { + ConstString name, + llvm::function_ref + callback) { for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(name.GetStringRef())) { if (isType(entry.tag())) { @@ -206,7 +220,8 @@ void DebugNamesDWARFIndex::GetTypes( const DWARFDeclContext &context, - llvm::function_ref callback) { + llvm::function_ref + callback) { auto name = context[0].name; for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(name)) { if (entry.tag() == context[0].tag) { @@ -219,7 +234,9 @@ } void DebugNamesDWARFIndex::GetNamespaces( - ConstString name, llvm::function_ref callback) { + ConstString name, + llvm::function_ref + callback) { for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(name.GetStringRef())) { if (entry.tag() == DW_TAG_namespace) { @@ -234,8 +251,10 @@ void DebugNamesDWARFIndex::GetFunctions( ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - llvm::function_ref callback) { + llvm::function_ref + callback) { + // FIXME: DWZ std::set seen; for (const DebugNames::Entry &entry : m_debug_names_up->equal_range(name.GetStringRef())) { @@ -244,12 +263,17 @@ continue; if (llvm::Optional ref = ToDIERef(entry)) { - if (!ProcessFunctionDIE(name.GetStringRef(), *ref, dwarf, parent_decl_ctx, - name_type_mask, [&](DWARFDIE die) { - if (!seen.insert(die.GetDIE()).second) - return true; - return callback(die); - })) + // FIXME: DWZ + DWARFCompileUnit *main_unit = nullptr; + if (!ProcessFunctionDIE( + name.GetStringRef(), main_unit, *ref, dwarf, parent_decl_ctx, + name_type_mask, + [&](DWARFCompileUnit *main_unit_check, DWARFDIE die) { + lldbassert(main_unit_check == main_unit); + if (!seen.insert(die.GetDIE()).second) + return true; + return callback(main_unit, die); + })) return; } } @@ -260,7 +284,8 @@ void DebugNamesDWARFIndex::GetFunctions( const RegularExpression ®ex, - llvm::function_ref callback) { + llvm::function_ref + callback) { for (const DebugNames::NameIndex &ni: *m_debug_names_up) { for (DebugNames::NameTableEntry nte: ni) { if (!regex.Execute(nte.getString())) 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 @@ -16,6 +16,7 @@ #include "lldb/Utility/RegularExpression.h" #include "lldb/lldb-defines.h" +#include "DIERef.h" #include "DWARFDefines.h" #include "DWARFFormValue.h" #include "NameToDIE.h" diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h @@ -26,32 +26,47 @@ void Preload() override { Index(); } - void - GetGlobalVariables(ConstString basename, - llvm::function_ref callback) override; - void - GetGlobalVariables(const RegularExpression ®ex, - llvm::function_ref callback) override; - void - GetGlobalVariables(const DWARFUnit &unit, - llvm::function_ref callback) override; - void GetObjCMethods(ConstString class_name, - llvm::function_ref callback) override; + void GetGlobalVariables( + ConstString basename, + llvm::function_ref + callback) override; + void GetGlobalVariables( + const RegularExpression ®ex, + llvm::function_ref + callback) override; + void GetGlobalVariables( + const DWARFUnit &unit, + llvm::function_ref + callback) override; + void GetObjCMethods( + ConstString class_name, + llvm::function_ref + callback) override; void GetCompleteObjCClass( ConstString class_name, bool must_be_implementation, - llvm::function_ref callback) override; - void GetTypes(ConstString name, - llvm::function_ref callback) override; - void GetTypes(const DWARFDeclContext &context, - llvm::function_ref callback) override; - void GetNamespaces(ConstString name, - llvm::function_ref callback) override; - void GetFunctions(ConstString name, SymbolFileDWARF &dwarf, - const CompilerDeclContext &parent_decl_ctx, - uint32_t name_type_mask, - llvm::function_ref callback) override; - void GetFunctions(const RegularExpression ®ex, - llvm::function_ref callback) override; + llvm::function_ref + callback) override; + void + GetTypes(ConstString name, + llvm::function_ref + callback) override; + void + GetTypes(const DWARFDeclContext &context, + llvm::function_ref + callback) override; + void GetNamespaces( + ConstString name, + llvm::function_ref + callback) override; + void GetFunctions( + ConstString name, SymbolFileDWARF &dwarf, + const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, + llvm::function_ref + callback) override; + void GetFunctions( + const RegularExpression ®ex, + llvm::function_ref + callback) override; void Dump(Stream &s) override; @@ -69,7 +84,7 @@ void Index(); void IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp, IndexSet &set); - static void IndexUnitImpl(DWARFUnit &unit, + static void IndexUnitImpl(DWARFUnit &unit, DWARFCompileUnit *main_unit, const lldb::LanguageType cu_language, IndexSet &set); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -8,6 +8,7 @@ #include "Plugins/SymbolFile/DWARF/ManualDWARFIndex.h" #include "Plugins/Language/ObjC/ObjCLanguage.h" +#include "Plugins/SymbolFile/DWARF/DWARFCompileUnit.h" #include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h" #include "Plugins/SymbolFile/DWARF/DWARFDeclContext.h" #include "Plugins/SymbolFile/DWARF/LogChannelDWARF.h" @@ -122,24 +123,26 @@ } const LanguageType cu_language = SymbolFileDWARF::GetLanguage(unit); + DWARFCompileUnit *main_unit = llvm::dyn_cast(&unit); - IndexUnitImpl(unit, cu_language, set); + IndexUnitImpl(unit, main_unit, cu_language, set); if (SymbolFileDWARFDwo *dwo_symbol_file = unit.GetDwoSymbolFile()) { // Type units in a dwp file are indexed separately, so we just need to // process the split unit here. However, if the split unit is in a dwo file, // then we need to process type units here. if (dwo_symbol_file == dwp) { - IndexUnitImpl(unit.GetNonSkeletonUnit(), cu_language, set); + IndexUnitImpl(unit.GetNonSkeletonUnit(), main_unit, cu_language, set); } else { DWARFDebugInfo &dwo_info = dwo_symbol_file->DebugInfo(); for (size_t i = 0; i < dwo_info.GetNumUnits(); ++i) - IndexUnitImpl(*dwo_info.GetUnitAtIndex(i), cu_language, set); + IndexUnitImpl(*dwo_info.GetUnitAtIndex(i), main_unit, cu_language, set); } } } void ManualDWARFIndex::IndexUnitImpl(DWARFUnit &unit, + DWARFCompileUnit *main_unit, const LanguageType cu_language, IndexSet &set) { for (const DWARFDebugInfoEntry &die : unit.dies()) { @@ -224,7 +227,7 @@ } } - DIERef ref = *DWARFDIE(&unit, &die).GetDIERef(); + user_id_t uid = DWARFDIE(&unit, &die).GetID(main_unit); switch (tag) { case DW_TAG_inlined_subroutine: case DW_TAG_subprogram: @@ -242,17 +245,17 @@ ConstString objc_fullname_no_category_name( objc_method.GetFullNameWithoutCategory(true)); ConstString class_name_no_category(objc_method.GetClassName()); - set.function_fullnames.Insert(ConstString(name), ref); + set.function_fullnames.Insert(ConstString(name), uid); if (class_name_with_category) - set.objc_class_selectors.Insert(class_name_with_category, ref); + set.objc_class_selectors.Insert(class_name_with_category, uid); if (class_name_no_category && class_name_no_category != class_name_with_category) - set.objc_class_selectors.Insert(class_name_no_category, ref); + set.objc_class_selectors.Insert(class_name_no_category, uid); if (objc_selector_name) - set.function_selectors.Insert(objc_selector_name, ref); + set.function_selectors.Insert(objc_selector_name, uid); if (objc_fullname_no_category_name) set.function_fullnames.Insert(objc_fullname_no_category_name, - ref); + uid); } } // If we have a mangled name, then the DW_AT_name attribute is @@ -260,12 +263,12 @@ bool is_method = DWARFDIE(&unit, &die).IsMethod(); if (is_method) - set.function_methods.Insert(ConstString(name), ref); + set.function_methods.Insert(ConstString(name), uid); else - set.function_basenames.Insert(ConstString(name), ref); + set.function_basenames.Insert(ConstString(name), uid); if (!is_method && !mangled_cstr && !is_objc_method) - set.function_fullnames.Insert(ConstString(name), ref); + set.function_fullnames.Insert(ConstString(name), uid); } if (mangled_cstr) { // Make sure our mangled name isn't the same string table entry as @@ -275,7 +278,7 @@ if (name && name != mangled_cstr && ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0))) { - set.function_fullnames.Insert(ConstString(mangled_cstr), ref); + set.function_fullnames.Insert(ConstString(mangled_cstr), uid); } } } @@ -293,19 +296,19 @@ case DW_TAG_union_type: case DW_TAG_unspecified_type: if (name && !is_declaration) - set.types.Insert(ConstString(name), ref); + set.types.Insert(ConstString(name), uid); if (mangled_cstr && !is_declaration) - set.types.Insert(ConstString(mangled_cstr), ref); + set.types.Insert(ConstString(mangled_cstr), uid); break; case DW_TAG_namespace: if (name) - set.namespaces.Insert(ConstString(name), ref); + set.namespaces.Insert(ConstString(name), uid); break; case DW_TAG_variable: if (name && has_location_or_const_value && is_global_or_static_variable) { - set.globals.Insert(ConstString(name), ref); + set.globals.Insert(ConstString(name), uid); // Be sure to include variables by their mangled and demangled names if // they have any since a variable can have a basename "i", a mangled // named "_ZN12_GLOBAL__N_11iE" and a demangled mangled name @@ -317,7 +320,7 @@ // entries if (mangled_cstr && name != mangled_cstr && ((mangled_cstr[0] == '_') || (::strcmp(name, mangled_cstr) != 0))) { - set.globals.Insert(ConstString(mangled_cstr), ref); + set.globals.Insert(ConstString(mangled_cstr), uid); } } break; @@ -329,87 +332,101 @@ } void ManualDWARFIndex::GetGlobalVariables( - ConstString basename, llvm::function_ref callback) { + ConstString basename, + llvm::function_ref + callback) { Index(); m_set.globals.Find(basename, - DIERefCallback(callback, basename.GetStringRef())); + DIEUIDCallback(callback, basename.GetStringRef())); } void ManualDWARFIndex::GetGlobalVariables( const RegularExpression ®ex, - llvm::function_ref callback) { + llvm::function_ref + callback) { Index(); - m_set.globals.Find(regex, DIERefCallback(callback, regex.GetText())); + m_set.globals.Find(regex, DIEUIDCallback(callback, regex.GetText())); } void ManualDWARFIndex::GetGlobalVariables( - const DWARFUnit &unit, llvm::function_ref callback) { + const DWARFUnit &unit, + llvm::function_ref + callback) { Index(); - m_set.globals.FindAllEntriesForUnit(unit, DIERefCallback(callback)); + m_set.globals.FindAllEntriesForUnit(unit, DIEUIDCallback(callback)); } void ManualDWARFIndex::GetObjCMethods( - ConstString class_name, llvm::function_ref callback) { + ConstString class_name, + llvm::function_ref + callback) { Index(); m_set.objc_class_selectors.Find( - class_name, DIERefCallback(callback, class_name.GetStringRef())); + class_name, DIEUIDCallback(callback, class_name.GetStringRef())); } void ManualDWARFIndex::GetCompleteObjCClass( ConstString class_name, bool must_be_implementation, - llvm::function_ref callback) { + llvm::function_ref + callback) { Index(); m_set.types.Find(class_name, - DIERefCallback(callback, class_name.GetStringRef())); + DIEUIDCallback(callback, class_name.GetStringRef())); } void ManualDWARFIndex::GetTypes( - ConstString name, llvm::function_ref callback) { + ConstString name, + llvm::function_ref + callback) { Index(); - m_set.types.Find(name, DIERefCallback(callback, name.GetStringRef())); + m_set.types.Find(name, DIEUIDCallback(callback, name.GetStringRef())); } void ManualDWARFIndex::GetTypes( const DWARFDeclContext &context, - llvm::function_ref callback) { + llvm::function_ref + callback) { Index(); auto name = context[0].name; m_set.types.Find(ConstString(name), - DIERefCallback(callback, llvm::StringRef(name))); + DIEUIDCallback(callback, llvm::StringRef(name))); } void ManualDWARFIndex::GetNamespaces( - ConstString name, llvm::function_ref callback) { + ConstString name, + llvm::function_ref + callback) { Index(); - m_set.namespaces.Find(name, DIERefCallback(callback, name.GetStringRef())); + m_set.namespaces.Find(name, DIEUIDCallback(callback, name.GetStringRef())); } void ManualDWARFIndex::GetFunctions( ConstString name, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, uint32_t name_type_mask, - llvm::function_ref callback) { + llvm::function_ref + callback) { Index(); if (name_type_mask & eFunctionNameTypeFull) { if (!m_set.function_fullnames.Find( - name, DIERefCallback( - [&](DWARFDIE die) { + name, DIEUIDCallback( + [&](DWARFCompileUnit *main_unit, DWARFDIE die) { if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, - die)) + main_unit, die)) return true; - return callback(die); + return callback(main_unit, die); }, name.GetStringRef()))) return; } if (name_type_mask & eFunctionNameTypeBase) { if (!m_set.function_basenames.Find( - name, DIERefCallback( - [&](DWARFDIE die) { + name, DIEUIDCallback( + [&](DWARFCompileUnit *main_unit, DWARFDIE die) { if (!SymbolFileDWARF::DIEInDeclContext(parent_decl_ctx, - die)) + main_unit, die)) return true; - return callback(die); + return callback(main_unit, die); }, name.GetStringRef()))) return; @@ -417,28 +434,29 @@ if (name_type_mask & eFunctionNameTypeMethod && !parent_decl_ctx.IsValid()) { if (!m_set.function_methods.Find( - name, DIERefCallback(callback, name.GetStringRef()))) + name, DIEUIDCallback(callback, name.GetStringRef()))) return; } if (name_type_mask & eFunctionNameTypeSelector && !parent_decl_ctx.IsValid()) { if (!m_set.function_selectors.Find( - name, DIERefCallback(callback, name.GetStringRef()))) + name, DIEUIDCallback(callback, name.GetStringRef()))) return; } } void ManualDWARFIndex::GetFunctions( const RegularExpression ®ex, - llvm::function_ref callback) { + llvm::function_ref + callback) { Index(); if (!m_set.function_basenames.Find(regex, - DIERefCallback(callback, regex.GetText()))) + DIEUIDCallback(callback, regex.GetText()))) return; if (!m_set.function_fullnames.Find(regex, - DIERefCallback(callback, regex.GetText()))) + DIEUIDCallback(callback, regex.GetText()))) return; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h --- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h @@ -11,7 +11,6 @@ #include -#include "DIERef.h" #include "lldb/Core/UniqueCStringMap.h" #include "lldb/Core/dwarf.h" #include "lldb/lldb-defines.h" @@ -26,29 +25,27 @@ void Dump(lldb_private::Stream *s); - void Insert(lldb_private::ConstString name, const DIERef &die_ref); + void Insert(lldb_private::ConstString name, lldb::user_id_t uid); void Append(const NameToDIE &other); void Finalize(); bool Find(lldb_private::ConstString name, - llvm::function_ref callback) const; + llvm::function_ref callback) const; bool Find(const lldb_private::RegularExpression ®ex, - llvm::function_ref callback) const; + llvm::function_ref callback) const; - void - FindAllEntriesForUnit(const DWARFUnit &unit, - llvm::function_ref callback) const; + void FindAllEntriesForUnit( + const DWARFUnit &unit, + llvm::function_ref callback) const; - void - ForEach(std::function const - &callback) const; + void ForEach(std::function const &callback) const; protected: - lldb_private::UniqueCStringMap m_map; + lldb_private::UniqueCStringMap m_map; }; #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_NAMETODIE_H diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp @@ -22,12 +22,12 @@ m_map.SizeToFit(); } -void NameToDIE::Insert(ConstString name, const DIERef &die_ref) { - m_map.Append(name, die_ref); +void NameToDIE::Insert(ConstString name, user_id_t uid) { + m_map.Append(name, uid); } bool NameToDIE::Find(ConstString name, - llvm::function_ref callback) const { + llvm::function_ref callback) const { for (const auto &entry : m_map.equal_range(name)) if (!callback(entry.value)) return false; @@ -35,7 +35,7 @@ } bool NameToDIE::Find(const RegularExpression ®ex, - llvm::function_ref callback) const { + llvm::function_ref callback) const { for (const auto &entry : m_map) if (regex.Execute(entry.cstring.GetCString())) { if (!callback(entry.value)) @@ -46,31 +46,35 @@ void NameToDIE::FindAllEntriesForUnit( const DWARFUnit &unit, - llvm::function_ref callback) const { + llvm::function_ref callback) const { const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { - const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i); - if (unit.GetSymbolFileDWARF().GetDwoNum() == die_ref.dwo_num() && - unit.GetDebugSection() == die_ref.section() && - unit.GetOffset() <= die_ref.die_offset() && - die_ref.die_offset() < unit.GetNextUnitOffset()) { - if (!callback(die_ref)) + user_id_t uid = m_map.GetValueAtIndexUnchecked(i); + if (unit.ContainsUID(uid)) { + if (!callback(uid)) return; } } } void NameToDIE::Dump(Stream *s) { + llvm::raw_ostream &OS = s->AsRawOstream(); const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { - s->Format("{0} \"{1}\"\n", m_map.GetValueAtIndexUnchecked(i), - m_map.GetCStringAtIndexUnchecked(i)); + user_id_t uid = m_map.GetValueAtIndexUnchecked(i); + uint32_t upper = (uid >> 32) & 0x1fffffff; + if (upper != 0x1fffffff) + OS << llvm::format_hex_no_prefix(upper, 8) << "/"; + OS << (uid & (1ULL << 63) ? "TYPE" : "INFO"); + // FIXME: DWZ + OS << "/" << llvm::format_hex_no_prefix(uid & 0xffffffff, 8) << " \"" + << m_map.GetCStringAtIndexUnchecked(i).GetStringRef() << "\"\n"; } } void NameToDIE::ForEach( - std::function const - &callback) const { + std::function const &callback) + const { const uint32_t size = m_map.GetSize(); for (uint32_t i = 0; i < size; ++i) { if (!callback(m_map.GetCStringAtIndexUnchecked(i), diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -139,7 +139,8 @@ bool CompleteType(lldb_private::CompilerType &compiler_type) override; - lldb_private::Type *ResolveType(const DWARFDIE &die, + lldb_private::Type *ResolveType(DWARFCompileUnit *main_unit, + const DWARFDIE &die, bool assert_not_being_parsed = true, bool resolve_function_context = false); @@ -237,8 +238,10 @@ lldb_private::CompileUnit * GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu); - virtual void GetObjCMethods(lldb_private::ConstString class_name, - llvm::function_ref callback); + virtual void GetObjCMethods( + lldb_private::ConstString class_name, + llvm::function_ref + callback); bool Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu); @@ -260,15 +263,17 @@ DWARFDIE GetDIE(lldb::user_id_t uid); - lldb::user_id_t GetUID(const DWARFBaseDIE &die) { - return GetUID(die.GetDIERef()); - } + DWARFDIE GetDIEUnlocked(lldb::user_id_t uid, + DWARFCompileUnit **main_unit_return = nullptr); + + lldb::user_id_t GetUID(DWARFCompileUnit *main_unit, const DWARFDIE &die); - lldb::user_id_t GetUID(const llvm::Optional &ref) { - return ref ? GetUID(*ref) : LLDB_INVALID_UID; + lldb::user_id_t GetUID(DWARFCompileUnit *main_unit, + const llvm::Optional &ref) { + return ref ? GetUID(main_unit, *ref) : LLDB_INVALID_UID; } - lldb::user_id_t GetUID(DIERef ref); + lldb::user_id_t GetUID(DWARFCompileUnit *main_unit, DIERef ref); std::shared_ptr GetDwoSymbolFileForCompileUnit(DWARFUnit &dwarf_cu, @@ -281,7 +286,7 @@ static bool DIEInDeclContext(const lldb_private::CompilerDeclContext &parent_decl_ctx, - const DWARFDIE &die); + DWARFCompileUnit *main_unit, const DWARFDIE &die); std::vector> ParseCallEdgesInFunction(UserID func_id) override; @@ -303,12 +308,14 @@ // CompilerDecl related functions - static lldb_private::CompilerDecl GetDecl(const DWARFDIE &die); + static lldb_private::CompilerDecl GetDecl(DWARFCompileUnit *main_unit, + const DWARFDIE &die); - static lldb_private::CompilerDeclContext GetDeclContext(const DWARFDIE &die); + static lldb_private::CompilerDeclContext + GetDeclContext(DWARFCompileUnit *main_unit, const DWARFDIE &die); static lldb_private::CompilerDeclContext - GetContainingDeclContext(const DWARFDIE &die); + GetContainingDeclContext(DWARFCompileUnit *main_unit, const DWARFDIE &die); static DWARFDeclContext GetDWARFDeclContext(const DWARFDIE &die); @@ -316,15 +323,28 @@ static lldb::LanguageType GetLanguage(DWARFUnit &unit); + struct DecodedUID { + SymbolFileDWARF &dwarf; + DIERef ref; + // FIXME: DWZ: uint32_t main_cu = 0xffffffff + }; + llvm::Optional DecodeUIDUnlocked(lldb::user_id_t uid); + protected: - typedef llvm::DenseMap + typedef llvm::DenseMap< + std::pair, + lldb_private::Type *> DIEToTypePtr; - typedef llvm::DenseMap + typedef llvm::DenseMap< + std::pair, + lldb::VariableSP> DIEToVariableSP; - typedef llvm::DenseMap + typedef llvm::DenseMap< + std::pair, + lldb::opaque_compiler_type_t> DIEToClangType; - typedef llvm::DenseMap ClangTypeToDIE; + typedef llvm::DenseMap + ClangTypeToDIE; DISALLOW_COPY_AND_ASSIGN(SymbolFileDWARF); @@ -342,12 +362,12 @@ lldb::CompUnitSP ParseCompileUnit(DWARFCompileUnit &dwarf_cu); - virtual DWARFUnit * - GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit); + DWARFCompileUnit *GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit); DWARFUnit *GetNextUnparsedDWARFCompileUnit(DWARFUnit *prev_cu); - bool GetFunction(const DWARFDIE &die, lldb_private::SymbolContext &sc); + bool GetFunction(DWARFCompileUnit *main_unit, const DWARFDIE &die, + lldb_private::SymbolContext &sc); lldb_private::Function *ParseFunction(lldb_private::CompileUnit &comp_unit, const DWARFDIE &die); @@ -363,10 +383,12 @@ lldb::TypeSP ParseType(const lldb_private::SymbolContext &sc, const DWARFDIE &die, bool *type_is_new); - lldb_private::Type *ResolveTypeUID(const DWARFDIE &die, + lldb_private::Type *ResolveTypeUID(DWARFCompileUnit *main_unit, + const DWARFDIE &die, bool assert_not_being_parsed); - lldb_private::Type *ResolveTypeUID(const DIERef &die_ref); + lldb_private::Type *ResolveTypeUID(DWARFCompileUnit *main_unit, + const DIERef &die_ref); lldb::VariableSP ParseVariableDIE(const lldb_private::SymbolContext &sc, const DWARFDIE &die, @@ -381,7 +403,8 @@ bool ClassOrStructIsVirtual(const DWARFDIE &die); // Given a die_offset, figure out the symbol context representing that die. - bool ResolveFunction(const DWARFDIE &die, bool include_inlines, + bool ResolveFunction(DWARFCompileUnit *main_unit, const DWARFDIE &die, + bool include_inlines, lldb_private::SymbolContextList &sc_list); /// Resolve functions and (possibly) blocks for the given file address and a @@ -401,7 +424,7 @@ lldb_private::Symbol * GetObjCClassSymbol(lldb_private::ConstString objc_class_name); - lldb::TypeSP GetTypeForDIE(const DWARFDIE &die, + lldb::TypeSP GetTypeForDIE(DWARFCompileUnit *main_unit, const DWARFDIE &die, bool resolve_function_context = false); void SetDebugMapModule(const lldb::ModuleSP &module_sp) { @@ -441,9 +464,9 @@ typedef llvm::SetVector TypeSet; - void GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset, - dw_offset_t max_die_offset, uint32_t type_mask, - TypeSet &type_set); + void GetTypes(DWARFCompileUnit *main_unit, const DWARFDIE &die, + dw_offset_t min_die_offset, dw_offset_t max_die_offset, + uint32_t type_mask, TypeSet &type_set); typedef lldb_private::RangeDataVector @@ -468,10 +491,6 @@ void BuildCuTranslationTable(); llvm::Optional GetDWARFUnitIndex(uint32_t cu_idx); - struct DecodedUID { - SymbolFileDWARF &dwarf; - DIERef ref; - }; llvm::Optional DecodeUID(lldb::user_id_t uid); void FindDwpSymbolFile(); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -265,7 +265,8 @@ return debug_map_symfile->GetTypeList(); return SymbolFile::GetTypeList(); } -void SymbolFileDWARF::GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset, +void SymbolFileDWARF::GetTypes(DWARFCompileUnit *main_unit, const DWARFDIE &die, + dw_offset_t min_die_offset, dw_offset_t max_die_offset, uint32_t type_mask, TypeSet &type_set) { if (die) { @@ -323,7 +324,7 @@ if (add_type) { const bool assert_not_being_parsed = true; - Type *type = ResolveTypeUID(die, assert_not_being_parsed); + Type *type = ResolveTypeUID(main_unit, die, assert_not_being_parsed); if (type) type_set.insert(type); } @@ -331,7 +332,8 @@ for (DWARFDIE child_die = die.GetFirstChild(); child_die.IsValid(); child_die = child_die.GetSibling()) { - GetTypes(child_die, min_die_offset, max_die_offset, type_mask, type_set); + GetTypes(main_unit, child_die, min_die_offset, max_die_offset, type_mask, + type_set); } } } @@ -344,23 +346,23 @@ TypeSet type_set; CompileUnit *comp_unit = nullptr; - DWARFUnit *dwarf_cu = nullptr; if (sc_scope) comp_unit = sc_scope->CalculateSymbolContextCompileUnit(); if (comp_unit) { - dwarf_cu = GetDWARFCompileUnit(comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit); if (!dwarf_cu) return; - GetTypes(dwarf_cu->DIE(), dwarf_cu->GetOffset(), + GetTypes(dwarf_cu, dwarf_cu->DIE(), dwarf_cu->GetOffset(), dwarf_cu->GetNextUnitOffset(), type_mask, type_set); } else { DWARFDebugInfo &info = DebugInfo(); const size_t num_cus = info.GetNumUnits(); for (size_t cu_idx = 0; cu_idx < num_cus; ++cu_idx) { - dwarf_cu = info.GetUnitAtIndex(cu_idx); + DWARFCompileUnit *dwarf_cu = + llvm::dyn_cast_or_null(info.GetUnitAtIndex(cu_idx)); if (dwarf_cu) - GetTypes(dwarf_cu->DIE(), 0, UINT32_MAX, type_mask, type_set); + GetTypes(dwarf_cu, dwarf_cu->DIE(), 0, UINT32_MAX, type_mask, type_set); } } @@ -445,9 +447,9 @@ LoadSectionData(eSectionTypeDWARFAppleTypes, apple_types); LoadSectionData(eSectionTypeDWARFAppleObjC, apple_objc); - m_index = AppleDWARFIndex::Create( - *GetObjectFile()->GetModule(), apple_names, apple_namespaces, - apple_types, apple_objc, m_context.getOrLoadStrData()); + m_index = AppleDWARFIndex::Create(*this, apple_names, apple_namespaces, + apple_types, apple_objc, + m_context.getOrLoadStrData()); if (m_index) return; @@ -604,16 +606,24 @@ return *m_info; } -DWARFUnit * +DWARFCompileUnit * SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) { if (!comp_unit) return nullptr; + if (SymbolFileDWARFDwo *dwo = llvm::dyn_cast(this)) + return dwo->GetBaseSymbolFile().GetDWARFCompileUnit(comp_unit); + // The compile unit ID is the index of the DWARF unit. DWARFUnit *dwarf_cu = DebugInfo().GetUnitAtIndex(comp_unit->GetID()); - if (dwarf_cu && dwarf_cu->GetUserData() == nullptr) + if (!dwarf_cu) + return nullptr; + + if (dwarf_cu->GetUserData() == nullptr) dwarf_cu->SetUserData(comp_unit); - return dwarf_cu; + else + lldbassert(dwarf_cu->GetUserData() == comp_unit); + return llvm::cast(dwarf_cu); } DWARFDebugRanges *SymbolFileDWARF::GetDebugRanges() { @@ -771,7 +781,7 @@ } lldb::LanguageType SymbolFileDWARF::ParseLanguage(CompileUnit &comp_unit) { std::lock_guard guard(GetModuleMutex()); - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); if (dwarf_cu) return GetLanguage(*dwarf_cu); else @@ -782,7 +792,7 @@ static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); Timer scoped_timer(func_cat, "SymbolFileDWARF::ParseFunctions"); std::lock_guard guard(GetModuleMutex()); - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); if (!dwarf_cu) return 0; @@ -793,7 +803,7 @@ continue; DWARFDIE die(dwarf_cu, &entry); - if (comp_unit.FindFunctionByUID(die.GetID())) + if (comp_unit.FindFunctionByUID(die.GetID(dwarf_cu))) continue; if (ParseFunction(comp_unit, die)) ++functions_added; @@ -886,7 +896,7 @@ bool SymbolFileDWARF::ParseIsOptimized(CompileUnit &comp_unit) { std::lock_guard guard(GetModuleMutex()); - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); if (dwarf_cu) return dwarf_cu->GetIsOptimized(); return false; @@ -897,7 +907,7 @@ std::vector &imported_modules) { std::lock_guard guard(GetModuleMutex()); assert(sc.comp_unit); - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit); if (!dwarf_cu) return false; if (!ClangModulesDeclVendor::LanguageSupportsClangModules( @@ -952,7 +962,7 @@ if (comp_unit.GetLineTable() != nullptr) return true; - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); if (!dwarf_cu) return false; @@ -1034,7 +1044,7 @@ bool SymbolFileDWARF::ParseDebugMacros(CompileUnit &comp_unit) { std::lock_guard guard(GetModuleMutex()); - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); if (dwarf_cu == nullptr) return false; @@ -1078,7 +1088,8 @@ block = parent_block; } else { - BlockSP block_sp(new Block(die.GetID())); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + BlockSP block_sp(new Block(die.GetID(dwarf_cu))); parent_block->AddChild(block_sp); block = block_sp.get(); } @@ -1204,20 +1215,50 @@ decl_ctx); } -user_id_t SymbolFileDWARF::GetUID(DIERef ref) { +user_id_t SymbolFileDWARF::GetUID(DWARFCompileUnit *main_unit, + const DWARFDIE &die) { + if (!die.MainUnitIsValid(main_unit)) + main_unit = nullptr; + return GetUID(die.MainDWARFCompileUnit(main_unit), die.GetDIERef()); +} + +user_id_t SymbolFileDWARF::GetUID(DWARFCompileUnit *main_unit, DIERef ref) { if (GetDebugMapSymfile()) return GetID() | ref.die_offset(); - return user_id_t(GetDwoNum().getValueOr(0x7fffffff)) << 32 | - ref.die_offset() | - (lldb::user_id_t(ref.section() == DIERef::Section::DebugTypes) << 63); + // FIXME: Expensive + DWARFDIE dwarfdie_check = GetDIE(ref); + lldbassert(dwarfdie_check.IsValid()); + lldbassert(*dwarfdie_check.GetDIERef() == ref); + + // WARNING: Use ref.dwo_num(), GetDwoNum() may not be valid in 'this'. + bool has_main_cu = + main_unit && (&main_unit->GetSymbolFileDWARF() != this || + !main_unit->ContainsDIEOffset(ref.die_offset())); + bool is_dwz = has_main_cu && !ref.dwo_num().hasValue(); + bool is_dwz_common = is_dwz && &main_unit->GetSymbolFileDWARF() != this; + lldbassert(!ref.dwo_num().hasValue() || *ref.dwo_num() < 0x1fffffff); + static_assert(sizeof(ref.die_offset()) * 8 == 32, ""); + + user_id_t retval = + user_id_t(is_dwz ? main_unit->GetID() + : ref.dwo_num().getValueOr(0x1fffffff)) + << 32 | + ref.die_offset() | user_id_t(is_dwz_common) << 61 | + user_id_t(is_dwz) << 62 | + (lldb::user_id_t(ref.section() == DIERef::Section::DebugTypes) << 63); + + // FIXME: Expensive + DWARFCompileUnit *main_unit_check; + lldbassert(GetDIEUnlocked(retval, &main_unit_check) == dwarfdie_check); + lldbassert(main_unit_check == main_unit || main_unit_check == nullptr); + lldbassert(!!main_unit_check == is_dwz); + + return retval; } llvm::Optional -SymbolFileDWARF::DecodeUID(lldb::user_id_t uid) { - // This method can be called without going through the symbol vendor so we - // need to lock the module. - std::lock_guard guard(GetModuleMutex()); +SymbolFileDWARF::DecodeUIDUnlocked(lldb::user_id_t uid) { // Anytime we get a "lldb::user_id_t" from an lldb_private::SymbolFile API we // must make sure we use the correct DWARF file when resolving things. On // MacOSX, when using SymbolFileDWARFDebugMap, we will use multiple @@ -1238,27 +1279,51 @@ DIERef::Section section = uid >> 63 ? DIERef::Section::DebugTypes : DIERef::Section::DebugInfo; - llvm::Optional dwo_num = uid >> 32 & 0x7fffffff; - if (*dwo_num == 0x7fffffff) + // FIXME: DWZ + + llvm::Optional dwo_num = uid >> 32 & 0x1fffffff; + if (*dwo_num == 0x1fffffff) dwo_num = llvm::None; return DecodedUID{*this, {dwo_num, section, die_offset}}; + // FIXME: DWZ: main_cu } -DWARFDIE -SymbolFileDWARF::GetDIE(lldb::user_id_t uid) { +llvm::Optional +SymbolFileDWARF::DecodeUID(lldb::user_id_t uid) { // This method can be called without going through the symbol vendor so we // need to lock the module. std::lock_guard guard(GetModuleMutex()); - llvm::Optional decoded = DecodeUID(uid); + return DecodeUIDUnlocked(uid); +} - if (decoded) - return decoded->dwarf.GetDIE(decoded->ref); +DWARFDIE +SymbolFileDWARF::GetDIEUnlocked(lldb::user_id_t uid, + DWARFCompileUnit **main_unit_return) { + llvm::Optional decoded = DecodeUIDUnlocked(uid); + + if (decoded) { + DWARFDIE die = decoded->dwarf.GetDIE(decoded->ref); + if (main_unit_return) { + // FIXME: DWZ + *main_unit_return = nullptr; + } + return die; + } return DWARFDIE(); } +DWARFDIE +SymbolFileDWARF::GetDIE(lldb::user_id_t uid) { + // This method can be called without going through the symbol vendor so we + // need to lock the module. + std::lock_guard guard(GetModuleMutex()); + + return GetDIEUnlocked(uid); +} + CompilerDecl SymbolFileDWARF::GetDeclForUID(lldb::user_id_t type_uid) { // This method can be called without going through the symbol vendor so we // need to lock the module. @@ -1266,8 +1331,9 @@ // Anytime we have a lldb::user_id_t, we must get the DIE by calling // SymbolFileDWARF::GetDIE(). See comments inside the // SymbolFileDWARF::GetDIE() for details. - if (DWARFDIE die = GetDIE(type_uid)) - return GetDecl(die); + DWARFCompileUnit *main_unit; + if (DWARFDIE die = GetDIEUnlocked(type_uid, &main_unit)) + return GetDecl(main_unit, die); return CompilerDecl(); } @@ -1279,8 +1345,9 @@ // Anytime we have a lldb::user_id_t, we must get the DIE by calling // SymbolFileDWARF::GetDIE(). See comments inside the // SymbolFileDWARF::GetDIE() for details. - if (DWARFDIE die = GetDIE(type_uid)) - return GetDeclContext(die); + DWARFCompileUnit *main_unit; + if (DWARFDIE die = GetDIEUnlocked(type_uid, &main_unit)) + return GetDeclContext(main_unit, die); return CompilerDeclContext(); } @@ -1290,8 +1357,9 @@ // Anytime we have a lldb::user_id_t, we must get the DIE by calling // SymbolFileDWARF::GetDIE(). See comments inside the // SymbolFileDWARF::GetDIE() for details. - if (DWARFDIE die = GetDIE(type_uid)) - return GetContainingDeclContext(die); + DWARFCompileUnit *main_unit; + if (DWARFDIE die = GetDIEUnlocked(type_uid, &main_unit)) + return GetContainingDeclContext(main_unit, die); return CompilerDeclContext(); } @@ -1300,8 +1368,9 @@ // Anytime we have a lldb::user_id_t, we must get the DIE by calling // SymbolFileDWARF::GetDIE(). See comments inside the // SymbolFileDWARF::GetDIE() for details. - if (DWARFDIE type_die = GetDIE(type_uid)) - return type_die.ResolveType(); + DWARFCompileUnit *main_unit; + if (DWARFDIE type_die = GetDIEUnlocked(type_uid, &main_unit)) + return type_die.ResolveType(main_unit); else return nullptr; } @@ -1316,11 +1385,13 @@ return llvm::None; } -Type *SymbolFileDWARF::ResolveTypeUID(const DIERef &die_ref) { - return ResolveType(GetDIE(die_ref), true); +Type *SymbolFileDWARF::ResolveTypeUID(DWARFCompileUnit *main_unit, + const DIERef &die_ref) { + return ResolveType(main_unit, GetDIE(die_ref), true); } -Type *SymbolFileDWARF::ResolveTypeUID(const DWARFDIE &die, +Type *SymbolFileDWARF::ResolveTypeUID(DWARFCompileUnit *main_unit, + const DWARFDIE &die, bool assert_not_being_parsed) { if (die) { Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); @@ -1354,7 +1425,7 @@ } } } - return ResolveType(die); + return ResolveType(main_unit, die); } return nullptr; } @@ -1404,7 +1475,8 @@ return true; } - DWARFDIE dwarf_die = GetDIE(die_it->getSecond()); + DWARFCompileUnit *main_unit; + DWARFDIE dwarf_die = GetDIEUnlocked(die_it->getSecond(), &main_unit); if (dwarf_die) { // Once we start resolving this type, remove it from the forward // declaration map in case anyone child members or other types require this @@ -1412,14 +1484,15 @@ // to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition are done. GetForwardDeclClangTypeToDie().erase(die_it); - Type *type = GetDIEToType().lookup(dwarf_die.GetDIE()); + Type *type = GetDIEToType().lookup(dwarf_die.MainCUtoDIEPair(main_unit)); + lldbassert(type); Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | DWARF_LOG_TYPE_COMPLETION)); if (log) GetObjectFile()->GetModule()->LogMessageVerboseBacktrace( log, "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...", - dwarf_die.GetID(), dwarf_die.GetTagAsCString(), + dwarf_die.GetID(nullptr), dwarf_die.GetTagAsCString(), type->GetName().AsCString()); assert(compiler_type); if (DWARFASTParser *dwarf_ast = GetDWARFParser(*dwarf_die.GetCU())) @@ -1428,11 +1501,12 @@ return false; } -Type *SymbolFileDWARF::ResolveType(const DWARFDIE &die, +Type *SymbolFileDWARF::ResolveType(DWARFCompileUnit *main_unit, + const DWARFDIE &die, bool assert_not_being_parsed, bool resolve_function_context) { if (die) { - Type *type = GetTypeForDIE(die, resolve_function_context).get(); + Type *type = GetTypeForDIE(main_unit, die, resolve_function_context).get(); if (assert_not_being_parsed) { if (type != DIE_IS_BEING_PARSED) @@ -1464,19 +1538,22 @@ } void SymbolFileDWARF::GetObjCMethods( - ConstString class_name, llvm::function_ref callback) { + ConstString class_name, + llvm::function_ref + callback) { m_index->GetObjCMethods(class_name, callback); } -bool SymbolFileDWARF::GetFunction(const DWARFDIE &die, SymbolContext &sc) { +bool SymbolFileDWARF::GetFunction(DWARFCompileUnit *main_unit, + const DWARFDIE &die, SymbolContext &sc) { sc.Clear(false); - if (die && llvm::isa(die.GetCU())) { + if (die && die.MainDWARFCompileUnit(main_unit)) { // Check if the symbol vendor already knows about this compile unit? sc.comp_unit = - GetCompUnitForDWARFCompUnit(llvm::cast(*die.GetCU())); + GetCompUnitForDWARFCompUnit(*die.MainDWARFCompileUnit(main_unit)); - sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get(); + sc.function = sc.comp_unit->FindFunctionByUID(die.GetID(main_unit)).get(); if (sc.function == nullptr) sc.function = ParseFunction(*sc.comp_unit, die); @@ -1501,7 +1578,7 @@ DWARFDIE SymbolFileDWARF::GetDIE(const DIERef &die_ref) { if (die_ref.dwo_num()) { - SymbolFileDWARF *dwarf = *die_ref.dwo_num() == 0x3fffffff + SymbolFileDWARF *dwarf = *die_ref.dwo_num() == 0x1ffffffe ? m_dwp_symfile.get() : this->DebugInfo() .GetUnitAtIndex(*die_ref.dwo_num()) @@ -1749,11 +1826,13 @@ bool lookup_block, SymbolContext &sc) { assert(sc.comp_unit); - DWARFUnit &cu = GetDWARFCompileUnit(sc.comp_unit)->GetNonSkeletonUnit(); + DWARFCompileUnit &cu = + GetDWARFCompileUnit(sc.comp_unit)->GetNonSkeletonUnit(); DWARFDIE function_die = cu.LookupAddress(file_vm_addr); DWARFDIE block_die; if (function_die) { - sc.function = sc.comp_unit->FindFunctionByUID(function_die.GetID()).get(); + sc.function = + sc.comp_unit->FindFunctionByUID(function_die.GetID(&cu)).get(); if (sc.function == nullptr) sc.function = ParseFunction(*sc.comp_unit, function_die); @@ -1766,9 +1845,9 @@ Block &block = sc.function->GetBlock(true); if (block_die) - sc.block = block.FindBlockByID(block_die.GetID()); + sc.block = block.FindBlockByID(block_die.GetID(&cu)); else - sc.block = block.FindBlockByID(function_die.GetID()); + sc.block = block.FindBlockByID(function_die.GetID(&cu)); } uint32_t SymbolFileDWARF::ResolveSymbolContext(const Address &so_addr, @@ -2051,41 +2130,42 @@ uint32_t pruned_idx = original_size; SymbolContext sc; - m_index->GetGlobalVariables(ConstString(basename), [&](DWARFDIE die) { - if (!sc.module_sp) - sc.module_sp = m_objfile_sp->GetModule(); - assert(sc.module_sp); + m_index->GetGlobalVariables( + ConstString(basename), [&](DWARFCompileUnit *main_unit, DWARFDIE die) { + if (!sc.module_sp) + sc.module_sp = m_objfile_sp->GetModule(); + assert(sc.module_sp); - if (die.Tag() != DW_TAG_variable) - return true; - - auto *dwarf_cu = llvm::dyn_cast(die.GetCU()); - if (!dwarf_cu) - return true; - sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); + if (die.Tag() != DW_TAG_variable) + return true; - if (parent_decl_ctx) { - if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) { - CompilerDeclContext actual_parent_decl_ctx = - dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); - if (!actual_parent_decl_ctx || - actual_parent_decl_ctx != parent_decl_ctx) + DWARFCompileUnit *dwarf_cu = die.MainDWARFCompileUnit(main_unit); + if (!dwarf_cu) return true; - } - } + sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); - ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables); - while (pruned_idx < variables.GetSize()) { - VariableSP var_sp = variables.GetVariableAtIndex(pruned_idx); - if (name_is_mangled || - var_sp->GetName().GetStringRef().contains(name.GetStringRef())) - ++pruned_idx; - else - variables.RemoveVariableAtIndex(pruned_idx); - } + if (parent_decl_ctx) { + if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) { + CompilerDeclContext actual_parent_decl_ctx = + dwarf_ast->GetDeclContextContainingUIDFromDWARF(main_unit, die); + if (!actual_parent_decl_ctx || + actual_parent_decl_ctx != parent_decl_ctx) + return true; + } + } - return variables.GetSize() - original_size < max_matches; - }); + ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables); + while (pruned_idx < variables.GetSize()) { + VariableSP var_sp = variables.GetVariableAtIndex(pruned_idx); + if (name_is_mangled || + var_sp->GetName().GetStringRef().contains(name.GetStringRef())) + ++pruned_idx; + else + variables.RemoveVariableAtIndex(pruned_idx); + } + + return variables.GetSize() - original_size < max_matches; + }); // Return the number of variable that were appended to the list const uint32_t num_matches = variables.GetSize() - original_size; @@ -2117,23 +2197,25 @@ const uint32_t original_size = variables.GetSize(); SymbolContext sc; - m_index->GetGlobalVariables(regex, [&](DWARFDIE die) { - if (!sc.module_sp) - sc.module_sp = m_objfile_sp->GetModule(); - assert(sc.module_sp); - - DWARFCompileUnit *dwarf_cu = llvm::dyn_cast(die.GetCU()); - if (!dwarf_cu) - return true; - sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); + m_index->GetGlobalVariables( + regex, [&](DWARFCompileUnit *main_unit, DWARFDIE die) { + if (!sc.module_sp) + sc.module_sp = m_objfile_sp->GetModule(); + assert(sc.module_sp); + + DWARFCompileUnit *dwarf_cu = die.MainDWARFCompileUnit(main_unit); + if (!dwarf_cu) + return true; + sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); - ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables); + ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables); - return variables.GetSize() - original_size < max_matches; - }); + return variables.GetSize() - original_size < max_matches; + }); } -bool SymbolFileDWARF::ResolveFunction(const DWARFDIE &orig_die, +bool SymbolFileDWARF::ResolveFunction(DWARFCompileUnit *main_unit, + const DWARFDIE &orig_die, bool include_inlines, SymbolContextList &sc_list) { SymbolContext sc; @@ -2162,12 +2244,12 @@ } } assert(die && die.Tag() == DW_TAG_subprogram); - if (GetFunction(die, sc)) { + if (GetFunction(main_unit, die, sc)) { Address addr; // Parse all blocks if needed if (inlined_die) { Block &function_block = sc.function->GetBlock(true); - sc.block = function_block.FindBlockByID(inlined_die.GetID()); + sc.block = function_block.FindBlockByID(inlined_die.GetID(main_unit)); if (sc.block == nullptr) sc.block = function_block.FindBlockByID(inlined_die.GetOffset()); if (sc.block == nullptr || !sc.block->GetStartAddress(addr)) @@ -2190,6 +2272,7 @@ } bool SymbolFileDWARF::DIEInDeclContext(const CompilerDeclContext &decl_ctx, + DWARFCompileUnit *main_unit, const DWARFDIE &die) { // If we have no parent decl context to match this DIE matches, and if the // parent decl context isn't valid, we aren't trying to look for any @@ -2198,9 +2281,10 @@ return true; if (die) { - if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) { + if (DWARFASTParser *dwarf_ast = + GetDWARFParser(*die.MainDWARFUnit(main_unit))) { if (CompilerDeclContext actual_decl_ctx = - dwarf_ast->GetDeclContextContainingUIDFromDWARF(die)) + dwarf_ast->GetDeclContextContainingUIDFromDWARF(main_unit, die)) return decl_ctx.IsContainedInLookup(actual_decl_ctx); } } @@ -2242,14 +2326,17 @@ const uint32_t original_size = sc_list.GetSize(); - llvm::DenseSet resolved_dies; + llvm::DenseSet> + resolved_dies; - m_index->GetFunctions(name, *this, parent_decl_ctx, name_type_mask, - [&](DWARFDIE die) { - if (resolved_dies.insert(die.GetDIE()).second) - ResolveFunction(die, include_inlines, sc_list); - return true; - }); + m_index->GetFunctions( + name, *this, parent_decl_ctx, name_type_mask, + [&](DWARFCompileUnit *main_unit, DWARFDIE die) { + if (resolved_dies.insert(std::make_pair(main_unit, die.GetDIE())) + .second) + ResolveFunction(main_unit, die, include_inlines, sc_list); + return true; + }); // Return the number of variable that were appended to the list const uint32_t num_matches = sc_list.GetSize() - original_size; @@ -2280,10 +2367,11 @@ regex.GetText().str().c_str()); } - llvm::DenseSet resolved_dies; - m_index->GetFunctions(regex, [&](DWARFDIE die) { - if (resolved_dies.insert(die.GetDIE()).second) - ResolveFunction(die, include_inlines, sc_list); + llvm::DenseSet> + resolved_dies; + m_index->GetFunctions(regex, [&](DWARFCompileUnit *main_unit, DWARFDIE die) { + if (resolved_dies.insert(std::make_pair(main_unit, die.GetDIE())).second) + ResolveFunction(main_unit, die, include_inlines, sc_list); return true; }); } @@ -2341,11 +2429,11 @@ if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) return; - m_index->GetTypes(name, [&](DWARFDIE die) { - if (!DIEInDeclContext(parent_decl_ctx, die)) + m_index->GetTypes(name, [&](DWARFCompileUnit *main_unit, DWARFDIE die) { + if (!DIEInDeclContext(parent_decl_ctx, main_unit, die)) return true; // The containing decl contexts don't match - Type *matching_type = ResolveType(die, true, true); + Type *matching_type = ResolveType(main_unit, die, true, true); if (!matching_type) return true; @@ -2403,7 +2491,7 @@ if (!name) return; - m_index->GetTypes(name, [&](DWARFDIE die) { + m_index->GetTypes(name, [&](DWARFCompileUnit *main_unit, DWARFDIE die) { if (!languages[GetLanguage(*die.GetCU())]) return true; @@ -2412,7 +2500,7 @@ if (!contextMatches(die_context, pattern)) return true; - if (Type *matching_type = ResolveType(die, true, true)) { + if (Type *matching_type = ResolveType(main_unit, die, true, true)) { // We found a type pointer, now find the shared pointer form our type // list. types.InsertUnique(matching_type->shared_from_this()); @@ -2448,15 +2536,16 @@ if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) return namespace_decl_ctx; - m_index->GetNamespaces(name, [&](DWARFDIE die) { - if (!DIEInDeclContext(parent_decl_ctx, die)) + m_index->GetNamespaces(name, [&](DWARFCompileUnit *main_unit, DWARFDIE die) { + if (!DIEInDeclContext(parent_decl_ctx, main_unit, die)) return true; // The containing decl contexts don't match - DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()); + DWARFASTParser *dwarf_ast = GetDWARFParser(*die.MainDWARFUnit(main_unit)); if (!dwarf_ast) return true; - namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(die); + namespace_decl_ctx = + dwarf_ast->GetDeclContextForUIDFromDWARF(main_unit, die); return !namespace_decl_ctx.IsValid(); }); @@ -2474,14 +2563,15 @@ return namespace_decl_ctx; } -TypeSP SymbolFileDWARF::GetTypeForDIE(const DWARFDIE &die, +TypeSP SymbolFileDWARF::GetTypeForDIE(DWARFCompileUnit *main_unit, + const DWARFDIE &die, bool resolve_function_context) { TypeSP type_sp; if (die) { - Type *type_ptr = GetDIEToType().lookup(die.GetDIE()); + Type *type_ptr = GetDIEToType().lookup(die.MainCUtoDIEPair(main_unit)); if (type_ptr == nullptr) { SymbolContextScope *scope; - if (auto *dwarf_cu = llvm::dyn_cast(die.GetCU())) + if (auto *dwarf_cu = die.MainDWARFCompileUnit(main_unit)) scope = GetCompUnitForDWARFCompUnit(*dwarf_cu); else scope = GetObjectFile()->GetModule().get(); @@ -2495,7 +2585,7 @@ } SymbolContext sc_backup = sc; if (resolve_function_context && parent_die != nullptr && - !GetFunction(DWARFDIE(die.GetCU(), parent_die), sc)) + !GetFunction(main_unit, DWARFDIE(die.GetCU(), parent_die), sc)) sc = sc_backup; type_sp = ParseType(sc, die, nullptr); @@ -2614,7 +2704,8 @@ return type_sp; m_index->GetCompleteObjCClass( - type_name, must_be_implementation, [&](DWARFDIE type_die) { + type_name, must_be_implementation, + [&](DWARFCompileUnit *main_unit, DWARFDIE type_die) { bool try_resolving_type = false; // Don't try and resolve the DIE we are looking for with the DIE @@ -2639,7 +2730,7 @@ if (!try_resolving_type) return true; - Type *resolved_type = ResolveType(type_die, false, true); + Type *resolved_type = ResolveType(main_unit, type_die, false, true); if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED) return true; @@ -2651,7 +2742,7 @@ type_die.GetID(), type_cu->GetID()); if (die) - GetDIEToType()[die.GetDIE()] = resolved_type; + GetDIEToType()[die.MainCUtoDIEPair(main_unit)] = resolved_type; type_sp = resolved_type->shared_from_this(); return false; }); @@ -2785,7 +2876,8 @@ } } - m_index->GetTypes(dwarf_decl_ctx, [&](DWARFDIE type_die) { + m_index->GetTypes(dwarf_decl_ctx, [&](DWARFCompileUnit *main_unit, + DWARFDIE type_die) { // Make sure type_die's langauge matches the type system we are // looking for. We don't want to find a "Foo" type from Java if we // are looking for a "Foo" type for C, C++, ObjC, or ObjC++. @@ -2856,7 +2948,7 @@ if (dwarf_decl_ctx != type_dwarf_decl_ctx) return true; - Type *resolved_type = ResolveType(type_die, false); + Type *resolved_type = ResolveType(main_unit, type_die, false); if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED) return true; @@ -2873,7 +2965,11 @@ if (!die) return {}; - auto type_system_or_err = GetTypeSystemForLanguage(GetLanguage(*die.GetCU())); + DWARFCompileUnit *main_unit = GetDWARFCompileUnit(sc.comp_unit); + SymbolFileDWARF *dwarf = + llvm::cast(sc.module_sp->GetSymbolFile()); + auto type_system_or_err = dwarf->GetTypeSystemForLanguage( + GetLanguage(*die.MainDWARFUnit(main_unit))); if (auto err = type_system_or_err.takeError()) { LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), std::move(err), "Unable to parse type"); @@ -2889,9 +2985,10 @@ GetTypeList().Insert(type_sp); if (die.Tag() == DW_TAG_subprogram) { - std::string scope_qualified_name(GetDeclContextForUID(die.GetID()) - .GetScopeQualifiedName() - .AsCString("")); + std::string scope_qualified_name( + GetDeclContextForUID(die.GetID(main_unit)) + .GetScopeQualifiedName() + .AsCString("")); if (scope_qualified_name.size()) { m_function_scope_qualified_name_map[scope_qualified_name].insert( *die.GetDIERef()); @@ -2925,8 +3022,10 @@ if (parse_children && die.HasChildren()) { if (die.Tag() == DW_TAG_subprogram) { + DWARFCompileUnit *main_unit = GetDWARFCompileUnit(sc.comp_unit); SymbolContext child_sc(sc); - child_sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get(); + child_sc.function = + sc.comp_unit->FindFunctionByUID(die.GetID(main_unit)).get(); types_added += ParseTypes(child_sc, die.GetFirstChild(), true, true); } else types_added += ParseTypes(sc, die.GetFirstChild(), true, true); @@ -2945,7 +3044,7 @@ CompileUnit *comp_unit = func.GetCompileUnit(); lldbassert(comp_unit); - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(comp_unit); if (!dwarf_cu) return 0; @@ -2964,12 +3063,13 @@ size_t SymbolFileDWARF::ParseTypes(CompileUnit &comp_unit) { std::lock_guard guard(GetModuleMutex()); size_t types_added = 0; - DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); + DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); if (dwarf_cu) { DWARFDIE dwarf_cu_die = dwarf_cu->DIE(); if (dwarf_cu_die && dwarf_cu_die.HasChildren()) { SymbolContext sc; sc.comp_unit = &comp_unit; + sc.module_sp = sc.comp_unit->GetModule(); types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true); } } @@ -3007,7 +3107,8 @@ sc.comp_unit->SetVariableList(variables); m_index->GetGlobalVariables( - dwarf_cu->GetNonSkeletonUnit(), [&](DWARFDIE die) { + dwarf_cu->GetNonSkeletonUnit(), + [&](DWARFCompileUnit *main_unit, DWARFDIE die) { VariableSP var_sp( ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS)); if (var_sp) { @@ -3026,14 +3127,16 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc, const DWARFDIE &die, const lldb::addr_t func_low_pc) { - if (die.GetDWARF() != this) - return die.GetDWARF()->ParseVariableDIE(sc, die, func_low_pc); + // if (die.GetDWARF() != this) + // return die.GetDWARF()->ParseVariableDIE(sc, die, func_low_pc); VariableSP var_sp; if (!die) return var_sp; - var_sp = GetDIEToVariable()[die.GetDIE()]; + DWARFCompileUnit *main_unit = GetDWARFCompileUnit(sc.comp_unit); + + var_sp = GetDIEToVariable()[die.MainCUtoDIEPair(main_unit)]; if (var_sp) return var_sp; // Already been parsed! @@ -3366,7 +3469,7 @@ case DW_TAG_lexical_block: if (sc.function) { symbol_context_scope = sc.function->GetBlock(true).FindBlockByID( - sc_parent_die.GetID()); + sc_parent_die.GetID(main_unit)); if (symbol_context_scope == nullptr) symbol_context_scope = sc.function; } @@ -3379,8 +3482,8 @@ } if (symbol_context_scope) { - SymbolFileTypeSP type_sp( - new SymbolFileType(*this, GetUID(type_die_form.Reference()))); + SymbolFileTypeSP type_sp(new SymbolFileType( + *this, GetUID(main_unit, type_die_form.Reference()))); if (const_value.Form() && type_sp && type_sp->GetType()) location.UpdateValue(const_value.Unsigned(), @@ -3388,9 +3491,9 @@ die.GetCU()->GetAddressByteSize()); var_sp = std::make_shared( - die.GetID(), name, mangled, type_sp, scope, symbol_context_scope, - scope_ranges, &decl, location, is_external, is_artificial, - is_static_member); + die.GetID(main_unit), name, mangled, type_sp, scope, + symbol_context_scope, scope_ranges, &decl, location, is_external, + is_artificial, is_static_member); var_sp->SetLocationIsConstantValueData(location_is_const_value_data); } else { @@ -3404,9 +3507,9 @@ // missing vital information to be able to be displayed in the debugger // (missing location due to optimization, etc)) so we don't re-parse this // DIE over and over later... - GetDIEToVariable()[die.GetDIE()] = var_sp; + GetDIEToVariable()[die.MainCUtoDIEPair(main_unit)] = var_sp; if (spec_die) - GetDIEToVariable()[spec_die.GetDIE()] = var_sp; + GetDIEToVariable()[spec_die.MainCUtoDIEPair(main_unit)] = var_sp; } return var_sp; } @@ -3465,6 +3568,7 @@ return 0; VariableListSP variable_list_sp; + DWARFCompileUnit *main_unit = GetDWARFCompileUnit(sc.comp_unit); size_t vars_added = 0; DWARFDIE die = orig_die; @@ -3472,7 +3576,7 @@ dw_tag_t tag = die.Tag(); // Check to see if we have already parsed this variable or constant? - VariableSP var_sp = GetDIEToVariable()[die.GetDIE()]; + VariableSP var_sp = GetDIEToVariable()[die.MainCUtoDIEPair(main_unit)]; if (var_sp) { if (cc_variable_list) cc_variable_list->AddVariableIfUnique(var_sp); @@ -3495,8 +3599,8 @@ GetObjectFile()->GetModule()->ReportError( "parent 0x%8.8" PRIx64 " %s with no valid compile unit in " "symbol context for 0x%8.8" PRIx64 " %s.\n", - sc_parent_die.GetID(), sc_parent_die.GetTagAsCString(), - orig_die.GetID(), orig_die.GetTagAsCString()); + sc_parent_die.GetID(nullptr), sc_parent_die.GetTagAsCString(), + orig_die.GetID(nullptr), orig_die.GetTagAsCString()); } break; @@ -3508,7 +3612,7 @@ // given scope Block *block = sc.function->GetBlock(true).FindBlockByID( - sc_parent_die.GetID()); + sc_parent_die.GetID(main_unit)); if (block == nullptr) { // This must be a specification or abstract origin with a // concrete block counterpart in the current function. We need @@ -3520,7 +3624,7 @@ sc_parent_die.GetOffset()); if (concrete_block_die) block = sc.function->GetBlock(true).FindBlockByID( - concrete_block_die.GetID()); + concrete_block_die.GetID(main_unit)); } if (block != nullptr) { @@ -3538,7 +3642,7 @@ GetObjectFile()->GetModule()->ReportError( "didn't find appropriate parent DIE for variable list for " "0x%8.8" PRIx64 " %s.\n", - orig_die.GetID(), orig_die.GetTagAsCString()); + orig_die.GetID(nullptr), orig_die.GetTagAsCString()); break; } } @@ -3813,7 +3917,7 @@ if (!dwp_obj_file) return; m_dwp_symfile = - std::make_shared(*this, dwp_obj_file, 0x3fffffff); + std::make_shared(*this, dwp_obj_file, 0x1ffffffe); } }); return m_dwp_symfile; @@ -3833,22 +3937,25 @@ return type_system_or_err->GetDWARFParser(); } -CompilerDecl SymbolFileDWARF::GetDecl(const DWARFDIE &die) { - if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) - return dwarf_ast->GetDeclForUIDFromDWARF(die); +CompilerDecl SymbolFileDWARF::GetDecl(DWARFCompileUnit *main_unit, + const DWARFDIE &die) { + if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.MainDWARFUnit(main_unit))) + return dwarf_ast->GetDeclForUIDFromDWARF(main_unit, die); return CompilerDecl(); } -CompilerDeclContext SymbolFileDWARF::GetDeclContext(const DWARFDIE &die) { - if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) - return dwarf_ast->GetDeclContextForUIDFromDWARF(die); +CompilerDeclContext SymbolFileDWARF::GetDeclContext(DWARFCompileUnit *main_unit, + const DWARFDIE &die) { + if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.MainDWARFUnit(main_unit))) + return dwarf_ast->GetDeclContextForUIDFromDWARF(main_unit, die); return CompilerDeclContext(); } CompilerDeclContext -SymbolFileDWARF::GetContainingDeclContext(const DWARFDIE &die) { - if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) - return dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); +SymbolFileDWARF::GetContainingDeclContext(DWARFCompileUnit *main_unit, + const DWARFDIE &die) { + if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.MainDWARFUnit(main_unit))) + return dwarf_ast->GetDeclContextContainingUIDFromDWARF(main_unit, die); return CompilerDeclContext(); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h @@ -31,8 +31,10 @@ DWARFCompileUnit *GetDWOCompileUnitForHash(uint64_t hash); - void GetObjCMethods(lldb_private::ConstString class_name, - llvm::function_ref callback) override; + void GetObjCMethods( + lldb_private::ConstString class_name, + llvm::function_ref + callback) override; llvm::Expected GetTypeSystemForLanguage(lldb::LanguageType language) override; @@ -42,6 +44,8 @@ llvm::Optional GetDwoNum() override { return GetID() >> 32; } + SymbolFileDWARF &GetBaseSymbolFile() { return m_base_symbol_file; } + protected: DIEToTypePtr &GetDIEToType() override; @@ -60,8 +64,6 @@ const DWARFDIE &die, lldb_private::ConstString type_name, bool must_be_implementation) override; - SymbolFileDWARF &GetBaseSymbolFile() { return m_base_symbol_file; } - /// If this file contains exactly one compile unit, this function will return /// it. Otherwise it returns nullptr. DWARFCompileUnit *FindSingleCompileUnit(); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp @@ -97,7 +97,8 @@ void SymbolFileDWARFDwo::GetObjCMethods( lldb_private::ConstString class_name, - llvm::function_ref callback) { + llvm::function_ref + callback) { GetBaseSymbolFile().GetObjCMethods(class_name, callback); } diff --git a/lldb/test/Shell/SymbolFile/DWARF/DW_AT_low_pc-addrx.s b/lldb/test/Shell/SymbolFile/DWARF/DW_AT_low_pc-addrx.s --- a/lldb/test/Shell/SymbolFile/DWARF/DW_AT_low_pc-addrx.s +++ b/lldb/test/Shell/SymbolFile/DWARF/DW_AT_low_pc-addrx.s @@ -5,9 +5,9 @@ # RUN: -o exit | FileCheck %s # CHECK-LABEL: image lookup -v -s lookup_rnglists -# CHECK: Function: id = {0x7fffffff0000002d}, name = "rnglists", range = [0x0000000000000000-0x0000000000000003) -# CHECK: Blocks: id = {0x7fffffff0000002d}, range = [0x00000000-0x00000003) -# CHECK-NEXT: id = {0x7fffffff00000043}, range = [0x00000001-0x00000002) +# CHECK: Function: id = {0x1fffffff0000002d}, name = "rnglists", range = [0x0000000000000000-0x0000000000000003) +# CHECK: Blocks: id = {0x1fffffff0000002d}, range = [0x00000000-0x00000003) +# CHECK-NEXT: id = {0x1fffffff00000043}, range = [0x00000001-0x00000002) .text rnglists: diff --git a/lldb/test/Shell/SymbolFile/DWARF/array-sizes.s b/lldb/test/Shell/SymbolFile/DWARF/array-sizes.s --- a/lldb/test/Shell/SymbolFile/DWARF/array-sizes.s +++ b/lldb/test/Shell/SymbolFile/DWARF/array-sizes.s @@ -9,8 +9,8 @@ # RUN: ld.lld %t.o -o %t # RUN: lldb-test symbols %t | FileCheck %s -# CHECK: Variable{0x7fffffff0000001e}, name = "X" -# CHECK-SAME: type = {7fffffff00000033} 0x{{[0-9A-F]*}} (char [56]) +# CHECK: Variable{0x1fffffff0000001e}, name = "X" +# CHECK-SAME: type = {1fffffff00000033} 0x{{[0-9A-F]*}} (char [56]) # Generated from "char X[47];" diff --git a/lldb/test/Shell/SymbolFile/DWARF/debug-types-address-ranges.s b/lldb/test/Shell/SymbolFile/DWARF/debug-types-address-ranges.s --- a/lldb/test/Shell/SymbolFile/DWARF/debug-types-address-ranges.s +++ b/lldb/test/Shell/SymbolFile/DWARF/debug-types-address-ranges.s @@ -11,11 +11,11 @@ # RUN: %lldb %t -o "image lookup -a 0x48000 -v" -o exit | FileCheck %s # CHECK: CompileUnit: id = {0x00000001}, file = "/tmp/a.cc", language = "c++" -# CHECK: Function: id = {0x7fffffff0000006a}, name = "::_start({{.*}})", range = [0x0000000000048000-0x000000000004800c) +# CHECK: Function: id = {0x1fffffff0000006a}, name = "::_start({{.*}})", range = [0x0000000000048000-0x000000000004800c) # CHECK: LineEntry: [0x0000000000048000-0x000000000004800a): /tmp/a.cc:4 # CHECK: Symbol: id = {0x00000002}, range = [0x0000000000048000-0x000000000004800c), name="_start" -# CHECK: Variable: id = {0x7fffffff00000075}, name = "v1", {{.*}} decl = a.cc:4 -# CHECK: Variable: id = {0x7fffffff00000080}, name = "v2", {{.*}} decl = a.cc:4 +# CHECK: Variable: id = {0x1fffffff00000075}, name = "v1", {{.*}} decl = a.cc:4 +# CHECK: Variable: id = {0x1fffffff00000080}, name = "v2", {{.*}} decl = a.cc:4 # Output generated via diff --git a/lldb/test/Shell/SymbolFile/DWARF/debug-types-dwarf5.s b/lldb/test/Shell/SymbolFile/DWARF/debug-types-dwarf5.s --- a/lldb/test/Shell/SymbolFile/DWARF/debug-types-dwarf5.s +++ b/lldb/test/Shell/SymbolFile/DWARF/debug-types-dwarf5.s @@ -1,8 +1,8 @@ # RUN: llvm-mc -triple=x86_64-pc-linux -filetype=obj %s > %t # RUN: %lldb %t -o "image lookup -v -s f1" -o exit | FileCheck %s -# CHECK: Function: id = {0x7fffffff0000003c}, name = "f1", range = [0x0000000000000000-0x0000000000000001) -# CHECK: Blocks: id = {0x7fffffff0000003c}, range = [0x00000000-0x00000001) +# CHECK: Function: id = {0x1fffffff0000003c}, name = "f1", range = [0x0000000000000000-0x0000000000000001) +# CHECK: Blocks: id = {0x1fffffff0000003c}, range = [0x00000000-0x00000001) .text diff --git a/lldb/test/Shell/SymbolFile/DWARF/debug_ranges-missing-section.s b/lldb/test/Shell/SymbolFile/DWARF/debug_ranges-missing-section.s --- a/lldb/test/Shell/SymbolFile/DWARF/debug_ranges-missing-section.s +++ b/lldb/test/Shell/SymbolFile/DWARF/debug_ranges-missing-section.s @@ -4,8 +4,8 @@ # RUN: %lldb %t -o "image lookup -v -s lookup_ranges" -o exit 2>&1 | FileCheck %s # CHECK: DIE has DW_AT_ranges(0x47) attribute, but range extraction failed (No debug_ranges section), -# CHECK: Function: id = {0x7fffffff0000001c}, name = "ranges", range = [0x0000000000000000-0x0000000000000004) -# CHECK: Blocks: id = {0x7fffffff0000001c}, range = [0x00000000-0x00000004) +# CHECK: Function: id = {0x1fffffff0000001c}, name = "ranges", range = [0x0000000000000000-0x0000000000000004) +# CHECK: Blocks: id = {0x1fffffff0000001c}, range = [0x00000000-0x00000004) .text .p2align 12 diff --git a/lldb/test/Shell/SymbolFile/DWARF/debug_ranges.s b/lldb/test/Shell/SymbolFile/DWARF/debug_ranges.s --- a/lldb/test/Shell/SymbolFile/DWARF/debug_ranges.s +++ b/lldb/test/Shell/SymbolFile/DWARF/debug_ranges.s @@ -3,9 +3,9 @@ # RUN: llvm-mc -triple=x86_64-pc-linux -filetype=obj %s > %t # RUN: %lldb %t -o "image lookup -v -s lookup_ranges" -o exit | FileCheck %s -# CHECK: Function: id = {0x7fffffff0000002b}, name = "ranges", range = [0x0000000000000000-0x0000000000000004) -# CHECK: Blocks: id = {0x7fffffff0000002b}, range = [0x00000000-0x00000004) -# CHECK-NEXT: id = {0x7fffffff0000003f}, ranges = [0x00000001-0x00000002)[0x00000003-0x00000004) +# CHECK: Function: id = {0x1fffffff0000002b}, name = "ranges", range = [0x0000000000000000-0x0000000000000004) +# CHECK: Blocks: id = {0x1fffffff0000002b}, range = [0x00000000-0x00000004) +# CHECK-NEXT: id = {0x1fffffff0000003f}, ranges = [0x00000001-0x00000002)[0x00000003-0x00000004) .text .p2align 12 diff --git a/lldb/test/Shell/SymbolFile/DWARF/debug_rnglists.s b/lldb/test/Shell/SymbolFile/DWARF/debug_rnglists.s --- a/lldb/test/Shell/SymbolFile/DWARF/debug_rnglists.s +++ b/lldb/test/Shell/SymbolFile/DWARF/debug_rnglists.s @@ -5,14 +5,14 @@ # RUN: -o "image lookup -v -s lookup_rnglists2" -o exit | FileCheck %s # CHECK-LABEL: image lookup -v -s lookup_rnglists -# CHECK: Function: id = {0x7fffffff00000030}, name = "rnglists", range = [0x0000000000000000-0x0000000000000004) -# CHECK: Blocks: id = {0x7fffffff00000030}, range = [0x00000000-0x00000004) -# CHECK-NEXT: id = {0x7fffffff00000046}, ranges = [0x00000001-0x00000002)[0x00000003-0x00000004) +# CHECK: Function: id = {0x1fffffff00000030}, name = "rnglists", range = [0x0000000000000000-0x0000000000000004) +# CHECK: Blocks: id = {0x1fffffff00000030}, range = [0x00000000-0x00000004) +# CHECK-NEXT: id = {0x1fffffff00000046}, ranges = [0x00000001-0x00000002)[0x00000003-0x00000004) # CHECK-LABEL: image lookup -v -s lookup_rnglists2 -# CHECK: Function: id = {0x7fffffff0000007a}, name = "rnglists2", range = [0x0000000000000004-0x0000000000000007) -# CHECK: Blocks: id = {0x7fffffff0000007a}, range = [0x00000004-0x00000007) -# CHECK-NEXT: id = {0x7fffffff00000091}, range = [0x00000005-0x00000007) +# CHECK: Function: id = {0x1fffffff0000007a}, name = "rnglists2", range = [0x0000000000000004-0x0000000000000007) +# CHECK: Blocks: id = {0x1fffffff0000007a}, range = [0x00000004-0x00000007) +# CHECK-NEXT: id = {0x1fffffff00000091}, range = [0x00000005-0x00000007) .text .p2align 12 diff --git a/lldb/test/Shell/SymbolFile/DWARF/dwarf5_locations.s b/lldb/test/Shell/SymbolFile/DWARF/dwarf5_locations.s --- a/lldb/test/Shell/SymbolFile/DWARF/dwarf5_locations.s +++ b/lldb/test/Shell/SymbolFile/DWARF/dwarf5_locations.s @@ -6,7 +6,7 @@ # RUN: ld.lld -m elf_x86_64 %t.o -o %t # RUN: lldb-test symbols %t | FileCheck %s -# CHECK: Variable{0x7fffffff00000011}, name = "color" +# CHECK: Variable{0x1fffffff00000011}, name = "color" # CHECK-SAME: location = DW_OP_addrx 0x0 .text diff --git a/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s b/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s --- a/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s +++ b/lldb/test/Shell/SymbolFile/DWARF/dwp-debug-types.s @@ -16,15 +16,15 @@ # Make sure each entity is present in the index only once. # SYMBOLS: Globals and statics: -# SYMBOLS-DAG: 3fffffff/INFO/00000023 "A" -# SYMBOLS-DAG: 3fffffff/INFO/0000005a "A" +# SYMBOLS-DAG: 1ffffffe/INFO/00000023 "A" +# SYMBOLS-DAG: 1ffffffe/INFO/0000005a "A" # SYMBOLS-EMPTY: # SYMBOLS: Types: -# SYMBOLS-DAG: 3fffffff/TYPE/00000018 "ENUM0" -# SYMBOLS-DAG: 3fffffff/TYPE/0000004d "ENUM1" -# SYMBOLS-DAG: 3fffffff/TYPE/0000002d "int" -# SYMBOLS-DAG: 3fffffff/TYPE/00000062 "int" +# SYMBOLS-DAG: 1ffffffe/TYPE/00000018 "ENUM0" +# SYMBOLS-DAG: 1ffffffe/TYPE/0000004d "ENUM1" +# SYMBOLS-DAG: 1ffffffe/TYPE/0000002d "int" +# SYMBOLS-DAG: 1ffffffe/TYPE/00000062 "int" # SYMBOLS-EMPTY: .ifdef MAIN diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp --- a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp +++ b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp @@ -95,7 +95,7 @@ TypeSystemClang ast_ctx("dummy ASTContext", HostInfoBase::GetTargetTriple()); DWARFASTParserClangStub ast_parser(ast_ctx); - DWARFUnit *unit = t.GetDwarfUnit().get(); + DWARFCompileUnit *unit = llvm::cast(t.GetDwarfUnit().get()); const DWARFDebugInfoEntry *die_first = unit->DIE().GetDIE(); const DWARFDebugInfoEntry *die_child0 = die_first->GetFirstChild(); const DWARFDebugInfoEntry *die_child1 = die_child0->GetSibling(); @@ -108,7 +108,7 @@ (clang::DeclContext *)1LL, (clang::DeclContext *)2LL, (clang::DeclContext *)2LL, (clang::DeclContext *)3LL}; for (int i = 0; i < 4; ++i) - ast_parser.LinkDeclContextToDIE(decl_ctxs[i], dies[i]); + ast_parser.LinkDeclContextToDIE(decl_ctxs[i], unit, dies[i]); ast_parser.EnsureAllDIEsInDeclContextHaveBeenParsed( CompilerDeclContext(nullptr, decl_ctxs[1]));