1 2import unittest2 3import os 4import shutil 5 6import lldb 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9from lldbsuite.test import lldbutil 10 11 12class TestClangModuleUpdate(TestBase): 13 mydir = TestBase.compute_mydir(__file__) 14 15 @skipIf(debug_info=no_match(["gmodules"])) 16 @skipIfReproducer # VFS is a snapshot. 17 @skipIfDarwin # rdar://76540904 18 def test_expr(self): 19 with open(self.getBuildArtifact("module.modulemap"), "w") as f: 20 f.write(""" 21 module Foo { header "f.h" } 22 """) 23 with open(self.getBuildArtifact("f.h"), "w") as f: 24 f.write(""" 25 struct Q { int i; }; 26 void f() {} 27 """) 28 29 mod_cache = self.getBuildArtifact("private-module-cache") 30 if os.path.isdir(mod_cache): 31 shutil.rmtree(mod_cache) 32 d = {'OBJC_SOURCES': 'first.m'} 33 self.build(dictionary=d) 34 self.assertTrue(os.path.isdir(mod_cache), "module cache exists") 35 36 logfile = self.getBuildArtifact("modules.log") 37 self.runCmd("log enable -f %s lldb module" % logfile) 38 target, process, _, bkpt = lldbutil.run_to_name_breakpoint(self, "main") 39 self.assertIn("int i", str(target.FindTypes('Q').GetTypeAtIndex(0))) 40 self.expect("image list -g", patterns=[r'first\.o', r'Foo.*\.pcm']) 41 42 # Update the module. 43 with open(self.getBuildArtifact("f.h"), "w") as f: 44 f.write(""" 45 struct S { int i; }; 46 struct S getS() { struct S r = {1}; return r; } 47 void f() {} 48 """) 49 50 # Rebuild. 51 d = {'OBJC_SOURCES': 'second.m'} 52 self.build(dictionary=d) 53 54 # Reattach. 55 process.Kill() 56 target, process, _, _ = lldbutil.run_to_breakpoint_do_run(self, target, bkpt) 57 self.assertIn("int i", str(target.FindTypes('S').GetTypeAtIndex(0))) 58 self.expect("image list -g", patterns=[r'second\.o', r'Foo.*\.pcm']) 59 60 # Check log file. 61 found = False 62 with open(logfile, 'r') as f: 63 for line in f: 64 if "module changed" in line and "Foo" in line: 65 found = True 66 self.assertTrue(found) 67