Skip to content

[lldb] Add test for @objc @implementation #10889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lldb/test/API/lang/swift/objc_implementation/Gadget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import <Foundation/Foundation.h>

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
4 changes: 4 additions & 0 deletions lldb/test/API/lang/swift/objc_implementation/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SWIFT_SOURCES = main.swift
SWIFT_BRIDGING_HEADER = Gadget.h
SWIFT_PRECOMPILE_BRIDGING_HEADER = NO

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity — why is this needed?
(It basically removes DWARF for the types in the header, so I'm curious if the test depends on the missing debug info)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the test depends on the absence of debug info (to emulate system or third party libraries). Is there a better way to do this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the clangimported part, this is probably them most convenient solution. Maybe we could add a comment like

# This hides the debug info, to make sure ObjC metadata is being used to resolve the types.

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil


class TestCase(TestBase):

@swiftTest
@skipUnlessFoundation
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",
"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
self.expect("frame var g", matching=False, substrs=['string = "Ace"'])
15 changes: 15 additions & 0 deletions lldb/test/API/lang/swift/objc_implementation/main.swift
Original file line number Diff line number Diff line change
@@ -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()