Skip to content

Instantly share code, notes, and snippets.

@mrkn
Created September 30, 2013 09:51
Show Gist options
  • Save mrkn/6761630 to your computer and use it in GitHub Desktop.
Save mrkn/6761630 to your computer and use it in GitHub Desktop.
@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