[LLDB][PDB] Fix age field in UUID in PDB file.
authorZequan Wu <zequanwu@google.com>
Mon, 5 Jun 2023 19:07:06 +0000 (15:07 -0400)
committerZequan Wu <zequanwu@google.com>
Tue, 6 Jun 2023 15:24:50 +0000 (11:24 -0400)
commitcb9a7c22ee6789569e28dde073e6827761b4d003
treedd889d67201207fbcbd1fffb18b291df07ce8392
parent6593fcccd7f43134f3d255e92d79ac34c3843b40
[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
lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
lldb/test/Shell/ObjectFile/PDB/object.test