From 756cb872fd9ffc5244ec9b78373d6483fc2e12c5 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Mon, 23 Jun 2025 10:30:04 -0700 Subject: [PATCH 1/4] [lldb] Add test for @objc @implementation --- .../lang/swift/objc_implementation/Gadget.h | 13 ++++++++++ .../lang/swift/objc_implementation/Makefile | 4 ++++ .../TestSwiftObjCImplementation.py | 24 +++++++++++++++++++ .../lang/swift/objc_implementation/main.swift | 15 ++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 lldb/test/API/lang/swift/objc_implementation/Gadget.h create mode 100644 lldb/test/API/lang/swift/objc_implementation/Makefile create mode 100644 lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py create mode 100644 lldb/test/API/lang/swift/objc_implementation/main.swift diff --git a/lldb/test/API/lang/swift/objc_implementation/Gadget.h b/lldb/test/API/lang/swift/objc_implementation/Gadget.h new file mode 100644 index 0000000000000..f0cb990036a17 --- /dev/null +++ b/lldb/test/API/lang/swift/objc_implementation/Gadget.h @@ -0,0 +1,13 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface Gadget : NSObject +@property(nonatomic, assign) NSInteger integer; +@property(nonatomic, assign) BOOL boolean; +@property(nonatomic, strong) NSObject *object; +@property(nonatomic, copy) NSString *string; +@property(nonatomic, copy) NSObject *stringObject; +@end + +NS_ASSUME_NONNULL_END diff --git a/lldb/test/API/lang/swift/objc_implementation/Makefile b/lldb/test/API/lang/swift/objc_implementation/Makefile new file mode 100644 index 0000000000000..51111ac36a3e2 --- /dev/null +++ b/lldb/test/API/lang/swift/objc_implementation/Makefile @@ -0,0 +1,4 @@ +SWIFT_SOURCES = main.swift +SWIFT_BRIDGING_HEADER = Gadget.h +SWIFT_PRECOMPILE_BRIDGING_HEADER = NO +include Makefile.rules diff --git a/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py b/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py new file mode 100644 index 0000000000000..1c807f0a3334f --- /dev/null +++ b/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py @@ -0,0 +1,24 @@ +import lldb +from lldbsuite.test.lldbtest import * +from lldbsuite.test.decorators import * +import lldbsuite.test.lldbutil as lldbutil + + +class TestCase(TestBase): + def test(self): + self.build() + lldbutil.run_to_source_breakpoint( + self, "break here", lldb.SBFileSpec("main.swift") + ) + self.expect( + "frame var g", + substrs=[ + "integer = 15", + "boolean = true", + "object = some", + 'stringObject = "Joker"', + ], + ) + # Swift types that are not representable in ObjC (bridged types such as + # String) are not currently listed in the children. rdar://154046212 + self.expect("frame var g", matching=False, substrs=['string = "Ace"']) diff --git a/lldb/test/API/lang/swift/objc_implementation/main.swift b/lldb/test/API/lang/swift/objc_implementation/main.swift new file mode 100644 index 0000000000000..ad9abfff91af7 --- /dev/null +++ b/lldb/test/API/lang/swift/objc_implementation/main.swift @@ -0,0 +1,15 @@ +@objc @implementation +extension Gadget { + var integer: Int = 15 + var boolean: Bool = true + var object: NSObject = NSObject() + var string: String = "Ace" + var stringObject: NSObject = "Joker" as NSString +} + +func main() { + let g = Gadget() + print("break here") +} + +main() From 78dd2a91005b9eea85e50f70e123620310ad9796 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Mon, 23 Jun 2025 14:25:55 -0700 Subject: [PATCH 2/4] Add test decorators --- .../swift/objc_implementation/TestSwiftObjCImplementation.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py b/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py index 1c807f0a3334f..9e32194ad2110 100644 --- a/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py +++ b/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py @@ -5,6 +5,9 @@ class TestCase(TestBase): + + @swiftTest + @skipUnlessFoundation def test(self): self.build() lldbutil.run_to_source_breakpoint( From 156e844a595e0e20c1e6e80ec7cf2e880264bba8 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Mon, 23 Jun 2025 16:02:08 -0700 Subject: [PATCH 3/4] Handle x86_64 bools --- .../swift/objc_implementation/TestSwiftObjCImplementation.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py b/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py index 9e32194ad2110..3b662822d2d50 100644 --- a/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py +++ b/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py @@ -17,10 +17,12 @@ def test(self): "frame var g", substrs=[ "integer = 15", - "boolean = true", "object = some", 'stringObject = "Joker"', ], + # On x86_64, BOOL types have an objc encoding of 'c', which is a + # signed char. The result is in an output of '\x01'. + patterns=[r"boolean = (true|'\x01')"], ) # Swift types that are not representable in ObjC (bridged types such as # String) are not currently listed in the children. rdar://154046212 From 1fe5cc8d5d6446ed29869ec4562e6804981df2ba Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Mon, 23 Jun 2025 19:02:51 -0700 Subject: [PATCH 4/4] Fix test regex --- .../swift/objc_implementation/TestSwiftObjCImplementation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py b/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py index 3b662822d2d50..000eb891dd3e4 100644 --- a/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py +++ b/lldb/test/API/lang/swift/objc_implementation/TestSwiftObjCImplementation.py @@ -22,7 +22,7 @@ def test(self): ], # On x86_64, BOOL types have an objc encoding of 'c', which is a # signed char. The result is in an output of '\x01'. - patterns=[r"boolean = (true|'\x01')"], + patterns=[r"boolean = (true|'\\x01')"], ) # Swift types that are not representable in ObjC (bridged types such as # String) are not currently listed in the children. rdar://154046212