ruby-debug 0.10.1 → 0.10.2

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.
Files changed (86) hide show
  1. data/CHANGES +7 -0
  2. data/ChangeLog +315 -278
  3. data/Rakefile +6 -6
  4. data/bin/rdebug +7 -3
  5. data/cli/ruby-debug.rb +2 -2
  6. data/cli/ruby-debug/commands/breakpoints.rb +15 -15
  7. data/cli/ruby-debug/commands/catchpoint.rb +18 -6
  8. data/cli/ruby-debug/commands/continue.rb +12 -6
  9. data/cli/ruby-debug/commands/info.rb +3 -3
  10. data/cli/ruby-debug/commands/irb.rb +2 -2
  11. data/cli/ruby-debug/commands/list.rb +1 -1
  12. data/cli/ruby-debug/commands/method.rb +44 -2
  13. data/cli/ruby-debug/commands/save.rb +16 -6
  14. data/cli/ruby-debug/commands/set.rb +11 -8
  15. data/cli/ruby-debug/commands/show.rb +28 -24
  16. data/cli/ruby-debug/commands/trace.rb +35 -11
  17. data/cli/ruby-debug/commands/variables.rb +47 -4
  18. data/cli/ruby-debug/interface.rb +28 -8
  19. data/cli/ruby-debug/processor.rb +6 -4
  20. data/rdbg.rb +0 -0
  21. data/test/base/base.rb +0 -0
  22. data/test/base/binding.rb +0 -0
  23. data/test/base/catchpoint.rb +0 -0
  24. data/test/bp_loop_issue.rb +3 -0
  25. data/test/classes.rb +11 -0
  26. data/test/cli/commands/catchpoint_test.rb +35 -0
  27. data/test/data/break_loop_bug.cmd +5 -0
  28. data/test/data/break_loop_bug.right +15 -0
  29. data/test/data/breakpoints.cmd +1 -1
  30. data/test/data/breakpoints.right +8 -12
  31. data/test/data/catch.cmd +17 -0
  32. data/test/data/catch.right +37 -0
  33. data/test/data/emacs_basic.right +2 -7
  34. data/test/data/frame.cmd +3 -0
  35. data/test/data/frame.right +4 -0
  36. data/test/data/method.cmd +10 -0
  37. data/test/data/method.right +21 -0
  38. data/test/data/methodsig.cmd +10 -0
  39. data/test/data/methodsig.right +20 -0
  40. data/test/data/output.right +0 -10
  41. data/test/data/quit.right +0 -9
  42. data/test/data/raise.right +1 -1
  43. data/test/data/save.cmd +33 -0
  44. data/test/data/save.right +59 -0
  45. data/test/data/setshow.cmd +13 -0
  46. data/test/data/setshow.right +25 -0
  47. data/test/dollar-0.rb +0 -0
  48. data/test/gcd-dbg.rb +0 -0
  49. data/test/helper.rb +24 -2
  50. data/test/pm-base.rb +0 -0
  51. data/test/pm.rb +0 -0
  52. data/test/raise.rb +0 -0
  53. data/test/tdebug.rb +5 -6
  54. data/test/test-annotate.rb +0 -0
  55. data/test/test-break-bad.rb +11 -0
  56. data/test/test-breakpoints.rb +0 -0
  57. data/test/test-catch.rb +25 -0
  58. data/test/test-condition.rb +0 -0
  59. data/test/test-ctrl.rb +0 -0
  60. data/test/test-display.rb +0 -0
  61. data/test/test-dollar-0.rb +0 -0
  62. data/test/test-edit.rb +0 -0
  63. data/test/test-emacs-basic.rb +2 -2
  64. data/test/test-enable.rb +0 -0
  65. data/test/test-finish.rb +0 -0
  66. data/test/test-frame.rb +11 -3
  67. data/test/test-help.rb +0 -0
  68. data/test/test-hist.rb +0 -0
  69. data/test/test-info-thread.rb +0 -0
  70. data/test/test-info-var.rb +0 -0
  71. data/test/test-info.rb +0 -0
  72. data/test/test-init.rb +3 -1
  73. data/test/test-list.rb +0 -0
  74. data/test/test-method.rb +34 -0
  75. data/test/test-output.rb +0 -0
  76. data/test/test-pm.rb +0 -0
  77. data/test/test-quit.rb +0 -0
  78. data/test/test-raise.rb +0 -0
  79. data/test/test-save.rb +25 -0
  80. data/test/test-setshow.rb +0 -0
  81. data/test/test-source.rb +0 -0
  82. data/test/test-stepping.rb +0 -0
  83. data/test/test-trace.rb +0 -0
  84. metadata +178 -155
  85. data/cli/ruby-debug/commands/disassemble.RB +0 -38
  86. data/test/except-bug2.rb +0 -7
