Skip to content

[cherry-pick][swift/release/5.9] [clang][DebugInfo] Emit DW_AT_type of preferred name if available #6612

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

Michael137
Copy link

With this patch, whenever we emit a DW_AT_type for some declaration
and the type is a template class with a clang::PreferredNameAttr, we
will emit the typedef that the attribute refers to instead. I.e.,

0x123 DW_TAG_variable
        DW_AT_name "var"
        DW_AT_type (0x123 "basic_string<char>")

0x124 DW_TAG_structure_type
        DW_AT_name "basic_string<char>"

...becomes

0x123 DW_TAG_variable
        DW_AT_name "var"
        DW_AT_type (0x124 "std::string")

0x124 DW_TAG_structure_type
        DW_AT_name "basic_string<char>"

0x125 DW_TAG_typedef
        DW_AT_name "std::string"
        DW_AT_type (0x124 "basic_string<char>")

We do this by returning the preferred name typedef DIType when
we create a structure definition. In some cases, e.g., with -gmodules,
we don't complete the structure definition immediately but do so later
via completeClassData, which overwrites the TypeCache. In such cases
we don't actually want to rewrite the cache with the preferred name. We
handle this by returning both the definition and the preferred typedef
from CreateTypeDefinition and let the callee decide what to do with
it.

Essentially we set up the types as:

TypeCache[Record] => DICompositeType
ReplaceMap[Record] => DIDerivedType(baseType: DICompositeType)

For now we keep this behind LLDB tuning.

Testing

  • Added clang unit-test
  • check-llvm, check-clang pass
  • Confirmed that this change correctly repoints
    basic_string references in some of my test programs.
  • Will add follow-up LLDB API tests

Differential Revision: https://reviews.llvm.org/D145803

@Michael137 Michael137 requested a review from adrian-prantl April 6, 2023 20:19
@Michael137
Copy link
Author

@swift-ci test

@Michael137 Michael137 force-pushed the feature/preferred-name-to-swift-5.9 branch from 18299a8 to bbb7995 Compare April 7, 2023 00:40
With this patch, whenever we emit a `DW_AT_type` for some declaration
and the type is a template class with a `clang::PreferredNameAttr`, we
will emit the typedef that the attribute refers to instead. I.e.,

```
0x123 DW_TAG_variable
        DW_AT_name "var"
        DW_AT_type (0x123 "basic_string<char>")

0x124 DW_TAG_structure_type
        DW_AT_name "basic_string<char>"
```
...becomes
```
0x123 DW_TAG_variable
        DW_AT_name "var"
        DW_AT_type (0x124 "std::string")

0x124 DW_TAG_structure_type
        DW_AT_name "basic_string<char>"

0x125 DW_TAG_typedef
        DW_AT_name "std::string"
        DW_AT_type (0x124 "basic_string<char>")
```

We do this by returning the preferred name typedef `DIType` when
we create a structure definition. In some cases, e.g., with `-gmodules`,
we don't complete the structure definition immediately but do so later
via `completeClassData`, which overwrites the `TypeCache`. In such cases
we don't actually want to rewrite the cache with the preferred name. We
handle this by returning both the definition and the preferred typedef
from `CreateTypeDefinition` and let the callee decide what to do with
it.

Essentially we set up the types as:
```
TypeCache[Record] => DICompositeType
ReplaceMap[Record] => DIDerivedType(baseType: DICompositeType)
```

For now we keep this behind LLDB tuning.

**Testing**

- Added clang unit-test
- `check-llvm`, `check-clang` pass
- Confirmed that this change correctly repoints
  `basic_string` references in some of my test programs.
- Will add follow-up LLDB API tests

Differential Revision: https://reviews.llvm.org/D145803

(cherry picked from commit 19cc390)
Describes changes made in D145803.

Differential Revision: https://reviews.llvm.org/D147695

(cherry picked from commit 80fe7358f6f4811d2619cf4c09fb246b6b6c764b)
Add some tests to make sure we're formatting structures
with preferred names correctly.

Differential Revision: https://reviews.llvm.org/D145832

(cherry picked from commit 1eaf3b7)
@Michael137 Michael137 force-pushed the feature/preferred-name-to-swift-5.9 branch from bbb7995 to 3e95d3e Compare April 8, 2023 10:21
@Michael137
Copy link
Author

@swift-ci test

1 similar comment
@Michael137
Copy link
Author

@swift-ci test

@Michael137 Michael137 merged commit d41f263 into swiftlang:swift/release/5.9 Apr 9, 2023
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.

1 participant