hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

The Ruby-GDB Arms Race Now At a Standoff #

by why in inspect

What glad times! Mauricio and Jamis have come out from behind the curtain to show us their GDB hooks and whoa these are shiny hooks and handy hooks.

Mauricio gives us some ~/.gdbinit settings that add a stellar set of functions for taking apart Ruby processes. Most of the wizardry here is Nobu’s.

After attaching with gdb ruby [process-id]:

 (gdb) session-ruby
 (gdb) redirect_stdout
 [Switching to Thread -1210431808 (LWP 4584)]
 $1 = 2
 (gdb) rb_object_counts
 $2 = 3078718700

The session-ruby command loads Mauricio’s functions. Standard out gets redirected to the file /tmp/ruby-debug.[pid]. In the above, the rb_object_counts will make a list of all the classes with instantiated objects and a count of objects created of that class.

  32640  String
   2435  Array
    951  Regexp
    819  Class
    ...

Jamis’ library (gdb.rb) takes a totally different approach by offering a Ruby wrapper for GDB and preferring dissecting Ruby structs byte by byte. So you don’t have to redirect STDOUT.

 >> require 'gdb'
 => true
 >> gdb = GDB::Ruby.new([pid])
 => #<GDB::Ruby:0xb7d72550 @gdb=#<IO:0xb7d72438>, @names={}, @interns={}>
 >> gdb.object_space
 => {"File"=>24, "OptionParser"=>1, "Gem::Version::Requirement"=>38, ... }

I don’t know about you guys, but I’m kind of freaking out that I can do all this from irb. It’s been a thrilling couple of days watching this unfold. (Jamis’ original post and his explanation of the library.)

said on 26 Sep 2006 at 19:01

Yes, it has been exciting!

Thanks Jamis and Mauricio. irb has quickly become my preferred Ruby debugger.

said on 28 Sep 2006 at 00:52

Man this is some cool voodoo. I tip my hatr to all involved.

said on 28 Sep 2006 at 15:58

That makes me all warm and squishy inside. I want to go write a web application that does everything now…

11 Jul 2010 at 21:13

* do fancy stuff in your comment.

PREVIEW PANE