Issue #17581 has been updated by jeremyevans0 (Jeremy Evans).

Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 2.5: DONTNEED, 2.6: DONTNEED, 2.7: DONTNEED, 3.0: REQUIRED

This happens for all backtrace frames where there is an `iseq` but no `pc`.  That part didn't change in the commit mentioned, so it must have been handled as a side effect of always looking at the entire backtrace, and filtering the resulting array.

The fix in this case is to keep two counters while iterating the backtrace, one for the desired backtrace size (so we generate the desired number of frames), and one for the actual backtrace size (so we don't process off the end of the stack).  When skipping a frame with an `iseq` and no `pc`, we need to decrement the first counter, since we aren't adding a frame in that iteration.  I've submitted a pull request for this: https://github.com/ruby/ruby/pull/4120

This should be backported to 3.0.

----------------------------------------
Bug #17581: Ruby 3.0 backtrace sometimes returns empty array
https://bugs.ruby-lang.org/issues/17581#change-90094

* Author: HParker (Adam Hess)
* Status: Assigned
* Priority: Normal
* Assignee: jeremyevans0 (Jeremy Evans)
* ruby -v: ruby 3.0.0dev (2020-09-04T16:41:35Z master de30450d91) [x86_64-darwin19]
* Backport: 2.5: DONTNEED, 2.6: DONTNEED, 2.7: DONTNEED, 3.0: REQUIRED
----------------------------------------
```ruby
class Foo
  def bar
    p caller(1,1)
  end
end
[Foo.new].group_by(&:bar)
```

3.0: []

2.7: ["test2.rb:6:in `each'"]

A similar thing happens when asking for a larger part of the backtrace:

```ruby
class Foo
  def bar
    p caller(0,4)
  end
end
[Foo.new].group_by(&:bar)
```

3.0: ["test2.rb:3:in `bar'", "test2.rb:6:in `each'", "test2.rb:6:in `group_by'"]

2.7: ["test2.rb:3:in `bar'", "test2.rb:6:in `each'", "test2.rb:6:in `group_by'", "test2.rb:6:in `<main>'"]

I suspect it was introduced by: https://github.com/ruby/ruby/commit/3b24b7914c16930bfadc89d6aff6326a51c54295
Since it seems to have to do with which frames are returned, though I haven't verified since the commit is difficult to revert.



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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>