The following was sent to ruby-core. In case there readers here that
do not follow that...
I'd like to offer for public review some patches for the Ruby 1.9 run-
time environment. The patches attempt to support better run-time
introspection, especially of VM instruction sequences, tracing, and
promote better support for writing tools like debuggers or profilers.
I use these changes to Ruby in an experimental C extension which
provides a run time call-stack object (
http://github.com/rocky/rb-
threadframe). In turn, that extension is used in an experimental
debugger (
http://github.com/rocky/rbdbgr).
The patches come in 3 variations.
1. A single patch file for the trunk (1.9.3),
http://github.com/rocky/rb-threadframe/blob/master/patches/ruby-trunk-combined.patch
2. The above broken out into 14 individual patches. There are 15,
but the last one, 14-eval-iseq-name.patch is not currently used.
3. A single patch file for 1.9.2 rc2. This is analogous to 1.
The patches are a bit too large to post here, but you can find them in
the threadframe project
http://github.com/rocky/rb-threadframe/tree/master/patches.
Each of the 14 separate patches has text at the beginning describing
what the patch does.
A synopsis of them is given below.
0. changes to allow a C extension to get access to some Ruby methods
and fields defined in vm_core.h.
1. Fixes rb_vm_get_sourceline() so it returns the correct line number
when the VM PC passed in is 0.
2. Adds the ability to set tracing on or off per call frame.
3. Add more access to VM opcodes and finer control of VM disassembly.
4. Adds access to instruction sequences via a mechanism similar to
SCRIPT_LINES__ via SCRIPT_ISEQS__ and ISEQS__
5. Allows an extension to create an RubyVM::InstructionSequence object
from
a rb_seq_t pointer. Useful in adding Method#iseq and Proc#iseq
6. Adds ability to get the number of parameters passed to a C
function. Like
"arity" but is the *actual* number of parameters passed.
7. Support for fast breakpoints. Used in the experimental 1.9
debugger.
8. Provides a way to get the exception object in a trace hook on a
"raise" event callback.
9. Adds an optional trace masks trace hooks, and chaining trace hooks
for threads. Adjusts the location slightly in C-function callbacks for
calls and returns so they have access to the call stack. Allows a hook
to change the return value on a C return.
10. Changes the instruction-sequence name of the top-most instruction
sequence to something less generic, e.g. <top /tmp/ruby-program.rb>
vs. <top (required)>
11. Adds RubyVM::InstructionSequence#arity and allows a C extension to
return a binding thread- and control-frame parameters. Used in rb-
threadframe to provide
RubyVM::ThreadFrame#binding.
12. Adds a new trace event mask to provide the ability to step VM
instructions
13. Keeps a trace hook which raises an exception in fielding a C
return from looping infinitely.
I look forward to hearing your comments and suggestions.
Thanks.