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 @@ -184,7 +184,7 @@ // The type in the Clang module must have the same language as the current CU. LanguageSet languages; - languages.Insert(die.GetCU()->GetLanguageType()); + languages.Insert(SymbolFileDWARF::GetLanguage(*die.GetCU())); llvm::DenseSet searched_symbol_files; clang_module_sp->GetSymbolFile()->FindTypes(decl_context, languages, searched_symbol_files, pcm_types); @@ -469,7 +469,7 @@ CompilerType clang_type; TypeSP type_sp; - LanguageType cu_language = die.GetLanguage(); + LanguageType cu_language = SymbolFileDWARF::GetLanguage(*die.GetCU()); switch (tag) { case DW_TAG_typedef: case DW_TAG_base_type: @@ -700,7 +700,7 @@ return type_sp; DWARFDeclContext die_decl_ctx; - die.GetDWARFDeclContext(die_decl_ctx); + SymbolFileDWARF::GetDWARFDeclContext(die, die_decl_ctx); type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx); @@ -1362,7 +1362,7 @@ CompilerType clang_type; const dw_tag_t tag = die.Tag(); SymbolFileDWARF *dwarf = die.GetDWARF(); - LanguageType cu_language = die.GetLanguage(); + LanguageType cu_language = SymbolFileDWARF::GetLanguage(*die.GetCU()); Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_TYPE_COMPLETION | DWARF_LOG_LOOKUPS); @@ -1495,7 +1495,7 @@ return type_sp; DWARFDeclContext die_decl_ctx; - die.GetDWARFDeclContext(die_decl_ctx); + SymbolFileDWARF::GetDWARFDeclContext(die, die_decl_ctx); // type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, // type_name_const_str); @@ -2424,9 +2424,11 @@ func_name.SetValue(ConstString(mangled), true); else if ((die.GetParent().Tag() == DW_TAG_compile_unit || die.GetParent().Tag() == DW_TAG_partial_unit) && - Language::LanguageIsCPlusPlus(die.GetLanguage()) && - !Language::LanguageIsObjC(die.GetLanguage()) && name && - strcmp(name, "main") != 0) { + Language::LanguageIsCPlusPlus( + SymbolFileDWARF::GetLanguage(*die.GetCU())) && + !Language::LanguageIsObjC( + SymbolFileDWARF::GetLanguage(*die.GetCU())) && + name && strcmp(name, "main") != 0) { // If the mangled name is not present in the DWARF, generate the // demangled name using the decl context. We skip if the function is // "main" as its name is never mangled. @@ -2439,7 +2441,7 @@ DWARFDeclContext decl_ctx; StreamString sstr; - die.GetDWARFDeclContext(decl_ctx); + SymbolFileDWARF::GetDWARFDeclContext(die, decl_ctx); sstr << decl_ctx.GetQualifiedName(); clang::DeclContext *containing_decl_ctx = @@ -3410,7 +3412,7 @@ SymbolFileDWARF *dwarf = die.GetDWARF(); DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import); if (imported_uid) { - CompilerDecl imported_decl = imported_uid.GetDecl(); + CompilerDecl imported_decl = SymbolFileDWARF::GetDecl(imported_uid); if (imported_decl) { clang::DeclContext *decl_context = ClangASTContext::DeclContextGetAsDeclContext( @@ -3429,7 +3431,8 @@ DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import); if (imported_uid) { - CompilerDeclContext imported_decl_ctx = imported_uid.GetDeclContext(); + CompilerDeclContext imported_decl_ctx = + SymbolFileDWARF::GetDeclContext(imported_uid); if (imported_decl_ctx) { clang::DeclContext *decl_context = ClangASTContext::DeclContextGetAsDeclContext( @@ -3775,9 +3778,8 @@ } DWARFASTParserClang *dwarf_ast_parser = - (DWARFASTParserClang *)src_die.GetDWARFParser(); - lldbassert(dwarf_ast_parser == - (DWARFASTParserClang *)dst_die.GetDWARFParser()); + (DWARFASTParserClang *)SymbolFileDWARF::GetDWARFParser(*src_die.GetCU()); + lldbassert(dwarf_ast_parser == (DWARFASTParserClang *)SymbolFileDWARF::GetDWARFParser(*dst_die.GetCU()); // Now do the work of linking the DeclContexts and Types. if (fast_path) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h @@ -57,10 +57,6 @@ llvm::Optional GetDIERef() const; - llvm::Expected GetTypeSystem() const; - - DWARFASTParser *GetDWARFParser() const; - void Set(DWARFUnit *cu, DWARFDebugInfoEntry *die) { if (cu && die) { m_cu = cu; @@ -98,8 +94,6 @@ const char *GetName() const; - lldb::LanguageType GetLanguage() const; - lldb::ModuleSP GetModule() const; // Getting attribute values from the DIE. diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp @@ -74,13 +74,6 @@ return nullptr; } -lldb::LanguageType DWARFBaseDIE::GetLanguage() const { - if (IsValid()) - return m_cu->GetLanguageType(); - else - return lldb::eLanguageTypeUnknown; -} - lldb::ModuleSP DWARFBaseDIE::GetModule() const { SymbolFileDWARF *dwarf = GetDWARF(); if (dwarf) @@ -103,24 +96,6 @@ return nullptr; } -llvm::Expected DWARFBaseDIE::GetTypeSystem() const { - if (!m_cu) - return llvm::make_error( - "Unable to get TypeSystem, no compilation unit available", - llvm::inconvertibleErrorCode()); - return m_cu->GetTypeSystem(); -} - -DWARFASTParser *DWARFBaseDIE::GetDWARFParser() const { - auto type_system_or_err = GetTypeSystem(); - if (auto err = type_system_or_err.takeError()) { - LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), - std::move(err), "Unable to get DWARFASTParser"); - return nullptr; - } - return type_system_or_err->GetDWARFParser(); -} - bool DWARFBaseDIE::HasChildren() const { return m_die && m_die->HasChildren(); } 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 @@ -70,8 +70,6 @@ // DeclContext related functions std::vector GetDeclContextDIEs() const; - void GetDWARFDeclContext(DWARFDeclContext &dwarf_decl_ctx) const; - /// Return this DIE's decl context as it is needed to look up types /// in Clang's -gmodules debug info format. void GetDeclContext( @@ -90,14 +88,6 @@ int &decl_line, int &decl_column, int &call_file, int &call_line, int &call_column, lldb_private::DWARFExpression *frame_base) const; - - // CompilerDecl related functions - - lldb_private::CompilerDecl GetDecl() const; - - lldb_private::CompilerDeclContext GetDeclContext() const; - - lldb_private::CompilerDeclContext GetContainingDeclContext() const; }; #endif // SymbolFileDWARF_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 @@ -333,15 +333,6 @@ return result; } -void DWARFDIE::GetDWARFDeclContext(DWARFDeclContext &dwarf_decl_ctx) const { - if (IsValid()) { - dwarf_decl_ctx.SetLanguage(GetLanguage()); - m_die->GetDWARFDeclContext(GetCU(), dwarf_decl_ctx); - } else { - dwarf_decl_ctx.Clear(); - } -} - void DWARFDIE::GetDeclContext( llvm::SmallVectorImpl &context) const { const dw_tag_t tag = Tag(); @@ -418,27 +409,3 @@ } else return false; } - -CompilerDecl DWARFDIE::GetDecl() const { - DWARFASTParser *dwarf_ast = GetDWARFParser(); - if (dwarf_ast) - return dwarf_ast->GetDeclForUIDFromDWARF(*this); - else - return CompilerDecl(); -} - -CompilerDeclContext DWARFDIE::GetDeclContext() const { - DWARFASTParser *dwarf_ast = GetDWARFParser(); - if (dwarf_ast) - return dwarf_ast->GetDeclContextForUIDFromDWARF(*this); - else - return CompilerDeclContext(); -} - -CompilerDeclContext DWARFDIE::GetContainingDeclContext() const { - DWARFASTParser *dwarf_ast = GetDWARFParser(); - if (dwarf_ast) - return dwarf_ast->GetDeclContextContainingUIDFromDWARF(*this); - else - return CompilerDeclContext(); -} 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 @@ -153,8 +153,6 @@ lldb::ByteOrder GetByteOrder() const; - llvm::Expected GetTypeSystem(); - const DWARFDebugAranges &GetFunctionAranges(); void SetBaseAddress(dw_addr_t base_addr); @@ -191,9 +189,7 @@ uint32_t GetProducerVersionUpdate(); - static lldb::LanguageType LanguageTypeFromDWARF(uint64_t val); - - lldb::LanguageType GetLanguageType(); + uint64_t GetDWARFLanguageType(); bool GetIsOptimized(); @@ -277,7 +273,7 @@ uint32_t m_producer_version_major = 0; uint32_t m_producer_version_minor = 0; uint32_t m_producer_version_update = 0; - lldb::LanguageType m_language_type = lldb::eLanguageTypeUnknown; + llvm::Optional m_language_type; lldb_private::LazyBool m_is_optimized = lldb_private::eLazyBoolCalculate; llvm::Optional m_comp_dir; llvm::Optional m_file_spec; 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 @@ -438,10 +438,6 @@ return m_dwarf.GetObjectFile()->GetByteOrder(); } -llvm::Expected DWARFUnit::GetTypeSystem() { - return m_dwarf.GetTypeSystemForLanguage(GetLanguageType()); -} - void DWARFUnit::SetBaseAddress(dw_addr_t base_addr) { m_base_addr = base_addr; } // Compare function DWARFDebugAranges::Range structures @@ -582,28 +578,17 @@ ParseProducerInfo(); return m_producer_version_update; } -LanguageType DWARFUnit::LanguageTypeFromDWARF(uint64_t val) { - // Note: user languages between lo_user and hi_user must be handled - // explicitly here. - switch (val) { - case DW_LANG_Mips_Assembler: - return eLanguageTypeMipsAssembler; - case DW_LANG_GOOGLE_RenderScript: - return eLanguageTypeExtRenderScript; - default: - return static_cast(val); - } -} -LanguageType DWARFUnit::GetLanguageType() { - if (m_language_type != eLanguageTypeUnknown) - return m_language_type; +uint64_t DWARFUnit::GetDWARFLanguageType() { + if (m_language_type) + return *m_language_type; const DWARFDebugInfoEntry *die = GetUnitDIEPtrOnly(); - if (die) - m_language_type = LanguageTypeFromDWARF( - die->GetAttributeValueAsUnsigned(this, DW_AT_language, 0)); - return m_language_type; + if (!die) + m_language_type = 0; + else + m_language_type = die->GetAttributeValueAsUnsigned(this, DW_AT_language, 0); + return *m_language_type; } bool DWARFUnit::GetIsOptimized() { 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 @@ -100,7 +100,7 @@ unit.GetOffset()); } - const LanguageType cu_language = unit.GetLanguageType(); + const LanguageType cu_language = SymbolFileDWARF::GetLanguage(unit); IndexUnitImpl(unit, cu_language, set); 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 @@ -318,6 +318,27 @@ lldb_private::FileSpec GetFile(DWARFUnit &unit, size_t file_idx); + static llvm::Expected + GetTypeSystem(DWARFUnit &unit); + + static DWARFASTParser *GetDWARFParser(DWARFUnit &unit); + + // CompilerDecl related functions + + static lldb_private::CompilerDecl GetDecl(const DWARFDIE &die); + + static lldb_private::CompilerDeclContext GetDeclContext(const DWARFDIE &die); + + static lldb_private::CompilerDeclContext + GetContainingDeclContext(const DWARFDIE &die); + + static void GetDWARFDeclContext(const DWARFDIE &die, + DWARFDeclContext &dwarf_decl_ctx); + + static lldb::LanguageType LanguageTypeFromDWARF(uint64_t val); + + static lldb::LanguageType GetLanguage(DWARFUnit &unit); + protected: typedef llvm::DenseMap DIEToTypePtr; 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 @@ -722,7 +722,7 @@ cu_file_spec.SetFile(remapped_file, FileSpec::Style::native); } - LanguageType cu_language = DWARFUnit::LanguageTypeFromDWARF( + LanguageType cu_language = SymbolFileDWARF::LanguageTypeFromDWARF( cu_die.GetAttributeValueAsUnsigned(DW_AT_language, 0)); bool is_optimized = dwarf_cu.GetIsOptimized(); @@ -800,8 +800,7 @@ if (!die.IsValid()) return nullptr; - auto type_system_or_err = - GetTypeSystemForLanguage(die.GetCU()->GetLanguageType()); + auto type_system_or_err = GetTypeSystemForLanguage(GetLanguage(*die.GetCU())); if (auto err = type_system_or_err.takeError()) { LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), std::move(err), "Unable to parse function"); @@ -826,7 +825,7 @@ std::lock_guard guard(GetModuleMutex()); DWARFUnit *dwarf_cu = GetDWARFCompileUnit(&comp_unit); if (dwarf_cu) - return dwarf_cu->GetLanguageType(); + return GetLanguage(*dwarf_cu); else return eLanguageTypeUnknown; } @@ -1309,7 +1308,7 @@ // SymbolFileDWARF::GetDIE(). See comments inside the // SymbolFileDWARF::GetDIE() for details. if (DWARFDIE die = GetDIE(type_uid)) - return die.GetDecl(); + return GetDecl(die); return CompilerDecl(); } @@ -1322,7 +1321,7 @@ // SymbolFileDWARF::GetDIE(). See comments inside the // SymbolFileDWARF::GetDIE() for details. if (DWARFDIE die = GetDIE(type_uid)) - return die.GetDeclContext(); + return GetDeclContext(die); return CompilerDeclContext(); } @@ -1333,7 +1332,7 @@ // SymbolFileDWARF::GetDIE(). See comments inside the // SymbolFileDWARF::GetDIE() for details. if (DWARFDIE die = GetDIE(type_uid)) - return die.GetContainingDeclContext(); + return GetContainingDeclContext(die); return CompilerDeclContext(); } @@ -1464,7 +1463,7 @@ dwarf_die.GetID(), dwarf_die.GetTagAsCString(), type->GetName().AsCString()); assert(compiler_type); - DWARFASTParser *dwarf_ast = dwarf_die.GetDWARFParser(); + DWARFASTParser *dwarf_ast = GetDWARFParser(*dwarf_die.GetCU()); if (dwarf_ast) return dwarf_ast->CompleteTypeFromDWARF(dwarf_die, type, compiler_type); } @@ -2152,7 +2151,7 @@ sc.comp_unit = GetCompUnitForDWARFCompUnit(*dwarf_cu); if (parent_decl_ctx) { - DWARFASTParser *dwarf_ast = die.GetDWARFParser(); + DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()); if (dwarf_ast) { CompilerDeclContext actual_parent_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); @@ -2308,7 +2307,7 @@ return true; if (die) { - DWARFASTParser *dwarf_ast = die.GetDWARFParser(); + DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()); if (dwarf_ast) { CompilerDeclContext actual_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); @@ -2559,7 +2558,7 @@ m_index->ReportInvalidDIERef(die_ref, name.GetStringRef()); continue; } - if (!languages[die.GetCU()->GetLanguageType()]) + if (!languages[GetLanguage(*die.GetCU())]) continue; llvm::SmallVector die_context; @@ -2616,7 +2615,7 @@ if (!DIEInDeclContext(parent_decl_ctx, die)) continue; // The containing decl contexts don't match - DWARFASTParser *dwarf_ast = die.GetDWARFParser(); + DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()); if (dwarf_ast) { namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(die); if (namespace_decl_ctx) @@ -2978,7 +2977,7 @@ // 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++. if (type_system && - !type_system->SupportsLanguage(type_die.GetLanguage())) + !type_system->SupportsLanguage(GetLanguage(*type_die.GetCU()))) continue; bool try_resolving_type = false; @@ -3013,7 +3012,7 @@ if (try_resolving_type) { DWARFDeclContext type_dwarf_decl_ctx; - type_die.GetDWARFDeclContext(type_dwarf_decl_ctx); + GetDWARFDeclContext(type_die, type_dwarf_decl_ctx); if (log) { GetObjectFile()->GetModule()->LogMessage( @@ -3063,8 +3062,7 @@ if (!die) return {}; - auto type_system_or_err = - GetTypeSystemForLanguage(die.GetCU()->GetLanguageType()); + auto type_system_or_err = GetTypeSystemForLanguage(GetLanguage(*die.GetCU())); if (auto err = type_system_or_err.takeError()) { LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), std::move(err), "Unable to parse type"); @@ -3428,10 +3426,10 @@ // declaration context. if ((parent_tag == DW_TAG_compile_unit || parent_tag == DW_TAG_partial_unit) && - Language::LanguageIsCPlusPlus(die.GetLanguage())) { + Language::LanguageIsCPlusPlus(GetLanguage(*die.GetCU()))) { DWARFDeclContext decl_ctx; - die.GetDWARFDeclContext(decl_ctx); + GetDWARFDeclContext(die, decl_ctx); mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString(); } } @@ -4003,3 +4001,69 @@ }); return m_dwp_symfile.get(); } + +llvm::Expected SymbolFileDWARF::GetTypeSystem(DWARFUnit &unit) { + return unit.GetSymbolFileDWARF().GetTypeSystemForLanguage(GetLanguage(unit)); +} + +DWARFASTParser *SymbolFileDWARF::GetDWARFParser(DWARFUnit &unit) { + auto type_system_or_err = GetTypeSystem(unit); + if (auto err = type_system_or_err.takeError()) { + LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), + std::move(err), "Unable to get DWARFASTParser"); + return nullptr; + } + return type_system_or_err->GetDWARFParser(); +} + +CompilerDecl SymbolFileDWARF::GetDecl(const DWARFDIE &die) { + DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()); + if (dwarf_ast) + return dwarf_ast->GetDeclForUIDFromDWARF(die); + else + return CompilerDecl(); +} + +CompilerDeclContext SymbolFileDWARF::GetDeclContext(const DWARFDIE &die) { + DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()); + if (dwarf_ast) + return dwarf_ast->GetDeclContextForUIDFromDWARF(die); + else + return CompilerDeclContext(); +} + +CompilerDeclContext +SymbolFileDWARF::GetContainingDeclContext(const DWARFDIE &die) { + DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU()); + if (dwarf_ast) + return dwarf_ast->GetDeclContextContainingUIDFromDWARF(die); + else + return CompilerDeclContext(); +} + +void SymbolFileDWARF::GetDWARFDeclContext(const DWARFDIE &die, + DWARFDeclContext &dwarf_decl_ctx) { + if (!die.IsValid()) { + dwarf_decl_ctx.Clear(); + return; + } + dwarf_decl_ctx.SetLanguage(GetLanguage(*die.GetCU())); + die.GetDIE()->GetDWARFDeclContext(die.GetCU(), dwarf_decl_ctx); +} + +LanguageType SymbolFileDWARF::LanguageTypeFromDWARF(uint64_t val) { + // Note: user languages between lo_user and hi_user must be handled + // explicitly here. + switch (val) { + case DW_LANG_Mips_Assembler: + return eLanguageTypeMipsAssembler; + case DW_LANG_GOOGLE_RenderScript: + return eLanguageTypeExtRenderScript; + default: + return static_cast(val); + } +} + +LanguageType SymbolFileDWARF::GetLanguage(DWARFUnit &unit) { + return LanguageTypeFromDWARF(unit.GetDWARFLanguageType()); +}