[Lldb-commits] [PATCH] D53677: Fix a bug PlatformDarwin::SDKSupportsModule
Adrian Prantl via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Wed Oct 24 15:24:15 PDT 2018
aprantl created this revision.
aprantl added reviewers: jingham, clayborg, labath.
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.
rdar://problem/45041492
https://reviews.llvm.org/D53677
Files:
source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
source/Plugins/Platform/MacOSX/PlatformDarwin.h
unittests/Platform/PlatformDarwinTest.cpp
Index: unittests/Platform/PlatformDarwinTest.cpp
===================================================================
--- unittests/Platform/PlatformDarwinTest.cpp
+++ 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 @@
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)));
}
Index: source/Plugins/Platform/MacOSX/PlatformDarwin.h
===================================================================
--- source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -85,6 +85,12 @@
static std::tuple<llvm::VersionTuple, llvm::StringRef>
ParseVersionBuildDir(llvm::StringRef str);
+ enum class SDKType {
+ MacOSX = 0,
+ iPhoneSimulator,
+ iPhoneOS,
+ };
+
protected:
void ReadLibdispatchOffsetsAddress(lldb_private::Process *process);
@@ -95,12 +101,6 @@
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,
Index: source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
===================================================================
--- source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1402,14 +1402,11 @@
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))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53677.171000.patch
Type: text/x-patch
Size: 3480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20181024/573066ce/attachment.bin>
More information about the lldb-commits
mailing list