Skip to content

Commit d2f0b68

Browse files
committed
[lldb][Platform] Move the GetSDKPathFromDebugInfo helpers from PlatformDarwin into Platform
This will soon be needed for llvm#102309, where we plan on calling these APIs from generic ExpressionParser code.
1 parent 29817a9 commit d2f0b68

File tree

3 files changed

+48
-29
lines changed

3 files changed

+48
-29
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "lldb/Utility/StructuredData.h"
2828
#include "lldb/Utility/Timeout.h"
2929
#include "lldb/Utility/UserIDResolver.h"
30+
#include "lldb/Utility/XcodeSDK.h"
3031
#include "lldb/lldb-private-forward.h"
3132
#include "lldb/lldb-public.h"
3233

@@ -436,6 +437,39 @@ class Platform : public PluginInterface {
436437
return lldb_private::ConstString();
437438
}
438439

440+
/// Search each CU associated with the specified 'module' for
441+
/// the SDK paths the CUs were compiled against. In the presence
442+
/// of different SDKs, we try to pick the most appropriate one
443+
/// using \ref XcodeSDK::Merge.
444+
///
445+
/// \param[in] module Module whose debug-info CUs to parse for
446+
/// which SDK they were compiled against.
447+
///
448+
/// \returns If successful, returns a pair of a parsed XcodeSDK
449+
/// object and a boolean that is 'true' if we encountered
450+
/// a conflicting combination of SDKs when parsing the CUs
451+
/// (e.g., a public and internal SDK).
452+
virtual llvm::Expected<std::pair<XcodeSDK, bool>>
453+
GetSDKPathFromDebugInfo(Module &module) {
454+
return llvm::createStringError(llvm::formatv(
455+
"{0} not implemented for '{1}' platform.", __func__, GetName()));
456+
}
457+
458+
/// Returns the full path of the most appropriate SDK for the
459+
/// specified 'module'. This function gets this path by parsing
460+
/// debug-info (see \ref `GetSDKPathFromDebugInfo`).
461+
///
462+
/// \param[in] module Module whose debug-info to parse for
463+
/// which SDK it was compiled against.
464+
///
465+
/// \returns If successful, returns the full path to an
466+
/// Xcode SDK.
467+
virtual llvm::Expected<std::string>
468+
ResolveSDKPathFromDebugInfo(Module &module) {
469+
return llvm::createStringError(llvm::formatv(
470+
"{0} not implemented for '{1}' platform.", __func__, GetName()));
471+
}
472+
439473
const std::string &GetRemoteURL() const { return m_remote_url; }
440474

441475
bool IsHost() const {

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

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -124,32 +124,11 @@ class PlatformDarwin : public PlatformPOSIX {
124124
/// located in.
125125
static FileSpec GetCurrentCommandLineToolsDirectory();
126126

127-
/// Search each CU associated with the specified 'module' for
128-
/// the SDK paths the CUs were compiled against. In the presence
129-
/// of different SDKs, we try to pick the most appropriate one
130-
/// using \ref XcodeSDK::Merge.
131-
///
132-
/// \param[in] module Module whose debug-info CUs to parse for
133-
/// which SDK they were compiled against.
134-
///
135-
/// \returns If successful, returns a pair of a parsed XcodeSDK
136-
/// object and a boolean that is 'true' if we encountered
137-
/// a conflicting combination of SDKs when parsing the CUs
138-
/// (e.g., a public and internal SDK).
139-
static llvm::Expected<std::pair<XcodeSDK, bool>>
140-
GetSDKPathFromDebugInfo(Module &module);
141-
142-
/// Returns the full path of the most appropriate SDK for the
143-
/// specified 'module'. This function gets this path by parsing
144-
/// debug-info (see \ref `GetSDKPathFromDebugInfo`).
145-
///
146-
/// \param[in] module Module whose debug-info to parse for
147-
/// which SDK it was compiled against.
148-
///
149-
/// \returns If successful, returns the full path to an
150-
/// Xcode SDK.
151-
static llvm::Expected<std::string>
152-
ResolveSDKPathFromDebugInfo(Module &module);
127+
llvm::Expected<std::pair<XcodeSDK, bool>>
128+
GetSDKPathFromDebugInfo(Module &module) override;
129+
130+
llvm::Expected<std::string>
131+
ResolveSDKPathFromDebugInfo(Module &module) override;
153132

154133
protected:
155134
static const char *GetCompatibleArch(ArchSpec::Core core, size_t idx);

lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_InvalidSDKPath) {
162162
ModuleSP module = t.GetModule();
163163
ASSERT_NE(module, nullptr);
164164

165-
auto path_or_err = PlatformDarwin::ResolveSDKPathFromDebugInfo(*module);
165+
auto platform_sp = Platform::GetHostPlatform();
166+
ASSERT_TRUE(platform_sp);
167+
auto path_or_err = platform_sp->ResolveSDKPathFromDebugInfo(*module);
166168
EXPECT_FALSE(static_cast<bool>(path_or_err));
167169
llvm::consumeError(path_or_err.takeError());
168170
}
@@ -206,7 +208,9 @@ TEST_F(XcodeSDKModuleTests, TestSDKPathFromDebugInfo_No_DW_AT_APPLE_sdk) {
206208
ModuleSP module = t.GetModule();
207209
ASSERT_NE(module, nullptr);
208210

209-
auto path_or_err = PlatformDarwin::ResolveSDKPathFromDebugInfo(*module);
211+
auto platform_sp = Platform::GetHostPlatform();
212+
ASSERT_TRUE(platform_sp);
213+
auto path_or_err = platform_sp->ResolveSDKPathFromDebugInfo(*module);
210214
EXPECT_FALSE(static_cast<bool>(path_or_err));
211215
llvm::consumeError(path_or_err.takeError());
212216
}
@@ -254,7 +258,9 @@ TEST_P(SDKPathParsingMultiparamTests, TestSDKPathFromDebugInfo) {
254258
ModuleSP module = t.GetModule();
255259
ASSERT_NE(module, nullptr);
256260

257-
auto sdk_or_err = PlatformDarwin::GetSDKPathFromDebugInfo(*module);
261+
auto platform_sp = Platform::GetHostPlatform();
262+
ASSERT_TRUE(platform_sp);
263+
auto sdk_or_err = platform_sp->GetSDKPathFromDebugInfo(*module);
258264
ASSERT_TRUE(static_cast<bool>(sdk_or_err));
259265

260266
auto [sdk, found_mismatch] = *sdk_or_err;

0 commit comments

Comments
 (0)