Skip to content

[lldb][Platform] Move the GetSDKPathFromDebugInfo helpers from PlatformDarwin into Platform #102488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions lldb/include/lldb/Target/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
#include "lldb/Utility/StructuredData.h"
#include "lldb/Utility/Timeout.h"
#include "lldb/Utility/UserIDResolver.h"
#include "lldb/Utility/XcodeSDK.h"
#include "lldb/lldb-private-forward.h"
#include "lldb/lldb-public.h"

#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/VersionTuple.h"

Expand Down Expand Up @@ -436,6 +438,41 @@ class Platform : public PluginInterface {
return lldb_private::ConstString();
}

/// Search each CU associated with the specified 'module' for
/// the SDK paths the CUs were compiled against. In the presence
/// of different SDKs, we try to pick the most appropriate one
/// using \ref XcodeSDK::Merge.
///
/// \param[in] module Module whose debug-info CUs to parse for
/// which SDK they were compiled against.
///
/// \returns If successful, returns a pair of a parsed XcodeSDK
/// object and a boolean that is 'true' if we encountered
/// a conflicting combination of SDKs when parsing the CUs
/// (e.g., a public and internal SDK).
virtual llvm::Expected<std::pair<XcodeSDK, bool>>
GetSDKPathFromDebugInfo(Module &module) {
return llvm::createStringError(
llvm::formatv("{0} not implemented for '{1}' platform.",
LLVM_PRETTY_FUNCTION, GetName()));
}

/// Returns the full path of the most appropriate SDK for the
/// specified 'module'. This function gets this path by parsing
/// debug-info (see \ref `GetSDKPathFromDebugInfo`).
///
/// \param[in] module Module whose debug-info to parse for
/// which SDK it was compiled against.
///
/// \returns If successful, returns the full path to an
/// Xcode SDK.
virtual llvm::Expected<std::string>
ResolveSDKPathFromDebugInfo(Module &module) {
return llvm::createStringError(
llvm::formatv("{0} not implemented for '{1}' platform.",
LLVM_PRETTY_FUNCTION, GetName()));
}

const std::string &GetRemoteURL() const { return m_remote_url; }

bool IsHost() const {
Expand Down
31 changes: 5 additions & 26 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,32 +124,11 @@ class PlatformDarwin : public PlatformPOSIX {
/// located in.
static FileSpec GetCurrentCommandLineToolsDirectory();

/// Search each CU associated with the specified 'module' for
/// the SDK paths the CUs were compiled against. In the presence
/// of different SDKs, we try to pick the most appropriate one
/// using \ref XcodeSDK::Merge.
///
/// \param[in] module Module whose debug-info CUs to parse for
/// which SDK they were compiled against.
///
/// \returns If successful, returns a pair of a parsed XcodeSDK
/// object and a boolean that is 'true' if we encountered
/// a conflicting combination of SDKs when parsing the CUs
/// (e.g., a public and internal SDK).
static llvm::Expected<std::pair<XcodeSDK, bool>>
GetSDKPathFromDebugInfo(Module &module);

/// Returns the full path of the most appropriate SDK for the
/// specified 'module'. This function gets this path by parsing
/// debug-info (see \ref `GetSDKPathFromDebugInfo`).
///
/// \param[in] module Module whose debug-info to parse for
/// which SDK it was compiled against.
///
/// \returns If successful, returns the full path to an
/// Xcode SDK.
static llvm::Expected<std::string>
ResolveSDKPathFromDebugInfo(Module &module);
llvm::Expected<std::pair<XcodeSDK, bool>>
GetSDKPathFromDebugInfo(Module &module) override;

llvm::Expected<std::string>
ResolveSDKPathFromDebugInfo(Module &module) override;

protected:
static const char *GetCompatibleArch(ArchSpec::Core core, size_t idx);
Expand Down
12 changes: 9 additions & 3 deletions lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
ModuleSP module = t.GetModule();
ASSERT_NE(module, nullptr);

auto path_or_err = PlatformDarwin::ResolveSDKPathFromDebugInfo(*module);
auto platform_sp = Platform::GetHostPlatform();
ASSERT_TRUE(platform_sp);
auto path_or_err = platform_sp->ResolveSDKPathFromDebugInfo(*module);
EXPECT_FALSE(static_cast<bool>(path_or_err));
llvm::consumeError(path_or_err.takeError());
}
Expand Down Expand Up @@ -206,7 +208,9 @@ TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_No_DW_AT_APPLE_sdk) {
ModuleSP module = t.GetModule();
ASSERT_NE(module, nullptr);

auto path_or_err = PlatformDarwin::ResolveSDKPathFromDebugInfo(*module);
auto platform_sp = Platform::GetHostPlatform();
ASSERT_TRUE(platform_sp);
auto path_or_err = platform_sp->ResolveSDKPathFromDebugInfo(*module);
EXPECT_FALSE(static_cast<bool>(path_or_err));
llvm::consumeError(path_or_err.takeError());
}
Expand Down Expand Up @@ -254,7 +258,9 @@ TEST_P(SDKPathParsingMultiparamTests, TestSDKPathFromDebugInfo) {
ModuleSP module = t.GetModule();
ASSERT_NE(module, nullptr);

auto sdk_or_err = PlatformDarwin::GetSDKPathFromDebugInfo(*module);
auto platform_sp = Platform::GetHostPlatform();
ASSERT_TRUE(platform_sp);
auto sdk_or_err = platform_sp->GetSDKPathFromDebugInfo(*module);
ASSERT_TRUE(static_cast<bool>(sdk_or_err));

auto [sdk, found_mismatch] = *sdk_or_err;
Expand Down
Loading