llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[lldb][DWARFASTParserClang] Eagerly search definitions for Objective-C classes

Open Michael137 opened this issue 1 year ago • 2 comments

This patch essentially reverts the definition DIE delay changes (in https://github.com/llvm/llvm-project/pull/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 avatar Dec 16 '24 11:12 Michael137

@swift-ci test

Michael137 avatar Dec 16 '24 11:12 Michael137

@swift-ci test

Michael137 avatar Dec 16 '24 19:12 Michael137

Not needed, for now..

Michael137 avatar Sep 03 '25 14:09 Michael137