Project

General

Profile

Actions

Feature #11348

closed

TracePoint API needs events for fiber's switching

Added by os97673 (Oleg Sukhodolsky) over 9 years ago. Updated about 9 years ago.

Status:
Feedback
Target version:
-
[ruby-core:69955]

Description

as discussed in https://github.com/deivid-rodriguez/byebug/issues/153 current implementation of byebug/debase has problem with stepping when Enumarator/Fiber is used. The problem is that Fiber completely replaces stack (w/o any events) while the gems assume that any stack modification has corresponding call/return event.

It would be nice to receive events for Fiber's switching (at least) to be able to track stack for every fiber independently.
Also I think it would be nice to discuss the API before adding it because different set of event will allow to implement different debugger's capabilities.
E.g. plain :fiber-changed (event about every fiber switch) will only allow us to handle every fiber independently (like threads are handled) while debugger's user may expect that step into on enumerator.next will step into enumerator's code and step out from that code should go to the place where enumerator.next has been called.
So, perhaps we should have different events for Fiber#resume and Fiber#yield, but I'm not sure and would like to here other opinions.

Here are two tests which can be used to play with (one for Enumerator, another for Fiber)

triangular_numbers = Enumerator.new do |yielder|
  number = 0
  count = 1
  loop do
    number += count
    count += 1
    yielder.yield number
  end
end

print triangular_numbers.next, " "

5.times do
  print triangular_numbers.next, " "
end
fiber = Fiber.new do
  number = 0
  count = 1
  loop do
    number += count
    count += 1
    Fiber.yield number
  end
end

print fiber.resume, " "

5.times do
  print fiber.resume, " "
end
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0