rbx-trepanning 0.0.5-universal-rubinius-1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. data/ChangeLog +2002 -0
  2. data/LICENSE +25 -0
  3. data/NEWS +31 -0
  4. data/README.textile +34 -0
  5. data/Rakefile +165 -0
  6. data/THANKS +14 -0
  7. data/app/breakpoint.rb +219 -0
  8. data/app/breakpoint.rbc +3551 -0
  9. data/app/brkptmgr.rb +140 -0
  10. data/app/brkptmgr.rbc +2903 -0
  11. data/app/client.rb +61 -0
  12. data/app/client.rbc +1225 -0
  13. data/app/complete.rb +52 -0
  14. data/app/complete.rbc +1288 -0
  15. data/app/default.rb +71 -0
  16. data/app/default.rbc +1132 -0
  17. data/app/display.rb +148 -0
  18. data/app/display.rbc +2578 -0
  19. data/app/frame.rb +98 -0
  20. data/app/frame.rbc +1808 -0
  21. data/app/irb.rb +111 -0
  22. data/app/irb.rbc +2094 -0
  23. data/app/iseq.rb +117 -0
  24. data/app/iseq.rbc +2192 -0
  25. data/app/llvm.rbc +2478 -0
  26. data/app/method.rb +173 -0
  27. data/app/method.rbc +2492 -0
  28. data/app/method_name.rbc +2467 -0
  29. data/app/mock.rb +13 -0
  30. data/app/mock.rbc +398 -0
  31. data/app/options.rb +137 -0
  32. data/app/options.rbc +2898 -0
  33. data/app/rbx-llvm.rb +165 -0
  34. data/app/rbx-llvm.rbc +2478 -0
  35. data/app/run.rb +86 -0
  36. data/app/run.rbc +1244 -0
  37. data/app/util.rb +49 -0
  38. data/app/util.rbc +1146 -0
  39. data/app/validate.rb +30 -0
  40. data/app/validate.rbc +676 -0
  41. data/bin/trepan.compiled.rbc +1043 -0
  42. data/bin/trepanx +69 -0
  43. data/bin/trepanx.compiled.rbc +1049 -0
  44. data/data/irbrc +41 -0
  45. data/data/irbrc.compiled.rbc +640 -0
  46. data/interface/base_intf.rb +105 -0
  47. data/interface/base_intf.rbc +1899 -0
  48. data/interface/client.rb +80 -0
  49. data/interface/client.rbc +1072 -0
  50. data/interface/comcodes.rb +20 -0
  51. data/interface/comcodes.rbc +385 -0
  52. data/interface/script.rb +104 -0
  53. data/interface/script.rbc +1642 -0
  54. data/interface/server.rb +143 -0
  55. data/interface/server.rbc +2213 -0
  56. data/interface/user.rb +150 -0
  57. data/interface/user.rbc +2867 -0
  58. data/io/base_io.rb +148 -0
  59. data/io/base_io.rbc +2111 -0
  60. data/io/input.rb +135 -0
  61. data/io/input.rbc +2528 -0
  62. data/io/null_output.rb +42 -0
  63. data/io/null_output.rbc +730 -0
  64. data/io/string_array.rb +156 -0
  65. data/io/string_array.rbc +2466 -0
  66. data/io/tcpclient.rb +129 -0
  67. data/io/tcpclient.rbc +2419 -0
  68. data/io/tcpfns.rb +33 -0
  69. data/io/tcpfns.rbc +694 -0
  70. data/io/tcpserver.rb +141 -0
  71. data/io/tcpserver.rbc +2638 -0
  72. data/lib/trepanning.rb +474 -0
  73. data/lib/trepanning.rbc +7705 -0
  74. data/lib/trepanning2.rb +441 -0
  75. data/processor/breakpoint.rb +164 -0
  76. data/processor/command/alias.rb +55 -0
  77. data/processor/command/backtrace.rb +76 -0
  78. data/processor/command/base/cmd.rb +173 -0
  79. data/processor/command/base/subcmd.rb +229 -0
  80. data/processor/command/base/submgr.rb +182 -0
  81. data/processor/command/base/subsubcmd.rb +103 -0
  82. data/processor/command/base/subsubmgr.rb +195 -0
  83. data/processor/command/break.rb +100 -0
  84. data/processor/command/complete.rb +37 -0
  85. data/processor/command/continue.rb +91 -0
  86. data/processor/command/delete.rb +30 -0
  87. data/processor/command/directory.rb +51 -0
  88. data/processor/command/disassemble.rb +145 -0
  89. data/processor/command/display.rb +82 -0
  90. data/processor/command/down.rb +54 -0
  91. data/processor/command/eval.rb +51 -0
  92. data/processor/command/exit.rb +62 -0
  93. data/processor/command/finish.rb +80 -0
  94. data/processor/command/frame.rb +89 -0
  95. data/processor/command/help.rb +251 -0
  96. data/processor/command/info.rb +28 -0
  97. data/processor/command/info_subcmd/breakpoints.rb +73 -0
  98. data/processor/command/info_subcmd/files.rb +209 -0
  99. data/processor/command/info_subcmd/line.rb +86 -0
  100. data/processor/command/info_subcmd/method.rb +71 -0
  101. data/processor/command/info_subcmd/program.rb +49 -0
  102. data/processor/command/info_subcmd/ruby.rb +62 -0
  103. data/processor/command/info_subcmd/variables.rb +48 -0
  104. data/processor/command/irb.rb +128 -0
  105. data/processor/command/kill.rb +70 -0
  106. data/processor/command/list.rb +300 -0
  107. data/processor/command/macro.rb +76 -0
  108. data/processor/command/next.rb +66 -0
  109. data/processor/command/nexti.rb +59 -0
  110. data/processor/command/pr.rb +38 -0
  111. data/processor/command/ps.rb +40 -0
  112. data/processor/command/restart.rb +60 -0
  113. data/processor/command/server.rb +72 -0
  114. data/processor/command/set.rb +47 -0
  115. data/processor/command/set_subcmd/auto.rb +27 -0
  116. data/processor/command/set_subcmd/auto_subcmd/dis.rb +33 -0
  117. data/processor/command/set_subcmd/auto_subcmd/eval.rb +54 -0
  118. data/processor/command/set_subcmd/auto_subcmd/irb.rb +34 -0
  119. data/processor/command/set_subcmd/auto_subcmd/list.rb +34 -0
  120. data/processor/command/set_subcmd/basename.rb +25 -0
  121. data/processor/command/set_subcmd/confirm.rb +24 -0
  122. data/processor/command/set_subcmd/debug.rb +26 -0
  123. data/processor/command/set_subcmd/debug_subcmd/dbgr.rb +36 -0
  124. data/processor/command/set_subcmd/debug_subcmd/skip.rb +23 -0
  125. data/processor/command/set_subcmd/debug_subcmd/step.rb +23 -0
  126. data/processor/command/set_subcmd/different.rb +59 -0
  127. data/processor/command/set_subcmd/hidelevel.rb +62 -0
  128. data/processor/command/set_subcmd/highlight.rb +33 -0
  129. data/processor/command/set_subcmd/kernelstep.rb +60 -0
  130. data/processor/command/set_subcmd/max.rb +26 -0
  131. data/processor/command/set_subcmd/max_subcmd/list.rb +49 -0
  132. data/processor/command/set_subcmd/max_subcmd/stack.rb +50 -0
  133. data/processor/command/set_subcmd/max_subcmd/string.rb +76 -0
  134. data/processor/command/set_subcmd/max_subcmd/width.rb +49 -0
  135. data/processor/command/set_subcmd/substitute.rb +24 -0
  136. data/processor/command/set_subcmd/substitute_subcmd/path.rb +56 -0
  137. data/processor/command/set_subcmd/trace.rb +36 -0
  138. data/processor/command/set_subcmd/trace_subcmd/print.rb +57 -0
  139. data/processor/command/show.rb +38 -0
  140. data/processor/command/show_subcmd/alias.rb +42 -0
  141. data/processor/command/show_subcmd/args.rb +25 -0
  142. data/processor/command/show_subcmd/auto.rb +28 -0
  143. data/processor/command/show_subcmd/auto_subcmd/dis.rb +37 -0
  144. data/processor/command/show_subcmd/auto_subcmd/eval.rb +28 -0
  145. data/processor/command/show_subcmd/auto_subcmd/irb.rb +23 -0
  146. data/processor/command/show_subcmd/auto_subcmd/list.rb +22 -0
  147. data/processor/command/show_subcmd/basename.rb +20 -0
  148. data/processor/command/show_subcmd/confirm.rb +18 -0
  149. data/processor/command/show_subcmd/debug.rb +26 -0
  150. data/processor/command/show_subcmd/debug_subcmd/dbgr.rb +21 -0
  151. data/processor/command/show_subcmd/debug_subcmd/skip.rb +22 -0
  152. data/processor/command/show_subcmd/debug_subcmd/step.rb +22 -0
  153. data/processor/command/show_subcmd/different.rb +26 -0
  154. data/processor/command/show_subcmd/hidelevel.rb +41 -0
  155. data/processor/command/show_subcmd/highlight.rb +24 -0
  156. data/processor/command/show_subcmd/kernelstep.rb +34 -0
  157. data/processor/command/show_subcmd/max.rb +27 -0
  158. data/processor/command/show_subcmd/max_subcmd/list.rb +38 -0
  159. data/processor/command/show_subcmd/max_subcmd/stack.rb +36 -0
  160. data/processor/command/show_subcmd/max_subcmd/string.rb +42 -0
  161. data/processor/command/show_subcmd/max_subcmd/width.rb +37 -0
  162. data/processor/command/show_subcmd/trace.rb +27 -0
  163. data/processor/command/show_subcmd/trace_subcmd/print.rb +38 -0
  164. data/processor/command/show_subcmd/version.rb +23 -0
  165. data/processor/command/source.rb +126 -0
  166. data/processor/command/step.rb +84 -0
  167. data/processor/command/tbreak.rb +19 -0
  168. data/processor/command/unalias.rb +44 -0
  169. data/processor/command/undisplay.rb +59 -0
  170. data/processor/command/up.rb +86 -0
  171. data/processor/default.rb +58 -0
  172. data/processor/disassemble.rb +46 -0
  173. data/processor/display.rb +18 -0
  174. data/processor/eval.rb +96 -0
  175. data/processor/frame.rb +211 -0
  176. data/processor/help.rb +72 -0
  177. data/processor/hook.rb +133 -0
  178. data/processor/load_cmds.rb +185 -0
  179. data/processor/location.rb +137 -0
  180. data/processor/main.rb +412 -0
  181. data/processor/mock.rb +144 -0
  182. data/processor/msg.rb +43 -0
  183. data/processor/running.rb +234 -0
  184. data/processor/stepping.rb +114 -0
  185. data/processor/subcmd.rb +161 -0
  186. data/processor/validate.rb +355 -0
  187. data/sample/list-terminal-colors.rb +139 -0
  188. data/sample/list-terminal-colors.rbc +2318 -0
  189. data/sample/rocky-dot-trepanxrc +14 -0
  190. data/sample/rocky-trepanx-colors.rb +47 -0
  191. data/sample/rocky-trepanx-colors.rbc +530 -0
  192. data/test/data/enable.right +36 -0
  193. data/test/data/fname-with-blank.cmd +6 -0
  194. data/test/data/fname-with-blank.right +4 -0
  195. data/test/data/inline-call.cmd +6 -0
  196. data/test/data/inline-call.right +13 -0
  197. data/test/data/quit-Xdebug.right +3 -0
  198. data/test/data/quit.cmd +5 -0
  199. data/test/data/quit.right +2 -0
  200. data/test/data/quit2.cmd +6 -0
  201. data/test/data/quit2.right +3 -0
  202. data/test/data/step-bug.cmd +11 -0
  203. data/test/data/step-bug.right +3 -0
  204. data/test/example/fname with blank.rb +1 -0
  205. data/test/example/gcd-server.rb +22 -0
  206. data/test/example/gcd.rb +19 -0
  207. data/test/example/inline-call.rb +23 -0
  208. data/test/example/null.rb +1 -0
  209. data/test/example/step-bug.rb +14 -0
  210. data/test/example/thread1.rb +3 -0
  211. data/test/functional/fn_helper.rb +112 -0
  212. data/test/functional/test-break-name.rb +52 -0
  213. data/test/functional/test-break.rb +51 -0
  214. data/test/functional/test-finish.rb +70 -0
  215. data/test/functional/test-fn_helper.rb +43 -0
  216. data/test/functional/test-list.rb +55 -0
  217. data/test/functional/test-next-bug.rb +49 -0
  218. data/test/functional/test-next.rb +101 -0
  219. data/test/functional/test-step.rb +272 -0
  220. data/test/functional/test-step2.rb +35 -0
  221. data/test/functional/test-tbreak.rb +41 -0
  222. data/test/integration/file-diff.rb +89 -0
  223. data/test/integration/helper.rb +78 -0
  224. data/test/integration/skip-test-step-bug.rb +17 -0
  225. data/test/integration/test-fname-with-blank.rb +16 -0
  226. data/test/integration/test-inline-call.rb +20 -0
  227. data/test/integration/test-quit.rb +47 -0
  228. data/test/unit/cmd-helper.rb +50 -0
  229. data/test/unit/mock-helper.rb +10 -0
  230. data/test/unit/test-app-brkpt.rb +29 -0
  231. data/test/unit/test-app-brkptmgr.rb +51 -0
  232. data/test/unit/test-app-iseq.rb +64 -0
  233. data/test/unit/test-app-method.rb +54 -0
  234. data/test/unit/test-app-options.rb +82 -0
  235. data/test/unit/test-app-run.rb +16 -0
  236. data/test/unit/test-app-util.rb +27 -0
  237. data/test/unit/test-app-validate.rb +18 -0
  238. data/test/unit/test-base-cmd.rb +47 -0
  239. data/test/unit/test-base-subcmd.rb +61 -0
  240. data/test/unit/test-base-submgr.rb +24 -0
  241. data/test/unit/test-bin-trepanx.rb +48 -0
  242. data/test/unit/test-cmd-alias.rb +48 -0
  243. data/test/unit/test-cmd-break.rb +22 -0
  244. data/test/unit/test-cmd-exit.rb +27 -0
  245. data/test/unit/test-cmd-finish.rb +27 -0
  246. data/test/unit/test-cmd-help.rb +104 -0
  247. data/test/unit/test-cmd-kill.rb +47 -0
  248. data/test/unit/test-cmd-source.rb +34 -0
  249. data/test/unit/test-cmd-step.rb +29 -0
  250. data/test/unit/test-completion.rb +38 -0
  251. data/test/unit/test-intf-user.rb +46 -0
  252. data/test/unit/test-io-input.rb +27 -0
  253. data/test/unit/test-io-tcp.rb +33 -0
  254. data/test/unit/test-io-tcpclient.rb +54 -0
  255. data/test/unit/test-io-tcpfns.rb +17 -0
  256. data/test/unit/test-io-tcpserver.rb +50 -0
  257. data/test/unit/test-proc-eval.rb +36 -0
  258. data/test/unit/test-proc-frame.rb +79 -0
  259. data/test/unit/test-proc-help.rb +16 -0
  260. data/test/unit/test-proc-hook.rb +30 -0
  261. data/test/unit/test-proc-load_cmds.rb +50 -0
  262. data/test/unit/test-proc-location.rb +53 -0
  263. data/test/unit/test-proc-main.rb +99 -0
  264. data/test/unit/test-proc-validate.rb +91 -0
  265. data/test/unit/test-subcmd-help.rb +47 -0
  266. metadata +398 -0
