[Lldb-commits] [PATCH] D57195: Add UUID::SetFromOptionalStringRef, use it in DynamicLoaderDarwin

Jim Ingham via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 24 14:19:10 PST 2019


jingham created this revision.
jingham added reviewers: jasonmolenda, labath.
Herald added subscribers: lldb-commits, abidh.

When you build a macOS binary with -no_uuid, we get a binary blob of all 0's from the file, and we read that in with UUID::fromOptionalData, so we get an invalid UUID.  When debugserver tells us about the binaries that have been loaded, it returns a UUID string of all 0's.  We need these two to match.  If we use SetFromStringRef in the latter case, we end up with a valid UUID of all 0's, so they don't match.

This patch adds SetFromOptionalStringRef to mirror the from...Bytes API's, and use it in the macOS Dynamic loader.

I added tests in UUIDTests.cpp to ensure this behavior.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D57195

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


Index: unittests/Utility/UUIDTest.cpp
===================================================================
--- unittests/Utility/UUIDTest.cpp
+++ unittests/Utility/UUIDTest.cpp
@@ -41,11 +41,18 @@
   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) {
Index: source/Utility/UUID.cpp
===================================================================
--- source/Utility/UUID.cpp
+++ source/Utility/UUID.cpp
@@ -109,3 +109,15 @@
   // 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;
+}
+
Index: source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
===================================================================
--- source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -476,7 +476,7 @@
       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
Index: include/lldb/Utility/UUID.h
===================================================================
--- include/lldb/Utility/UUID.h
+++ include/lldb/Utility/UUID.h
@@ -67,6 +67,11 @@
   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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57195.183396.patch
Type: text/x-patch
Size: 2720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190124/6a850f10/attachment.bin>


More information about the lldb-commits mailing list