Core dumps are very important when debugging a problem. But sometime you would notice that even after the program crashes with a Segmentation Fault, the size of the core dump file is still zero or in some cases the core dump is not created.
The size of the core dump file is governed by "ulimit" in bash. To get more information about ulimit, do a info on bash and search for ulimit
$info bashTo get the status of the current limits set you can do
ulimit -a Notice the core file size (-c). If it reads 0, it means that bash would not create the core dump file. You need to change the size.
ulimit -c 1024You can even set it to unlimited
ulimit -c unlimitedGenerating the core /* coredump.c */
#include <stdio.h>
int main (void)
{
int *point = NULL;
*point = 0;
return 0;
}Compile the code
gcc -g coredump.c -o coredump When you try to run, it would generate a segmentation fault
./coredump
Segmentation fault (core dumped)Using the coreTo use the core, start gdb and pass the core dump generated
gdb coredump -c core
GNU gdb 6.6-debian
Copyright (C) 2006 Free Software Foundation, Inc.
Reading symbols...
Core was generated by ./coredump
Program terminated with signal 11, Segmentation fault.
#0 0x08048381 in main () at coredump.c:6
(gdb)You can now use the gdb commands to view the call stack, registers, memory etc.