pry-byebug 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c079446464cffea15a38fd173ef57ef076bf9002
4
+ data.tar.gz: 38c27e09ca3c57a6a1e322e49589a47e0316d301
5
+ SHA512:
6
+ metadata.gz: 3750ce1963ae9660c470a81afbea8864e3cb79297278816468c2fadf779f968c7033f49da92aa7e67863c95215dd0c0952067ac4d1680df9bbd221e1de603cd9
7
+ data.tar.gz: 27c62f7240695a1596a0c508211529f577ac6f9c6dcd6b5e91ab66132525c3e5d6a2e710b954b6f12c7ac28288b59ec8dbf9a38f3a36780f2c7a68933837996c
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .gdb_history
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1 @@
1
+ pry-byebug
@@ -0,0 +1,31 @@
1
+ ## 1.0.0 (2013-05-07)
2
+
3
+ * Forked from [pry-debugger](https://github.com/nixme/pry-debugger) to support
4
+ byebug
5
+
6
+ ## 0.2.2 (2013-03-07)
7
+
8
+ * Relaxed [byebug][byebug] dependency.
9
+
10
+
11
+ ## 0.2.1 (2012-12-26)
12
+
13
+ * Support breakpoints on methods defined in the pry console. (@banister)
14
+ * Fix support for specifying breakpoints by *file:line_number*. (@nviennot)
15
+ * Validate breakpoint conditionals are real Ruby expressions.
16
+ * Support for debugger ~> 1.2.0. (@jshou)
17
+ * Safer `alias_method_chain`-style patching of `Pry.start` and
18
+ `PryRemote::Server#teardown`. (@benizi)
19
+
20
+
21
+ ## 0.2.0 (2012-06-11)
22
+
23
+ * Breakpoints
24
+ * **finish** command
25
+ * Internal cleanup and bug fixes
26
+
27
+
28
+ ## 0.1.0 (2012-06-07)
29
+
30
+ * First release. **step**, **next**, and **continue** commands.
31
+ [pry-remote 0.1.4][pry-remote] support.
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,149 @@
1
+ pry-byebug
2
+ ============
3
+
4
+ _Fast execution control in Pry_
5
+
6
+ Adds **step**, **next**, **finish**, and **continue** commands and
7
+ **breakpoints** to [Pry][pry] using [byebug][byebug].
8
+
9
+ To use, invoke pry normally. No need to start your script or app differently.
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
+ For a complete debugging environment, add
19
+ [pry-stack_explorer][pry-stack_explorer] for call-stack frame navigation.
20
+
21
+
22
+ ## Execution Commands
23
+
24
+ **step:** Step execution into the next line or method. Takes an optional numeric
25
+ argument to step multiple times.
26
+
27
+ **next:** Step over to the next line within the same frame. Also takes an
28
+ optional numeric argument to step multiple lines.
29
+
30
+ **finish:** Execute until current stack frame returns.
31
+
32
+ **continue:** Continue program execution and end the Pry session.
33
+
34
+
35
+ ## Breakpoints
36
+
37
+ You can set and adjust breakpoints directly from a Pry session using the
38
+ following commands:
39
+
40
+ **break:** Set a new breakpoint from a line number in the current file, a file
41
+ and line number, or a method. Pass an optional expression to create a
42
+ conditional breakpoint. Edit existing breakpoints via various flags.
43
+
44
+ Examples:
45
+
46
+ ```
47
+ break SomeClass#run Break at the start of `SomeClass#run`.
48
+ break Foo#bar if baz? Break at `Foo#bar` only if `baz?`.
49
+ break app/models/user.rb:15 Break at line 15 in user.rb.
50
+ break 14 Break at line 14 in the current file.
51
+
52
+ break --condition 4 x > 2 Change condition on breakpoint #4 to 'x > 2'.
53
+ break --condition 3 Remove the condition on breakpoint #3.
54
+
55
+ break --delete 5 Delete breakpoint #5.
56
+ break --disable-all Disable all breakpoints.
57
+
58
+ break List all breakpoints. (Same as `breakpoints`)
59
+ break --show 2 Show details about breakpoint #2.
60
+ ```
61
+
62
+ Type `break --help` from a Pry session to see all available options.
63
+
64
+
65
+ **breakpoints**: List all defined breakpoints. Pass `-v` or `--verbose` to see
66
+ the source code around each breakpoint.
67
+
68
+
69
+ ## Caveats
70
+
71
+ **pry-byebug** is not yet thread-safe, so only use in single-threaded
72
+ environments.
73
+
74
+ Only supports MRI 1.9.2 and 1.9.3. For a pure ruby approach not reliant on
75
+ [byebug][byebug], check out [pry-nav][pry-nav]. Note: *pry-nav* and
76
+ *pry-byebug* cannot be loaded together.
77
+
78
+
79
+ ## Remote debugging
80
+
81
+ Support for [pry-remote][pry-remote] (>= 0.1.4) is also included. Requires
82
+ explicity requiring *pry-byebug*, not just relying on pry's plugin loader.
83
+
84
+ Want to debug a Rails app running inside [foreman][foreman]? Add to your
85
+ Gemfile:
86
+
87
+ ```ruby
88
+ gem 'pry'
89
+ gem 'pry-remote'
90
+ gem 'pry-stack_explorer'
91
+ gem 'pry-byebug'
92
+ ```
93
+
94
+ Then add `binding.remote_pry` where you want to pause:
95
+
96
+ ```ruby
97
+ class UsersController < ApplicationController
98
+ def index
99
+ binding.remote_pry
100
+ ...
101
+ end
102
+ end
103
+ ```
104
+
105
+ Load a page that triggers the code. Connect to the session:
106
+
107
+ ```
108
+ $ bundle exec pry-remote
109
+ ```
110
+
111
+ Using Pry with Rails? Check out [Jazz Hands][jazz_hands].
112
+
113
+
114
+ ## Tips
115
+
116
+ Stepping through code often? Add the following shortcuts to `~/.pryrc`:
117
+
118
+ ```ruby
119
+ Pry.commands.alias_command 'c', 'continue'
120
+ Pry.commands.alias_command 's', 'step'
121
+ Pry.commands.alias_command 'n', 'next'
122
+ Pry.commands.alias_command 'f', 'finish'
123
+ ```
124
+
125
+
126
+ ## Contributors
127
+
128
+ * Gopal Patel (@nixme)
129
+ * John Mair (@banister)
130
+ * Nicolas Viennot (@nviennot)
131
+ * Benjamin R. Haskell (@benizi)
132
+ * Joshua Hou (@jshou)
133
+ * ...and others who helped with [pry-nav][pry-nav]
134
+
135
+ Patches and bug reports are welcome. Just send a [pull request][pullrequests] or
136
+ file an [issue][issues]. [Project changelog][changelog].
137
+
138
+
139
+
140
+ [pry]: http://pry.github.com
141
+ [byebug]: https://github.com/deivid-rodriguez/byebug
142
+ [pry-stack_explorer]: https://github.com/pry/pry-stack_explorer
143
+ [pry-nav]: https://github.com/nixme/pry-nav
144
+ [pry-remote]: https://github.com/Mon-Ouie/pry-remote
145
+ [foreman]: https://github.com/ddollar/foreman
146
+ [jazz_hands]: https://github.com/nixme/jazz_hands
147
+ [pullrequests]: https://github.com/nixme/pry-byebug/pulls
148
+ [issues]: https://github.com/nixme/pry-byebug/issues
149
+ [changelog]: https://github.com/nixme/pry-byebug/blob/master/CHANGELOG.md
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,3 @@
1
+ require 'pry-byebug/base'
2
+ require 'pry-byebug/pry_ext'
3
+ require 'pry-byebug/commands'
@@ -0,0 +1,13 @@
1
+ module PryByebug
2
+ extend self
3
+
4
+ # Checks that a binding is in a local file context. Extracted from
5
+ # https://github.com/pry/pry/blob/master/lib/pry/default_commands/context.rb
6
+ def check_file_context(target)
7
+ file = target.eval('__FILE__')
8
+ file == Pry.eval_path || (file !~ /(\(.*\))|<.*>/ && file != '' && file != '-e')
9
+ end
10
+
11
+ # Reference to currently running pry-remote server. Used by the processor.
12
+ attr_accessor :current_remote_server
13
+ end
@@ -0,0 +1,96 @@
1
+ module PryByebug
2
+
3
+ # Wrapper for Byebug.breakpoints that respects our Processor and has better
4
+ # failure behavior. Acts as an Enumerable.
5
+ #
6
+ module Breakpoints
7
+ extend Enumerable
8
+ extend self
9
+
10
+ # Add a new breakpoint.
11
+ def add(file, line, expression = nil)
12
+ real_file = (file != Pry.eval_path)
13
+ raise ArgumentError, 'Invalid file!' if real_file && !File.exist?(file)
14
+ validate_expression expression
15
+
16
+ Pry.processor.debugging = true
17
+
18
+ path = (real_file ? File.expand_path(file) : file)
19
+ Byebug.add_breakpoint(path, line, expression)
20
+ end
21
+
22
+ # Change the conditional expression for a breakpoint.
23
+ def change(id, expression = nil)
24
+ validate_expression expression
25
+
26
+ breakpoint = find_by_id(id)
27
+ breakpoint.expr = expression
28
+ breakpoint
29
+ end
30
+
31
+ # Delete an existing breakpoint with the given ID.
32
+ def delete(id)
33
+ unless Byebug.started? && Byebug.remove_breakpoint(id)
34
+ raise ArgumentError, "No breakpoint ##{id}"
35
+ end
36
+ Pry.processor.debugging = false if to_a.empty?
37
+ end
38
+
39
+ # Delete all breakpoints.
40
+ def clear
41
+ Byebug.breakpoints.clear if Byebug.started?
42
+ Pry.processor.debugging = false
43
+ end
44
+
45
+ # Enable a disabled breakpoint with the given ID.
46
+ def enable(id)
47
+ change_status id, true
48
+ end
49
+
50
+ # Disable a breakpoint with the given ID.
51
+ def disable(id)
52
+ change_status id, false
53
+ end
54
+
55
+ # Disable all breakpoints.
56
+ def disable_all
57
+ each do |breakpoint|
58
+ breakpoint.enabled = false
59
+ end
60
+ end
61
+
62
+ def to_a
63
+ Byebug.started? ? Byebug.breakpoints : []
64
+ end
65
+
66
+ def size
67
+ to_a.size
68
+ end
69
+
70
+ def each(&block)
71
+ to_a.each(&block)
72
+ end
73
+
74
+ def find_by_id(id)
75
+ breakpoint = find { |b| b.id == id }
76
+ raise ArgumentError, "No breakpoint ##{id}!" unless breakpoint
77
+ breakpoint
78
+ end
79
+
80
+
81
+ private
82
+
83
+ def change_status(id, enabled = true)
84
+ breakpoint = find_by_id(id)
85
+ breakpoint.enabled = enabled
86
+ breakpoint
87
+ end
88
+
89
+ def validate_expression(expression)
90
+ if expression && # `nil` implies no expression given, so pass
91
+ (expression.empty? || !Pry::Code.complete_expression?(expression))
92
+ raise "Invalid breakpoint conditional: #{expression}"
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,245 @@
1
+ require 'pry'
2
+ require 'pry-byebug/breakpoints'
3
+
4
+ module PryByebug
5
+ Commands = Pry::CommandSet.new do
6
+ create_command 'step' do
7
+ description 'Step execution into the next line or method.'
8
+
9
+ banner <<-BANNER
10
+ Usage: step [TIMES]
11
+
12
+ Step execution forward. By default, moves a single step.
13
+
14
+ Examples:
15
+
16
+ step Move a single step forward.
17
+ step 5 Execute the next 5 steps.
18
+ BANNER
19
+
20
+ def process
21
+ check_file_context
22
+ breakout_navigation :step, args.first
23
+ end
24
+ end
25
+
26
+
27
+ create_command 'next' do
28
+ description 'Execute the next line within the current stack frame.'
29
+
30
+ banner <<-BANNER
31
+ Usage: next [LINES]
32
+
33
+ Step over within the same frame. By default, moves forward a single
34
+ line.
35
+
36
+ Examples:
37
+
38
+ next Move a single line forward.
39
+ next 4 Execute the next 4 lines.
40
+ BANNER
41
+
42
+ def process
43
+ check_file_context
44
+ breakout_navigation :next, args.first
45
+ end
46
+ end
47
+
48
+
49
+ create_command 'finish' do
50
+ description 'Execute until current stack frame returns.'
51
+
52
+ def process
53
+ check_file_context
54
+ breakout_navigation :finish
55
+ end
56
+ end
57
+
58
+
59
+ create_command 'continue' do
60
+ description 'Continue program execution and end the Pry session.'
61
+
62
+ def process
63
+ check_file_context
64
+ run 'exit-all'
65
+ end
66
+ end
67
+
68
+
69
+ create_command 'break' do
70
+ description 'Set or edit a breakpoint.'
71
+
72
+ banner <<-BANNER
73
+ Usage: break <METHOD | FILE:LINE | LINE> [if CONDITION]
74
+ break --condition N [CONDITION]
75
+ break [--show | --delete | --enable | --disable] N
76
+ break [--delete-all | --disable-all]
77
+ Aliases: breakpoint
78
+
79
+ Set a breakpoint. Accepts a line number in the current file, a file and
80
+ line number, or a method, and an optional condition.
81
+
82
+ Pass appropriate flags to manipulate existing breakpoints.
83
+
84
+ Examples:
85
+
86
+ break SomeClass#run Break at the start of `SomeClass#run`.
87
+ break Foo#bar if baz? Break at `Foo#bar` only if `baz?`.
88
+ break app/models/user.rb:15 Break at line 15 in user.rb.
89
+ break 14 Break at line 14 in the current file.
90
+
91
+ break --condition 4 x > 2 Add/change condition on breakpoint #4.
92
+ break --condition 3 Remove the condition on breakpoint #3.
93
+
94
+ break --delete 5 Delete breakpoint #5.
95
+ break --disable-all Disable all breakpoints.
96
+
97
+ break List all breakpoints. (Same as `breakpoints`)
98
+ break --show 2 Show details about breakpoint #2.
99
+ BANNER
100
+
101
+ def options(opt)
102
+ opt.on :c, :condition, 'Change the condition of a breakpoint.', :argument => true, :as => Integer
103
+ opt.on :s, :show, 'Show breakpoint details and source.', :argument => true, :as => Integer
104
+ opt.on :D, :delete, 'Delete a breakpoint.', :argument => true, :as => Integer
105
+ opt.on :d, :disable, 'Disable a breakpoint.', :argument => true, :as => Integer
106
+ opt.on :e, :enable, 'Enable a disabled breakpoint.', :argument => true, :as => Integer
107
+ opt.on :'disable-all', 'Disable all breakpoints.'
108
+ opt.on :'delete-all', 'Delete all breakpoints.'
109
+ method_options(opt)
110
+ end
111
+
112
+ def process
113
+ Pry.processor.pry = _pry_
114
+
115
+ { :delete => :delete,
116
+ :disable => :disable,
117
+ :enable => :enable,
118
+ :'disable-all' => :disable_all,
119
+ :'delete-all' => :clear
120
+ }.each do |action, method|
121
+ if opts.present?(action)
122
+ Breakpoints.__send__ method, *(method == action ? [opts[action]] : [])
123
+ return run 'breakpoints'
124
+ end
125
+ end
126
+
127
+ if opts.present?(:condition)
128
+ Breakpoints.change(opts[:condition], args.empty? ? nil : args.join(' '))
129
+ run 'breakpoints'
130
+ elsif opts.present?(:show)
131
+ print_full_breakpoint Breakpoints.find_by_id(opts[:show])
132
+ elsif args.empty?
133
+ run 'breakpoints'
134
+ else
135
+ new_breakpoint
136
+ end
137
+ end
138
+
139
+ def new_breakpoint
140
+ place = args.shift
141
+ condition = args.join(' ') if 'if' == args.shift
142
+
143
+ file, line =
144
+ case place
145
+ when /^(\d+)$/ # Line number only
146
+ line = $1
147
+ unless PryByebug.check_file_context(target)
148
+ raise ArgumentError, 'Line number declaration valid only in a file context.'
149
+ end
150
+ [target.eval('__FILE__'), line]
151
+ when /^(.+):(\d+)$/ # File and line number
152
+ [$1, $2]
153
+ else # Method or class name
154
+ self.args = [place]
155
+ method_object.source_location
156
+ end
157
+
158
+ print_full_breakpoint Breakpoints.add(file, line.to_i, condition)
159
+ end
160
+ end
161
+ alias_command 'breakpoint', 'break'
162
+
163
+
164
+ create_command 'breakpoints' do
165
+ description 'List defined breakpoints.'
166
+
167
+ banner <<-BANNER
168
+ Usage: breakpoints [OPTIONS]
169
+ Aliases: breaks
170
+
171
+ List registered breakpoints and their current status.
172
+ BANNER
173
+
174
+ def options(opt)
175
+ opt.on :v, :verbose, 'Print source around each breakpoint.'
176
+ end
177
+
178
+ def process
179
+ if Breakpoints.count > 0
180
+ if opts.verbose? # Long-form with source output
181
+ Breakpoints.each { |b| print_full_breakpoint(b) }
182
+ else # Simple table output
183
+ max_width = [Math.log10(Breakpoints.count).ceil, 1].max
184
+ header = "#{' ' * (max_width - 1)}# Enabled At "
185
+
186
+ output.puts
187
+ output.puts text.bold(header)
188
+ output.puts text.bold('-' * header.size)
189
+ Breakpoints.each do |breakpoint|
190
+ output.printf "%#{max_width}d ", breakpoint.id
191
+ output.print breakpoint.enabled? ? 'Yes ' : 'No '
192
+ output.print "#{breakpoint.source}:#{breakpoint.pos}"
193
+ output.print " (if #{breakpoint.expr})" if breakpoint.expr
194
+ output.puts
195
+ end
196
+ output.puts
197
+ end
198
+ else
199
+ output.puts text.bold('No breakpoints defined.')
200
+ end
201
+ end
202
+ end
203
+ alias_command 'breaks', 'breakpoints'
204
+
205
+
206
+ helpers do
207
+ def breakout_navigation(action, times = nil)
208
+ _pry_.binding_stack.clear # Clear the binding stack.
209
+ throw :breakout_nav, { # Break out of the REPL loop and
210
+ :action => action, # signal the tracer.
211
+ :times => times,
212
+ :pry => _pry_
213
+ }
214
+ end
215
+
216
+ # Ensures that a command is executed in a local file context.
217
+ def check_file_context
218
+ unless PryByebug.check_file_context(target)
219
+ raise Pry::CommandError, 'Cannot find local context. Did you use `binding.pry`?'
220
+ end
221
+ end
222
+
223
+ # Print out full information about a breakpoint including surrounding code
224
+ # at that point.
225
+ def print_full_breakpoint(breakpoint)
226
+ line = breakpoint.pos
227
+ output.print text.bold("Breakpoint #{breakpoint.id}: ")
228
+ output.print "#{breakpoint.source} @ line #{line} "
229
+ output.print breakpoint.enabled? ? '(Enabled)' : '(Disabled)'
230
+ output.puts ' :'
231
+ if (expr = breakpoint.expr)
232
+ output.puts "#{text.bold('Condition:')} #{expr}"
233
+ end
234
+ output.puts
235
+ output.puts Pry::Code.from_file(breakpoint.source).
236
+ around(line, 3).
237
+ with_line_numbers.
238
+ with_marker(line).to_s
239
+ output.puts
240
+ end
241
+ end
242
+ end
243
+ end
244
+
245
+ Pry.commands.import PryByebug::Commands
@@ -0,0 +1,149 @@
1
+ require 'pry'
2
+ require 'byebug'
3
+
4
+ module PryByebug
5
+ class Processor
6
+ attr_accessor :pry
7
+
8
+ def initialize
9
+ Byebug.handler = self
10
+ @always_enabled = true
11
+ @delayed = Hash.new(0)
12
+ end
13
+
14
+ # Wrap a Pry REPL to catch navigational commands and act on them.
15
+ def run(initial = true, &block)
16
+ return_value = nil
17
+ command = catch(:breakout_nav) do # Throws from PryByebug::Commands
18
+ return_value = yield
19
+ {} # Nothing thrown == no navigational command
20
+ end
21
+
22
+ times = (command[:times] || 1).to_i # Command argument
23
+ times = 1 if times <= 0
24
+
25
+ if [:step, :next, :finish].include? command[:action]
26
+ @pry = command[:pry] # Pry instance to resume after stepping
27
+ Byebug.start unless Byebug.started?
28
+
29
+ if initial
30
+ # Movement when on the initial binding.pry line will have a frame
31
+ # inside Byebug. If we step normally, it'll stop inside this
32
+ # Processor. So jump out and stop at the above frame, then step/next
33
+ # from our callback.
34
+ finish
35
+ @delayed[command[:action]] = times
36
+ end
37
+
38
+ if :next == command[:action]
39
+ step_over times
40
+
41
+ elsif :step == command[:action]
42
+ step times
43
+
44
+ elsif :finish == command[:action]
45
+ finish
46
+ end
47
+ else
48
+ stop
49
+ end
50
+
51
+ return_value
52
+ end
53
+
54
+ # Adjust debugging. When set to false, the Processor will manage enabling
55
+ # and disabling the debugger itself. When set to true, byebug is always
56
+ # enabled.
57
+ def debugging=(enabled)
58
+ if enabled
59
+ @always_enabled = true
60
+ Byebug.start unless Byebug.started?
61
+ else
62
+ @always_enabled = false
63
+ # Byebug will get stopped if necessary in `stop` once the repl ends.
64
+ end
65
+ end
66
+
67
+
68
+ # --- Callbacks from byebug C extension ---
69
+
70
+ def at_line(context, file, line)
71
+ # If stopped for a breakpoint or catchpoint, can't play any delayed steps
72
+ # as they'll move away from the interruption point. (Unsure if scenario is
73
+ # possible, but just keeping assertions in check.)
74
+ p "Stop_reason: #{context.stop_reason}"
75
+ @delayed = Hash.new(0) unless :step == context.stop_reason
76
+
77
+ if @delayed[:next] > 0 # If any delayed nexts/steps, do 'em.
78
+ step_over @delayed[:next]
79
+ @delayed = Hash.new(0)
80
+
81
+ elsif @delayed[:step] > 0
82
+ step @delayed[:step]
83
+ @delayed = Hash.new(0)
84
+
85
+ elsif @delayed[:finish] > 0
86
+ finish
87
+ @delayed = Hash.new(0)
88
+
89
+ else # Otherwise, resume the pry session at the stopped line.
90
+ resume_pry context
91
+ end
92
+ end
93
+
94
+ # Called when a breakpoint is triggered. Note: `at_line`` is called
95
+ # immediately after with the context's `stop_reason == :breakpoint`.
96
+ def at_breakpoint(context, breakpoint)
97
+ @pry.output.print Pry::Helpers::Text.bold("\nBreakpoint #{breakpoint.id}. ")
98
+ @pry.output.puts (breakpoint.hit_count == 1 ?
99
+ 'First hit.' :
100
+ "Hit #{breakpoint.hit_count} times." )
101
+ if (expr = breakpoint.expr)
102
+ @pry.output.print Pry::Helpers::Text.bold("Condition: ")
103
+ @pry.output.puts expr
104
+ end
105
+ end
106
+
107
+ def at_catchpoint(context, exception)
108
+ # TODO
109
+ end
110
+
111
+
112
+ private
113
+
114
+ # Resume an existing Pry REPL at the paused point. Binding extracted from
115
+ # the Byebug::Context.
116
+ def resume_pry(context)
117
+ new_binding = context.frame_binding(0)
118
+ Byebug.stop unless @always_enabled
119
+
120
+ @pry.binding_stack.clear
121
+ run(false) do
122
+ @pry.repl new_binding
123
+ end
124
+ end
125
+
126
+ # Move execution forward.
127
+ def step(times)
128
+ Byebug.context.step_into times
129
+ end
130
+
131
+ # Move execution forward a number of lines in the same frame.
132
+ def step_over(lines)
133
+ Byebug.context.step_over lines, 0
134
+ end
135
+
136
+ # Execute until specified frame returns.
137
+ def finish(frame = 0)
138
+ Byebug.context.step_out frame
139
+ end
140
+
141
+ # Cleanup when debugging is stopped and execution continues.
142
+ def stop
143
+ Byebug.stop if !@always_enabled && Byebug.started?
144
+ if PryByebug.current_remote_server # Cleanup DRb remote if running
145
+ PryByebug.current_remote_server.teardown
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,23 @@
1
+ require 'pry'
2
+ require 'pry-byebug/processor'
3
+
4
+ class << Pry
5
+ alias_method :start_without_pry_byebug, :start
6
+ attr_reader :processor
7
+
8
+ def start_with_pry_byebug(target = TOPLEVEL_BINDING, options = {})
9
+ @processor ||= PryByebug::Processor.new
10
+
11
+ if target.is_a?(Binding) && PryByebug.check_file_context(target)
12
+ # Wrap the processer around the usual Pry.start to catch navigation
13
+ # commands.
14
+ @processor.run(true) do
15
+ start_without_pry_byebug(target, options)
16
+ end
17
+ else
18
+ # No need for the tracer unless we have a file context to step through
19
+ start_without_pry_byebug(target, options)
20
+ end
21
+ end
22
+ alias_method :start, :start_with_pry_byebug
23
+ end
@@ -0,0 +1,41 @@
1
+ require 'pry-remote'
2
+
3
+ module PryRemote
4
+ class Server
5
+ # Override the call to Pry.start to save off current Server, and not
6
+ # teardown the server right after Pry.start finishes.
7
+ def run
8
+ if PryByebug.current_remote_server
9
+ raise 'Already running a pry-remote session!'
10
+ else
11
+ PryByebug.current_remote_server = self
12
+ end
13
+
14
+ setup
15
+ Pry.start @object, {
16
+ :input => client.input_proxy,
17
+ :output => client.output
18
+ }
19
+ end
20
+
21
+ # Override to reset our saved global current server session.
22
+ alias_method :teardown_without_pry_byebug, :teardown
23
+ def teardown_with_pry_byebug
24
+ return if @torn
25
+
26
+ teardown_without_pry_byebug
27
+ PryByebug.current_remote_server = nil
28
+ @torn = true
29
+ end
30
+ alias_method :teardown, :teardown_with_pry_byebug
31
+ end
32
+ end
33
+
34
+ # Ensure cleanup when a program finishes without another break. For example,
35
+ # 'next' on the last line of a program won't hit PryByebug::Processor#run,
36
+ # which normally handles cleanup.
37
+ at_exit do
38
+ if PryByebug.current_remote_server
39
+ PryByebug.current_remote_server.teardown
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module PryByebug
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/pry-byebug/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'pry-byebug'
7
+ gem.version = PryByebug::VERSION
8
+ gem.author = 'Gopal Patel'
9
+ gem.email = 'nixme@stillhope.com'
10
+ gem.license = 'MIT'
11
+ gem.homepage = 'https://github.com/deivid-rodriguez/pry-byebug'
12
+ gem.summary = 'Fast debugging with Pry.'
13
+ gem.description = "Combine 'pry' with 'byebug'. Adds 'step', 'next', and " \
14
+ "'continue' commands to control execution."
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 = '>= 2.0.0'
22
+ gem.add_runtime_dependency 'pry', '>= 0.9.10'
23
+ gem.add_runtime_dependency 'byebug', '~> 1.1.1'
24
+ gem.add_development_dependency 'bundler', '~> 1.3.5'
25
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-byebug
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gopal Patel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.5
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.5
55
+ description: Combine 'pry' with 'byebug'. Adds 'step', 'next', and 'continue' commands
56
+ to control execution.
57
+ email: nixme@stillhope.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .ruby-gemset
64
+ - CHANGELOG.md
65
+ - Gemfile
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - lib/pry-byebug.rb
70
+ - lib/pry-byebug/base.rb
71
+ - lib/pry-byebug/breakpoints.rb
72
+ - lib/pry-byebug/commands.rb
73
+ - lib/pry-byebug/processor.rb
74
+ - lib/pry-byebug/pry_ext.rb
75
+ - lib/pry-byebug/pry_remote_ext.rb
76
+ - lib/pry-byebug/version.rb
77
+ - pry-byebug.gemspec
78
+ homepage: https://github.com/deivid-rodriguez/pry-byebug
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: 2.0.0
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.0.3
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Fast debugging with Pry.
102
+ test_files: []