From 10deee997df8ba9aeb4f479ecc2f794fa5e41371 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 25 Oct 2018 15:30:43 +0000 Subject: [PATCH] Fix a bug PlatformDarwin::SDKSupportsModule. This fixes a bug PlatformDarwin::SDKSupportsModule introduced by https://reviews.llvm.org/D47889. VersionTuple::tryParse() can deal with an optional third (micro) component, but the parse will fail when there are extra characters after the version number (e.g.: trying to parse the substring "12.0.sdk" out of "iPhoneSimulator12.0.sdk" fails after that patch). Fixed here by stripping the ".sdk" suffix first. (Part of) rdar://problem/45041492 Differential Revision https://reviews.llvm.org/D53677 llvm-svn: 345274 --- .../Plugins/Platform/MacOSX/PlatformDarwin.cpp | 11 ++++----- .../Plugins/Platform/MacOSX/PlatformDarwin.h | 12 +++++----- lldb/source/Utility/ArchSpec.cpp | 5 +++++ lldb/unittests/Platform/PlatformDarwinTest.cpp | 26 ++++++++++++++++++++++ 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp index 886e3b6..1665448 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp @@ -1402,14 +1402,11 @@ bool PlatformDarwin::SDKSupportsModules(SDKType desired_type, if (last_path_component) { const llvm::StringRef sdk_name = last_path_component.GetStringRef(); - llvm::StringRef version_part; - - if (sdk_name.startswith(sdk_strings[(int)desired_type])) { - version_part = - sdk_name.drop_front(strlen(sdk_strings[(int)desired_type])); - } else { + if (!sdk_name.startswith(sdk_strings[(int)desired_type])) return false; - } + auto version_part = + sdk_name.drop_front(strlen(sdk_strings[(int)desired_type])); + version_part.consume_back(".sdk"); llvm::VersionTuple version; if (version.tryParse(version_part)) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h index 3ad29ec..6060310 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h @@ -85,6 +85,12 @@ public: static std::tuple ParseVersionBuildDir(llvm::StringRef str); + enum class SDKType { + MacOSX = 0, + iPhoneSimulator, + iPhoneOS, + }; + protected: void ReadLibdispatchOffsetsAddress(lldb_private::Process *process); @@ -95,12 +101,6 @@ protected: const lldb_private::FileSpecList *module_search_paths_ptr, lldb::ModuleSP *old_module_sp_ptr, bool *did_create_ptr); - enum class SDKType { - MacOSX = 0, - iPhoneSimulator, - iPhoneOS, - }; - static bool SDKSupportsModules(SDKType sdk_type, llvm::VersionTuple version); static bool SDKSupportsModules(SDKType desired_type, diff --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp index df1029e..26f1421 100644 --- a/lldb/source/Utility/ArchSpec.cpp +++ b/lldb/source/Utility/ArchSpec.cpp @@ -1029,6 +1029,11 @@ static bool isCompatibleEnvironment(llvm::Triple::EnvironmentType lhs, rhs == llvm::Triple::UnknownEnvironment) return true; + // If any of the environment is unknown then they are compatible + if (lhs == llvm::Triple::UnknownEnvironment || + rhs == llvm::Triple::UnknownEnvironment) + return true; + // If one of the environment is Android and the other one is EABI then they // are considered to be compatible. This is required as a workaround for // shared libraries compiled for Android without the NOTE section indicating diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp b/lldb/unittests/Platform/PlatformDarwinTest.cpp index 18cd1b7..c0a9aef 100644 --- a/lldb/unittests/Platform/PlatformDarwinTest.cpp +++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp @@ -18,6 +18,13 @@ using namespace lldb; using namespace lldb_private; +struct PlatformDarwinTester : public PlatformDarwin { + static bool SDKSupportsModules(SDKType desired_type, + const lldb_private::FileSpec &sdk_path) { + return PlatformDarwin::SDKSupportsModules(desired_type, sdk_path); + } +}; + TEST(PlatformDarwinTest, TestParseVersionBuildDir) { llvm::VersionTuple V; llvm::StringRef D; @@ -44,4 +51,23 @@ TEST(PlatformDarwinTest, TestParseVersionBuildDir) { std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("3.4.5"); EXPECT_EQ(llvm::VersionTuple(3, 4, 5), V); + + std::string base = "/Applications/Xcode.app/Contents/Developer/Platforms/"; + EXPECT_TRUE(PlatformDarwinTester::SDKSupportsModules( + PlatformDarwin::SDKType::iPhoneSimulator, + FileSpec(base + + "iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.0.sdk", + false))); + EXPECT_FALSE(PlatformDarwinTester::SDKSupportsModules( + PlatformDarwin::SDKType::iPhoneSimulator, + FileSpec(base + + "iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.2.sdk", + false))); + EXPECT_TRUE(PlatformDarwinTester::SDKSupportsModules( + PlatformDarwin::SDKType::MacOSX, + FileSpec(base + "MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk", + false))); + EXPECT_FALSE(PlatformDarwinTester::SDKSupportsModules( + PlatformDarwin::SDKType::MacOSX, + FileSpec(base + "MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk", false))); } -- 2.7.4