ruby-debug-base 0.10.0-mswin32 → 0.10.4-mswin32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,17 @@
1
1
  require 'ruby_debug.so'
2
-
3
- SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
4
- SCRIPT_TIMESTAMPS__ = {} unless defined? SCRIPT_TIMESTAMPS__
2
+ require 'rubygems'
3
+ require 'linecache'
5
4
 
6
5
  module Debugger
6
+
7
+ # Default options to Debugger.start
8
+ DEFAULT_START_SETTINGS = {
9
+ :init => true, # Set $0 and save ARGV?
10
+ :post_mortem => false, # post-mortem debugging on uncaught exception?
11
+ :tracing => nil # Debugger.tracing value. true/false resets,
12
+ # nil keeps the prior value
13
+ } unless defined?(DEFAULT_START_SETTINGS)
14
+
7
15
  class Context
8
16
  def interrupt
9
17
  self.stop_next = 1
@@ -18,7 +26,7 @@ module Debugger
18
26
 
19
27
  def hbinding(frame)
20
28
  hash = frame_locals(frame)
21
- code = hash.keys.map{|k| "#{k} = hash['#{k}']"}.join(';') + ';binding'
29
+ code = hash.keys.map{|k| "#{k} = hash['#{k}']" unless k=='self' }.compact.join(';') + ';binding'
22
30
  if obj = frame_self(frame)
23
31
  obj.instance_eval code
24
32
  else
@@ -45,6 +53,10 @@ module Debugger
45
53
  def at_line(file, line)
46
54
  handler.at_line(self, file, line)
47
55
  end
56
+
57
+ def at_return(file, line)
58
+ handler.at_return(self, file, line)
59
+ end
48
60
  end
49
61
 
50
62
  @reload_source_on_change = false
@@ -55,6 +67,9 @@ module Debugger
55
67
 
56
68
  # if <tt>true</tt>, checks the modification time of source files and reloads if it was modified
57
69
  attr_accessor :reload_source_on_change
70
+
71
+ attr_accessor :last_exception
72
+ Debugger.last_exception = nil
58
73
 
59
74
  #
60
75
  # Interrupts the current thread
@@ -74,42 +89,17 @@ module Debugger
74
89
  context
75
90
  end
76
91
 
77
- def source_for(file) # :nodoc:
78
- finder = lambda do
79
- if File.exists?(file)
80
- if SCRIPT_LINES__[file].nil? || SCRIPT_LINES__[file] == true
81
- SCRIPT_LINES__[file] = File.readlines(file)
82
- end
83
-
84
- change_time = File.stat(file).mtime
85
- SCRIPT_TIMESTAMPS__[file] ||= change_time
86
- if @reload_source_on_change && SCRIPT_TIMESTAMPS__[file] < change_time
87
- SCRIPT_LINES__[file] = File.readlines(file)
88
- end
89
-
90
- SCRIPT_LINES__[file]
91
- end
92
- end
93
-
94
- Dir.chdir(File.dirname($0)){finder.call} || finder.call ||
95
- (SCRIPT_LINES__[file] == true ? nil : SCRIPT_LINES__[file])
96
- end
97
-
98
92
  def source_reload
99
- SCRIPT_LINES__.keys.each do |file|
100
- next unless File.exists?(file)
101
- SCRIPT_LINES__[file] = nil
102
- end
93
+ LineCache::clear_file_cache
103
94
  end
104
95
 
105
- def line_at(file, line) # :nodoc:
106
- lines = source_for(file)
107
- if lines
108
- line = lines[line-1]
109
- return "\n" unless line
110
- return "#{line.gsub(/^\s+/, '').chomp}\n"
111
- end
112
- return "\n"
96
+ # Get line +line_number+ from file named +filename+. Return "\n"
97
+ # there was a problem. Leaking blanks are stripped off.
98
+ def line_at(filename, line_number) # :nodoc:
99
+ @reload_on_change=nil unless defined?(@reload_on_change)
100
+ line = LineCache::getline(filename, line_number, @reload_on_change)
101
+ return "\n" unless line
102
+ return "#{line.gsub(/^\s+/, '').chomp}\n"
113
103
  end
