1da816ca0SGreg Clayton"""Test the LLDB module cache funcionality.""" 2da816ca0SGreg Clayton 3da816ca0SGreg Claytonimport glob 4da816ca0SGreg Claytonimport lldb 5da816ca0SGreg Claytonfrom lldbsuite.test.decorators import * 6da816ca0SGreg Claytonfrom lldbsuite.test.lldbtest import * 7da816ca0SGreg Claytonfrom lldbsuite.test import lldbutil 8da816ca0SGreg Claytonimport os 9da816ca0SGreg Claytonimport time 10da816ca0SGreg Clayton 11da816ca0SGreg Clayton 12da816ca0SGreg Claytonclass ModuleCacheTestcaseBSD(TestBase): 13da816ca0SGreg Clayton 14da816ca0SGreg Clayton def setUp(self): 15da816ca0SGreg Clayton # Call super's setUp(). 16da816ca0SGreg Clayton TestBase.setUp(self) 17da816ca0SGreg Clayton # Find the line number in a(int) to break at. 18da816ca0SGreg Clayton self.line_a = line_number( 19da816ca0SGreg Clayton 'a.c', '// Set file and line breakpoint inside a().') 20da816ca0SGreg Clayton self.line_b = line_number( 21da816ca0SGreg Clayton 'b.c', '// Set file and line breakpoint inside b().') 22da816ca0SGreg Clayton self.line_c = line_number( 23da816ca0SGreg Clayton 'c.c', '// Set file and line breakpoint inside c().') 24da816ca0SGreg Clayton self.cache_dir = os.path.join(self.getBuildDir(), 'lldb-module-cache') 25da816ca0SGreg Clayton # Set the lldb module cache directory to a directory inside the build 26da816ca0SGreg Clayton # artifacts directory so no other tests are interfered with. 27da816ca0SGreg Clayton self.runCmd('settings set symbols.lldb-index-cache-path "%s"' % (self.cache_dir)) 28da816ca0SGreg Clayton self.runCmd('settings set symbols.enable-lldb-index-cache true') 29da816ca0SGreg Clayton self.build() 30da816ca0SGreg Clayton 31da816ca0SGreg Clayton 32da816ca0SGreg Clayton def get_module_cache_files(self, basename): 33da816ca0SGreg Clayton module_cache_glob = os.path.join(self.cache_dir, "llvmcache-*%s*symtab*" % (basename)) 34da816ca0SGreg Clayton return glob.glob(module_cache_glob) 35da816ca0SGreg Clayton 36da816ca0SGreg Clayton 37da816ca0SGreg Clayton # Requires no dSYM, so we let the Makefile make the right stuff for us 38da816ca0SGreg Clayton @no_debug_info_test 39da816ca0SGreg Clayton @skipUnlessDarwin 40da816ca0SGreg Clayton def test(self): 41da816ca0SGreg Clayton """ 42*b6087ba7SGreg Clayton This test has been modified to make sure .o files that don't have 43*b6087ba7SGreg Clayton UUIDs are not cached after discovering build systems that play with 44*b6087ba7SGreg Clayton modification times of .o files that the modification times are not 45*b6087ba7SGreg Clayton unique enough to ensure the .o file within the .a file are the right 46*b6087ba7SGreg Clayton files as this was causing older cache files to be accepted for new 47*b6087ba7SGreg Clayton updated .o files. 48*b6087ba7SGreg Clayton 49*b6087ba7SGreg Clayton ELF .o files do calculate a UUID from the contents of the file, 50*b6087ba7SGreg Clayton which is expensive, but no one loads .o files into a debug sessions 51*b6087ba7SGreg Clayton when using ELF files. Mach-o .o files do not have UUID values and do 52*b6087ba7SGreg Clayton no calculate one as they _are_ used during debug sessions when no 53*b6087ba7SGreg Clayton dSYM file is generated. If we can find a way to uniquely and cheaply 54*b6087ba7SGreg Clayton create UUID values for mach-o .o files in the future, this test will 55*b6087ba7SGreg Clayton be updated to test this functionality. This test will now make sure 56*b6087ba7SGreg Clayton there are no cache entries for any .o files in BSD archives. 57*b6087ba7SGreg Clayton 58*b6087ba7SGreg Clayton The old test case description is below in case we enable caching for 59*b6087ba7SGreg Clayton .o files again: 60*b6087ba7SGreg Clayton 61da816ca0SGreg Clayton Test module cache functionality for bsd archive object files. 62da816ca0SGreg Clayton 63da816ca0SGreg Clayton This will test that if we enable the module cache, we have a 64da816ca0SGreg Clayton corresponding cache entry for the .o files in libfoo.a. 65da816ca0SGreg Clayton 66da816ca0SGreg Clayton The static library has two entries for "a.o": 67da816ca0SGreg Clayton - one from a.c 68da816ca0SGreg Clayton - one from c.c which had c.o renamed to a.o and then put into the 69da816ca0SGreg Clayton libfoo.a as an extra .o file with different contents from the 70da816ca0SGreg Clayton original a.o 71da816ca0SGreg Clayton 72da816ca0SGreg Clayton We do this to test that we can correctly cache duplicate .o files 73da816ca0SGreg Clayton that appear in .a files. 74da816ca0SGreg Clayton 75da816ca0SGreg Clayton This test only works on darwin because of the way DWARF is stored 76da816ca0SGreg Clayton where the debug map will refer to .o files inside of .a files. 77da816ca0SGreg Clayton """ 78da816ca0SGreg Clayton exe = self.getBuildArtifact("a.out") 79da816ca0SGreg Clayton 80da816ca0SGreg Clayton # Create a module with no depedencies. 81da816ca0SGreg Clayton target = self.createTestTarget(load_dependent_modules=False) 82da816ca0SGreg Clayton 83da816ca0SGreg Clayton self.runCmd('breakpoint set -f a.c -l %d' % (self.line_a)) 84da816ca0SGreg Clayton self.runCmd('breakpoint set -f b.c -l %d' % (self.line_b)) 85da816ca0SGreg Clayton self.runCmd('breakpoint set -f c.c -l %d' % (self.line_c)) 86da816ca0SGreg Clayton 87da816ca0SGreg Clayton # Get the executable module and get the number of symbols to make 88da816ca0SGreg Clayton # sure the symbol table gets parsed and cached. The module cache is 89da816ca0SGreg Clayton # enabled in the setUp() function. 90da816ca0SGreg Clayton main_module = target.GetModuleAtIndex(0) 91da816ca0SGreg Clayton self.assertTrue(main_module.IsValid()) 92da816ca0SGreg Clayton # Make sure the symbol table gets loaded and cached 93da816ca0SGreg Clayton main_module.GetNumSymbols() 94da816ca0SGreg Clayton a_o_cache_files = self.get_module_cache_files("libfoo.a(a.o)") 95da816ca0SGreg Clayton b_o_cache_files = self.get_module_cache_files("libfoo.a(b.o)") 96*b6087ba7SGreg Clayton 97*b6087ba7SGreg Clayton 98da816ca0SGreg Clayton # We expect the directory for a.o to have two cache directories: 99da816ca0SGreg Clayton # - 1 for the a.o with a earlier mod time 100da816ca0SGreg Clayton # - 1 for the a.o that was renamed from c.o that should be 2 seconds older 101*b6087ba7SGreg Clayton # self.assertEqual(len(a_o_cache_files), 2, 102*b6087ba7SGreg Clayton # "make sure there are two files in the module cache directory (%s) for libfoo.a(a.o)" % (self.cache_dir)) 103*b6087ba7SGreg Clayton # self.assertEqual(len(b_o_cache_files), 1, 104*b6087ba7SGreg Clayton # "make sure there are two files in the module cache directory (%s) for libfoo.a(b.o)" % (self.cache_dir)) 105*b6087ba7SGreg Clayton 106*b6087ba7SGreg Clayton # We are no longer caching .o files in the lldb index cache. If we ever 107*b6087ba7SGreg Clayton # re-enable this functionality, we can uncomment out the above lines of 108*b6087ba7SGreg Clayton # code. 109*b6087ba7SGreg Clayton self.assertEqual(len(a_o_cache_files), 0, 110*b6087ba7SGreg Clayton "make sure there are no files in the module cache directory (%s) for libfoo.a(a.o)" % (self.cache_dir)) 111*b6087ba7SGreg Clayton self.assertEqual(len(b_o_cache_files), 0, 112*b6087ba7SGreg Clayton "make sure there are no files in the module cache directory (%s) for libfoo.a(b.o)" % (self.cache_dir)) 113