ruby / debug

Debugging functionality for Ruby
BSD 2-Clause "Simplified" License
1.14k stars 127 forks source link

Keystrokes between `debugger` sessions seem to persist #1098

Open joshuay03 opened 7 months ago

joshuay03 commented 7 months ago

Your environment

Describe the bug

After hitting a debugger break point once, and using c to move on, if you hit Enter before the next break point, the next breakpoint is skipped.

To Reproduce

Script:

require "debug"; def my_method; 2.times { |i| p i; debugger; sleep 1 }; end

Without hitting Enter:

https://github.com/ruby/debug/assets/54629302/2c5779ef-a054-4db9-97d0-1f09eaf05e49

With hitting Enter during the first sleep:

https://github.com/ruby/debug/assets/54629302/808ccb30-456a-4888-9794-96f514f8189f

Expected behavior

The execution should stop at the next breakpoint regardless of what keystrokes are used between breakpoints.

Additional context

None.

ko1 commented 7 months ago

wow I see... Should we consume all input before REPL?

ko1 commented 7 months ago

advices are very welcome If someone knows a techniques about it on other implementations

joshuay03 commented 7 months ago

Should we consume all input before REPL?

Hmm possibly, is that considered unconventional? Might be worth looking at how pry handles this.

Or maybe just ignore previous REPL if in-between sessions.

joshuay03 commented 7 months ago

The source of the issue:

https://github.com/ruby/debug/blob/0b77e8294b5b220b3b2a089bf09f94808654899a/lib/debug/session.rb#L1146-L1152

mattkuras commented 2 months ago

I too recently encountered this same issue. makes it hard to clear extra lines in the console

dhh commented 2 months ago

Been seeing the same issue. This didn't use to be the case. Maybe we can track down when this started?

joshuay03 commented 2 months ago

Maybe we can track down when this started?

I think it was introduced here. And there's this related follow-up issue.

I think a sensible middle ground would be to skip the repeat functionality on enter / empty line until the prompt is displaying. Or discard empty line input altogether until then.

dhh commented 1 month ago

@ko1 What do you think about an option where Rails could turn off this repeater behavior? Right now ruby/debug is not all that usable in Rails because of this issue.