@@ -1,19 +1,42 @@
1
1
  module Debugger
2
2
  class TraceCommand < Command # :nodoc:
3
3
  def regexp
4
- /^\s*tr(?:ace)?(?:\s+(on|off))?(?:\s+(all))?$/
4
+ /^\s* tr(?:ace)? (?: \s+ (\S+)) # on |off | var(iable)
5
+ (?: \s+ (\S+))? # (all | variable-name)?
6
+ (?: \s+ (\S+))? \s* # (stop | nostop)?
7
+ $/ix
5
8
  end
6
9
 
7
10
  def execute
8
- if @match[2]
9
- Debugger.tracing = @match[1] == 'on'
10
- elsif @match[1]
11
- Debugger.current_context.tracing = @match[1] == 'on'
12
- end
13
- if Debugger.tracing || Debugger.current_context.tracing
14
- print "Trace on.\n"
15
- else
16
- print "Trace off.\n"
11
+ if @match[1] =~ /on|off/
12
+ onoff = 'on' == @match[1]
13
+ if @match[2]
14
+ Debugger.current_context.tracing = onoff
15
+ print "Tracing %s all threads.\n" % (onoff ? 'on' : 'off')
16
+ else
17
+ Debugger.tracing = onoff
18
+ print "Tracing %s on current thread.\n" % (onoff ? 'on' : 'off')
19
+ end
20
+ elsif @match[1] =~ /var(?:iable)?/
21
+ varname=@match[2]
22
+ if debug_eval("defined?(#{varname})")
23
+ if @match[3] && @match[3] !~ /(:?no)?stop/
24
+ errmsg("expecting 'stop' or 'nostop'; got %s\n" % @match[3])
25
+ else
26
+ dbg_cmd = if @match[3] && (@match[3] !~ /nostop/)
27
+ 'debugger' else '' end
28
+ end
29
+ eval("
30
+ trace_var(:#{varname}) do |val|
31
+ print \"traced variable #{varname} has value \#{val}\n\"
32
+ #{dbg_cmd}
33
+ end")
34
+ else
35
+ errmsg "#{varname} is not a global variable.\n"
36
+ end
37
+ else
38
+ errmsg("expecting 'on', 'off', 'var' or 'variable'; got: %s\n" %
39
+ @match[1])
17
40
  end
18
41
  end
19
42
 
@@ -26,8 +49,9 @@ module Debugger
26
49
  %{
27
50
  tr[ace] (on|off)\tset trace mode of current thread
28
51
  tr[ace] (on|off) all\tset trace mode of all threads
52
+ tr[ace] var(iable) VARNAME [stop|nostop]\tset trace variable on VARNAME
29
53
  }
30
54
  end
31
55
  end
32
56
  end
33
- end
57
+ end
@@ -24,14 +24,15 @@ module Debugger
24
24
  end
25
25
  end
26
26
 
27
- class VarClassVarCommand < Command # :nodoc:
27
+ # Implements the debugger 'var class' command.
28
+ class VarClassVarCommand < Command
28
29
  def regexp
29
30
  /^\s*v(?:ar)?\s+cl(?:ass)?/
30
31
  end
31
32
 
32
33
  def execute
33
34
  unless @state.context
34
- print "can't get class variables here.\n"
35
+ errmsg "can't get class variables here.\n"
35
36
  return
36
37
  end
37
38
  var_class_self
@@ -107,7 +108,7 @@ module Debugger
107
108
 
108
109
  class VarInstanceCommand < Command # :nodoc:
109
110
  def regexp
110
- /^\s*v(?:ar)?\s+i(?:nstance)?\s*/
111
+ /^\s*v(?:ar)?\s+ins(?:tance)?\s*/
111
112
  end
112
113
 
113
114
  def execute
@@ -128,7 +129,8 @@ module Debugger
128
129
  end
129
130
  end
130
131
 
131
- class VarLocalCommand < Command # :nodoc:
132
+ # Implements the debugger 'var local' command.
133
+ class VarLocalCommand < Command
132
134
  def regexp
133
135
  /^\s*v(?:ar)?\s+l(?:ocal)?\s*$/
134
136
  end
@@ -153,4 +155,45 @@ module Debugger
153
155
  end
154
156
  end
155
157
  end
158
+
159
+ # Implements the debugger 'var inherit' command.
160
+ begin
161
+ require 'classtree'
162
+ have_classtree = true
163
+ rescue LoadError
164
+ have_classtree = false
165
+ end
166
+
167
+ class VarInheritCommand < Command
168
+ def regexp
169
+ /^\s*v(?:ar)?\s+ct\s*/
170
+ end
171
+
172
+ def execute
173
+ unless @state.context
174
+ errmsg "can't get object inheritance.\n"
175
+ return
176
+ end
177
+ puts @match.post_match
178
+ obj = debug_eval("#{@match.post_match}.classtree")
179
+ if obj
180
+ print obj
181
+ else
182
+ errmsg "Trouble getting object #{@match.post_match}\n"
183
+ end
184
+ end
185
+
186
+ class << self
187
+ def help_command
188
+ 'var'
189
+ end
190
+
191
+ def help(cmd)
192
+ %{
193
+ v[ar] ct\t\t\tshow class heirarchy of object
194
+ }
195
+ end
196
+ end
197
+ end if have_classtree
198
+
156
199
  end
@@ -1,5 +1,10 @@
1
1
  module Debugger
2
2
  class Interface # :nodoc:
3
+ attr_writer :have_readline # true if Readline is available
4
+
5
+ def initialize
6
+ @have_readline = false
7
+ end
3
8
 
4
9
  # Common routine for reporting debugger error messages.
5
10
  # Derived classed may want to override this to capture output.
@@ -38,6 +43,7 @@ module Debugger
38
43
  def initialize()
39
44
  super
40
45
  @command_queue = []
46
+ @have_readline = false
41
47
  @history_save = true
42
48
  # take gdb's default
43
49
  @history_length = ENV["HISTSIZE"] ? ENV["HISTSIZE"].to_i : 256
@@ -77,10 +83,15 @@ module Debugger
77
83
  end
78
84
  end
79
85
 
86
+ def readline_support?(msg)
87
+ @have_readline
88
+ end
89
+
80
90
  private
81
91
  begin
82
92
  require 'readline'
83
93
  class << Debugger
94
+ @have_readline = true
84
95
  define_method(:save_history) do
85
96
  iface = self.handler.interface
86
97
  iface.histfile ||= File.join(ENV["HOME"]||ENV["HOMEPATH"]||".",
@@ -114,7 +125,7 @@ module Debugger
114
125
  end
115
126
  end
116
127
 
117
- class RemoteInterface # :nodoc:
128
+ class RemoteInterface < Interface # :nodoc:
118
129
  attr_accessor :command_queue
119
130
  attr_accessor :histfile
120
131
  attr_accessor :history_save
@@ -137,6 +148,15 @@ module Debugger
137
148
  @restart_file = nil
138
149
  end
139
150
 
151
+ def close
152
+ @socket.close
153
+ rescue Exception
154
+ end
155
+
156
+ def confirm(prompt)
157
+ send_command "CONFIRM #{prompt}"
158
+ end
159
+
140
160
  def finalize
141
161
  end
142
162
 
@@ -144,19 +164,14 @@ module Debugger
144
164
  send_command "PROMPT #{prompt}"
145
165
  end
146
166
 
147
- def confirm(prompt)
148
- send_command "CONFIRM #{prompt}"
167
+ def readline_support?
168
+ false
149
169
  end
150
170
 
151
171
  def print(*args)
152
172
  @socket.printf(*args)
153
173
  end
154
174
 
155
- def close
156
- @socket.close
157
- rescue Exception
158
- end
159
-
160
175
  private
161
176
 
162
177
  def send_command(msg)
@@ -172,6 +187,7 @@ module Debugger
172
187
  attr_accessor :histfile
173
188
  attr_accessor :history_save
174
189
  attr_accessor :history_length
190
+ attr_accessor :restart_file
175
191
  def initialize(file, out, verbose=false)
176
192
  super()
177
193
  @command_queue = []
@@ -197,6 +213,10 @@ module Debugger
197
213
  result.chomp!
198
214
  end
199
215
 
216
+ def readline_support?
217
+ false
218
+ end
219
+
200
220
  def confirm(prompt)
201
221
  'y'
202
222
  end
@@ -267,6 +267,7 @@ module Debugger
267
267
  def one_cmd(commands, context, input)
268
268
  if cmd = commands.find{ |c| c.match(input) }
269
269
  if context.dead? && cmd.class.need_context
270
+ p cmd
270
271
  print "Command is unavailable\n"
271
272
  else
272
273
  cmd.execute
@@ -276,7 +277,7 @@ module Debugger
276
277
  if unknown_cmd
277
278
  unknown_cmd.execute
278
279
  else
279
- print "Unknown command\n"
280
+ errmsg "Unknown command: \"#{input}\". Try \"help\".\n"
280
281
  end
281
282
  end
282
283
  end
@@ -393,7 +394,7 @@ module Debugger
393
394
  @debugger_context_was_dead = true # Assume we haven't started.
394
395
  end
395
396
 
396
- def process_commands
397
+ def process_commands(verbose=false)
397
398
  control_cmds = Command.commands.select do |cmd|
398
399
  cmd.allow_in_control
399
400
  end
@@ -409,11 +410,12 @@ module Debugger
409
410
  end
410
411
 
411
412
  while input = @interface.read_command(prompt(nil))
413
+ print "+#{input}" if verbose
412
414
  catch(:debug_error) do
413
415
  if cmd = commands.find{|c| c.match(input) }
414
416
  cmd.execute
415
417
  else
416
- print "Unknown command\n"
418
+ errmsg "Unknown command\n"
417
419
  end
418
420
  end
419
421
  end
@@ -462,7 +464,7 @@ module Debugger
462
464
  end
463
465
 
464
466
  def file
465
- print "No filename given.\n"
467
+ errmsg "No filename given.\n"
466
468
  throw :debug_error
467
469
  end
468
470
  end # State
data/rdbg.rb CHANGED
File without changes
data/test/base/base.rb CHANGED
File without changes
data/test/base/binding.rb CHANGED
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ 1.upto(2) {
2
+ sleep 0.01
3
+ }
data/test/classes.rb ADDED
@@ -0,0 +1,11 @@
1
+ class Mine
2
+ def initialize
3
+ @myvar = 'init'
4
+ end
5
+ def mymethod(a, b=5, &block)
6
+ end
7
+ def self.classmeth
8
+ end
9
+ end
10
+ me = Mine.new
11
+ metoo = Mine(new)
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+
5
+ BASE_DIR = File.join(File.dirname(__FILE__), '..', '..', '..')
6
+
7
+ %w(ext lib cli).each do |dir|
8
+ $: << File.join(BASE_DIR, dir)
9
+ end
10
+
11
+ require File.join(BASE_DIR, 'cli', 'ruby-debug')
12
+
13
+ class TestCatchCommand < Test::Unit::TestCase
14
+
15
+ class MockState
16
+ attr_accessor :message
17
+ def context; end
18
+ def confirm(msg); true end
19
+ def print(*args)
20
+ @message = *args
21
+ end
22
+ end
23
+
24
+ # regression test for bug #20156
25
+ def test_catch_does_not_blow_up
26
+ state = MockState.new
27
+ catch_cmd = Debugger::CatchCommand.new(state)
28
+ assert(catch_cmd.match('catch off'))
29
+ catch(:debug_error) do
30
+ catch_cmd.execute
31
+ end
32
+ assert_equal(nil, state.message)
33
+ end
34
+
35
+ end
@@ -0,0 +1,5 @@
1
+ set debuggertesting on
2
+ break 2
3
+ cont
4
+ cont
5
+ cont
@@ -0,0 +1,15 @@
1
+ bp_loop_issue.rb:1
2
+ 1.upto(2) {
3
+ # set debuggertesting on
4
+ Currently testing the debugger is on.
5
+ # break 2
6
+ Breakpoint 1 file ./bp_loop_issue.rb, line 2
7
+ # cont
8
+ Breakpoint 1 at bp_loop_issue.rb:2
9
+ bp_loop_issue.rb:2
10
+ sleep 0.01
11
+ # cont
12
+ Breakpoint 1 at bp_loop_issue.rb:2
13
+ bp_loop_issue.rb:2
14
+ sleep 0.01
15
+ # cont
@@ -16,7 +16,7 @@ info break
16
16
  continue
17
17
  where
18
18
  info program
19
- c 10
19
+ c 6
20
20
  info break
21
21
  break foo
22
22
  info break
@@ -41,18 +41,17 @@ return nil if a <= 0
41
41
  #1 at line gcd.rb:18
42
42
  # info program
43
43
  Program stopped. It stopped at a breakpoint.
44
- # c 10
45
- Breakpoint 3 at Object:gcd
46
- gcd.rb:4
47
- def gcd(a, b)
44
+ # c 6
45
+ Breakpoint 2 at gcd.rb:10
46
+ gcd.rb:10
47
+ return nil if a <= 0
48
48
  # info break
49
49
  Num Enb What
50
50
  1 y at gcd.rb:6
51
51
  breakpoint already hit 1 time
52
52
  2 y at gcd.rb:10
53
- breakpoint already hit 1 time
53
+ breakpoint already hit 2 times
54
54
  3 y at Object:gcd
55
- breakpoint already hit 1 time
56
55
  # break foo
57
56
  *** Invalid breakpoint location: foo.
58
57
  # info break
@@ -60,26 +59,23 @@ Num Enb What
60
59
  1 y at gcd.rb:6
61
60
  breakpoint already hit 1 time
62
61
  2 y at gcd.rb:10
63
- breakpoint already hit 1 time
62
+ breakpoint already hit 2 times
64
63
  3 y at Object:gcd
65
- breakpoint already hit 1 time
66
64
  # disable 1
67
65
  # info break
68
66
  Num Enb What
69
67
  1 n at gcd.rb:6
70
68
  breakpoint already hit 1 time
71
69
  2 y at gcd.rb:10
72
- breakpoint already hit 1 time
70
+ breakpoint already hit 2 times
73
71
  3 y at Object:gcd
74
- breakpoint already hit 1 time
75
72
  # delete 1
76
73
  # # We should see breakpoint 2 but not 1
77
74
  # info break
78
75
  Num Enb What
79
76
  2 y at gcd.rb:10
80
- breakpoint already hit 1 time
77
+ breakpoint already hit 2 times
81
78
  3 y at Object:gcd
82
- breakpoint already hit 1 time
83
79
  # # We should still be able to access 2
84
80
  # disable 2
85
81
  # disable bar
@@ -0,0 +1,17 @@
1
+ # ***************************************************
2
+ # Test catch
3
+ # ***************************************************
4
+ set debuggertesting on
5
+ set autoeval off
6
+ set basename on
7
+ info catch
8
+ catch ZeroDivisionError off
9
+ catch ZeroDivisionError off afdasdf
10
+ catch ZeroDivisionError
11
+ info catch
12
+ catch ZeroDivisionError off
13
+ info catch
14
+ catch ZeroDivisionError
15
+ c
16
+ where
17
+ quit