There's #set_trace_func built-in to Ruby. Or for a more complete
solution try Calibre's TracePoint. (see Rubyforge)

HTH,
T.