24 #include "eval_intern.h"
26 #include "internal/hash.h"
27 #include "internal/symbol.h"
40 rb_event_hook_flag_t hook_flags;
48 unsigned int target_line;
54 #define MAX_EVENT_NUM 32
72 hooks->need_clean =
true;
74 if (hooks->running == 0) {
75 clean_hooks(GET_EC(), hooks);
81 void rb_clear_attr_ccs(
void);
87 rb_event_flag_t enabled_iseq_events = ruby_vm_event_enabled_global_flags & ISEQ_TRACE_EVENTS;
89 if (new_iseq_events & ~enabled_iseq_events) {
94 mjit_cancel_all(
"TracePoint is enabled");
98 rb_iseq_trace_set_all(new_iseq_events | enabled_iseq_events);
108 ruby_vm_event_flags = new_events;
109 ruby_vm_event_enabled_global_flags |= new_events;
110 rb_objspace_set_event_hook(new_events);
116 rb_yjit_tracing_invalidate_all();
132 hook->hook_flags = hook_flags;
133 hook->events = events;
138 hook->filter.th = NULL;
139 hook->filter.target_line = 0;
148 hook->next = list->hooks;
150 list->events |= hook->events;
154 update_global_event_hook(prev_events, list->events);
165 hook_list_connect(
Qundef, list, hook, TRUE);
172 rb_event_hook_t *hook = alloc_event_hook(func, events, data, hook_flags);
173 hook->filter.th = th;
174 connect_event_hook(ec, hook);
180 rb_threadptr_add_event_hook(GET_EC(), rb_thread_ptr(thval), func, events, data, RUBY_EVENT_HOOK_FLAG_SAFE);
186 rb_add_event_hook2(func, events, data, RUBY_EVENT_HOOK_FLAG_SAFE);
192 rb_threadptr_add_event_hook(GET_EC(), rb_thread_ptr(thval), func, events, data, hook_flags);
198 rb_event_hook_t *hook = alloc_event_hook(func, events, data, hook_flags);
199 connect_event_hook(GET_EC(), hook);
208 VM_ASSERT(list->running == 0);
209 VM_ASSERT(list->need_clean ==
true);
212 list->need_clean =
false;
214 while ((hook = *nextp) != 0) {
215 if (hook->hook_flags & RUBY_EVENT_HOOK_FLAG_DELETED) {
220 list->events |= hook->events;
225 if (list->is_local) {
226 if (list->events == 0) {
232 update_global_event_hook(prev_events, list->events);
239 if (UNLIKELY(list->need_clean)) {
240 if (list->running == 0) {
241 clean_hooks(ec, list);
246 #define MATCH_ANY_FILTER_TH ((rb_thread_t *)1)
257 if (func == 0 || hook->func == func) {
258 if (hook->filter.th == filter_th || filter_th == MATCH_ANY_FILTER_TH) {
259 if (data ==
Qundef || hook->data == data) {
260 hook->hook_flags |= RUBY_EVENT_HOOK_FLAG_DELETED;
262 list->need_clean =
true;
269 clean_hooks_check(ec, list);
276 return remove_event_hook(ec, filter_th, func, data);
282 return rb_threadptr_remove_event_hook(GET_EC(), rb_thread_ptr(thval), func,
Qundef);
288 return rb_threadptr_remove_event_hook(GET_EC(), rb_thread_ptr(thval), func, data);
294 return remove_event_hook(GET_EC(), NULL, func,
Qundef);
300 return remove_event_hook(GET_EC(), NULL, func, data);
306 rb_threadptr_remove_event_hook(ec, rb_ec_thread_ptr(ec), 0,
Qundef);
312 rb_threadptr_remove_event_hook(ec, MATCH_ANY_FILTER_TH, 0,
Qundef);
322 for (hook = list->hooks; hook; hook = hook->next) {
323 if (!(hook->hook_flags & RUBY_EVENT_HOOK_FLAG_DELETED) &&
324 (trace_arg->event & hook->events) &&
325 (LIKELY(hook->filter.th == 0) || hook->filter.th == rb_ec_thread_ptr(ec)) &&
326 (LIKELY(hook->filter.target_line == 0) || (hook->filter.target_line == (
unsigned int)rb_vm_get_sourceline(ec->cfp)))) {
327 if (!(hook->hook_flags & RUBY_EVENT_HOOK_FLAG_RAW_ARG)) {
328 (*hook->func)(trace_arg->event, hook->data, trace_arg->self, trace_arg->id, trace_arg->klass);
331 (*((rb_event_hook_raw_arg_func_t)hook->func))(hook->data, trace_arg);
340 if (list->events & trace_arg->event) {
353 clean_hooks_check(ec, list);
359 if (exec_hooks_precheck(ec, list, trace_arg) == 0)
return;
360 exec_hooks_body(ec, list, trace_arg);
361 exec_hooks_postcheck(ec, list);
367 enum ruby_tag_type state;
370 if (exec_hooks_precheck(ec, list, trace_arg) == 0)
return 0;
372 raised = rb_ec_reset_raised(ec);
377 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
378 exec_hooks_body(ec, list, trace_arg);
382 exec_hooks_postcheck(ec, list);
385 rb_ec_set_raised(ec);
391 MJIT_FUNC_EXPORTED
void
403 ec->trace_arg = trace_arg;
405 exec_hooks_unprotected(ec, rb_ec_ractor_hooks(ec), trace_arg);
406 ec->trace_arg = prev_trace_arg;
410 if (ec->trace_arg == NULL &&
411 trace_arg->self != rb_mRubyVMFrozenCore ) {
412 const VALUE errinfo = ec->errinfo;
413 const VALUE old_recursive = ec->local_storage_recursive_hash;
417 ec->local_storage_recursive_hash = ec->local_storage_recursive_hash_for_trace;
419 ec->trace_arg = trace_arg;
422 if ((state = exec_hooks_protected(ec, hooks, trace_arg)) == TAG_NONE) {
423 ec->errinfo = errinfo;
427 ec->trace_arg = NULL;
428 ec->local_storage_recursive_hash_for_trace = ec->local_storage_recursive_hash;
429 ec->local_storage_recursive_hash = old_recursive;
433 if (VM_FRAME_FINISHED_P(ec->cfp)) {
434 ec->tag = ec->tag->prev;
438 EC_JUMP_TAG(ec, state);
450 rb_vm_t *
const vm = rb_ec_vm_ptr(ec);
451 enum ruby_tag_type state;
453 dummy_trace_arg.event = 0;
455 if (!ec->trace_arg) {
456 ec->trace_arg = &dummy_trace_arg;
459 raised = rb_ec_reset_raised(ec);
462 if (LIKELY((state = EC_EXEC_TAG()) == TAG_NONE)) {
463 result = (*func)(arg);
471 rb_ec_reset_raised(ec);
474 if (ec->trace_arg == &dummy_trace_arg) {
475 ec->trace_arg = NULL;
479 #if defined RUBY_USE_SETJMPEX && RUBY_USE_SETJMPEX
482 EC_JUMP_TAG(ec, state);
579 rb_threadptr_add_event_hook(ec, filter_th, call_trace_func,
RUBY_EVENT_ALL, trace, RUBY_EVENT_HOOK_FLAG_SAFE);
592 thread_add_trace_func_m(
VALUE obj,
VALUE trace)
594 thread_add_trace_func(GET_EC(), rb_thread_ptr(obj), trace);
610 thread_set_trace_func_m(
VALUE target_thread,
VALUE trace)
613 rb_thread_t *target_th = rb_thread_ptr(target_thread);
615 rb_threadptr_remove_event_hook(ec, target_th, call_trace_func,
Qundef);
621 thread_add_trace_func(ec, target_th, trace);
649 #define C(name, NAME) case RUBY_EVENT_##NAME: CONST_ID(id, #name); return id;
656 C(c_return, C_RETURN);
659 C(b_return, B_RETURN);
660 C(thread_begin, THREAD_BEGIN);
661 C(thread_end, THREAD_END);
662 C(fiber_switch, FIBER_SWITCH);
663 C(script_compiled, SCRIPT_COMPILED);
673 cfp = rb_vm_get_ruby_level_next_cfp(ec, cfp);
677 *pathp = rb_iseq_path(iseq);
682 *linep =
FIX2INT(rb_iseq_first_lineno(iseq));
685 *linep = rb_vm_get_sourceline(cfp);
703 get_path_and_lineno(ec, ec->cfp, event, &filename, &line);
706 rb_ec_frame_method_id_and_class(ec, &
id, 0, &klass);
711 klass =
RBASIC(klass)->klass;
723 argv[5] = klass ? klass :
Qnil;
730 static VALUE rb_cTracePoint;
736 VALUE local_target_set;
740 void (*func)(
VALUE tpval,
void *data);
753 if (tp->target_th)
rb_gc_mark(tp->target_th->self);
757 tp_memsize(
const void *ptr)
765 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
769 tp_alloc(
VALUE klass)
776 symbol2event_flag(
VALUE v)
779 VALUE sym = rb_to_symbol_type(v);
785 #define C(name, NAME) CONST_ID(id, #name); if (sym == ID2SYM(id)) return RUBY_EVENT_##NAME
792 C(c_return, C_RETURN);
795 C(b_return, B_RETURN);
796 C(thread_begin, THREAD_BEGIN);
797 C(thread_end, THREAD_END);
798 C(fiber_switch, FIBER_SWITCH);
799 C(script_compiled, SCRIPT_COMPILED);
803 C(a_return, A_RETURN);
820 if (trace_arg == 0) {
829 return get_trace_arg();
835 return trace_arg->event;
841 return ID2SYM(get_event_id(trace_arg->event));
847 if (trace_arg->path ==
Qundef) {
848 get_path_and_lineno(trace_arg->ec, trace_arg->cfp, trace_arg->event, &trace_arg->path, &trace_arg->lineno);
855 fill_path_and_lineno(trace_arg);
856 return INT2FIX(trace_arg->lineno);
861 fill_path_and_lineno(trace_arg);
862 return trace_arg->path;
868 if (!trace_arg->klass_solved) {
869 if (!trace_arg->klass) {
870 rb_vm_control_frame_id_and_class(trace_arg->cfp, &trace_arg->id, &trace_arg->called_id, &trace_arg->klass);
873 if (trace_arg->klass) {
875 trace_arg->klass =
RBASIC(trace_arg->klass)->klass;
879 trace_arg->klass =
Qnil;
882 trace_arg->klass_solved = 1;
889 switch (trace_arg->event) {
894 const rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(trace_arg->ec, trace_arg->cfp);
897 if (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_BLOCK && !VM_FRAME_LAMBDA_P(cfp)) {
900 return rb_iseq_parameters(cfp->iseq, is_proc);
906 fill_id_and_klass(trace_arg);
907 if (trace_arg->klass && trace_arg->id) {
910 me = rb_method_entry_without_refinements(trace_arg->klass, trace_arg->called_id, &iclass);
911 return rb_unnamed_parameters(rb_method_entry_arity(me));
929 fill_id_and_klass(trace_arg);
930 return trace_arg->id ?
ID2SYM(trace_arg->id) :
Qnil;
936 fill_id_and_klass(trace_arg);
937 return trace_arg->called_id ?
ID2SYM(trace_arg->called_id) :
Qnil;
943 fill_id_and_klass(trace_arg);
944 return trace_arg->klass;
951 cfp = rb_vm_get_binding_creatable_next_cfp(trace_arg->ec, trace_arg->cfp);
954 return rb_vm_make_binding(trace_arg->ec, cfp);
964 return trace_arg->self;
976 if (trace_arg->data ==
Qundef) {
977 rb_bug(
"rb_tracearg_return_value: unreachable");
979 return trace_arg->data;
991 if (trace_arg->data ==
Qundef) {
992 rb_bug(
"rb_tracearg_raised_exception: unreachable");
994 return trace_arg->data;
1000 VALUE data = trace_arg->data;
1009 rb_bug(
"rb_tracearg_raised_exception: unreachable");
1011 if (rb_obj_is_iseq(data)) {
1024 VALUE data = trace_arg->data;
1033 rb_bug(
"rb_tracearg_raised_exception: unreachable");
1036 if (rb_obj_is_iseq(data)) {
1037 return rb_iseqw_new((
const rb_iseq_t *)data);
1057 if (trace_arg->data ==
Qundef) {
1058 rb_bug(
"rb_tracearg_object: unreachable");
1060 return trace_arg->data;
1083 return rb_tracearg_parameters(get_trace_arg());
1131 return rb_tracearg_eval_script(get_trace_arg());
1137 return rb_tracearg_instruction_sequence(get_trace_arg());
1146 (*tp->func)(tpval, tp->data);
1149 if (tp->ractor == NULL || tp->ractor == GET_RACTOR()) {
1161 if (tp->local_target_set !=
Qfalse) {
1165 if (tp->target_th) {
1166 rb_thread_add_event_hook2(tp->target_th->self, (
rb_event_hook_func_t)tp_call_trace, tp->events, tpval,
1167 RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
1171 RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
1178 iseq_of(
VALUE target)
1185 return rb_iseqw_to_iseq(iseqv);
1192 rb_tracepoint_enable_for_target(
VALUE tpval,
VALUE target,
VALUE target_line)
1195 const rb_iseq_t *iseq = iseq_of(target);
1197 unsigned int line = 0;
1198 bool target_bmethod =
false;
1200 if (tp->tracing > 0) {
1204 if (!
NIL_P(target_line)) {
1213 VM_ASSERT(tp->local_target_set ==
Qfalse);
1214 tp->local_target_set =
rb_obj_hide(rb_ident_hash_new());
1219 if (def->type == VM_METHOD_TYPE_BMETHOD &&
1222 rb_hook_list_connect_tracepoint(target, def->body.bmethod.hooks, tpval, 0);
1224 target_bmethod =
true;
1231 n += rb_iseq_add_local_tracepoint_recursively(iseq, tp->events, tpval, line, target_bmethod);
1239 rb_yjit_tracing_invalidate_all();
1241 ruby_vm_event_local_num++;
1252 rb_iseq_remove_local_tracepoint_recursively((
rb_iseq_t *)target, tpval);
1258 VM_ASSERT(hooks != NULL);
1259 rb_hook_list_remove_tracepoint(hooks, tpval);
1261 if (hooks->events == 0) {
1262 rb_hook_list_free(def->body.bmethod.hooks);
1263 def->body.bmethod.hooks = NULL;
1276 if (tp->local_target_set) {
1277 rb_hash_foreach(tp->local_target_set, disable_local_event_iseq_i, tpval);
1278 tp->local_target_set =
Qfalse;
1279 ruby_vm_event_local_num--;
1282 if (tp->target_th) {
1290 tp->target_th = NULL;
1299 RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
1300 hook->filter.target_line = target_line;
1301 hook_list_connect(target, list, hook, FALSE);
1311 if (hook->data == tpval) {
1312 hook->hook_flags |= RUBY_EVENT_HOOK_FLAG_DELETED;
1313 list->need_clean =
true;
1315 else if ((hook->hook_flags & RUBY_EVENT_HOOK_FLAG_DELETED) == 0) {
1316 events |= hook->events;
1321 list->events = events;
1328 int previous_tracing = tp->tracing;
1331 if (
RTEST(target_thread)) {
1332 if (tp->target_th) {
1335 tp->target_th = rb_thread_ptr(target_thread);
1338 tp->target_th = NULL;
1341 if (
NIL_P(target)) {
1342 if (!
NIL_P(target_line)) {
1348 rb_tracepoint_enable_for_target(tpval, target, target_line);
1357 return RBOOL(previous_tracing);
1365 int previous_tracing = tp->tracing;
1368 if (tp->local_target_set !=
Qfalse) {
1379 return RBOOL(previous_tracing);
1387 return RBOOL(tp->tracing);
1399 VALUE tpval = tp_alloc(klass);
1407 tp->events = events;
1418 if (
RTEST(target_thval)) {
1419 target_th = rb_thread_ptr(target_thval);
1424 return tracepoint_new(rb_cTracePoint, target_th, events, func, data,
Qundef);
1435 for (i=0; i<argc; i++) {
1436 events |= symbol2event_flag(
RARRAY_AREF(args, i));
1447 return tracepoint_new(
self, 0, events, 0, 0,
rb_block_proc());
1453 VALUE trace = tracepoint_new_s(ec,
self, args);
1465 switch (trace_arg->event) {
1471 return rb_sprintf(
"#<TracePoint:%"PRIsVALUE
" %"PRIsVALUE
":%d in `%"PRIsVALUE
"'>",
1481 return rb_sprintf(
"#<TracePoint:%"PRIsVALUE
" `%"PRIsVALUE
"' %"PRIsVALUE
":%d>",
1488 return rb_sprintf(
"#<TracePoint:%"PRIsVALUE
" %"PRIsVALUE
">",
1494 return rb_sprintf(
"#<TracePoint:%"PRIsVALUE
" %"PRIsVALUE
":%d>",
1500 return rb_sprintf(
"#<TracePoint:%s>", tp->tracing ?
"enabled" :
"disabled");
1507 int active = 0, deleted = 0;
1510 if (hook->hook_flags & RUBY_EVENT_HOOK_FLAG_DELETED) {
1528 tracepoint_stat_event_hooks(stat, vm->self, rb_ec_ractor_hooks(ec)->hooks);
1535 disallow_reentry(
VALUE val)
1539 if (ec->trace_arg != NULL)
rb_bug(
"should be NULL, but %p", (
void *)ec->trace_arg);
1540 ec->trace_arg = arg;
1549 ec->trace_arg = NULL;
1553 #include "trace_point.rbinc"
1573 #define MAX_POSTPONED_JOB 1000
1574 #define MAX_POSTPONED_JOB_SPECIAL_ADDITION 24
1577 struct list_node jnode;
1582 Init_vm_postponed_job(
void)
1586 vm->postponed_job_index = 0;
1590 enum postponed_job_register_result {
1593 PJRR_INTERRUPTED = 2
1597 static enum postponed_job_register_result
1603 if (expected_index >= max)
return PJRR_FULL;
1605 if (ATOMIC_CAS(vm->postponed_job_index, expected_index, expected_index+1) == expected_index) {
1606 pjob = &vm->postponed_job_buffer[expected_index];
1609 return PJRR_INTERRUPTED;
1616 RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(ec);
1618 return PJRR_SUCCESS;
1625 if (ec == NULL) ec = rb_vm_main_ractor_ec(vm);
1640 switch (postponed_job_register(ec, vm, flags, func, data, MAX_POSTPONED_JOB, vm->postponed_job_index)) {
1641 case PJRR_SUCCESS :
return 1;
1642 case PJRR_FULL :
return 0;
1643 case PJRR_INTERRUPTED:
goto begin;
1644 default:
rb_bug(
"unreachable\n");
1661 index = vm->postponed_job_index;
1662 for (i=0; i<index; i++) {
1663 pjob = &vm->postponed_job_buffer[i];
1664 if (pjob->func == func) {
1665 RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(ec);
1669 switch (postponed_job_register(ec, vm, flags, func, data, MAX_POSTPONED_JOB + MAX_POSTPONED_JOB_SPECIAL_ADDITION, index)) {
1670 case PJRR_SUCCESS :
return 1;
1671 case PJRR_FULL :
return 0;
1672 case PJRR_INTERRUPTED:
goto begin;
1673 default:
rb_bug(
"unreachable\n");
1687 if (!wq_job)
return FALSE;
1688 wq_job->job.func = func;
1689 wq_job->job.data = data;
1692 list_add_tail(&vm->workqueue, &wq_job->jnode);
1696 RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(rb_vm_main_ractor_ec(vm));
1702 rb_postponed_job_flush(
rb_vm_t *vm)
1705 const rb_atomic_t block_mask = POSTPONED_JOB_INTERRUPT_MASK|TRAP_INTERRUPT_MASK;
1706 volatile rb_atomic_t saved_mask = ec->interrupt_mask & block_mask;
1707 VALUE volatile saved_errno = ec->errinfo;
1708 struct list_head tmp;
1710 list_head_init(&tmp);
1713 list_append_list(&tmp, &vm->workqueue);
1718 ec->interrupt_mask |= block_mask;
1721 if (EC_EXEC_TAG() == TAG_NONE) {
1725 while ((index = vm->postponed_job_index) > 0) {
1726 if (ATOMIC_CAS(vm->postponed_job_index, index, index-1) == index) {
1728 (*pjob->func)(pjob->data);
1735 (pjob.func)(pjob.data);
1741 ec->interrupt_mask &= ~(saved_mask ^ block_mask);
1742 ec->errinfo = saved_errno;
1745 if (!list_empty(&tmp)) {
1747 list_prepend_list(&vm->workqueue, &tmp);
1750 RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(GET_EC());
std::atomic< unsigned > rb_atomic_t
Type that is eligible for atomic operations.
VALUE rb_tracearg_binding(rb_trace_arg_t *trace_arg)
Creates a binding object of the point where the trace is at.
VALUE rb_tracepoint_enabled_p(VALUE tpval)
Queries if the passed TracePoint is up and running.
VALUE rb_tracearg_object(rb_trace_arg_t *trace_arg)
Queries the allocated/deallocated object that the trace represents.
VALUE rb_tracearg_callee_id(rb_trace_arg_t *trace_arg)
Identical to rb_tracearg_method_id(), except it returns callee id like rb_frame_callee().
VALUE rb_tracearg_defined_class(rb_trace_arg_t *trace_arg)
Queries the class that defines the method that the passed trace is at.
VALUE rb_tracepoint_new(VALUE target_thread_not_supported_yet, rb_event_flag_t events, void(*func)(VALUE, void *), void *data)
Creates a tracepoint by registering a callback function for one or more tracepoint events.
rb_trace_arg_t * rb_tracearg_from_tracepoint(VALUE tpval)
Queries the current event of the passed tracepoint.
VALUE rb_tracearg_raised_exception(rb_trace_arg_t *trace_arg)
Queries the raised exception that the trace represents.
void rb_thread_add_event_hook(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
Identical to rb_add_event_hook(), except its effect is limited to the passed thread.
VALUE rb_tracepoint_disable(VALUE tpval)
Stops (disables) an already running instance of TracePoint.
VALUE rb_tracearg_self(rb_trace_arg_t *trace_arg)
Queries the receiver of the point trace is at.
int rb_thread_remove_event_hook(VALUE thval, rb_event_hook_func_t func)
Identical to rb_remove_event_hook(), except it additionally takes a thread argument.
int rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data)
Identical to rb_postponed_job_register_one(), except it additionally checks for duplicated registrati...
VALUE rb_tracearg_return_value(rb_trace_arg_t *trace_arg)
Queries the return value that the trace represents.
rb_event_flag_t rb_tracearg_event_flag(rb_trace_arg_t *trace_arg)
Queries the event of the passed trace.
VALUE rb_tracearg_path(rb_trace_arg_t *trace_arg)
Queries the file name of the point where the trace is at.
int rb_thread_remove_event_hook_with_data(VALUE thval, rb_event_hook_func_t func, VALUE data)
Identical to rb_thread_remove_event_hook(), except it additionally takes the data argument.
VALUE rb_tracepoint_enable(VALUE tpval)
Starts (enables) trace(s) defined by the passed object.
int rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data)
Registers a postponed job.
VALUE rb_tracearg_method_id(rb_trace_arg_t *trace_arg)
Queries the method name of the point where the trace is at.
int rb_remove_event_hook_with_data(rb_event_hook_func_t func, VALUE data)
Identical to rb_remove_event_hook(), except it additionally takes the data argument.
VALUE rb_tracearg_lineno(rb_trace_arg_t *trace_arg)
Queries the line of the point where the trace is at.
void(* rb_postponed_job_func_t)(void *arg)
Type of postponed jobs.
VALUE rb_tracearg_event(rb_trace_arg_t *trace_arg)
Identical to rb_tracearg_event_flag(), except it returns the name of the event in Ruby's symbol.
#define RUBY_EVENT_END
Encountered an end of a class clause.
#define RUBY_EVENT_C_CALL
A method, written in C, is called.
#define RUBY_EVENT_TRACEPOINT_ALL
Bitmask of extended events.
void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
Registers an event hook function.
#define RUBY_EVENT_RAISE
Encountered a raise statement.
#define RUBY_EVENT_B_RETURN
Encountered a next statement.
#define RUBY_EVENT_SCRIPT_COMPILED
Encountered an eval.
#define RUBY_INTERNAL_EVENT_MASK
Bitmask of internal events.
int rb_remove_event_hook(rb_event_hook_func_t func)
Removes the passed function from the list of event hooks.
#define RUBY_EVENT_ALL
Bitmask of traditional events.
#define RUBY_EVENT_THREAD_BEGIN
Encountered a new thread.
#define RUBY_EVENT_CLASS
Encountered a new class.
void(* rb_event_hook_func_t)(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass)
Type of event hooks.
#define RUBY_EVENT_LINE
Encountered a new line.
#define RUBY_EVENT_RETURN
Encountered a return statement.
#define RUBY_EVENT_C_RETURN
Return from a method, written in C.
#define RUBY_EVENT_B_CALL
Encountered an yield statement.
#define RUBY_INTERNAL_EVENT_FREEOBJ
Object swept.
uint32_t rb_event_flag_t
Represents event(s).
#define RUBY_EVENT_CALL
A method, written in Ruby, is called.
#define RUBY_INTERNAL_EVENT_NEWOBJ
Object allocated.
#define RUBY_EVENT_THREAD_END
Encountered an end of a thread.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a method.
int rb_block_given_p(void)
Determines if the current method is given a block.
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define FL_SINGLETON
Old name of RUBY_FL_SINGLETON.
#define ALLOC
Old name of RB_ALLOC.
#define xfree
Old name of ruby_xfree.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define ID2SYM
Old name of RB_ID2SYM.
#define ZALLOC
Old name of RB_ZALLOC.
#define FIX2INT
Old name of RB_FIX2INT.
#define NUM2UINT
Old name of RB_NUM2UINT.
#define T_ICLASS
Old name of RUBY_T_ICLASS.
#define ALLOC_N
Old name of RB_ALLOC_N.
#define rb_ary_new3
Old name of rb_ary_new_from_args.
#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 FL_TEST
Old name of RB_FL_TEST.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
void rb_bug(const char *fmt,...)
Interpreter panic switch.
VALUE rb_eTypeError
TypeError exception.
VALUE rb_eRuntimeError
RuntimeError exception.
VALUE rb_eArgError
ArgumentError exception.
VALUE rb_ensure(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*e_proc)(VALUE), VALUE data2)
An equivalent to ensure clause.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
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.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
Defines RBIMPL_HAS_BUILTIN.
void rb_gc_mark(VALUE obj)
Marks an object.
void rb_hash_foreach(VALUE hash, int(*func)(VALUE key, VALUE val, VALUE arg), VALUE arg)
Iterates over a hash.
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Inserts or replaces ("upsert"s) the objects into the given hash table.
VALUE rb_hash_new(void)
Creates a new, empty hash object.
VALUE rb_block_proc(void)
Constructs a Proc object from implicitly passed components.
VALUE rb_proc_call_with_block(VALUE recv, int argc, const VALUE *argv, VALUE proc)
Identical to rb_proc_call(), except you can additionally pass another proc object,...
VALUE rb_obj_is_method(VALUE recv)
Queries if the given object is a method.
VALUE rb_binding_new(void)
Snapshots the current execution context and turn it into an instance of rb_cBinding.
VALUE rb_obj_is_proc(VALUE recv)
Queries if the given object is a proc.
VALUE rb_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
void rb_undef_alloc_func(VALUE klass)
Deletes the allocator function of a class.
ID rb_intern(const char *name)
Finds or creates a symbol of the given name.
VALUE rb_sym2str(VALUE id)
Identical to rb_id2str(), except it takes an instance of rb_cSymbol rather than an ID.
VALUE rb_sprintf(const char *fmt,...)
Ruby's extended sprintf(3).
VALUE rb_yield(VALUE val)
Yields the block.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
static bool rb_ractor_shareable_p(VALUE obj)
Queries if multiple Ractors can share the passed object or not.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
#define RBASIC(obj)
Convenient casting macro.
#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...
#define RTEST
This is an old name of RB_TEST.
This is the struct that holds necessary info for a struct.
void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock)
Blocks until the current thread obtains a lock.
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock)
Releases a lock.
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.
void ruby_xfree(void *ptr)
Deallocates a storage instance.