Add UUID::SetFromOptionalStringRef, use it in DynamicLoaderDarwin

We use UUID::fromOptionalData to read UUID's from the Mach-O files, so UUID's
of all 0's are invalid UUID's.
We also get uuid's from debugserver, which need to match the file UUID's.  So
we need an API that treats "000000000" as invalid as well.  Added that and use it.

Differential Revision: https://reviews.llvm.org/D57195

llvm-svn: 352122
This commit is contained in:
Jim Ingham
2019-01-24 22:43:44 +00:00
parent 8367b0750f
commit f3ecbfc164
4 changed files with 25 additions and 1 deletions

View File

@@ -67,6 +67,11 @@ public:
std::string GetAsString(llvm::StringRef separator = "-") const;
size_t SetFromStringRef(llvm::StringRef str, uint32_t num_uuid_bytes = 16);
// Same as SetFromStringRef, but if the resultant UUID is all 0 bytes, set the
// UUID to invalid.
size_t SetFromOptionalStringRef(llvm::StringRef str,
uint32_t num_uuid_bytes = 16);
// Decode as many UUID bytes (up to 16) as possible from the C string "cstr"
// This is used for auto completion where a partial UUID might have been

View File

@@ -476,7 +476,7 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo(
image_infos[i].segments.push_back(segment);
}
image_infos[i].uuid.SetFromStringRef(
image_infos[i].uuid.SetFromOptionalStringRef(
image->GetValueForKey("uuid")->GetAsString()->GetValue());
// All sections listed in the dyld image info structure will all either be

View File

@@ -109,3 +109,15 @@ size_t UUID::SetFromStringRef(llvm::StringRef str, uint32_t num_uuid_bytes) {
// Else return zero to indicate we were not able to parse a UUID value
return 0;
}
size_t UUID::SetFromOptionalStringRef(llvm::StringRef str,
uint32_t num_uuid_bytes) {
size_t num_chars_consumed = SetFromStringRef(str, num_uuid_bytes);
if (num_chars_consumed) {
if (llvm::all_of(m_bytes, [](uint8_t b) { return b == 0; }))
Clear();
}
return num_chars_consumed;
}

View File

@@ -41,11 +41,18 @@ TEST(UUIDTest, Validity) {
UUID a20 = UUID::fromData(zeroes.data(), 20);
UUID a16_0 = UUID::fromOptionalData(zeroes.data(), 16);
UUID a20_0 = UUID::fromOptionalData(zeroes.data(), 20);
UUID from_str;
from_str.SetFromStringRef("00000000-0000-0000-0000-000000000000");
UUID opt_from_str;
opt_from_str.SetFromOptionalStringRef("00000000-0000-0000-0000-000000000000");
EXPECT_FALSE(empty);
EXPECT_TRUE(a16);
EXPECT_TRUE(a20);
EXPECT_TRUE(from_str);
EXPECT_FALSE(a16_0);
EXPECT_FALSE(a20_0);
EXPECT_FALSE(opt_from_str);
}
TEST(UUIDTest, SetFromStringRef) {