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 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 m_deps_filespec; typedef llvm::object::OwningBinary OWNBINType; llvm::Optional 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(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(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; }