Skip to content

Commit ff9fcc7

Browse files
committed
[lldb] Store SupportFile in CompileUnit (NFC)
Store a SupportFile, rather than a FileSpec, in CompileUnit. This commit works towards having the SourceManager operate on SupportFiles so that it can (1) validate the Checksum and (2) materialize the content of inline source information.
1 parent 4e64159 commit ff9fcc7

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

lldb/include/lldb/Symbol/CompileUnit.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class CompileUnit : public std::enable_shared_from_this<CompileUnit>,
9191
/// \param[in] user_data
9292
/// User data where the SymbolFile parser can store data.
9393
///
94-
/// \param[in] file_spec
94+
/// \param[in] support_file_sp
9595
/// The file specification for the source file of this compile
9696
/// unit.
9797
///
@@ -116,7 +116,7 @@ class CompileUnit : public std::enable_shared_from_this<CompileUnit>,
116116
/// An rvalue list of already parsed support files.
117117
/// \see lldb::LanguageType
118118
CompileUnit(const lldb::ModuleSP &module_sp, void *user_data,
119-
const FileSpec &file_spec, lldb::user_id_t uid,
119+
lldb::SupportFileSP support_file_sp, lldb::user_id_t uid,
120120
lldb::LanguageType language, lldb_private::LazyBool is_optimized,
121121
SupportFileList &&support_files = {});
122122

@@ -226,11 +226,15 @@ class CompileUnit : public std::enable_shared_from_this<CompileUnit>,
226226
const FileSpec *file_spec_ptr, bool exact,
227227
LineEntry *line_entry);
228228

229-
/// Return the primary source file associated with this compile unit.
230-
const FileSpec &GetPrimaryFile() const { return m_file_spec; }
229+
/// Return the primary source spec associated with this compile unit.
230+
const FileSpec &GetPrimaryFile() const {
231+
return m_primary_support_file_sp->GetSpecOnly();
232+
}
231233

232234
/// Return the primary source file associated with this compile unit.
233-
void SetPrimaryFile(const FileSpec &fs) { m_file_spec = fs; }
235+
lldb::SupportFileSP GetPrimarySupportFile() const {
236+
return m_primary_support_file_sp;
237+
}
234238

235239
/// Get the line table for the compile unit.
236240
///
@@ -419,7 +423,7 @@ class CompileUnit : public std::enable_shared_from_this<CompileUnit>,
419423
/// compile unit.
420424
std::vector<SourceModule> m_imported_modules;
421425
/// The primary file associated with this compile unit.
422-
FileSpec m_file_spec;
426+
lldb::SupportFileSP m_primary_support_file_sp;
423427
/// Files associated with this compile unit's line table and declarations.
424428
SupportFileList m_support_files;
425429
/// Line table that will get parsed on demand.

lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,11 @@ CompUnitSP SymbolFileBreakpad::ParseCompileUnitAtIndex(uint32_t index) {
216216
spec = (*m_files)[record->FileNum];
217217
}
218218

219-
auto cu_sp = std::make_shared<CompileUnit>(m_objfile_sp->GetModule(),
220-
/*user_data*/ nullptr, spec, index,
221-
eLanguageTypeUnknown,
222-
/*is_optimized*/ eLazyBoolNo);
219+
auto cu_sp = std::make_shared<CompileUnit>(
220+
m_objfile_sp->GetModule(),
221+
/*user_data*/ nullptr, std::make_shared<SupportFile>(spec), index,
222+
eLanguageTypeUnknown,
223+
/*is_optimized*/ eLazyBoolNo);
223224

