@@ -721,7 +721,7 @@ TEST_F(SymtabTest, TestDecodeCStringMaps) {
721721 ASSERT_NE (symbol, nullptr );
722722}
723723
724- TEST_F (SymtabTest, TestSymbolFileAndSymbolTableCreatedOnDemand ) {
724+ TEST_F (SymtabTest, TestSymbolFileCreatedOnDemand ) {
725725 auto ExpectedFile = TestFile::fromYaml (R"(
726726--- !ELF
727727FileHeader:
@@ -753,16 +753,6 @@ TEST_F(SymtabTest, TestSymbolFileAndSymbolTableCreatedOnDemand) {
753753 Symtab *module_symtab = module_sp->GetSymtab (/* can_create=*/ false );
754754 ASSERT_EQ (module_symtab, nullptr );
755755
756- // Even if the symbol file is created, the symbol table should not be created by default.
757-
758- // TODO:
759- // I need to create a symbol file here, but without causing it to parse the symbol table.
760- // See next line as a failed attempt.
761-
762- // module_sp->GetSymbolFile(/*can_create=*/true); // Cannot do this because it will parse the symbol table.
763- module_symtab = module_sp->GetSymtab (/* can_create=*/ false );
764- ASSERT_EQ (module_symtab, nullptr );
765-
766756 // But it should be created on demand.
767757 module_symtab = module_sp->GetSymtab (/* can_create=*/ true );
768758 ASSERT_NE (module_symtab, nullptr );
@@ -771,3 +761,74 @@ TEST_F(SymtabTest, TestSymbolFileAndSymbolTableCreatedOnDemand) {
771761 Symtab *cached_module_symtab = module_sp->GetSymtab (/* can_create=*/ false );
772762 ASSERT_EQ (module_symtab, cached_module_symtab);
773763}
764+
765+ TEST_F (SymtabTest, TestSymbolTableCreatedOnDemand) {
766+ const char *yamldata = R"(
767+ --- !ELF
768+ FileHeader:
769+ Class: ELFCLASS64
770+ Data: ELFDATA2LSB
771+ Type: ET_EXEC
772+ Machine: EM_386
773+ DWARF:
774+ debug_abbrev:
775+ - Table:
776+ - Code: 0x00000001
777+ Tag: DW_TAG_compile_unit
778+ Children: DW_CHILDREN_no
779+ Attributes:
780+ - Attribute: DW_AT_addr_base
781+ Form: DW_FORM_sec_offset
782+ debug_info:
783+ - Version: 5
784+ AddrSize: 4
785+ UnitType: DW_UT_compile
786+ Entries:
787+ - AbbrCode: 0x00000001
788+ Values:
789+ - Value: 0x8 # Offset of the first Address past the header
790+ - AbbrCode: 0x0
791+ debug_addr:
792+ - Version: 5
793+ AddressSize: 4
794+ Entries:
795+ - Address: 0x1234
796+ - Address: 0x5678
797+ debug_line:
798+ - Length: 42
799+ Version: 2
800+ PrologueLength: 36
801+ MinInstLength: 1
802+ DefaultIsStmt: 1
803+ LineBase: 251
804+ LineRange: 14
805+ OpcodeBase: 13
806+ StandardOpcodeLengths: [ 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 ]
807+ IncludeDirs:
808+ - '/tmp'
809+ Files:
810+ - Name: main.cpp
811+ DirIdx: 1
812+ ModTime: 0
813+ Length: 0
814+ )" ;
815+ llvm::Expected<TestFile> file = TestFile::fromYaml (yamldata);
816+ EXPECT_THAT_EXPECTED (file, llvm::Succeeded ());
817+ auto module_sp = std::make_shared<Module>(file->moduleSpec ());
818+
819+ SymbolFile* symbol_file = module_sp->GetSymbolFile ();
820+ // At this point, the symbol table is not created. This is because the above yaml data contains the necessary sections in order for SymbolFileDWARF::CalculateAbilities() to identify all abilities,
821+ // saving the code from calling SymbolFileDWARFDebugMap::CalculateAbilities(), which eventually loads the symbol table, which we don't want.
822+
823+ // The symbol table should not be created if asked not to.
824+ Symtab* symtab = symbol_file->GetSymtab (/* can_create=*/ false );
825+ ASSERT_EQ (symtab, nullptr );
826+
827+ // But it should be created on demand.
828+ symtab = symbol_file->GetSymtab (/* can_create=*/ true );
829+ ASSERT_NE (symtab, nullptr );
830+
831+ // And we should be able to get it again once it has been created.
832+ symtab = symbol_file->GetSymtab (/* can_create=*/ false );
833+ ASSERT_NE (symtab, nullptr );
834+ }
0 commit comments