Skip to content

Commit 56309f6

Browse files
committed
Debug Info: Store the SDK in the DICompileUnit.
This an intermediate step for PR44213 (https://bugs.llvm.org/show_bug.cgi?id=44213). This stores the SDK *name* in the debug info, to make it possible to `-fdebug-prefix-map`-replace the sysroot with a recognizable string and allowing the debugger to find a fitting SDK relative to itself, not the machine the executable was compiled on. rdar://problem/51645582
1 parent f1ccb39 commit 56309f6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,15 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
16961696
DebugPrefixMap.remapPath(Opts.DebugCompilationDir));
16971697

16981698
StringRef Sysroot = IGM.Context.SearchPathOpts.SDKPath;
1699+
StringRef SDK;
1700+
{
1701+
auto B = llvm::sys::path::rbegin(Sysroot);
1702+
auto E = llvm::sys::path::rend(Sysroot);
1703+
auto It = std::find_if(B, E, [](auto SDK) { return SDK.endswith(".sdk"); });
1704+
if (It != E)
1705+
SDK = *It;
1706+
}
1707+
16991708
TheCU = DBuilder.createCompileUnit(
17001709
Lang, MainFile,
17011710
Producer, Opts.shouldOptimize(), Opts.getDebugFlags(PD),
@@ -1706,7 +1715,7 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
17061715
/* DWOId */ 0, /* SplitDebugInlining */ true,
17071716
/* DebugInfoForProfiling */ false,
17081717
llvm::DICompileUnit::DebugNameTableKind::Default,
1709-
/* RangesBaseAddress */ false, Sysroot);
1718+
/* RangesBaseAddress */ false, Sysroot, SDK);
17101719

17111720
// Because the swift compiler relies on Clang to setup the Module,
17121721
// the clang CU is always created first. Several dwarf-reading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -g -o - \
2+
// RUN: -sdk /SWIFT_SYSROOT/MacOSX.sdk | %FileCheck %s
3+
// Test that sysroot and SDK are stored in the debug info.
4+
// CHECK: distinct !DICompileUnit({{.*}}sysroot: "/SWIFT_SYSROOT/MacOSX.sdk",
5+
// LLDB-SAME: sdk: "MacOSX.sdk"

0 commit comments

Comments
 (0)