224225
SetCompileUnitAtIndex(index, cu_sp);
225226
return cu_sp;

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -783,12 +783,12 @@ lldb::CompUnitSP SymbolFileDWARF::ParseCompileUnit(DWARFCompileUnit &dwarf_cu) {
783783
} else {
784784
ModuleSP module_sp(m_objfile_sp->GetModule());
785785
if (module_sp) {
786-
auto initialize_cu = [&](const FileSpec &file_spec,
786+
auto initialize_cu = [&](lldb::SupportFileSP support_file_sp,
787787
LanguageType cu_language,
788788
SupportFileList &&support_files = {}) {
789789
BuildCuTranslationTable();
790790
cu_sp = std::make_shared<CompileUnit>(
791-
module_sp, &dwarf_cu, file_spec,
791+
module_sp, &dwarf_cu, support_file_sp,
792792
*GetDWARFUnitIndex(dwarf_cu.GetID()), cu_language,
793793
eLazyBoolCalculate, std::move(support_files));
794794

@@ -821,7 +821,7 @@ lldb::CompUnitSP SymbolFileDWARF::ParseCompileUnit(DWARFCompileUnit &dwarf_cu) {
821821
return false;
822822
if (support_files.GetSize() == 0)
823823
return false;
824-
initialize_cu(support_files.GetFileSpecAtIndex(0),
824+
initialize_cu(support_files.GetSupportFileAtIndex(0),
825825
eLanguageTypeUnknown, std::move(support_files));
826826
return true;
827827
};
@@ -840,7 +840,8 @@ lldb::CompUnitSP SymbolFileDWARF::ParseCompileUnit(DWARFCompileUnit &dwarf_cu) {
840840
// case ParseSupportFiles takes care of the remapping.
841841
MakeAbsoluteAndRemap(cu_file_spec, dwarf_cu, module_sp);
842842

843-
initialize_cu(cu_file_spec, cu_language);
843+
initialize_cu(std::make_shared<SupportFile>(cu_file_spec),
844+
cu_language);
844845
}
845846
}
846847
}

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,10 @@ CompUnitSP SymbolFileDWARFDebugMap::ParseCompileUnitAtIndex(uint32_t cu_idx) {
598598
// User zero as the ID to match the compile unit at offset zero in each
599599
// .o file.
600600
lldb::user_id_t cu_id = 0;
601-
cu_info.compile_units_sps.push_back(
602-
std::make_shared<CompileUnit>(
603-
m_objfile_sp->GetModule(), nullptr, so_file_spec, cu_id,
604-
eLanguageTypeUnknown, eLazyBoolCalculate));
601+
cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
602+
m_objfile_sp->GetModule(), nullptr,
603+
std::make_shared<SupportFile>(so_file_spec), cu_id,
604+
eLanguageTypeUnknown, eLazyBoolCalculate));
605605
cu_info.id_to_index_map.insert({0, 0});
606606
SetCompileUnitAtIndex(cu_idx, cu_info.compile_units_sps[0]);
607607
// If there's a symbol file also register all the extra compile units.
@@ -615,7 +615,8 @@ CompUnitSP SymbolFileDWARFDebugMap::ParseCompileUnitAtIndex(uint32_t cu_idx) {
615615
if (dwarf_cu->GetID() == 0)
616616
continue;
617617
cu_info.compile_units_sps.push_back(std::make_shared<CompileUnit>(
618-
m_objfile_sp->GetModule(), nullptr, so_file_spec,
618+
m_objfile_sp->GetModule(), nullptr,
619+
std::make_shared<SupportFile>(so_file_spec),
619620
dwarf_cu->GetID(), eLanguageTypeUnknown, eLazyBoolCalculate));
620621
cu_info.id_to_index_map.insert(
621622
{dwarf_cu->GetID(), cu_info.compile_units_sps.size() - 1});

lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,9 @@ SymbolFileNativePDB::CreateCompileUnit(const CompilandIndexItem &cci) {
534534
FileSpec fs(llvm::sys::path::convert_to_slash(
535535
source_file_name, llvm::sys::path::Style::windows_backslash));
536536

537-
CompUnitSP cu_sp =
538-
std::make_shared<CompileUnit>(m_objfile_sp->GetModule(), nullptr, fs,
539-
toOpaqueUid(cci.m_id), lang, optimized);
537+
CompUnitSP cu_sp = std::make_shared<CompileUnit>(
538+
m_objfile_sp->GetModule(), nullptr, std::make_shared<SupportFile>(fs),
539+
toOpaqueUid(cci.m_id), lang, optimized);
540540

541541
SetCompileUnitAtIndex(cci.m_id.modi, cu_sp);
542542
return cu_sp;

lldb/source/Symbol/CompileUnit.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,19 @@ CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data,
2222
const char *pathname, const lldb::user_id_t cu_sym_id,
2323
lldb::LanguageType language,
2424
lldb_private::LazyBool is_optimized)
25-
: CompileUnit(module_sp, user_data, FileSpec(pathname), cu_sym_id, language,
26-
is_optimized) {}
25+
: CompileUnit(module_sp, user_data,
26+
std::make_shared<SupportFile>(FileSpec(pathname)), cu_sym_id,
27+
language, is_optimized) {}
2728

2829
CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data,
29-
const FileSpec &fspec, const lldb::user_id_t cu_sym_id,
30+
lldb::SupportFileSP support_file_sp,
31+
const lldb::user_id_t cu_sym_id,
3032
lldb::LanguageType language,
3133
lldb_private::LazyBool is_optimized,
3234
SupportFileList &&support_files)
3335
: ModuleChild(module_sp), UserID(cu_sym_id), m_user_data(user_data),
34-
m_language(language), m_flags(0), m_file_spec(fspec),
36+
m_language(language), m_flags(0),
37+
m_primary_support_file_sp(support_file_sp),
3538
m_support_files(std::move(support_files)), m_is_optimized(is_optimized) {
3639
if (language != eLanguageTypeUnknown)
3740
m_flags.Set(flagsParsedLanguage);

0 commit comments

Comments
 (0)