Skip to content

Instantly share code, notes, and snippets.

@mgruberman
Created July 15, 2009 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgruberman/147336 to your computer and use it in GitHub Desktop.
Save mgruberman/147336 to your computer and use it in GitHub Desktop.
require 'tempfile'
require 'dl'
class Carp
@@in_gdb_bt = false
def initialize
bt = []
if ! @@in_gdb_bt
@@in_gdb_bt = true
pid = Process.pid.to_s
script_name = "/tmp/#{pid}.gdb"
script = open script_name, "w"
script.puts "attach #{pid}"
script.puts "bt"
script.puts "detach"
script.puts "quit"
script.close
backtrace_name = "/tmp/#{pid}.bt"
command = "gdb -x #{script_name} > #{backtrace_name}"
puts backtrace_name
puts command
system command
File.unlink( script_name )
backtrace = open backtrace_name, "r"
backtrace.each_line do |l|
if l =~ /\brb_call .+argv=(0x[[:xdigit:]]+)/
want_ptr = DL::PtrData.new( $1.hex )
ObjectSpace.each_object do |o|
if o.is_a?( Fixnum )
elsif o.respond_to?( :ptr )
ptr = o.ptr
if ptr == want_ptr
puts "Got #{ptr}"
end
end
end
end
end
File.unlink( backtrace_name )
end
super
end
end
Carp.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment