Skip to content

Instantly share code, notes, and snippets.

@mrkn mrkn/gist:6761630
Created Sep 30, 2013

Embed
What would you like to do?
@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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.