Using the DIA SDK (Debug Interface Access SDK) from .Net
I’m currently working on a new MemorySystem. So I just wanted to access some Debugging Information out of the .pdb file … But this, turned into quite some time spent . The Documentation isn’t really a great help, when you are starting to use the DIA SDK for the first time.
When using the DIA SDK from .Net, even less documentation is available on the Web.
The DIA SDK is a COM component so we can just Add a Reference to it in our C# project.
Under the COM Tab you should find the “dia 2.0 Type Library”, this is the Component you have to add.
If you don’t have the component in the list, as I had. You aren’t lost. The dll is just not registered. We have to do this manually. Normally this should be done by the installer, but the newer versions seem to be not doing this.
Register the dll manually
So start by searching for the DIA SDK directory. This is normally placed under your Visual Studio install directory. When you have multiple version of Visual Studio installed on your computer (as I have) you can choose which version you want to use. I choose to use the Version installed with VS 2010. In most cases you should be using the newest version available to you.
If you have found the directory it’s time to open cmd.exe and move to the \bin folder in the DIA SDK you choose to use.
For me the Path is: D:\Program Files (x86)\Microsoft Visual Studio 10.0\DIA SDK\bin
When you are in the directory, execute the following command, to register the dll.
regsvr32 msdia<VersionNumber>.dll
(For me the file was named: msdia100.dll)
You will now be presented with a window telling you that the dll was registered correctly. If not, you will receive an error.
If you have successfully registered the dll, close Visual Studio and reopen it, so it will reload the references. You should now find the “dia 2.0 Type Library” under the COM components Tab under Add References.
Just add the reference.
Using the DIA SDK to load a .pdb
The following section is not mean to be a complete tutorial, just should show how to use SDK from .Net. From now on always have a look at the Documentation.
The first thing you have to create is a to create a source where the data is coming from.
IDiaDataSource source = new DiaSource();
So now we have to load the actual pdb file. There are multiple possibilities to do this. We can explicitly tell which pdb file to load:
source.loadDataFromPdb(@"D:\Jendrik Illner Projects\C++\TestApplication1\Debug\TestApplication1.pdb");
Or we let the SDK decide which one to use:
source.loadDataForExe(@"D:\Jendrik Illner Projects\C++\TestApplication1\Debug\TestApplication1.exe", @".\Debug", null);
Now we told where the data coming from, but we are not able to access it. For this we have to define and open a IDiaSession.
IDiaSession session;
source.openSession(out session);
Now we are able to access all information available in the PDB file, which can be a huge amount of data.
List all functions from the PDB
This is just a example of what you can do with a PDB file. This will just list all functions listed in the PDB file.
IDiaEnumSymbols results; session.findChildren(session.globalScope, SymTagEnum.SymTagFunction, null, 0, out results); foreach (IDiaSymbol symbol in results) { Console.WriteLine(symbol.name); }
Hope this small Article helps getting you started with the DIA SDK. If you have any questions left unanswered, feel free to ask them.

