The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
The Ruby-GDB Arms Race Now At a Standoff

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
The Ruby-GDB Arms Race Now At a Standoff Posted: Sep 26, 2006 2:00 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: The Ruby-GDB Arms Race Now At a Standoff
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

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.)

Read: The Ruby-GDB Arms Race Now At a Standoff

Topic: Tendencias en Lenguajes de Programaci��n Previous Topic   Next Topic Topic: Rails code that doesn't get executed for generations and migrations

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use