Conversation
|
@llvm/pr-subscribers-lldb @llvm/pr-subscribers-debuginfo Author: Keith Smiley (keith) ChangesThis enables excluding the absolute path to the sysroot from debug info This was also possible using Assisted by: claude Full diff: https://github.com/llvm/llvm-project/pull/192541.diff 6 Files Affected:
diff --git a/clang/include/clang/Basic/DebugOptions.def b/clang/include/clang/Basic/DebugOptions.def
index 604e87e615a69..c9dd3f726e799 100644
--- a/clang/include/clang/Basic/DebugOptions.def
+++ b/clang/include/clang/Basic/DebugOptions.def
@@ -125,6 +125,9 @@ DEBUGOPT(CodeViewCommandLine, 1, 0, Compatible)
/// Whether emit extra debug info for sample pgo profile collection.
DEBUGOPT(DebugInfoForProfiling, 1, 0, Compatible)
+/// Whether to record the sysroot path or scrub it from debug info.
+DEBUGOPT(DebugRecordSysroot, 1, 1, Compatible)
+
/// Whether to emit DW_TAG_template_alias for template aliases.
DEBUGOPT(DebugTemplateAlias, 1, 0, Compatible)
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 5673fb0c47d5b..0afbb6f1d0b37 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -1823,6 +1823,13 @@ defm debug_info_for_profiling : BoolFOption<"debug-info-for-profiling",
PosFlag<SetTrue, [], [ClangOption, CC1Option, FlangOption, FC1Option],
"Emit extra debug info to make sample profile more accurate">,
NegFlag<SetFalse, [], [ClangOption, FlangOption]>>;
+defm debug_record_sysroot : BoolFOption<"debug-record-sysroot",
+ CodeGenOpts<"DebugRecordSysroot">, DefaultTrue,
+ PosFlag<SetTrue, [], [ClangOption, CC1Option],
+ "Record the sysroot path in debug info as DW_AT_LLVM_sysroot and in DW_AT_LLVM_include_path "
+ "(used by LLDB to locate the SDK for Clang module imports).">,
+ NegFlag<SetFalse, [], [ClangOption, CC1Option],
+ "Scrub the sysroot path from debug info.">>;
def fprofile_generate_cold_function_coverage : Flag<["-"], "fprofile-generate-cold-function-coverage">,
Group<f_Group>, Visibility<[ClangOption, CLOption]>,
HelpText<"Generate instrumented code to collect coverage info for cold functions into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index c5a92a8e7ceb0..253cb03230b48 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -852,9 +852,11 @@ void CGDebugInfo::CreateCompileUnit() {
StringRef Sysroot, SDK;
if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB) {
- Sysroot = CGM.getHeaderSearchOpts().Sysroot;
- auto B = llvm::sys::path::rbegin(Sysroot);
- auto E = llvm::sys::path::rend(Sysroot);
+ StringRef FullSysroot = CGM.getHeaderSearchOpts().Sysroot;
+ if (CGM.getCodeGenOpts().DebugRecordSysroot)
+ Sysroot = FullSysroot;
+ auto B = llvm::sys::path::rbegin(FullSysroot);
+ auto E = llvm::sys::path::rend(FullSysroot);
auto It =
std::find_if(B, E, [](auto SDK) { return SDK.ends_with(".sdk"); });
if (It != E)
@@ -3529,7 +3531,12 @@ llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
IsRootModule ? nullptr
: getOrCreateModuleRef(ASTSourceDescriptor(*M->Parent),
CreateSkeletonCU);
- std::string IncludePath = Mod.getPath().str();
+ StringRef IncludePath = Mod.getPath();
+ if (!CGM.getCodeGenOpts().DebugRecordSysroot) {
+ StringRef Sysroot = CGM.getHeaderSearchOpts().Sysroot;
+ if (!Sysroot.empty() && IncludePath.starts_with(Sysroot))
+ IncludePath = "";
+ }
llvm::DIModule *DIMod =
DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros,
RemapPath(IncludePath));
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 267e674441599..ecd5bf5a31fce 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4460,6 +4460,10 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T,
addDebugInfoForProfilingArgs(D, TC, Args, CmdArgs);
+ if (!Args.hasFlag(options::OPT_fdebug_record_sysroot,
+ options::OPT_fno_debug_record_sysroot, true))
+ CmdArgs.push_back("-fno-debug-record-sysroot");
+
// The 'g' groups options involve a somewhat intricate sequence of decisions
// about what to pass from the driver to the frontend, but by the time they
// reach cc1 they've been factored into three well-defined orthogonal choices:
diff --git a/clang/test/DebugInfo/Generic/sysroot-sdk.c b/clang/test/DebugInfo/Generic/sysroot-sdk.c
index b52d2e1de9c1d..b424e62f5d3b0 100644
--- a/clang/test/DebugInfo/Generic/sysroot-sdk.c
+++ b/clang/test/DebugInfo/Generic/sysroot-sdk.c
@@ -4,6 +4,10 @@
// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
// RUN: %s -isysroot /CLANG_SYSROOT/MacOSX.sdk -emit-llvm -o - \
// RUN: -debugger-tuning=gdb | FileCheck %s --check-prefix=GDB
+// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
+// RUN: %s -isysroot /CLANG_SYSROOT/MacOSX.sdk -emit-llvm -o - \
+// RUN: -debugger-tuning=lldb -fno-debug-record-sysroot \
+// RUN: | FileCheck %s --check-prefix=NOSYSROOT
void foo(void) {}
@@ -14,3 +18,8 @@ void foo(void) {}
// GDB: distinct !DICompileUnit(
// GDB-NOT: sysroot: "/CLANG_SYSROOT/MacOSX.sdk"
// GDB-NOT: sdk: "MacOSX.sdk"
+
+// -fno-debug-record-sysroot suppresses the sysroot path but keeps the SDK marker.
+// NOSYSROOT: distinct !DICompileUnit(
+// NOSYSROOT-NOT: sysroot: "/CLANG_SYSROOT/MacOSX.sdk"
+// NOSYSROOT-SAME: sdk: "MacOSX.sdk"
diff --git a/clang/test/Modules/debug-info-moduleimport.m b/clang/test/Modules/debug-info-moduleimport.m
index bdeb05bc08a02..b242364e7100e 100644
--- a/clang/test/Modules/debug-info-moduleimport.m
+++ b/clang/test/Modules/debug-info-moduleimport.m
@@ -44,3 +44,16 @@
// SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[DWOFILE:[0-9]+]]{{.*}}splitDebugFilename: "/MODULE-CACHE{{.*}}dwoId
// SKEL-CHECK: ![[DWOFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR]]"
+
+// With -fno-debug-record-sysroot and a sysroot that covers the module's
+// include path (%S contains %S/Inputs), the DICompileUnit has no sysroot
+// field and the DIModule has no includePath field.
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
+// RUN: -fmodules-cache-path=%t/cache %s -I %S/Inputs -isysroot %S -I %t \
+// RUN: -emit-llvm -debugger-tuning=lldb -fno-debug-record-sysroot -o - \
+// RUN: | FileCheck %s --check-prefix=NO-SYSROOT
+
+// NO-SYSROOT-NOT: sysroot:
+// NO-SYSROOT-NOT: includePath:
+// NO-SYSROOT: !DIModule(scope: null, name: "DebugObjC")
|
|
@llvm/pr-subscribers-clang-driver Author: Keith Smiley (keith) ChangesThis enables excluding the absolute path to the sysroot from debug info This was also possible using Assisted by: claude Full diff: https://github.com/llvm/llvm-project/pull/192541.diff 6 Files Affected:
diff --git a/clang/include/clang/Basic/DebugOptions.def b/clang/include/clang/Basic/DebugOptions.def
index 604e87e615a69..c9dd3f726e799 100644
--- a/clang/include/clang/Basic/DebugOptions.def
+++ b/clang/include/clang/Basic/DebugOptions.def
@@ -125,6 +125,9 @@ DEBUGOPT(CodeViewCommandLine, 1, 0, Compatible)
/// Whether emit extra debug info for sample pgo profile collection.
DEBUGOPT(DebugInfoForProfiling, 1, 0, Compatible)
+/// Whether to record the sysroot path or scrub it from debug info.
+DEBUGOPT(DebugRecordSysroot, 1, 1, Compatible)
+
/// Whether to emit DW_TAG_template_alias for template aliases.
DEBUGOPT(DebugTemplateAlias, 1, 0, Compatible)
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 5673fb0c47d5b..0afbb6f1d0b37 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -1823,6 +1823,13 @@ defm debug_info_for_profiling : BoolFOption<"debug-info-for-profiling",
PosFlag<SetTrue, [], [ClangOption, CC1Option, FlangOption, FC1Option],
"Emit extra debug info to make sample profile more accurate">,
NegFlag<SetFalse, [], [ClangOption, FlangOption]>>;
+defm debug_record_sysroot : BoolFOption<"debug-record-sysroot",
+ CodeGenOpts<"DebugRecordSysroot">, DefaultTrue,
+ PosFlag<SetTrue, [], [ClangOption, CC1Option],
+ "Record the sysroot path in debug info as DW_AT_LLVM_sysroot and in DW_AT_LLVM_include_path "
+ "(used by LLDB to locate the SDK for Clang module imports).">,
+ NegFlag<SetFalse, [], [ClangOption, CC1Option],
+ "Scrub the sysroot path from debug info.">>;
def fprofile_generate_cold_function_coverage : Flag<["-"], "fprofile-generate-cold-function-coverage">,
Group<f_Group>, Visibility<[ClangOption, CLOption]>,
HelpText<"Generate instrumented code to collect coverage info for cold functions into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index c5a92a8e7ceb0..253cb03230b48 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -852,9 +852,11 @@ void CGDebugInfo::CreateCompileUnit() {
StringRef Sysroot, SDK;
if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB) {
- Sysroot = CGM.getHeaderSearchOpts().Sysroot;
- auto B = llvm::sys::path::rbegin(Sysroot);
- auto E = llvm::sys::path::rend(Sysroot);
+ StringRef FullSysroot = CGM.getHeaderSearchOpts().Sysroot;
+ if (CGM.getCodeGenOpts().DebugRecordSysroot)
+ Sysroot = FullSysroot;
+ auto B = llvm::sys::path::rbegin(FullSysroot);
+ auto E = llvm::sys::path::rend(FullSysroot);
auto It =
std::find_if(B, E, [](auto SDK) { return SDK.ends_with(".sdk"); });
if (It != E)
@@ -3529,7 +3531,12 @@ llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
IsRootModule ? nullptr
: getOrCreateModuleRef(ASTSourceDescriptor(*M->Parent),
CreateSkeletonCU);
- std::string IncludePath = Mod.getPath().str();
+ StringRef IncludePath = Mod.getPath();
+ if (!CGM.getCodeGenOpts().DebugRecordSysroot) {
+ StringRef Sysroot = CGM.getHeaderSearchOpts().Sysroot;
+ if (!Sysroot.empty() && IncludePath.starts_with(Sysroot))
+ IncludePath = "";
+ }
llvm::DIModule *DIMod =
DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros,
RemapPath(IncludePath));
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 267e674441599..ecd5bf5a31fce 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4460,6 +4460,10 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T,
addDebugInfoForProfilingArgs(D, TC, Args, CmdArgs);
+ if (!Args.hasFlag(options::OPT_fdebug_record_sysroot,
+ options::OPT_fno_debug_record_sysroot, true))
+ CmdArgs.push_back("-fno-debug-record-sysroot");
+
// The 'g' groups options involve a somewhat intricate sequence of decisions
// about what to pass from the driver to the frontend, but by the time they
// reach cc1 they've been factored into three well-defined orthogonal choices:
diff --git a/clang/test/DebugInfo/Generic/sysroot-sdk.c b/clang/test/DebugInfo/Generic/sysroot-sdk.c
index b52d2e1de9c1d..b424e62f5d3b0 100644
--- a/clang/test/DebugInfo/Generic/sysroot-sdk.c
+++ b/clang/test/DebugInfo/Generic/sysroot-sdk.c
@@ -4,6 +4,10 @@
// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
// RUN: %s -isysroot /CLANG_SYSROOT/MacOSX.sdk -emit-llvm -o - \
// RUN: -debugger-tuning=gdb | FileCheck %s --check-prefix=GDB
+// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
+// RUN: %s -isysroot /CLANG_SYSROOT/MacOSX.sdk -emit-llvm -o - \
+// RUN: -debugger-tuning=lldb -fno-debug-record-sysroot \
+// RUN: | FileCheck %s --check-prefix=NOSYSROOT
void foo(void) {}
@@ -14,3 +18,8 @@ void foo(void) {}
// GDB: distinct !DICompileUnit(
// GDB-NOT: sysroot: "/CLANG_SYSROOT/MacOSX.sdk"
// GDB-NOT: sdk: "MacOSX.sdk"
+
+// -fno-debug-record-sysroot suppresses the sysroot path but keeps the SDK marker.
+// NOSYSROOT: distinct !DICompileUnit(
+// NOSYSROOT-NOT: sysroot: "/CLANG_SYSROOT/MacOSX.sdk"
+// NOSYSROOT-SAME: sdk: "MacOSX.sdk"
diff --git a/clang/test/Modules/debug-info-moduleimport.m b/clang/test/Modules/debug-info-moduleimport.m
index bdeb05bc08a02..b242364e7100e 100644
--- a/clang/test/Modules/debug-info-moduleimport.m
+++ b/clang/test/Modules/debug-info-moduleimport.m
@@ -44,3 +44,16 @@
// SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[DWOFILE:[0-9]+]]{{.*}}splitDebugFilename: "/MODULE-CACHE{{.*}}dwoId
// SKEL-CHECK: ![[DWOFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR]]"
+
+// With -fno-debug-record-sysroot and a sysroot that covers the module's
+// include path (%S contains %S/Inputs), the DICompileUnit has no sysroot
+// field and the DIModule has no includePath field.
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
+// RUN: -fmodules-cache-path=%t/cache %s -I %S/Inputs -isysroot %S -I %t \
+// RUN: -emit-llvm -debugger-tuning=lldb -fno-debug-record-sysroot -o - \
+// RUN: | FileCheck %s --check-prefix=NO-SYSROOT
+
+// NO-SYSROOT-NOT: sysroot:
+// NO-SYSROOT-NOT: includePath:
+// NO-SYSROOT: !DIModule(scope: null, name: "DebugObjC")
|
|
@llvm/pr-subscribers-clang Author: Keith Smiley (keith) ChangesThis enables excluding the absolute path to the sysroot from debug info This was also possible using Assisted by: claude Full diff: https://github.com/llvm/llvm-project/pull/192541.diff 6 Files Affected:
diff --git a/clang/include/clang/Basic/DebugOptions.def b/clang/include/clang/Basic/DebugOptions.def
index 604e87e615a69..c9dd3f726e799 100644
--- a/clang/include/clang/Basic/DebugOptions.def
+++ b/clang/include/clang/Basic/DebugOptions.def
@@ -125,6 +125,9 @@ DEBUGOPT(CodeViewCommandLine, 1, 0, Compatible)
/// Whether emit extra debug info for sample pgo profile collection.
DEBUGOPT(DebugInfoForProfiling, 1, 0, Compatible)
+/// Whether to record the sysroot path or scrub it from debug info.
+DEBUGOPT(DebugRecordSysroot, 1, 1, Compatible)
+
/// Whether to emit DW_TAG_template_alias for template aliases.
DEBUGOPT(DebugTemplateAlias, 1, 0, Compatible)
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 5673fb0c47d5b..0afbb6f1d0b37 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -1823,6 +1823,13 @@ defm debug_info_for_profiling : BoolFOption<"debug-info-for-profiling",
PosFlag<SetTrue, [], [ClangOption, CC1Option, FlangOption, FC1Option],
"Emit extra debug info to make sample profile more accurate">,
NegFlag<SetFalse, [], [ClangOption, FlangOption]>>;
+defm debug_record_sysroot : BoolFOption<"debug-record-sysroot",
+ CodeGenOpts<"DebugRecordSysroot">, DefaultTrue,
+ PosFlag<SetTrue, [], [ClangOption, CC1Option],
+ "Record the sysroot path in debug info as DW_AT_LLVM_sysroot and in DW_AT_LLVM_include_path "
+ "(used by LLDB to locate the SDK for Clang module imports).">,
+ NegFlag<SetFalse, [], [ClangOption, CC1Option],
+ "Scrub the sysroot path from debug info.">>;
def fprofile_generate_cold_function_coverage : Flag<["-"], "fprofile-generate-cold-function-coverage">,
Group<f_Group>, Visibility<[ClangOption, CLOption]>,
HelpText<"Generate instrumented code to collect coverage info for cold functions into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index c5a92a8e7ceb0..253cb03230b48 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -852,9 +852,11 @@ void CGDebugInfo::CreateCompileUnit() {
StringRef Sysroot, SDK;
if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB) {
- Sysroot = CGM.getHeaderSearchOpts().Sysroot;
- auto B = llvm::sys::path::rbegin(Sysroot);
- auto E = llvm::sys::path::rend(Sysroot);
+ StringRef FullSysroot = CGM.getHeaderSearchOpts().Sysroot;
+ if (CGM.getCodeGenOpts().DebugRecordSysroot)
+ Sysroot = FullSysroot;
+ auto B = llvm::sys::path::rbegin(FullSysroot);
+ auto E = llvm::sys::path::rend(FullSysroot);
auto It =
std::find_if(B, E, [](auto SDK) { return SDK.ends_with(".sdk"); });
if (It != E)
@@ -3529,7 +3531,12 @@ llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
IsRootModule ? nullptr
: getOrCreateModuleRef(ASTSourceDescriptor(*M->Parent),
CreateSkeletonCU);
- std::string IncludePath = Mod.getPath().str();
+ StringRef IncludePath = Mod.getPath();
+ if (!CGM.getCodeGenOpts().DebugRecordSysroot) {
+ StringRef Sysroot = CGM.getHeaderSearchOpts().Sysroot;
+ if (!Sysroot.empty() && IncludePath.starts_with(Sysroot))
+ IncludePath = "";
+ }
llvm::DIModule *DIMod =
DBuilder.createModule(Parent, Mod.getModuleName(), ConfigMacros,
RemapPath(IncludePath));
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 267e674441599..ecd5bf5a31fce 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4460,6 +4460,10 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T,
addDebugInfoForProfilingArgs(D, TC, Args, CmdArgs);
+ if (!Args.hasFlag(options::OPT_fdebug_record_sysroot,
+ options::OPT_fno_debug_record_sysroot, true))
+ CmdArgs.push_back("-fno-debug-record-sysroot");
+
// The 'g' groups options involve a somewhat intricate sequence of decisions
// about what to pass from the driver to the frontend, but by the time they
// reach cc1 they've been factored into three well-defined orthogonal choices:
diff --git a/clang/test/DebugInfo/Generic/sysroot-sdk.c b/clang/test/DebugInfo/Generic/sysroot-sdk.c
index b52d2e1de9c1d..b424e62f5d3b0 100644
--- a/clang/test/DebugInfo/Generic/sysroot-sdk.c
+++ b/clang/test/DebugInfo/Generic/sysroot-sdk.c
@@ -4,6 +4,10 @@
// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
// RUN: %s -isysroot /CLANG_SYSROOT/MacOSX.sdk -emit-llvm -o - \
// RUN: -debugger-tuning=gdb | FileCheck %s --check-prefix=GDB
+// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
+// RUN: %s -isysroot /CLANG_SYSROOT/MacOSX.sdk -emit-llvm -o - \
+// RUN: -debugger-tuning=lldb -fno-debug-record-sysroot \
+// RUN: | FileCheck %s --check-prefix=NOSYSROOT
void foo(void) {}
@@ -14,3 +18,8 @@ void foo(void) {}
// GDB: distinct !DICompileUnit(
// GDB-NOT: sysroot: "/CLANG_SYSROOT/MacOSX.sdk"
// GDB-NOT: sdk: "MacOSX.sdk"
+
+// -fno-debug-record-sysroot suppresses the sysroot path but keeps the SDK marker.
+// NOSYSROOT: distinct !DICompileUnit(
+// NOSYSROOT-NOT: sysroot: "/CLANG_SYSROOT/MacOSX.sdk"
+// NOSYSROOT-SAME: sdk: "MacOSX.sdk"
diff --git a/clang/test/Modules/debug-info-moduleimport.m b/clang/test/Modules/debug-info-moduleimport.m
index bdeb05bc08a02..b242364e7100e 100644
--- a/clang/test/Modules/debug-info-moduleimport.m
+++ b/clang/test/Modules/debug-info-moduleimport.m
@@ -44,3 +44,16 @@
// SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[DWOFILE:[0-9]+]]{{.*}}splitDebugFilename: "/MODULE-CACHE{{.*}}dwoId
// SKEL-CHECK: ![[DWOFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR]]"
+
+// With -fno-debug-record-sysroot and a sysroot that covers the module's
+// include path (%S contains %S/Inputs), the DICompileUnit has no sysroot
+// field and the DIModule has no includePath field.
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
+// RUN: -fmodules-cache-path=%t/cache %s -I %S/Inputs -isysroot %S -I %t \
+// RUN: -emit-llvm -debugger-tuning=lldb -fno-debug-record-sysroot -o - \
+// RUN: | FileCheck %s --check-prefix=NO-SYSROOT
+
+// NO-SYSROOT-NOT: sysroot:
+// NO-SYSROOT-NOT: includePath:
+// NO-SYSROOT: !DIModule(scope: null, name: "DebugObjC")
|
|
Possibly orthogonal to the discussion, but we've previously talked about removing the need for @keith could you elaborate on the "reproducible builds" part? |
|
I (think I) understand the problem you want solve, but I don't think this is a good solution because it breaks LLDB's ability to detect what SDK type the object file was built with. On Darwin-derived operating systems LLDB really only consumes the name of the SDK directory, because it will want to look up a compatible sysroot relative to where LLDB is running (as opposed to where the object file was built). I would propose that for the sysroot in the compile unit we either
For the sysroot/include_dir in I need to double-check what we practically pass as sysroot on Windows and Linux (is it always |
|
For our implementation of caching work, I don't think I want to have an opinion here since this is not in the path CAS based caching compilation is done. This is fine as long as it is a configurable build configuration and people decide to scrub the sys root knows the tradeoff. Also I really hope we don't use the name of SDK directory to do some meaningful decision in lldb. @adrian-prantl we need to change that! |
the case I'm interested in at the moment is that if you build
I might be misunderstanding the issue here, but in this patch I left the This is with
see above.
if this is the case than likely the
are you doing anything special to handle this path or just letting lldb's fallback logic deal with it? |
It's definitely used. Just to be clear: only the last path component (e.g.: See the uses of |
|
@keith Sorry, you are correct. I forgot that we already recorded SDK and sysroot separately. LLDB is currently using the sysroot for Clang module importing, and to automagically remap source paths pointing into the original sysroot ( ). Especially the second use-case should be irrelevant, if you already prove the remapping yourself, so I retract my concerns with this patch! |
You can also use |
Not for this case since the compilation root likely isn't within the Xcode directory |
|
I think the Objective-C/C module importing in LLDB might be affected by this, but that code has so many fallbacks that for standard use cases (e.g., importing Foundation) it probably works just fine with this patch/flag enabled. At least our test for this can find Foundation just fine. Also an LLDB test case as part of this patch would be nice. Otherwise I would just check in the test case below as a follow up PR (depends on #194357 in case you have to cherry-pick). |
This enables excluding the absolute path to the sysroot from debug info for reproducible builds. These fields are used by lldb, which also has fallbacks since it's possible these paths don't exist on the machine doing the debugging when built remotely anyways. This was also possible using `-fdebug-prefix-map=/path/to/Xcode.app=/some/path` but depending on the environment you might not be able to easily pass that with the user specific developer directory path. Assisted by: claude
20a8f42 to
f553895
Compare
|
applied your patch, we'll see what CI thinks. my understanding from the code was definitely that lldb's fallback behavior would actually be the ideal for my case anyways, since I'm trying to normalize across arbitrary Xcode install paths, and really lldb using the one that is selected at time of debug is what I'd want |
Teemperor
left a comment
There was a problem hiding this comment.
I personally don't have any objections assuming the CI is happy.
This enables excluding the absolute path to the sysroot from debug info
for reproducible builds. These fields are used by lldb, which also has
fallbacks since it's possible these paths don't exist on the machine
doing the debugging when built remotely anyways.
This was also possible using
-fdebug-prefix-map=/path/to/Xcode.app=/some/pathbut depending on the environment you might not be able to easily pass
that with the user specific developer directory path.
Assisted by: claude