https://github.com/walter-erquinigo updated https://github.com/llvm/llvm-project/pull/70157
>From 98c80871a753c58a49e8ba0d535e03e99d633109 Mon Sep 17 00:00:00 2001 From: walter erquinigo <wal...@modular.com> Date: Tue, 24 Oct 2023 22:32:38 -0400 Subject: [PATCH 1/2] [LLDB][NFC] Remove DWARFASTParserClang as friend from SymbolFileDWARF This effectively moves a few functions from protected to public. In any case, for the sake of having a cleaner SymbolFileDWARF API, it's better if it's not a friend of a one of its consumers, DWARFASTParserClang. Another effect of this change is that I can use SymbolFileDWARF for the out-of-tree mojo dwarf parser, which relies on pretty much the same functions that DWARFASTParserClang needs from SymbolFileDWARF. --- .../SymbolFile/DWARF/SymbolFileDWARF.h | 65 ++++++++++--------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index 1ce62e6a6bb9e44..5b651a910e6deca 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -83,7 +83,6 @@ class SymbolFileDWARF : public SymbolFileCommon { friend class DWARFCompileUnit; friend class DWARFDIE; friend class DWARFASTParser; - friend class ::DWARFASTParserClang; // Static Functions static void Initialize(); @@ -138,7 +137,6 @@ class SymbolFileDWARF : public SymbolFileCommon { size_t ParseVariablesForContext(const SymbolContext &sc) override; - Type *ResolveTypeUID(lldb::user_id_t type_uid) override; std::optional<ArrayInfo> GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, const ExecutionContext *exe_ctx) override; @@ -325,15 +323,46 @@ class SymbolFileDWARF : public SymbolFileCommon { m_file_index = file_index; } -protected: typedef llvm::DenseMap<const DWARFDebugInfoEntry *, Type *> DIEToTypePtr; - typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP> - DIEToVariableSP; + + virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; } + typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::opaque_compiler_type_t> DIEToClangType; + + virtual DIEToClangType &GetForwardDeclDieToClangType() { + return m_forward_decl_die_to_clang_type; + } + typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> ClangTypeToDIE; + virtual ClangTypeToDIE &GetForwardDeclClangTypeToDie() { + return m_forward_decl_clang_type_to_die; + } + + virtual UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap(); + + bool ClassOrStructIsVirtual(const DWARFDIE &die); + + SymbolFileDWARFDebugMap *GetDebugMapSymfile(); + + virtual lldb::TypeSP + FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die); + + virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE( + const DWARFDIE &die, ConstString type_name, bool must_be_implementation); + + Type *ResolveTypeUID(lldb::user_id_t type_uid) override; + + Type *ResolveTypeUID(const DWARFDIE &die, bool assert_not_being_parsed); + + Type *ResolveTypeUID(const DIERef &die_ref); + +protected: + typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP> + DIEToVariableSP; + SymbolFileDWARF(const SymbolFileDWARF &) = delete; const SymbolFileDWARF &operator=(const SymbolFileDWARF &) = delete; @@ -371,10 +400,6 @@ class SymbolFileDWARF : public SymbolFileCommon { bool ParseSupportFiles(DWARFUnit &dwarf_cu, const lldb::ModuleSP &module, FileSpecList &support_files); - Type *ResolveTypeUID(const DWARFDIE &die, bool assert_not_being_parsed); - - Type *ResolveTypeUID(const DIERef &die_ref); - lldb::VariableSP ParseVariableDIE(const SymbolContext &sc, const DWARFDIE &die, const lldb::addr_t func_low_pc); @@ -402,8 +427,6 @@ class SymbolFileDWARF : public SymbolFileCommon { DIEArray MergeBlockAbstractParameters(const DWARFDIE &block_die, DIEArray &&variable_dies); - 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, SymbolContextList &sc_list); @@ -415,12 +438,6 @@ class SymbolFileDWARF : public SymbolFileCommon { void ResolveFunctionAndBlock(lldb::addr_t file_vm_addr, bool lookup_block, SymbolContext &sc); - virtual lldb::TypeSP - FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die); - - virtual lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE( - const DWARFDIE &die, ConstString type_name, bool must_be_implementation); - Symbol *GetObjCClassSymbol(ConstString objc_class_name); lldb::TypeSP GetTypeForDIE(const DWARFDIE &die, @@ -430,8 +447,6 @@ class SymbolFileDWARF : public SymbolFileCommon { m_debug_map_module_wp = module_sp; } - SymbolFileDWARFDebugMap *GetDebugMapSymfile(); - DWARFDIE FindBlockContainingSpecification(const DIERef &func_die_ref, dw_offset_t spec_block_die_offset); @@ -440,8 +455,6 @@ class SymbolFileDWARF : public SymbolFileCommon { FindBlockContainingSpecification(const DWARFDIE &die, dw_offset_t spec_block_die_offset); - virtual UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap(); - bool DIEDeclContextsMatch(const DWARFDIE &die1, const DWARFDIE &die2); bool ClassContainsSelector(const DWARFDIE &class_die, ConstString selector); @@ -473,18 +486,8 @@ class SymbolFileDWARF : public SymbolFileCommon { void UpdateExternalModuleListIfNeeded(); - virtual DIEToTypePtr &GetDIEToType() { return m_die_to_type; } - virtual DIEToVariableSP &GetDIEToVariable() { return m_die_to_variable_sp; } - virtual DIEToClangType &GetForwardDeclDieToClangType() { - return m_forward_decl_die_to_clang_type; - } - - virtual ClangTypeToDIE &GetForwardDeclClangTypeToDie() { - return m_forward_decl_clang_type_to_die; - } - void BuildCuTranslationTable(); std::optional<uint32_t> GetDWARFUnitIndex(uint32_t cu_idx); >From fda99a6b9f3af6b15fd6347064ff81c1aa092a77 Mon Sep 17 00:00:00 2001 From: walter erquinigo <wal...@modular.com> Date: Wed, 25 Oct 2023 16:47:53 -0500 Subject: [PATCH 2/2] [LLDB] Rename clang -> compiler in some SymbolFileDWARF symbols --- .../SymbolFile/DWARF/DWARFASTParserClang.cpp | 18 +++++++++--------- .../SymbolFile/DWARF/SymbolFileDWARF.cpp | 10 +++++----- .../SymbolFile/DWARF/SymbolFileDWARF.h | 19 ++++++++++--------- .../DWARF/SymbolFileDWARFDebugMap.cpp | 2 +- .../SymbolFile/DWARF/SymbolFileDWARFDwo.cpp | 12 ++++++------ .../SymbolFile/DWARF/SymbolFileDWARFDwo.h | 4 ++-- 6 files changed, 33 insertions(+), 32 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index f642e8d67403dee..182cc6764651747 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -834,9 +834,9 @@ TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc, CompilerType enumerator_clang_type; CompilerType clang_type; - clang_type = - CompilerType(m_ast.weak_from_this(), - dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE())); + clang_type = CompilerType( + m_ast.weak_from_this(), + dwarf->GetForwardDeclDIEToCompilerType().lookup(die.GetDIE())); if (!clang_type) { if (attrs.type.IsValid()) { Type *enumerator_type = @@ -1764,9 +1764,9 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc, assert(tag_decl_kind != -1); (void)tag_decl_kind; bool clang_type_was_created = false; - clang_type = - CompilerType(m_ast.weak_from_this(), - dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE())); + clang_type = CompilerType( + m_ast.weak_from_this(), + dwarf->GetForwardDeclDIEToCompilerType().lookup(die.GetDIE())); if (!clang_type) { clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE(die, nullptr); @@ -1896,16 +1896,16 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc, // the SymbolFile virtual function // "SymbolFileDWARF::CompleteType(Type *)" When the definition // needs to be defined. - assert(!dwarf->GetForwardDeclClangTypeToDie().count( + assert(!dwarf->GetForwardDeclCompilerTypeToDIE().count( ClangUtil::RemoveFastQualifiers(clang_type) .GetOpaqueQualType()) && "Type already in the forward declaration map!"); // Can't assume m_ast.GetSymbolFile() is actually a // SymbolFileDWARF, it can be a SymbolFileDWARFDebugMap for Apple // binaries. - dwarf->GetForwardDeclDieToClangType()[die.GetDIE()] = + dwarf->GetForwardDeclDIEToCompilerType()[die.GetDIE()] = clang_type.GetOpaqueQualType(); - dwarf->GetForwardDeclClangTypeToDie().try_emplace( + dwarf->GetForwardDeclCompilerTypeToDIE().try_emplace( ClangUtil::RemoveFastQualifiers(clang_type).GetOpaqueQualType(), *die.GetDIERef()); m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index bfec67ce83bc3d0..ee7164d2f050ed1 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1532,11 +1532,11 @@ Type *SymbolFileDWARF::ResolveTypeUID(const DWARFDIE &die, // This function is used when SymbolFileDWARFDebugMap owns a bunch of // SymbolFileDWARF objects to detect if this DWARF file is the one that can // resolve a compiler_type. -bool SymbolFileDWARF::HasForwardDeclForClangType( +bool SymbolFileDWARF::HasForwardDeclForCompilerType( const CompilerType &compiler_type) { CompilerType compiler_type_no_qualifiers = ClangUtil::RemoveFastQualifiers(compiler_type); - if (GetForwardDeclClangTypeToDie().count( + if (GetForwardDeclCompilerTypeToDIE().count( compiler_type_no_qualifiers.GetOpaqueQualType())) { return true; } @@ -1564,9 +1564,9 @@ bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) { // We have a struct/union/class/enum that needs to be fully resolved. CompilerType compiler_type_no_qualifiers = ClangUtil::RemoveFastQualifiers(compiler_type); - auto die_it = GetForwardDeclClangTypeToDie().find( + auto die_it = GetForwardDeclCompilerTypeToDIE().find( compiler_type_no_qualifiers.GetOpaqueQualType()); - if (die_it == GetForwardDeclClangTypeToDie().end()) { + if (die_it == GetForwardDeclCompilerTypeToDIE().end()) { // We have already resolved this type... return true; } @@ -1577,7 +1577,7 @@ bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) { // declaration map in case anyone child members or other types require this // type to get resolved. The type will get resolved when all of the calls // to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition are done. - GetForwardDeclClangTypeToDie().erase(die_it); + GetForwardDeclCompilerTypeToDIE().erase(die_it); Type *type = GetDIEToType().lookup(dwarf_die.GetDIE()); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index 5b651a910e6deca..069a2050f0eaadc 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -223,7 +223,7 @@ class SymbolFileDWARF : public SymbolFileCommon { DWARFDIE GetDeclContextDIEContainingDIE(const DWARFDIE &die); - bool HasForwardDeclForClangType(const CompilerType &compiler_type); + bool HasForwardDeclForCompilerType(const CompilerType &compiler_type); CompileUnit *GetCompUnitForDWARFCompUnit(DWARFCompileUnit &dwarf_cu); @@ -329,16 +329,17 @@ class SymbolFileDWARF : public SymbolFileCommon { typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::opaque_compiler_type_t> - DIEToClangType; + DIEToCompilerType; - virtual DIEToClangType &GetForwardDeclDieToClangType() { - return m_forward_decl_die_to_clang_type; + virtual DIEToCompilerType &GetForwardDeclDIEToCompilerType() { + return m_forward_decl_die_to_compiler_type; } - typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> ClangTypeToDIE; + typedef llvm::DenseMap<lldb::opaque_compiler_type_t, DIERef> + CompilerTypeToDIE; - virtual ClangTypeToDIE &GetForwardDeclClangTypeToDie() { - return m_forward_decl_clang_type_to_die; + virtual CompilerTypeToDIE &GetForwardDeclCompilerTypeToDIE() { + return m_forward_decl_compiler_type_to_die; } virtual UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap(); @@ -531,8 +532,8 @@ class SymbolFileDWARF : public SymbolFileCommon { UniqueDWARFASTTypeMap m_unique_ast_type_map; DIEToTypePtr m_die_to_type; DIEToVariableSP m_die_to_variable_sp; - DIEToClangType m_forward_decl_die_to_clang_type; - ClangTypeToDIE m_forward_decl_clang_type_to_die; + DIEToCompilerType m_forward_decl_die_to_compiler_type; + CompilerTypeToDIE m_forward_decl_compiler_type_to_die; llvm::DenseMap<dw_offset_t, FileSpecList> m_type_unit_support_files; std::vector<uint32_t> m_lldb_cu_to_dwarf_unit; /// DWARF does not provide a good way for traditional (concatenating) linkers diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp index d275c2cdf91c532..2135ed784252f41 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -803,7 +803,7 @@ bool SymbolFileDWARFDebugMap::CompleteType(CompilerType &compiler_type) { bool success = false; if (compiler_type) { ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool { - if (oso_dwarf->HasForwardDeclForClangType(compiler_type)) { + if (oso_dwarf->HasForwardDeclForCompilerType(compiler_type)) { oso_dwarf->CompleteType(compiler_type); success = true; return true; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp index 60313ca3a0f7b25..223af281cd57db7 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp @@ -99,14 +99,14 @@ SymbolFileDWARF::DIEToVariableSP &SymbolFileDWARFDwo::GetDIEToVariable() { return GetBaseSymbolFile().GetDIEToVariable(); } -SymbolFileDWARF::DIEToClangType & -SymbolFileDWARFDwo::GetForwardDeclDieToClangType() { - return GetBaseSymbolFile().GetForwardDeclDieToClangType(); +SymbolFileDWARF::DIEToCompilerType & +SymbolFileDWARFDwo::GetForwardDeclDIEToCompilerType() { + return GetBaseSymbolFile().GetForwardDeclDIEToCompilerType(); } -SymbolFileDWARF::ClangTypeToDIE & -SymbolFileDWARFDwo::GetForwardDeclClangTypeToDie() { - return GetBaseSymbolFile().GetForwardDeclClangTypeToDie(); +SymbolFileDWARF::CompilerTypeToDIE & +SymbolFileDWARFDwo::GetForwardDeclCompilerTypeToDIE() { + return GetBaseSymbolFile().GetForwardDeclCompilerTypeToDIE(); } void SymbolFileDWARFDwo::GetObjCMethods( diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h index 8408264c3445356..fa8376507d6a89b 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h @@ -56,9 +56,9 @@ class SymbolFileDWARFDwo : public SymbolFileDWARF { DIEToVariableSP &GetDIEToVariable() override; - DIEToClangType &GetForwardDeclDieToClangType() override; + DIEToCompilerType &GetForwardDeclDIEToCompilerType() override; - ClangTypeToDIE &GetForwardDeclClangTypeToDie() override; + CompilerTypeToDIE &GetForwardDeclCompilerTypeToDIE() override; UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() override; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits