[SymbolFile] Make ParseCompileUnitXXX accept a CompileUnit&.
Previously all of these functions accepted a SymbolContext&.
While a CompileUnit is one member of a SymbolContext, there
are also many others, and by passing such a monolithic parameter
in this way it makes the requirements and assumptions of the
API unclear for both callers as well as implementors.
All these methods need is a CompileUnit. By limiting the
parameter type in this way, we simplify the code as well as
make it self-documenting for both implementers and users.
Differential Revision: https://reviews.llvm.org/D56564
llvm-svn: 350943
diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
index 916a7af..1878671 100644
--- a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
+++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
@@ -267,14 +267,8 @@
return ParseCompileUnitForUID(compiland_up->getSymIndexId(), index);
}
-lldb::LanguageType
-SymbolFilePDB::ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) {
- // What fields should I expect to be filled out on the SymbolContext? Is it
- // safe to assume that `sc.comp_unit` is valid?
- if (!sc.comp_unit)
- return lldb::eLanguageTypeUnknown;
-
- auto compiland_up = GetPDBCompilandByUID(sc.comp_unit->GetID());
+lldb::LanguageType SymbolFilePDB::ParseLanguage(CompileUnit &comp_unit) {
+ auto compiland_up = GetPDBCompilandByUID(comp_unit.GetID());
if (!compiland_up)
return lldb::eLanguageTypeUnknown;
auto details = compiland_up->findOneChild<PDBSymbolCompilandDetails>();
@@ -283,12 +277,10 @@
return TranslateLanguage(details->getLanguage());
}
-lldb_private::Function *SymbolFilePDB::ParseCompileUnitFunctionForPDBFunc(
- const PDBSymbolFunc &pdb_func, const lldb_private::SymbolContext &sc) {
- lldbassert(sc.comp_unit && sc.module_sp.get());
-
- if (FunctionSP result =
- sc.comp_unit->FindFunctionByUID(pdb_func.getSymIndexId()))
+lldb_private::Function *
+SymbolFilePDB::ParseCompileUnitFunctionForPDBFunc(const PDBSymbolFunc &pdb_func,
+ CompileUnit &comp_unit) {
+ if (FunctionSP result = comp_unit.FindFunctionByUID(pdb_func.getSymIndexId()))
return result.get();
auto file_vm_addr = pdb_func.getVirtualAddress();
@@ -297,7 +289,8 @@
auto func_length = pdb_func.getLength();
AddressRange func_range =
- AddressRange(file_vm_addr, func_length, sc.module_sp->GetSectionList());
+ AddressRange(file_vm_addr, func_length,
+ GetObjectFile()->GetModule()->GetSectionList());
if (!func_range.GetBaseAddress().IsValid())
return nullptr;
@@ -310,10 +303,10 @@
Mangled mangled = GetMangledForPDBFunc(pdb_func);
FunctionSP func_sp =
- std::make_shared<Function>(sc.comp_unit, pdb_func.getSymIndexId(),
+ std::make_shared<Function>(&comp_unit, pdb_func.getSymIndexId(),
func_type_uid, mangled, func_type, func_range);
- sc.comp_unit->AddFunction(func_sp);
+ comp_unit.AddFunction(func_sp);
TypeSystem *type_system = GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus);
if (!type_system)
@@ -327,52 +320,44 @@
return func_sp.get();
}
-size_t SymbolFilePDB::ParseCompileUnitFunctions(
- const lldb_private::SymbolContext &sc) {
- lldbassert(sc.comp_unit);
+size_t SymbolFilePDB::ParseFunctions(CompileUnit &comp_unit) {
size_t func_added = 0;
- auto compiland_up = GetPDBCompilandByUID(sc.comp_unit->GetID());
+ auto compiland_up = GetPDBCompilandByUID(comp_unit.GetID());
if (!compiland_up)
return 0;
auto results_up = compiland_up->findAllChildren<PDBSymbolFunc>();
if (!results_up)
return 0;
while (auto pdb_func_up = results_up->getNext()) {
- auto func_sp =
- sc.comp_unit->FindFunctionByUID(pdb_func_up->getSymIndexId());
+ auto func_sp = comp_unit.FindFunctionByUID(pdb_func_up->getSymIndexId());
if (!func_sp) {
- if (ParseCompileUnitFunctionForPDBFunc(*pdb_func_up, sc))
+ if (ParseCompileUnitFunctionForPDBFunc(*pdb_func_up, comp_unit))
++func_added;
}
}
return func_added;
}
-bool SymbolFilePDB::ParseCompileUnitLineTable(
- const lldb_private::SymbolContext &sc) {
- lldbassert(sc.comp_unit);
- if (sc.comp_unit->GetLineTable())
+bool SymbolFilePDB::ParseLineTable(CompileUnit &comp_unit) {
+ if (comp_unit.GetLineTable())
return true;
- return ParseCompileUnitLineTable(sc, 0);
+ return ParseCompileUnitLineTable(comp_unit, 0);
}
-bool SymbolFilePDB::ParseCompileUnitDebugMacros(
- const lldb_private::SymbolContext &sc) {
+bool SymbolFilePDB::ParseDebugMacros(CompileUnit &comp_unit) {
// PDB doesn't contain information about macros
return false;
}
-bool SymbolFilePDB::ParseCompileUnitSupportFiles(
- const lldb_private::SymbolContext &sc,
- lldb_private::FileSpecList &support_files) {
- lldbassert(sc.comp_unit);
+bool SymbolFilePDB::ParseSupportFiles(
+ CompileUnit &comp_unit, lldb_private::FileSpecList &support_files) {
// In theory this is unnecessary work for us, because all of this information
// is easily (and quickly) accessible from DebugInfoPDB, so caching it a
// second time seems like a waste. Unfortunately, there's no good way around
// this short of a moderate refactor since SymbolVendor depends on being able
// to cache this list.
- auto compiland_up = GetPDBCompilandByUID(sc.comp_unit->GetID());
+ auto compiland_up = GetPDBCompilandByUID(comp_unit.GetID());
if (!compiland_up)
return false;
auto files = m_session_up->getSourceFilesForCompiland(*compiland_up);
@@ -386,7 +371,7 @@
// LLDB uses the DWARF-like file numeration (one based),
// the zeroth file is the compile unit itself
- support_files.Insert(0, *sc.comp_unit);
+ support_files.Insert(0, comp_unit);
return true;
}
@@ -464,7 +449,7 @@
return num_added;
}
-size_t SymbolFilePDB::ParseTypesForCompileUnit(CompileUnit &comp_unit) {
+size_t SymbolFilePDB::ParseTypes(CompileUnit &comp_unit) {
size_t num_added = 0;
auto compiland = GetPDBCompilandByUID(comp_unit.GetID());
@@ -726,7 +711,8 @@
auto func_uid = pdb_func->getSymIndexId();
sc.function = sc.comp_unit->FindFunctionByUID(func_uid).get();
if (sc.function == nullptr)
- sc.function = ParseCompileUnitFunctionForPDBFunc(*pdb_func, sc);
+ sc.function =
+ ParseCompileUnitFunctionForPDBFunc(*pdb_func, *sc.comp_unit);
if (sc.function) {
resolved_flags |= eSymbolContextFunction;
if (resolve_scope & eSymbolContextBlock) {
@@ -796,7 +782,7 @@
// table that match the requested line (or all lines if `line` == 0).
if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock |
eSymbolContextLineEntry)) {
- bool has_line_table = ParseCompileUnitLineTable(sc, line);
+ bool has_line_table = ParseCompileUnitLineTable(*sc.comp_unit, line);
if ((resolve_scope & eSymbolContextLineEntry) && !has_line_table) {
// The query asks for line entries, but we can't get them for the
@@ -839,7 +825,8 @@
if (sc.function == nullptr) {
auto pdb_func = llvm::dyn_cast<PDBSymbolFunc>(symbol_up.get());
assert(pdb_func);
- sc.function = ParseCompileUnitFunctionForPDBFunc(*pdb_func, sc);
+ sc.function = ParseCompileUnitFunctionForPDBFunc(*pdb_func,
+ *sc.comp_unit);
}
if (sc.function && (resolve_scope & eSymbolContextBlock)) {
Block &block = sc.function->GetBlock(true);
@@ -1139,7 +1126,7 @@
if (!sc.comp_unit)
return false;
sc.module_sp = sc.comp_unit->GetModule();
- sc.function = ParseCompileUnitFunctionForPDBFunc(pdb_func, sc);
+ sc.function = ParseCompileUnitFunctionForPDBFunc(pdb_func, *sc.comp_unit);
if (!sc.function)
return false;
@@ -1717,11 +1704,9 @@
return cu_sp;
}
-bool SymbolFilePDB::ParseCompileUnitLineTable(
- const lldb_private::SymbolContext &sc, uint32_t match_line) {
- lldbassert(sc.comp_unit);
-
- auto compiland_up = GetPDBCompilandByUID(sc.comp_unit->GetID());
+bool SymbolFilePDB::ParseCompileUnitLineTable(CompileUnit &comp_unit,
+ uint32_t match_line) {
+ auto compiland_up = GetPDBCompilandByUID(comp_unit.GetID());
if (!compiland_up)
return false;
@@ -1731,10 +1716,10 @@
// to do a mapping so that we can hand out indices.
llvm::DenseMap<uint32_t, uint32_t> index_map;
BuildSupportFileIdToSupportFileIndexMap(*compiland_up, index_map);
- auto line_table = llvm::make_unique<LineTable>(sc.comp_unit);
+ auto line_table = llvm::make_unique<LineTable>(&comp_unit);
// Find contributions to `compiland` from all source and header files.
- std::string path = sc.comp_unit->GetPath();
+ std::string path = comp_unit.GetPath();
auto files = m_session_up->getSourceFilesForCompiland(*compiland_up);
if (!files)
return false;
@@ -1818,7 +1803,7 @@
}
if (line_table->GetSize()) {
- sc.comp_unit->SetLineTable(line_table.release());
+ comp_unit.SetLineTable(line_table.release());
return true;
}
return false;