zequanwu created this revision. zequanwu added reviewers: labath, rnk, aganea. Herald added a project: All. zequanwu requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D152189 Files: lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp lldb/test/Shell/ObjectFile/PDB/object.test Index: lldb/test/Shell/ObjectFile/PDB/object.test =================================================================== --- lldb/test/Shell/ObjectFile/PDB/object.test +++ 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 @@ Version: VC70 DbiStream: VerHeader: V70 - Age: 1 + Age: 3 BuildNumber: 36363 PdbDllVersion: 0 PdbDllRbld: 0 Index: lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp =================================================================== --- lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp +++ lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp @@ -27,10 +27,10 @@ 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 @@ 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 @@ } 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()) {
Index: lldb/test/Shell/ObjectFile/PDB/object.test =================================================================== --- lldb/test/Shell/ObjectFile/PDB/object.test +++ 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 @@ Version: VC70 DbiStream: VerHeader: V70 - Age: 1 + Age: 3 BuildNumber: 36363 PdbDllVersion: 0 PdbDllRbld: 0 Index: lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp =================================================================== --- lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp +++ lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp @@ -27,10 +27,10 @@ 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 @@ 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 @@ } 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()) {
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits