Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/pry-debugger/before_session_hook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module PryDebugger
class BeforeSessionHook

def caller_bindings(target)

bindings = binding.callers

start_frames = bindings.each_with_index.select do |b, i|
(b.frame_type == :method &&
b.eval("self.class") == Debugger::Context &&
b.eval("__method__") == :at_line)
end

start_frame_index = start_frames.first.last
bindings = bindings.drop(start_frame_index + 1)

bindings
end

def call(output, target, _pry_)
return if binding.callers.map(&:frame_description).include?("start")
bindings = caller_bindings(target)
PryStackExplorer.create_and_push_frame_manager bindings, _pry_, :initial_frame => 0
end
end
end
2 changes: 2 additions & 0 deletions lib/pry-debugger/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
#

require 'pry-debugger/base'
require 'pry-debugger/before_session_hook.rb'
require 'pry-debugger/pry_ext'
require 'pry-debugger/commands'
require 'pry-debugger/version'
29 changes: 23 additions & 6 deletions lib/pry-debugger/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module PryDebugger

def process
check_file_context
breakout_navigation :step, args.first
breakout_navigation :step, :times => args.first
end
end

Expand All @@ -41,17 +41,33 @@ def process

def process
check_file_context
breakout_navigation :next, args.first
breakout_navigation :next, :times => args.first
end
end


create_command 'finish' do
description 'Execute until current stack frame returns.'

banner <<-BANNER
Usage: finish [frame-number]

Return the current or selected stack frame.

Examples:

finish Return from the current frame
finish 2 Return from the 2nd stack frame
BANNER


def process
check_file_context
breakout_navigation :finish

frame_manager = PryStackExplorer.frame_manager(_pry_)
binding_index = (args.first || frame_manager.binding_index).to_i

breakout_navigation :finish, :binding_index => binding_index
end
end

Expand Down Expand Up @@ -204,12 +220,13 @@ def process


helpers do
def breakout_navigation(action, times = nil)
def breakout_navigation(action, opts={})
_pry_.binding_stack.clear # Clear the binding stack.
throw :breakout_nav, { # Break out of the REPL loop and
:action => action, # signal the tracer.
:times => times,
:pry => _pry_
:times => opts[:times],
:pry => _pry_,
:binding_index => opts[:binding_index]
}
end

Expand Down
4 changes: 3 additions & 1 deletion lib/pry-debugger/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def initialize
Debugger.handler = self
@always_enabled = false
@delayed = Hash.new(0)
@binding_index = 0
end

# Wrap a Pry REPL to catch navigational commands and act on them.
Expand All @@ -21,6 +22,7 @@ def run(initial = true, &block)

times = (command[:times] || 1).to_i # Command argument
times = 1 if times <= 0
@binding_index = command[:binding_index]

if [:step, :next, :finish].include? command[:action]
@pry = command[:pry] # Pry instance to resume after stepping
Expand Down Expand Up @@ -135,7 +137,7 @@ def step_over(lines)

# Execute until current frame returns.
def finish
Debugger.current_context.stop_frame = 0
Debugger.current_context.stop_frame = @binding_index
end

# Cleanup when debugging is stopped and execution continues.
Expand Down
9 changes: 9 additions & 0 deletions lib/pry-debugger/pry_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ def start(target = TOPLEVEL_BINDING, options = {})
end
end
end

if Pry.plugins.include?("stack_explorer")
Pry.config.hooks.add_hook(:before_session, :debugger_frame_manager, PryDebugger::BeforeSessionHook.new)

# move default to the back of before_session
default = Pry.config.hooks.get_hook(:before_session, :default)
Pry.config.hooks.delete_hook(:before_session, :default)
Pry.config.hooks.add_hook(:before_session, :default, default)
end