From: Reginald Tan Date: 2012-07-03T10:11:11+09:00 Subject: Using binding + set_trace_func to capture execution state Hi guys, I'm interested in building a program that will display the callgraph trace of a program and at the same time will allow you to inspect the variables in your program *after* the execution has ended (diff from using debugger to halt execution and inspecting the state). Initially I thought I could use set_trace_func and store the binding in a table and just retrieve that binding later on to evaluate the resulting expression of my target variable, but it's not behaving as I expected. In the code provided below, I thought running it would output "1 3 5", but I get "5 5 5" instead. What am I missing here? Is there another way to go about what I'm trying to do? Thanks! binding_table = {} def hello x = 1 x = 3 x = 5 end set_trace_func proc { |event, file, line, id, binding, classname| if event == "line" binding_table[line] = binding end } hello set_trace_func nil puts eval("x", binding_table[4]) puts eval("x", binding_table[5]) puts eval("x", binding_table[6]) -- Posted via http://www.ruby-forum.com/.