Simplify ObjectFile::GetUUID

instead of returning the UUID through by-ref argument and a boolean
value indicating success, we can just return it directly. Since the UUID
class already has an invalid state, it can be used to denote the failure
without the additional bool.

llvm-svn: 353714
diff --git a/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp b/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
index 8825c83..5f36638 100644
--- a/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
+++ b/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
@@ -122,11 +122,6 @@
   return nullptr;
 }
 
-bool ObjectFileBreakpad::GetUUID(UUID *uuid) {
-  *uuid = m_uuid;
-  return true;
-}
-
 void ObjectFileBreakpad::CreateSections(SectionList &unified_section_list) {
   if (m_sections_ap)
     return;
diff --git a/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h b/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
index 0304eff..1593081 100644
--- a/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
+++ b/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
@@ -82,7 +82,7 @@
 
   ArchSpec GetArchitecture() override { return m_arch; }
 
-  bool GetUUID(UUID *uuid) override;
+  UUID GetUUID() override { return m_uuid; }
 
   FileSpecList GetDebugSymbolFilePaths() override { return FileSpecList(); }
 
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 1f1551c..521e875 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -896,49 +896,43 @@
   return m_header.Parse(m_data, &offset);
 }
 
-bool ObjectFileELF::GetUUID(lldb_private::UUID *uuid) {
+UUID ObjectFileELF::GetUUID() {
   // Need to parse the section list to get the UUIDs, so make sure that's been
   // done.
   if (!ParseSectionHeaders() && GetType() != ObjectFile::eTypeCoreFile)
-    return false;
+    return UUID();
 
-  using u32le = llvm::support::ulittle32_t;
-  if (m_uuid.IsValid()) {
-    // We have the full build id uuid.
-    *uuid = m_uuid;
-    return true;
-  } else if (GetType() == ObjectFile::eTypeCoreFile) {
-    uint32_t core_notes_crc = 0;
+  if (!m_uuid) {
+    using u32le = llvm::support::ulittle32_t;
+    if (GetType() == ObjectFile::eTypeCoreFile) {
+      uint32_t core_notes_crc = 0;
 
-    if (!ParseProgramHeaders())
-      return false;
+      if (!ParseProgramHeaders())
+        return UUID();
 
-    core_notes_crc = CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
+      core_notes_crc =
+          CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
 
-    if (core_notes_crc) {
-      // Use 8 bytes - first 4 bytes for *magic* prefix, mainly to make it look
-      // different 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));
-    }
-  } else {
-    if (!m_gnu_debuglink_crc)
-      m_gnu_debuglink_crc =
-          calc_gnu_debuglink_crc32(m_data.GetDataStart(), m_data.GetByteSize());
-    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));
+      if (core_notes_crc) {
+        // Use 8 bytes - first 4 bytes for *magic* prefix, mainly to make it
+        // look different 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));
+      }
+    } else {
+      if (!m_gnu_debuglink_crc)
+        m_gnu_debuglink_crc = calc_gnu_debuglink_crc32(m_data.GetDataStart(),
+                                                       m_data.GetByteSize());
+      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));
+      }
     }
   }
 
-  if (m_uuid.IsValid()) {
-    *uuid = m_uuid;
-    return true;
-  }
-
-  return false;
+  return m_uuid;
 }
 
 lldb_private::FileSpecList ObjectFileELF::GetDebugSymbolFilePaths() {
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index 570a8ba..fb51212 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -122,7 +122,7 @@
 
   lldb_private::ArchSpec GetArchitecture() override;
 
-  bool GetUUID(lldb_private::UUID *uuid) override;
+  lldb_private::UUID GetUUID() override;
 
   lldb_private::FileSpecList GetDebugSymbolFilePaths() override;
 
diff --git a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp b/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
index d1e9a5d..ec55006 100644
--- a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
+++ b/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
@@ -166,9 +166,9 @@
   }
 }
 
-bool ObjectFileJIT::GetUUID(lldb_private::UUID *uuid) {
+UUID ObjectFileJIT::GetUUID() {
   // TODO: maybe get from delegate, not needed for first pass
-  return false;
+  return UUID();
 }
 
 uint32_t ObjectFileJIT::GetDependentModules(FileSpecList &files) {
diff --git a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h b/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
index 2d0b17d..694bbcd 100644
--- a/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
+++ b/lldb/source/Plugins/ObjectFile/JIT/ObjectFileJIT.h
@@ -74,7 +74,7 @@
 
   lldb_private::ArchSpec GetArchitecture() override;
 
-  bool GetUUID(lldb_private::UUID *uuid) override;
+  lldb_private::UUID GetUUID() override;
 
   uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
 
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index b4c320f..4046082 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -916,7 +916,7 @@
 
         spec.GetArchitecture() = GetArchitecture(header, data, data_offset);
         if (spec.GetArchitecture().IsValid()) {
-          GetUUID(header, data, data_offset, spec.GetUUID());
+          spec.GetUUID() = GetUUID(header, data, data_offset);
           specs.Append(spec);
         }
       }
@@ -4845,10 +4845,9 @@
   }
 }
 
