[Lldb-commits] [lldb] [lldb][NFC] remove the ResolveSDKPathFromDebugInfo method (PR #145744)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Wed Jun 25 10:44:20 PDT 2025
https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/145744
>From e28a9e6249077c9ffca878cbf4c933b6f4f9eab8 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Thu, 19 Jun 2025 16:17:33 +0100
Subject: [PATCH 1/4] [lldb][darwin] force BuiltinHeadersInSystemModules to be
always false
---
lldb/include/lldb/Utility/XcodeSDK.h | 13 -----
.../Clang/ClangExpressionParser.cpp | 50 +------------------
lldb/source/Utility/XcodeSDK.cpp | 21 --------
3 files changed, 1 insertion(+), 83 deletions(-)
diff --git a/lldb/include/lldb/Utility/XcodeSDK.h b/lldb/include/lldb/Utility/XcodeSDK.h
index ceb8abb8c502d..a1a0ec415b90e 100644
--- a/lldb/include/lldb/Utility/XcodeSDK.h
+++ b/lldb/include/lldb/Utility/XcodeSDK.h
@@ -93,19 +93,6 @@ class XcodeSDK {
static bool SDKSupportsModules(Type type, llvm::VersionTuple version);
static bool SDKSupportsModules(Type desired_type, const FileSpec &sdk_path);
- /// Returns true if the SDK for the specified triple supports
- /// builtin modules in system headers.
- ///
- /// NOTE: should be kept in sync with sdkSupportsBuiltinModules in
- /// Toolchains/Darwin.cpp
- ///
- /// FIXME: this function will be removed once LLDB's ClangExpressionParser
- /// constructs the compiler instance through the driver/toolchain. See \ref
- /// SetupImportStdModuleLangOpts
- ///
- static bool SDKSupportsBuiltinModules(const llvm::Triple &target_triple,
- llvm::VersionTuple sdk_version);
-
/// Return the canonical SDK name, such as "macosx" for the macOS SDK.
static std::string GetCanonicalName(Info info);
/// Return the best-matching SDK type for a specific triple.
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 7aa9cae5a5614..3caf30c5822a2 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -319,49 +319,6 @@ class ClangDiagnosticManagerAdapter : public clang::DiagnosticConsumer {
StringRef m_filename;
};
-/// Returns true if the SDK for the specified triple supports
-/// builtin modules in system headers. This is used to decide
-/// whether to pass -fbuiltin-headers-in-system-modules to
-/// the compiler instance when compiling the `std` module.
-static llvm::Expected<bool>
-sdkSupportsBuiltinModules(lldb_private::Target &target) {
- auto arch_spec = target.GetArchitecture();
- auto const &triple = arch_spec.GetTriple();
- auto module_sp = target.GetExecutableModule();
- if (!module_sp)
- return llvm::createStringError("Executable module not found.");
-
- // Get SDK path that the target was compiled against.
- auto platform_sp = target.GetPlatform();
- if (!platform_sp)
- return llvm::createStringError("No Platform plugin found on target.");
-
- auto sdk_or_err = platform_sp->GetSDKPathFromDebugInfo(*module_sp);
- if (!sdk_or_err)
- return sdk_or_err.takeError();
-
- // Use the SDK path from debug-info to find a local matching SDK directory.
- auto sdk_path_or_err =
- HostInfo::GetSDKRoot(HostInfo::SDKOptions{std::move(sdk_or_err->first)});
- if (!sdk_path_or_err)
- return sdk_path_or_err.takeError();
-
- auto VFS = FileSystem::Instance().GetVirtualFileSystem();
- if (!VFS)
- return llvm::createStringError("No virtual filesystem available.");
-
- // Extract SDK version from the /path/to/some.sdk/SDKSettings.json
- auto parsed_or_err = clang::parseDarwinSDKInfo(*VFS, *sdk_path_or_err);
- if (!parsed_or_err)
- return parsed_or_err.takeError();
-
- auto maybe_sdk = *parsed_or_err;
- if (!maybe_sdk)
- return llvm::createStringError("Couldn't find Darwin SDK info.");
-
- return XcodeSDK::SDKSupportsBuiltinModules(triple, maybe_sdk->getVersion());
-}
-
static void SetupModuleHeaderPaths(CompilerInstance *compiler,
std::vector<std::string> include_directories,
lldb::TargetSP target_sp) {
@@ -723,12 +680,7 @@ static void SetupImportStdModuleLangOpts(CompilerInstance &compiler,
lang_opts.GNUKeywords = true;
lang_opts.CPlusPlus11 = true;
- if (auto supported_or_err = sdkSupportsBuiltinModules(target))
- lang_opts.BuiltinHeadersInSystemModules = !*supported_or_err;
- else
- LLDB_LOG_ERROR(log, supported_or_err.takeError(),
- "Failed to determine BuiltinHeadersInSystemModules when "
- "setting up import-std-module: {0}");
+ lang_opts.BuiltinHeadersInSystemModules = false;
// The Darwin libc expects this macro to be set.
lang_opts.GNUCVersion = 40201;
diff --git a/lldb/source/Utility/XcodeSDK.cpp b/lldb/source/Utility/XcodeSDK.cpp
index 004b4717e315b..eb2047e67c326 100644
--- a/lldb/source/Utility/XcodeSDK.cpp
+++ b/lldb/source/Utility/XcodeSDK.cpp
@@ -266,27 +266,6 @@ bool XcodeSDK::SupportsSwift() const {
}
}
-bool XcodeSDK::SDKSupportsBuiltinModules(const llvm::Triple &target_triple,
- llvm::VersionTuple sdk_version) {
- using namespace llvm;
-
- switch (target_triple.getOS()) {
- case Triple::OSType::MacOSX:
- return sdk_version >= VersionTuple(15U);
- case Triple::OSType::IOS:
- return sdk_version >= VersionTuple(18U);
- case Triple::OSType::TvOS:
- return sdk_version >= VersionTuple(18U);
- case Triple::OSType::WatchOS:
- return sdk_version >= VersionTuple(11U);
- case Triple::OSType::XROS:
- return sdk_version >= VersionTuple(2U);
- default:
- // New SDKs support builtin modules from the start.
- return true;
- }
-}
-
bool XcodeSDK::SDKSupportsModules(XcodeSDK::Type desired_type,
const FileSpec &sdk_path) {
ConstString last_path_component = sdk_path.GetFilename();
>From d8f808bc7fbaf592e7347e8ece84b3bb06edde1c Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Mon, 23 Jun 2025 18:18:57 +0200
Subject: [PATCH 2/4] remove unused variable
---
.../Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 3caf30c5822a2..ffc76e6e93498 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -662,7 +662,6 @@ static void SetupLangOpts(CompilerInstance &compiler,
static void SetupImportStdModuleLangOpts(CompilerInstance &compiler,
lldb_private::Target &target) {
- Log *log = GetLog(LLDBLog::Expressions);
LangOptions &lang_opts = compiler.getLangOpts();
lang_opts.Modules = true;
// We want to implicitly build modules.
>From 8fc573c71a6fcb37931cda0237bd019eaaa5037e Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Mon, 23 Jun 2025 18:19:57 +0200
Subject: [PATCH 3/4] remove ResolveSDKPathFromDebugInfo
---
lldb/include/lldb/Target/Platform.h | 16 ------
.../Platform/MacOSX/PlatformDarwin.cpp | 56 +++++++++----------
.../Plugins/Platform/MacOSX/PlatformDarwin.h | 3 -
.../SymbolFile/DWARF/XcodeSDKModuleTests.cpp | 6 --
4 files changed, 25 insertions(+), 56 deletions(-)
diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h
index 35ffdabf907e7..1a05bdf54332f 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -458,22 +458,6 @@ class Platform : public PluginInterface {
LLVM_PRETTY_FUNCTION, GetName()));
}
- /// Returns the full path of the most appropriate SDK for the
- /// specified 'module'. This function gets this path by parsing
- /// debug-info (see \ref `GetSDKPathFromDebugInfo`).
- ///
- /// \param[in] module Module whose debug-info to parse for
- /// which SDK it was compiled against.
- ///
- /// \returns If successful, returns the full path to an
- /// Xcode SDK.
- virtual llvm::Expected<std::string>
- ResolveSDKPathFromDebugInfo(Module &module) {
- return llvm::createStringError(
- llvm::formatv("{0} not implemented for '{1}' platform.",
- LLVM_PRETTY_FUNCTION, GetName()));
- }
-
/// Search CU for the SDK path the CUs was compiled against.
///
/// \param[in] unit The CU
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 262a7dc731713..54d70e6ffb0c2 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1130,14 +1130,33 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
if (target) {
if (ModuleSP exe_module_sp = target->GetExecutableModule()) {
- auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp);
- if (path_or_err) {
- sysroot_spec = FileSpec(*path_or_err);
+ SymbolFile *sym_file = exe_module_sp->GetSymbolFile();
+ if (!sym_file)
+ return;
+
+ XcodeSDK merged_sdk;
+ for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) {
+ if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) {
+ auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp);
+ merged_sdk.Merge(cu_sdk);
+ }
+ }
+
+ if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) {
+ sysroot_spec = merged_sdk.GetSysroot();
} else {
- LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host),
- path_or_err.takeError(),
- "Failed to resolve SDK path: {0}");
+ auto path_or_err =
+ HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk});
+ if (path_or_err) {
+ sysroot_spec = FileSpec(*path_or_err);
+ } else {
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host),
+ path_or_err.takeError(),
+ "Failed to resolve SDK path: {0}");
+ }
}
+ // getSDKfortriple()
+ // would not work for internal/public variants.
}
}
@@ -1384,31 +1403,6 @@ PlatformDarwin::GetSDKPathFromDebugInfo(Module &module) {
return std::pair{std::move(merged_sdk), found_mismatch};
}
-llvm::Expected<std::string>
-PlatformDarwin::ResolveSDKPathFromDebugInfo(Module &module) {
- auto sdk_or_err = GetSDKPathFromDebugInfo(module);
- if (!sdk_or_err)
- return llvm::createStringError(
- llvm::inconvertibleErrorCode(),
- llvm::formatv("Failed to parse SDK path from debug-info: {0}",
- llvm::toString(sdk_or_err.takeError())));
-
- auto [sdk, _] = std::move(*sdk_or_err);
-
- if (FileSystem::Instance().Exists(sdk.GetSysroot()))
- return sdk.GetSysroot().GetPath();
-
- auto path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk});
- if (!path_or_err)
- return llvm::createStringError(
- llvm::inconvertibleErrorCode(),
- llvm::formatv("Error while searching for SDK (XcodeSDK '{0}'): {1}",
- sdk.GetString(),
- llvm::toString(path_or_err.takeError())));
-
- return path_or_err->str();
-}
-
llvm::Expected<XcodeSDK>
PlatformDarwin::GetSDKPathFromDebugInfo(CompileUnit &unit) {
ModuleSP module_sp = unit.CalculateSymbolContextModule();
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index f8a62ceb958fe..f8a9301002e0d 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -120,9 +120,6 @@ class PlatformDarwin : public PlatformPOSIX {
llvm::Expected<std::pair<XcodeSDK, bool>>
GetSDKPathFromDebugInfo(Module &module) override;
- llvm::Expected<std::string>
- ResolveSDKPathFromDebugInfo(Module &module) override;
-
llvm::Expected<XcodeSDK> GetSDKPathFromDebugInfo(CompileUnit &unit) override;
llvm::Expected<std::string>
diff --git a/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp b/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
index 50c37dcd4568e..e04183d85e5bd 100644
--- a/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -161,9 +161,6 @@ TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
auto platform_sp = Platform::GetHostPlatform();
ASSERT_TRUE(platform_sp);
- auto path_or_err = platform_sp->ResolveSDKPathFromDebugInfo(*module);
- EXPECT_FALSE(static_cast<bool>(path_or_err));
- llvm::consumeError(path_or_err.takeError());
}
TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_No_DW_AT_APPLE_sdk) {
@@ -207,9 +204,6 @@ TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_No_DW_AT_APPLE_sdk) {
auto platform_sp = Platform::GetHostPlatform();
ASSERT_TRUE(platform_sp);
- auto path_or_err = platform_sp->ResolveSDKPathFromDebugInfo(*module);
- EXPECT_FALSE(static_cast<bool>(path_or_err));
- llvm::consumeError(path_or_err.takeError());
}
TEST_P(SDKPathParsingMultiparamTests, TestSDKPathFromDebugInfo) {
>From 5d4b702c1e5f2176effee0f6bddcfd117c8a6d7d Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Wed, 25 Jun 2025 18:44:06 +0100
Subject: [PATCH 4/4] remove comment
---
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 54d70e6ffb0c2..03f3656748d48 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1155,8 +1155,6 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
"Failed to resolve SDK path: {0}");
}
}
- // getSDKfortriple()
- // would not work for internal/public variants.
}
}
More information about the lldb-commits
mailing list