[Lldb-commits] [lldb] r367086 - SymbolVendor: Move Symtab construction into the SymbolFile

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Fri Jul 26 00:03:28 PDT 2019


Author: labath
Date: Fri Jul 26 00:03:28 2019
New Revision: 367086

URL: http://llvm.org/viewvc/llvm-project?rev=367086&view=rev
Log:
SymbolVendor: Move Symtab construction into the SymbolFile

Summary:
Instead of having SymbolVendor coordinate Symtab construction between
Symbol and Object files, make the SymbolVendor function a passthrough,
and put all of the logic into the SymbolFile.

Reviewers: clayborg, JDevlieghere, jingham, espindola

Subscribers: emaste, mgorny, arichardson, MaskRay, lldb-commits

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

Modified:
    lldb/trunk/include/lldb/Symbol/SymbolFile.h
    lldb/trunk/include/lldb/Symbol/SymbolVendor.h
    lldb/trunk/source/Symbol/SymbolFile.cpp
    lldb/trunk/source/Symbol/SymbolVendor.cpp
    lldb/trunk/unittests/Core/CMakeLists.txt
    lldb/trunk/unittests/Core/MangledTest.cpp
    lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt
    lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
    lldb/trunk/unittests/Symbol/CMakeLists.txt
    lldb/trunk/unittests/Symbol/TestDWARFCallFrameInfo.cpp
    lldb/trunk/unittests/Target/CMakeLists.txt
    lldb/trunk/unittests/Target/ModuleCacheTest.cpp

Modified: lldb/trunk/include/lldb/Symbol/SymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolFile.h?rev=367086&r1=367085&r2=367086&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolFile.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolFile.h Fri Jul 26 00:03:28 2019
@@ -114,6 +114,8 @@ public:
   uint32_t GetNumCompileUnits();
   lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx);
 
+  Symtab *GetSymtab();
+
   virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) = 0;
   virtual size_t ParseFunctions(CompileUnit &comp_unit) = 0;
   virtual bool ParseLineTable(CompileUnit &comp_unit) = 0;
@@ -246,6 +248,7 @@ protected:
   ObjectFile *m_obj_file; // The object file that symbols can be extracted from.
   llvm::Optional<std::vector<lldb::CompUnitSP>> m_compile_units;
   TypeList m_type_list;
+  Symtab *m_symtab = nullptr;
   uint32_t m_abilities;
   bool m_calculated_abilities;
 

Modified: lldb/trunk/include/lldb/Symbol/SymbolVendor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolVendor.h?rev=367086&r1=367085&r2=367086&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolVendor.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolVendor.h Fri Jul 26 00:03:28 2019
@@ -121,9 +121,6 @@ public:
   // Get module unified section list symbol table.
   virtual Symtab *GetSymtab();
 
-  // Clear module unified section list symbol table.
-  virtual void ClearSymtab();
-
   /// Notify the SymbolVendor that the file addresses in the Sections
   /// for this module have been changed.
   virtual void SectionFileAddressesChanged();
@@ -140,8 +137,6 @@ protected:
                                    // file)
   std::unique_ptr<SymbolFile> m_sym_file_up; // A single symbol file. Subclasses
                                              // can add more of these if needed.
-  Symtab *m_symtab; // Save a symtab once to not pass it through `AddSymbols` of
-                    // the symbol file each time when it is needed
 
 private:
   // For SymbolVendor only

