rbx-trepanning 0.2.0-universal-rubinius-2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (312) hide show
  1. data/.gitignore +7 -0
  2. data/ChangeLog +2967 -0
  3. data/LICENSE +25 -0
  4. data/Makefile +13 -0
  5. data/NEWS +105 -0
  6. data/README.textile +34 -0
  7. data/Rakefile +244 -0
  8. data/THANKS +14 -0
  9. data/app/.gitignore +2 -0
  10. data/app/breakpoint.rb +242 -0
  11. data/app/brkptmgr.rb +153 -0
  12. data/app/client.rb +71 -0
  13. data/app/cmd_parse.kpeg +242 -0
  14. data/app/cmd_parse.rb +209 -0
  15. data/app/cmd_parser.rb +2083 -0
  16. data/app/complete.rb +79 -0
  17. data/app/condition.rb +22 -0
  18. data/app/default.rb +71 -0
  19. data/app/display.rb +186 -0
  20. data/app/eventbuffer.rb +147 -0
  21. data/app/file.rb +24 -0
  22. data/app/frame.rb +120 -0
  23. data/app/irb.rb +113 -0
  24. data/app/iseq.rb +188 -0
  25. data/app/method.rb +178 -0
  26. data/app/mock.rb +13 -0
  27. data/app/options.rb +154 -0
  28. data/app/rbx-llvm.rb +163 -0
  29. data/app/run.rb +92 -0
  30. data/app/util.rb +99 -0
  31. data/app/validate.rb +30 -0
  32. data/bin/.gitignore +2 -0
  33. data/bin/trepanx +69 -0
  34. data/data/.gitignore +2 -0
  35. data/data/irbrc +41 -0
  36. data/interface/.gitignore +2 -0
  37. data/interface/client.rb +84 -0
  38. data/interface/comcodes.rb +20 -0
  39. data/interface/script.rb +112 -0
  40. data/interface/server.rb +147 -0
  41. data/interface/user.rb +158 -0
  42. data/interface.rb +109 -0
  43. data/io/.gitignore +3 -0
  44. data/io/input.rb +151 -0
  45. data/io/null_output.rb +46 -0
  46. data/io/string_array.rb +155 -0
  47. data/io/tcpclient.rb +129 -0
  48. data/io/tcpfns.rb +33 -0
  49. data/io/tcpserver.rb +141 -0
  50. data/io.rb +148 -0
  51. data/lib/.gitignore +2 -0
  52. data/lib/trepanning.rb +467 -0
  53. data/processor/.gitignore +3 -0
  54. data/processor/Makefile +7 -0
  55. data/processor/breakpoint.rb +167 -0
  56. data/processor/command/.gitignore +2 -0
  57. data/processor/command/alias.rb +65 -0
  58. data/processor/command/backtrace.rb +68 -0
  59. data/processor/command/base/.gitignore +2 -0
  60. data/processor/command/base/subcmd.rb +226 -0
  61. data/processor/command/base/submgr.rb +185 -0
  62. data/processor/command/base/subsubcmd.rb +125 -0
  63. data/processor/command/base/subsubmgr.rb +196 -0
  64. data/processor/command/break.rb +78 -0
  65. data/processor/command/complete.rb +39 -0
  66. data/processor/command/condition.rb +64 -0
  67. data/processor/command/continue.rb +61 -0
  68. data/processor/command/delete.rb +44 -0
  69. data/processor/command/directory.rb +51 -0
  70. data/processor/command/disable.rb +71 -0
  71. data/processor/command/disassemble.rb +180 -0
  72. data/processor/command/display.rb +84 -0
  73. data/processor/command/down.rb +54 -0
  74. data/processor/command/edit.rb +74 -0
  75. data/processor/command/enable.rb +43 -0
  76. data/processor/command/eval.rb +93 -0
  77. data/processor/command/exit.rb +83 -0
  78. data/processor/command/finish.rb +80 -0
  79. data/processor/command/frame.rb +93 -0
  80. data/processor/command/help/.gitignore +1 -0
  81. data/processor/command/help/README +10 -0
  82. data/processor/command/help/command.txt +58 -0
  83. data/processor/command/help/examples.txt +16 -0
  84. data/processor/command/help/filename.txt +40 -0
  85. data/processor/command/help/location.txt +37 -0
  86. data/processor/command/help/suffixes.txt +17 -0
  87. data/processor/command/help.rb +228 -0
  88. data/processor/command/info.rb +30 -0
  89. data/processor/command/info_subcmd/.gitignore +3 -0
  90. data/processor/command/info_subcmd/breakpoints.rb +103 -0
  91. data/processor/command/info_subcmd/files.rb +219 -0
  92. data/processor/command/info_subcmd/frame.rb +68 -0
  93. data/processor/command/info_subcmd/line.rb +75 -0
  94. data/processor/command/info_subcmd/locals.rb +22 -0
  95. data/processor/command/info_subcmd/macro.rb +62 -0
  96. data/processor/command/info_subcmd/method.rb +71 -0
  97. data/processor/command/info_subcmd/program.rb +51 -0
  98. data/processor/command/info_subcmd/ruby.rb +64 -0
  99. data/processor/command/info_subcmd/source.rb +75 -0
  100. data/processor/command/info_subcmd/stack.rb +25 -0
  101. data/processor/command/info_subcmd/variables.rb +35 -0
  102. data/processor/command/info_subcmd/variables_subcmd/.gitignore +2 -0
  103. data/processor/command/info_subcmd/variables_subcmd/class.rb +42 -0
  104. data/processor/command/info_subcmd/variables_subcmd/constant.rb +42 -0
  105. data/processor/command/info_subcmd/variables_subcmd/globals.rb +69 -0
  106. data/processor/command/info_subcmd/variables_subcmd/instance.rb +42 -0
  107. data/processor/command/info_subcmd/variables_subcmd/locals.rb +80 -0
  108. data/processor/command/kill.rb +79 -0
  109. data/processor/command/list.rb +234 -0
  110. data/processor/command/macro.rb +86 -0
  111. data/processor/command/next.rb +67 -0
  112. data/processor/command/nexti.rb +59 -0
  113. data/processor/command/parsetree.rb +51 -0
  114. data/processor/command/pr.rb +37 -0
  115. data/processor/command/ps.rb +40 -0
  116. data/processor/command/restart.rb +60 -0
  117. data/processor/command/save.rb +58 -0
  118. data/processor/command/server.rb +72 -0
  119. data/processor/command/set.rb +47 -0
  120. data/processor/command/set_subcmd/.gitignore +2 -0
  121. data/processor/command/set_subcmd/abbrev.rb +25 -0
  122. data/processor/command/set_subcmd/auto.rb +33 -0
  123. data/processor/command/set_subcmd/auto_subcmd/.gitignore +2 -0
  124. data/processor/command/set_subcmd/auto_subcmd/dis.rb +33 -0
  125. data/processor/command/set_subcmd/auto_subcmd/eval.rb +53 -0
  126. data/processor/command/set_subcmd/auto_subcmd/irb.rb +33 -0
  127. data/processor/command/set_subcmd/auto_subcmd/list.rb +33 -0
  128. data/processor/command/set_subcmd/basename.rb +25 -0
  129. data/processor/command/set_subcmd/confirm.rb +24 -0
  130. data/processor/command/set_subcmd/debug.rb +26 -0
  131. data/processor/command/set_subcmd/debug_subcmd/.gitignore +2 -0
  132. data/processor/command/set_subcmd/debug_subcmd/dbgr.rb +36 -0
  133. data/processor/command/set_subcmd/debug_subcmd/skip.rb +23 -0
  134. data/processor/command/set_subcmd/debug_subcmd/step.rb +23 -0
  135. data/processor/command/set_subcmd/different.rb +61 -0
  136. data/processor/command/set_subcmd/hidelevel.rb +62 -0
  137. data/processor/command/set_subcmd/highlight.rb +39 -0
  138. data/processor/command/set_subcmd/kernelstep.rb +60 -0
  139. data/processor/command/set_subcmd/max.rb +26 -0
  140. data/processor/command/set_subcmd/max_subcmd/.gitignore +2 -0
  141. data/processor/command/set_subcmd/max_subcmd/list.rb +49 -0
  142. data/processor/command/set_subcmd/max_subcmd/stack.rb +50 -0
  143. data/processor/command/set_subcmd/max_subcmd/string.rb +76 -0
  144. data/processor/command/set_subcmd/max_subcmd/width.rb +49 -0
  145. data/processor/command/set_subcmd/reload.rb +42 -0
  146. data/processor/command/set_subcmd/substitute.rb +24 -0
  147. data/processor/command/set_subcmd/substitute_subcmd/.gitignore +3 -0
  148. data/processor/command/set_subcmd/substitute_subcmd/path.rb +56 -0
  149. data/processor/command/set_subcmd/timer.rb +58 -0
  150. data/processor/command/set_subcmd/trace.rb +37 -0
  151. data/processor/command/set_subcmd/trace_subcmd/.gitignore +2 -0
  152. data/processor/command/set_subcmd/trace_subcmd/buffer.rb +42 -0
  153. data/processor/command/set_subcmd/trace_subcmd/print.rb +41 -0
  154. data/processor/command/shell.rb +131 -0
  155. data/processor/command/show.rb +39 -0
  156. data/processor/command/show_subcmd/.gitignore +3 -0
  157. data/processor/command/show_subcmd/abbrev.rb +20 -0
  158. data/processor/command/show_subcmd/aliases.rb +46 -0
  159. data/processor/command/show_subcmd/args.rb +25 -0
  160. data/processor/command/show_subcmd/auto.rb +28 -0
  161. data/processor/command/show_subcmd/auto_subcmd/.gitignore +3 -0
  162. data/processor/command/show_subcmd/auto_subcmd/dis.rb +37 -0
  163. data/processor/command/show_subcmd/auto_subcmd/eval.rb +24 -0
  164. data/processor/command/show_subcmd/auto_subcmd/irb.rb +23 -0
  165. data/processor/command/show_subcmd/auto_subcmd/list.rb +22 -0
  166. data/processor/command/show_subcmd/basename.rb +20 -0
  167. data/processor/command/show_subcmd/confirm.rb +18 -0
  168. data/processor/command/show_subcmd/debug.rb +26 -0
  169. data/processor/command/show_subcmd/debug_subcmd/.gitignore +3 -0
  170. data/processor/command/show_subcmd/debug_subcmd/dbgr.rb +21 -0
  171. data/processor/command/show_subcmd/debug_subcmd/skip.rb +22 -0
  172. data/processor/command/show_subcmd/debug_subcmd/step.rb +22 -0
  173. data/processor/command/show_subcmd/different.rb +26 -0
  174. data/processor/command/show_subcmd/directories.rb +22 -0
  175. data/processor/command/show_subcmd/hidelevel.rb +41 -0
  176. data/processor/command/show_subcmd/highlight.rb +25 -0
  177. data/processor/command/show_subcmd/kernelstep.rb +34 -0
  178. data/processor/command/show_subcmd/max.rb +27 -0
  179. data/processor/command/show_subcmd/max_subcmd/.gitignore +2 -0
  180. data/processor/command/show_subcmd/max_subcmd/list.rb +38 -0
  181. data/processor/command/show_subcmd/max_subcmd/stack.rb +36 -0
  182. data/processor/command/show_subcmd/max_subcmd/string.rb +42 -0
  183. data/processor/command/show_subcmd/max_subcmd/width.rb +37 -0
  184. data/processor/command/show_subcmd/reload.rb +18 -0
  185. data/processor/command/show_subcmd/timer.rb +18 -0
  186. data/processor/command/show_subcmd/trace.rb +27 -0
  187. data/processor/command/show_subcmd/trace_subcmd/.gitignore +2 -0
  188. data/processor/command/show_subcmd/trace_subcmd/buffer.rb +64 -0
  189. data/processor/command/show_subcmd/trace_subcmd/print.rb +23 -0
  190. data/processor/command/show_subcmd/version.rb +23 -0
  191. data/processor/command/source.rb +133 -0
  192. data/processor/command/step.rb +97 -0
  193. data/processor/command/tbreak.rb +20 -0
  194. data/processor/command/unalias.rb +49 -0
  195. data/processor/command/undisplay.rb +63 -0
  196. data/processor/command/up.rb +89 -0
  197. data/processor/command.rb +173 -0
  198. data/processor/default.rb +64 -0
  199. data/processor/disassemble.rb +59 -0
  200. data/processor/display.rb +53 -0
  201. data/processor/eval.rb +97 -0
  202. data/processor/eventbuf.rb +101 -0
  203. data/processor/frame.rb +265 -0
  204. data/processor/help.rb +94 -0
  205. data/processor/hook.rb +134 -0
  206. data/processor/list.rb +123 -0
  207. data/processor/load_cmds.rb +253 -0
  208. data/processor/location.rb +228 -0
  209. data/processor/mock.rb +138 -0
  210. data/processor/msg.rb +74 -0
  211. data/processor/running.rb +244 -0
  212. data/processor/stepping.rb +135 -0
  213. data/processor/subcmd.rb +136 -0
  214. data/processor/validate.rb +379 -0
  215. data/processor/virtual.rb +33 -0
  216. data/processor.rb +404 -0
  217. data/rbx-trepanning.gemspec +39 -0
  218. data/sample/.gitignore +2 -0
  219. data/sample/list-terminal-colors.rb +139 -0
  220. data/sample/rocky-dot-trepanxrc +14 -0
  221. data/sample/rocky-trepanx-colors.rb +46 -0
  222. data/test/data/.gitignore +1 -0
  223. data/test/data/enable.right +36 -0
  224. data/test/data/fname-with-blank.cmd +6 -0
  225. data/test/data/fname-with-blank.right +6 -0
  226. data/test/data/inline-call.cmd +6 -0
  227. data/test/data/inline-call.right +14 -0
  228. data/test/data/quit-Xdebug.right +3 -0
  229. data/test/data/quit.cmd +5 -0
  230. data/test/data/quit.right +3 -0
  231. data/test/data/quit2.cmd +6 -0
  232. data/test/data/quit2.right +3 -0
  233. data/test/example/.gitignore +2 -0
  234. data/test/example/debugger-stop.rb +16 -0
  235. data/test/example/factorial.rb +10 -0
  236. data/test/example/fname with blank.rb +1 -0
  237. data/test/example/gcd-server.rb +22 -0
  238. data/test/example/gcd.rb +19 -0
  239. data/test/example/goto2goto.rb +11 -0
  240. data/test/example/inline-call.rb +23 -0
  241. data/test/example/null.rb +1 -0
  242. data/test/example/thread1.rb +3 -0
  243. data/test/functional/.gitignore +3 -0
  244. data/test/functional/fn_helper.rb +112 -0
  245. data/test/functional/test-break-name.rb +52 -0
  246. data/test/functional/test-break.rb +85 -0
  247. data/test/functional/test-eval.rb +115 -0
  248. data/test/functional/test-finish.rb +70 -0
  249. data/test/functional/test-fn_helper.rb +43 -0
  250. data/test/functional/test-list.rb +56 -0
  251. data/test/functional/test-next-bug.rb +49 -0
  252. data/test/functional/test-next.rb +101 -0
  253. data/test/functional/test-recursive-bt.rb +94 -0
  254. data/test/functional/test-step.rb +272 -0
  255. data/test/functional/test-step2.rb +35 -0
  256. data/test/functional/test-tbreak.rb +41 -0
  257. data/test/integration/.gitignore +3 -0
  258. data/test/integration/file-diff.rb +89 -0
  259. data/test/integration/helper.rb +81 -0
  260. data/test/integration/test-fname-with-blank.rb +16 -0
  261. data/test/integration/test-inline-call.rb +20 -0
  262. data/test/integration/test-quit.rb +47 -0
  263. data/test/unit/.gitignore +3 -0
  264. data/test/unit/cmd-helper.rb +50 -0
  265. data/test/unit/mock-helper.rb +10 -0
  266. data/test/unit/test-app-brkpt.rb +31 -0
  267. data/test/unit/test-app-brkptmgr.rb +51 -0
  268. data/test/unit/test-app-cmd_parse.rb +97 -0
  269. data/test/unit/test-app-cmd_parser.rb +23 -0
  270. data/test/unit/test-app-complete.rb +39 -0
  271. data/test/unit/test-app-condition.rb +18 -0
  272. data/test/unit/test-app-display.rb +22 -0
  273. data/test/unit/test-app-iseq.rb +64 -0
  274. data/test/unit/test-app-method.rb +54 -0
  275. data/test/unit/test-app-options.rb +94 -0
  276. data/test/unit/test-app-run.rb +14 -0
  277. data/test/unit/test-app-util.rb +44 -0
  278. data/test/unit/test-app-validate.rb +18 -0
  279. data/test/unit/test-base-cmd.rb +45 -0
  280. data/test/unit/test-base-subcmd.rb +57 -0
  281. data/test/unit/test-base-submgr.rb +24 -0
  282. data/test/unit/test-base-subsubcmd.rb +17 -0
  283. data/test/unit/test-bin-trepanx.rb +48 -0
  284. data/test/unit/test-cmd-alias.rb +48 -0
  285. data/test/unit/test-cmd-break.rb +66 -0
  286. data/test/unit/test-cmd-edit.rb +34 -0
  287. data/test/unit/test-cmd-exit.rb +27 -0
  288. data/test/unit/test-cmd-finish.rb +31 -0
  289. data/test/unit/test-cmd-help.rb +104 -0
  290. data/test/unit/test-cmd-kill.rb +54 -0
  291. data/test/unit/test-cmd-parse_list_cmd.rb +36 -0
  292. data/test/unit/test-cmd-source.rb +34 -0
  293. data/test/unit/test-cmd-step.rb +29 -0
  294. data/test/unit/test-command.rb +45 -0
  295. data/test/unit/test-completion.rb +48 -0
  296. data/test/unit/test-intf-user.rb +46 -0
  297. data/test/unit/test-io-input.rb +27 -0
  298. data/test/unit/test-io-tcp.rb +33 -0
  299. data/test/unit/test-io-tcpclient.rb +54 -0
  300. data/test/unit/test-io-tcpfns.rb +17 -0
  301. data/test/unit/test-io-tcpserver.rb +50 -0
  302. data/test/unit/test-proc-eval.rb +35 -0
  303. data/test/unit/test-proc-frame.rb +81 -0
  304. data/test/unit/test-proc-help.rb +16 -0
  305. data/test/unit/test-proc-hook.rb +30 -0
  306. data/test/unit/test-proc-list.rb +55 -0
  307. data/test/unit/test-proc-load_cmds.rb +51 -0
  308. data/test/unit/test-proc-location.rb +67 -0
  309. data/test/unit/test-proc-main.rb +95 -0
  310. data/test/unit/test-proc-validate.rb +139 -0
  311. data/test/unit/test-subcmd-help.rb +43 -0
  312. metadata +545 -0
