mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Rework tracing for blocks running as methods
The main impetus for this change is to fix [Bug #13392]. Previously, we fired the "return" TracePoint event after popping the stack frame for the block running as method (BMETHOD). This gave undesirable source location outputs as the return event normally fires right before the frame going away. The iseq for each block can run both as a block and as a method. To accommodate that, this commit makes vm_trace() fire call/return events for instructions that have b_call/b_return events attached when the iseq is running as a BMETHOD. The logic for rewriting to "trace_*" instruction is tweaked so that when the user listens to call/return events, instructions with b_call/b_return become trace variants. To continue to provide the return value for non-local returns done using the "return" or "break" keyword inside BMETHODs, the stack unwinding code is tweaked. b_return events now provide the same return value as return events for these non-local cases. A pre-existing test deemed not providing a return value for these b_return events as a limitation. This commit removes the checks for call/return TracePoint events that happen when calling into BMETHODs when no TracePoints are active. Technically, migrating just the return event is enough to fix the bug, but migrating both call and return removes our reliance on `VM_FRAME_FLAG_FINISH` and re-entering the interpreter when the caller is already in the interpreter.
This commit is contained in:
parent
3b2b28d035
commit
9121e57a5f
Notes:
git
2021-12-02 07:42:54 +09:00
6 changed files with 209 additions and 59 deletions
2
iseq.h
2
iseq.h
|
@ -160,7 +160,7 @@ const rb_iseq_t *rb_iseq_ibf_load(VALUE str);
|
|||
const rb_iseq_t *rb_iseq_ibf_load_bytes(const char *cstr, size_t);
|
||||
VALUE rb_iseq_ibf_load_extra_data(VALUE str);
|
||||
void rb_iseq_init_trace(rb_iseq_t *iseq);
|
||||
int rb_iseq_add_local_tracepoint_recursively(const rb_iseq_t *iseq, rb_event_flag_t turnon_events, VALUE tpval, unsigned int target_line);
|
||||
int rb_iseq_add_local_tracepoint_recursively(const rb_iseq_t *iseq, rb_event_flag_t turnon_events, VALUE tpval, unsigned int target_line, bool target_bmethod);
|
||||
int rb_iseq_remove_local_tracepoint_recursively(const rb_iseq_t *iseq, VALUE tpval);
|
||||
const rb_iseq_t *rb_iseq_load_iseq(VALUE fname);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue