Skip to content

Commit 4b09528

Browse files
Michael137adrian-prantl
authored andcommitted
[lldb][Platform] Move the GetSDKPathFromDebugInfo helpers from PlatformDarwin into Platform (llvm#102488)
This is needed for relanding llvm#102497, where we plan on calling these APIs from generic ExpressionParser code. (cherry picked from commit 4bb1396)
1 parent 3b0dc19 commit 4b09528

File tree

3 files changed

+51
-29
lines changed

3 files changed

+51
-29
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
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

34+
#include "llvm/Support/Compiler.h"
3335
#include "llvm/Support/Error.h"
3436
#include "llvm/Support/VersionTuple.h"
3537

@@ -436,6 +438,41 @@ class Platform : public PluginInterface {
436438
return lldb_private::ConstString();
437439
}
438440

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

441478
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)