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
llvm-svn: 366791
diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
index 17dfcda..c6c25fd 100644
--- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
@@ -123,8 +123,7 @@
}
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 @@
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 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(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 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 @@
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;
}