Define a controller with an infinite loop and start up a rails server.
class SomeController < ApplicationController def show while true do end end end
Make a request to
/home/any-params to call the show method. Then find the location of the ruby executable, and the PID of the running process.
$ which ruby /usr/bin/ruby $ top PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 25215 ben 20 0 40100 27m 2088 R 100 0.9 0:15.53 ruby
Attach a GDB session to the ruby process.
$ gdb /usr/bin/ruby 25215
Call the rb_backtrace() function from within GDB.
(gdb) call rb_backtrace()
Check the passenger log.
from /home/ben/rails/app/controllers/some_controller.rb:3:in `show' ...
You can also raise an exception.
(gdb) call rb_raise((int)rb_eException, "Raised a special exception with GDB")
Check the production log.
Exception (Raised a special exception with GDB): app/controllers/some_controller.rb:3:in `show'
Ben Holley is a Ruby on Rails developer for isotope|eleven. He graduated with a Bachelor of Science in Mathematics from the University of Alabama at Birmingham.