[Lldb-commits] [lldb] 5ad6ed0 - Change the meaning of a UUID with all zeros for data.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 30 10:18:41 PDT 2022


Author: Jim Ingham
Date: 2022-08-30T10:17:58-07:00
New Revision: 5ad6ed0e5519ed26442cd0a21cdb07f5c53b854e

URL: https://github.com/llvm/llvm-project/commit/5ad6ed0e5519ed26442cd0a21cdb07f5c53b854e
DIFF: https://github.com/llvm/llvm-project/commit/5ad6ed0e5519ed26442cd0a21cdb07f5c53b854e.diff

LOG: 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

Added: 
    

Modified: 
    lldb/include/lldb/Utility/UUID.h
    lldb/source/API/SBModuleSpec.cpp
    lldb/source/Core/DataFileCache.cpp
    lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
    lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
    lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
    lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
    lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
    lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
    lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
    lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
    lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
    lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
    lldb/source/Utility/UUID.cpp
    lldb/unittests/ObjectFile/Breakpad/BreakpadRecordsTest.cpp
    lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
    lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp
    lldb/unittests/Utility/UUIDTest.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Utility/UUID.h b/lldb/include/lldb/Utility/UUID.h
index 1c7c04758da0..56aa3fa8450b 100644
--- a/lldb/include/lldb/Utility/UUID.h
+++ b/lldb/include/lldb/Utility/UUID.h
@@ -21,8 +21,18 @@ namespace lldb_private {
   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;
+  
+  /// 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:
   // https://crashpad.chromium.org/doxygen/structcrashpad_1_1CodeViewRecordPDB70.html
@@ -38,35 +48,15 @@ class UUID {
   };
 
   /// 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.
-  static UUID fromData(const void *bytes, uint32_t num_bytes) {
-    if (bytes)
-      return fromData({reinterpret_cast<const uint8_t *>(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.
-  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);
+  UUID(CvRecordPdb70 debug_info);
+
+  /// Creates a UUID from the data pointed to by the bytes argument. 
+  UUID(const void *bytes, uint32_t num_bytes) {
+    if (!bytes)
+      return;
+    *this 
+        = UUID(llvm::ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(bytes), 
+               num_bytes));
   }
 
   void Clear() { m_bytes.clear(); }
@@ -77,15 +67,11 @@ class UUID {
 
   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,8 +89,6 @@ class UUID {
                             llvm::SmallVectorImpl<uint8_t> &uuid_bytes);
 
 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
   // for this case.
   llvm::SmallVector<uint8_t, 20> m_bytes;

diff  --git a/lldb/source/API/SBModuleSpec.cpp b/lldb/source/API/SBModuleSpec.cpp
index 7deba8e971f8..83b1b6b74941 100644
--- a/lldb/source/API/SBModuleSpec.cpp
+++ b/lldb/source/API/SBModuleSpec.cpp
@@ -134,7 +134,7 @@ size_t SBModuleSpec::GetUUIDLength() {
 
 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(uuid, uuid_len);
   return m_opaque_up->GetUUID().IsValid();
 }
 

diff  --git a/lldb/source/Core/DataFileCache.cpp b/lldb/source/Core/DataFileCache.cpp
index 07c6839f0149..a678cd91efb8 100644
--- a/lldb/source/Core/DataFileCache.cpp
+++ b/lldb/source/Core/DataFileCache.cpp
@@ -238,7 +238,7 @@ bool CacheSignature::Decode(const lldb_private::DataExtractor &data,
       const uint8_t length = data.GetU8(offset_ptr);
       const uint8_t *bytes = (const uint8_t *)data.GetData(offset_ptr, length);
       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;
     case eSignatureModTime: {
       uint32_t mod_time = data.GetU32(offset_ptr);

diff  --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
index 4cb9f5ddbb0e..11590be56fbc 100644
--- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
@@ -565,7 +565,7 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
         assert(minVmAddr != UINT_MAX);
         assert(maxVmAddr != 0);
         m_images[dyld_image_get_installname(image)] = SharedCacheImageInfo{
-            UUID::fromData(uuid, 16),
+            UUID(uuid, 16),
             std::make_shared<DataBufferUnowned>((uint8_t *)minVmAddr,
                                                 maxVmAddr - minVmAddr)};
       });
@@ -585,12 +585,12 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
       _dyld_get_shared_cache_range(&shared_cache_size);
   uuid_t 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(
       dsc_uuid, ^(const dyld_shared_cache_dylib_text_info *info) {
         m_images[info->path] = SharedCacheImageInfo{
-            UUID::fromData(info->dylibUuid, 16),
+            UUID(info->dylibUuid, 16),
             std::make_shared<DataBufferUnowned>(
                 shared_cache_start + info->textSegmentOffset,
                 shared_cache_size - info->textSegmentOffset)};

diff  --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index 74c501d3dbb0..93f8f222b296 100644
--- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -1389,7 +1389,7 @@ uint32_t DynamicLoaderDarwinKernel::ReadKextSummaries(
       if (name_data == nullptr)
         break;
       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].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
index 3f185fac269e..d6c890c64b98 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -501,7 +501,7 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo(
       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
index 832057eb3308..26bc26432307 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -885,7 +885,7 @@ uint32_t DynamicLoaderMacOSXDYLD::ParseLoadCommands(const DataExtractor &data,
         break;
 
       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;
 
       default:
@@ -1093,7 +1093,7 @@ bool DynamicLoaderMacOSXDYLD::GetSharedCacheInformation(
         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(shared_cache_uuid, 16);
           if (uuid.IsValid()) {
             using_shared_cache = eLazyBoolYes;
           }

diff  --git a/lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp b/lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
index bd5624099dc5..0c1b36514d26 100644
--- a/lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
+++ b/lldb/source/Plugins/ObjectFile/Breakpad/BreakpadRecords.cpp
@@ -122,8 +122,8 @@ 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
   // match the native uuid format of these platforms.
-  return UUID::fromData(&data, os == llvm::Triple::Win32 ? sizeof(data)
-                                                         : sizeof(data.uuid));
+  return UUID(&data, os == llvm::Triple::Win32 ? sizeof(data)
+                                               : sizeof(data.uuid));
 }
 
 llvm::Optional<Record::Kind> Record::classify(llvm::StringRef Line) {

diff  --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index bc488a77fd94..ba4a1f62f342 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -627,13 +627,13 @@ size_t ObjectFileELF::GetModuleSpecifications(
             if (gnu_debuglink_crc) {
               // Use 4 bytes of crc from the .gnu_debuglink section.
               u32le data(gnu_debuglink_crc);
-              uuid = UUID::fromData(&data, sizeof(data));
+              uuid = UUID(&data, sizeof(data));
             } else if (core_notes_crc) {
               // Use 8 bytes - first 4 bytes for *magic* prefix, mainly to make
               // it look 
diff erent form .gnu_debuglink crc followed by 4 bytes
               // of note segments 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 
diff erent form .gnu_debuglink crc - followed by 4 bytes of note
         // segments 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 {
       if (!m_gnu_debuglink_crc)
@@ -796,7 +796,7 @@ UUID ObjectFileELF::GetUUID() {
       if (m_gnu_debuglink_crc) {
         // Use 4 bytes of crc from the .gnu_debuglink section.
         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 (const uint8_t *buf = data.PeekData(offset, note.n_descsz)) {
               // Save the build id as the UUID for the module.
-              uuid = UUID::fromData(buf, note.n_descsz);
+              uuid = UUID(buf, note.n_descsz);
             } else {
               error.SetErrorString("failed to read GNU_BUILD_ID note payload");
               return error;

diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index c14d4190094b..0af75fca6cc8 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -2188,8 +2188,8 @@ UUID ObjectFileMachO::GetSharedCacheUUID(FileSpec dyld_shared_cache,
   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_header_data.GetData(&offset, sizeof(uuid_t)), sizeof(uuid_t));
+    dsc_uuid = UUID(dsc_header_data.GetData(&offset, sizeof(uuid_t)), 
+                    sizeof(uuid_t));
   }
   Log *log = GetLog(LLDBLog::Symbols);
   if (log && dsc_uuid.IsValid()) {
@@ -2329,7 +2329,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
       const uint8_t *uuid_bytes = m_data.PeekData(offset, 16);
 
       if (uuid_bytes)
-        image_uuid = UUID::fromOptionalData(uuid_bytes, 16);
+        image_uuid = UUID(uuid_bytes, 16);
       break;
     }
 
@@ -2726,7 +2726,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
         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) {
@@ -2735,7 +2735,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
           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;
@@ -4853,7 +4853,7 @@ UUID ObjectFileMachO::GetUUID(const llvm::MachO::mach_header &header,
         if (!memcmp(uuid_bytes, opencl_uuid, 16))
           return UUID();
 
-        return UUID::fromOptionalData(uuid_bytes, 16);
+        return UUID(uuid_bytes, 16);
       }
       return UUID();
     }
@@ -5616,8 +5616,7 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t &value,
             }
 
             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(raw_uuid, sizeof(uuid_t));
               // convert the "main bin spec" type into our
               // ObjectFile::BinaryType enum
               switch (binspec_type) {
@@ -5912,7 +5911,7 @@ void ObjectFileMachO::GetLLDBSharedCacheUUID(addr_t &base_addr, UUID &uuid) {
                          100); // sharedCacheBaseAddress <mach-o/dyld_images.h>
           }
         }
-        uuid = UUID::fromOptionalData(sharedCacheUUID_address, sizeof(uuid_t));
+        uuid = UUID(sharedCacheUUID_address, sizeof(uuid_t));
       }
     }
   } else {
@@ -5941,7 +5940,7 @@ void ObjectFileMachO::GetLLDBSharedCacheUUID(addr_t &base_addr, UUID &uuid) {
         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(sc_info.cacheUUID, sizeof(uuid_t));
         }
         dyld_process_info_release(process_info);
       }
@@ -6928,8 +6927,7 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
 
           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(uuid, sizeof(uuid_t));
           image_entry.load_address = load_address;
           image_entry.currently_executing = currently_executing;
 
@@ -6960,8 +6958,7 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
 
           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(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/ObjectFile/PDB/ObjectFilePDB.cpp b/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
index 44c708676e52..c62a67fa29f9 100644
--- a/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
+++ b/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
@@ -31,7 +31,7 @@ static UUID GetPDBUUID(InfoStream &IS) {
   UUID::CvRecordPdb70 debug_info;
   memcpy(&debug_info.Uuid, IS.getGuid().Guid, sizeof(debug_info.Uuid));
   debug_info.Age = IS.getAge();
-  return UUID::fromCvRecord(debug_info);
+  return UUID(debug_info);
 }
 
 char ObjectFilePDB::ID;

diff  --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
index 2c1660960250..98d750fcde6a 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -147,7 +147,7 @@ static UUID GetCoffUUID(llvm::object::COFFObjectFile &coff_obj) {
       UUID::CvRecordPdb70 info;
       memcpy(&info.Uuid, pdb_info->PDB70.Signature, sizeof(info.Uuid));
       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.
   llvm::support::ulittle32_t data(gnu_debuglink_crc);
-  return UUID::fromData(&data, sizeof(data));
+  return UUID(&data, sizeof(data));
 }
 
 char ObjectFilePECOFF::ID;

diff  --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
index ecf363aa2e73..63b6083ddffc 100644
--- a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
+++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp
@@ -68,13 +68,13 @@ UUID MinidumpParser::GetModuleUUID(const minidump::Module *module) {
       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(pdb70_uuid, sizeof(*pdb70_uuid));
+      return UUID(&pdb70_uuid->Uuid,
                                     sizeof(pdb70_uuid->Uuid));
     }
-    return UUID::fromCvRecord(*pdb70_uuid);
+    return UUID(*pdb70_uuid);
   } else if (cv_signature == CvSignature::ElfBuildId)
-    return UUID::fromOptionalData(cv_record);
+    return UUID(cv_record);
 
   return UUID();
 }

diff  --git a/lldb/source/Utility/UUID.cpp b/lldb/source/Utility/UUID.cpp
index 0adeb06e4c04..62a75ecf47c2 100644
--- a/lldb/source/Utility/UUID.cpp
+++ b/lldb/source/Utility/UUID.cpp
@@ -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.Data2);
   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));
+    *this = UUID(&debug_info, sizeof(debug_info));
+  else
+    *this = UUID(&debug_info.Uuid, sizeof(debug_info.Uuid));
 }
 
 std::string UUID::GetAsString(llvm::StringRef separator) const {
@@ -107,16 +108,6 @@ bool UUID::SetFromStringRef(llvm::StringRef str) {
   if (!rest.empty() || bytes.empty())
     return false;
 
-  *this = fromData(bytes);
+  *this = UUID(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/ObjectFile/Breakpad/BreakpadRecordsTest.cpp b/lldb/unittests/ObjectFile/Breakpad/BreakpadRecordsTest.cpp
index 66f2b8633192..519dbd22a0b8 100644
--- a/lldb/unittests/ObjectFile/Breakpad/BreakpadRecordsTest.cpp
+++ b/lldb/unittests/ObjectFile/Breakpad/BreakpadRecordsTest.cpp
@@ -37,7 +37,7 @@ TEST(Record, classify) {
 
 TEST(ModuleRecord, parse) {
   EXPECT_EQ(ModuleRecord(llvm::Triple::Linux, llvm::Triple::x86_64,
-                         UUID::fromData("@ABCDEFGHIJKLMNO", 16)),
+                         UUID("@ABCDEFGHIJKLMNO", 16)),
             ModuleRecord::parse(
                 "MODULE Linux x86_64 404142434445464748494a4b4c4d4e4f0 a.out"));
 
@@ -49,7 +49,7 @@ TEST(ModuleRecord, parse) {
 }
 
 TEST(InfoRecord, parse) {
-  EXPECT_EQ(InfoRecord(UUID::fromData("@ABCDEFGHIJKLMNO", 16)),
+  EXPECT_EQ(InfoRecord(UUID("@ABCDEFGHIJKLMNO", 16)),
             InfoRecord::parse("INFO CODE_ID 404142434445464748494a4b4c4d4e4f"));
   EXPECT_EQ(InfoRecord(UUID()), InfoRecord::parse("INFO CODE_ID 47 a.exe"));
 

diff  --git a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
index b80c44dfae82..80a9d9878ed5 100644
--- a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
+++ b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
@@ -194,7 +194,7 @@ TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfo) {
   ASSERT_EQ(1u, result->size());
   EXPECT_EQ("/foo/bar.so", result.value()[0].GetFileSpec().GetPath());
   EXPECT_EQ(triple, result.value()[0].GetArchitecture().GetTriple());
-  EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNO", 16),
+  EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16),
             result.value()[0].GetUUID());
   EXPECT_EQ(0u, result.value()[0].GetObjectOffset());
   EXPECT_EQ(1234u, result.value()[0].GetObjectSize());
@@ -219,7 +219,7 @@ TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfo_UUID20) {
   ASSERT_EQ(1u, result->size());
   EXPECT_EQ("/foo/bar.so", result.value()[0].GetFileSpec().GetPath());
   EXPECT_EQ(triple, result.value()[0].GetArchitecture().GetTriple());
-  EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNOPQRS", 20),
+  EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20),
             result.value()[0].GetUUID());
   EXPECT_EQ(0u, result.value()[0].GetObjectOffset());
   EXPECT_EQ(1234u, result.value()[0].GetObjectSize());

diff  --git a/lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp b/lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp
index 361e529e7164..4878bbf56caa 100644
--- a/lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp
@@ -231,7 +231,7 @@ TEST(DWARFIndexCachingTest, CacheSignatureTests) {
   EncodeDecode(sig, /*encode_result=*/false);
   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());
   EncodeDecode(sig, /*encode_result=*/true);
   sig.m_mod_time = 0x12345678;

diff  --git a/lldb/unittests/Utility/UUIDTest.cpp b/lldb/unittests/Utility/UUIDTest.cpp
index 1c84315d402a..0852f07a4faa 100644
--- a/lldb/unittests/Utility/UUIDTest.cpp
+++ b/lldb/unittests/Utility/UUIDTest.cpp
@@ -14,10 +14,10 @@ using namespace lldb_private;
 
 TEST(UUIDTest, RelationalOperators) {
   UUID empty;
-  UUID a16 = UUID::fromData("1234567890123456", 16);
-  UUID b16 = UUID::fromData("1234567890123457", 16);
-  UUID a20 = UUID::fromData("12345678901234567890", 20);
-  UUID b20 = UUID::fromData("12345678900987654321", 20);
+  UUID a16 = UUID("1234567890123456", 16);
+  UUID b16 = UUID("1234567890123457", 16);
+  UUID a20 = UUID("12345678901234567890", 20);
+  UUID b20 = UUID("12345678900987654321", 20);
 
   EXPECT_EQ(empty, empty);
   EXPECT_EQ(a16, a16);
@@ -37,59 +37,52 @@ TEST(UUIDTest, RelationalOperators) {
 TEST(UUIDTest, Validity) {
   UUID empty;
   std::vector<uint8_t> 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 a16 = UUID(zeroes.data(), 16);
+  UUID a20 = UUID(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) {
   UUID u;
   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_EQ(UUID::fromData("@ABCDEFGHIJKLMNO", 16), u);
+  EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u);
 
   EXPECT_TRUE(
       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_FALSE(u.SetFromStringRef("40xxxxx"));
   EXPECT_FALSE(u.SetFromStringRef(""));
-  EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNO", 16), u)
+  EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), u)
       << "uuid was changed by failed parse calls";
 
   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_EQ(UUID::fromData("@ABCD", 4), u);
+  EXPECT_EQ(UUID("@ABCD", 4), u);
 
   EXPECT_FALSE(u.SetFromStringRef("4"));
 }
 
 TEST(UUIDTest, StringConverion) {
-  EXPECT_EQ("40414243", UUID::fromData("@ABC", 4).GetAsString());
-  EXPECT_EQ("40414243-4445-4647", UUID::fromData("@ABCDEFG", 8).GetAsString());
+  EXPECT_EQ("40414243", UUID("@ABC", 4).GetAsString());
+  EXPECT_EQ("40414243-4445-4647", UUID("@ABCDEFG", 8).GetAsString());
   EXPECT_EQ("40414243-4445-4647-4849-4A4B",
-            UUID::fromData("@ABCDEFGHIJK", 12).GetAsString());
+            UUID("@ABCDEFGHIJK", 12).GetAsString());
   EXPECT_EQ("40414243-4445-4647-4849-4A4B4C4D4E4F",
-            UUID::fromData("@ABCDEFGHIJKLMNO", 16).GetAsString());
+            UUID("@ABCDEFGHIJKLMNO", 16).GetAsString());
   EXPECT_EQ("40414243-4445-4647-4849-4A4B4C4D4E4F-50515253",
-            UUID::fromData("@ABCDEFGHIJKLMNOPQRS", 20).GetAsString());
+            UUID("@ABCDEFGHIJKLMNOPQRS", 20).GetAsString());
 }


        


More information about the lldb-commits mailing list