ruby-debug-base 0.10.4-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,270 @@
1
+ require 'ruby_debug.jar'
2
+ require File.join(File.dirname(__FILE__), 'tracelines')
3
+ require File.join(File.dirname(__FILE__), 'linecache')
4
+
5
+ SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
6
+ SCRIPT_TIMESTAMPS__ = {} unless defined? SCRIPT_TIMESTAMPS__
7
+
8
+ module Debugger
9
+
10
+ # Default options to Debugger.start
11
+ DEFAULT_START_SETTINGS = {
12
+ :init => true, # Set $0 and save ARGV?
13
+ :post_mortem => false # post-mortem debugging on uncaught exception?
14
+ } unless defined?(DEFAULT_START_SETTINGS)
15
+
16
+ class Context
17
+ def interrupt
18
+ self.stop_next = 1
19
+ end
20
+
21
+ alias __c_frame_binding frame_binding
22
+ def frame_binding(frame)
23
+ __c_frame_binding(frame) || hbinding(frame)
24
+ end
25
+
26
+ private
27
+
28
+ def hbinding(frame)
29
+ hash = frame_locals(frame)
30
+ code = hash.keys.map{|k| "#{k} = hash['#{k}']"}.join(';') + ';binding'
31
+ if obj = frame_self(frame)
32
+ obj.instance_eval code
33
+ else
34
+ eval code, TOPLEVEL_BINDING
35
+ end
36
+ end
37
+
38
+ def handler
39
+ Debugger.handler or raise 'No interface loaded'
40
+ end
41
+
42
+ def at_breakpoint(breakpoint)
43
+ handler.at_breakpoint(self, breakpoint)
44
+ end
45
+
46
+ def at_catchpoint(excpt)
47
+ handler.at_catchpoint(self, excpt)
48
+ end
49
+
50
+ def at_tracing(file, line)
51
+ handler.at_tracing(self, file, line)
52
+ end
53
+
54
+ def at_line(file, line)
55
+ handler.at_line(self, file, line)
56
+ end
57
+
58
+ def at_return(file, line)
59
+ handler.at_return(self, file, line)
60
+ end
61
+ end
62
+
63
+ @reload_source_on_change = false
64
+
65
+ class << self
66
+ # interface modules provide +handler+ object
67
+ attr_accessor :handler
68
+
69
+ # if <tt>true</tt>, checks the modification time of source files and reloads if it was modified
70
+ attr_accessor :reload_source_on_change
71
+
72
+ attr_accessor :last_exception
73
+ Debugger.last_exception = nil
74
+
75
+ #
76
+ # Interrupts the current thread
77
+ #
78
+ def interrupt
79
+ current_context.interrupt
80
+ end
81
+
82
+ #
83
+ # Interrupts the last debugged thread
84
+ #
85
+ def interrupt_last
86
+ if context = last_context
87
+ return nil unless context.thread.alive?
88
+ context.interrupt
89
+ end
90
+ context
91
+ end
92
+
93
+ def source_reload
94
+ LineCache::clear_file_cache(true)
95
+ end
96
+
97
+ # Get line +line_number+ from file named +filename+. Return "\n"
98
+ # there was a problem. Leaking blanks are stripped off.
99
+ def line_at(filename, line_number) # :nodoc:
100
+ line = LineCache::getline(filename, line_number, @reload_on_change)
101
+ return "\n" unless line
102
+ return "#{line.gsub(/^\s+/, '').chomp}\n"
103
+ end
104
+
105
+ #
106
+ # Activates the post-mortem mode. There are two ways of using it:
107
+ #
108
+ # == Global post-mortem mode
109
+ # By calling Debugger.post_mortem method without a block, you install
110
+ # at_exit hook that intercepts any unhandled by your script exceptions
111
+ # and enables post-mortem mode.
112
+ #
113
+ # == Local post-mortem mode
114
+ #
115
+ # If you know that a particular block of code raises an exception you can
116
+ # enable post-mortem mode by wrapping this block with Debugger.post_mortem, e.g.
117
+ #
118
+ # def offender
119
+ # raise 'error'
120
+ # end
121
+ # Debugger.post_mortem do
122
+ # ...
123
+ # offender
124
+ # ...
125
+ # end
126
+ def post_mortem
127
+ if block_given?
128
+ old_post_mortem = self.post_mortem?
129
+ begin
130
+ self.post_mortem = true
131
+ yield
132
+ rescue Exception => exp
133
+ handle_post_mortem(exp)
134
+ raise
135
+ ensure
136
+ self.post_mortem = old_post_mortem
137
+ end
138
+ else
139
+ return if post_mortem?
140
+ self.post_mortem = true
141
+ debug_at_exit do
142
+ handle_post_mortem($!) if $! && post_mortem?
143
+ end
144
+ end
145
+ end
146
+
147
+ def handle_post_mortem(exp)
148
+ return if !exp || !exp.__debug_context ||
149
+ exp.__debug_context.stack_size == 0
150
+ Debugger.suspend
151
+ orig_tracing = Debugger.tracing, Debugger.current_context.tracing
152
+ Debugger.tracing = Debugger.current_context.tracing = false
153
+ Debugger.last_exception = exp
154
+ handler.at_line(exp.__debug_context, exp.__debug_file, exp.__debug_line)
155
+ ensure
156
+ Debugger.tracing, Debugger.current_context.tracing = orig_tracing
157
+ Debugger.resume
158
+ end
159
+ # private :handle_post_mortem
160
+ end
161
+
162
+ class DebugThread # :nodoc:
163
+ end
164
+
165
+ class ThreadsTable # :nodoc:
166
+ end
167
+ end
168
+
169
+ module Kernel
170
+ #
171
+ # Enters the debugger in the current thread after a number of
172
+ # _steps_ made.
173
+ #
174
+ def debugger(steps = 1)
175
+ Debugger.start unless Debugger.started?
176
+ Debugger.run_init_script(StringIO.new)
177
+ Debugger.current_context.stop_next = steps
178
+ end
179
+ alias breakpoint debugger unless respond_to?(:breakpoint)
180
+
181
+ # Debugger.start(options) -> bool
182
+ # Debugger.start(options) { ... } -> obj
183
+ #
184
+ # This method is internal and activates the debugger. Use
185
+ # Debugger.start (from ruby-debug-base.rb) instead.
186
+ #
187
+ # If it's called without a block it returns +true+, unless debugger
188
+ # was already started. If a block is given, it starts debugger and
189
+ # yields to block. When the block is finished executing it stops
190
+ # the debugger with Debugger.stop method.
191
+ #
192
+ # <i>Note that if you want to stop debugger, you must call
193
+ # Debugger.stop as many time as you called Debugger.start
194
+ # method.</i>
195
+ #
196
+ # +options+ is a hash used to set various debugging options.
197
+ # Set :init true if you want to save ARGV and some variables which
198
+ # make a debugger restart possible. Only the first time :init is set true
199
+ # will values get set. Since ARGV is saved, you should make sure
200
+ # it hasn't been changed before the (first) call.
201
+ # Set :post_mortem true if you want to enter post-mortem debugging
202
+ # on an uncaught exception. Once post-mortem debugging is set, it can't
203
+ # be unset.
204
+ def start(options={}, &block)
205
+ options = Debugger::DEFAULT_START_SETTINGS.merge(options)
206
+ if options[:init]
207
+ Debugger.const_set('ARGV', ARGV.clone) unless
208
+ defined? Debugger::ARGV
209
+ Debugger.const_set('PROG_SCRIPT', $0) unless
210
+ defined? Debugger::PROG_SCRIPT
211
+ Debugger.const_set('INITIAL_DIR', Dir.pwd) unless
212
+ defined? Debugger::INITIAL_DIR
213
+ end
214
+ retval = Debugger.started? ? nil : Debugger.start_(&block)
215
+ if options[:post_mortem]
216
+ post_mortem
217
+ end
218
+ return retval
219
+ end
220
+
221
+ #
222
+ # Returns a binding of n-th call frame
223
+ #
224
+ def binding_n(n = 0)
225
+ Debugger.skip do
226
+ Debugger.current_context.frame_binding(n+2)
227
+ end
228
+ end
229
+ end
230
+
231
+ class Exception # :nodoc:
232
+ attr_reader :__debug_file, :__debug_line, :__debug_binding, :__debug_context
233
+ end
234
+
235
+ class Module
236
+ #
237
+ # Wraps the +meth+ method with Debugger.start {...} block.
238
+ #
239
+ def debug_method(meth)
240
+ old_meth = "__debugee_#{meth}"
241
+ old_meth = "#{$1}_set" if old_meth =~ /^(.+)=$/
242
+ alias_method old_meth.to_sym, meth
243
+ class_eval <<-EOD
244
+ def #{meth}(*args, &block)
245
+ Debugger.start do
246
+ debugger 2
247
+ #{old_meth}(*args, &block)
248
+ end
249
+ end
250
+ EOD
251
+ end
252
+
253
+ #
254
+ # Wraps the +meth+ method with Debugger.post_mortem {...} block.
255
+ #
256
+ def post_mortem_method(meth)
257
+ old_meth = "__postmortem_#{meth}"
258
+ old_meth = "#{$1}_set" if old_meth =~ /^(.+)=$/
259
+ alias_method old_meth.to_sym, meth
260
+ class_eval <<-EOD
261
+ def #{meth}(*args, &block)
262
+ Debugger.start do |dbg|
263
+ dbg.post_mortem do
264
+ #{old_meth}(*args, &block)
265
+ end
266
+ end
267
+ end
268
+ EOD
269
+ end
270
+ end
Binary file
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Temporary solution. Copy-pasted from rocky-hacks/linecache project.
4
+ # Will/should be solved generally in the future.
5
+
6
+ begin require 'rubygems' rescue LoadError end
7
+ # require 'ruby-debug' ; Debugger.start
8
+
9
+ module TraceLineNumbers
10
+ @@SRC_DIR = File.expand_path(File.dirname(__FILE__))
11
+ # require File.join(@@SRC_DIR, '..', 'ext', 'trace_nums')
12
+
13
+ # Return an array of lines numbers that could be
14
+ # stopped at given a file name of a Ruby program.
15
+ def lnums_for_file(file)
16
+ lnums_for_str(File.read(file))
17
+ end
18
+ module_function :lnums_for_file
19
+
20
+ # Return an array of lines numbers that could be
21
+ # stopped at given a file name of a Ruby program.
22
+ # We assume the each line has \n at the end. If not
23
+ # set the newline parameters to \n.
24
+ def lnums_for_str_array(string_array, newline='')
25
+ lnums_for_str(string_array.join(newline))
26
+ end
27
+ module_function :lnums_for_str_array
28
+ end
29
+
30
+ if __FILE__ == $0
31
+ SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
32
+ # test_file = '../test/rcov-bug.rb'
33
+ test_file = '../test/lnum-data/begin1.rb'
34
+ if File.exists?(test_file)
35
+ puts TraceLineNumbers.lnums_for_file(test_file).inspect
36
+ load(test_file, 0) # for later
37
+ end
38
+ puts TraceLineNumbers.lnums_for_file(__FILE__).inspect
39
+ unless SCRIPT_LINES__.empty?
40
+ key = SCRIPT_LINES__.keys.first
41
+ puts key
42
+ puts SCRIPT_LINES__[key]
43
+ puts TraceLineNumbers.lnums_for_str_array(SCRIPT_LINES__[key]).inspect
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-debug-base
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 10
8
+ - 4
9
+ version: 0.10.4
10
+ platform: java
11
+ authors:
12
+ - debug-commons team
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-10 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: |
22
+ Java extension to make fast ruby debugger run on JRuby.
23
+ It is the same what ruby-debug-base is for native Ruby.
24
+
25
+ email:
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - AUTHORS
34
+ - ChangeLog
35
+ - lib/linecache.rb
36
+ - lib/linecache-ruby.rb
37
+ - lib/ruby-debug-base.rb
38
+ - lib/ruby_debug.jar
39
+ - lib/tracelines.rb
40
+ - MIT-LICENSE
41
+ - Rakefile
42
+ - README
43
+ has_rdoc: true
44
+ homepage: http://rubyforge.org/projects/debug-commons/
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project: debug-commons
71
+ rubygems_version: 1.3.7
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Java implementation of Fast Ruby Debugger
75
+ test_files: []
76
+