114
104
 
115
105
  #
@@ -155,16 +145,18 @@ module Debugger
155
145
  end
156
146
 
157
147
  def handle_post_mortem(exp)
158
- return if exp.__debug_context.stack_size == 0
148
+ return if !exp || !exp.__debug_context ||
149
+ exp.__debug_context.stack_size == 0
159
150
  Debugger.suspend
160
151
  orig_tracing = Debugger.tracing, Debugger.current_context.tracing
161
152
  Debugger.tracing = Debugger.current_context.tracing = false
153
+ Debugger.last_exception = exp
162
154
  handler.at_line(exp.__debug_context, exp.__debug_file, exp.__debug_line)
163
155
  ensure
164
156
  Debugger.tracing, Debugger.current_context.tracing = orig_tracing
165
157
  Debugger.resume
166
158
  end
167
- private :handle_post_mortem
159
+ # private :handle_post_mortem
168
160
  end
169
161
 
170
162
  class DebugThread # :nodoc:
@@ -172,17 +164,88 @@ module Debugger
172
164
 
173
165
  class ThreadsTable # :nodoc:
174
166
  end
167
+
168
+ # Debugger.start(options) -> bool
169
+ # Debugger.start(options) { ... } -> obj
170
+ #
171
+ # If it's called without a block it returns +true+, unless debugger
172
+ # was already started. If a block is given, it starts debugger and
173
+ # yields to block. When the block is finished executing it stops
174
+ # the debugger with Debugger.stop method.
175
+ #
176
+ # If a block is given, it starts debugger and yields to block. When
177
+ # the block is finished executing it stops the debugger with
178
+ # Debugger.stop method. Inside the block you will probably want to
179
+ # have a call to Debugger.debugger. For example:
180
+ #
181
+ # Debugger.start{debugger; foo} # Stop inside of foo
182
+ #
183
+ # Also, ruby-debug only allows
184
+ # one invocation of debugger at a time; nested Debugger.start's
185
+ # have no effect and you can't use this inside the debugger itself.
186
+ #
187
+ # <i>Note that if you want to stop debugger, you must call
188
+ # Debugger.stop as many time as you called Debugger.start
189
+ # method.</i>
190
+ #
191
+ # +options+ is a hash used to set various debugging options.
192
+ # Set :init true if you want to save ARGV and some variables which
193
+ # make a debugger restart possible. Only the first time :init is set true
194
+ # will values get set. Since ARGV is saved, you should make sure
195
+ # it hasn't been changed before the (first) call.
196
+ # Set :post_mortem true if you want to enter post-mortem debugging
197
+ # on an uncaught exception. Once post-mortem debugging is set, it can't
198
+ # be unset.
199
+ def start(options={}, &block)
200
+ options = Debugger::DEFAULT_START_SETTINGS.merge(options)
201
+ if options[:init]
202
+ Debugger.const_set('ARGV', ARGV.clone) unless
203
+ defined? Debugger::ARGV
204
+ Debugger.const_set('PROG_SCRIPT', $0) unless
205
+ defined? Debugger::PROG_SCRIPT
206
+ Debugger.const_set('INITIAL_DIR', Dir.pwd) unless
207
+ defined? Debugger::INITIAL_DIR
208
+ end
209
+ Debugger.tracing = options[:tracing] unless options[:tracing].nil?
210
+ retval = Debugger.started? ? block && block.call(self) : Debugger.start_(&block)
211
+ if options[:post_mortem]
212
+ post_mortem
213
+ end
214
+ return retval
215
+ end
216
+ module_function :start
175
217
  end
176
218
 
177
219
  module Kernel
