rb8-trepanning 0.1.3-universal-ruby-1.9.2

Sign up to get free protection for your applications and to get access to all the features.
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 +58 -0
  274. metadata +388 -0
@@ -0,0 +1,54 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative 'up'
5
+
6
+ # Debugger "down" command. Is the same as the "up" command with the
7
+ # direction (set by DIRECTION) reversed.
8
+ class Trepan::Command::DownCommand < Trepan::Command::UpCommand
9
+
10
+ # Silence already initialized constant .. warnings
11
+ old_verbose = $VERBOSE
12
+ $VERBOSE = nil
13
+ HELP = <<-HELP
14
+ #{NAME} [count]
15
+
16
+ Move the current frame down in the stack trace (to a newer frame). 0
17
+ is the most recent frame. If no count is given, move down 1.
18
+
19
+ See also 'up' and 'frame'.
20
+ HELP
21
+
22
+ ALIASES = %w(d)
23
+ NAME = File.basename(__FILE__, '.rb')
24
+ SHORT_HELP = 'Move frame in the direction of the caller of the last-selected frame'
25
+ $VERBOSE = old_verbose
26
+
27
+ def initialize(proc)
28
+ super
29
+ @direction = -1 # +1 for up.
30
+ end
31
+
32
+ end
33
+
34
+ if __FILE__ == $0
35
+ # Demo it.
36
+ require_relative '../mock'
37
+ dbgr, cmd = MockDebugger::setup
38
+
39
+ # def sep ; puts '=' * 40 end
40
+ # cmd.run [cmd.name]
41
+ # %w(-1 0 1 -2).each do |count|
42
+ # puts "#{cmd.name} #{count}"
43
+ # cmd.run([cmd.name, count])
44
+ # sep
45
+ # end
46
+ # def foo(cmd, cmd.name)
47
+ # puts "#{cmd.name}"
48
+ # cmd.run([cmd.name])
49
+ # sep
50
+ # puts "#{cmd.name} -1"
51
+ # cmd.run([cmd.name, '-1'])
52
+ # end
53
+ # foo(cmd, cmd.name)
54
+ end
@@ -0,0 +1,79 @@
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
+
6
+ class Trepan::Command::EditCommand < Trepan::Command
7
+
8
+ old_verbose = $VERBOSE
9
+ $VERBOSE = nil
10
+ NAME = File.basename(__FILE__, '.rb')
11
+ HELP = <<-HELP
12
+ #{NAME} [[FILE] [LINE]]
13
+
14
+ With no argument, edits file containing most recent line listed.
15
+ The value of the environment variable EDITOR is used for the
16
+ editor to run. If no EDITOR environment variable is set /bin/ex
17
+ is used. The editor should support line and file positioning via
18
+ editor-name +line file-name
19
+ (Most editors do.)
20
+
21
+ Examples:
22
+ #{NAME} # Edit current location
23
+ #{NAME} 7 # Edit current file at line 7
24
+ #{NAME} test.rb # Edit test.rb, line 1
25
+ #{NAME} test.rb 10 # Edit test.rb line 10
26
+ HELP
27
+
28
+ ALIASES = %w(e)
29
+ CATEGORY = 'files'
30
+ NEED_STACK = false
31
+ SHORT_HELP = 'Invoke an editor on some source code'
32
+ MAX_ARGS = 2
33
+ $VERBOSE = old_verbose
34
+
35
+ # FIXME: redo with locations and kparse.
36
+ def run(args)
37
+ case args.size
38
+ when 1
39
+ unless @proc.context
40
+ errmsg "We are not in a state that has an associated file."
41
+ return
42
+ end
43
+ file = @proc.frame.file
44
+ line = @proc.frame.line
45
+ when 2
46
+ line = Integer(args[1]) rescue nil
47
+ if line
48
+ unless @proc.context
49
+ errmsg "We are not in a state that has an associated file."
50
+ return
51
+ end
52
+ file = @proc.frame.file
53
+ else
54
+ file = args[1]
55
+ line = 1
56
+ end
57
+ when 3
58
+ line, file = args[2], args[1]
59
+ else
60
+ errmsg "edit needs at most 2 args."
61
+ end
62
+ editor = ENV['EDITOR'] || '/bin/ex'
63
+ if File.readable?(file)
64
+ file = File.basename(file) if settings[:basename]
65
+ edit_cmd = "#{editor} +#{line} \"#{file}\""
66
+ msg "Running #{edit_cmd}..."
67
+ system(edit_cmd)
68
+ msg "Warning: return code was #{$?.exitstatus}" if $?.exitstatus != 0
69
+ else
70
+ errmsg "File \"#{file}\" is not readable."
71
+ end
72
+ end
73
+ end
74
+
75
+ if __FILE__ == $0
76
+ require_relative '../mock'
77
+ dbgr, cmd = MockDebugger::setup
78
+ cmd.run [cmd.name] if ARGV.size > 0
79
+ end
@@ -0,0 +1,48 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative 'disable'
5
+
6
+ # enable breakpoint command. Is like disable but the parameter
7
+ # to @proc.en_disable_breakpoint_by_number is different (set as
8
+ # ENABLE_PARM below).
9
+ class Trepan::Command::EnableCommand < Trepan::Command::DisableCommand
10
+
11
+ # Silence already initialized constant .. warnings
12
+ old_verbose = $VERBOSE
13
+ $VERBOSE = nil
14
+ NAME = File.basename(__FILE__, '.rb')
15
+ HELP = <<-HELP
16
+ #{NAME} BPNUM1 [BPNUM2 ...]
17
+
18
+ Enables breakpoints BPNUM1. Breakpoints numbers are given as a space-
19
+ separated list numbers.
20
+
21
+ See also "info break" to get a list of breakpoints.
22
+ HELP
23
+
24
+ ALIASES = %w(en)
25
+ SHORT_HELP = 'Enable some breakpoints'
26
+ $VERBOSE = old_verbose
27
+
28
+ def run(args)
29
+ if args.size == 1
30
+ errmsg('No breakpoint number given.')
31
+ return
32
+ end
33
+ enable_disable_breakpoints("Disable", args[1..-1])
34
+ end
35
+
36
+ end
37
+
38
+ if __FILE__ == $0
39
+ require_relative '../mock'
40
+ dbgr, cmd = MockDebugger::setup
41
+ cmd.run([cmd.name])
42
+ cmd.run([cmd.name, '1'])
43
+ cmds = cmd.proc.commands
44
+ break_cmd = cmds['break']
45
+ puts "To be continued..."
46
+ # break_cmd.run(['break', cmdproc.frame.source_location[0].to_s])
47
+ # cmd.run([cmd.name, '1'])
48
+ end
@@ -0,0 +1,90 @@
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/util'
6
+
7
+ class Trepan::Command::EvalCommand < Trepan::Command
8
+
9
+ old_verbose = $VERBOSE
10
+ $VERBOSE = nil
11
+ NAME = File.basename(__FILE__, '.rb')
12
+ HELP = <<-HELP
13
+ #{NAME} [STRING]
14
+
15
+ Run code in the context of the current frame.
16
+
17
+ The value of the expression is stored into a global variable so it
18
+ may be used again easily. The name of the global variable is printed
19
+ next to the inspect output of the value.
20
+
21
+ If no string is given, we run the string from the current source code
22
+ about to be run. If the command ends ? (via an alias) and no string is
23
+ given we will the following translations occur:
24
+
25
+ {if|elsif|unless} expr [then] => expr
26
+ {until|while} expr [do] => expr
27
+ return expr => expr
28
+ case expr => expr
29
+ def fn(params) => [params]
30
+ var = expr => expr
31
+
32
+ The above is done via regular expression. No fancy parsing is done, say,
33
+ to look to see if expr is split across a line or whether var an assigment
34
+ might have multiple variables on the left-hand side.
35
+
36
+ Examples:
37
+
38
+ #{NAME} 1+2 # 3
39
+ #{NAME} @v
40
+ #{NAME} # Run current source-code line
41
+ #{NAME}? # but strips off leading 'if', 'while', ..
42
+ # from command
43
+
44
+ See also 'set autoeval'. The command helps one predict future execution.
45
+ See 'set buffer trace' for showing what may have already been run.
46
+ HELP
47
+
48
+ ALIASES = %w(eval? ev? ev)
49
+ CATEGORY = 'data'
50
+ NEED_STACK = true
51
+ SHORT_HELP = 'Run code in the current context'
52
+ $VERBOSE = old_verbose
53
+
54
+ def complete(prefix)
55
+ if prefix.empty?
56
+ if @proc.leading_str.start_with?('eval?')
57
+ Trepan::Util.extract_expression(@proc.current_source_text)
58
+ else
59
+ @proc.current_source_text
60
+ end
61
+ else
62
+ prefix
63
+ end
64
+ end
65
+
66
+ def run(args)
67
+ if args.size == 1
68
+ text = @proc.current_source_text.chomp
69
+ ## FIXME turn into a subroutine and use in complete.
70
+ if '?' == args[0][-1..-1]
71
+ text = Trepan::Util::extract_expression(text)
72
+ msg "eval: #{text}"
73
+ end
74
+ else
75
+ text = @proc.cmd_argstr
76
+ end
77
+ @proc.eval_code(text, settings[:maxstring])
78
+ end
79
+ end
80
+
81
+ if __FILE__ == $0
82
+ require_relative '../mock'
83
+ dbgr, cmd = MockDebugger::setup
84
+ arg_str = '1 + 2'
85
+ cmd.proc.instance_variable_set('@cmd_argstr', arg_str)
86
+ puts "eval #{arg_str} is: #{cmd.run([cmd.name, arg_str])}"
87
+ arg_str = 'return "foo"'
88
+ cmd.proc.instance_variable_set('@cmd_argstr', arg_str)
89
+ puts "eval? #{arg_str} is: #{cmd.run([cmd.name + '?'])}"
90
+ end
@@ -0,0 +1,66 @@
1
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
+ require 'rubygems'; require 'require_relative'
3
+ require_relative 'base/cmd'
4
+ class Trepan::Command::ExitCommand < Trepan::Command
5
+
6
+ unless defined?(HELP)
7
+ NAME = File.basename(__FILE__, '.rb')
8
+ ALIASES = %w(quit q q! quit! exit!)
9
+ HELP = <<-HELP
10
+ #{NAME} [exitcode] - hard exit of the debugged program.
11
+
12
+ The program being debugged is exited via exit!() which does not run
13
+ the Kernel at_exit finalizers. If a return code is given, that is the
14
+ return code passed to exit() - presumably the return code that will be
15
+ passed back to the OS. If no exit code is given, 0 is used.
16
+
17
+ If you are in interactive mode, and confirm is not set off, you are
18
+ prompted to confirm quitting. However if you do not want to be
19
+ prompted, add ! the end. (vim/vi/ed users can use alias q!).
20
+
21
+ See also "kill" and "set confirm".'
22
+ HELP
23
+
24
+ CATEGORY = 'support'
25
+ MAX_ARGS = 2 # Need at most this many
26
+ SHORT_HELP = 'Exit program via "exit!()"'
27
+ end
28
+
29
+ # FIXME: Combine 'quit' and 'exit'. The only difference is
30
+ # whether exit! or exit is used.
31
+
32
+ # This method runs the command
33
+ def run(args) # :nodoc
34
+ unconditional =
35
+ if args.size > 1 && args[1] == 'unconditionally'
36
+ args.shift
37
+ true
38
+ elsif args[0][-1..-1] == '!'
39
+ true
40
+ else
41
+ false
42
+ end
43
+ unless unconditional || confirm('Really quit?', false)
44
+ msg('Quit not confirmed.')
45
+ return
46
+ end
47
+ exitrc = (args.size > 1) ? exitrc = Integer(args[1]) rescue 0 : 0
48
+
49
+ # FIXME: Is this the best/most general way?
50
+ ## @proc.finalize
51
+ ## @proc.dbgr.intf[-1].finalize
52
+
53
+ # No graceful way to stop threads...
54
+ # A little harsh, but for now let's go with this.
55
+ exit! exitrc
56
+ end
57
+ end
58
+
59
+ if __FILE__ == $0
60
+ require_relative '../mock'
61
+ dbgr, cmd = MockDebugger::setup
62
+ puts "before #{cmd.name}"
63
+ fork { cmd.run([cmd.name]) }
64
+ puts "before #{cmd.name} 10"
65
+ cmd.run([cmd.name, '10'])
66
+ end
@@ -0,0 +1,59 @@
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::FinishCommand < Trepan::Command
6
+
7
+ unless defined?(HELP)
8
+ ALIASES = %w(fin)
9
+ CATEGORY = 'running'
10
+ NAME = File.basename(__FILE__, '.rb')
11
+ HELP = <<-HELP
12
+ #{NAME} [FRAME_NUM]
13
+
14
+ Execute until selected stack frame returns.
15
+
16
+ If no frame number is given, we run until the currently selected frame
17
+ returns. The currently selected frame starts out the most-recent
18
+ frame or 0 if no frame positioning (e.g "up", "down" or "frame") has
19
+ been performed. If a frame number is given we run until that frame
20
+ returns.
21
+ HELP
22
+ NEED_RUNNING = true
23
+ SHORT_HELP = 'Step into next method call or to next line'
24
+ end
25
+
26
+ # self.allow_in_post_mortem = false
27
+ # self.need_context = true
28
+
29
+ def run(args)
30
+ state = @proc.state
31
+ context = @proc.context
32
+ max_frame = context.stack_size - state.frame_pos
33
+ if args.size == 1
34
+ frame_pos = state.frame_pos
35
+ else
36
+ count_str = args[1]
37
+ count_opts = {
38
+ :msg_on_error =>
39
+ "The '#{NAME}' command argument must eval to an integer. Got: %s" %
40
+ count_str,
41
+ :min_value => 0,
42
+ :max_valiue => context.stack_size - state.frame_pos
43
+ }
44
+ count = @proc.get_an_int(count_str, count_opts)
45
+ return unless count
46
+ frame_pos = count - 1
47
+ end
48
+ context.stop_frame = frame_pos
49
+ state.frame_pos = 0
50
+ state.proceed
51
+ @proc.leave_cmd_loop = true
52
+ end
53
+ end
54
+
55
+ if __FILE__ == $0
56
+ require_relative '../mock'
57
+ dbgr, cmd = MockDebugger::setup
58
+ cmd.run([cmd.name])
59
+ end
@@ -0,0 +1,97 @@
1
+ require 'rubygems'; require 'require_relative'
2
+ require_relative './base/cmd'
3
+
4
+ class Trepan::Command::FrameCommand < Trepan::Command
5
+ CATEGORY = 'stack'
6
+ HELP = <<-HELP
7
+ frame [frame-number]
8
+
9
+ Change the current frame to frame `frame-number' if specified, or the
10
+ most-recent frame, 0, if no frame number specified.
11
+
12
+ A negative number indicates the position from the other or
13
+ least-recently-entered end. So 'frame -1' moves to the oldest frame.
14
+ Any variable or expression that evaluates to a number can be used as a
15
+ position, however due to parsing limitations, the position expression
16
+ has to be seen as a single blank-delimited parameter. That is, the
17
+ expression '(5*3)-1' is okay while '( (5 * 3) - 1 )' isn't.
18
+
19
+ Examples:
20
+ frame # Set current frame at the current stopping point
21
+ frame 0 # Same as above
22
+ frame 5-5 # Same as above. Note: no spaces allowed in expression 5-5
23
+ frame 1 # Move to frame 1. Same as: frame 0; up
24
+ frame -1 # The least-recent frame
25
+
26
+ See also 'up', 'down', and 'backtrace'.
27
+ HELP
28
+ NAME = File.basename(__FILE__, '.rb')
29
+ SHORT_HELP = 'Make a specific frame in the call stack the current frame'
30
+
31
+ def complete(prefix)
32
+ @proc.frame_complete(prefix, nil)
33
+ end
34
+
35
+ def run(args)
36
+
37
+ if args.size == 1
38
+ # Form is: "frame" which means "frame 0"
39
+ position_str = '0'
40
+ elsif args.size == 2
41
+ # Form is: "frame position"
42
+ position_str = args[1]
43
+ # elsif args.size == 3
44
+ # # Form is: frame <position> <thread>
45
+ # name_or_id = args[1]
46
+ # thread_str = args[2]
47
+ # th = @proc.get_thread_from_string(thread_str)
48
+ # if th
49
+ # @proc.frame_setup(th.threadframe)
50
+ # return
51
+ # else
52
+ # # FIXME: Give suitable error message was given
53
+ # end
54
+ # else
55
+ # # Form should be: "frame thread" which means
56
+ # # "frame thread 0"
57
+ # position_str = '0'
58
+ # ## FIXME:
59
+ # ## @proc.find_and_set_debugged_frame(frame, thread_id)
60
+ end
61
+
62
+ stack_size = @proc.frame.stack_size
63
+ if stack_size == 0
64
+ errmsg('No frames recorded.')
65
+ return false
66
+ end
67
+ low, high = @proc.frame_low_high(nil)
68
+ opts={
69
+ :msg_on_error =>
70
+ "The '#{NAME}' command requires a frame number. Got: #{position_str}",
71
+ :min_value => low, :max_value => high
72
+ }
73
+ frame_num = @proc.get_an_int(position_str, opts)
74
+ return false unless frame_num
75
+
76
+ @proc.adjust_frame(frame_num, true)
77
+ return true
78
+ end
79
+ end
80
+
81
+ if __FILE__ == $0
82
+ # Demo it.
83
+ require_relative '../mock'
84
+ dbgr, cmd = MockDebugger::setup
85
+
86
+ puts "To be continued..."
87
+ # def sep ; puts '=' * 40 end
88
+ # require 'ruby-debug'
89
+ # %w(0 1 -2).each {|count|
90
+ # cmd.run([cmd.name, count.to_s]); sep
91
+ # }
92
+ # def foo(cmd, name)
93
+ # cmd.proc.frame_setup(Debugger.current_context, nil)
94
+ # %w(0 -1).each {|count| cmd.run([cmd.name, count.to_s]); sep }
95
+ # end
96
+ # foo(cmd, cmd.name)
97
+ end