Skip to content

Instantly share code, notes, and snippets.

@mmullis
Created August 12, 2013 14:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmullis/6211061 to your computer and use it in GitHub Desktop.
Save mmullis/6211061 to your computer and use it in GitHub Desktop.
Debugging and Dumping the state of a running Ruby process using GDB.
# Connect to ruby process
gdb `which ruby` <pid>
# Run GC
p rb_eval_string("GC.start")
# Count each Object class
p rb_eval_string("$gdb_objs = Hash.new 0")
p rb_eval_string("ObjectSpace.each_object {|o| $gdb_objs[o.class] += 1}")
p rb_eval_string("$stderr.puts($gdb_objs.inspect)")
# Show ObjectSpace.count_objects
p rb_eval_string("$stderr.puts(ObjectSpace.count_objects)")
# Print portion of every String - good if you need to find excessive duplication
p rb_eval_string("ObjectSpace.each_object {|v| $stderr.puts(v[0,132]) if v.is_a?(String)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment