Skip to content

Rubykaigi 2010 present part2

rocky edited this page Aug 24, 2010 · 3 revisions

That’s enough of the ThreadFrame object for now. Let us move on how the Ruby 1.9 debugger uses this. We will come back to the C extension later.

Here is the new Ruby 1.9 debugger I’ve been working on.

 rbdbgr eval.rb

Notice the -- which appear in other debuggers. It is an icon for the event of the callback in the debugger hook. -- is a line event. There will be others.

The debugger makes much greater use of the richness of events that is an underlying part of Ruby’s trace mechanisms. One can filter and step by events. Filtering by “call” and “return” is often what is used in timing and profiling.

A failing of ruby-debug and debug.rb is that they do not allow stopping at a call or return event. Many people have complained that they would like to stop after the last statement was run which might be a method call, but before the return of the method.

You can also step to a particular event. To step to the next “call” event:

 (rbdbgr): step>

Note that we are now at a “C” call event shown with the C> icon. Another deficiency of other Ruby debuggers is they don’t see into C function calls and returns. There is I think a bug in 1.9 YARV where the frame is pushed after the call hook is run but popped before calling the return hook. By correcting this as we have done here, I can see C program arguments and return values.

 (rbdbgr): where

In an unpatched Ruby, the top sequence name is something like “top required”. I’ve changed it here to the file name.

The ability to track C program arguments is also useful inside eval(). It allows a debugger to track where inside the string as it is evaluated. Let me show that

 (rbdbgr): step

When I type

 (rbdgr): where

note that we are honest and instead of saying “in file” we say “in string”. The debugger has created a temporary file out of the string for display purposes.

I can step to the next return event:

 (rbdbgr): step<

Notice the C return icon here C<. And I can even change the return value:

 (rbdbgr): set return "Hi there"

Now when I do another step

 (rbdbgr): step

you see the changed parameter has been passed to puts().