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