使用dia-sdk从microsoft pdb文件加载数据

时间:2013-08-22 07:19:05

标签: c# .net pdb-files dia-sdk

我正在尝试从pdb文件中读取数据

我已按照How do I use the MS DIA SDK from C#?中的步骤生成了程序集

问题是:在MS pdb文件上调用dataSource.loadDataFromPdb时,它会抛出一个ComException(HRESULT:0x806D000C)

我尝试过使用dumpbin.exe / headers但是它以“未知格式”

失败

在自生成的pdb上使用.loadDataFromPdb和dumpbin可以正常工作

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();

是否有其他方法可以打开MS pdb文件,特别是提取GUID

2 个答案:

答案 0 :(得分:1)

基于info here的小数学建议0x806D000C对应于E_PDB_FORMAT which MSDN has a description of:“试图访问具有过时格式的文件。”

基于此我不得不问(是的,可能是迟到的)...你还记得哪个版本的Visual Studio& DIA你试过这个吗?对于Microsoft发送的那些您的工具可能不是最新的PDB,PDB格式可能已经发生了变化。

答案 1 :(得分:0)

您可以使用如下所示的BinaryReader从.pdb文件中读取GUID值。关键是获得抵消:

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());
    }
}

从.dll或.exe中获取值需要更多的工作:)