调试 C++ Windbg 中的 STL 容器

发布于 2024-07-07 00:53:51 字数 285 浏览 2 评论 0 原文

Windbg 粉丝声称它非常强大,我也倾向于同意。 但当涉及到调试STL容器时,我总是陷入困境。 如果变量位于堆栈上,!stl 扩展有时会计算出来,但是当容器具有复杂类型时(例如 std::vector ; >) 位于堆或其他结构的一部分上,我只是不知道如何查看其内容。

感谢任何提示、指点。

Windbg fans claim that it is quite powerful and I tend to agree. But when it comes to debugging STL containers, I am always stuck. If the variable is on the stack, the !stl extension sometimes figures it out, but when a container with a complex type (e.g. std::vector<TemplateField, std::allocator<TemplateField> >) is on the heap or part of some other structure, I just don't know how to view its contents.

Appreciate any tips, pointers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

自此以后,行同陌路 2024-07-14 00:53:52

我通常最终会在很多类中使用 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

对岸观火 2024-07-14 00:53:52

使用 dt -r
即 dt yourapp!class 7ffdf000 -r5

Use dt -r
i.e dt yourapp!class 7ffdf000 -r5

你的笑 2024-07-14 00:53:52

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).

自由范儿 2024-07-14 00:53:52

前段时间我也有同样的问题。 我的答案是,Visual Studio 确实是 STL 和复杂类型更好的调试器(就像 Visual Studio 只是比 MDbg 更好的调试器一样)。

这并不是说 WinDBG 功能较弱,只是它的级别较低(例如,尝试使用 Visual Studio 对故障转储执行任何有用的操作 - 但您不能)。

无论如何,要回答您的问题,您可以使用 Visual Studio 使用一些技巧来查看数据类型:

  1. 启动 WinDBG 的另一个实例,以非侵入方式附加:cdb -p ; -pv。 这将挂起调试者的线程。 现在,您可以安全地分离原始 WinDBG qd
  2. 将 Visual Studio 附加到其上,然后分离非侵入式 WinDBG qd。 查看 STL 并按照您的意愿继续。
  3. 当您需要返回WinDBG时,请转到步骤1,与侵入式WinDBG交换。

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:

  1. Start another instance of WinDBG, attach non-invasively: cdb -p <PID> -pv. This will suspend the threads of the debugee. Now you can safely detach the original WinDBG qd
  2. Attach Visual Studio to it, and then detach the non-invasive WinDBG qd. Look at the STL and continue as you wish.
  3. When you need to go back to WinDBG, goto step 1, swap with an invasive WinDBG.
梦幻的味道 2024-07-14 00:53:52

您可能还想尝试一下调试器扩展。 它是一个名为 SDbgExt 的库,由 Skywing 开发。

You might also want to give this debugger extension a try. It is a library called SDbgExt, developed by Skywing.

送舟行 2024-07-14 00:53:51

我经常发现调试器对 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文