C
C#17mo ago
dreamdoctor

❔ Read a .pdb file in C#

Does anyone have a simple example of opening and reading a Windows PDB (not Portable PDB) file in C#? The examples I can find from Microsoft and others are all in C++, and the couple of examples I can find are very old and no longer work.
14 Replies
dreamdoctor
dreamdoctor17mo ago
Everything I can find says to use Microsoft.DiaSymReader.Native (https://www.nuget.org/packages/Microsoft.DiaSymReader.Native/), however I cannot find a single piece of documentation or further information anywhere.
Denis
Denis17mo ago
I believe it is best to use a library for that. dnlib is a wonderful reflection library that has pdb reading features However, I found that reading pdb files can be quite tricky and unstable. I required reading them to determine the source code file for a given type discovered via reflection. Finding the source file worked for some pdbs, while not for others and still to this day I'm not sure what affects this
Denis
Denis17mo ago
GitHub
ModularDoc/Resolver.cs at b41eb3adadbd5a4d40ac2a277a3b60c6e2cf7a91 ...
Modular documentation generator for .NET libraries. Currently supporting Markdown only for GitHub, GitLab, and Bitbucket - ModularDoc/Resolver.cs at b41eb3adadbd5a4d40ac2a277a3b60c6e2cf7a91 · hails...
Denis
Denis17mo ago
There's also sharpdb or something like that for loading pdbs
dreamdoctor
dreamdoctor17mo ago
Thank you so much for the information. Were you reading Windows PDBs? From your code it looks like you were working with Portable PDBs?
Denis
Denis17mo ago
Should work with both imo SharpPdb is supposed to support switching between the two pdb types Been butchering the name of the library this whole time
Denis
Denis17mo ago
GitHub
GitHub - southpolenator/SharpPdb: Library for reading PDB files, bo...
Library for reading PDB files, both Windows and PortablePDBs. - GitHub - southpolenator/SharpPdb: Library for reading PDB files, both Windows and PortablePDBs.
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
dreamdoctor
dreamdoctor17mo ago
Unfortunately, as with every other library I've tried, I can't find a single example to demonstrate how to read native Windows PDB files using the SharpPdb library. I even tried asking ChatGPT, however the code it gave me was basically nonsense.
Anton
Anton17mo ago
GitHub
SharpPdb/PdbFileTests.cs at master · southpolenator/SharpPdb
Library for reading PDB files, both Windows and PortablePDBs. - SharpPdb/PdbFileTests.cs at master · southpolenator/SharpPdb
dreamdoctor
dreamdoctor17mo ago
Thanks but that doesn't help.
Denis
Denis17mo ago
How come? It should at least give you some pointers on how to do it. Unfortunately, PDB is quite an undocumented topic, and it will probably require a lot of trial and error
dreamdoctor
dreamdoctor17mo ago
I've spent three days trying to work it all out. Those tests don't offer any real examples.
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.