Change the meaning of a UUID with all zeros for data.

Previously, depending on how you constructed a UUID from data or a
StringRef, an input value of all zeros was valid (e.g. setFromData)
or not (e.g. setFromOptionalData).  Since there was no way to tell
which interpretation to use, it was done somewhat inconsistently.
This standardizes the meaning of a UUID of all zeros to Not Valid,
and removes all the Optional methods and their uses, as well as the
static factories that supported them.

Differential Revision: https://reviews.llvm.org/D132191
This commit is contained in:
Jim Ingham 2022-08-18 17:20:55 -07:00
parent 52556c3c0f
commit 5ad6ed0e55
18 changed files with 83 additions and 118 deletions

View File

@ -21,9 +21,19 @@ namespace lldb_private {
class Stream; class Stream;
class UUID { 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: public:
UUID() = default; UUID() = default;
/// Creates a uuid from the data pointed to by the bytes argument.
UUID(llvm::ArrayRef<uint8_t> bytes) : m_bytes(bytes.begin(), bytes.end()) {
if (llvm::all_of(m_bytes, [](uint8_t b) { return b == 0; })) {
Clear();
}
}
// Reference: // Reference:
// https://crashpad.chromium.org/doxygen/structcrashpad_1_1CodeViewRecordPDB70.html // https://crashpad.chromium.org/doxygen/structcrashpad_1_1CodeViewRecordPDB70.html
struct CvRecordPdb70 { struct CvRecordPdb70 {
@ -38,35 +48,15 @@ public:
}; };
/// Create a UUID from CvRecordPdb70. /// Create a UUID from CvRecordPdb70.
static UUID fromCvRecord(CvRecordPdb70 debug_info); UUID(CvRecordPdb70 debug_info);
/// Creates a UUID from the data pointed to by the bytes argument. No special /// Creates a UUID from the data pointed to by the bytes argument.
/// significance is attached to any of the values. UUID(const void *bytes, uint32_t num_bytes) {
static UUID fromData(const void *bytes, uint32_t num_bytes) { if (!bytes)
if (bytes) return;
return fromData({reinterpret_cast<const uint8_t *>(bytes), num_bytes}); *this
return UUID(); = UUID(llvm::ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(bytes),
} num_bytes));
/// Creates a uuid from the data pointed to by the bytes argument. No special
/// significance is attached to any of the values.
static UUID fromData(llvm::ArrayRef<uint8_t> 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<const uint8_t *>(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<uint8_t> bytes) {
if (llvm::all_of(bytes, [](uint8_t b) { return b == 0; }))
return UUID();
return UUID(bytes);
} }
void Clear() { m_bytes.clear(); } void Clear() { m_bytes.clear(); }
@ -82,10 +72,6 @@ public:
bool SetFromStringRef(llvm::StringRef str); 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. /// Decode as many UUID bytes as possible from the C string \a cstr.
/// ///
/// \param[in] str /// \param[in] str
@ -103,8 +89,6 @@ public:
llvm::SmallVectorImpl<uint8_t> &uuid_bytes); llvm::SmallVectorImpl<uint8_t> &uuid_bytes);
private: private:
UUID(llvm::ArrayRef<uint8_t> bytes) : m_bytes(bytes.begin(), bytes.end()) {}
// GNU ld generates 20-byte build-ids. Size chosen to avoid heap allocations // GNU ld generates 20-byte build-ids. Size chosen to avoid heap allocations
// for this case. // for this case.
llvm::SmallVector<uint8_t, 20> m_bytes; llvm::SmallVector<uint8_t, 20> m_bytes;

View File

@ -134,7 +134,7 @@ size_t SBModuleSpec::GetUUIDLength() {
bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) { bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) {
LLDB_INSTRUMENT_VA(this, uuid, uuid_len) LLDB_INSTRUMENT_VA(this, uuid, uuid_len)
m_opaque_up->GetUUID() = UUID::fromOptionalData(uuid, uuid_len); m_opaque_up->GetUUID() = UUID(uuid, uuid_len);
return m_opaque_up->GetUUID().IsValid(); return m_opaque_up->GetUUID().IsValid();
} }

