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