12#include "eval_intern.h"
14#include "internal/class.h"
15#include "internal/error.h"
16#include "internal/object.h"
17#include "internal/proc.h"
18#include "internal/ruby_parser.h"
19#include "internal/vm.h"
21#include "prism_compile.h"
28static VALUE rb_cBacktrace;
29static VALUE rb_cBacktraceLocation;
34 VALUE str = rb_id2str(
id);
35 if (!str)
return Qnil;
38#define rb_id2str(id) id2str(id)
41calc_pos(
const rb_iseq_t *iseq,
const VALUE *pc,
int *lineno,
int *node_id)
46 if (ISEQ_BODY(iseq)->
type == ISEQ_TYPE_TOP) {
47 VM_ASSERT(! ISEQ_BODY(iseq)->local_table);
48 VM_ASSERT(! ISEQ_BODY(iseq)->local_table_size);
51 if (lineno) *lineno = ISEQ_BODY(iseq)->location.first_lineno;
52 if (node_id) *node_id = ISEQ_BODY(iseq)->location.node_id;
56 VM_ASSERT(ISEQ_BODY(iseq));
57 VM_ASSERT(ISEQ_BODY(iseq)->iseq_encoded);
58 VM_ASSERT(ISEQ_BODY(iseq)->iseq_size);
60 ptrdiff_t n = pc - ISEQ_BODY(iseq)->iseq_encoded;
62#if SIZEOF_PTRDIFF_T > SIZEOF_INT
63 VM_ASSERT(n <= (ptrdiff_t)UINT_MAX);
65 VM_ASSERT((
unsigned int)n <= ISEQ_BODY(iseq)->iseq_size);
72#if VMDEBUG && defined(HAVE_BUILTIN___BUILTIN_TRAP)
75 rb_print_backtrace(stderr);
79 if (lineno) *lineno = rb_iseq_line_no(iseq, pos);
80 if (node_id) *node_id = rb_iseq_node_id(iseq, pos);
86calc_lineno(
const rb_iseq_t *iseq,
const VALUE *pc)
89 if (calc_pos(iseq, pc, &lineno, NULL))
return lineno;
94calc_node_id(
const rb_iseq_t *iseq,
const VALUE *pc)
97 if (calc_pos(iseq, pc, NULL, &node_id))
return node_id;
102rb_vm_get_sourceline(
const rb_control_frame_t *cfp)
104 if (VM_FRAME_RUBYFRAME_P(cfp) && CFP_ISEQ(cfp)) {
105 const rb_iseq_t *iseq = CFP_ISEQ(cfp);
106 int line = calc_lineno(iseq, CFP_PC(cfp));
111 return ISEQ_BODY(iseq)->location.first_lineno;
120 const rb_callable_method_entry_t *cme;
121 const rb_iseq_t *iseq;
123} rb_backtrace_location_t;
126 rb_backtrace_location_t *loc;
131location_mark(
void *ptr)
134 rb_gc_mark_movable(vfi->btobj);
138location_ref_update(
void *ptr)
141 rb_gc_update_moved(&vfi->btobj);
145location_mark_entry(rb_backtrace_location_t *fi)
147 rb_gc_mark((
VALUE)fi->cme);
148 if (fi->iseq) rb_gc_mark_movable((
VALUE)fi->iseq);
159 0, 0, RUBY_TYPED_THREAD_SAFE_FREE | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
163rb_frame_info_p(
VALUE obj)
165 return rb_typeddata_is_kind_of(obj, &location_data_type);
168static inline rb_backtrace_location_t *
169location_ptr(
VALUE locobj)
177location_lineno(rb_backtrace_location_t *loc)
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);
226calculate_iseq_label(
VALUE owner,
const rb_iseq_t *iseq)
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: {
239 const rb_iseq_t *orig_iseq = iseq;
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;
276location_cfunc_p(rb_backtrace_location_t *loc)
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);
309location_original_module(
const rb_callable_method_entry_t *cme)
311 if (!cme || !cme->def)
return Qnil;
312 VALUE owner = cme->owner;
313 VALUE defined_in = cme->def->original_module;
314 if (!defined_in)
return owner;
315 if (defined_in != owner &&
317 RCLASS_ATTACHED_OBJECT(owner) == defined_in) {
324location_label(rb_backtrace_location_t *loc)
326 if (location_cfunc_p(loc)) {
327 return rb_gen_method_name(location_original_module(loc->cme), rb_id2str(loc->cme->def->original_id));
330 return calculate_iseq_label(location_original_module(loc->cme), loc->iseq);
360location_label_m(
VALUE self)
362 return location_label(location_ptr(self));
366location_base_label(rb_backtrace_location_t *loc)
368 if (location_cfunc_p(loc)) {
369 return rb_id2str(loc->cme->def->original_id);
372 return rb_iseq_base_label(loc->iseq);
400location_base_label_m(
VALUE self)
402 return location_base_label(location_ptr(self));
405static const rb_iseq_t *
406location_iseq(rb_backtrace_location_t *loc)
422location_path_m(
VALUE self)
424 const rb_iseq_t *iseq = location_iseq(location_ptr(self));
425 return iseq ? rb_iseq_path(iseq) :
Qnil;
429location_node_id(rb_backtrace_location_t *loc)
432 return calc_node_id(loc->iseq, loc->pc);
437extern VALUE rb_e_script;
440location_source_end_marker_p(
const uint8_t *line,
size_t length)
442 return (length == 7 && memcmp(line,
"__END__", 7) == 0) ||
443 (length == 8 && memcmp(line,
"__END__\n", 8) == 0) ||
444 (length == 9 && memcmp(line,
"__END__\r\n", 9) == 0);
448location_source_hash_matches(
VALUE source, uint64_t source_hash)
451 const uint8_t *bytes = (
const uint8_t *)RSTRING_PTR(source);
452 size_t length = (size_t)RSTRING_LEN(source);
453 size_t line_start = 0;
454 rb_source_hash_state_t state;
455 rb_source_hash_init(&state);
457 for (
size_t index = 0; index < length; index++) {
458 if (bytes[index] !=
'\n')
continue;
460 size_t line_length = index + 1 - line_start;
461 rb_source_hash_update(&state, bytes + line_start, line_length);
462 if (location_source_end_marker_p(bytes + line_start, line_length) &&
463 rb_source_hash_finalize(&state) == source_hash) {
466 line_start = index + 1;
469 if (line_start < length) {
470 size_t line_length = length - line_start;
471 rb_source_hash_update(&state, bytes + line_start, line_length);
472 if (location_source_end_marker_p(bytes + line_start, line_length) &&
473 rb_source_hash_finalize(&state) == source_hash) {
478 return rb_source_hash_finalize(&state) == source_hash;
482location_source_read(
VALUE io)
494location_source_read_file(
VALUE path)
501location_code_location_equal(
const rb_code_location_t *left,
const rb_code_location_t *right)
503 return left->beg_pos.lineno == right->beg_pos.lineno &&
504 left->beg_pos.column == right->beg_pos.column &&
505 left->end_pos.lineno == right->end_pos.lineno &&
506 left->end_pos.column == right->end_pos.column;
510iseq_from_e_script_p(
const rb_iseq_t *iseq,
VALUE path, uint64_t source_hash)
513 RSTRING_LEN(path) != 2 ||
514 memcmp(RSTRING_PTR(path),
"-e", 2) != 0 ||
515 !
RTEST(rb_e_script)) {
518 bool matches = ISEQ_BODY(iseq)->prism ?
519 pm_source_hash_matches(rb_e_script, path, source_hash) :
520 location_source_hash_matches(rb_e_script, source_hash);
521 if (!matches)
return false;
523 const rb_iseq_t *source_iseq = iseq;
524 for (; source_iseq; source_iseq = ISEQ_BODY(source_iseq)->parent_iseq) {
525 if (ISEQ_BODY(source_iseq)->
type == ISEQ_TYPE_EVAL)
return false;
526 if (ISEQ_BODY(source_iseq)->
type == ISEQ_TYPE_MAIN)
return true;
529 int node_id = ISEQ_BODY(iseq)->location.node_id;
530 if (node_id == -1)
return false;
532 rb_code_location_t source_location;
534 if (ISEQ_BODY(iseq)->prism) {
535 found = pm_node_source_location(rb_e_script, path, 1, node_id, source_hash, &source_location);
538 found = rb_ast_node_source_location(
543 ISEQ_BODY(iseq)->
type == ISEQ_TYPE_BLOCK,
549 return found && location_code_location_equal(
550 &source_location, &ISEQ_BODY(iseq)->location.code_location);
554location_source_first_lineno(
const rb_iseq_t *iseq,
VALUE script_lines)
556 const rb_iseq_t *source_iseq = iseq;
558 while (ISEQ_BODY(source_iseq)->parent_iseq) {
559 const rb_iseq_t *parent = ISEQ_BODY(source_iseq)->parent_iseq;
560 if (ISEQ_SCRIPT_LINES(parent) != script_lines)
break;
561 source_iseq = parent;
564 return ISEQ_BODY(source_iseq)->location.first_lineno;
586location_source_range_m(
VALUE self)
588 rb_backtrace_location_t *backtrace_location = location_ptr(self);
589 const rb_iseq_t *iseq = location_iseq(backtrace_location);
591 rb_raise(
rb_eRuntimeError,
"cannot get source range for location without Ruby bytecode");
595 int node_id = location_node_id(backtrace_location);
597 rb_raise(
rb_eRuntimeError,
"cannot get source range for location without a node ID");
599 if (!ISEQ_BODY(iseq)->source_hash) {
600 rb_raise(
rb_eRuntimeError,
"cannot get source range because the source hash is unavailable");
602 uint64_t source_hash = ISEQ_BODY(iseq)->source_hash;
604 VALUE path = rb_iseq_path(iseq);
605 VALUE absolute_path = rb_iseq_realpath(iseq);
606 VALUE script_lines = ISEQ_SCRIPT_LINES(iseq);
608 VALUE parser_path = path;
609 int first_lineno = 1;
611 if (!
NIL_P(script_lines)) {
613 first_lineno = location_source_first_lineno(iseq, script_lines);
615 else if (iseq_from_e_script_p(iseq, path, source_hash)) {
616 source = rb_e_script;
618 else if (!
NIL_P(absolute_path)) {
619 source = location_source_read_file(absolute_path);
620 parser_path = absolute_path;
623 rb_raise(rb_eArgError,
"cannot get source range for location in eval");
626 if (
NIL_P(parser_path)) {
631 if (!ISEQ_BODY(iseq)->prism && !location_source_hash_matches(source, source_hash)) {
635 rb_code_location_t code_location;
638 if (ISEQ_BODY(iseq)->prism) {
639 found = pm_node_source_location(
649 found = rb_ast_node_source_location(
654 ISEQ_BODY(iseq)->
type == ISEQ_TYPE_BLOCK,
655 ISEQ_BODY(iseq)->location.node_id,
661 rb_raise(
rb_eRuntimeError,
"cannot find node ID %d in parsed source", node_id);
664 return rb_source_range_new(path, absolute_path, &code_location);
668rb_get_node_id_from_frame_info(
VALUE obj)
670 rb_backtrace_location_t *loc = location_ptr(obj);
671 return location_node_id(loc);
675rb_get_iseq_from_frame_info(
VALUE obj)
677 rb_backtrace_location_t *loc = location_ptr(obj);
678 const rb_iseq_t *iseq = location_iseq(loc);
683location_realpath(rb_backtrace_location_t *loc)
686 return rb_iseq_realpath(loc->iseq);
698location_absolute_path_m(
VALUE self)
700 return location_realpath(location_ptr(self));
704location_format(
VALUE file,
int lineno,
VALUE name)
708 rb_str_catf(s,
":%d", lineno);
715 rb_str_catf(s,
"'%"PRIsVALUE
"'", name);
722location_to_str(rb_backtrace_location_t *loc)
727 if (location_cfunc_p(loc)) {
728 if (loc->iseq && loc->pc) {
729 file = rb_iseq_path(loc->iseq);
730 lineno = calc_lineno(loc->iseq, loc->pc);
733 file = GET_VM()->progname;
736 name = rb_gen_method_name(location_original_module(loc->cme), rb_id2str(loc->cme->def->original_id));
739 file = rb_iseq_path(loc->iseq);
740 lineno = calc_lineno(loc->iseq, loc->pc);
742 owner = location_original_module(loc->cme);
744 name = calculate_iseq_label(owner, loc->iseq);
747 return location_format(file, lineno, name);
754location_to_str_m(
VALUE self)
756 return location_to_str(location_ptr(self));
764location_inspect_m(
VALUE self)
773 rb_backtrace_location_t backtrace[1];
777backtrace_mark(
void *ptr)
779 rb_backtrace_t *bt = (rb_backtrace_t *)ptr;
780 size_t i, s = bt->backtrace_size;
782 for (i=0; i<s; i++) {
783 location_mark_entry(&bt->backtrace[i]);
785 rb_gc_mark_movable(bt->strary);
786 rb_gc_mark_movable(bt->locary);
790location_update_entry(rb_backtrace_location_t *fi)
792 rb_gc_update_moved_ptr(&fi->cme);
794 rb_gc_update_moved_ptr(&fi->iseq);
799backtrace_update(
void *ptr)
801 rb_backtrace_t *bt = (rb_backtrace_t *)ptr;
802 size_t i, s = bt->backtrace_size;
804 for (i=0; i<s; i++) {
805 location_update_entry(&bt->backtrace[i]);
807 rb_gc_update_moved(&bt->strary);
808 rb_gc_update_moved(&bt->locary);
822 0, 0, RUBY_TYPED_THREAD_SAFE_FREE | RUBY_TYPED_WB_PROTECTED
826rb_backtrace_p(
VALUE obj)
828 return rb_typeddata_is_kind_of(obj, &backtrace_data_type);
832backtrace_alloc_capa(
rb_len_t num_frames, rb_backtrace_t **backtrace)
834 size_t memsize = offsetof(rb_backtrace_t, backtrace) + num_frames *
sizeof(rb_backtrace_location_t);
835 VALUE btobj = rb_data_typed_object_zalloc(rb_cBacktrace, memsize, &backtrace_data_type);
844rb_backtrace_dup(
VALUE btobj)
846 rb_backtrace_t *src, *dst;
849 VALUE dupobj = backtrace_alloc_capa(src->backtrace_size, &dst);
850 dst->backtrace_size = src->backtrace_size;
851 MEMCPY(dst->backtrace, src->backtrace, rb_backtrace_location_t, src->backtrace_size);
852 for (
int i = 0; i < dst->backtrace_size; i++) {
853 const rb_backtrace_location_t *fi = &dst->backtrace[i];
866rb_backtrace_blob_dump(
VALUE btobj,
int *size_out)
871 int size = bt->backtrace_size;
873 rb_backtrace_location_t *blob =
ALLOC_N(rb_backtrace_location_t, size > 0 ? size : 1);
874 MEMCPY(blob, bt->backtrace, rb_backtrace_location_t, size);
879rb_backtrace_blob_load(
const void *blob_,
int size)
881 const rb_backtrace_location_t *blob = blob_;
883 VALUE btobj = backtrace_alloc_capa(size, &dst);
885 dst->backtrace_size = size;
886 MEMCPY(dst->backtrace, blob, rb_backtrace_location_t, size);
887 for (
int i = 0; i < size; i++) {
888 const rb_backtrace_location_t *fi = &dst->backtrace[i];
897rb_backtrace_blob_mark_ctx(
const struct rb_gc_mark_ctx *ctx,
const void *blob_,
int size)
899 const rb_backtrace_location_t *blob = blob_;
900 for (
int i = 0; i < size; i++) {
901 if (blob[i].cme) rb_gc_mark_ctx(ctx, (
VALUE)blob[i].cme);
902 if (blob[i].iseq) rb_gc_mark_ctx(ctx, (
VALUE)blob[i].iseq);
907backtrace_size(
const rb_execution_context_t *ec)
909 const rb_control_frame_t *last_cfp = ec->cfp;
910 const rb_control_frame_t *start_cfp = RUBY_VM_END_CONTROL_FRAME(ec);
912 if (start_cfp == NULL) {
917 RUBY_VM_NEXT_CONTROL_FRAME(
918 RUBY_VM_NEXT_CONTROL_FRAME(start_cfp));
920 if (start_cfp < last_cfp) {
924 return start_cfp - last_cfp + 1;
928is_rescue_or_ensure_frame(
const rb_control_frame_t *cfp)
930 enum rb_iseq_type
type = ISEQ_BODY(CFP_ISEQ(cfp))->type;
931 return type == ISEQ_TYPE_RESCUE ||
type == ISEQ_TYPE_ENSURE;
935bt_backpatch_loc(
unsigned long backpatch_counter, rb_backtrace_location_t *loc,
const rb_iseq_t *iseq,
const VALUE *pc)
937 for (; backpatch_counter > 0; backpatch_counter--, loc--) {
943static VALUE location_create(rb_backtrace_location_t *srcloc,
void *btobj);
946bt_yield_loc(rb_backtrace_location_t *loc,
long num_frames,
VALUE btobj)
948 for (; num_frames > 0; num_frames--, loc++) {
949 rb_yield(location_create(loc, (
void *)btobj));
954rb_ec_partial_backtrace_object(
const rb_execution_context_t *ec,
rb_len_t start_frame,
rb_len_t num_frames,
int* start_too_large,
bool skip_internal,
bool do_yield)
956 const rb_control_frame_t *cfp = ec->cfp;
957 const rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(ec);
959 rb_backtrace_t *bt = NULL;
961 rb_backtrace_location_t *loc = NULL;
962 unsigned long backpatch_counter = 0;
963 bool skip_next_frame = FALSE;
966 if (end_cfp == NULL) {
970 end_cfp = RUBY_VM_NEXT_CONTROL_FRAME(end_cfp);
982 size = end_cfp - cfp + 1;
986 else if (num_frames < 0 || num_frames > size) {
991 btobj = backtrace_alloc_capa(num_frames, &bt);
993 bt->backtrace_size = 0;
994 if (num_frames == 0) {
995 if (start_too_large) *start_too_large = 0;
999 for (; cfp != end_cfp && (bt->backtrace_size < num_frames); cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)) {
1000 if (CFP_ISEQ(cfp)) {
1002 if (start_frame > 0) {
1006 bool internal = is_internal_location(CFP_ISEQ(cfp));
1007 if (skip_internal && internal)
continue;
1008 if (!skip_next_frame) {
1009 const rb_iseq_t *iseq = CFP_ISEQ(cfp);
1010 const VALUE *pc = CFP_PC(cfp);
1011 if (internal && backpatch_counter > 0) {
1013 bt->backtrace_size -= backpatch_counter;
1014 backpatch_counter = 0;
1016 loc = &bt->backtrace[bt->backtrace_size++];
1017 RB_OBJ_WRITE(btobj, &loc->cme, rb_vm_frame_method_entry(cfp));
1025 backpatch_counter++;
1029 if ((VM_FRAME_TYPE(cfp) & VM_FRAME_MAGIC_MASK) == VM_FRAME_MAGIC_DUMMY) {
1035 bt_backpatch_loc(backpatch_counter, loc-1, iseq, pc);
1037 bt_yield_loc(loc - backpatch_counter, backpatch_counter+1, btobj);
1039 backpatch_counter = 0;
1042 skip_next_frame = is_rescue_or_ensure_frame(cfp);
1047 VM_ASSERT(RUBYVM_CFUNC_FRAME_P(cfp));
1048 if (start_frame > 0) {
1052 loc = &bt->backtrace[bt->backtrace_size++];
1053 RB_OBJ_WRITE(btobj, &loc->cme, rb_vm_frame_method_entry(cfp));
1056 backpatch_counter++;
1063 if (backpatch_counter > 0) {
1064 for (; cfp != end_cfp; cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)) {
1065 if (CFP_ISEQ(cfp) && CFP_PC(cfp) && !(skip_internal && is_internal_location(CFP_ISEQ(cfp)))) {
1066 VM_ASSERT(!skip_next_frame);
1067 bt_backpatch_loc(backpatch_counter, loc, CFP_ISEQ(cfp), CFP_PC(cfp));
1070 bt_yield_loc(loc - backpatch_counter + 1, backpatch_counter, btobj);
1077 if (start_too_large) *start_too_large = (start_frame > 0 ? -1 : 0);
1082rb_ec_backtrace_object(
const rb_execution_context_t *ec)
1084 return rb_ec_partial_backtrace_object(ec, RUBY_BACKTRACE_START, RUBY_ALL_BACKTRACE_LINES, NULL, FALSE, FALSE);
1088backtrace_collect(rb_backtrace_t *bt,
VALUE (*func)(rb_backtrace_location_t *,
void *arg),
void *arg)
1095 for (i=0; i<bt->backtrace_size; i++) {
1096 rb_backtrace_location_t *loc = &bt->backtrace[i];
1104location_to_str_dmyarg(rb_backtrace_location_t *loc,
void *dmy)
1106 return location_to_str(loc);
1110backtrace_to_str_ary(
VALUE self)
1115 r = backtrace_collect(bt, location_to_str_dmyarg, 0);
1121rb_backtrace_to_str_ary(
VALUE self)
1127 RB_OBJ_WRITE(self, &bt->strary, backtrace_to_str_ary(self));
1133location_create(rb_backtrace_location_t *srcloc,
void *btobj)
1146backtrace_to_location_ary(
VALUE self)
1151 r = backtrace_collect(bt, location_create, (
void *)self);
1157rb_backtrace_to_location_ary(
VALUE self)
1163 RB_OBJ_WRITE(self, &bt->locary, backtrace_to_location_ary(self));
1169rb_location_ary_to_backtrace(
VALUE ary)
1175 rb_backtrace_t *new_backtrace;
1177 VALUE btobj = backtrace_alloc_capa(num_frames, &new_backtrace);
1182 if (!rb_frame_info_p(locobj)) {
1189 rb_backtrace_location_t *dst_location = &new_backtrace->backtrace[index];
1190 RB_OBJ_WRITE(btobj, &dst_location->cme, src_vloc->loc->cme);
1191 RB_OBJ_WRITE(btobj, &dst_location->iseq, src_vloc->loc->iseq);
1192 dst_location->pc = src_vloc->loc->pc;
1194 new_backtrace->backtrace_size++;
1203backtrace_dump_data(
VALUE self)
1205 VALUE str = rb_backtrace_to_str_ary(self);
1269backtrace_limit(
VALUE self)
1271 return LONG2NUM(rb_backtrace_length_limit);
1276backtrace_clone(
VALUE self)
1281 rb_backtrace_t *other_bt;
1282 VALUE clone = backtrace_alloc_capa(bt->backtrace_size, &other_bt);
1284 rb_obj_clone_setup(self, clone,
Qfalse);
1291backtrace_dup(
VALUE self)
1300backtrace_initialize_copy(
VALUE self,
VALUE original)
1305 rb_backtrace_t *original_bt;
1308 bt->backtrace_size = original_bt->backtrace_size;
1309 MEMCPY(bt->backtrace, original_bt->backtrace, rb_backtrace_location_t, original_bt->backtrace_size);
1310 rb_gc_writebarrier_remember(self);
1316rb_ec_backtrace_str_ary(
const rb_execution_context_t *ec,
long lev,
long n)
1318 return rb_backtrace_to_str_ary(rb_ec_partial_backtrace_object(ec, lev, n, NULL, FALSE, FALSE));
1322rb_ec_backtrace_location_ary(
const rb_execution_context_t *ec,
long lev,
long n,
bool skip_internal)
1324 return rb_backtrace_to_location_ary(rb_ec_partial_backtrace_object(ec, lev, n, NULL, skip_internal, FALSE));
1330backtrace_each(
const rb_execution_context_t *ec,
1331 void (*init)(
void *arg,
size_t size),
1332 void (*iter_iseq)(
void *arg,
const rb_control_frame_t *cfp),
1333 void (*iter_cfunc)(
void *arg,
const rb_control_frame_t *cfp,
ID mid),
1336 const rb_control_frame_t *last_cfp = ec->cfp;
1337 const rb_control_frame_t *start_cfp = RUBY_VM_END_CONTROL_FRAME(ec);
1338 const rb_control_frame_t *cfp;
1342 if (start_cfp == NULL) {
1358 RUBY_VM_NEXT_CONTROL_FRAME(
1359 RUBY_VM_NEXT_CONTROL_FRAME(start_cfp));
1361 if (start_cfp < last_cfp) {
1365 size = start_cfp - last_cfp + 1;
1371 for (i=0, cfp = start_cfp; i<size; i++, cfp = RUBY_VM_NEXT_CONTROL_FRAME(cfp)) {
1373 if (CFP_ISEQ(cfp)) {
1375 iter_iseq(arg, cfp);
1379 VM_ASSERT(RUBYVM_CFUNC_FRAME_P(cfp));
1380 const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp);
1381 ID mid = me->def->original_id;
1383 iter_cfunc(arg, cfp, mid);
1391 void (*func)(
void *data,
VALUE file,
int lineno,
VALUE name);
1396oldbt_init(
void *ptr,
size_t dmy)
1399 arg->filename = GET_VM()->progname;
1404oldbt_iter_iseq(
void *ptr,
const rb_control_frame_t *cfp)
1406 const rb_iseq_t *iseq = CFP_ISEQ(cfp);
1407 const VALUE *pc = CFP_PC(cfp);
1409 VALUE file = arg->filename = rb_iseq_path(iseq);
1410 VALUE name = ISEQ_BODY(iseq)->location.label;
1411 int lineno = arg->lineno = calc_lineno(iseq, pc);
1413 (arg->func)(arg->data, file, lineno, name);
1417oldbt_iter_cfunc(
void *ptr,
const rb_control_frame_t *cfp,
ID mid)
1420 VALUE file = arg->filename;
1421 VALUE name = rb_id2str(mid);
1422 int lineno = arg->lineno;
1424 (arg->func)(arg->data, file, lineno, name);
1428oldbt_print(
void *data,
VALUE file,
int lineno,
VALUE name)
1430 FILE *fp = (FILE *)data;
1433 fprintf(fp,
"\tfrom %.*s:%d:in unknown method\n",
1437 fprintf(fp,
"\tfrom %.*s:%d:in '%.*s'\n",
1444vm_backtrace_print(FILE *fp)
1448 arg.func = oldbt_print;
1449 arg.data = (
void *)fp;
1450 backtrace_each(GET_EC(),
1463oldbt_bugreport(
void *arg,
VALUE file,
int line,
VALUE method)
1467 const char *filename =
NIL_P(file) ?
"ruby" : RSTRING_PTR(file);
1470 fprintf(fp,
"-- Ruby level backtrace information "
1471 "----------------------------------------\n");
1474 if (
NIL_P(method)) {
1475 fprintf(fp,
"%.*s:%d:in unknown method\n",
1476 filename_len, filename, line);
1479 fprintf(fp,
"%.*s:%d:in '%.*s'\n",
1480 filename_len, filename, line,
1486rb_backtrace_print_as_bugreport(FILE *fp)
1491 arg.func = oldbt_bugreport;
1494 backtrace_each(GET_EC(),
1504 vm_backtrace_print(stderr);
1513oldbt_print_to(
void *data,
VALUE file,
int lineno,
VALUE name)
1516 VALUE str = rb_sprintf(
"\tfrom %"PRIsVALUE
":%d:in ", file, lineno);
1522 rb_str_catf(str,
" '%"PRIsVALUE
"'\n", name);
1524 (*arg->iter)(arg->output, str);
1534 parg.output = output;
1535 arg.func = oldbt_print_to;
1537 backtrace_each(GET_EC(),
1547 return rb_ec_backtrace_str_ary(GET_EC(), RUBY_BACKTRACE_START, RUBY_ALL_BACKTRACE_LINES);
1551ec_backtrace_range(
const rb_execution_context_t *ec,
int argc,
const VALUE *argv,
int lev_default,
int lev_plus,
rb_len_t *len_ptr)
1553 VALUE level, vn, opts;
1561 if (argc == 2 &&
NIL_P(vn)) argc--;
1565 lev = lev_default + lev_plus;
1566 n = RUBY_ALL_BACKTRACE_LINES;
1575 rb_raise(rb_eArgError,
"negative level (%"PRIdLEN
")", lev);
1578 n = RUBY_ALL_BACKTRACE_LINES;
1583 lev = beg + lev_plus;
1593 rb_raise(rb_eArgError,
"negative level (%"PRIdLEN
")", lev);
1596 rb_raise(rb_eArgError,
"negative size (%"PRIdLEN
")", n);
1610ec_backtrace_to_ary(
const rb_execution_context_t *ec,
int argc,
const VALUE *argv,
int lev_default,
int lev_plus,
int to_str)
1616 lev = ec_backtrace_range(ec, argc, argv, lev_default, lev_plus, &n);
1617 if (lev < 0)
return Qnil;
1623 btval = rb_ec_partial_backtrace_object(ec, lev, n, &too_large, FALSE, FALSE);
1630 r = backtrace_to_str_ary(btval);
1633 r = backtrace_to_location_ary(btval);
1640thread_backtrace_to_ary(
int argc,
const VALUE *argv,
VALUE thval,
int to_str)
1642 rb_thread_t *target_th = rb_thread_ptr(thval);
1644 if (target_th->to_kill || target_th->status == THREAD_KILLED)
1647 return ec_backtrace_to_ary(target_th->ec, argc, argv, 0, 0, to_str);
1651rb_vm_thread_backtrace(
int argc,
const VALUE *argv,
VALUE thval)
1653 return thread_backtrace_to_ary(argc, argv, thval, 1);
1657rb_vm_thread_backtrace_locations(
int argc,
const VALUE *argv,
VALUE thval)
1659 return thread_backtrace_to_ary(argc, argv, thval, 0);
1665 return ec_backtrace_to_ary(ec, argc, argv, 0, 0, 1);
1671 return ec_backtrace_to_ary(ec, argc, argv, 0, 0, 0);
1715 return ec_backtrace_to_ary(GET_EC(), argc, argv, 1, 1, 1);
1741rb_f_caller_locations(
int argc,
VALUE *argv,
VALUE _)
1743 return ec_backtrace_to_ary(GET_EC(), argc, argv, 1, 1, 0);
1754each_caller_location(
int argc,
VALUE *argv,
VALUE _)
1756 rb_execution_context_t *ec = GET_EC();
1757 rb_len_t n, lev = ec_backtrace_range(ec, argc, argv, 1, 1, &n);
1758 if (lev >= 0 && n != 0) {
1759 rb_ec_partial_backtrace_object(ec, lev, n, NULL, FALSE, TRUE);
1765backtrace_no_allocator(
VALUE klass)
1774Init_vm_backtrace(
void)
1792 rb_define_method(rb_cBacktrace,
"initialize_copy", backtrace_initialize_copy, 1);
1841 rb_cBacktraceLocation = rb_define_class_under(rb_cBacktrace,
"Location",
rb_cObject);
1846 rb_define_method(rb_cBacktraceLocation,
"base_label", location_base_label_m, 0);
1848 rb_define_method(rb_cBacktraceLocation,
"absolute_path", location_absolute_path_m, 0);
1849 rb_define_method(rb_cBacktraceLocation,
"source_range", location_source_range_m, 0);
1861RUBY_SYMBOL_EXPORT_BEGIN
1863RUBY_SYMBOL_EXPORT_END
1866 rb_execution_context_t *ec;
1867 rb_control_frame_t *cfp;
1869 VALUE raw_backtrace;
1873 CALLER_BINDING_SELF,
1874 CALLER_BINDING_CLASS,
1875 CALLER_BINDING_BINDING,
1876 CALLER_BINDING_ISEQ,
1879 CALLER_BINDING_DEPTH,
1884 const rb_execution_context_t *ec;
1890collect_caller_bindings_init(
void *arg,
size_t num_frames)
1893 data->btobj = backtrace_alloc_capa(num_frames, &data->bt);
1897get_klass(
const rb_control_frame_t *cfp)
1900 if (rb_vm_control_frame_id_and_class(cfp, 0, 0, &klass)) {
1902 return RBASIC(klass)->klass;
1914frame_depth(
const rb_execution_context_t *ec,
const rb_control_frame_t *cfp)
1916 VM_ASSERT(RUBY_VM_END_CONTROL_FRAME(ec) >= cfp);
1917 return (
int)(RUBY_VM_END_CONTROL_FRAME(ec) - cfp);
1921collect_caller_bindings_iseq(
void *arg,
const rb_control_frame_t *cfp)
1925 const rb_iseq_t *iseq = CFP_ISEQ(cfp);
1928 rb_ary_store(frame, CALLER_BINDING_CLASS, get_klass(cfp));
1929 rb_ary_store(frame, CALLER_BINDING_BINDING, GC_GUARDED_PTR(cfp));
1931 rb_ary_store(frame, CALLER_BINDING_CFP, GC_GUARDED_PTR(cfp));
1933 rb_backtrace_location_t *loc = &data->bt->backtrace[data->bt->backtrace_size++];
1934 RB_OBJ_WRITE(data->btobj, &loc->cme, rb_vm_frame_method_entry(cfp));
1936 loc->pc = CFP_PC(cfp);
1937 VALUE vloc = location_create(loc, (
void *)data->btobj);
1946collect_caller_bindings_cfunc(
void *arg,
const rb_control_frame_t *cfp,
ID mid)
1952 rb_ary_store(frame, CALLER_BINDING_CLASS, get_klass(cfp));
1955 rb_ary_store(frame, CALLER_BINDING_CFP, GC_GUARDED_PTR(cfp));
1957 rb_backtrace_location_t *loc = &data->bt->backtrace[data->bt->backtrace_size++];
1958 RB_OBJ_WRITE(data->btobj, &loc->cme, rb_vm_frame_method_entry(cfp));
1961 VALUE vloc = location_create(loc, (
void *)data->btobj);
1970collect_caller_bindings(
const rb_execution_context_t *ec)
1979 collect_caller_bindings_init,
1980 collect_caller_bindings_iseq,
1981 collect_caller_bindings_cfunc,
1991 if (!
NIL_P(cfp_val)) {
1992 rb_control_frame_t *cfp = GC_GUARDED_PTR_REF(cfp_val);
1993 rb_ary_store(entry, CALLER_BINDING_BINDING, rb_vm_make_binding(ec, cfp));
2009 rb_execution_context_t *ec = GET_EC();
2010 enum ruby_tag_type state;
2011 volatile VALUE MAYBE_UNUSED(result);
2015 rb_vm_stack_to_heap(ec);
2017 dbg_context.ec = ec;
2018 dbg_context.cfp = dbg_context.ec->cfp;
2019 dbg_context.contexts = collect_caller_bindings(ec);
2021 for (i=0; i<
RARRAY_LEN(dbg_context.contexts); i++) {
2027 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
2028 result = (*func)(&dbg_context, data);
2035 EC_JUMP_TAG(ec, state);
2044 if (index < 0 || index >=
RARRAY_LEN(dc->contexts)) {
2045 rb_raise(rb_eArgError,
"no such frame");
2053 VALUE frame = frame_get(dc, index);
2060 VALUE frame = frame_get(dc, index);
2067 VALUE frame = frame_get(dc, index);
2074 VALUE frame = frame_get(dc, index);
2077 return RTEST(iseq) ? rb_iseqw_new((rb_iseq_t *)iseq) :
Qnil;
2083 VALUE frame = frame_get(dc, index);
2090 rb_execution_context_t *ec = GET_EC();
2091 return INT2FIX(frame_depth(ec, ec->cfp));
2097 return dc->raw_backtrace;
2101thread_profile_frames(rb_execution_context_t *ec,
int start,
int limit,
VALUE *buff,
int *lines)
2104 const rb_control_frame_t *cfp = ec->cfp, *end_cfp = RUBY_VM_END_CONTROL_FRAME(ec);
2105 const rb_control_frame_t *top = cfp;
2106 const rb_callable_method_entry_t *cme;
2118 end_cfp = RUBY_VM_NEXT_CONTROL_FRAME(end_cfp);
2120 for (i=0; i<limit && cfp != end_cfp; cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)) {
2121 if (VM_FRAME_RUBYFRAME_P_UNCHECKED(cfp) && CFP_PC(cfp)) {
2128 cme = rb_vm_frame_method_entry_unchecked(cfp);
2129 const rb_iseq_t *iseq = CFP_ISEQ(cfp);
2130 if (cme && cme->def->type == VM_METHOD_TYPE_ISEQ) {
2131 buff[i] = (
VALUE)cme;
2134 buff[i] = (
VALUE)iseq;
2138 const VALUE *pc = CFP_PC(cfp);
2139 VALUE *iseq_encoded = ISEQ_BODY(iseq)->iseq_encoded;
2140 VALUE *pc_end = iseq_encoded + ISEQ_BODY(iseq)->iseq_size;
2147 if (cfp == top && (pc < iseq_encoded || pc > pc_end)) {
2151 lines[i] = calc_lineno(iseq, pc);
2158 cme = rb_vm_frame_method_entry_unchecked(cfp);
2159 if (cme && cme->def->type == VM_METHOD_TYPE_CFUNC) {
2164 buff[i] = (
VALUE)cme;
2165 if (lines) lines[i] = 0;
2177 rb_execution_context_t *ec = rb_current_execution_context(
false);
2185 return thread_profile_frames(ec, start, limit, buff, lines);
2191 rb_thread_t *th = rb_thread_ptr(thread);
2192 return thread_profile_frames(th->ec, start, limit, buff, lines);
2195static const rb_iseq_t *
2196frame2iseq(
VALUE frame)
2198 if (
NIL_P(frame))
return NULL;
2201 switch (imemo_type(frame)) {
2203 return (
const rb_iseq_t *)frame;
2206 const rb_callable_method_entry_t *cme = (rb_callable_method_entry_t *)frame;
2207 switch (cme->def->type) {
2208 case VM_METHOD_TYPE_ISEQ:
2209 return cme->def->body.iseq.
iseqptr;
2218 rb_bug(
"frame2iseq: unreachable");
2224 const rb_iseq_t *iseq = frame2iseq(frame);
2225 return iseq ? rb_iseq_path(iseq) :
Qnil;
2228static const rb_callable_method_entry_t *
2231 if (
NIL_P(frame))
return NULL;
2234 switch (imemo_type(frame)) {
2237 const rb_callable_method_entry_t *cme = (rb_callable_method_entry_t *)frame;
2238 switch (cme->def->type) {
2239 case VM_METHOD_TYPE_CFUNC:
2256 if (cframe(frame)) {
2260 rb_vm_register_global_object(cfunc_str);
2264 const rb_iseq_t *iseq = frame2iseq(frame);
2265 return iseq ? rb_iseq_realpath(iseq) :
Qnil;
2271 const rb_iseq_t *iseq = frame2iseq(frame);
2272 return iseq ? rb_iseq_label(iseq) :
Qnil;
2278 const rb_iseq_t *iseq = frame2iseq(frame);
2279 return iseq ? rb_iseq_base_label(iseq) :
Qnil;
2285 const rb_iseq_t *iseq = frame2iseq(frame);
2286 return iseq ? rb_iseq_first_lineno(iseq) :
Qnil;
2290frame2klass(
VALUE frame)
2295 const rb_callable_method_entry_t *cme = (rb_callable_method_entry_t *)frame;
2297 if (imemo_type(frame) == imemo_ment) {
2298 return cme->defined_class;
2307 VALUE klass = frame2klass(frame);
2309 if (klass && !
NIL_P(klass)) {
2311 klass =
RBASIC(klass)->klass;
2313 else if (RCLASS_SINGLETON_P(klass)) {
2314 klass = RCLASS_ATTACHED_OBJECT(klass);
2328 VALUE klass = frame2klass(frame);
2330 return RBOOL(klass && !
NIL_P(klass) && RCLASS_SINGLETON_P(klass));
2336 const rb_callable_method_entry_t *cme = cframe(frame);
2338 ID mid = cme->def->original_id;
2341 const rb_iseq_t *iseq = frame2iseq(frame);
2342 return iseq ? rb_iseq_method_name(iseq) :
Qnil;
2346qualified_method_name(
VALUE frame,
VALUE method_name)
2348 if (method_name !=
Qnil) {
2352 if (classpath !=
Qnil) {
2353 return rb_sprintf(
"%"PRIsVALUE
"%s%"PRIsVALUE,
2354 classpath, singleton_p ==
Qtrue ?
"." :
"#", method_name);
2370 return qualified_method_name(frame, method_name);
2376 const rb_callable_method_entry_t *cme = cframe(frame);
2378 ID mid = cme->def->original_id;
2379 VALUE method_name = id2str(mid);
2380 return qualified_method_name(frame, method_name);
2387 if (
NIL_P(qualified_method_name) || base_label == qualified_method_name) {
2391 rb_len_t label_length = RSTRING_LEN(label);
2392 rb_len_t base_label_length = RSTRING_LEN(base_label);
2393 int prefix_len =
rb_len2int(label_length - base_label_length);
2395 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_debug_inspector_frame_binding_get(const rb_debug_inspector_t *dc, rb_len_t index)
Queries the binding of the passed context's upper frame.
VALUE rb_profile_frame_full_label(VALUE frame)
Identical to rb_profile_frame_label(), except it returns a qualified result.
struct rb_debug_inspector_struct rb_debug_inspector_t
Opaque struct representing a debug inspector.
VALUE rb_debug_inspector_current_depth(void)
Return current frame depth.
VALUE rb_debug_inspector_frame_depth(const rb_debug_inspector_t *dc, rb_len_t index)
Queries the depth of the passed context's upper frame.
VALUE rb_profile_frame_method_name(VALUE frame)
Queries the name of the method of the passed 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_class_get(const rb_debug_inspector_t *dc, rb_len_t index)
Queries the current class of the passed context's upper frame.
VALUE rb_debug_inspector_frame_iseq_get(const rb_debug_inspector_t *dc, rb_len_t index)
Queries the instruction sequence 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.
VALUE rb_debug_inspector_frame_self_get(const rb_debug_inspector_t *dc, rb_len_t index)
Queries the current receiver of the passed context's upper frame.
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.
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 T_STRING
Old name of RUBY_T_STRING.
#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 UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#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 ALLOC_N
Old name of RB_ALLOC_N.
#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 NUM2LEN
Old name of RB_NUM2LEN.
#define rb_ary_new2
Old name of rb_ary_new_capa.
#define rb_notimplement()
VALUE rb_eRuntimeError
RuntimeError exception.
VALUE rb_cArray
Array class.
VALUE rb_cObject
Object 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_entry(VALUE ary, rb_len_t off)
Queries an element of an array.
void rb_ary_store(VALUE ary, rb_len_t key, VALUE val)
Destructively stores the passed value to the passed array's passed index.
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_join(VALUE ary, VALUE sep)
Recursively stringises the elements of the passed array, flattens that result, then joins the sequenc...
Public APIs related to rb_cIO.
VALUE rb_io_gets(VALUE io)
Reads a "line" from the given IO.
VALUE rb_file_open_str(VALUE fname, const char *fmode)
Identical to rb_file_open(), except it takes the pathname as a Ruby's string instead of C's.
VALUE rb_io_close(VALUE io)
Closes the IO.
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
Marshal format compatibility layer.
VALUE rb_range_beg_len(VALUE range, rb_len_t *begp, rb_len_t *lenp, rb_len_t len, int err)
Deconstructs a numerical range.
#define rb_str_new_literal(str)
Just another name of rb_str_new_lit.
VALUE rb_str_buf_append(VALUE dst, VALUE src)
Identical to rb_str_cat_cstr(), except it takes Ruby's string instead of C's.
VALUE rb_str_inspect(VALUE str)
Generates a "readable" version of the receiver.
VALUE rb_str_buf_new(rb_len_t capa)
Allocates a "string buffer".
#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.
#define rb_str_new_cstr(str)
Identical to rb_str_new, 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.
VALUE rb_make_backtrace(void)
Creates the good old fashioned array-of-strings style backtrace info.
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_len2int
Just another name of rb_len2int_inline.
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE type(ANYARGS)
ANYARGS-ed function type.
VALUE rb_ensure(type *q, VALUE w, type *e, VALUE r)
An equivalent of ensure clause.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
References an object in an array.
#define RBASIC(obj)
Convenient casting macro.
#define RUBY_DEFAULT_FREE
This is a value you can set to RData::dfree.
#define StringValue(v)
Ensures that the parameter object is a String.
static int RSTRING_LENINT(VALUE str)
Identical to RSTRING_LEN(), except it differs for the return type.
#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.
struct rb_data_type_struct rb_data_type_t
This is the struct that holds necessary info for a struct.
#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.
const rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
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.