View File

@ -238,7 +238,7 @@ bool CacheSignature::Decode(const lldb_private::DataExtractor &data,
const uint8_t length = data.GetU8(offset_ptr); const uint8_t length = data.GetU8(offset_ptr);
const uint8_t *bytes = (const uint8_t *)data.GetData(offset_ptr, length); const uint8_t *bytes = (const uint8_t *)data.GetData(offset_ptr, length);
if (bytes != nullptr && length > 0) if (bytes != nullptr && length > 0)
m_uuid = UUID::fromData(llvm::ArrayRef<uint8_t>(bytes, length)); m_uuid = UUID(llvm::ArrayRef<uint8_t>(bytes, length));
} break; } break;
case eSignatureModTime: { case eSignatureModTime: {
uint32_t mod_time = data.GetU32(offset_ptr); uint32_t mod_time = data.GetU32(offset_ptr);

View File

@ -565,7 +565,7 @@ bool SharedCacheInfo::CreateSharedCacheInfoWithInstrospectionSPIs() {
assert(minVmAddr != UINT_MAX); assert(minVmAddr != UINT_MAX);
assert(maxVmAddr != 0); assert(maxVmAddr != 0);
m_images[dyld_image_get_installname(image)] = SharedCacheImageInfo{ m_images[dyld_image_get_installname(image)] = SharedCacheImageInfo{
UUID::fromData(uuid, 16), UUID(uuid, 16),
std::make_shared<DataBufferUnowned>((uint8_t *)minVmAddr, std::make_shared<DataBufferUnowned>((uint8_t *)minVmAddr,
maxVmAddr - minVmAddr)}; maxVmAddr - minVmAddr)};
}); });
@ -585,12 +585,12 @@ SharedCacheInfo::SharedCacheInfo() {
_dyld_get_shared_cache_range(&shared_cache_size); _dyld_get_shared_cache_range(&shared_cache_size);
uuid_t dsc_uuid; uuid_t dsc_uuid;
_dyld_get_shared_cache_uuid(dsc_uuid); _dyld_get_shared_cache_uuid(dsc_uuid);
m_uuid = UUID::fromData(dsc_uuid); m_uuid = UUID(dsc_uuid);
dyld_shared_cache_iterate_text( dyld_shared_cache_iterate_text(
dsc_uuid, ^(const dyld_shared_cache_dylib_text_info *info) { dsc_uuid, ^(const dyld_shared_cache_dylib_text_info *info) {
m_images[info->path] = SharedCacheImageInfo{ m_images[info->path] = SharedCacheImageInfo{
UUID::fromData(info->dylibUuid, 16), UUID(info->dylibUuid, 16),
std::make_shared<DataBufferUnowned>( std::make_shared<DataBufferUnowned>(
shared_cache_start + info->textSegmentOffset, shared_cache_start + info->textSegmentOffset,
shared_cache_size - info->textSegmentOffset)}; shared_cache_size - info->textSegmentOffset)};

View File

@ -1389,7 +1389,7 @@ uint32_t DynamicLoaderDarwinKernel::ReadKextSummaries(
if (name_data == nullptr) if (name_data == nullptr)
break; break;
image_infos[i].SetName((const char *)name_data); image_infos[i].SetName((const char *)name_data);
UUID uuid = UUID::fromOptionalData(extractor.GetData(&offset, 16), 16); UUID uuid(extractor.GetData(&offset, 16), 16);
image_infos[i].SetUUID(uuid); image_infos[i].SetUUID(uuid);
image_infos[i].SetLoadAddress(extractor.GetU64(&offset)); image_infos[i].SetLoadAddress(extractor.GetU64(&offset));
image_infos[i].SetSize(extractor.GetU64(&offset)); image_infos[i].SetSize(extractor.GetU64(&offset));

View File

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

View File

@ -885,7 +885,7 @@ uint32_t DynamicLoaderMacOSXDYLD::ParseLoadCommands(const DataExtractor &data,
break; break;
case llvm::MachO::LC_UUID: case llvm::MachO::LC_UUID:
dylib_info.uuid = UUID::fromOptionalData(data.GetData(&offset, 16), 16); dylib_info.uuid = UUID(data.GetData(&offset, 16), 16);
break; break;
default: default:
@ -1093,7 +1093,7 @@ bool DynamicLoaderMacOSXDYLD::GetSharedCacheInformation(
uuid_t shared_cache_uuid; uuid_t shared_cache_uuid;
if (m_process->ReadMemory(sharedCacheUUID_address, shared_cache_uuid, if (m_process->ReadMemory(sharedCacheUUID_address, shared_cache_uuid,
sizeof(uuid_t), err) == sizeof(uuid_t)) { sizeof(uuid_t), err) == sizeof(uuid_t)) {
uuid = UUID::fromOptionalData(shared_cache_uuid, 16); uuid = UUID(shared_cache_uuid, 16);
if (uuid.IsValid()) { if (uuid.IsValid()) {
using_shared_cache = eLazyBoolYes; using_shared_cache = eLazyBoolYes;
} }

View File

@ -122,7 +122,7 @@ static UUID parseModuleId(llvm::Triple::OSType os, llvm::StringRef str) {
// On non-windows, the age field should always be zero, so we don't include to // On non-windows, the age field should always be zero, so we don't include to
// match the native uuid format of these platforms. // match the native uuid format of these platforms.
return UUID::fromData(&data, os == llvm::Triple::Win32 ? sizeof(data) return UUID(&data, os == llvm::Triple::Win32 ? sizeof(data)
: sizeof(data.uuid)); : sizeof(data.uuid));
} }

View File

@ -627,13 +627,13 @@ size_t ObjectFileELF::GetModuleSpecifications(
if (gnu_debuglink_crc) { if (gnu_debuglink_crc) {
// Use 4 bytes of crc from the .gnu_debuglink section. // Use 4 bytes of crc from the .gnu_debuglink section.
u32le data(gnu_debuglink_crc); u32le data(gnu_debuglink_crc);
uuid = UUID::fromData(&data, sizeof(data)); uuid = UUID(&data, sizeof(data));
} else if (core_notes_crc) { } else if (core_notes_crc) {
// Use 8 bytes - first 4 bytes for *magic* prefix, mainly to make // Use 8 bytes - first 4 bytes for *magic* prefix, mainly to make
// it look different form .gnu_debuglink crc followed by 4 bytes // it look different form .gnu_debuglink crc followed by 4 bytes
// of note segments crc. // of note segments crc.
u32le data[] = {u32le(g_core_uuid_magic), u32le(core_notes_crc)}; u32le data[] = {u32le(g_core_uuid_magic), u32le(core_notes_crc)};
uuid = UUID::fromData(data, sizeof(data)); uuid = UUID(data, sizeof(data));
} }
} }
@ -788,7 +788,7 @@ UUID ObjectFileELF::GetUUID() {
// look different form .gnu_debuglink crc - followed by 4 bytes of note // look different form .gnu_debuglink crc - followed by 4 bytes of note
// segments crc. // segments crc.
u32le data[] = {u32le(g_core_uuid_magic), u32le(core_notes_crc)}; u32le data[] = {u32le(g_core_uuid_magic), u32le(core_notes_crc)};
m_uuid = UUID::fromData(data, sizeof(data)); m_uuid = UUID(data, sizeof(data));
} }
} else { } else {
if (!m_gnu_debuglink_crc) if (!m_gnu_debuglink_crc)
@ -796,7 +796,7 @@ UUID ObjectFileELF::GetUUID() {
if (m_gnu_debuglink_crc) { if (m_gnu_debuglink_crc) {
// Use 4 bytes of crc from the .gnu_debuglink section. // Use 4 bytes of crc from the .gnu_debuglink section.
u32le data(m_gnu_debuglink_crc); u32le data(m_gnu_debuglink_crc);
m_uuid = UUID::fromData(&data, sizeof(data)); m_uuid = UUID(&data, sizeof(data));
} }
} }
} }
@ -1134,7 +1134,7 @@ ObjectFileELF::RefineModuleDetailsFromNote(lldb_private::DataExtractor &data,
if (note.n_descsz >= 4) { if (note.n_descsz >= 4) {
if (const uint8_t *buf = data.PeekData(offset, note.n_descsz)) { if (const uint8_t *buf = data.PeekData(offset, note.n_descsz)) {
// Save the build id as the UUID for the module. // Save the build id as the UUID for the module.
uuid = UUID::fromData(buf, note.n_descsz); uuid = UUID(buf, note.n_descsz);
} else { } else {
error.SetErrorString("failed to read GNU_BUILD_ID note payload"); error.SetErrorString("failed to read GNU_BUILD_ID note payload");
return error; return error;

View File

@ -2188,8 +2188,8 @@ UUID ObjectFileMachO::GetSharedCacheUUID(FileSpec dyld_shared_cache,
version_str[6] = '\0'; version_str[6] = '\0';
if (strcmp(version_str, "dyld_v") == 0) { if (strcmp(version_str, "dyld_v") == 0) {
offset = offsetof(struct lldb_copy_dyld_cache_header_v1, uuid); offset = offsetof(struct lldb_copy_dyld_cache_header_v1, uuid);
dsc_uuid = UUID::fromOptionalData( dsc_uuid = UUID(dsc_header_data.GetData(&offset, sizeof(uuid_t)),
dsc_header_data.GetData(&offset, sizeof(uuid_t)), sizeof(uuid_t)); sizeof(uuid_t));
} }
Log *log = GetLog(LLDBLog::Symbols); Log *log = GetLog(LLDBLog::Symbols);
if (log && dsc_uuid.IsValid()) { if (log && dsc_uuid.IsValid()) {
@ -2329,7 +2329,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
const uint8_t *uuid_bytes = m_data.PeekData(offset, 16); const uint8_t *uuid_bytes = m_data.PeekData(offset, 16);
if (uuid_bytes) if (uuid_bytes)
image_uuid = UUID::fromOptionalData(uuid_bytes, 16); image_uuid = UUID(uuid_bytes, 16);
break; break;
} }
@ -2726,7 +2726,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
return; return;
if (process_shared_cache_uuid.IsValid() && 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; return;
dyld_shared_cache_for_each_image(shared_cache, ^(dyld_image_t image) { dyld_shared_cache_for_each_image(shared_cache, ^(dyld_image_t image) {
@ -2735,7 +2735,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
return; return;
dyld_image_copy_uuid(image, &dsc_image_uuid); 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; return;
found_image = true; found_image = true;
@ -4853,7 +4853,7 @@ UUID ObjectFileMachO::GetUUID(const llvm::MachO::mach_header &header,
if (!memcmp(uuid_bytes, opencl_uuid, 16)) if (!memcmp(uuid_bytes, opencl_uuid, 16))
return UUID(); return UUID();
return UUID::fromOptionalData(uuid_bytes, 16); return UUID(uuid_bytes, 16);
} }
return UUID(); return UUID();
} }
@ -5616,8 +5616,7 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t &value,
} }
if (m_data.CopyData(offset, sizeof(uuid_t), raw_uuid) != 0) { if (m_data.CopyData(offset, sizeof(uuid_t), raw_uuid) != 0) {
if (!uuid_is_null(raw_uuid)) uuid = UUID(raw_uuid, sizeof(uuid_t));
uuid = UUID::fromOptionalData(raw_uuid, sizeof(uuid_t));
// convert the "main bin spec" type into our // convert the "main bin spec" type into our
// ObjectFile::BinaryType enum // ObjectFile::BinaryType enum
switch (binspec_type) { switch (binspec_type) {
@ -5912,7 +5911,7 @@ void ObjectFileMachO::GetLLDBSharedCacheUUID(addr_t &base_addr, UUID &uuid) {
100); // sharedCacheBaseAddress <mach-o/dyld_images.h> 100); // sharedCacheBaseAddress <mach-o/dyld_images.h>
} }
} }
uuid = UUID::fromOptionalData(sharedCacheUUID_address, sizeof(uuid_t)); uuid = UUID(sharedCacheUUID_address, sizeof(uuid_t));
} }
} }
} else { } else {
@ -5941,7 +5940,7 @@ void ObjectFileMachO::GetLLDBSharedCacheUUID(addr_t &base_addr, UUID &uuid) {
dyld_process_info_get_cache(process_info, &sc_info); dyld_process_info_get_cache(process_info, &sc_info);
if (sc_info.cacheBaseAddress != 0) { if (sc_info.cacheBaseAddress != 0) {
base_addr = sc_info.cacheBaseAddress; base_addr = sc_info.cacheBaseAddress;
uuid = UUID::fromOptionalData(sc_info.cacheUUID, sizeof(uuid_t)); uuid = UUID(sc_info.cacheUUID, sizeof(uuid_t));
} }
dyld_process_info_release(process_info); dyld_process_info_release(process_info);
} }
@ -6928,8 +6927,7 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
MachOCorefileImageEntry image_entry; MachOCorefileImageEntry image_entry;
image_entry.filename = (const char *)m_data.GetCStr(&filepath_offset); image_entry.filename = (const char *)m_data.GetCStr(&filepath_offset);
if (!uuid_is_null(uuid)) image_entry.uuid = UUID(uuid, sizeof(uuid_t));
image_entry.uuid = UUID::fromData(uuid, sizeof(uuid_t));
image_entry.load_address = load_address; image_entry.load_address = load_address;
image_entry.currently_executing = currently_executing; image_entry.currently_executing = currently_executing;
@ -6960,8 +6958,7 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
MachOCorefileImageEntry image_entry; MachOCorefileImageEntry image_entry;
image_entry.filename = filename; image_entry.filename = filename;
if (!uuid_is_null(uuid)) image_entry.uuid = UUID(uuid, sizeof(uuid_t));
image_entry.uuid = UUID::fromData(uuid, sizeof(uuid_t));
image_entry.load_address = load_address; image_entry.load_address = load_address;
image_entry.slide = slide; image_entry.slide = slide;
image_entry.currently_executing = true; image_entry.currently_executing = true;

View File

@ -31,7 +31,7 @@ static UUID GetPDBUUID(InfoStream &IS) {
UUID::CvRecordPdb70 debug_info; UUID::CvRecordPdb70 debug_info;
memcpy(&debug_info.Uuid, IS.getGuid().Guid, sizeof(debug_info.Uuid)); memcpy(&debug_info.Uuid, IS.getGuid().Guid, sizeof(debug_info.Uuid));
debug_info.Age = IS.getAge(); debug_info.Age = IS.getAge();
return UUID::fromCvRecord(debug_info); return UUID(debug_info);
} }
char ObjectFilePDB::ID; char ObjectFilePDB::ID;

View File

@ -147,7 +147,7 @@ static UUID GetCoffUUID(llvm::object::COFFObjectFile &coff_obj) {
UUID::CvRecordPdb70 info; UUID::CvRecordPdb70 info;
memcpy(&info.Uuid, pdb_info->PDB70.Signature, sizeof(info.Uuid)); memcpy(&info.Uuid, pdb_info->PDB70.Signature, sizeof(info.Uuid));
info.Age = pdb_info->PDB70.Age; info.Age = pdb_info->PDB70.Age;
return UUID::fromCvRecord(info); return UUID(info);
} }
} }
@ -170,7 +170,7 @@ static UUID GetCoffUUID(llvm::object::COFFObjectFile &coff_obj) {
} }
// Use 4 bytes of crc from the .gnu_debuglink section. // Use 4 bytes of crc from the .gnu_debuglink section.
llvm::support::ulittle32_t data(gnu_debuglink_crc); llvm::support::ulittle32_t data(gnu_debuglink_crc);
return UUID::fromData(&data, sizeof(data)); return UUID(&data, sizeof(data));
} }
char ObjectFilePECOFF::ID; char ObjectFilePECOFF::ID;

View File

@ -68,13 +68,13 @@ UUID MinidumpParser::GetModuleUUID(const minidump::Module *module) {
return UUID(); return UUID();
if (GetArchitecture().GetTriple().isOSBinFormatELF()) { if (GetArchitecture().GetTriple().isOSBinFormatELF()) {
if (pdb70_uuid->Age != 0) if (pdb70_uuid->Age != 0)
return UUID::fromOptionalData(pdb70_uuid, sizeof(*pdb70_uuid)); return UUID(pdb70_uuid, sizeof(*pdb70_uuid));
return UUID::fromOptionalData(&pdb70_uuid->Uuid, return UUID(&pdb70_uuid->Uuid,
sizeof(pdb70_uuid->Uuid)); sizeof(pdb70_uuid->Uuid));
} }
return UUID::fromCvRecord(*pdb70_uuid); return UUID(*pdb70_uuid);
} else if (cv_signature == CvSignature::ElfBuildId) } else if (cv_signature == CvSignature::ElfBuildId)
return UUID::fromOptionalData(cv_record); return UUID(cv_record);
return UUID(); return UUID();
} }

View File

@ -35,14 +35,15 @@ static inline bool separate(size_t count) {
} }
} }
UUID UUID::fromCvRecord(UUID::CvRecordPdb70 debug_info) { UUID::UUID(UUID::CvRecordPdb70 debug_info) {
llvm::sys::swapByteOrder(debug_info.Uuid.Data1); llvm::sys::swapByteOrder(debug_info.Uuid.Data1);
llvm::sys::swapByteOrder(debug_info.Uuid.Data2); llvm::sys::swapByteOrder(debug_info.Uuid.Data2);
llvm::sys::swapByteOrder(debug_info.Uuid.Data3); llvm::sys::swapByteOrder(debug_info.Uuid.Data3);
llvm::sys::swapByteOrder(debug_info.Age); llvm::sys::swapByteOrder(debug_info.Age);
if (debug_info.Age) if (debug_info.Age)
return UUID::fromOptionalData(&debug_info, sizeof(debug_info)); *this = UUID(&debug_info, sizeof(debug_info));
return UUID::fromOptionalData(&debug_info.Uuid, sizeof(debug_info.Uuid)); else
*this = UUID(&debug_info.Uuid, sizeof(debug_info.Uuid));
} }
std::string UUID::GetAsString(llvm::StringRef separator) const { std::string UUID::GetAsString(llvm::StringRef separator) const {
@ -107,16 +108,6 @@ bool UUID::SetFromStringRef(llvm::StringRef str) {
if (!rest.empty() || bytes.empty()) if (!rest.empty() || bytes.empty())
return false; return false;
*this = fromData(bytes); *this = UUID(bytes);
return true; 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;
}

View File

@ -37,7 +37,7 @@ TEST(Record, classify) {
TEST(ModuleRecord, parse) { TEST(ModuleRecord, parse) {
EXPECT_EQ(ModuleRecord(llvm::Triple::Linux, llvm::Triple::x86_64, EXPECT_EQ(ModuleRecord(llvm::Triple::Linux, llvm::Triple::x86_64,
UUID::fromData("@ABCDEFGHIJKLMNO", 16)), UUID("@ABCDEFGHIJKLMNO", 16)),
ModuleRecord::parse( ModuleRecord::parse(
"MODULE Linux x86_64 404142434445464748494a4b4c4d4e4f0 a.out")); "MODULE Linux x86_64 404142434445464748494a4b4c4d4e4f0 a.out"));
@ -49,7 +49,7 @@ TEST(ModuleRecord, parse) {
} }
TEST(InfoRecord, parse) { TEST(InfoRecord, parse) {
EXPECT_EQ(InfoRecord(UUID::fromData("@ABCDEFGHIJKLMNO", 16)), EXPECT_EQ(InfoRecord(UUID("@ABCDEFGHIJKLMNO", 16)),
InfoRecord::parse("INFO CODE_ID 404142434445464748494a4b4c4d4e4f")); InfoRecord::parse("INFO CODE_ID 404142434445464748494a4b4c4d4e4f"));
EXPECT_EQ(InfoRecord(UUID()), InfoRecord::parse("INFO CODE_ID 47 a.exe")); EXPECT_EQ(InfoRecord(UUID()), InfoRecord::parse("INFO CODE_ID 47 a.exe"));

View File

@ -194,7 +194,7 @@ TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfo) {
ASSERT_EQ(1u, result->size()); ASSERT_EQ(1u, result->size());
EXPECT_EQ("/foo/bar.so", result.value()[0].GetFileSpec().GetPath()); EXPECT_EQ("/foo/bar.so", result.value()[0].GetFileSpec().GetPath());
EXPECT_EQ(triple, result.value()[0].GetArchitecture().GetTriple()); EXPECT_EQ(triple, result.value()[0].GetArchitecture().GetTriple());
EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNO", 16), EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16),
result.value()[0].GetUUID()); result.value()[0].GetUUID());
EXPECT_EQ(0u, result.value()[0].GetObjectOffset()); EXPECT_EQ(0u, result.value()[0].GetObjectOffset());
EXPECT_EQ(1234u, result.value()[0].GetObjectSize()); EXPECT_EQ(1234u, result.value()[0].GetObjectSize());
@ -219,7 +219,7 @@ TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfo_UUID20) {
ASSERT_EQ(1u, result->size()); ASSERT_EQ(1u, result->size());
EXPECT_EQ("/foo/bar.so", result.value()[0].GetFileSpec().GetPath()); EXPECT_EQ("/foo/bar.so", result.value()[0].GetFileSpec().GetPath());
EXPECT_EQ(triple, result.value()[0].GetArchitecture().GetTriple()); EXPECT_EQ(triple, result.value()[0].GetArchitecture().GetTriple());
EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNOPQRS", 20), EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20),
result.value()[0].GetUUID()); result.value()[0].GetUUID());
EXPECT_EQ(0u, result.value()[0].GetObjectOffset()); EXPECT_EQ(0u, result.value()[0].GetObjectOffset());
EXPECT_EQ(1234u, result.value()[0].GetObjectSize()); EXPECT_EQ(1234u, result.value()[0].GetObjectSize());

View File

@ -231,7 +231,7 @@ TEST(DWARFIndexCachingTest, CacheSignatureTests) {
EncodeDecode(sig, /*encode_result=*/false); EncodeDecode(sig, /*encode_result=*/false);
sig.Clear(); sig.Clear();
sig.m_uuid = UUID::fromData("@\x00\x11\x22\x33\x44\x55\x66\x77", 8); sig.m_uuid = UUID("@\x00\x11\x22\x33\x44\x55\x66\x77", 8);
EXPECT_TRUE(sig.IsValid()); EXPECT_TRUE(sig.IsValid());
EncodeDecode(sig, /*encode_result=*/true); EncodeDecode(sig, /*encode_result=*/true);
sig.m_mod_time = 0x12345678; sig.m_mod_time = 0x12345678;

View File

@ -14,10 +14,10 @@ using namespace lldb_private;
TEST(UUIDTest, RelationalOperators) { TEST(UUIDTest, RelationalOperators) {
UUID empty; UUID empty;
UUID a16 = UUID::fromData("1234567890123456", 16); UUID a16 = UUID("1234567890123456", 16);
UUID b16 = UUID::fromData("1234567890123457", 16); UUID b16 = UUID("1234567890123457", 16);
UUID a20 = UUID::fromData("12345678901234567890", 20); UUID a20 = UUID("12345678901234567890", 20);
UUID b20 = UUID::fromData("12345678900987654321", 20); UUID b20 = UUID("12345678900987654321", 20);
EXPECT_EQ(empty, empty); EXPECT_EQ(empty, empty);
EXPECT_EQ(a16, a16); EXPECT_EQ(a16, a16);
@ -37,59 +37,52 @@ TEST(UUIDTest, RelationalOperators) {
TEST(UUIDTest, Validity) { TEST(UUIDTest, Validity) {
UUID empty; UUID empty;
std::vector<uint8_t> zeroes(20, 0); std::vector<uint8_t> zeroes(20, 0);
UUID a16 = UUID::fromData(zeroes.data(), 16); UUID a16 = UUID(zeroes.data(), 16);
UUID a20 = UUID::fromData(zeroes.data(), 20); UUID a20 = UUID(zeroes.data(), 20);
UUID a16_0 = UUID::fromOptionalData(zeroes.data(), 16);
UUID a20_0 = UUID::fromOptionalData(zeroes.data(), 20);
UUID from_str; UUID from_str;
from_str.SetFromStringRef("00000000-0000-0000-0000-000000000000"); 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_FALSE(empty);
EXPECT_TRUE(a16); EXPECT_FALSE(a16);
EXPECT_TRUE(a20); EXPECT_FALSE(a20);
EXPECT_TRUE(from_str); EXPECT_FALSE(from_str);
EXPECT_FALSE(a16_0);
EXPECT_FALSE(a20_0);
EXPECT_FALSE(opt_from_str);
} }
TEST(UUIDTest, SetFromStringRef) { TEST(UUIDTest, SetFromStringRef) {
UUID u; UUID u;
EXPECT_TRUE(u.SetFromStringRef("404142434445464748494a4b4c4d4e4f")); EXPECT_TRUE(u.SetFromStringRef("404142434445464748494a4b4c4d4e4f"));
EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNO", 16), u); EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u);
EXPECT_TRUE(u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f")); EXPECT_TRUE(u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f"));
EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNO", 16), u); EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u);
EXPECT_TRUE( EXPECT_TRUE(
u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f-50515253")); u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f-50515253"));
EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNOPQRS", 20), u); EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20), u);
EXPECT_TRUE(u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f")); EXPECT_TRUE(u.SetFromStringRef("40-41-42-43-4445464748494a4b4c4d4e4f"));
EXPECT_FALSE(u.SetFromStringRef("40xxxxx")); EXPECT_FALSE(u.SetFromStringRef("40xxxxx"));
EXPECT_FALSE(u.SetFromStringRef("")); EXPECT_FALSE(u.SetFromStringRef(""));
EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNO", 16), u) EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u)
<< "uuid was changed by failed parse calls"; << "uuid was changed by failed parse calls";
EXPECT_TRUE(u.SetFromStringRef("404142434445464748494a4b4c4d4e4f-50515253")); EXPECT_TRUE(u.SetFromStringRef("404142434445464748494a4b4c4d4e4f-50515253"));
EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNOPQRS", 20), u); EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20), u);
EXPECT_TRUE(u.SetFromStringRef("40414243")); EXPECT_TRUE(u.SetFromStringRef("40414243"));
EXPECT_EQ(UUID::fromData("@ABCD", 4), u); EXPECT_EQ(UUID("@ABCD", 4), u);
EXPECT_FALSE(u.SetFromStringRef("4")); EXPECT_FALSE(u.SetFromStringRef("4"));
} }
TEST(UUIDTest, StringConverion) { TEST(UUIDTest, StringConverion) {
EXPECT_EQ("40414243", UUID::fromData("@ABC", 4).GetAsString()); EXPECT_EQ("40414243", UUID("@ABC", 4).GetAsString());
EXPECT_EQ("40414243-4445-4647", UUID::fromData("@ABCDEFG", 8).GetAsString()); EXPECT_EQ("40414243-4445-4647", UUID("@ABCDEFG", 8).GetAsString());
EXPECT_EQ("40414243-4445-4647-4849-4A4B", EXPECT_EQ("40414243-4445-4647-4849-4A4B",
UUID::fromData("@ABCDEFGHIJK", 12).GetAsString()); UUID("@ABCDEFGHIJK", 12).GetAsString());
EXPECT_EQ("40414243-4445-4647-4849-4A4B4C4D4E4F", EXPECT_EQ("40414243-4445-4647-4849-4A4B4C4D4E4F",
UUID::fromData("@ABCDEFGHIJKLMNO", 16).GetAsString()); UUID("@ABCDEFGHIJKLMNO", 16).GetAsString());
EXPECT_EQ("40414243-4445-4647-4849-4A4B4C4D4E4F-50515253", EXPECT_EQ("40414243-4445-4647-4849-4A4B4C4D4E4F-50515253",
UUID::fromData("@ABCDEFGHIJKLMNOPQRS", 20).GetAsString()); UUID("@ABCDEFGHIJKLMNOPQRS", 20).GetAsString());
} }