Module Debugging: Use the clang module signature as the module's dwo_id

when building a module. Clang already records the module signature when
building a skeleton CU to reference a clang module.

Matching the id in the skeleton with the one in the module allows a DWARF
consumer to verify that they found the correct version of the module
without them needing to know about the clang module format.

llvm-svn: 248345
This commit is contained in:
Adrian Prantl 2015-09-22 23:26:43 +00:00
parent adbd2b1f32
commit a5206ce72a
8 changed files with 27 additions and 8 deletions

View File

@ -30,8 +30,9 @@ class DiagnosticsEngine;
class CompilerInstance; class CompilerInstance;
struct PCHBuffer { struct PCHBuffer {
bool IsComplete; uint64_t Signature;
llvm::SmallVector<char, 0> Data; llvm::SmallVector<char, 0> Data;
bool IsComplete;
}; };
/// This abstract interface provides operations for creating /// This abstract interface provides operations for creating

View File

@ -3453,6 +3453,12 @@ CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl) {
return NS; return NS;
} }
void CGDebugInfo::setDwoId(uint64_t Signature) {
assert(TheCU && "no main compile unit");
TheCU->setDWOId(Signature);
}
void CGDebugInfo::finalize() { void CGDebugInfo::finalize() {
// Creating types might create further types - invalidating the current // Creating types might create further types - invalidating the current
// element and the size(), so don't cache/reference them. // element and the size(), so don't cache/reference them.

View File

@ -276,6 +276,9 @@ public:
void finalize(); void finalize();
/// Set the main CU's DwoId field to \p Signature.
void setDwoId(uint64_t Signature);
/// When generating debug information for a clang module or /// When generating debug information for a clang module or
/// precompiled header, this module map will be used to determine /// precompiled header, this module map will be used to determine
/// the module of origin of each Decl. /// the module of origin of each Decl.

View File

@ -142,7 +142,6 @@ public:
CodeGenOpts.ThreadModel = "single"; CodeGenOpts.ThreadModel = "single";
CodeGenOpts.DebugTypeExtRefs = true; CodeGenOpts.DebugTypeExtRefs = true;
CodeGenOpts.setDebugInfo(CodeGenOptions::FullDebugInfo); CodeGenOpts.setDebugInfo(CodeGenOptions::FullDebugInfo);
CodeGenOpts.SplitDwarfFile = OutputFileName;
} }
~PCHContainerGenerator() override = default; ~PCHContainerGenerator() override = default;
@ -201,6 +200,7 @@ public:
M->setTargetTriple(Ctx.getTargetInfo().getTriple().getTriple()); M->setTargetTriple(Ctx.getTargetInfo().getTriple().getTriple());
M->setDataLayout(Ctx.getTargetInfo().getDataLayoutString()); M->setDataLayout(Ctx.getTargetInfo().getDataLayoutString());
Builder->getModuleDebugInfo()->setDwoId(Buffer->Signature);
// Finalize the Builder. // Finalize the Builder.
if (Builder) if (Builder)

View File

@ -48,7 +48,8 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
// Emit the PCH file to the Buffer. // Emit the PCH file to the Buffer.
assert(SemaPtr && "No Sema?"); assert(SemaPtr && "No Sema?");
Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot, hasErrors); Buffer->Signature =
Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot, hasErrors);
Buffer->IsComplete = true; Buffer->IsComplete = true;
} }

View File

