Crashes normally, but not with GDB?

Sterling picture Sterling · Sep 22, 2011 · Viewed 12.8k times · Source

My program crashes with a segmentation fault when ran normally. So I run it with gdb, but it won't crash when I do that. Does anyone know why this might occur? I know that Valgrind's faq mentions this (not crashing under valgrind), but I couldn't really find anything about this related to gdb in google. If someone could tell me why, or recommend something to look for when this happens I would be very grateful.

Answer

Ethereal picture Ethereal · Sep 22, 2011

I've had this happen to me before (you're not alone), but I can't remember what I did to fix things (I think it was a double free).

My suggestion would be to set up your environment to create core dumps, then use GDB to investigate the core dump after the program crashes. In bash, this is done with ulimit -c size, where size can be anything; I personally use 50000 for 25MB max size; the unit is in 512-byte increments.

You can use GDB to investigate a core dump by using gdb program core.