From cb9a7c22ee6789569e28dde073e6827761b4d003 Mon Sep 17 00:00:00 2001 From: Zequan Wu Date: Mon, 5 Jun 2023 15:07:06 -0400 Subject: [PATCH] [LLDB][PDB] Fix age field in UUID in PDB file. There are two age fields in a PDB file. One from the PDB Stream and another one from the DBI stream. According to https://randomascii.wordpress.com/2011/11/11/source-indexing-is-underused-awesomeness/#comment-34328, The age in DBI stream is used to against the binary's age. `Pdbstr.exe` is used to only increment the age from PDB stream without changing the DBI age. I also verified this by manually changing the DBI age of a PDB file and let `windbg.exe` to load it. It shows the following logs before and after changing: Before: ``` SYMSRV: BYINDEX: 0xA c:\symbols*https://msdl.microsoft.com/download/symbols nlaapi.pdb D72AA69CD5ABE5D28C74FADB17DE3F8C1 SYMSRV: PATH: c:\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb SYMSRV: RESULT: 0x00000000 *** WARNING: Unable to verify checksum for NLAapi.dll DBGHELP: NLAapi - public symbols c:\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb ... ``` After: ``` SYMSRV: BYINDEX: 0xA c:\symbols*https://msdl.microsoft.com/download/symbols nlaapi.pdb D72AA69CD5ABE5D28C74FADB17DE3F8C1 SYMSRV: PATH: c:\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb SYMSRV: RESULT: 0x00000000 DBGHELP: c:\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb - mismatched pdb SYMSRV: BYINDEX: 0xB c:\symbols*https://chromium-browser-symsrv.commondatastorage.googleapis.com nlaapi.pdb D72AA69CD5ABE5D28C74FADB17DE3F8C1 SYMSRV: PATH: c:\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb SYMSRV: RESULT: 0x00000000 DBGHELP: c:\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb - mismatched pdb SYMSRV: BYINDEX: 0xC c:\src\symbols*https://msdl.microsoft.com/download/symbols nlaapi.pdb D72AA69CD5ABE5D28C74FADB17DE3F8C1 SYMSRV: PATH: c:\src\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb SYMSRV: RESULT: 0x00000000 *** WARNING: Unable to verify checksum for NLAapi.dll DBGHELP: NLAapi - public symbols c:\src\symbols\nlaapi.pdb\D72AA69CD5ABE5D28C74FADB17DE3F8C1\nlaapi.pdb ``` So, `windbg.exe` uses the DBI age to detect mismatched pdb, but it still loads the pdb even if the age mismatched. Probably lldb should do the same and give some warnings. This fixes a bug that lldb can't load some windows system pdbs due to mismatched uuid. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D152189 --- .../source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp | 13 +++++++++---- lldb/test/Shell/ObjectFile/PDB/object.test | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp b/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp index c62a67fa29f9..a3b91fc37dac 100644 --- a/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp +++ b/lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp @@ -27,10 +27,10 @@ using namespace llvm::codeview; LLDB_PLUGIN_DEFINE(ObjectFilePDB) -static UUID GetPDBUUID(InfoStream &IS) { +static UUID GetPDBUUID(InfoStream &IS, DbiStream &DS) { UUID::CvRecordPdb70 debug_info; memcpy(&debug_info.Uuid, IS.getGuid().Guid, sizeof(debug_info.Uuid)); - debug_info.Age = IS.getAge(); + debug_info.Age = DS.getAge(); return UUID(debug_info); } @@ -82,7 +82,12 @@ bool ObjectFilePDB::initPDBFile() { llvm::consumeError(info_stream.takeError()); return false; } - m_uuid = GetPDBUUID(*info_stream); + auto dbi_stream = m_file_up->getPDBDbiStream(); + if (!dbi_stream) { + llvm::consumeError(dbi_stream.takeError()); + return false; + } + m_uuid = GetPDBUUID(*info_stream, *dbi_stream); return true; } @@ -126,7 +131,7 @@ size_t ObjectFilePDB::GetModuleSpecifications( } lldb_private::UUID &uuid = module_spec.GetUUID(); - uuid = GetPDBUUID(*info_stream); + uuid = GetPDBUUID(*info_stream, *dbi_stream); ArchSpec &module_arch = module_spec.GetArchitecture(); switch (dbi_stream->getMachineType()) { diff --git a/lldb/test/Shell/ObjectFile/PDB/object.test b/lldb/test/Shell/ObjectFile/PDB/object.test index 35373d52a393..62564243f054 100644 --- a/lldb/test/Shell/ObjectFile/PDB/object.test +++ b/lldb/test/Shell/ObjectFile/PDB/object.test @@ -3,7 +3,7 @@ # CHECK: Plugin name: pdb # CHECK: Architecture: x86_64-pc-windows-msvc -# CHECK: UUID: 61AF583F-29A8-7A6C-4C4C-44205044422E-00000001 +# CHECK: UUID: 61AF583F-29A8-7A6C-4C4C-44205044422E-00000003 # CHECK: Executable: false # CHECK: Stripped: false # CHECK: Type: debug info @@ -52,7 +52,7 @@ PdbStream: Version: VC70 DbiStream: VerHeader: V70 - Age: 1 + Age: 3 BuildNumber: 36363 PdbDllVersion: 0 PdbDllRbld: 0 -- 2.34.1