Index: lldb/include/lldb/Utility/XcodeSDK.h =================================================================== --- lldb/include/lldb/Utility/XcodeSDK.h +++ lldb/include/lldb/Utility/XcodeSDK.h @@ -14,6 +14,10 @@ #include "llvm/Support/VersionTuple.h" #include +namespace llvm { +class Triple; +} + namespace lldb_private { /// An abstraction for Xcode-style SDKs that works like \ref ArchSpec. @@ -76,6 +80,8 @@ static bool SDKSupportsModules(Type desired_type, const FileSpec &sdk_path); /// Return the canonical SDK name, such as "macosx" for the macOS SDK. static std::string GetCanonicalName(Info info); + /// Return the best-matching SDK type for a specific triple. + static XcodeSDK::Type GetSDKTypeForTriple(const llvm::Triple &triple); }; } // namespace lldb_private Index: lldb/source/Utility/XcodeSDK.cpp =================================================================== --- lldb/source/Utility/XcodeSDK.cpp +++ lldb/source/Utility/XcodeSDK.cpp @@ -6,10 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Utility/FileSpec.h" #include "lldb/Utility/XcodeSDK.h" +#include "lldb/Utility/FileSpec.h" #include "lldb/lldb-types.h" + +#include "llvm/ADT/Triple.h" + #include using namespace lldb; @@ -211,3 +214,32 @@ return false; return SDKSupportsModules(sdk.GetType(), sdk.GetVersion()); } + +XcodeSDK::Type XcodeSDK::GetSDKTypeForTriple(const llvm::Triple &triple) { + switch (triple.getOS()) { + case llvm::Triple::OSType::MacOSX: + case llvm::Triple::OSType::Darwin: + return Type::MacOSX; + case llvm::Triple::OSType::IOS: + switch (triple.getEnvironment()) { + case llvm::Triple::MacABI: + return Type::MacOSX; + case llvm::Triple::Simulator: + return Type::iPhoneSimulator; + default: + return Type::iPhoneOS; + } + case llvm::Triple::OSType::TvOS: + if (triple.getEnvironment() == llvm::Triple::Simulator) + return Type::AppleTVSimulator; + return Type::AppleTVOS; + case llvm::Triple::OSType::WatchOS: + if (triple.getEnvironment() == llvm::Triple::Simulator) + return Type::WatchSimulator; + return Type::watchOS; + case llvm::Triple::OSType::Linux: + return Type::Linux; + default: + return Type::unknown; + } +} Index: lldb/unittests/Utility/XcodeSDKTest.cpp =================================================================== --- lldb/unittests/Utility/XcodeSDKTest.cpp +++ lldb/unittests/Utility/XcodeSDKTest.cpp @@ -12,6 +12,7 @@ #include "lldb/Utility/XcodeSDK.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Triple.h" #include @@ -158,3 +159,33 @@ info.version = llvm::VersionTuple(7, 0); EXPECT_EQ("iphoneos7.0.internal", XcodeSDK::GetCanonicalName(info)); } + +TEST(XcodeSDKTest, GetSDKTypeForTriple) { + EXPECT_EQ( + XcodeSDK::GetSDKTypeForTriple(llvm::Triple("x86_64-apple-macosx10.14")), + XcodeSDK::Type::MacOSX); + EXPECT_EQ(XcodeSDK::GetSDKTypeForTriple(llvm::Triple("x86_64-apple-darwin")), + XcodeSDK::Type::MacOSX); + EXPECT_EQ(XcodeSDK::GetSDKTypeForTriple( + llvm::Triple("x86_64-apple-ios13.4-simulator")), + XcodeSDK::Type::iPhoneSimulator); + EXPECT_EQ(XcodeSDK::GetSDKTypeForTriple(llvm::Triple("arm64-apple-ios13.4")), + XcodeSDK::Type::iPhoneOS); + EXPECT_EQ(XcodeSDK::GetSDKTypeForTriple( + llvm::Triple("x86_64-apple-ios13.4-macabi")), + XcodeSDK::Type::MacOSX); + EXPECT_EQ(XcodeSDK::GetSDKTypeForTriple( + llvm::Triple("x86_64-apple-tvos-simulator")), + XcodeSDK::Type::AppleTVSimulator); + EXPECT_EQ(XcodeSDK::GetSDKTypeForTriple(llvm::Triple("arm64-apple-tvos")), + XcodeSDK::Type::AppleTVOS); + EXPECT_EQ(XcodeSDK::GetSDKTypeForTriple( + llvm::Triple("x86_64-apple-watchos-simulator")), + XcodeSDK::Type::WatchSimulator); + EXPECT_EQ(XcodeSDK::GetSDKTypeForTriple(llvm::Triple("arm64-apple-watchos")), + XcodeSDK::Type::watchOS); + EXPECT_EQ(XcodeSDK::GetSDKTypeForTriple(llvm::Triple("x86_64-unknown-linux")), + XcodeSDK::Type::Linux); + EXPECT_EQ(XcodeSDK::GetSDKTypeForTriple(llvm::Triple("i386-unknown-netbsd")), + XcodeSDK::Type::unknown); +}