Skip to content

Commit 7381d81

Browse files
[lldb][NFC] remove the ResolveSDKPathFromDebugInfo method (#145744)
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 #144913.
1 parent ff0dcc4 commit 7381d81

File tree

4 files changed

+26
-56
lines changed

4 files changed

+26
-56
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -458,22 +458,6 @@ class Platform : public PluginInterface {
458458
LLVM_PRETTY_FUNCTION, GetName()));
459459
}
460460

461-
/// Returns the full path of the most appropriate SDK for the
462-
/// specified 'module'. This function gets this path by parsing
463-
/// debug-info (see \ref `GetSDKPathFromDebugInfo`).
464-
///
465-
/// \param[in] module Module whose debug-info to parse for
466-
/// which SDK it was compiled against.
467-
///
468-
/// \returns If successful, returns the full path to an
469-
/// Xcode SDK.
470-
virtual llvm::Expected<std::string>
471-
ResolveSDKPathFromDebugInfo(Module &module) {
472-
return llvm::createStringError(
473-
llvm::formatv("{0} not implemented for '{1}' platform.",
474-
LLVM_PRETTY_FUNCTION, GetName()));
475-
}
476-
477461
/// Search CU for the SDK path the CUs was compiled against.
478462
///
479463
/// \param[in] unit The CU

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

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,13 +1130,33 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
11301130

11311131
if (target) {
11321132
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);
1133+
SymbolFile *sym_file = exe_module_sp->GetSymbolFile();
1134+
if (!sym_file)
1135+
return;
1136+
1137+
XcodeSDK merged_sdk;
1138+
for (unsigned i = 0; i < sym_file->GetNumCompileUnits(); ++i) {
1139+
if (auto cu_sp = sym_file->GetCompileUnitAtIndex(i)) {
1140+
auto cu_sdk = sym_file->ParseXcodeSDK(*cu_sp);
1141+
merged_sdk.Merge(cu_sdk);
1142+
}
1143+
}
1144+
1145+
// TODO: The result of this loop is almost equivalent to deriving the SDK
1146+
// from the target triple, which would be a lot cheaper.
1147+
1148+
if (FileSystem::Instance().Exists(merged_sdk.GetSysroot())) {
1149+
sysroot_spec = merged_sdk.GetSysroot();
11361150
} else {
1137-
LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host),
1138-
path_or_err.takeError(),
1139-
"Failed to resolve SDK path: {0}");
1151+
auto path_or_err =
1152+
HostInfo::GetSDKRoot(HostInfo::SDKOptions{merged_sdk});
1153+
if (path_or_err) {
1154+
sysroot_spec = FileSpec(*path_or_err);
1155+
} else {
1156+
LLDB_LOG_ERROR(GetLog(LLDBLog::Types | LLDBLog::Host),
1157+
path_or_err.takeError(),
1158+
"Failed to resolve SDK path: {0}");
1159+
}
11401160
}
11411161
}
11421162
}
@@ -1384,31 +1404,6 @@ PlatformDarwin::GetSDKPathFromDebugInfo(Module &module) {
13841404
return std::pair{std::move(merged_sdk), found_mismatch};
13851405
}
13861406

1387-
llvm::Expected<std::string>
1388-
PlatformDarwin::ResolveSDKPathFromDebugInfo(Module &module) {
1389-
auto sdk_or_err = GetSDKPathFromDebugInfo(module);
1390-
if (!sdk_or_err)
1391-
return llvm::createStringError(
1392-
llvm::inconvertibleErrorCode(),
1393-
llvm::formatv("Failed to parse SDK path from debug-info: {0}",
1394-
llvm::toString(sdk_or_err.takeError())));
1395-
1396-
auto [sdk, _] = std::move(*sdk_or_err);
1397-
1398-
if (FileSystem::Instance().Exists(sdk.GetSysroot()))
1399-
return sdk.GetSysroot().GetPath();
1400-
1401-
auto path_or_err = HostInfo::GetSDKRoot(HostInfo::SDKOptions{sdk});
1402-
if (!path_or_err)
1403-
return llvm::createStringError(
1404-
llvm::inconvertibleErrorCode(),
1405-
llvm::formatv("Error while searching for SDK (XcodeSDK '{0}'): {1}",
1406-
sdk.GetString(),
1407-
llvm::toString(path_or_err.takeError())));
1408-
1409-
return path_or_err->str();
1410-
}
1411-
14121407
llvm::Expected<XcodeSDK>
14131408
PlatformDarwin::GetSDKPathFromDebugInfo(CompileUnit &unit) {
14141409
ModuleSP module_sp = unit.CalculateSymbolContextModule();

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ class PlatformDarwin : public PlatformPOSIX {
120120
llvm::Expected<std::pair<XcodeSDK, bool>>
121121
GetSDKPathFromDebugInfo(Module &module) override;
122122

123-
llvm::Expected<std::string>
124-
ResolveSDKPathFromDebugInfo(Module &module) override;
125-
126123
llvm::Expected<XcodeSDK> GetSDKPathFromDebugInfo(CompileUnit &unit) override;
127124

128125
llvm::Expected<std::string>

lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
161161

162162
auto platform_sp = Platform::GetHostPlatform();
163163
ASSERT_TRUE(platform_sp);
164-
auto path_or_err = platform_sp->ResolveSDKPathFromDebugInfo(*module);
165-
EXPECT_FALSE(static_cast<bool>(path_or_err));
166-
llvm::consumeError(path_or_err.takeError());
167164
}
168165

169166
TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_No_DW_AT_APPLE_sdk) {
@@ -207,9 +204,6 @@ TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_No_DW_AT_APPLE_sdk) {
207204

208205
auto platform_sp = Platform::GetHostPlatform();
209206
ASSERT_TRUE(platform_sp);
210-
auto path_or_err = platform_sp->ResolveSDKPathFromDebugInfo(*module);
211-
EXPECT_FALSE(static_cast<bool>(path_or_err));
212-
llvm::consumeError(path_or_err.takeError());
213207
}
214208

215209
TEST_P(SDKPathParsingMultiparamTests, TestSDKPathFromDebugInfo) {

0 commit comments

Comments
 (0)