rb8-trepanning 0.1.3-universal-ruby-1.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) 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/.gitignore +1 -0
  41. data/processor/command/alias.rb +54 -0
  42. data/processor/command/backtrace.rb +123 -0
  43. data/processor/command/base/cmd.rb +177 -0
  44. data/processor/command/base/subcmd.rb +230 -0
  45. data/processor/command/base/submgr.rb +188 -0
  46. data/processor/command/base/subsubcmd.rb +128 -0
  47. data/processor/command/base/subsubmgr.rb +199 -0
  48. data/processor/command/break.rb +114 -0
  49. data/processor/command/catch.rb +71 -0
  50. data/processor/command/complete.rb +39 -0
  51. data/processor/command/continue.rb +57 -0
  52. data/processor/command/directory.rb +50 -0
  53. data/processor/command/disable.rb +85 -0
  54. data/processor/command/display.rb +78 -0
  55. data/processor/command/down.rb +54 -0
  56. data/processor/command/edit.rb +79 -0
  57. data/processor/command/enable.rb +48 -0
  58. data/processor/command/eval.rb +90 -0
  59. data/processor/command/exit.rb +66 -0
  60. data/processor/command/finish.rb +59 -0
  61. data/processor/command/frame.rb +97 -0
  62. data/processor/command/help/.gitignore +1 -0
  63. data/processor/command/help/README +10 -0
  64. data/processor/command/help/command.txt +58 -0
  65. data/processor/command/help/examples.txt +16 -0
  66. data/processor/command/help/filename.txt +40 -0
  67. data/processor/command/help/location.txt +37 -0
  68. data/processor/command/help/suffixes.txt +17 -0
  69. data/processor/command/help.rb +230 -0
  70. data/processor/command/info.rb +28 -0
  71. data/processor/command/info_subcmd/.gitignore +1 -0
  72. data/processor/command/info_subcmd/args.rb +39 -0
  73. data/processor/command/info_subcmd/breakpoints.rb +80 -0
  74. data/processor/command/info_subcmd/catch.rb +36 -0
  75. data/processor/command/info_subcmd/files.rb +39 -0
  76. data/processor/command/info_subcmd/globals.rb +64 -0
  77. data/processor/command/info_subcmd/line.rb +30 -0
  78. data/processor/command/info_subcmd/locals.rb +69 -0
  79. data/processor/command/info_subcmd/macro.rb +62 -0
  80. data/processor/command/info_subcmd/program.rb +51 -0
  81. data/processor/command/info_subcmd/ruby.rb +57 -0
  82. data/processor/command/info_subcmd/source.rb +74 -0
  83. data/processor/command/info_subcmd/stack.rb +25 -0
  84. data/processor/command/info_subcmd/threads.rb +75 -0
  85. data/processor/command/kill.rb +78 -0
  86. data/processor/command/list.rb +117 -0
  87. data/processor/command/macro.rb +68 -0
  88. data/processor/command/next.rb +79 -0
  89. data/processor/command/parsetree.rb +56 -0
  90. data/processor/command/pp.rb +40 -0
  91. data/processor/command/pr.rb +37 -0
  92. data/processor/command/ps.rb +40 -0
  93. data/processor/command/restart.rb +86 -0
  94. data/processor/command/save.rb +58 -0
  95. data/processor/command/set.rb +47 -0
  96. data/processor/command/set_subcmd/.gitignore +1 -0
  97. data/processor/command/set_subcmd/abbrev.rb +25 -0
  98. data/processor/command/set_subcmd/auto.rb +27 -0
  99. data/processor/command/set_subcmd/auto_subcmd/.gitignore +1 -0
  100. data/processor/command/set_subcmd/auto_subcmd/eval.rb +53 -0
  101. data/processor/command/set_subcmd/auto_subcmd/irb.rb +33 -0
  102. data/processor/command/set_subcmd/auto_subcmd/list.rb +33 -0
  103. data/processor/command/set_subcmd/basename.rb +25 -0
  104. data/processor/command/set_subcmd/callstyle.rb +46 -0
  105. data/processor/command/set_subcmd/confirm.rb +24 -0
  106. data/processor/command/set_subcmd/debug.rb +47 -0
  107. data/processor/command/set_subcmd/different.rb +61 -0
  108. data/processor/command/set_subcmd/highlight.rb +43 -0
  109. data/processor/command/set_subcmd/max.rb +26 -0
  110. data/processor/command/set_subcmd/max_subcmd/list.rb +49 -0
  111. data/processor/command/set_subcmd/max_subcmd/stack.rb +50 -0
  112. data/processor/command/set_subcmd/max_subcmd/string.rb +76 -0
  113. data/processor/command/set_subcmd/max_subcmd/width.rb +49 -0
  114. data/processor/command/set_subcmd/reload.rb +42 -0
  115. data/processor/command/set_subcmd/timer.rb +58 -0
  116. data/processor/command/shell.rb +139 -0
  117. data/processor/command/show.rb +39 -0
  118. data/processor/command/show_subcmd/.gitignore +1 -0
  119. data/processor/command/show_subcmd/abbrev.rb +20 -0
  120. data/processor/command/show_subcmd/alias.rb +46 -0
  121. data/processor/command/show_subcmd/args.rb +34 -0
  122. data/processor/command/show_subcmd/auto.rb +28 -0
  123. data/processor/command/show_subcmd/auto_subcmd/eval.rb +27 -0
  124. data/processor/command/show_subcmd/auto_subcmd/irb.rb +23 -0
  125. data/processor/command/show_subcmd/auto_subcmd/list.rb +22 -0
  126. data/processor/command/show_subcmd/basename.rb +20 -0
  127. data/processor/command/show_subcmd/callstyle.rb +22 -0
  128. data/processor/command/show_subcmd/confirm.rb +18 -0
  129. data/processor/command/show_subcmd/debug.rb +26 -0
  130. data/processor/command/show_subcmd/debug_subcmd/dbgr.rb +21 -0
  131. data/processor/command/show_subcmd/debug_subcmd/skip.rb +22 -0
  132. data/processor/command/show_subcmd/debug_subcmd/step.rb +22 -0
  133. data/processor/command/show_subcmd/different.rb +26 -0
  134. data/processor/command/show_subcmd/directories.rb +22 -0
  135. data/processor/command/show_subcmd/highlight.rb +24 -0
  136. data/processor/command/show_subcmd/max.rb +27 -0
  137. data/processor/command/show_subcmd/max_subcmd/list.rb +38 -0
  138. data/processor/command/show_subcmd/max_subcmd/stack.rb +36 -0
  139. data/processor/command/show_subcmd/max_subcmd/string.rb +42 -0
  140. data/processor/command/show_subcmd/max_subcmd/width.rb +37 -0
  141. data/processor/command/show_subcmd/reload.rb +18 -0
  142. data/processor/command/show_subcmd/timer.rb +18 -0
  143. data/processor/command/show_subcmd/version.rb +23 -0
  144. data/processor/command/source.rb +134 -0
  145. data/processor/command/step.rb +81 -0
  146. data/processor/command/tbreak.rb +19 -0
  147. data/processor/command/unalias.rb +44 -0
  148. data/processor/command/undisplay.rb +59 -0
  149. data/processor/command/up.rb +72 -0
  150. data/processor/command-ruby-debug/breakpoints.rb +155 -0
  151. data/processor/command-ruby-debug/catchpoint.rb +55 -0
  152. data/processor/command-ruby-debug/condition.rb +49 -0
  153. data/processor/command-ruby-debug/control.rb +31 -0
  154. data/processor/command-ruby-debug/display.rb +120 -0
  155. data/processor/command-ruby-debug/enable.rb +202 -0
  156. data/processor/command-ruby-debug/frame.rb +199 -0
  157. data/processor/command-ruby-debug/help.rb +63 -0
  158. data/processor/command-ruby-debug/info.rb +359 -0
  159. data/processor/command-ruby-debug/method.rb +84 -0
  160. data/processor/command-ruby-debug/reload.rb +40 -0
  161. data/processor/command-ruby-debug/save.rb +90 -0
  162. data/processor/command-ruby-debug/set.rb +237 -0
  163. data/processor/command-ruby-debug/show.rb +251 -0
  164. data/processor/command-ruby-debug/source.rb +36 -0
  165. data/processor/command-ruby-debug/threads.rb +189 -0
  166. data/processor/command-ruby-debug/trace.rb +57 -0
  167. data/processor/command-ruby-debug/variables.rb +199 -0
  168. data/processor/command.rb +270 -0
  169. data/processor/default.rb +56 -0
  170. data/processor/display.rb +17 -0
  171. data/processor/eval.rb +113 -0
  172. data/processor/eventbuf.rb +105 -0
  173. data/processor/frame.rb +172 -0
  174. data/processor/help.rb +92 -0
  175. data/processor/helper.rb +76 -0
  176. data/processor/hook.rb +134 -0
  177. data/processor/load_cmds.rb +258 -0
  178. data/processor/location.rb +174 -0
  179. data/processor/main.rb +455 -0
  180. data/processor/mock.rb +136 -0
  181. data/processor/msg.rb +61 -0
  182. data/processor/processor.rb +674 -0
  183. data/processor/running.rb +168 -0
  184. data/processor/stepping.rb +18 -0
  185. data/processor/subcmd.rb +161 -0
  186. data/processor/validate.rb +355 -0
  187. data/processor/virtual.rb +34 -0
  188. data/test/data/.gitignore +1 -0
  189. data/test/data/break_bad.cmd +19 -0
  190. data/test/data/break_bad.right +29 -0
  191. data/test/data/break_loop_bug.cmd +5 -0
  192. data/test/data/break_loop_bug.right +15 -0
  193. data/test/data/dollar-0.right +2 -0
  194. data/test/data/dollar-0a.right +2 -0
  195. data/test/data/dollar-0b.right +2 -0
  196. data/test/data/edit.cmd +14 -0
  197. data/test/data/edit.right +24 -0
  198. data/test/data/file-with-space.cmd +6 -0
  199. data/test/data/file-with-space.right +4 -0
  200. data/test/data/printvar.cmd +17 -0
  201. data/test/data/printvar.right +31 -0
  202. data/test/data/raise.cmd +11 -0
  203. data/test/data/raise.right +19 -0
  204. data/test/data/source.cmd +5 -0
  205. data/test/data/source.right +18 -0
  206. data/test/data/stepping-1.9.right +50 -0
  207. data/test/data/stepping.cmd +21 -0
  208. data/test/data/stepping.right +48 -0
  209. data/test/data/trepan8-save.1 +6 -0
  210. data/test/example/bp_loop_issue.rb +3 -0
  211. data/test/example/break-bug.rb +7 -0
  212. data/test/example/brkpt-class-bug.rb +8 -0
  213. data/test/example/classes.rb +11 -0
  214. data/test/example/dollar-0.rb +5 -0
  215. data/test/example/except-bug1.rb +4 -0
  216. data/test/example/except-bug2.rb +7 -0
  217. data/test/example/file with space.rb +1 -0
  218. data/test/example/gcd.rb +18 -0
  219. data/test/example/info-var-bug.rb +47 -0
  220. data/test/example/info-var-bug2.rb +2 -0
  221. data/test/example/null.rb +1 -0
  222. data/test/example/pm-bug.rb +3 -0
  223. data/test/example/pm.rb +11 -0
  224. data/test/example/raise.rb +3 -0
  225. data/test/integration/.gitignore +4 -0
  226. data/test/integration/config.yaml +8 -0
  227. data/test/integration/helper.rb +154 -0
  228. data/test/integration/test-break_bad.rb +26 -0
  229. data/test/integration/test-dollar-0.rb +31 -0
  230. data/test/integration/test-edit.rb +17 -0
  231. data/test/integration/test-file-with-space.rb +26 -0
  232. data/test/integration/test-printvar.rb +17 -0
  233. data/test/integration/test-raise.rb +21 -0
  234. data/test/integration/test-source.rb +16 -0
  235. data/test/integration/test-stepping.rb +24 -0
  236. data/test/unit/.gitignore +1 -0
  237. data/test/unit/cmd-helper.rb +52 -0
  238. data/test/unit/mock-helper.rb +12 -0
  239. data/test/unit/test-app-cmd_parse.rb +97 -0
  240. data/test/unit/test-app-cmd_parser.rb +23 -0
  241. data/test/unit/test-app-complete.rb +39 -0
  242. data/test/unit/test-app-frame.rb +32 -0
  243. data/test/unit/test-app-options.rb +92 -0
  244. data/test/unit/test-app-run.rb +14 -0
  245. data/test/unit/test-app-util.rb +44 -0
  246. data/test/unit/test-base-cmd.rb +45 -0
  247. data/test/unit/test-base-subcmd.rb +57 -0
  248. data/test/unit/test-base-submgr.rb +23 -0
  249. data/test/unit/test-base-subsubcmd.rb +17 -0
  250. data/test/unit/test-cmd-alias.rb +48 -0
  251. data/test/unit/test-cmd-exit.rb +27 -0
  252. data/test/unit/test-cmd-help.rb +104 -0
  253. data/test/unit/test-cmd-kill.rb +46 -0
  254. data/test/unit/test-cmd-source.rb +34 -0
  255. data/test/unit/test-completion.rb +42 -0
  256. data/test/unit/test-intf-user.rb +46 -0
  257. data/test/unit/test-io-input.rb +27 -0
  258. data/test/unit/test-io-tcp.rb +33 -0
  259. data/test/unit/test-io-tcpclient.rb +54 -0
  260. data/test/unit/test-io-tcpfns.rb +17 -0
  261. data/test/unit/test-io-tcpserver.rb +50 -0
  262. data/test/unit/test-proc-eval.rb +36 -0
  263. data/test/unit/test-proc-hook.rb +30 -0
  264. data/test/unit/test-proc-load_cmds.rb +50 -0
  265. data/test/unit/test-proc-location.rb +79 -0
  266. data/test/unit/test-subcmd-help.rb +44 -0
  267. data/trepan8.gemspec +58 -0
  268. metadata +385 -0
