Working with Core Dumps

Sometimes you end up in a state where you can’t catch your crash in lldb using any of the methods in [debugging].

In this case you can tell ruby to generate a core dump. I have no idea where this stuff is documented.

First set the max size of all core files (?) to be unlimited:

ulimit -c unlimited

Then (on OSX, don’t know about Linux), make sure that the /cores directory exists and is writable by your user. There are more elegant ways of doing this but I did

sudo mkdir /cores
sudo chown -R mattvh /cores

Now replicate your crash using make run or make runruby or running your test or whatever. Once it crashes you’ll see that there is a file inside /cores called something like core.12387.

You can load this into lldb using

lldb ./ruby -c /cores/core.12387

and now you’ve got a post-mortem debugger that allows you to walk the stack just like you were live debugging a process.

NOTE: You’re going to want to clean these out regularly. each core file is large (the ones I generated from running a single test are >2GiB)