debug: `next` stops in the wrong place when blocks are called

Your environment

  • ruby -v: 2.7.2p137
  • rdbg -v: 1.6.2

To Reproduce For a simple case:

  1. Create a file like:
def with_block
    yield
end
   
with_block do
    1
end
puts("`next` should stop here")
  1. Add a breakpoint in line 5
  2. Try to move to next
  3. See the debugger stop at line 6 (and then 7, and 3)

For more complex cases:

  1. Create a file like:
class Bar
  define_method("dynamic") do
    true
  end

  def regular; false; end
end

def foo(a, b, c); end

bar = Bar.new
foo(
  bar.regular,
  bar.dynamic, # `next` stops here
  bar.regular
)
puts("`next` should stop here")
  1. Add a breakpoint in line 12 (where the call to foo is)
  2. Try to move to next
  3. See the debugger stop at line 14

Expected behavior The debugger should stop at line 8 in the simple example, and 17 in the complex one

Additional context I included non-dynamically-defined methods, to show that next only behaves incorrectly for the dynamically-defined ones (as it doesn’t stop at line 13 nor 15)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (11 by maintainers)

Most upvoted comments

cc @WillHalto. Just a heads up that https://github.com/ruby/debug/pull/743 doesn’t seem to make this worse, but given that you are already there and have some context, you might find it interesting.