Put following text into project's root dir gdb_commands.txt
--------------------------------------------------
define redirect_stdout
call rb_eval_string("$_old_stdout, $stdout = $stdout, File.open('/tmp/ruby-debug.' + Process.pid.to_s, 'a'); $stdout.sync = true")
end
define ruby_eval
call(rb_p(rb_eval_string_protect($arg0,(int*)0)))
end
redirect_stdout
ruby_eval("Kernel.caller")
quit
--------------------------------------------------
run from project's dir
sudo gdb --batch-silent -x gdb_commands.txt ruby 16667
16667 - ruby pid