From 3d19de9910ab7fb9497933c2136d253295c761b2 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Wed, 11 Apr 2012 05:56:05 +0000 Subject: [PATCH] Enable debug info for objective c implementations that may not have an explicit instance variable. rdar://10590352 llvm-svn: 154481 --- clang/lib/CodeGen/CGDebugInfo.cpp | 12 +++++++++++- clang/lib/CodeGen/CGDebugInfo.h | 6 ++++++ clang/lib/CodeGen/CodeGenModule.cpp | 5 +++++ clang/test/CodeGenObjC/debug-info-block-helper.m | 2 +- clang/test/CodeGenObjC/debug-info-impl.m | 16 ++++++++++++++++ clang/test/CodeGenObjC/debug-info-pubtypes.m | 2 +- clang/test/CodeGenObjC/debug-info-synthesis.m | 4 ++-- 7 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 clang/test/CodeGenObjC/debug-info-impl.m diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 587ab8a3571e..23e922de6bc6 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1181,6 +1181,15 @@ llvm::DIType CGDebugInfo::getOrCreateRecordType(QualType RTy, return T; } +/// getOrCreateInterfaceType - Emit an objective c interface type standalone +/// debug info. +llvm::DIType CGDebugInfo::getOrCreateInterfaceType(QualType D, + SourceLocation Loc) { + llvm::DIType T = getOrCreateType(D, getOrCreateFile(Loc)); + DBuilder.retainType(T); + return T; +} + /// CreateType - get structure or union type. llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty) { RecordDecl *RD = Ty->getDecl(); @@ -1282,6 +1291,7 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, RuntimeLang); return FwdDecl; } + ID = Def; // Bit size, align and offset of the type. @@ -1296,7 +1306,7 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, DBuilder.createStructType(Unit, ID->getName(), DefUnit, Line, Size, Align, Flags, llvm::DIArray(), RuntimeLang); - + // Otherwise, insert it into the CompletedTypeCache so that recursive uses // will find it and we're emitting the complete type. CompletedTypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl; diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index a071b06c26d3..ec7705c05447 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -226,6 +226,12 @@ public: /// getOrCreateRecordType - Emit record type's standalone debug info. llvm::DIType getOrCreateRecordType(QualType Ty, SourceLocation L); + + /// getOrCreateInterfaceType - Emit an objective c interface type standalone + /// debug info. + llvm::DIType getOrCreateInterfaceType(QualType Ty, + SourceLocation Loc); + private: /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index c9f1066032d9..c0ccf4de4c9f 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2535,6 +2535,11 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { EmitObjCPropertyImplementations(OMD); EmitObjCIvarInitializations(OMD); ObjCRuntime->GenerateClass(OMD); + // Emit global variable debug information. + if (CGDebugInfo *DI = getModuleDebugInfo()) + DI->getOrCreateInterfaceType(getContext().getObjCInterfaceType(OMD->getClassInterface()), + OMD->getLocation()); + break; } case Decl::ObjCMethod: { diff --git a/clang/test/CodeGenObjC/debug-info-block-helper.m b/clang/test/CodeGenObjC/debug-info-block-helper.m index 28374cd16d78..ac164618f81c 100644 --- a/clang/test/CodeGenObjC/debug-info-block-helper.m +++ b/clang/test/CodeGenObjC/debug-info-block-helper.m @@ -2,7 +2,7 @@ // RUN: %clang_cc1 -emit-llvm -fblocks -g -triple x86_64-apple-darwin10 -fobjc-fragile-abi %s -o - | FileCheck %s extern void foo(void(^)(void)); -// CHECK: !40 = metadata !{i32 {{.*}}, i32 0, metadata !25, metadata !"__destroy_helper_block_", metadata !"__destroy_helper_block_", metadata !"", metadata !25, i32 24, metadata !41, i1 true, i1 true, i32 0, i32 0, null, i32 256, i1 false, void (i8*)* @__destroy_helper_block_, null, null, metadata !43, i32 24} ; [ DW_TAG_subprogram ] +// CHECK: !42 = metadata !{i32 {{.*}}, i32 0, metadata !27, metadata !"__destroy_helper_block_", metadata !"__destroy_helper_block_", metadata !"", metadata !27, i32 24, metadata !43, i1 true, i1 true, i32 0, i32 0, null, i32 256, i1 false, void (i8*)* @__destroy_helper_block_, null, null, metadata !45, i32 24} ; [ DW_TAG_subprogram ] @interface NSObject { struct objc_object *isa; diff --git a/clang/test/CodeGenObjC/debug-info-impl.m b/clang/test/CodeGenObjC/debug-info-impl.m new file mode 100644 index 000000000000..68ce5d9406a0 --- /dev/null +++ b/clang/test/CodeGenObjC/debug-info-impl.m @@ -0,0 +1,16 @@ +// RUN: %clang -fverbose-asm -g -S -emit-llvm %s -o - | FileCheck %s +// CHECK: metadata !{i32 786451, metadata !6, metadata !"Circle", metadata !6, i32 11, i64 64, i64 64, i32 0, i32 512, null, metadata !7, i32 16, i32 0} ; [ DW_TAG_structure_type ] +@interface NSObject { + struct objc_object *isa; +} +@end + +@interface Shape : NSObject + +@end +@interface Circle : Shape + +@end +@implementation Circle + +@end diff --git a/clang/test/CodeGenObjC/debug-info-pubtypes.m b/clang/test/CodeGenObjC/debug-info-pubtypes.m index d00db67c55bc..658430d9307b 100644 --- a/clang/test/CodeGenObjC/debug-info-pubtypes.m +++ b/clang/test/CodeGenObjC/debug-info-pubtypes.m @@ -1,7 +1,7 @@ // REQUIRES: x86-64-registered-target // RUN: %clang -cc1 -triple x86_64-apple-darwin10 -g -emit-llvm %s -o - | FileCheck %s -// CHECK: !10 = metadata !{i32 {{.*}}, metadata !6, metadata !"H", metadata !6, i32 6, i64 0, i64 8, i32 0, i32 512, null, metadata !2, i32 16, i32 0} ; [ DW_TAG_structure_type ] +// CHECK: !5 = metadata !{i32 {{.*}}, metadata !6, metadata !"H", metadata !6, i32 6, i64 0, i64 8, i32 0, i32 512, null, metadata !2, i32 16, i32 0} ; [ DW_TAG_structure_type ] @interface H -(void) foo; diff --git a/clang/test/CodeGenObjC/debug-info-synthesis.m b/clang/test/CodeGenObjC/debug-info-synthesis.m index 389e6230356c..7e263cf74c6e 100644 --- a/clang/test/CodeGenObjC/debug-info-synthesis.m +++ b/clang/test/CodeGenObjC/debug-info-synthesis.m @@ -30,5 +30,5 @@ int main(int argc, char *argv[]) { } } -// CHECK: !11 = metadata !{i32 {{.*}}, metadata !"./foo.h" -// CHECK: !29 = metadata !{i32 {{.*}}, i32 0, metadata !11, metadata !"-[Foo dict]", metadata !"-[Foo dict]", metadata !"", metadata !11, i32 8, metadata !30, i1 true, i1 true, i32 0, i32 0, null, i32 320, i1 false, %1* (%0*, i8*)* @"\01-[Foo dict]", null, null, metadata !32, i32 8} ; [ DW_TAG_subprogram ] +// CHECK: !7 = metadata !{i32 {{.*}}, metadata !"./foo.h" +// CHECK: !31 = metadata !{i32 {{.*}}, i32 0, metadata !7, metadata !"-[Foo dict]", metadata !"-[Foo dict]", metadata !"", metadata !7, i32 8, metadata !32, i1 true, i1 true, i32 0, i32 0, null, i32 320, i1 false, %1* (%0*, i8*)* @"\01-[Foo dict]", null, null, metadata !34, i32 8} ; [ DW_TAG_subprogram ]