I think you need core dump file but not catch the run-time error of gcc
I show you how to get core dump under Linux, I wrote a test program, test_coredump.c
:
#include <stdlib.h>
int main(void){
int *ptr = NULL;
*ptr = 10; //Segmentation fault will happen since you write to a null memory
return 0;
}
Normally, I will do following step before compile:
how@ubuntu-sw:~/Work/c/test_coredump
-> ulimit -c
0
how@ubuntu-sw:~/Work/c/test_coredump
-> ulimit -c unlimited
how@ubuntu-sw:~/Work/c/test_coredump
-> ulimit -c
unlimited
how@ubuntu-sw:~/Work/c/test_coredump
-> gcc -g ./test_coredump.c
how@ubuntu-sw:~/Work/c/test_coredump
-> ls
a.out test_coredump.c
how@ubuntu-sw:~/Work/c/test_coredump
-> ./a.out
Segmentation fault (core dumped)
after this, it will generate core dump file for you:
how@ubuntu-sw:~/Work/c/test_coredump
-> ls
a.out core test_coredump.c
and you can know use gdb
or whatever debug tool you like to see:
how@ubuntu-sw:~/Work/c/test_coredump
-> gdb ./a.out ./core
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
[New LWP 6421]
Core was generated by `./a.out'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x080483fd in main () at test_coredump.c:5
5 *ptr = 10; //Segmentation fault will happen since you write to a null memory
(gdb)
you can find where you program trap.