rb8-trepanning 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGES +34 -0
  3. data/ChangeLog +875 -0
  4. data/README.textile +59 -0
  5. data/Rakefile +215 -0
  6. data/app/.gitignore +1 -0
  7. data/app/cmd_parse.kpeg +241 -0
  8. data/app/cmd_parse.rb +212 -0
  9. data/app/cmd_parser.rb +1948 -0
  10. data/app/complete.rb +79 -0
  11. data/app/default.rb +90 -0
  12. data/app/display.rb +148 -0
  13. data/app/eventbuffer.rb +147 -0
  14. data/app/frame.rb +166 -0
  15. data/app/irb.rb +114 -0
  16. data/app/options.rb +200 -0
  17. data/app/run.rb +74 -0
  18. data/app/util.rb +65 -0
  19. data/bin/.gitignore +1 -0
  20. data/bin/trepan8 +115 -0
  21. data/data/.gitignore +1 -0
  22. data/data/irbrc +41 -0
  23. data/interface/.gitignore +1 -0
  24. data/interface/base_intf.rb +109 -0
  25. data/interface/client.rb +82 -0
  26. data/interface/comcodes.rb +20 -0
  27. data/interface/script.rb +110 -0
  28. data/interface/server.rb +147 -0
  29. data/interface/user.rb +165 -0
  30. data/io/base_io.rb +148 -0
  31. data/io/input.rb +158 -0
  32. data/io/null_output.rb +46 -0
  33. data/io/string_array.rb +156 -0
  34. data/io/tcpclient.rb +129 -0
  35. data/io/tcpfns.rb +33 -0
  36. data/io/tcpserver.rb +141 -0
  37. data/lib/debugger.rb +8 -0
  38. data/lib/trepanning.rb +283 -0
  39. data/processor/.gitignore +1 -0
  40. data/processor/command-ruby-debug/breakpoints.rb +155 -0
  41. data/processor/command-ruby-debug/catchpoint.rb +55 -0
  42. data/processor/command-ruby-debug/condition.rb +49 -0
  43. data/processor/command-ruby-debug/control.rb +31 -0
  44. data/processor/command-ruby-debug/display.rb +120 -0
  45. data/processor/command-ruby-debug/enable.rb +202 -0
  46. data/processor/command-ruby-debug/frame.rb +199 -0
  47. data/processor/command-ruby-debug/help.rb +63 -0
  48. data/processor/command-ruby-debug/info.rb +359 -0
  49. data/processor/command-ruby-debug/method.rb +84 -0
  50. data/processor/command-ruby-debug/reload.rb +40 -0
  51. data/processor/command-ruby-debug/save.rb +90 -0
  52. data/processor/command-ruby-debug/set.rb +237 -0
  53. data/processor/command-ruby-debug/show.rb +251 -0
  54. data/processor/command-ruby-debug/source.rb +36 -0
  55. data/processor/command-ruby-debug/threads.rb +189 -0
  56. data/processor/command-ruby-debug/trace.rb +57 -0
  57. data/processor/command-ruby-debug/variables.rb +199 -0
  58. data/processor/command.rb +270 -0
  59. data/processor/command/.gitignore +1 -0
  60. data/processor/command/alias.rb +54 -0
  61. data/processor/command/backtrace.rb +123 -0
  62. data/processor/command/base/cmd.rb +177 -0
  63. data/processor/command/base/subcmd.rb +230 -0
  64. data/processor/command/base/submgr.rb +188 -0
  65. data/processor/command/base/subsubcmd.rb +128 -0
  66. data/processor/command/base/subsubmgr.rb +199 -0
  67. data/processor/command/break.rb +114 -0
  68. data/processor/command/catch.rb +71 -0
  69. data/processor/command/complete.rb +39 -0
  70. data/processor/command/continue.rb +57 -0
  71. data/processor/command/directory.rb +50 -0
  72. data/processor/command/disable.rb +85 -0
  73. data/processor/command/display.rb +78 -0
  74. data/processor/command/down.rb +54 -0
  75. data/processor/command/edit.rb +79 -0
  76. data/processor/command/enable.rb +48 -0
  77. data/processor/command/eval.rb +90 -0
  78. data/processor/command/exit.rb +66 -0
  79. data/processor/command/finish.rb +59 -0
  80. data/processor/command/frame.rb +97 -0
  81. data/processor/command/help.rb +230 -0
  82. data/processor/command/help/.gitignore +1 -0
  83. data/processor/command/help/README +10 -0
  84. data/processor/command/help/command.txt +58 -0
  85. data/processor/command/help/examples.txt +16 -0
  86. data/processor/command/help/filename.txt +40 -0
  87. data/processor/command/help/location.txt +37 -0
  88. data/processor/command/help/suffixes.txt +17 -0
  89. data/processor/command/info.rb +28 -0
  90. data/processor/command/info_subcmd/.gitignore +1 -0
  91. data/processor/command/info_subcmd/args.rb +39 -0
  92. data/processor/command/info_subcmd/breakpoints.rb +80 -0
  93. data/processor/command/info_subcmd/catch.rb +36 -0
  94. data/processor/command/info_subcmd/files.rb +39 -0
  95. data/processor/command/info_subcmd/globals.rb +64 -0
  96. data/processor/command/info_subcmd/line.rb +30 -0
  97. data/processor/command/info_subcmd/locals.rb +69 -0
  98. data/processor/command/info_subcmd/macro.rb +62 -0
  99. data/processor/command/info_subcmd/program.rb +51 -0
  100. data/processor/command/info_subcmd/ruby.rb +57 -0
  101. data/processor/command/info_subcmd/source.rb +74 -0
  102. data/processor/command/info_subcmd/stack.rb +25 -0
  103. data/processor/command/info_subcmd/threads.rb +75 -0
  104. data/processor/command/kill.rb +78 -0
  105. data/processor/command/list.rb +117 -0
  106. data/processor/command/macro.rb +68 -0
  107. data/processor/command/next.rb +79 -0
  108. data/processor/command/parsetree.rb +56 -0
  109. data/processor/command/pp.rb +40 -0
  110. data/processor/command/pr.rb +37 -0
  111. data/processor/command/ps.rb +40 -0
  112. data/processor/command/restart.rb +86 -0
  113. data/processor/command/save.rb +58 -0
  114. data/processor/command/set.rb +47 -0
  115. data/processor/command/set_subcmd/.gitignore +1 -0
  116. data/processor/command/set_subcmd/abbrev.rb +25 -0
  117. data/processor/command/set_subcmd/auto.rb +27 -0
  118. data/processor/command/set_subcmd/auto_subcmd/.gitignore +1 -0
  119. data/processor/command/set_subcmd/auto_subcmd/eval.rb +53 -0
  120. data/processor/command/set_subcmd/auto_subcmd/irb.rb +33 -0
  121. data/processor/command/set_subcmd/auto_subcmd/list.rb +33 -0
  122. data/processor/command/set_subcmd/basename.rb +25 -0
  123. data/processor/command/set_subcmd/callstyle.rb +46 -0
  124. data/processor/command/set_subcmd/confirm.rb +24 -0
  125. data/processor/command/set_subcmd/debug.rb +47 -0
  126. data/processor/command/set_subcmd/different.rb +61 -0
  127. data/processor/command/set_subcmd/highlight.rb +43 -0
  128. data/processor/command/set_subcmd/max.rb +26 -0
  129. data/processor/command/set_subcmd/max_subcmd/list.rb +49 -0
  130. data/processor/command/set_subcmd/max_subcmd/stack.rb +50 -0
  131. data/processor/command/set_subcmd/max_subcmd/string.rb +76 -0
  132. data/processor/command/set_subcmd/max_subcmd/width.rb +49 -0
  133. data/processor/command/set_subcmd/reload.rb +42 -0
  134. data/processor/command/set_subcmd/timer.rb +58 -0
  135. data/processor/command/set_subcmd/trace.rb +37 -0
  136. data/processor/command/set_subcmd/trace_subcmd/buffer.rb +42 -0
  137. data/processor/command/set_subcmd/trace_subcmd/print.rb +41 -0
  138. data/processor/command/shell.rb +139 -0
  139. data/processor/command/show.rb +39 -0
  140. data/processor/command/show_subcmd/.gitignore +1 -0
  141. data/processor/command/show_subcmd/abbrev.rb +20 -0
  142. data/processor/command/show_subcmd/alias.rb +46 -0
  143. data/processor/command/show_subcmd/args.rb +34 -0
  144. data/processor/command/show_subcmd/auto.rb +28 -0
  145. data/processor/command/show_subcmd/auto_subcmd/eval.rb +27 -0
  146. data/processor/command/show_subcmd/auto_subcmd/irb.rb +23 -0
  147. data/processor/command/show_subcmd/auto_subcmd/list.rb +22 -0
  148. data/processor/command/show_subcmd/basename.rb +20 -0
  149. data/processor/command/show_subcmd/callstyle.rb +22 -0
  150. data/processor/command/show_subcmd/confirm.rb +18 -0
  151. data/processor/command/show_subcmd/debug.rb +26 -0
  152. data/processor/command/show_subcmd/debug_subcmd/dbgr.rb +21 -0
  153. data/processor/command/show_subcmd/debug_subcmd/skip.rb +22 -0
  154. data/processor/command/show_subcmd/debug_subcmd/step.rb +22 -0
  155. data/processor/command/show_subcmd/different.rb +26 -0
  156. data/processor/command/show_subcmd/directories.rb +22 -0
  157. data/processor/command/show_subcmd/highlight.rb +24 -0
  158. data/processor/command/show_subcmd/max.rb +27 -0
  159. data/processor/command/show_subcmd/max_subcmd/list.rb +38 -0
  160. data/processor/command/show_subcmd/max_subcmd/stack.rb +36 -0
  161. data/processor/command/show_subcmd/max_subcmd/string.rb +42 -0
  162. data/processor/command/show_subcmd/max_subcmd/width.rb +37 -0
  163. data/processor/command/show_subcmd/reload.rb +18 -0
  164. data/processor/command/show_subcmd/timer.rb +18 -0
  165. data/processor/command/show_subcmd/trace.rb +29 -0
  166. data/processor/command/show_subcmd/trace_subcmd/buffer.rb +65 -0
  167. data/processor/command/show_subcmd/trace_subcmd/print.rb +23 -0
  168. data/processor/command/show_subcmd/version.rb +23 -0
  169. data/processor/command/source.rb +134 -0
  170. data/processor/command/step.rb +81 -0
  171. data/processor/command/tbreak.rb +19 -0
  172. data/processor/command/unalias.rb +44 -0
  173. data/processor/command/undisplay.rb +59 -0
  174. data/processor/command/up.rb +72 -0
  175. data/processor/default.rb +56 -0
  176. data/processor/display.rb +17 -0
  177. data/processor/eval.rb +113 -0
  178. data/processor/eventbuf.rb +105 -0
  179. data/processor/frame.rb +172 -0
  180. data/processor/help.rb +92 -0
  181. data/processor/helper.rb +76 -0
  182. data/processor/hook.rb +134 -0
  183. data/processor/load_cmds.rb +258 -0
  184. data/processor/location.rb +174 -0
  185. data/processor/main.rb +455 -0
  186. data/processor/mock.rb +136 -0
  187. data/processor/msg.rb +61 -0
  188. data/processor/processor.rb +674 -0
  189. data/processor/running.rb +168 -0
  190. data/processor/stepping.rb +18 -0
  191. data/processor/subcmd.rb +161 -0
  192. data/processor/validate.rb +355 -0
  193. data/processor/virtual.rb +34 -0
  194. data/test/data/.gitignore +1 -0
  195. data/test/data/break_bad.cmd +19 -0
  196. data/test/data/break_bad.right +29 -0
  197. data/test/data/break_loop_bug.cmd +5 -0
  198. data/test/data/break_loop_bug.right +15 -0
  199. data/test/data/dollar-0.right +2 -0
  200. data/test/data/dollar-0a.right +2 -0
  201. data/test/data/dollar-0b.right +2 -0
  202. data/test/data/edit.cmd +14 -0
  203. data/test/data/edit.right +24 -0
  204. data/test/data/file-with-space.cmd +6 -0
  205. data/test/data/file-with-space.right +4 -0
  206. data/test/data/printvar.cmd +17 -0
  207. data/test/data/printvar.right +31 -0
  208. data/test/data/raise.cmd +11 -0
  209. data/test/data/raise.right +19 -0
  210. data/test/data/source.cmd +5 -0
  211. data/test/data/source.right +18 -0
  212. data/test/data/stepping-1.9.right +50 -0
  213. data/test/data/stepping.cmd +21 -0
  214. data/test/data/stepping.right +48 -0
  215. data/test/data/trepan8-save.1 +6 -0
  216. data/test/example/bp_loop_issue.rb +3 -0
  217. data/test/example/break-bug.rb +7 -0
  218. data/test/example/brkpt-class-bug.rb +8 -0
  219. data/test/example/classes.rb +11 -0
  220. data/test/example/dollar-0.rb +5 -0
  221. data/test/example/except-bug1.rb +4 -0
  222. data/test/example/except-bug2.rb +7 -0
  223. data/test/example/file with space.rb +1 -0
  224. data/test/example/gcd.rb +18 -0
  225. data/test/example/info-var-bug.rb +47 -0
  226. data/test/example/info-var-bug2.rb +2 -0
  227. data/test/example/null.rb +1 -0
  228. data/test/example/pm-bug.rb +3 -0
  229. data/test/example/pm.rb +11 -0
  230. data/test/example/raise.rb +3 -0
  231. data/test/integration/.gitignore +4 -0
  232. data/test/integration/config.yaml +8 -0
  233. data/test/integration/helper.rb +154 -0
  234. data/test/integration/test-break_bad.rb +26 -0
  235. data/test/integration/test-dollar-0.rb +31 -0
  236. data/test/integration/test-edit.rb +17 -0
  237. data/test/integration/test-file-with-space.rb +26 -0
  238. data/test/integration/test-printvar.rb +17 -0
  239. data/test/integration/test-raise.rb +21 -0
  240. data/test/integration/test-source.rb +16 -0
  241. data/test/integration/test-stepping.rb +24 -0
  242. data/test/unit/.gitignore +1 -0
  243. data/test/unit/cmd-helper.rb +52 -0
  244. data/test/unit/mock-helper.rb +12 -0
  245. data/test/unit/test-app-cmd_parse.rb +97 -0
  246. data/test/unit/test-app-cmd_parser.rb +23 -0
  247. data/test/unit/test-app-complete.rb +39 -0
  248. data/test/unit/test-app-frame.rb +32 -0
  249. data/test/unit/test-app-options.rb +92 -0
  250. data/test/unit/test-app-run.rb +14 -0
  251. data/test/unit/test-app-util.rb +44 -0
  252. data/test/unit/test-base-cmd.rb +45 -0
  253. data/test/unit/test-base-subcmd.rb +57 -0
  254. data/test/unit/test-base-submgr.rb +23 -0
  255. data/test/unit/test-base-subsubcmd.rb +17 -0
  256. data/test/unit/test-cmd-alias.rb +48 -0
  257. data/test/unit/test-cmd-exit.rb +27 -0
  258. data/test/unit/test-cmd-help.rb +104 -0
  259. data/test/unit/test-cmd-kill.rb +46 -0
  260. data/test/unit/test-cmd-source.rb +34 -0
  261. data/test/unit/test-completion.rb +42 -0
  262. data/test/unit/test-intf-user.rb +46 -0
  263. data/test/unit/test-io-input.rb +27 -0
  264. data/test/unit/test-io-tcp.rb +33 -0
  265. data/test/unit/test-io-tcpclient.rb +54 -0
  266. data/test/unit/test-io-tcpfns.rb +17 -0
  267. data/test/unit/test-io-tcpserver.rb +50 -0
  268. data/test/unit/test-proc-eval.rb +36 -0
  269. data/test/unit/test-proc-hook.rb +30 -0
  270. data/test/unit/test-proc-load_cmds.rb +50 -0
  271. data/test/unit/test-proc-location.rb +79 -0
  272. data/test/unit/test-subcmd-help.rb +44 -0
  273. data/trepan8.gemspec +52 -0
  274. metadata +391 -0
