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