[Lldb-commits] [lldb] 5cbf516 - Refactor protected virtual functions from SymbolFile into new SymbolFileCommon class.

Jeffrey Tan via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 25 18:34:06 PDT 2022


Author: Jeffrey Tan
Date: 2022-04-25T18:33:47-07:00
New Revision: 5cbf516cb79fa27395dabb33002ab20243b1ee5d

URL: https://github.com/llvm/llvm-project/commit/5cbf516cb79fa27395dabb33002ab20243b1ee5d
DIFF: https://github.com/llvm/llvm-project/commit/5cbf516cb79fa27395dabb33002ab20243b1ee5d.diff

LOG: Refactor protected virtual functions from SymbolFile into new SymbolFileCommon class.

This is a preparatory patch for https://reviews.llvm.org/D121631.
It refactors protected virtual members of SymbolFile
into a new SymbolFileCommon class per suggestion in:
https://reviews.llvm.org/D121631

This will avoid the friendship declaration in that patch.

Differential Revision: https://reviews.llvm.org/D124110

Added: 
    

Modified: 
    lldb/include/lldb/Symbol/SymbolFile.h
    lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
    lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
    lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
    lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
    lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
    lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
    lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
    lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
    lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
    lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
    lldb/source/Symbol/SymbolFile.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Symbol/SymbolFile.h b/lldb/include/lldb/Symbol/SymbolFile.h
