[PATCH] D56229: [PECOFF] Implementation of ObjectFilePECOFF:: GetUUID()

Aaron Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 2 16:04:58 PST 2019


asmith created this revision.
asmith added reviewers: zturner, llvm-commits.
Herald added a subscriber: lldb-commits.

Provide an implementation of GetUUID() for remote debugging scenarios based on the md5 of the object's path.

Include a simple lit test that checks the first 8 bytes of the UUID is non-empty.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D56229

Files:
  lit/Modules/PECOFF/export-dllfunc.yaml
  source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h


Index: source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
===================================================================
--- source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
+++ source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
@@ -289,6 +289,8 @@
   llvm::Optional<lldb_private::FileSpecList> m_deps_filespec;
   typedef llvm::object::OwningBinary<llvm::object::Binary> OWNBINType;
   llvm::Optional<OWNBINType> m_owningbin;
+
+  lldb_private::UUID m_uuid;
 };
 
 #endif // liblldb_ObjectFilePECOFF_h_
Index: source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
===================================================================
--- source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -129,18 +129,27 @@
       if (pe_signature != IMAGE_NT_SIGNATURE)
         return false;
       if (ParseCOFFHeader(data, &offset, coff_header)) {
-        ArchSpec spec;
+        ModuleSpec module_spec(file);
+        ArchSpec &spec = module_spec.GetArchitecture();
+
+        lldb_private::UUID &uuid = module_spec.GetUUID();
+        if (!uuid.IsValid()) {
+          if (auto Result = llvm::sys::fs::md5_contents(file.GetPath()))
+            uuid =
+                UUID::fromOptionalData(llvm::ArrayRef<uint8_t>(Result->Bytes));
+        }
+
         if (coff_header.machine == MachineAmd64) {
           spec.SetTriple("x86_64-pc-windows");
-          specs.Append(ModuleSpec(file, spec));
+          specs.Append(module_spec);
         } else if (coff_header.machine == MachineX86) {
           spec.SetTriple("i386-pc-windows");
-          specs.Append(ModuleSpec(file, spec));
+          specs.Append(module_spec);
           spec.SetTriple("i686-pc-windows");
-          specs.Append(ModuleSpec(file, spec));
+          specs.Append(module_spec);
         } else if (coff_header.machine == MachineArmNt) {
           spec.SetTriple("arm-pc-windows");
-          specs.Append(ModuleSpec(file, spec));
+          specs.Append(module_spec);
         }
       }
     }
@@ -842,7 +851,20 @@
   }
 }
 
-bool ObjectFilePECOFF::GetUUID(UUID *uuid) { return false; }
+bool ObjectFilePECOFF::GetUUID(lldb_private::UUID *uuid) {
+  if (m_uuid.IsValid()) {
+    *uuid = m_uuid;
+    return true;
+  }
+
+  // Use the object content's MD5 as UUID
+  auto Result = llvm::sys::fs::md5_contents(GetFileSpec().GetPath());
+  if (!Result)
+    return false;
+  m_uuid = UUID::fromOptionalData(llvm::ArrayRef<uint8_t>(Result->Bytes));
+  *uuid = m_uuid;
+  return true;
+}
 
 uint32_t ObjectFilePECOFF::ParseDependentModules() {
   ModuleSP module_sp(GetModule());
@@ -926,7 +948,8 @@
   if (!section_list)
     m_entry_point_address.SetOffset(file_addr);
   else
-    m_entry_point_address.ResolveAddressUsingFileSections(file_addr, section_list);
+    m_entry_point_address.ResolveAddressUsingFileSections(file_addr,
+                                                          section_list);
   return m_entry_point_address;
 }
 
Index: lit/Modules/PECOFF/export-dllfunc.yaml
===================================================================
--- lit/Modules/PECOFF/export-dllfunc.yaml
+++ lit/Modules/PECOFF/export-dllfunc.yaml
@@ -6,6 +6,10 @@
 # RUN: lldb-test object-file %t.dll | FileCheck -check-prefix=BASIC-CHECK %s
 # RUN: lldb-test object-file -dep-modules %t.dll | FileCheck -check-prefix=DEPS %s
 
+# BASIC-CHECK: Plugin name: pe-coff
+
+# timestamp and build id of debug info in the coff header varies. So does its UUID.
+# BASIC-CHECK-DAG: UUID: {{[0-9A-F]{7,}[0-9A-F]}}-{{.*}}
 
 # BASIC-CHECK: Showing 3 sections
 # BASIC-CHECK:  Index: 0


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56229.179958.patch
Type: text/x-patch
Size: 3611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190103/75cf246b/attachment-0001.bin>


More information about the llvm-commits mailing list