Skip to content

Commit bc57d3d

Browse files
Merge pull request #21709 from adrian-prantl/breadcrumbs
Leave skeleton CU breadcrumbs fo imported Clang modules in the debug …
2 parents 6cbad06 + 10004ed commit bc57d3d

File tree

5 files changed

+61
-16
lines changed

5 files changed

+61
-16
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
7272
const IRGenOptions &Opts;
7373
ClangImporter &CI;
7474
SourceManager &SM;
75+
llvm::Module &M;
7576
llvm::DIBuilder DBuilder;
7677
IRGenModule &IGM;
7778
const PathRemapper &DebugPrefixMap;
@@ -559,36 +560,55 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
559560

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

570+
// For Clang modules / PCH, create a Skeleton CU pointing to the PCM/PCH.
571+
bool CreateSkeletonCU = !ASTFile.empty();
572+
bool IsRootModule = !Parent;
573+
if (CreateSkeletonCU && IsRootModule) {
574+
llvm::DIBuilder DIB(M);
575+
DIB.createCompileUnit(IGM.ObjCInterop ? llvm::dwarf::DW_LANG_ObjC
576+
: llvm::dwarf::DW_LANG_C99,
577+
DIB.createFile(Name, IncludePath),
578+
TheCU->getProducer(), true, StringRef(), 0, ASTFile,
579+
llvm::DICompileUnit::FullDebug, Signature);
580+
DIB.finalize();
581+
}
582+
568583
StringRef Sysroot = IGM.Context.SearchPathOpts.SDKPath;
569-
auto M = DBuilder.createModule(
570-
Parent, Name, ConfigMacros, DebugPrefixMap.remapPath(IncludePath),
571-
Sysroot);
584+
auto M =
585+
DBuilder.createModule(Parent, Name, ConfigMacros, IncludePath, Sysroot);
572586
DIModuleCache.insert({Key, llvm::TrackingMDNodeRef(M)});
573587
return M;
574588
}
575589

576590
llvm::DIModule *
577591
getOrCreateModule(clang::ExternalASTSource::ASTSourceDescriptor Desc) {
592+
// PCH files don't have a signature field in the control block,
593+
// but LLVM detects skeleton CUs by looking for a non-zero DWO id.
594+
// We use the lower 64 bits for debug info.
595+
uint64_t Signature =
596+
Desc.getSignature()
597+
? (uint64_t)Desc.getSignature()[1] << 32 | Desc.getSignature()[0]
598+
: ~1ULL;
599+
578600
// Handle Clang modules.
579601
if (const clang::Module *ClangModule = Desc.getModuleOrNull()) {
580602
llvm::DIModule *Parent = nullptr;
581603
if (ClangModule->Parent)
582604
Parent = getOrCreateModule(*ClangModule->Parent);
583-
584-
return getOrCreateModule(ClangModule, Parent,
585-
Desc.getModuleName(), Desc.getPath(),
586-
ConfigMacros);
605+
return getOrCreateModule(ClangModule, Parent, Desc.getModuleName(),
606+
Desc.getPath(), Signature, Desc.getASTFile());
587607
}
588608
// Handle PCH.
589609
return getOrCreateModule(Desc.getASTFile().bytes_begin(), nullptr,
590-
Desc.getModuleName(), Desc.getPath(),
591-
ConfigMacros);
610+
Desc.getModuleName(), Desc.getPath(), Signature,
611+
Desc.getASTFile());
592612
};
593613

594614
llvm::DIModule *getOrCreateModule(ModuleDecl::ImportedModule IM) {
@@ -1480,7 +1500,7 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
14801500
ClangImporter &CI, IRGenModule &IGM,
14811501
llvm::Module &M,
14821502
StringRef MainOutputFilenameForDebugInfo)
1483-
: Opts(Opts), CI(CI), SM(IGM.Context.SourceMgr), DBuilder(M),
1503+
: Opts(Opts), CI(CI), SM(IGM.Context.SourceMgr), M(M), DBuilder(M),
14841504
IGM(IGM), DebugPrefixMap(Opts.DebugPrefixMap), MetadataTypeDecl(nullptr),
14851505
InternalType(nullptr), LastDebugLoc({}), LastScope(nullptr) {
14861506
assert(Opts.DebugInfoLevel > IRGenDebugInfoLevel::None &&

test/DebugInfo/ASTSection_ObjC.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// REQUIRES: executable_test
2+
// REQUIRES: objc_interop
3+
14
// RUN: %empty-directory(%t)
25

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

13-
// REQUIRES: executable_test
14-
// REQUIRES: objc_interop
15-
1616
// CHECK: - Target: {{.+}}-{{.+}}-{{.+}}
1717
// CHECK: Importing ASTSection... ok!
1818

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend \
2+
// RUN: -emit-pch %S/Inputs/InlineBridgingHeader.h -o %t.pch
3+
// RUN: %target-swift-frontend \
4+
// RUN: -import-objc-header %t.pch -emit-ir -g %s -o - | %FileCheck %s
5+
6+
// CHECK: !DICompileUnit(language: DW_LANG_Swift
7+
// CHECK: !DICompileUnit(language: DW_LANG_{{ObjC|C99}},
8+
// CHECK: !DICompileUnit(language: DW_LANG_{{ObjC|C99}},
9+
// CHECK-SAME: splitDebugFilename: "{{.*}}.pch"
10+
// CHECK-SAME: dwoId:
11+
12+
Foo()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend -emit-ir %s -g -I %S/Inputs \
2+
// RUN: -Xcc -DFOO="foo" -Xcc -UBAR -o - | %FileCheck %s
3+
import ClangModule.SubModule
4+
import OtherClangModule.SubModule
5+
6+
// Check for Clang module breadcrumbs.
7+
// CHECK: !DICompileUnit(language: DW_LANG_{{ObjC|C99}},{{.*}} producer: "{{.*}}Swift
8+
// CHECK-SAME: ClangModule
9+
// CHECK-SAME: dwoId:
10+
11+
// CHECK: !DICompileUnit(language: DW_LANG_{{ObjC|C99}}, {{.*}} producer: "{{.*}}Swift
12+
// CHECK-SAME: OtherClangModule
13+
// CHECK-SAME: dwoId:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// RUN: %target-swift-frontend \
22
// RUN: -import-objc-header %S/Inputs/InlineBridgingHeader.h \
33
// RUN: -emit-ir -g %s -o - | %FileCheck %s
4-
// REQUIRES: objc_interop
54

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

1212
Foo()

0 commit comments

Comments
 (0)