220
+
221
+ # Enters the debugger in the current thread after _steps_ line
222
+ # events occur. Before entering the debugger, a user-defined
223
+ # startup script is may be read.
224
+ #
225
+ # Setting _steps_ to 0 will cause a break in the debugger subroutine
226
+ # and not wait for a line event to occur. You will have to go "up 1"
227
+ # in order to be back in your debugged program rather than the
228
+ # debugger. Settings _steps_ to 0 could be useful you want to stop
229
+ # right after the last statement in some scope, because the next
230
+ # step will take you out of some scope.
178
231
  #
179
- # Enters the debugger in the current thread after a number of
180
- # _steps_ made.
232
+ # If block _block_ is given (and the debugger hasn't been started,
233
+ # we run the block under the debugger.
181
234
  #
182
- def debugger(steps = 1)
183
- Debugger.start unless Debugger.started?
184
- Debugger.run_init_script(StringIO.new)
185
- Debugger.current_context.stop_next = steps
235
+ # FIXME: Alas, when a block is given, we can't support running the
236
+ # startup script or support the steps option.
237
+ def debugger(steps = 1, &block)
238
+ if block
239
+ Debugger.start({}, &block)
240
+ else
241
+ Debugger.start unless Debugger.started?
242
+ Debugger.run_init_script(StringIO.new)
243
+ if 0 == steps
244
+ Debugger.current_context.stop_frame = 0
245
+ else
246
+ Debugger.current_context.stop_next = steps
247
+ end
248
+ end
186
249
  end
187
250
  alias breakpoint debugger unless respond_to?(:breakpoint)
188
251
 
data/lib/ruby_debug.so CHANGED
Binary file
@@ -1,75 +1,73 @@
1
1
  #!/usr/bin/env ruby
2
- require "test/unit"
2
+ require 'test/unit'
3
3
 
4
- $: << File.expand_path(File.dirname(__FILE__)) + '/../ext'
5
- $: << File.expand_path(File.dirname(__FILE__)) + '/../lib'
6
- require "ruby_debug"
7
-
8
- # Test of C extension ruby_debug.so
4
+ # Some tests of Debugger module in C extension ruby_debug
9
5
  class TestRubyDebug < Test::Unit::TestCase
10
- include Debugger
6
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'ext')
7
+ require 'ruby_debug'
8
+ $:.shift
11
9
 
12
10
  # test current_context
13
11
  def test_current_context
14
12
  assert_equal(false, Debugger.started?,
15
- "debugger should not initially be started.")
16
- Debugger.start
13
+ 'debugger should not initially be started.')
14
+ Debugger.start_
17
15
  assert(Debugger.started?,
18
- "debugger should now be started.")
19
- assert_equal(19, Debugger.current_context.frame_line)
16
+ 'debugger should now be started.')
17
+ assert_equal(__LINE__, Debugger.current_context.frame_line)
20
18
  assert_equal(nil, Debugger.current_context.frame_args_info,
21
- "no frame args info.")
19
+ 'no frame args info.')
22
20
  assert_equal(Debugger.current_context.frame_file,
23
21
  Debugger.current_context.frame_file(0))
24
- assert_equal("test-ruby-debug-base.rb",
22
+ assert_equal(File.basename(__FILE__),
25
23
  File.basename(Debugger.current_context.frame_file))
26
24
  assert_raises(ArgumentError) {Debugger.current_context.frame_file(1, 2)}
27
25
  assert_raises(ArgumentError) {Debugger.current_context.frame_file(10)}
28
26
  assert_equal(1, Debugger.current_context.stack_size)
29
27
  assert_equal(TestRubyDebug, Debugger.current_context.frame_class)
30
- assert_equal(false, Debugger.current_context.dead?, "Not dead yet!")
28
+ assert_equal(false, Debugger.current_context.dead?, 'Not dead yet!')
31
29
  Debugger.stop
32
30
  assert_equal(false, Debugger.started?,
33
- "Debugger should no longer be started.")
31
+ 'Debugger should no longer be started.')
34
32
  end
35
33
 
36
34
  # Test initial variables and setting/getting state.
37
35
  def test_debugger_base
38
36
  assert_equal(false, Debugger.started?,
39
- "Debugger should not initially be started.")
40
- Debugger.start
37
+ 'Debugger should not initially be started.')
38
+ Debugger.start_
41
39
  assert(Debugger.started?,
42
- "Debugger should now be started.")
40
+ 'Debugger should now be started.')
43
41
  assert_equal(false, Debugger.debug,
44
- "Debug variable should not be set.")
42
+ 'Debug variable should not be set.')
45
43
  assert_equal(false, Debugger.post_mortem?,
46
- "Post mortem debugging should not be set.")
44
+ 'Post mortem debugging should not be set.')
47
45
  a = Debugger.contexts
48
46
  assert_equal(1, a.size,
49
- "There should only be one context.")
47
+ 'There should only be one context.')
50
48
  assert_equal(Array, a.class,
51
- "Context should be an array.")
49
+ 'Context should be an array.')
52
50
  Debugger.stop
53
51
  assert_equal(false, Debugger.started?,
54
- "debugger should no longer be started.")
52
+ 'debugger should no longer be started.')
55
53
  end
56
54
 
57
55
  # Test breakpoint handling
58
56
  def test_breakpoints
59
- Debugger.start
57
+ Debugger.start_
60
58
  assert_equal(0, Debugger.breakpoints.size,
61
- "There should not be any breakpoints set.")
59
+ 'There should not be any breakpoints set.')
62
60
  brk = Debugger.add_breakpoint(__FILE__, 1)
63
61
  assert_equal(Debugger::Breakpoint, brk.class,
64
- "Breakpoint should have been set and returned.")
62
+ 'Breakpoint should have been set and returned.')
65
63
  assert_equal(1, Debugger.breakpoints.size,
66
- "There should now be one breakpoint set.")
64
+ 'There should now be one breakpoint set.')
67
65
  Debugger.remove_breakpoint(0)
68
66
  assert_equal(1, Debugger.breakpoints.size,
69
- "There should still be one breakpoint set.")
67
+ 'There should still be one breakpoint set.')
70
68
  Debugger.remove_breakpoint(1)
71
69
  assert_equal(0, Debugger.breakpoints.size,
72
- "There should no longer be any breakpoints set.")
70
+ 'There should no longer be any breakpoints set.')
73
71
  Debugger.stop
74
72
  end
75
73
  end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+
