21

I figured out how a .NET assembly .dll file maps to a .pdb using a GUID (blog). When I debug into an assembly and it asks for the source code, if I navigate to a file, it may tell me that the source code is different from the original. How does it know this? I was expecting the .pdb file to contain a checksum for each file, but it doesn't appear to. The best tool I found to dump the debug information is dia2dump. The C++ .pdb files had MD5 entries, but the C# .pdb files did not.

C++ dump
dia2dump -f dia2dump.pdb > dia2dump.pdb.files.txt

C# dump
dia2dump -f Autofac.pdb > Autofac.pdb.files.txt
dia2dump -all Autofac.pdb > Autofac.pdb.all.txt

Is there something I missed in the "all" dump?

It has got to be using a checksum. If I change a single character in Module.cs, I get:
enter image description here

Where do I find the checksum for a source file referenced in a .pdb?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Cameron Taggart
  • 5,771
  • 4
  • 45
  • 70

1 Answers1

13

An MD5 checksum is stored in the .pdb file for each source file. If you answer "No" to the question above "Would you like the debugger to use it anyway?", it prints out the checksum it was looking for:

enter image description here

Using a hex editor, you can see it is definitely in the .pdb. My next task is to figure out how to get access to it programatically. For a .pdb file, I want it to return all source file names and their MD5 checksums.

enter image description here

Cameron Taggart
  • 5,771
  • 4
  • 45
  • 70
  • I've been looking at pdb files a lot lately. You can find more details here. http://blog.ctaggart.com/search/label/pdb – Cameron Taggart Jun 19 '13 at 15:40
  • Did you ever find a way to get the MD5 hash out of the .NET PDBs? – Petrik Apr 22 '14 at 04:07
  • 4
    I did. I created a .NET library named SourceLink that can do it. https://github.com/ctaggart/SourceLink – Cameron Taggart Apr 22 '14 at 13:24
  • @CameronTaggart unfortunately the Source search information is [not available anymore in VS2015](http://i.stack.imgur.com/58uO7.png) – m0sa Dec 03 '15 at 09:18
  • 3
    `sourcelink checksums -p ` to save the day – m0sa Dec 03 '15 at 09:35
  • @CameronTaggart I know this is an old post, but.. the link in your [comment above](https://stackoverflow.com/questions/17120215/how-does-visual-studio-know-if-the-source-file-matches-the-original-version#comment24904184_17124980) says "no posts found". – S.L. Barth is on codidact.com Nov 08 '17 at 09:56
  • @S.L.Barth SourceLink is still alive. Lots of blog posts with the "SourceLink" label instead: http://blog.ctaggart.com/search/label/SourceLink – Cameron Taggart Nov 08 '17 at 12:53