rb8-trepanning 0.1.3

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 (274) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGES +34 -0
  3. data/ChangeLog +875 -0
  4. data/README.textile +59 -0
  5. data/Rakefile +215 -0
  6. data/app/.gitignore +1 -0
  7. data/app/cmd_parse.kpeg +241 -0
  8. data/app/cmd_parse.rb +212 -0
  9. data/app/cmd_parser.rb +1948 -0
  10. data/app/complete.rb +79 -0
  11. data/app/default.rb +90 -0
  12. data/app/display.rb +148 -0
  13. data/app/eventbuffer.rb +147 -0
  14. data/app/frame.rb +166 -0
  15. data/app/irb.rb +114 -0
  16. data/app/options.rb +200 -0
  17. data/app/run.rb +74 -0
  18. data/app/util.rb +65 -0
  19. data/bin/.gitignore +1 -0
  20. data/bin/trepan8 +115 -0
  21. data/data/.gitignore +1 -0
  22. data/data/irbrc +41 -0
  23. data/interface/.gitignore +1 -0
  24. data/interface/base_intf.rb +109 -0
  25. data/interface/client.rb +82 -0
  26. data/interface/comcodes.rb +20 -0
  27. data/interface/script.rb +110 -0
  28. data/interface/server.rb +147 -0
  29. data/interface/user.rb +165 -0
  30. data/io/base_io.rb +148 -0
  31. data/io/input.rb +158 -0
  32. data/io/null_output.rb +46 -0
  33. data/io/string_array.rb +156 -0
  34. data/io/tcpclient.rb +129 -0
  35. data/io/tcpfns.rb +33 -0
  36. data/io/tcpserver.rb +141 -0
  37. data/lib/debugger.rb +8 -0
  38. data/lib/trepanning.rb +283 -0
  39. data/processor/.gitignore +1 -0
  40. data/processor/command-ruby-debug/breakpoints.rb +155 -0
  41. data/processor/command-ruby-debug/catchpoint.rb +55 -0
  42. data/processor/command-ruby-debug/condition.rb +49 -0
  43. data/processor/command-ruby-debug/control.rb +31 -0
  44. data/processor/command-ruby-debug/display.rb +120 -0
  45. data/processor/command-ruby-debug/enable.rb +202 -0
  46. data/processor/command-ruby-debug/frame.rb +199 -0
  47. data/processor/command-ruby-debug/help.rb +63 -0
  48. data/processor/command-ruby-debug/info.rb +359 -0
  49. data/processor/command-ruby-debug/method.rb +84 -0
  50. data/processor/command-ruby-debug/reload.rb +40 -0
  51. data/processor/command-ruby-debug/save.rb +90 -0
  52. data/processor/command-ruby-debug/set.rb +237 -0
  53. data/processor/command-ruby-debug/show.rb +251 -0
  54. data/processor/command-ruby-debug/source.rb +36 -0
  55. data/processor/command-ruby-debug/threads.rb +189 -0
  56. data/processor/command-ruby-debug/trace.rb +57 -0
  57. data/processor/command-ruby-debug/variables.rb +199 -0
  58. data/processor/command.rb +270 -0
  59. data/processor/command/.gitignore +1 -0
  60. data/processor/command/alias.rb +54 -0
  61. data/processor/command/backtrace.rb +123 -0
  62. data/processor/command/base/cmd.rb +177 -0
  63. data/processor/command/base/subcmd.rb +230 -0
  64. data/processor/command/base/submgr.rb +188 -0
  65. data/processor/command/base/subsubcmd.rb +128 -0
  66. data/processor/command/base/subsubmgr.rb +199 -0
  67. data/processor/command/break.rb +114 -0
  68. data/processor/command/catch.rb +71 -0
  69. data/processor/command/complete.rb +39 -0
  70. data/processor/command/continue.rb +57 -0
  71. data/processor/command/directory.rb +50 -0
  72. data/processor/command/disable.rb +85 -0
  73. data/processor/command/display.rb +78 -0
  74. data/processor/command/down.rb +54 -0
  75. data/processor/command/edit.rb +79 -0
  76. data/processor/command/enable.rb +48 -0
  77. data/processor/command/eval.rb +90 -0
  78. data/processor/command/exit.rb +66 -0
  79. data/processor/command/finish.rb +59 -0
  80. data/processor/command/frame.rb +97 -0
  81. data/processor/command/help.rb +230 -0
  82. data/processor/command/help/.gitignore +1 -0
  83. data/processor/command/help/README +10 -0
  84. data/processor/command/help/command.txt +58 -0
  85. data/processor/command/help/examples.txt +16 -0
  86. data/processor/command/help/filename.txt +40 -0
  87. data/processor/command/help/location.txt +37 -0
  88. data/processor/command/help/suffixes.txt +17 -0
  89. data/processor/command/info.rb +28 -0
  90. data/processor/command/info_subcmd/.gitignore +1 -0
  91. data/processor/command/info_subcmd/args.rb +39 -0
  92. data/processor/command/info_subcmd/breakpoints.rb +80 -0
  93. data/processor/command/info_subcmd/catch.rb +36 -0
  94. data/processor/command/info_subcmd/files.rb +39 -0
  95. data/processor/command/info_subcmd/globals.rb +64 -0
  96. data/processor/command/info_subcmd/line.rb +30 -0
  97. data/processor/command/info_subcmd/locals.rb +69 -0
  98. data/processor/command/info_subcmd/macro.rb +62 -0
  99. data/processor/command/info_subcmd/program.rb +51 -0
  100. data/processor/command/info_subcmd/ruby.rb +57 -0
  101. data/processor/command/info_subcmd/source.rb +74 -0
  102. data/processor/command/info_subcmd/stack.rb +25 -0
  103. data/processor/command/info_subcmd/threads.rb +75 -0
  104. data/processor/command/kill.rb +78 -0
  105. data/processor/command/list.rb +117 -0
  106. data/processor/command/macro.rb +68 -0
  107. data/processor/command/next.rb +79 -0
  108. data/processor/command/parsetree.rb +56 -0
  109. data/processor/command/pp.rb +40 -0
  110. data/processor/command/pr.rb +37 -0
  111. data/processor/command/ps.rb +40 -0
  112. data/processor/command/restart.rb +86 -0
  113. data/processor/command/save.rb +58 -0
  114. data/processor/command/set.rb +47 -0
  115. data/processor/command/set_subcmd/.gitignore +1 -0
  116. data/processor/command/set_subcmd/abbrev.rb +25 -0
  117. data/processor/command/set_subcmd/auto.rb +27 -0
  118. data/processor/command/set_subcmd/auto_subcmd/.gitignore +1 -0
  119. data/processor/command/set_subcmd/auto_subcmd/eval.rb +53 -0
  120. data/processor/command/set_subcmd/auto_subcmd/irb.rb +33 -0
  121. data/processor/command/set_subcmd/auto_subcmd/list.rb +33 -0
  122. data/processor/command/set_subcmd/basename.rb +25 -0
  123. data/processor/command/set_subcmd/callstyle.rb +46 -0
  124. data/processor/command/set_subcmd/confirm.rb +24 -0
  125. data/processor/command/set_subcmd/debug.rb +47 -0
  126. data/processor/command/set_subcmd/different.rb +61 -0
  127. data/processor/command/set_subcmd/highlight.rb +43 -0
  128. data/processor/command/set_subcmd/max.rb +26 -0
  129. data/processor/command/set_subcmd/max_subcmd/list.rb +49 -0
  130. data/processor/command/set_subcmd/max_subcmd/stack.rb +50 -0
  131. data/processor/command/set_subcmd/max_subcmd/string.rb +76 -0
  132. data/processor/command/set_subcmd/max_subcmd/width.rb +49 -0
  133. data/processor/command/set_subcmd/reload.rb +42 -0
  134. data/processor/command/set_subcmd/timer.rb +58 -0
  135. data/processor/command/set_subcmd/trace.rb +37 -0
  136. data/processor/command/set_subcmd/trace_subcmd/buffer.rb +42 -0
  137. data/processor/command/set_subcmd/trace_subcmd/print.rb +41 -0
  138. data/processor/command/shell.rb +139 -0
  139. data/processor/command/show.rb +39 -0
  140. data/processor/command/show_subcmd/.gitignore +1 -0
  141. data/processor/command/show_subcmd/abbrev.rb +20 -0
  142. data/processor/command/show_subcmd/alias.rb +46 -0
  143. data/processor/command/show_subcmd/args.rb +34 -0
  144. data/processor/command/show_subcmd/auto.rb +28 -0
  145. data/processor/command/show_subcmd/auto_subcmd/eval.rb +27 -0
  146. data/processor/command/show_subcmd/auto_subcmd/irb.rb +23 -0
  147. data/processor/command/show_subcmd/auto_subcmd/list.rb +22 -0
  148. data/processor/command/show_subcmd/basename.rb +20 -0
  149. data/processor/command/show_subcmd/callstyle.rb +22 -0
  150. data/processor/command/show_subcmd/confirm.rb +18 -0
  151. data/processor/command/show_subcmd/debug.rb +26 -0
  152. data/processor/command/show_subcmd/debug_subcmd/dbgr.rb +21 -0
  153. data/processor/command/show_subcmd/debug_subcmd/skip.rb +22 -0
  154. data/processor/command/show_subcmd/debug_subcmd/step.rb +22 -0
  155. data/processor/command/show_subcmd/different.rb +26 -0
  156. data/processor/command/show_subcmd/directories.rb +22 -0
  157. data/processor/command/show_subcmd/highlight.rb +24 -0
  158. data/processor/command/show_subcmd/max.rb +27 -0
  159. data/processor/command/show_subcmd/max_subcmd/list.rb +38 -0
  160. data/processor/command/show_subcmd/max_subcmd/stack.rb +36 -0
  161. data/processor/command/show_subcmd/max_subcmd/string.rb +42 -0
  162. data/processor/command/show_subcmd/max_subcmd/width.rb +37 -0
  163. data/processor/command/show_subcmd/reload.rb +18 -0
  164. data/processor/command/show_subcmd/timer.rb +18 -0
  165. data/processor/command/show_subcmd/trace.rb +29 -0
  166. data/processor/command/show_subcmd/trace_subcmd/buffer.rb +65 -0
  167. data/processor/command/show_subcmd/trace_subcmd/print.rb +23 -0
  168. data/processor/command/show_subcmd/version.rb +23 -0
  169. data/processor/command/source.rb +134 -0
  170. data/processor/command/step.rb +81 -0
  171. data/processor/command/tbreak.rb +19 -0
  172. data/processor/command/unalias.rb +44 -0
  173. data/processor/command/undisplay.rb +59 -0
  174. data/processor/command/up.rb +72 -0
  175. data/processor/default.rb +56 -0
  176. data/processor/display.rb +17 -0
  177. data/processor/eval.rb +113 -0
  178. data/processor/eventbuf.rb +105 -0
  179. data/processor/frame.rb +172 -0
  180. data/processor/help.rb +92 -0
  181. data/processor/helper.rb +76 -0
  182. data/processor/hook.rb +134 -0
  183. data/processor/load_cmds.rb +258 -0
  184. data/processor/location.rb +174 -0
  185. data/processor/main.rb +455 -0
  186. data/processor/mock.rb +136 -0
  187. data/processor/msg.rb +61 -0
  188. data/processor/processor.rb +674 -0
  189. data/processor/running.rb +168 -0
  190. data/processor/stepping.rb +18 -0
  191. data/processor/subcmd.rb +161 -0
  192. data/processor/validate.rb +355 -0
  193. data/processor/virtual.rb +34 -0
  194. data/test/data/.gitignore +1 -0
  195. data/test/data/break_bad.cmd +19 -0
  196. data/test/data/break_bad.right +29 -0
  197. data/test/data/break_loop_bug.cmd +5 -0
  198. data/test/data/break_loop_bug.right +15 -0
  199. data/test/data/dollar-0.right +2 -0
  200. data/test/data/dollar-0a.right +2 -0
  201. data/test/data/dollar-0b.right +2 -0
  202. data/test/data/edit.cmd +14 -0
  203. data/test/data/edit.right +24 -0
  204. data/test/data/file-with-space.cmd +6 -0
  205. data/test/data/file-with-space.right +4 -0
  206. data/test/data/printvar.cmd +17 -0
  207. data/test/data/printvar.right +31 -0
  208. data/test/data/raise.cmd +11 -0
  209. data/test/data/raise.right +19 -0
  210. data/test/data/source.cmd +5 -0
  211. data/test/data/source.right +18 -0
  212. data/test/data/stepping-1.9.right +50 -0
  213. data/test/data/stepping.cmd +21 -0
  214. data/test/data/stepping.right +48 -0
  215. data/test/data/trepan8-save.1 +6 -0
  216. data/test/example/bp_loop_issue.rb +3 -0
  217. data/test/example/break-bug.rb +7 -0
  218. data/test/example/brkpt-class-bug.rb +8 -0
  219. data/test/example/classes.rb +11 -0
  220. data/test/example/dollar-0.rb +5 -0
  221. data/test/example/except-bug1.rb +4 -0
  222. data/test/example/except-bug2.rb +7 -0
  223. data/test/example/file with space.rb +1 -0
  224. data/test/example/gcd.rb +18 -0
  225. data/test/example/info-var-bug.rb +47 -0
  226. data/test/example/info-var-bug2.rb +2 -0
  227. data/test/example/null.rb +1 -0
  228. data/test/example/pm-bug.rb +3 -0
  229. data/test/example/pm.rb +11 -0
  230. data/test/example/raise.rb +3 -0
  231. data/test/integration/.gitignore +4 -0
  232. data/test/integration/config.yaml +8 -0
  233. data/test/integration/helper.rb +154 -0
  234. data/test/integration/test-break_bad.rb +26 -0
  235. data/test/integration/test-dollar-0.rb +31 -0
  236. data/test/integration/test-edit.rb +17 -0
  237. data/test/integration/test-file-with-space.rb +26 -0
  238. data/test/integration/test-printvar.rb +17 -0
  239. data/test/integration/test-raise.rb +21 -0
  240. data/test/integration/test-source.rb +16 -0
  241. data/test/integration/test-stepping.rb +24 -0
  242. data/test/unit/.gitignore +1 -0
  243. data/test/unit/cmd-helper.rb +52 -0
  244. data/test/unit/mock-helper.rb +12 -0
  245. data/test/unit/test-app-cmd_parse.rb +97 -0
  246. data/test/unit/test-app-cmd_parser.rb +23 -0
  247. data/test/unit/test-app-complete.rb +39 -0
  248. data/test/unit/test-app-frame.rb +32 -0
  249. data/test/unit/test-app-options.rb +92 -0
  250. data/test/unit/test-app-run.rb +14 -0
  251. data/test/unit/test-app-util.rb +44 -0
  252. data/test/unit/test-base-cmd.rb +45 -0
  253. data/test/unit/test-base-subcmd.rb +57 -0
  254. data/test/unit/test-base-submgr.rb +23 -0
  255. data/test/unit/test-base-subsubcmd.rb +17 -0
  256. data/test/unit/test-cmd-alias.rb +48 -0
  257. data/test/unit/test-cmd-exit.rb +27 -0
  258. data/test/unit/test-cmd-help.rb +104 -0
  259. data/test/unit/test-cmd-kill.rb +46 -0
  260. data/test/unit/test-cmd-source.rb +34 -0
  261. data/test/unit/test-completion.rb +42 -0
  262. data/test/unit/test-intf-user.rb +46 -0
  263. data/test/unit/test-io-input.rb +27 -0
  264. data/test/unit/test-io-tcp.rb +33 -0
  265. data/test/unit/test-io-tcpclient.rb +54 -0
  266. data/test/unit/test-io-tcpfns.rb +17 -0
  267. data/test/unit/test-io-tcpserver.rb +50 -0
  268. data/test/unit/test-proc-eval.rb +36 -0
  269. data/test/unit/test-proc-hook.rb +30 -0
  270. data/test/unit/test-proc-load_cmds.rb +50 -0
  271. data/test/unit/test-proc-location.rb +79 -0
  272. data/test/unit/test-subcmd-help.rb +44 -0
  273. data/trepan8.gemspec +52 -0
  274. metadata +391 -0
