[Lldb-commits] [lldb] r366791 - SymbolVendor: Move compile unit handling into the SymbolFile class
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 23 02:24:02 PDT 2019
Author: labath
Date: Tue Jul 23 02:24:02 2019
New Revision: 366791
URL: http://llvm.org/viewvc/llvm-project?rev=366791&view=rev
Log:
SymbolVendor: Move compile unit handling into the SymbolFile class
Summary:
SymbolFile classes are responsible for creating CompileUnit instances
and they already need to have a notion of the id<->CompileUnit mapping
(because of APIs like ParseCompileUnitAtIndex). However, the
SymbolVendor has remained as the thing responsible for caching created
units (which the SymbolFiles were calling via convoluted constructs like
"m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(...)").
This patch moves the responsibility of caching the units into the
SymbolFile class. It does this by moving the implementation of
SymbolVendor::{GetNumCompileUnits,GetCompileUnitAtIndex} into the
equivalent SymbolFile functions. The SymbolVendor functions become just
a passthrough much like the rest of SymbolVendor.
The original implementations of SymbolFile::GetNumCompileUnits is moved
to "CalculateNumCompileUnits", and are made protected, as the "Get"
function is the external api of the class.
SymbolFile::ParseCompileUnitAtIndex is made protected for the same
reason.
This is the first step in removing the SymbolVendor indirection, as
proposed in
<http://lists.llvm.org/pipermail/lldb-dev/2019-June/015071.html>. After
removing all interesting logic from the SymbolVendor class, I'll proceed
with removing the indirection itself.
Reviewers: clayborg, jingham, JDevlieghere
Subscribers: jdoerfert, lldb-commits
Differential Revision: https://reviews.llvm.org/D65089
Modified:
lldb/trunk/include/lldb/Symbol/SymbolFile.h
lldb/trunk/include/lldb/Symbol/SymbolVendor.h
lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
lldb/trunk/source/Symbol/SymbolFile.cpp
lldb/trunk/source/Symbol/SymbolVendor.cpp
lldb/trunk/tools/lldb-test/lldb-test.cpp
Modified: lldb/trunk/include/lldb/Symbol/SymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolFile.h?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolFile.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolFile.h Tue Jul 23 02:24:02 2019
@@ -110,8 +110,8 @@ public:
// Compile Unit function calls
// Approach 1 - iterator
- virtual uint32_t GetNumCompileUnits() = 0;
- virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) = 0;
+ uint32_t GetNumCompileUnits();
+ lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx);
virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) = 0;
virtual size_t ParseFunctions(CompileUnit &comp_unit) = 0;
@@ -235,12 +235,17 @@ public:
return nullptr;
}
- virtual void Dump(Stream &s) {}
+ virtual void Dump(Stream &s);
protected:
void AssertModuleLock();
+ virtual uint32_t CalculateNumCompileUnits() = 0;
+ virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t idx) = 0;
+
+ void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp);
ObjectFile *m_obj_file; // The object file that symbols can be extracted from.
+ llvm::Optional<std::vector<lldb::CompUnitSP>> m_compile_units;
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=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolVendor.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolVendor.h Tue Jul 23 02:24:02 2019
@@ -110,9 +110,6 @@ public:
virtual size_t GetNumCompileUnits();
- virtual bool SetCompileUnitAtIndex(size_t cu_idx,
- const lldb::CompUnitSP &cu_sp);
-
virtual lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx);
TypeList &GetTypeList() { return m_type_list; }
@@ -142,13 +139,7 @@ public:
uint32_t GetPluginVersion() override;
protected:
- // Classes that inherit from SymbolVendor can see and modify these
- typedef std::vector<lldb::CompUnitSP> CompileUnits;
- typedef CompileUnits::iterator CompileUnitIter;
- typedef CompileUnits::const_iterator CompileUnitConstIter;
-
TypeList m_type_list; // Uniqued types for all parsers owned by this module
- CompileUnits m_compile_units; // The current compile units
lldb::ObjectFileSP m_objfile_sp; // Keep a reference to the object file in
// case it isn't the same as the module
// object file (debug symbols in a separate
Modified: lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp Tue Jul 23 02:24:02 2019
@@ -187,7 +187,7 @@ uint32_t SymbolFileBreakpad::CalculateAb
return CompileUnits | Functions | LineTables;
}
-uint32_t SymbolFileBreakpad::GetNumCompileUnits() {
+uint32_t SymbolFileBreakpad::CalculateNumCompileUnits() {
ParseCUData();
return m_cu_data->GetSize();
}
@@ -218,7 +218,7 @@ CompUnitSP SymbolFileBreakpad::ParseComp
eLanguageTypeUnknown,
/*is_optimized*/ eLazyBoolNo);
- GetSymbolVendor().SetCompileUnitAtIndex(index, cu_sp);
+ SetCompileUnitAtIndex(index, cu_sp);
return cu_sp;
}
@@ -260,7 +260,7 @@ SymbolFileBreakpad::ResolveSymbolContext
if (idx == UINT32_MAX)
return 0;
- sc.comp_unit = GetSymbolVendor().GetCompileUnitAtIndex(idx).get();
+ sc.comp_unit = GetCompileUnitAtIndex(idx).get();
SymbolContextItem result = eSymbolContextCompUnit;
if (resolve_scope & eSymbolContextLineEntry) {
if (sc.comp_unit->GetLineTable()->FindLineEntryByAddress(so_addr,
@@ -280,7 +280,7 @@ uint32_t SymbolFileBreakpad::ResolveSymb
uint32_t old_size = sc_list.GetSize();
for (size_t i = 0, size = GetNumCompileUnits(); i < size; ++i) {
- CompileUnit &cu = *GetSymbolVendor().GetCompileUnitAtIndex(i);
+ CompileUnit &cu = *GetCompileUnitAtIndex(i);
cu.ResolveSymbolContext(file_spec, line, check_inlines,
/*exact*/ false, resolve_scope, sc_list);
}
@@ -522,10 +522,6 @@ SymbolFileBreakpad::GetUnwindPlan(const
return plan_sp;
}
-SymbolVendor &SymbolFileBreakpad::GetSymbolVendor() {
- return *m_obj_file->GetModule()->GetSymbolVendor();
-}
-
addr_t SymbolFileBreakpad::GetBaseFileAddress() {
return m_obj_file->GetModule()
->GetObjectFile()
Modified: lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h Tue Jul 23 02:24:02 2019
@@ -46,10 +46,6 @@ public:
// Compile Unit function calls
- uint32_t GetNumCompileUnits() override;
-
- lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
-
lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override {
return lldb::eLanguageTypeUnknown;
}
@@ -196,7 +192,9 @@ private:
};
- SymbolVendor &GetSymbolVendor();
+ uint32_t CalculateNumCompileUnits() override;
+ lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
+
lldb::addr_t GetBaseFileAddress();
void ParseFileRecords();
void ParseCUData();
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Tue Jul 23 02:24:02 2019
@@ -677,8 +677,7 @@ lldb::CompUnitSP SymbolFileDWARF::ParseC
dwarf_cu.SetUserData(cu_sp.get());
- m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(
- dwarf_cu.GetID(), cu_sp);
+ SetCompileUnitAtIndex(dwarf_cu.GetID(), cu_sp);
}
}
}
@@ -715,7 +714,7 @@ llvm::Optional<uint32_t> SymbolFileDWARF
return m_lldb_cu_to_dwarf_unit[cu_idx];
}
-uint32_t SymbolFileDWARF::GetNumCompileUnits() {
+uint32_t SymbolFileDWARF::CalculateNumCompileUnits() {
DWARFDebugInfo *info = DebugInfo();
if (!info)
return 0;
@@ -3713,7 +3712,10 @@ ConstString SymbolFileDWARF::GetPluginNa
uint32_t SymbolFileDWARF::GetPluginVersion() { return 1; }
-void SymbolFileDWARF::Dump(lldb_private::Stream &s) { m_index->Dump(s); }
+void SymbolFileDWARF::Dump(lldb_private::Stream &s) {
+ SymbolFile::Dump(s);
+ m_index->Dump(s);
+}
void SymbolFileDWARF::DumpClangAST(Stream &s) {
TypeSystem *ts = GetTypeSystemForLanguage(eLanguageTypeC_plus_plus);
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Tue Jul 23 02:24:02 2019
@@ -95,10 +95,6 @@ public:
// Compile Unit function calls
- uint32_t GetNumCompileUnits() override;
-
- lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
-
lldb::LanguageType
ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
@@ -331,6 +327,10 @@ protected:
bool DeclContextMatchesThisSymbolFile(
const lldb_private::CompilerDeclContext *decl_ctx);
+ uint32_t CalculateNumCompileUnits() override;
+
+ lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
+
virtual DWARFUnit *
GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit);
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp Tue Jul 23 02:24:02 2019
@@ -562,7 +562,7 @@ uint32_t SymbolFileDWARFDebugMap::Calcul
return 0;
}
-uint32_t SymbolFileDWARFDebugMap::GetNumCompileUnits() {
+uint32_t SymbolFileDWARFDebugMap::CalculateNumCompileUnits() {
InitOSO();
return m_compile_unit_infos.size();
}
@@ -585,9 +585,8 @@ CompUnitSP SymbolFileDWARFDebugMap::Pars
eLanguageTypeUnknown, eLazyBoolCalculate);
if (m_compile_unit_infos[cu_idx].compile_unit_sp) {
- // Let our symbol vendor know about this compile unit
- m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(
- cu_idx, m_compile_unit_infos[cu_idx].compile_unit_sp);
+ SetCompileUnitAtIndex(cu_idx,
+ m_compile_unit_infos[cu_idx].compile_unit_sp);
}
}
}
@@ -1284,8 +1283,7 @@ void SymbolFileDWARFDebugMap::SetCompile
cu_sp.get());
} else {
m_compile_unit_infos[cu_idx].compile_unit_sp = cu_sp;
- m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(
- cu_idx, cu_sp);
+ SetCompileUnitAtIndex(cu_idx, cu_sp);
}
}
}
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h Tue Jul 23 02:24:02 2019
@@ -44,9 +44,6 @@ public:
void InitializeObject() override;
// Compile Unit function calls
- uint32_t GetNumCompileUnits() override;
- lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
-
lldb::LanguageType
ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
@@ -174,6 +171,9 @@ protected:
// Protected Member Functions
void InitOSO();
+ uint32_t CalculateNumCompileUnits() override;
+ lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
+
static uint32_t GetOSOIndexFromUserID(lldb::user_id_t uid) {
return (uint32_t)((uid >> 32ull) - 1ull);
}
Modified: lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp Tue Jul 23 02:24:02 2019
@@ -329,7 +329,7 @@ void SymbolFileNativePDB::InitializeObje
m_ast = llvm::make_unique<PdbAstBuilder>(*m_obj_file, *m_index);
}
-uint32_t SymbolFileNativePDB::GetNumCompileUnits() {
+uint32_t SymbolFileNativePDB::CalculateNumCompileUnits() {
const DbiModuleList &modules = m_index->dbi().modules();
uint32_t count = modules.getModuleCount();
if (count == 0)
@@ -433,8 +433,7 @@ SymbolFileNativePDB::CreateCompileUnit(c
std::make_shared<CompileUnit>(m_obj_file->GetModule(), nullptr, fs,
toOpaqueUid(cci.m_id), lang, optimized);
- m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(
- cci.m_id.modi, cu_sp);
+ SetCompileUnitAtIndex(cci.m_id.modi, cu_sp);
return cu_sp;
}
Modified: lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h Tue Jul 23 02:24:02 2019
@@ -68,13 +68,9 @@ public:
// Compile Unit function calls
- uint32_t GetNumCompileUnits() override;
-
void
ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
- lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
-
lldb::LanguageType
ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
@@ -157,6 +153,9 @@ public:
void DumpClangAST(Stream &s) override;
private:
+ uint32_t CalculateNumCompileUnits() override;
+
+ lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
size_t FindTypesByName(llvm::StringRef name, uint32_t max_matches,
TypeMap &types);
Modified: lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp Tue Jul 23 02:24:02 2019
@@ -123,8 +123,7 @@ SymbolFilePDB::CreateInstance(lldb_priva
}
SymbolFilePDB::SymbolFilePDB(lldb_private::ObjectFile *object_file)
- : SymbolFile(object_file), m_session_up(), m_global_scope_up(),
- m_cached_compile_unit_count(0) {}
+ : SymbolFile(object_file), m_session_up(), m_global_scope_up() {}
SymbolFilePDB::~SymbolFilePDB() {}
@@ -191,33 +190,30 @@ void SymbolFilePDB::InitializeObject() {
lldbassert(m_global_scope_up.get());
}
-uint32_t SymbolFilePDB::GetNumCompileUnits() {
- if (m_cached_compile_unit_count == 0) {
- auto compilands = m_global_scope_up->findAllChildren<PDBSymbolCompiland>();
- if (!compilands)
- return 0;
+uint32_t SymbolFilePDB::CalculateNumCompileUnits() {
+ auto compilands = m_global_scope_up->findAllChildren<PDBSymbolCompiland>();
+ if (!compilands)
+ return 0;
- // The linker could link *.dll (compiland language = LINK), or import
- // *.dll. For example, a compiland with name `Import:KERNEL32.dll` could be
- // found as a child of the global scope (PDB executable). Usually, such
- // compilands contain `thunk` symbols in which we are not interested for
- // now. However we still count them in the compiland list. If we perform
- // any compiland related activity, like finding symbols through
- // llvm::pdb::IPDBSession methods, such compilands will all be searched
- // automatically no matter whether we include them or not.
- m_cached_compile_unit_count = compilands->getChildCount();
-
- // The linker can inject an additional "dummy" compilation unit into the
- // PDB. Ignore this special compile unit for our purposes, if it is there.
- // It is always the last one.
- auto last_compiland_up =
- compilands->getChildAtIndex(m_cached_compile_unit_count - 1);
- lldbassert(last_compiland_up.get());
- std::string name = last_compiland_up->getName();
- if (name == "* Linker *")
- --m_cached_compile_unit_count;
- }
- return m_cached_compile_unit_count;
+ // The linker could link *.dll (compiland language = LINK), or import
+ // *.dll. For example, a compiland with name `Import:KERNEL32.dll` could be
+ // found as a child of the global scope (PDB executable). Usually, such
+ // compilands contain `thunk` symbols in which we are not interested for
+ // now. However we still count them in the compiland list. If we perform
+ // any compiland related activity, like finding symbols through
+ // llvm::pdb::IPDBSession methods, such compilands will all be searched
+ // automatically no matter whether we include them or not.
+ uint32_t compile_unit_count = compilands->getChildCount();
+
+ // The linker can inject an additional "dummy" compilation unit into the
+ // PDB. Ignore this special compile unit for our purposes, if it is there.
+ // It is always the last one.
+ auto last_compiland_up = compilands->getChildAtIndex(compile_unit_count - 1);
+ lldbassert(last_compiland_up.get());
+ std::string name = last_compiland_up->getName();
+ if (name == "* Linker *")
+ --compile_unit_count;
+ return compile_unit_count;
}
void SymbolFilePDB::GetCompileUnitIndex(
@@ -1698,8 +1694,7 @@ lldb::CompUnitSP SymbolFilePDB::ParseCom
if (index == UINT32_MAX)
GetCompileUnitIndex(*compiland_up, index);
lldbassert(index != UINT32_MAX);
- m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(index,
- cu_sp);
+ SetCompileUnitAtIndex(index, cu_sp);
return cu_sp;
}
Modified: lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h Tue Jul 23 02:24:02 2019
@@ -48,10 +48,6 @@ public:
// Compile Unit function calls
- uint32_t GetNumCompileUnits() override;
-
- lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
-
lldb::LanguageType
ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
@@ -173,6 +169,10 @@ private:
};
using SecContribsMap = std::map<uint32_t, std::vector<SecContribInfo>>;
+ uint32_t CalculateNumCompileUnits() override;
+
+ lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
+
lldb::CompUnitSP ParseCompileUnitForUID(uint32_t id,
uint32_t index = UINT32_MAX);
@@ -245,7 +245,6 @@ private:
std::vector<lldb::TypeSP> m_builtin_types;
std::unique_ptr<llvm::pdb::IPDBSession> m_session_up;
std::unique_ptr<llvm::pdb::PDBSymbolExe> m_global_scope_up;
- uint32_t m_cached_compile_unit_count;
lldb_private::UniqueCStringMap<uint32_t> m_func_full_names;
lldb_private::UniqueCStringMap<uint32_t> m_func_base_names;
Modified: lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp Tue Jul 23 02:24:02 2019
@@ -104,7 +104,7 @@ uint32_t SymbolFileSymtab::CalculateAbil
return abilities;
}
-uint32_t SymbolFileSymtab::GetNumCompileUnits() {
+uint32_t SymbolFileSymtab::CalculateNumCompileUnits() {
// If we don't have any source file symbols we will just have one compile
// unit for the entire object file
if (m_source_indexes.empty())
Modified: lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.h Tue Jul 23 02:24:02 2019
@@ -37,10 +37,6 @@ public:
uint32_t CalculateAbilities() override;
// Compile Unit function calls
- uint32_t GetNumCompileUnits() override;
-
- lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
-
lldb::LanguageType
ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
@@ -85,6 +81,10 @@ public:
uint32_t GetPluginVersion() override;
protected:
+ uint32_t CalculateNumCompileUnits() override;
+
+ lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
+
typedef std::map<lldb_private::ConstString, lldb::TypeSP> TypeMap;
lldb_private::Symtab::IndexCollection m_source_indexes;
Modified: lldb/trunk/source/Symbol/SymbolFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolFile.cpp?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolFile.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolFile.cpp Tue Jul 23 02:24:02 2019
@@ -10,6 +10,7 @@
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
+#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/TypeMap.h"
#include "lldb/Symbol/TypeSystem.h"
@@ -21,6 +22,7 @@
#include <future>
using namespace lldb_private;
+using namespace lldb;
void SymbolFile::PreloadSymbols() {
// No-op for most implementations.
@@ -169,4 +171,50 @@ void SymbolFile::AssertModuleLock() {
#endif
}
+uint32_t SymbolFile::GetNumCompileUnits() {
+ std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
+ if (!m_compile_units) {
+ // Create an array of compile unit shared pointers -- which will each
+ // remain NULL until someone asks for the actual compile unit information.
+ m_compile_units.emplace(CalculateNumCompileUnits());
+ }
+ return m_compile_units->size();
+}
+
+CompUnitSP SymbolFile::GetCompileUnitAtIndex(uint32_t idx) {
+ uint32_t num = GetNumCompileUnits();
+ if (idx >= num)
+ return nullptr;
+ lldb::CompUnitSP &cu_sp = (*m_compile_units)[idx];
+ if (!cu_sp)
+ cu_sp = ParseCompileUnitAtIndex(idx);
+ return cu_sp;
+}
+
+void SymbolFile::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);
+
+ // Fire off an assertion if this compile unit already exists for now. The
+ // partial parsing should take care of only setting the compile unit
+ // once, so if this assertion fails, we need to make sure that we don't
+ // have a race condition, or have a second parse of the same compile
+ // unit.
+ assert((*m_compile_units)[idx] == nullptr);
+ (*m_compile_units)[idx] = cu_sp;
+}
+
+void SymbolFile::Dump(Stream &s) {
+ s.PutCString("Compile units:\n");
+ if (m_compile_units) {
+ for (const CompUnitSP &cu_sp : *m_compile_units) {
+ // We currently only dump the compile units that have been parsed
+ if (cu_sp)
+ cu_sp->Dump(&s, /*show_context*/ false);
+ }
+ }
+ s.PutChar('\n');
+}
+
SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default;
Modified: lldb/trunk/source/Symbol/SymbolVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolVendor.cpp?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolVendor.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolVendor.cpp Tue Jul 23 02:24:02 2019
@@ -58,8 +58,7 @@ SymbolVendor *SymbolVendor::FindPlugin(c
// SymbolVendor constructor
SymbolVendor::SymbolVendor(const lldb::ModuleSP &module_sp)
- : ModuleChild(module_sp), m_type_list(), m_compile_units(), m_sym_file_up(),
- m_symtab() {}
+ : ModuleChild(module_sp), m_type_list(), m_sym_file_up(), m_symtab() {}
// Destructor
SymbolVendor::~SymbolVendor() {}
@@ -76,44 +75,14 @@ void SymbolVendor::AddSymbolFileRepresen
}
}
-bool SymbolVendor::SetCompileUnitAtIndex(size_t idx, const CompUnitSP &cu_sp) {
- ModuleSP module_sp(GetModule());
- if (module_sp) {
- std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
- const size_t num_compile_units = GetNumCompileUnits();
- if (idx < num_compile_units) {
- // Fire off an assertion if this compile unit already exists for now. The
- // partial parsing should take care of only setting the compile unit
- // once, so if this assertion fails, we need to make sure that we don't
- // have a race condition, or have a second parse of the same compile
- // unit.
- assert(m_compile_units[idx].get() == nullptr);
- m_compile_units[idx] = cu_sp;
- return true;
- } else {
- // This should NOT happen, and if it does, we want to crash and know
- // about it
- assert(idx < num_compile_units);
- }
- }
- return false;
-}
-
size_t SymbolVendor::GetNumCompileUnits() {
ModuleSP module_sp(GetModule());
if (module_sp) {
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
- if (m_compile_units.empty()) {
- if (m_sym_file_up) {
- // Resize our array of compile unit shared pointers -- which will each
- // remain NULL until someone asks for the actual compile unit
- // information. When this happens, the symbol file will be asked to
- // parse this compile unit information.
- m_compile_units.resize(m_sym_file_up->GetNumCompileUnits());
- }
- }
+ if (m_sym_file_up)
+ return m_sym_file_up->GetNumCompileUnits();
}
- return m_compile_units.size();
+ return 0;
}
lldb::LanguageType SymbolVendor::ParseLanguage(CompileUnit &comp_unit) {
@@ -390,14 +359,6 @@ void SymbolVendor::Dump(Stream *s) {
s->IndentMore();
m_type_list.Dump(s, show_context);
- CompileUnitConstIter cu_pos, cu_end;
- cu_end = m_compile_units.end();
- for (cu_pos = m_compile_units.begin(); cu_pos != cu_end; ++cu_pos) {
- // We currently only dump the compile units that have been parsed
- if (*cu_pos)
- (*cu_pos)->Dump(s, show_context);
- }
-
if (Symtab *symtab = GetSymtab())
symtab->Dump(s, nullptr, eSortOrderNone);
@@ -406,20 +367,13 @@ void SymbolVendor::Dump(Stream *s) {
}
CompUnitSP SymbolVendor::GetCompileUnitAtIndex(size_t idx) {
- CompUnitSP cu_sp;
ModuleSP module_sp(GetModule());
if (module_sp) {
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
- const size_t num_compile_units = GetNumCompileUnits();
- if (idx < num_compile_units) {
- cu_sp = m_compile_units[idx];
- if (cu_sp.get() == nullptr) {
- m_compile_units[idx] = m_sym_file_up->ParseCompileUnitAtIndex(idx);
- cu_sp = m_compile_units[idx];
- }
- }
+ if (m_sym_file_up)
+ return m_sym_file_up->GetCompileUnitAtIndex(idx);
}
- return cu_sp;
+ return nullptr;
}
FileSpec SymbolVendor::GetMainFileSpec() const {
Modified: lldb/trunk/tools/lldb-test/lldb-test.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-test/lldb-test.cpp?rev=366791&r1=366790&r2=366791&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-test/lldb-test.cpp (original)
+++ lldb/trunk/tools/lldb-test/lldb-test.cpp Tue Jul 23 02:24:02 2019
@@ -558,7 +558,7 @@ Error opts::symbols::verify(lldb_private
outs() << "Found " << comp_units_count << " compile units.\n";
for (uint32_t i = 0; i < comp_units_count; i++) {
- lldb::CompUnitSP comp_unit = symfile->ParseCompileUnitAtIndex(i);
+ lldb::CompUnitSP comp_unit = symfile->GetCompileUnitAtIndex(i);
if (!comp_unit)
return make_string_error("Connot parse compile unit {0}.", i);
More information about the lldb-commits
mailing list