Visual Studio loading a mismatched PDB file

When debugging programs under Windows using Visual Studio, if the PDB file does not match the executable file, Visual Studio will display “Unable to load symbol file.” The program crashes and generates a crash dump. If it’s an mismatched PDB file, Visual Studio cannot smoothly enter the crash site.

What is a PDB File?

A PDB file is a debugging information file created by Microsoft, used for debugging programs. It contains information such as the symbol table, source code filenames, line numbers, and other debugging data. A PDB file can be generated during program compilation to aid in debugging.

WinDbg Debugging

WinDbg is a debugging tool from Microsoft that can be used to debug Windows programs. WinDbg can load mismatched PDB files, but this requires manual loading. The .reload /f /i command forces the loading of mismatched PDB files.

However, WinDbg is less convenient to use than Visual Studio, so we want Visual Studio to also be able to load mismatched PDB files.

Visual Studio Cannot Load Matching PDB Files

Source code is now generally managed through Git, allowing you to find the corresponding version of the code and recompile it to generate matching PDB files. Why can’t they be loaded? The main reason is that metadata doesn’t match.

There’s a small tool that can modify metadata, generating a new PDB file based on the EXE file information so that Visual Studio can load it.

ChkMatch download address: https://www.debuginfo.com/tools/chkmatch.html Site cache address: chkmatch.zip

The 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 a 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.

Using chkmatch

First, perform the check operation to analyze the cause of mismatches and prompt signature mismatch.

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 the modify operation to match the pdb file with 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:

## References
- [forcing-to-load-unmatched-symbols-in-visual-studio-2015-debugger](https://stackoverflow.com/questions/38147487/forcing-to-load-unmatched-symbols-in-visual-studio-2015-debugger)
A financial IT programmer's tinkering and daily life musings
Built with Hugo
Theme Stack designed by Jimmy