forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lldb][DWARFASTParserClang] Eagerly search definitions for Objective-…
…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.
- Loading branch information
1 parent
1274e90
commit f767cb7
Showing
4 changed files
with
132 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
lldb/test/Shell/SymbolFile/DWARF/objc-gmodules-class-extension.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# REQUIRES: system-darwin | ||
|
||
# Test that we can set a breakpoint in a method of a class extension. | ||
# This requires us to parse the method into an AST type, and the context | ||
# too (which in DWARF is just a forward declaration). | ||
# | ||
# RUN: split-file %s %t | ||
# RUN: %clangxx_host %t/lib.m -c -g -gmodules -fmodules -o %t/lib.o | ||
# RUN: %clangxx_host %t/main.m -g -gmodules -fmodules %t/lib.o -o %t/a.out -framework Foundation | ||
# | ||
# RUN: %lldb %t/a.out -o "breakpoint set -f lib.m -l 6" -o exit | FileCheck %s | ||
|
||
# CHECK: (lldb) breakpoint set -f lib.m -l 6 | ||
# CHECK: Breakpoint 1: where = a.out`-[NSObject(Foo) func] | ||
|
||
#--- main.m | ||
int main() { | ||
return 0; | ||
} | ||
|
||
#--- lib.m | ||
#import <Foundation/Foundation.h> | ||
|
||
@implementation NSObject (Foo) | ||
- (NSError *)func { | ||
NSLog(@"Hello, World!"); | ||
return 0; | ||
} | ||
@end | ||
|
||
NSObject * func() { | ||
return 0; | ||
} |