Ruby: vm_trace.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Typedefs | Enumerations | Functions
vm_trace.c File Reference
`#include "eval_intern.h"`
`#include "internal.h"`
`#include "internal/hash.h"`
`#include "internal/symbol.h"`
`#include "iseq.h"`
`#include "mjit.h"`
`#include "ruby/debug.h"`
`#include "vm_core.h"`
`#include "ruby/ractor.h"`
`#include "builtin.h"`
`#include "trace_point.rbinc"`

Go to the source code of this file.

## Data Structures
struct | rb_event_hook_struct
struct | rb_tp_struct
struct | rb_postponed_job_struct
struct | rb_workqueue_job

## Macros
#define | MAX_EVENT_NUM 32
#define | MATCH_ANY_FILTER_TH ((rb_thread_t *)1)
#define | C(name, NAME) case RUBY_EVENT_##NAME: CONST_ID(id, #name); return id;
#define | C(name, NAME) CONST_ID(id, #name); if (sym == ID2SYM(id)) return RUBY_EVENT_##NAME
#define | MAX_POSTPONED_JOB 1000
#define | MAX_POSTPONED_JOB_SPECIAL_ADDITION 24

## Typedefs
typedef struct rb_event_hook_struct | rb_event_hook_t
typedef void(* | rb_event_hook_raw_arg_func_t) (VALUE data, const rb_trace_arg_t *arg)
typedef struct rb_tp_struct | rb_tp_t
typedef struct rb_postponed_job_struct | rb_postponed_job_t

## Enumerations
enum | postponed_job_register_result { PJRR_SUCCESS = 0 , PJRR_FULL = 1 , PJRR_INTERRUPTED = 2 }

