Getting a Heap Dump from a Ruby Segfault

To people who encounter this situation often, this may seem like the most obvious thing in the world… But recently I encountered a situation where a Ruby application was experiencing regular but apparently random segmentation faults on our Mac laptops, and it took quite a while for me to figure out how to get a heap dump. So without further ado:

  1. Set your ulimit -c to a non-zero value (ie: “ulimit -c 99999”). The ‘c’ is short for “Core dumps”, and tells the OS that yes, it can and should dump the core on seg fault.
  2. Get the segfault to happen. This is often easier said than done, and not something I can help you with.
  3. Copy the resulting core dump file out of /Cores. You will probably need root access to see this directory.
  4. Chown the file to yourself, then open it with gdb.

In hindsight, it’s kind of obvious, but even so I wasted several minutes trying to Google it (and several more minutes reproducing segfaults without the right configuration to capture them) so I recorded the process for future reference.

Leave a Reply

Your email address will not be published. Required fields are marked *