-bool ObjectFileMachO::GetUUID(const llvm::MachO::mach_header &header,
+UUID ObjectFileMachO::GetUUID(const llvm::MachO::mach_header &header,
                               const lldb_private::DataExtractor &data,
-                              lldb::offset_t lc_offset,
-                              lldb_private::UUID &uuid) {
+                              lldb::offset_t lc_offset) {
   uint32_t i;
   struct uuid_command load_cmd;
 
@@ -4870,16 +4869,15 @@
                                        0xbb, 0x14, 0xf0, 0x0d};
 
         if (!memcmp(uuid_bytes, opencl_uuid, 16))
-          return false;
+          return UUID();
 
-        uuid = UUID::fromOptionalData(uuid_bytes, 16);
-        return true;
+        return UUID::fromOptionalData(uuid_bytes, 16);
       }
-      return false;
+      return UUID();
     }
     offset = cmd_offset + load_cmd.cmdsize;
   }
-  return false;
+  return UUID();
 }
 
 static llvm::StringRef GetOSName(uint32_t cmd) {
@@ -5066,14 +5064,14 @@
   return arch;
 }
 
-bool ObjectFileMachO::GetUUID(lldb_private::UUID *uuid) {
+UUID ObjectFileMachO::GetUUID() {
   ModuleSP module_sp(GetModule());
   if (module_sp) {
     std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
     lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
-    return GetUUID(m_header, m_data, offset, *uuid);
+    return GetUUID(m_header, m_data, offset);
   }
-  return false;
+  return UUID();
 }
 
 uint32_t ObjectFileMachO::GetDependentModules(FileSpecList &files) {
@@ -5553,8 +5551,7 @@
     if (GetAddressByteSize() == 4) {
       // 32 bit kexts are just object files, but they do have a valid
       // UUID load command.
-      UUID uuid;
-      if (GetUUID(&uuid)) {
+      if (GetUUID()) {
         // this checking for the UUID load command is not enough we could
         // eventually look for the symbol named "OSKextGetCurrentIdentifier" as
         // this is required of kexts
@@ -5597,8 +5594,7 @@
   {
     // 32 bit kexts are just object files, but they do have a valid
     // UUID load command.
-    UUID uuid;
-    if (GetUUID(&uuid)) {
+    if (GetUUID()) {
       // this checking for the UUID load command is not enough we could
       // eventually look for the symbol named "OSKextGetCurrentIdentifier" as
       // this is required of kexts
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
index 29ee204..1ad89c0 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
@@ -93,7 +93,7 @@
 
   lldb_private::ArchSpec GetArchitecture() override;
 
-  bool GetUUID(lldb_private::UUID *uuid) override;
+  lldb_private::UUID GetUUID() override;
 
   uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
 
@@ -140,11 +140,10 @@
   uint32_t GetPluginVersion() override;
 
 protected:
-  static bool
+  static lldb_private::UUID
   GetUUID(const llvm::MachO::mach_header &header,
           const lldb_private::DataExtractor &data,
-          lldb::offset_t lc_offset, // Offset to the first load command
-          lldb_private::UUID &uuid);
+          lldb::offset_t lc_offset); // Offset to the first load command
 
   static lldb_private::ArchSpec
   GetArchitecture(const llvm::MachO::mach_header &header,
diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
index e554884..dc7f610 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -837,7 +837,7 @@
   }
 }
 
-bool ObjectFilePECOFF::GetUUID(UUID *uuid) { return false; }
+UUID ObjectFilePECOFF::GetUUID() { return UUID(); }
 
 uint32_t ObjectFilePECOFF::ParseDependentModules() {
   ModuleSP module_sp(GetModule());
diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
index cd1cb02..17f5f4de 100644
--- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
+++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
@@ -111,7 +111,7 @@
 
   lldb_private::ArchSpec GetArchitecture() override;
 
-  bool GetUUID(lldb_private::UUID *uuid) override;
+  lldb_private::UUID GetUUID() override;
 
   uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;