October 20, 2008

More Backtracing

Related to the earlier post on doing backtraces, I figured out how to make some portions work on the Mac version of ruby and/or gdb, so you can do it even when you can’t easily capture stdout…

$ gdb -p <process_id>
call (int)rb_eval_string(“$_old_stdout, $stdout = $stdout, File.open(‘/tmp/ruby-debug.’ + Process.pid.to_s, ‘a’); $stdout.sync = true”)
call (int)rb_eval_string(“puts caller.join(\”\\n\”)”)

Yay.  Now it’ll throw the backtrace into a file in your tmp dir.  I’m assuming the same would still work on linux or other unix variants, too.