调试 C++ Windbg 中的 STL 容器
Windbg 粉丝声称它非常强大,我也倾向于同意。 但当涉及到调试STL容器时,我总是陷入困境。 如果变量位于堆栈上,!stl
扩展有时会计算出来,但是当容器具有复杂类型时(例如 std::vector
) 位于堆或其他结构的一部分上,我只是不知道如何查看其内容。
感谢任何提示、指点。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我通常最终会在很多类中使用
toString()
方法。 这显示了我认为重要的所有信息,任何容器都可以调用它来在控制台中显示类信息I usually end up sticking a
toString()
method in a lot of my classes. This shows all the info that I deem important, any containers can then call this to display the class information in the console使用 dt -r
即 dt yourapp!class 7ffdf000 -r5
Use dt -r
i.e dt yourapp!class 7ffdf000 -r5
WinDbg (pykd) 的 Python 扩展 有片段 stlp.py 可以转储地图内容。
目前它支持STLPort映射实现。 在 x86 和 x64 上测试。
这篇文章演示了如何使用它(其在俄语,但是,示例是不言自明的)。
Python extension for WinDbg (pykd) have snippet stlp.py which can dump map contents.
Currently it supports STLPort map implementation. Tested on x86 and x64.
This article demonstrates how to use it (its on Russian, but, examples are self-explanatory).
前段时间我也有同样的问题。 我的答案是,Visual Studio 确实是 STL 和复杂类型更好的调试器(就像 Visual Studio 只是比 MDbg 更好的调试器一样)。
这并不是说 WinDBG 功能较弱,只是它的级别较低(例如,尝试使用 Visual Studio 对故障转储执行任何有用的操作 - 但您不能)。
无论如何,要回答您的问题,您可以使用 Visual Studio 使用一些技巧来查看数据类型:
cdb -p; -pv
。 这将挂起调试者的线程。 现在,您可以安全地分离原始 WinDBGqd
qd
。 查看 STL 并按照您的意愿继续。I had the exact same question some time ago. My answer is that Visual Studio is truly a better debugger for STL and complex types (just like Visual Studio is just a plain better debugger than MDbg).
This is not to say WinDBG is less powerful, just that it's lower level (e.g. try doing anything useful with crash dumps using Visual Studio -- you can't).
Anyway, to answer your question, you can use Visual Studio to look at the data types using some tricks:
cdb -p <PID> -pv
. This will suspend the threads of the debugee. Now you can safely detach the original WinDBGqd
qd
. Look at the STL and continue as you wish.您可能还想尝试一下调试器扩展。 它是一个名为 SDbgExt 的库,由 Skywing 开发。
You might also want to give this debugger extension a try. It is a library called SDbgExt, developed by Skywing.
我经常发现调试器对 STL 数据类型的支持不够。 因此,我越来越多地使用日志框架和日志语句。 我曾经认为这些是为那些无法使用调试器的人准备的,但我现在意识到它们提供了真正的价值。 它们允许您将可移植的调试知识嵌入到代码中,并将其与代码一起维护。 相反,您在调试器中所做的工作通常是短暂的。
I often find debugger support for STL data types inadequate. For this reason I'm increasingly using logging frameworks and logging statements. I used to think that these are for people who can't use a debugger, but I now realize that they offer real value. They allow you to embed portable debugging knowledge in your code and maintain it together with the code. In contrast, work you do in the debugger is typically ephemeral.