Skip to content

Commit 0304360

Browse files
committed
Add a testcase for Clang modules being updated within one LLDB session.
This actually works as expected, but wasn't explicitly tested before.
1 parent d295087 commit 0304360

File tree

7 files changed

+91
-3
lines changed

7 files changed

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

lldb/source/Core/ModuleList.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,10 @@ Status ModuleList::GetSharedModule(const ModuleSpec &module_spec,
752752

753753
Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_MODULES));
754754
if (log != nullptr)
755-
LLDB_LOGF(log,
756-
"module changed: %p, removing from global module list",
757-
static_cast<void *>(module_sp.get()));
755+
LLDB_LOGF(
756+
log, "%p '%s' module changed: removing from global module list",
757+
static_cast<void *>(module_sp.get()),
758+
module_sp->GetFileSpec().GetFilename().GetCString());
758759

759760
shared_module_list.Remove(module_sp);
760761
module_sp.reset();

0 commit comments

Comments
 (0)