In some rare cases, you may encounter bugs that happen only in normal execution, but not with GDB. It's really annoying; if you try to investigate it, it just disappears. Such bugs are called Haisenbug, and you can debug it with GDB by using a trick described here.
The idea is using signal handlers in programs.
When SIGSEGV
is caught, a signal handler is called.
You can sleep for a long time in the signal handler, and then attach the program by using gdb attach
.