Skip to content

Commit 5cbf516

Browse files
author
Jeffrey Tan
committed
Refactor protected virtual functions from SymbolFile into new SymbolFileCommon class.
This is a preparatory patch for https://reviews.llvm.org/D121631. It refactors protected virtual members of SymbolFile into a new SymbolFileCommon class per suggestion in: https://reviews.llvm.org/D121631 This will avoid the friendship declaration in that patch. Differential Revision: https://reviews.llvm.org/D124110
1 parent 3143840 commit 5cbf516

File tree

13 files changed

+166
-103
lines changed

13 files changed

+166
-103
lines changed

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 91 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636

3737
namespace lldb_private {
3838

39+
/// Provides public interface for all SymbolFiles. Any protected
40+
/// virtual members should go into SymbolFileCommon; most SymbolFile
41+
/// implementations should inherit from SymbolFileCommon to override
42+
/// the behaviors except SymbolFileOnDemand which inherits
43+
/// public interfaces from SymbolFile and forward to underlying concrete
44+
/// SymbolFile implementation.
3945
class SymbolFile : public PluginInterface {
4046
/// LLVM RTTI support.
4147
static char ID;
@@ -67,8 +73,7 @@ class SymbolFile : public PluginInterface {
6773
static SymbolFile *FindPlugin(lldb::ObjectFileSP objfile_sp);
6874

6975
// Constructors and Destructors
70-
SymbolFile(lldb::ObjectFileSP objfile_sp)
71-
: m_objfile_sp(std::move(objfile_sp)) {}
76+
SymbolFile() = default;
7277

7378
~SymbolFile() override = default;
7479

@@ -99,15 +104,7 @@ class SymbolFile : public PluginInterface {
99104
/// A uint32_t mask containing bits from the SymbolFile::Abilities
100105
/// enumeration. Any bits that are set represent an ability that
101106
/// this symbol plug-in can parse from the object file.
102-
uint32_t GetAbilities() {
103-
if (!m_calculated_abilities) {
104-
m_abilities = CalculateAbilities();
105-
m_calculated_abilities = true;
106-
}
107-
108-
return m_abilities;
109-
}
110-
107+
virtual uint32_t GetAbilities() = 0;
111108
virtual uint32_t CalculateAbilities() = 0;
112109

113110
/// Symbols file subclasses should override this to return the Module that
@@ -125,10 +122,10 @@ class SymbolFile : public PluginInterface {
125122

126123
// Compile Unit function calls
127124
// Approach 1 - iterator
128-
uint32_t GetNumCompileUnits();
129-
lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx);
125+
virtual uint32_t GetNumCompileUnits() = 0;
126+
virtual lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) = 0;
130127

131-
Symtab *GetSymtab();
128+
virtual Symtab *GetSymtab() = 0;
132129

133130
virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) = 0;
134131
/// Return the Xcode SDK comp_unit was compiled against.
@@ -256,16 +253,16 @@ class SymbolFile : public PluginInterface {
256253
virtual void PreloadSymbols();
257254

258255
virtual llvm::Expected<lldb_private::TypeSystem &>
259-
GetTypeSystemForLanguage(lldb::LanguageType language);
256+
GetTypeSystemForLanguage(lldb::LanguageType language) = 0;
260257

261258
virtual CompilerDeclContext
262259
FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx) {
263260
return CompilerDeclContext();
264261
}
265262

266-
ObjectFile *GetObjectFile() { return m_objfile_sp.get(); }
267-
const ObjectFile *GetObjectFile() const { return m_objfile_sp.get(); }
268-
ObjectFile *GetMainObjectFile();
263+
virtual ObjectFile *GetObjectFile() = 0;
264+
virtual const ObjectFile *GetObjectFile() const = 0;
265+
virtual ObjectFile *GetMainObjectFile() = 0;
269266

270267
virtual std::vector<std::unique_ptr<CallEdge>>
271268
ParseCallEdgesInFunction(UserID func_id) {
@@ -276,7 +273,7 @@ class SymbolFile : public PluginInterface {
276273

277274
/// Notify the SymbolFile that the file addresses in the Sections
278275
/// for this module have been changed.
279-
virtual void SectionFileAddressesChanged();
276+
virtual void SectionFileAddressesChanged() = 0;
280277

281278
struct RegisterInfoResolver {
282279
virtual ~RegisterInfoResolver(); // anchor
@@ -297,7 +294,7 @@ class SymbolFile : public PluginInterface {
297294
"Operation not supported.");
298295
}
299296

300-
virtual void Dump(Stream &s);
297+
virtual void Dump(Stream &s) = 0;
301298

302299
/// Metrics gathering functions
303300

@@ -311,7 +308,7 @@ class SymbolFile : public PluginInterface {
311308
/// entire file should be returned. The default implementation of this
312309
/// function will iterate over all sections in a module and add up their
313310
/// debug info only section byte sizes.
314-
virtual uint64_t GetDebugInfoSize();
311+
virtual uint64_t GetDebugInfoSize() = 0;
315312

316313
/// Return the time taken to parse the debug information.
317314
///
@@ -344,26 +341,90 @@ class SymbolFile : public PluginInterface {
344341
/// index is saved to the cache, debug sessions can be slower. These accessors
345342
/// can be accessed by the statistics and emitted to help track these costs.
346343
/// \{
347-
bool GetDebugInfoIndexWasLoadedFromCache() const {
344+
virtual bool GetDebugInfoIndexWasLoadedFromCache() const = 0;
345+
virtual void SetDebugInfoIndexWasLoadedFromCache() = 0;
346+
virtual bool GetDebugInfoIndexWasSavedToCache() const = 0;
347+
virtual void SetDebugInfoIndexWasSavedToCache() = 0;
348+
/// \}
349+
350+
protected:
351+
void AssertModuleLock();
352+
353+
private:
354+
SymbolFile(const SymbolFile &) = delete;
355+
const SymbolFile &operator=(const SymbolFile &) = delete;
356+
};
357+
358+
/// Containing protected virtual methods for child classes to override.
359+
/// Most actual SymbolFile implementations should inherit from this class.
360+
class SymbolFileCommon : public SymbolFile {
361+
/// LLVM RTTI support.
362+
static char ID;
363+
364+
public:
365+
/// LLVM RTTI support.
366+
/// \{
367+
bool isA(const void *ClassID) const override {
368+
return ClassID == &ID || SymbolFile::isA(ClassID);
369+
}
370+
static bool classof(const SymbolFileCommon *obj) { return obj->isA(&ID); }
371+
/// \}
372+
373+
// Constructors and Destructors
374+
SymbolFileCommon(lldb::ObjectFileSP objfile_sp)
375+
: m_objfile_sp(std::move(objfile_sp)) {}
376+
377+
~SymbolFileCommon() override = default;
378+
379+
uint32_t GetAbilities() override {
380+
if (!m_calculated_abilities) {
381+
m_abilities = CalculateAbilities();
382+
m_calculated_abilities = true;
383+
}
384+
return m_abilities;
385+
}
386+
387+
Symtab *GetSymtab() override;
388+
389+
ObjectFile *GetObjectFile() override { return m_objfile_sp.get(); }
390+
const ObjectFile *GetObjectFile() const override {
391+
return m_objfile_sp.get();
392+
}
393+
ObjectFile *GetMainObjectFile() override;
394+
395+
/// Notify the SymbolFile that the file addresses in the Sections
396+
/// for this module have been changed.
397+
void SectionFileAddressesChanged() override;
398+
399+
// Compile Unit function calls
400+
// Approach 1 - iterator
401+
uint32_t GetNumCompileUnits() override;
402+
lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) override;
403+
404+
llvm::Expected<lldb_private::TypeSystem &>
405+
GetTypeSystemForLanguage(lldb::LanguageType language) override;
406+
407+
void Dump(Stream &s) override;
408+
409+
uint64_t GetDebugInfoSize() override;
410+
411+
bool GetDebugInfoIndexWasLoadedFromCache() const override {
348412
return m_index_was_loaded_from_cache;
349413
}
350-
void SetDebugInfoIndexWasLoadedFromCache() {
414+
void SetDebugInfoIndexWasLoadedFromCache() override {
351415
m_index_was_loaded_from_cache = true;
352416
}
353-
bool GetDebugInfoIndexWasSavedToCache() const {
417+
bool GetDebugInfoIndexWasSavedToCache() const override {
354418
return m_index_was_saved_to_cache;
355419
}
356-
void SetDebugInfoIndexWasSavedToCache() {
420+
void SetDebugInfoIndexWasSavedToCache() override {
357421
m_index_was_saved_to_cache = true;
358422
}
359-
/// \}
360423

361424
protected:
362-
void AssertModuleLock();
363425
virtual uint32_t CalculateNumCompileUnits() = 0;
364426
virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t idx) = 0;
365427
virtual TypeList &GetTypeList() { return m_type_list; }
366-
367428
void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp);
368429

369430
lldb::ObjectFileSP m_objfile_sp; // Keep a reference to the object file in
@@ -379,8 +440,8 @@ class SymbolFile : public PluginInterface {
379440
bool m_index_was_saved_to_cache = false;
380441

381442
private:
382-
SymbolFile(const SymbolFile &) = delete;
383-
const SymbolFile &operator=(const SymbolFile &) = delete;
443+
SymbolFileCommon(const SymbolFileCommon &) = delete;
444+
const SymbolFileCommon &operator=(const SymbolFileCommon &) = delete;
384445
};
385446

386447
} // namespace lldb_private

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ namespace lldb_private {
2020

2121
namespace breakpad {
2222

23-
class SymbolFileBreakpad : public SymbolFile {
23+
class SymbolFileBreakpad : public SymbolFileCommon {
2424
/// LLVM RTTI support.
2525
static char ID;
2626

2727
public:
2828
/// LLVM RTTI support.
2929
/// \{
3030
bool isA(const void *ClassID) const override {
31-
return ClassID == &ID || SymbolFile::isA(ClassID);
31+
return ClassID == &ID || SymbolFileCommon::isA(ClassID);
3232
}
3333
static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
3434
/// \}
@@ -49,7 +49,7 @@ class SymbolFileBreakpad : public SymbolFile {
4949

5050
// Constructors and Destructors
5151
SymbolFileBreakpad(lldb::ObjectFileSP objfile_sp)
52-
: SymbolFile(std::move(objfile_sp)) {}
52+
: SymbolFileCommon(std::move(objfile_sp)) {}
5353

5454
~SymbolFileBreakpad() override = default;
5555

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ TypeList &SymbolFileDWARF::GetTypeList() {
274274
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
275275
if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile())
276276
return debug_map_symfile->GetTypeList();
277-
return SymbolFile::GetTypeList();
277+
return SymbolFileCommon::GetTypeList();
278278
}
279279
void SymbolFileDWARF::GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset,
280280
dw_offset_t max_die_offset, uint32_t type_mask,
@@ -407,7 +407,7 @@ SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDIE &child_die) {
407407

408408
SymbolFileDWARF::SymbolFileDWARF(ObjectFileSP objfile_sp,
409409
SectionList *dwo_section_list)
410-
: SymbolFile(std::move(objfile_sp)),
410+
: SymbolFileCommon(std::move(objfile_sp)),
411411
UserID(0x7fffffff00000000), // Used by SymbolFileDWARFDebugMap to
412412
// when this class parses .o files to
413413
// contain the .o file index/ID
@@ -3968,7 +3968,7 @@ SymbolFileDWARF::ParseCallEdgesInFunction(UserID func_id) {
39683968
}
39693969

39703970
void SymbolFileDWARF::Dump(lldb_private::Stream &s) {
3971-
SymbolFile::Dump(s);
3971+
SymbolFileCommon::Dump(s);
39723972
m_index->Dump(s);
39733973
}
39743974

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class SymbolFileDWARFDwp;
5656

5757
#define DIE_IS_BEING_PARSED ((lldb_private::Type *)1)
5858

59-
class SymbolFileDWARF : public lldb_private::SymbolFile,
59+
class SymbolFileDWARF : public lldb_private::SymbolFileCommon,
6060
public lldb_private::UserID {
6161
/// LLVM RTTI support.
6262
static char ID;
@@ -65,7 +65,7 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
6565
/// LLVM RTTI support.
6666
/// \{
6767
bool isA(const void *ClassID) const override {
68-
return ClassID == &ID || SymbolFile::isA(ClassID);
68+
return ClassID == &ID || SymbolFileCommon::isA(ClassID);
6969
}
7070
static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
7171
/// \}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ SymbolFile *SymbolFileDWARFDebugMap::CreateInstance(ObjectFileSP objfile_sp) {
237237
}
238238

239239
SymbolFileDWARFDebugMap::SymbolFileDWARFDebugMap(ObjectFileSP objfile_sp)
240-
: SymbolFile(std::move(objfile_sp)), m_flags(), m_compile_unit_infos(),
240+
: SymbolFileCommon(std::move(objfile_sp)), m_flags(), m_compile_unit_infos(),
241241
m_func_indexes(), m_glob_indexes(),
242242
m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate) {}
243243

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ class SymbolFileDWARF;
2222
class DWARFDebugAranges;
2323
class DWARFDeclContext;
2424

25-
class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
25+
class SymbolFileDWARFDebugMap : public lldb_private::SymbolFileCommon {
2626
/// LLVM RTTI support.
2727
static char ID;
2828

2929
public:
3030
/// LLVM RTTI support.
3131
/// \{
3232
bool isA(const void *ClassID) const override {
33-
return ClassID == &ID || SymbolFile::isA(ClassID);
33+
return ClassID == &ID || SymbolFileCommon::isA(ClassID);
3434
}
3535
static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
3636
/// \}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ SymbolFile *SymbolFileNativePDB::CreateInstance(ObjectFileSP objfile_sp) {
254254
}
255255

256256
SymbolFileNativePDB::SymbolFileNativePDB(ObjectFileSP objfile_sp)
257-
: SymbolFile(std::move(objfile_sp)) {}
257+
: SymbolFileCommon(std::move(objfile_sp)) {}
258258

259259
SymbolFileNativePDB::~SymbolFileNativePDB() = default;
260260

@@ -1936,4 +1936,3 @@ uint64_t SymbolFileNativePDB::GetDebugInfoSize() {
19361936
// PDB files are a separate file that contains all debug info.
19371937
return m_index->pdb().getFileSize();
19381938
}
1939-

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace lldb_private {
3939
namespace npdb {
4040
class PdbAstBuilder;
4141

42-
class SymbolFileNativePDB : public SymbolFile {
42+
class SymbolFileNativePDB : public SymbolFileCommon {
4343
friend class UdtRecordCompleter;
4444

4545
/// LLVM RTTI support.
@@ -49,7 +49,7 @@ class SymbolFileNativePDB : public SymbolFile {
4949
/// LLVM RTTI support.
5050
/// \{
5151
bool isA(const void *ClassID) const override {
52-
return ClassID == &ID || SymbolFile::isA(ClassID);
52+
return ClassID == &ID || SymbolFileCommon::isA(ClassID);
5353
}
5454
static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
5555
/// \}

lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ SymbolFilePDB::CreateInstance(ObjectFileSP objfile_sp) {
135135
}
136136

137137
SymbolFilePDB::SymbolFilePDB(lldb::ObjectFileSP objfile_sp)
138-
: SymbolFile(std::move(objfile_sp)), m_session_up(), m_global_scope_up() {}
138+
: SymbolFileCommon(std::move(objfile_sp)), m_session_up(), m_global_scope_up() {}
139139

140140
SymbolFilePDB::~SymbolFilePDB() = default;
141141

lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121

2222
class PDBASTParser;
2323

24-
class SymbolFilePDB : public lldb_private::SymbolFile {
24+
class SymbolFilePDB : public lldb_private::SymbolFileCommon {
2525
/// LLVM RTTI support.
2626
static char ID;
2727

2828
public:
2929
/// LLVM RTTI support.
3030
/// \{
3131
bool isA(const void *ClassID) const override {
32-
return ClassID == &ID || SymbolFile::isA(ClassID);
32+
return ClassID == &ID || SymbolFileCommon::isA(ClassID);
3333
}
3434
static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
3535
/// \}

0 commit comments

Comments
 (0)