data/app/frame.rb ADDED
@@ -0,0 +1,166 @@
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ module Trepan
3
+
4
+ # Call-Stack frame methods
5
+ class Frame
6
+ attr_accessor :stack_size, :index
7
+ def initialize(context, index=0)
8
+ @context = context
9
+ @index = index
10
+ @stack_size = @context.stack_size
11
+ reset
12
+ end
13
+
14
+ def reset
15
+ @binding = @klass = @file = @line =
16
+ @local_variables = @method_name = @thread = nil
17
+ end
18
+
19
+ def index=(new_value)
20
+ if new_value > 0 && new_value < @stack_size
21
+ reset
22
+ @index = new_value
23
+ else
24
+ nil
25
+ end
26
+ end
27
+
28
+ def run(code, filename=nil)
29
+ filename='(eval :%s)' % code unless filename
30
+ eval(code, self.binding, filename)
31
+ end
32
+
33
+ def binding
34
+ @binding ||= @context.frame_binding(@index)
35
+ end
36
+
37
+ def call_string(opts={:maxwidth=>80, :callstyle => :last})
38
+ call_str = ""
39
+ if method_name
40
+ locals = local_variables
41
+ if opts[:callstyle] != :short && klass
42
+ if opts[:callstyle] == :tracked
43
+ arg_info = @context.frame_args_info(@index)
44
+ end
45
+ call_str << "#{klass}."
46
+ end
47
+ call_str << method_name
48
+ if args.any?
49
+ call_str << "("
50
+ args.each_with_index do |name, i|
51
+ case opts[:callstyle]
52
+ when :short
53
+ call_str += "%s, " % [name]
54
+ when :last
55
+ klass = locals[name].class
56
+ if klass.inspect.size > 20+3
57
+ klass = klass.inspect[0..20]+"..."
58
+ end
59
+ call_str += "%s#%s, " % [name, klass]
60
+ when :tracked
61
+ if arg_info && arg_info.size > i
62
+ call_str += "#{name}: #{arg_info[i].inspect}, "
63
+ else
64
+ call_str += "%s, " % name
65
+ end
66
+ end
67
+ if call_str.size > opts[:maxwidth]
68
+ # Strip off trailing ', ' if any but add stuff for later trunc
69
+ call_str[-2..-1] = ",...XX"
70
+ break
71
+ end
72
+ end
73
+ call_str[-2..-1] = ")" # Strip off trailing ', ' if any
74
+ end
75
+ end
76
+ return call_str
77
+ end
78
+
79
+ def describe(opts = {:maxwidth => 80})
80
+ str = ''
81
+ # FIXME There seem to be bugs in showing call if
82
+ # index != 0
83
+ call_str = index == 0 ? call_string(opts) : ''
84
+ file = opts[:basename] ? File.basename(self.file) : self.file
85
+ file_line = "at line %s:%d\n" % [file, line]
86
+ unless call_str.empty?
87
+ str += call_str + ' '
88
+ if str.size + call_str.size + 1 + file_line.size > opts[:maxwidth]
89
+ str += "\n "
90
+ else
91
+ str += ' '
92
+ end
93
+ end
94
+ str += file_line
95
+ str
96
+ end
97
+
98
+ def args
99
+ @args ||= @context.frame_args(@index)
100
+ end
101
+
102
+ def file
103
+ @file ||= @context.frame_file(@index)
104
+ end
105
+
106
+ def klass
107
+ @klass ||= @context.frame_class(@index)
108
+ end
109
+
110
+ def line
111
+ @line ||= @context.frame_line(@index)
112
+ end
113
+
114
+ def local_variables
115
+ @local_variables ||= @context.frame_locals(@index)
116
+ end
117
+
118
+ def method_name
119
+ if @method_name
120
+ @method_name
121
+ else
122
+ m = @context.frame_method(@index)
123
+ @method_name = m ? m.id2name : ''
124
+ end
125
+ end
126
+
127
+ def thread
128
+ @thread ||= @context.thread
129
+ end
130
+
131
+ # def eval?
132
+ # static = @vm_location.static_scope
133
+ # static && static.script && static.script.eval_source
134
+ # end
135
+
136
+ # def eval_string
137
+ # return nil unless eval?
138
+ # static = @vm_location.static_scope
139
+ # static.script.eval_source
140
+ # end
141
+
142
+ end
143
+ end
144
+
145
+ if __FILE__ == $0
146
+ # Show it:
147
+ require 'rubygems'
148
+ require 'ruby-debug-base'; Debugger.start
149
+ def foo(str, num)
150
+ x = 1
151
+ context = Debugger.current_context
152
+ Debugger.skip do
153
+ 0.upto(Debugger.current_context.stack_size-1) do |i|
154
+ frame = Trepan::Frame.new(context)
155
+ frame.index = i
156
+ puts "Frame #{i}: #{frame.file}, line #{frame.line}, " +
157
+ "class #{frame.klass}, thread: #{frame.thread}, " +
158
+ "method: #{frame.method_name}"
159
+ p frame.local_variables
160
+ puts frame.describe(:maxwidth => 80, :callstyle=>:tracked)
161
+ puts '-' * 30
162
+ end
163
+ end
164
+ end
165
+ foo('arg', 5)
166
+ end
data/app/irb.rb ADDED
@@ -0,0 +1,114 @@
1
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # This code comes more or less from ruby-debug.
3
+ require 'irb'
4
+ module IRB # :nodoc:
5
+ module ExtendCommand # :nodoc:
6
+ # FIXME: should we read these out of a directory to
7
+ # make this more user-customizable?
8
+
9
+ # A base command class that resume execution
10
+ class DebuggerResumeCommand
11
+ def self.execute(conf, *opts)
12
+ name =
13
+ if self.name =~ /IRB::ExtendCommand::(\S+)/
14
+ $1.downcase
15
+ else
16
+ 'unknown'
17
+ end
18
+ $trepan_args = opts
19
+ $trepan_command =
20
+ if $trepan_irb_statements
21
+ $trepan_irb_statements
22
+ else
23
+ ([name] + opts).join(' ')
24
+ end
25
+
26
+ throw :IRB_EXIT, name.to_sym
27
+ end
28
+ end
29
+
30
+ # FIXME: figure out why superclass type mismatch problem on 1.9
31
+ if RUBY_VERSION !~ /^1.9/
32
+ class Continue < DebuggerResumeCommand ; end
33
+ class Finish < DebuggerResumeCommand ; end
34
+ class Next < DebuggerResumeCommand ; end
35
+ class Quit < DebuggerResumeCommand ; end
36
+ class Step < DebuggerResumeCommand ; end
37
+ end
38
+
39
+ # Issues a comamnd to the debugger without continuing
40
+ # execution.
41
+ class Dbgr
42
+ def self.execute(conf, *opts)
43
+ $trepan_command =
44
+ if opts.size == 1 && opts[0].is_a?(String)
45
+ $trepan_args = opts[0]
46
+ else
47
+ opts.join(' ')
48
+ end
49
+ dbg_cmdproc = conf.workspace.instance_variable_get('@dbg_cmdproc')
50
+ dbg_cmdproc.run_command($trepan_command)
51
+ end
52
+ end
53
+
54
+ end
55
+ if defined?(ExtendCommandBundle)
56
+ # New irb Commands which are the same name as their debugger
57
+ # counterpart
58
+ %w(Dbgr Finish Step).each do |name|
59
+ command = name.downcase
60
+ sym = name.to_sym
61
+ ExtendCommandBundle.def_extend_command command, sym
62
+ end
63
+ # New irb Commands which are the slightly different from their
64
+ # debugger counterpart
65
+ [['cont', :Continue],
66
+ ['ne', :Next],
67
+ ['q', :Quit]].each do |command, sym|
68
+ ExtendCommandBundle.def_extend_command command, sym
69
+ end
70
+ end
71
+
72
+ def self.start_session(binding, dbg_cmdproc, conf={})
73
+ unless @__initialized
74
+
75
+ # Set to run the standard trepan IRB profile
76
+ irbrc = File.expand_path(File.join(File.dirname(__FILE__),
77
+ %w(.. data irbrc)))
78
+ ENV['IRBRC'] = irbrc
79
+
80
+ args = ARGV.dup
81
+ ARGV.replace([])
82
+ IRB.setup(nil)
83
+ ARGV.replace(args)
84
+
85
+ # If the user has a IRB profile, run that now.
86
+ if ENV['TREPANX_IRB']
87
+ ENV['IRBRC'] = ENV['TREPANX_IRB']
88
+ @CONF[:RC_NAME_GENERATOR]=nil
89
+ IRB.run_config
90
+ end
91
+
92
+ @__initialized = true
93
+ end
94
+
95
+ workspace = WorkSpace.new(binding)
96
+
97
+ irb = Irb.new(workspace)
98
+
99
+ @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
100
+ @CONF[:MAIN_CONTEXT] = irb.context
101
+ conf.each {|k, v| @CONF[k] = v}
102
+ # A copy of this back_trace_limit is already active. How?
103
+ IRB.CurrentContext.back_trace_limit = @CONF[:BACK_TRACE_LIMIT]
104
+
105
+ catch(:IRB_EXIT) do
106
+ irb.eval_input
107
+ end
108
+ end
109
+ end
110
+
111
+ if __FILE__ == $0
112
+ # Demo it.
113
+ IRB.start_session(binding, nil) if ARGV.size > 0
114
+ end
data/app/options.rb ADDED
@@ -0,0 +1,200 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
4
+ #=== Summary
5
+ # Parses command-line options.
6
+
7
+ require 'optparse'
8
+ module Trepan
9
+ require 'rubygems'; require 'require_relative'
10
+ require_relative 'default'
11
+
12
+ VERSION = '0.1.3' unless defined? Trepan::VERSION
13
+ PROGRAM = 'trepan8' unless defined? Trepan::PROGRAM
14
+
15
+ module_function
16
+
17
+ def show_version
18
+ "#{PROGRAM}, version #{VERSION}"
19
+ end
20
+
21
+ def copy_default_options
22
+ options = {}
23
+ DEFAULT_CMDLINE_SETTINGS.each do |key, value|
24
+ begin
25
+ options[key] = value.clone
26
+ rescue TypeError
27
+ options[key] = value
28
+ end
29
+ end
30
+ options
31
+ end
32
+
33
+ def setup_options(options, stdout=$stdout, stderr=$stderr)
34
+ OptionParser.new do |opts|
35
+ opts.banner = <<EOB
36
+ #{show_version}
37
+ Usage: #{PROGRAM} [options] [[--] <script.rb> <script.rb parameters>]
38
+ EOB
39
+ opts.separator ''
40
+ opts.separator 'Options:'
41
+ opts.on('--client',
42
+ 'Connect to out-of-process program') do
43
+ if options[:server]
44
+ stderr.puts '--server option previously given. --client option ignored.'
45
+ else
46
+ options[:client] = true
47
+ end
48
+ end
49
+ opts.on('-c', '--command FILE', String,
50
+ 'Execute debugger commands from FILE') do |cmdfile|
51
+ if File.readable?(cmdfile)
52
+ options[:cmdfiles] << cmdfile
53
+ elsif File.exists?(cmdfile)
54
+ stderr.puts "Command file '#{cmdfile}' is not readable. Option ignored."
55
+ else
56
+ stderr.puts "Command file '#{cmdfile}' does not exist."
57
+ end
58
+ end
59
+ opts.on('--cd DIR', String, 'Change current directory to DIR') do |dir|
60
+ if File.directory?(dir)
61
+ if File.executable?(dir)
62
+ options[:chdir] = dir
63
+ else
64
+ stderr.puts "Can't cd to #{dir}. Option --cd ignored."
65
+ end
66
+ else
67
+ stderr.puts "\"#{dir}\" is not a directory. Option --cd ignored."
68
+ end
69
+ end
70
+ opts.on('--basename',
71
+ 'Show only file basename in file locations') do
72
+ options[:basename] = true
73
+ end
74
+ opts.on('-d', '--debug', 'Set $DEBUG=true') do
75
+ $DEBUG = true
76
+ end
77
+ opts.on('--cport PORT', Integer, 'Port used for control commands') do
78
+ |cport|
79
+ options[:cport] = cport
80
+ end
81
+ opts.on('--[no-]highlight',
82
+ 'Use [no] syntax highlight output') do |v|
83
+ options[:highlight] = ((v) ? :term : nil)
84
+ if options[:highlight]
85
+ begin
86
+ require 'linecache'
87
+ rescue LoadError
88
+ require 'linecache19'
89
+ end
90
+ unless LineCache.respond_to?(:clear_file_format_cache)
91
+ stderr.puts "Your version of LineCache doesn't support terminal highlight"
92
+ options[:higlight] = false
93
+ end
94
+ end
95
+ end
96
+ opts.on('-h', '--host NAME', String,
97
+ 'Host or IP used in TCP connections for --server or --client. ' +
98
+ "Default is #{DEFAULT_SETTINGS[:host].inspect}.") do
99
+ |name_or_ip|
100
+ options[:host] = name_or_ip
101
+ end
102
+ opts.on('-I', '--include PATH', String, 'Add PATH to $LOAD_PATH') do |path|
103
+ $LOAD_PATH.unshift(path)
104
+ end
105
+ opts.on('--keep-frame-binding', 'Keep frame bindings') do
106
+ options[:frame_bind] = true
107
+ end
108
+ opts.on('-m', '--post-mortem', 'Activate post-mortem mode') do
109
+ options[:post_mortem] = true
110
+ end
111
+ opts.on('--nx',
112
+ "Do not run debugger initialization file #{CMD_INITFILE}") do
113
+ options[:nx] = true
114
+ end
115
+ opts.on('--[no-]control', 'Start [not] control thread') do |v|
116
+ options[:control] = v
117
+ end
118
+ opts.on('-p', '--port NUMBER', Integer,
119
+ 'Port number used in TCP connections for --server or --client. ' +
120
+ "Default is #{DEFAULT_SETTINGS[:port]}.") do
121
+ |num|
122
+ options[:port] = num
123
+ end
124
+ opts.on('--[no-]quit', 'Do [not] quit when script finishes') do |v|
125
+ options[:quit] = v
126
+ end
127
+ opts.on('--[no-]readline',
128
+ 'Try [not] GNU Readline') do |v|
129
+ options[:readline] = v
130
+ end
131
+ opts.on('-r', '--require SCRIPT', String,
132
+ 'Require the library, before executing your script') do |name|
133
+ if name == 'debug'
134
+ stderr.puts "trepan8 is not compatible with Ruby's 'debug' library. This option is ignored."
135
+ else
136
+ require name
137
+ end
138
+ end
139
+ opts.on('--[no-]rewrite-program',
140
+ 'Do not set $0 to the program being debugged') do |v|
141
+ options[:rewrite_program] = v
142
+ end
143
+ opts.on('--[no-]stop', 'Do not stop when script is loaded') do |v|
144
+ options[:stop] = v
145
+ end
146
+ opts.on('--script FILE', String, 'Name of the script file to run') do
147
+ |script|
148
+ options[:script] = script
149
+ unless File.exists?(options[:script])
150
+ stderr.puts "Script file '#{options[:script]}' is not found"
151
+ exit 10
152
+ end
153
+ end
154
+ opts.on('-s', '--server',
155
+ 'Set up for out-of-process debugging') do
156
+ if options[:client]
157
+ stderr.puts '--client option previously given. --server option ignored.'
158
+ else
159
+ options[:server] = true
160
+ end
161
+ end
162
+ opts.on('-w', '--wait', 'Wait for a client connection; implies -s option') do
163
+ options[:wait] = true
164
+ end
165
+ opts.on('-x', '--trace', 'Turn on line tracing') do
166
+ options[:tracing] = true
167
+ end
168
+ opts.separator ''
169
+ opts.on_tail('-?', '--help', 'Show this message') do
170
+ options[:help] = true
171
+ stdout.puts opts
172
+ exit
173
+ end
174
+ opts.on_tail('-v', '--version',
175
+ 'print the version') do
176
+ options[:version] = true
177
+ stdout.puts show_version
178
+ end
179
+ end
180
+ end
181
+ end
182
+
183
+ if __FILE__ == $0
184
+ include Trepan
185
+ opts = {}
186
+ options ={}
187
+ [%w(--help), %w(--version)].each do |o|
188
+ options = Trepan::copy_default_options
189
+ opts = Trepan::setup_options(options)
190
+ rest = opts.parse o
191
+ p options
192
+ puts '=' * 10
193
+ end
194
+ rest = opts.parse! ARGV
195
+ puts opts
196
+ puts '=' * 10
197
+ p options
198
+ puts '=' * 10
199
+ p Trepan::DEFAULT_CMDLINE_SETTINGS
200
+ end