Author: adrian Date: Fri Jan 22 15:14:41 2016 New Revision: 258555 URL: http://llvm.org/viewvc/llvm-project?rev=258555&view=rev Log: Module debugging: Create a parent DIModule with the PCH name for types emitted into a precompiled header to mirror the debug info emitted for object files importing the PCH.
rdar://problem/24290667 Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.h cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp cfe/trunk/test/Modules/ModuleDebugInfo.m Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=258555&r1=258554&r2=258555&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Jan 22 15:14:41 2016 @@ -2224,8 +2224,12 @@ llvm::DIModule *CGDebugInfo::getParentMo // option. FullSourceLoc Loc(D->getLocation(), CGM.getContext().getSourceManager()); if (Module *M = ClangModuleMap->inferModuleFromLocation(Loc)) { + // This is a (sub-)module. auto Info = ExternalASTSource::ASTSourceDescriptor(*M); return getOrCreateModuleRef(Info, /*SkeletonCU=*/false); + } else { + // This the precompiled header being built. + return getOrCreateModuleRef(PCHDescriptor, /*SkeletonCU=*/false); } } Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=258555&r1=258554&r2=258555&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Fri Jan 22 15:14:41 2016 @@ -16,6 +16,7 @@ #include "CGBuilder.h" #include "clang/AST/Expr.h" +#include "clang/AST/ExternalASTSource.h" #include "clang/AST/Type.h" #include "clang/Basic/SourceLocation.h" #include "clang/Frontend/CodeGenOptions.h" @@ -57,6 +58,7 @@ class CGDebugInfo { llvm::DIBuilder DBuilder; llvm::DICompileUnit *TheCU = nullptr; ModuleMap *ClangModuleMap = nullptr; + ExternalASTSource::ASTSourceDescriptor PCHDescriptor; SourceLocation CurLoc; llvm::DIType *VTablePtrType = nullptr; llvm::DIType *ClassTy = nullptr; @@ -275,6 +277,8 @@ public: void finalize(); + /// Module debugging: Support for building PCMs. + /// @{ /// Set the main CU's DwoId field to \p Signature. void setDwoId(uint64_t Signature); @@ -283,6 +287,14 @@ public: /// the module of origin of each Decl. void setModuleMap(ModuleMap &MMap) { ClangModuleMap = &MMap; } + /// When generating debug information for a clang module or + /// precompiled header, this module map will be used to determine + /// the module of origin of each Decl. + void setPCHDescriptor(ExternalASTSource::ASTSourceDescriptor PCH) { + PCHDescriptor = PCH; + } + /// @} + /// Update the current source location. If \arg loc is invalid it is /// ignored. void setLocation(SourceLocation Loc); Modified: cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp?rev=258555&r1=258554&r2=258555&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp (original) +++ cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp Fri Jan 22 15:14:41 2016 @@ -42,6 +42,7 @@ namespace { class PCHContainerGenerator : public ASTConsumer { DiagnosticsEngine &Diags; const std::string MainFileName; + const std::string OutputFileName; ASTContext *Ctx; ModuleMap &MMap; const HeaderSearchOptions &HeaderSearchOpts; @@ -137,7 +138,8 @@ public: const std::string &OutputFileName, raw_pwrite_stream *OS, std::shared_ptr<PCHBuffer> Buffer) - : Diags(CI.getDiagnostics()), Ctx(nullptr), + : Diags(CI.getDiagnostics()), MainFileName(MainFileName), + OutputFileName(OutputFileName), Ctx(nullptr), MMap(CI.getPreprocessor().getHeaderSearchInfo().getModuleMap()), HeaderSearchOpts(CI.getHeaderSearchOpts()), PreprocessorOpts(CI.getPreprocessorOpts()), @@ -163,6 +165,8 @@ public: Builder.reset(new CodeGen::CodeGenModule( *Ctx, HeaderSearchOpts, PreprocessorOpts, CodeGenOpts, *M, Diags)); Builder->getModuleDebugInfo()->setModuleMap(MMap); + Builder->getModuleDebugInfo()->setPCHDescriptor( + {MainFileName, "", OutputFileName, ~1ULL}); } bool HandleTopLevelDecl(DeclGroupRef D) override { Modified: cfe/trunk/test/Modules/ModuleDebugInfo.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ModuleDebugInfo.m?rev=258555&r1=258554&r2=258555&view=diff ============================================================================== --- cfe/trunk/test/Modules/ModuleDebugInfo.m (original) +++ cfe/trunk/test/Modules/ModuleDebugInfo.m Fri Jan 22 15:14:41 2016 @@ -10,13 +10,14 @@ // RUN: -I %S/Inputs -I %t -emit-llvm -o %t.ll \ // RUN: -mllvm -debug-only=pchcontainer &>%t-mod.ll // RUN: cat %t-mod.ll | FileCheck %s -// RUN: cat %t-mod.ll | FileCheck %s --check-prefix=MODULE-CHECK +// RUN: cat %t-mod.ll | FileCheck %s --check-prefix=CHECK2 // PCH: // RUN: %clang_cc1 -x objective-c -emit-pch -fmodule-format=obj -I %S/Inputs \ // RUN: -o %t.pch %S/Inputs/DebugObjC.h \ // RUN: -mllvm -debug-only=pchcontainer &>%t-pch.ll // RUN: cat %t-pch.ll | FileCheck %s +// RUN: cat %t-pch.ll | FileCheck %s --check-prefix=CHECK2 #ifdef MODULES @import DebugObjC; @@ -24,61 +25,65 @@ // CHECK: distinct !DICompileUnit(language: DW_LANG_ObjC // CHECK-SAME: isOptimized: false, + +// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, +// CHECK-SAME: scope: ![[MODULE:[0-9]+]], +// CHECK: ![[MODULE]] = !DIModule(scope: null, name:{{.*}}DebugObjC + +// CHECK: ![[TD_ENUM:.*]] = !DICompositeType(tag: DW_TAG_enumeration_type, +// CHECK-SAME-NOT: name: +// CHECK-SAME: elements: + // CHECK: !DICompositeType(tag: DW_TAG_structure_type, // CHECK-SAME: name: "FwdDecl", +// CHECK-SAME: scope: ![[MODULE]], // CHECK: !DICompositeType(tag: DW_TAG_structure_type, // CHECK-SAME: name: "ObjCClass", -// CHECK: !DIObjCProperty(name: "property", -// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "ivar" -// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "InnerEnum" -// CHECK: !DISubprogram(name: "+[ObjCClass classMethod]" -// CHECK: !DISubprogram(name: "-[ObjCClass instanceMethodWithInt:]" -// CHECK: !DISubprogram(name: "-[Category(Category) categoryMethod]" - -// MODULE-CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, -// MODULE-CHECK-SAME: scope: ![[MODULE:[0-9]+]], -// MODULE-CHECK: ![[MODULE]] = !DIModule(scope: null, name: "DebugObjC" - -// MODULE-CHECK: ![[TD_ENUM:.*]] = !DICompositeType(tag: DW_TAG_enumeration_type, -// MODULE-CHECK-SAME-NOT: name: -// MODULE-CHECK-SAME: elements: - -// MODULE-CHECK: !DICompositeType(tag: DW_TAG_structure_type, -// MODULE-CHECK-SAME: name: "FwdDecl", -// MODULE-CHECK-SAME: scope: ![[MODULE]], -// MODULE-CHECK: !DICompositeType(tag: DW_TAG_structure_type, -// MODULE-CHECK-SAME: name: "ObjCClass", -// MODULE-CHECK-SAME: scope: ![[MODULE]], - -// MODULE-CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "FwdDeclared" -// MODULE-CHECK-SAME: elements: - -// MODULE-CHECK: ![[TD_UNION:.*]] = !DICompositeType(tag: DW_TAG_union_type, -// MODULE-CHECK-SAME-NOT: name: -// MODULE-CHECK-SAME: elements: - -// MODULE-CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefUnion", -// MODULE-CHECK-SAME: baseType: ![[TD_UNION]]) - -// MODULE-CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefEnum", -// MODULE-CHECK-SAME: baseType: ![[TD_ENUM:.*]]) - -// MODULE-CHECK: ![[TD_STRUCT:.*]] = !DICompositeType(tag: DW_TAG_structure_type, -// MODULE-CHECK-SAME-NOT: name: -// MODULE-CHECK-SAME: elements: -// MODULE-CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefStruct", -// MODULE-CHECK-SAME: baseType: ![[TD_STRUCT]]) +// CHECK-SAME: scope: ![[MODULE]], + +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "FwdDeclared" +// CHECK-SAME: elements: + +// CHECK: ![[TD_UNION:.*]] = !DICompositeType(tag: DW_TAG_union_type, +// CHECK-SAME-NOT: name: +// CHECK-SAME: elements: + +// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefUnion", +// CHECK-SAME: baseType: ![[TD_UNION]]) -// MODULE-CHECK: !DICompositeType(tag: DW_TAG_union_type, -// MODULE-CHECK-SAME-NOT: name: +// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefEnum", +// CHECK-SAME: baseType: ![[TD_ENUM:.*]]) -// MODULE-CHECK: !DICompositeType(tag: DW_TAG_structure_type, -// MODULE-CHECK-SAME-NOT: name: +// CHECK: ![[TD_STRUCT:.*]] = !DICompositeType(tag: DW_TAG_structure_type, +// CHECK-SAME-NOT: name: +// CHECK-SAME: elements: +// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefStruct", +// CHECK-SAME: baseType: ![[TD_STRUCT]]) -// MODULE-CHECK: !DISubprogram(name: "+[ObjCClass classMethod]", -// MODULE-CHECK-SAME: scope: ![[MODULE]], +// CHECK: !DICompositeType(tag: DW_TAG_union_type, +// CHECK-SAME-NOT: name: + +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, +// CHECK-SAME-NOT: name: + +// CHECK: !DISubprogram(name: "+[ObjCClass classMethod]", +// CHECK-SAME: scope: ![[MODULE]], // The forward declaration should not be in the module scope. -// MODULE-CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "OpaqueData", file +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "OpaqueData", file + +// CHECK-NEG-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "PureForwardDecl" -// MODULE-CHECK-NEG-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "PureForwardDecl" +// The output order is sublty different for module vs. pch, +// so these are checked separately: +// +// CHECK2: !DICompositeType(tag: DW_TAG_structure_type, +// CHECK2-SAME: name: "FwdDecl", +// CHECK2: !DICompositeType(tag: DW_TAG_structure_type, +// CHECK2-SAME: name: "ObjCClass", +// CHECK2: !DIObjCProperty(name: "property", +// CHECK2: !DIDerivedType(tag: DW_TAG_member, name: "ivar" +// CHECK2: !DIDerivedType(tag: DW_TAG_typedef, name: "InnerEnum" +// CHECK2: !DISubprogram(name: "+[ObjCClass classMethod]" +// CHECK2: !DISubprogram(name: "-[ObjCClass instanceMethodWithInt:]" +// CHECK2: !DISubprogram(name: "-[Category(Category) categoryMethod]" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits