# File lib/pry-debugger/processor.rb, line 8 def initialize Debugger.handler = self @always_enabled = false @delayed = Hash.new(0) end
Called when a breakpoint is triggered. Note: `#at_line“ is called immediately after with the context’s `stop_reason == :breakpoint`.
# File lib/pry-debugger/processor.rb, line 96 def at_breakpoint(context, breakpoint) @pry.output.print Pry::Helpers::Text.bold("\nBreakpoint #{breakpoint.id}. ") @pry.output.puts (breakpoint.hit_count == 1 ? 'First hit.' : "Hit #{breakpoint.hit_count} times." ) if (expr = breakpoint.expr) @pry.output.print Pry::Helpers::Text.bold("Condition: ") @pry.output.puts expr end end
# File lib/pry-debugger/processor.rb, line 107 def at_catchpoint(context, exception) # TODO end
— Callbacks from debugger C extension —
# File lib/pry-debugger/processor.rb, line 69 def at_line(context, file, line) return if file && TRACE_IGNORE_FILES.include?(File.expand_path(file)) # If stopped for a breakpoint or catchpoint, can't play any delayed steps # as they'll move away from the interruption point. (Unsure if scenario is # possible, but just keeping assertions in check.) @delayed = Hash.new(0) unless :step == context.stop_reason if @delayed[:next] > 1 # If any delayed nexts/steps, do 'em. step_over @delayed[:next] - 1 @delayed = Hash.new(0) elsif @delayed[:step] > 1 step @delayed[:step] - 1 @delayed = Hash.new(0) elsif @delayed[:finish] > 0 finish @delayed = Hash.new(0) else # Otherwise, resume the pry session at the stopped line. resume_pry context end end
Adjust debugging. When set to false, the Processor will manage enabling and disabling the debugger itself. When set to true, the debugger is always enabled.
# File lib/pry-debugger/processor.rb, line 56 def debugging=(enabled) if enabled @always_enabled = true Debugger.start unless Debugger.started? else @always_enabled = false # Debugger will get stopped if necessary in `stop` once the repl ends. end end
Wrap a Pry REPL to catch navigational commands and act on them.
# File lib/pry-debugger/processor.rb, line 15 def run(initial = true, &block) return_value = nil command = catch(:breakout_nav) do # Throws from PryDebugger::Commands return_value = yield {} # Nothing thrown == no navigational command end times = (command[:times] || 1).to_i # Command argument times = 1 if times <= 0 if [:step, :next, :finish].include? command[:action] @pry = command[:pry] # Pry instance to resume after stepping Debugger.start unless Debugger.started? if initial # Movement when on the initial binding.pry line will have a frame # inside Debugger. If we step normally, it'll stop inside this # Processor. So jump out and stop at the above frame, then step/next # from our callback. Debugger.current_context.stop_frame = 1 @delayed[command[:action]] = times elsif :next == command[:action] step_over times elsif :step == command[:action] step times elsif :finish == command[:action] finish end else stop end return_value end