ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: os97673@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:70591] [Ruby trunk - Feature #11348] TracePoint API needs events for fiber's switching
Date: Tue, 25 Aug 2015 13:08:23 +0000	[thread overview]
Message-ID: <redmine.journal-53997.20150825130822.7444a635543c6900@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11348.20150713140158@ruby-lang.org

Issue #11348 has been updated by Oleg Sukhodolsky.


Oleg Sukhodolsky wrote:
> Koichi Sasada wrote:
> > I agree to add 'switching' events so I try to commit it.
> > 
> > Could you try it and could you tell me "what" is not enough?

I've played with the event a little bit and here is what I think.
Suppose we have the following program:

~~~ruby
f1 = Fiber.new do
  loop do
    Fiber.yield 1
  end
end
f1.resume # stopped at the line
f1.resume # want to stop here after step over
f1.resume
f1.resume
~~~

To implement expected behavior debugger (debase/byebug) store current stack size and stops at next line event with the same (or lower) stack size.
To handle fibers I would expect to use pair (fiber-stack-size, stack-size) and stop only if current fiber stack size is less than original or fiber stack sizes are equal and stack-size is equal or less than original (if you have better idea how to implement this feel free to share it with me).
So to implement this approach we need to detect fiber switch AND figure out if it was "fiber call" or "fiber return"  to be able to do this we either need to have two different events, or Fiber.nesting call you propose should help as at the moment we receive "fiber-switch" event, or (worse case for debugger) store the information about the switch and detect if it was call/return at next event we will process.  The latter is more complicated for debugger than 1 or 2.

Thus I'd prefer to have fiber-call/fiber-return, or be able to detect direction of the switch at the moment debugger is processing "fiber-switch".
Does this looks reasonable for you?  Is it doable on Ruby VM side? Do you have another ideas about implementing the debugger's functionality?

----------------------------------------
Feature #11348: TracePoint API needs events for fiber's switching
https://bugs.ruby-lang.org/issues/11348#change-53997

* Author: Oleg Sukhodolsky
* Status: Feedback
* Priority: Normal
* Assignee: Koichi Sasada
----------------------------------------
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)

~~~ruby
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
~~~

~~~ruby
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
~~~



-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2015-08-25 12:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-11348.20150713140158@ruby-lang.org>
2015-07-13 14:02 ` [ruby-core:69955] [Ruby trunk - Feature #11348] [Open] TracePoint API needs events for fiber's switching os97673
2015-08-10  1:39 ` [ruby-core:70289] [Ruby trunk - Feature #11348] [Assigned] " nagachika00
2015-08-21  9:56 ` [ruby-core:70506] [Ruby trunk - Feature #11348] [Feedback] " ko1
2015-08-21 12:42 ` [ruby-core:70514] [Ruby trunk - Feature #11348] " os97673
2015-08-25 13:08 ` os97673 [this message]
2015-09-01  8:57 ` [ruby-core:70642] " ko1
2015-09-01  9:12 ` [ruby-core:70645] " os97673
2015-09-01  9:53   ` [ruby-core:70648] " SASADA Koichi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-53997.20150825130822.7444a635543c6900@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).