| 1 |
#include "ruby/ruby.h" |
| 2 |
#include "ruby/debug.h" |
| 3 |
|
| 4 |
static VALUE |
| 5 |
callback(const rb_debug_inspector_t *dbg_context, void *data) |
| 6 |
{ |
| 7 |
VALUE locs = rb_debug_inspector_backtrace_locations(dbg_context); |
| 8 |
long i, len = RARRAY_LEN(locs); |
| 9 |
VALUE binds = rb_ary_new(); |
| 10 |
for (i = 0; i < len; ++i) { |
| 11 |
VALUE entry = rb_ary_new(); |
| 12 |
rb_ary_push(binds, entry); |
| 13 |
rb_ary_push(entry, rb_debug_inspector_frame_self_get(dbg_context, i)); |
| 14 |
rb_ary_push(entry, rb_debug_inspector_frame_binding_get(dbg_context, i)); |
| 15 |
rb_ary_push(entry, rb_debug_inspector_frame_class_get(dbg_context, i)); |
| 16 |
rb_ary_push(entry, rb_debug_inspector_frame_iseq_get(dbg_context, i)); |
| 17 |
rb_ary_push(entry, rb_ary_entry(locs, i)); |
| 18 |
} |
| 19 |
return binds; |
| 20 |
} |
| 21 |
|
| 22 |
static VALUE |
| 23 |
debug_inspector(VALUE self) |
| 24 |
{ |
| 25 |
return rb_debug_inspector_open(callback, NULL); |
| 26 |
} |
| 27 |
|
| 28 |
void |
| 29 |
Init_inspector(VALUE klass) |
| 30 |
{ |
| 31 |
rb_define_module_function(klass, "inspector", debug_inspector, 0); |
| 32 |
} |