debugger 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. data/AUTHORS +10 -0
  2. data/CHANGES +334 -0
  3. data/ChangeLog +5655 -0
  4. data/INSTALL.SVN +154 -0
  5. data/LICENSE +23 -0
  6. data/Makefile.am +14 -0
  7. data/OLD_README +122 -0
  8. data/README.md +10 -0
  9. data/Rakefile +266 -0
  10. data/autogen.sh +4 -0
  11. data/bin/rdebug +398 -0
  12. data/cli/ruby-debug.rb +173 -0
  13. data/cli/ruby-debug/command.rb +228 -0
  14. data/cli/ruby-debug/commands/breakpoints.rb +153 -0
  15. data/cli/ruby-debug/commands/catchpoint.rb +55 -0
  16. data/cli/ruby-debug/commands/condition.rb +49 -0
  17. data/cli/ruby-debug/commands/continue.rb +38 -0
  18. data/cli/ruby-debug/commands/control.rb +107 -0
  19. data/cli/ruby-debug/commands/display.rb +120 -0
  20. data/cli/ruby-debug/commands/edit.rb +48 -0
  21. data/cli/ruby-debug/commands/enable.rb +202 -0
  22. data/cli/ruby-debug/commands/eval.rb +176 -0
  23. data/cli/ruby-debug/commands/finish.rb +42 -0
  24. data/cli/ruby-debug/commands/frame.rb +301 -0
  25. data/cli/ruby-debug/commands/help.rb +56 -0
  26. data/cli/ruby-debug/commands/info.rb +467 -0
  27. data/cli/ruby-debug/commands/irb.rb +123 -0
  28. data/cli/ruby-debug/commands/jump.rb +66 -0
  29. data/cli/ruby-debug/commands/kill.rb +51 -0
  30. data/cli/ruby-debug/commands/list.rb +94 -0
  31. data/cli/ruby-debug/commands/method.rb +84 -0
  32. data/cli/ruby-debug/commands/quit.rb +39 -0
  33. data/cli/ruby-debug/commands/reload.rb +40 -0
  34. data/cli/ruby-debug/commands/save.rb +90 -0
  35. data/cli/ruby-debug/commands/set.rb +221 -0
  36. data/cli/ruby-debug/commands/show.rb +247 -0
  37. data/cli/ruby-debug/commands/skip.rb +35 -0
  38. data/cli/ruby-debug/commands/source.rb +36 -0
  39. data/cli/ruby-debug/commands/stepping.rb +81 -0
  40. data/cli/ruby-debug/commands/threads.rb +189 -0
  41. data/cli/ruby-debug/commands/tmate.rb +36 -0
  42. data/cli/ruby-debug/commands/trace.rb +57 -0
  43. data/cli/ruby-debug/commands/variables.rb +199 -0
  44. data/cli/ruby-debug/debugger.rb +5 -0
  45. data/cli/ruby-debug/helper.rb +69 -0
  46. data/cli/ruby-debug/interface.rb +232 -0
  47. data/cli/ruby-debug/processor.rb +474 -0
  48. data/configure.ac +12 -0
  49. data/debugger.gemspec +24 -0
  50. data/doc/.cvsignore +42 -0
  51. data/doc/Makefile.am +63 -0
  52. data/doc/emacs-notes.txt +38 -0
  53. data/doc/hanoi.rb +35 -0
  54. data/doc/primes.rb +28 -0
  55. data/doc/rdebug-emacs.texi +1030 -0
  56. data/doc/rdebug.1 +241 -0
  57. data/doc/ruby-debug.texi +3791 -0
  58. data/doc/test-tri2.rb +18 -0
  59. data/doc/tri3.rb +8 -0
  60. data/doc/triangle.rb +12 -0
  61. data/emacs/Makefile.am +130 -0
  62. data/emacs/rdebug-annotate.el +385 -0
  63. data/emacs/rdebug-breaks.el +407 -0
  64. data/emacs/rdebug-cmd.el +92 -0
  65. data/emacs/rdebug-core.el +502 -0
  66. data/emacs/rdebug-dbg.el +62 -0
  67. data/emacs/rdebug-error.el +79 -0
  68. data/emacs/rdebug-fns.el +111 -0
  69. data/emacs/rdebug-frames.el +230 -0
  70. data/emacs/rdebug-gud.el +242 -0
  71. data/emacs/rdebug-help.el +104 -0
  72. data/emacs/rdebug-info.el +83 -0
  73. data/emacs/rdebug-layouts.el +180 -0
  74. data/emacs/rdebug-locring.el +118 -0
  75. data/emacs/rdebug-output.el +106 -0
  76. data/emacs/rdebug-regexp.el +118 -0
  77. data/emacs/rdebug-secondary.el +260 -0
  78. data/emacs/rdebug-shortkey.el +175 -0
  79. data/emacs/rdebug-source.el +568 -0
  80. data/emacs/rdebug-track.el +392 -0
  81. data/emacs/rdebug-varbuf.el +150 -0
  82. data/emacs/rdebug-vars.el +125 -0
  83. data/emacs/rdebug-watch.el +132 -0
  84. data/emacs/rdebug.el +326 -0
  85. data/emacs/test/elk-test.el +242 -0
  86. data/emacs/test/test-annotate.el +103 -0
  87. data/emacs/test/test-cmd.el +116 -0
  88. data/emacs/test/test-core.el +104 -0
  89. data/emacs/test/test-fns.el +65 -0
  90. data/emacs/test/test-frames.el +62 -0
  91. data/emacs/test/test-gud.el +35 -0
  92. data/emacs/test/test-indent.el +58 -0
  93. data/emacs/test/test-regexp.el +144 -0
  94. data/emacs/test/test-shortkey.el +61 -0
  95. data/ext/ruby_debug/breakpoint.c +586 -0
  96. data/ext/ruby_debug/extconf.rb +49 -0
  97. data/ext/ruby_debug/ruby_debug.c +2624 -0
  98. data/ext/ruby_debug/ruby_debug.h +148 -0
  99. data/lib/ChangeLog +1065 -0
  100. data/lib/debugger.rb +7 -0
  101. data/lib/debugger/version.rb +3 -0
  102. data/lib/ruby-debug-base.rb +304 -0
  103. data/rdbg.rb +33 -0
  104. data/runner.sh +7 -0
  105. data/svn2cl_usermap +3 -0
  106. data/test/.cvsignore +1 -0
  107. data/test/base/base.rb +74 -0
  108. data/test/base/binding.rb +31 -0
  109. data/test/base/catchpoint.rb +26 -0
  110. data/test/base/load.rb +40 -0
  111. data/test/bp_loop_issue.rb +3 -0
  112. data/test/classes.rb +11 -0
  113. data/test/cli/commands/catchpoint_test.rb +36 -0
  114. data/test/cli/commands/unit/regexp.rb +42 -0
  115. data/test/config.yaml +8 -0
  116. data/test/data/annotate.cmd +29 -0
  117. data/test/data/annotate.right +139 -0
  118. data/test/data/break_bad.cmd +18 -0
  119. data/test/data/break_bad.right +28 -0
  120. data/test/data/break_loop_bug.cmd +5 -0
  121. data/test/data/break_loop_bug.right +15 -0
  122. data/test/data/breakpoints.cmd +38 -0
  123. data/test/data/breakpoints.right +98 -0
  124. data/test/data/catch.cmd +20 -0
  125. data/test/data/catch.right +49 -0
  126. data/test/data/catch2.cmd +19 -0
  127. data/test/data/catch2.right +65 -0
  128. data/test/data/catch3.cmd +11 -0
  129. data/test/data/catch3.right +37 -0
  130. data/test/data/condition.cmd +28 -0
  131. data/test/data/condition.right +65 -0
  132. data/test/data/ctrl.cmd +23 -0
  133. data/test/data/ctrl.right +70 -0
  134. data/test/data/display.cmd +24 -0
  135. data/test/data/display.right +44 -0
  136. data/test/data/dollar-0.right +2 -0
  137. data/test/data/dollar-0a.right +2 -0
  138. data/test/data/dollar-0b.right +2 -0
  139. data/test/data/edit.cmd +12 -0
  140. data/test/data/edit.right +19 -0
  141. data/test/data/emacs_basic.cmd +43 -0
  142. data/test/data/emacs_basic.right +106 -0
  143. data/test/data/enable.cmd +20 -0
  144. data/test/data/enable.right +36 -0
  145. data/test/data/finish.cmd +16 -0
  146. data/test/data/finish.right +31 -0
  147. data/test/data/frame.cmd +26 -0
  148. data/test/data/frame.right +55 -0
  149. data/test/data/help.cmd +20 -0
  150. data/test/data/help.right +21 -0
  151. data/test/data/history.right +7 -0
  152. data/test/data/info-thread.cmd +13 -0
  153. data/test/data/info-thread.right +37 -0
  154. data/test/data/info-var-bug2.cmd +5 -0
  155. data/test/data/info-var-bug2.right +10 -0
  156. data/test/data/info-var.cmd +23 -0
  157. data/test/data/info-var.right +52 -0
  158. data/test/data/info.cmd +21 -0
  159. data/test/data/info.right +65 -0
  160. data/test/data/jump.cmd +16 -0
  161. data/test/data/jump.right +56 -0
  162. data/test/data/jump2.cmd +16 -0
  163. data/test/data/jump2.right +44 -0
  164. data/test/data/linetrace.cmd +6 -0
  165. data/test/data/linetrace.right +23 -0
  166. data/test/data/list.cmd +19 -0
  167. data/test/data/list.right +127 -0
  168. data/test/data/method.cmd +10 -0
  169. data/test/data/method.right +21 -0
  170. data/test/data/methodsig.cmd +10 -0
  171. data/test/data/methodsig.right +20 -0
  172. data/test/data/next.cmd +22 -0
  173. data/test/data/next.right +61 -0
  174. data/test/data/noquit.right +1 -0
  175. data/test/data/output.cmd +6 -0
  176. data/test/data/output.right +31 -0
  177. data/test/data/pm-bug.cmd +7 -0
  178. data/test/data/pm-bug.right +12 -0
  179. data/test/data/post-mortem-next.cmd +8 -0
  180. data/test/data/post-mortem-next.right +14 -0
  181. data/test/data/post-mortem-osx.right +31 -0
  182. data/test/data/post-mortem.cmd +13 -0
  183. data/test/data/post-mortem.right +32 -0
  184. data/test/data/quit.cmd +6 -0
  185. data/test/data/quit.right +0 -0
  186. data/test/data/raise.cmd +11 -0
  187. data/test/data/raise.right +23 -0
  188. data/test/data/save.cmd +34 -0
  189. data/test/data/save.right +59 -0
  190. data/test/data/scope-var.cmd +42 -0
  191. data/test/data/scope-var.right +587 -0
  192. data/test/data/setshow.cmd +56 -0
  193. data/test/data/setshow.right +98 -0
  194. data/test/data/source.cmd +5 -0
  195. data/test/data/source.right +15 -0
  196. data/test/data/stepping.cmd +21 -0
  197. data/test/data/stepping.right +50 -0
  198. data/test/data/test-init-cygwin.right +7 -0
  199. data/test/data/test-init-osx.right +4 -0
  200. data/test/data/test-init.right +5 -0
  201. data/test/data/trace.right +14 -0
  202. data/test/dollar-0.rb +5 -0
  203. data/test/gcd-dbg-nox.rb +31 -0
  204. data/test/gcd-dbg.rb +30 -0
  205. data/test/gcd.rb +18 -0
  206. data/test/helper.rb +144 -0
  207. data/test/info-var-bug.rb +47 -0
  208. data/test/info-var-bug2.rb +2 -0
  209. data/test/jump.rb +14 -0
  210. data/test/jump2.rb +27 -0
  211. data/test/next.rb +18 -0
  212. data/test/null.rb +1 -0
  213. data/test/output.rb +2 -0
  214. data/test/pm-base.rb +22 -0
  215. data/test/pm-bug.rb +3 -0
  216. data/test/pm-catch.rb +12 -0
  217. data/test/pm-catch2.rb +27 -0
  218. data/test/pm-catch3.rb +47 -0
  219. data/test/pm.rb +11 -0
  220. data/test/raise.rb +3 -0
  221. data/test/rdebug-save.1 +7 -0
  222. data/test/runall +12 -0
  223. data/test/scope-var.rb +29 -0
  224. data/test/tdebug.rb +248 -0
  225. data/test/test-annotate.rb +25 -0
  226. data/test/test-break-bad.rb +37 -0
  227. data/test/test-breakpoints.rb +25 -0
  228. data/test/test-catch.rb +25 -0
  229. data/test/test-catch2.rb +25 -0
  230. data/test/test-catch3.rb +25 -0
  231. data/test/test-condition.rb +25 -0
  232. data/test/test-ctrl.rb +55 -0
  233. data/test/test-display.rb +26 -0
  234. data/test/test-dollar-0.rb +40 -0
  235. data/test/test-edit.rb +26 -0
  236. data/test/test-emacs-basic.rb +26 -0
  237. data/test/test-enable.rb +25 -0
  238. data/test/test-finish.rb +34 -0
  239. data/test/test-frame.rb +34 -0
  240. data/test/test-help.rb +60 -0
  241. data/test/test-hist.rb +68 -0
  242. data/test/test-info-thread.rb +32 -0
  243. data/test/test-info-var.rb +47 -0
  244. data/test/test-info.rb +26 -0
  245. data/test/test-init.rb +44 -0
  246. data/test/test-jump.rb +35 -0
  247. data/test/test-list.rb +25 -0
  248. data/test/test-method.rb +34 -0
  249. data/test/test-next.rb +25 -0
  250. data/test/test-output.rb +26 -0
  251. data/test/test-quit.rb +30 -0
  252. data/test/test-raise.rb +25 -0
  253. data/test/test-save.rb +31 -0
  254. data/test/test-scope-var.rb +25 -0
  255. data/test/test-setshow.rb +25 -0
  256. data/test/test-source.rb +25 -0
  257. data/test/test-stepping.rb +26 -0
  258. data/test/test-trace.rb +47 -0
  259. data/test/thread1.rb +26 -0
  260. data/test/trunc-call.rb +31 -0
  261. metadata +364 -0
