forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 340
[lldb] Fix stepping into Objective-C interop ctors #10697
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
Open
felipepiovezan
wants to merge
2
commits into
swiftlang:swift/release/6.2
Choose a base branch
from
felipepiovezan:felipe/wip_step_into_objectivec_interop
base: swift/release/6.2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+194
−35
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
lldb/test/API/lang/swift/step_into_objc_interop_init/Foo.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
@interface Foo : NSObject | ||
|
||
@property (nonnull) NSArray<NSString *> *values; | ||
|
||
- (nonnull id)init; | ||
- (nonnull id)initWithString:(nonnull NSString *)value; | ||
- (nonnull id)initWithString:(nonnull NSString *)value andOtherString:(nonnull NSString *) otherValue; | ||
|
||
@end |
18 changes: 18 additions & 0 deletions
18
lldb/test/API/lang/swift/step_into_objc_interop_init/Foo.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#import "Foo.h" | ||
|
||
@implementation Foo | ||
|
||
- (id)init { | ||
} | ||
|
||
- (id)initWithString:(nonnull NSString *)value { | ||
self->_values = @[value]; | ||
return self; | ||
} | ||
|
||
- (nonnull id)initWithString:(nonnull NSString *)value andOtherString:(nonnull NSString *) otherValue { | ||
self->_values = @[value, otherValue]; | ||
return self; | ||
} | ||
|
||
@end |
6 changes: 6 additions & 0 deletions
6
lldb/test/API/lang/swift/step_into_objc_interop_init/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
SWIFT_SOURCES := main.swift | ||
SWIFT_BRIDGING_HEADER := bridging-header.h | ||
OBJC_SOURCES := Foo.m | ||
SWIFT_OBJC_INTEROP := 1 | ||
|
||
include Makefile.rules |
51 changes: 51 additions & 0 deletions
51
lldb/test/API/lang/swift/step_into_objc_interop_init/TestStepIntoObjCInteropInit.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import lldb | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test.decorators import * | ||
import lldbsuite.test.lldbutil as lldbutil | ||
|
||
|
||
class TestSwiftObjcProtocol(TestBase): | ||
def skip_debug_info_libraries(self): | ||
if platform.system() == "Darwin": | ||
lib_name = "libswiftCore.dylib" | ||
else: | ||
lib_name = "libswiftCore.so" | ||
|
||
self.dbg.HandleCommand( | ||
"settings set " | ||
"target.process.thread.step-avoid-libraries {}".format(lib_name) | ||
) | ||
|
||
@skipUnlessDarwin | ||
@swiftTest | ||
def test(self): | ||
self.build() | ||
(target, process, thread, breakpoint) = lldbutil.run_to_source_breakpoint( | ||
self, "break here", lldb.SBFileSpec("main.swift") | ||
) | ||
|
||
self.skip_debug_info_libraries() | ||
# Go to the first constructor, assert we can step into it. | ||
thread.StepInto() | ||
self.assertEqual(thread.stop_reason, lldb.eStopReasonPlanComplete) | ||
self.assertIn("-[Foo init]", thread.frames[0].GetFunctionName()) | ||
|
||
# Go back to "work" function | ||
thread.StepOut() | ||
self.assertEqual(thread.stop_reason, lldb.eStopReasonPlanComplete) | ||
self.assertIn("work", thread.frames[0].GetFunctionName()) | ||
|
||
# Go to the next constructor call. | ||
thread.StepOver() | ||
self.assertEqual(thread.stop_reason, lldb.eStopReasonPlanComplete) | ||
self.assertIn("work", thread.frames[0].GetFunctionName()) | ||
|
||
# Assert we can step into it. | ||
thread.StepInto() | ||
self.assertEqual(thread.stop_reason, lldb.eStopReasonPlanComplete) | ||
self.assertIn("-[Foo initWithString:]", thread.frames[0].GetFunctionName()) | ||
|
||
# Go back to "work" function | ||
thread.StepOut() | ||
self.assertEqual(thread.stop_reason, lldb.eStopReasonPlanComplete) | ||
self.assertIn("work", thread.frames[0].GetFunctionName()) |
1 change: 1 addition & 0 deletions
1
lldb/test/API/lang/swift/step_into_objc_interop_init/bridging-header.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#import "Foo.h" |
7 changes: 7 additions & 0 deletions
7
lldb/test/API/lang/swift/step_into_objc_interop_init/main.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
func work() { | ||
let noParams = Foo() // break here | ||
let oneParam = Foo(string: "Bar") | ||
print("done") | ||
} | ||
|
||
work() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if childAtPath handles null NodePointer arguments, still seem easier to follow if you checked the return here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
If we're taking this approach, it would be worth being consistent everywhere (in a separate patch) and changing
childAtPath
to take a reference instead, so that it no longer accepts nullptrs by definition.While I believe the current approach leads to more succinct code, either one is fine as long as we're consistent. The only undesirable outcome is the middle ground where the callee handles nullptrs but callers are also expected to be checking. Either we trust the API to do things correctly (the API said it would when it declared itself taking a pointer), or we change the API to take a reference. APIs that accept pointers but don't handle null are bad APIs.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops, I forgot to do this. Will push another patch shortly
edit: done