@@ -0,0 +1,55 @@
1
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
+ require 'rubygems'; require 'require_relative'
3
+ require_relative 'base/cmd'
4
+
5
+ class Trepan::Command::AliasCommand < Trepan::Command
6
+
7
+ unless defined?(HELP)
8
+ NAME = File.basename(__FILE__, '.rb')
9
+ HELP = <<-HELP
10
+ #{NAME} ALIAS COMMAND
11
+
12
+ Add an alias for a COMMAND
13
+
14
+ See also 'unalias'.
15
+ HELP
16
+
17
+ CATEGORY = 'support'
18
+ MAX_ARGS = 2 # Need at most this many
19
+ NAME = File.basename(__FILE__, '.rb')
20
+ NEED_STACK = true
21
+ SHORT_HELP = 'Add an alias for a debugger command'
22
+ end
23
+
24
+ # Run command.
25
+ def run(args)
26
+ if args.size == 1
27
+ @proc.commands['show'].run(%w(show alias))
28
+ elsif args.size == 2
29
+ @proc.commands['show'].run(%W(show alias #{args[1]}))
30
+ else
31
+ junk, al, command = args
32
+ old_command = @proc.aliases[al]
33
+ if @proc.commands.member?(command)
34
+ @proc.aliases[al] = command
35
+ if old_command
36
+ msg("Alias '#{al}' for command '#{command}' replaced old " +
37
+ "alias for '#{old_command}'.")
38
+ else
39
+ msg "New alias '#{al}' for command '#{command}' created."
40
+ end
41
+ else
42
+ errmsg "You must alias to a command name, and '#{command}' isn't one."
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ if __FILE__ == $0
49
+ # Demo it.
50
+ require_relative '../mock'
51
+ dbgr, cmd = MockDebugger::setup
52
+ cmd.run %W(#{cmd.name} yy foo)
53
+ cmd.run [cmd.name]
54
+ cmd.run %W(cmd.name yy next)
55
+ end
@@ -0,0 +1,76 @@
1
+ require 'rubygems'; require 'require_relative'
2
+ require_relative './base/cmd'
3
+
4
+ class Trepan::Command::BacktraceCommand < Trepan::Command
5
+ ALIASES = %w(bt where)
6
+ CATEGORY = 'stack'
7
+ MAX_ARGS = 2 # Need at most this many
8
+ NAME = File.basename(__FILE__, '.rb')
9
+ HELP = <<-HELP
10
+ #{NAME} [full] [COUNT]
11
+
12
+ Print a backtrace of all stack frames, or innermost COUNT frames. Use
13
+ of the 'full' qualifier also prints the values of the local variables.
14
+
15
+ Passing "full" will also show the values of all locals variables in
16
+ each frame.
17
+
18
+ Normally outer frames which constitute debugger overhead are hidden
19
+ from view. However if a count is given and it runs into those hidden
20
+ frames, they will be shown.
21
+
22
+ Examples:
23
+
24
+ #{NAME}
25
+ #{NAME} full # show
26
+ #{NAME} 2
27
+ #{NAME} 3 full
28
+ #{NAME} full 3 # same as above
29
+ #{NAME} 1000 # probably will show any outer hidden frames
30
+
31
+ See also 'set hidelevel'.
32
+ HELP
33
+ NEED_STACK = true
34
+ SHORT_HELP = 'Show the current call stack'
35
+
36
+ def run(args)
37
+ verbose_ary, count_ary = args[1..-1].partition {|item| item =~ /full/i}
38
+ verbose = !verbose_ary.empty?
39
+
40
+ if count_ary.size > 1
41
+ errmsg "Expecting only at most one parameter other than 'full'"
42
+ return
43
+ end
44
+
45
+ if 1 == count_ary.size
46
+ begin
47
+ count = Integer(count_ary[0])
48
+ rescue
49
+ errmsg "Expecting count to be an integer; got #{count_ary[0]}"
50
+ return
51
+ end
52
+ elsif 0 == count_ary.size
53
+ count = proc.stack_size
54
+ else
55
+ errmsg "Wrong number of parameters. Expecting at most 2."
56
+ return
57
+ end
58
+
59
+ @proc.dbgr.each_frame(@proc.top_frame) do |frame|
60
+ if count and frame.number >= count
61
+ msg "(More stack frames follow...)" if count != proc.stack_size
62
+ return
63
+ end
64
+
65
+ prefix = (frame == @proc.frame) ? '-->' : ' '
66
+ msg "%s #%d %s" % [prefix, frame.number,
67
+ frame.describe(:show_ip => verbose)]
68
+
69
+ if verbose
70
+ frame.local_variables.each do |local|
71
+ msg " #{local} = #{frame.run(local.to_s).inspect}"
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,173 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ # Base class of all commands. Code common to all commands is here.
4
+ # Note: don't end classname with Command (capital C) since main
5
+ # will think this a command name like QuitCommand
6
+ require 'rubygems'; require 'require_relative'
7
+ require 'columnize'
8
+ require_relative '../../../app/complete'
9
+
10
+ class Trepan
11
+ class Command
12
+ attr_accessor :core, :proc
13
+
14
+ unless defined?(MIN_ARGS)
15
+ MIN_ARGS = 0 # run()'s args array must be at least this many
16
+ MAX_ARGS = nil # run()'s args array must be at least this many
17
+ NEED_STACK = false # We'll say that commands which need a stack
18
+ # to run have to declare that and those that
19
+ # don't don't have to mention it.
20
+ end
21
+
22
+ def initialize(proc)
23
+ @name = my_const(:NAME)
24
+ @proc = proc
25
+ end
26
+
27
+ def category
28
+ my_const(:CATEGORY)
29
+ end
30
+
31
+ # List commands arranged in an aligned columns
32
+ def columnize_commands(commands)
33
+ width = settings[:maxwidth]
34
+ Columnize::columnize(commands, width, ' ' * 4,
35
+ true, true, ' ' * 2).chomp
36
+ end
37
+
38
+ def columnize_numbers(commands)
39
+ width = settings[:maxwidth]
40
+ Columnize::columnize(commands, width, ', ',
41
+ false, false, ' ' * 2).chomp
42
+ end
43
+
44
+ # FIXME: probably there is a way to do the delegation to proc methods
45
+ # without having type it all out.
46
+
47
+ def confirm(message, default)
48
+ @proc.confirm(message, default)
49
+ end
50
+
51
+ def errmsg(message, opts={})
52
+ @proc.errmsg(message, opts)
53
+ end
54
+
55
+ def obj_const(obj, name)
56
+ obj.class.const_get(name)
57
+ end
58
+
59
+ def msg(message, opts={})
60
+ @proc.msg(message, opts)
61
+ end
62
+
63
+ # Convenience short-hand for @dbgr.intf[-1].msg_nocr
64
+ def msg_nocr(msg, opts={})
65
+ @proc.msg_nocr(msg, opts)
66
+ end
67
+
68
+ def my_const(name)
69
+ # Set class constant SHORT_HELP to be the first line of HELP
70
+ # unless it has been defined in the class already.
71
+ # The below was the simplest way I could find to do this since
72
+ # we are the super class but want to set the subclass's constant.
73
+ # defined? didn't seem to work here.
74
+ c = self.class.constants
75
+ if c.member?('HELP') and !c.member?('SHORT_HELP')
76
+ short_help = self.class.const_get(:HELP).split("\n")[0].chomp('.')
77
+ self.class.const_set(:SHORT_HELP, short_help)
78
+ end
79
+ self.class.const_get(name)
80
+ end
81
+
82
+ def name
83
+ self.class.const_get(:NAME)
84
+ end
85
+
86
+ # The method that implements the debugger command.
87
+ def run(*args)
88
+ raise RuntimeError, 'You need to define this method elsewhere'
89
+ end
90
+
91
+ def section(message, opts={})
92
+ @proc.section(message, opts)
93
+ end
94
+
95
+ def settings
96
+ @proc.settings
97
+ end
98
+
99
+ def short_help
100
+ help_constant_sym = if self.class.constants.member?('SHORT_HELP')
101
+ :SHORT_HELP
102
+ else :HELP
103
+ end
104
+ my_const(help_constant_sym)
105
+ end
106
+
107
+ # Define a method called 'complete' on the singleton class.
108
+ def self.completion(ary)
109
+ self.send(:define_method,
110
+ :complete,
111
+ Proc.new {|prefix|
112
+ Trepan::Complete.complete_token(ary, prefix) })
113
+ end
114
+
115
+ # From reference debugger
116
+ def run_code(str)
117
+ @proc.dbgr.current_frame.run(str)
118
+ end
119
+
120
+ def current_method
121
+ @proc.frame.method
122
+ end
123
+
124
+ def current_frame
125
+ @proc.frame
126
+ end
127
+
128
+ def variables
129
+ @proc.variables
130
+ end
131
+
132
+ def listen(step=false)
133
+ @proc.listen(step)
134
+ end
135
+
136
+ end
137
+ end
138
+ if __FILE__ == $0
139
+ class Trepan
140
+ class CmdProcessor
141
+ def initialize(dbgr)
142
+ end
143
+ def confirm(message, default)
144
+ p ['confirm: ', message, default]
145
+ end
146
+ def errmsg(message, opts)
147
+ p ['err:', message, opts]
148
+ end
149
+ def msg(message, opts)
150
+ p [message, opts]
151
+ end
152
+ def msg_nocr(message, opts)
153
+ p ['nocr: ', message, opts]
154
+ end
155
+ def section(message, opts)
156
+ p ['section: ', message, opts]
157
+ end
158
+ end
159
+ class Command::Test < Trepan::Command
160
+ NAME = 'test'
161
+ CATEGORY = 'testcategory'
162
+ completion %w(a aa ab ba aac)
163
+ end
164
+ end
165
+ proc = Trepan::CmdProcessor.new(nil)
166
+ cmd = Trepan::Command::Test.new(proc)
167
+ %w(confirm errmsg msg msg_nocr section).each do |meth|
168
+ cmd.send(meth, 'test', nil)
169
+ end
170
+ p cmd.complete('aa')
171
+ cmd.instance_variable_set('@completions', %w(aardvark apple))
172
+ p cmd.complete('aa')
173
+ end
@@ -0,0 +1,229 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ # A base class for debugger subcommands.
4
+ #
5
+ # Note: don't end classname with Command (capital C) since main
6
+ # will think this a command name like QuitCommand
7
+ # ^
8
+
9
+ # Base Class for Trepan subcommands. We pull in some helper
10
+ # functions for command from module cmdfns.
11
+
12
+ require 'rubygems'; require 'require_relative'
13
+ require_relative 'cmd'
14
+
15
+ class Trepan
16
+
17
+ class Subcommand < Command
18
+
19
+ NotImplementedMessage =
20
+ "This method must be overridden in a subclass" unless
21
+ defined?(NotImplementedMessage)
22
+
23
+ attr_reader :name
24
+
25
+ unless defined?(IN_LIST)
26
+ IN_LIST = true # Show item in help list of commands
27
+ RUN_CMD = true # Run subcommand for those subcommands like "show"
28
+ # which append current settings to list output.
29
+ MIN_ABBREV = 1
30
+ NEED_STACK = false
31
+ NAME = 'your_command_name'
32
+ end
33
+
34
+
35
+ # cmd contains the command object that this
36
+ # command is invoked through. A debugger field gives access to
37
+ # the stack frame and I/O.
38
+ def initialize(cmd)
39
+ @cmd = cmd
40
+
41
+ # Convenience class access. We don't expect that any of these
42
+ # will change over the course of the program execution like
43
+ # errmsg(), msg(), and msg_nocr() might. (See the note below
44
+ # on these latter 3 methods.)
45
+ #
46
+ @core = cmd.core
47
+ @proc = cmd.proc
48
+ # @dbgr = cmd.dbgr
49
+
50
+ # By default the name of the subcommand will be the name of the
51
+ # last part of module (e.g. "args" in "info.args" or "basename"
52
+ # in "shows.basename"). However it *is* possible for one to change
53
+ # that -- perhaps one may want to put several subcommands into
54
+ # a single file. So in those cases, one will have to set @name
55
+ # accordingly by other means.
56
+ @name = my_const(:NAME).to_sym
57
+
58
+ end
59
+
60
+ # Convenience short-hand for @proc.confirm
61
+ def confirm(msg, default=false)
62
+ return(@proc.confirm(msg, default))
63
+ end
64
+
65
+ def prefix
66
+ my_const('PREFIX')
67
+ end
68
+
69
+ # Set a Boolean-valued debugger setting.
70
+ def run_set_bool(args, default=true)
71
+ onoff_arg = args.size < 3 ? 'on' : args[2]
72
+ begin
73
+ settings[subcmd_setting_key] = @proc.get_onoff(onoff_arg)
74
+ run_show_bool
75
+ rescue NameError, TypeError
76
+ end
77
+ end
78
+
79
+ # set an Integer-valued debugger setting.
80
+ def run_set_int(arg, msg_on_error, min_value=nil, max_value=nil)
81
+ if arg.strip.empty?
82
+ errmsg('You need to supply a number.')
83
+ return
84
+ end
85
+ val = @proc.get_an_int(arg,
86
+ :max_value => max_value,
87
+ :min_value => min_value,
88
+ :msg_on_error => msg_on_error
89
+ )
90
+ if val
91
+ settings[subcmd_setting_key] = val
92
+ run_show_int
93
+ end
94
+ end
95
+
96
+ # Generic subcommand showing a boolean-valued debugger setting.
97
+ def run_show_bool(what=nil)
98
+ val = show_onoff(settings[subcmd_setting_key])
99
+ what = @name unless what
100
+ msg("%s is %s." % [what, val])
101
+ end
102
+
103
+ # Generic subcommand integer value display
104
+ def run_show_int(what=nil)
105
+ val = settings[subcmd_setting_key]
106
+ what = self.class.const_get(:PREFIX)[1..-1].join(' ') unless what
107
+ msg("%s is %d." % [what, val])
108
+ end
109
+
110
+ # Generic subcommand value display. Pass in a hash which may
111
+ # which optionally contain:
112
+ #
113
+ # :name - the String name of key in settings to use. If :value
114
+ # (described below) is set, then setting :name does
115
+ # nothing.
116
+ #
117
+ # :what - the String name of what we are showing. If none is
118
+ # given, then we use the part of the SHORT_HELP string.
119
+ #
120
+ # :value - a String value associated with "what" above. If none
121
+ # is given, then we pick up the value from settings.
122
+ #
123
+ def run_show_val(opts={})
124
+ what = opts.member?(:what) ? opts[:what] : string_in_show
125
+ name = opts.member?(:name) ? opts[:name] : @name
126
+ val = opts.member?(:value) ? opts[:value] : settings[name]
127
+ msg("%s is %s." % [what, val])
128
+ end
129
+
130
+ def save_command_from_settings
131
+ ["#{subcmd_prefix_string} #{settings[subcmd_setting_key]}"]
132
+ end
133
+
134
+ def settings
135
+ @proc.settings
136
+ end
137
+
138
+ def subcmd_prefix_string
139
+ self.class.const_get(:PREFIX).join(' ')
140
+ end
141
+
142
+ def subcmd_setting_key
143
+ self.class.const_get(:PREFIX)[1..-1].join('').to_sym
144
+ end
145
+
146
+ # Return 'on' for true and 'off' for false, and ?? for anything else.
147
+ def show_onoff(bool)
148
+ case(bool)
149
+ when true; return 'on'
150
+ when false; return 'off'
151
+ when nil; return 'unset'
152
+ else return '??'
153
+ end
154
+ end
155
+
156
+ def string_in_show
157
+ my_const(:SHORT_HELP)['Show '.size .. -1].capitalize
158
+ end
159
+
160
+ def summary_help(subcmd_name)
161
+ msg_nocr("%-12s: %s" % [subcmd_name, my_const(:SHORT_HELP)])
162
+ end
163
+ end
164
+
165
+ class SetBoolSubcommand < Subcommand
166
+ completion %w(on off)
167
+
168
+ def run(args)
169
+ run_set_bool(args)
170
+ end
171
+
172
+ def save_command
173
+ val = settings[subcmd_setting_key] ? 'on' : 'off'
174
+ ["#{subcmd_prefix_string} #{val}"]
175
+ end
176
+ end
177
+
178
+ class ShowBoolSubcommand < Subcommand
179
+ def run(args)
180
+ run_show_bool(string_in_show)
181
+ end
182
+ end
183
+
184
+ class ShowIntSubcommand < Subcommand
185
+ def run(args)
186
+ doc =
187
+ if self.respond_to?(:short_help)
188
+ short_help
189
+ else
190
+ my_const(:HELP)[5..-2].capitalize
191
+ end
192
+ run_show_int(doc)
193
+ end
194
+ end
195
+
196
+ end
197
+
198
+ module Trepanning
199
+ module Subcommand
200
+ module_function
201
+ def set_name_prefix(__file__, klass)
202
+ dirname = File.basename(File.dirname(File.expand_path(__file__)))
203
+ name = File.basename(__file__, '.rb')
204
+ klass.const_set('NAME', name)
205
+ klass.const_set('PREFIX', %W(#{dirname[0...-'_subcmd'.size]} #{name}))
206
+ end
207
+ end
208
+ end
209
+
210
+ if __FILE__ == $0
211
+ # Demo it.
212
+ require_relative '../../mock'
213
+ dbgr = MockDebugger::MockDebugger.new
214
+ # cmds = dbgr.core.processor.commands
215
+ # p cmds.keys
216
+ # subcmd = Trepan::Subcommand.new(cmds['exit'])
217
+ # def subcmd.msg(message)
218
+ # puts message
219
+ # end
220
+ # def subcmd.errmsg(message)
221
+ # puts message
222
+ # end
223
+ # p subcmd.settings
224
+ # p subcmd.show_onoff(subcmd.settings[:autoeval])
225
+ # subcmd.run_set_int('', 'Just a test')
226
+ class Trepan::Subcommand::Foo < Trepan::Subcommand
227
+ Trepanning::Subcommand.set_name_prefix(__FILE__, self)
228
+ end
229
+ end