12#include "eval_intern.h"
14#include "internal/class.h"
15#include "internal/error.h"
16#include "internal/vm.h"
22static VALUE rb_cBacktrace;
23static VALUE rb_cBacktraceLocation;
28 VALUE str = rb_id2str(
id);
29 if (!str)
return Qnil;
32#define rb_id2str(id) id2str(id)
35calc_pos(
const rb_iseq_t *iseq,
const VALUE *pc,
int *lineno,
int *node_id)
40 if (ISEQ_BODY(iseq)->
type == ISEQ_TYPE_TOP) {
41 VM_ASSERT(! ISEQ_BODY(iseq)->local_table);
42 VM_ASSERT(! ISEQ_BODY(iseq)->local_table_size);
45 if (lineno) *lineno = ISEQ_BODY(iseq)->location.first_lineno;
46#ifdef USE_ISEQ_NODE_ID
47 if (node_id) *node_id = -1;
52 VM_ASSERT(ISEQ_BODY(iseq));
53 VM_ASSERT(ISEQ_BODY(iseq)->iseq_encoded);
54 VM_ASSERT(ISEQ_BODY(iseq)->iseq_size);
56 ptrdiff_t n = pc - ISEQ_BODY(iseq)->iseq_encoded;
58#if SIZEOF_PTRDIFF_T > SIZEOF_INT
59 VM_ASSERT(n <= (ptrdiff_t)UINT_MAX);
61 VM_ASSERT((
unsigned int)n <= ISEQ_BODY(iseq)->iseq_size);
68#if VMDEBUG && defined(HAVE_BUILTIN___BUILTIN_TRAP)
71 rb_print_backtrace(stderr);
75 if (lineno) *lineno = rb_iseq_line_no(iseq, pos);
76#ifdef USE_ISEQ_NODE_ID
77 if (node_id) *node_id = rb_iseq_node_id(iseq, pos);
87 if (calc_pos(iseq, pc, &lineno, NULL))
return lineno;
91#ifdef USE_ISEQ_NODE_ID
96 if (calc_pos(iseq, pc, NULL, &node_id))
return node_id;
104 if (VM_FRAME_RUBYFRAME_P(cfp) && cfp->iseq) {
106 int line = calc_lineno(iseq, cfp->pc);
111 return ISEQ_BODY(iseq)->location.first_lineno;
131location_mark(
void *ptr)
134 rb_gc_mark_movable(vfi->btobj);
138location_ref_update(
void *ptr)
141 vfi->btobj = rb_gc_location(vfi->btobj);
147 rb_gc_mark((
VALUE)fi->cme);
148 if (fi->iseq) rb_gc_mark_movable((
VALUE)fi->iseq);
159 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
163rb_frame_info_p(
VALUE obj)
169location_ptr(
VALUE locobj)
180 return calc_lineno(loc->iseq, loc->pc);
194location_lineno_m(
VALUE self)
196 return INT2FIX(location_lineno(location_ptr(self)));
199VALUE rb_mod_name0(
VALUE klass,
bool *permanent);
206 if (RCLASS_SINGLETON_P(owner)) {
207 VALUE v = RCLASS_ATTACHED_OBJECT(owner);
209 v = rb_mod_name0(v, &permanent);
210 if (permanent && !
NIL_P(v)) {
211 return rb_sprintf(
"%"PRIsVALUE
".%"PRIsVALUE, v, name);
216 owner = rb_mod_name0(owner, &permanent);
217 if (permanent && !
NIL_P(owner)) {
218 return rb_sprintf(
"%"PRIsVALUE
"#%"PRIsVALUE, owner, name);
229 switch (ISEQ_BODY(iseq)->
type) {
231 case ISEQ_TYPE_CLASS:
233 return ISEQ_BODY(iseq)->location.label;
234 case ISEQ_TYPE_METHOD:
235 return rb_gen_method_name(owner, ISEQ_BODY(iseq)->location.label);
236 case ISEQ_TYPE_BLOCK:
237 case ISEQ_TYPE_PLAIN: {
240 if (ISEQ_BODY(orig_iseq)->parent_iseq != 0) {
241 while (ISEQ_BODY(orig_iseq)->local_iseq != iseq) {
242 if (ISEQ_BODY(iseq)->
type == ISEQ_TYPE_BLOCK) {
245 iseq = ISEQ_BODY(iseq)->parent_iseq;
249 return rb_sprintf(
"block in %"PRIsVALUE, calculate_iseq_label(owner, iseq));
252 return rb_sprintf(
"block (%d levels) in %"PRIsVALUE, level, calculate_iseq_label(owner, iseq));
255 case ISEQ_TYPE_RESCUE:
256 case ISEQ_TYPE_ENSURE:
258 iseq = ISEQ_BODY(iseq)->parent_iseq;
261 rb_bug(
"calculate_iseq_label: unreachable");
266is_internal_location(
const rb_iseq_t *iseq)
268 static const char prefix[] =
"<internal:";
269 const size_t prefix_len =
sizeof(prefix) - 1;
270 VALUE file = rb_iseq_path(iseq);
271 return strncmp(prefix, RSTRING_PTR(file), prefix_len) == 0;
278 if (!loc->cme)
return false;
280 switch (loc->cme->def->type) {
281 case VM_METHOD_TYPE_CFUNC:
283 case VM_METHOD_TYPE_ISEQ:
284 return is_internal_location(loc->cme->def->body.iseq.
iseqptr);
293 if (location_cfunc_p(loc)) {
294 return rb_gen_method_name(loc->cme->owner, rb_id2str(loc->cme->def->original_id));
299 owner = loc->cme->owner;
301 return calculate_iseq_label(owner, loc->iseq);
331location_label_m(
VALUE self)
333 return location_label(location_ptr(self));
339 if (location_cfunc_p(loc)) {
340 return rb_id2str(loc->cme->def->original_id);
343 return ISEQ_BODY(loc->iseq)->location.base_label;
371location_base_label_m(
VALUE self)
373 return location_base_label(location_ptr(self));
393location_path_m(
VALUE self)
395 const rb_iseq_t *iseq = location_iseq(location_ptr(self));
396 return iseq ? rb_iseq_path(iseq) :
Qnil;
399#ifdef USE_ISEQ_NODE_ID
403 if (loc->iseq && loc->pc) {
404 return calc_node_id(loc->iseq, loc->pc);
411rb_get_node_id_from_frame_info(
VALUE obj)
413#ifdef USE_ISEQ_NODE_ID
415 return location_node_id(loc);
422rb_get_iseq_from_frame_info(
VALUE obj)
425 const rb_iseq_t *iseq = location_iseq(loc);
433 return rb_iseq_realpath(loc->iseq);
445location_absolute_path_m(
VALUE self)
447 return location_realpath(location_ptr(self));
451location_format(
VALUE file,
int lineno,
VALUE name)
455 rb_str_catf(s,
":%d", lineno);
462 rb_str_catf(s,
"'%s'", RSTRING_PTR(name));
473 if (location_cfunc_p(loc)) {
474 if (loc->iseq && loc->pc) {
475 file = rb_iseq_path(loc->iseq);
476 lineno = calc_lineno(loc->iseq, loc->pc);
479 file = GET_VM()->progname;
482 name = rb_gen_method_name(loc->cme->owner, rb_id2str(loc->cme->def->original_id));
485 file = rb_iseq_path(loc->iseq);
486 lineno = calc_lineno(loc->iseq, loc->pc);
488 owner = loc->cme->owner;
490 name = calculate_iseq_label(owner, loc->iseq);
493 return location_format(file, lineno, name);
500location_to_str_m(
VALUE self)
502 return location_to_str(location_ptr(self));
510location_inspect_m(
VALUE self)
523backtrace_mark(
void *ptr)
526 size_t i, s = bt->backtrace_size;
528 for (i=0; i<s; i++) {
529 location_mark_entry(&bt->backtrace[i]);
531 rb_gc_mark_movable(bt->strary);
532 rb_gc_mark_movable(bt->locary);
545backtrace_update(
void *ptr)
548 size_t i, s = bt->backtrace_size;
550 for (i=0; i<s; i++) {
551 location_update_entry(&bt->backtrace[i]);
553 bt->strary = rb_gc_location(bt->strary);
554 bt->locary = rb_gc_location(bt->locary);
568 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
572rb_backtrace_p(
VALUE obj)
578backtrace_alloc(
VALUE klass)
589 VALUE btobj = rb_data_typed_object_zalloc(rb_cBacktrace, memsize, &backtrace_data_type);
601 if (start_cfp == NULL) {
606 RUBY_VM_NEXT_CONTROL_FRAME(
607 RUBY_VM_NEXT_CONTROL_FRAME(start_cfp));
609 if (start_cfp < last_cfp) {
613 return start_cfp - last_cfp + 1;
619 enum rb_iseq_type
type = ISEQ_BODY(cfp->iseq)->type;
620 return type == ISEQ_TYPE_RESCUE ||
type == ISEQ_TYPE_ENSURE;
626 for (; backpatch_counter > 0; backpatch_counter--, loc--) {
637 for (; num_frames > 0; num_frames--, loc++) {
638 rb_yield(location_create(loc, (
void *)btobj));
643rb_ec_partial_backtrace_object(
const rb_execution_context_t *ec,
long start_frame,
long num_frames,
int* start_too_large,
bool skip_internal,
bool do_yield)
651 unsigned long backpatch_counter = 0;
652 bool skip_next_frame = FALSE;
655 if (end_cfp == NULL) {
659 end_cfp = RUBY_VM_NEXT_CONTROL_FRAME(end_cfp);
671 size = end_cfp - cfp + 1;
675 else if (num_frames < 0 || num_frames > size) {
680 btobj = backtrace_alloc_capa(num_frames, &bt);
682 bt->backtrace_size = 0;
683 if (num_frames == 0) {
684 if (start_too_large) *start_too_large = 0;
688 for (; cfp != end_cfp && (bt->backtrace_size < num_frames); cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)) {
691 if (start_frame > 0) {
695 bool internal = is_internal_location(cfp->iseq);
696 if (skip_internal && internal)
continue;
697 if (!skip_next_frame) {
699 const VALUE *pc = cfp->pc;
700 if (internal && backpatch_counter > 0) {
702 bt->backtrace_size -= backpatch_counter;
703 backpatch_counter = 0;
705 loc = &bt->backtrace[bt->backtrace_size++];
706 RB_OBJ_WRITE(btobj, &loc->cme, rb_vm_frame_method_entry(cfp));
718 if ((VM_FRAME_TYPE(cfp) & VM_FRAME_MAGIC_MASK) == VM_FRAME_MAGIC_DUMMY) {
724 bt_backpatch_loc(backpatch_counter, loc-1, iseq, pc);
726 bt_yield_loc(loc - backpatch_counter, backpatch_counter+1, btobj);
728 backpatch_counter = 0;
731 skip_next_frame = is_rescue_or_ensure_frame(cfp);
736 VM_ASSERT(RUBYVM_CFUNC_FRAME_P(cfp));
737 if (start_frame > 0) {
741 loc = &bt->backtrace[bt->backtrace_size++];
742 RB_OBJ_WRITE(btobj, &loc->cme, rb_vm_frame_method_entry(cfp));
752 if (backpatch_counter > 0) {
753 for (; cfp != end_cfp; cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)) {
754 if (cfp->iseq && cfp->pc && !(skip_internal && is_internal_location(cfp->iseq))) {
755 VM_ASSERT(!skip_next_frame);
756 bt_backpatch_loc(backpatch_counter, loc, cfp->iseq, cfp->pc);
759 bt_yield_loc(loc - backpatch_counter, backpatch_counter, btobj);
766 if (start_too_large) *start_too_large = (start_frame > 0 ? -1 : 0);
773 return rb_ec_partial_backtrace_object(ec, RUBY_BACKTRACE_START, RUBY_ALL_BACKTRACE_LINES, NULL, FALSE, FALSE);
784 for (i=0; i<bt->backtrace_size; i++) {
795 return location_to_str(loc);
799backtrace_to_str_ary(
VALUE self)
804 r = backtrace_collect(bt, location_to_str_dmyarg, 0);
810rb_backtrace_to_str_ary(
VALUE self)
816 RB_OBJ_WRITE(self, &bt->strary, backtrace_to_str_ary(self));
835backtrace_to_location_ary(
VALUE self)
840 r = backtrace_collect(bt, location_create, (
void *)self);
846rb_backtrace_to_location_ary(
VALUE self)
852 RB_OBJ_WRITE(self, &bt->locary, backtrace_to_location_ary(self));
858rb_location_ary_to_backtrace(
VALUE ary)
866 VALUE btobj = backtrace_alloc_capa(num_frames, &new_backtrace);
868 for (
long index = 0; index <
RARRAY_LEN(ary); index++) {
871 if (!rb_frame_info_p(locobj)) {
879 RB_OBJ_WRITE(btobj, &dst_location->cme, src_vloc->loc->cme);
880 RB_OBJ_WRITE(btobj, &dst_location->iseq, src_vloc->loc->iseq);
881 dst_location->pc = src_vloc->loc->pc;
883 new_backtrace->backtrace_size++;
892backtrace_dump_data(
VALUE self)
894 VALUE str = rb_backtrace_to_str_ary(self);
958backtrace_limit(
VALUE self)
960 return LONG2NUM(rb_backtrace_length_limit);
966 return rb_backtrace_to_str_ary(rb_ec_partial_backtrace_object(ec, lev, n, NULL, FALSE, FALSE));
972 return rb_backtrace_to_location_ary(rb_ec_partial_backtrace_object(ec, lev, n, NULL, skip_internal, FALSE));
979 void (*init)(
void *arg,
size_t size),
990 if (start_cfp == NULL) {
1006 RUBY_VM_NEXT_CONTROL_FRAME(
1007 RUBY_VM_NEXT_CONTROL_FRAME(start_cfp));
1009 if (start_cfp < last_cfp) {
1013 size = start_cfp - last_cfp + 1;
1019 for (i=0, cfp = start_cfp; i<size; i++, cfp = RUBY_VM_NEXT_CONTROL_FRAME(cfp)) {
1023 iter_iseq(arg, cfp);
1027 VM_ASSERT(RUBYVM_CFUNC_FRAME_P(cfp));
1029 ID mid = me->def->original_id;
1031 iter_cfunc(arg, cfp, mid);
1039 void (*func)(
void *data,
VALUE file,
int lineno,
VALUE name);
1044oldbt_init(
void *ptr,
size_t dmy)
1047 arg->filename = GET_VM()->progname;
1055 const VALUE *pc = cfp->pc;
1057 VALUE file = arg->filename = rb_iseq_path(iseq);
1058 VALUE name = ISEQ_BODY(iseq)->location.label;
1059 int lineno = arg->lineno = calc_lineno(iseq, pc);
1061 (arg->func)(arg->data, file, lineno, name);
1068 VALUE file = arg->filename;
1069 VALUE name = rb_id2str(mid);
1070 int lineno = arg->lineno;
1072 (arg->func)(arg->data, file, lineno, name);
1076oldbt_print(
void *data,
VALUE file,
int lineno,
VALUE name)
1081 fprintf(fp,
"\tfrom %s:%d:in unknown method\n",
1082 RSTRING_PTR(file), lineno);
1085 fprintf(fp,
"\tfrom %s:%d:in '%s'\n",
1086 RSTRING_PTR(file), lineno, RSTRING_PTR(name));
1091vm_backtrace_print(
FILE *fp)
1095 arg.func = oldbt_print;
1096 arg.data = (
void *)fp;
1097 backtrace_each(GET_EC(),
1110oldbt_bugreport(
void *arg,
VALUE file,
int line,
VALUE method)
1114 const char *filename =
NIL_P(file) ?
"ruby" : RSTRING_PTR(file);
1116 fprintf(fp,
"-- Ruby level backtrace information "
1117 "----------------------------------------\n");
1120 if (
NIL_P(method)) {
1121 fprintf(fp,
"%s:%d:in unknown method\n", filename, line);
1124 fprintf(fp,
"%s:%d:in '%s'\n", filename, line, RSTRING_PTR(method));
1129rb_backtrace_print_as_bugreport(
FILE *fp)
1134 arg.func = oldbt_bugreport;
1137 backtrace_each(GET_EC(),
1147 vm_backtrace_print(stderr);
1156oldbt_print_to(
void *data,
VALUE file,
int lineno,
VALUE name)
1159 VALUE str = rb_sprintf(
"\tfrom %"PRIsVALUE
":%d:in ", file, lineno);
1165 rb_str_catf(str,
" '%"PRIsVALUE
"'\n", name);
1167 (*arg->iter)(arg->output, str);
1177 parg.output = output;
1178 arg.func = oldbt_print_to;
1180 backtrace_each(GET_EC(),
1188rb_make_backtrace(
void)
1190 return rb_ec_backtrace_str_ary(GET_EC(), RUBY_BACKTRACE_START, RUBY_ALL_BACKTRACE_LINES);
1196 VALUE level, vn, opts;
1204 if (argc == 2 &&
NIL_P(vn)) argc--;
1208 lev = lev_default + lev_plus;
1209 n = RUBY_ALL_BACKTRACE_LINES;
1213 long beg,
len, bt_size = backtrace_size(ec);
1218 rb_raise(rb_eArgError,
"negative level (%ld)", lev);
1221 n = RUBY_ALL_BACKTRACE_LINES;
1226 lev = beg + lev_plus;
1236 rb_raise(rb_eArgError,
"negative level (%ld)", lev);
1239 rb_raise(rb_eArgError,
"negative size (%ld)", n);
1259 lev = ec_backtrace_range(ec, argc, argv, lev_default, lev_plus, &n);
1260 if (lev < 0)
return Qnil;
1266 btval = rb_ec_partial_backtrace_object(ec, lev, n, &too_large, FALSE, FALSE);
1273 r = backtrace_to_str_ary(btval);
1276 r = backtrace_to_location_ary(btval);
1283thread_backtrace_to_ary(
int argc,
const VALUE *argv,
VALUE thval,
int to_str)
1287 if (target_th->to_kill || target_th->status == THREAD_KILLED)
1290 return ec_backtrace_to_ary(target_th->ec, argc, argv, 0, 0, to_str);
1294rb_vm_thread_backtrace(
int argc,
const VALUE *argv,
VALUE thval)
1296 return thread_backtrace_to_ary(argc, argv, thval, 1);
1300rb_vm_thread_backtrace_locations(
int argc,
const VALUE *argv,
VALUE thval)
1302 return thread_backtrace_to_ary(argc, argv, thval, 0);
1308 return ec_backtrace_to_ary(ec, argc, argv, 0, 0, 1);
1314 return ec_backtrace_to_ary(ec, argc, argv, 0, 0, 0);
1358 return ec_backtrace_to_ary(GET_EC(), argc, argv, 1, 1, 1);
1384rb_f_caller_locations(
int argc,
VALUE *argv,
VALUE _)
1386 return ec_backtrace_to_ary(GET_EC(), argc, argv, 1, 1, 0);
1397each_caller_location(
int argc,
VALUE *argv,
VALUE _)
1400 long n, lev = ec_backtrace_range(ec, argc, argv, 1, 1, &n);
1401 if (lev >= 0 && n != 0) {
1402 rb_ec_partial_backtrace_object(ec, lev, n, NULL, FALSE, TRUE);
1409Init_vm_backtrace(
void)
1474 rb_define_method(rb_cBacktraceLocation,
"base_label", location_base_label_m, 0);
1476 rb_define_method(rb_cBacktraceLocation,
"absolute_path", location_absolute_path_m, 0);
1488RUBY_SYMBOL_EXPORT_BEGIN
1490RUBY_SYMBOL_EXPORT_END
1496 VALUE raw_backtrace;
1500 CALLER_BINDING_SELF,
1501 CALLER_BINDING_CLASS,
1502 CALLER_BINDING_BINDING,
1503 CALLER_BINDING_ISEQ,
1506 CALLER_BINDING_DEPTH,
1517collect_caller_bindings_init(
void *arg,
size_t num_frames)
1520 data->btobj = backtrace_alloc_capa(num_frames, &data->bt);
1527 if (rb_vm_control_frame_id_and_class(cfp, 0, 0, &klass)) {
1529 return RBASIC(klass)->klass;
1543 VM_ASSERT(RUBY_VM_END_CONTROL_FRAME(ec) >= cfp);
1544 return (
int)(RUBY_VM_END_CONTROL_FRAME(ec) - cfp);
1554 rb_ary_store(frame, CALLER_BINDING_CLASS, get_klass(cfp));
1555 rb_ary_store(frame, CALLER_BINDING_BINDING, GC_GUARDED_PTR(cfp));
1557 rb_ary_store(frame, CALLER_BINDING_CFP, GC_GUARDED_PTR(cfp));
1560 RB_OBJ_WRITE(data->btobj, &loc->cme, rb_vm_frame_method_entry(cfp));
1563 VALUE vloc = location_create(loc, (
void *)data->btobj);
1578 rb_ary_store(frame, CALLER_BINDING_CLASS, get_klass(cfp));
1581 rb_ary_store(frame, CALLER_BINDING_CFP, GC_GUARDED_PTR(cfp));
1584 RB_OBJ_WRITE(data->btobj, &loc->cme, rb_vm_frame_method_entry(cfp));
1587 VALUE vloc = location_create(loc, (
void *)data->btobj);
1605 collect_caller_bindings_init,
1606 collect_caller_bindings_iseq,
1607 collect_caller_bindings_cfunc,
1617 if (!
NIL_P(cfp_val)) {
1619 rb_ary_store(entry, CALLER_BINDING_BINDING, rb_vm_make_binding(ec, cfp));
1636 enum ruby_tag_type state;
1637 volatile VALUE MAYBE_UNUSED(result);
1641 rb_vm_stack_to_heap(ec);
1643 dbg_context.ec = ec;
1644 dbg_context.cfp = dbg_context.ec->cfp;
1645 dbg_context.contexts = collect_caller_bindings(ec);
1647 for (i=0; i<
RARRAY_LEN(dbg_context.contexts); i++) {
1653 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1654 result = (*func)(&dbg_context, data);
1661 EC_JUMP_TAG(ec, state);
1670 if (index < 0 || index >=
RARRAY_LEN(dc->contexts)) {
1671 rb_raise(rb_eArgError,
"no such frame");
1679 VALUE frame = frame_get(dc, index);
1686 VALUE frame = frame_get(dc, index);
1693 VALUE frame = frame_get(dc, index);
1700 VALUE frame = frame_get(dc, index);
1709 VALUE frame = frame_get(dc, index);
1717 return INT2FIX(frame_depth(ec, ec->cfp));
1723 return dc->raw_backtrace;
1744 end_cfp = RUBY_VM_NEXT_CONTROL_FRAME(end_cfp);
1746 for (i=0; i<limit && cfp != end_cfp; cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)) {
1747 if (VM_FRAME_RUBYFRAME_P(cfp) && cfp->pc != 0) {
1754 cme = rb_vm_frame_method_entry(cfp);
1755 if (cme && cme->def->type == VM_METHOD_TYPE_ISEQ) {
1756 buff[i] = (
VALUE)cme;
1759 buff[i] = (
VALUE)cfp->iseq;
1767 if (cfp == top && cfp->jit_return) {
1771 lines[i] = calc_lineno(cfp->iseq, cfp->pc);
1778 cme = rb_vm_frame_method_entry(cfp);
1779 if (cme && cme->def->type == VM_METHOD_TYPE_CFUNC) {
1784 buff[i] = (
VALUE)cme;
1785 if (lines) lines[i] = 0;
1805 return thread_profile_frames(ec, start, limit, buff, lines);
1812 return thread_profile_frames(th->ec, start, limit, buff, lines);
1816frame2iseq(
VALUE frame)
1818 if (
NIL_P(frame))
return NULL;
1821 switch (imemo_type(frame)) {
1827 switch (cme->def->type) {
1828 case VM_METHOD_TYPE_ISEQ:
1829 return cme->def->body.iseq.
iseqptr;
1838 rb_bug(
"frame2iseq: unreachable");
1844 const rb_iseq_t *iseq = frame2iseq(frame);
1845 return iseq ? rb_iseq_path(iseq) :
Qnil;
1851 if (
NIL_P(frame))
return NULL;
1854 switch (imemo_type(frame)) {
1858 switch (cme->def->type) {
1859 case VM_METHOD_TYPE_CFUNC:
1876 if (cframe(frame)) {
1880 rb_vm_register_global_object(cfunc_str);
1884 const rb_iseq_t *iseq = frame2iseq(frame);
1885 return iseq ? rb_iseq_realpath(iseq) :
Qnil;
1891 const rb_iseq_t *iseq = frame2iseq(frame);
1892 return iseq ? rb_iseq_label(iseq) :
Qnil;
1898 const rb_iseq_t *iseq = frame2iseq(frame);
1899 return iseq ? rb_iseq_base_label(iseq) :
Qnil;
1905 const rb_iseq_t *iseq = frame2iseq(frame);
1906 return iseq ? rb_iseq_first_lineno(iseq) :
Qnil;
1910frame2klass(
VALUE frame)
1917 if (imemo_type(frame) == imemo_ment) {
1918 return cme->defined_class;
1927 VALUE klass = frame2klass(frame);
1929 if (klass && !
NIL_P(klass)) {
1931 klass =
RBASIC(klass)->klass;
1933 else if (RCLASS_SINGLETON_P(klass)) {
1934 klass = RCLASS_ATTACHED_OBJECT(klass);
1948 VALUE klass = frame2klass(frame);
1950 return RBOOL(klass && !
NIL_P(klass) && RCLASS_SINGLETON_P(klass));
1958 ID mid = cme->def->original_id;
1961 const rb_iseq_t *iseq = frame2iseq(frame);
1962 return iseq ? rb_iseq_method_name(iseq) :
Qnil;
1966qualified_method_name(
VALUE frame,
VALUE method_name)
1968 if (method_name !=
Qnil) {
1972 if (classpath !=
Qnil) {
1973 return rb_sprintf(
"%"PRIsVALUE
"%s%"PRIsVALUE,
1974 classpath, singleton_p ==
Qtrue ?
"." :
"#", method_name);
1990 return qualified_method_name(frame, method_name);
1998 ID mid = cme->def->original_id;
1999 VALUE method_name = id2str(mid);
2000 return qualified_method_name(frame, method_name);
2007 if (
NIL_P(qualified_method_name) || base_label == qualified_method_name) {
2011 long label_length = RSTRING_LEN(label);
2012 long base_label_length = RSTRING_LEN(base_label);
2013 int prefix_len =
rb_long2int(label_length - base_label_length);
2015 return rb_sprintf(
"%.*s%"PRIsVALUE, prefix_len, RSTRING_PTR(label), qualified_method_name);
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
#define rb_define_global_function(mid, func, arity)
Defines rb_mKernel #mid.
int rb_profile_frames(int start, int limit, VALUE *buff, int *lines)
Queries mysterious "frame"s of the given range.
VALUE rb_profile_frame_full_label(VALUE frame)
Identical to rb_profile_frame_label(), except it returns a qualified result.
VALUE rb_debug_inspector_frame_iseq_get(const rb_debug_inspector_t *dc, long index)
Queries the instruction sequence of the passed context's upper frame.
VALUE rb_debug_inspector_current_depth(void)
Return current frmae depth.
VALUE rb_profile_frame_method_name(VALUE frame)
Queries the name of the method of the passed frame.
VALUE rb_debug_inspector_frame_depth(const rb_debug_inspector_t *dc, long index)
Queries the depth of the passed context's upper frame.
VALUE rb_profile_frame_qualified_method_name(VALUE frame)
Identical to rb_profile_frame_method_name(), except it "qualifies" the return value with its defining...
VALUE rb_profile_frame_label(VALUE frame)
Queries human-readable "label" string.
VALUE rb_profile_frame_singleton_method_p(VALUE frame)
Queries if the method of the passed frame is a singleton class.
VALUE rb_debug_inspector_backtrace_locations(const rb_debug_inspector_t *dc)
Queries the backtrace object of the context.
VALUE rb_profile_frame_absolute_path(VALUE frame)
Identical to rb_profile_frame_path(), except it tries to expand the returning path.
VALUE rb_debug_inspector_open(rb_debug_inspector_func_t func, void *data)
Prepares, executes, then cleans up a debug session.
VALUE rb_debug_inspector_frame_self_get(const rb_debug_inspector_t *dc, long index)
Queries the current receiver of the passed context's upper frame.
VALUE rb_debug_inspector_frame_binding_get(const rb_debug_inspector_t *dc, long index)
Queries the binding of the passed context's upper frame.
VALUE rb_debug_inspector_frame_class_get(const rb_debug_inspector_t *dc, long index)
Queries the current class of the passed context's upper frame.
VALUE rb_profile_frame_classpath(VALUE frame)
Queries the class path of the method that the passed frame represents.
VALUE rb_profile_frame_path(VALUE frame)
Queries the path of the passed backtrace.
VALUE rb_profile_frame_first_lineno(VALUE frame)
Queries the first line of the method of the passed frame pointer.
int rb_profile_thread_frames(VALUE thread, int start, int limit, VALUE *buff, int *lines)
Queries mysterious "frame"s of the given range.
VALUE(* rb_debug_inspector_func_t)(const rb_debug_inspector_t *dc, void *data)
Type of the callback function passed to rb_debug_inspector_open().
VALUE rb_profile_frame_base_label(VALUE frame)
Identical to rb_profile_frame_label(), except it does not "qualify" the result.
VALUE rb_enc_sprintf(rb_encoding *enc, const char *fmt,...)
Identical to rb_sprintf(), except it additionally takes an encoding.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_undef_method(VALUE klass, const char *name)
Defines an undef of a method.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
Keyword argument deconstructor.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define rb_str_cat2
Old name of rb_str_cat_cstr.
#define T_IMEMO
Old name of RUBY_T_IMEMO.
#define CLASS_OF
Old name of rb_class_of.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define ASSUME
Old name of RBIMPL_ASSUME.
#define T_ICLASS
Old name of RUBY_T_ICLASS.
#define LONG2NUM
Old name of RB_LONG2NUM.
#define Qtrue
Old name of RUBY_Qtrue.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define NIL_P
Old name of RB_NIL_P.
#define T_CLASS
Old name of RUBY_T_CLASS.
#define NUM2LONG
Old name of RB_NUM2LONG.
#define rb_ary_new2
Old name of rb_ary_new_capa.
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
Checks if the given object is of given kind.
VALUE rb_cArray
Array class.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_cThread
Thread class.
#define RB_OBJ_WRITTEN(old, oldv, young)
Identical to RB_OBJ_WRITE(), except it doesn't write any values, but only a WB declaration.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
VALUE rb_ary_reverse(VALUE ary)
Destructively reverses the passed array in-place.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_entry(VALUE ary, long off)
Queries an element of an array.
void rb_ary_store(VALUE ary, long key, VALUE val)
Destructively stores the passed value to the passed array's passed index.
VALUE rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
Deconstructs a numerical range.
#define rb_str_new_literal(str)
Just another name of rb_str_new_lit.
VALUE rb_str_inspect(VALUE str)
Generates a "readable" version of the receiver.
#define rb_str_cat_cstr(buf, str)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_class_path(VALUE mod)
Identical to rb_mod_name(), except it returns #<Class: ...> style inspection for anonymous modules.
void rb_undef_alloc_func(VALUE klass)
Deletes the allocator function of a class.
void rb_define_alloc_func(VALUE klass, rb_alloc_func_t func)
Sets the allocator function of a class.
void rb_backtrace(void)
Prints the backtrace out to the standard error.
int len
Length of the buffer.
VALUE rb_yield(VALUE val)
Yields the block.
#define rb_long2int
Just another name of rb_long2int_inline.
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
Marshal format compatibility layer.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE type(ANYARGS)
ANYARGS-ed function type.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
#define RBASIC(obj)
Convenient casting macro.
#define RUBY_DEFAULT_FREE
This is a value you can set to RData::dfree.
#define RUBY_TYPED_DEFAULT_FREE
This is a value you can set to rb_data_type_struct::dfree.
#define TypedData_Get_Struct(obj, type, data_type, sval)
Obtains a C struct from inside of a wrapper Ruby object.
#define TypedData_Make_Struct(klass, type, data_type, sval)
Identical to TypedData_Wrap_Struct, except it allocates a new data region internally instead of takin...
const char * rb_class2name(VALUE klass)
Queries the name of the passed class.
#define RTEST
This is an old name of RB_TEST.
#define _(args)
This was a transition path from K&R to ANSI.
This is the struct that holds necessary info for a struct.
const rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.