debugger2 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.travis.yml +3 -0
  4. data/AUTHORS +10 -0
  5. data/CHANGELOG.md +65 -0
  6. data/CONTRIBUTING.md +1 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE +23 -0
  9. data/OLDER_CHANGELOG +334 -0
  10. data/OLD_CHANGELOG +5655 -0
  11. data/OLD_README +122 -0
  12. data/README.md +108 -0
  13. data/Rakefile +78 -0
  14. data/bin/rdebug +397 -0
  15. data/debugger2.gemspec +29 -0
  16. data/doc/.cvsignore +42 -0
  17. data/doc/Makefile.am +63 -0
  18. data/doc/emacs-notes.txt +38 -0
  19. data/doc/hanoi.rb +35 -0
  20. data/doc/primes.rb +28 -0
  21. data/doc/rdebug-emacs.texi +1030 -0
  22. data/doc/ruby-debug.texi +3791 -0
  23. data/doc/test-tri2.rb +18 -0
  24. data/doc/tri3.rb +8 -0
  25. data/doc/triangle.rb +12 -0
  26. data/emacs/Makefile.am +130 -0
  27. data/emacs/rdebug-annotate.el +385 -0
  28. data/emacs/rdebug-breaks.el +407 -0
  29. data/emacs/rdebug-cmd.el +92 -0
  30. data/emacs/rdebug-core.el +502 -0
  31. data/emacs/rdebug-dbg.el +62 -0
  32. data/emacs/rdebug-error.el +79 -0
  33. data/emacs/rdebug-fns.el +111 -0
  34. data/emacs/rdebug-frames.el +230 -0
  35. data/emacs/rdebug-gud.el +242 -0
  36. data/emacs/rdebug-help.el +104 -0
  37. data/emacs/rdebug-info.el +83 -0
  38. data/emacs/rdebug-layouts.el +180 -0
  39. data/emacs/rdebug-locring.el +118 -0
  40. data/emacs/rdebug-output.el +106 -0
  41. data/emacs/rdebug-regexp.el +118 -0
  42. data/emacs/rdebug-secondary.el +260 -0
  43. data/emacs/rdebug-shortkey.el +175 -0
  44. data/emacs/rdebug-source.el +568 -0
  45. data/emacs/rdebug-track.el +392 -0
  46. data/emacs/rdebug-varbuf.el +150 -0
  47. data/emacs/rdebug-vars.el +125 -0
  48. data/emacs/rdebug-watch.el +132 -0
  49. data/emacs/rdebug.el +326 -0
  50. data/emacs/test/elk-test.el +242 -0
  51. data/emacs/test/test-annotate.el +103 -0
  52. data/emacs/test/test-cmd.el +116 -0
  53. data/emacs/test/test-core.el +104 -0
  54. data/emacs/test/test-fns.el +65 -0
  55. data/emacs/test/test-frames.el +62 -0
  56. data/emacs/test/test-gud.el +35 -0
  57. data/emacs/test/test-indent.el +58 -0
  58. data/emacs/test/test-regexp.el +144 -0
  59. data/emacs/test/test-shortkey.el +61 -0
  60. data/ext/ruby_debug/breakpoint.c +630 -0
  61. data/ext/ruby_debug/extconf.rb +11 -0
  62. data/ext/ruby_debug/ruby_debug.c +2203 -0
  63. data/ext/ruby_debug/ruby_debug.h +151 -0
  64. data/lib/debugger.rb +5 -0
  65. data/lib/debugger/version.rb +5 -0
  66. data/lib/debugger2.rb +6 -0
  67. data/lib/ruby-debug-base.rb +307 -0
  68. data/lib/ruby-debug.rb +176 -0
  69. data/lib/ruby-debug/command.rb +227 -0
  70. data/lib/ruby-debug/commands/breakpoints.rb +153 -0
  71. data/lib/ruby-debug/commands/catchpoint.rb +55 -0
  72. data/lib/ruby-debug/commands/condition.rb +49 -0
  73. data/lib/ruby-debug/commands/continue.rb +38 -0
  74. data/lib/ruby-debug/commands/control.rb +107 -0
  75. data/lib/ruby-debug/commands/display.rb +120 -0
  76. data/lib/ruby-debug/commands/edit.rb +48 -0
  77. data/lib/ruby-debug/commands/enable.rb +202 -0
  78. data/lib/ruby-debug/commands/eval.rb +176 -0
  79. data/lib/ruby-debug/commands/finish.rb +42 -0
  80. data/lib/ruby-debug/commands/frame.rb +301 -0
  81. data/lib/ruby-debug/commands/help.rb +56 -0
  82. data/lib/ruby-debug/commands/info.rb +467 -0
  83. data/lib/ruby-debug/commands/irb.rb +123 -0
  84. data/lib/ruby-debug/commands/jump.rb +66 -0
  85. data/lib/ruby-debug/commands/kill.rb +51 -0
  86. data/lib/ruby-debug/commands/list.rb +94 -0
  87. data/lib/ruby-debug/commands/method.rb +84 -0
  88. data/lib/ruby-debug/commands/quit.rb +39 -0
  89. data/lib/ruby-debug/commands/reload.rb +40 -0
  90. data/lib/ruby-debug/commands/save.rb +90 -0
  91. data/lib/ruby-debug/commands/set.rb +223 -0
  92. data/lib/ruby-debug/commands/show.rb +247 -0
  93. data/lib/ruby-debug/commands/skip.rb +35 -0
  94. data/lib/ruby-debug/commands/source.rb +36 -0
  95. data/lib/ruby-debug/commands/stepping.rb +81 -0
  96. data/lib/ruby-debug/commands/threads.rb +189 -0
  97. data/lib/ruby-debug/commands/tmate.rb +36 -0
  98. data/lib/ruby-debug/commands/trace.rb +57 -0
  99. data/lib/ruby-debug/commands/variables.rb +199 -0
  100. data/lib/ruby-debug/debugger.rb +5 -0
  101. data/lib/ruby-debug/helper.rb +69 -0
  102. data/lib/ruby-debug/interface.rb +232 -0
  103. data/lib/ruby-debug/processor.rb +474 -0
  104. data/man/rdebug.1 +241 -0
  105. data/old_scripts/Makefile.am +14 -0
  106. data/old_scripts/README.md +2 -0
  107. data/old_scripts/autogen.sh +4 -0
  108. data/old_scripts/configure.ac +12 -0
  109. data/old_scripts/rdbg.rb +33 -0
  110. data/old_scripts/runner.sh +7 -0
  111. data/old_scripts/svn2cl_usermap +3 -0
  112. data/test/.cvsignore +1 -0
  113. data/test/breakpoints_test.rb +366 -0
  114. data/test/conditions_test.rb +77 -0
  115. data/test/continue_test.rb +28 -0
  116. data/test/display_test.rb +143 -0
  117. data/test/edit_test.rb +55 -0
  118. data/test/eval_test.rb +94 -0
  119. data/test/examples/breakpoint1.rb +15 -0
  120. data/test/examples/breakpoint2.rb +7 -0
  121. data/test/examples/conditions.rb +4 -0
  122. data/test/examples/continue.rb +4 -0
  123. data/test/examples/display.rb +5 -0
  124. data/test/examples/edit.rb +3 -0
  125. data/test/examples/edit2.rb +3 -0
  126. data/test/examples/eval.rb +4 -0
  127. data/test/examples/finish.rb +20 -0
  128. data/test/examples/frame.rb +31 -0
  129. data/test/examples/help.rb +2 -0
  130. data/test/examples/info.rb +48 -0
  131. data/test/examples/info2.rb +3 -0
  132. data/test/examples/irb.rb +6 -0
  133. data/test/examples/jump.rb +14 -0
  134. data/test/examples/kill.rb +2 -0
  135. data/test/examples/list.rb +12 -0
  136. data/test/examples/method.rb +15 -0
  137. data/test/examples/post_mortem.rb +19 -0
  138. data/test/examples/quit.rb +2 -0
  139. data/test/examples/reload.rb +6 -0
  140. data/test/examples/restart.rb +6 -0
  141. data/test/examples/save.rb +3 -0
  142. data/test/examples/set.rb +3 -0
  143. data/test/examples/set_annotate.rb +12 -0
  144. data/test/examples/settings.rb +1 -0
  145. data/test/examples/show.rb +2 -0
  146. data/test/examples/source.rb +3 -0
  147. data/test/examples/stepping.rb +21 -0
  148. data/test/examples/thread.rb +32 -0
  149. data/test/examples/tmate.rb +10 -0
  150. data/test/examples/trace.rb +7 -0
  151. data/test/examples/trace_threads.rb +20 -0
  152. data/test/examples/variables.rb +26 -0
  153. data/test/finish_test.rb +49 -0
  154. data/test/frame_test.rb +140 -0
  155. data/test/help_test.rb +51 -0
  156. data/test/info_test.rb +326 -0
  157. data/test/irb_test.rb +82 -0
  158. data/test/jump_test.rb +70 -0
  159. data/test/kill_test.rb +49 -0
  160. data/test/list_test.rb +147 -0
  161. data/test/method_test.rb +72 -0
  162. data/test/post_mortem_test.rb +25 -0
  163. data/test/quit_test.rb +56 -0
  164. data/test/reload_test.rb +47 -0
  165. data/test/restart_test.rb +145 -0
  166. data/test/save_test.rb +94 -0
  167. data/test/set_test.rb +183 -0
  168. data/test/show_test.rb +294 -0
  169. data/test/source_test.rb +46 -0
  170. data/test/stepping_test.rb +122 -0
  171. data/test/support/breakpoint.rb +12 -0
  172. data/test/support/context.rb +14 -0
  173. data/test/support/matchers.rb +67 -0
  174. data/test/support/mocha_extensions.rb +71 -0
  175. data/test/support/processor.rb +7 -0
  176. data/test/support/test_dsl.rb +206 -0
  177. data/test/support/test_interface.rb +66 -0
  178. data/test/test_helper.rb +9 -0
  179. data/test/thread_test.rb +124 -0
  180. data/test/tmate_test.rb +45 -0
  181. data/test/trace_test.rb +156 -0
  182. data/test/variables_test.rb +116 -0
  183. metadata +319 -0
