简体   繁体   English

程序接收信号SIGSEGV,分段故障(程序耗尽堆栈。)

[英]Program received signal SIGSEGV, Segmentation fault (program runs out of stack.)

I get this error message when i run the program with gdb. 当我用gdb运行程序时,我收到此错误消息。 The error is shown at this line: 错误显示在此行:

long a = thread_fake(); //in file1.c

I was getting the problem with other function that was defined in a separate file, so i simplified it to a simple function that just returns 0. The function has been defined as: 我得到了在单独的文件中定义的其他函数的问题,所以我将其简化为一个只返回0的简单函数。该函数定义为:

long thread_fake(){ //defined in file2.c
    return 0;
}

As @EmployedRussian pointed out, it seems the program runs out of stack. 正如@EmployedRussian所指出的那样,程序似乎已经耗尽了堆栈。 The valgrind shows the following error: valgrind显示以下错误:

==14711== 144 bytes in 1 blocks are possibly lost in loss record 17 of 32
==14711==    at 0x4025315: calloc (vg_replace_malloc.c:467)
==14711==    by 0x4010CD7: allocate_dtv (dl-tls.c:300)
==14711==    by 0x401146B: _dl_allocate_tls (dl-tls.c:464)
==14711==    by 0x40475C6: pthread_create@@GLIBC_2.1 (allocatestack.c:570)
==14711==    by 0x8050583: tm_main_startup 
==14711==    by 0x8048F6B: main (genome.c:201)
==14711== 144 bytes in 1 blocks are possibly lost in loss record 18 of 32
==14711==    at 0x4025315: calloc (vg_replace_malloc.c:467)
==14711==    by 0x4010CD7: allocate_dtv (dl-tls.c:300)
==14711==    by 0x401146B: _dl_allocate_tls (dl-tls.c:464)
==14711==    by 0x40475C6: pthread_create@@GLIBC_2.1 (allocatestack.c:570)
==14711==    by 0x804DFE3: thread_startup (thread.c:151)
==14711==    by 0x8048F73: main (genome.c:203)

All the threads created are joined a corresponding pthread_join call. 创建的所有线程都加入了相应的pthread_join调用。 Also i tried the sgcheck tool but it doesn't work on the platform'x86-linux'. 此外,我尝试了sgcheck工具,但它不适用于平台'x86-linux'。 Please help. 请帮忙。

The complete output of bt command: bt命令的完整输出:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x406e8b70 (LWP 19416)]
sequencer_run (argPtr=0x89fce00) at sequencer.c:251
251 a = thread_fake();
(gdb) bt
#0  sequencer_run (argPtr=0x89fce00) at sequencer.c:251
#1  0x0804e306 in threadWait (argPtr=0x89dc1f4) at ../lib/thread.c:105
#2  0x4003be99 in start_thread (arg=0x406e8b70) at pthread_create.c:304
#3  0x40253cbe in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:130

The error is shown at this line: 错误显示在此行:

long a = thread_fake(); //in file1.c

The likely way this could case a SIGSEGV is if your program has run out of stack. 这可能是SIGSEGV一种可能方式,如果您的程序已经耗尽了堆栈。

Examine actual crashing instruction in GDB with x/i $pc . 使用x/i $pc检查GDB中的实际崩溃指令。

If the instruction is a PUSH , or a CALL , then my guess is confirmed. 如果指令是PUSHCALL ,那么我的猜测就会被确认。

Another possibility: you've compiled your code with optimization, and the actual faulting instruction has little to do with the source line it is attributed to. 另一种可能性:您已经使用优化编译了代码,并且实际的错误指令与它所归属的源代码行几乎没有关系。

Update: 更新:

Yes it gives a call call 0x804e580 <thread_fake> . 是的,它会拨打call 0x804e580 <thread_fake> What could be the solution? 可能是什么解决方案?

The solution is to not run out of stack. 解决方案是不要耗尽堆栈。 Execute a GDB where command, then, in each frame leading to the crash, execute info frame and look for frames that are excessively large. 执行GDB where命令,然后,在每一帧中导致死机,执行info frame ,并寻找过大帧。

Don't allocate too much data on stack, or increase your stack size ( ulimit -s ). 不要在堆栈上分配太多数据,或者增加堆栈大小( ulimit -s )。

valgrind shows the following error: valgrind显示以下错误:

That is 那是

  • not an error 不是错误
  • has nothing to do with your problem 与你的问题无关

Update2: UPDATE2:

How do I check the size of each frame? 如何检查每个框架的大小?

Given this: 鉴于这种:

Stack level 0, frame at 0xffffc248:
...
Stack level 1, frame at 0xffffc250:
...
Stack level 2, frame at 0xffffc2a0:

the size of frame #1 is 8 ( 0xffffc250 - 0xffffc248 ), frame #2 is 80 , etc. 帧#1的大小是80xffffc250 - 0xffffc248 ),帧#2是80 ,等等。

Final Update: 最后更新:

It turned out that my procedure above failed to measure the size of frame#0, which turned out to be ... 61MB! 事实证明,我上面的程序无法测量帧#0的大小,结果是...... 61MB! due to presence of humongous local arrays (just as Grady Player correctly guessed). 由于存在巨大的局部阵列(就像Grady Player正确猜测的那样)。

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

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