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/io/null_output.rb ADDED
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+
4
+ # Nukes output. Used for example in sourcing where you don't want
5
+ # to see output.
6
+ #
7
+
8
+ require 'rubygems'; require 'require_relative'
9
+ require_relative '../io'
10
+
11
+ class Trepan::OutputNull < Trepan::OutputBase
12
+ def initialize(out, opts={})
13
+ @closed = false
14
+ super
15
+ end
16
+
17
+ def close
18
+ @closed = true
19
+ end
20
+
21
+ def closed?
22
+ !!@closed
23
+ end
24
+
25
+ def flush
26
+ end
27
+
28
+ # Use this to set where to write to. output can be a
29
+ # file object or a string. This code raises IOError on error.
30
+ def write(*args)
31
+ end
32
+
33
+ # used to write to a debugger that is connected to this
34
+ # `str' written will have a newline added to it
35
+ #
36
+ def writeline( msg)
37
+ end
38
+ end
39
+
40
+ # Demo it
41
+ if __FILE__ == $0
42
+ output = Trepan::OutputNull.new(nil)
43
+ p output
44
+ output.write("Invisible")
45
+ output.writeline("Invisible")
46
+ end
@@ -0,0 +1,155 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+
4
+ # Simulate I/O using lists of strings.
5
+
6
+ require 'rubygems'; require 'require_relative'
7
+ require_relative '../io'
8
+
9
+ # Simulate I/O using an array of strings. Sort of like StringIO, but
10
+ # even simplier.
11
+ class Trepan::StringArrayInput < Trepan::InputBase
12
+
13
+ def initialize(inp, opts={})
14
+ super
15
+ @closed = false
16
+ end
17
+
18
+ # this close() interface is defined for class compatibility
19
+ def close
20
+ @closed = true
21
+ end
22
+
23
+ def closed?
24
+ @closed
25
+ end
26
+
27
+ def eof?
28
+ @closed || @input.empty?
29
+ end
30
+
31
+ # Nothing to do here. Interface is for compatibility
32
+ def flush ; end
33
+
34
+ # Read a line of input. EOFError will be raised on EOF.
35
+ # Note that we don't support prompting
36
+ def readline
37
+ raise EOFError if eof?
38
+ if @input.empty?
39
+ raise EOFError
40
+ end
41
+ line = @input.shift
42
+ return line
43
+ end
44
+
45
+ class << self
46
+ # Use this to set where to read from.
47
+ def open(inp, opts={})
48
+ if inp.is_a?(Array)
49
+ return self.new(inp)
50
+ else
51
+ raise IOError, "Invalid input type (%s) for %s" % [inp.class, inp]
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ # Simulate I/O using an array of strings. Sort of like StringIO, but
58
+ # even simplier.
59
+ class Trepan::StringArrayOutput < Trepan::OutputBase
60
+
61
+ def initialize(out=[], opts={})
62
+ super
63
+ @closed = false
64
+ end
65
+
66
+ # Nothing to do here. Interface is for compatibility
67
+ def close
68
+ @closed = true
69
+ end
70
+
71
+ def closed?
72
+ @closed
73
+ end
74
+
75
+ def eof?
76
+ @closed || @output.empty?
77
+ end
78
+
79
+ # Nothing to do here. Interface is for compatibility
80
+ def flush ; end
81
+
82
+ # This method the debugger uses to write. In contrast to
83
+ # writeline, no newline is added to the end to `str'.
84
+ #
85
+ def write(msg)
86
+ raise ValueError if @closed
87
+ @output << msg
88
+ end
89
+
90
+ # used to write to a debugger that is connected to this
91
+ # server; Here, we use the null string '' as an indicator of a
92
+ # newline.
93
+ def writeline(msg)
94
+ write(msg)
95
+ write('')
96
+ end
97
+
98
+ class << self
99
+ # Use this to set where to write to. output can be a
100
+ # file object or a string. This code raises IOError on error.
101
+ #
102
+ # If another file was previously open upon calling this open,
103
+ # that will be stacked and will come back into use after
104
+ # a close_write().
105
+ def open(output=[])
106
+ if output.is_a?(Array)
107
+ return self.new(output)
108
+ else
109
+ raise IOError, ("Invalid output type (%s) for %s" %
110
+ [output.class, output])
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ # Demo
117
+ if __FILE__ == $0
118
+ inp = Trepan::StringArrayInput.open(['Now is the time', 'for all good men'])
119
+ line = inp.readline
120
+ p line
121
+ line = inp.readline
122
+ p line
123
+ begin
124
+ line = inp.readline
125
+ rescue EOFError
126
+ puts 'EOF hit on read'
127
+ end
128
+
129
+ out = Trepan::StringArrayOutput.open
130
+ p out.output
131
+ # line = io.readline('Type some more characters: ')
132
+ out.writeline('Hello, world!')
133
+ p out.output
134
+ out.write('Hello');
135
+ p out.output
136
+ out.writeline(', again.');
137
+ p out.output
138
+ # io.open_write(sys.stdout)
139
+ out.flush_after_write = true
140
+ out.write('Last hello')
141
+ puts "Output is closed? #{out.closed?}"
142
+ out.close
143
+ p out.output
144
+ begin
145
+ out.writeline("You won't see me")
146
+ rescue
147
+ end
148
+
149
+ # Closing after already closed is okay
150
+ out.close
151
+ puts "Output is closed? #{out.closed?}"
152
+ puts "Input is closed? #{inp.closed?}"
153
+ inp.close
154
+ puts "Input is closed? #{inp.closed?}"
155
+ end
data/io/tcpclient.rb ADDED
@@ -0,0 +1,129 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ # Debugger Socket Input/Output Interface.
4
+
5
+ require 'socket'
6
+ require 'rubygems'; require 'require_relative'
7
+ require_relative '../io'
8
+ require_relative 'tcpfns'
9
+
10
+ class Trepan
11
+ # Debugger Client Input/Output Socket.
12
+ class TCPDbgClient < Trepan::InOutBase
13
+
14
+ include Trepanning::TCPPacking
15
+
16
+ DEFAULT_INIT_OPTS = {:open => true}
17
+
18
+ CLIENT_SOCKET_OPTS = {
19
+ :host => 'localhost', # Symbolic name
20
+ :port => 1027, # Arbitrary non-privileged port
21
+ }
22
+
23
+ attr_reader :state
24
+
25
+ def initialize(opts={})
26
+ @opts = CLIENT_SOCKET_OPTS.merge(opts)
27
+ @addr = nil
28
+ @buf = ''
29
+ @line_edit = false # Our name for GNU readline capability
30
+ @state = :disconnected
31
+ @inout = nil
32
+ open(@opts) if @opts[:open]
33
+ end
34
+
35
+ # Closes both input and output
36
+ def close
37
+ @state = :closing
38
+ @inout.close if @inout
39
+ @state = :disconnected
40
+ end
41
+
42
+ def disconnected?
43
+ :disconnected == @state
44
+ end
45
+
46
+ def open(opts={})
47
+ @opts = CLIENT_SOCKET_OPTS.merge(opts)
48
+ @host = @opts[:host]
49
+ @port = @opts[:port]
50
+ begin
51
+ @inout = TCPSocket.new(@host, @port)
52
+ @state = :connected
53
+ rescue SystemCallError => e
54
+ raise IOError,
55
+ ('Open client for host %s on port %s gives error: %s' %
56
+ [@host, @port, e])
57
+ end
58
+ end
59
+
60
+ # Read one message unit. It's possible however that
61
+ # more than one message will be set in a receive, so we will
62
+ # have to buffer that for the next read.
63
+ # EOFError will be raised on EOF.
64
+ def read_msg
65
+ if @state == :connected
66
+ if !@buf || @buf.empty?
67
+ @buf = @inout.recv(TCP_MAX_PACKET)
68
+ if @buf.empty?
69
+ @state = :disconnected
70
+ raise EOFError
71
+ end
72
+ end
73
+ @buf, data = unpack_msg(@buf)
74
+ return data
75
+ else
76
+ raise IOError, ("read_msg called in state: %s." % @state.to_s)
77
+ end
78
+ end
79
+
80
+ # This method the debugger uses to write a message unit.
81
+ def write(msg)
82
+ # FIXME: do we have to check the size of msg and split output?
83
+ @inout.write(pack_msg(msg))
84
+ end
85
+
86
+ def writeline(msg)
87
+ write(msg + "\n")
88
+ end
89
+ end
90
+ end
91
+
92
+ # Demo
93
+ if __FILE__ == $0
94
+ client = Trepan::TCPDbgClient.new({'open' => false})
95
+ if ARGV.size > 0
96
+ threads = []
97
+ Thread.new do
98
+ server = TCPServer.new('localhost', 1027)
99
+ session = server.accept
100
+ while 'quit' != (line = session.gets)
101
+ session.puts line
102
+ end
103
+ session.close
104
+ end
105
+
106
+ threads << Thread.new do
107
+ print 'Connecting...'
108
+ client.open()
109
+ puts 'connected.'
110
+ while true
111
+ print "input? "
112
+ line = STDIN.gets
113
+ break if line.chomp == 'quit'
114
+ begin
115
+ line = client.writeline(line)
116
+ puts "Got: #{client.read_msg.chomp}"
117
+ rescue EOFError
118
+ puts "Got EOF"
119
+ break
120
+ rescue Exception => e
121
+ puts "Got #{e}"
122
+ break
123
+ end
124
+ end
125
+ end
126
+ threads.each {|t| t.join }
127
+ end
128
+ client.close
129
+ end
data/io/tcpfns.rb ADDED
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ # Subsidiary routines used to "pack" and "unpack" TCP messages.
4
+
5
+ module Trepanning
6
+ module TCPPacking
7
+
8
+ unless defined?(TCP_MAX_PACKET)
9
+ TCP_MAX_PACKET = 8192 # Largest size for a recv
10
+ LOG_MAX_MSG = Math.log10(TCP_MAX_PACKET).ceil
11
+ end
12
+
13
+ def pack_msg(msg)
14
+ fmt = '%%%dd' % LOG_MAX_MSG # A funny way of writing: '%4d'
15
+ (fmt % msg.size) + msg
16
+ end
17
+
18
+ def unpack_msg(buf)
19
+ length = Integer(buf[0...LOG_MAX_MSG])
20
+ data = buf[LOG_MAX_MSG..LOG_MAX_MSG+length]
21
+ buf = buf[LOG_MAX_MSG+length..-1]
22
+ [buf, data]
23
+ end
24
+ end
25
+ end
26
+
27
+ # Demo
28
+ if __FILE__ == $0
29
+ include Trepanning::TCPPacking
30
+ msg = "Hi there!"
31
+ puts unpack_msg(pack_msg(msg))[1] == msg
32
+ end
33
+
data/io/tcpserver.rb ADDED
@@ -0,0 +1,141 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ # Debugger Server Input/Output interface.
4
+
5
+ require 'socket'
6
+ require 'rubygems'; require 'require_relative'
7
+ require_relative '../app/default' # For host and port
8
+ require_relative '../io'
9
+ require_relative 'tcpfns'
10
+
11
+ class Trepan
12
+ # Debugger Server Input/Output Socket.
13
+ class TCPDbgServer < Trepan::InOutBase
14
+
15
+ include Trepanning::TCPPacking
16
+
17
+ unless defined?(SERVER_SOCKET_OPTS)
18
+ DEFAULT_INIT_OPTS = {:open => true}
19
+
20
+ SERVER_SOCKET_OPTS = {
21
+ :host => Trepan::DEFAULT_SETTINGS[:host],
22
+ :port => Trepan::DEFAULT_SETTINGS[:port], # A non-privileged port
23
+ :timeout => 5, # FIXME: not used
24
+ :reuse => true, # FIXME: not used. Allow port to be resued on close?
25
+ # Python has: 'posix' == os.name
26
+ }
27
+ end
28
+
29
+ attr_reader :state
30
+
31
+ def initialize(opts={})
32
+ @opts = DEFAULT_INIT_OPTS.merge(opts)
33
+ @input = @output = @session = nil
34
+ @buf = '' # Read buffer
35
+ @state = :disconnected
36
+ @port = nil # Current port in use
37
+ @host = nil # current host in use
38
+ @line_edit = false
39
+ open(@opts) if @opts[:open]
40
+ end
41
+
42
+ def connected?
43
+ :connected == @state
44
+ end
45
+
46
+
47
+ # Closes server connection.
48
+ def close
49
+ @state = :closing
50
+ @session.close if @session
51
+ @state = :disconnected
52
+ end
53
+
54
+ def open(opts={})
55
+ @opts = SERVER_SOCKET_OPTS.merge(opts)
56
+ @host = @opts[:host]
57
+ @port = @opts[:port]
58
+ @server = TCPServer.new(@host, @port)
59
+ # @server.setsockopt(Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, 5)
60
+ # # @opts[:timeout])
61
+ @state = :listening
62
+ end
63
+
64
+ # Read one message unit. It's possible however that
65
+ # more than one message will be set in a receive, so we will
66
+ # have to buffer that for the next read.
67
+ # EOFError will be raised on EOF.
68
+ def read_msg
69
+ wait_for_connect unless connected?
70
+ while !@buf || @buf.empty?
71
+ @buf, info = @session.recvfrom(TCP_MAX_PACKET)
72
+ end
73
+ @buf, data = unpack_msg(@buf)
74
+ data
75
+ end
76
+
77
+ def wait_for_connect
78
+ @input = @output = @session = @server.accept
79
+ @state = :connected
80
+ end
81
+
82
+ # This method the debugger uses to write. In contrast to
83
+ # writeline, no newline is added to the end to `str'. Also
84
+ # msg doesn't have to be a string.
85
+ def write(msg)
86
+ wait_for_connect() unless connected?
87
+ # FIXME: do we have to check the size of msg and split output?
88
+ @session.print(pack_msg(msg))
89
+ end
90
+
91
+ def writeline(msg)
92
+ write(msg + "\n")
93
+ end
94
+
95
+ end
96
+ end
97
+
98
+ # Demo
99
+ if __FILE__ == $0
100
+ include Trepanning::TCPPacking
101
+ server = Trepan::TCPDbgServer.new({ :open => false,
102
+ :port => 1027,
103
+ :host => 'localhost'
104
+ })
105
+ if ARGV.size > 0
106
+ puts 'Listening for connection...'
107
+ server.open
108
+ threads = []
109
+ Thread.new do
110
+ while true do
111
+ begin
112
+ line = server.read_msg.chomp
113
+ puts "got #{line}"
114
+ rescue EOFError
115
+ puts 'Got EOF'
116
+ break
117
+ end
118
+ end
119
+ end
120
+ threads << Thread.new do
121
+ t = TCPSocket.new('localhost', 1027)
122
+ while true do
123
+ begin
124
+ print "input? "
125
+ line = STDIN.gets
126
+ break if !line || line.chomp == 'quit'
127
+ t.puts(pack_msg(line))
128
+ rescue EOFError
129
+ puts "Got EOF"
130
+ break
131
+ rescue Exception => e
132
+ puts "Got #{e}"
133
+ break
134
+ end
135
+ end
136
+ t.close
137
+ end
138
+ threads.each {|t| t.join }
139
+ server.close
140
+ end
141
+ end
data/io.rb ADDED
@@ -0,0 +1,148 @@
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # classes to support communication to and from the debugger. This
3
+ # communcation might be to/from another process or another computer.
4
+ # And reading may be from a debugger command script.
5
+ #
6
+ # For example, we'd like to support Sockets, and serial lines and file
7
+ # reading, as well a readline-type input. Encryption and Authentication
8
+ # methods might decorate some of the communication channels.
9
+ #
10
+ # Some ideas originiated as part of Matt Fleming's 2006 Google Summer of
11
+ # Code project.
12
+
13
+ class Trepan
14
+
15
+ NotImplementedMessage = 'This method must be overriden in a subclass' unless
16
+ defined?(NotImplementedMessage)
17
+
18
+ class InputBase
19
+ attr_reader :input
20
+ attr_reader :line_edit
21
+
22
+ DEFAULT_OPTS = {
23
+ :line_edit => false,
24
+ } unless defined?(DEFAULT_OPTS)
25
+
26
+ def initialize(inp, opts={})
27
+ @opts = DEFAULT_OPTS.merge(opts)
28
+ @input = inp
29
+ @line_edit = opts[:line_edit]
30
+ end
31
+
32
+ def close
33
+ @input.close unless @input.closed?
34
+ end
35
+
36
+ def eof?
37
+ begin
38
+ @input.eof?
39
+ rescue IOError
40
+ true
41
+ end
42
+ end
43
+
44
+ # Read a line of input. EOFError will be raised on EOF.
45
+ #
46
+ # Note that we don't support prompting first. Instead, arrange
47
+ # to call Trepan::Output.write() first with the prompt. If
48
+ # `use_raw' is set raw_input() will be used in that is supported
49
+ # by the specific input input. If this option is left None as is
50
+ # normally expected the value from the class initialization is
51
+ # used.
52
+ def readline
53
+ @input.readline
54
+ end
55
+ end
56
+
57
+ # This is an abstract class that specifies debugger output.
58
+ class OutputBase
59
+ attr_accessor :flush_after_write
60
+ attr_reader :output
61
+ def initialize(out, opts={})
62
+ @output = out
63
+ @flush_after_write = false
64
+ @eof = false
65
+ end
66
+
67
+ def close
68
+ @output.close if @output
69
+ @eof = true
70
+ end
71
+
72
+ def eof?
73
+ @eof
74
+ end
75
+
76
+ def flush
77
+ @output.flush
78
+ end
79
+
80
+ # Use this to set where to write to. output can be a
81
+ # file object or a string. This code raises IOError on error.
82
+ def write(*args)
83
+ @output.print(*args)
84
+ end
85
+
86
+ # used to write to a debugger that is connected to this
87
+ # `str' written will have a newline added to it
88
+ #
89
+ def writeline(msg)
90
+ @output.write("%s\n" % msg)
91
+ end
92
+ end
93
+
94
+ # This is an abstract class that specifies debugger input output when
95
+ # handled by the same channel, e.g. a socket or tty.
96
+ #
97
+ class InOutBase
98
+
99
+ def initialize(inout, opts={})
100
+ @opts = DEFAULT_OPTS.merge(opts)
101
+ @inout = inout
102
+ end
103
+
104
+ def close
105
+ @inout.close() if @inout
106
+ end
107
+
108
+ def eof?
109
+ begin
110
+ @input.eof?
111
+ rescue IOError
112
+ true
113
+ end
114
+ end
115
+
116
+ def flush
117
+ @inout.flush
118
+ end
119
+
120
+ # Read a line of input. EOFError will be raised on EOF.
121
+ #
122
+ # Note that we don't support prompting first. Instead, arrange to
123
+ # call DebuggerOutput.write() first with the prompt. If `use_raw'
124
+ # is set raw_input() will be used in that is supported by the
125
+ # specific input input. If this option is left nil as is normally
126
+ # expected the value from the class initialization is used.
127
+ def readline(use_raw=nil)
128
+ @input.readline
129
+ end
130
+
131
+ # Use this to set where to write to. output can be a
132
+ # file object or a string. This code raises IOError on error.
133
+ #
134
+ # Use this to set where to write to. output can be a
135
+ # file object or a string. This code raises IOError on error.
136
+ def write(*args)
137
+ @inout.write(*args)
138
+ end
139
+
140
+ # used to write to a debugger that is connected to this
141
+ # server; `str' written will have a newline added to it
142
+ def writeline( msg)
143
+ @inout.write("%s\n" % msg)
144
+ end
145
+ end
146
+
147
+ end
148
+
data/lib/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /*.rbc
2
+ /*~