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/app/rbx-llvm.rb ADDED
@@ -0,0 +1,163 @@
1
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # A CodeRay Scanner for Rubinius' LLVM.
3
+ # FIXME: add unit test.
4
+ require 'rubygems'
5
+ require 'coderay'
6
+ module CodeRay
7
+ module Scanners
8
+
9
+ class LLVM < Scanner
10
+
11
+ register_for :llvm
12
+ file_extension 'llvm'
13
+
14
+ def string_parse(tokens)
15
+ if match = scan(/^"[^"]*"/)
16
+ string = match.dup
17
+ while "\\" == match[-2..-2]
18
+ match = scan(/^.*"/)
19
+ break unless match
20
+ string << match
21
+ end
22
+ tokens << [string, :string]
23
+ true
24
+ else
25
+ false
26
+ end
27
+ end
28
+
29
+ def space_parse(tokens)
30
+ if match = scan(/^[ \t]*/)
31
+ tokens << [match, :space] if match
32
+ end
33
+ end
34
+
35
+ def scan_tokens(tokens, options)
36
+
37
+ state = :initial
38
+ number_expected = true
39
+
40
+ until eos?
41
+
42
+ kind = nil
43
+ match = nil
44
+
45
+ case state
46
+
47
+ when :initial
48
+ if match = scan(/^\s*/)
49
+ tokens << [match, :space] unless match.empty?
50
+ end
51
+ state =
52
+ if match = scan(/^$/)
53
+ :initial
54
+ else
55
+ :expect_label
56
+ end
57
+
58
+ when :expect_label
59
+ state =
60
+ if match = scan(/\d+:/x)
61
+ tokens << [match, :label]
62
+ :expect_opcode
63
+ else
64
+ match = scan(/^.*$/)
65
+ tokens << [match, :error]
66
+ :initial
67
+ end
68
+
69
+ when :expect_opcode
70
+ state =
71
+ if scan(/(\s+)(\S+)/)
72
+ tokens << [@match[1], :space]
73
+ opcode = @match[2]
74
+ tokens << [opcode, :reserved]
75
+ if %w(push_literal create_block set_literal).member?(opcode)
76
+ :expect_literal
77
+ else
78
+ :expect_operand
79
+ end
80
+ else
81
+ match = scan(/^(.*)$/)
82
+ tokens << [match, :error]
83
+ :initial
84
+ end
85
+
86
+ when :expect_literal
87
+ space_parse(tokens)
88
+ if match = scan(/^#<.+>/)
89
+ tokens << [match, :content]
90
+ elsif scan(/^(\d+)/)
91
+ tokens << [@match[0], :integer]
92
+ elsif scan(/^([:][^: ,\n]+)/)
93
+ tokens << [@match[0], :symbol]
94
+ elsif string_parse(tokens)
95
+ #
96
+ elsif match = scan(/nil|true|false/)
97
+ tokens << [match, :pre_constant]
98
+ elsif match = scan(/\/.*\//)
99
+ tokens << [match, :entity]
100
+ else
101
+ match = scan(/^.*$/)
102
+ tokens << [match, :error] unless match.empty?
103
+ end
104
+ state = :expect_opt_comment
105
+
106
+ when :expect_operand
107
+ space_parse(tokens)
108
+ state =
109
+ if scan(/^(\d+)/)
110
+ tokens << [@match[0], :integer]
111
+ :expect_another_operand
112
+ elsif scan(/^([:][^: ,\n]+)/)
113
+ tokens << [@match[0], :symbol]
114
+ :expect_another_operand
115
+ elsif string_parse(tokens)
116
+ :expect_another_operand
117
+ else
118
+ :expect_opt_comment
119
+ end
120
+
121
+ when :expect_another_operand
122
+ state =
123
+ if match = scan(/^,/)
124
+ tokens << [@match[0], :operator]
125
+ :expect_operand
126
+ else
127
+ :expect_opt_comment
128
+ end
129
+ when :expect_opt_comment
130
+ space_parse(tokens)
131
+ if match = scan(/^#.*$/)
132
+ tokens << [match, :comment]
133
+ else
134
+ match = scan(/^.*$/)
135
+ tokens << [match, :error] unless match.empty?
136
+ end
137
+ state = :initial
138
+ end
139
+ end
140
+ tokens
141
+ end
142
+ end
143
+ end
144
+ end
145
+ if __FILE__ == $0
146
+ require 'term/ansicolor'
147
+ ruby_scanner = CodeRay.scanner :llvm
148
+ string='
149
+ 0003: push_literal #<Rubinius::CompiledMethod gcd file=/x>
150
+ 0028: create_block #<Rubinius::CompiledMethod __block__ file=/y>
151
+ 0007: send_stack :method_visibility, 0
152
+ 0046: push_literal "The GCD of %d and %d is %d"
153
+ 0000: passed_arg 1 # line: 679
154
+ 0002: goto_if_true 8
155
+ 0004: push_false
156
+ 0080: push_literal "\n 0003: push_literal #<Rubinius::CompiledMethod gcd file=/x>\n 0028: create_block #<Rubinius::CompiledMethod __block__ file=/y>\n 0007: send_stack :method_visibility, 0\n 0046: push_literal \" # line: 147
157
+ '
158
+ llvm_scanner = CodeRay.scanner :llvm
159
+ tokens = llvm_scanner.tokenize(string)
160
+ p tokens
161
+ llvm_highlighter = CodeRay::Duo[:llvm, :term]
162
+ puts llvm_highlighter.encode(string)
163
+ end
data/app/run.rb ADDED
@@ -0,0 +1,92 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ require 'rbconfig'
4
+ require 'rubygems'; require 'require_relative'
5
+ module Trepanning
6
+
7
+ module_function # All functions below are easily publically accessible
8
+
9
+ # Given a Ruby interpreter and program we are to debug, debug it.
10
+ # The caller must ensure that ARGV is set up to remove any debugger
11
+ # arguments or things that the debugged program isn't supposed to
12
+ # see. FIXME: Should we make ARGV an explicit parameter?
13
+ def debug_program(dbgr, ruby_path, program_to_debug, start_opts={})
14
+
15
+ # Make sure Ruby script syntax checks okay.
16
+ # Otherwise we get a load message that looks like trepanning has
17
+ # a problem.
18
+ output = `#{ruby_path} -c #{program_to_debug.inspect} 2>&1`
19
+ if $?.exitstatus != 0 and RUBY_PLATFORM !~ /mswin/
20
+ puts output
21
+ exit $?.exitstatus
22
+ end
23
+ # print "\032\032starting\n" if Trepan.annotate and Trepan.annotate > 2
24
+
25
+ ## FIXME: put in fn.
26
+ m = self.method(:debug_program).executable
27
+ dbgr.processor.ignore_methods[m]='step'
28
+
29
+ # m = Kernel.method(:load).executable
30
+ # dbgr.processor.ignore_methods[m]='step'
31
+
32
+ # Any frame from us or below should be hidden by default.
33
+ hide_level = Rubinius::VM.backtrace(0, true).size+1
34
+
35
+ old_dollar_0 = $0
36
+
37
+ # Without the dance below to set $0, setting it to a signifcantly
38
+ # longer value will truncate it in some OS's. See
39
+ # http://www.ruby-forum.com/topic/187083
40
+ $progname = program_to_debug
41
+ alias $0 $progname
42
+ ## dollar_0_tracker = lambda {|val| $program_name = val}
43
+ ## trace_var(:$0, dollar_0_tracker)
44
+
45
+ ## FIXME: we gets lots of crap before we get to the real stuff.
46
+ start_opts = {
47
+ :skip_loader => true
48
+ }.merge(start_opts)
49
+ dbgr.start(start_opts)
50
+ begin
51
+ Kernel::load program_to_debug
52
+ rescue Interrupt
53
+ end
54
+
55
+ # The dance we have to undo to restore $0 and undo the mess created
56
+ # above.
57
+ $0 = old_dollar_0
58
+ ## untrace_var(:$0, dollar_0_tracker)
59
+ end
60
+
61
+ # Do a shell-like path lookup for prog_script and return the results.
62
+ # If we can't find anything return prog_script.
63
+ def whence_file(prog_script)
64
+ if prog_script.start_with?(File::SEPARATOR) || prog_script.start_with?('.')
65
+ # Don't search since this name has path is explicitly absolute or
66
+ # relative.
67
+ return prog_script
68
+ end
69
+ for dirname in ENV['PATH'].split(File::PATH_SEPARATOR) do
70
+ prog_script_try = File.join(dirname, prog_script)
71
+ return prog_script_try if File.readable?(prog_script_try)
72
+ end
73
+ # Failure
74
+ return prog_script
75
+ end
76
+ end
77
+
78
+ # Path name of Ruby interpreter we were invoked with. Is part of
79
+ # 1.9 but not necessarily 1.8.
80
+ def RbConfig.ruby
81
+ File.join(RbConfig::CONFIG['bindir'],
82
+ RbConfig::CONFIG['RUBY_INSTALL_NAME'] +
83
+ RbConfig::CONFIG['EXEEXT'])
84
+ end unless defined? RbConfig.ruby
85
+
86
+ if __FILE__ == $0
87
+ # Demo it.
88
+ include Trepanning
89
+ puts whence_file('irb')
90
+ puts whence_file('probably-does-not-exist')
91
+ puts RbConfig.ruby
92
+ end
data/app/util.rb ADDED
@@ -0,0 +1,99 @@
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+
3
+ class Trepan
4
+ module Util
5
+
6
+ module_function
7
+ def safe_repr(str, max, elipsis='... ')
8
+ if str.is_a?(String) && max > 0 && str.size > max && !str.index("\n")
9
+ "%s%s%s" % [ str[0...max/2], elipsis, str[str.size-max/2..str.size]]
10
+ else
11
+ str
12
+ end
13
+ end
14
+
15
+ # name is String and list is an Array of String.
16
+ # If name is a unique leading prefix of one of the entries of list,
17
+ # then return that. Otherwise return name.
18
+ def uniq_abbrev(list, name)
19
+ candidates = list.select do |try_name|
20
+ try_name.start_with?(name)
21
+ end
22
+ candidates.size == 1 ? candidates.first : name
23
+ end
24
+
25
+ # extract the "expression" part of a line of source code.
26
+ #
27
+ def extract_expression(text)
28
+ if text =~ /^\s*(?:if|elsif|unless)\s+/
29
+ text.gsub!(/^\s*(?:if|elsif|unless)\s+/,'')
30
+ text.gsub!(/\s+then\s*$/, '')
31
+ elsif text =~ /^\s*(?:until|while)\s+/
32
+ text.gsub!(/^\s*(?:until|while)\s+/,'')
33
+ text.gsub!(/\s+do\s*$/, '')
34
+ elsif text =~ /^\s*return\s+/
35
+ # EXPRESION in: return EXPRESSION
36
+ text.gsub!(/^\s*return\s+/,'')
37
+ elsif text =~ /^\s*case\s+/
38
+ # EXPRESSION in: case EXPESSION
39
+ text.gsub!(/^\s*case\s*/,'')
40
+ elsif text =~ /^\s*def\s*.*\(.+\)/
41
+ text.gsub!(/^\s*def\s*.*\((.*)\)/,'[\1]')
42
+ elsif text =~ /^\s*[A-Za-z_][A-Za-z0-9_\[\]]*\s*=[^=>]/
43
+ # RHS of an assignment statement.
44
+ text.gsub!(/^\s*[A-Za-z_][A-Za-z0-9_\[\]]*\s*=/,'')
45
+ end
46
+ return text
47
+ end
48
+
49
+ # Find user portion of script skipping over Rubinius code loading.
50
+ # Unless hidestack is off, we don't show parts of the frame below this.
51
+ def find_main_script(locs)
52
+ candidate = nil
53
+ (locs.size-1).downto(0) do |i|
54
+ loc = locs[i]
55
+ if 'Object#' == loc.describe_receiver &&
56
+ :__script__ == loc.name
57
+ if loc.method.active_path =~ /\/trepanx$/ ||
58
+ loc.method.active_path == 'kernel/loader.rb'
59
+ # Might have been run from standalone trepanx.
60
+ candidate = i
61
+ else
62
+ return locs.size - i
63
+ end
64
+ end
65
+ end
66
+ candidate ? locs.size - candidate - 1 : nil
67
+ end
68
+
69
+ # Suppress warnings. The main one we encounter is "already initialized
70
+ # constant" because perhaps another version readline has done that already.
71
+ def suppress_warnings
72
+ original_verbosity = $VERBOSE
73
+ $VERBOSE = nil
74
+ result = yield
75
+ $VERBOSE = original_verbosity
76
+ return result
77
+ end
78
+ end
79
+ end
80
+
81
+ if __FILE__ == $0
82
+ include Trepan::Util
83
+ string = 'The time has come to talk of many things.'
84
+ puts safe_repr(string, 50)
85
+ puts safe_repr(string, 17)
86
+ puts safe_repr(string.inspect, 17)
87
+ puts safe_repr(string.inspect, 17, '')
88
+ locs = Rubinius::VM.backtrace(0)
89
+ locs.each_with_index do |l, i|
90
+ puts "#{i}: #{l.describe}"
91
+ end
92
+ ## puts "main script in above is #{locs.size() - 1 - find_main_script(locs)}"
93
+
94
+ list = %w(disassemble disable distance up)
95
+ p list
96
+ %w(dis disa u upper foo).each do |name|
97
+ puts "uniq_abbrev of #{name} is #{uniq_abbrev(list, name)}"
98
+ end
99
+ end
data/app/validate.rb ADDED
@@ -0,0 +1,30 @@
1
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
+
3
+ class Trepan
4
+ module Validate
5
+ def line_or_ip(arg_str)
6
+ arg=arg_str.dup
7
+ is_ip =
8
+ if '@' == arg[0..0]
9
+ arg[0] = ''
10
+ true
11
+ else
12
+ false
13
+ end
14
+ line_or_ip = Integer(arg) rescue nil
15
+ if is_ip
16
+ return line_or_ip, nil
17
+ else
18
+ return nil, line_or_ip
19
+ end
20
+ end
21
+ module_function :line_or_ip
22
+ end
23
+ end
24
+
25
+ if __FILE__ == $0
26
+ include Trepan::Validate
27
+ %w(@1 oink 1 12 -12).each do |arg|
28
+ puts "line_or_ip(#{arg})=#{line_or_ip(arg).inspect}"
29
+ end
30
+ end
data/bin/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /*~
2
+ /*.rbc
data/bin/trepanx ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
3
+ # Invoke debugger from the command line.
4
+ require 'rubygems'; require 'require_relative'
5
+ require 'rbconfig' # For RbConfig.ruby
6
+ require_relative '../app/run'
7
+ require_relative '../app/options'
8
+ require_relative '../app/client'
9
+ require_relative '../lib/trepanning'
10
+
11
+ # FIXME: the figure out how to run via gem installation.
12
+ if File.basename(__FILE__) == File.basename($0)
13
+ include Trepanning
14
+
15
+ # One way to get local variables is to create a block which is run
16
+ # once.
17
+ #
18
+ # Note however that since there are constants below, we can't
19
+ # wrap all of this in a procedure as that would be defining
20
+ # constants dynamically.
21
+ 1.times do
22
+ trepan_path = program_to_debug = nil
23
+
24
+ # options = DEFAULT_CMDLINE_SETTINGS.merge({}) seems to change up
25
+ # DEFAULT_CMDLINE_SETTINGS when options[:key] is changed. The
26
+ # below is the simplest thing I can come up with so far.
27
+ options = Trepan.copy_default_options
28
+ opts = Trepan.setup_options(options)
29
+ Trepan::ARGV = ARGV.clone
30
+ rest = opts.parse! ARGV
31
+
32
+ trepan_path = File.expand_path($0)
33
+ if RUBY_PLATFORM =~ /mswin/
34
+ trepan_path += '.cmd' unless trepan_path =~ /\.cmd$/i
35
+ end
36
+
37
+ # FIXME: do we need to test defined?
38
+ # FIXME: Should (some of) these be instance variables?
39
+ Trepan::TREPAN_PATH = trepan_path
40
+
41
+ if ARGV.empty?
42
+ if options[:version] || options[:help]
43
+ exit 100
44
+ elsif options[:client]
45
+ start_client(options)
46
+ exit
47
+ else
48
+ STDERR.puts 'Sorry - for now you must specify a Ruby script to debug or use the --client option.'
49
+ exit(1)
50
+ end
51
+ end
52
+
53
+ program_to_debug = (Trepan::PROG_UNRESOLVED_SCRIPT = ARGV.shift).dup
54
+ program_to_debug = whence_file(Trepan::PROG_UNRESOLVED_SCRIPT) unless
55
+ File.exist?(Trepan::PROG_UNRESOLVED_SCRIPT)
56
+ Trepan::PROG_SCRIPT = program_to_debug
57
+
58
+ opts = {}
59
+ %w(cmdfiles highlight initial_dir host nx port readline server traceprint
60
+ ).each do |opt|
61
+ opts[opt.to_sym] = options[opt.to_sym]
62
+ end
63
+
64
+ # Set global so others may use this debugger.
65
+ $trepan = Trepan.new(opts)
66
+ debug_program($trepan, RbConfig.ruby,
67
+ File.expand_path(program_to_debug))
68
+ end
69
+ end
data/data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /*~
2
+ /*.rbc
data/data/irbrc ADDED
@@ -0,0 +1,41 @@
1
+ # -*- Ruby -*-
2
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+ # We use this as the default startup file for irb inside trepan
4
+ # Down the line we will have a way for folks to add/override this
5
+ # with their own file.
6
+ IRB.conf[:PROMPT_MODE] = :SIMPLE
7
+ IRB.conf[:PROMPT][:SIMPLE] =
8
+ {:PROMPT_C=>"trepan ?> ",
9
+ :PROMPT_I=>"trepan >> ",
10
+ :PROMPT_N=>"trepan >> ",
11
+ :PROMPT_S=>nil,
12
+ :RETURN=>"=> %s\n"}
13
+
14
+ # Using dbgr to issue a debugger statement inside irb:
15
+ # dbgr %w(info program)
16
+ # dbgr 'info program' # also works
17
+ # But...
18
+ # dbgr info program # wrong!
19
+ #
20
+ puts "You are in a trepan session. You should have access to program scope."
21
+ puts "'dbgr', 'step', 'ne', 'q', 'cont' commands have been added."
22
+
23
+ if defined?($trepan) && $trepan
24
+ puts 'You should have access to debugger state via global variable $trepan'
25
+ end
26
+ if defined?($trepan_frame) && $trepan_frame
27
+ puts 'You should have access to the program frame via global variable $trepan_frame'
28
+ end
29
+ if defined?($trepan_cmdproc) && $trepan_cmdproc
30
+ puts 'You should have access to the command processor via global variable $trepan_cmdproc'
31
+ end
32
+
33
+ # Monkeypatch to save the current IRB statement to be run.
34
+ class IRB::Context
35
+ alias_method :_trepan_original_evaluate, :evaluate
36
+ def evaluate(line, line_no)
37
+ $trepan_irb_statements = line
38
+ _trepan_original_evaluate(line, line_no)
39
+ end
40
+ end
41
+
@@ -0,0 +1,2 @@
1
+ /*.rbc
2
+ /*~
@@ -0,0 +1,84 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+
4
+ # Interface for client (i.e. user to communication-device) interaction.
5
+ # The debugged program is at the other end of the communcation.
6
+
7
+ require 'rubygems'; require 'require_relative'
8
+ require_relative 'user'
9
+ require_relative '../io/tcpclient'
10
+ require_relative 'comcodes'
11
+
12
+ # Mfifoclient = import_relative('fifoclient', '..io', 'pydbgr')
13
+
14
+ # Interface for a user which is attached to a debugged process via
15
+ # some sort of communication medium (e.g. socket, tty, FIFOs). This
16
+ # could be on the same computer in a different process or on a remote
17
+ # computer.
18
+ class Trepan::ClientInterface < Trepan::Interface
19
+
20
+ DEFAULT_INIT_CONNECTION_OPTS = {
21
+ :open => true,
22
+ :io => :tcp
23
+ }
24
+
25
+ def initialize(inp=nil, out=nil, inout=nil, user_opts={},
26
+ connection_opts={})
27
+
28
+ @connection_opts = DEFAULT_INIT_CONNECTION_OPTS.merge(connection_opts)
29
+
30
+ @user = Trepan::UserInterface.new(inp, out, user_opts)
31
+
32
+ @inout =
33
+ if inout
34
+ inout
35
+ else
36
+ # @server_type = @connection_opts[:io]
37
+ # if 'FIFO' == self.server_type
38
+ # Mfifoclient.FIFOClient(opts=@connection_opts)
39
+ # elsif :tcp == self.server_type
40
+ Trepan::TCPDbgClient.new(@connection_opts)
41
+ # else
42
+ # errmsg("Expecting server type TCP or FIFO. Got: %s." %
43
+ # self.server_type)
44
+ # return
45
+ # end
46
+ end
47
+ end
48
+
49
+ def closed?
50
+ @inout.closed?
51
+ end
52
+
53
+ def confirm(prompt, default)
54
+ @user.confirm(prompt, default)
55
+ end
56
+
57
+ def read_command(prompt='')
58
+ @user.read_command(prompt)
59
+ end
60
+
61
+ # Send a message back to the server (in contrast to the local user
62
+ # output channel).
63
+ def read_remote
64
+ coded_line = nil
65
+ until coded_line
66
+ coded_line = @inout.read_msg
67
+ end
68
+ control = coded_line[0..0]
69
+ remote_line = coded_line[1..-1]
70
+ [control, remote_line]
71
+ end
72
+
73
+ # Send a message back to the server (in contrast to the local user
74
+ # output channel).
75
+ def write_remote(code, msg)
76
+ # FIXME change into write_xxx
77
+ @inout.writeline(code + msg)
78
+ end
79
+ end
80
+
81
+ # Demo
82
+ if __FILE__ == $0
83
+ intf = Trepan::ClientInterface.new
84
+ end
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
+
4
+ # Communication status codes
5
+ module Trepanning
6
+ # Most of these go from debugged process to front-end
7
+ # client interface. COMMAND goes the other way.
8
+ module RemoteCommunication
9
+ unless defined?(PRINT)
10
+ PRINT = '.'
11
+ COMMAND = 'C'
12
+ CONFIRM_TRUE = 'Y'
13
+ CONFIRM_FALSE = 'N'
14
+ CONFIRM_REPLY = '?'
15
+ QUIT = 'q'
16
+ PROMPT = 'p'
17
+ RESTART = 'r'
18
+ end
19
+ end
20
+ end