[Lldb-commits] [lldb] r352122 - Add UUID::SetFromOptionalStringRef, use it in DynamicLoaderDarwin

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 24 14:43:44 PST 2019


Author: jingham
Date: Thu Jan 24 14:43:44 2019
New Revision: 352122

URL: http://llvm.org/viewvc/llvm-project?rev=352122&view=rev
Log:
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

Modified:
    lldb/trunk/include/lldb/Utility/UUID.h
    lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
    lldb/trunk/source/Utility/UUID.cpp
    lldb/trunk/unittests/Utility/UUIDTest.cpp

Modified: lldb/trunk/include/lldb/Utility/UUID.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/UUID.h?rev=352122&r1=352121&r2=352122&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/UUID.h (original)
+++ lldb/trunk/include/lldb/Utility/UUID.h Thu Jan 24 14:43:44 2019
@@ -67,6 +67,11 @@ public:
   std::string GetAsString(llvm::StringRef separator = "-") const;
 
   size_t SetFromStringRef(llvm::StringRef str, uint32_t num_uuid_bytes = 16);
+  
+  // Same as SetFromStringRef, but if the resultant UUID is all 0 bytes, set the 
+  // UUID to invalid.
+  size_t SetFromOptionalStringRef(llvm::StringRef str, 
+                                  uint32_t num_uuid_bytes = 16);
 
   // Decode as many UUID bytes (up to 16) as possible from the C string "cstr"
   // This is used for auto completion where a partial UUID might have been

Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp?rev=352122&r1=352121&r2=352122&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp Thu Jan 24 14:43:44 2019
@@ -476,7 +476,7 @@ bool DynamicLoaderDarwin::JSONImageInfor
       image_infos[i].segments.push_back(segment);
     }
 
-    image_infos[i].uuid.SetFromStringRef(
+    image_infos[i].uuid.SetFromOptionalStringRef(
         image->GetValueForKey("uuid")->GetAsString()->GetValue());
 
     // All sections listed in the dyld image info structure will all either be

Modified: lldb/trunk/source/Utility/UUID.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/UUID.cpp?rev=352122&r1=352121&r2=352122&view=diff
==============================================================================
--- lldb/trunk/source/Utility/UUID.cpp (original)
+++ lldb/trunk/source/Utility/UUID.cpp Thu Jan 24 14:43:44 2019
@@ -109,3 +109,15 @@ size_t UUID::SetFromStringRef(llvm::Stri
   // Else return zero to indicate we were not able to parse a UUID value
   return 0;
 }
+
+size_t UUID::SetFromOptionalStringRef(llvm::StringRef str, 
+                                      uint32_t num_uuid_bytes) {
+  size_t num_chars_consumed = SetFromStringRef(str, num_uuid_bytes);
+  if (num_chars_consumed) {
+    if (llvm::all_of(m_bytes, [](uint8_t b) { return b == 0; }))
+        Clear();
+  }
+  
+  return num_chars_consumed;
+}
+

Modified: lldb/trunk/unittests/Utility/UUIDTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/UUIDTest.cpp?rev=352122&r1=352121&r2=352122&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/UUIDTest.cpp (original)
+++ lldb/trunk/unittests/Utility/UUIDTest.cpp Thu Jan 24 14:43:44 2019
@@ -41,11 +41,18 @@ TEST(UUIDTest, Validity) {
   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);
 }
 
 TEST(UUIDTest, SetFromStringRef) {




More information about the lldb-commits mailing list