Bug #15313

Updated by alanwu (Alan Wu) over 1 year ago

## Background 
 The popular debugger "byebug" relies on tracepoint events to implement a few core functionality such as "next". 
 The "next" command needs to pause execution when the VM reaches the next line on the same stack frame. As there is no direct way, using the public 
 API, to tell the execution progress of a frame, Byebug keeps track of the currently executing frame by maintaining a counter using the "call" and "return" 
 tracepoint event. 

 Byebug's counter becomes incorrect when the interpreter performs a tail call, since after a tail call, the "return" event doesn't fire for the caller. #15303 
 This causes cause the "next" command to misbehave when stepping over code that performs tail call. 

 ## Proposed solution 
 I implemented a new method in TracePoint that lets Byebug, or any other debugger to differentiate between a normal method call and a tail call. Using this API, 
 Byebug can maintain the counter properly in the event of a tail call. 

 Here are some other solutions 
   - Some sort of public api that exposes execution progress of control frames. This might take a lot of effort. 
   - Some sort of public api that give ids to stack frames. After a tail call, debuggers can use this to tell that a frame is different, even though it's on the same location on the stack. 
   - Turning off tail call optimization in Forwardable. This side steps the problem but the core issue still remain. Third party libraries could still use tco 
      and byebug wouldn't be able to work with them. 

 Here are some downsides to my solution: 
   - This is a pretty niche feature that only debuggers want 
   - I'm adding a vm frame flag. While we have a few more bits to play with, it is a limited resource.