Friday, September 6, 2013

Heisenbug, Post-mortem debugging, and a reminder.

Today I discovered post-mortem debugging. I knew programs could generate core dumps and that those dumps contained program execution info. I often wondered why I couldn't find those core dumps when my progs crashed with the "Segmentation fault (core dumped)" message.

Today I also had my first Heisenbug (1). My program segfaulted at runtime but not inside gdb.

This is why I set out to find how to tell bash to let my programs generate core dumps (2, 3)...
ulimit -c unlimited
... and how to use that in gdb
gdb ./myprogram corefile

And so I discovered that my program was crashing in the deepest layers of glibc, after a use of the new operator. After triple-checking my code, I started suspecting glibc! :) But suddenly I realized I was messing with memory allocated by another guy with malloc/calloc and that I was messing with those pointer using new/delete. So, as a reminder : never mix C memory routines with C++ memory operators (4) (or make sure you know where that pointer comes from).

After 6 years of C++ coding... it's never too late!

Of interest:

  1. Heisenbug Wikipedia :
  2. SO showing post-mortem debugging :
  3. Article explaining ulimit : (french)
  4. C vs C++ allocation :

No comments:

Post a Comment