Skip to content

Commit 0c124be

Browse files
[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: - #144913. --------- Co-authored-by: Michael Buch <[email protected]>
1 parent 69b69cb commit 0c124be

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,40 @@ PlatformDarwin::ExtractAppSpecificInfo(Process &process) {
10301030
return dict_sp;
10311031
}
10321032

1033+
static llvm::Expected<lldb_private::FileSpec>
1034+
ResolveSDKPathFromDebugInfo(lldb_private::Target *target) {
1035+
1036+
ModuleSP exe_module_sp = target->GetExecutableModule();
1037+
if (!exe_module_sp)
1038+
return llvm::createStringError("Failed to get module from target");
1039+
1040+
SymbolFile *sym_file = exe_module_sp->GetSymbolFile();
1041+
if (!sym_file)
1042+
return llvm::createStringError("Failed to get symbol file from module");
1043+
1044+
XcodeSDK merged_sdk;
1045+
for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) {
1046+
if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) {
1047+
auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp);
1048+
merged_sdk.Merge(cu_sdk);
1049+
}
1050+
}
1051+
1052+
// TODO: The result of this loop is almost equivalent to deriving the SDK
1053+
// from the target triple, which would be a lot cheaper.
1054+
FileSpec sdk_path = merged_sdk.GetSysroot();
1055+
if (FileSystem::Instance().Exists(sdk_path)) {
1056+
return sdk_path;
1057+
}
1058+
auto path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk});
1059+
if (!path_or_err)
1060+
return llvm::createStringError(
1061+
llvm::formatv("Failed to resolve SDK path: {0}",
1062+
llvm::toString(path_or_err.takeError())));
1063+
1064+
return FileSpec(*path_or_err);
1065+
}
1066+
10331067
void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
10341068
Target *target, std::vector<std::string> &options, XcodeSDK::Type sdk_type) {
10351069
const std::vector<std::string> apple_arguments = {
@@ -1129,15 +1163,13 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
11291163
FileSpec sysroot_spec;
11301164

11311165
if (target) {
1132-
if (ModuleSP exe_module_sp = target->GetExecutableModule()) {
1133-
auto path_or_err = ResolveSDKPathFromDebugInfo(*exe_module_sp);
1134-
if (path_or_err) {
1135-
sysroot_spec = FileSpec(*path_or_err);
1136-
} else {
1137-
LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host),
1138-
path_or_err.takeError(),
1139-
"Failed to resolve SDK path: {0}");
1140-
}
1166+
auto sysroot_spec_or_err = ::ResolveSDKPathFromDebugInfo(target);
1167+
if (!sysroot_spec_or_err) {
1168+
LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host),
1169+
sysroot_spec_or_err.takeError(),
1170+
"Failed to resolve sysroot: {0}");
1171+
} else {
1172+
sysroot_spec = *sysroot_spec_or_err;
11411173
}
11421174
}
11431175

0 commit comments

Comments
 (0)