debug icon indicating copy to clipboard operation
debug copied to clipboard

Broken command history when I execute debugger on irb

Open takatea opened this issue 3 years ago • 3 comments

Your environment

  • ruby -v: ruby 3.3.0preview1 (2023-05-12 master a1b01e7701) [x86_64-darwin22]
  • rdbg -v: rdbg 1.8.0

Describe the bug

Broken command histories (both .irb_history and .rdbg_history), when I execute debugger on irb.

To Reproduce

  1. Prepare a ruby script test.rb like this:

    require "debug"
    
    class Test
        def run
            debugger
        end
    end
    
  2. Remove .irb_history and .rdbg_history to clean up

  3. Run irb

  4. Run the following commands on irb

    require "./test"
    puts "irb 1"
    puts "irb 2"
    puts "irb 3"
    Test.new.run
    
  5. Debugger started

  6. Run the following commands on debugger console

    puts "debug 4"
    puts "debug 5"
    puts "debug 6"
    continue
    
  7. Debugger finished (then I return to irb console)

  8. Run quit to exit irb

  9. Run irb again

  10. Run the following commands on irb

    puts "irb 7"
    puts "irb 8"
    puts "irb 9"
    require "./test"
    Test.new.run
    
  11. Debugger started

  12. Run the following commands on debugger console

    puts "debug 10"
    puts "debug 11"
    puts "debug 12"
    continue
    
  13. Run quit to exit irb

  14. Look at .irb_history and .rdbg_history

Actual behavior

I got:

[.irb_history]

require "./test"
puts "irb 1"
puts "irb 2"
puts "irb 3"
Test.new.run
puts "debug 4"
puts "debug 5"
puts "debug 6"
continue
quit
puts "irb 7"
puts "irb 8"
puts "irb 9"
require "./test"
Test.new.run
# Today's OMIKUJI: CHU-KICHI
require "./test"
puts "irb 1"
puts "irb 2"
puts "irb 3"
Test.new.run
puts "debug 4"
puts "debug 5"
puts "debug 6"
continue
quit
puts "debug 10"
puts "debug 11"
puts "debug 12"
continue
quit

[.rdbg_history]

require "./test"
puts "irb 1"
puts "irb 2"
puts "irb 3"
Test.new.run
puts "debug 4"
puts "debug 5"
puts "debug 6"
continue
quit
puts "irb 8"
puts "irb 9"
require "./test"
Test.new.run
require "./test"
puts "irb 1"
puts "irb 2"
puts "irb 3"
Test.new.run
puts "debug 4"
puts "debug 5"
puts "debug 6"
continue
quit
puts "debug 10"
puts "debug 11"
puts "debug 12"
continue
quit

Expected behavior

Both history .irb_history and .rdbg_history should have same contents:

require "./test"
puts "irb 1"
puts "irb 2"
puts "irb 3"
Test.new.run
puts "debug 4"
puts "debug 5"
puts "debug 6"
continue
quit
puts "irb 7"
puts "irb 8"
puts "irb 9"
require "./test"
Test.new.run
puts "debug 10"
puts "debug 11"
puts "debug 12"
continue
quit

I do not know where Today's OMIKUJI should appear at.

Additional context

This problem dose not appear with:

  1. Remove .irb_history and .rdbg_history to clean up

  2. Run irb

  3. Run the following commands on irb

    require "./test"
    puts "irb 1"
    puts "irb 2"
    puts "irb 3"
    Test.new.run
    
  4. Debugger started

  5. Run the following commands on debugger console

    puts "debug 4"
    puts "debug 5"
    puts "debug 6"
    continue
    
  6. Debugger finished (then I return to irb console)

  7. Do not exit irb console here!!!

  8. Run the following commands on irb

    puts "irb 7"
    puts "irb 8"
    puts "irb 9"
    require "./test"
    Test.new.run
    
  9. Debugger started

  10. Run the following commands on debugger console

    puts "debug 10"
    puts "debug 11"
    puts "debug 12"
    continue
    
  11. Run quit to exit irb

  12. Look at .irb_history and .rdbg_history

I got:

[.irb_history]

require "./test"
puts "irb 1"
puts "irb 2"
puts "irb 3"
Test.new.run
puts "debug 4"
puts "debug 5"
puts "debug 6"
continue
puts "irb 7"
puts "irb 8"
puts "irb 9"
Test.new.run
puts "debug 10"
puts "debug 11"
puts "debug 12"
continue
quit

[.rdbg_history]

require "./test"
puts "irb 1"
puts "irb 2"
puts "irb 3"
Test.new.run
puts "debug 4"
puts "debug 5"
puts "debug 6"
continue
puts "irb 7"
puts "irb 8"
puts "irb 9"
Test.new.run
puts "debug 10"
puts "debug 11"
puts "debug 12"
continue
quit

takatea avatar Jun 23 '23 03:06 takatea

I asked the issue in the ruby-jp slack channel (#debugger) and found that the problem caused by the shared using Reline::HISTORY between irb and debug. (thanks to @ima1zumi and @tompng for their helpful insights!)

Therefore, the following steps are carried out to confirm that both irb and debug share the same Reline::HISTORY.

  1. Remove .irb_history and .rdbg_history to clean up

  2. Run irb

  3. Run the following commands on irb

    require "./test"
    puts "irb 1"
    puts "irb 2"
    puts "irb 3"
    Test.new.run
    
  4. Debugger started

  5. Puts Reline::HISTORY, and then I got:

    ["require \"./test\"",
    "puts \"irb 1\"",
    "puts \"irb 2\"",
    "puts \"irb 3\"",
    "Test.new.run",
    "Reline::HISTORY"]
    

When the debugger loads (appends) histories while running on irb, duplicate histories are currently stored in Reline::HISTORY because both the irb and debug history files contain the same saved content.

As a result, repeatedly saving and loading the same content leads to the history looks broken and bloating of the files.

takatea avatar Jul 08 '23 22:07 takatea

#997

ko1 avatar Sep 25 '23 08:09 ko1

Looking forward to this one being released 😅 ❤️

jon-sully avatar Nov 20 '23 14:11 jon-sully