Skip to content

Conversation

@kastiglione
Copy link

@kastiglione kastiglione commented May 5, 2023

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:

else if (!options.m_hide_name)
  stream.Printf(" =");

ValueObjectPrinter:

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.

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione requested a review from adrian-prantl May 5, 2023 21:59
@kastiglione kastiglione marked this pull request as draft May 5, 2023 21:59
@kastiglione
Copy link
Author

Will update with test coverage.

@adrian-prantl
Copy link

This looks like it should be an upstream change?

@kastiglione
Copy link
Author

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?

@kastiglione
Copy link
Author

@swift-ci test

let object = Object()
_ = object // break here
let user = User()
// break here

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.

Copy link
Author

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?

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.

@adrian-prantl
Copy link

You might be able to sell it as an NFC patch upstream

@kastiglione kastiglione marked this pull request as ready for review May 5, 2023 22:38
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test windows

@kastiglione kastiglione merged commit e6d9bd6 into swift/release/5.9 May 6, 2023
@kastiglione kastiglione deleted the dl/lldb-fix-language-plugin-decl-printing branch May 6, 2023 19:33
ConstString type_name_cstr(typeName.GetString());
ConstString var_name_cstr(varName.GetString());

DumpValueObjectOptions decl_print_options;
Copy link
Author

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.

@kastiglione
Copy link
Author

This looks like it should be an upstream change?

https://reviews.llvm.org/D150129

kastiglione added a commit that referenced this pull request May 8, 2023
Correction to #6795. This should be a copy constructed instance.
kastiglione added a commit that referenced this pull request May 9, 2023
`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)
kastiglione added a commit that referenced this pull request May 9, 2023
`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)
kastiglione added a commit that referenced this pull request May 9, 2023
Correction to #6795. This should be a copy constructed instance.

(cherry-picked from commit d20d8db)
kastiglione added a commit that referenced this pull request May 9, 2023
Correction to #6795. This should be a copy constructed instance.

(cherry-picked from commit d20d8db)
kastiglione added a commit to llvm/llvm-project that referenced this pull request May 15, 2023
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
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