diff --git a/lldb/include/lldb/Symbol/SymbolFile.h b/lldb/include/lldb/Symbol/SymbolFile.h --- a/lldb/include/lldb/Symbol/SymbolFile.h +++ b/lldb/include/lldb/Symbol/SymbolFile.h @@ -36,6 +36,12 @@ namespace lldb_private { +/// Provides public interface for all SymbolFiles. Any protected +/// virtual members should go into SymbolFileCommon; most SymbolFile +/// implementations should inherit from SymbolFileCommon to override +/// the behaviors except SymbolFileOnDemand which inherits +/// public interfaces from SymbolFile and forward to underlying concrete +/// SymbolFile implementation. class SymbolFile : public PluginInterface { /// LLVM RTTI support. static char ID; @@ -67,8 +73,7 @@ static SymbolFile *FindPlugin(lldb::ObjectFileSP objfile_sp); // Constructors and Destructors - SymbolFile(lldb::ObjectFileSP objfile_sp) - : m_objfile_sp(std::move(objfile_sp)) {} + SymbolFile() = default; ~SymbolFile() override = default; @@ -99,15 +104,7 @@ /// A uint32_t mask containing bits from the SymbolFile::Abilities /// enumeration. Any bits that are set represent an ability that /// this symbol plug-in can parse from the object file. - uint32_t GetAbilities() { - if (!m_calculated_abilities) { - m_abilities = CalculateAbilities(); - m_calculated_abilities = true; - } - - return m_abilities; - } - + virtual uint32_t GetAbilities() = 0; virtual uint32_t CalculateAbilities() = 0; /// Symbols file subclasses should override this to return the Module that @@ -125,10 +122,10 @@ // Compile Unit function calls // Approach 1 - iterator - uint32_t GetNumCompileUnits(); - lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx); + virtual uint32_t GetNumCompileUnits() = 0; + virtual lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) = 0; - Symtab *GetSymtab(); + virtual Symtab *GetSymtab() = 0; virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) = 0; /// Return the Xcode SDK comp_unit was compiled against. @@ -256,16 +253,16 @@ virtual void PreloadSymbols(); virtual llvm::Expected - GetTypeSystemForLanguage(lldb::LanguageType language); + GetTypeSystemForLanguage(lldb::LanguageType language) = 0; virtual CompilerDeclContext FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx) { return CompilerDeclContext(); } - ObjectFile *GetObjectFile() { return m_objfile_sp.get(); } - const ObjectFile *GetObjectFile() const { return m_objfile_sp.get(); } - ObjectFile *GetMainObjectFile(); + virtual ObjectFile *GetObjectFile() = 0; + virtual const ObjectFile *GetObjectFile() const = 0; + virtual ObjectFile *GetMainObjectFile() = 0; virtual std::vector> ParseCallEdgesInFunction(UserID func_id) { @@ -276,7 +273,7 @@ /// Notify the SymbolFile that the file addresses in the Sections /// for this module have been changed. - virtual void SectionFileAddressesChanged(); + virtual void SectionFileAddressesChanged() = 0; struct RegisterInfoResolver { virtual ~RegisterInfoResolver(); // anchor @@ -297,7 +294,7 @@ "Operation not supported."); } - virtual void Dump(Stream &s); + virtual void Dump(Stream &s) = 0; /// Metrics gathering functions @@ -311,7 +308,7 @@ /// entire file should be returned. The default implementation of this /// function will iterate over all sections in a module and add up their /// debug info only section byte sizes. - virtual uint64_t GetDebugInfoSize(); + virtual uint64_t GetDebugInfoSize() = 0; /// Return the time taken to parse the debug information. /// @@ -344,26 +341,90 @@ /// index is saved to the cache, debug sessions can be slower. These accessors /// can be accessed by the statistics and emitted to help track these costs. /// \{ - bool GetDebugInfoIndexWasLoadedFromCache() const { + virtual bool GetDebugInfoIndexWasLoadedFromCache() const = 0; + virtual void SetDebugInfoIndexWasLoadedFromCache() = 0; + virtual bool GetDebugInfoIndexWasSavedToCache() const = 0; + virtual void SetDebugInfoIndexWasSavedToCache() = 0; + /// \} + +protected: + void AssertModuleLock(); + +private: + SymbolFile(const SymbolFile &) = delete; + const SymbolFile &operator=(const SymbolFile &) = delete; +}; + +/// Containing protected virtual methods for child classes to override. +/// Most actual SymbolFile implementations should inherit from this class. +class SymbolFileCommon : public SymbolFile { + /// LLVM RTTI support. + static char ID; + +public: + /// LLVM RTTI support. + /// \{ + bool isA(const void *ClassID) const override { + return ClassID == &ID || SymbolFile::isA(ClassID); + } + static bool classof(const SymbolFileCommon *obj) { return obj->isA(&ID); } + /// \} + + // Constructors and Destructors + SymbolFileCommon(lldb::ObjectFileSP objfile_sp) + : m_objfile_sp(std::move(objfile_sp)) {} + + ~SymbolFileCommon() override = default; + + uint32_t GetAbilities() override { + if (!m_calculated_abilities) { + m_abilities = CalculateAbilities(); + m_calculated_abilities = true; + } + return m_abilities; + } + + Symtab *GetSymtab() override; + + ObjectFile *GetObjectFile() override { return m_objfile_sp.get(); } + const ObjectFile *GetObjectFile() const override { + return m_objfile_sp.get(); + } + ObjectFile *GetMainObjectFile() override; + + /// Notify the SymbolFile that the file addresses in the Sections + /// for this module have been changed. + void SectionFileAddressesChanged() override; + + // Compile Unit function calls + // Approach 1 - iterator + uint32_t GetNumCompileUnits() override; + lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) override; + + llvm::Expected + GetTypeSystemForLanguage(lldb::LanguageType language) override; + + void Dump(Stream &s) override; + + uint64_t GetDebugInfoSize() override; + + bool GetDebugInfoIndexWasLoadedFromCache() const override { return m_index_was_loaded_from_cache; } - void SetDebugInfoIndexWasLoadedFromCache() { + void SetDebugInfoIndexWasLoadedFromCache() override { m_index_was_loaded_from_cache = true; } - bool GetDebugInfoIndexWasSavedToCache() const { + bool GetDebugInfoIndexWasSavedToCache() const override { return m_index_was_saved_to_cache; } - void SetDebugInfoIndexWasSavedToCache() { + void SetDebugInfoIndexWasSavedToCache() override { m_index_was_saved_to_cache = true; } - /// \} protected: - void AssertModuleLock(); virtual uint32_t CalculateNumCompileUnits() = 0; virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t idx) = 0; virtual TypeList &GetTypeList() { return m_type_list; } - void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp); lldb::ObjectFileSP m_objfile_sp; // Keep a reference to the object file in @@ -379,8 +440,8 @@ bool m_index_was_saved_to_cache = false; private: - SymbolFile(const SymbolFile &) = delete; - const SymbolFile &operator=(const SymbolFile &) = delete; + SymbolFileCommon(const SymbolFileCommon &) = delete; + const SymbolFileCommon &operator=(const SymbolFileCommon &) = delete; }; } // namespace lldb_private diff --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h --- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h +++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h @@ -20,7 +20,7 @@ namespace breakpad { -class SymbolFileBreakpad : public SymbolFile { +class SymbolFileBreakpad : public SymbolFileCommon { /// LLVM RTTI support. static char ID; @@ -28,7 +28,7 @@ /// LLVM RTTI support. /// \{ bool isA(const void *ClassID) const override { - return ClassID == &ID || SymbolFile::isA(ClassID); + return ClassID == &ID || SymbolFileCommon::isA(ClassID); } static bool classof(const SymbolFile *obj) { return obj->isA(&ID); } /// \} @@ -49,7 +49,7 @@ // Constructors and Destructors SymbolFileBreakpad(lldb::ObjectFileSP objfile_sp) - : SymbolFile(std::move(objfile_sp)) {} + : SymbolFileCommon(std::move(objfile_sp)) {} ~SymbolFileBreakpad() override = default; 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 @@ -56,7 +56,7 @@ #define DIE_IS_BEING_PARSED ((lldb_private::Type *)1) -class SymbolFileDWARF : public lldb_private::SymbolFile, +class SymbolFileDWARF : public lldb_private::SymbolFileCommon, public lldb_private::UserID { /// LLVM RTTI support. static char ID; @@ -65,7 +65,7 @@ /// LLVM RTTI support. /// \{ bool isA(const void *ClassID) const override { - return ClassID == &ID || SymbolFile::isA(ClassID); + return ClassID == &ID || SymbolFileCommon::isA(ClassID); } static bool classof(const SymbolFile *obj) { return obj->isA(&ID); } /// \} 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 @@ -274,7 +274,7 @@ std::lock_guard guard(GetModuleMutex()); if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile()) return debug_map_symfile->GetTypeList(); - return SymbolFile::GetTypeList(); + return SymbolFileCommon::GetTypeList(); } void SymbolFileDWARF::GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset, dw_offset_t max_die_offset, uint32_t type_mask, @@ -407,7 +407,7 @@ SymbolFileDWARF::SymbolFileDWARF(ObjectFileSP objfile_sp, SectionList *dwo_section_list) - : SymbolFile(std::move(objfile_sp)), + : SymbolFileCommon(std::move(objfile_sp)), UserID(0x7fffffff00000000), // Used by SymbolFileDWARFDebugMap to // when this class parses .o files to // contain the .o file index/ID @@ -3968,7 +3968,7 @@ } void SymbolFileDWARF::Dump(lldb_private::Stream &s) { - SymbolFile::Dump(s); + SymbolFileCommon::Dump(s); m_index->Dump(s); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h @@ -22,7 +22,7 @@ class DWARFDebugAranges; class DWARFDeclContext; -class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile { +class SymbolFileDWARFDebugMap : public lldb_private::SymbolFileCommon { /// LLVM RTTI support. static char ID; @@ -30,7 +30,7 @@ /// LLVM RTTI support. /// \{ bool isA(const void *ClassID) const override { - return ClassID == &ID || SymbolFile::isA(ClassID); + return ClassID == &ID || SymbolFileCommon::isA(ClassID); } static bool classof(const SymbolFile *obj) { return obj->isA(&ID); } /// \} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -237,7 +237,7 @@ } SymbolFileDWARFDebugMap::SymbolFileDWARFDebugMap(ObjectFileSP objfile_sp) - : SymbolFile(std::move(objfile_sp)), m_flags(), m_compile_unit_infos(), + : SymbolFileCommon(std::move(objfile_sp)), m_flags(), m_compile_unit_infos(), m_func_indexes(), m_glob_indexes(), m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate) {} diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h @@ -39,7 +39,7 @@ namespace npdb { class PdbAstBuilder; -class SymbolFileNativePDB : public SymbolFile { +class SymbolFileNativePDB : public SymbolFileCommon { friend class UdtRecordCompleter; /// LLVM RTTI support. @@ -49,7 +49,7 @@ /// LLVM RTTI support. /// \{ bool isA(const void *ClassID) const override { - return ClassID == &ID || SymbolFile::isA(ClassID); + return ClassID == &ID || SymbolFileCommon::isA(ClassID); } static bool classof(const SymbolFile *obj) { return obj->isA(&ID); } /// \} diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -254,7 +254,7 @@ } SymbolFileNativePDB::SymbolFileNativePDB(ObjectFileSP objfile_sp) - : SymbolFile(std::move(objfile_sp)) {} + : SymbolFileCommon(std::move(objfile_sp)) {} SymbolFileNativePDB::~SymbolFileNativePDB() = default; @@ -1936,4 +1936,3 @@ // PDB files are a separate file that contains all debug info. return m_index->pdb().getFileSize(); } - diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h --- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h +++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h @@ -21,7 +21,7 @@ class PDBASTParser; -class SymbolFilePDB : public lldb_private::SymbolFile { +class SymbolFilePDB : public lldb_private::SymbolFileCommon { /// LLVM RTTI support. static char ID; @@ -29,7 +29,7 @@ /// LLVM RTTI support. /// \{ bool isA(const void *ClassID) const override { - return ClassID == &ID || SymbolFile::isA(ClassID); + return ClassID == &ID || SymbolFileCommon::isA(ClassID); } static bool classof(const SymbolFile *obj) { return obj->isA(&ID); } /// \} diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp --- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp @@ -135,7 +135,7 @@ } SymbolFilePDB::SymbolFilePDB(lldb::ObjectFileSP objfile_sp) - : SymbolFile(std::move(objfile_sp)), m_session_up(), m_global_scope_up() {} + : SymbolFileCommon(std::move(objfile_sp)), m_session_up(), m_global_scope_up() {} SymbolFilePDB::~SymbolFilePDB() = default; diff --git a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h --- a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h +++ b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h @@ -15,7 +15,7 @@ #include "lldb/Symbol/SymbolFile.h" #include "lldb/Symbol/Symtab.h" -class SymbolFileSymtab : public lldb_private::SymbolFile { +class SymbolFileSymtab : public lldb_private::SymbolFileCommon { /// LLVM RTTI support. static char ID; @@ -23,7 +23,7 @@ /// LLVM RTTI support. /// \{ bool isA(const void *ClassID) const override { - return ClassID == &ID || SymbolFile::isA(ClassID); + return ClassID == &ID || SymbolFileCommon::isA(ClassID); } static bool classof(const SymbolFile *obj) { return obj->isA(&ID); } /// \} diff --git a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp --- a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp +++ b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp @@ -51,8 +51,8 @@ lldb_private::TypeList &type_list) {} SymbolFileSymtab::SymbolFileSymtab(ObjectFileSP objfile_sp) - : SymbolFile(std::move(objfile_sp)), m_source_indexes(), m_func_indexes(), - m_code_indexes(), m_objc_class_name_to_index() {} + : SymbolFileCommon(std::move(objfile_sp)), m_source_indexes(), + m_func_indexes(), m_code_indexes(), m_objc_class_name_to_index() {} uint32_t SymbolFileSymtab::CalculateAbilities() { uint32_t abilities = 0; diff --git a/lldb/source/Symbol/SymbolFile.cpp b/lldb/source/Symbol/SymbolFile.cpp --- a/lldb/source/Symbol/SymbolFile.cpp +++ b/lldb/source/Symbol/SymbolFile.cpp @@ -25,6 +25,7 @@ using namespace lldb; char SymbolFile::ID; +char SymbolFileCommon::ID; void SymbolFile::PreloadSymbols() { // No-op for most implementations. @@ -33,9 +34,6 @@ std::recursive_mutex &SymbolFile::GetModuleMutex() const { return GetObjectFile()->GetModule()->GetMutex(); } -ObjectFile *SymbolFile::GetMainObjectFile() { - return m_objfile_sp->GetModule()->GetObjectFile(); -} SymbolFile *SymbolFile::FindPlugin(ObjectFileSP objfile_sp) { std::unique_ptr best_symfile_up; @@ -87,16 +85,6 @@ return best_symfile_up.release(); } -llvm::Expected -SymbolFile::GetTypeSystemForLanguage(lldb::LanguageType language) { - auto type_system_or_err = - m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language); - if (type_system_or_err) { - type_system_or_err->SetSymbolFile(this); - } - return type_system_or_err; -} - uint32_t SymbolFile::ResolveSymbolContext(const SourceLocationSpec &src_location_spec, lldb::SymbolContextItem resolve_scope, @@ -154,7 +142,37 @@ #endif } -uint32_t SymbolFile::GetNumCompileUnits() { +SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default; + +Symtab *SymbolFileCommon::GetSymtab() { + std::lock_guard guard(GetModuleMutex()); + if (m_symtab) + return m_symtab; + + // Fetch the symtab from the main object file. + m_symtab = GetMainObjectFile()->GetSymtab(); + + // Then add our symbols to it. + if (m_symtab) + AddSymbols(*m_symtab); + + return m_symtab; +} + +ObjectFile *SymbolFileCommon::GetMainObjectFile() { + return m_objfile_sp->GetModule()->GetObjectFile(); +} + +void SymbolFileCommon::SectionFileAddressesChanged() { + ObjectFile *module_objfile = GetMainObjectFile(); + ObjectFile *symfile_objfile = GetObjectFile(); + if (symfile_objfile != module_objfile) + symfile_objfile->SectionFileAddressesChanged(); + if (m_symtab) + m_symtab->SectionFileAddressesChanged(); +} + +uint32_t SymbolFileCommon::GetNumCompileUnits() { std::lock_guard guard(GetModuleMutex()); if (!m_compile_units) { // Create an array of compile unit shared pointers -- which will each @@ -164,7 +182,7 @@ return m_compile_units->size(); } -CompUnitSP SymbolFile::GetCompileUnitAtIndex(uint32_t idx) { +CompUnitSP SymbolFileCommon::GetCompileUnitAtIndex(uint32_t idx) { std::lock_guard guard(GetModuleMutex()); uint32_t num = GetNumCompileUnits(); if (idx >= num) @@ -175,7 +193,8 @@ return cu_sp; } -void SymbolFile::SetCompileUnitAtIndex(uint32_t idx, const CompUnitSP &cu_sp) { +void SymbolFileCommon::SetCompileUnitAtIndex(uint32_t idx, + const CompUnitSP &cu_sp) { std::lock_guard guard(GetModuleMutex()); const size_t num_compile_units = GetNumCompileUnits(); assert(idx < num_compile_units); @@ -190,31 +209,29 @@ (*m_compile_units)[idx] = cu_sp; } -Symtab *SymbolFile::GetSymtab() { - std::lock_guard guard(GetModuleMutex()); - if (m_symtab) - return m_symtab; - - // Fetch the symtab from the main object file. - m_symtab = GetMainObjectFile()->GetSymtab(); - - // Then add our symbols to it. - if (m_symtab) - AddSymbols(*m_symtab); - - return m_symtab; +llvm::Expected +SymbolFileCommon::GetTypeSystemForLanguage(lldb::LanguageType language) { + auto type_system_or_err = + m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language); + if (type_system_or_err) { + type_system_or_err->SetSymbolFile(this); + } + return type_system_or_err; } -void SymbolFile::SectionFileAddressesChanged() { - ObjectFile *module_objfile = GetMainObjectFile(); - ObjectFile *symfile_objfile = GetObjectFile(); - if (symfile_objfile != module_objfile) - symfile_objfile->SectionFileAddressesChanged(); - if (m_symtab) - m_symtab->SectionFileAddressesChanged(); +uint64_t SymbolFileCommon::GetDebugInfoSize() { + if (!m_objfile_sp) + return 0; + ModuleSP module_sp(m_objfile_sp->GetModule()); + if (!module_sp) + return 0; + const SectionList *section_list = module_sp->GetSectionList(); + if (section_list) + return section_list->GetDebugInfoSize(); + return 0; } -void SymbolFile::Dump(Stream &s) { +void SymbolFileCommon::Dump(Stream &s) { s.Format("SymbolFile {0} ({1})\n", GetPluginName(), GetMainObjectFile()->GetFileSpec()); s.PutCString("Types:\n"); @@ -234,17 +251,3 @@ if (Symtab *symtab = GetSymtab()) symtab->Dump(&s, nullptr, eSortOrderNone); } - -SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default; - -uint64_t SymbolFile::GetDebugInfoSize() { - if (!m_objfile_sp) - return 0; - ModuleSP module_sp(m_objfile_sp->GetModule()); - if (!module_sp) - return 0; - const SectionList *section_list = module_sp->GetSectionList(); - if (section_list) - return section_list->GetDebugInfoSize(); - return 0; -}