Skip to content

Commit cb9a7c2

Browse files
committed
[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
1 parent 6593fcc commit cb9a7c2

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ using namespace llvm::codeview;
2727

2828
LLDB_PLUGIN_DEFINE(ObjectFilePDB)
2929

30-
static UUID GetPDBUUID(InfoStream &IS) {
30+
static UUID GetPDBUUID(InfoStream &IS, DbiStream &DS) {
3131
UUID::CvRecordPdb70 debug_info;
3232
memcpy(&debug_info.Uuid, IS.getGuid().Guid, sizeof(debug_info.Uuid));
33-
debug_info.Age = IS.getAge();
33+
debug_info.Age = DS.getAge();
3434
return UUID(debug_info);
3535
}
3636

@@ -82,7 +82,12 @@ bool ObjectFilePDB::initPDBFile() {
8282
llvm::consumeError(info_stream.takeError());
8383
return false;
8484
}
85-
m_uuid = GetPDBUUID(*info_stream);
85+
auto dbi_stream = m_file_up->getPDBDbiStream();
86+
if (!dbi_stream) {
87+
llvm::consumeError(dbi_stream.takeError());
88+
return false;
89+
}
90+
m_uuid = GetPDBUUID(*info_stream, *dbi_stream);
8691
return true;
8792
}
8893

@@ -126,7 +131,7 @@ size_t ObjectFilePDB::GetModuleSpecifications(
126131
}
127132

128133
lldb_private::UUID &uuid = module_spec.GetUUID();
129-
uuid = GetPDBUUID(*info_stream);
134+
uuid = GetPDBUUID(*info_stream, *dbi_stream);
130135

131136
ArchSpec &module_arch = module_spec.GetArchitecture();
132137
switch (dbi_stream->getMachineType()) {

lldb/test/Shell/ObjectFile/PDB/object.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# CHECK: Plugin name: pdb
55
# CHECK: Architecture: x86_64-pc-windows-msvc
6-
# CHECK: UUID: 61AF583F-29A8-7A6C-4C4C-44205044422E-00000001
6+
# CHECK: UUID: 61AF583F-29A8-7A6C-4C4C-44205044422E-00000003
77
# CHECK: Executable: false
88
# CHECK: Stripped: false
99
# CHECK: Type: debug info
@@ -52,7 +52,7 @@ PdbStream:
5252
Version: VC70
5353
DbiStream:
5454
VerHeader: V70
55-
Age: 1
55+
Age: 3
5656
BuildNumber: 36363
5757
PdbDllVersion: 0
5858
PdbDllRbld: 0

0 commit comments

Comments
 (0)