Skip to content

Leave skeleton CU breadcrumbs fo imported Clang modules in the debug … #21709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
const IRGenOptions &Opts;
ClangImporter &CI;
SourceManager &SM;
llvm::Module &M;
llvm::DIBuilder DBuilder;
IRGenModule &IGM;
const PathRemapper &DebugPrefixMap;
Expand Down Expand Up @@ -559,36 +560,55 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {

llvm::DIModule *getOrCreateModule(const void *Key, llvm::DIScope *Parent,
StringRef Name, StringRef IncludePath,
StringRef ConfigMacros = StringRef()) {
uint64_t Signature = ~1ULL,
StringRef ASTFile = StringRef()) {
// Look in the cache first.
auto Val = DIModuleCache.find(Key);
if (Val != DIModuleCache.end())
return cast<llvm::DIModule>(Val->second);

// For Clang modules / PCH, create a Skeleton CU pointing to the PCM/PCH.
bool CreateSkeletonCU = !ASTFile.empty();
bool IsRootModule = !Parent;
if (CreateSkeletonCU && IsRootModule) {
llvm::DIBuilder DIB(M);
DIB.createCompileUnit(IGM.ObjCInterop ? llvm::dwarf::DW_LANG_ObjC
: llvm::dwarf::DW_LANG_C99,
DIB.createFile(Name, IncludePath),
TheCU->getProducer(), true, StringRef(), 0, ASTFile,
llvm::DICompileUnit::FullDebug, Signature);
DIB.finalize();
}

StringRef Sysroot = IGM.Context.SearchPathOpts.SDKPath;
auto M = DBuilder.createModule(
Parent, Name, ConfigMacros, DebugPrefixMap.remapPath(IncludePath),
Sysroot);
auto M =
DBuilder.createModule(Parent, Name, ConfigMacros, IncludePath, Sysroot);
DIModuleCache.insert({Key, llvm::TrackingMDNodeRef(M)});
return M;
}

llvm::DIModule *
getOrCreateModule(clang::ExternalASTSource::ASTSourceDescriptor Desc) {
// PCH files don't have a signature field in the control block,
// but LLVM detects skeleton CUs by looking for a non-zero DWO id.
// We use the lower 64 bits for debug info.
uint64_t Signature =
Desc.getSignature()
? (uint64_t)Desc.getSignature()[1] << 32 | Desc.getSignature()[0]
: ~1ULL;

// Handle Clang modules.
if (const clang::Module *ClangModule = Desc.getModuleOrNull()) {
llvm::DIModule *Parent = nullptr;
if (ClangModule->Parent)
Parent = getOrCreateModule(*ClangModule->Parent);

return getOrCreateModule(ClangModule, Parent,
Desc.getModuleName(), Desc.getPath(),
ConfigMacros);
return getOrCreateModule(ClangModule, Parent, Desc.getModuleName(),
Desc.getPath(), Signature, Desc.getASTFile());
}
// Handle PCH.
return getOrCreateModule(Desc.getASTFile().bytes_begin(), nullptr,
Desc.getModuleName(), Desc.getPath(),
ConfigMacros);
Desc.getModuleName(), Desc.getPath(), Signature,
Desc.getASTFile());
};

llvm::DIModule *getOrCreateModule(ModuleDecl::ImportedModule IM) {
Expand Down Expand Up @@ -1480,7 +1500,7 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
ClangImporter &CI, IRGenModule &IGM,
llvm::Module &M,
StringRef MainOutputFilenameForDebugInfo)
: Opts(Opts), CI(CI), SM(IGM.Context.SourceMgr), DBuilder(M),
: Opts(Opts), CI(CI), SM(IGM.Context.SourceMgr), M(M), DBuilder(M),
IGM(IGM), DebugPrefixMap(Opts.DebugPrefixMap), MetadataTypeDecl(nullptr),
InternalType(nullptr), LastDebugLoc({}), LastScope(nullptr) {
assert(Opts.DebugInfoLevel > IRGenDebugInfoLevel::None &&
Expand Down
6 changes: 3 additions & 3 deletions test/DebugInfo/ASTSection_ObjC.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// REQUIRES: executable_test
// REQUIRES: objc_interop

// RUN: %empty-directory(%t)

// RUN: cp %S/Inputs/serialized-objc-header.h %t
Expand All @@ -10,9 +13,6 @@
// RUN: %target-build-swift -emit-executable %S/ASTSection.swift -gline-tables-only -o %t/ASTSection -emit-module
// RUN: %lldb-moduleimport-test -verbose %t/ASTSection | %FileCheck %s --allow-empty --check-prefix=LINETABLE-CHECK

// REQUIRES: executable_test
// REQUIRES: objc_interop

// CHECK: - Target: {{.+}}-{{.+}}-{{.+}}
// CHECK: Importing ASTSection... ok!

Expand Down
12 changes: 12 additions & 0 deletions test/DebugInfo/BridgingHeaderPCH.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %target-swift-frontend \
// RUN: -emit-pch %S/Inputs/InlineBridgingHeader.h -o %t.pch
// RUN: %target-swift-frontend \
// RUN: -import-objc-header %t.pch -emit-ir -g %s -o - | %FileCheck %s

// CHECK: !DICompileUnit(language: DW_LANG_Swift
// CHECK: !DICompileUnit(language: DW_LANG_{{ObjC|C99}},
// CHECK: !DICompileUnit(language: DW_LANG_{{ObjC|C99}},
// CHECK-SAME: splitDebugFilename: "{{.*}}.pch"
// CHECK-SAME: dwoId:

Foo()
13 changes: 13 additions & 0 deletions test/DebugInfo/ClangModuleBreadcrumbs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %target-swift-frontend -emit-ir %s -g -I %S/Inputs \
// RUN: -Xcc -DFOO="foo" -Xcc -UBAR -o - | %FileCheck %s
import ClangModule.SubModule
import OtherClangModule.SubModule

// Check for Clang module breadcrumbs.
// CHECK: !DICompileUnit(language: DW_LANG_{{ObjC|C99}},{{.*}} producer: "{{.*}}Swift
// CHECK-SAME: ClangModule
// CHECK-SAME: dwoId:

// CHECK: !DICompileUnit(language: DW_LANG_{{ObjC|C99}}, {{.*}} producer: "{{.*}}Swift
// CHECK-SAME: OtherClangModule
// CHECK-SAME: dwoId:
4 changes: 2 additions & 2 deletions test/DebugInfo/InlineBridgingHeader.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// RUN: %target-swift-frontend \
// RUN: -import-objc-header %S/Inputs/InlineBridgingHeader.h \
// RUN: -emit-ir -g %s -o - | %FileCheck %s
// REQUIRES: objc_interop

// The Swift CU must come first.
// CHECK: !llvm.dbg.cu = !{![[SWIFT_CU:[0-9]+]], ![[CLANG_CU:[0-9]+]]}
// CHECK: ![[SWIFT_CU]] = distinct !DICompileUnit(language: DW_LANG_Swift
// CHECK: ![[CLANG_CU]] = distinct !DICompileUnit(language: DW_LANG_ObjC
// CHECK: ![[CLANG_CU]] = distinct !DICompileUnit(
// CHECK-SAME: language: {{DW_LANG_ObjC|DW_LANG_C}}
// CHECK: DISubprogram(name: "Foo"{{.*}} unit: ![[CLANG_CU]],

Foo()