On emulating set_trace_func in Rubinius

6 views
Skip to first unread message

Rocky Bernstein

unread,
Dec 22, 2010, 9:43:05 AM12/22/10
to ruby-d...@googlegroups.com
Recently I've been working on a Gem for Rubinius to emulate set_trace_func. 

The idea of adding set_trace_func in Rubinius was not just that I thought set_trace_func should be there for compatibility with MRI/YARV/Pickaxe, but also because stepping in Rubinius is a bit unique. "step over", "step out", and "step into" are handled largely outside of the kernel, in the Ruby callback code. 

The callback code does this by scanning LLVM opcodes for the next statement, including branching opcodes. For each possible next statement it sets temporary breakpoints. And of course you need code to remove all previously-set temporary stepping breakpoints on the next debugger entry.

Stepping by setting temporary breakpoints is not novel, but what is I think novel is that such low-level inspection and control of the bytecodes is done in he high-level callback code. The only thing Rubinius has to support at the run-time level is the ability to set a breakpoint at a VM instruction offset. 

On the one hand, one can argue that it is not good to make high-level code have to know so much about VM instructions. After all, it is possible for such things to change. On the other hand, since it is complicated where ever it occurs, it's nicer and less code to do this in Ruby than say C++ and it allows for more flexibility. It reminds me of a similar issue which comes up in compilers for RISC architectures: the compiler sometimes has to figure out how to do what in a CISC instruction set would be  primitive, like how to do a 32x32 bit multiply (or more generally an n x m bit multiply). 

ruby-debug for MRI and other debuggers such as the ones for Python or my debuggers POSIX shells handle breakpoints in a symbolic way by testing file names and line numbers against a list, but they still rely on the event hook to do the stepping which is implemented in the run-time kernel. 

Roger Pack

unread,
Dec 29, 2010, 11:02:52 AM12/29/10
to ruby-d...@googlegroups.com
Recently I've been working on a Gem for Rubinius to emulate set_trace_func. 
 
Maybe it should be rolled into rubinius' core :P
Reply all
Reply to author
Forward
0 new messages