@@ -0,0 +1,79 @@
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ require 'rubygems'; require 'require_relative'
3
+ require_relative 'base/cmd'
4
+
5
+ class Trepan::Command::NextCommand < Trepan::Command
6
+
7
+ ALIASES = %w(n n+ n- next+)
8
+ CATEGORY = 'running'
9
+ NAME = File.basename(__FILE__, '.rb')
10
+ HELP = <<-HELP
11
+ #{NAME}[+|-] [into] [count]
12
+
13
+ Attempt to continue execution and stop at the next line. If there is
14
+ a conditional branch between the current position and the next line,
15
+ execution is stopped within the conditional branch instead.
16
+
17
+ The optional argument is a number which specifies how many lines to
18
+ attempt to skip past before stopping execution.
19
+
20
+ If the current line is the last in a method, execution is stopped
21
+ at the current position of the caller.
22
+
23
+ See also 'step' and 'nexti'.
24
+
25
+ Examples:
26
+ #{NAME} # next 1 line
27
+ #{NAME} 1 # same as above
28
+ #{NAME}+ # same but force stopping on a new line
29
+ #{NAME}- # same but force stopping on a new line or a new frame added
30
+
31
+ Related and similar is the 'step' (step into) and 'finish' (step out)
32
+ commands.
33
+ HELP
34
+ NEED_RUNNING = true
35
+ SHORT_HELP = 'Step into next method call or to next line'
36
+
37
+ Keyword_to_related_cmd = {
38
+ 'out' => 'finish',
39
+ 'over' => 'next',
40
+ 'into' => 'step',
41
+ }
42
+
43
+ # self.allow_in_post_mortem = false
44
+ # self.need_context = true
45
+
46
+ def run(args)
47
+ condition = nil
48
+ opts = {}
49
+ if args.size == 1
50
+ step_count = 1
51
+ else
52
+ replace_cmd = Keyword_to_related_cmd[args[1]]
53
+ if replace_cmd
54
+ cmd = @proc.commands[replace_cmd]
55
+ return cmd.run([replace_cmd] + args[2..-1])
56
+ end
57
+ step_str = args[1]
58
+ opts = @proc.parse_next_step_suffix(args[0])
59
+ count_opts = {
60
+ :msg_on_error =>
61
+ "The #{NAME} command argument must eval to an integer. Got: %s" %
62
+ step_str,
63
+ :min_value => 1
64
+ }
65
+ step_count = @proc.get_an_int(step_str, count_opts)
66
+ return unless step_count
67
+ end
68
+ ## @proc.state.context.step(step_count, force)
69
+ @proc.context.step_over(step_count, @proc.state.frame_pos,
70
+ opts[:different_pos])
71
+ @proc.state.proceed
72
+ @proc.leave_cmd_loop = true
73
+ end
74
+ end
75
+
76
+ if __FILE__ == $0
77
+ require_relative '../mock'
78
+ dbgr, cmd = MockDebugger::setup
79
+ end
@@ -0,0 +1,56 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ begin
4
+ require 'rubygems'; require 'require_relative'
5
+ require 'parse_tree'
6
+ require_relative 'base/cmd'
7
+ require_relative '../../app/cmd_parse'
8
+ class Trepan::Command::ParseTreeCommand < Trepan::Command
9
+
10
+ unless defined?(HELP)
11
+ NAME = File.basename(__FILE__, '.rb')
12
+ HELP = <<-HELP
13
+ #{NAME}
14
+ #{NAME} method
15
+
16
+ In the first form, print a ParseTree S-expression of the current
17
+ class.
18
+ In the second form, preint a ParseTree S-expression of the current method.
19
+ In the third form print a ParseTree S-expression of CLASS.
20
+ In the fourth form, print a ParseTree S-expression of the given method.
21
+ HELP
22
+
23
+ # ALIASES = %w(p)
24
+ CATEGORY = 'data'
25
+ SHORT_HELP = 'PrettyPrint a ParseTree S-expression'
26
+ end
27
+
28
+ def run(args)
29
+ meth = nil
30
+ case args.size
31
+ when 1
32
+ method_name = @proc.frame.method_name
33
+ when 2
34
+ method_name = args[1]
35
+ else
36
+ errmsg 'Expecting a method name'
37
+ end
38
+ meth = Trepan::CmdParser.meth_for_string(method_name, @proc.frame.binding)
39
+ if meth and meth.kind_of?(Method)
40
+ section "ParseTree for method: #{method_name}"
41
+ msg ParseTree.translate(meth.owner, meth.name.to_sym).pretty_inspect
42
+ end
43
+ end
44
+
45
+ if __FILE__ == $0
46
+ require 'pp'
47
+ require_relative '../mock'
48
+ dbgr, cmd = MockDebugger::setup
49
+ cmd.proc.frame_setup(Debugger.current_context, nil)
50
+ cmd.proc.frame.instance_variable_set('@binding', TOPLEVEL_BINDING)
51
+ cmd.run([cmd.name, 'FileUtils.rm'])
52
+ end
53
+
54
+ end
55
+ rescue LoadError
56
+ end
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require 'pp'
5
+ require_relative 'base/cmd'
6
+ class Trepan::Command::PPCommand < Trepan::Command
7
+
8
+ unless defined?(HELP)
9
+ NAME = File.basename(__FILE__, '.rb')
10
+ HELP =
11
+ "#{NAME} EXPRESSION
12
+
13
+ Prtty Print the value of the EXPRESSION. Variables accessible are
14
+ those of the environment of the selected stack frame, plus globals.
15
+
16
+ If the length output string large, the first part of the value is
17
+ shown and ... indicates it has been truncated.
18
+
19
+ See 'set max string' to change the string truncation limit.
20
+ "
21
+ CATEGORY = 'data'
22
+ SHORT_HELP = 'pretty print expression truncating long output'
23
+ end
24
+
25
+ def run(args)
26
+ obj = @proc.debug_eval(@proc.cmd_argstr)
27
+ msg (obj.respond_to?(:pretty_inspect) ? obj.pretty_inspect : obj.inspect)
28
+ end
29
+ end
30
+
31
+ if __FILE__ == $0
32
+ require_relative '../mock'
33
+ dbgr, cmd = MockDebugger::setup
34
+ ['(0..10).to_a', '$LOADED_FEATURES'].each do |expr_str|
35
+ cmd_argstr = expr_str
36
+ cmd.proc.instance_variable_set('@cmd_argstr', cmd_argstr)
37
+ cmd.run([cmd.name, cmd_argstr])
38
+ puts '-' * 20
39
+ end
40
+ end
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative 'base/cmd'
5
+ class Trepan::Command::PrCommand < Trepan::Command
6
+
7
+ unless defined?(HELP)
8
+ NAME = File.basename(__FILE__, '.rb')
9
+ HELP =
10
+ "#{NAME} EXPRESSION
11
+
12
+ Print the value of the EXPRESSION. Variables accessible are those of the
13
+ environment of the selected stack frame, plus globals.
14
+
15
+ If the length output string large, the first part of the value is
16
+ shown and ... indicates it has been truncated.
17
+
18
+ See 'set max string' to change the string truncation limit.
19
+ "
20
+
21
+ # ALIASES = %w(p)
22
+ CATEGORY = 'data'
23
+ SHORT_HELP = 'print expression truncating long output'
24
+ end
25
+
26
+ def run(args)
27
+ msg @proc.debug_eval(@proc.cmd_argstr, settings[:maxstring])
28
+ end
29
+ end
30
+
31
+ if __FILE__ == $0
32
+ require_relative '../mock'
33
+ dbgr, cmd = MockDebugger::setup
34
+ arg_str = '1 + 2'
35
+ cmd.proc.instance_variable_set('@cmd_argstr', arg_str)
36
+ cmd.run([cmd.name, arg_str])
37
+ end
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative 'base/cmd'
5
+ require_relative '../eval'
6
+ class Trepan::Command::PsCommand < Trepan::Command
7
+
8
+ unless defined?(HELP)
9
+ HELP =
10
+ "ps ARRAY
11
+
12
+ Print the value of the ARRAY in columns and sorted."
13
+
14
+ CATEGORY = 'data'
15
+ MIN_ARGS = 1 # Need least this many
16
+ NAME = File.basename(__FILE__, '.rb')
17
+ SHORT_HELP = 'Print array sorted and in columns'
18
+ end
19
+
20
+ def run(args)
21
+ array = @proc.debug_eval(@proc.cmd_argstr, settings[:maxstring])
22
+ # FIXME: should test for enumerable
23
+ if array.is_a?(Array)
24
+ msg columnize_commands(array.sort)
25
+ else
26
+ errmsg "ps: #{@proc.cmd_argstr} should evaluate an Array not #{array.class}"
27
+ end
28
+ end
29
+ end
30
+
31
+ if __FILE__ == $0
32
+ require_relative '../mock'
33
+ dbgr, cmd = MockDebugger::setup
34
+ arg_str = '(1..30).to_a'
35
+ cmd.proc.instance_variable_set('@cmd_argstr', arg_str)
36
+ cmd.run([cmd.name, arg_str])
37
+ arg_str = '1'
38
+ cmd.proc.instance_variable_set('@cmd_argstr', arg_str)
39
+ cmd.run([cmd.name, arg_str])
40
+ end
@@ -0,0 +1,86 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative 'base/cmd'
5
+ ## require_relative '../../app/run'
6
+ class Trepan::Command::RestartCommand < Trepan::Command
7
+
8
+ unless defined?(HELP)
9
+ NAME = File.basename(__FILE__, '.rb')
10
+ ALIASES = %w(R run)
11
+ HELP = <<-HELP
12
+ #{NAME}
13
+
14
+ Restart debugger and program via an exec call. All state is lost, and
15
+ new copy of the debugger is used.
16
+ HELP
17
+
18
+ CATEGORY = 'running'
19
+ MAX_ARGS = nil # Need at most this many
20
+ SHORT_HELP = '(Hard) restart of program via exec()'
21
+ end
22
+
23
+ # This method runs the command
24
+ def run(args)
25
+ if not defined? Trepan::PROG_SCRIPT
26
+ errmsg "Don't know name of debugged program"
27
+ return
28
+ end
29
+ prog_script = Trepan::PROG_SCRIPT
30
+ if not defined? Trepan::PROG_UNRESOLVED_SCRIPT
31
+ # FIXME? Should ask for confirmation?
32
+ msg "Debugger was not called from the outset..."
33
+ trepan8_script = prog_script
34
+ else
35
+ trepan8_script = Trepan::PROG_UNRESOLVED_SCRIPT
36
+ end
37
+ begin
38
+ Dir.chdir(Trepan::INITIAL_DIR)
39
+ rescue
40
+ print "Failed to change initial directory #{Trepan::INITIAL_DIR}"
41
+ end
42
+ if not File.exist?(File.expand_path(prog_script))
43
+ errmsg "Ruby program #{prog_script} doesn't exist\n"
44
+ return
45
+ end
46
+ if not File.executable?(prog_script) and trepan8_script == prog_script
47
+ msg "Ruby program #{prog_script} doesn't seem to be executable..."
48
+ msg "We'll add a call to Ruby.\n"
49
+ ruby = begin defined?(Gem) ? Gem.ruby : "ruby" rescue "ruby" end
50
+ trepan8_script = "#{ruby} -I#{$:.join(' -I')} #{prog_script}"
51
+ else
52
+ trepan8_script += ' '
53
+ end
54
+ if args.size == 1
55
+ if not defined? Trepan::OldCommand.settings[:argv]
56
+ errmsg "Arguments have not been set. Use 'set args' to set them."
57
+ return
58
+ else
59
+ argv = Trepan::OldCommand.settings[:argv]
60
+ end
61
+ else
62
+ argv = [prog_script] + args[1..-1]
63
+ end
64
+ args = argv.join(' ')
65
+
66
+ # An execv would be preferable to the "exec" below.
67
+ cmd = trepan8_script + args
68
+ msg "Re exec'ing:\n\t#{cmd}"
69
+ exec cmd
70
+ rescue Errno::EOPNOTSUPP
71
+ msg "Restart command is not available at this time."
72
+ end
73
+ end
74
+
75
+ if __FILE__ == $0
76
+ exit if ARGV[-1] == 'exit'
77
+ require_relative '../mock'
78
+ dbgr, cmd = MockDebugger::setup
79
+ Trepan::PROG_SCRIPT = ''
80
+ Trepan::INITIAL_DIR = Dir.pwd
81
+ cmd.run([cmd.name, $0, 'exit'])
82
+ dbgr.restart_argv = ARGV + ['exit']
83
+ # require_relative '../../debugger'
84
+ # Trepan.start
85
+ cmd.run([cmd.name])
86
+ end
@@ -0,0 +1,58 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative 'base/cmd'
5
+ class Trepan::Command::SaveCommand < Trepan::Command
6
+
7
+ unless defined?(HELP)
8
+ NAME = File.basename(__FILE__, '.rb')
9
+ HELP = <<-HELP
10
+ #{NAME} [--[no-]erase] [--output|-o FILENAME]
11
+
12
+ Save settings to file FILENAME. If FILENAME not given one will be made
13
+ selected.
14
+ HELP
15
+
16
+ CATEGORY = 'running'
17
+ MAX_ARGS = 1 # Need at most this many
18
+ SHORT_HELP = 'Send debugger state to a file'
19
+
20
+ DEFAULT_OPTIONS = { :erase => true, }
21
+ end
22
+
23
+ def parse_options(options, args) # :nodoc
24
+ parser = OptionParser.new do |opts|
25
+ opts.on("-e", "--[no-]erase",
26
+ "Add line to erase after reading") do
27
+ |v|
28
+ options[:erase] = v
29
+ end
30
+ opts.on("-o", "--output FILE", String,
31
+ "Save file to FILE. ") do
32
+ |filename|
33
+ options[:filename] = filename
34
+ end
35
+ end
36
+ parser.parse(args)
37
+ return options
38
+ end
39
+
40
+ # This method runs the command
41
+ def run(args)
42
+ options = parse_options(DEFAULT_OPTIONS.dup, args[1..-1])
43
+ save_filename = @proc.save_commands(options)
44
+ msg "Debugger commands written to file: #{save_filename}" if
45
+ save_filename
46
+ end
47
+ end
48
+
49
+ if __FILE__ == $0
50
+ require_relative '../mock'
51
+ dbgr, cmd = MockDebugger::setup
52
+ require 'tmpdir'
53
+ cmd.run([cmd.name])
54
+ # require_relative '../../lib/trepanning'; debugger
55
+ cmd.run([cmd.name, '--erase',
56
+ '--output', File.join(Dir.tmpdir, 'save_file.txt')])
57
+ # A good test would be to see we can read in those files without error.
58
+ end
@@ -0,0 +1,47 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative 'base/submgr'
5
+
6
+ class Trepan::Command::SetCommand < Trepan::SubcommandMgr
7
+ unless defined?(HELP)
8
+ HELP =
9
+ 'Modifies parts of the debugger environment.
10
+
11
+ You can give unique prefix of the name of a subcommand to get
12
+ information about just that subcommand.
13
+
14
+ Type "set" for a list of "set" subcommands and what they do.
15
+ Type "help set *" for just the list of "set" subcommands.
16
+
17
+ For compatability with older ruby-debug "set auto..." is the
18
+ same as "set auto ...". For example "set autolist" is the same
19
+ as "set auto list".
20
+ '
21
+
22
+ CATEGORY = 'support'
23
+ NAME = File.basename(__FILE__, '.rb')
24
+ NEED_STACK = false
25
+ SHORT_HELP = 'Modify parts of the debugger environment'
26
+ end
27
+
28
+ def run(args)
29
+ if args.size > 1
30
+ first = args[1].downcase
31
+ alen = 'auto'.size
32
+ args[1..1] = ['auto', first[alen..-1]] if
33
+ first.start_with?('auto') && first.size > alen
34
+ end
35
+ super
36
+ end
37
+
38
+ end
39
+
40
+ if __FILE__ == $0
41
+ require_relative '../mock'
42
+ dbgr, cmd = MockDebugger::setup
43
+ cmd.run([cmd.name])
44
+ cmd.run([cmd.name, 'autolist'])
45
+ cmd.run([cmd.name, 'autoeval', 'off'])
46
+ cmd.run([cmd.name, 'basename'])
47
+ end