data/processor/main.rb ADDED
@@ -0,0 +1,455 @@
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # The main "driver" class for a command processor. Other parts of the
3
+ # command class and debugger command objects are pulled in from here.
4
+
5
+ require 'set'
6
+
7
+ require 'rubygems'; require 'require_relative'
8
+ ## %w(default display eventbuf eval load_cmds location frame hook msg
9
+ ## validate).each do
10
+ # %w(default breakpoint disassemble display eval eventbuf load_cmds location
11
+ # frame hook msg running stepping validate).each do
12
+ %w(default display eval eventbuf frame hook load_cmds location msg running validate).each do
13
+ |mod_str|
14
+ require_relative mod_str
15
+ end
16
+ ## require_relative '../app/brkptmgr'
17
+
18
+ module Trepan
19
+ class CmdProcessor < VirtualCmdProcessor
20
+
21
+ # SEE ALSO attr's in require_relative's of loop above.
22
+
23
+ attr_reader :cmd_argstr # Current command args, a String.
24
+ # This is current_command with the command
25
+ # name removed from the beginning.
26
+ attr_reader :cmd_name # command name before alias or macro resolution
27
+ attr_reader :cmd_queue # queue of commands to run
28
+ ## attr_reader :core # Trepan core object
29
+ attr_reader :current_command # Current command getting run, a String.
30
+
31
+ attr_accessor :dbgr # Trepan instance (via
32
+ # Trepan::Core instance)
33
+ ## FIXME 1.9.2 has attr_reader !
34
+ attr_accessor :interfaces
35
+ attr_accessor :state
36
+
37
+ attr_accessor :debug_nest # Number of nested debugs. Used in showing
38
+ # prompt.
39
+ attr_accessor :different_pos # Same type as settings[:different]
40
+ # this is the temporary value for the
41
+ # next stop while settings is the default
42
+ # value to use.
43
+ attr_accessor :event # Stop event
44
+ attr_reader :intf # Current interface
45
+ # Trepan::Core instance)
46
+ attr_accessor :leave_cmd_loop # Commands set this to signal to leave
47
+ # the command loop (which often continues to
48
+ # run the debugged program).
49
+ attr_accessor :line_no # Last line shown in "list" command
50
+ attr_accessor :next_level # Fixnum. frame.stack_size has to
51
+ # be <= than this. If next'ing,
52
+ # this will be > 0.
53
+ attr_accessor :next_thread # Thread. If non-nil then in
54
+ # stepping the thread has to be
55
+ # this thread.
56
+ attr_accessor :pass_exception # Pass an exception back
57
+ attr_accessor :prompt # String print before requesting input
58
+ attr_reader :settings # Hash[:symbol] of command
59
+ # processor settings
60
+ attr_reader :step_bp
61
+
62
+ # The following are used in to force stopping at a different line
63
+ # number. FIXME: could generalize to a position object.
64
+ attr_accessor :last_pos # Last position. 6-Tuple: of
65
+ # [location, container, stack_size,
66
+ # current_thread, pc_offset]
67
+
68
+ unless defined?(EVENT2ICON)
69
+ # Event icons used in printing locations.
70
+ EVENT2ICON = {
71
+ 'brkpt' => 'xx',
72
+ 'tbrkpt' => 'x1',
73
+ 'c-call' => 'C>',
74
+ 'c-return' => '<C',
75
+ 'step-call' => '->',
76
+ 'call' => '->',
77
+ 'class' => '::',
78
+ 'coverage' => '[]',
79
+ 'debugger-call' => ':o',
80
+ 'end' => '-|',
81
+ 'line' => '--',
82
+ 'raise' => '!!',
83
+ 'return' => '<-',
84
+ 'start' => '>>',
85
+ 'switch' => 'sw',
86
+ 'trace-var' => '$V',
87
+ 'unknown' => '?!',
88
+ 'vm' => 'VM',
89
+ 'vm-insn' => '..',
90
+ }
91
+ # These events are important enough event that we always want to
92
+ # stop on them.
93
+ UNMASKABLE_EVENTS = Set.new(['end', 'raise', 'unknown'])
94
+ end
95
+
96
+ ## def initialize(dbgr, settings={})
97
+ def initialize(interfaces, settings={})
98
+ @cmd_queue = []
99
+ @event = nil
100
+ @interfaces = interfaces
101
+ @intf = interfaces[-1]
102
+ @debug_nest = 1
103
+ @hidelevels = {}
104
+ @last_command = nil
105
+ @last_pos = [nil, nil, nil, nil, nil, nil]
106
+ @next_level = 32000
107
+ @next_thread = nil
108
+ @user_variables = 0
109
+ @state = nil
110
+
111
+
112
+ start_cmds = settings.delete(:start_cmds)
113
+ start_file = settings.delete(:start_file)
114
+
115
+ @settings = DEFAULT_SETTINGS.merge(settings)
116
+ @different_pos = @settings[:different]
117
+
118
+ # FIXME: Rework using a general "set substitute file" command and
119
+ # a global default profile which gets read.
120
+ prelude_file = File.expand_path(File.join(File.dirname(__FILE__),
121
+ %w(.. data prelude.rb)))
122
+
123
+ # Start with empty thread and frame info.
124
+ frame_teardown
125
+
126
+ # Run initialization routines for each of the "submodule"s.
127
+ # load_cmds has to come first.
128
+ ## %w(load_cmds breakpoint display eventbuf frame running validate
129
+ ## ).each do |submod|
130
+ ## %w(load_cmds breakpoint display eventbuf frame running
131
+ ## stepping validate).each do
132
+ %w(load_cmds display eventbuf frame running validate).each do
133
+ |submod|
134
+ self.send("#{submod}_initialize")
135
+ end
136
+ hook_initialize(commands)
137
+ end
138
+
139
+ def compute_prompt
140
+ "(#{@settings[:prompt]}): "
141
+ end
142
+
143
+ def finalize
144
+ # breakpoint_finalize
145
+ # stepping_breakpoint_finalize
146
+ @intf.finalize
147
+ end
148
+
149
+ def canonic_container(container)
150
+ [container[0], canonic_file(container[1])]
151
+ end
152
+
153
+ def compute_prompt
154
+ "(#{@settings[:prompt]}): "
155
+ end
156
+
157
+ # Check that we meed the criteria that cmd specifies it needs
158
+ def ok_for_running(cmd, name, nargs)
159
+ # TODO check execution_set against execution status.
160
+ # Check we have frame is not null
161
+ min_args = cmd.class.const_get(:MIN_ARGS)
162
+ if nargs < min_args
163
+ errmsg(("Command '%s' needs at least %d argument(s); " +
164
+ "got %d.") % [name, min_args, nargs])
165
+ return false
166
+ end
167
+ max_args = cmd.class.const_get(:MAX_ARGS)
168
+ if max_args and nargs > max_args
169
+ errmsg(("Command '%s' needs at most %d argument(s); " +
170
+ "got %d.") % [name, max_args, nargs])
171
+ return false
172
+ end
173
+ # if cmd.class.const_get(:NEED_RUNNING) && !...
174
+ # errmsg "Command '%s' requires a running program." % name
175
+ # return false
176
+ # end
177
+
178
+ if cmd.class.const_get(:NEED_STACK) && !@context
179
+ errmsg "Command '%s' requires a running stack frame." % name
180
+ return false
181
+ end
182
+
183
+ return true
184
+ end
185
+
186
+ # Run one debugger command. True is returned if we want to quit.
187
+ def process_command_and_quit?()
188
+ intf_size = @interfaces.size
189
+ if @interfaces.empty?
190
+ puts "FOO"
191
+ exit
192
+ end
193
+ @intf = @interfaces[-1]
194
+ return true if @intf.input_eof? && intf_size == 1
195
+ while intf_size > 1 || !@intf.input_eof?
196
+ begin
197
+ @current_command =
198
+ if @cmd_queue.empty?
199
+ # Leave trailing blanks on for the "complete" command
200
+ read_command.chomp
201
+ else
202
+ @cmd_queue.shift
203
+ end
204
+ if @current_command.empty?
205
+ if @last_command && intf.interactive?
206
+ @current_command = @last_command
207
+ else
208
+ next
209
+ end
210
+ end
211
+ next if @current_command[0..0] == '#' # Skip comment lines
212
+ break
213
+ rescue IOError, Errno::EPIPE => e
214
+ if intf_size > 1
215
+ @interfaces.pop
216
+ intf_size = @interfaces.size
217
+ @intf = @interfaces.last
218
+ @last_command = nil
219
+ print_location
220
+ else
221
+ ## FIXME: think of something better.
222
+ quit('exit!')
223
+ return true
224
+ end
225
+ rescue Exception => exc
226
+ errmsg("Internal debugger error in read: #{exc.inspect}")
227
+ exception_dump(exc, @settings[:debugexcept], $!.backtrace)
228
+ end
229
+ end
230
+ run_command(@current_command)
231
+
232
+ # Save it to the history.
233
+ @intf.history_io.puts @last_command if @last_command && @intf.history_io
234
+ end
235
+
236
+ def after_cmdloop
237
+ @cmdloop_posthooks.run
238
+ end
239
+
240
+ def before_cmdloop
241
+
242
+ frame_setup(@context, @state)
243
+
244
+ @unconditional_prehooks.run
245
+ if breakpoint?
246
+ delete_breakpoint(@brkpt) if @brkpt.temp?
247
+ @last_pos = [@frame.vm_location, @stack_size, @current_thread, @event]
248
+ end
249
+
250
+ if stepping_skip? # || @stack_size <= @hide_level
251
+ if @next_thread
252
+ self.next(@step_count, :next_level => @next_level)
253
+ else
254
+ step(@return_to_program, @step_count, {}, @stop_condition)
255
+ end
256
+ return true
257
+ elsif @event == 'start'
258
+ step('step', 0)
259
+ return true
260
+ end
261
+
262
+ @prompt = compute_prompt
263
+
264
+ @leave_cmd_loop = false
265
+ print_location unless @settings[:traceprint]
266
+ # if 'trace-var' == @event
267
+ # msg "Note: we are stopped *after* the above location."
268
+ # end
269
+
270
+ @eventbuf.add_mark if @settings[:tracebuffer]
271
+
272
+ @return_to_program = false
273
+ @cmdloop_prehooks.run
274
+ return false
275
+ end
276
+
277
+ # This is the main entry point.
278
+ def process_commands(context, state)
279
+
280
+ @context = context
281
+ @state = state
282
+ frame_setup(@context, @state)
283
+ # @event = @core.event
284
+
285
+ @unconditional_prehooks.run
286
+ # if breakpoint?
287
+ # @last_pos = [@frame.source_container, frame_line,
288
+ # @stack_size, @current_thread, @event,
289
+ # @frame.pc_offset]
290
+ # else
291
+ # return if stepping_skip? || @stack_size <= @hide_level
292
+ # end
293
+
294
+ @prompt = compute_prompt
295
+
296
+ @leave_cmd_loop = false
297
+ print_location unless @settings[:traceprint]
298
+ # if 'trace-var' == @event
299
+ # msg "Note: we are stopped *after* the above location."
300
+ # end
301
+
302
+ @eventbuf.add_mark if @settings[:tracebuffer]
303
+
304
+ @cmdloop_prehooks.run
305
+ while not @leave_cmd_loop do
306
+ begin
307
+ break if process_command_and_quit?()
308
+ rescue SystemExit
309
+ @dbgr.stop
310
+ raise
311
+ rescue Exception => exc
312
+ # If we are inside the script interface errmsg may fail.
313
+ begin
314
+ errmsg("Internal debugger error in cmdloop: #{exc.inspect}")
315
+ rescue IOError
316
+ $stderr.puts "Internal debugger error: #{exc.inspect}"
317
+ end
318
+ exception_dump(exc, @settings[:debugexcept], $!.backtrace)
319
+ end
320
+ end
321
+ @cmdloop_posthooks.run
322
+ end
323
+
324
+ # Run current_command, a String. @last_command is set after the
325
+ # command is run if it is a command.
326
+ def run_command(current_command)
327
+ eval_command =
328
+ if current_command[0..0] == '!'
329
+ current_command[0] = ''
330
+ else
331
+ false
332
+ end
333
+
334
+ unless eval_command
335
+ commands = current_command.split(';;')
336
+ if commands.size > 1
337
+ current_command = commands.shift
338
+ @cmd_queue.unshift *commands
339
+ end
340
+ args = current_command.split
341
+ # Expand macros. FIXME: put in a procedure
342
+ while true do
343
+ macro_cmd_name = args[0]
344
+ return false if args.size == 0
345
+ break unless @macros.member?(macro_cmd_name)
346
+ current_command = @macros[macro_cmd_name][0].call(*args[1..-1])
347
+ msg current_command.inspect if settings[:debugmacro]
348
+ if current_command.is_a?(Array) &&
349
+ current_command.all? {|val| val.is_a?(String)}
350
+ args = (first=current_command.shift).split
351
+ @cmd_queue += current_command
352
+ current_command = first
353
+ elsif current_command.is_a?(String)
354
+ args = current_command.split
355
+ else
356
+ errmsg("macro #{macro_cmd_name} should return an Array " +
357
+ "of Strings or a String. Got #{current_command.inspect}")
358
+ return false
359
+ end
360
+ end
361
+
362
+ @cmd_name = args[0]
363
+ run_cmd_name =
364
+ if @aliases.member?(@cmd_name)
365
+ @aliases[@cmd_name]
366
+ else
367
+ @cmd_name
368
+ end
369
+
370
+ run_cmd_name = uniq_abbrev(@commands.keys, run_cmd_name) if
371
+ !@commands.member?(run_cmd_name) && @settings[:abbrev]
372
+
373
+ if @commands.member?(run_cmd_name)
374
+ cmd = @commands[run_cmd_name]
375
+ if ok_for_running(cmd, run_cmd_name, args.size-1)
376
+ @cmd_argstr = current_command[@cmd_name.size..-1].lstrip
377
+ cmd.run(args)
378
+ @last_command = current_command
379
+ end
380
+ return false
381
+ end
382
+ end
383
+
384
+ # Eval anything that's not a command or has been
385
+ # requested to be eval'd
386
+ if settings[:autoeval] || eval_command
387
+ begin
388
+ eval_code(current_command, @settings[:maxstring])
389
+ return false
390
+ rescue NameError
391
+ end
392
+ end
393
+ undefined_command(cmd_name)
394
+ end
395
+
396
+ # Error message when a command doesn't exist
397
+ def undefined_command(cmd_name)
398
+ begin
399
+ errmsg('Undefined command: "%s". Try "help".' % cmd_name)
400
+ rescue
401
+ $stderr.puts 'Undefined command: "%s". Try "help".' % cmd_name
402
+ end
403
+ end
404
+
405
+ # FIXME: Allow access to both Trepan::CmdProcessor and Trepan
406
+ # for index [] and []=.
407
+ # If there is a Trepan::CmdProcessor setting that would take precidence.
408
+ # def settings
409
+ # @settings.merge(@dbgr.settings) # wrong because this doesn't allow []=
410
+ # end
411
+ end
412
+ end
413
+
414
+ if __FILE__ == $0
415
+ $0 = 'foo' # So we don't get here again
416
+ require_relative '../lib/trepanning'
417
+ puts "To be continued...."
418
+ exit
419
+ dbg = Trepan.new(:nx => true)
420
+ cmdproc = dbg.instance_variable_get('@processor')
421
+ cmdproc.msg('I am main')
422
+ cmdproc.errmsg('Whoa!')
423
+ cmds = cmdproc.commands
424
+ p cmdproc.aliases
425
+ p cmdproc.commands.keys.sort
426
+ cmd_name, cmd_obj = cmds.first
427
+ puts cmd_obj.class.const_get(:HELP)
428
+ puts cmd_obj.class.const_get(:SHORT_HELP)
429
+
430
+ cmdproc.instance_variable_set('@current_thread', Thread.current)
431
+ puts cmdproc.compute_prompt
432
+ Thread.new{ puts cmdproc.compute_prompt }.join
433
+
434
+ x = Thread.new{ Thread.pass; x = 1 }
435
+ puts cmdproc.compute_prompt
436
+ x.join
437
+ cmdproc.debug_nest += 1
438
+ puts cmdproc.compute_prompt
439
+
440
+ # if ARGV.size > 0
441
+ # cmdproc.msg('Enter "q" to quit')
442
+ # cmdproc.process_commands
443
+ # else
444
+ # $input = []
445
+ # class << cmdproc
446
+ # def read_command
447
+ # $input.shift
448
+ # end
449
+ # end
450
+ # $input = ['1+2']
451
+ # cmdproc.process_command_and_quit?
452
+ # $input = ['!s = 5'] # ! means eval line
453
+ # cmdproc.process_command_and_quit?
454
+ # end
455
+ end
data/processor/mock.rb ADDED
@@ -0,0 +1,136 @@
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Mock setup for commands.
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative 'virtual'
5
+
6
+ # require_relative '../app/core'
7
+ require_relative '../app/default'
8
+ require_relative '../interface/user' # user interface (includes I/O)
9
+
10
+ require 'ruby-debug-base'; Debugger.start(:init => true)
11
+ require_relative 'processor'
12
+
13
+ module MockDebugger
14
+ class MockDebugger
15
+ attr_accessor :trace_filter # Procs/Methods we ignore.
16
+
17
+ attr_accessor :frame # Actually a "Rubinius::Location object
18
+ attr_accessor :core # access to Debugger::Core instance
19
+ attr_accessor :intf # The way the outside world interfaces with us.
20
+ attr_reader :initial_dir # String. Current directory when program
21
+ # started. Used in restart program.
22
+ attr_accessor :restart_argv # How to restart us, empty or nil.
23
+ # Note restart[0] is typically $0.
24
+ attr_reader :settings # Hash[:symbol] of things you can configure
25
+ attr_accessor :processor
26
+
27
+ # FIXME: move more stuff of here and into Trepan::CmdProcessor
28
+ # These below should go into Trepan::CmdProcessor.
29
+ attr_reader :cmd_argstr, :cmd_name, :current_frame, :completion_proc
30
+
31
+ def initialize(settings={:start_frame=>1})
32
+ @before_cmdloop_hooks = []
33
+ @settings = Trepan::DEFAULT_SETTINGS.merge(settings)
34
+ @intf = [Trepan::UserInterface.new(nil, nil,
35
+ :history_save=>false)]
36
+ # @current_frame = Trepan::Frame.new(context)
37
+ @frames = []
38
+
39
+ @trace_filter = []
40
+
41
+ @completion_proc = Proc.new{|str| str}
42
+
43
+ # Don't allow user commands in mocks.
44
+ ## @core.processor.settings[:user_cmd_dir] = nil
45
+
46
+ end
47
+
48
+ def frame(num)
49
+ @frames[num] ||= caller
50
+ end
51
+ end
52
+
53
+ # Common Mock debugger setup
54
+ def setup(name=nil, show_constants=true)
55
+ unless name
56
+ file = caller.first.split(/:\d/,2).first
57
+ name = File.basename(File.basename(file), '.rb')
58
+ end
59
+
60
+ if ARGV.size > 0 && ARGV[0] == 'debug'
61
+ require_relative '../lib/trepanning'
62
+ dbgr = Trepan.new
63
+ dbgr.debugger
64
+ else
65
+ dbgr = MockDebugger.new(:start_frame=>2)
66
+ end
67
+
68
+ cmdproc = Trepan::CmdProcessor.new(dbgr.intf)
69
+ state = Trepan::CommandProcessor::State.new(self) do |s|
70
+ s.context = Debugger.current_context
71
+ s.binding = binding
72
+ end
73
+ cmdproc.frame_setup(state.context, state)
74
+ dbgr.processor = cmdproc
75
+
76
+ cmdproc.interfaces = dbgr.intf
77
+ cmdproc.load_cmds_initialize
78
+ cmds = cmdproc.commands
79
+ cmd = cmds[name]
80
+ ## cmd.proc.frame_setup
81
+ ## cmd.proc.event = 'debugger-call'
82
+ show_special_class_constants(cmd) if show_constants
83
+
84
+ def cmd.confirm(prompt, default)
85
+ true
86
+ end
87
+ def cmd.msg_nocr(message, opts={})
88
+ print message
89
+ end
90
+
91
+ return dbgr, cmd
92
+ end
93
+ module_function :setup
94
+
95
+ def sub_setup(sub_class, run=true)
96
+ sub_name = sub_class.const_get('PREFIX')
97
+ dbgr, cmd = setup(sub_name[0], false)
98
+ sub_cmd = sub_class.new(cmd)
99
+ sub_cmd.summary_help(sub_cmd.name)
100
+ puts
101
+ sub_cmd.run([cmd.name]) if run
102
+ return sub_cmd
103
+ end
104
+ module_function :sub_setup
105
+
106
+ def subsub_setup(sub_class, subsub_class, run=true)
107
+ subsub_name = subsub_class.const_get('PREFIX')
108
+ dbgr, cmd = setup(subsub_name[0], false)
109
+ sub_cmd = sub_class.new(dbgr.processor, cmd)
110
+ subsub_cmd = subsub_class.new(cmd.proc, sub_cmd, subsub_name.join(''))
111
+ subsub_cmd.run([subsub_cmd.name]) if run
112
+ return subsub_cmd
113
+ end
114
+ module_function :subsub_setup
115
+
116
+ def show_special_class_constants(cmd)
117
+ puts 'ALIASES: %s' % [cmd.class.const_get('ALIASES').inspect] if
118
+ cmd.class.constants.member?(:ALIASES)
119
+ %w(CATEGORY MIN_ARGS MAX_ARGS
120
+ NAME NEED_STACK SHORT_HELP).each do |name|
121
+ puts '%s: %s' % [name, cmd.class.const_get(name).inspect]
122
+ end
123
+ puts '-' * 30
124
+ puts cmd.class.const_get('HELP')
125
+ puts '=' * 30
126
+ end
127
+ module_function :show_special_class_constants
128
+
129
+ end
130
+
131
+ if __FILE__ == $0
132
+ dbgr = MockDebugger::MockDebugger.new
133
+ p dbgr.settings
134
+ puts '=' * 10
135
+ # p dbgr.core.processor.settings
136
+ end
data/processor/msg.rb ADDED
@@ -0,0 +1,61 @@
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # I/O related command processor methods
3
+ require 'rubygems'; require 'require_relative'
4
+ require_relative '../app/util'
5
+ require_relative 'virtual'
6
+ module Trepan
7
+ class CmdProcessor < VirtualCmdProcessor
8
+ attr_accessor :ruby_highlighter
9
+
10
+ def errmsg(message, opts={})
11
+ message = safe_rep(message) unless opts[:unlimited]
12
+ if @settings[:highlight] && defined?(Term::ANSIColor)
13
+ message =
14
+ Term::ANSIColor.italic + message + Term::ANSIColor.reset
15
+ end
16
+ @intf.errmsg(message)
17
+ end
18
+
19
+ def msg(message, opts={})
20
+ message = safe_rep(message) unless opts[:unlimited]
21
+ @intf.msg(message)
22
+ end
23
+
24
+ def msg_nocr(message, opts={})
25
+ message = safe_rep(message) unless opts[:unlimited]
26
+ @intf.msg_nocr(message)
27
+ end
28
+
29
+ def read_command()
30
+ @intf.read_command(@prompt)
31
+ end
32
+
33
+ def ruby_format(text)
34
+ return text unless settings[:highlight]
35
+ unless @ruby_highlighter
36
+ begin
37
+ require 'coderay'
38
+ require 'term/ansicolor'
39
+ @ruby_highlighter = CodeRay::Duo[:ruby, :term]
40
+ rescue LoadError
41
+ return text
42
+ end
43
+ end
44
+ return @ruby_highlighter.encode(text)
45
+ end
46
+
47
+ def safe_rep(str)
48
+ Util::safe_repr(str, @settings[:maxstring])
49
+ end
50
+
51
+ def section(message, opts={})
52
+ message = safe_rep(message) unless opts[:unlimited]
53
+ if @settings[:highlight] && defined?(Term::ANSIColor)
54
+ message =
55
+ Term::ANSIColor.bold + message + Term::ANSIColor.reset
56
+ end
57
+ @intf.msg(message)
58
+ end
59
+
60
+ end
61
+ end