我怎样才能在gdb中调试这个SIGSEV?

发布于 2024-09-11 07:09:02 字数 589 浏览 2 评论 0原文

我正在构建以前可以工作的代码,但是遇到了段错误,并且我无法弄清楚出了什么问题。 gdb 捕获了错误,但没有指出明显的原因。它显示的源代码行是一个函数名称,因此它甚至没有进入该函数。如果我查看指令的反汇编,它仍在设置堆栈,所以堆栈可能被搞乱了。那么我应该如何调试呢?这是在 QNX 6.2 中,仅限控制台 gdb。

0x0816b829 in __ml (this=0x79b963c, anMultiplier=0) at ../u_matrix.cpp:56
56      tcMatrix tcMatrix::operator*(float64 anMultiplier)

0x816b820 <__ml>:       push   %ebp
0x816b821 <__ml+1>:     mov    %esp,%ebp
0x816b823 <__ml+3>:     sub    $0x13ac,%esp
0x816b829 <__ml+9>:     push   %edi
0x816b82a <__ml+10>:    push   %esi
0x816b82b <__ml+11>:    push   %ebx 

I am building previously working code, but I am getting a seg fault and I can't figure out what went wrong. gdb catches the error, but it doesn't point to an obvious cause. The source line it shows is a function name, so it doesn't even get into the function. If I look at the dissasembly of the instruction it is still setting up the stack, so maybe the stack is messed up. So how should I go about debugging this? This is in QNX 6.2, console gdb only.

0x0816b829 in __ml (this=0x79b963c, anMultiplier=0) at ../u_matrix.cpp:56
56      tcMatrix tcMatrix::operator*(float64 anMultiplier)

0x816b820 <__ml>:       push   %ebp
0x816b821 <__ml+1>:     mov    %esp,%ebp
0x816b823 <__ml+3>:     sub    $0x13ac,%esp
0x816b829 <__ml+9>:     push   %edi
0x816b82a <__ml+10>:    push   %esi
0x816b82b <__ml+11>:    push   %ebx 

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

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

发布评论

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

评论(6

葵雨 2024-09-18 07:09:02

您崩溃的指令是push %edi

这很可能意味着您有堆栈溢出。

堆栈溢出的可能原因之一是无限递归。如果 (gdb) where 显示无休止的函数调用流,那就是你的问题。

如果where显示合理的调用顺序,则重复执行infoframeup,寻找尺寸过大的帧。

最后,问题可能是由执行环境的更改引起的,而不是由程序中的任何内容引起的。我不确定 ulimit -s 的 QNX 等价物是什么,但您的堆栈限制可能太小了。

The instruction you are crashing on is push %edi.

This most likely means that you have a stack overflow.

One likely cause of stack overflow is infinite recursion. If (gdb) where shows unending stream of function calls, that's your problem.

If where shows reasonable sequence of calls, execute info frame and up repeatedly, looking for frames with unreasonably large size.

Finally, the problem may be caused by a change in your execution environment, and not by anything in your program. I am not sure what QNX equivalent of ulimit -s is, but it's possible that your stack limit is simply too small.

梨涡少年 2024-09-18 07:09:02

以下是俄罗斯雇员的回答:

ulimit -s 适用于 QNX,但默认情况下是无限制的。

我将尝试使用

ldrel -S2M -L yourexecutablename

来调整初始堆栈分配/惰性,以查看核心转储是否再次发生。您还可以使用 QCC 的 -N 标志将初始堆栈大小设置得更高。

Following Employed Russian's answer:

ulimit -s works on QNX but it is unlimited by default.

I would experiment with

ldrel -S2M -L yourexecutablename

to adjust the initial stack allocation / laziness to see if coredumps reoccur. You can also use QCC's -N flag to set the initial stack size higher.

醉生梦死 2024-09-18 07:09:02

如果在 gdb 中执行“bt”,有什么相关的吗?

Anything relevant if doing a "bt" in gdb?

找个人就嫁了吧 2024-09-18 07:09:02

“this”指针看起来很混乱 - 0x79b963c 似乎已关闭,但有可能取决于对象的初始化方式。尝试

print *this

并查看数据是否有意义还是垃圾。它也看起来像你的源与可执行文件不匹配 - 示例中的行看起来像一个运算符覆盖声明,而不是可执行文件。

我会忽略特定的行,在源代码中查找整个 _ml 函数,并尝试打印一些局部变量,看看您是否位于循环或其他包含它们的范围内。

我猜你有一个矩阵乘法运算符,其中矩阵乘以浮点数 - 很可能这类似于索引越界,某种离一问题,你在内存范围之外运行并损坏了堆栈。

就像 Unknown 所说,也尝试一下 bt - 如果它返回大量 ??() 那么你确实有一个损坏的堆栈。

"this" pointer looks messed up - 0x79b963c seems to be off but it is possible depending on how objects are initialized. Try

print *this

and see if data makes sense or is garbage. It also looks like your source doesn't match the executable - the line you have in the example looks like an operator override declaration and not something executable.

I would ignore the particular line, look for the whole _ml function in the source and try printing a few local variables to see if maybe you are within a loop or some other scope that would have them.

I am guessing you have a matrix multiplication operator where a matrix is multiplied by a float - most likely this is something like index out of bounds, off-by-one problem of some sort where you ran outside of the memory scope and corrupted the stack.

like Unknown said, try bt as well - if it comes back with a lot of ??()'s then you do have a corrupt stack.

十级心震 2024-09-18 07:09:02

QNX does now appear to support valgrind (at least from 6.5 onwards):

http://community.qnx.com/sf/frs/do/viewRelease/projects.valgrind/frs.valgrind.valgrind_3_10

无名指的心愿 2024-09-18 07:09:02

您也可以尝试对其进行 valgrind'ing,这可以提供更多信息。

You could also try valgrind'ing it, which can give more info.

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