rbx-trepanning 0.0.5-universal-rubinius-1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. data/ChangeLog +2002 -0
  2. data/LICENSE +25 -0
  3. data/NEWS +31 -0
  4. data/README.textile +34 -0
  5. data/Rakefile +165 -0
  6. data/THANKS +14 -0
  7. data/app/breakpoint.rb +219 -0
  8. data/app/breakpoint.rbc +3551 -0
  9. data/app/brkptmgr.rb +140 -0
  10. data/app/brkptmgr.rbc +2903 -0
  11. data/app/client.rb +61 -0
  12. data/app/client.rbc +1225 -0
  13. data/app/complete.rb +52 -0
  14. data/app/complete.rbc +1288 -0
  15. data/app/default.rb +71 -0
  16. data/app/default.rbc +1132 -0
  17. data/app/display.rb +148 -0
  18. data/app/display.rbc +2578 -0
  19. data/app/frame.rb +98 -0
  20. data/app/frame.rbc +1808 -0
  21. data/app/irb.rb +111 -0
  22. data/app/irb.rbc +2094 -0
  23. data/app/iseq.rb +117 -0
  24. data/app/iseq.rbc +2192 -0
  25. data/app/llvm.rbc +2478 -0
  26. data/app/method.rb +173 -0
  27. data/app/method.rbc +2492 -0
  28. data/app/method_name.rbc +2467 -0
  29. data/app/mock.rb +13 -0
  30. data/app/mock.rbc +398 -0
  31. data/app/options.rb +137 -0
  32. data/app/options.rbc +2898 -0
  33. data/app/rbx-llvm.rb +165 -0
  34. data/app/rbx-llvm.rbc +2478 -0
  35. data/app/run.rb +86 -0
  36. data/app/run.rbc +1244 -0
  37. data/app/util.rb +49 -0
  38. data/app/util.rbc +1146 -0
  39. data/app/validate.rb +30 -0
  40. data/app/validate.rbc +676 -0
  41. data/bin/trepan.compiled.rbc +1043 -0
  42. data/bin/trepanx +69 -0
  43. data/bin/trepanx.compiled.rbc +1049 -0
  44. data/data/irbrc +41 -0
  45. data/data/irbrc.compiled.rbc +640 -0
  46. data/interface/base_intf.rb +105 -0
  47. data/interface/base_intf.rbc +1899 -0
  48. data/interface/client.rb +80 -0
  49. data/interface/client.rbc +1072 -0
  50. data/interface/comcodes.rb +20 -0
  51. data/interface/comcodes.rbc +385 -0
  52. data/interface/script.rb +104 -0
  53. data/interface/script.rbc +1642 -0
  54. data/interface/server.rb +143 -0
  55. data/interface/server.rbc +2213 -0
  56. data/interface/user.rb +150 -0
  57. data/interface/user.rbc +2867 -0
  58. data/io/base_io.rb +148 -0
  59. data/io/base_io.rbc +2111 -0
  60. data/io/input.rb +135 -0
  61. data/io/input.rbc +2528 -0
  62. data/io/null_output.rb +42 -0
  63. data/io/null_output.rbc +730 -0
  64. data/io/string_array.rb +156 -0
  65. data/io/string_array.rbc +2466 -0
  66. data/io/tcpclient.rb +129 -0
  67. data/io/tcpclient.rbc +2419 -0
  68. data/io/tcpfns.rb +33 -0
  69. data/io/tcpfns.rbc +694 -0
  70. data/io/tcpserver.rb +141 -0
  71. data/io/tcpserver.rbc +2638 -0
  72. data/lib/trepanning.rb +474 -0
  73. data/lib/trepanning.rbc +7705 -0
  74. data/lib/trepanning2.rb +441 -0
  75. data/processor/breakpoint.rb +164 -0
  76. data/processor/command/alias.rb +55 -0
  77. data/processor/command/backtrace.rb +76 -0
  78. data/processor/command/base/cmd.rb +173 -0
  79. data/processor/command/base/subcmd.rb +229 -0
  80. data/processor/command/base/submgr.rb +182 -0
  81. data/processor/command/base/subsubcmd.rb +103 -0
  82. data/processor/command/base/subsubmgr.rb +195 -0
  83. data/processor/command/break.rb +100 -0
  84. data/processor/command/complete.rb +37 -0
  85. data/processor/command/continue.rb +91 -0
  86. data/processor/command/delete.rb +30 -0
  87. data/processor/command/directory.rb +51 -0
  88. data/processor/command/disassemble.rb +145 -0
  89. data/processor/command/display.rb +82 -0
  90. data/processor/command/down.rb +54 -0
  91. data/processor/command/eval.rb +51 -0
  92. data/processor/command/exit.rb +62 -0
  93. data/processor/command/finish.rb +80 -0
  94. data/processor/command/frame.rb +89 -0
  95. data/processor/command/help.rb +251 -0
  96. data/processor/command/info.rb +28 -0
  97. data/processor/command/info_subcmd/breakpoints.rb +73 -0
  98. data/processor/command/info_subcmd/files.rb +209 -0
  99. data/processor/command/info_subcmd/line.rb +86 -0
  100. data/processor/command/info_subcmd/method.rb +71 -0
  101. data/processor/command/info_subcmd/program.rb +49 -0
  102. data/processor/command/info_subcmd/ruby.rb +62 -0
  103. data/processor/command/info_subcmd/variables.rb +48 -0
  104. data/processor/command/irb.rb +128 -0
  105. data/processor/command/kill.rb +70 -0
  106. data/processor/command/list.rb +300 -0
  107. data/processor/command/macro.rb +76 -0
  108. data/processor/command/next.rb +66 -0
  109. data/processor/command/nexti.rb +59 -0
  110. data/processor/command/pr.rb +38 -0
  111. data/processor/command/ps.rb +40 -0
  112. data/processor/command/restart.rb +60 -0
  113. data/processor/command/server.rb +72 -0
  114. data/processor/command/set.rb +47 -0
  115. data/processor/command/set_subcmd/auto.rb +27 -0
  116. data/processor/command/set_subcmd/auto_subcmd/dis.rb +33 -0
  117. data/processor/command/set_subcmd/auto_subcmd/eval.rb +54 -0
  118. data/processor/command/set_subcmd/auto_subcmd/irb.rb +34 -0
  119. data/processor/command/set_subcmd/auto_subcmd/list.rb +34 -0
  120. data/processor/command/set_subcmd/basename.rb +25 -0
  121. data/processor/command/set_subcmd/confirm.rb +24 -0
  122. data/processor/command/set_subcmd/debug.rb +26 -0
  123. data/processor/command/set_subcmd/debug_subcmd/dbgr.rb +36 -0
  124. data/processor/command/set_subcmd/debug_subcmd/skip.rb +23 -0
  125. data/processor/command/set_subcmd/debug_subcmd/step.rb +23 -0
  126. data/processor/command/set_subcmd/different.rb +59 -0
  127. data/processor/command/set_subcmd/hidelevel.rb +62 -0
  128. data/processor/command/set_subcmd/highlight.rb +33 -0
  129. data/processor/command/set_subcmd/kernelstep.rb +60 -0
  130. data/processor/command/set_subcmd/max.rb +26 -0
  131. data/processor/command/set_subcmd/max_subcmd/list.rb +49 -0
  132. data/processor/command/set_subcmd/max_subcmd/stack.rb +50 -0
  133. data/processor/command/set_subcmd/max_subcmd/string.rb +76 -0
  134. data/processor/command/set_subcmd/max_subcmd/width.rb +49 -0
  135. data/processor/command/set_subcmd/substitute.rb +24 -0
  136. data/processor/command/set_subcmd/substitute_subcmd/path.rb +56 -0
  137. data/processor/command/set_subcmd/trace.rb +36 -0
  138. data/processor/command/set_subcmd/trace_subcmd/print.rb +57 -0
  139. data/processor/command/show.rb +38 -0
  140. data/processor/command/show_subcmd/alias.rb +42 -0
  141. data/processor/command/show_subcmd/args.rb +25 -0
  142. data/processor/command/show_subcmd/auto.rb +28 -0
  143. data/processor/command/show_subcmd/auto_subcmd/dis.rb +37 -0
  144. data/processor/command/show_subcmd/auto_subcmd/eval.rb +28 -0
  145. data/processor/command/show_subcmd/auto_subcmd/irb.rb +23 -0
  146. data/processor/command/show_subcmd/auto_subcmd/list.rb +22 -0
  147. data/processor/command/show_subcmd/basename.rb +20 -0
  148. data/processor/command/show_subcmd/confirm.rb +18 -0
  149. data/processor/command/show_subcmd/debug.rb +26 -0
  150. data/processor/command/show_subcmd/debug_subcmd/dbgr.rb +21 -0
  151. data/processor/command/show_subcmd/debug_subcmd/skip.rb +22 -0
  152. data/processor/command/show_subcmd/debug_subcmd/step.rb +22 -0
  153. data/processor/command/show_subcmd/different.rb +26 -0
  154. data/processor/command/show_subcmd/hidelevel.rb +41 -0
  155. data/processor/command/show_subcmd/highlight.rb +24 -0
  156. data/processor/command/show_subcmd/kernelstep.rb +34 -0
  157. data/processor/command/show_subcmd/max.rb +27 -0
  158. data/processor/command/show_subcmd/max_subcmd/list.rb +38 -0
  159. data/processor/command/show_subcmd/max_subcmd/stack.rb +36 -0
  160. data/processor/command/show_subcmd/max_subcmd/string.rb +42 -0
  161. data/processor/command/show_subcmd/max_subcmd/width.rb +37 -0
  162. data/processor/command/show_subcmd/trace.rb +27 -0
  163. data/processor/command/show_subcmd/trace_subcmd/print.rb +38 -0
  164. data/processor/command/show_subcmd/version.rb +23 -0
  165. data/processor/command/source.rb +126 -0
  166. data/processor/command/step.rb +84 -0
  167. data/processor/command/tbreak.rb +19 -0
  168. data/processor/command/unalias.rb +44 -0
  169. data/processor/command/undisplay.rb +59 -0
  170. data/processor/command/up.rb +86 -0
  171. data/processor/default.rb +58 -0
  172. data/processor/disassemble.rb +46 -0
  173. data/processor/display.rb +18 -0
  174. data/processor/eval.rb +96 -0
  175. data/processor/frame.rb +211 -0
  176. data/processor/help.rb +72 -0
  177. data/processor/hook.rb +133 -0
  178. data/processor/load_cmds.rb +185 -0
  179. data/processor/location.rb +137 -0
  180. data/processor/main.rb +412 -0
  181. data/processor/mock.rb +144 -0
  182. data/processor/msg.rb +43 -0
  183. data/processor/running.rb +234 -0
  184. data/processor/stepping.rb +114 -0
  185. data/processor/subcmd.rb +161 -0
  186. data/processor/validate.rb +355 -0
  187. data/sample/list-terminal-colors.rb +139 -0
  188. data/sample/list-terminal-colors.rbc +2318 -0
  189. data/sample/rocky-dot-trepanxrc +14 -0
  190. data/sample/rocky-trepanx-colors.rb +47 -0
  191. data/sample/rocky-trepanx-colors.rbc +530 -0
  192. data/test/data/enable.right +36 -0
  193. data/test/data/fname-with-blank.cmd +6 -0
  194. data/test/data/fname-with-blank.right +4 -0
  195. data/test/data/inline-call.cmd +6 -0
  196. data/test/data/inline-call.right +13 -0
  197. data/test/data/quit-Xdebug.right +3 -0
  198. data/test/data/quit.cmd +5 -0
  199. data/test/data/quit.right +2 -0
  200. data/test/data/quit2.cmd +6 -0
  201. data/test/data/quit2.right +3 -0
  202. data/test/data/step-bug.cmd +11 -0
  203. data/test/data/step-bug.right +3 -0
  204. data/test/example/fname with blank.rb +1 -0
  205. data/test/example/gcd-server.rb +22 -0
  206. data/test/example/gcd.rb +19 -0
  207. data/test/example/inline-call.rb +23 -0
  208. data/test/example/null.rb +1 -0
  209. data/test/example/step-bug.rb +14 -0
  210. data/test/example/thread1.rb +3 -0
  211. data/test/functional/fn_helper.rb +112 -0
  212. data/test/functional/test-break-name.rb +52 -0
  213. data/test/functional/test-break.rb +51 -0
  214. data/test/functional/test-finish.rb +70 -0
  215. data/test/functional/test-fn_helper.rb +43 -0
  216. data/test/functional/test-list.rb +55 -0
  217. data/test/functional/test-next-bug.rb +49 -0
  218. data/test/functional/test-next.rb +101 -0
  219. data/test/functional/test-step.rb +272 -0
  220. data/test/functional/test-step2.rb +35 -0
  221. data/test/functional/test-tbreak.rb +41 -0
  222. data/test/integration/file-diff.rb +89 -0
  223. data/test/integration/helper.rb +78 -0
  224. data/test/integration/skip-test-step-bug.rb +17 -0
  225. data/test/integration/test-fname-with-blank.rb +16 -0
  226. data/test/integration/test-inline-call.rb +20 -0
  227. data/test/integration/test-quit.rb +47 -0
  228. data/test/unit/cmd-helper.rb +50 -0
  229. data/test/unit/mock-helper.rb +10 -0
  230. data/test/unit/test-app-brkpt.rb +29 -0
  231. data/test/unit/test-app-brkptmgr.rb +51 -0
  232. data/test/unit/test-app-iseq.rb +64 -0
  233. data/test/unit/test-app-method.rb +54 -0
  234. data/test/unit/test-app-options.rb +82 -0
  235. data/test/unit/test-app-run.rb +16 -0
  236. data/test/unit/test-app-util.rb +27 -0
  237. data/test/unit/test-app-validate.rb +18 -0
  238. data/test/unit/test-base-cmd.rb +47 -0
  239. data/test/unit/test-base-subcmd.rb +61 -0
  240. data/test/unit/test-base-submgr.rb +24 -0
  241. data/test/unit/test-bin-trepanx.rb +48 -0
  242. data/test/unit/test-cmd-alias.rb +48 -0
  243. data/test/unit/test-cmd-break.rb +22 -0
  244. data/test/unit/test-cmd-exit.rb +27 -0
  245. data/test/unit/test-cmd-finish.rb +27 -0
  246. data/test/unit/test-cmd-help.rb +104 -0
  247. data/test/unit/test-cmd-kill.rb +47 -0
  248. data/test/unit/test-cmd-source.rb +34 -0
  249. data/test/unit/test-cmd-step.rb +29 -0
  250. data/test/unit/test-completion.rb +38 -0
  251. data/test/unit/test-intf-user.rb +46 -0
  252. data/test/unit/test-io-input.rb +27 -0
  253. data/test/unit/test-io-tcp.rb +33 -0
  254. data/test/unit/test-io-tcpclient.rb +54 -0
  255. data/test/unit/test-io-tcpfns.rb +17 -0
  256. data/test/unit/test-io-tcpserver.rb +50 -0
  257. data/test/unit/test-proc-eval.rb +36 -0
  258. data/test/unit/test-proc-frame.rb +79 -0
  259. data/test/unit/test-proc-help.rb +16 -0
  260. data/test/unit/test-proc-hook.rb +30 -0
  261. data/test/unit/test-proc-load_cmds.rb +50 -0
  262. data/test/unit/test-proc-location.rb +53 -0
  263. data/test/unit/test-proc-main.rb +99 -0
  264. data/test/unit/test-proc-validate.rb +91 -0
  265. data/test/unit/test-subcmd-help.rb +47 -0
  266. metadata +398 -0
@@ -0,0 +1,144 @@
1
+ # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
2
+ # Mock setup for commands.
3
+ require 'rubygems'; require 'require_relative'
4
+
5
+ require_relative 'main'
6
+
7
+ # require_relative '../app/core'
8
+ require_relative '../app/default'
9
+ require_relative '../app/frame'
10
+ require_relative '../interface/user' # user interface (includes I/O)
11
+
12
+ module MockDebugger
13
+ class MockDebugger
14
+ attr_accessor :trace_filter # Procs/Methods we ignore.
15
+
16
+ attr_accessor :frame # Actually a "Rubinius::Location object
17
+ attr_accessor :core # access to Debugger::Core instance
18
+ attr_accessor :intf # The way the outside world interfaces with us.
19
+ attr_reader :initial_dir # String. Current directory when program
20
+ # started. Used in restart program.
21
+ attr_accessor :restart_argv # How to restart us, empty or nil.
22
+ # Note restart[0] is typically $0.
23
+ attr_reader :settings # Hash[:symbol] of things you can configure
24
+ attr_accessor :processor
25
+
26
+ # FIXME: move more stuff of here and into Trepan::CmdProcessor
27
+ # These below should go into Trepan::CmdProcessor.
28
+ attr_reader :cmd_argstr, :cmd_name, :vm_locations, :current_frame,
29
+ :debugee_thread, :completion_proc
30
+
31
+ def initialize(settings={})
32
+ @before_cmdloop_hooks = []
33
+ @settings = Trepan::DEFAULT_SETTINGS.merge(settings)
34
+ @intf = [Trepan::UserInterface.new(nil, nil,
35
+ :history_save=>false)]
36
+ @vm_locations = Rubinius::VM.backtrace(1, true)
37
+ @current_frame = Trepan::Frame.new(self, 0, @vm_locations[0])
38
+ @debugee_thread = Thread.current
39
+ @frames = []
40
+ @restart_argv = Rubinius::OS_STARTUP_DIR
41
+
42
+ ## @core = Trepan::Core.new(self)
43
+ @trace_filter = []
44
+
45
+ @completion_proc = Proc.new{|str| str}
46
+
47
+ # Don't allow user commands in mocks.
48
+ ## @core.processor.settings[:user_cmd_dir] = nil
49
+
50
+ end
51
+
52
+ def frame(num)
53
+ @frames[num] ||= Trepan::Frame.new(self, num, @vm_locations[num])
54
+ end
55
+ end
56
+
57
+ # Common Mock debugger setup
58
+ def setup(name=nil, show_constants=true)
59
+ unless name
60
+ loc = Rubinius::VM.backtrace(1, true)[0]
61
+ name = File.basename(loc.file, '.rb')
62
+ end
63
+
64
+ if ARGV.size > 0 && ARGV[0] == 'debug'
65
+ require_relative '../lib/trepanning'
66
+ dbgr = Trepan.new
67
+ dbgr.debugger
68
+ else
69
+ dbgr = MockDebugger.new
70
+ end
71
+
72
+ cmdproc = Trepan::CmdProcessor.new(dbgr)
73
+ cmdproc.frame = dbgr.frame(0)
74
+ dbgr.processor = cmdproc
75
+
76
+ cmdproc.load_cmds_initialize
77
+ cmds = cmdproc.commands
78
+ cmd = cmds[name]
79
+ cmd.proc.frame_setup
80
+ cmd.proc.event = 'debugger-call'
81
+ show_special_class_constants(cmd) if show_constants
82
+
83
+ def cmd.confirm(prompt, default)
84
+ true
85
+ end
86
+ def cmd.errmsg(message, opts={})
87
+ puts "Error: #{message}"
88
+ end
89
+ def cmd.msg(message, opts={})
90
+ puts message
91
+ end
92
+ def cmd.msg_nocr(message, opts={})
93
+ print message
94
+ end
95
+ def cmd.section(message, opts={})
96
+ puts "Section: #{message}"
97
+ end
98
+
99
+ return dbgr, cmd
100
+ end
101
+ module_function :setup
102
+
103
+ def sub_setup(sub_class, run=true)
104
+ sub_name = sub_class.const_get('PREFIX')
105
+ dbgr, cmd = setup(sub_name[0], false)
106
+ sub_cmd = sub_class.new(cmd)
107
+ sub_cmd.summary_help(sub_cmd.name)
108
+ puts
109
+ sub_cmd.run([cmd.name]) if run
110
+ return sub_cmd
111
+ end
112
+ module_function :sub_setup
113
+
114
+ def subsub_setup(sub_class, subsub_class, run=true)
115
+ subsub_name = subsub_class.const_get('PREFIX')
116
+ dbgr, cmd = setup(subsub_name[0], false)
117
+ sub_cmd = sub_class.new(dbgr.processor, cmd)
118
+ subsub_cmd = subsub_class.new(cmd.proc, sub_cmd, subsub_name.join(''))
119
+ subsub_cmd.run([subsub_cmd.name]) if run
120
+ return subsub_cmd
121
+ end
122
+ module_function :subsub_setup
123
+
124
+ def show_special_class_constants(cmd)
125
+ puts 'ALIASES: %s' % [cmd.class.const_get('ALIASES').inspect] if
126
+ cmd.class.constants.member?(:ALIASES)
127
+ %w(CATEGORY MIN_ARGS MAX_ARGS
128
+ NAME NEED_STACK SHORT_HELP).each do |name|
129
+ puts '%s: %s' % [name, cmd.class.const_get(name).inspect]
130
+ end
131
+ puts '-' * 30
132
+ puts cmd.class.const_get('HELP')
133
+ puts '=' * 30
134
+ end
135
+ module_function :show_special_class_constants
136
+
137
+ end
138
+
139
+ if __FILE__ == $0
140
+ dbgr = MockDebugger::MockDebugger.new
141
+ p dbgr.settings
142
+ puts '=' * 10
143
+ # p dbgr.core.processor.settings
144
+ end
@@ -0,0 +1,43 @@
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
+ class Trepan
6
+ class CmdProcessor
7
+ def errmsg(message, opts={})
8
+ message = safe_rep(message) unless opts[:unlimited]
9
+ if @settings[:highlight] && defined?(Term::ANSIColor)
10
+ message =
11
+ Term::ANSIColor.italic + message + Term::ANSIColor.reset
12
+ end
13
+ @dbgr.intf[-1].errmsg(message)
14
+ end
15
+
16
+ def msg(message, opts={})
17
+ message = safe_rep(message) unless opts[:unlimited]
18
+ @dbgr.intf[-1].msg(message)
19
+ end
20
+
21
+ def msg_nocr(message, opts={})
22
+ message = safe_rep(message) unless opts[:unlimited]
23
+ @dbgr.intf[-1].msg_nocr(message)
24
+ end
25
+
26
+ def read_command()
27
+ @dbgr.intf[-1].read_command(@prompt)
28
+ end
29
+
30
+ def safe_rep(str)
31
+ Util::safe_repr(str, @settings[:maxstring])
32
+ end
33
+
34
+ def section(message, opts={})
35
+ message = safe_rep(message) unless opts[:unlimited]
36
+ if @settings[:highlight] && defined?(Term::ANSIColor)
37
+ message =
38
+ Term::ANSIColor.bold + message + Term::ANSIColor.reset
39
+ end
40
+ @dbgr.intf[-1].msg(message)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,234 @@
1
+ # Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.net>
2
+ require 'rubygems'; require 'require_relative'
3
+ require 'set'
4
+ ## require_relative '../app/core'
5
+ class Trepan
6
+ class CmdProcessor
7
+
8
+
9
+ attr_accessor :ignore_file_re # Hash[file_re] -> String
10
+ # action. File re's we don't want
11
+ # to stop while stepping. Like
12
+ # ignore_methods. Skipping kernel methods
13
+ # is handled this way.
14
+ attr_accessor :ignore_methods # Hash[CompiledMethod] -> String:
15
+ # action. Methods we don't want to
16
+ # ever stop while stepping. action
17
+ # is 'step' or 'next'.
18
+ attr_accessor :stop_condition # String or nil. When not nil
19
+ # this has to eval non-nil
20
+ # in order to stop.
21
+ attr_accessor :stop_events # Set or nil. If not nil, only
22
+ # events in this set will be
23
+ # considered for stopping. This is
24
+ # like core.step_events (which
25
+ # could be used instead), but it is
26
+ # a set of event names rather than
27
+ # a bitmask and it is intended to
28
+ # be more temporarily changed via
29
+ # "step>" or "step!" commands.
30
+ attr_accessor :step_count
31
+ attr_accessor :to_method
32
+
33
+ # # Does whatever needs to be done to set to continue program
34
+ # # execution.
35
+ # # FIXME: turn line_number into a condition.
36
+
37
+ def continue(return_to_program)
38
+ @next_thread = nil
39
+ @step_count = -1 # No more event stepping
40
+ if 'step-finish' == return_to_program
41
+ step_to_return_or_yield
42
+ return_to_program = 'step'
43
+ end
44
+ @return_to_program = return_to_program
45
+ end
46
+
47
+ # Does whatever setup needs to be done to set to ignore stepping
48
+ # to the finish of the current method. Elsewhere in
49
+ # "skipping_step?" we do the checking.
50
+ def finish(level_count=0, opts={})
51
+ step_to_return_or_yield
52
+ continue('finish')
53
+ @next_thread = @current_thread
54
+
55
+ @step_count = 2 if 'nostack' == opts[:different_pos]
56
+
57
+ # # Try high-speed (run-time-assisted) method
58
+ # @frame.trace_off = true # No more tracing in this frame
59
+ # @frame.return_stop = true # don't need to
60
+ end
61
+
62
+ def step_finish
63
+ step_to_return_or_yield
64
+ continue('step')
65
+ @next_thread = @current_thread
66
+ end
67
+
68
+ # # Does whatever needs to be done to set to "next" program
69
+ # # execution.
70
+ # def next(step_count=1, opts={})
71
+ # step(step_count, opts)
72
+ # @next_thread = Thread.current
73
+ # end
74
+
75
+ # Does whatever needs to be done to set to step program
76
+ # execution.
77
+ def step(return_to_program, step_count=1, opts={}, condition=nil)
78
+ continue(return_to_program)
79
+ @step_count = step_count
80
+ @different_pos = opts[:different_pos] if
81
+ opts.keys.member?(:different_pos)
82
+ @stop_condition = condition
83
+ @stop_events = opts[:stop_events] if
84
+ opts.keys.member?(:stop_events)
85
+ @to_method = opts[:to_method]
86
+ end
87
+
88
+ def quit(cmd='exit')
89
+ @next_level = 32000 # I'm guessing the stack size can't
90
+ # ever reach this
91
+ @next_thread = nil
92
+ @step_count = -1 # No more event stepping
93
+ @leave_cmd_loop = true # Break out of the processor command loop.
94
+ @settings[:autoirb] = false
95
+ @cmdloop_prehooks.delete_by_name('autoirb')
96
+ @commands['exit'].run([cmd])
97
+ end
98
+
99
+ def parse_next_step_suffix(step_cmd)
100
+ opts = {}
101
+ case step_cmd[-1..-1]
102
+ when '-'
103
+ opts[:different_pos] = false
104
+ when '+'
105
+ opts[:different_pos] = 'nostack'
106
+ when '='
107
+ opts[:different_pos] = true
108
+ when '!'
109
+ opts[:stop_events] = Set.new(%w(raise))
110
+ when '<'
111
+ opts[:stop_events] = Set.new(%w(c-return return))
112
+ when '>'
113
+ opts[:stop_events] = Set.new(%w(c-call call))
114
+ if step_cmd.size > 1 && step_cmd[-2..-2] == '<'
115
+ opts[:stop_events] = Set.new(%w(c-call c-return call return))
116
+ else
117
+ opts[:stop_events] = Set.new(%w(c-call call))
118
+ end
119
+ end
120
+ return opts
121
+ end
122
+
123
+ def running_initialize
124
+ @ignore_file_re = {}
125
+ @ignore_methods = {}
126
+
127
+ @step_count = 0
128
+ @stop_condition = nil
129
+ @stop_events = nil
130
+ @to_method = nil
131
+ end
132
+
133
+ # If we are not in some kind of steppable event, return
134
+ # false. If we are in a steppable event, update step state
135
+ # and return true if the step count is 0 and other conditions
136
+ # like the @settings[:different] are met.
137
+ def stepping_skip?
138
+
139
+ debug_loc = "#{frame.vm_location.describe} #{frame.line}" if
140
+ @settings[:debugskip]
141
+
142
+ if @step_count < 0
143
+ # We may eventually stop for some other reason, but it's not
144
+ # because we were stepping here.
145
+ msg "skip: step_count < 0 #{debug_loc}" if @settings[:debugskip]
146
+ return false
147
+ end
148
+
149
+ @ignore_file_re.each_pair do |file_re, action|
150
+ if frame.vm_location.method.active_path =~ file_re
151
+ @return_to_program = action
152
+ msg "skip re: #{debug_loc}" if @settings[:debugskip]
153
+ return true
154
+ end
155
+ end
156
+
157
+ ms = frame.method.scope
158
+ @ignore_methods.each do |m, val|
159
+ # Guard against crap put into @ignore_methods
160
+ unless m.respond_to?(:scope)
161
+ @ignore_methods.delete(m)
162
+ next
163
+ end
164
+ if ms == m.scope
165
+ msg "skip ignore method: #{debug_loc}" if @settings[:debugskip]
166
+ @return_to_program = val
167
+ return true
168
+ end
169
+ end
170
+
171
+ # Only skip on these kinds of events
172
+ unless %w(step-call line return).include?(@event)
173
+ msg "skip non-line: #{@event} #{debug_loc}" if @settings[:debugskip]
174
+ return false
175
+ end
176
+
177
+ # We are in some kind of stepping event, so do whatever we
178
+ # do to record that we've hit the step. Whether we decide
179
+ # to stop, will be done after recording the step took place.
180
+ @step_count -= 1 unless step_count == 0
181
+ new_pos = [@frame.file, @frame.line,
182
+ @stack_size, @current_thread, @event]
183
+
184
+
185
+ # Decide whether this step is skippable.
186
+ should_skip = false
187
+
188
+ if @settings[:debugskip]
189
+ msg("last: #{@last_pos.inspect}, ")
190
+ msg("new: #{new_pos.inspect}")
191
+ msg("skip: #{should_skip.inspect}, event: #{@event}")
192
+ msg("@step_count: #{@step_count}")
193
+ end
194
+
195
+ @last_pos[2] = new_pos[2] if 'nostack' == @different_pos
196
+ condition_met = @step_count == 0
197
+
198
+ # if @stop_condition
199
+ # puts 'stop_cond' if @settings[:'debugskip']
200
+ # debug_eval_no_errmsg(@stop_condition)
201
+ # elsif @to_method
202
+ # puts "method #{@frame.method} #{@to_method}" if
203
+ # @settings[:'debugskip']
204
+ # @frame.method == @to_method
205
+ # else
206
+ # puts 'uncond' if @settings[:'debugskip']
207
+ # true
208
+ # end
209
+
210
+ # msg("condition_met: #{condition_met}, last: #{@last_pos}, " +
211
+ # "new: #{new_pos}, different #{@different_pos.inspect}") if
212
+ # @settings[:'debugskip']
213
+
214
+ should_skip = ((@last_pos[0..3] == new_pos[0..3] && @different_pos) ||
215
+ !condition_met)
216
+
217
+ msg("should_skip: #{should_skip}, #{debug_loc}") if @settings[:debugskip]
218
+
219
+ @last_pos = new_pos
220
+
221
+ unless should_skip
222
+ # Set up the default values for the
223
+ # next time we consider step skipping.
224
+ @different_pos = @settings[:different]
225
+ # @stop_events = nil
226
+ end
227
+
228
+ @return_to_program = 'step' if should_skip &&
229
+ (!@return_to_program || 'finish' == @return_to_program)
230
+ return should_skip
231
+ end
232
+
233
+ end
234
+ end
@@ -0,0 +1,114 @@
1
+ require 'rubygems'; require 'require_relative'
2
+ require_relative '../app/iseq'
3
+ class Trepan
4
+ class CmdProcessor
5
+
6
+ # It might be interesting to allow stepping within a parent frame
7
+ def step_over_by(step, frame=@top_frame)
8
+
9
+ f = frame
10
+
11
+ meth = f.method
12
+ possible_line = f.line + step
13
+ next_ip = f.next_ip == f.ip ? f.next_ip + 1 : f.next_ip
14
+ # BUGGY: remove after writing a decent test case for this.
15
+ # See beginning of rbx-require/require_relative.
16
+ fin_ip = meth.first_ip_on_line_after(possible_line, f.next_ip)
17
+ # fin_ip = meth.first_ip_on_line_after(possible_line, next_ip)
18
+
19
+ unless fin_ip
20
+ return step_to_parent('line')
21
+ end
22
+
23
+ set_breakpoints_between(meth, f.next_ip, fin_ip)
24
+ end
25
+
26
+ def step_to_return_or_yield
27
+ f = @frame
28
+ unless f
29
+ msg 'Unable to find frame to finish'
30
+ return
31
+ end
32
+
33
+ meth = f.method
34
+ fin_ip = meth.lines.last
35
+
36
+ set_breakpoints_on_return_between(meth, f.next_ip, fin_ip)
37
+ end
38
+
39
+ def step_to_parent(event='return')
40
+ f = parent_frame
41
+ unless f
42
+ errmsg "Unable to find parent frame to step to next"
43
+ return nil
44
+ end
45
+ meth = f.method
46
+ ip = f.ip
47
+
48
+ bp = Breakpoint.for_ip(meth, ip, {:event => event, :temp => true})
49
+ bp.scoped!(parent_frame.scope)
50
+ bp.activate
51
+
52
+ return bp
53
+ end
54
+
55
+ # Sets temporary breakpoints in met between start_ip and fin_ip.
56
+ # We also set a temporary breakpoint in the caller.
57
+ def set_breakpoints_between(meth, start_ip, fin_ip)
58
+ opts = {:event => 'line', :temp => true}
59
+ ips = ISeq.goto_between(meth, start_ip, fin_ip)
60
+ bps = []
61
+
62
+ if ips.kind_of? Fixnum
63
+ if ips == -1
64
+ errmsg "No place to step to"
65
+ return nil
66
+ elsif ips == -2
67
+ bps << step_to_parent(event='line')
68
+ ips = []
69
+ else
70
+ ips = [ips]
71
+ end
72
+ end
73
+
74
+ msg "temp ips: #{ips.inspect}" if settings[:debugstep]
75
+ ips.each do |ip|
76
+ bp = Breakpoint.for_ip(meth, ip, opts)
77
+ bp.scoped!(@frame.scope)
78
+ bp.activate
79
+ bps << bp
80
+ end
81
+ first_bp = bps[0]
82
+ bps[1..-1].each do |bp|
83
+ first_bp.related_with(bp)
84
+ end
85
+ return first_bp
86
+ end
87
+
88
+ def set_breakpoints_on_return_between(meth, start_ip, fin_ip)
89
+ ips = ISeq::yield_or_return_between(meth, start_ip, fin_ip)
90
+ if ips.empty?
91
+ errmsg '"ret" or "yield_stack" opcode not found'
92
+ return []
93
+ end
94
+
95
+ bp1 = Breakpoint.for_ip(meth, ips[0],
96
+ { :event => 'return',
97
+ :temp => true})
98
+ bp1.scoped!(@frame.scope)
99
+ bp1.activate
100
+ result = [bp1]
101
+
102
+ 1.upto(ips.size-1) do |i|
103
+ bp2 = Breakpoint.for_ip(meth, ips[i],
104
+ { :event => 'return',
105
+ :temp => true})
106
+ bp2.scoped!(@frame.scope)
107
+ bp1.related_with(bp2)
108
+ bp2.activate
109
+ result << bp2
110
+ end
111
+ return result
112
+ end
113
+ end
114
+ end