When debugging a program in Visual Studio on Windows, if the PDB file does not match the executable file, Visual Studio will prompt “Unable to load symbol file.” If the program crashes and a crash dump file is generated, Visual Studio may also fail to smoothly enter the crash site if the PDB file is mismatched
What is a pdb file?
PDB files are debugging information files created by Microsoft, used for debugging programs. They contain information such as program symbol tables, source file names, and line numbers. PDB files can be generated during program compilation for debugging purposes.
Debugging with WinDbg
WinDbg is a debugging tool from Microsoft that can be used to debug Windows programs. WinDbg can load mismatched PDB files, but they need to be loaded manually. The .reload /f /i
command can force the loading of mismatched PDB files.
However, WinDbg is not as convenient to use as Visual Studio, so we hope that Visual Studio can also load mismatched PDB files
Visual Studio loading mismatched PDB file
Source code is generally managed through git now, so it’s possible to find the corresponding version of the code, recompile it, and generate the corresponding pdb file. Why can’t it be loaded? It’s mainly due to metadata mismatches.
There’s a small tool that can modify metadata, generate a new PDB file based on the executable file information, allowing Visual Studio to load it
chkmatch download address: [https://www.debuginfo.com/tools/chkmatch.html]
Site cache address: chkmatch.zip
ChkMatch utility can be used to check whether an executable and debug information file match. It can also be used to enforce matching between an executable and debug information file, if they are compatible.
For more information about debug information matching and related issues, see this article.
Supported debug information formats: DBG, PDB 2.0, PDB 7.0.
chkmatch [-c ExeFile DebugInfoFile ] |
[-m ExeFile DebugInfoFile]
-c
Check matching between the executable and the debug information file.
-m
Make the executable and the debug information file match.
ExeFile
The name of the executable file.
DebugInfoFile
The name of the debug information file.
Use chkmatch
First, perform a verification check, analyze the reason for the mismatch, and prompt that the signature does not match
C:\Users\tianlong.xiang\Downloads\chkmatch>ChkMatch.exe -c "D:\Program Files\Rolan\trade\UAT_YinStrade\YinTrade.Main.exe" E:\YinTech\ykcz_securities_trading_client\Sec_Trade\YinTrade.Main\bin\Release\YinTrade.Main.pdb
ChkMatch - version 1.0
Copyright (C) 2004 Oleg Starodumov
http://www.debuginfo.com/
Executable: D:\Program Files\Rolan\trade\UAT_YinStrade\YinTrade.Main.exe
Debug info file: E:\YinTech\ykcz_securities_trading_client\Sec_Trade\YinTrade.Main\bin\Release\YinTrade.Main.pdb
Executable:
TimeDateStamp: c26d9be3
Debug info: 2 ( CodeView )
TimeStamp: f86b0a4f Characteristics: 0 MajorVer: 0 MinorVer: 0
Size: 122 RVA: 001cdc44 FileOffset: 001cbe44
CodeView format: RSDS
Signature: {428c9b95-39a3-4a8d-a8e5-7be453684757} Age: 1
PdbFile: D:\stock_UAT\ykcz_securities_trading_client\Sec_Trade\YinTrade.Main\obj\Release\YinTrade.Main.pdb
Debug info: 16 ( Unknown )
TimeStamp: 00000000 Characteristics: 0 MajorVer: 0 MinorVer: 0
Size: 0 RVA: 00000000 FileOffset: 00000000
Debug information file:
Format: PDB 7.00
Signature: {06fae08e-c0a2-4f3d-9c7c-dfc684445dd1} Age: 1
Result: Unmatched (reason: Signature mismatch)
Then perform modification operations to make the PDB file match the EXE file
C:\Users\tianlong.xiang\Downloads\chkmatch>ChkMatch.exe -m "D:\Program Files\Rolan\trade\UAT_YinStrade\YinTrade.Main.exe" E:\YinTech\ykcz_securities_trading_client\Sec_Trade\YinTrade.Main\bin\Release\YinTrade.Main.pdb
ChkMatch - version 1.0
Copyright (C) 2004 Oleg Starodumov
http://www.debuginfo.com/
Executable: D:\Program Files\Rolan\trade\UAT_YinStrade\YinTrade.Main.exe
Debug info file: E:\YinTech\ykcz_securities_trading_client\Sec_Trade\YinTrade.Main\bin\Release\YinTrade.Main.pdb
Executable:
TimeDateStamp: c26d9be3
Debug info: 2 ( CodeView )
TimeStamp: f86b0a4f Characteristics: 0 MajorVer: 0 MinorVer: 0
Size: 122 RVA: 001cdc44 FileOffset: 001cbe44
CodeView format: RSDS
Signature: {428c9b95-39a3-4a8d-a8e5-7be453684757} Age: 1
PdbFile: D:\stock_UAT\ykcz_securities_trading_client\Sec_Trade\YinTrade.Main\obj\Release\YinTrade.Main.pdb
Debug info: 16 ( Unknown )
TimeStamp: 00000000 Characteristics: 0 MajorVer: 0 MinorVer: 0
Size: 0 RVA: 00000000 FileOffset: 00000000
Debug information file:
Format: PDB 7.00
Signature: {06fae08e-c0a2-4f3d-9c7c-dfc684445dd1} Age: 1
Writing to the debug information file...
Result: Success.