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,82 @@
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
+
6
+ class Trepan::Command::DisplayCommand < Trepan::Command
7
+
8
+ unless defined?(HELP)
9
+ NAME = File.basename(__FILE__, '.rb')
10
+ HELP = <<-HELP
11
+ #{name} [format] EXP
12
+
13
+ Print value of expression EXP each time the program stops. FMT may be
14
+ used before EXP and may be one of 'c' for char, 'x' for hex, 'o' for
15
+ octal, 'f' for float or 's' for string.
16
+
17
+ For now, display expressions are only evaluated when in the same
18
+ instruction sequence as the frame that was in effect when the display
19
+ expression was set. This is a departure from gdb and we may allow for
20
+ more flexibility in the future to specify whether this should be the
21
+ case or not.
22
+
23
+ With no argument, evaluate and display all currently requested
24
+ auto-display expressions. Use "undisplay" to cancel display
25
+ requests previously made.
26
+ HELP
27
+
28
+ CATEGORY = 'data'
29
+ NEED_STACK = false
30
+ SHORT_HELP = 'Display expressions when entering debugger'
31
+ end
32
+
33
+ def run(args)
34
+
35
+ if args.size == 1
36
+ # Display anything active
37
+ @proc.run_eval_display
38
+ else
39
+ if %w(/c /x /o /f /s).member?(args[1])
40
+ if 2 == args.size
41
+ errmsg("Expecting an expression after the format")
42
+ return
43
+ end
44
+ format = args[1]
45
+ expr = args[2..-1].join(' ')
46
+ else
47
+ format = nil
48
+ expr = args[1..-1].join(' ')
49
+ end
50
+
51
+ dp = @proc.displays.add(@proc.frame, expr, format)
52
+ unless dp
53
+ errmsg('Error evaluating "%s" in the current frame' % expr)
54
+ return
55
+ end
56
+ msg(dp.to_s(@proc.frame))
57
+ @proc.cmdloop_prehooks.insert_if_new(5, *@proc.display_hook)
58
+ end
59
+ end
60
+ end
61
+
62
+ if __FILE__ == $0
63
+ # Demo it.
64
+ require_relative '../mock'
65
+ dbgr, cmd = MockDebugger::setup
66
+
67
+ def run_cmd(cmd, args)
68
+ cmd.run(args)
69
+ puts '==' * 10
70
+ end
71
+
72
+ # run_cmd(cmd, [cmd.name])
73
+ # run_cmd(cmd, [cmd.name, '/x', '10'])
74
+ # run_cmd(cmd, [cmd.name, 'd'])
75
+ # run_cmd(cmd, [cmd.name])
76
+ e = 5
77
+ vm_locations = Rubinius::VM.backtrace(0, true)
78
+ cmd.proc.instance_variable_set('@frame ',
79
+ Trepan::Frame.new(self, 0, vm_locations[0]))
80
+
81
+ run_cmd(cmd, [cmd.name, 'e'])
82
+ end
@@ -0,0 +1,54 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010 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 =
14
+ "d(own) [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
+ "
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,51 @@
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::EvalCommand < Trepan::Command
7
+
8
+ NAME = File.basename(__FILE__, '.rb')
9
+ CATEGORY = 'data'
10
+ HELP = <<-HELP
11
+ #{NAME} [STRING]
12
+
13
+ Run code in the context of the current frame.
14
+
15
+ The value of the expression is stored into a global variable so it
16
+ may be used again easily. The name of the global variable is printed
17
+ next to the inspect output of the value.
18
+
19
+ If no string is given we run the string from the current source code
20
+ about to be run
21
+
22
+ #{NAME} 1+2 # 3
23
+ #{NAME} @v
24
+ #{NAME} # Run current source-code line
25
+
26
+ See also 'set autoeval'
27
+ HELP
28
+
29
+ NAME = File.basename(__FILE__, '.rb')
30
+ NEED_STACK = true
31
+ SHORT_HELP = 'Run code in the current context'
32
+ def run(args)
33
+ if args.size == 1
34
+ loc = @proc.source_location_info
35
+ opts = {:reload_on_change => @proc.reload_on_change}
36
+ loc, junk, text = @proc.loc_and_text(loc, opts)
37
+ msg "eval: #{text}"
38
+ else
39
+ text = @proc.cmd_argstr
40
+ end
41
+ @proc.eval_code(text, settings[:maxstring])
42
+ end
43
+ end
44
+
45
+ if __FILE__ == $0
46
+ require_relative '../mock'
47
+ dbgr, cmd = MockDebugger::setup
48
+ arg_str = '1 + 2'
49
+ cmd.proc.instance_variable_set('@cmd_argstr', arg_str)
50
+ puts "eval #{arg_str} is: #{cmd.run([cmd.name, arg_str])}"
51
+ end
@@ -0,0 +1,62 @@
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
+ ALIASES = %w(quit q q! quit! exit!)
8
+ HELP =
9
+ 'exit [exitcode] - hard exit of the debugged program.
10
+
11
+ The program being debugged is exited via exit!() which does not run
12
+ the Kernel at_exit finalizers. If a return code is given, that is the
13
+ return code passed to exit() - presumably the return code that will be
14
+ passed back to the OS. If no exit code is given, 0 is used.
15
+
16
+ If you are in interactive mode, you are prompted to confirm
17
+ quitting. However if you do not want to be prompted, add ! the end.
18
+ (vim/vi/ed users can use alias q!).
19
+
20
+ See also "kill".'
21
+
22
+ CATEGORY = 'support'
23
+ MAX_ARGS = 2 # Need at most this many
24
+ NAME = File.basename(__FILE__, '.rb')
25
+ SHORT_HELP = 'Exit program via "exit!()"'
26
+ end
27
+
28
+ # FIXME: Combine 'quit' and 'exit'. The only difference is
29
+ # whether exit! or exit is used.
30
+
31
+ # This method runs the command
32
+ def run(args) # :nodoc
33
+ unconditional =
34
+ if args.size > 1 && args[1] == 'unconditionally'
35
+ args.shift
36
+ true
37
+ elsif args[0][-1..-1] == '!'
38
+ true
39
+ else
40
+ false
41
+ end
42
+ unless unconditional || confirm('Really quit?', false)
43
+ msg('Quit not confirmed.')
44
+ return
45
+ end
46
+ exitrc = (args.size > 1) ? exitrc = Integer(args[1]) rescue 0 : 0
47
+
48
+ # FIXME: funnel to sort of more general finalize routine
49
+ @proc.dbgr.intf[-1].close
50
+
51
+ # No graceful way to stop threads...
52
+ # A little harsh, but for now let's go with this.
53
+ exit! exitrc
54
+ end
55
+ end
56
+
57
+ if __FILE__ == $0
58
+ require_relative '../mock'
59
+ dbgr, cmd = MockDebugger::setup
60
+ fork { cmd.run([cmd.name]) }
61
+ cmd.run([cmd.name, '10'])
62
+ end
@@ -0,0 +1,80 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative 'base/cmd'
5
+
6
+ class Trepan::Command::FinishCommand < Trepan::Command
7
+
8
+ unless defined?(HELP)
9
+ NAME = File.basename(__FILE__, '.rb')
10
+ HELP = <<-HELP
11
+ #{NAME}
12
+ #{NAME}+
13
+
14
+ Continue execution until leaving the current method. Sometimes this
15
+ is called 'step out'.
16
+
17
+ Normally, stopping occurs just before the return on or yield out of a
18
+ method. However sometimes one wants go to the calling method or place
19
+ just beyond the current method.For this, suffix the command or an
20
+ alias of it with a plus sign. The disadvantange of this is that you
21
+ will no longer be in the scope of the method and so you won't be able
22
+ to see variables of that method.
23
+
24
+ Examples:
25
+ #{NAME}
26
+ #{NAME}+
27
+
28
+ See also commands:
29
+ 'continue', 'break', 'next', 'nexti', 'step' for other ways to continue.
30
+ HELP
31
+ ALIASES = %w(fin finish+ fin+)
32
+ CATEGORY = 'running'
33
+ # execution_set = ['Running']
34
+ MAX_ARGS = 1 # Need at most this many.
35
+ NEED_STACK = true
36
+ SHORT_HELP = 'Step to end of current method (step out)'
37
+ end
38
+
39
+ # This method runs the command
40
+ def run(args) # :nodoc
41
+ opts = @proc.parse_next_step_suffix(args[0])
42
+ if args.size == 1
43
+ # Form is: "finish" which means "finish 1"
44
+ level_count = 0
45
+ else
46
+ count_str = args[1]
47
+ count_opts = {
48
+ :msg_on_error =>
49
+ "The '#{NAME}' command argument must eval to an integer. Got: %s" %
50
+ count_str,
51
+ :min_value => 1
52
+ }
53
+ count = @proc.get_an_int(count_str, count_opts)
54
+ return unless count
55
+ # step 1 is core.level_count = 0 or "stop next event"
56
+ level_count = count - 1
57
+ end
58
+ if 0 == level_count and %w(return c-return).member?(@proc.event)
59
+ errmsg "You are already at the requested return event."
60
+ else
61
+ @proc.finish(level_count, opts)
62
+ end
63
+ end
64
+ end
65
+
66
+ if __FILE__ == $0
67
+ require_relative '../mock'
68
+ dbgr, cmd = MockDebugger::setup
69
+ [%W(#{cmd.name}), %w(fin 2-1), %w(n foo)].each do |c|
70
+ cmd.proc.instance_variable_set('@return_to_program', false)
71
+ cmd.run(c)
72
+ puts 'return_to_program: %s' % cmd.proc.instance_variable_get('@return_to_program')
73
+ puts 'step_count: %s' % cmd.proc.instance_variable_get('@step_count')
74
+ end
75
+ [%w(fin), [cmd.name]].each do |c|
76
+ cmd.proc.leave_cmd_loop = false
77
+ result = cmd.run(c)
78
+ puts cmd.proc.different_pos
79
+ end
80
+ end
@@ -0,0 +1,89 @@
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 run(args)
32
+
33
+ if args.size == 1
34
+ # Form is: "frame" which means "frame 0"
35
+ position_str = '0'
36
+ elsif args.size == 2
37
+ # Form is: "frame position"
38
+ position_str = args[1]
39
+ # elsif args.size == 3
40
+ # # Form is: frame <position> <thread>
41
+ # name_or_id = args[1]
42
+ # thread_str = args[2]
43
+ # th = @proc.get_thread_from_string(thread_str)
44
+ # if th
45
+ # @proc.frame_setup(th.threadframe)
46
+ # return
47
+ # else
48
+ # # FIXME: Give suitable error message was given
49
+ # end
50
+ # else
51
+ # # Form should be: "frame thread" which means
52
+ # # "frame thread 0"
53
+ # position_str = '0'
54
+ # ## FIXME:
55
+ # ## @proc.find_and_set_debugged_frame(frame, thread_id)
56
+ end
57
+
58
+ stack_size = @proc.dbgr.vm_locations.size
59
+ if stack_size == 0
60
+ errmsg('No frames recorded.')
61
+ return false
62
+ end
63
+ opts={
64
+ :msg_on_error =>
65
+ "The '#{NAME}' command requires a frame number. Got: #{position_str}",
66
+ :min_value => -stack_size,
67
+ :max_value => stack_size-1
68
+ }
69
+ frame_num = @proc.get_an_int(position_str, opts)
70
+ return false unless frame_num
71
+
72
+ @proc.adjust_frame(frame_num, true)
73
+ return true
74
+ end
75
+ end
76
+
77
+ if __FILE__ == $0
78
+ # Demo it.
79
+ require_relative '../mock'
80
+ dbgr, cmd = MockDebugger::setup
81
+
82
+ # def sep ; puts '=' * 40 end
83
+ # %w(0 1 -2).each {|count| cmd.run([cmd.name, count]); sep }
84
+ # def foo(cmd, cmd.name)
85
+ # cmd.proc.frame_setup(RubyVM::ThreadFrame::current)
86
+ # %w(0 -1).each {|count| cmd.run([cmd.name, count]); sep }
87
+ # end
88
+ # foo(cmd, cmd.name)
89
+ end
@@ -0,0 +1,251 @@
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ require 'rubygems'; require 'require_relative'
3
+ require_relative 'base/cmd'
4
+ require_relative '../../app/complete'
5
+ class Trepan::Command::HelpCommand < Trepan::Command
6
+
7
+ unless defined?(HELP)
8
+ NAME = File.basename(__FILE__, '.rb')
9
+ HELP = <<-HELP
10
+ #{NAME} [command [subcommand]|expression]
11
+
12
+ Without argument, print the list of available debugger commands.
13
+
14
+ When an argument is given, it is first checked to see if it is command
15
+ name. 'help where' gives help on the 'where' debugger command.
16
+
17
+ If the environment variable $PAGER is defined, the file is
18
+ piped through that command. You'll notice this only for long help
19
+ output.
20
+
21
+ Some commands like 'info', 'set', and 'show' can accept an
22
+ additional subcommand to give help just about that particular
23
+ subcommand. For example 'help info line' give help about the
24
+ info line command.
25
+
26
+ See also 'examine' and 'whatis'.
27
+ HELP
28
+
29
+ ALIASES = %w(?)
30
+ CATEGORIES = {
31
+ 'breakpoints' => 'Making the program stop at certain points',
32
+ 'data' => 'Examining data',
33
+ 'files' => 'Specifying and examining files',
34
+ 'running' => 'Running the program',
35
+ 'status' => 'Status inquiries',
36
+ 'support' => 'Support facilities',
37
+ 'stack' => 'Examining the call stack'
38
+ }
39
+ CATEGORY = 'support'
40
+ NEED_STACK = false
41
+ SHORT_HELP = 'Print commands or give help for command(s)'
42
+ end
43
+
44
+ def complete(prefix)
45
+ matches = Trepan::Complete.complete_token(CATEGORIES.keys +
46
+ %w(* syntax all) +
47
+ @proc.commands.keys, prefix)
48
+ aliases = Trepan::Complete.complete_token_filtered(@proc.aliases, prefix,
49
+ matches)
50
+ (matches + aliases).sort
51
+ end
52
+
53
+ def complete(prefix)
54
+ matches = Trepan::Complete.complete_token(CATEGORIES.keys +
55
+ %w(* syntax all) +
56
+ @proc.commands.keys, prefix)
57
+ aliases = Trepan::Complete.complete_token_filtered(@proc.aliases, prefix,
58
+ matches)
59
+ (matches + aliases).sort
60
+ end
61
+
62
+ def complete_token_with_next(prefix)
63
+ complete(prefix).map do |cmd|
64
+ [cmd, @proc.commands.member?(cmd) ? @proc.commands[cmd] : nil]
65
+ end
66
+ end
67
+
68
+ # List the command categories and a short description of each.
69
+ def list_categories
70
+ section 'Classes of commands:'
71
+ CATEGORIES.keys.sort.each do |cat|
72
+ msg("%-13s -- %s" % [cat, CATEGORIES[cat]])
73
+ end
74
+ final_msg = '
75
+ Type "help" followed by a class name for a list of commands in that class.
76
+ Type "help syntax" for information on debugger command syntax.
77
+ Type "help aliases" for a list of current aliases
78
+ Type "help macros" for a list of current macros
79
+ Type "help *" for the list of all commands, macros and aliases.
80
+ Type "help all" for the list of all commands.
81
+ Type "help REGEXP" for the list of commands matching /^#{REGEXP}/
82
+ Type "help CLASS *" for the list of all commands in class CLASS.
83
+ Type "help" followed by command name for full documentation.
84
+ '
85
+ msg(final_msg)
86
+ end
87
+
88
+ # This method runs the command
89
+ def run(args) # :nodoc
90
+ if args.size > 1
91
+ cmd_name = args[1]
92
+ if cmd_name == '*'
93
+ section 'All command names:'
94
+ msg columnize_commands(@proc.commands.keys.sort)
95
+ show_aliases unless @proc.aliases.empty?
96
+ show_macros unless @proc.macros.empty?
97
+ elsif cmd_name =~ /^aliases$/i
98
+ show_aliases
99
+ elsif cmd_name =~ /^macros$/i
100
+ show_macros
101
+ elsif cmd_name =~ /^syntax$/i
102
+ show_command_syntax
103
+ elsif cmd_name =~ /^all$/i
104
+ CATEGORIES.sort.each do |category|
105
+ show_category(category[0], [])
106
+ end
107
+ elsif CATEGORIES.member?(cmd_name)
108
+ show_category(args[1], args[2..-1])
109
+ elsif @proc.commands.member?(cmd_name) or @proc.aliases.member?(cmd_name)
110
+ real_name =
111
+ if @proc.commands.member?(cmd_name)
112
+ cmd_name
113
+ else
114
+ @proc.aliases[cmd_name]
115
+ end
116
+ cmd_obj = @proc.commands[real_name]
117
+ help_text =
118
+ cmd_obj.respond_to?(:help) ? cmd_obj.help(args) :
119
+ cmd_obj.class.const_get(:HELP)
120
+ if help_text
121
+ msg(help_text)
122
+ if cmd_obj.class.constants.member?('ALIASES') and
123
+ args.size == 2
124
+ msg "Aliases: #{cmd_obj.class.const_get(:ALIASES).join(', ')}"
125
+ end
126
+ end
127
+ elsif @proc.macros.member?(cmd_name)
128
+ msg "#{cmd_name} is a macro which expands to:"
129
+ msg " #{@proc.macros[cmd_name]}", {:unlimited => true}
130
+ else
131
+ matches = @proc.commands.keys.grep(/^#{cmd_name}/).sort rescue []
132
+ if matches.empty?
133
+ errmsg("No commands found matching /^#{cmd_name}/. Try \"help\".")
134
+ else
135
+ section "Command names matching /^#{cmd_name}/:"
136
+ msg columnize_commands(matches.sort)
137
+ end
138
+ end
139
+ else
140
+ list_categories
141
+ end
142
+ end
143
+
144
+ def show_aliases
145
+ section 'All alias names:'
146
+ msg columnize_commands(@proc.aliases.keys.sort)
147
+ end
148
+
149
+ # Show short help for all commands in `category'.
150
+ def show_category(category, args)
151
+
152
+ if args.size == 1 && args[0] == '*'
153
+ section "Commands in class %s:" % category
154
+
155
+ cmds = @proc.commands.keys.select do |cmd_name|
156
+ category == @proc.commands[cmd_name].category
157
+ end.sort
158
+ width = settings[:maxwidth]
159
+ return columnize_commands(cmds)
160
+ end
161
+
162
+ msg('')
163
+ section "Command class: %s" % category
164
+ msg('')
165
+ @proc.commands.keys.sort.each do |name|
166
+ next if category != @proc.commands[name].category
167
+ msg("%-13s -- %s" % [name, @proc.commands[name].short_help])
168
+ end
169
+ end
170
+
171
+ def show_command_syntax
172
+ section "Debugger command syntax"
173
+ msg <<-EOS
174
+ Command tokenization syntax is very simple-minded.
175
+
176
+ If a line starts with #, the command is ignored.
177
+ If a line starts with !, the line is eval'd.
178
+
179
+ If the command you want eval'd uses the Ruby ! initally, add that
180
+ after the first !.
181
+
182
+ Commands are split at whereever ;; appears. This process disregards
183
+ any quotes or other symbols that have meaning in Ruby. The strings
184
+ after the leading command string are put back on a command queue.
185
+
186
+ Within a single command, tokens are then white-space split. Again,
187
+ this process disregards quotes or symbols that have meaning in Ruby.
188
+ Some commands like 'eval' and 'macro' have access to the untokenized
189
+ string entered and make use of that rather than the tokenized list.
190
+
191
+ The leading token is first looked up in the macro table. If it
192
+ found there, the expansion is replaces the current command and possibly
193
+ other commands pushed onto a command queue. Next the leading token is
194
+ looked up in the debugger alias table and the name may be substituted
195
+ there. Finally, the leading token is looked up in the debugger alias
196
+ table. If a match is found, the command name and arguments are
197
+ dispatched to the command object that process the command.
198
+
199
+ If the command is not found and "auto eval" is set on, then the
200
+ command is eval'd in the context that the program is currently stopped
201
+ at. If "auto eval" is not set on, then we display an error message
202
+ that the entered string is "undefined".
203
+
204
+ If you want irb-like command-processing, it's possible to go into an
205
+ irb shell with the "irb" command. It is also possible to arrange going
206
+ into an irb shell every time you enter the debugger.
207
+
208
+ Examples:
209
+
210
+ # This line does nothing. It is a comment
211
+ s # by default, this is an alias for the "step" command
212
+ !s # shows the value of variable step.
213
+ !!s # Evaluates !s (or "not s"). The first ! is indicates evaluate.
214
+ info program;; list # Runs two commands "info program" and "list"
215
+ pr "hi ;;-)" # Syntax error since ;; splits the line and " is not closed.
216
+ !puts "hi ;;-)" # One way to do the above.
217
+
218
+ See also "alias", "irb", "set auto eval", and "set auto irb".
219
+ EOS
220
+ end
221
+
222
+ def show_macros
223
+ section 'All macro names:'
224
+ msg columnize_commands(@proc.macros.keys.sort)
225
+ end
226
+
227
+ end
228
+
229
+ if __FILE__ == $0
230
+ # Demo it.
231
+ require_relative '../mock'
232
+ dbgr, cmd = MockDebugger::setup
233
+
234
+ cmd.run %W(#{cmd.name} help)
235
+ puts '=' * 40
236
+ cmd.run %W(#{cmd.name} *)
237
+ puts '=' * 40
238
+ cmd.run %W(#{cmd.name} fdafsasfda)
239
+ puts '=' * 40
240
+ cmd.run [cmd.name]
241
+ puts '=' * 40
242
+ cmd.run %W(#{cmd.name} support)
243
+ puts '=' * 40
244
+ cmd.run %W(#{cmd.name} support *)
245
+ puts '=' * 40
246
+ cmd.run %W(#{cmd.name} s.*)
247
+ puts '=' * 40
248
+ cmd.run %W(#{cmd.name} s<>)
249
+ puts '=' * 40
250
+ p cmd.complete('br')
251
+ end