Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Consider alternatives to dbghelp.dll #535

Open
ChrisDenton opened this issue Jun 28, 2023 · 1 comment
Open

Windows: Consider alternatives to dbghelp.dll #535

ChrisDenton opened this issue Jun 28, 2023 · 1 comment

Comments

@ChrisDenton
Copy link
Member

The advantage of dbghelp.dll is that it can nearly always be found on any Windows system. However, the major disadvantage is it's ridiculously single threaded:

Note that all DbgHelp functions are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function.

We have to implement synchronization across whatever random dlls may be thrown together and hope to hell nothing else is using it in the same process. It also may be old, The PDB debug format can and does change over time.

A stack backtrace can be retrieved without dbghelp using either CaptureStackBackTrace or RtlVirtualUnwind.

Reading PDB files is more complex but can be done using the Debug Interface Access (DIA) SDK. The downside is this requires an msdia*.dll but at least it's redistributable. The upside is that it has a proper API that doesn't break in the presence of threads.


Note: I don't personally have a ton of time atm to follow up on this but I'm posting it here in case someone else wants to. Maybe that someone will be future!me, or maybe not. Also it's fine to conclude that dbghelp is our best option but I'm kinda hoping it isn't.

@ChrisDenton
Copy link
Member Author

As I noted in the experiment linked above, decoupling tracing from symbol loading can be done even without deciding on dia vs. dbghelp. Not needing to load an external dll is great if you just need to store a backtrace for later. Also doing this would mean the windows-gnu targets don't need dbghelp or dia at all since they use DWARF.

If anyone wants to try this then I think the easiest thing would be to try using RtlVirtualUnwind on x86_64 only initially.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants