@@ -2377,6 +2377,8 @@ rb_iseq_event_flags(const rb_iseq_t *iseq, size_t pos)
23772377 }
23782378}
23792379
2380+ // Clear tracing event flags and turn off tracing for a given instruction as needed.
2381+ // This is currently used after updating a one-shot line coverage for the current instruction.
23802382void
23812383rb_iseq_clear_event_flags (const rb_iseq_t * iseq , size_t pos , rb_event_flag_t reset )
23822384{
@@ -3767,6 +3769,8 @@ rb_free_encoded_insn_data(void)
37673769 st_free_table (encoded_insn_data );
37683770}
37693771
3772+ // Initialize a table to decode bare, trace, and zjit instructions.
3773+ // This function also determines which instructions are used when TracePoint is enabled.
37703774void
37713775rb_vm_encoded_insn_data_table_init (void )
37723776{
@@ -3783,7 +3787,8 @@ rb_vm_encoded_insn_data_table_init(void)
37833787 insn_data [insn ].insn_len = insn_len (insn );
37843788
37853789 // When tracing :return events, we convert opt_invokebuiltin_delegate_leave + leave into
3786- // opt_invokebuiltin_delegate + trace_leave. https://github.com/ruby/ruby/pull/3256
3790+ // opt_invokebuiltin_delegate + trace_leave, presumably because we don't want to fire
3791+ // :return events before invokebuiltin. https://github.com/ruby/ruby/pull/3256
37873792 int notrace_insn = (insn != BIN (opt_invokebuiltin_delegate_leave )) ? insn : BIN (opt_invokebuiltin_delegate );
37883793 insn_data [insn ].notrace_encoded_insn = (void * )INSN_CODE (notrace_insn );
37893794 insn_data [insn ].trace_encoded_insn = (void * )INSN_CODE (notrace_insn + VM_BARE_INSTRUCTION_SIZE );
@@ -3806,6 +3811,9 @@ rb_vm_encoded_insn_data_table_init(void)
38063811 }
38073812}
38083813
3814+ // Decode an insn address to an insn. This returns bare instructions
3815+ // even if they're trace/zjit instructions. Use rb_vm_insn_addr2opcode
3816+ // to decode trace/zjit instructions as is.
38093817int
38103818rb_vm_insn_addr2insn (const void * addr )
38113819{
@@ -3820,7 +3828,8 @@ rb_vm_insn_addr2insn(const void *addr)
38203828 rb_bug ("rb_vm_insn_addr2insn: invalid insn address: %p" , addr );
38213829}
38223830
3823- // Unlike rb_vm_insn_addr2insn, this function can return trace opcode variants.
3831+ // Decode an insn address to an insn. Unlike rb_vm_insn_addr2insn,
3832+ // this function can return trace/zjit opcode variants.
38243833int
38253834rb_vm_insn_addr2opcode (const void * addr )
38263835{
@@ -3844,7 +3853,9 @@ rb_vm_insn_addr2opcode(const void *addr)
38443853 rb_bug ("rb_vm_insn_addr2opcode: invalid insn address: %p" , addr );
38453854}
38463855
3847- // Decode `ISEQ_BODY(iseq)->iseq_encoded[i]` to an insn.
3856+ // Decode `ISEQ_BODY(iseq)->iseq_encoded[i]` to an insn. This returns
3857+ // bare instructions even if they're trace/zjit instructions. Use
3858+ // rb_vm_insn_addr2opcode to decode trace/zjit instructions as is.
38483859int
38493860rb_vm_insn_decode (const VALUE encoded )
38503861{
@@ -3856,6 +3867,7 @@ rb_vm_insn_decode(const VALUE encoded)
38563867 return insn ;
38573868}
38583869
3870+ // Turn on or off tracing for a given instruction address
38593871static inline int
38603872encoded_iseq_trace_instrument (VALUE * iseq_encoded_insn , rb_event_flag_t turnon , bool remain_current_trace )
38613873{
@@ -3874,6 +3886,7 @@ encoded_iseq_trace_instrument(VALUE *iseq_encoded_insn, rb_event_flag_t turnon,
38743886 rb_bug ("trace_instrument: invalid insn address: %p" , (void * )* iseq_encoded_insn );
38753887}
38763888
3889+ // Turn off tracing for an instruction at pos after tracing event flags are cleared
38773890void
38783891rb_iseq_trace_flag_cleared (const rb_iseq_t * iseq , size_t pos )
38793892{
0 commit comments