Created
March 6, 2009 17:14
-
-
Save shri-zz/74979 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
# Function to print hierarchical call trees as the program executes. | |
# Use "ir.exe -trace" for IronRuby | |
$CALL_DEPTH = 0 | |
p = proc { |op, file, line, method, b, cls| | |
if op == "call" | |
filename = file.nil? ? nil : file.gsub('\\','/') | |
puts "#{$CALL_DEPTH}\t" + ('| ' * $CALL_DEPTH) + "> #{cls}::#{method} #{filename}:#{line}" | |
locals = eval("local_variables", b) | |
local_values = locals.each { |l| | |
val = nil | |
begin | |
val = eval(l, b) | |
rescue | |
end | |
puts "#{$CALL_DEPTH}\t" + ('| ' * $CALL_DEPTH) + " #{l}:#{val.inspect}" | |
} | |
$CALL_DEPTH += 1 | |
elsif op == "return" | |
$CALL_DEPTH -= 1 if $CALL_DEPTH > 0 | |
elsif op == "raise" | |
puts "$!" * 20 | |
end | |
} | |
set_trace_func p | |
# A simpler solution is: | |
# set_trace_func proc { |*args| p args } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment