检查堆栈

发布于 2024-11-09 05:02:24 字数 319 浏览 4 评论 0 原文

我遇到堆栈溢出问题,想确切地了解堆栈上的内容是什么。

如何使用 GDB 检查堆栈帧? 是同样的问题,但是 info locals 在这里看起来很好(很少有变量,其中大多数是 std::vector 和 std::maps),所以我不认为堆栈会因此溢出。此外,我已将堆栈限制设置为 32MB,因此这应该足够并且不使用递归函数。

是否有一个工具可以显示堆栈的完整内容(可能按大小排序)?

I'm having problems with stack overflows and would like to see exactly what the contents on the stack are.

How can I examine the stack frame with GDB? is kind of the same question, however info locals looks fine here (few variables, most of them std::vectors and std::maps), so I wouldn't expect the stack to overflow from this. Moreover, I have set the stack limit to 32MB, so this should be plenty and no recursive functions are used.

Is there a tool that can show the complete contents of the stack, maybe ordered by size?

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

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

发布评论

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

评论(4

南巷近海 2024-11-16 05:02:24

堆栈溢出可以通过特殊的分析器更好地捕获,而不是手动查看 gdb 中的变量。更有可能的是缓冲区溢出而不是堆栈溢出。无论哪种情况,下面列出了一些分析器,可以帮助您指出问题:

祝你好运!

Stack overflows are better caught by special profilers rather than manually looking at variables in gdb. It is more likely that you have buffer overrun rather than stack overflow. In either case, here is a list of some profilers that can help you to point out the problem:

Good luck!

后知后觉 2024-11-16 05:02:24

即使您没有调用自身的函数,您也可能创建了两个或多个函数相互递归的情况。

一个好的起点是使用“backtrace”(或简称“bt”)命令检查堆栈帧列表,而不是当前堆栈帧。如果您看到两个或多个函数相互调用的重复模式,则说明存在相互递归。

Even if you have no functions that call themselves, it's possible you've created a situation in which two or more functions are mutually recursive.

A good starting point would be to examine not the current stack frame, but a list of stack frames, using the "backtrace" (or "bt" for short) command. If you see a repeated pattern of two or more functions calling each other, then you have mutual recursion.

凯凯我们等你回来 2024-11-16 05:02:24

您可以使用 backtrace 命令检查当前堆栈帧。

You can examine the current stack frame using the backtrace command.

A君 2024-11-16 05:02:24

您还可以获取 gdb 中的当前堆栈指针(例如,通过运行“信息寄存器”),然后使用检查(或“x”)命令转储该位置周围的内存。请注意,堆栈指针指向堆栈下方,因此您需要从堆栈指针 - N 开始转储以查看堆栈上的前 N ​​个字节。

You can also get the current stack pointer in gdb (e.g., by running 'info registers') and then dump the memory around that location using the examine (or 'x') command. Just be aware that the stack pointer points below the stack, so you need to start dumping from stack pointer - N to see the first N bytes on the stack.

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