@@ -1030,6 +1030,40 @@ PlatformDarwin::ExtractAppSpecificInfo(Process &process) {
1030
1030
return dict_sp;
1031
1031
}
1032
1032
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
+
1033
1067
void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType (
1034
1068
Target *target, std::vector<std::string> &options, XcodeSDK::Type sdk_type) {
1035
1069
const std::vector<std::string> apple_arguments = {
@@ -1129,15 +1163,13 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
1129
1163
FileSpec sysroot_spec;
1130
1164
1131
1165
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;
1141
1173
}
1142
1174
}
1143
1175
0 commit comments