Created
September 30, 2013 09:51
-
-
Save mrkn/6761630 to your computer and use it in GitHub Desktop.
This file contains 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
@call_trace = TracePoint.new(:call) do |tp| | |
Thread.current['backtraces'] ||= [] | |
Thread.current['backtraces'] << { | |
binding: tp.binding, | |
method_id: tp.method_id | |
} | |
end | |
@raise_trace = TracePoint.new(:raise) do |tp| | |
Thread.current['backtraces'].each do |bt| | |
yourself = bt[:binding].eval('self') | |
method = yourself.method(bt[:method_id]) | |
arguments = method.parameters.inject({}) do |args, (type, name)| | |
args.update(name => (bt[:binding].eval("#{name}") rescue nil)) | |
end | |
puts "(#{yourself.inspect})##{bt[:method_id]}:" | |
arguments.each do |name, value| | |
puts " #{name} = #{value.inspect}" | |
end | |
end | |
end | |
def foo(x, y) | |
raise | |
end | |
def bar(x, y) | |
foo(y, x) | |
end | |
def baz(x, y, z) | |
bar(x + z, y) | |
end | |
@call_trace.enable | |
@raise_trace.enable | |
baz(1, :ahi, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment