debug icon indicating copy to clipboard operation
debug copied to clipboard

Keystrokes between `debugger` sessions seem to persist

Open joshuay03 opened this issue 1 year ago • 11 comments

Your environment

  • ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
  • rdbg -v: rdbg 1.9.2

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.

joshuay03 avatar Apr 23 '24 23:04 joshuay03

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

ko1 avatar Apr 24 '24 00:04 ko1

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

ko1 avatar Apr 24 '24 00:04 ko1

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 avatar Apr 24 '24 00:04 joshuay03

The source of the issue:

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

joshuay03 avatar Apr 24 '24 23:04 joshuay03

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

mattkuras avatar Aug 30 '24 16:08 mattkuras

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

dhh avatar Sep 09 '24 00:09 dhh

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.

joshuay03 avatar Sep 21 '24 04:09 joshuay03

@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.

dhh avatar Oct 04 '24 23:10 dhh

Sorry for long absent.

I have two options.

  1. clear $stdin just before printing prompt.
  2. provide an option to disable repeating input.

I made patches for 1 and 2. 1 seems aggressive, but I'll try to merge. 2 is conservative approach, so no problem to introduce (RUBY_DEBUG_NO_REPEAT or no_repeat option).

BTW, I confirmed that:

a. pry behaves similar (typed "foo" while sleeping appears on the prompt) , but pry doesn't have repeating previous command with white space, there is no same issue. b. gdb behaves similar and has same issue.

ko1 avatar Jun 04 '25 07:06 ko1

For 1, I found that the patch makes failure on remote debugging features.

ko1 avatar Jun 13 '25 09:06 ko1

Thank you @ko1, it seems we can close this issue off in that case?

@dhh I opened https://github.com/rails/rails/pull/55214 if we want to enable the config option in new Rails apps.

joshuay03 avatar Jun 20 '25 09:06 joshuay03

When would you not want to have the no repeat thing on? I'd very much prefer if Rails could just run with the default Debug options in place.,

dhh avatar Aug 24 '25 11:08 dhh