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
@@ -0,0 +1,112 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
3
+
4
+ # Module for reading debugger scripts
5
+
6
+ # Our local modules
7
+ require 'rubygems'; require 'require_relative'
8
+ require_relative '../interface'
9
+ require_relative '../io/input'
10
+ require_relative '../io/string_array'
11
+
12
+ # Interface when reading debugger scripts
13
+ class Trepan::ScriptInterface < Trepan::Interface
14
+ attr_accessor :opts, :output
15
+
16
+ DEFAULT_OPTS = {
17
+ :abort_on_error => true,
18
+ :confirm_val => false,
19
+ :verbose => false,
20
+ :basename => false
21
+ } unless defined?(DEFAULT_OPTS)
22
+
23
+ def initialize(script_name, out=nil, opts={})
24
+
25
+ @opts = DEFAULT_OPTS.merge(opts)
26
+
27
+ at_exit { finalize }
28
+ @script_name = script_name
29
+ @input_lineno = 0
30
+ @input = opts[:input] ||
31
+ Trepan::UserInput.open(script_name, :line_edit => false)
32
+ @buffer_output = []
33
+ unless @opts[:verbose] or out
34
+ out = Trepan::StringArrayOutput.open(@buffer_output)
35
+ end
36
+ super(@input, out, @opts)
37
+ end
38
+
39
+ # Closes input only.
40
+ def close
41
+ @input.close
42
+ end
43
+
44
+ # Called when a dangerous action is about to be done, to make
45
+ # sure it's okay.
46
+ #
47
+ # Could look also look for interactive input and
48
+ # use that. For now, though we'll simplify.
49
+ def confirm(prompt, default)
50
+ @opts[:default_confirm]
51
+ end
52
+
53
+ # Common routine for reporting debugger error messages.
54
+ #
55
+ def errmsg(msg, prefix="*** ")
56
+ # self.verbose shows lines so we don't have to duplicate info
57
+ # here. Perhaps there should be a 'terse' mode to never show
58
+ # position info.
59
+ mess = if not @opts[:verbose]
60
+ location = ("%s:%s: Error in source command file" %
61
+ [@script_name, @input_lineno])
62
+ "%s%s:\n%s%s" % [prefix, location, prefix, msg]
63
+ else
64
+ "%s%s" % [prefix, msg]
65
+ end
66
+ msg(mess)
67
+ # FIXME: should we just set a flag and report eof? to be more
68
+ # consistent with File and IO?
69
+ raise ScriptError if @opts[:abort_on_error]
70
+ end
71
+
72
+ def interactive? ; false end
73
+
74
+ # Script interface to read a command. `prompt' is a parameter for
75
+ # compatibilty and is ignored.
76
+ def read_command(prompt='')
77
+ @input_lineno += 1
78
+ line = readline
79
+ if @opts[:verbose]
80
+ script_name =
81
+ if @opts[:basename]
82
+ File.basename(@script_name)
83
+ else
84
+ @script_name
85
+ end
86
+ location = "%s line %s" % [script_name, @input_lineno]
87
+ msg('+ %s: %s' % [location, line])
88
+ end
89
+ # Do something with history?
90
+ return line
91
+ end
92
+
93
+ # Script interface to read a line. `prompt' is a parameter for
94
+ # compatibilty and is ignored.
95
+ #
96
+ # Could decide make this look for interactive input?
97
+ def readline(prompt='')
98
+ begin
99
+ return input.readline().chomp
100
+ rescue EOFError
101
+ @eof = true
102
+ raise EOFError
103
+ end
104
+ end
105
+ end
106
+
107
+ # Demo
108
+ if __FILE__ == $0
109
+ intf = Trepan::ScriptInterface.new(__FILE__)
110
+ line = intf.readline()
111
+ print "Line read: ", line
112
+ end
@@ -0,0 +1,147 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+
4
+ # Our local modules
5
+ require 'rubygems'; require 'require_relative'
6
+ require_relative '../interface'
7
+ require_relative 'comcodes'
8
+ require_relative '../io/input'
9
+ require_relative '../io/tcpserver'
10
+
11
+ # Mfifoserver = import_relative('fifoserver', '..io', 'pydbgr')
12
+
13
+ # Interface for debugging a program but having user control
14
+ # reside outside of the debugged process, possibly on another
15
+ # computer
16
+ class Trepan::ServerInterface < Trepan::Interface
17
+
18
+ include Trepanning::RemoteCommunication
19
+
20
+ DEFAULT_INIT_CONNECTION_OPTS = {
21
+ :io => 'TCP'
22
+ } unless defined?(DEFAULT_INIT_CONNECTION_OPTS)
23
+
24
+ def initialize(inout=nil, out=nil, connection_opts={})
25
+
26
+ @connection_opts = DEFAULT_INIT_CONNECTION_OPTS.merge(connection_opts)
27
+
28
+ at_exit { finalize }
29
+ @inout =
30
+ if inout
31
+ inout
32
+ else
33
+ server_type = @connection_opts[:io]
34
+ # FIXME: complete this.
35
+ # if 'FIFO' == server_type
36
+ # FIFOServer.new
37
+ # else
38
+ Trepan::TCPDbgServer.new(@connection_opts)
39
+ # end
40
+ end
41
+ # For Compatability
42
+ @output = @inout
43
+ @input = @inout
44
+ @interactive = true # Or at least so we think initially
45
+ end
46
+
47
+ # Closes both input and output
48
+ def close
49
+ if @inout && @inout.connected?
50
+ @inout.write(QUIT + 'bye')
51
+ @inout.close
52
+ end
53
+ end
54
+
55
+ def closed?
56
+ @inout.closed?
57
+ end
58
+
59
+ # Called when a dangerous action is about to be done to make sure
60
+ # it's okay. `prompt' is printed; user response is returned.
61
+ # FIXME: make common routine for this and user.rb
62
+ def confirm(prompt, default)
63
+ while true
64
+ begin
65
+ write_confirm(prompt, default)
66
+ reply = readline(nil).strip.downcase
67
+ rescue EOFError
68
+ return default
69
+ end
70
+ if YES.member?(reply)
71
+ return true
72
+ elsif NO.member?(reply)
73
+ return false
74
+ else
75
+ msg "Please answer 'yes' or 'no'. Try again."
76
+ end
77
+ end
78
+ return default
79
+ end
80
+
81
+ # Return true if we are connected
82
+ def connected?
83
+ :connected == @inout.state
84
+ end
85
+
86
+ # print exit annotation
87
+ def finalize(last_wishes=QUIT)
88
+ @inout.writeline(last_wishes) if connected?
89
+ close
90
+ end
91
+
92
+ def input_eof?
93
+ false
94
+ end
95
+
96
+ # used to write to a debugger that is connected to this
97
+ # server; `str' written will have a newline added to it
98
+ def msg(msg)
99
+ @inout.writeline(PRINT + msg)
100
+ end
101
+
102
+ # used to write to a debugger that is connected to this
103
+ # server; `str' written will not have a newline added to it
104
+ def msg_nocr(msg)
105
+ @inout.write(PRINT + msg)
106
+ end
107
+
108
+ def read_command(prompt)
109
+ readline(prompt)
110
+ end
111
+
112
+ def read_data
113
+ @inout.read_dat
114
+ end
115
+
116
+ def readline(prompt, add_to_history=true)
117
+ if prompt
118
+ write_prompt(prompt)
119
+ end
120
+ coded_line = @inout.read_msg()
121
+ @read_ctrl = coded_line[0..0]
122
+ coded_line[1..-1]
123
+ end
124
+
125
+ # Return connected
126
+ def state
127
+ @inout.state
128
+ end
129
+
130
+ def write_prompt(prompt)
131
+ @inout.write(PROMPT + prompt)
132
+ end
133
+
134
+ def write_confirm(prompt, default)
135
+ if default
136
+ code = CONFIRM_TRUE
137
+ else
138
+ code = CONFIRM_FALSE
139
+ end
140
+ @inout.write(code + prompt)
141
+ end
142
+ end
143
+
144
+ # Demo
145
+ if __FILE__ == $0
146
+ intf = Trepan::ServerInterface.new(nil, nil, :open => false)
147
+ end
data/interface/user.rb ADDED
@@ -0,0 +1,158 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010-2012 Rocky Bernstein <rockyb@rubyforge.net>
3
+
4
+ # Interface when communicating with the user.
5
+
6
+ # Our local modules
7
+
8
+ require 'rubygems'; require 'require_relative'
9
+ require_relative '../interface'
10
+ require_relative '../io/input'
11
+
12
+ # Interface when communicating with the user.
13
+ class Trepan::UserInterface < Trepan::Interface
14
+
15
+ DEFAULT_USER_OPTS = {
16
+ :readline => true, # Try to use GNU Readline?
17
+
18
+ # The below are only used if we want and have readline support.
19
+ # See method Trepan::GNU_readline? below.
20
+ :histsize => 256, # Use gdb's default setting
21
+ :file_history => '.trepanx_hist', # where history file lives
22
+ # Note a directory will
23
+ # be appended
24
+ :history_save => true # do we save the history?
25
+ } unless defined?(DEFAULT_USER_OPTS)
26
+
27
+ def initialize(inp=nil, out=nil, opts={})
28
+ super(inp, out, opts)
29
+ @opts = DEFAULT_USER_OPTS.merge(opts)
30
+ @input = if inp.class.ancestors.member?(Trepan::InputBase)
31
+ inp
32
+ else
33
+ Trepan::UserInput.open(inp, {:readline => opts[:readline]})
34
+ end
35
+ if Trepan::GNU_readline? && @opts[:complete]
36
+ Readline.completion_proc = @opts[:complete]
37
+ read_history
38
+ end
39
+ at_exit { finalize }
40
+ end
41
+
42
+ def closed?
43
+ @input.closed? && @output.closed?
44
+ end
45
+
46
+ # Called when a dangerous action is about to be done, to make
47
+ # sure it's okay. Expect a yes/no answer to `prompt' which is printed,
48
+ # suffixed with a question mark and the default value. The user
49
+ # response converted to a boolean is returned.
50
+ # FIXME: make common routine for this and server.rb
51
+ def confirm(prompt, default)
52
+ default_str = default ? 'Y/n' : 'N/y'
53
+ while true do
54
+ begin
55
+ response = readline('%s (%s) ' % [prompt, default_str])
56
+ rescue EOFError
57
+ return default
58
+ end
59
+ response = response.strip.downcase
60
+
61
+ # We don't catch "Yes, I'm sure" or "NO!", but I leave that
62
+ # as an exercise for the reader.
63
+ break if YES_OR_NO.member?(response)
64
+ msg "Please answer 'yes' or 'no'. Try again."
65
+ end
66
+ return YES.member?(response)
67
+ end
68
+
69
+ # Read a saved Readline history file into Readline. The history
70
+ # file will be created if it doesn't already exist.
71
+ # Much of this code follows what's done in ruby-debug.
72
+ def read_history
73
+ unless @histfile
74
+ dirname = ENV['HOME'] || ENV['HOMEPATH'] || File.expand_path('~')
75
+ @histfile = File.join(dirname, @opts[:file_history])
76
+ end
77
+ @histsize ||= (ENV['HISTSIZE'] ? ENV['HISTSIZE'].to_i : @opts[:histsize])
78
+ Readline.completion_proc = @opts[:complete]
79
+ if File.exists?(@histfile)
80
+ lines = IO::readlines(@histfile).last(@histsize).collect do
81
+ |line| line.chomp
82
+ end
83
+ Readline::HISTORY.push(*lines)
84
+ @history_io = File.new(@histfile, "a")
85
+ else
86
+ @history_io = File.new(@histfile, "w")
87
+ end
88
+ @history_io.sync = true
89
+ @history_save = @opts[:history_save]
90
+ end
91
+
92
+ def save_history
93
+ if @histfile
94
+ lines = Readline::HISTORY.to_a
95
+ lines = lines[-@histsize, @histsize] if lines.size > @histsize
96
+ begin
97
+ open(@histfile, 'w') do |file|
98
+ Readline::HISTORY.to_a.last(@histsize).each do |line|
99
+ file.puts line
100
+ end
101
+ end if defined?(@history_save) and @history_save
102
+ rescue
103
+ end
104
+ end
105
+ end
106
+
107
+ def finalize(last_wishes=nil)
108
+ # ?? print gdb-style exit annotation if annotate = 2?
109
+ if Trepan::GNU_readline? && @history_save
110
+ save_history
111
+ end
112
+ super
113
+ end
114
+
115
+ def interactive? ; @input.interactive? end
116
+
117
+ def read_command(prompt='')
118
+ readline(prompt)
119
+ end
120
+
121
+ def readline(prompt='')
122
+ @output.flush
123
+ if @input.line_edit && @input.use_readline
124
+ @input.readline(prompt)
125
+ else
126
+ @output.write(prompt) if prompt and prompt.size > 0
127
+ @input.readline
128
+ end
129
+ end
130
+
131
+ end
132
+
133
+ # Demo
134
+ if __FILE__ == $0
135
+ intf = Trepan::UserInterface.new
136
+ intf.errmsg("Houston, we have a problem here!")
137
+ if ARGV.size > 0
138
+ begin
139
+ line = intf.readline("Type something: ")
140
+ rescue EOFError
141
+ puts "No input, got EOF"
142
+ else
143
+ puts "You typed: #{line}"
144
+ end
145
+ puts "EOF is now: %s" % intf.input.eof?.inspect
146
+ unless intf.input.eof?
147
+ line = intf.confirm("Are you sure", false)
148
+ puts "You typed: #{line}"
149
+ puts "EOF is now: %s" % intf.input.eof?.inspect
150
+ line = intf.confirm("Are you not sure", true)
151
+ puts "You typed: #{line}"
152
+ puts "EOF is now: %s" % intf.input.eof?.inspect
153
+ end
154
+ end
155
+ puts "User interface closed?: #{intf.closed?}"
156
+ intf.close
157
+ STDERR.puts "User interface closed?: #{intf.closed?}"
158
+ end
data/interface.rb ADDED
@@ -0,0 +1,109 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+
4
+ # A base class for a debugger interface.
5
+
6
+ class Trepan
7
+
8
+ unless defined?(NotImplementedMessage)
9
+ NotImplementedMessage = 'This method must be overriden in a subclass'
10
+ end
11
+
12
+ # A debugger interface handles the communication or interaction with between
13
+ # the program and the outside portion which could be
14
+ # - a user,
15
+ # - a front-end that talks to a user, or
16
+ # - another interface in another process or computer
17
+ class Interface
18
+
19
+ attr_accessor :history_io, :history_save, :interactive, :input, :output
20
+
21
+ unless defined?(YES)
22
+ YES = %w(y yes oui si yep ja)
23
+ NO = %w(n no non nope nein)
24
+ YES_OR_NO = YES + NO
25
+ end
26
+
27
+ def initialize(inp=nil, out=nil, opts={})
28
+ @histfile = nil
29
+ @history_io = nil
30
+ @history_save = false
31
+ @histsize = nil
32
+ @input = inp || STDIN
33
+ @interactive = false
34
+ @opts = opts
35
+ @output = out || STDOUT
36
+ end
37
+
38
+ # Closes all input and/or output.
39
+ def close
40
+ @input.close unless !@input || @input.closed?
41
+ @output.close unless !@output || @output.closed?
42
+ end
43
+
44
+ # Called when a dangerous action is about to be done to make sure
45
+ # it's okay. `prompt' is printed; user response is returned.
46
+ def confirm(prompt, default=false)
47
+ raise RuntimeError, Trepan::NotImplementedMessage
48
+ end
49
+
50
+ # Common routine for reporting debugger error messages.
51
+ def errmsg(str, prefix='** ')
52
+ if str.is_a?(Array)
53
+ str.each{|s| errmsg(s)}
54
+ else
55
+ str.split("\n").each do |s|
56
+ msg("%s%s" % [prefix, s])
57
+ end
58
+ end
59
+ end
60
+
61
+ def finalize(last_wishes=nil)
62
+ if @output && !@output.closed?
63
+ msg "%sThat's all, folks..." %
64
+ (defined?(Trepan::PROGRAM) ? "#{Trepan::PROGRAM}: " : '')
65
+ end
66
+ close
67
+ end
68
+
69
+ def input_eof?
70
+ @input.eof?
71
+ end
72
+
73
+ # Return true if interface is interactive.
74
+ def interactive?
75
+ # Default false and making subclasses figure out how to determine
76
+ # interactiveness.
77
+ false
78
+ end
79
+
80
+ # used to write to a debugger that is connected to this
81
+ # server; `str' written will have a newline added to it.
82
+ def msg(message)
83
+ if message.is_a?(Array)
84
+ message.each{|s| msg(s)}
85
+ else
86
+ message = message ? message.to_s + "\n" : ''
87
+ @output.write(message)
88
+ end
89
+ end
90
+
91
+ # used to write to a debugger that is connected to this
92
+ # server; `str' written will not have a newline added to it
93
+ def msg_nocr(msg)
94
+ @output.write(msg)
95
+ end
96
+
97
+ def read_command(prompt='')
98
+ line = readline(prompt)
99
+ # FIXME: Do something with history?
100
+ return line
101
+ end
102
+
103
+ def readline(prompt='')
104
+ @output.flush
105
+ @output.write(prompt) if prompt and prompt.size > 0
106
+ @input.readline
107
+ end
108
+ end
109
+ end
data/io/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /*.rbc
2
+ /*~
3
+
data/io/input.rb ADDED
@@ -0,0 +1,151 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010-2012 Rocky Bernstein <rockyb@rubyforge.net>
3
+
4
+ # Debugger user/command-oriented input possibly attached to IO-style
5
+ # input or GNU Readline.
6
+ #
7
+
8
+ require 'rubygems'; require 'require_relative'
9
+ require_relative '../io'
10
+
11
+ class Trepan
12
+
13
+ # Debugger user/command-oriented input possibly attached to IO-style
14
+ # input or GNU Readline.
15
+ class UserInput < Trepan::InputBase
16
+
17
+ attr_reader :use_readline
18
+
19
+ @@readline_finalized = false
20
+
21
+ def initialize(inp, opts={})
22
+ @opts = DEFAULT_OPTS.merge(opts)
23
+ @input = inp || STDIN
24
+ @eof = false
25
+ @line_edit = @opts[:line_edit]
26
+ @use_readline = @opts[:readline]
27
+ end
28
+
29
+ def closed?; @input.closed? end
30
+ def eof?; @eof end
31
+
32
+ def interactive?
33
+ @input.respond_to?(:isatty) && @input.isatty
34
+ end
35
+ # Read a line of input. EOFError will be raised on EOF.
36
+ def readline(prompt='')
37
+ raise EOFError if eof?
38
+ begin
39
+ if @line_edit && @use_readline
40
+ line = Readline.readline(prompt, true)
41
+ else
42
+ # Prompt should be empty and should have been
43
+ # handled by caller.
44
+ unless prompt.empty?
45
+ raise RuntimeError,
46
+ "Internal error: prompt '#{prompt}' should have been handled by caller" unless prompt.empty?
47
+ end
48
+ line = @input.gets
49
+ end
50
+ rescue Interrupt
51
+ return ''
52
+ rescue EOFError
53
+ rescue => e
54
+ puts $!.backtrace
55
+ puts "Exception caught #{e.inspect}"
56
+ @eof = true
57
+ end
58
+ @eof = !line
59
+ raise EOFError if eof?
60
+ return line
61
+ end
62
+
63
+ class << self
64
+ # Use this to set where to read from.
65
+ #
66
+ # Set opts[:line_edit] if you want this input to interact with
67
+ # GNU-like readline library. By default, we will assume to try
68
+ # using readline.
69
+ def open(inp=nil, opts={})
70
+ inp ||= STDIN
71
+ inp = File.new(inp, 'r') if inp.is_a?(String)
72
+ opts[:line_edit] = @line_edit =
73
+ inp.respond_to?(:isatty) && inp.isatty && Trepan::GNU_readline?
74
+ self.new(inp, opts)
75
+ end
76
+
77
+ def finalize
78
+ if defined?(RbReadline) && !@@readline_finalized
79
+ begin
80
+ RbReadline.rl_cleanup_after_signal()
81
+ rescue
82
+ end
83
+ begin
84
+ RbReadline.rl_deprep_terminal()
85
+ rescue
86
+ end
87
+ @@readline_finalized = true
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ def Trepan::GNU_readline?
95
+ begin
96
+ return @use_readline unless @use_readline.nil?
97
+ %w(rb-readline rb-readline.rb/readline).each do |gem_name|
98
+ @use_readline ||= require gem_name
99
+ break if @use_readline
100
+ end
101
+ if @use_readline
102
+ # Returns current line buffer
103
+ def Readline.line_buffer
104
+ RbReadline.rl_line_buffer
105
+ end
106
+ at_exit { Trepan::UserInput::finalize }
107
+ end
108
+ return true
109
+ rescue LoadError
110
+ return false
111
+ end
112
+ end
113
+
114
+ # Demo
115
+ if __FILE__ == $0
116
+ puts 'Have GNU is: %s' % Trepan::GNU_readline?
117
+ inp = Trepan::UserInput.open(__FILE__, :line_edit => false)
118
+ line = inp.readline
119
+ puts line
120
+ inp.close
121
+ filename = 'input.py'
122
+ begin
123
+ Trepan::UserInput.open(filename)
124
+ rescue
125
+ puts "Can't open #{filename} for reading: #{$!}"
126
+ end
127
+ inp = Trepan::UserInput.open(__FILE__, :line_edit => false)
128
+ while true
129
+ begin
130
+ inp.readline
131
+ rescue EOFError
132
+ break
133
+ end
134
+ end
135
+ begin
136
+ inp.readline
137
+ rescue EOFError
138
+ puts 'EOF handled correctly'
139
+ end
140
+
141
+ if ARGV.size > 0
142
+ inp = Trepan::UserInput.open
143
+ begin
144
+ print "Type some characters: "
145
+ line = inp.readline()
146
+ puts "You typed: %s" % line
147
+ rescue EOFError
148
+ puts 'Got EOF'
149
+ end
150
+ end
151
+ end