Modified: lldb/trunk/source/Symbol/SymbolFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolFile.cpp?rev=367086&r1=367085&r2=367086&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolFile.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolFile.cpp Fri Jul 26 00:03:28 2019
@@ -200,6 +200,21 @@ void SymbolFile::SetCompileUnitAtIndex(u
   (*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 = m_obj_file->GetModule()->GetObjectFile()->GetSymtab();
+
+  // Then add our symbols to it.
+  if (m_symtab)
+    AddSymbols(*m_symtab);
+
+  return m_symtab;
+}
+
 void SymbolFile::Dump(Stream &s) {
   s.PutCString("Types:\n");
   m_type_list.Dump(&s, /*show_context*/ false);

Modified: lldb/trunk/source/Symbol/SymbolVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolVendor.cpp?rev=367086&r1=367085&r2=367086&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolVendor.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolVendor.cpp Fri Jul 26 00:03:28 2019
@@ -58,7 +58,7 @@ SymbolVendor *SymbolVendor::FindPlugin(c
 
 // SymbolVendor constructor
 SymbolVendor::SymbolVendor(const lldb::ModuleSP &module_sp)
-    : ModuleChild(module_sp), m_sym_file_up(), m_symtab() {}
+    : ModuleChild(module_sp), m_sym_file_up() {}
 
 // Destructor
 SymbolVendor::~SymbolVendor() {}
@@ -384,35 +384,9 @@ FileSpec SymbolVendor::GetMainFileSpec()
 }
 
 Symtab *SymbolVendor::GetSymtab() {
-  ModuleSP module_sp(GetModule());
-  if (!module_sp)
-    return nullptr;
-
-  std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
-
-  if (m_symtab)
-    return m_symtab;
-
-  ObjectFile *objfile = module_sp->GetObjectFile();
-  if (!objfile)
-    return nullptr;
-
-  m_symtab = objfile->GetSymtab();
-  if (m_symtab && m_sym_file_up)
-    m_sym_file_up->AddSymbols(*m_symtab);
-
-  return m_symtab;
-}
-
-void SymbolVendor::ClearSymtab() {
-  ModuleSP module_sp(GetModule());
-  if (module_sp) {
-    ObjectFile *objfile = module_sp->GetObjectFile();
-    if (objfile) {
-      // Clear symbol table from unified section list.
-      objfile->ClearSymtab();
-    }
-  }
+  if (m_sym_file_up)
+    return m_sym_file_up->GetSymtab();
+  return nullptr;
 }
 
 void SymbolVendor::SectionFileAddressesChanged() {

Modified: lldb/trunk/unittests/Core/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Core/CMakeLists.txt?rev=367086&r1=367085&r2=367086&view=diff
==============================================================================
--- lldb/trunk/unittests/Core/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Core/CMakeLists.txt Fri Jul 26 00:03:28 2019
@@ -9,7 +9,7 @@ add_lldb_unittest(LLDBCoreTests
     lldbHost
     lldbSymbol
     lldbPluginObjectFileELF
-    lldbPluginSymbolVendorELF
+    lldbPluginSymbolFileSymtab
     lldbUtilityHelpers
     LLVMTestingSupport
   LINK_COMPONENTS

Modified: lldb/trunk/unittests/Core/MangledTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Core/MangledTest.cpp?rev=367086&r1=367085&r2=367086&view=diff
==============================================================================
--- lldb/trunk/unittests/Core/MangledTest.cpp (original)
+++ lldb/trunk/unittests/Core/MangledTest.cpp Fri Jul 26 00:03:28 2019
@@ -7,7 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
-#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
+#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
 #include "TestingSupport/TestUtilities.h"
 
 #include "lldb/Core/Mangled.h"
@@ -54,7 +54,7 @@ TEST(MangledTest, NameIndexes_FindFuncti
   FileSystem::Initialize();
   HostInfo::Initialize();
   ObjectFileELF::Initialize();
-  SymbolVendorELF::Initialize();
+  SymbolFileSymtab::Initialize();
 
   llvm::SmallString<128> Obj;
   ASSERT_NO_ERROR(llvm::sys::fs::createTemporaryFile(
@@ -146,7 +146,7 @@ TEST(MangledTest, NameIndexes_FindFuncti
   EXPECT_EQ(0, Count("undemangable", eFunctionNameTypeBase));
   EXPECT_EQ(0, Count("undemangable", eFunctionNameTypeMethod));
 
-  SymbolVendorELF::Terminate();
+  SymbolFileSymtab::Terminate();
   ObjectFileELF::Terminate();
   HostInfo::Terminate();
   FileSystem::Terminate();

Modified: lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt?rev=367086&r1=367085&r2=367086&view=diff
==============================================================================
--- lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt (original)
+++ lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt Fri Jul 26 00:03:28 2019
@@ -3,7 +3,7 @@ add_lldb_unittest(ObjectFileELFTests
 
   LINK_LIBS
     lldbPluginObjectFileELF
-    lldbPluginSymbolVendorELF
+    lldbPluginSymbolFileSymtab
     lldbCore
     lldbUtilityHelpers
     LLVMTestingSupport

Modified: lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp?rev=367086&r1=367085&r2=367086&view=diff
==============================================================================
--- lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp (original)
+++ lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp Fri Jul 26 00:03:28 2019
@@ -8,7 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
-#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
+#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
 #include "TestingSupport/TestUtilities.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleSpec.h"
@@ -34,11 +34,11 @@ public:
     FileSystem::Initialize();
     HostInfo::Initialize();
     ObjectFileELF::Initialize();
-    SymbolVendorELF::Initialize();
+    SymbolFileSymtab::Initialize();
   }
 
   void TearDown() override {
-    SymbolVendorELF::Terminate();
+    SymbolFileSymtab::Terminate();
     ObjectFileELF::Terminate();
     HostInfo::Terminate();
     FileSystem::Terminate();

Modified: lldb/trunk/unittests/Symbol/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Symbol/CMakeLists.txt?rev=367086&r1=367085&r2=367086&view=diff
==============================================================================
--- lldb/trunk/unittests/Symbol/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Symbol/CMakeLists.txt Fri Jul 26 00:03:28 2019
@@ -13,6 +13,7 @@ add_lldb_unittest(SymbolTests
     lldbPluginObjectFileELF
     lldbPluginObjectFileMachO
     lldbPluginSymbolFileDWARF
+    lldbPluginSymbolFileSymtab
     LLVMTestingSupport
   )
 

Modified: lldb/trunk/unittests/Symbol/TestDWARFCallFrameInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Symbol/TestDWARFCallFrameInfo.cpp?rev=367086&r1=367085&r2=367086&view=diff
==============================================================================
--- lldb/trunk/unittests/Symbol/TestDWARFCallFrameInfo.cpp (original)
+++ lldb/trunk/unittests/Symbol/TestDWARFCallFrameInfo.cpp Fri Jul 26 00:03:28 2019
@@ -11,6 +11,7 @@
 
 #include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
 #include "Plugins/Process/Utility/RegisterContext_x86.h"
+#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
 #include "TestingSupport/TestUtilities.h"
 
 #include "lldb/Core/Module.h"
@@ -36,9 +37,11 @@ public:
     FileSystem::Initialize();
     HostInfo::Initialize();
     ObjectFileELF::Initialize();
+    SymbolFileSymtab::Initialize();
   }
 
   void TearDown() override {
+    SymbolFileSymtab::Terminate();
     ObjectFileELF::Terminate();
     HostInfo::Terminate();
     FileSystem::Terminate();

Modified: lldb/trunk/unittests/Target/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Target/CMakeLists.txt?rev=367086&r1=367085&r2=367086&view=diff
==============================================================================
--- lldb/trunk/unittests/Target/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Target/CMakeLists.txt Fri Jul 26 00:03:28 2019
@@ -10,6 +10,7 @@ add_lldb_unittest(TargetTests
       lldbSymbol
       lldbUtility
       lldbPluginObjectFileELF
+      lldbPluginSymbolFileSymtab
       lldbUtilityHelpers
     LINK_COMPONENTS
       Support

Modified: lldb/trunk/unittests/Target/ModuleCacheTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Target/ModuleCacheTest.cpp?rev=367086&r1=367085&r2=367086&view=diff
==============================================================================
--- lldb/trunk/unittests/Target/ModuleCacheTest.cpp (original)
+++ lldb/trunk/unittests/Target/ModuleCacheTest.cpp Fri Jul 26 00:03:28 2019
@@ -5,6 +5,7 @@
 #include "llvm/Support/Path.h"
 
 #include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
 #include "TestingSupport/TestUtilities.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleSpec.h"
@@ -69,12 +70,14 @@ void ModuleCacheTest::SetUpTestCase() {
   FileSystem::Initialize();
   HostInfo::Initialize();
   ObjectFileELF::Initialize();
+  SymbolFileSymtab::Initialize();
 
   s_cache_dir = HostInfo::GetProcessTempDir();
   s_test_executable = GetInputFilePath(module_name);
 }
 
 void ModuleCacheTest::TearDownTestCase() {
+  SymbolFileSymtab::Terminate();
   ObjectFileELF::Terminate();
   HostInfo::Terminate();
   FileSystem::Terminate();




More information about the lldb-commits mailing list