From: Caleb Clausen Date: 2010-03-27T06:03:42+09:00 Subject: [ruby-core:29052] Re: [Feature #1395](Open) Steppable Kernel::eval On 3/26/10, Yusuke Endoh wrote: > Hmm, ok. I reopen the ticket with change of the target to 2.0. > > But, what purpose is it for? I can't think of no use case else > debugging YARV. Isn't current set_trace_func enough? I can imagine this capability used to create a debugger. Debugging your program's YARV instructions may not be so nice as debugging at the source level, but I'd imagine it could occasionally be useful, just as c programmers have cause to occasionally need to debug at the assembly level. I can also see this used to create a profiler or coverage tool. Finer grained coverage or performance information would be a clear win over current tools, which are limited to line-by-line data, since that's what set_trace_func readily supports. set_trace_func is nice, but the information provided by it is only part of the picture. Consider this program: require 'pp' set_trace_func(proc{|*x| pp x }) a=1 b=2 if a, false] ["line", "stf.rb", 6, nil, #, false] ["line", "stf.rb", 8, nil, #, false] ["c-call", "stf.rb", 8, :<, #, Fixnum] ["c-return", "stf.rb", 8, :<, #, Fixnum] ["line", "stf.rb", 8, nil, #, false] ["line", "stf.rb", 9, nil, #, false] ["c-call", "stf.rb", 9, :p, #, Kernel] ["c-call", "stf.rb", 9, :inspect, #, Symbol] ["c-return", "stf.rb", 9, :inspect, #, Symbol] ["c-call", "stf.rb", 9, :write, #, IO] :c["c-return", "stf.rb", 9, :write, #, IO] ["c-call", "stf.rb", 9, :write, #, IO] ["c-return", "stf.rb", 9, :write, #, IO] ["c-return", "stf.rb", 9, :p, #, Kernel] There's some nice stuff in the set_trace_func events about when methods are entered and exited, but it says nothing about assignments to variables or whether or not the if statement was taken. (Unless something for these has been added since the ruby versions I tested this with.) (This could also be an argument in favor of expanding set_trace_func to cover these kinds of events...) Finally, a good reason to consider a feature like this is just because it would be so cool. Clearly, this would be a very powerful (and dangerous) meta-programming facility. The really far-out uses for something like that are things no one can imagine yet. Who would have thought that set_trace_func could be twisted into helping make the Binding.of_caller hack work? This is a trivial example of the kind of unexpected benefit from this kind of capability.