## Functions
void | rb_hook_list_mark (rb_hook_list_t *hooks)
void | rb_hook_list_free (rb_hook_list_t *hooks)
void | rb_thread_add_event_hook (VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
void | rb_add_event_hook (rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
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_flags)
void | rb_add_event_hook2 (rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flags)
int | rb_thread_remove_event_hook (VALUE thval, rb_event_hook_func_t func)
int | rb_thread_remove_event_hook_with_data (VALUE thval, rb_event_hook_func_t func, VALUE data)
int | rb_remove_event_hook (rb_event_hook_func_t func)
int | rb_remove_event_hook_with_data (rb_event_hook_func_t func, VALUE data)
void | rb_ec_clear_current_thread_trace_func (const rb_execution_context_t *ec)
void | rb_ec_clear_all_trace_func (const rb_execution_context_t *ec)
void | rb_exec_event_hooks (rb_trace_arg_t *trace_arg, rb_hook_list_t *hooks, int pop_p)
VALUE | rb_suppress_tracing (VALUE(*func)(VALUE), VALUE arg)
struct rb_trace_arg_struct * | rb_tracearg_from_tracepoint (VALUE tpval)
rb_event_flag_t | rb_tracearg_event_flag (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_event (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_lineno (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_path (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_parameters (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_method_id (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_callee_id (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_defined_class (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_binding (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_self (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_return_value (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_raised_exception (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_eval_script (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_instruction_sequence (rb_trace_arg_t *trace_arg)
VALUE | rb_tracearg_object (rb_trace_arg_t *trace_arg)
VALUE | rb_tracepoint_enable (VALUE tpval)
const rb_method_definition_t * | rb_method_def (VALUE method)
VALUE | rb_tracepoint_disable (VALUE tpval)
void | rb_hook_list_connect_tracepoint (VALUE target, rb_hook_list_t *list, VALUE tpval, unsigned int target_line)
void | rb_hook_list_remove_tracepoint (rb_hook_list_t *list, VALUE tpval)
VALUE | rb_tracepoint_enabled_p (VALUE tpval)
VALUE | rb_tracepoint_new (VALUE target_thval, rb_event_flag_t events, void(*func)(VALUE, void *), void *data)
void | Init_vm_trace (void)
void | Init_vm_postponed_job (void)
int | rb_postponed_job_register (unsigned int flags, rb_postponed_job_func_t func, void *data)
int | rb_postponed_job_register_one (unsigned int flags, rb_postponed_job_func_t func, void *data)
int | rb_workqueue_register (unsigned flags, rb_postponed_job_func_t func, void *data)
void | rb_postponed_job_flush (rb_vm_t *vm)

## Macro Definition Documentation

## ◆ C [1/2]

#define C | ( |  | name,
|  |  | NAME
| ) |  | case RUBY_EVENT_##NAME: CONST_ID(id, #name); return id;

## ◆ C [2/2]

#define C | ( |  | name,
|  |  | NAME
| ) |  | CONST_ID(id, #name); if (sym == ID2SYM(id)) return RUBY_EVENT_##NAME

## ◆ MATCH_ANY_FILTER_TH

#define MATCH_ANY_FILTER_TH ((rb_thread_t *)1)

Definition at line 219 of file vm_trace.c.

## ◆ MAX_EVENT_NUM

#define MAX_EVENT_NUM 32

Definition at line 53 of file vm_trace.c.

## ◆ MAX_POSTPONED_JOB

#define MAX_POSTPONED_JOB 1000

Definition at line 1547 of file vm_trace.c.

## ◆ MAX_POSTPONED_JOB_SPECIAL_ADDITION

#define MAX_POSTPONED_JOB_SPECIAL_ADDITION 24

Definition at line 1548 of file vm_trace.c.

## Typedef Documentation

## ◆ rb_event_hook_raw_arg_func_t

typedef void(* rb_event_hook_raw_arg_func_t) (VALUE data, const rb_trace_arg_t *arg)

Definition at line 51 of file vm_trace.c.

## ◆ rb_event_hook_t

typedef struct rb_event_hook_struct rb_event_hook_t

## ◆ rb_postponed_job_t

typedef struct rb_postponed_job_struct rb_postponed_job_t

## ◆ rb_tp_t

typedef struct rb_tp_struct rb_tp_t

## Enumeration Type Documentation

## ◆ postponed_job_register_result

enum postponed_job_register_result

Enumerator
PJRR_SUCCESS |
PJRR_FULL |
PJRR_INTERRUPTED |

Definition at line 1564 of file vm_trace.c.

## Function Documentation

## ◆ Init_vm_postponed_job()

void Init_vm_postponed_job | ( | void |  | ) |

Definition at line 1556 of file vm_trace.c.

References ALLOC_N, MAX_POSTPONED_JOB, rb_vm_struct::postponed_job_buffer, and rb_vm_struct::postponed_job_index.

## ◆ Init_vm_trace()

void Init_vm_trace | ( | void |  | ) |

Definition at line 1531 of file vm_trace.c.

References rb_cObject, rb_cThread, rb_define_class(), rb_define_global_function, rb_define_method, and rb_undef_alloc_func().

## ◆ rb_add_event_hook()

void rb_add_event_hook | ( | rb_event_hook_func_t | func,
|  | rb_event_flag_t | events,
|  | VALUE | data
| ) |  |

Definition at line 161 of file vm_trace.c.

References RUBY_EVENT_HOOK_FLAG_SAFE.

Referenced by ole_initialize().

## ◆ rb_add_event_hook2()

void rb_add_event_hook2 | ( | rb_event_hook_func_t | func,
|  | rb_event_flag_t | events,
|  | VALUE | data,
|  | rb_event_hook_flag_t | hook_flags
| ) |  |

Definition at line 174 of file vm_trace.c.

Referenced by rb_set_coverages(), and rb_tracepoint_enable().

## ◆ rb_ec_clear_all_trace_func()

void rb_ec_clear_all_trace_func | ( | const rb_execution_context_t * | ec | ) |

Definition at line 283 of file vm_trace.c.

References MATCH_ANY_FILTER_TH, and Qundef.

## ◆ rb_ec_clear_current_thread_trace_func()

void rb_ec_clear_current_thread_trace_func | ( | const rb_execution_context_t * | ec | ) |

Definition at line 277 of file vm_trace.c.

References Qundef.

Referenced by ruby_options().

## ◆ rb_exec_event_hooks()

void rb_exec_event_hooks | ( | rb_trace_arg_t * | trace_arg,
|  | rb_hook_list_t * | hooks,
|  | int | pop_p
| ) |  |

Definition at line 365 of file vm_trace.c.

References rb_execution_context_struct::cfp, rb_trace_arg_struct::ec, EC_JUMP_TAG, rb_execution_context_struct::errinfo, rb_trace_arg_struct::event, rb_execution_context_struct::local_storage_recursive_hash, rb_execution_context_struct::local_storage_recursive_hash_for_trace, NULL, rb_vm_tag::prev, Qnil, rb_mRubyVMFrozenCore, rb_vm_pop_frame(), RUBY_INTERNAL_EVENT_MASK, rb_trace_arg_struct::self, rb_execution_context_struct::tag, TAG_NONE, rb_execution_context_struct::trace_arg, and UNLIKELY.

## ◆ rb_hook_list_connect_tracepoint()

void rb_hook_list_connect_tracepoint | ( | VALUE | target,
|  | rb_hook_list_t * | list,
|  | VALUE | tpval,
|  | unsigned int | target_line
| ) |  |

Definition at line 1258 of file vm_trace.c.

References rb_tp_struct::events, FALSE, rb_event_hook_struct::filter, RUBY_EVENT_HOOK_FLAG_RAW_ARG, RUBY_EVENT_HOOK_FLAG_SAFE, and rb_event_hook_struct::target_line.

## ◆ rb_hook_list_free()

void rb_hook_list_free | ( | rb_hook_list_t * | hooks | ) |

Definition at line 69 of file vm_trace.c.

References rb_hook_list_struct::need_clean, and TRUE.

Referenced by rb_iseq_free().

## ◆ rb_hook_list_mark()

void rb_hook_list_mark | ( | rb_hook_list_t * | hooks | ) |

Definition at line 56 of file vm_trace.c.

References rb_event_hook_struct::data, rb_hook_list_struct::hooks, rb_event_hook_struct::next, and rb_gc_mark().

Referenced by rb_iseq_mark().

## ◆ rb_hook_list_remove_tracepoint()

void rb_hook_list_remove_tracepoint | ( | rb_hook_list_t * | list,
|  | VALUE | tpval
| ) |  |

Definition at line 1268 of file vm_trace.c.

References rb_event_hook_struct::data, rb_hook_list_struct::events, rb_event_hook_struct::events, rb_event_hook_struct::hook_flags, rb_hook_list_struct::hooks, rb_hook_list_struct::need_clean, rb_event_hook_struct::next, RUBY_EVENT_HOOK_FLAG_DELETED, and TRUE.

## ◆ rb_method_def()

const rb_method_definition_t * rb_method_def | ( | VALUE | method | ) |

Definition at line 2802 of file proc.c.

References rb_method_entry_struct::def, METHOD::me, and TypedData_Get_Struct.

Referenced by rb_method_iseq(), and rb_method_location().

## ◆ rb_postponed_job_flush()

void rb_postponed_job_flush | ( | rb_vm_t * | vm | ) |

Definition at line 1676 of file vm_trace.c.

References ATOMIC_CAS, rb_postponed_job_struct::data, EC_EXEC_TAG, EC_POP_TAG, EC_PUSH_TAG, rb_execution_context_struct::errinfo, free, rb_postponed_job_struct::func, rb_execution_context_struct::interrupt_mask, rb_workqueue_job::jnode, rb_workqueue_job::job, rb_vm_struct::postponed_job_buffer, rb_vm_struct::postponed_job_index, POSTPONED_JOB_INTERRUPT_MASK, Qnil, rb_nativethread_lock_lock(), rb_nativethread_lock_unlock(), RUBY_VM_SET_POSTPONED_JOB_INTERRUPT, TAG_NONE, TRAP_INTERRUPT_MASK, rb_vm_struct::workqueue, and rb_vm_struct::workqueue_lock.

Referenced by rb_threadptr_execute_interrupts().

## ◆ rb_postponed_job_register()

int rb_postponed_job_register | ( | unsigned int | flags,
|  | rb_postponed_job_func_t | func,
|  | void * | data
| ) |  |

Definition at line 1608 of file vm_trace.c.

References MAX_POSTPONED_JOB, PJRR_FULL, PJRR_INTERRUPTED, PJRR_SUCCESS, rb_vm_struct::postponed_job_index, and rb_bug().

## ◆ rb_postponed_job_register_one()

int rb_postponed_job_register_one | ( | unsigned int | flags,
|  | rb_postponed_job_func_t | func,
|  | void * | data
| ) |  |

Definition at line 1627 of file vm_trace.c.

References rb_postponed_job_struct::func, MAX_POSTPONED_JOB, MAX_POSTPONED_JOB_SPECIAL_ADDITION, PJRR_FULL, PJRR_INTERRUPTED, PJRR_SUCCESS, rb_vm_struct::postponed_job_buffer, rb_vm_struct::postponed_job_index, rb_bug(), and RUBY_VM_SET_POSTPONED_JOB_INTERRUPT.

## ◆ rb_remove_event_hook()

int rb_remove_event_hook | ( | rb_event_hook_func_t | func | ) |

Definition at line 265 of file vm_trace.c.

References NULL, and Qundef.

Referenced by rb_reset_coverages().

## ◆ rb_remove_event_hook_with_data()

int rb_remove_event_hook_with_data | ( | rb_event_hook_func_t | func,
|  | VALUE | data
| ) |  |

Definition at line 271 of file vm_trace.c.

References NULL.

Referenced by rb_tracepoint_disable().

## ◆ rb_suppress_tracing()

VALUE rb_suppress_tracing | ( | VALUE(*)(VALUE) | func,
|  | VALUE | arg
| ) |  |

Definition at line 418 of file vm_trace.c.

References EC_EXEC_TAG, EC_JUMP_TAG, EC_POP_TAG, EC_PUSH_TAG, rb_trace_arg_struct::event, LIKELY, NULL, Qnil, rb_ec_reset_raised(), RB_GC_GUARD, TAG_NONE, and rb_execution_context_struct::trace_arg.

## ◆ rb_thread_add_event_hook()

void rb_thread_add_event_hook | ( | VALUE | thval,
|  | rb_event_hook_func_t | func,
|  | rb_event_flag_t | events,
|  | VALUE | data
| ) |  |

Definition at line 155 of file vm_trace.c.

References RUBY_EVENT_HOOK_FLAG_SAFE.

## ◆ rb_thread_add_event_hook2()

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_flags
| ) |  |

Definition at line 168 of file vm_trace.c.

Referenced by rb_tracepoint_enable().

## ◆ rb_thread_remove_event_hook()

int rb_thread_remove_event_hook | ( | VALUE | thval,
|  | rb_event_hook_func_t | func
| ) |  |

Definition at line 253 of file vm_trace.c.

References Qundef.

## ◆ rb_thread_remove_event_hook_with_data()

int rb_thread_remove_event_hook_with_data | ( | VALUE | thval,
|  | rb_event_hook_func_t | func,
|  | VALUE | data
| ) |  |

Definition at line 259 of file vm_trace.c.

Referenced by rb_tracepoint_disable().

## ◆ rb_tracearg_binding()

VALUE rb_tracearg_binding | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 917 of file vm_trace.c.

References rb_trace_arg_struct::cfp, rb_trace_arg_struct::ec, Qnil, rb_vm_get_binding_creatable_next_cfp(), and rb_vm_make_binding().

## ◆ rb_tracearg_callee_id()

VALUE rb_tracearg_callee_id | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 903 of file vm_trace.c.

References rb_trace_arg_struct::called_id, ID2SYM, and Qnil.

## ◆ rb_tracearg_defined_class()

VALUE rb_tracearg_defined_class | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 910 of file vm_trace.c.

References rb_trace_arg_struct::klass.

## ◆ rb_tracearg_eval_script()

VALUE rb_tracearg_eval_script | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 967 of file vm_trace.c.

References rb_trace_arg_struct::data, rb_trace_arg_struct::event, Qnil, Qundef, RARRAY_AREF, rb_bug(), rb_eRuntimeError, rb_raise(), RUBY_EVENT_SCRIPT_COMPILED, T_ARRAY, and VM_ASSERT.

## ◆ rb_tracearg_event()

VALUE rb_tracearg_event | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 808 of file vm_trace.c.

References rb_trace_arg_struct::event, and ID2SYM.

## ◆ rb_tracearg_event_flag()

rb_event_flag_t rb_tracearg_event_flag | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 802 of file vm_trace.c.

References rb_trace_arg_struct::event.

## ◆ rb_tracearg_from_tracepoint()

struct rb_trace_arg_struct * rb_tracearg_from_tracepoint | ( | VALUE | tpval | ) |

Definition at line 796 of file vm_trace.c.

## ◆ rb_tracearg_instruction_sequence()

VALUE rb_tracearg_instruction_sequence | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 991 of file vm_trace.c.

References rb_trace_arg_struct::data, rb_trace_arg_struct::event, Qundef, RARRAY_AREF, rb_bug(), rb_eRuntimeError, rb_iseqw_new(), rb_raise(), RUBY_EVENT_SCRIPT_COMPILED, T_ARRAY, and VM_ASSERT.

## ◆ rb_tracearg_lineno()

VALUE rb_tracearg_lineno | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 822 of file vm_trace.c.

References INT2FIX, and rb_trace_arg_struct::lineno.

## ◆ rb_tracearg_method_id()

VALUE rb_tracearg_method_id | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 896 of file vm_trace.c.

References rb_trace_arg_struct::id, ID2SYM, and Qnil.

## ◆ rb_tracearg_object()

VALUE rb_tracearg_object | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 1018 of file vm_trace.c.

References rb_trace_arg_struct::data, rb_trace_arg_struct::event, Qundef, rb_bug(), rb_eRuntimeError, rb_raise(), RUBY_INTERNAL_EVENT_FREEOBJ, and RUBY_INTERNAL_EVENT_NEWOBJ.

## ◆ rb_tracearg_parameters()

VALUE rb_tracearg_parameters | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 856 of file vm_trace.c.

References rb_trace_arg_struct::cfp, rb_trace_arg_struct::ec, rb_trace_arg_struct::event, rb_trace_arg_struct::id, rb_control_frame_struct::iseq, rb_trace_arg_struct::klass, Qnil, rb_eRuntimeError, rb_iseq_parameters(), rb_method_entry_arity(), rb_method_entry_without_refinements(), rb_raise(), rb_unnamed_parameters(), rb_vm_get_ruby_level_next_cfp(), RUBY_EVENT_B_CALL, RUBY_EVENT_B_RETURN, RUBY_EVENT_C_CALL, RUBY_EVENT_C_RETURN, RUBY_EVENT_CALL, RUBY_EVENT_CLASS, RUBY_EVENT_END, RUBY_EVENT_LINE, RUBY_EVENT_RAISE, RUBY_EVENT_RETURN, RUBY_EVENT_SCRIPT_COMPILED, and VM_FRAME_MAGIC_BLOCK.

## ◆ rb_tracearg_path()

VALUE rb_tracearg_path | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 828 of file vm_trace.c.

References rb_trace_arg_struct::path.

## ◆ rb_tracearg_raised_exception()

VALUE rb_tracearg_raised_exception | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 952 of file vm_trace.c.

References rb_trace_arg_struct::data, rb_trace_arg_struct::event, Qundef, rb_bug(), rb_eRuntimeError, rb_raise(), and RUBY_EVENT_RAISE.

## ◆ rb_tracearg_return_value()

VALUE rb_tracearg_return_value | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 937 of file vm_trace.c.

References rb_trace_arg_struct::data, rb_trace_arg_struct::event, Qundef, rb_bug(), rb_eRuntimeError, rb_raise(), RUBY_EVENT_B_RETURN, RUBY_EVENT_C_RETURN, and RUBY_EVENT_RETURN.

## ◆ rb_tracearg_self()

VALUE rb_tracearg_self | ( | rb_trace_arg_t * | trace_arg | ) |

Definition at line 931 of file vm_trace.c.

References rb_trace_arg_struct::self.

## ◆ rb_tracepoint_disable()

VALUE rb_tracepoint_disable | ( | VALUE | tpval | ) |

Definition at line 1233 of file vm_trace.c.

References rb_tp_struct::local_target_set, NULL, Qfalse, Qundef, rb_hash_foreach(), rb_remove_event_hook_with_data(), rb_thread_remove_event_hook_with_data(), ruby_vm_event_local_num, rb_thread_struct::self, rb_tp_struct::target_th, and rb_tp_struct::tracing.

## ◆ rb_tracepoint_enable()

VALUE rb_tracepoint_enable | ( | VALUE | tpval | ) |

Definition at line 1125 of file vm_trace.c.

References rb_tp_struct::events, rb_tp_struct::local_target_set, Qfalse, Qundef, rb_add_event_hook2(), rb_eArgError, rb_raise(), rb_thread_add_event_hook2(), RUBY_EVENT_HOOK_FLAG_RAW_ARG, RUBY_EVENT_HOOK_FLAG_SAFE, rb_thread_struct::self, rb_tp_struct::target_th, and rb_tp_struct::tracing.

## ◆ rb_tracepoint_enabled_p()

VALUE rb_tracepoint_enabled_p | ( | VALUE | tpval | ) |

Definition at line 1347 of file vm_trace.c.

References Qfalse, Qtrue, and rb_tp_struct::tracing.

## ◆ rb_tracepoint_new()

VALUE rb_tracepoint_new | ( | VALUE | target_thval,
|  | rb_event_flag_t | events,
|  | void(*)(VALUE, void *) | func,
|  | void * | data
| ) |  |

Definition at line 1407 of file vm_trace.c.

References rb_trace_arg_struct::data, NULL, Qundef, and RTEST.

## ◆ rb_workqueue_register()

int rb_workqueue_register | ( | unsigned | flags,
|  | rb_postponed_job_func_t | func,
|  | void * | data
| ) |  |

Definition at line 1656 of file vm_trace.c.

References rb_postponed_job_struct::data, FALSE, rb_postponed_job_struct::func, rb_workqueue_job::jnode, rb_workqueue_job::job, malloc, rb_nativethread_lock_lock(), rb_nativethread_lock_unlock(), rb_vm_main_ractor_ec(), RUBY_VM_SET_POSTPONED_JOB_INTERRUPT, TRUE, rb_vm_struct::workqueue, and rb_vm_struct::workqueue_lock.