Skip to content

Commit dd1c41d

Browse files
committed
Move (most of) No.Swiftmodule into a proper API test.
Testing debugging from just reflection metadata is very important on all platforms. Shell tests only run on the host. By migrating this test to an API test we can make sure this is also tested when debugging on iOS devices.
1 parent cd2992b commit dd1c41d

File tree

7 files changed

+185
-34
lines changed

7 files changed

+185
-34
lines changed

lldb/packages/Python/lldbsuite/test/make/Makefile.rules

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -599,21 +599,26 @@ VPATHSOURCES=$(patsubst %,$(VPATH)/%,$(SWIFT_SOURCES)) $(patsubst %,$(VPATH)/%,$
599599
-o $(BUILDDIR)/$@
600600

601601
ifeq "$(OS)" "Darwin"
602-
$(EXE): $(MODULENAME).swiftmodule $(OBJECTS)
602+
ifeq "$(HIDE_SWIFTMODULE)" ""
603+
SWIFTMODULE = $(MODULENAME).swiftmodule
604+
LD_SWIFTFLAGS = -Xlinker -add_ast_path -Xlinker $(SWIFTMODULE)
605+
else
606+
SWIFTMODULE =
607+
LD_SWIFTFLAGS =
608+
endif
609+
$(EXE): $(SWIFTMODULE) $(OBJECTS)
603610
@echo "### Linking" $(EXE)
604-
$(SWIFTC) $(LD_EXTRAS) $(OBJECTS) \
605-
-Xlinker -add_ast_path -Xlinker $(MODULENAME).swiftmodule \
606-
$(patsubst -g,,$(SWIFTFLAGS)) -o "$(EXE)"
611+
$(SWIFTC) $(LD_EXTRAS) $(LD_SWIFTFLAGS) $(OBJECTS) $(patsubst -g,,$(SWIFTFLAGS)) -o "$(EXE)"
607612
ifneq "$(CODESIGN)" ""
608613
$(CODESIGN) -s - "$(EXE)"
609614
endif
610615
else # OS = Linux
611616
$(EXE): $(MODULENAME).swiftmodule.o $(OBJECTS)
612617
@echo "### Linking" $(EXE)
613-
ifneq "$(EXCLUDE_WRAPPED_SWIFTMODULE)" ""
614-
$(SWIFTC) $(LD_EXTRAS) $(patsubst %.swiftmodule.o,,$^) $(patsubst -g,,$(SWIFTFLAGS)) -o "$(EXE)"
618+
ifneq "$(HIDE_SWIFTMODULE)" ""
619+
$(SWIFTC) $(LD_EXTRAS) $(LD_SWIFTFLAGS) $(patsubst %.swiftmodule.o,,$^) $(patsubst -g,,$(SWIFTFLAGS)) -o "$(EXE)"
615620
else
616-
$(SWIFTC) $(LD_EXTRAS) $^ $(patsubst -g,,$(SWIFTFLAGS)) -o "$(EXE)"
621+
$(SWIFTC) $(LD_EXTRAS) $(LD_SWIFTFLAGS) $^ $(patsubst -g,,$(SWIFTFLAGS)) -o "$(EXE)"
617622
endif
618623

619624
$(MODULENAME).swiftmodule.o: $(MODULENAME).swiftmodule
@@ -694,7 +699,7 @@ ifeq "$(OS)" "Darwin"
694699
DYLIB_SWIFT_FLAGS= \
695700
-Xlinker -dylib \
696701
-Xlinker -install_name -Xlinker @executable_path/$(shell basename $@) \
697-
$(LD_EXTRAS)
702+
$(LD_EXTRAS) $(LD_SWIFTFLAGS)
698703
ifeq "$(DYLIB_HIDE_SWIFTMODULE)" ""
699704
DYLIB_SWIFT_FLAGS+= -Xlinker -add_ast_path -Xlinker $(DYLIB_NAME).swiftmodule
700705
endif

lldb/test/API/lang/swift/playgrounds-repl/Makefile.common

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ SWIFT_SOURCES := PlaygroundStub.swift
33

44
PlaygroundStub: libPlaygroundsRuntime.dylib
55

6+
ifneq ($(MAKECMDGOALS),libPlaygroundsRuntime.dylib)
7+
LD_EXTRAS := -L. -lPlaygroundsRuntime
8+
endif
9+
610
include Makefile.rules
711

812
ifneq ($(MAKECMDGOALS),libPlaygroundsRuntime.dylib)
9-
LD_EXTRAS := -L. -lPlaygroundsRuntime
1013
libPlaygroundsRuntime.dylib: PlaygroundsRuntime.swift
1114
$(MAKE) -C $(BUILDDIR) -f $(SRCDIR)/Makefile \
1215
SWIFT_SOURCES= DYLIB_SWIFT_SOURCES=PlaygroundsRuntime.swift \
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SWIFT_SOURCES := main.swift
2+
HIDE_SWIFTMODULE := YES
3+
4+
SWIFTFLAGS_EXTRAS := -I. -enable-library-evolution
5+
6+
LD_EXTRAS = -L. -Xlinker -rpath -Xlinker $(BUILDDIR) -ldynamic_lib
7+
8+
all: dylib $(EXE)
9+
.PHONY: dylib
10+
11+
include Makefile.rules
12+
dylib: lib.swift
13+
$(MAKE) -f $(MAKEFILE_RULES) \
14+
MAKE_DSYM=YES DYLIB_ONLY=YES DYLIB_NAME=dynamic_lib \
15+
DYLIB_SWIFT_SOURCES="lib.swift" \
16+
DYLIB_HIDE_SWIFTMODULE=YES \
17+
SWIFTFLAGS_EXTRAS="-I$(BUILDDIR) $(SWIFTFLAGS_EXTRAS)"
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import unittest2
6+
import re
7+
8+
class TestSwiftReflectionOnly(lldbtest.TestBase):
9+
NO_DEBUG_INFO_TESTCASE = True
10+
11+
mydir = lldbtest.TestBase.compute_mydir(__file__)
12+
13+
@swiftTest
14+
def test(self):
15+
"""Test debugging a program without swiftmodules is functional"""
16+
self.build()
17+
18+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
19+
self, 'Set breakpoint here', lldb.SBFileSpec('main.swift'),
20+
extra_images=['dynamic_lib'])
21+
log = self.getBuildArtifact('types.log')
22+
self.expect('log enable lldb types -f ' + log)
23+
24+
check_var = lldbutil.check_variable
25+
frame = thread.frames[0]
26+
var_self = frame.FindVariable("self")
27+
var_self_x = var_self.GetChildMemberWithName("x")
28+
check_var(self, var_self_x, value="42")
29+
30+
check_var(self, frame.FindVariable("number"), value="1")
31+
32+
array = frame.FindVariable("array")
33+
check_var(self, array, num_children=3)
34+
check_var(self, array.GetChildAtIndex(0), value="1")
35+
check_var(self, array.GetChildAtIndex(1), value="2")
36+
check_var(self, array.GetChildAtIndex(2), value="3")
37+
38+
check_var(self, frame.FindVariable("string"), summary='"hello"')
39+
40+
tup = frame.FindVariable("tuple")
41+
check_var(self, tup, num_children=2)
42+
check_var(self, tup.GetChildAtIndex(0), value="0")
43+
check_var(self, tup.GetChildAtIndex(1), value="1")
44+
45+
strct = frame.FindVariable("strct")
46+
check_var(self, strct, num_children=5)
47+
check_var(self, strct.GetChildMemberWithName("pub"), value="1")
48+
check_var(self, strct.GetChildMemberWithName("priv"), value="2")
49+
check_var(self, strct.GetChildMemberWithName("filepriv"), value="3")
50+
s_priv = strct.GetChildMemberWithName("s_priv")
51+
check_var(self, s_priv, num_children=1)
52+
check_var(self, s_priv.GetChildMemberWithName("i"), value="2")
53+
s_filepriv = strct.GetChildMemberWithName("s_filepriv")
54+
check_var(self, s_filepriv, num_children=1)
55+
check_var(self, s_filepriv.GetChildMemberWithName("i"), value="3")
56+
57+
# FIXME: scratch context assertion
58+
# check_var(self, frame.FindVariable("generic"), use_dynamic=True, value="42")
59+
60+
# gtup = frame.FindVariable("generic_tuple")
61+
# check_var(self, gtup, num_children=2)
62+
# check_var(self, gtup.GetChildAtIndex(0), use_dynamic=True, value="42")
63+
# check_var(self, gtup.GetChildAtIndex(1), use_dynamic=True, value="42")
64+
65+
check_var(self, frame.FindVariable("word"), value="0")
66+
check_var(self, frame.FindVariable("enum1"), value="second")
67+
enum2 = frame.FindVariable("enum2")
68+
check_var(self, enum2, value="with")
69+
check_var(self, enum2, num_children=1)
70+
# FIXME: Fails in swift::reflection::NoPayloadEnumTypeInfo::projectEnumValue: .second
71+
# check_var(self, enum2.GetChildAtIndex(0), value="42")
72+
73+
# Scan through the types log.
74+
logfile = open(log, "r")
75+
found_ref_exe = 0
76+
found_ref_lib = 0
77+
found_ast_exe = 0
78+
found_ast_lib = 0
79+
for line in logfile:
80+
if 'SwiftASTContextForExpressions::RegisterSectionModules("a.out")' in line:
81+
found_ast_exe += 1
82+
elif 'SwiftASTContextForExpressions::RegisterSectionModules("dyld")' in line:
83+
found_ast_lib += 1
84+
elif re.search(r'Adding reflection metadata in .*a\.out', line):
85+
found_ref_exe += 1
86+
elif re.search(r'Adding reflection metadata in .*dynamic_lib', line):
87+
found_ref_lib += 1
88+
self.assertEqual(found_ref_exe, 1)
89+
self.assertEqual(found_ref_lib, 1)
90+
self.assertEqual(found_ast_exe, 0)
91+
self.assertEqual(found_ast_lib, 0)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
public struct S {
2+
public init() {}
3+
public let pub = 1
4+
private let priv = 2
5+
fileprivate let filepriv = 3
6+
7+
private let s_priv = SPriv()
8+
fileprivate let s_filepriv = SFilePriv()
9+
}
10+
11+
private struct SPriv {
12+
let i = 2
13+
}
14+
15+
fileprivate struct SFilePriv {
16+
let i = 3
17+
}
18+
19+
open class Base {
20+
public let x : Int = 42
21+
public init() {}
22+
}
23+
24+
public enum NoPayload {
25+
case first
26+
case second
27+
}
28+
29+
public enum WithPayload {
30+
case empty
31+
case with(i: Int)
32+
}
33+
34+
public protocol P {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import dynamic_lib
2+
3+
struct MyP : P {
4+
let i = 1
5+
}
6+
7+
class C : Base {
8+
func f<T>(_ t: T, _ p : P) {
9+
let number = 1
10+
let array = [1, 2, 3]
11+
let string = "hello"
12+
let tuple = (0, 1)
13+
let strct = S()
14+
let generic = t
15+
let generic_tuple = (t, t)
16+
let word = 0._builtinWordValue
17+
let enum1 = NoPayload.second
18+
// FIXME: Fails in swift::reflection::NoPayloadEnumTypeInfo::projectEnumValue: .second
19+
let enum2 = WithPayload.with(i:42)
20+
print("Set breakpoint here")
21+
}
22+
}
23+
24+
let c = C()
25+
c.f(42, MyP())

lldb/test/Shell/Swift/Inputs/No.swiftmodule.swift

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,13 @@
11
import NoSwiftmoduleHelper
22

3-
// The struct is resolved using type metadata and the Swift runtime.
4-
struct S { let i = 0 }
5-
63
func useTypeFromOtherModule(x: S2) {
74
// break here
85
}
96

10-
enum NoPayload {
11-
case first
12-
case second
13-
}
14-
15-
enum WithPayload {
16-
case empty
17-
case with(i: Int)
18-
}
197

208
func f<T>(_ t: T) {
21-
let number = 1 // CHECK-DAG: (Int) number {{=}} 1
22-
let array = [1, 2, 3] // CHECK-DAG: ([Int]) array {{=}} 3 values
23-
let string = "hello" // CHECK-DAG: (String) string {{=}} "hello"
24-
let tuple = (0, 1) // CHECK-DAG: (Int, Int) tuple {{=}} (0 = 0, 1 = 1)
25-
let strct = S() // CHECK-DAG: strct {{=}} (i = 0)
269
let strct2 = S2() // CHECK-DAG: strct2 {{=}} {}{{$}}
27-
let generic = t // CHECK-DAG: (Int) generic {{=}} 23
28-
let generic_tuple = (t, t) // CHECK-DAG: generic_tuple {{=}} (0 = 23, 1 = 23)
29-
let word = 0._builtinWordValue // CHECK-DAG: word {{=}} 0
30-
let enum1 = NoPayload.second // CHECK-DAG: enum1 {{=}}
31-
// FIXME: Fails in swift::reflection::NoPayloadEnumTypeInfo::projectEnumValue: .second
32-
let enum2 = WithPayload.with(i:42) // CHECK-DAG: enum2 {{=}} with
33-
// CHECK-DAG: i {{=}} 42
34-
print(number)
10+
print(strct2)
3511
useTypeFromOtherModule(x: S2())
3612
}
3713

0 commit comments

Comments
 (0)