data/lib/trepanning.rb ADDED
@@ -0,0 +1,467 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (C) 2010-2011, 2013 Rocky Bernstein <rockyb@rubyforge.net>
4
+ require 'readline'
5
+ require 'compiler/iseq'
6
+
7
+ require 'rubygems'; require 'require_relative'
8
+ require_relative '../app/complete' # command completion
9
+ require_relative '../app/frame'
10
+ require_relative '../app/util' # get_dollar_0
11
+ require_relative '../processor'
12
+ require_relative '../app/breakpoint'
13
+ require_relative '../app/default' # default debugger settings
14
+ require_relative '../app/breakpoint'
15
+ require_relative '../interface/user' # user interface (includes I/O)
16
+ require_relative '../interface/script' # --command interface (includes I/O)
17
+ require_relative '../interface/client' # client interface (remote debugging)
18
+ require_relative '../interface/server' # server interface (remote debugging)
19
+ require_relative '../io/null_output'
20
+
21
+ #
22
+ # The Rubinius Trepan debugger.
23
+ #
24
+ # This debugger is wired into the debugging APIs provided by Rubinius.
25
+ #
26
+
27
+ class Trepan
28
+ attr_accessor :breakpoint # Breakpoint. The current breakpoint we are
29
+ # stopped at or nil if none.
30
+ attr_accessor :intf # Array. The way the outside world
31
+ # interfaces with us. An array, so that
32
+ # interfaces can be stacked.
33
+ attr_accessor :restart_argv # How to restart us, empty or nil.
34
+ # Note: restart_argv is typically C's
35
+ # **argv, not Ruby's ARGV. So
36
+ # restart_argv[0] is $0.
37
+ attr_reader :settings # Hash[:symbol] of things you can configure
38
+ attr_reader :deferred_breakpoints
39
+ attr_reader :processor
40
+
41
+ # Create a new debugger object. The debugger starts up a thread
42
+ # which is where the command line interface executes from. Other
43
+ # threads that you wish to debug are told that their debugging
44
+ # thread is the debugger thread. This is how the debugger is handed
45
+ # control of execution.
46
+ #
47
+ def initialize(settings={})
48
+ @breakpoint = nil
49
+ @settings = DEFAULT_SETTINGS.merge(settings)
50
+ @input = @settings[:input] || STDIN
51
+ @output = @settings[:output] || STDOUT
52
+
53
+ cmdproc_settings = {:highlight => @settings[:highlight],
54
+ :traceprint => @settings[:traceprint]}
55
+
56
+ @processor = CmdProcessor.new(self, cmdproc_settings)
57
+ @completion_proc = method(:completion_method)
58
+
59
+ @in_deferred_checking = false
60
+
61
+ @intf =
62
+ if @settings[:server]
63
+ @completion_proc = nil
64
+ opts = Trepan::ServerInterface::DEFAULT_INIT_CONNECTION_OPTS.dup
65
+ opts[:port] = @settings[:port] if @settings[:port]
66
+ opts[:host] = @settings[:host] if @settings[:host]
67
+ opts[:readline] = false
68
+ puts("starting debugger in out-of-process mode port at " +
69
+ "#{opts[:host]}:#{opts[:port]}")
70
+ [Trepan::ServerInterface.new(nil, nil, opts)]
71
+ elsif @settings[:client]
72
+ opts = Trepan::ClientInterface::DEFAULT_INIT_CONNECTION_OPTS.dup
73
+ opts[:port] = @settings[:port] if @settings[:port]
74
+ opts[:host] = @settings[:host] if @settings[:host]
75
+ opts[:complete] = @completion_proc
76
+ opts[:readline] ||= @settings[:readline]
77
+ [Trepan::ClientInterface.new(nil, nil, nil, {}, opts)]
78
+ else
79
+ opts = {:complete => @completion_proc,
80
+ :readline => @settings[:readline]}
81
+ [Trepan::UserInterface.new(@input, @output, opts)]
82
+ end
83
+
84
+ process_cmdfile_setting(@settings)
85
+ if @settings[:initial_dir]
86
+ Dir.chdir(@settings[:initial_dir])
87
+ else
88
+ @settings[:initial_dir] = Dir.pwd
89
+ end
90
+ @initial_dir = @settings[:initial_dir]
91
+ @restart_argv = @settings[:restart_argv]
92
+
93
+ ## FIXME: Delete these and use the ones in processor/default instead.
94
+ @variables = {
95
+ :show_bytecode => false,
96
+ }
97
+
98
+ @processor.dbgr = self
99
+ @deferred_breakpoints = []
100
+ @thread = nil
101
+ @frames = []
102
+
103
+ unless @settings[:client]
104
+ ## FIXME: put in fn
105
+ ## m = Rubinius::Loader.method(:debugger).executable.inspect
106
+ meth = Rubinius::VM.backtrace(0)[0].method
107
+ @processor.ignore_methods[meth] = 'next'
108
+ @processor.ignore_methods[method(:debugger)] = 'step'
109
+
110
+ @loaded_hook = proc { |file|
111
+ check_deferred_breakpoints
112
+ }
113
+
114
+ @added_hook = proc { |mod, name, exec|
115
+ check_deferred_breakpoints
116
+ }
117
+
118
+ # Use a few Rubinius-specific hooks to trigger checking
119
+ # for deferred breakpoints.
120
+
121
+ Rubinius::CodeLoader.loaded_hook.add @loaded_hook
122
+ Rubinius.add_method_hook.add @added_hook
123
+
124
+ end
125
+
126
+ # Run user debugger command startup files.
127
+ add_startup_files unless @settings[:nx]
128
+ end
129
+
130
+ # The method is called when we want to do debugger command completion
131
+ # such as called from GNU Readline with <TAB>.
132
+ def completion_method(last_token, leading=Readline.line_buffer)
133
+ completion = @processor.complete(leading, last_token)
134
+ if 1 == completion.size
135
+ completion_token = completion[0]
136
+ if last_token.end_with?(' ')
137
+ if last_token.rstrip == completion_token
138
+ # There is nothing more to complete
139
+ []
140
+ else
141
+ []
142
+ end
143
+ else
144
+ [completion_token]
145
+ end
146
+ else
147
+ # We have multiple completions. Get the last token so that will
148
+ # be presented as a list of completions.
149
+ completion
150
+ end
151
+ end
152
+
153
+ ## HACK to skip over loader code. Until I find something better...
154
+ def skip_loader
155
+ cmds =
156
+ if @settings[:skip_loader] == :Xdebug
157
+ ['continue Rubinius::CodeLoader.load_script',
158
+ 'next 6',
159
+ # 'set kernelstep off', # eventually would like 'on'
160
+ 'step',
161
+ ]
162
+ else
163
+ ['next', 'next', 'next',
164
+ # 'set kernelstep off', # eventually would like 'on'
165
+ 'set hidelevel -1',
166
+ 'step', ]
167
+ end
168
+
169
+ input = Trepan::StringArrayInput.open(cmds)
170
+ startup = Trepan::ScriptInterface.new('startup',
171
+ Trepan::OutputNull.new(nil),
172
+ :input => input)
173
+ @intf << startup
174
+ end
175
+
176
+ attr_reader :completion_proc # GNU Readline completion proc
177
+ attr_reader :variables, :current_frame, :breakpoints
178
+ attr_reader :vm_locations, :debugee_thread
179
+
180
+ def self.global(settings={})
181
+ @global ||= new(settings)
182
+ end
183
+
184
+ def self.start(settings={})
185
+ settings = {:immediate => false, :offset => 1}.merge(settings)
186
+ global(settings).start(settings)
187
+ end
188
+
189
+ # This is simplest API point. This starts up the debugger in the caller
190
+ # of this method to begin debugging.
191
+ #
192
+ def self.here(settings={})
193
+ global(settings).start(:offset => 1)
194
+ end
195
+
196
+ # Startup the debugger, skipping back +offset+ frames. This lets you start
197
+ # the debugger straight into callers method.
198
+ #
199
+ def debugger(settings = {:immediate => false})
200
+ @settings = @settings.merge(settings)
201
+ skip_loader if @settings[:skip_loader]
202
+ spinup_thread
203
+ @debugee_thread = @thread
204
+ if @settings[:hide_level]
205
+ @processor.hidelevels[@thread] = @settings[:hide_level]
206
+ end
207
+
208
+ process_cmdfile_setting(settings)
209
+
210
+ # Feed info (breakpoint, debugged program thread, channel and backtrace
211
+ # info) to the debugger thread
212
+ locs = Rubinius::VM.backtrace(@settings[:offset] + 1, true)
213
+
214
+ method = Rubinius::CompiledMethod.of_sender
215
+
216
+ event = settings[:immediate] ? 'debugger-call' : 'start'
217
+ bp = Breakpoint.new('<start>', method, 0, 0, 0, {:event => event} )
218
+ channel = Rubinius::Channel.new
219
+
220
+ @local_channel.send Rubinius::Tuple[bp, Thread.current, channel, locs]
221
+
222
+ # wait for the debugger to release us
223
+ channel.receive
224
+
225
+ # Now that there is a debugger on the other end, set the debugged
226
+ # program thread to call us when it hits a breakpoint.
227
+ Thread.current.set_debugger_thread @thread
228
+ self
229
+ end
230
+ alias start debugger
231
+
232
+ def stop(settings = {})
233
+ @processor.finalize
234
+ # Rubinius::VM.debug_channel = nil
235
+ end
236
+
237
+ def add_command_file(cmdfile, opts={}, stderr=$stderr)
238
+ unless File.readable?(cmdfile)
239
+ if File.exists?(cmdfile)
240
+ stderr.puts "Command file '#{cmdfile}' is not readable."
241
+ return
242
+ else
243
+ stderr.puts "Command file '#{cmdfile}' does not exist."
244
+ return
245
+ end
246
+ end
247
+ @intf << Trepan::ScriptInterface.new(cmdfile, @output, opts)
248
+ end
249
+
250
+ def add_startup_files()
251
+ seen = {}
252
+ cwd_initfile = File.join('.', Trepan::CMD_INITFILE_BASE)
253
+ [cwd_initfile, Trepan::CMD_INITFILE].each do |initfile|
254
+ full_initfile_path = File.expand_path(initfile)
255
+ next if seen[full_initfile_path]
256
+ add_command_file(full_initfile_path) if File.readable?(full_initfile_path)
257
+ seen[full_initfile_path] = true
258
+ end
259
+ end
260
+
261
+ def process_cmdfile_setting(settings)
262
+ settings[:cmdfiles].each do |item|
263
+ cmdfile, opts =
264
+ if item.kind_of?(Array)
265
+ item
266
+ else
267
+ [item, {}]
268
+ end
269
+ add_command_file(cmdfile, opts)
270
+ end if settings.member?(:cmdfiles)
271
+ end
272
+
273
+ # Stop and wait for a debuggee thread to send us info about
274
+ # stopping at a breakpoint.
275
+ #
276
+ def listen(step_into=false)
277
+ @breakpoint = nil
278
+ while true
279
+ if @channel
280
+ if step_into
281
+ @channel << :step
282
+ else
283
+ @channel << true
284
+ end
285
+ end
286
+
287
+ # Wait for someone to stop
288
+ @breakpoint, @debugee_thread, @channel, @vm_locations =
289
+ @local_channel.receive
290
+
291
+ # Uncache all frames since we stopped at a new place
292
+ @frames = []
293
+
294
+ set_frame(0)
295
+
296
+ if @breakpoint
297
+ # Some breakpoints are frame specific. Check for this. hit!
298
+ # also removes the breakpoint if it was temporary and hit.
299
+ status = @breakpoint.hit!(@vm_locations.first.variables)
300
+ if status
301
+ break
302
+ elsif @breakpoint.enabled? && status.nil?
303
+ # A permanent breakpoint. Check the condition.
304
+ break if @breakpoint.condition?(@current_frame.binding)
305
+ end
306
+ else
307
+ @processor.remove_step_brkpt
308
+ break
309
+ end
310
+ end
311
+
312
+ event =
313
+ if @breakpoint
314
+ @breakpoint.event || 'brkpt'
315
+ else
316
+ # Evan assures me that the only way the breakpoint can be nil
317
+ # is if we are stepping and enter a function.
318
+ 'step-call'
319
+ end
320
+ @processor.instance_variable_set('@event', event)
321
+
322
+ if @variables[:show_bytecode]
323
+ decode_one
324
+ end
325
+
326
+ end
327
+
328
+ def frame(num)
329
+ @frames[num] ||= Frame.new(self, num, @vm_locations[num])
330
+ end
331
+
332
+ def set_frame(num)
333
+ @current_frame = frame(num)
334
+ end
335
+
336
+ def each_frame(start=0)
337
+ start = start.number if start.kind_of?(Frame)
338
+
339
+ start.upto(@vm_locations.size-1) do |idx|
340
+ yield frame(idx)
341
+ end
342
+ end
343
+
344
+ def add_deferred_breakpoint(klass_name, which, name, line)
345
+ dbp = Trepan::DeferredBreakpoint.new(self, @current_frame, klass_name,
346
+ which, name, line,
347
+ @deferred_breakpoints)
348
+ @deferred_breakpoints << dbp
349
+ # @processor.brkpts << dbp
350
+ end
351
+
352
+ def check_deferred_breakpoints
353
+ unless @in_deferred_checking
354
+ @in_deferred_checking = true
355
+ @deferred_breakpoints.delete_if do |bp|
356
+ bp.resolve!
357
+ end
358
+ @in_deferred_checking = false
359
+ end
360
+ end
361
+
362
+ def send_between(exec, start, fin)
363
+ ss = Rubinius::InstructionSet.opcodes_map[:send_stack]
364
+ sm = Rubinius::InstructionSet.opcodes_map[:send_method]
365
+ sb = Rubinius::InstructionSet.opcodes_map[:send_stack_with_block]
366
+
367
+ iseq = exec.iseq
368
+
369
+ fin = iseq.size if fin < 0
370
+
371
+ i = start
372
+ while i < fin
373
+ op = iseq[i]
374
+ case op
375
+ when ss, sm, sb
376
+ return exec.literals[iseq[i + 1]]
377
+ else
378
+ op = Rubinius::InstructionSet[op]
379
+ i += (op.arg_count + 1)
380
+ end
381
+ end
382
+
383
+ return nil
384
+ end
385
+
386
+ def show_code(line=@current_frame.line)
387
+ path = @current_frame.method.active_path
388
+ str = @processor.line_at(path, line)
389
+ unless str.nil?
390
+ # if @variables[:highlight]
391
+ # fin = @current_frame.method.first_ip_on_line(line + 1)
392
+ # name = send_between(@current_frame.method, @current_frame.ip, fin)
393
+
394
+ # if name
395
+ # str = str.gsub name.to_s, "\033[0;4m#{name}\033[0m"
396
+ # end
397
+ # end
398
+ # info "#{line}: #{str}"
399
+ else
400
+ show_bytecode(line)
401
+ end
402
+ end
403
+
404
+ def decode_one
405
+ ip = @current_frame.next_ip
406
+
407
+ meth = @current_frame.method
408
+ decoder = Rubinius::InstructionDecoder.new(meth.iseq)
409
+ partial = decoder.decode_between(ip, ip+1)
410
+
411
+ partial.each do |ins|
412
+ op = ins.shift
413
+
414
+ ins.each_index do |i|
415
+ case op.args[i]
416
+ when :literal
417
+ ins[i] = meth.literals[ins[i]].inspect
418
+ when :local
419
+ if meth.local_names
420
+ ins[i] = meth.local_names[ins[i]]
421
+ end
422
+ end
423
+ end
424
+
425
+ puts "=> ip #{ip} = #{op.opcode} #{ins.join(', ')}"
426
+ end
427
+ end
428
+
429
+ def spinup_thread
430
+ return if @thread
431
+
432
+ @local_channel = Rubinius::Channel.new
433
+
434
+ @thread = Thread.new do
435
+ begin
436
+ listen
437
+ rescue Exception => e
438
+ e.render("Listening")
439
+ break
440
+ end
441
+
442
+ @processor.process_commands
443
+
444
+ end
445
+
446
+ @thread.setup_control!(@local_channel)
447
+ end
448
+
449
+ private :spinup_thread
450
+
451
+ end
452
+
453
+ module Kernel
454
+ # A simpler way of calling Trepan.start
455
+ def debugger(settings = {})
456
+ settings = {:immediate => false, :offset => 2}.merge(settings)
457
+ Trepan.start(settings)
458
+ end
459
+ alias breakpoint debugger unless respond_to?(:breakpoint)
460
+ end
461
+
462
+ if __FILE__ == $0
463
+ if ARGV.size > 0
464
+ debugger
465
+ x = 1
466
+ end
467
+ end
@@ -0,0 +1,3 @@
1
+ /*.rbc
2
+ /*~
3
+
@@ -0,0 +1,7 @@
1
+ # Whatever it is you want to do, it should be forwarded to the
2
+ # to top-level irectories
3
+ PHONY=check
4
+ check:
5
+
6
+ %:
7
+ $(MAKE) -C .. $@
@@ -0,0 +1,167 @@
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ require 'rubygems'; require 'require_relative'
3
+ require_relative 'virtual'
4
+ require_relative '../app/brkptmgr'
5
+ class Trepan::CmdProcessor < Trepan::VirtualCmdProcessor
6
+
7
+ attr_reader :brkpts # BreakpointManager.
8
+
9
+ attr_reader :brkpt # Breakpoint. If we are stopped at a
10
+ # breakpoint this is the one we
11
+ # found. (There may be other
12
+ # breakpoints that would have caused a stop
13
+ # as well; this is just one of them).
14
+ # If no breakpoint stop this is nil.
15
+
16
+ def breakpoint_initialize
17
+ @brkpts = Trepan::BreakpointMgr.new
18
+ @brkpt = nil
19
+ end
20
+
21
+ def breakpoint_finalize
22
+ @brkpts.finalize
23
+ end
24
+
25
+ def breakpoint?
26
+ @brkpt = @dbgr.breakpoint
27
+ return !!@brkpt && %w(tbrkpt brkpt).member?(@brkpt.event)
28
+ end
29
+
30
+ def breakpoint_find(bpnum, show_errmsg = true)
31
+ if 0 == @brkpts.size
32
+ errmsg('No breakpoints set.') if show_errmsg
33
+ return nil
34
+ elsif bpnum > brkpts.size || bpnum < 1
35
+ errmsg('Breakpoint number %d is out of range 1..%d' %
36
+ [bpnum, brkpts.size]) if show_errmsg
37
+ return nil
38
+ end
39
+ bp = @brkpts[bpnum]
40
+ unless bp
41
+ errmsg "Unknown breakpoint '#{bpnum}'" if show_errmsg
42
+ return nil
43
+ end
44
+ bp
45
+ end
46
+
47
+ def set_breakpoint_method(meth, line=nil, ip=nil,
48
+ opts={:event => 'brkpt', :negate=>false,
49
+ :temp => false})
50
+ cm =
51
+ if meth.kind_of?(Method) || meth.kind_of?(UnboundMethod)
52
+ meth.executable
53
+ else
54
+ meth
55
+ end
56
+
57
+ unless cm.kind_of?(Rubinius::CompiledMethod)
58
+ errmsg "Unsupported method type: #{cm.class}"
59
+ return nil
60
+ end
61
+
62
+ if line && line > 0
63
+ ip = cm.first_ip_on_line(line, -2) unless ip
64
+
65
+ unless ip
66
+ errmsg "Unknown line '#{line}' in method '#{cm.name}'"
67
+ return nil
68
+ end
69
+ elsif !ip
70
+ line = cm.first_line
71
+ ip = 0
72
+ end
73
+
74
+ # def lines without code will have value -1.
75
+ ip = 0 if -1 == ip
76
+
77
+ bp = @brkpts.add(meth.name, cm, ip, line, @brkpts.max+1, opts)
78
+ bp.activate
79
+ msg("Set %sbreakpoint #{bp.id}: #{meth.name}() at #{bp.location}" %
80
+ (opts[:temp] ? 'temporary ' : ''))
81
+ return bp
82
+ end
83
+
84
+ # MRI 1.9.2 code
85
+ # def breakpoint_find(bpnum, show_errmsg = true)
86
+ # if 0 == @brkpts.size
87
+ # errmsg('No breakpoints set.') if show_errmsg
88
+ # return nil
89
+ # elsif bpnum > @brkpts.max || bpnum < 1
90
+ # errmsg('Breakpoint number %d is out of range 1..%d' %
91
+ # [bpnum, @brkpts.max]) if show_errmsg
92
+ # return nil
93
+ # end
94
+ # bp = @brkpts[bpnum]
95
+ # if bp
96
+ # return bp
97
+ # else
98
+ # errmsg('Breakpoint number %d previously deleted.' %
99
+ # bpnum) if show_errmsg
100
+ # return nil
101
+ # end
102
+ # end
103
+
104
+ # # Does whatever needs to be done to set a breakpoint
105
+ # def breakpoint_line(line_number, iseq, temp=false)
106
+ # # FIXME: handle breakpoint conditions.
107
+ # iseq = iseq.child_iseqs.detect do |iseq|
108
+ # iseq.lineoffsets.keys.member?(line_number)
109
+ # end
110
+ # offset =
111
+ # if iseq
112
+ # # FIXME
113
+ # iseq.line2offsets(line_number)[1] || iseq.line2offsets(line_number)[0]
114
+ # else
115
+ # nil
116
+ # end
117
+ # unless offset
118
+ # place = "in #{iseq.source_container.join(' ')} " if iseq
119
+ # errmsg("No line #{line_number} found #{place}for breakpoint.")
120
+ # return nil
121
+ # end
122
+ # @brkpts.add(iseq, offset, :temp => temp)
123
+ # end
124
+
125
+ # def breakpoint_offset(offset, iseq, temp=false)
126
+ # # FIXME: handle breakpoint conditions.
127
+ # unless iseq.offsetlines.keys.member?(offset)
128
+ # errmsg("Offset #{offset} not found in #{iseq.name} for breakpoint.")
129
+ # return nil
130
+ # end
131
+ # @brkpts.add(iseq, offset, :temp => temp, :type => 'offset')
132
+ # end
133
+
134
+ # Delete a breakpoint given its breakpoint number.
135
+ # FIXME: use do_enable
136
+ def delete_breakpoint_by_number(bpnum, do_enable=true)
137
+ bp = breakpoint_find(bpnum)
138
+ return false unless bp
139
+ delete_breakpoint(bp)
140
+ end
141
+
142
+ # Enable or disable a breakpoint given its breakpoint number.
143
+ def en_disable_breakpoint_by_number(bpnum, do_enable=true)
144
+ bp = breakpoint_find(bpnum)
145
+ return false unless bp
146
+
147
+ enable_disable = do_enable ? 'en' : 'dis'
148
+ if bp.enabled? == do_enable
149
+ errmsg('Breakpoint %d previously %sabled.' %
150
+ [bpnum, enable_disable])
151
+ return false
152
+ end
153
+ bp.enabled = do_enable
154
+ return true
155
+ end
156
+
157
+ def delete_breakpoint(bp)
158
+ @brkpts.delete_by_brkpt(bp)
159
+ return true
160
+ end
161
+
162
+ end
163
+
164
+ if __FILE__ == $0
165
+ cmdproc = Trepan::CmdProcessor.new([])
166
+ cmdproc.breakpoint_initialize
167
+ end
@@ -0,0 +1,2 @@
1
+ /*.rbc
2
+ /*~
@@ -0,0 +1,65 @@
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ require 'rubygems'; require 'require_relative'
3
+ require_relative '../command'
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 alias ALIAS for a debugger command COMMAND.
13
+
14
+ Add an alias when you want to use a command abbreviation for a command
15
+ that would otherwise be ambigous. For example, by default we make 's'
16
+ be an alias of 'step' to force it to be used. Without the alias, "s"
17
+ might be "step", "show", or "set" among others
18
+
19
+ Example:
20
+
21
+ alias cat list # "cat rubyfile.rb" is the same as "list rubyfile.rb"
22
+ alias s step # "s" is now an alias for "step".
23
+ # The above examples done by default.
24
+
25
+ See also 'unalias' and 'show #{NAME}'.
26
+ HELP
27
+
28
+ CATEGORY = 'support'
29
+ MAX_ARGS = 2 # Need at most this many
30
+ NEED_STACK = true
31
+ SHORT_HELP = 'Add an alias for a debugger command'
32
+ end
33
+
34
+ # Run command.
35
+ def run(args)
36
+ if args.size == 1
37
+ @proc.commands['show'].run(%W(show #{NAME}))
38
+ elsif args.size == 2
39
+ @proc.commands['show'].run(%W(show #{NAME} #{args[1]}))
40
+ else
41
+ junk, al, command = args
42
+ old_command = @proc.aliases[al]
43
+ if @proc.commands.member?(command)
44
+ @proc.aliases[al] = command
45
+ if old_command
46
+ msg("Alias '#{al}' for command '#{command}' replaced old " +
47
+ "alias for '#{old_command}'.")
48
+ else
49
+ msg "New alias '#{al}' for command '#{command}' created."
50
+ end
51
+ else
52
+ errmsg "You must alias to a command name, and '#{command}' isn't one."
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ if __FILE__ == $0
59
+ # Demo it.
60
+ require_relative '../mock'
61
+ dbgr, cmd = MockDebugger::setup
62
+ cmd.run %W(#{cmd.name} yy foo)
63
+ cmd.run [cmd.name]
64
+ cmd.run %W(cmd.name yy alias)
65
+ end