Write a buggy program:
int main() {
int *p = 0;
*p = 42;
return 0;
}
Compile it with debug options:
cc -ggdb3 crash.c -o crash
Enable core dump (on ubuntu 24.04.2):
ulimit -c unlimited
sudo service apport stop
Crash it
$ ./crash
Segmentation fault (core dumped)
Debug it:
gdb crash core
You can debug a stripped crashed program if you kept the debug version handy:
$ cp crash crash.debug
$ strip crash
$ ./crash
$ gdb --quiet crash.debug core
Reading symbols from crash.debug...
[New LWP 21153]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./crash'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000627af1f6213d in main () at crash.c:3
3 *p = 42;
(gdb)