5
+ # Test binding_n command
6
+ class TestBinding < Test::Unit::TestCase
7
+
8
+ SRC_DIR = File.expand_path(File.dirname(__FILE__)) unless
9
+ defined?(SRC_DIR)
10
+ %w(ext lib).each do |dir|
11
+ $:.unshift File.join(SRC_DIR, '..', '..', dir)
12
+ end
13
+ require File.join(SRC_DIR, '..', '..', 'lib', 'ruby-debug-base')
14
+ $:.shift; $:.shift
15
+
16
+ def test_basic
17
+ def inside_fn
18
+ s = 'some other string'
19
+ b2 = Kernel::binding_n(1)
20
+ y2 = eval('s', b2)
21
+ assert_equal('this is a test', y2)
22
+ end
23
+ s = 'this is a test'
24
+ Debugger.start
25
+ b = Kernel::binding_n(0)
26
+ y = eval('s', b)
27
+ assert_equal(y, s)
28
+ inside_fn
29
+ Debugger.stop
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+
4
+ # Test catchpoint in C ruby_debug extension.
5
+
6
+ class TestRubyDebugCatchpoint < Test::Unit::TestCase
7
+
8
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'ext')
9
+ require 'ruby_debug'
10
+ $:.shift
11
+
12
+ # test current_context
13
+ def test_catchpoints
14
+ assert_raise(RuntimeError) {Debugger.catchpoints}
15
+ Debugger.start_
16
+ assert_equal({}, Debugger.catchpoints)
17
+ Debugger.add_catchpoint('ZeroDivisionError')
18
+ assert_equal({'ZeroDivisionError' => 0}, Debugger.catchpoints)
19
+ Debugger.add_catchpoint('RuntimeError')
20
+ assert_equal(['RuntimeError', 'ZeroDivisionError'],
21
+ Debugger.catchpoints.keys.sort)
22
+ Debugger.stop
23
+ end
24
+
25
+ end
26
+
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+ class TestReloadBug < Test::Unit::TestCase
4
+ def test_reload_bug
5
+ top_srcdir = File.join(File.dirname(__FILE__), '..', '..')
6
+ assert_equal({}, Debugger::source_reload)
7
+ end
8
+ end
metadata CHANGED
@@ -1,61 +1,93 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: ruby-debug-base
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.10.0
7
- date: 2008-02-07 00:00:00 -05:00
8
- summary: Fast Ruby debugger - core component
9
- require_paths:
10
- - lib
11
- email: ksibilev@yahoo.com
12
- homepage: http://rubyforge.org/projects/ruby-debug/
13
- rubyforge_project: ruby-debug
14
- description: ruby-debug is a fast implementation of the standard Ruby debugger debug.rb. It is implemented by utilizing a new Ruby C API hook. The core component provides support that front-ends can build on. It provides breakpoint handling, bindings for stack frames among other things.
15
- autorequire: ruby-debug-base
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.8.2
24
- version:
4
+ version: 0.10.4
25
5
  platform: mswin32
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Kent Sibilev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-10-27 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: linecache
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0.3"
24
+ version:
25
+ description: |
26
+ ruby-debug is a fast implementation of the standard Ruby debugger debug.rb.
27
+ It is implemented by utilizing a new Ruby C API hook. The core component
28
+ provides support that front-ends can build on. It provides breakpoint
29
+ handling, bindings for stack frames among other things.
30
+
31
+ email: ksibilev@yahoo.com
32
+ executables: []
33
+
34
+ extensions: []
35
+
36
+ extra_rdoc_files:
37
+ - README
38
+ - ext/ruby_debug.c
31
39
  files:
32
40
  - AUTHORS
33
41
  - CHANGES
34
42
  - LICENSE
35
43
  - README
44
+ - VERSION
36
45
  - Rakefile
37
- - lib/ruby-debug-base.rb
38
- - lib/ChangeLog
39
- - ext/ChangeLog
40
- - ext/ruby_debug.c
46
+ - ext/breakpoint.c
41
47
  - ext/extconf.rb
48
+ - ext/ruby_debug.c
49
+ - ext/ruby_debug.h
50
+ - ext/win32/breakpoint.o
51
+ - ext/win32/ruby_debug.o
42
52
  - ext/win32/ruby_debug.so
43
53
  - ext/win32/Makefile
44
- - ext/win32/ruby_debug.o
45
- - test/test-ruby-debug-base.rb
54
+ - lib/ChangeLog
55
+ - lib/ruby-debug-base.rb
56
+ - test/base/base.rb
57
+ - test/base/binding.rb
58
+ - test/base/catchpoint.rb
59
+ - test/base/reload_bug.rb
46
60
  - lib/ruby_debug.so
47
- test_files:
48
- - test/test-ruby-debug-base.rb
49
- rdoc_options: []
50
-
51
- extra_rdoc_files:
52
- - README
53
- - ext/ruby_debug.c
54
- executables: []
61
+ has_rdoc: true
62
+ homepage: http://rubyforge.org/projects/ruby-debug/
63
+ licenses: []
55
64
 
56
- extensions: []
65
+ post_install_message:
66
+ rdoc_options: []
57
67
 
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.8.2
75
+ version:
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
58
82
  requirements: []
59
83
 
60
- dependencies: []
61
-
84
+ rubyforge_project: ruby-debug
85
+ rubygems_version: 1.3.5
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Fast Ruby debugger - core component
89
+ test_files:
90
+ - test/base/base.rb
91
+ - test/base/binding.rb
92
+ - test/base/catchpoint.rb
93
+ - test/base/reload_bug.rb