pry-debugger 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +7 -0
- data/README.md +102 -14
- data/lib/pry-debugger/breakpoints.rb +83 -0
- data/lib/pry-debugger/commands.rb +217 -11
- data/lib/pry-debugger/processor.rb +106 -26
- data/lib/pry-debugger/pry_ext.rb +5 -4
- data/lib/pry-debugger/pry_remote_ext.rb +3 -5
- data/lib/pry-debugger/version.rb +1 -1
- metadata +10 -24
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,10 +3,10 @@ pry-debugger
|
|
3
3
|
|
4
4
|
_Fast execution control in Pry_
|
5
5
|
|
6
|
-
Adds **step**, **next**, and **continue** commands
|
7
|
-
[debugger][debugger].
|
6
|
+
Adds **step**, **next**, **finish**, and **continue** commands and
|
7
|
+
**breakpoints** to [Pry][pry] using [debugger][debugger].
|
8
8
|
|
9
|
-
To use, invoke pry normally
|
9
|
+
To use, invoke pry normally. No need to start your script or app differently.
|
10
10
|
|
11
11
|
```ruby
|
12
12
|
def some_method
|
@@ -15,40 +15,128 @@ def some_method
|
|
15
15
|
end
|
16
16
|
```
|
17
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
|
+
|
18
71
|
**pry-debugger** is not yet thread-safe, so only use in single-threaded
|
19
72
|
environments.
|
20
73
|
|
21
|
-
Only supports MRI 1.9.2 and 1.9.3. For a pure
|
74
|
+
Only supports MRI 1.9.2 and 1.9.3. For a pure ruby approach not reliant on
|
22
75
|
[debugger][debugger], check out [pry-nav][pry-nav]. Note: *pry-nav* and
|
23
76
|
*pry-debugger* cannot be loaded together.
|
24
77
|
|
78
|
+
|
79
|
+
## Remote debugging
|
80
|
+
|
25
81
|
Support for [pry-remote][pry-remote] (>= 0.1.4) is also included. Requires
|
26
|
-
explicity requiring pry-
|
27
|
-
|
82
|
+
explicity requiring *pry-debugger*, 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:
|
28
86
|
|
29
87
|
```ruby
|
30
88
|
gem 'pry'
|
31
|
-
gem 'pry-
|
89
|
+
gem 'pry-remote'
|
90
|
+
gem 'pry-stack_explorer'
|
91
|
+
gem 'pry-debugger'
|
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
|
32
109
|
```
|
33
110
|
|
111
|
+
Using Pry with Rails? Check out [Jazz Hands][jazz_hands].
|
112
|
+
|
113
|
+
|
114
|
+
## Tips
|
115
|
+
|
34
116
|
Stepping through code often? Add the following shortcuts to `~/.pryrc`:
|
35
117
|
|
36
118
|
```ruby
|
37
119
|
Pry.commands.alias_command 'c', 'continue'
|
38
120
|
Pry.commands.alias_command 's', 'step'
|
39
121
|
Pry.commands.alias_command 'n', 'next'
|
122
|
+
Pry.commands.alias_command 'f', 'finish'
|
40
123
|
```
|
41
124
|
|
125
|
+
|
42
126
|
## Contributions
|
43
127
|
|
44
128
|
Patches and bug reports are welcome. Just send a [pull request][pullrequests] or
|
45
129
|
file an [issue][issues]. [Project changelog][changelog].
|
46
130
|
|
47
131
|
|
48
|
-
|
49
|
-
[
|
50
|
-
[
|
51
|
-
[pry-
|
52
|
-
[
|
53
|
-
[
|
54
|
-
[
|
132
|
+
|
133
|
+
[pry]: http://pry.github.com
|
134
|
+
[debugger]: https://github.com/cldwalker/debugger
|
135
|
+
[pry-stack_explorer]: https://github.com/pry/pry-stack_explorer
|
136
|
+
[pry-nav]: https://github.com/nixme/pry-nav
|
137
|
+
[pry-remote]: https://github.com/Mon-Ouie/pry-remote
|
138
|
+
[foreman]: https://github.com/ddollar/foreman
|
139
|
+
[jazz_hands]: https://github.com/nixme/jazz_hands
|
140
|
+
[pullrequests]: https://github.com/nixme/pry-debugger/pulls
|
141
|
+
[issues]: https://github.com/nixme/pry-debugger/issues
|
142
|
+
[changelog]: https://github.com/nixme/pry-debugger/blob/master/CHANGELOG.md
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module PryDebugger
|
2
|
+
|
3
|
+
# Wrapper for Debugger.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
|
+
|
11
|
+
# Add a new breakpoint.
|
12
|
+
def add(file, line, expression = nil)
|
13
|
+
raise ArgumentError, 'Invalid file!' unless File.exist?(file)
|
14
|
+
Pry.processor.debugging = true
|
15
|
+
Debugger.add_breakpoint(File.expand_path(file), line, expression)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Change the conditional expression for a breakpoint.
|
19
|
+
def change(id, expression = nil)
|
20
|
+
breakpoint = find_by_id(id)
|
21
|
+
breakpoint.expr = expression
|
22
|
+
breakpoint
|
23
|
+
end
|
24
|
+
|
25
|
+
# Delete an existing breakpoint with the given ID.
|
26
|
+
def delete(id)
|
27
|
+
unless Debugger.started? && Debugger.remove_breakpoint(id)
|
28
|
+
raise ArgumentError, "No breakpoint ##{id}"
|
29
|
+
end
|
30
|
+
Pry.processor.debugging = false if to_a.empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
# Delete all breakpoints.
|
34
|
+
def clear
|
35
|
+
Debugger.breakpoints.clear if Debugger.started?
|
36
|
+
Pry.processor.debugging = false
|
37
|
+
end
|
38
|
+
|
39
|
+
# Enable a disabled breakpoint with the given ID.
|
40
|
+
def enable(id)
|
41
|
+
change_status id, true
|
42
|
+
end
|
43
|
+
|
44
|
+
# Disable a breakpoint with the given ID.
|
45
|
+
def disable(id)
|
46
|
+
change_status id, false
|
47
|
+
end
|
48
|
+
|
49
|
+
# Disable all breakpoints.
|
50
|
+
def disable_all
|
51
|
+
each do |breakpoint|
|
52
|
+
breakpoint.enabled = false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_a
|
57
|
+
Debugger.started? ? Debugger.breakpoints : []
|
58
|
+
end
|
59
|
+
|
60
|
+
def size
|
61
|
+
to_a.size
|
62
|
+
end
|
63
|
+
|
64
|
+
def each(&block)
|
65
|
+
to_a.each(&block)
|
66
|
+
end
|
67
|
+
|
68
|
+
def find_by_id(id)
|
69
|
+
breakpoint = find { |b| b.id == id }
|
70
|
+
raise ArgumentError, "No breakpoint ##{id}!" unless breakpoint
|
71
|
+
breakpoint
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def change_status(id, enabled = true)
|
78
|
+
breakpoint = find_by_id(id)
|
79
|
+
breakpoint.enabled = enabled
|
80
|
+
breakpoint
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -1,28 +1,215 @@
|
|
1
1
|
require 'pry'
|
2
|
+
require 'pry-debugger/breakpoints'
|
2
3
|
|
3
4
|
module PryDebugger
|
4
5
|
Commands = Pry::CommandSet.new do
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
8
46
|
end
|
9
47
|
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
13
56
|
end
|
14
57
|
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
18
66
|
end
|
19
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 PryDebugger.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
|
+
|
20
206
|
helpers do
|
21
|
-
def breakout_navigation(action, times)
|
207
|
+
def breakout_navigation(action, times = nil)
|
22
208
|
_pry_.binding_stack.clear # Clear the binding stack.
|
23
209
|
throw :breakout_nav, { # Break out of the REPL loop and
|
24
210
|
:action => action, # signal the tracer.
|
25
|
-
:times
|
211
|
+
:times => times,
|
212
|
+
:pry => _pry_
|
26
213
|
}
|
27
214
|
end
|
28
215
|
|
@@ -32,6 +219,25 @@ module PryDebugger
|
|
32
219
|
raise Pry::CommandError, 'Cannot find local context. Did you use `binding.pry`?'
|
33
220
|
end
|
34
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
|
35
241
|
end
|
36
242
|
end
|
37
243
|
end
|
@@ -3,12 +3,16 @@ require 'debugger'
|
|
3
3
|
|
4
4
|
module PryDebugger
|
5
5
|
class Processor
|
6
|
-
|
6
|
+
attr_accessor :pry
|
7
|
+
|
8
|
+
def initialize
|
7
9
|
Debugger.handler = self
|
8
|
-
@
|
10
|
+
@always_enabled = false
|
11
|
+
@delayed = Hash.new(0)
|
9
12
|
end
|
10
13
|
|
11
|
-
|
14
|
+
# Wrap a Pry REPL to catch navigational commands and act on them.
|
15
|
+
def run(initial = true, &block)
|
12
16
|
return_value = nil
|
13
17
|
command = catch(:breakout_nav) do # Throws from PryDebugger::Commands
|
14
18
|
return_value = yield
|
@@ -18,41 +22,86 @@ module PryDebugger
|
|
18
22
|
times = (command[:times] || 1).to_i # Command argument
|
19
23
|
times = 1 if times <= 0
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
if
|
26
|
-
#
|
27
|
-
# step normally, it'll stop inside this
|
28
|
-
# out
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
25
|
+
if [:step, :next, :finish].include? command[:action]
|
26
|
+
@pry = command[:pry] # Pry instance to resume after stepping
|
27
|
+
Debugger.start unless Debugger.started?
|
28
|
+
|
29
|
+
if initial
|
30
|
+
# Movement when on the initial binding.pry line will have a frame
|
31
|
+
# inside Debugger. 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
|
+
Debugger.current_context.stop_frame = 1
|
35
|
+
@delayed[command[:action]] = times
|
36
|
+
|
37
|
+
elsif :next == command[:action]
|
38
|
+
step_over times
|
39
|
+
|
40
|
+
elsif :step == command[:action]
|
41
|
+
step times
|
42
|
+
|
43
|
+
elsif :finish == command[:action]
|
44
|
+
finish
|
38
45
|
end
|
39
|
-
|
40
|
-
|
46
|
+
else
|
47
|
+
stop
|
41
48
|
end
|
42
49
|
|
43
50
|
return_value
|
44
51
|
end
|
45
52
|
|
53
|
+
# Adjust debugging. When set to false, the Processor will manage enabling
|
54
|
+
# and disabling the debugger itself. When set to true, the debugger is
|
55
|
+
# always enabled.
|
56
|
+
def debugging=(enabled)
|
57
|
+
if enabled
|
58
|
+
@always_enabled = true
|
59
|
+
Debugger.start unless Debugger.started?
|
60
|
+
else
|
61
|
+
@always_enabled = false
|
62
|
+
# Debugger will get stopped if necessary in `stop` once the repl ends.
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
46
66
|
|
47
67
|
# --- Callbacks from debugger C extension ---
|
48
68
|
|
49
69
|
def at_line(context, file, line)
|
50
70
|
return if file && TRACE_IGNORE_FILES.include?(File.expand_path(file))
|
51
|
-
|
71
|
+
|
72
|
+
# If stopped for a breakpoint or catchpoint, can't play any delayed steps
|
73
|
+
# as they'll move away from the interruption point. (Unsure if scenario is
|
74
|
+
# possible, but just keeping assertions in check.)
|
75
|
+
@delayed = Hash.new(0) unless :step == context.stop_reason
|
76
|
+
|
77
|
+
if @delayed[:next] > 1 # If any delayed nexts/steps, do 'em.
|
78
|
+
step_over @delayed[:next] - 1
|
79
|
+
@delayed = Hash.new(0)
|
80
|
+
|
81
|
+
elsif @delayed[:step] > 1
|
82
|
+
step @delayed[:step] - 1
|
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
|
52
92
|
end
|
53
93
|
|
94
|
+
# Called when a breakpoint is triggered. Note: `at_line`` is called
|
95
|
+
# immediately after with the context's `stop_reason == :breakpoint`.
|
54
96
|
def at_breakpoint(context, breakpoint)
|
55
|
-
#
|
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
|
56
105
|
end
|
57
106
|
|
58
107
|
def at_catchpoint(context, exception)
|
@@ -62,8 +111,39 @@ module PryDebugger
|
|
62
111
|
|
63
112
|
private
|
64
113
|
|
65
|
-
|
66
|
-
|
114
|
+
# Resume an existing Pry REPL at the paused point. Binding extracted from
|
115
|
+
# the Debugger::Context.
|
116
|
+
def resume_pry(context)
|
117
|
+
new_binding = context.frame_binding(0)
|
118
|
+
Debugger.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
|
+
Debugger.current_context.step(times)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Move execution forward a number of lines in the same frame.
|
132
|
+
def step_over(lines)
|
133
|
+
Debugger.current_context.step_over(lines, 0)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Execute until current frame returns.
|
137
|
+
def finish
|
138
|
+
Debugger.current_context.stop_frame = 0
|
139
|
+
end
|
140
|
+
|
141
|
+
# Cleanup when debugging is stopped and execution continues.
|
142
|
+
def stop
|
143
|
+
Debugger.stop if !@always_enabled && Debugger.started?
|
144
|
+
if PryDebugger.current_remote_server # Cleanup DRb remote if running
|
145
|
+
PryDebugger.current_remote_server.teardown
|
146
|
+
end
|
67
147
|
end
|
68
148
|
end
|
69
149
|
end
|
data/lib/pry-debugger/pry_ext.rb
CHANGED
@@ -3,19 +3,20 @@ require 'pry-debugger/processor'
|
|
3
3
|
|
4
4
|
class << Pry
|
5
5
|
alias_method :start_existing, :start
|
6
|
+
attr_reader :processor
|
6
7
|
|
7
8
|
def start(target = TOPLEVEL_BINDING, options = {})
|
8
|
-
|
9
|
+
@processor ||= PryDebugger::Processor.new
|
9
10
|
|
10
11
|
if target.is_a?(Binding) && PryDebugger.check_file_context(target)
|
11
12
|
# Wrap the processer around the usual Pry.start to catch navigation
|
12
13
|
# commands.
|
13
|
-
|
14
|
-
start_existing(target,
|
14
|
+
@processor.run(true) do
|
15
|
+
start_existing(target, options)
|
15
16
|
end
|
16
17
|
else
|
17
18
|
# No need for the tracer unless we have a file context to step through
|
18
|
-
start_existing(target,
|
19
|
+
start_existing(target, options)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
@@ -2,9 +2,8 @@ require 'pry-remote'
|
|
2
2
|
|
3
3
|
module PryRemote
|
4
4
|
class Server
|
5
|
-
# Override the call to Pry.start to save off current Server,
|
6
|
-
#
|
7
|
-
# kill the server right away.
|
5
|
+
# Override the call to Pry.start to save off current Server, and not
|
6
|
+
# teardown the server right after Pry.start finishes.
|
8
7
|
def run
|
9
8
|
if PryDebugger.current_remote_server
|
10
9
|
raise 'Already running a pry-remote session!'
|
@@ -15,8 +14,7 @@ module PryRemote
|
|
15
14
|
setup
|
16
15
|
Pry.start @object, {
|
17
16
|
:input => client.input_proxy,
|
18
|
-
:output => client.output
|
19
|
-
:pry_remote => true
|
17
|
+
:output => client.output
|
20
18
|
}
|
21
19
|
end
|
22
20
|
|
data/lib/pry-debugger/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-debugger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
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: 2012-06-
|
12
|
+
date: 2012-06-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70204822544220 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,15 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.9.9
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.9.9
|
24
|
+
version_requirements: *70204822544220
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: debugger
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &70204822543060 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
30
|
- - ~>
|
@@ -37,15 +32,10 @@ dependencies:
|
|
37
32
|
version: 1.1.3
|
38
33
|
type: :runtime
|
39
34
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.1.3
|
35
|
+
version_requirements: *70204822543060
|
46
36
|
- !ruby/object:Gem::Dependency
|
47
37
|
name: pry-remote
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &70204822541940 !ruby/object:Gem::Requirement
|
49
39
|
none: false
|
50
40
|
requirements:
|
51
41
|
- - ~>
|
@@ -53,12 +43,7 @@ dependencies:
|
|
53
43
|
version: 0.1.4
|
54
44
|
type: :development
|
55
45
|
prerelease: false
|
56
|
-
version_requirements:
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.1.4
|
46
|
+
version_requirements: *70204822541940
|
62
47
|
description: Combine 'pry' with 'debugger'. Adds 'step', 'next', and 'continue' commands
|
63
48
|
to control execution.
|
64
49
|
email: nixme@stillhope.com
|
@@ -74,6 +59,7 @@ files:
|
|
74
59
|
- Rakefile
|
75
60
|
- lib/pry-debugger.rb
|
76
61
|
- lib/pry-debugger/base.rb
|
62
|
+
- lib/pry-debugger/breakpoints.rb
|
77
63
|
- lib/pry-debugger/cli.rb
|
78
64
|
- lib/pry-debugger/commands.rb
|
79
65
|
- lib/pry-debugger/processor.rb
|
@@ -102,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
88
|
version: '0'
|
103
89
|
requirements: []
|
104
90
|
rubyforge_project:
|
105
|
-
rubygems_version: 1.8.
|
91
|
+
rubygems_version: 1.8.11
|
106
92
|
signing_key:
|
107
93
|
specification_version: 3
|
108
94
|
summary: Fast debugging with Pry.
|