[Lldb-commits] [lldb] 0c124be - [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (#146062)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 1 08:23:26 PDT 2025
Author: Charles Zablit
Date: 2025-07-01T16:23:23+01:00
New Revision: 0c124be33f8d2ed6ede41bcd3d8f0ca115921ef3
URL: https://github.com/llvm/llvm-project/commit/0c124be33f8d2ed6ede41bcd3d8f0ca115921ef3
DIFF: https://github.com/llvm/llvm-project/commit/0c124be33f8d2ed6ede41bcd3d8f0ca115921ef3.diff
LOG: [lldb][NFC] Inline ResolveSDKPathFromDebugInfo in one of its call site (#146062)
This patch is part of an effort to remove the
`ResolveSDKPathFromDebugInfo` method, and more specifically the variant
which takes a Module as argument.
See the following PR for a follow up on what to do:
- https://github.com/llvm/llvm-project/pull/144913.
---------
Co-authored-by: Michael Buch <michaelbuch12 at gmail.com>
Added:
Modified:
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 262a7dc731713..1db7bc78013d7 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1030,6 +1030,40 @@ PlatformDarwin::ExtractAppSpecificInfo(Process &process) {
return dict_sp;
}
+static llvm::Expected<lldb_private::FileSpec>
+ResolveSDKPathFromDebugInfo(lldb_private::Target *target) {
+
+ ModuleSP exe_module_sp = target->GetExecutableModule();
+ if (!exe_module_sp)
+ return llvm::createStringError("Failed to get module from target");
+
+ SymbolFile *sym_file = exe_module_sp->GetSymbolFile();
+ if (!sym_file)
+ return llvm::createStringError("Failed to get symbol file from module");
+
+ 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.
+ FileSpec sdk_path = merged_sdk.GetSysroot();
+ if (FileSystem::Instance().Exists(sdk_path)) {
+ return sdk_path;
+ }
+ auto path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk});
+ if (!path_or_err)
+ return llvm::createStringError(
+ llvm::formatv("Failed to resolve SDK path: {0}",
+ llvm::toString(path_or_err.takeError())));
+
+ return FileSpec(*path_or_err);
+}
+
void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
Target *target, std::vector<std::string> &options, XcodeSDK::Type sdk_type) {
const std::vector<std::string> apple_arguments = {
@@ -1129,15 +1163,13 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
FileSpec sysroot_spec;
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);
- } else {
- LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host),
- path_or_err.takeError(),
- "Failed to resolve SDK path: {0}");
- }
+ auto sysroot_spec_or_err = ::ResolveSDKPathFromDebugInfo(target);
+ if (!sysroot_spec_or_err) {
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host),
+ sysroot_spec_or_err.takeError(),
+ "Failed to resolve sysroot: {0}");
+ } else {
+ sysroot_spec = *sysroot_spec_or_err;
}
}
More information about the lldb-commits
mailing list