@@ -0,0 +1,55 @@
1
+ module Debugger
2
+ class CatchCommand < Command # :nodoc:
3
+ self.allow_in_control = true
4
+
5
+ def regexp
6
+ /^\s* cat(?:ch)?
7
+ (?:\s+ (\S+))?
8
+ (?:\s+ (off))? \s* $/ix
9
+ end
10
+
11
+ def execute
12
+ excn = @match[1]
13
+ if not excn
14
+ # No args given.
15
+ info_catch
16
+ elsif not @match[2]
17
+ # One arg given.
18
+ if 'off' == excn
19
+ Debugger.catchpoints.clear if
20
+ confirm("Delete all catchpoints? (y or n) ")
21
+ else
22
+ binding = @state.context ? get_binding : TOPLEVEL_BINDING
23
+ unless debug_eval("#{excn}.is_a?(Class)", binding)
24
+ print "Warning #{excn} is not known to be a Class\n"
25
+ end
26
+ Debugger.add_catchpoint(excn)
27
+ print "Catch exception %s.\n", excn
28
+ end
29
+ elsif @match[2] != 'off'
30
+ errmsg "Off expected. Got %s\n", @match[2]
31
+ elsif Debugger.catchpoints.member?(excn)
32
+ Debugger.catchpoints.delete(excn)
33
+ print "Catch for exception %s removed.\n", excn
34
+ else
35
+ errmsg "Catch for exception %s not found.\n", excn
36
+ end
37
+ end
38
+
39
+ class << self
40
+ def help_command
41
+ 'catch'
42
+ end
43
+
44
+ def help(cmd)
45
+ %{
46
+ cat[ch]\t\tsame as "info catch"
47
+ cat[ch] <exception-name> [on|off]
48
+ \tIntercept <exception-name> when there would otherwise be no handler.
49
+ \tWith an "on" or "off", turn handling the exception on or off.
50
+ cat[ch] off\tdelete all catchpoints
51
+ }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,49 @@
1
+ module Debugger
2
+
3
+ class ConditionCommand < Command # :nodoc:
4
+
5
+ def regexp
6
+ /^\s* cond(?:ition)? (?:\s+(\d+)\s*(.*))?$/ix
7
+ end
8
+
9
+ def execute
10
+ if not @match[1]
11
+ errmsg "\"condition\" must be followed a breakpoint number and expression\n"
12
+ else
13
+ breakpoints = Debugger.breakpoints.sort_by{|b| b.id }
14
+ largest = breakpoints.inject(0) do |tally, b|
15
+ tally = b.id if b.id > tally
16
+ end
17
+ if 0 == largest
18
+ print "No breakpoints have been set.\n"
19
+ return
20
+ end
21
+ pos = get_int(@match[1], "Condition", 1, largest)
22
+ return unless pos
23
+ breakpoints.each do |b|
24
+ if b.id == pos
25
+ b.expr = @match[2].empty? ? nil : @match[2]
26
+ break
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+
33
+ class << self
34
+ def help_command
35
+ 'condition'
36
+ end
37
+
38
+ def help(cmd)
39
+ %{
40
+ Condition breakpoint-number expression
41
+ Specify breakpoint number N to break only if COND is true.
42
+ N is an integer and COND is an expression to be evaluated whenever
43
+ breakpoint N is reached. If the empty string is used, the condition is removed.
44
+ }
45
+ end
46
+ end
47
+ end
48
+
49
+ end # module Debugger
@@ -0,0 +1,38 @@
1
+ module Debugger
2
+
3
+ # Implements debugger "continue" command.
4
+ class ContinueCommand < Command
5
+ self.allow_in_post_mortem = true
6
+ self.need_context = false
7
+ def regexp
8
+ /^\s* c(?:ont(?:inue)?)? (?:\s+(.*))? $/x
9
+ end
10
+
11
+ def execute
12
+ if @match[1] && !@state.context.dead?
13
+ filename = File.expand_path(@state.file)
14
+ line_number = get_int(@match[1], "Continue", 0, nil, 0)
15
+ return unless line_number
16
+ unless LineCache.trace_line_numbers(filename).member?(line_number)
17
+ errmsg("Line %d is not a stopping point in file \"%s\".\n",
18
+ line_number, filename)
19
+ return
20
+ end
21
+ @state.context.set_breakpoint(filename, line_number)
22
+ end
23
+ @state.proceed
24
+ end
25
+
26
+ class << self
27
+ def help_command
28
+ 'continue'
29
+ end
30
+
31
+ def help(cmd)
32
+ %{
33
+ c[ont[inue]][ nnn]\trun until program ends, hits a breakpoint or reaches line nnn
34
+ }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,107 @@
1
+ module Debugger
2
+ class RestartCommand < Command # :nodoc:
3
+ self.allow_in_control = true
4
+
5
+ def regexp
6
+ / ^\s*
7
+ (?:restart|R)
8
+ (?:\s+ (\S?.*\S))? \s*
9
+ $
10
+ /ix
11
+ end
12
+
13
+ def execute
14
+ if not defined? Debugger::PROG_SCRIPT
15
+ errmsg "Don't know name of debugged program\n"
16
+ return
17
+ end
18
+ prog_script = Debugger::PROG_SCRIPT
19
+ if not defined? Debugger::RDEBUG_SCRIPT
20
+ # FIXME? Should ask for confirmation?
21
+ print "Debugger was not called from the outset...\n"
22
+ rdebug_script = prog_script
23
+ else
24
+ rdebug_script = Debugger::RDEBUG_SCRIPT
25
+ end
26
+ begin
27
+ Dir.chdir(Debugger::INITIAL_DIR)
28
+ rescue
29
+ print "Failed to change initial directory #{Debugger::INITIAL_DIR}"
30
+ end
31
+ if not File.exist?(File.expand_path(prog_script))
32
+ errmsg "Ruby program #{prog_script} doesn't exist\n"
33
+ return
34
+ end
35
+ if not File.executable?(prog_script) and rdebug_script == prog_script
36
+ print "Ruby program #{prog_script} doesn't seem to be executable...\n"
37
+ print "We'll add a call to Ruby.\n"
38
+ ruby = begin defined?(Gem) ? Gem.ruby : "ruby" rescue "ruby" end
39
+ rdebug_script = "#{ruby} -I#{$:.join(' -I')} #{prog_script}"
40
+ else
41
+ rdebug_script += ' '
42
+ end
43
+ if @match[1]
44
+ argv = [prog_script] + @match[1].split(/[ \t]+/)
45
+ else
46
+ if not defined? Command.settings[:argv]
47
+ errmsg "Arguments have not been set. Use 'set args' to set them.\n"
48
+ return
49
+ else
50
+ argv = Command.settings[:argv]
51
+ end
52
+ end
53
+ args = argv.join(' ')
54
+
55
+ # An execv would be preferable to the "exec" below.
56
+ cmd = rdebug_script + args
57
+ print "Re exec'ing:\n\t#{cmd}\n"
58
+ exec cmd
59
+ rescue Errno::EOPNOTSUPP
60
+ print "Restart command is not available at this time.\n"
61
+ end
62
+
63
+ class << self
64
+ def help_command
65
+ 'restart'
66
+ end
67
+
68
+ def help(cmd)
69
+ %{
70
+ restart|R [args]
71
+ Restart the program. This is a re-exec - all debugger state
72
+ is lost. If command arguments are passed those are used.
73
+ }
74
+ end
75
+ end
76
+ end
77
+
78
+ class InterruptCommand < Command # :nodoc:
79
+ self.allow_in_control = true
80
+ self.allow_in_post_mortem = false
81
+ self.event = false
82
+ self.need_context = true
83
+
84
+ def regexp
85
+ /^\s*i(?:nterrupt)?\s*$/
86
+ end
87
+
88
+ def execute
89
+ unless Debugger.interrupt_last
90
+ context = Debugger.thread_context(Thread.main)
91
+ context.interrupt
92
+ end
93
+ end
94
+
95
+ class << self
96
+ def help_command
97
+ 'interrupt'
98
+ end
99
+
100
+ def help(cmd)
101
+ %{
102
+ i[nterrupt]\tinterrupt the program
103
+ }
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,120 @@
1
+ module Debugger
2
+ module DisplayFunctions # :nodoc:
3
+ def display_expression(exp)
4
+ print "%s = %s\n", exp, debug_silent_eval(exp).to_s
5
+ end
6
+
7
+ def active_display_expressions?
8
+ @state.display.select{|d| d[0]}.size > 0
9
+ end
10
+
11
+ def print_display_expressions
12
+ n = 1
13
+ for d in @state.display
14
+ if d[0]
15
+ print "%d: ", n
16
+ display_expression(d[1])
17
+ end
18
+ n += 1
19
+ end
20
+ end
21
+ end
22
+
23
+ class AddDisplayCommand < Command # :nodoc:
24
+ def regexp
25
+ /^\s*disp(?:lay)?\s+(.+)$/
26
+ end
27
+
28
+ def execute
29
+ exp = @match[1]
30
+ @state.display.push [true, exp]
31
+ print "%d: ", @state.display.size
32
+ display_expression(exp)
33
+ end
34
+
35
+ class << self
36
+ def help_command
37
+ 'display'
38
+ end
39
+
40
+ def help(cmd)
41
+ %{
42
+ disp[lay] <expression>\tadd expression into display expression list
43
+ }
44
+ end
45
+ end
46
+ end
47
+
48
+ class DisplayCommand < Command # :nodoc:
49
+ def self.always_run
50
+ Debugger.annotate = 0 unless Debugger.annotate
51
+ if Debugger.annotate > 1
52
+ 0
53
+ else
54
+ 2
55
+ end
56
+ end
57
+
58
+ def regexp
59
+ /^\s*disp(?:lay)?$/
60
+ end
61
+
62
+ def execute
63
+ print_display_expressions
64
+ end
65
+
66
+ class << self
67
+ def help_command
68
+ 'display'
69
+ end
70
+
71
+ def help(cmd)
72
+ %{
73
+ disp[lay]\t\tdisplay expression list
74
+ }
75
+ end
76
+ end
77
+ end
78
+
79
+ class DeleteDisplayCommand < Command # :nodoc:
80
+
81
+ def regexp
82
+ /^\s* undisp(?:lay)? \s* (?:(\S+))?$/x
83
+ end
84
+
85
+ def execute
86
+ unless pos = @match[1]
87
+ if confirm("Clear all expressions? (y/n) ")
88
+ for d in @state.display
89
+ d[0] = false
90
+ end
91
+ end
92
+ else
93
+ pos = get_int(pos, "Undisplay")
94
+ return unless pos
95
+ if @state.display[pos-1]
96
+ @state.display[pos-1][0] = nil
97
+ else
98
+ errmsg "Display expression %d is not defined.\n", pos
99
+ end
100
+ end
101
+ end
102
+
103
+ class << self
104
+ def help_command
105
+ 'undisplay'
106
+ end
107
+
108
+ def help(cmd)
109
+ %{
110
+ undisp[lay][ nnn]
111
+ Cancel some expressions to be displayed when program stops.
112
+ Arguments are the code numbers of the expressions to stop displaying.
113
+ No argument means cancel all automatic-display expressions.
114
+ "delete display" has the same effect as this command.
115
+ Do "info display" to see current list of code numbers.
116
+ }
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,48 @@
1
+ module Debugger
2
+ class Edit < Command # :nodoc:
3
+ self.allow_in_control = true
4
+ def regexp
5
+ /^\s* ed(?:it)? (?:\s+(.*))?$/ix
6
+ end
7
+
8
+ def execute
9
+ if not @match[1] or @match[1].strip.empty?
10
+ unless @state.context
11
+ errmsg "We are not in a state that has an associated file.\n"
12
+ return
13
+ end
14
+ file = @state.file
15
+ line_number = @state.line
16
+ elsif @pos_match = /([^:]+)[:]([0-9]+)/.match(@match[1])
17
+ file, line_number = @pos_match.captures
18
+ else
19
+ errmsg "Invalid file/line number specification: #{@match[1]}\n"
20
+ return
21
+ end
22
+ editor = ENV['EDITOR'] || 'ex'
23
+ if File.readable?(file)
24
+ system("#{editor} +#{line_number} #{file}")
25
+ else
26
+ errmsg "File \"#{file}\" is not readable.\n"
27
+ end
28
+ end
29
+
30
+ class << self
31
+ def help_command
32
+ 'edit'
33
+ end
34
+
35
+ def help(cmd)
36
+ %{
37
+ Edit specified file.
38
+
39
+ With no argument, edits file containing most recent line listed.
40
+ Editing targets can also be specified in this:
41
+ FILE:LINENUM, to edit at that line in that file,
42
+ }
43
+ end
44
+ end
45
+ end
46
+
47
+
48
+ end # module Debugger
@@ -0,0 +1,202 @@
1
+ module Debugger
2
+ # Mix-in module to assist in command parsing.
3
+ module EnableDisableFunctions # :nodoc:
4
+ def enable_disable_breakpoints(is_enable, args)
5
+ breakpoints = Debugger.breakpoints.sort_by{|b| b.id }
6
+ largest = breakpoints.inject(0) do |tally, b|
7
+ tally = b.id if b.id > tally
8
+ end
9
+ if 0 == largest
10
+ errmsg "No breakpoints have been set.\n"
11
+ return
12
+ end
13
+ args.each do |pos|
14
+ pos = get_int(pos, "#{is_enable} breakpoints", 1, largest)
15
+ return nil unless pos
16
+ breakpoints.each do |b|
17
+ if b.id == pos
18
+ enabled = ("Enable" == is_enable)
19
+ if enabled
20
+ unless syntax_valid?(b.expr)
21
+ errmsg("Expression \"#{b.expr}\" syntactically incorrect; breakpoint remains disabled.\n")
22
+ break
23
+ end
24
+ end
25
+ b.enabled = ("Enable" == is_enable)
26
+ break
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ def enable_disable_display(is_enable, args)
33
+ if 0 == @state.display.size
34
+ errmsg "No display expressions have been set.\n"
35
+ return
36
+ end
37
+ args.each do |pos|
38
+ pos = get_int(pos, "#{is_enable} display", 1, @state.display.size)
39
+ return nil unless pos
40
+ @state.display[pos-1][0] = ("Enable" == is_enable)
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ class EnableCommand < Command # :nodoc:
47
+ Subcommands =
48
+ [
49
+ ['breakpoints', 2, "Enable specified breakpoints",
50
+ "Give breakpoint numbers (separated by spaces) as arguments.
51
+ This is used to cancel the effect of the \"disable\" command."
52
+ ],
53
+ ['display', 2,
54
+ "Enable some expressions to be displayed when program stops",
55
+ "Arguments are the code numbers of the expressions to resume displaying.
56
+ Do \"info display\" to see current list of code numbers."],
57
+ ].map do |name, min, short_help, long_help|
58
+ SubcmdStruct.new(name, min, short_help, long_help)
59
+ end unless defined?(Subcommands)
60
+
61
+ def regexp
62
+ /^\s* en(?:able)? (?:\s+(.*))?$/ix
63
+ end
64
+
65
+ def execute
66
+ if not @match[1]
67
+ errmsg "\"enable\" must be followed \"display\", \"breakpoints\"" +
68
+ " or breakpoint numbers.\n"
69
+ else
70
+ args = @match[1].split(/[ \t]+/)
71
+ param = args.shift
72
+ subcmd = find(Subcommands, param)
73
+ if subcmd
74
+ send("enable_#{subcmd.name}", args)
75
+ else
76
+ send("enable_breakpoints", args.unshift(param))
77
+ end
78
+ end
79
+ end
80
+
81
+ def enable_breakpoints(args)
82
+ enable_disable_breakpoints("Enable", args)
83
+ end
84
+
85
+ def enable_display(args)
86
+ enable_disable_display("Enable", args)
87
+ end
88
+
89
+ class << self
90
+ def help_command
91
+ 'enable'
92
+ end
93
+
94
+ def help(args)
95
+ if args[1]
96
+ s = args[1]
97
+ subcmd = Subcommands.find do |try_subcmd|
98
+ (s.size >= try_subcmd.min) and
99
+ (try_subcmd.name[0..s.size-1] == s)
100
+ end
101
+ if subcmd
102
+ str = subcmd.short_help + '.'
103
+ str += "\n" + subcmd.long_help if subcmd.long_help
104
+ return str
105
+ else
106
+ return "Invalid 'enable' subcommand '#{args[1]}'."
107
+ end
108
+ end
109
+ s = %{
110
+ Enable some things.
111
+ This is used to cancel the effect of the "disable" command.
112
+ --
113
+ List of enable subcommands:
114
+ --
115
+ }
116
+ for subcmd in Subcommands do
117
+ s += "enable #{subcmd.name} -- #{subcmd.short_help}\n"
118
+ end
119
+ return s
120
+ end
121
+ end
122
+ end
123
+
124
+ class DisableCommand < Command # :nodoc:
125
+ Subcommands =
126
+ [
127
+ ['breakpoints', 1, "Disable some breakpoints",
128
+ "Arguments are breakpoint numbers with spaces in between.
129
+ A disabled breakpoint is not forgotten, but has no effect until reenabled."],
130
+ ['display', 1, "Disable some display expressions when program stops",
131
+ "Arguments are the code numbers of the expressions to stop displaying.
132
+ Do \"info display\" to see current list of code numbers."],
133
+ ].map do |name, min, short_help, long_help|
134
+ SubcmdStruct.new(name, min, short_help, long_help)
135
+ end unless defined?(Subcommands)
136
+
137
+ def regexp
138
+ /^\s* dis(?:able)? (?:\s+(.*))?$/ix
139
+ end
140
+
141
+ def execute
142
+ if not @match[1]
143
+ errmsg "\"disable\" must be followed \"display\", \"breakpoints\"" +
144
+ " or breakpoint numbers.\n"
145
+ else
146
+ args = @match[1].split(/[ \t]+/)
147
+ param = args.shift
148
+ subcmd = find(Subcommands, param)
149
+ if subcmd
150
+ send("disable_#{subcmd.name}", args)
151
+ else
152
+ send("disable_breakpoints", args.unshift(param))
153
+ end
154
+ end
155
+ end
156
+
157
+ def disable_breakpoints(args)
158
+ enable_disable_breakpoints("Disable", args)
159
+ end
160
+
161
+ def disable_display(args)
162
+ enable_disable_display("Disable", args)
163
+ end
164
+
165
+ class << self
166
+ def help_command
167
+ 'disable'
168
+ end
169
+
170
+ def help(args)
171
+ if args[1]
172
+ s = args[1]
173
+ subcmd = Subcommands.find do |try_subcmd|
174
+ (s.size >= try_subcmd.min) and
175
+ (try_subcmd.name[0..s.size-1] == s)
176
+ end
177
+ if subcmd
178
+ str = subcmd.short_help + '.'
179
+ str += "\n" + subcmd.long_help if subcmd.long_help
180
+ return str
181
+ else
182
+ return "Invalid 'disable' subcommand '#{args[1]}'."
183
+ end
184
+ end
185
+ s = %{
186
+ Disable some things.
187
+
188
+ A disabled item is not forgotten, but has no effect until reenabled.
189
+ Use the "enable" command to have it take effect again.
190
+ --
191
+ List of disable subcommands:
192
+ --
193
+ }
194
+ for subcmd in Subcommands do
195
+ s += "disable #{subcmd.name} -- #{subcmd.short_help}\n"
196
+ end
197
+ return s
198
+ end
199
+ end
200
+ end
201
+
202
+ end # module Debugger