"Inspecting a live Ruby process", easier if you cheat.
Are you still adding printf/puts calls and restarting your app to figure what went wrong? Sometimes, the problem is hard to reproduce, or you only discover it in production. You've got a process that exhibits the bug, but you didn't run it under ruby-debug, so there's no choice but kill it and reproduce after adding some code to inspect your program, right?
Sure not. Jamis Buck blogged about how to use GDB to inspect a live Ruby process, and showed how to get a stack-trace using Ruby's C API and some GDB scripting:
(gdb) set $ary = (int)backtrace(-1) (gdb) set $count = *($ary+8) (gdb) set $index = 0 (gdb) while $index < $count > x/1s *((int)rb_ary_entry($ary, $index)+12) > set $index = $index + 1 >end
But it gets much easier than that. How about this:
(gdb) eval "caller"


Loading...