debugger 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +10 -0
- data/CHANGES +334 -0
- data/ChangeLog +5655 -0
- data/INSTALL.SVN +154 -0
- data/LICENSE +23 -0
- data/Makefile.am +14 -0
- data/OLD_README +122 -0
- data/README.md +10 -0
- data/Rakefile +266 -0
- data/autogen.sh +4 -0
- data/bin/rdebug +398 -0
- data/cli/ruby-debug.rb +173 -0
- data/cli/ruby-debug/command.rb +228 -0
- data/cli/ruby-debug/commands/breakpoints.rb +153 -0
- data/cli/ruby-debug/commands/catchpoint.rb +55 -0
- data/cli/ruby-debug/commands/condition.rb +49 -0
- data/cli/ruby-debug/commands/continue.rb +38 -0
- data/cli/ruby-debug/commands/control.rb +107 -0
- data/cli/ruby-debug/commands/display.rb +120 -0
- data/cli/ruby-debug/commands/edit.rb +48 -0
- data/cli/ruby-debug/commands/enable.rb +202 -0
- data/cli/ruby-debug/commands/eval.rb +176 -0
- data/cli/ruby-debug/commands/finish.rb +42 -0
- data/cli/ruby-debug/commands/frame.rb +301 -0
- data/cli/ruby-debug/commands/help.rb +56 -0
- data/cli/ruby-debug/commands/info.rb +467 -0
- data/cli/ruby-debug/commands/irb.rb +123 -0
- data/cli/ruby-debug/commands/jump.rb +66 -0
- data/cli/ruby-debug/commands/kill.rb +51 -0
- data/cli/ruby-debug/commands/list.rb +94 -0
- data/cli/ruby-debug/commands/method.rb +84 -0
- data/cli/ruby-debug/commands/quit.rb +39 -0
- data/cli/ruby-debug/commands/reload.rb +40 -0
- data/cli/ruby-debug/commands/save.rb +90 -0
- data/cli/ruby-debug/commands/set.rb +221 -0
- data/cli/ruby-debug/commands/show.rb +247 -0
- data/cli/ruby-debug/commands/skip.rb +35 -0
- data/cli/ruby-debug/commands/source.rb +36 -0
- data/cli/ruby-debug/commands/stepping.rb +81 -0
- data/cli/ruby-debug/commands/threads.rb +189 -0
- data/cli/ruby-debug/commands/tmate.rb +36 -0
- data/cli/ruby-debug/commands/trace.rb +57 -0
- data/cli/ruby-debug/commands/variables.rb +199 -0
- data/cli/ruby-debug/debugger.rb +5 -0
- data/cli/ruby-debug/helper.rb +69 -0
- data/cli/ruby-debug/interface.rb +232 -0
- data/cli/ruby-debug/processor.rb +474 -0
- data/configure.ac +12 -0
- data/debugger.gemspec +24 -0
- data/doc/.cvsignore +42 -0
- data/doc/Makefile.am +63 -0
- data/doc/emacs-notes.txt +38 -0
- data/doc/hanoi.rb +35 -0
- data/doc/primes.rb +28 -0
- data/doc/rdebug-emacs.texi +1030 -0
- data/doc/rdebug.1 +241 -0
- data/doc/ruby-debug.texi +3791 -0
- data/doc/test-tri2.rb +18 -0
- data/doc/tri3.rb +8 -0
- data/doc/triangle.rb +12 -0
- data/emacs/Makefile.am +130 -0
- data/emacs/rdebug-annotate.el +385 -0
- data/emacs/rdebug-breaks.el +407 -0
- data/emacs/rdebug-cmd.el +92 -0
- data/emacs/rdebug-core.el +502 -0
- data/emacs/rdebug-dbg.el +62 -0
- data/emacs/rdebug-error.el +79 -0
- data/emacs/rdebug-fns.el +111 -0
- data/emacs/rdebug-frames.el +230 -0
- data/emacs/rdebug-gud.el +242 -0
- data/emacs/rdebug-help.el +104 -0
- data/emacs/rdebug-info.el +83 -0
- data/emacs/rdebug-layouts.el +180 -0
- data/emacs/rdebug-locring.el +118 -0
- data/emacs/rdebug-output.el +106 -0
- data/emacs/rdebug-regexp.el +118 -0
- data/emacs/rdebug-secondary.el +260 -0
- data/emacs/rdebug-shortkey.el +175 -0
- data/emacs/rdebug-source.el +568 -0
- data/emacs/rdebug-track.el +392 -0
- data/emacs/rdebug-varbuf.el +150 -0
- data/emacs/rdebug-vars.el +125 -0
- data/emacs/rdebug-watch.el +132 -0
- data/emacs/rdebug.el +326 -0
- data/emacs/test/elk-test.el +242 -0
- data/emacs/test/test-annotate.el +103 -0
- data/emacs/test/test-cmd.el +116 -0
- data/emacs/test/test-core.el +104 -0
- data/emacs/test/test-fns.el +65 -0
- data/emacs/test/test-frames.el +62 -0
- data/emacs/test/test-gud.el +35 -0
- data/emacs/test/test-indent.el +58 -0
- data/emacs/test/test-regexp.el +144 -0
- data/emacs/test/test-shortkey.el +61 -0
- data/ext/ruby_debug/breakpoint.c +586 -0
- data/ext/ruby_debug/extconf.rb +49 -0
- data/ext/ruby_debug/ruby_debug.c +2624 -0
- data/ext/ruby_debug/ruby_debug.h +148 -0
- data/lib/ChangeLog +1065 -0
- data/lib/debugger.rb +7 -0
- data/lib/debugger/version.rb +3 -0
- data/lib/ruby-debug-base.rb +304 -0
- data/rdbg.rb +33 -0
- data/runner.sh +7 -0
- data/svn2cl_usermap +3 -0
- data/test/.cvsignore +1 -0
- data/test/base/base.rb +74 -0
- data/test/base/binding.rb +31 -0
- data/test/base/catchpoint.rb +26 -0
- data/test/base/load.rb +40 -0
- data/test/bp_loop_issue.rb +3 -0
- data/test/classes.rb +11 -0
- data/test/cli/commands/catchpoint_test.rb +36 -0
- data/test/cli/commands/unit/regexp.rb +42 -0
- data/test/config.yaml +8 -0
- data/test/data/annotate.cmd +29 -0
- data/test/data/annotate.right +139 -0
- data/test/data/break_bad.cmd +18 -0
- data/test/data/break_bad.right +28 -0
- data/test/data/break_loop_bug.cmd +5 -0
- data/test/data/break_loop_bug.right +15 -0
- data/test/data/breakpoints.cmd +38 -0
- data/test/data/breakpoints.right +98 -0
- data/test/data/catch.cmd +20 -0
- data/test/data/catch.right +49 -0
- data/test/data/catch2.cmd +19 -0
- data/test/data/catch2.right +65 -0
- data/test/data/catch3.cmd +11 -0
- data/test/data/catch3.right +37 -0
- data/test/data/condition.cmd +28 -0
- data/test/data/condition.right +65 -0
- data/test/data/ctrl.cmd +23 -0
- data/test/data/ctrl.right +70 -0
- data/test/data/display.cmd +24 -0
- data/test/data/display.right +44 -0
- data/test/data/dollar-0.right +2 -0
- data/test/data/dollar-0a.right +2 -0
- data/test/data/dollar-0b.right +2 -0
- data/test/data/edit.cmd +12 -0
- data/test/data/edit.right +19 -0
- data/test/data/emacs_basic.cmd +43 -0
- data/test/data/emacs_basic.right +106 -0
- data/test/data/enable.cmd +20 -0
- data/test/data/enable.right +36 -0
- data/test/data/finish.cmd +16 -0
- data/test/data/finish.right +31 -0
- data/test/data/frame.cmd +26 -0
- data/test/data/frame.right +55 -0
- data/test/data/help.cmd +20 -0
- data/test/data/help.right +21 -0
- data/test/data/history.right +7 -0
- data/test/data/info-thread.cmd +13 -0
- data/test/data/info-thread.right +37 -0
- data/test/data/info-var-bug2.cmd +5 -0
- data/test/data/info-var-bug2.right +10 -0
- data/test/data/info-var.cmd +23 -0
- data/test/data/info-var.right +52 -0
- data/test/data/info.cmd +21 -0
- data/test/data/info.right +65 -0
- data/test/data/jump.cmd +16 -0
- data/test/data/jump.right +56 -0
- data/test/data/jump2.cmd +16 -0
- data/test/data/jump2.right +44 -0
- data/test/data/linetrace.cmd +6 -0
- data/test/data/linetrace.right +23 -0
- data/test/data/list.cmd +19 -0
- data/test/data/list.right +127 -0
- data/test/data/method.cmd +10 -0
- data/test/data/method.right +21 -0
- data/test/data/methodsig.cmd +10 -0
- data/test/data/methodsig.right +20 -0
- data/test/data/next.cmd +22 -0
- data/test/data/next.right +61 -0
- data/test/data/noquit.right +1 -0
- data/test/data/output.cmd +6 -0
- data/test/data/output.right +31 -0
- data/test/data/pm-bug.cmd +7 -0
- data/test/data/pm-bug.right +12 -0
- data/test/data/post-mortem-next.cmd +8 -0
- data/test/data/post-mortem-next.right +14 -0
- data/test/data/post-mortem-osx.right +31 -0
- data/test/data/post-mortem.cmd +13 -0
- data/test/data/post-mortem.right +32 -0
- data/test/data/quit.cmd +6 -0
- data/test/data/quit.right +0 -0
- data/test/data/raise.cmd +11 -0
- data/test/data/raise.right +23 -0
- data/test/data/save.cmd +34 -0
- data/test/data/save.right +59 -0
- data/test/data/scope-var.cmd +42 -0
- data/test/data/scope-var.right +587 -0
- data/test/data/setshow.cmd +56 -0
- data/test/data/setshow.right +98 -0
- data/test/data/source.cmd +5 -0
- data/test/data/source.right +15 -0
- data/test/data/stepping.cmd +21 -0
- data/test/data/stepping.right +50 -0
- data/test/data/test-init-cygwin.right +7 -0
- data/test/data/test-init-osx.right +4 -0
- data/test/data/test-init.right +5 -0
- data/test/data/trace.right +14 -0
- data/test/dollar-0.rb +5 -0
- data/test/gcd-dbg-nox.rb +31 -0
- data/test/gcd-dbg.rb +30 -0
- data/test/gcd.rb +18 -0
- data/test/helper.rb +144 -0
- data/test/info-var-bug.rb +47 -0
- data/test/info-var-bug2.rb +2 -0
- data/test/jump.rb +14 -0
- data/test/jump2.rb +27 -0
- data/test/next.rb +18 -0
- data/test/null.rb +1 -0
- data/test/output.rb +2 -0
- data/test/pm-base.rb +22 -0
- data/test/pm-bug.rb +3 -0
- data/test/pm-catch.rb +12 -0
- data/test/pm-catch2.rb +27 -0
- data/test/pm-catch3.rb +47 -0
- data/test/pm.rb +11 -0
- data/test/raise.rb +3 -0
- data/test/rdebug-save.1 +7 -0
- data/test/runall +12 -0
- data/test/scope-var.rb +29 -0
- data/test/tdebug.rb +248 -0
- data/test/test-annotate.rb +25 -0
- data/test/test-break-bad.rb +37 -0
- data/test/test-breakpoints.rb +25 -0
- data/test/test-catch.rb +25 -0
- data/test/test-catch2.rb +25 -0
- data/test/test-catch3.rb +25 -0
- data/test/test-condition.rb +25 -0
- data/test/test-ctrl.rb +55 -0
- data/test/test-display.rb +26 -0
- data/test/test-dollar-0.rb +40 -0
- data/test/test-edit.rb +26 -0
- data/test/test-emacs-basic.rb +26 -0
- data/test/test-enable.rb +25 -0
- data/test/test-finish.rb +34 -0
- data/test/test-frame.rb +34 -0
- data/test/test-help.rb +60 -0
- data/test/test-hist.rb +68 -0
- data/test/test-info-thread.rb +32 -0
- data/test/test-info-var.rb +47 -0
- data/test/test-info.rb +26 -0
- data/test/test-init.rb +44 -0
- data/test/test-jump.rb +35 -0
- data/test/test-list.rb +25 -0
- data/test/test-method.rb +34 -0
- data/test/test-next.rb +25 -0
- data/test/test-output.rb +26 -0
- data/test/test-quit.rb +30 -0
- data/test/test-raise.rb +25 -0
- data/test/test-save.rb +31 -0
- data/test/test-scope-var.rb +25 -0
- data/test/test-setshow.rb +25 -0
- data/test/test-source.rb +25 -0
- data/test/test-stepping.rb +26 -0
- data/test/test-trace.rb +47 -0
- data/test/thread1.rb +26 -0
- data/test/trunc-call.rb +31 -0
- metadata +364 -0
data/lib/debugger.rb
ADDED
@@ -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
|
data/runner.sh
ADDED
data/svn2cl_usermap
ADDED
data/test/.cvsignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
config.private.yaml
|
data/test/base/base.rb
ADDED
@@ -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
|