Created
August 17, 2017 21:58
-
-
Save wteuber/a04709057655087250c2fc25d108f861 to your computer and use it in GitHub Desktop.
set_trace_func
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
set_trace_func -> (event, file, line, id, binding, classname) do | |
if event == 'call' && meth = binding.eval('__method__') | |
params = binding.method(meth).parameters.select{|e| e[0] != :block} | |
values = params.map{|_, var| [var, binding.local_variable_get(var)]} | |
printf "%8s %s:%-2d %15s %8s %s\n", event, file, line, id, classname, values.inspect | |
else | |
printf "%8s %s:%-2d %15s %8s\n", event, file, line, id, classname | |
end | |
end | |
def foo(a,b = 0) | |
bar(a, foo: true) | |
end | |
def bar(c, d = {}) | |
puts "!!!buz!!!\n" | |
end | |
foo('lol') | |
# output: | |
# c-return /path/to/trace.rb:1 set_trace_func Kernel | |
# line /path/to/trace.rb:12 | |
# c-call /path/to/trace.rb:12 method_added Module | |
# c-return /path/to/trace.rb:12 method_added Module | |
# line /path/to/trace.rb:16 | |
# c-call /path/to/trace.rb:16 method_added Module | |
# c-return /path/to/trace.rb:16 method_added Module | |
# line /path/to/trace.rb:20 | |
# call /path/to/trace.rb:12 foo Object [[:a, "lol"], [:b, 0]] | |
# line /path/to/trace.rb:13 foo Object | |
# call /path/to/trace.rb:16 bar Object [[:c, "lol"], [:d, {:foo=>true}]] | |
# line /path/to/trace.rb:17 bar Object | |
# c-call /path/to/trace.rb:17 puts Kernel | |
# c-call /path/to/trace.rb:17 puts IO | |
# c-call /path/to/trace.rb:17 write IO | |
# !!!buz!!! | |
# c-return /path/to/trace.rb:17 write IO | |
# c-return /path/to/trace.rb:17 puts IO | |
# c-return /path/to/trace.rb:17 puts Kernel | |
# return /path/to/trace.rb:18 bar Object | |
# return /path/to/trace.rb:14 foo Object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment