ruby / debug

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

Support IRB console #1024

Closed st0012 closed 11 months ago

st0012 commented 1 year ago

Motivation

Currently, the irb command always opens up a fresh IRB session, which means:

So in this PR, I enhanced the irb command by making it activate IRB's new irb:debug integration.

And if users want to always activate the new IRB console, without constantly typing irb command manually, they can achieve this by setting CONFIG[:irb_console] to true.

Closes https://github.com/ruby/irb/issues/712

Changes

When the new irb command is executed, it will:

Furthermore, if users set RUBY_DEBUG_IRB_CONSOLE or CONFIG[:irb_console] to true, then the irb:rdbg console will be opened automatically in the sessions.

Main differences

https://github.com/ruby/debug/assets/5079556/a69fe51b-561a-423e-b0b8-d3b424ebc2c2

jon-sully commented 1 year ago

Excited for this one! 😁

ko1 commented 1 year ago

Is this intentional?

[master]$ RUBY_DEBUG_IRB_CONSOLE=true exe/rdbg -O target.rb
DEBUGGER: Debugger can attach via UNIX domain socket (/run/user/1000/ruby-debug-ko1-223275)
/home/ko1/ruby/install/trunk/lib/ruby/gems/3.3.0+0/gems/debug-1.8.0/lib/debug/color.rb:22: warning: already initialized constant DEBUGGER__::Color::SUPPORT_COLORABLE_OPTION
/home/ko1/ruby/debug/lib/debug/color.rb:22: warning: previous definition of SUPPORT_COLORABLE_OPTION was here
[1, 10] in target.rb
     1|
=>   2| n = 10
     3| p 1
     4| p 2
     5| p 3
     6| p 4
     7| p 5

and

irb:rdbg(main):002> n
[1, 10] in target.rb
     1|
     2| n = 10
=>   3| p 1
     4| p 2
     5| p 3
     6| p 4
     7| p 5
     8|
     9|
    10| __END__
=>#0    <main> at target.rb:3
irb:rdbg(main):003>

(n as next command)

ko1 commented 1 year ago

For the remote connection, hmm... ignore this option? It is safer strategy for VSCode (DAP).

st0012 commented 1 year ago

@ko1 great catch on the doc and remote mode issue. I've fixed both now.

(n as next command)

Yes this is expected. The irb:rdbg integration only handles IRB commands and passes other types of input to debug.

ko1 commented 1 year ago

Yes this is expected. The irb:rdbg integration only handles IRB commands and passes other types of input to debug.

This is why I could not allow to input Ruby expression directly (and allow with Reline prompt changing). Could you consider to use escaping such as , next which is used on VSCode DAP REPL?

st0012 commented 1 year ago

Thanks for raising this 🙏 I talked to a few users during RubyConf and some said they did experience the issue before. But we all think it's better not to add the comma prefix. Because it means users will need to constantly be aware of which commands are from IRB (without comma) and which are from debug (with comma), which increases the learning curve for the feature. Alternatively, I think we can add an input hint to let user know the current input will be treated as a debug command through https://github.com/ruby/irb/pull/768.

ko1 commented 1 year ago

Alternatively, I think we can add an input hint to let user know the current input will be treated as a debug command through https://github.com/ruby/irb/pull/768.

It is one idea. How to know the string is debug command or not?

st0012 commented 11 months ago

@ko1 In IRB v1.10, I added hint to irb:rdbg session, which only show up when the input will be processed as debug command. And it will be removed once the user hits enter so it doesn't pollute the output history. Finally, it will be disabled if the user has no_hint set for debug.

I've bumped the PR's IRB requirement to v1.10 to take advantage of this feature. Here's a short demo:

https://github.com/ruby/debug/assets/5079556/a69fe51b-561a-423e-b0b8-d3b424ebc2c2

ko1 commented 11 months ago

Thank you. It's great.