class Byebug::PryProcessor

Extends raw byebug's processor.

Attributes

pry[RW]

Public Class Methods

start() click to toggle source
# File lib/byebug/processors/pry_processor.rb, line 14
def self.start
  Byebug.start
  Setting[:autolist] = false
  Context.processor = self
  Byebug.current_context.step_out(4, true)
end

Public Instance Methods

at_breakpoint(breakpoint) click to toggle source

Called when a breakpoint is hit. Note that `at_line“ is called inmediately after with the context's `stop_reason == :breakpoint`, so we must not resume the pry instance here

# File lib/byebug/processors/pry_processor.rb, line 86
def at_breakpoint(breakpoint)
  @pry ||= Pry.new

  output.puts bold("\n  Breakpoint #{breakpoint.id}. ") + n_hits(breakpoint)

  expr = breakpoint.expr
  return unless expr

  output.puts bold("Condition: ") + expr
end
at_end() click to toggle source

Called when the debugger wants to stop right before the end of a class definition

# File lib/byebug/processors/pry_processor.rb, line 77
def at_end
  resume_pry
end
at_line() click to toggle source

Called when the debugger wants to stop at a regular line

# File lib/byebug/processors/pry_processor.rb, line 62
def at_line
  resume_pry
end
at_return(_return_value) click to toggle source

Called when the debugger wants to stop right before a method return

# File lib/byebug/processors/pry_processor.rb, line 69
def at_return(_return_value)
  resume_pry
end
perform(action, options = {}) click to toggle source

Set up a number of navigational commands to be performed by Byebug.

# File lib/byebug/processors/pry_processor.rb, line 43
def perform(action, options = {})
  return unless %i[
    backtrace
    down
    finish
    frame
    next
    step
    up
  ].include?(action)

  send("perform_#{action}", options)
end
run() { || ... } click to toggle source

Wrap a Pry REPL to catch navigational commands and act on them.

# File lib/byebug/processors/pry_processor.rb, line 24
def run(&_block)
  return_value = nil

  command = catch(:breakout_nav) do # Throws from PryByebug::Commands
    return_value = allowing_other_threads { yield }
    {} # Nothing thrown == no navigational command
  end

  # Pry instance to resume after stepping
  @pry = command[:pry]

  perform(command[:action], command[:options])

  return_value
end

Private Instance Methods

n_hits(breakpoint) click to toggle source
# File lib/byebug/processors/pry_processor.rb, line 99
def n_hits(breakpoint)
  n_hits = breakpoint.hit_count

  n_hits == 1 ? "First hit" : "Hit #{n_hits} times."
end
perform_backtrace(_options) click to toggle source
# File lib/byebug/processors/pry_processor.rb, line 120
def perform_backtrace(_options)
  Byebug::WhereCommand.new(self, "backtrace").execute

  resume_pry
end
perform_down(options) click to toggle source
# File lib/byebug/processors/pry_processor.rb, line 148
def perform_down(options)
  times = (options[:times] || 1).to_i

  Byebug::DownCommand.new(self, "down #{times}").execute

  resume_pry
end
perform_finish(*) click to toggle source
# File lib/byebug/processors/pry_processor.rb, line 136
def perform_finish(*)
  context.step_out(1)
end
perform_frame(options) click to toggle source
# File lib/byebug/processors/pry_processor.rb, line 156
def perform_frame(options)
  index = options[:index] ? options[:index].to_i : ""

  Byebug::FrameCommand.new(self, "frame #{index}").execute

  resume_pry
end
perform_next(options) click to toggle source
# File lib/byebug/processors/pry_processor.rb, line 126
def perform_next(options)
  lines = (options[:lines] || 1).to_i
  context.step_over(lines, frame.pos)
end
perform_step(options) click to toggle source
# File lib/byebug/processors/pry_processor.rb, line 131
def perform_step(options)
  times = (options[:times] || 1).to_i
  context.step_into(times, frame.pos)
end
perform_up(options) click to toggle source
# File lib/byebug/processors/pry_processor.rb, line 140
def perform_up(options)
  times = (options[:times] || 1).to_i

  Byebug::UpCommand.new(self, "up #{times}").execute

  resume_pry
end
resume_pry() click to toggle source

Resume an existing Pry REPL at the paused point.

# File lib/byebug/processors/pry_processor.rb, line 108
def resume_pry
  new_binding = frame._binding

  run do
    if defined?(@pry) && @pry
      @pry.repl(new_binding)
    else
      @pry = Pry.start_without_pry_byebug(new_binding)
    end
  end
end