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 @skipIfDarwin # rdar://76540904 17 def test_expr(self): 18 with open(self.getBuildArtifact("module.modulemap"), "w") as f: 19 f.write(""" 20 module Foo { header "f.h" } 21 """) 22 with open(self.getBuildArtifact("f.h"), "w") as f: 23 f.write(""" 24 struct Q { int i; }; 25 void f() {} 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 struct S { int i; }; 45 struct S getS() { struct S r = {1}; return r; } 46 void f() {} 47 """) 48 49 # Rebuild. 50 d = {'OBJC_SOURCES': 'second.m'} 51 self.build(dictionary=d) 52 53 # Reattach. 54 process.Kill() 55 target, process, _, _ = lldbutil.run_to_breakpoint_do_run(self, target, bkpt) 56 self.assertIn("int i", str(target.FindTypes('S').GetTypeAtIndex(0))) 57 self.expect("image list -g", patterns=[r'second\.o', r'Foo.*\.pcm']) 58 59 # Check log file. 60 found = False 61 with open(logfile, 'r') as f: 62 for line in f: 63 if "module changed" in line and "Foo" in line: 64 found = True 65 self.assertTrue(found) 66