Skip to content

Add a command to activate and switch to ruby/debug console #425

@st0012

Description

@st0012

Background

When debugging programs with Ruby 2.7+ , it's common to start with adding binding.irb breakpoints in the code. This is because irb is the only console-based tool (including REPLs and debuggers) that doesn't require installation nor require.

However, because irb is a REPL and lacks debugger features like step-debugging, frame navigation...etc., users may need to switch to debuggers like ruby/debug for advanced debugging.

And currently, that switch looks like this:

  1. Exit the current irb session.
  2. Add require "debug" if it's not yet required.
  3. Replace binding.irb with ruby/debug's breakpoints like binding.b or debugger (they're the same).
  4. Rerun the program and start debugging.

It's a 4-step process and requires switching between terminal and editor.

During a discussion with @k0kubun, he mentioned that maybe irb can help reduce the pain.

Proposal

Add a new debug command to irb, which when being executed will

  1. Run require "debug/session" and start the debugger.
    • If it causes LoadError, it means the new debug gem is not installed. So it will print a message to remind the user instead.
  2. Replace the current irb session with a new debug console.
  3. The user can start debugging at the same location as binding.irb was placed.

With this command, a user's irb -> debug switch would be:

  1. Type debug in the irb session.
  2. Start debugging.

Demo

irb debug command

Discussion Points

  • Should the command be debug or debugger?
    • debug:
      • As a verb it seems to convey the intention well as "Debug in the current context"
      • On the other hand, it's another debugging related name to remember.
    • debugger:
      • It's the same as the debugger statement ruby/debug already has.
      • It may give a false impression that we're simply calling the same statement in irb.
  • When users exit the debugger, should they exit completely or return to irb?
    • IMO, it should exit completely so users don't need to exit twice.
  • Because irb registers autocompletion logic to reline, debug's console (also powered by reline) will inherit that too.
    • Perhaps it should be suspended to avoid unexpected side-effects?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions