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");
269 if (!loc->cme)
return false;
271 switch (loc->cme->def->type) {
272 case VM_METHOD_TYPE_CFUNC:
274 case VM_METHOD_TYPE_ISEQ:
275 return rb_iseq_attr_p(loc->cme->def->body.iseq.
iseqptr, BUILTIN_ATTR_C_TRACE);
284 if (location_cfunc_p(loc)) {
285 return rb_gen_method_name(loc->cme->owner, rb_id2str(loc->cme->def->original_id));
290 owner = loc->cme->owner;
292 return calculate_iseq_label(owner, loc->iseq);
322location_label_m(
VALUE self)
324 return location_label(location_ptr(self));
330 if (location_cfunc_p(loc)) {
331 return rb_id2str(loc->cme->def->original_id);
334 return ISEQ_BODY(loc->iseq)->location.base_label;
362location_base_label_m(
VALUE self)
364 return location_base_label(location_ptr(self));
384location_path_m(
VALUE self)
386 const rb_iseq_t *iseq = location_iseq(location_ptr(self));
387 return iseq ? rb_iseq_path(iseq) :
Qnil;
390#ifdef USE_ISEQ_NODE_ID
394 if (loc->iseq && loc->pc) {
395 return calc_node_id(loc->iseq, loc->pc);
402rb_get_node_id_from_frame_info(
VALUE obj)
404#ifdef USE_ISEQ_NODE_ID
406 return location_node_id(loc);
413rb_get_iseq_from_frame_info(
VALUE obj)
416 const rb_iseq_t *iseq = location_iseq(loc);
424 return rb_iseq_realpath(loc->iseq);
436location_absolute_path_m(
VALUE self)
438 return location_realpath(location_ptr(self));
442location_format(
VALUE file,
int lineno,
VALUE name)
446 rb_str_catf(s,
":%d", lineno);
453 rb_str_catf(s,
"'%s'", RSTRING_PTR(name));
464 if (location_cfunc_p(loc)) {
465 if (loc->iseq && loc->pc) {
466 file = rb_iseq_path(loc->iseq);
467 lineno = calc_lineno(loc->iseq, loc->pc);
470 file = GET_VM()->progname;
473 name = rb_gen_method_name(loc->cme->owner, rb_id2str(loc->cme->def->original_id));
476 file = rb_iseq_path(loc->iseq);
477 lineno = calc_lineno(loc->iseq, loc->pc);
479 owner = loc->cme->owner;
481 name = calculate_iseq_label(owner, loc->iseq);
484 return location_format(file, lineno, name);
491location_to_str_m(
VALUE self)
493 return location_to_str(location_ptr(self));
501location_inspect_m(
VALUE self)
514backtrace_mark(
void *ptr)
517 size_t i, s = bt->backtrace_size;
519 for (i=0; i<s; i++) {
520 location_mark_entry(&bt->backtrace[i]);
522 rb_gc_mark_movable(bt->strary);
523 rb_gc_mark_movable(bt->locary);
536backtrace_update(
void *ptr)
539 size_t i, s = bt->backtrace_size;
541 for (i=0; i<s; i++) {
542 location_update_entry(&bt->backtrace[i]);
544 bt->strary = rb_gc_location(bt->strary);
545 bt->locary = rb_gc_location(bt->locary);
559 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
563rb_backtrace_p(
VALUE obj)
569backtrace_alloc(
VALUE klass)
580 VALUE btobj = rb_data_typed_object_zalloc(rb_cBacktrace, memsize, &backtrace_data_type);
592 if (start_cfp == NULL) {
597 RUBY_VM_NEXT_CONTROL_FRAME(
598 RUBY_VM_NEXT_CONTROL_FRAME(start_cfp));
600 if (start_cfp < last_cfp) {
604 return start_cfp - last_cfp + 1;
610 static const char prefix[] =
"<internal:";
611 const size_t prefix_len =
sizeof(prefix) - 1;
612 VALUE file = rb_iseq_path(cfp->iseq);
613 return strncmp(prefix, RSTRING_PTR(file), prefix_len) == 0;
619 enum rb_iseq_type
type = ISEQ_BODY(cfp->iseq)->type;
620 return type == ISEQ_TYPE_RESCUE ||
type == ISEQ_TYPE_ENSURE;
626 for (; cfunc_counter > 0; cfunc_counter--, cfunc_loc--) {
627 cfunc_loc->iseq = iseq;
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 cfunc_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) {
694 else if (!(skip_internal && is_internal_location(cfp))) {
695 if (!skip_next_frame) {
697 const VALUE *pc = cfp->pc;
698 loc = &bt->backtrace[bt->backtrace_size++];
699 RB_OBJ_WRITE(btobj, &loc->cme, rb_vm_frame_method_entry(cfp));
701 if (rb_iseq_attr_p(cfp->iseq, BUILTIN_ATTR_C_TRACE)) {
709 bt_update_cfunc_loc(cfunc_counter, loc-1, iseq, pc);
711 bt_yield_loc(loc - cfunc_counter, cfunc_counter+1, btobj);
716 skip_next_frame = is_rescue_or_ensure_frame(cfp);
721 VM_ASSERT(RUBYVM_CFUNC_FRAME_P(cfp));
722 if (start_frame > 0) {
726 loc = &bt->backtrace[bt->backtrace_size++];
727 RB_OBJ_WRITE(btobj, &loc->cme, rb_vm_frame_method_entry(cfp));
737 if (cfunc_counter > 0) {
738 for (; cfp != end_cfp; cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)) {
739 if (cfp->iseq && cfp->pc && !(skip_internal && is_internal_location(cfp))) {
740 VM_ASSERT(!skip_next_frame);
741 bt_update_cfunc_loc(cfunc_counter, loc, cfp->iseq, cfp->pc);
744 bt_yield_loc(loc - cfunc_counter, cfunc_counter, btobj);
751 if (start_too_large) *start_too_large = (start_frame > 0 ? -1 : 0);
758 return rb_ec_partial_backtrace_object(ec, RUBY_BACKTRACE_START, RUBY_ALL_BACKTRACE_LINES, NULL, FALSE, FALSE);
769 for (i=0; i<bt->backtrace_size; i++) {
771 rb_ary_push(btary, func(loc, arg));
780 return location_to_str(loc);
784backtrace_to_str_ary(
VALUE self)
789 r = backtrace_collect(bt, location_to_str_dmyarg, 0);
795rb_backtrace_to_str_ary(
VALUE self)
801 RB_OBJ_WRITE(self, &bt->strary, backtrace_to_str_ary(self));
807rb_backtrace_use_iseq_first_lineno_for_last_location(
VALUE self)
813 VM_ASSERT(bt->backtrace_size > 0);
815 loc = &bt->backtrace[0];
817 VM_ASSERT(!loc->cme || loc->cme->def->type == VM_METHOD_TYPE_ISEQ);
836backtrace_to_location_ary(
VALUE self)
841 r = backtrace_collect(bt, location_create, (
void *)self);
847rb_backtrace_to_location_ary(
VALUE self)
853 RB_OBJ_WRITE(self, &bt->locary, backtrace_to_location_ary(self));
859rb_location_ary_to_backtrace(
VALUE ary)
867 VALUE btobj = backtrace_alloc_capa(num_frames, &new_backtrace);
869 for (
long index = 0; index <
RARRAY_LEN(ary); index++) {
872 if (!rb_frame_info_p(locobj)) {
880 RB_OBJ_WRITE(btobj, &dst_location->cme, src_vloc->loc->cme);
881 RB_OBJ_WRITE(btobj, &dst_location->iseq, src_vloc->loc->iseq);
882 dst_location->pc = src_vloc->loc->pc;
884 new_backtrace->backtrace_size++;
893backtrace_dump_data(
VALUE self)
895 VALUE str = rb_backtrace_to_str_ary(self);
959backtrace_limit(
VALUE self)
961 return LONG2NUM(rb_backtrace_length_limit);
967 return rb_backtrace_to_str_ary(rb_ec_partial_backtrace_object(ec, lev, n, NULL, FALSE, FALSE));
973 return rb_backtrace_to_location_ary(rb_ec_partial_backtrace_object(ec, lev, n, NULL, skip_internal, FALSE));
980 void (*init)(
void *arg,
size_t size),
991 if (start_cfp == NULL) {
1007 RUBY_VM_NEXT_CONTROL_FRAME(
1008 RUBY_VM_NEXT_CONTROL_FRAME(start_cfp));
1010 if (start_cfp < last_cfp) {
1014 size = start_cfp - last_cfp + 1;
1020 for (i=0, cfp = start_cfp; i<size; i++, cfp = RUBY_VM_NEXT_CONTROL_FRAME(cfp)) {
1024 iter_iseq(arg, cfp);
1028 VM_ASSERT(RUBYVM_CFUNC_FRAME_P(cfp));
1030 ID mid = me->def->original_id;
1032 iter_cfunc(arg, cfp, mid);
1040 void (*func)(
void *data,
VALUE file,
int lineno,
VALUE name);
1045oldbt_init(
void *ptr,
size_t dmy)
1048 arg->filename = GET_VM()->progname;
1056 const VALUE *pc = cfp->pc;
1058 VALUE file = arg->filename = rb_iseq_path(iseq);
1059 VALUE name = ISEQ_BODY(iseq)->location.label;
1060 int lineno = arg->lineno = calc_lineno(iseq, pc);
1062 (arg->func)(arg->data, file, lineno, name);
1069 VALUE file = arg->filename;
1070 VALUE name = rb_id2str(mid);
1071 int lineno = arg->lineno;
1073 (arg->func)(arg->data, file, lineno, name);
1077oldbt_print(
void *data,
VALUE file,
int lineno,
VALUE name)
1082 fprintf(fp,
"\tfrom %s:%d:in unknown method\n",
1083 RSTRING_PTR(file), lineno);
1086 fprintf(fp,
"\tfrom %s:%d:in '%s'\n",
1087 RSTRING_PTR(file), lineno, RSTRING_PTR(name));
1092vm_backtrace_print(
FILE *fp)
1096 arg.func = oldbt_print;
1097 arg.data = (
void *)fp;
1098 backtrace_each(GET_EC(),
1111oldbt_bugreport(
void *arg,
VALUE file,
int line,
VALUE method)
1115 const char *filename =
NIL_P(file) ?
"ruby" : RSTRING_PTR(file);
1117 fprintf(fp,
"-- Ruby level backtrace information "
1118 "----------------------------------------\n");
1121 if (
NIL_P(method)) {
1122 fprintf(fp,
"%s:%d:in unknown method\n", filename, line);
1125 fprintf(fp,
"%s:%d:in '%s'\n", filename, line, RSTRING_PTR(method));
1130rb_backtrace_print_as_bugreport(
FILE *fp)
1135 arg.func = oldbt_bugreport;
1138 backtrace_each(GET_EC(),
1148 vm_backtrace_print(stderr);
1157oldbt_print_to(
void *data,
VALUE file,
int lineno,
VALUE name)
1160 VALUE str = rb_sprintf(
"\tfrom %"PRIsVALUE
":%d:in ", file, lineno);
1166 rb_str_catf(str,
" '%"PRIsVALUE
"'\n", name);
1168 (*arg->iter)(arg->output, str);
1178 parg.output = output;
1179 arg.func = oldbt_print_to;
1181 backtrace_each(GET_EC(),
1189rb_make_backtrace(
void)
1191 return rb_ec_backtrace_str_ary(GET_EC(), RUBY_BACKTRACE_START, RUBY_ALL_BACKTRACE_LINES);
1197 VALUE level, vn, opts;
1205 if (argc == 2 &&
NIL_P(vn)) argc--;
1209 lev = lev_default + lev_plus;
1210 n = RUBY_ALL_BACKTRACE_LINES;
1214 long beg,
len, bt_size = backtrace_size(ec);
1219 rb_raise(rb_eArgError,
"negative level (%ld)", lev);
1222 n = RUBY_ALL_BACKTRACE_LINES;
1227 lev = beg + lev_plus;
1237 rb_raise(rb_eArgError,
"negative level (%ld)", lev);
1240 rb_raise(rb_eArgError,
"negative size (%ld)", n);
1260 lev = ec_backtrace_range(ec, argc, argv, lev_default, lev_plus, &n);
1261 if (lev < 0)
return Qnil;
1264 return rb_ary_new();
1267 btval = rb_ec_partial_backtrace_object(ec, lev, n, &too_large, FALSE, FALSE);
1274 r = backtrace_to_str_ary(btval);
1277 r = backtrace_to_location_ary(btval);
1284thread_backtrace_to_ary(
int argc,
const VALUE *argv,
VALUE thval,
int to_str)
1288 if (target_th->to_kill || target_th->status == THREAD_KILLED)
1291 return ec_backtrace_to_ary(target_th->ec, argc, argv, 0, 0, to_str);
1295rb_vm_thread_backtrace(
int argc,
const VALUE *argv,
VALUE thval)
1297 return thread_backtrace_to_ary(argc, argv, thval, 1);
1301rb_vm_thread_backtrace_locations(
int argc,
const VALUE *argv,
VALUE thval)
1303 return thread_backtrace_to_ary(argc, argv, thval, 0);
1309 return ec_backtrace_to_ary(ec, argc, argv, 0, 0, 1);
1315 return ec_backtrace_to_ary(ec, argc, argv, 0, 0, 0);
1359 return ec_backtrace_to_ary(GET_EC(), argc, argv, 1, 1, 1);
1385rb_f_caller_locations(
int argc,
VALUE *argv,
VALUE _)
1387 return ec_backtrace_to_ary(GET_EC(), argc, argv, 1, 1, 0);
1398each_caller_location(
int argc,
VALUE *argv,
VALUE _)
1401 long n, lev = ec_backtrace_range(ec, argc, argv, 1, 1, &n);
1402 if (lev >= 0 && n != 0) {
1403 rb_ec_partial_backtrace_object(ec, lev, n, NULL, FALSE, TRUE);
1410Init_vm_backtrace(
void)
1475 rb_define_method(rb_cBacktraceLocation,
"base_label", location_base_label_m, 0);
1477 rb_define_method(rb_cBacktraceLocation,
"absolute_path", location_absolute_path_m, 0);
1489RUBY_SYMBOL_EXPORT_BEGIN
1491RUBY_SYMBOL_EXPORT_END
1498 long backtrace_size;
1502 CALLER_BINDING_SELF,
1503 CALLER_BINDING_CLASS,
1504 CALLER_BINDING_BINDING,
1505 CALLER_BINDING_ISEQ,
1507 CALLER_BINDING_DEPTH,
1516collect_caller_bindings_init(
void *arg,
size_t size)
1525 if (rb_vm_control_frame_id_and_class(cfp, 0, 0, &klass)) {
1527 return RBASIC(klass)->klass;
1541 VM_ASSERT(RUBY_VM_END_CONTROL_FRAME(ec) >= cfp);
1542 return (
int)(RUBY_VM_END_CONTROL_FRAME(ec) - cfp);
1551 rb_ary_store(frame, CALLER_BINDING_SELF, cfp->self);
1552 rb_ary_store(frame, CALLER_BINDING_CLASS, get_klass(cfp));
1553 rb_ary_store(frame, CALLER_BINDING_BINDING, GC_GUARDED_PTR(cfp));
1554 rb_ary_store(frame, CALLER_BINDING_ISEQ, cfp->iseq ? (
VALUE)cfp->iseq :
Qnil);
1555 rb_ary_store(frame, CALLER_BINDING_CFP, GC_GUARDED_PTR(cfp));
1556 rb_ary_store(frame, CALLER_BINDING_DEPTH,
INT2FIX(frame_depth(data->ec, cfp)));
1558 rb_ary_push(data->ary, frame);
1567 rb_ary_store(frame, CALLER_BINDING_SELF, cfp->self);
1568 rb_ary_store(frame, CALLER_BINDING_CLASS, get_klass(cfp));
1569 rb_ary_store(frame, CALLER_BINDING_BINDING,
Qnil);
1570 rb_ary_store(frame, CALLER_BINDING_ISEQ,
Qnil);
1571 rb_ary_store(frame, CALLER_BINDING_CFP, GC_GUARDED_PTR(cfp));
1572 rb_ary_store(frame, CALLER_BINDING_DEPTH,
INT2FIX(frame_depth(data->ec, cfp)));
1574 rb_ary_push(data->ary, frame);
1587 collect_caller_bindings_init,
1588 collect_caller_bindings_iseq,
1589 collect_caller_bindings_cfunc,
1592 result = rb_ary_reverse(data.ary);
1596 VALUE entry = rb_ary_entry(result, i);
1597 VALUE cfp_val = rb_ary_entry(entry, CALLER_BINDING_BINDING);
1599 if (!
NIL_P(cfp_val)) {
1601 rb_ary_store(entry, CALLER_BINDING_BINDING, rb_vm_make_binding(ec, cfp));
1618 enum ruby_tag_type state;
1619 volatile VALUE MAYBE_UNUSED(result);
1622 rb_vm_stack_to_heap(ec);
1624 dbg_context.ec = ec;
1625 dbg_context.cfp = dbg_context.ec->cfp;
1626 dbg_context.backtrace = rb_ec_backtrace_location_ary(ec, RUBY_BACKTRACE_START, RUBY_ALL_BACKTRACE_LINES, FALSE);
1627 dbg_context.backtrace_size =
RARRAY_LEN(dbg_context.backtrace);
1628 dbg_context.contexts = collect_caller_bindings(ec);
1631 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1632 result = (*func)(&dbg_context, data);
1639 EC_JUMP_TAG(ec, state);
1648 if (index < 0 || index >= dc->backtrace_size) {
1649 rb_raise(rb_eArgError,
"no such frame");
1651 return rb_ary_entry(dc->contexts, index);
1657 VALUE frame = frame_get(dc, index);
1658 return rb_ary_entry(frame, CALLER_BINDING_SELF);
1664 VALUE frame = frame_get(dc, index);
1665 return rb_ary_entry(frame, CALLER_BINDING_CLASS);
1671 VALUE frame = frame_get(dc, index);
1672 return rb_ary_entry(frame, CALLER_BINDING_BINDING);
1678 VALUE frame = frame_get(dc, index);
1679 VALUE iseq = rb_ary_entry(frame, CALLER_BINDING_ISEQ);
1687 VALUE frame = frame_get(dc, index);
1688 return rb_ary_entry(frame, CALLER_BINDING_DEPTH);
1695 return INT2FIX(frame_depth(ec, ec->cfp));
1701 return dc->backtrace;
1722 end_cfp = RUBY_VM_NEXT_CONTROL_FRAME(end_cfp);
1724 for (i=0; i<limit && cfp != end_cfp; cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)) {
1725 if (VM_FRAME_RUBYFRAME_P(cfp) && cfp->pc != 0) {
1732 cme = rb_vm_frame_method_entry(cfp);
1733 if (cme && cme->def->type == VM_METHOD_TYPE_ISEQ) {
1734 buff[i] = (
VALUE)cme;
1737 buff[i] = (
VALUE)cfp->iseq;
1745 if (cfp == top && cfp->jit_return) {
1749 lines[i] = calc_lineno(cfp->iseq, cfp->pc);
1756 cme = rb_vm_frame_method_entry(cfp);
1757 if (cme && cme->def->type == VM_METHOD_TYPE_CFUNC) {
1762 buff[i] = (
VALUE)cme;
1763 if (lines) lines[i] = 0;
1783 return thread_profile_frames(ec, start, limit, buff, lines);
1790 return thread_profile_frames(th->ec, start, limit, buff, lines);
1794frame2iseq(
VALUE frame)
1796 if (
NIL_P(frame))
return NULL;
1799 switch (imemo_type(frame)) {
1805 switch (cme->def->type) {
1806 case VM_METHOD_TYPE_ISEQ:
1807 return cme->def->body.iseq.
iseqptr;
1816 rb_bug(
"frame2iseq: unreachable");
1822 const rb_iseq_t *iseq = frame2iseq(frame);
1823 return iseq ? rb_iseq_path(iseq) :
Qnil;
1829 if (
NIL_P(frame))
return NULL;
1832 switch (imemo_type(frame)) {
1836 switch (cme->def->type) {
1837 case VM_METHOD_TYPE_CFUNC:
1854 if (cframe(frame)) {
1858 rb_vm_register_global_object(cfunc_str);
1862 const rb_iseq_t *iseq = frame2iseq(frame);
1863 return iseq ? rb_iseq_realpath(iseq) :
Qnil;
1869 const rb_iseq_t *iseq = frame2iseq(frame);
1870 return iseq ? rb_iseq_label(iseq) :
Qnil;
1876 const rb_iseq_t *iseq = frame2iseq(frame);
1877 return iseq ? rb_iseq_base_label(iseq) :
Qnil;
1883 const rb_iseq_t *iseq = frame2iseq(frame);
1884 return iseq ? rb_iseq_first_lineno(iseq) :
Qnil;
1888frame2klass(
VALUE frame)
1895 if (imemo_type(frame) == imemo_ment) {
1896 return cme->defined_class;
1905 VALUE klass = frame2klass(frame);
1907 if (klass && !
NIL_P(klass)) {
1909 klass =
RBASIC(klass)->klass;
1911 else if (RCLASS_SINGLETON_P(klass)) {
1912 klass = RCLASS_ATTACHED_OBJECT(klass);
1926 VALUE klass = frame2klass(frame);
1928 return RBOOL(klass && !
NIL_P(klass) && RCLASS_SINGLETON_P(klass));
1936 ID mid = cme->def->original_id;
1939 const rb_iseq_t *iseq = frame2iseq(frame);
1940 return iseq ? rb_iseq_method_name(iseq) :
Qnil;
1944qualified_method_name(
VALUE frame,
VALUE method_name)
1946 if (method_name !=
Qnil) {
1950 if (classpath !=
Qnil) {
1951 return rb_sprintf(
"%"PRIsVALUE
"%s%"PRIsVALUE,
1952 classpath, singleton_p ==
Qtrue ?
"." :
"#", method_name);
1968 return qualified_method_name(frame, method_name);
1976 ID mid = cme->def->original_id;
1977 VALUE method_name = id2str(mid);
1978 return qualified_method_name(frame, method_name);
1985 if (
NIL_P(qualified_method_name) || base_label == qualified_method_name) {
1989 long label_length = RSTRING_LEN(label);
1990 long base_label_length = RSTRING_LEN(base_label);
1991 int prefix_len =
rb_long2int(label_length - base_label_length);
1993 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_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.