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

llvm-svn: 367086
This commit is contained in:
Pavel Labath 2019-07-26 07:03:28 +00:00
parent 3c3a76527e
commit 84a6856928
12 changed files with 38 additions and 43 deletions

View File

@ -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;

View File

@ -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

View File

@ -200,6 +200,21 @@ 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 = 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);

View File

@ -58,7 +58,7 @@ SymbolVendor *SymbolVendor::FindPlugin(const lldb::ModuleSP &module_sp,
// 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() const {
}
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() {

View File

@ -9,7 +9,7 @@ add_lldb_unittest(LLDBCoreTests
lldbHost
lldbSymbol
lldbPluginObjectFileELF
lldbPluginSymbolVendorELF
lldbPluginSymbolFileSymtab
lldbUtilityHelpers
LLVMTestingSupport
LINK_COMPONENTS

View File

@ -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_FindFunctionSymbols) {
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_FindFunctionSymbols) {
EXPECT_EQ(0, Count("undemangable", eFunctionNameTypeBase));
EXPECT_EQ(0, Count("undemangable", eFunctionNameTypeMethod));
SymbolVendorELF::Terminate();
SymbolFileSymtab::Terminate();
ObjectFileELF::Terminate();
HostInfo::Terminate();
FileSystem::Terminate();

View File

@ -3,7 +3,7 @@ add_lldb_unittest(ObjectFileELFTests
LINK_LIBS
lldbPluginObjectFileELF
lldbPluginSymbolVendorELF
lldbPluginSymbolFileSymtab
lldbCore
lldbUtilityHelpers
LLVMTestingSupport

View File

@ -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();

View File

@ -13,6 +13,7 @@ add_lldb_unittest(SymbolTests
lldbPluginObjectFileELF
lldbPluginObjectFileMachO
lldbPluginSymbolFileDWARF
lldbPluginSymbolFileSymtab
LLVMTestingSupport
)

View File

@ -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();

View File

@ -10,6 +10,7 @@ add_lldb_unittest(TargetTests
lldbSymbol
lldbUtility
lldbPluginObjectFileELF
lldbPluginSymbolFileSymtab
lldbUtilityHelpers
LINK_COMPONENTS
Support

View File

@ -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();