How do I get the PDB source file checksums with DIA?

Shouldn't IDiaSourceFile::get_checksum return the hash calculated for each source file AFAICT the debugger has some way to determine whether a file has changed since it was compiled. I figured that's the hash.

However, IDiaSourceFile::get_checksumType always returns 0. And IDiaSourceFile::get_checksum leaves pcbData unchanged when both cbData and data are 0 (which is probably a bug even if no checksum is present)

Is the information present at all (assuming a standard PDB with private symbols (/Zi) ) If so, where do I get it from Or where does the debugger get if from

Thanks

-hg



Answer this question

How do I get the PDB source file checksums with DIA?

  • Kevin O Donovan

    Yes, checksums are present in the PDB files generate with the latest VC++ compiler.

    As I said in my previous reply, checksums are indeed useful for verifying that the source file did not change when you're debugging and stepping into it in the debugger. This kind of information is very useful when you have a Source Server setup for instance which holds the source file information and could help you find the right version. Now as far as generating the hash sequence yourself, I don't realy know exactly how you can do it. Check the web for a free hash alghoritm implementation; VC++ uses MD5 to generate 16 bytes long hashes.

    And yes, this property is supported! I worked with it myself :-)

    VS2005 is actually shipped with a DIA SDK sample called Dia2Dump; try to build that sample and pass to the executable that is generate "-l" and the PDB file it was also generated. The output will look like this:

    line 215 at [0xd650][0x1:0xc650], len = 0x6 f:\your_source_file_name (checksum = 0xdf 0xb4 0xec 0x56 0x90 0x4b 0xef 0x94 0xa1 0x07 0xd8 0x5e 0x5e 0x58 0x5b 0x5d )
    line 216 at [0xd656][0x1:0xc656], len = 0x4b
    line 218 at [0xd6a1][0x1:0xc6a1], len = 0x29
    line 220 at [0xd6ca][0x1:0xc6ca], len = 0x2
    line 219 at [0xd6cc][0x1:0xc6cc], len = 0x17



  • binyaz

    Thanks. Works fine with the same code path that's taken by dia2dump (i.e. for each compiland find the source files and dump the check sum).

    What I did was enumerating the records in the "SourceFiles" table, which for some reason does not work (even though I get all other properties of the source files).

    -hg


  • John Torjo

    You're correct, IDiaSourceFile::get_checksum will retrieve the corresponding hash stored inside the PDB for a source file. The debugger will look at the current source file and recalculate that hash then compare with the existing one stored in the PDB file. I personally don't think of any tool Microsoft shipped for public usage to calculate that hash for a given source file. Still I believe the alghoriths are public and you could probably implement one on your own.

    The reason why you can get the hash for your particular source file could be because you might not have one store in the PDB you're working with. I can see a number of causes: old PDB file (not built with VC++ 2005 compiler), static linked libraries that have no debug info for that specific source file...



  • engfellow

    So do you say it should work with a valid PDB

    Consider I'd like to write my own debugger (actually I only want to inject some additional information), how would I make sure the file has not changed I.e. if I don't calculate the hash myself at compile time, then there's nothing to compare to.

    Did you try to generate a PDB with checksums I did build with /Zi and VC 2005. Just vanilla C++. I get everything but the checksum property (it is not present in IDiaPropertyStorage::Enum) and checksumType is always 0 (==none).

    Are you sure this property is really supported

    Thanks

    -hg


  • Michael Sargent

    I'm glad to hear that it worked :-)

    And yes, you have to go through the compiland in order to get the hashes for the source file. It is by design not to have the hashes present in the SourceFiles table (one reason could be that you have multiple instances with the same name for a source file but compiled differently because of different macro defs being used).



  • How do I get the PDB source file checksums with DIA?