When a program crashes, it will create a core dump. A core dump is a memory image of the code and data of the program when it crashes. This core dump can be used by a debugger to locate the offending instruction without having to run the program within the debugger. Make sure that core dumps really get created; it is possible to limit the coredumpsize to 0, thereby disabling core dumps.
When the faulty program of the previous section is run, it will crash and create a core dump:
ls -al core -rw-r--r-- 1 se prac 63276 Aug 13 10:42 coreWhen the core file is passed as second parameter to GDB, GDB immediately locates the offending statement:
gdb bug core GDB is free software and you are welcome to 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. GDB 4.15.1 (sparc-sun-solaris2.4), Copyright 1995 Free Software Foundation, Inc... Core was generated by `bug'. Program terminated with signal 11, Segmentation fault. Reading symbols from /usr/lib/libc.so.1...done. Reading symbols from /usr/lib/libdl.so.1...done. #0 0x106b4 in printptr (iptr=0x0) at bug.c:8 8 printf("%d\n", *iptr); (gdb)