Created
July 15, 2009 00:08
-
-
Save mgruberman/147336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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