Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support IRB console #1024

Merged
merged 4 commits into from
Dec 5, 2023
Merged

Support IRB console #1024

merged 4 commits into from
Dec 5, 2023

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Oct 10, 2023

Motivation

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

  • Users won't have access to debug's commands in this mode.
  • To use debug commands, users need to leave the IRB session first, which means losing IRB commands or feature like multi-line input.
  • Moving between the 2 modes is not practical and doesn't provide a good experience.

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 ruby/irb#712

Changes

When the new irb command is executed, it will:

  • Open a new irb:rdbg console, which is achieved by replacing debug's UI_LocalConsole UI with IRB's IRB::Debug::UI.
  • In addition to replacing the UI class, it also performs a few setups like:
    • Making the debug gem skip IRB's frames.
    • Patch IRB's Context#evaluate method so when it evaluates IRB commands frozen threads will be temporarily unfroze.

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

  • In this new session, users can access both IRB and debug's commands, instead of just IRB's.
  • Since users have the features of both tools in the session, I didn't implement a way to "exit" back to debug's default console.
    • I'll be happy to make a follow up PR for it if it's proven useful in some cases.
  • In the irb:rdbg console, users get hint when their input is going to be processed as a debug command:
Screen.Recording.2023-12-04.at.21.41.35.mov

@st0012 st0012 force-pushed the upgrade-irb-command branch 3 times, most recently from 879d442 to b9234cc Compare October 14, 2023 14:48
@st0012 st0012 marked this pull request as ready for review October 14, 2023 14:56
@st0012 st0012 force-pushed the upgrade-irb-command branch from b9234cc to 85fa62a Compare October 19, 2023 10:09
@st0012 st0012 requested a review from ko1 October 19, 2023 10:09
@jon-sully
Copy link

Excited for this one! 😁

@st0012 st0012 force-pushed the upgrade-irb-command branch from 17abf5e to 85fa62a Compare October 26, 2023 15:20
@st0012 st0012 changed the title Upgrade the irb command to use irb:debug integration Support IRB console Nov 1, 2023
@st0012 st0012 force-pushed the upgrade-irb-command branch from c104241 to ad82b01 Compare November 6, 2023 21:24
@ko1
Copy link
Collaborator

ko1 commented Nov 13, 2023

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
Copy link
Collaborator

ko1 commented Nov 13, 2023

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

ko1 added a commit that referenced this pull request Nov 14, 2023
This reverts commit 6571e2a.

It contains #1024 accidentally.
@st0012 st0012 force-pushed the upgrade-irb-command branch 2 times, most recently from 0baae2e to ec76862 Compare November 14, 2023 21:21
@st0012
Copy link
Member Author

st0012 commented Nov 14, 2023

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

@st0012 st0012 force-pushed the upgrade-irb-command branch from ec76862 to 2165a70 Compare November 14, 2023 23:25
@ko1
Copy link
Collaborator

ko1 commented Nov 15, 2023

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
Copy link
Member Author

st0012 commented Nov 19, 2023

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 ruby/irb#768.

@ko1
Copy link
Collaborator

ko1 commented Nov 20, 2023

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

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

@st0012 st0012 force-pushed the upgrade-irb-command branch from 2165a70 to ad8ea78 Compare December 3, 2023 22:25
This means that user will get an IRB session that has access to the debug
commands too by activating IRB's debug integration automatically:
https://github.com/ruby/irb#debugging-with-irb
The required IRB version only supports 2.7+
@st0012 st0012 force-pushed the upgrade-irb-command branch from ad8ea78 to f282982 Compare December 3, 2023 23:02
@st0012
Copy link
Member Author

st0012 commented Dec 4, 2023

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

Screen.Recording.2023-12-04.at.21.41.35.mov

lib/debug/session.rb Outdated Show resolved Hide resolved
@ko1
Copy link
Collaborator

ko1 commented Dec 5, 2023

Thank you. It's great.

