diff --git a/lldb/include/lldb/Utility/UUID.h b/lldb/include/lldb/Utility/UUID.h --- a/lldb/include/lldb/Utility/UUID.h +++ b/lldb/include/lldb/Utility/UUID.h @@ -21,6 +21,9 @@ class Stream; class UUID { + // Represents UUID's of various sizes. In all cases, a uuid of all zeros is + // treated as an "Invalid UUID" marker, and the UUID created from such data + // will return false for IsValid. public: UUID() = default; @@ -40,35 +43,16 @@ /// Create a UUID from CvRecordPdb70. static UUID fromCvRecord(CvRecordPdb70 debug_info); - /// Creates a UUID from the data pointed to by the bytes argument. No special - /// significance is attached to any of the values. + /// Creates a UUID from the data pointed to by the bytes argument. static UUID fromData(const void *bytes, uint32_t num_bytes) { if (bytes) return fromData({reinterpret_cast(bytes), num_bytes}); return UUID(); } - /// Creates a uuid from the data pointed to by the bytes argument. No special - /// significance is attached to any of the values. + /// Creates a uuid from the data pointed to by the bytes argument. static UUID fromData(llvm::ArrayRef bytes) { return UUID(bytes); } - /// Creates a UUID from the data pointed to by the bytes argument. Data - /// consisting purely of zero bytes is treated as an invalid UUID. - static UUID fromOptionalData(const void *bytes, uint32_t num_bytes) { - if (bytes) - return fromOptionalData( - {reinterpret_cast(bytes), num_bytes}); - return UUID(); - } - - /// Creates a UUID from the data pointed to by the bytes argument. Data - /// consisting purely of zero bytes is treated as an invalid UUID. - static UUID fromOptionalData(llvm::ArrayRef bytes) { - if (llvm::all_of(bytes, [](uint8_t b) { return b == 0; })) - return UUID(); - return UUID(bytes); - } - void Clear() { m_bytes.clear(); } void Dump(Stream *s) const; @@ -77,15 +61,11 @@ explicit operator bool() const { return IsValid(); } bool IsValid() const { return !m_bytes.empty(); } - + std::string GetAsString(llvm::StringRef separator = "-") const; bool SetFromStringRef(llvm::StringRef str); - // Same as SetFromStringRef, but if the resultant UUID is all 0 bytes, set the - // UUID to invalid. - bool SetFromOptionalStringRef(llvm::StringRef str); - /// Decode as many UUID bytes as possible from the C string \a cstr. /// /// \param[in] str @@ -103,7 +83,11 @@ llvm::SmallVectorImpl &uuid_bytes); private: - UUID(llvm::ArrayRef bytes) : m_bytes(bytes.begin(), bytes.end()) {} + UUID(llvm::ArrayRef bytes) : m_bytes(bytes.begin(), bytes.end()) { + if (llvm::all_of(m_bytes, [](uint8_t b) { return b == 0; })) { + Clear(); + } + } // GNU ld generates 20-byte build-ids. Size chosen to avoid heap allocations // for this case. diff --git a/lldb/source/API/SBModuleSpec.cpp b/lldb/source/API/SBModuleSpec.cpp --- a/lldb/source/API/SBModuleSpec.cpp +++ b/lldb/source/API/SBModuleSpec.cpp @@ -134,7 +134,7 @@ bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) { LLDB_INSTRUMENT_VA(this, uuid, uuid_len) - m_opaque_up->GetUUID() = UUID::fromOptionalData(uuid, uuid_len); + m_opaque_up->GetUUID() = UUID::fromData(uuid, uuid_len); return m_opaque_up->GetUUID().IsValid(); } diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp --- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp +++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp @@ -1389,7 +1389,7 @@ if (name_data == nullptr) break; image_infos[i].SetName((const char *)name_data); - UUID uuid = UUID::fromOptionalData(extractor.GetData(&offset, 16), 16); + UUID uuid = UUID::fromData(extractor.GetData(&offset, 16), 16); image_infos[i].SetUUID(uuid); image_infos[i].SetLoadAddress(extractor.GetU64(&offset)); image_infos[i].SetSize(extractor.GetU64(&offset)); diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp @@ -501,7 +501,7 @@ image_infos[i].segments.push_back(segment); } - image_infos[i].uuid.SetFromOptionalStringRef( + image_infos[i].uuid.SetFromStringRef( image->GetValueForKey("uuid")->GetAsString()->GetValue()); // All sections listed in the dyld image info structure will all either be diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -885,7 +885,7 @@ break; case llvm::MachO::LC_UUID: - dylib_info.uuid = UUID::fromOptionalData(data.GetData(&offset, 16), 16); + dylib_info.uuid = UUID::fromData(data.GetData(&offset, 16), 16); break; default: @@ -1093,7 +1093,7 @@ uuid_t shared_cache_uuid; if (m_process->ReadMemory(sharedCacheUUID_address, shared_cache_uuid, sizeof(uuid_t), err) == sizeof(uuid_t)) { - uuid = UUID::fromOptionalData(shared_cache_uuid, 16); + uuid = UUID::fromData(shared_cache_uuid, 16); if (uuid.IsValid()) { using_shared_cache = eLazyBoolYes; } diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -2177,7 +2177,7 @@ version_str[6] = '\0'; if (strcmp(version_str, "dyld_v") == 0) { offset = offsetof(struct lldb_copy_dyld_cache_header_v1, uuid); - dsc_uuid = UUID::fromOptionalData( + dsc_uuid = UUID::fromData( dsc_header_data.GetData(&offset, sizeof(uuid_t)), sizeof(uuid_t)); } Log *log = GetLog(LLDBLog::Symbols); @@ -2318,7 +2318,7 @@ const uint8_t *uuid_bytes = m_data.PeekData(offset, 16); if (uuid_bytes) - image_uuid = UUID::fromOptionalData(uuid_bytes, 16); + image_uuid = UUID::fromData(uuid_bytes, 16); break; } @@ -2715,7 +2715,7 @@ return; if (process_shared_cache_uuid.IsValid() && - process_shared_cache_uuid != UUID::fromOptionalData(&cache_uuid, 16)) + process_shared_cache_uuid != UUID::fromData(&cache_uuid, 16)) return; dyld_shared_cache_for_each_image(shared_cache, ^(dyld_image_t image) { @@ -2724,7 +2724,7 @@ return; dyld_image_copy_uuid(image, &dsc_image_uuid); - if (image_uuid != UUID::fromOptionalData(dsc_image_uuid, 16)) + if (image_uuid != UUID::fromData(dsc_image_uuid, 16)) return; found_image = true; @@ -4842,7 +4842,7 @@ if (!memcmp(uuid_bytes, opencl_uuid, 16)) return UUID(); - return UUID::fromOptionalData(uuid_bytes, 16); + return UUID::fromData(uuid_bytes, 16); } return UUID(); } @@ -5605,8 +5605,7 @@ } if (m_data.CopyData(offset, sizeof(uuid_t), raw_uuid) != 0) { - if (!uuid_is_null(raw_uuid)) - uuid = UUID::fromOptionalData(raw_uuid, sizeof(uuid_t)); + uuid = UUID::fromData(raw_uuid, sizeof(uuid_t)); // convert the "main bin spec" type into our // ObjectFile::BinaryType enum switch (binspec_type) { @@ -5901,7 +5900,7 @@ 100); // sharedCacheBaseAddress } } - uuid = UUID::fromOptionalData(sharedCacheUUID_address, sizeof(uuid_t)); + uuid = UUID::fromData(sharedCacheUUID_address, sizeof(uuid_t)); } } } else { @@ -5930,7 +5929,7 @@ dyld_process_info_get_cache(process_info, &sc_info); if (sc_info.cacheBaseAddress != 0) { base_addr = sc_info.cacheBaseAddress; - uuid = UUID::fromOptionalData(sc_info.cacheUUID, sizeof(uuid_t)); + uuid = UUID::fromData(sc_info.cacheUUID, sizeof(uuid_t)); } dyld_process_info_release(process_info); } @@ -6917,8 +6916,7 @@ MachOCorefileImageEntry image_entry; image_entry.filename = (const char *)m_data.GetCStr(&filepath_offset); - if (!uuid_is_null(uuid)) - image_entry.uuid = UUID::fromData(uuid, sizeof(uuid_t)); + image_entry.uuid = UUID::fromData(uuid, sizeof(uuid_t)); image_entry.load_address = load_address; image_entry.currently_executing = currently_executing; @@ -6949,8 +6947,7 @@ MachOCorefileImageEntry image_entry; image_entry.filename = filename; - if (!uuid_is_null(uuid)) - image_entry.uuid = UUID::fromData(uuid, sizeof(uuid_t)); + image_entry.uuid = UUID::fromData(uuid, sizeof(uuid_t)); image_entry.load_address = load_address; image_entry.slide = slide; image_entry.currently_executing = true; diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp --- a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp +++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp @@ -68,13 +68,13 @@ return UUID(); if (GetArchitecture().GetTriple().isOSBinFormatELF()) { if (pdb70_uuid->Age != 0) - return UUID::fromOptionalData(pdb70_uuid, sizeof(*pdb70_uuid)); - return UUID::fromOptionalData(&pdb70_uuid->Uuid, + return UUID::fromData(pdb70_uuid, sizeof(*pdb70_uuid)); + return UUID::fromData(&pdb70_uuid->Uuid, sizeof(pdb70_uuid->Uuid)); } return UUID::fromCvRecord(*pdb70_uuid); } else if (cv_signature == CvSignature::ElfBuildId) - return UUID::fromOptionalData(cv_record); + return UUID::fromData(cv_record); return UUID(); } diff --git a/lldb/source/Utility/UUID.cpp b/lldb/source/Utility/UUID.cpp --- a/lldb/source/Utility/UUID.cpp +++ b/lldb/source/Utility/UUID.cpp @@ -41,8 +41,8 @@ llvm::sys::swapByteOrder(debug_info.Uuid.Data3); llvm::sys::swapByteOrder(debug_info.Age); if (debug_info.Age) - return UUID::fromOptionalData(&debug_info, sizeof(debug_info)); - return UUID::fromOptionalData(&debug_info.Uuid, sizeof(debug_info.Uuid)); + return UUID::fromData(&debug_info, sizeof(debug_info)); + return UUID::fromData(&debug_info.Uuid, sizeof(debug_info.Uuid)); } std::string UUID::GetAsString(llvm::StringRef separator) const { @@ -110,13 +110,3 @@ *this = fromData(bytes); return true; } - -bool UUID::SetFromOptionalStringRef(llvm::StringRef str) { - bool result = SetFromStringRef(str); - if (result) { - if (llvm::all_of(m_bytes, [](uint8_t b) { return b == 0; })) - Clear(); - } - - return result; -} diff --git a/lldb/unittests/Utility/UUIDTest.cpp b/lldb/unittests/Utility/UUIDTest.cpp --- a/lldb/unittests/Utility/UUIDTest.cpp +++ b/lldb/unittests/Utility/UUIDTest.cpp @@ -39,20 +39,13 @@ std::vector zeroes(20, 0); UUID a16 = UUID::fromData(zeroes.data(), 16); 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); + EXPECT_FALSE(a16); + EXPECT_FALSE(a20); + EXPECT_FALSE(from_str); } TEST(UUIDTest, SetFromStringRef) {