简体   繁体   English

分段错误后GDB不返回

[英]GDB doesn't return after segmentation fault

I have some code, that I'm currently porting from OS X to Linux (console tool). 我有一些代码,目前正在从OS X移植到Linux(控制台工具)。

Somewhere in this code, I get a segmentation fault. 在这段代码的某个地方,我遇到了分段错误。 The problem is, that if I run the program without GDB, I clearly see the segmentation fault, and the program is killed. 问题是,如果我在没有GDB的情况下运行该程序,我会清楚地看到分段错误,并且该程序将被杀死。 But when I'm running GDB it just halts, and GDB never returns to the prompt. 但是,当我运行GDB时,它只是停止了,而GDB从不返回提示。 So I'm not really able to examine what's going on. 因此,我真的无法检查发生了什么。

C++ is the code. C ++是代码。 Compiled with the -g option in g++. 与g ++中的-g选项一起编译。

Btw. 顺便说一句。 Pretty new to GDB, so excuse me if this is obvious. 对GDB来说还很陌生,如果这很明显,请原谅。

Any ideas? 有任何想法吗? Thanks in advance. 提前致谢。

Trenskow 特伦斯科

gdb will suspend your program when the seg fault signal is received 收到seg错误信号时,gdb将暂停您的程序

type where to see the stack trace and start inspecting what's going on from there. 键入where看到堆栈跟踪,并开始检查什么从那里上。

Also consider enabling core dumps, that way you can load the core dump in GDB and investigate what is going on 还可以考虑启用核心转储,这样您就可以在GDB中加载核心转储并调查正在发生的事情

you can then load the core dump like this 然后您可以像这样加载核心转储

> gdb your_program the_core_dump

The behaviour you describe is not typical - I suspect the stack may have been trashed. 您描述的行为不是典型的-我怀疑堆栈可能已被丢弃。

Try sending various signals directly via the 'kill' command. 尝试直接通过“ kill”命令发送各种信号。

Might be worth you running a test program in gdb with an abort() in it so that you can learn what the expected behaviour is for gdb. 您可能值得在gdb中运行带有abort()的测试程序,以便了解gdb的预期行为。

I've seen this before when my stack was too large. 在堆栈太大之前,我已经看到了这一点。 Try moving stack variables onto the heap (make them globals), recompile, and see if you still get the error. 尝试将堆栈变量移动到堆上(使它们成为全局变量),重新编译,看看是否仍然收到错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM