14

Using the byebug gem gives me the ability to continue until the next breakpoint:

(byebug) help

  break      -- Sets breakpoints in the source code
  catch      -- Handles exception catchpoints
  condition  -- Sets conditions on breakpoints
  continue   -- Runs until program ends, hits a breakpoint or reaches a line
  delete     -- Deletes breakpoints
  disable    -- Disables breakpoints or displays
  display    -- Evaluates expressions every time the debugger stops
  down       -- Moves to a lower frame in the stack trace
  edit       -- Edits source files
  enable     -- Enables breakpoints or displays
  finish     -- Runs the program until frame returns
  frame      -- Moves to a frame in the call stack
  help       -- Helps you using byebug
  history    -- Shows byebug's history of commands
  info       -- Shows several informations about the program being debugged
  interrupt  -- Interrupts the program
  irb        -- Starts an IRB session
  kill       -- Sends a signal to the current process
  list       -- Lists lines of source code
  method     -- Shows methods of an object, class or module
  next       -- Runs one or more lines of code
  pry        -- Starts a Pry session
  ps         -- Evaluates an expression and prettyprints & sort the result
  quit       -- Exits byebug
  restart    -- Restarts the debugged program
  save       -- Saves current byebug session to a file
  set        -- Modifies byebug settings
  show       -- Shows byebug settings
  source     -- Restores a previously saved byebug session
  step       -- Steps into blocks or methods one or more times
  thread     -- Commands to manipulate threads
  tracevar   -- Enables tracing of a global variable
  undisplay  -- Stops displaying all or some expressions when program stops
  untracevar -- Stops tracing a global variable
  up         -- Moves to a higher frame in the stack trace
  var        -- Shows variables and its values
  where      -- Displays the backtrace

I looked all over and I cannot find a way to "continue without breakpoints". The only way I can think of is to remove or comment the byebug statements, quit with q! and restart the test.

How can I continue without stopping at other byebug statements in Ruby?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
ardavis
  • 9,842
  • 12
  • 58
  • 112

3 Answers3

21

You can use continue! or alias c! since byebug 11.0.0, released on February 15, 2019.

See this PR https://github.com/deivid-rodriguez/byebug/pull/524

If you are working with Rails, you may wanna reset it back on new request, than you can add a filter:

# application_controller.rb
 before_action do
    if defined?(Byebug) && Byebug.mode == :off && Rails.env.development?
      Byebug.mode = nil
    end
 end
Fangxing
  • 5,716
  • 2
  • 49
  • 53
6

A byebug method call in your code is not a 'breakpoint' (thinking of the references to breakpoint in the help output).

As per the help output, breakpoints can be disabled with the disable command. But that does not solve your problem because the next byebug will pause execution again.

Since byebug is just a method call, you can make it conditional:

byebug if SomeModule.byebug?

Then, in SomeModule, you could use a global variable to toggle it on/off. You'd either have to do that on all your calls to byebug, or you could monkey-patch the byebug method to do the same, alias_method_chain or something similar.

"Make Byebug finish executing without exiting Pry" is a similar answer.

Community
  • 1
  • 1
Lucas Nelson
  • 2,511
  • 1
  • 17
  • 14
6

I just found out in the code, that you can stop byebug altogether using:

Byebug.mode = :off

You can't turn it back on, since it won't attach on itself any more, but this is handy, e.g. when just debugging a script that you want to finish running.

estani
  • 24,254
  • 2
  • 93
  • 76
  • This is exactly what I was looking for. Pairs nicely with a temporary before_action in the application controller to turn it back on with every request. – ardavis Aug 14 '20 at 12:38
  • is there any other way to achieve it ? like --disable-all or something like that ? – Vijay Meena Sep 05 '20 at 06:31