pry-debugger 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,7 @@
1
+ ## 0.1.0 (2012-06-07)
2
+
3
+ * First release. **step**, **next**, and **continue** commands.
4
+ [pry-remote 0.1.4][pry-remote] support.
5
+
6
+
7
+ [pry-remote]: https://github.com/Mon-Ouie/pry-remote
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT/Expat License
2
+
3
+ Copyright (c) 2012 by Gopal Patel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,54 @@
1
+ pry-debugger
2
+ ============
3
+
4
+ _Fast execution control in Pry_
5
+
6
+ Adds **step**, **next**, and **continue** commands to [Pry][pry] using
7
+ [debugger][debugger].
8
+
9
+ To use, invoke pry normally:
10
+
11
+ ```ruby
12
+ def some_method
13
+ binding.pry # Execution will stop here.
14
+ puts 'Hello World' # Run 'step' or 'next' in the console to move here.
15
+ end
16
+ ```
17
+
18
+ **pry-debugger** is not yet thread-safe, so only use in single-threaded
19
+ environments.
20
+
21
+ Only supports MRI 1.9.2 and 1.9.3. For a pure-ruby approach not reliant on
22
+ [debugger][debugger], check out [pry-nav][pry-nav]. Note: *pry-nav* and
23
+ *pry-debugger* cannot be loaded together.
24
+
25
+ Support for [pry-remote][pry-remote] (>= 0.1.4) is also included. Requires
26
+ explicity requiring pry-nav, not just relying on pry's plugin loader. For
27
+ example, in a Gemfile:
28
+
29
+ ```ruby
30
+ gem 'pry'
31
+ gem 'pry-nav'
32
+ ```
33
+
34
+ Stepping through code often? Add the following shortcuts to `~/.pryrc`:
35
+
36
+ ```ruby
37
+ Pry.commands.alias_command 'c', 'continue'
38
+ Pry.commands.alias_command 's', 'step'
39
+ Pry.commands.alias_command 'n', 'next'
40
+ ```
41
+
42
+ ## Contributions
43
+
44
+ Patches and bug reports are welcome. Just send a [pull request][pullrequests] or
45
+ file an [issue][issues]. [Project changelog][changelog].
46
+
47
+
48
+ [pry]: http://pry.github.com
49
+ [debugger]: https://github.com/cldwalker/debugger
50
+ [pry-nav]: https://github.com/nixme/pry-nav
51
+ [pry-remote]: https://github.com/Mon-Ouie/pry-remote
52
+ [pullrequests]: https://github.com/nixme/pry-debugger/pulls
53
+ [issues]: https://github.com/nixme/pry-debugger/issues
54
+ [changelog]: https://github.com/nixme/pry-debugger/blob/master/CHANGELOG.md
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ require 'pry-debugger/cli'
2
+
3
+ # Load pry-remote monkey patches if pry-remote's available
4
+ begin
5
+ require 'pry-debugger/pry_remote_ext'
6
+ rescue LoadError
7
+ end
@@ -0,0 +1,15 @@
1
+ module PryDebugger
2
+ TRACE_IGNORE_FILES = Dir[File.join(File.dirname(__FILE__), '..', '**', '*.rb')].map { |f| File.expand_path(f) }
3
+
4
+ extend self
5
+
6
+ # Checks that a binding is in a local file context. Extracted from
7
+ # https://github.com/pry/pry/blob/master/lib/pry/default_commands/context.rb
8
+ def check_file_context(target)
9
+ file = target.eval('__FILE__')
10
+ file == Pry.eval_path || (file !~ /(\(.*\))|<.*>/ && file != '' && file != '-e')
11
+ end
12
+
13
+ # Reference to currently running pry-remote server. Used by the processor.
14
+ attr_accessor :current_remote_server
15
+ end
@@ -0,0 +1,15 @@
1
+ # Pry's new plugin loading system ensures this file runs before pry-remote. So
2
+ # attempting to load everything directly from lib/pry-debugger.rb and
3
+ # referencing that here causes a circular dependency when running
4
+ # bin/pry-remote.
5
+ #
6
+ # So delay loading our monkey-patch to when someone explicity does a:
7
+ #
8
+ # require 'pry-debugger'
9
+ #
10
+ # Load everything else here.
11
+ #
12
+
13
+ require 'pry-debugger/base'
14
+ require 'pry-debugger/pry_ext'
15
+ require 'pry-debugger/commands'
@@ -0,0 +1,39 @@
1
+ require 'pry'
2
+
3
+ module PryDebugger
4
+ Commands = Pry::CommandSet.new do
5
+ block_command 'step', 'Step execution into the next line or method.' do |steps|
6
+ check_file_context
7
+ breakout_navigation :step, steps
8
+ end
9
+
10
+ block_command 'next', 'Execute the next line within the same stack frame.' do |lines|
11
+ check_file_context
12
+ breakout_navigation :next, lines
13
+ end
14
+
15
+ block_command 'continue', 'Continue program execution and end the Pry session.' do
16
+ check_file_context
17
+ run 'exit-all'
18
+ end
19
+
20
+ helpers do
21
+ def breakout_navigation(action, times)
22
+ _pry_.binding_stack.clear # Clear the binding stack.
23
+ throw :breakout_nav, { # Break out of the REPL loop and
24
+ :action => action, # signal the tracer.
25
+ :times => times
26
+ }
27
+ end
28
+
29
+ # Ensures that a command is executed in a local file context.
30
+ def check_file_context
31
+ unless PryDebugger.check_file_context(target)
32
+ raise Pry::CommandError, 'Cannot find local context. Did you use `binding.pry`?'
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ Pry.commands.import PryDebugger::Commands
@@ -0,0 +1,69 @@
1
+ require 'pry'
2
+ require 'debugger'
3
+
4
+ module PryDebugger
5
+ class Processor
6
+ def initialize(pry_start_options = {}, &block)
7
+ Debugger.handler = self
8
+ @pry_start_options = pry_start_options
9
+ end
10
+
11
+ def run(&block)
12
+ return_value = nil
13
+ command = catch(:breakout_nav) do # Throws from PryDebugger::Commands
14
+ return_value = yield
15
+ {} # Nothing thrown == no navigational command
16
+ end
17
+
18
+ times = (command[:times] || 1).to_i # Command argument
19
+ times = 1 if times <= 0
20
+
21
+ remote = @pry_start_options[:pry_remote] && PryDebugger.current_remote_server
22
+
23
+ if [:step, :next].include? command[:action]
24
+ Debugger.start
25
+ if Debugger.current_context.frame_self.is_a? Debugger::Context
26
+ # The first binding.pry call will have a frame inside Debugger. If we
27
+ # step normally, it'll stop inside this Processor instead. So jump it
28
+ # out to the above frame.
29
+ #
30
+ # TODO: times isn't respected
31
+ Debugger.current_context.stop_frame = 1 # (remote ? 2 : 1)
32
+ else
33
+ if :next == command[:action]
34
+ Debugger.current_context.step_over(times, 0)
35
+ else # step
36
+ Debugger.current_context.step(times)
37
+ end
38
+ end
39
+ elsif remote # Continuing execution... cleanup DRb remote if running
40
+ PryDebugger.current_remote_server.teardown
41
+ end
42
+
43
+ return_value
44
+ end
45
+
46
+
47
+ # --- Callbacks from debugger C extension ---
48
+
49
+ def at_line(context, file, line)
50
+ return if file && TRACE_IGNORE_FILES.include?(File.expand_path(file))
51
+ start_pry context
52
+ end
53
+
54
+ def at_breakpoint(context, breakpoint)
55
+ # TODO
56
+ end
57
+
58
+ def at_catchpoint(context, exception)
59
+ # TODO
60
+ end
61
+
62
+
63
+ private
64
+
65
+ def start_pry(context)
66
+ Pry.start(context.frame_binding(0), @pry_start_options)
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,21 @@
1
+ require 'pry'
2
+ require 'pry-debugger/processor'
3
+
4
+ class << Pry
5
+ alias_method :start_existing, :start
6
+
7
+ def start(target = TOPLEVEL_BINDING, options = {})
8
+ old_options = options.reject { |k, _| k == :pry_remote }
9
+
10
+ if target.is_a?(Binding) && PryDebugger.check_file_context(target)
11
+ # Wrap the processer around the usual Pry.start to catch navigation
12
+ # commands.
13
+ PryDebugger::Processor.new(options).run do
14
+ start_existing(target, old_options)
15
+ end
16
+ else
17
+ # No need for the tracer unless we have a file context to step through
18
+ start_existing(target, old_options)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,42 @@
1
+ require 'pry-remote'
2
+
3
+ module PryRemote
4
+ class Server
5
+ # Override the call to Pry.start to save off current Server, pass a
6
+ # pry_remote flag so pry-debugger knows this is a remote session, and not
7
+ # kill the server right away.
8
+ def run
9
+ if PryDebugger.current_remote_server
10
+ raise 'Already running a pry-remote session!'
11
+ else
12
+ PryDebugger.current_remote_server = self
13
+ end
14
+
15
+ setup
16
+ Pry.start @object, {
17
+ :input => client.input_proxy,
18
+ :output => client.output,
19
+ :pry_remote => true
20
+ }
21
+ end
22
+
23
+ # Override to reset our saved global current server session.
24
+ alias_method :teardown_existing, :teardown
25
+ def teardown
26
+ return if @torn
27
+
28
+ teardown_existing
29
+ PryDebugger.current_remote_server = nil
30
+ @torn = true
31
+ end
32
+ end
33
+ end
34
+
35
+ # Ensure cleanup when a program finishes without another break. For example,
36
+ # 'next' on the last line of a program won't hit PryDebugger::Processor#run,
37
+ # which normally handles cleanup.
38
+ at_exit do
39
+ if PryDebugger.current_remote_server
40
+ PryDebugger.current_remote_server.teardown
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module PryDebugger
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/pry-debugger/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'pry-debugger'
7
+ gem.version = PryDebugger::VERSION
8
+ gem.author = 'Gopal Patel'
9
+ gem.email = 'nixme@stillhope.com'
10
+ gem.license = 'MIT'
11
+ gem.homepage = 'https://github.com/nixme/pry-debugger'
12
+ gem.summary = 'Fast debugging with Pry.'
13
+ gem.description = "Combine 'pry' with 'debugger'. Adds 'step', 'next', and 'continue' commands to control execution."
14
+
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.files = `git ls-files`.split("\n")
17
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ gem.require_paths = ["lib"]
19
+
20
+ # Dependencies
21
+ gem.required_ruby_version = '>= 1.9.2'
22
+ gem.add_runtime_dependency 'pry', '~> 0.9.9'
23
+ gem.add_runtime_dependency 'debugger', '~> 1.1.3'
24
+ gem.add_development_dependency 'pry-remote', '~> 0.1.4'
25
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-debugger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gopal Patel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pry
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.9
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.9
30
+ - !ruby/object:Gem::Dependency
31
+ name: debugger
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.1.3
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry-remote
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.1.4
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.4
62
+ description: Combine 'pry' with 'debugger'. Adds 'step', 'next', and 'continue' commands
63
+ to control execution.
64
+ email: nixme@stillhope.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - CHANGELOG.md
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - lib/pry-debugger.rb
76
+ - lib/pry-debugger/base.rb
77
+ - lib/pry-debugger/cli.rb
78
+ - lib/pry-debugger/commands.rb
79
+ - lib/pry-debugger/processor.rb
80
+ - lib/pry-debugger/pry_ext.rb
81
+ - lib/pry-debugger/pry_remote_ext.rb
82
+ - lib/pry-debugger/version.rb
83
+ - pry-debugger.gemspec
84
+ homepage: https://github.com/nixme/pry-debugger
85
+ licenses:
86
+ - MIT
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.9.2
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.23
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Fast debugging with Pry.
109
+ test_files: []