Skip to content
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][DWARFASTParserClang] Eagerly search definitions for Objective-C classes #9749

Open
wants to merge 1 commit into
base: swift/release/6.1
Choose a base branch
from

Conversation

Michael137
Copy link

This patch essentially reverts the definition DIE delay changes (in llvm#98361) for Objective-C.

The problem we've been seeing is as follows:

  1. An Objetive-C class extension is represented in DWARF as:
DW_TAG_structure_type
  DW_AT_declaration (true)
  DW_AT_name ("ExtendedClass")

  DW_TAG_subprogram
    DW_AT_name ("extensionMethod")
    ...

I.e., it is a forward declaration of the extended class, but that forward declaration has children methods.

  1. When we set a breakpoint in one of those methods we parse the subprogram DIE and try to create an ObjCMethodDecl for it (and attach it to the context).

  2. When parsing the subprogram DIE, we first try to complete the DeclContext. Because ExtendedClass is only a forward declaration and we don't try to fetch the definition DIE eagerly anymore, LLDB has no idea that we're dealing with an Objective-C type. So it goes ahead and constructs it as a CXXRecordDecl. This confuses DWARFASTParserClang::ParseObjCMethod because it expects the context to be an clang::ObjCObjectOrInterfaceType. So it bails and we end up crashing because we try to attach a FunctionDecl to an incomplete CXXRecordDecl (which wasn't even forcefully completed).

Since there's no good way to tell whether a forward declaration is an Objective-C type, the only solution I can really see here is to eagerly fetch the definition for Objective-C types.

@Michael137 Michael137 requested a review from a team as a code owner December 16, 2024 11:48
@Michael137
Copy link
Author

@swift-ci test

@Michael137 Michael137 force-pushed the lldb/gmodules-dsym-objc-crash-to-6.1 branch 5 times, most recently from f767cb7 to 318b66a Compare December 16, 2024 19:47
@Michael137
Copy link
Author

@swift-ci test

…C classes

This patch essentially reverts the definition DIE delay changes (in llvm#98361) for Objective-C.

The problem we've been seeing is as follows:
1. An Objetive-C class extension is represented in DWARF as:
```
DW_TAG_structure_type
  DW_AT_declaration (true)
  DW_AT_name ("ExtendedClass")

  DW_TAG_subprogram
    DW_AT_name ("extensionMethod")
    ...
```
I.e., it is a forward declaration of the extended class, but that forward declaration has children methods.

2. When we set a breakpoint in one of those methods we parse the subprogram DIE and try to create an `ObjCMethodDecl` for it (and attach it to the context).

3. When parsing the subprogram DIE, we first try to complete the DeclContext. Because `ExtendedClass` is only a forward declaration and we don't try to fetch the definition DIE eagerly anymore, LLDB has no idea that we're dealing with an Objective-C type. So it goes ahead and constructs it as a `CXXRecordDecl`. This confuses `DWARFASTParserClang::ParseObjCMethod` because it expects the context to be an `clang::ObjCObjectOrInterfaceType`. So it bails and we end up crashing because we try to attach a `FunctionDecl` to an incomplete `CXXRecordDecl` (which wasn't even forcefully completed).

Since there's no good way to tell whether a forward declaration is an Objective-C type, the only solution I can really see here is to eagerly fetch the definition for Objective-C types.
@Michael137 Michael137 force-pushed the lldb/gmodules-dsym-objc-crash-to-6.1 branch from 318b66a to c1d797b Compare December 16, 2024 20:25
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