@ -6,10 +6,17 @@
@import diamond_left; @import diamond_left;
// CHECK: ![[TOP_DEF:.*]] = distinct !DICompileUnit({{.*}}diamond_top // Definition of top:
// CHECK: ![[LEFT_DEF:.*]] = distinct !DICompileUnit({{.*}}diamond_left // CHECK: !DICompileUnit({{.*}}dwoId:
// CHECK: !DIFile({{.*}}diamond_top.h
// Definition of left:
// CHECK: !DICompileUnit({{.*}}dwoId:
// CHECK: !DIFile({{.*}}diamond_left
// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, // CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration,
// CHECK-SAME: entity: ![[MODULE:.*]], line: 3) // CHECK-SAME: entity: ![[MODULE:.*]], line: 3)
// CHECK: ![[MODULE]] = !DIModule(scope: null, name: "diamond_top" // CHECK: ![[MODULE]] = !DIModule(scope: null, name: "diamond_top"
// CHECK: ![[TOP_SKEL_CU:.*]] = distinct !DICompileUnit({{.*}}diamond_top{{.*}}dwoId:
// Skeleton for top:
// CHECK: !DICompileUnit({{.*}}splitDebugFilename: {{.*}}diamond_top{{.*}}dwoId:

View File

@ -8,6 +8,7 @@
// RUN: %clang_cc1 -triple %itanium_abi_triple -x objective-c++ -std=c++11 -g -fmodules -fmodule-format=obj -fimplicit-module-maps -DMODULES -fmodules-cache-path=%t %s -I %S/Inputs -I %t -emit-llvm -o %t.ll -mllvm -debug-only=pchcontainer &>%t-mod.ll // RUN: %clang_cc1 -triple %itanium_abi_triple -x objective-c++ -std=c++11 -g -fmodules -fmodule-format=obj -fimplicit-module-maps -DMODULES -fmodules-cache-path=%t %s -I %S/Inputs -I %t -emit-llvm -o %t.ll -mllvm -debug-only=pchcontainer &>%t-mod.ll
// RUN: cat %t-mod.ll | FileCheck %s // RUN: cat %t-mod.ll | FileCheck %s
// RUN: cat %t-mod.ll | FileCheck --check-prefix=CHECK-NEG %s // RUN: cat %t-mod.ll | FileCheck --check-prefix=CHECK-NEG %s
// RUN: cat %t-mod.ll | FileCheck --check-prefix=CHECK-DWO %s
// PCH: // PCH:
// RUN: %clang_cc1 -triple %itanium_abi_triple -x c++ -std=c++11 -emit-pch -fmodule-format=obj -I %S/Inputs -o %t.pch %S/Inputs/DebugCXX.h -mllvm -debug-only=pchcontainer &>%t-pch.ll // RUN: %clang_cc1 -triple %itanium_abi_triple -x c++ -std=c++11 -emit-pch -fmodule-format=obj -I %S/Inputs -o %t.pch %S/Inputs/DebugCXX.h -mllvm -debug-only=pchcontainer &>%t-pch.ll
@ -20,7 +21,8 @@
// CHECK: distinct !DICompileUnit(language: DW_LANG_{{.*}}C_plus_plus, // CHECK: distinct !DICompileUnit(language: DW_LANG_{{.*}}C_plus_plus,
// CHECK-SAME: isOptimized: false, // CHECK-SAME: isOptimized: false,
// CHECK-SAME: splitDebugFilename: // CHECK-SAME-NOT: splitDebugFilename:
// CHECK-DWO: dwoId:
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum" // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum"
// CHECK-SAME: identifier: "_ZTSN8DebugCXX4EnumE") // CHECK-SAME: identifier: "_ZTSN8DebugCXX4EnumE")
// CHECK: !DINamespace(name: "DebugCXX" // CHECK: !DINamespace(name: "DebugCXX"

View File

@ -18,7 +18,6 @@
// CHECK: distinct !DICompileUnit(language: DW_LANG_ObjC // CHECK: distinct !DICompileUnit(language: DW_LANG_ObjC
// CHECK-SAME: isOptimized: false, // CHECK-SAME: isOptimized: false,
// CHECK-SAME: splitDebugFilename:
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClass" // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClass"
// CHECK: !DIObjCProperty(name: "property", // CHECK: !DIObjCProperty(name: "property",
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "ivar" // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "ivar"