2010-08-05 105 views
6

我正在为应用程序编写插件,有时会丢弃SIGSEGV。但是,应用程序捕获信号SIGSEGV。换句话说,插件是一个动态库。该错误发生在我的插件和动态库中。但应用程序处理sSIGSEGV并正常退出。所以,我很难调试并获得所有堆栈帧的回溯。任何想法?如何使用SIGSEGV的信号处理程序调试程序

目前我正在使用gdb作为调试工具。

回答

6

GDB SIGSEGV之前的应用程序一样。

你在评论Logan的答案中描述的是没有道理的。

我怀疑真正发生的事情是应用程序创建一个新进程,并且只在其他进程中获得SIGSEGV,而不是您附加到GDB的进程。如果我的猜测是正确的

下面的命令可能是有用的:

(gdb) catch fork 
(gdb) catch vfork 
(gdb) set follow-fork-mode child 

您可能还需要编辑和扩大你的问题:

  • 你怎么知道有一个SIGSEGV开始?
  • 将您与GDB的互动日志发布也可能有用。
+0

你是对的。当然,我应该抓住孩子进程的错误。谢谢。 – Blad 2010-08-09 02:06:03

+0

我试着根据你的建议,但另一个问题使应用程序中止:“shell-init:错误检索当前目录:getcwd:无法访问父目录:没有这样的文件或目录”。任何想法? – Blad 2010-08-09 06:54:57

4

即使程序陷阱SIGSEGV,gdb仍然应该首先获得它并给你一个调试程序的机会。你做过类似

handle SIGSEGV nostop 

in GDB?如果是这样,那可能是为什么它不停止。

您确定段落发生了吗?您是否可以用另一个程序复制此行为,或通过故意导致分段违规?

例如:

$ cat sig.c 
#include <signal.h> 
#include <stdio.h> 
#include <stdlib.h> 

void handle(int n) 
{ 
     puts("Bail"); 
     exit(1); 
} 

int main() 
{ 
     signal(SIGSEGV, handle); 
     int *pi = 0; 
     *pi = 10; 
     return 0; 
} 
$ gcc -g sig.c 
$ ./a.out 
Bail 
$ gdb ./a.out 
GNU gdb 6.6-debian 
Copyright (C) 2006 Free Software Foundation, Inc. 
GDB is free software, covered by the GNU General Public License, and you are 
welcome to change it and/or distribute copies of it under certain conditions. 
Type "show copying" to see the conditions. 
There is absolutely no warranty for GDB. Type "show warranty" for details. 
This GDB was configured as "i486-linux-gnu"... 
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1". 
(gdb) run 
Starting program: /home/elcapaldo/a.out 

Program received signal SIGSEGV, Segmentation fault. 
0x08048421 in main() at sig.c:15 
15    *pi = 10; 
(gdb) where 
#0 0x08048421 in main() at sig.c:15 
(gdb) c 
Continuing. 
Bail 

Program exited with code 01. 
(gdb) q 
+0

非常感谢您的回复。不,实际上,我使用“处理所有停止”,但它没有奏效。即使我尝试过“处理所有nopass”,该应用仍然抓住了SIGSEGV,并正常退出。 – Blad 2010-08-06 02:03:37

+0

正确,我再次调试。看起来崩溃发生在一个相反的过程中。 – Blad 2010-08-09 02:57:59