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

Fix broken command history when executing debugger on irb #997

Merged

Conversation

takatea
Copy link
Contributor

@takatea takatea commented Jul 8, 2023

Related issue

#994

Enviroment

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

Description

This PR fixed the load_history method in the console.rb to handle the issue #994.

In particular, it contains the following changes:

  • Load the history only if it doesn't exist
  • Return value to the line count of the history

I have conducted the following test in addition to running all automatic tests (rake test_all) successfully in my local environment.

Additional test

The following steps are carried out to compare the output of .irb_history and .rdbg_history before and after the changes in this Pull Request.

  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 debugger without irb console. (e.g. ruby -e 'require "debug"; debugger')

  4. Run the following commands on debugger console

    puts "only debugger 1"
    puts "only debugger 2"
    puts "only debugger 3"
    continue
  5. Debugger and the ruby proess finished

  6. Run irb

  7. Run the following commands on irb

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

  9. Run the following commands on debugger console

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

  11. Run quit to exit irb

(The same procedure is repeated as described above)

  1. Run debugger again without irb console. (e.g. ruby -e 'require "debug"; debugger')

  2. Run the following commands on debugger console

    puts "only debugger 4"
    puts "only debugger 5"
    puts "only debugger 6"
    continue
  3. Debugger and the ruby proess finished

  4. Run irb again

  5. Run the following commands on irb

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

  7. Run the following commands on debugger console

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

And then, I got the following .irb_history and .rdbg_history files:

after revision

.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
require "./test"
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

puts "only debugger 1"
puts "only debugger 2"
puts "only debugger 3"
continue
puts "debug 4"
puts "debug 5"
puts "debug 6"
continue
quit
puts "only debugger 4"
puts "only debugger 5"
puts "only debugger 6"
continue
puts "debug 10"
puts "debug 11"
puts "debug 12"
continue
quit
before revision

.irb_history

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

.rdbg_history

puts "only debugger 1"
puts "only debugger 2"
puts "only debugger 3"
continue
puts "only debugger 1"
puts "only debugger 2"
puts "only debugger 3"
continue
puts "debug 4"
puts "debug 5"
puts "debug 6"
continue
quit
puts "only debugger 4"
puts "only debugger 5"
puts "only debugger 6"
continue
puts "irb 9"
Test.new.run
puts "only debugger 1"
puts "only debugger 2"
puts "only debugger 3"
continue
puts "only debugger 1"
puts "only debugger 2"
puts "only debugger 3"
continue
puts "debug 4"
puts "debug 5"
puts "debug 6"
continue
quit
puts "only debugger 4"
puts "only debugger 5"
puts "only debugger 6"
continue
puts "debug 10"
puts "debug 11"
puts "debug 12"
continue
quit

Fixed the `load_history` method in the console.rb
The following changes:

* Load the history only if it doesn't exist
* Return value to the line count of the history
@ko1 ko1 merged commit 8d5c2a9 into ruby:master Sep 25, 2023
@takatea takatea deleted the fix-broken-history-when-debugger-was-invoked-on-irb branch September 26, 2023 03:14
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://togithub.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://togithub.com/ruby/debug/releases/tag/v1.9.0)

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

#### What's Changed

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

#### New Contributors

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

2 participants