@@ -0,0 +1,7 @@
1
+ module Debugger
2
+ end
3
+ # TODO: merge cli/ into lib/
4
+ $:.unshift File.expand_path(File.dirname(__FILE__) + '/../cli')
5
+
6
+ require 'ruby-debug'
7
+ require 'debugger/version'
@@ -0,0 +1,3 @@
1
+ module Debugger
2
+ VERSION = '1.0.0.rc1'
3
+ end
@@ -0,0 +1,304 @@
1
+ require 'ruby_debug.so'
2
+ require 'rubygems'
3
+ require 'linecache19'
4
+
5
+ module Debugger
6
+
7
+ # Default options to Debugger.start
8
+ DEFAULT_START_SETTINGS = {
9
+ :init => true, # Set $0 and save ARGV?
10
+ :post_mortem => false, # post-mortem debugging on uncaught exception?
11
+ :tracing => nil # Debugger.tracing value. true/false resets,
12
+ # nil keeps the prior value
13
+ } unless defined?(DEFAULT_START_SETTINGS)
14
+
15
+ class Context
16
+ def interrupt
17
+ self.stop_next = 1
18
+ end
19
+
20
+ alias __c_frame_binding frame_binding
21
+ def frame_binding(frame)
22
+ __c_frame_binding(frame) || hbinding(frame)
23
+ end
24
+
25
+ private
26
+
27
+ def hbinding(frame)
28
+ hash = frame_locals(frame)
29
+ code = hash.keys.map{|k| "#{k} = hash['#{k}']" unless k=='self' }.compact.join(';') + ';binding'
30
+ if obj = frame_self(frame)
31
+ obj.instance_eval code
32
+ else
33
+ eval code, TOPLEVEL_BINDING
34
+ end
35
+ end
36
+
37
+ def handler
38
+ Debugger.handler or raise 'No interface loaded'
39
+ end
40
+
41
+ def at_breakpoint(breakpoint)
42
+ handler.at_breakpoint(self, breakpoint)
43
+ end
44
+
45
+ def at_catchpoint(excpt)
46
+ handler.at_catchpoint(self, excpt)
47
+ end
48
+
49
+ def at_tracing(file, line)
50
+ @tracing_started = true if File.identical?(file, File.join(Debugger::INITIAL_DIR, Debugger::PROG_SCRIPT))
51
+ handler.at_tracing(self, file, line) if @tracing_started
52
+ end
53
+
54
+ def at_line(file, line)
55
+ handler.at_line(self, file, line)
56
+ end
57
+
58
+ def at_return(file, line)
59
+ handler.at_return(self, file, line)
60
+ end
61
+ end
62
+
63
+ @reload_source_on_change = false
64
+ @tracing_started = false
65
+
66
+ class << self
67
+ # interface modules provide +handler+ object
68
+ attr_accessor :handler
69
+
70
+ # if <tt>true</tt>, checks the modification time of source files and reloads if it was modified
71
+ attr_accessor :reload_source_on_change
72
+
73
+ attr_accessor :last_exception
74
+ Debugger.last_exception = nil
75
+
76
+ #
77
+ # Interrupts the current thread
78
+ #
79
+ def interrupt
80
+ current_context.interrupt
81
+ end
82
+
83
+ #
84
+ # Interrupts the last debugged thread
85
+ #
86
+ def interrupt_last
87
+ if context = last_context
88
+ return nil unless context.thread.alive?
89
+ context.interrupt
90
+ end
91
+ context
92
+ end
93
+
94
+ def source_reload
95
+ LineCache::clear_file_cache
96
+ end
97
+
98
+ # Get line +line_number+ from file named +filename+. Return "\n"
99
+ # there was a problem. Leaking blanks are stripped off.
100
+ def line_at(filename, line_number) # :nodoc:
101
+ @reload_on_change=nil unless defined?(@reload_on_change)
102
+ line = LineCache::getline(filename, line_number, @reload_on_change)
103
+ return "\n" unless line
104
+ return "#{line.gsub(/^\s+/, '').chomp}\n"
105
+ end
106
+
107
+ #
108
+ # Activates the post-mortem mode. There are two ways of using it:
109
+ #
110
+ # == Global post-mortem mode
111
+ # By calling Debugger.post_mortem method without a block, you install
112
+ # at_exit hook that intercepts any unhandled by your script exceptions
113
+ # and enables post-mortem mode.
114
+ #
115
+ # == Local post-mortem mode
116
+ #
117
+ # If you know that a particular block of code raises an exception you can
118
+ # enable post-mortem mode by wrapping this block with Debugger.post_mortem, e.g.
119
+ #
120
+ # def offender
121
+ # raise 'error'
122
+ # end
123
+ # Debugger.post_mortem do
124
+ # ...
125
+ # offender
126
+ # ...
127
+ # end
128
+ def post_mortem
129
+ if block_given?
130
+ old_post_mortem = self.post_mortem?
131
+ begin
132
+ self.post_mortem = true
133
+ yield
134
+ rescue Exception => exp
135
+ handle_post_mortem(exp)
136
+ raise
137
+ ensure
138
+ self.post_mortem = old_post_mortem
139
+ end
140
+ else
141
+ return if post_mortem?
142
+ self.post_mortem = true
143
+ debug_at_exit do
144
+ handle_post_mortem($!) if $! && post_mortem?
145
+ end
146
+ end
147
+ end
148
+
149
+ def handle_post_mortem(exp)
150
+ return if !exp || !exp.__debug_context ||
151
+ exp.__debug_context.stack_size == 0
152
+ Debugger.suspend
153
+ orig_tracing = Debugger.tracing, Debugger.current_context.tracing
154
+ Debugger.tracing = Debugger.current_context.tracing = false
155
+ Debugger.last_exception = exp
156
+ handler.at_line(exp.__debug_context, exp.__debug_file, exp.__debug_line)
157
+ ensure
158
+ Debugger.tracing, Debugger.current_context.tracing = orig_tracing
159
+ Debugger.resume
160
+ end
161
+ # private :handle_post_mortem
162
+ end
163
+
164
+ class DebugThread # :nodoc:
165
+ end
166
+
167
+ class ThreadsTable # :nodoc:
168
+ end
169
+
170
+ # Debugger.start(options) -> bool
171
+ # Debugger.start(options) { ... } -> obj
172
+ #
173
+ # If it's called without a block it returns +true+, unless debugger
174
+ # was already started. If a block is given, it starts debugger and
175
+ # yields to block. When the block is finished executing it stops
176
+ # the debugger with Debugger.stop method.
177
+ #
178
+ # If a block is given, it starts debugger and yields to block. When
179
+ # the block is finished executing it stops the debugger with
180
+ # Debugger.stop method. Inside the block you will probably want to
181
+ # have a call to Debugger.debugger. For example:
182
+ #
183
+ # Debugger.start{debugger; foo} # Stop inside of foo
184
+ #
185
+ # Also, ruby-debug only allows
186
+ # one invocation of debugger at a time; nested Debugger.start's
187
+ # have no effect and you can't use this inside the debugger itself.
188
+ #
189
+ # <i>Note that if you want to stop debugger, you must call
190
+ # Debugger.stop as many time as you called Debugger.start
191
+ # method.</i>
192
+ #
193
+ # +options+ is a hash used to set various debugging options.
194
+ # Set :init true if you want to save ARGV and some variables which
195
+ # make a debugger restart possible. Only the first time :init is set true
196
+ # will values get set. Since ARGV is saved, you should make sure
197
+ # it hasn't been changed before the (first) call.
198
+ # Set :post_mortem true if you want to enter post-mortem debugging
199
+ # on an uncaught exception. Once post-mortem debugging is set, it can't
200
+ # be unset.
201
+ def start(options={}, &block)
202
+ options = Debugger::DEFAULT_START_SETTINGS.merge(options)
203
+ if options[:init]
204
+ Debugger.const_set('ARGV', ARGV.clone) unless
205
+ defined? Debugger::ARGV
206
+ Debugger.const_set('PROG_SCRIPT', $0) unless
207
+ defined? Debugger::PROG_SCRIPT
208
+ Debugger.const_set('INITIAL_DIR', Dir.pwd) unless
209
+ defined? Debugger::INITIAL_DIR
210
+ end
211
+ Debugger.tracing = options[:tracing] unless options[:tracing].nil?
212
+ retval = Debugger.started? ? block && block.call(self) : Debugger.start_(&block)
213
+ if options[:post_mortem]
214
+ post_mortem
215
+ end
216
+ return retval
217
+ end
218
+ module_function :start
219
+ end
220
+
221
+ module Kernel
222
+
223
+ # Enters the debugger in the current thread after _steps_ line events occur.
224
+ # Before entering the debugger startup script is read.
225
+ #
226
+ # Setting _steps_ to 0 will cause a break in the debugger subroutine
227
+ # and not wait for a line event to occur. You will have to go "up 1"
228
+ # in order to be back in your debugged program rather than the
229
+ # debugger. Settings _steps_ to 0 could be useful you want to stop
230
+ # right after the last statement in some scope, because the next
231
+ # step will take you out of some scope.
232
+
233
+ # If a block is given (and the debugger hasn't been started, we run the
234
+ # block under the debugger. Alas, when a block is given, we can't support
235
+ # running the startup script or support the steps option. FIXME.
236
+ def debugger(steps = 1, &block)
237
+ if block
238
+ Debugger.start({}, &block)
239
+ else
240
+ Debugger.start unless Debugger.started?
241
+ Debugger.run_init_script(StringIO.new)
242
+ if 0 == steps
243
+ Debugger.current_context.stop_frame = 0
244
+ else
245
+ Debugger.current_context.stop_next = steps
246
+ end
247
+ end
248
+ end
249
+ alias breakpoint debugger unless respond_to?(:breakpoint)
250
+
251
+ #
252
+ # Returns a binding of n-th call frame
253
+ #
254
+ def binding_n(n = 0)
255
+ Debugger.skip do
256
+ if RUBY_VERSION < "1.9"
257
+ Debugger.current_context.frame_binding(n+2)
258
+ else
259
+ Debugger.current_context.frame_binding(n+1)
260
+ end
261
+ end
262
+ end
263
+ end
264
+
265
+ class Exception # :nodoc:
266
+ attr_reader :__debug_file, :__debug_line, :__debug_binding, :__debug_context
267
+ end
268
+
269
+ class Module
270
+ #
271
+ # Wraps the +meth+ method with Debugger.start {...} block.
272
+ #
273
+ def debug_method(meth)
274
+ old_meth = "__debugee_#{meth}"
275
+ old_meth = "#{$1}_set" if old_meth =~ /^(.+)=$/
276
+ alias_method old_meth.to_sym, meth
277
+ class_eval <<-EOD
278
+ def #{meth}(*args, &block)
279
+ Debugger.start do
280
+ debugger 2
281
+ #{old_meth}(*args, &block)
282
+ end
283
+ end
284
+ EOD
285
+ end
286
+
287
+ #
288
+ # Wraps the +meth+ method with Debugger.post_mortem {...} block.
289
+ #
290
+ def post_mortem_method(meth)
291
+ old_meth = "__postmortem_#{meth}"
292
+ old_meth = "#{$1}_set" if old_meth =~ /^(.+)=$/
293
+ alias_method old_meth.to_sym, meth
294
+ class_eval <<-EOD
295
+ def #{meth}(*args, &block)
296
+ Debugger.start do |dbg|
297
+ dbg.post_mortem do
298
+ #{old_meth}(*args, &block)
299
+ end
300
+ end
301
+ end
302
+ EOD
303
+ end
304
+ end
data/rdbg.rb ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ #!/usr/bin/env ruby
3
+ # $Id: rdbg.rb 756 2008-03-13 02:15:04Z rockyb $
4
+
5
+ # Use this to run rdebug without installing it. We assume that the
6
+ # library directories are stored at the same level the directory
7
+ # this program.
8
+ module RDebugRunner
9
+ def runner(stdout=nil)
10
+
11
+ # Add libraries to load path.
12
+ dirname=File.dirname(__FILE__)
13
+ libs = %w(ext lib cli)
14
+ libs.each { |lib| $:.unshift File.join(dirname, lib) }
15
+
16
+ rdebug=ENV['RDEBUG'] || File.join(dirname, 'bin', 'rdebug')
17
+ if stdout
18
+ old_stdout = $stdout
19
+ $stdout.reopen(stdout)
20
+ else
21
+ old_stdout = nil
22
+ end
23
+ load(rdebug, true)
24
+ $stdout.reopen(old_stdout) if old_stdout
25
+
26
+ # Remove those libraries we just added.
27
+ 1.upto(libs.size) {$:.shift}
28
+ end
29
+ module_function :runner
30
+ end
31
+ if __FILE__ == $0
32
+ RDebugRunner.runner
33
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ruby=${RUBY:-ruby}
4
+ dir=`dirname $0`
5
+ rdebug=${RDEBUG:-${dir}/bin/rdebug}
6
+ $ruby -I${dir}/ext:${dir}/lib:${dir}/cli -- $rdebug $*
7
+ exit $?
@@ -0,0 +1,3 @@
1
+ andersl:Anders Lindgren
2
+ kent:Kent Sibilev
3
+ rockyb:Rocky Bernstein
@@ -0,0 +1 @@
1
+ config.private.yaml
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+
4
+ # Some tests of Debugger module in C extension ruby_debug
5
+ class TestRubyDebug < Test::Unit::TestCase
6
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'ext')
7
+ require 'ruby_debug'
8
+ $:.shift
9
+
10
+ # test current_context
11
+ def test_current_context
12
+ assert_equal(false, Debugger.started?,
13
+ 'debugger should not initially be started.')
14
+ Debugger.start_
15
+ assert(Debugger.started?,
16
+ 'debugger should now be started.')
17
+ assert_equal(__LINE__, Debugger.current_context.frame_line)
18
+ assert_equal(nil, Debugger.current_context.frame_args_info,
19
+ 'no frame args info.')
20
+ assert_equal(Debugger.current_context.frame_file,
21
+ Debugger.current_context.frame_file(0))
22
+ assert_equal(File.basename(__FILE__),
23
+ File.basename(Debugger.current_context.frame_file))
24
+ assert_raises(ArgumentError) {Debugger.current_context.frame_file(1, 2)}
25
+ assert_raises(ArgumentError) {Debugger.current_context.frame_file(10)}
26
+ assert_equal(1, Debugger.current_context.stack_size)
27
+ assert_equal(TestRubyDebug, Debugger.current_context.frame_class)
28
+ assert_equal(false, Debugger.current_context.dead?, 'Not dead yet!')
29
+ Debugger.stop
30
+ assert_equal(false, Debugger.started?,
31
+ 'Debugger should no longer be started.')
32
+ end
33
+
34
+ # Test initial variables and setting/getting state.
35
+ def test_debugger_base
36
+ assert_equal(false, Debugger.started?,
37
+ 'Debugger should not initially be started.')
38
+ Debugger.start_
39
+ assert(Debugger.started?,
40
+ 'Debugger should now be started.')
41
+ assert_equal(false, Debugger.debug,
42
+ 'Debug variable should not be set.')
43
+ assert_equal(false, Debugger.post_mortem?,
44
+ 'Post mortem debugging should not be set.')
45
+ a = Debugger.contexts
46
+ assert_equal(1, a.size,
47
+ 'There should only be one context.')
48
+ assert_equal(Array, a.class,
49
+ 'Context should be an array.')
50
+ Debugger.stop
51
+ assert_equal(false, Debugger.started?,
52
+ 'debugger should no longer be started.')
53
+ end
54
+
55
+ # Test breakpoint handling
56
+ def test_breakpoints
57
+ Debugger.start_
58
+ assert_equal(0, Debugger.breakpoints.size,
59
+ 'There should not be any breakpoints set.')
60
+ brk = Debugger.add_breakpoint(__FILE__, 1)
61
+ assert_equal(Debugger::Breakpoint, brk.class,
62
+ 'Breakpoint should have been set and returned.')
63
+ assert_equal(1, Debugger.breakpoints.size,
64
+ 'There should now be one breakpoint set.')
65
+ Debugger.remove_breakpoint(0)
66
+ assert_equal(1, Debugger.breakpoints.size,
67
+ 'There should still be one breakpoint set.')
68
+ Debugger.remove_breakpoint(1)
69
+ assert_equal(0, Debugger.breakpoints.size,
70
+ 'There should no longer be any breakpoints set.')
71
+ Debugger.stop
72
+ end
73
+ end
74
+
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+
5
+ # Test binding_n command
6
+ class TestBinding < Test::Unit::TestCase
7
+
8
+ SRC_DIR = File.expand_path(File.dirname(__FILE__)) unless
9
+ defined?(SRC_DIR)
10
+ %w(ext lib).each do |dir|
11
+ $:.unshift File.join(SRC_DIR, '..', '..', dir)
12
+ end
13
+ require File.join(SRC_DIR, '..', '..', 'lib', 'ruby-debug-base')
14
+ $:.shift; $:.shift
15
+
16
+ def test_basic
17
+ def inside_fn
18
+ s = 'some other string'
19
+ b2 = Kernel::binding_n(1)
20
+ y2 = eval('s', b2)
21
+ assert_equal('this is a test', y2)
22
+ end
23
+ s = 'this is a test'
24
+ Debugger.start
25
+ b = Kernel::binding_n(0)
26
+ y = eval('s', b)
27
+ assert_equal(y, s)
28
+ inside_fn
29
+ Debugger.stop
30
+ end
31
+ end