-
Notifications
You must be signed in to change notification settings - Fork 353
[lldb] Fix Language Plugin decl printing #6795
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
[lldb] Fix Language Plugin decl printing #6795
Conversation
|
@swift-ci test |
|
Will update with test coverage. |
|
This looks like it should be an upstream change? |
|
It should be yes, but the test won't be. I thought I'd do it here with the test and then add the code change to upstream. Thoughts? |
|
@swift-ci test |
| let object = Object() | ||
| _ = object // break here | ||
| let user = User() | ||
| // break 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.
print("break here") is safer.
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.
I was under the impression that the following line (_ = (object, user)) has the same safety effect as the print would. Is that not the case?
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.
I'm sure it works fine now. A (future) compiler could decide to optimize away the assignment, but not an i/o call.
|
You might be able to sell it as an NFC patch upstream |
|
@swift-ci test |
|
@swift-ci test windows |
| ConstString type_name_cstr(typeName.GetString()); | ||
| ConstString var_name_cstr(varName.GetString()); | ||
|
|
||
| DumpValueObjectOptions decl_print_options; |
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.
Mistake: this should be copy construction from m_options. New PR to follow.
|
Correction to #6795. This should be a copy constructed instance.
`SwiftLanguage::GetDeclPrintingHelper` is a helper function used for Swift types. This
code contains some very similar logic to the default logic in `ValueObjectPrinter`.
Specifically:
`SwiftLanguage`:
```c++
else if (!options.m_hide_name)
stream.Printf(" =");
```
`ValueObjectPrinter`:
```c++
else if (ShouldShowName())
m_stream->Printf(" =");
```
The function `ValueObjectPrinter::ShouldShowName` is not accessible by `SwiftLanguage`.
To allow `SwiftLanguage` to make the right decision, and fit within the existing API
boundary, this change uses a custom print options, which sets calls `SetHideName`
according to the value of `ShouldShowName()`. This allows the Swift language decl
printing helper to correctly know whether to print the name, or not.
(cherry-picked from commit e6d9bd6)
`SwiftLanguage::GetDeclPrintingHelper` is a helper function used for Swift types. This
code contains some very similar logic to the default logic in `ValueObjectPrinter`.
Specifically:
`SwiftLanguage`:
```c++
else if (!options.m_hide_name)
stream.Printf(" =");
```
`ValueObjectPrinter`:
```c++
else if (ShouldShowName())
m_stream->Printf(" =");
```
The function `ValueObjectPrinter::ShouldShowName` is not accessible by `SwiftLanguage`.
To allow `SwiftLanguage` to make the right decision, and fit within the existing API
boundary, this change uses a custom print options, which sets calls `SetHideName`
according to the value of `ShouldShowName()`. This allows the Swift language decl
printing helper to correctly know whether to print the name, or not.
(cherry-picked from commit e6d9bd6)
When `ValueObjectPrinter` calls its `m_decl_printing_helper`, not all state is passed to the helper. In particular, the helper doesn't have access to `m_curr_depth`, and thus can't act on the logic within `ShouldShowName`. To address this, this change passes in a modified copy of `m_options`. The modified copy has has `m_hide_name` set according to the results of `ShouldShowName`. This allows helper functions to know whether the name should be shown or hidden, without having access to `ValueObjectPrinter`'s full state. This is NFC in mainline lldb, as the only decl printing helper doesn't make use of this. However in swift-lldb at least, there are decl printing helpers that do need this information passed to them. See swiftlang#6795 where a test is also included. Differential Revision: https://reviews.llvm.org/D150129
SwiftLanguage::GetDeclPrintingHelperis a helper function used for Swift types. This code contains some very similar logic to the default logic inValueObjectPrinter. Specifically:SwiftLanguage:ValueObjectPrinter:The function
ValueObjectPrinter::ShouldShowNameis not accessible bySwiftLanguage.To allow
SwiftLanguageto make the right decision, and fit within the existing API boundary, this change uses a custom print options, which sets callsSetHideNameaccording to the value ofShouldShowName(). This allows the Swift language decl printing helper to correctly know whether to print the name, or not.