From: Adrian Prantl Date: Fri, 22 Jan 2016 21:14:41 +0000 (+0000) Subject: Module debugging: Create a parent DIModule with the PCH name for types X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d97ae762ac6e2f11ed112b9b03eb26b5446531af;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258555 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index efacc35d14..675b5eb07c 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -2224,8 +2224,12 @@ llvm::DIModule *CGDebugInfo::getParentModuleOrNull(const Decl *D) { // 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); } } diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index a68dd33fa5..55d813834e 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -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); diff --git a/lib/CodeGen/ObjectFilePCHContainerOperations.cpp b/lib/CodeGen/ObjectFilePCHContainerOperations.cpp index 0e3aa61314..406b433c95 100644 --- a/lib/CodeGen/ObjectFilePCHContainerOperations.cpp +++ b/lib/CodeGen/ObjectFilePCHContainerOperations.cpp @@ -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 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 { diff --git a/test/Modules/ModuleDebugInfo.m b/test/Modules/ModuleDebugInfo.m index cba4063b1d..3d6c6657c9 100644 --- a/test/Modules/ModuleDebugInfo.m +++ b/test/Modules/ModuleDebugInfo.m @@ -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" +// CHECK-SAME: scope: ![[MODULE]], -// MODULE-CHECK: ![[TD_ENUM:.*]] = !DICompositeType(tag: DW_TAG_enumeration_type, -// MODULE-CHECK-SAME-NOT: name: -// MODULE-CHECK-SAME: elements: +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "FwdDeclared" +// 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]], +// CHECK: ![[TD_UNION:.*]] = !DICompositeType(tag: DW_TAG_union_type, +// CHECK-SAME-NOT: name: +// CHECK-SAME: elements: -// MODULE-CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "FwdDeclared" -// MODULE-CHECK-SAME: elements: +// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefUnion", +// CHECK-SAME: baseType: ![[TD_UNION]]) -// MODULE-CHECK: ![[TD_UNION:.*]] = !DICompositeType(tag: DW_TAG_union_type, -// MODULE-CHECK-SAME-NOT: name: -// MODULE-CHECK-SAME: elements: +// CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefEnum", +// CHECK-SAME: baseType: ![[TD_ENUM:.*]]) -// MODULE-CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefUnion", -// MODULE-CHECK-SAME: baseType: ![[TD_UNION]]) +// 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: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefEnum", -// MODULE-CHECK-SAME: baseType: ![[TD_ENUM:.*]]) +// CHECK: !DICompositeType(tag: DW_TAG_union_type, +// CHECK-SAME-NOT: name: -// 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]]) - -// MODULE-CHECK: !DICompositeType(tag: DW_TAG_union_type, -// MODULE-CHECK-SAME-NOT: name: - -// MODULE-CHECK: !DICompositeType(tag: DW_TAG_structure_type, -// MODULE-CHECK-SAME-NOT: name: +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, +// CHECK-SAME-NOT: name: -// MODULE-CHECK: !DISubprogram(name: "+[ObjCClass classMethod]", -// MODULE-CHECK-SAME: scope: ![[MODULE]], +// 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 - -// MODULE-CHECK-NEG-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "PureForwardDecl" +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "OpaqueData", file + +// 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]"