How To Force A Ruby Process To Show A Backtrace


@charliesome showed me an awesome little trick. You can force a ruby process to print out a stack trace. It's surprisingly simple to do.

Fist thing: find the process id:

$> ps aux | grep ruby
>> asellitt        36488   0.0  0.9  2625676 158132 s003  S+    1:56pm   0:09.80 /path/to/ruby/proc/rails s

Once we have that, we can open up GDB and attach onto it:

$> gdb
gdb$> attach 36488

Once we've attached, we can call any function we want (provided its defined...) The function we want is rb_backtrace:

gdb$> p (void) rb_backtrace()

Quit gdb and flip to the tab containing the ruby process.

gdb$> quit

BAM!