pry-nav 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 0.0.3 (2011-12-01)
2
+
3
+ * Performance improvement: Don't trace while in the Pry console. Only works in
4
+ >= 1.9.3-p0 because 1.9.2 segfaults: http://redmine.ruby-lang.org/issues/3921
5
+ * Always cleanup pry-remote DRb server and trace function when a program
6
+ ends. Fixes [#1](https://github.com/nixme/pry-nav/issues/1).
7
+ * **step** and **next** now check for a local file context. Prevents errors and
8
+ infinite loops when called from outside `binding.pry`, e.g. `rails console`.
9
+ * More resilient cleanup when [pry-remote][pry-remote] CLI disconnects.
10
+
11
+
1
12
  ## 0.0.2 (2011-11-30)
2
13
 
3
14
  * Rudimentary [pry-remote][pry-remote] support. Still a bit buggy.
data/lib/pry-nav.rb CHANGED
@@ -5,3 +5,7 @@ require 'pry-nav/tracer'
5
5
 
6
6
  # Optionally load pry-remote monkey patches
7
7
  require 'pry-nav/pry_remote_ext' if defined? PryRemote
8
+
9
+ module PryNav
10
+ TRACE_IGNORE_FILES = Dir[File.join(File.dirname(__FILE__), '**', '*.rb')]
11
+ end
@@ -3,10 +3,12 @@ require 'pry'
3
3
  module PryNav
4
4
  Commands = Pry::CommandSet.new do
5
5
  command 'step', 'Step execution into the next line or method.' do |steps|
6
+ check_local_context
6
7
  breakout_navigation :step, steps
7
8
  end
8
9
 
9
10
  command 'next', 'Execute the next line within the same stack frame.' do |lines|
11
+ check_local_context
10
12
  breakout_navigation :next, lines
11
13
  end
12
14
 
@@ -26,6 +28,15 @@ module PryNav
26
28
  times: times
27
29
  }
28
30
  end
31
+
32
+ # Checks that a command is executed in a local file context. Extracted
33
+ # from https://github.com/pry/pry/blob/master/lib/pry/default_commands/context.rb
34
+ def check_local_context
35
+ file = target.eval('__FILE__')
36
+ if file != Pry.eval_path && (file =~ /(\(.*\))|<.*>/ || file == '' || file == '-e')
37
+ raise Pry::CommandError, 'Cannot find local context. Did you use `binding.pry`?'
38
+ end
39
+ end
29
40
  end
30
41
  end
31
42
  end
@@ -1,4 +1,5 @@
1
1
  require 'pry-remote'
2
+ require 'drb'
2
3
 
3
4
  module PryRemote
4
5
 
@@ -13,6 +14,7 @@ module PryRemote
13
14
  uri = "druby://#{host}:#{port}"
14
15
 
15
16
  @client = PryRemote::Client.new
17
+ @started = true
16
18
  DRb.start_service uri, @client
17
19
 
18
20
  puts "[pry-remote] Waiting for client on #{uri}"
@@ -45,6 +47,8 @@ module PryRemote
45
47
  end
46
48
 
47
49
  def stop
50
+ return unless @started
51
+
48
52
  # Reset output streams
49
53
  $stdout = @old_stdout
50
54
  $stderr = @old_stderr
@@ -55,10 +59,16 @@ module PryRemote
55
59
  # Reset system
56
60
  Pry.config.system = @old_system
57
61
 
58
- puts "[pry-remote] Remote sesion terminated"
59
- @client.kill
62
+ begin
63
+ @client.kill
64
+ rescue DRb::DRbConnError
65
+ # Ignore connection errors. The CLI client may have killed itself.
66
+ ensure
67
+ DRb.stop_service
68
+ end
60
69
 
61
- DRb.stop_service
70
+ @started = false
71
+ puts "[pry-remote] Remote sesion terminated"
62
72
  end
63
73
  end
64
74
  end
@@ -76,3 +86,11 @@ class Object
76
86
  }
77
87
  end
78
88
  end
89
+
90
+ # Ensure cleanup when a program finishes without another break. For example,
91
+ # 'next' on the last line of a program never hits the tracer proc, and thus
92
+ # PryNav::Tracer#run doesn't have a chance to cleanup.
93
+ END {
94
+ set_trace_func nil
95
+ PryRemote::Server.stop
96
+ }
@@ -2,27 +2,34 @@ require 'pry'
2
2
 
3
3
  module PryNav
4
4
  class Tracer
5
- FILE = File.expand_path(__FILE__)
6
-
7
5
  def initialize(pry_start_options = {}, &block)
8
6
  @step_in_lines = -1 # Break after this many lines
9
7
  @frames_when_stepping = nil # Only break at this frame level
10
- @frames = [] # Traced stack frames
8
+ @frames = 0 # Traced stack frame level
11
9
  @pry_start_options = pry_start_options # Options to use for Pry.start
12
10
 
13
11
  run &block
14
12
  end
15
13
 
16
14
  def run(&block)
17
- start # Set the trace function
15
+ # For performance, disable any tracers while in the console.
16
+ # Unfortunately, only works in >= 1.9.3 because of
17
+ # http://redmine.ruby-lang.org/issues/3921
18
+ stop if RUBY_VERSION >= '1.9.3'
18
19
 
19
20
  return_value = nil
20
- command = catch(:breakout_nav) do # Coordinate with PryNav::Commands
21
+ command = catch(:breakout_nav) do # Coordinates with PryNav::Commands
21
22
  return_value = yield
22
23
  {} # Nothing thrown == no navigational command
23
24
  end
24
25
 
25
- process_command command
26
+ # Adjust tracer based on command
27
+ if process_command(command)
28
+ start
29
+ else
30
+ stop unless RUBY_VERSION >= '1.9.3'
31
+ PryRemote::Server.stop if @pry_start_options[:pry_remote]
32
+ end
26
33
 
27
34
  return_value
28
35
  end
@@ -43,12 +50,13 @@ module PryNav
43
50
  when :step
44
51
  @step_in_lines = times
45
52
  @frames_when_stepping = nil
53
+ true
46
54
  when :next
47
55
  @step_in_lines = times
48
- @frames_when_stepping = @frames.size
56
+ @frames_when_stepping = @frames
57
+ true
49
58
  else
50
- stop
51
- PryRemote::Server.stop if @pry_start_options[:pry_remote]
59
+ false
52
60
  end
53
61
  end
54
62
 
@@ -57,18 +65,18 @@ module PryNav
57
65
 
58
66
  def tracer(event, file, line, id, binding, klass)
59
67
  # Ignore traces inside pry-nav code
60
- return if (file && File.expand_path(file) == FILE)
68
+ return if file && TRACE_IGNORE_FILES.include?(File.expand_path(file))
61
69
 
62
70
  case event
63
71
  when 'line'
64
72
  # Are we stepping? Or continuing by line ('next') and we're at the right
65
73
  # frame? Then decrement our line counter cause this line counts.
66
- if !@frames_when_stepping || @frames.size == @frames_when_stepping
74
+ if !@frames_when_stepping || @frames == @frames_when_stepping
67
75
  @step_in_lines -= 1
68
76
  @step_in_lines = -1 if @step_in_lines < 0
69
77
 
70
78
  # Did we go up a frame and not break for a 'next' yet?
71
- elsif @frames.size < @frames_when_stepping
79
+ elsif @frames < @frames_when_stepping
72
80
  @step_in_lines = 0 # Break right away
73
81
  end
74
82
 
@@ -76,10 +84,11 @@ module PryNav
76
84
  Pry.start(binding, @pry_start_options) if @step_in_lines == 0
77
85
 
78
86
  when 'call', 'class'
79
- @frames.unshift [binding, file, line, id] # Track entering a frame
87
+ @frames += 1 # Track entering a frame
80
88
 
81
89
  when 'return', 'end'
82
- @frames.shift # Track leaving a stack frame
90
+ @frames -= 1 # Track leaving a stack frame
91
+ @frames = 0 if @frames < 0
83
92
  end
84
93
  end
85
94
  end
@@ -1,3 +1,3 @@
1
1
  module PryNav
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-nav
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-30 00:00:00.000000000 Z
12
+ date: 2011-12-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
16
- requirement: &70264352532260 !ruby/object:Gem::Requirement
16
+ requirement: &70332078184900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.9.7.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70264352532260
24
+ version_requirements: *70332078184900
25
25
  description: Turn Pry into a primitive debugger. Adds 'step' and 'next' commands to
26
26
  control execution.
27
27
  email: nixme@stillhope.com
@@ -62,9 +62,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  version: '0'
63
63
  requirements: []
64
64
  rubyforge_project:
65
- rubygems_version: 1.8.11
65
+ rubygems_version: 1.8.10
66
66
  signing_key:
67
67
  specification_version: 3
68
68
  summary: Simple execution navigation for Pry.
69
69
  test_files: []
70
- has_rdoc: