Skip to content

[lldb] Support breakpoints on specific property accessor blocks #8546

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

Conversation

kastiglione
Copy link

@kastiglione kastiglione commented Apr 4, 2024

Allows breakpoints to be set on computed properties, as well as other property accessor blocks including setters, and observers (willSet, didSet).

This change allows property accessor blocks to be set using the suffix generated for these by the compiler. They are:

  • .get
  • .set
  • .willset
  • .didset

In particular, this change allows the following command to work: b computed_prop.get. This will create a breakpoint on a computed property's getter – which is the motivation of this change. Currently, there's no way to set a breakpoint by name on computed properties.

Note that these suffixes are emitted by the compiler into debug info. Ex:

% dwarfdump main.dSYM | grep computed_prop
                    DW_AT_linkage_name	("$s4main1SV13computed_propSbvg")
                    DW_AT_name	("computed_prop.get")

rdar://125740294

@kastiglione kastiglione marked this pull request as draft April 4, 2024 23:24
@kastiglione
Copy link
Author

kastiglione commented Apr 4, 2024

TODO

  • Test core functionality
  • Test false positives

@jimingham
Copy link

Saying that the getter & setter names are variants of the property name makes sense.

Is it worth thinking of a way to specify "only setters" or "only getters"? You can always disable the extra locations after the fact, but that might get tedious.

This needs some tests, first that show it works for the property access variants. It would also be nice to test that this doesn't cause unintended hits against classes that just happen to have a method with one of these names.

@kastiglione kastiglione marked this pull request as ready for review April 5, 2024 01:38
@kastiglione
Copy link
Author

Is it worth thinking of a way to specify "only setters" or "only getters"?

I don't understand. With this change, property breakpoints must explicitly indicate which accessor the breakpoint should be set on (.get, .set, etc).

This needs some tests, first that show it works for the property access variants.

done ✅

It would also be nice to test that this doesn't cause unintended hits against classes that just happen to have a method with one of these names.

I'm also not sure what you mean. Could you illustrate an example of an unintended match? thanks

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

It would also be nice to test that this doesn't cause unintended hits against classes that just happen to have a method with one of these names.

do you meaning that b get should not match getters of computed properties, only functions/methods actually named get?

@kastiglione
Copy link
Author

@swift-ci test windows

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione requested a review from jimingham April 5, 2024 16:23
Copy link

@jimingham jimingham left a comment

Choose a reason for hiding this comment

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

I missed where this came in the breakpoint flow, I thought it would add hits not candidates. Since it's just adding candidates, the user gets to choose which ones they want, so that's taken care of.

What is the flow when I have a property that doesn't have a willSet, but I set a breakpoint on willSet? The GetMethodNameVariants will add a willSet name to the list of variants, but that method doesn't actually exist. Is it clear what went on in that case?

If that's not confusing, I'm fine with this. Thanks for the test!

@kastiglione
Copy link
Author

@swift-ci test windows

@@ -138,6 +138,25 @@ SwiftLanguage::GetMethodNameVariants(ConstString method_name) const {
if (method_name.GetMangledCounterpart(counterpart))
if (SwiftLanguageRuntime::IsSwiftMangledName(counterpart.GetStringRef()))
variant_names.emplace_back(counterpart, eFunctionNameTypeFull);

// Properties can have multiple accessor blocks. This section of code supports
// breakpoints on accessor blocks by name.

Choose a reason for hiding this comment

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

Is accessor "block" a term of art? I would have expected this to be called an "accessor method" or just an "accessor".

Copy link
Author

@kastiglione kastiglione Apr 5, 2024

Choose a reason for hiding this comment

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

the documentation of the swift grammar calls them blocks, see "variable-declaration" in https://docs.swift.org/swift-book/documentation/the-swift-programming-language/summaryofthegrammar#Declarations

I'm fine with removing the word block though.

@kastiglione
Copy link
Author

@swift-ci test

@adrian-prantl
Copy link

@swift-ci test windows

@adrian-prantl adrian-prantl merged commit 49cbc3a into swift/release/6.0 Apr 15, 2024
@kastiglione kastiglione deleted the dl/lldb-Support-breakpoints-on-specific-property-accessor-blocks branch April 16, 2024 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants