[Lldb-commits] [lldb] 4bb1396 - [lldb][Platform] Move the GetSDKPathFromDebugInfo helpers from PlatformDarwin into Platform (#102488)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Aug 9 01:41:28 PDT 2024
Author: Michael Buch
Date: 2024-08-09T09:41:25+01:00
New Revision: 4bb139622ee318571cb2ef6649ff1766051f0e84
URL: https://github.com/llvm/llvm-project/commit/4bb139622ee318571cb2ef6649ff1766051f0e84
DIFF: https://github.com/llvm/llvm-project/commit/4bb139622ee318571cb2ef6649ff1766051f0e84.diff
LOG: [lldb][Platform] Move the GetSDKPathFromDebugInfo helpers from PlatformDarwin into Platform (#102488)
This is needed for relanding
https://github.com/llvm/llvm-project/pull/102497, where we plan on
calling these APIs from generic ExpressionParser code.
Added:
Modified:
lldb/include/lldb/Target/Platform.h
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h
index 5ed2fc33356d9d..920f80bc733174 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -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"
@@ -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
diff erent 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 {
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index ff7087da6825d9..66a26d2f496776 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -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
diff erent 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);
diff --git a/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp b/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
index c37da89ff79ce7..dc5680522e1836 100644
--- a/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -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());
}
@@ -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());
}
@@ -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;
More information about the lldb-commits
mailing list