关于线程安全的 DbgHelp vs DbgEng vs DIA SDK

DbgHelp vs DbgEng vs DIA SDK in regards to thread safety

所有这些 APIs(DbgHelp、DbgEng、DIA SDK)可用于从函数指针恢复函数 name/source 文件位置,因此可用于解密堆栈跟踪。

但是,每个 DbgHelp 函数都有以下注释:

All DbgHelp functions, such as this one, 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.

至于 DbgEng,没有这样的声明,但它似乎是基于 DbgHelp,因此不能是线程安全的:即使 DbgEng 保护对 DbgHelp 的每次调用,也可能有对 DbgHelp 的调用不是来自DbgEng,但直接来自用户的代码。

恐怕DIA SDK也是用DbgHelp实现的

那么,是否有可以在为多线程应用程序设计的库中使用的可靠符号 API?

DIA SDK 被假定为线程安全解决方案。

Boost.Stacktrace 存储库中有一个 issue 要求切换到 DIA SDK。那里提到了 DbgHelp 和 DbgEng 的不安全性。

还有一个选项可以滚动自己的实现;一个可能的起点在这里:https://github.com/microsoft/microsoft-pdb