How to debug a program with a signal processor for SIGSEGV

I write a plugin for an application, sometimes SIGSEGV is thrown. However, the application captures the SIGSEGV signal. In other words, the plugin is a dynamic library. The error occurs in my plugin and dynamic library. But the application processes sSIGSEGV and exits normally. Therefore, it is quite difficult for me to debug and get a back trace of all the frames of the stack. Any ideas?

I am currently using gdb as a debugging tool.

+6
c ++ debugging linux gdb
source share
2 answers

GDB will catch SIGSEGV before the application executes.

What you described in the comment on Logan does not make sense.

I suspect that what is actually happening is that the application creates a new process and receives only SIGSEGV in this other process, and not the one to which you bound GDB.

The following commands may be useful if my assumption is correct:

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

You can also edit and expand your question:

  • How do you know if there is SIGSEGV for starters?
  • Posting a log of your interactions with GDB can also be helpful.
+6
source share

Even if the SIGSEGV trap program, gdb will still get it first and give you the ability to debug the program. You did something like

  handle SIGSEGV nostop 

in gdb? If so, then why not stop.

Are you sure segfault is really happening? Can you repeat this behavior with another program or intentionally cause a segmentation violation?

For example:

 $ 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 
+4
source share

All Articles