Skip to content

Commit f3ecbfc

Browse files
committedJan 24, 2019
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
1 parent 8367b07 commit f3ecbfc

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed
 

‎lldb/include/lldb/Utility/UUID.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class UUID {
6767
std::string GetAsString(llvm::StringRef separator = "-") const;
6868

6969
size_t SetFromStringRef(llvm::StringRef str, uint32_t num_uuid_bytes = 16);
70+
71+
// Same as SetFromStringRef, but if the resultant UUID is all 0 bytes, set the
72+
// UUID to invalid.
73+
size_t SetFromOptionalStringRef(llvm::StringRef str,
74+
uint32_t num_uuid_bytes = 16);
7075

7176
// Decode as many UUID bytes (up to 16) as possible from the C string "cstr"
7277
// This is used for auto completion where a partial UUID might have been

‎lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo(
476476
image_infos[i].segments.push_back(segment);
477477
}
478478

479-
image_infos[i].uuid.SetFromStringRef(
479+
image_infos[i].uuid.SetFromOptionalStringRef(
480480
image->GetValueForKey("uuid")->GetAsString()->GetValue());
481481

482482
// All sections listed in the dyld image info structure will all either be

‎lldb/source/Utility/UUID.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,15 @@ size_t UUID::SetFromStringRef(llvm::StringRef str, uint32_t num_uuid_bytes) {
109109
// Else return zero to indicate we were not able to parse a UUID value
110110
return 0;
111111
}
112+
113+
size_t UUID::SetFromOptionalStringRef(llvm::StringRef str,
114+
uint32_t num_uuid_bytes) {
115+
size_t num_chars_consumed = SetFromStringRef(str, num_uuid_bytes);
116+
if (num_chars_consumed) {
117+
if (llvm::all_of(m_bytes, [](uint8_t b) { return b == 0; }))
118+
Clear();
119+
}
120+
121+
return num_chars_consumed;
122+
}
123+

‎lldb/unittests/Utility/UUIDTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ TEST(UUIDTest, Validity) {
4141
UUID a20 = UUID::fromData(zeroes.data(), 20);
4242
UUID a16_0 = UUID::fromOptionalData(zeroes.data(), 16);
4343
UUID a20_0 = UUID::fromOptionalData(zeroes.data(), 20);
44+
UUID from_str;
45+
from_str.SetFromStringRef("00000000-0000-0000-0000-000000000000");
46+
UUID opt_from_str;
47+
opt_from_str.SetFromOptionalStringRef("00000000-0000-0000-0000-000000000000");
48+
4449
EXPECT_FALSE(empty);
4550
EXPECT_TRUE(a16);
4651
EXPECT_TRUE(a20);
52+
EXPECT_TRUE(from_str);
4753
EXPECT_FALSE(a16_0);
4854
EXPECT_FALSE(a20_0);
55+
EXPECT_FALSE(opt_from_str);
4956
}
5057

5158
TEST(UUIDTest, SetFromStringRef) {

0 commit comments

Comments
 (0)
Please sign in to comment.