我想出了一个使用MSYS2 终端的方法。其他方法可能适用于 GUI 软件。
一个主要的警告是,这不能在纯 C/C++ 中完成并为最终用户发布。它仅供开发人员使用,但总比没有好。
通过下载 Windows SDK 并取消选中除调试工具以外的所有内容来安装 Debugging Tools for Windows。
我可能是错的,但似乎安装此软件会在 Windows 内核中安装一个挂钩,以允许 LoadLibrary() 将详细信息写入标准错误。
以管理员身份打开MSYS2 Mingw64终端并运行
'/c/Program Files (x86)/Windows Kits/10/Debuggers/x64/gflags.exe' -i main.exe +sls
这会将以下内容打印到终端以确认注册表已更改。
Current Registry Settings for main.exe executable are: 00000002
sls - Show Loader Snaps
如果您需要撤消,请使用 -sls 而不是 +sls,因为我相信更改会发生在全局 Windows 中所有名为 main.exe 的程序上,而不仅仅是您的文件。
然后运行main.exe 应该将调试信息打印到stderr,但由于我正在调试-mwindows 应用程序,它不适合我。
但由于某种原因,使用 MSYS2 的 gdb 运行二进制文件允许将此调试信息打印到 stderr。
使用 MSYS2 安装 mingw-w64-x86_64-gdb 并运行 gdb ./main.exe 并键入 run 或 r。
搜索类似于以下内容的部分。
warning: 1ec8:43a0 @ 764081125 - LdrpNameToOrdinal - WARNING: Procedure "foo" could not be located in DLL at base 0x000000006FC40000.
warning: 1ec8:43a0 @ 764081125 - LdrpReportError - ERROR: Locating export "foo" for DLL "C:\whatever\plugin.dll" failed with status: 0xc0000139.
warning: 1ec8:43a0 @ 764081125 - LdrpGenericExceptionFilter - ERROR: Function LdrpSnapModule raised exception 0xc0000139
Exception record: .exr 00000000050BE5F0
Context record: .cxr 00000000050BE100
warning: 1ec8:43a0 @ 764081125 - LdrpProcessWork - ERROR: Unable to load DLL: "C:\whatever\plugin.dll", Parent Module: "(null)", Status: 0xc0000139
warning: 1ec8:43a0 @ 764081171 - LdrpLoadDllInternal - RETURN: Status: 0xc0000139
warning: 1ec8:43a0 @ 764081171 - LdrLoadDll - RETURN: Status: 0xc0000139
太棒了!它说Procedure "foo" could not be located in DLL,所以我们缺少符号,就像在 POSIX/UNIX 的dlopen() 中一样。