Skip to content

Commit 98f84e5

Browse files
Merge pull request #10347 from adrian-prantl/resilience-test
[lldb] Add a resilience test for binary swiftmodules created from tex…
2 parents fb4eac3 + 799412b commit 98f84e5

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public struct S {
2+
public var a = 100
3+
private var b = 200
4+
public init() {}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public struct S {
2+
private var b = 100
3+
public var a = 200
4+
public init() {}
5+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
SWIFT_SOURCES := main.swift
2+
3+
all: ImplA a.out Postprocess
4+
5+
include Makefile.rules
6+
# Register a swiftmodule built of an out-of-date interface with the linker.
7+
LD_EXTRAS = -lImpl -L$(BUILDDIR) -Xlinker -add_ast_path -Xlinker Impl.swiftmodule
8+
SWIFTFLAGS_EXTRAS = -I$(BUILDDIR)
9+
10+
ImplB: ImplB.swift
11+
echo "Building an out-of-date swift interface"
12+
"$(MAKE)" MAKE_DSYM=YES CC=$(CC) SWIFTC=$(SWIFTC) \
13+
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
14+
SWIFTFLAGS_EXTRAS="-I$(BUILDDIR) -enable-library-evolution" \
15+
VPATH=$(SRCDIR) -I $(SRCDIR) \
16+
DYLIB_ONLY:=YES DYLIB_NAME=Impl \
17+
DYLIB_SWIFT_SOURCES:=ImplB.swift \
18+
-f $(MAKEFILE_RULES)
19+
mv Impl.swiftinterface ImplB.swiftinterface
20+
rm Impl.swiftmodule Impl.private.swiftinterface libImpl.dylib
21+
22+
ImplA: ImplB ImplA.swift
23+
"$(MAKE)" MAKE_DSYM=YES CC=$(CC) SWIFTC=$(SWIFTC) \
24+
ARCH=$(ARCH) DSYMUTIL=$(DSYMUTIL) \
25+
SWIFTFLAGS_EXTRAS="-I$(BUILDDIR) -enable-library-evolution" \
26+
VPATH=$(SRCDIR) -I $(SRCDIR) \
27+
DYLIB_ONLY:=YES DYLIB_NAME=Impl \
28+
DYLIB_SWIFT_SOURCES:=ImplA.swift \
29+
-f $(MAKEFILE_RULES)
30+
echo "Moving out-of-date-swiftinterface into place"
31+
rm -rf libImpl.dylib.dSYM Impl.swiftmodule Impl.private.swiftinterface
32+
rm ImplA.swift.o ImplB.swift.o
33+
mv ImplB.swiftinterface Impl.swiftinterface
34+
35+
Postprocess:
36+
echo "Compiling Impl.swiftinterfact to Impl.swiftmodule"
37+
echo "import Impl" >trigger.swift
38+
$(SWIFT_FE) -module-cache-path cache -c trigger.swift -o trigger -I.
39+
mv cache/Impl*.swiftmodule Impl.swiftmodule
40+
rm Impl.swiftinterface
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
import lldbsuite.test.lldbutil as lldbutil
5+
6+
7+
class TestSwiftResilienceSwiftInterface(TestBase):
8+
9+
@skipUnlessDarwin
10+
@swiftTest
11+
def test(self):
12+
"""Test the odd scenario where a user registers a binary
13+
.swiftmodule file that was built from a textual
14+
.swiftinterface files with -add_ast_path. We need to make sure
15+
LLDB doesn't bypass reilience for it.
16+
"""
17+
self.build()
18+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
19+
self, "break here", lldb.SBFileSpec('main.swift'))
20+
21+
self.expect("expression s", substrs=["a", "100", "b", "200"])
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Impl
2+
3+
func f() {
4+
var s = Impl.S()
5+
print("break here")
6+
}
7+
8+
f()

0 commit comments

Comments
 (0)