44 #define MAX_EVENT_NUM 32
70 if (events & (1 << i)) {
86 if (events & (1 << i)) {
172 if (func == 0 || hook->
func == func) {
241 while ((hook = *nextp) != 0) {
259 for (hook = list->
hooks; hook; hook = hook->
next) {
274 if ((list->
events & trace_arg->
event) == 0)
return 0;
339 const int outer_state = th->
state;
350 if (state)
goto terminate;
354 if (state)
goto terminate;
372 th->
state = outer_state;
393 volatile int outer_state;
397 const int tracing = th->
trace_arg ? 1 : 0;
399 dummy_trace_arg.
event = 0;
405 outer_state = th->
state;
410 result = (*func)(
arg);
425 th->
state = outer_state;
589 #define C(name, NAME) case RUBY_EVENT_##NAME: CONST_ID(id, #name); return id;
596 C(c_return, C_RETURN);
599 C(b_return, B_RETURN);
600 C(thread_begin, THREAD_BEGIN);
601 C(thread_end, THREAD_END);
602 C(specified_line, SPECIFIED_LINE);
626 klass =
RBASIC(klass)->klass;
638 argv[5] = klass ? klass :
Qnil;
692 #define C(name, NAME) CONST_ID(id, #name); if (sym == ID2SYM(id)) return RUBY_EVENT_##NAME
699 C(c_return, C_RETURN);
702 C(b_return, B_RETURN);
703 C(thread_begin, THREAD_BEGIN);
704 C(thread_end, THREAD_END);
705 C(specified_line, SPECIFIED_LINE);
724 if (trace_arg == 0) {
739 return trace_arg->
event;
775 return trace_arg->
path;
782 if (!trace_arg->
klass) {
786 if (trace_arg->
klass) {
810 return trace_arg->
klass;
830 return trace_arg->
self;
843 rb_bug(
"tp_attr_return_value_m: unreachable");
845 return trace_arg->
data;
858 rb_bug(
"tp_attr_raised_exception_m: unreachable");
860 return trace_arg->
data;
873 rb_bug(
"tp_attr_raised_exception_m: unreachable");
875 return trace_arg->
data;
1085 int previous_tracing = tp->
tracing;
1136 int previous_tracing = tp->
tracing;
1182 if (
RTEST(target_thval)) {
1245 for (i=0; i<
argc; i++) {
1283 switch (trace_arg->
event) {
1307 return rb_sprintf(
"#<TracePoint:%"PRIsVALUE
" %"PRIsVALUE
">",
1312 return rb_sprintf(
"#<TracePoint:%"PRIsVALUE
"@%"PRIsVALUE
":%d>",
1428 #define MAX_POSTPONED_JOB 1000
1429 #define MAX_POSTPONED_JOB_SPECIAL_ADDITION 24
1451 if (expected_index >= max)
return PJRR_FULL;
1483 default:
rb_bug(
"unreachable\n");
1498 for (i=0; i<
index; i++) {
1500 if (pjob->
func == func) {
1509 default:
rb_bug(
"unreachable\n");
void(* rb_event_hook_func_t)(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass)
#define RB_TYPE_P(obj, type)
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
#define RUBY_EVENT_B_RETURN
#define RUBY_EVENT_THREAD_END
void(* rb_postponed_job_func_t)(void *arg)
#define RUBY_EVENT_THREAD_BEGIN
void rb_bug(const char *fmt,...)
void rb_postponed_job_flush(rb_vm_t *vm)
rb_control_frame_t * rb_vm_get_binding_creatable_next_cfp(rb_thread_t *th, const rb_control_frame_t *cfp)
rb_event_flag_t rb_tracearg_event_flag(rb_trace_arg_t *trace_arg)
int rb_vm_get_sourceline(const rb_control_frame_t *cfp)
#define VM_FRAME_TYPE_FINISH_P(cfp)
static int max(int a, int b)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
int rb_thread_remove_event_hook(VALUE thval, rb_event_hook_func_t func)
static VALUE set_trace_func(VALUE obj, VALUE trace)
SSL_METHOD *(* func)(void)
static VALUE tp_alloc(VALUE klass)
#define RUBY_EVENT_C_RETURN
static VALUE tracepoint_new(VALUE klass, rb_thread_t *target_th, rb_event_flag_t events, void(func)(VALUE, void *), void *data, VALUE proc)
static VALUE tracepoint_attr_path(VALUE tpval)
static void connect_event_hook(rb_hook_list_t *list, rb_event_hook_t *hook)
static VALUE thread_add_trace_func_m(VALUE obj, VALUE trace)
void rb_thread_add_event_hook(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
#define TH_JUMP_TAG(th, st)
void rb_add_event_hook2(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flag)
static void rb_threadptr_exec_event_hooks_orig(rb_trace_arg_t *trace_arg, int pop_p)
VALUE rb_tracearg_binding(rb_trace_arg_t *trace_arg)
static ID get_event_id(rb_event_flag_t event)
VALUE rb_proc_call_with_block(VALUE, int argc, const VALUE *argv, VALUE)
static size_t tp_memsize(const void *ptr)
static rb_tp_t * tpptr(VALUE tpval)
void rb_raise(VALUE exc, const char *fmt,...)
int rb_thread_remove_event_hook_with_data(VALUE thval, rb_event_hook_func_t func, VALUE data)
static VALUE tracepoint_attr_event(VALUE tpval)
static void clean_hooks(rb_hook_list_t *list)
#define RUBY_INTERNAL_EVENT_NEWOBJ
static void recalc_remove_ruby_vm_event_flags(rb_event_flag_t events)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
VALUE rb_tracepoint_enabled_p(VALUE tpval)
#define RUBY_EVENT_TRACEPOINT_ALL
static const char * get_event_name(rb_event_flag_t event)
void rb_undef_method(VALUE klass, const char *name)
static void recalc_add_ruby_vm_event_flags(rb_event_flag_t events)
VALUE rb_ivar_get(VALUE, ID)
struct rb_tp_struct rb_tp_t
static int clear_trace_func_i(st_data_t key, st_data_t val, st_data_t flag)
unsigned long rb_event_flag_t
static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALUE klass)
VALUE rb_tracearg_event(rb_trace_arg_t *trace_arg)
int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE *klassp)
static rb_thread_t * thval2thread_t(VALUE thval)
VALUE rb_binding_new(void)
struct rb_thread_struct * th
int rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data)
VALUE rb_block_proc(void)
#define RUBY_TYPED_NEVER_FREE
int rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, VALUE *klassp)
int rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data)
#define TypedData_Get_Struct(obj, type, data_type, sval)
int rb_block_given_p(void)
int rb_threadptr_set_raised(rb_thread_t *th)
rb_control_frame_t * rb_vm_get_ruby_level_next_cfp(rb_thread_t *th, const rb_control_frame_t *cfp)
struct rb_event_hook_struct * next
void(* func)(VALUE tpval, void *data)
static VALUE tracepoint_enable_m(VALUE tpval)
static void rb_threadptr_add_event_hook(rb_thread_t *th, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flags)
VALUE rb_tracearg_raised_exception(rb_trace_arg_t *trace_arg)
static VALUE rb_cTracePoint
VALUE rb_binding_new_with_cfp(rb_thread_t *th, const rb_control_frame_t *src_cfp)
#define RUBY_EVENT_B_CALL
static VALUE tracepoint_attr_defined_class(VALUE tpval)
void rb_threadptr_exec_event_hooks_and_pop_frame(struct rb_trace_arg_struct *trace_arg)
static VALUE thread_set_trace_func_m(VALUE obj, VALUE trace)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
#define RUBY_EVENT_RETURN
void rb_objspace_set_event_hook(const rb_event_flag_t event)
VALUE rb_suppress_tracing(VALUE(*func)(VALUE), VALUE arg)
struct rb_event_hook_struct * hooks
static void fill_path_and_lineno(rb_trace_arg_t *trace_arg)
#define ATOMIC_CAS(var, oldval, newval)
static int ruby_event_flag_count[MAX_EVENT_NUM]
rb_trace_arg_t * rb_tracearg_from_tracepoint(VALUE tpval)
static rb_event_hook_t * alloc_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flags)
static VALUE tracepoint_inspect(VALUE self)
static rb_event_flag_t symbol2event_flag(VALUE v)
static void exec_hooks_body(rb_thread_t *th, rb_hook_list_t *list, const rb_trace_arg_t *trace_arg)
static void fill_id_and_klass(rb_trace_arg_t *trace_arg)
rb_hook_list_t event_hooks
rb_event_hook_func_t func
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
VALUE rb_tracearg_method_id(rb_trace_arg_t *trace_arg)
static VALUE tracepoint_attr_raised_exception(VALUE tpval)
VALUE rb_sprintf(const char *format,...)
void(* rb_event_hook_raw_arg_func_t)(VALUE data, const rb_trace_arg_t *arg)
#define RUBY_TYPED_FREE_IMMEDIATELY
VALUE rb_tracearg_defined_class(rb_trace_arg_t *trace_arg)
#define CONST_ID(var, str)
static int remove_event_hook(rb_hook_list_t *list, rb_event_hook_func_t func, VALUE data)
static VALUE tracepoint_attr_return_value(VALUE tpval)
VALUE rb_tracepoint_new(VALUE target_thread_not_supported_yet, rb_event_flag_t events, void(*func)(VALUE, void *), void *data)
int rb_remove_event_hook(rb_event_hook_func_t func)
int rb_threadptr_reset_raised(rb_thread_t *th)
void rb_undef_alloc_func(VALUE)
VALUE rb_tracearg_lineno(rb_trace_arg_t *trace_arg)
rb_iseq_location_t location
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
static const rb_data_type_t tp_data_type
rb_event_hook_flag_t hook_flags
static int rb_threadptr_remove_event_hook(rb_thread_t *th, rb_event_hook_func_t func, VALUE data)
void rb_threadptr_restore_recursive_data(rb_thread_t *th, VALUE old)
VALUE rb_obj_is_proc(VALUE)
static VALUE tracepoint_attr_lineno(VALUE tpval)
#define MAX_POSTPONED_JOB
static VALUE tracepoint_disable_m(VALUE tpval)
VALUE rb_threadptr_reset_recursive_data(rb_thread_t *th)
static rb_trace_arg_t * get_trace_arg(void)
VALUE rb_mRubyVMFrozenCore
static void thread_add_trace_func(rb_thread_t *th, VALUE trace)
VALUE rb_tracearg_object(rb_trace_arg_t *trace_arg)
static VALUE tracepoint_trace_s(int argc, VALUE *argv, VALUE self)
struct rb_event_hook_struct rb_event_hook_t
static void tp_call_trace(VALUE tpval, rb_trace_arg_t *trace_arg)
static int exec_hooks_precheck(rb_thread_t *th, rb_hook_list_t *list, const rb_trace_arg_t *trace_arg)
unsigned long interrupt_mask
static void tp_mark(void *ptr)
#define RUBY_EVENT_SPECIFIED_LINE
void rb_thread_add_event_hook2(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flag)
rb_hook_list_t event_hooks
#define TypedData_Make_Struct(klass, type, data_type, sval)
RUBY_EXTERN VALUE rb_cObject
static VALUE tracepoint_attr_binding(VALUE tpval)
static int exec_hooks_protected(rb_thread_t *th, rb_hook_list_t *list, const rb_trace_arg_t *trace_arg)
static enum postponed_job_register_result postponed_job_register(rb_thread_t *th, rb_vm_t *vm, unsigned int flags, rb_postponed_job_func_t func, void *data, int max, int expected_index)
rb_event_flag_t ruby_vm_event_flags
void rb_vm_trace_mark_event_hooks(rb_hook_list_t *hooks)
struct rb_encoding_entry * list
rb_postponed_job_func_t func
VALUE rb_tracearg_path(rb_trace_arg_t *trace_arg)
#define GetThreadPtr(obj, ptr)
struct rb_postponed_job_struct rb_postponed_job_t
static void Init_postponed_job(void)
const char * rb_id2name(ID id)
postponed_job_register_result
#define MAX_POSTPONED_JOB_SPECIAL_ADDITION
VALUE rb_tracepoint_enable(VALUE tpval)
#define RUBY_INTERNAL_EVENT_FREEOBJ
struct rb_postponed_job_struct * postponed_job_buffer
void rb_clear_trace_func(void)
void rb_threadptr_exec_event_hooks(struct rb_trace_arg_struct *trace_arg)
#define RUBY_INTERNAL_EVENT_MASK
#define RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(th)
void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
VALUE rb_tracearg_return_value(rb_trace_arg_t *trace_arg)
static VALUE tracepoint_attr_self(VALUE tpval)
int rb_remove_event_hook_with_data(rb_event_hook_func_t func, VALUE data)
static rb_thread_t * GET_THREAD(void)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
#define RUBY_EVENT_C_CALL
static VALUE tracepoint_attr_method_id(VALUE tpval)
VALUE rb_tracearg_self(rb_trace_arg_t *trace_arg)
VALUE rb_tracepoint_disable(VALUE tpval)
static VALUE default_inspect(VALUE self, const char *class_name)
VALUE rb_convert_type(VALUE, int, const char *, const char *)
static void exec_hooks_unprotected(rb_thread_t *th, rb_hook_list_t *list, const rb_trace_arg_t *trace_arg)
RUBY_EXTERN VALUE rb_cThread
struct rb_trace_arg_struct * trace_arg
static VALUE tracepoint_new_s(int argc, VALUE *argv, VALUE self)