@ko1 ko1 merged commit 5581994 into ruby:master Dec 5, 2023
17 of 19 checks passed
@st0012 st0012 deleted the upgrade-irb-command branch December 5, 2023 19:05
xjunior referenced this pull request in powerhome/audiences Dec 11, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [debug](https://github.com/ruby/debug) | `1.8.0` -> `1.9.0` |
[![age](https://developer.mend.io/api/mc/badges/age/rubygems/debug/1.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/rubygems/debug/1.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/rubygems/debug/1.8.0/1.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/rubygems/debug/1.8.0/1.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>ruby/debug (debug)</summary>

### [`v1.9.0`](https://github.com/ruby/debug/releases/tag/v1.9.0)

[Compare
Source](https://github.com/ruby/debug/compare/v1.8.0...v1.9.0)

#### What's Changed

-   Configuration
- `session_name` config by [@&#8203;ko1](https://github.com/ko1) in
[https://github.com/ruby/debug/pull/1036](https://github.com/ruby/debug/pull/1036)
-   CLI
- Require Reline 0.3.8+ to avoid frozen issue by
[@&#8203;st0012](https://github.com/st0012) in
[https://github.com/ruby/debug/pull/1020](https://github.com/ruby/debug/pull/1020)
- Fix prompt list size and colorized code line size to match input line
size passed to Reline by [@&#8203;tompng](https://github.com/tompng)
in
[https://github.com/ruby/debug/pull/1010](https://github.com/ruby/debug/pull/1010)
- Fix broken command history when executing debugger on irb by
[@&#8203;takatea](https://github.com/takatea) in
[https://github.com/ruby/debug/pull/997](https://github.com/ruby/debug/pull/997)
- Drop patch for Reline 0.2.7 by
[@&#8203;st0012](https://github.com/st0012) in
[https://github.com/ruby/debug/pull/1022](https://github.com/ruby/debug/pull/1022)
- Support IRB console by [@&#8203;st0012](https://github.com/st0012)
in
[https://github.com/ruby/debug/pull/1024](https://github.com/ruby/debug/pull/1024)
-   Remote
- Allow TracePoint reentry during DAP's evaluation by
[@&#8203;st0012](https://github.com/st0012) in
[https://github.com/ruby/debug/pull/1026](https://github.com/ruby/debug/pull/1026)
- CDP: Add debuggerId field in the RETURN OBJECT of "Debugger.enable" by
[@&#8203;ono-max](https://github.com/ono-max) in
[https://github.com/ruby/debug/pull/1028](https://github.com/ruby/debug/pull/1028)
- CDP: disable JavaScript engine based autocompletion by
[@&#8203;ono-max](https://github.com/ono-max) in
[https://github.com/ruby/debug/pull/1029](https://github.com/ruby/debug/pull/1029)
- Do not use HEAD request if 1 port by
[@&#8203;ko1](https://github.com/ko1) in
[https://github.com/ruby/debug/pull/1035](https://github.com/ruby/debug/pull/1035)
- Show session_name on connection by
[@&#8203;ko1](https://github.com/ko1) in
[https://github.com/ruby/debug/pull/1037](https://github.com/ruby/debug/pull/1037)
-   Internal
- Stop assuming Integer#times is written in C by
[@&#8203;k0kubun](https://github.com/k0kubun) in
[https://github.com/ruby/debug/pull/1015](https://github.com/ruby/debug/pull/1015)
- Disable cloned breakpoints trace point events by
[@&#8203;vinistock](https://github.com/vinistock) in
[https://github.com/ruby/debug/pull/1008](https://github.com/ruby/debug/pull/1008)
- Unfreeze threads for some object-evaluating commands by
[@&#8203;st0012](https://github.com/st0012) in
[https://github.com/ruby/debug/pull/1030](https://github.com/ruby/debug/pull/1030)
- Prevent backtrace from hanging if objects in the backtrace use Thread
in inspect by [@&#8203;vinistock](https://github.com/vinistock) in
[https://github.com/ruby/debug/pull/1038](https://github.com/ruby/debug/pull/1038)
- Compile iseq_collector.c logic only on CRuby by
[@&#8203;eregon](https://github.com/eregon) in
[https://github.com/ruby/debug/pull/1039](https://github.com/ruby/debug/pull/1039)
- Fix compatibility with Fiber Scheduler. by
[@&#8203;ioquatix](https://github.com/ioquatix) in
[https://github.com/ruby/debug/pull/987](https://github.com/ruby/debug/pull/987)
- Do not make a Fiber for commands by
[@&#8203;ko1](https://github.com/ko1) in
[https://github.com/ruby/debug/pull/1044](https://github.com/ruby/debug/pull/1044)
- support Ruby 3.3 by [@&#8203;ko1](https://github.com/ko1) in
[https://github.com/ruby/debug/pull/1045](https://github.com/ruby/debug/pull/1045)
-   Misc/Doc
- Fix ruby warnings by [@&#8203;y-yagi](https://github.com/y-yagi) in
[https://github.com/ruby/debug/pull/993](https://github.com/ruby/debug/pull/993)
- Fix a typo by [@&#8203;makenowjust](https://github.com/makenowjust)
in
[https://github.com/ruby/debug/pull/988](https://github.com/ruby/debug/pull/988)
- Update `TrapInterceptor` to avoid assigning to an unused variable by
[@&#8203;DavidZivk](https://github.com/DavidZivk) in
[https://github.com/ruby/debug/pull/985](https://github.com/ruby/debug/pull/985)
- remove debug print by [@&#8203;ko1](https://github.com/ko1) in
[https://github.com/ruby/debug/pull/1043](https://github.com/ruby/debug/pull/1043)
- Minor punctuation and grammar fixes by
[@&#8203;ahangarha](https://github.com/ahangarha) in
[https://github.com/ruby/debug/pull/1041](https://github.com/ruby/debug/pull/1041)
-   Tests
- Bump actions/checkout from 3 to 4 by
[@&#8203;dependabot](https://github.com/dependabot) in
[https://github.com/ruby/debug/pull/1014](https://github.com/ruby/debug/pull/1014)

#### New Contributors

- [@&#8203;dependabot](https://github.com/dependabot) made their first
contribution in
[https://github.com/ruby/debug/pull/1014](https://github.com/ruby/debug/pull/1014)
- [@&#8203;tompng](https://github.com/tompng) made their first
contribution in
[https://github.com/ruby/debug/pull/1010](https://github.com/ruby/debug/pull/1010)
- [@&#8203;takatea](https://github.com/takatea) made their first
contribution in
[https://github.com/ruby/debug/pull/997](https://github.com/ruby/debug/pull/997)
- [@&#8203;y-yagi](https://github.com/y-yagi) made their first
contribution in
[https://github.com/ruby/debug/pull/993](https://github.com/ruby/debug/pull/993)
- [@&#8203;DavidZivk](https://github.com/DavidZivk) made their first
contribution in
[https://github.com/ruby/debug/pull/985](https://github.com/ruby/debug/pull/985)
- [@&#8203;eregon](https://github.com/eregon) made their first
contribution in
[https://github.com/ruby/debug/pull/1039](https://github.com/ruby/debug/pull/1039)
- [@&#8203;ahangarha](https://github.com/ahangarha) made their first
contribution in
[https://github.com/ruby/debug/pull/1041](https://github.com/ruby/debug/pull/1041)
- [@&#8203;ioquatix](https://github.com/ioquatix) made their first
contribution in
[https://github.com/ruby/debug/pull/987](https://github.com/ruby/debug/pull/987)

**Full Changelog**:
ruby/debug@v1.8.0...v1.9.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/powerhome/audiences).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy44Ny4yIiwidXBkYXRlZEluVmVyIjoiMzcuODcuMiIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

irb as _default_ debug front-end?
3 participants