pry-debugger-jruby 1.0.0-java

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: 81ff16ce021c8e8175681bf7680c0aaf3265d74e
4
+ data.tar.gz: 7a8faa1b0040ae47666c530080924cff69541c5e
5
+ SHA512:
6
+ metadata.gz: 4226ab1696b4932d899e25b5886ced67d816c42b4531fff5ea488a23652a02ac083522b212dc8684f055113452d405872f18abf4c3338aa04eb6c341cd821e3f
7
+ data.tar.gz: 7e13eee633369b8f0ed1745e5a934ee45b5406c6c9f3c9acd055180b4ef46877f4038f1bc8adfbdd17cf68a76a4d5c0a84c255426074cb5f08050cf2efecab45
@@ -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 @@
1
+ jruby-9.1.5.0
@@ -0,0 +1,41 @@
1
+ ## 1.0.0 (2016-12-01)
2
+
3
+ * Revamp documentation for JRuby usage
4
+ * Add workaround for using `step` in JRuby
5
+ * Fix circular require warning
6
+ * Fixed missing banner in commands causing uninitialized variable warning
7
+ * Drop support for ruby < 2.2
8
+ * Officially forked from `pry-debugger`, renaming gem to `pry-debugger-jruby` and releasing on RubyGems
9
+
10
+ ## 0.2.3 (2014-07-02)
11
+
12
+ * Support [pry] 0.10
13
+
14
+ ## 0.2.2 (2013-03-07)
15
+
16
+ * Relaxed [debugger][debugger] dependency.
17
+
18
+ ## 0.2.1 (2012-12-26)
19
+
20
+ * Support breakpoints on methods defined in the pry console. (@banister)
21
+ * Fix support for specifying breakpoints by *file:line_number*. (@nviennot)
22
+ * Validate breakpoint conditionals are real Ruby expressions.
23
+ * Support for [debugger][debugger] ~> 1.2.0. (@jshou)
24
+ * Safer `alias_method_chain`-style patching of `Pry.start` and
25
+ `PryRemote::Server#teardown`. (@benizi)
26
+
27
+ ## 0.2.0 (2012-06-11)
28
+
29
+ * Breakpoints
30
+ * **finish** command
31
+ * Internal cleanup and bug fixes
32
+
33
+ ## 0.1.0 (2012-06-07)
34
+
35
+ * First release. **step**, **next**, and **continue** commands.
36
+ [pry-remote 0.1.4][pry-remote] support.
37
+
38
+
39
+ [pry]: http://pryrepl.org/
40
+ [pry-remote]: https://github.com/Mon-Ouie/pry-remote
41
+ [debugger]: https://github.com/cldwalker/debugger
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT/Expat License
2
+
3
+ Copyright (c) 2016 by Ivo Anjo
4
+ Copyright (c) 2012 by Gopal Patel
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ the Software, and to permit persons to whom the Software is furnished to do so,
11
+ subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,111 @@
1
+ # pry-debugger-jruby
2
+
3
+ _JRuby 9k-compatible pry debugging!_
4
+
5
+ Using MRI? I strongly recommend [`pry-byebug`](https://github.com/deivid-rodriguez/pry-byebug) instead!
6
+
7
+ Adds `step`, `next`, `finish`, and `continue` commands and `breakpoints` to [Pry](http://pry.github.com).
8
+
9
+ To use, run JRuby with the `--debug` flag, and then 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
+ You can also add the `--debug` flag to your `JRUBY_OPTS` environment variable, so it will be picked up by any ruby application. Do note that running `JRuby` in debug mode **does** have a noticeable impact on performance.
19
+
20
+ ## Execution Commands
21
+
22
+ * `step`: Step execution into the next line or method. Takes an optional numeric argument to step multiple times.
23
+
24
+ * `next`: Step over to the next line within the same frame. Also takes an optional numeric argument to step multiple lines.
25
+
26
+ * `finish`: Execute until current stack frame returns.
27
+
28
+ * `continue`: Continue program execution and end the Pry session.
29
+
30
+ ## Breakpoints
31
+
32
+ You can set and adjust breakpoints directly from a Pry session using the following commands:
33
+
34
+ * `break`: Set a new breakpoint from a line number in the current file, a file and line number, or a method. Pass an optional expression to create a conditional breakpoint. Edit existing breakpoints via various flags.
35
+
36
+ Examples:
37
+
38
+ ```ruby
39
+ break SomeClass#run Break at the start of `SomeClass#run`.
40
+ break Foo#bar if baz? Break at `Foo#bar` only if `baz?`.
41
+ break app/models/user.rb:15 Break at line 15 in user.rb.
42
+ break 14 Break at line 14 in the current file.
43
+
44
+ break --condition 4 x > 2 Change condition on breakpoint #4 to 'x > 2'.
45
+ break --condition 3 Remove the condition on breakpoint #3.
46
+
47
+ break --delete 5 Delete breakpoint #5.
48
+ break --disable-all Disable all breakpoints.
49
+
50
+ break List all breakpoints. (Same as `breakpoints`)
51
+ break --show 2 Show details about breakpoint #2.
52
+ ```
53
+
54
+ Type `break --help` from a Pry session to see all available options.
55
+
56
+ * `breakpoints`: List all defined breakpoints. Pass `-v` or `--verbose` to see the source code around each breakpoint.
57
+
58
+ ## Remote debugging
59
+
60
+ Support for [pry-remote](https://github.com/Mon-Ouie/pry-remote) is also included. Requires explicity requiring `pry-debugger-jruby`, not just relying on pry's plugin loader.
61
+
62
+ Want to debug a Rails app running inside `foreman`? Add to your `Gemfile`:
63
+
64
+ ```ruby
65
+ gem 'pry'
66
+ gem 'pry-remote'
67
+ gem 'pry-debugger-jruby'
68
+ ```
69
+
70
+ Then add `binding.remote_pry` where you want to pause:
71
+
72
+ ```ruby
73
+ class UsersController < ApplicationController
74
+ def index
75
+ binding.remote_pry
76
+ # ...
77
+ end
78
+ end
79
+ ```
80
+
81
+ Load a page that triggers the code. Connect to the session:
82
+
83
+ ```bash
84
+ $ bundle exec pry-remote
85
+ ```
86
+
87
+ ## Tips
88
+
89
+ Stepping through code often? Add the following shortcuts to `~/.pryrc`:
90
+
91
+ ```ruby
92
+ if defined?(PryDebuggerJRuby)
93
+ Pry.commands.alias_command 'c', 'continue'
94
+ Pry.commands.alias_command 's', 'step'
95
+ Pry.commands.alias_command 'n', 'next'
96
+ Pry.commands.alias_command 'f', 'finish'
97
+ end
98
+ ```
99
+
100
+ ## Contributors
101
+
102
+ `pry-debugger-jruby` is maintained by [@ivoanjo](https://github.com/ivoanjo/) and is based off the awesome previous work from the [`pry-debugger`](https://github.com/nixme/pry-debugger) creators:
103
+
104
+ * Gopal Patel (@nixme)
105
+ * John Mair (@banister)
106
+ * Nicolas Viennot (@nviennot)
107
+ * Benjamin R. Haskell (@benizi)
108
+ * Joshua Hou (@jshou)
109
+ * ...and others who helped with [`pry-nav`](https://github.com/nixme/pry-nav)
110
+
111
+ Patches and bug reports are welcome. Just send in a pull request or issue :)
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,8 @@
1
+ require 'pry-debugger-jruby/cli'
2
+ require 'pry-debugger-jruby/version'
3
+
4
+ # Load pry-remote monkey patches if pry-remote's available
5
+ begin
6
+ require 'pry-debugger-jruby/pry_remote_ext'
7
+ rescue LoadError
8
+ end
@@ -0,0 +1,15 @@
1
+ module PryDebuggerJRuby
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,94 @@
1
+ module PryDebuggerJRuby
2
+ # Wrapper for Debugger.breakpoints that respects our Processor and has better
3
+ # failure behavior. Acts as an Enumerable.
4
+ #
5
+ module Breakpoints
6
+ extend Enumerable
7
+ extend self
8
+
9
+ # Add a new breakpoint.
10
+ def add(file, line, expression = nil)
11
+ real_file = (file != Pry.eval_path)
12
+ raise ArgumentError, 'Invalid file!' if real_file && !File.exist?(file)
13
+ validate_expression expression
14
+
15
+ Pry.processor.debugging = true
16
+
17
+ path = (real_file ? File.expand_path(file) : file)
18
+ Debugger.add_breakpoint(path, line, expression)
19
+ end
20
+
21
+ # Change the conditional expression for a breakpoint.
22
+ def change(id, expression = nil)
23
+ validate_expression expression
24
+
25
+ breakpoint = find_by_id(id)
26
+ breakpoint.expr = expression
27
+ breakpoint
28
+ end
29
+
30
+ # Delete an existing breakpoint with the given ID.
31
+ def delete(id)
32
+ unless Debugger.started? && Debugger.remove_breakpoint(id)
33
+ raise ArgumentError, "No breakpoint ##{id}"
34
+ end
35
+ Pry.processor.debugging = false if to_a.empty?
36
+ end
37
+
38
+ # Delete all breakpoints.
39
+ def clear
40
+ Debugger.breakpoints.clear if Debugger.started?
41
+ Pry.processor.debugging = false
42
+ end
43
+
44
+ # Enable a disabled breakpoint with the given ID.
45
+ def enable(id)
46
+ change_status id, true
47
+ end
48
+
49
+ # Disable a breakpoint with the given ID.
50
+ def disable(id)
51
+ change_status id, false
52
+ end
53
+
54
+ # Disable all breakpoints.
55
+ def disable_all
56
+ each do |breakpoint|
57
+ breakpoint.enabled = false
58
+ end
59
+ end
60
+
61
+ def to_a
62
+ Debugger.started? ? Debugger.breakpoints : []
63
+ end
64
+
65
+ def size
66
+ to_a.size
67
+ end
68
+
69
+ def each(&block)
70
+ to_a.each(&block)
71
+ end
72
+
73
+ def find_by_id(id)
74
+ breakpoint = find { |b| b.id == id }
75
+ raise ArgumentError, "No breakpoint ##{id}!" unless breakpoint
76
+ breakpoint
77
+ end
78
+
79
+ private
80
+
81
+ def change_status(id, enabled = true)
82
+ breakpoint = find_by_id(id)
83
+ breakpoint.enabled = enabled
84
+ breakpoint
85
+ end
86
+
87
+ def validate_expression(expression)
88
+ if expression && # `nil` implies no expression given, so pass
89
+ (expression.empty? || !Pry::Code.complete_expression?(expression))
90
+ raise "Invalid breakpoint conditional: #{expression}"
91
+ end
92
+ end
93
+ end
94
+ 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-jruby.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-jruby'
9
+ #
10
+ # Load everything else here.
11
+ #
12
+
13
+ require 'pry-debugger-jruby/base'
14
+ require 'pry-debugger-jruby/pry_ext'
15
+ require 'pry-debugger-jruby/commands'
@@ -0,0 +1,252 @@
1
+ require 'pry' unless defined? Pry
2
+ require 'pry-debugger-jruby/breakpoints'
3
+
4
+ module PryDebuggerJRuby
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
+ create_command 'next' do
27
+ description 'Execute the next line within the current stack frame.'
28
+
29
+ banner <<-BANNER
30
+ Usage: next [LINES]
31
+
32
+ Step over within the same frame. By default, moves forward a single
33
+ line.
34
+
35
+ Examples:
36
+
37
+ next Move a single line forward.
38
+ next 4 Execute the next 4 lines.
39
+ BANNER
40
+
41
+ def process
42
+ check_file_context
43
+ breakout_navigation :next, args.first
44
+ end
45
+ end
46
+
47
+ create_command 'finish' do
48
+ description 'Execute until current stack frame returns.'
49
+
50
+ banner <<-BANNER
51
+ Usage: finish
52
+
53
+ Execute until current stack frame returns.
54
+ BANNER
55
+
56
+ def process
57
+ check_file_context
58
+ breakout_navigation :finish
59
+ end
60
+ end
61
+
62
+ create_command 'continue' do
63
+ description 'End the Pry session and continue program execution.'
64
+
65
+ banner <<-BANNER
66
+ Usage: finish
67
+
68
+ End the Pry session and continue program execution.
69
+ BANNER
70
+
71
+ def process
72
+ check_file_context
73
+ run 'exit-all'
74
+ end
75
+ end
76
+
77
+ create_command 'break' do
78
+ description 'Set or edit a breakpoint.'
79
+
80
+ banner <<-BANNER
81
+ Usage: break <METHOD | FILE:LINE | LINE> [if CONDITION]
82
+ break --condition N [CONDITION]
83
+ break [--show | --delete | --enable | --disable] N
84
+ break [--delete-all | --disable-all]
85
+ Aliases: breakpoint
86
+
87
+ Set a breakpoint. Accepts a line number in the current file, a file and
88
+ line number, or a method, and an optional condition.
89
+
90
+ Pass appropriate flags to manipulate existing breakpoints.
91
+
92
+ Examples:
93
+
94
+ break SomeClass#run Break at the start of `SomeClass#run`.
95
+ break Foo#bar if baz? Break at `Foo#bar` only if `baz?`.
96
+ break app/models/user.rb:15 Break at line 15 in user.rb.
97
+ break 14 Break at line 14 in the current file.
98
+
99
+ break --condition 4 x > 2 Add/change condition on breakpoint #4.
100
+ break --condition 3 Remove the condition on breakpoint #3.
101
+
102
+ break --delete 5 Delete breakpoint #5.
103
+ break --disable-all Disable all breakpoints.
104
+
105
+ break List all breakpoints. (Same as `breakpoints`)
106
+ break --show 2 Show details about breakpoint #2.
107
+ BANNER
108
+
109
+ def options(opt)
110
+ opt.on :c, :condition, 'Change the condition of a breakpoint.', argument: true, as: Integer
111
+ opt.on :s, :show, 'Show breakpoint details and source.', argument: true, as: Integer
112
+ opt.on :D, :delete, 'Delete a breakpoint.', argument: true, as: Integer
113
+ opt.on :d, :disable, 'Disable a breakpoint.', argument: true, as: Integer
114
+ opt.on :e, :enable, 'Enable a disabled breakpoint.', argument: true, as: Integer
115
+ opt.on :'disable-all', 'Disable all breakpoints.'
116
+ opt.on :'delete-all', 'Delete all breakpoints.'
117
+ method_options(opt)
118
+ end
119
+
120
+ def process
121
+ Pry.processor.pry = _pry_
122
+
123
+ {
124
+ delete: :delete,
125
+ disable: :disable,
126
+ enable: :enable,
127
+ 'disable-all': :disable_all,
128
+ 'delete-all': :clear,
129
+ }.each do |action, method|
130
+ if opts.present?(action)
131
+ Breakpoints.__send__ method, *(method == action ? [opts[action]] : [])
132
+ return run 'breakpoints'
133
+ end
134
+ end
135
+
136
+ if opts.present?(:condition)
137
+ Breakpoints.change(opts[:condition], args.empty? ? nil : args.join(' '))
138
+ run 'breakpoints'
139
+ elsif opts.present?(:show)
140
+ print_full_breakpoint Breakpoints.find_by_id(opts[:show])
141
+ elsif args.empty?
142
+ run 'breakpoints'
143
+ else
144
+ new_breakpoint
145
+ end
146
+ end
147
+
148
+ def new_breakpoint
149
+ place = args.shift
150
+ condition = args.join(' ') if 'if' == args.shift
151
+
152
+ file, line =
153
+ case place
154
+ when /^(\d+)$/ # Line number only
155
+ line = $1
156
+ unless PryDebuggerJRuby.check_file_context(target)
157
+ raise ArgumentError, 'Line number declaration valid only in a file context.'
158
+ end
159
+ [target.eval('__FILE__'), line]
160
+ when /^(.+):(\d+)$/ # File and line number
161
+ [$1, $2]
162
+ else # Method or class name
163
+ self.args = [place]
164
+ method_object.source_location
165
+ end
166
+
167
+ print_full_breakpoint Breakpoints.add(file, line.to_i, condition)
168
+ end
169
+ end
170
+ alias_command 'breakpoint', 'break'
171
+
172
+ create_command 'breakpoints' do
173
+ description 'List defined breakpoints.'
174
+
175
+ banner <<-BANNER
176
+ Usage: breakpoints [OPTIONS]
177
+ Aliases: breaks
178
+
179
+ List registered breakpoints and their current status.
180
+ BANNER
181
+
182
+ def options(opt)
183
+ opt.on :v, :verbose, 'Print source around each breakpoint.'
184
+ end
185
+
186
+ def process
187
+ if Breakpoints.count > 0
188
+ if opts.verbose? # Long-form with source output
189
+ Breakpoints.each { |b| print_full_breakpoint(b) }
190
+ else # Simple table output
191
+ max_width = [Math.log10(Breakpoints.count).ceil, 1].max
192
+ header = "#{' ' * (max_width - 1)}# Enabled At "
193
+
194
+ output.puts
195
+ output.puts text.bold(header)
196
+ output.puts text.bold('-' * header.size)
197
+ Breakpoints.each do |breakpoint|
198
+ output.printf "%#{max_width}d ", breakpoint.id
199
+ output.print breakpoint.enabled? ? 'Yes ' : 'No '
200
+ output.print "#{breakpoint.source}:#{breakpoint.pos}"
201
+ output.print " (if #{breakpoint.expr})" if breakpoint.expr
202
+ output.puts
203
+ end
204
+ output.puts
205
+ end
206
+ else
207
+ output.puts text.bold('No breakpoints defined.')
208
+ end
209
+ end
210
+ end
211
+ alias_command 'breaks', 'breakpoints'
212
+
213
+ helpers do
214
+ def breakout_navigation(action, times = nil)
215
+ _pry_.binding_stack.clear # Clear the binding stack
216
+ throw :breakout_nav, { # Break out of the REPL loop and
217
+ action: action, # signal the tracer
218
+ times: times,
219
+ pry: _pry_,
220
+ }
221
+ end
222
+
223
+ # Ensures that a command is executed in a local file context.
224
+ def check_file_context
225
+ unless PryDebuggerJRuby.check_file_context(target)
226
+ raise Pry::CommandError, 'Cannot find local context. Did you use `binding.pry`?'
227
+ end
228
+ end
229
+
230
+ # Print out full information about a breakpoint including surrounding code
231
+ # at that point.
232
+ def print_full_breakpoint(breakpoint)
233
+ line = breakpoint.pos
234
+ output.print text.bold("Breakpoint #{breakpoint.id}: ")
235
+ output.print "#{breakpoint.source} @ line #{line} "
236
+ output.print breakpoint.enabled? ? '(Enabled)' : '(Disabled)'
237
+ output.puts ' :'
238
+ if (expr = breakpoint.expr)
239
+ output.puts "#{text.bold('Condition:')} #{expr}"
240
+ end
241
+ output.puts
242
+ output.puts(
243
+ Pry::Code.from_file(breakpoint.source)
244
+ .around(line, 3).with_line_numbers.with_marker(line).to_s
245
+ )
246
+ output.puts
247
+ end
248
+ end
249
+ end
250
+ end
251
+
252
+ Pry.commands.import PryDebuggerJRuby::Commands
@@ -0,0 +1,147 @@
1
+ require 'pry' unless defined? Pry
2
+ require 'ruby-debug-base'
3
+
4
+ module PryDebuggerJRuby
5
+ class Processor
6
+ attr_accessor :pry
7
+
8
+ def initialize
9
+ Debugger.handler = self
10
+ @always_enabled = true # FIXME: JRuby workaround
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)
16
+ return_value = nil
17
+ command = catch(:breakout_nav) do # Throws from PryDebuggerJRuby::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
+ 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
45
+ end
46
+ else
47
+ stop
48
+ end
49
+
50
+ return_value
51
+ end
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
+
66
+ # --- Callbacks from debugger C extension ---
67
+
68
+ def at_line(context, file, _line)
69
+ return if file && TRACE_IGNORE_FILES.include?(File.expand_path(file))
70
+
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
+ @delayed = Hash.new(0) unless :step == context.stop_reason
75
+
76
+ if @delayed[:next] > 1 # If any delayed nexts/steps, do 'em.
77
+ step_over @delayed[:next] - 1
78
+ @delayed = Hash.new(0)
79
+
80
+ elsif @delayed[:step] > 1
81
+ step @delayed[:step] - 1
82
+ @delayed = Hash.new(0)
83
+
84
+ elsif @delayed[:finish] > 0
85
+ finish
86
+ @delayed = Hash.new(0)
87
+
88
+ else # Otherwise, resume the pry session at the stopped line.
89
+ resume_pry context
90
+ end
91
+ end
92
+
93
+ # Called when a breakpoint is triggered. Note: `at_line`` is called
94
+ # immediately after with the context's `stop_reason == :breakpoint`.
95
+ def at_breakpoint(_context, breakpoint)
96
+ @pry.output.print Pry::Helpers::Text.bold("\nBreakpoint #{breakpoint.id}. ")
97
+ @pry.output.puts (breakpoint.hit_count == 1 ?
98
+ 'First hit.' :
99
+ "Hit #{breakpoint.hit_count} times.")
100
+ if (expr = breakpoint.expr)
101
+ @pry.output.print Pry::Helpers::Text.bold('Condition: ')
102
+ @pry.output.puts expr
103
+ end
104
+ end
105
+
106
+ def at_catchpoint(context, exception)
107
+ # TODO
108
+ end
109
+
110
+ private
111
+
112
+ # Resume an existing Pry REPL at the paused point. Binding extracted from
113
+ # the Debugger::Context.
114
+ def resume_pry(context)
115
+ new_binding = context.frame_binding(0)
116
+ Debugger.stop unless @always_enabled
117
+
118
+ @pry.binding_stack.clear
119
+ run(false) do
120
+ @pry.repl new_binding
121
+ end
122
+ end
123
+
124
+ # Move execution forward.
125
+ def step(times)
126
+ Debugger.current_context.step(times)
127
+ end
128
+
129
+ # Move execution forward a number of lines in the same frame.
130
+ def step_over(lines)
131
+ Debugger.current_context.step_over(lines, 0)
132
+ end
133
+
134
+ # Execute until current frame returns.
135
+ def finish
136
+ Debugger.current_context.stop_frame = 0
137
+ end
138
+
139
+ # Cleanup when debugging is stopped and execution continues.
140
+ def stop
141
+ Debugger.stop if !@always_enabled && Debugger.started?
142
+ if PryDebuggerJRuby.current_remote_server # Cleanup DRb remote if running
143
+ PryDebuggerJRuby.current_remote_server.teardown
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,23 @@
1
+ require 'pry' unless defined? Pry
2
+ require 'pry-debugger-jruby/processor'
3
+
4
+ class << Pry
5
+ alias start_without_pry_debugger start
6
+ attr_reader :processor
7
+
8
+ def start_with_pry_debugger(target = TOPLEVEL_BINDING, options = {})
9
+ @processor ||= PryDebuggerJRuby::Processor.new
10
+
11
+ if target.is_a?(Binding) && PryDebuggerJRuby.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_debugger(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_debugger(target, options)
20
+ end
21
+ end
22
+ alias start start_with_pry_debugger
23
+ end
@@ -0,0 +1,38 @@
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 PryDebuggerJRuby.current_remote_server
9
+ raise 'Already running a pry-remote session!'
10
+ else
11
+ PryDebuggerJRuby.current_remote_server = self
12
+ end
13
+
14
+ setup
15
+ Pry.start(@object, input: client.input_proxy, output: client.output)
16
+ end
17
+
18
+ # Override to reset our saved global current server session.
19
+ alias teardown_without_pry_debugger teardown
20
+ def teardown_with_pry_debugger
21
+ return if @torn
22
+
23
+ teardown_without_pry_debugger
24
+ PryDebuggerJRuby.current_remote_server = nil
25
+ @torn = true
26
+ end
27
+ alias teardown teardown_with_pry_debugger
28
+ end
29
+ end
30
+
31
+ # Ensure cleanup when a program finishes without another break. For example,
32
+ # 'next' on the last line of a program won't hit PryDebuggerJRuby::Processor#run,
33
+ # which normally handles cleanup.
34
+ at_exit do
35
+ if PryDebuggerJRuby.current_remote_server
36
+ PryDebuggerJRuby.current_remote_server.teardown
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module PryDebuggerJRuby
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'pry-debugger-jruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'pry-debugger-jruby'
8
+ spec.version = PryDebuggerJRuby::VERSION
9
+ spec.platform = 'java'
10
+ spec.author = 'Ivo Anjo'
11
+ spec.email = 'ivo.anjo@ist.utl.pt'
12
+ spec.license = 'MIT'
13
+ spec.homepage = 'https://github.com/ivoanjo/pry-debugger-jruby'
14
+ spec.summary = 'JRuby 9k-compatible pry debugging!'
15
+ spec.description = "Add a JRuby-compatible debugger to 'pry'. Adds 'step', 'next', and 'continue' commands to control execution."
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.required_ruby_version = '>= 2.2.0'
23
+
24
+ spec.add_runtime_dependency 'pry', '>= 0.10', '< 0.11'
25
+ spec.add_runtime_dependency 'ruby-debug-base', '~> 0.10.4'
26
+
27
+ spec.add_development_dependency 'pry-remote', '~> 0.1.6'
28
+ spec.add_development_dependency 'rake', '~> 11.3'
29
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-debugger-jruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: java
6
+ authors:
7
+ - Ivo Anjo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0.10'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '0.11'
22
+ name: pry
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0.10'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.11'
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: 0.10.4
39
+ name: ruby-debug-base
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.10.4
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: 0.1.6
53
+ name: pry-remote
54
+ prerelease: false
55
+ type: :development
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.1.6
61
+ - !ruby/object:Gem::Dependency
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '11.3'
67
+ name: rake
68
+ prerelease: false
69
+ type: :development
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '11.3'
75
+ description: Add a JRuby-compatible debugger to 'pry'. Adds 'step', 'next', and 'continue' commands to control execution.
76
+ email: ivo.anjo@ist.utl.pt
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - ".gitignore"
82
+ - ".ruby-version"
83
+ - CHANGELOG.md
84
+ - Gemfile
85
+ - LICENSE
86
+ - README.md
87
+ - Rakefile
88
+ - lib/pry-debugger-jruby.rb
89
+ - lib/pry-debugger-jruby/base.rb
90
+ - lib/pry-debugger-jruby/breakpoints.rb
91
+ - lib/pry-debugger-jruby/cli.rb
92
+ - lib/pry-debugger-jruby/commands.rb
93
+ - lib/pry-debugger-jruby/processor.rb
94
+ - lib/pry-debugger-jruby/pry_ext.rb
95
+ - lib/pry-debugger-jruby/pry_remote_ext.rb
96
+ - lib/pry-debugger-jruby/version.rb
97
+ - pry-debugger-jruby.gemspec
98
+ homepage: https://github.com/ivoanjo/pry-debugger-jruby
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 2.2.0
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.6.6
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: JRuby 9k-compatible pry debugging!
122
+ test_files: []