index c7bb6c16f0398..c9be5dbd2b256 100644
--- 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 @@ class SymbolFile : public PluginInterface {
   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 @@ class SymbolFile : public PluginInterface {
   ///     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 @@ class SymbolFile : public PluginInterface {
 
   // 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 @@ class SymbolFile : public PluginInterface {
   virtual void PreloadSymbols();
 
   virtual llvm::Expected<lldb_private::TypeSystem &>
-  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<std::unique_ptr<CallEdge>>
   ParseCallEdgesInFunction(UserID func_id) {
@@ -276,7 +273,7 @@ class SymbolFile : public PluginInterface {
 
   /// 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 @@ class SymbolFile : public PluginInterface {
                                    "Operation not supported.");
   }
 
-  virtual void Dump(Stream &s);
+  virtual void Dump(Stream &s) = 0;
 
   /// Metrics gathering functions
 
@@ -311,7 +308,7 @@ class SymbolFile : public PluginInterface {
   /// 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 @@ class SymbolFile : public PluginInterface {
   /// 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<lldb_private::TypeSystem &>
+  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 @@ class SymbolFile : public PluginInterface {
   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
index bf3e25c1a63ed..639d2e272adf7 100644
--- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
+++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
@@ -20,7 +20,7 @@ namespace lldb_private {
 
 namespace breakpad {
 
-class SymbolFileBreakpad : public SymbolFile {
+class SymbolFileBreakpad : public SymbolFileCommon {
   /// LLVM RTTI support.
   static char ID;
 
@@ -28,7 +28,7 @@ class SymbolFileBreakpad : public SymbolFile {
   /// 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 @@ class SymbolFileBreakpad : public SymbolFile {
 
   // 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.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index e207c32d6ad38..5252c5f11abbe 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -274,7 +274,7 @@ TypeList &SymbolFileDWARF::GetTypeList() {
   std::lock_guard<std::recursive_mutex> 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::GetParentSymbolContextDIE(const DWARFDIE &child_die) {
 
 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 @@ SymbolFileDWARF::ParseCallEdgesInFunction(UserID func_id) {
 }
 
 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/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
index 86338ccdf68cc..2403ee2624ea1 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -56,7 +56,7 @@ class SymbolFileDWARFDwp;
 
 #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 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
   /// 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
index e36d8e85732b7..7637726892a08 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -237,7 +237,7 @@ SymbolFile *SymbolFileDWARFDebugMap::CreateInstance(ObjectFileSP objfile_sp) {
 }
 
 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/DWARF/SymbolFileDWARFDebugMap.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
index 7bff978941a5e..52c4d77a10b63 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -22,7 +22,7 @@ class SymbolFileDWARF;
 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 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
   /// 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
index 57b3cca47daa8..fcbf667798644 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
@@ -254,7 +254,7 @@ SymbolFile *SymbolFileNativePDB::CreateInstance(ObjectFileSP objfile_sp) {
 }
 
 SymbolFileNativePDB::SymbolFileNativePDB(ObjectFileSP objfile_sp)
-    : SymbolFile(std::move(objfile_sp)) {}
+    : SymbolFileCommon(std::move(objfile_sp)) {}
 
 SymbolFileNativePDB::~SymbolFileNativePDB() = default;
 
@@ -1936,4 +1936,3 @@ uint64_t SymbolFileNativePDB::GetDebugInfoSize() {
   // PDB files are a separate file that contains all debug info.
   return m_index->pdb().getFileSize();
 }
-

diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
index d626daf4e95d3..187791b0fd014 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
@@ -39,7 +39,7 @@ namespace lldb_private {
 namespace npdb {
 class PdbAstBuilder;
 
-class SymbolFileNativePDB : public SymbolFile {
+class SymbolFileNativePDB : public SymbolFileCommon {
   friend class UdtRecordCompleter;
 
   /// LLVM RTTI support.
@@ -49,7 +49,7 @@ class SymbolFileNativePDB : public SymbolFile {
   /// 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
index 130353dfc67a6..5567ca409c566 100644
--- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
@@ -135,7 +135,7 @@ SymbolFilePDB::CreateInstance(ObjectFileSP objfile_sp) {
 }
 
 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/PDB/SymbolFilePDB.h b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
index 69f1d268edfd7..5d4b51ba2e19d 100644
--- 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 @@ class SymbolFilePDB : public lldb_private::SymbolFile {
   /// 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
index d95cfea5e8729..cc22eaeef779c 100644
--- a/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
+++ b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
@@ -51,8 +51,8 @@ void SymbolFileSymtab::GetTypes(SymbolContextScope *sc_scope,
                                 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/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h b/lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
index 2dad12baac6f6..0a9fa5fce1b0b 100644
--- 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 @@ class SymbolFileSymtab : public lldb_private::SymbolFile {
   /// 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/Symbol/SymbolFile.cpp b/lldb/source/Symbol/SymbolFile.cpp
index b85901af4d67f..440c22887d83c 100644
--- a/lldb/source/Symbol/SymbolFile.cpp
+++ b/lldb/source/Symbol/SymbolFile.cpp
@@ -25,6 +25,7 @@ using namespace lldb_private;
 using namespace lldb;
 
 char SymbolFile::ID;
+char SymbolFileCommon::ID;
 
 void SymbolFile::PreloadSymbols() {
   // No-op for most implementations.
@@ -33,9 +34,6 @@ void SymbolFile::PreloadSymbols() {
 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<SymbolFile> best_symfile_up;
@@ -87,16 +85,6 @@ SymbolFile *SymbolFile::FindPlugin(ObjectFileSP objfile_sp) {
   return best_symfile_up.release();
 }
 
-llvm::Expected<TypeSystem &>
-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 @@ void SymbolFile::AssertModuleLock() {
 #endif
 }
 
-uint32_t SymbolFile::GetNumCompileUnits() {
+SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default;
+
+Symtab *SymbolFileCommon::GetSymtab() {
+  std::lock_guard<std::recursive_mutex> 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<std::recursive_mutex> guard(GetModuleMutex());
   if (!m_compile_units) {
     // Create an array of compile unit shared pointers -- which will each
@@ -164,7 +182,7 @@ uint32_t SymbolFile::GetNumCompileUnits() {
   return m_compile_units->size();
 }
 
-CompUnitSP SymbolFile::GetCompileUnitAtIndex(uint32_t idx) {
+CompUnitSP SymbolFileCommon::GetCompileUnitAtIndex(uint32_t idx) {
   std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
   uint32_t num = GetNumCompileUnits();
   if (idx >= num)
@@ -175,7 +193,8 @@ CompUnitSP SymbolFile::GetCompileUnitAtIndex(uint32_t idx) {
   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<std::recursive_mutex> guard(GetModuleMutex());
   const size_t num_compile_units = GetNumCompileUnits();
   assert(idx < num_compile_units);
@@ -190,31 +209,29 @@ void SymbolFile::SetCompileUnitAtIndex(uint32_t idx, const CompUnitSP &cu_sp) {
   (*m_compile_units)[idx] = cu_sp;
 }
 
-Symtab *SymbolFile::GetSymtab() {
-  std::lock_guard<std::recursive_mutex> 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<TypeSystem &>
+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 @@ void SymbolFile::Dump(Stream &s) {
   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;
-}


        


More information about the lldb-commits mailing list