Reputation: 436
Hi im trying to read data from pdb files
Ive followed the steps from How do I use the MS DIA SDK from C#? and generated the assembly
The problem is: When calling dataSource.loadDataFromPdb on a MS pdb file it throws a ComException(HRESULT: 0x806D000C)
Ive tried using dumpbin.exe /headers but it fails with "unknown format"
Using .loadDataFromPdb and dumpbin on a selfgenerated pdb works as it should
IDiaDataSource dataSource = new DiaSourceClass();
//dataSource.loadDataFromPdb(@"D:\Symbols\System.Data.Entity.pdb"); // Fails
dataSource.loadDataFromPdb(@"D:\Symbols\myassembly.pdb"); // Success
IDiaSession session;
dataSource.openSession(out session);
var guid = session.globalScope.guid.ToString();
Is there another way to open MS pdb files, and specifically extract the GUID
Upvotes: 2
Views: 2313
Reputation: 1012
A little math based on the info here suggests that 0x806D000C corresponds to E_PDB_FORMAT which MSDN has a description of: "Attempted to access a file with an obsolete format."
Based on that I have to ask (yes, a late possible )... do your recall which version of Visual Studio & DIA you were attempting this with? It is possible that the PDB format may have changed for those PDBs being sent by Microsoft that your tooling may not have been up to date.
Upvotes: 3
Reputation: 8019
You can read the GUID value from the .pdb file using a BinaryReader like below. The key is getting the offsets:
var fileName = @"c:\temp\StructureMap.pdb";
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
using (BinaryReader binReader = new BinaryReader(fs))
{
// This is where the GUID for the .pdb file is stored
fs.Position = 0x00000a0c;
//starts at 0xa0c but is pieced together up to 0xa1b
byte[] guidBytes = binReader.ReadBytes(16);
Guid pdbGuid = new Guid(guidBytes);
Debug.WriteLine(pdbGuid.ToString());
}
}
to get the value from a .dll or .exe requires a bit more work :)
Upvotes: 1