[Lldb-commits] [lldb] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (PR #146062)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Fri Jun 27 04:50:52 PDT 2025
https://github.com/charles-zablit created https://github.com/llvm/llvm-project/pull/146062
This patch is part of an effort to remove the ResolveSDKPathFromDebugInfo method, and more specifically the variant which takes a Module as argument.
This PR should be merged after https://github.com/llvm/llvm-project/pull/144913.
>From 6ce75177264d47ffedbf0e6ee44831eac1d3ea55 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Fri, 27 Jun 2025 12:49:53 +0100
Subject: [PATCH] [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its
call site
---
.../Platform/MacOSX/PlatformDarwin.cpp | 32 +++++++++++++++----
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 262a7dc731713..ae46ac63e756a 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1130,13 +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);
+ }
+ }
+
+ // TODO: The result of this loop is almost equivalent to deriving the SDK
+ // from the target triple, which would be a lot cheaper.
+
+ 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}");
+ }
}
}
}
More information about the lldb-commits
mailing list