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
@@ -0,0 +1,47 @@
|
|
1
|
+
class Lousy_inspect
|
2
|
+
attr_accessor :var
|
3
|
+
def inspect # An unhelpful inspect
|
4
|
+
throw "Foo" # Raises an exception
|
5
|
+
end
|
6
|
+
def initialize
|
7
|
+
@var = 'initialized'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
class Lousy_inspect_and_to_s
|
11
|
+
attr_accessor :var
|
12
|
+
def inspect # An unhelpful inspect
|
13
|
+
throw "Foo" # Raises an exception
|
14
|
+
end
|
15
|
+
def to_s # An unhelpful to_s
|
16
|
+
throw "bar" # Raises an exception
|
17
|
+
end
|
18
|
+
def initialize
|
19
|
+
@var = 'initialized' # Something to inspect
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Something that will be passed objects with
|
24
|
+
# bad inspect or to_s methods
|
25
|
+
class UnsuspectingClass
|
26
|
+
@@Const = 'A constant'
|
27
|
+
@@var = 'a class variable'
|
28
|
+
def initialize(a)
|
29
|
+
@a = a # "info locals" will try to use
|
30
|
+
# inspect or to_s here
|
31
|
+
@b = 5
|
32
|
+
end
|
33
|
+
end
|
34
|
+
def test_Lousy_inspect
|
35
|
+
x = Lousy_inspect.new
|
36
|
+
x
|
37
|
+
end
|
38
|
+
def test_lousy_inspect_and_to_s
|
39
|
+
x = Lousy_inspect_and_to_s.new
|
40
|
+
x
|
41
|
+
end
|
42
|
+
x = test_Lousy_inspect
|
43
|
+
y = test_lousy_inspect_and_to_s
|
44
|
+
UnsuspectingClass.new(10)
|
45
|
+
UnsuspectingClass.new(x)
|
46
|
+
UnsuspectingClass.new(y)
|
47
|
+
y = 2
|
data/test/jump.rb
ADDED
data/test/jump2.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
def foo3(arg)
|
2
|
+
arg = arg + 3
|
3
|
+
puts arg
|
4
|
+
arg = arg/0 if arg > 10
|
5
|
+
rescue
|
6
|
+
puts "r3"
|
7
|
+
end
|
8
|
+
|
9
|
+
def foo2(arg)
|
10
|
+
arg = arg + 2
|
11
|
+
foo3(arg)
|
12
|
+
puts arg
|
13
|
+
rescue
|
14
|
+
puts "r2"
|
15
|
+
end
|
16
|
+
|
17
|
+
def foo1(arg)
|
18
|
+
arg = arg + 1
|
19
|
+
foo2(arg)
|
20
|
+
puts arg
|
21
|
+
rescue
|
22
|
+
puts "r1"
|
23
|
+
end
|
24
|
+
|
25
|
+
foo1(0)
|
26
|
+
foo2(10)
|
27
|
+
puts "done"
|
data/test/next.rb
ADDED
data/test/null.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Nothing here. Move along.
|
data/test/output.rb
ADDED
data/test/pm-base.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Test post-mortem handling using only ruby-debug-base.
|
3
|
+
src_dir = File.dirname(__FILE__)
|
4
|
+
%w(ext lib cli).each do |dir|
|
5
|
+
$:.unshift File.join(src_dir, '..', dir)
|
6
|
+
end
|
7
|
+
require 'ruby-debug-base'
|
8
|
+
|
9
|
+
class CommandProcessor
|
10
|
+
def at_line(context, file, line)
|
11
|
+
puts 'file: %s, line: %s' % [ File.basename(file), line ]
|
12
|
+
exit!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Debugger.start(:post_mortem => true)
|
17
|
+
Debugger.handler = CommandProcessor.new
|
18
|
+
def zero_div
|
19
|
+
1/0
|
20
|
+
end
|
21
|
+
zero_div
|
22
|
+
|
data/test/pm-bug.rb
ADDED
data/test/pm-catch.rb
ADDED
data/test/pm-catch2.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Test Debugger.catchpoint
|
3
|
+
def bar(arg)
|
4
|
+
puts "bar begin"
|
5
|
+
1/0 if arg
|
6
|
+
raise ZeroDivisionError
|
7
|
+
puts "bar end"
|
8
|
+
end
|
9
|
+
|
10
|
+
def foo
|
11
|
+
puts "foo begin"
|
12
|
+
yield 1
|
13
|
+
puts "foo end"
|
14
|
+
rescue ZeroDivisionError
|
15
|
+
puts "rescue"
|
16
|
+
end
|
17
|
+
|
18
|
+
def zero_div(arg)
|
19
|
+
x = 5
|
20
|
+
foo { |i| bar(i) }
|
21
|
+
x + arg
|
22
|
+
rescue ZeroDivisionError
|
23
|
+
"zero_div rescue"
|
24
|
+
end
|
25
|
+
|
26
|
+
puts zero_div(10)
|
27
|
+
puts "done"
|
data/test/pm-catch3.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Test catching uncaught exceptions
|
3
|
+
def get_exception(arg)
|
4
|
+
result = case arg
|
5
|
+
when 0 then LoadError
|
6
|
+
when 1 then ZeroDivisionError
|
7
|
+
when 2 then NoMethodError
|
8
|
+
else RuntimeError
|
9
|
+
end
|
10
|
+
return result
|
11
|
+
end
|
12
|
+
|
13
|
+
def bar(arg)
|
14
|
+
$var = $var + "bar begin:"
|
15
|
+
1/0 if arg
|
16
|
+
if false
|
17
|
+
raise LoadError
|
18
|
+
end
|
19
|
+
$var = $var + "bar end:"
|
20
|
+
end
|
21
|
+
|
22
|
+
def foo(arg)
|
23
|
+
$var = $var + "foo begin:"
|
24
|
+
yield arg
|
25
|
+
$var = $var + "foo end:"
|
26
|
+
rescue get_exception(0), NameError
|
27
|
+
$var = $var + "foo rescue:"
|
28
|
+
ensure
|
29
|
+
$var = $var + "foo ensure:"
|
30
|
+
end
|
31
|
+
|
32
|
+
def zero_div(arg)
|
33
|
+
x = 5
|
34
|
+
foo(arg) { |i| bar(i) }
|
35
|
+
x + arg
|
36
|
+
rescue get_exception(arg)
|
37
|
+
$var = $var + "zero_div rescue:"
|
38
|
+
return "divide by zero"
|
39
|
+
end
|
40
|
+
|
41
|
+
$var = "start1:"
|
42
|
+
puts zero_div(1)
|
43
|
+
puts $var
|
44
|
+
$var = "start2:"
|
45
|
+
puts zero_div(2)
|
46
|
+
puts $var
|
47
|
+
puts "done"
|
data/test/pm.rb
ADDED
data/test/raise.rb
ADDED
data/test/rdebug-save.1
ADDED
data/test/runall
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#-*- Ruby -*-
|
3
|
+
debug_opt = '-d ' if $DEBUG or 'd' == ARGV[0]
|
4
|
+
for file in Dir.glob("test-*.rb") do
|
5
|
+
puts "=" * 50
|
6
|
+
puts "== running #{file}..."
|
7
|
+
system("ruby #{file}");
|
8
|
+
end
|
9
|
+
if ARGV[0] == "really"
|
10
|
+
system("(cd test && ruby #{debug_opt}runall)")
|
11
|
+
system("(cd examples && ruby #{debug_opt}runall)")
|
12
|
+
end
|
data/test/scope-var.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'ruby_debug'
|
2
|
+
def scope1(arg1, arg2)
|
3
|
+
s1_var1 = 123
|
4
|
+
s1_var2 = "scope1"
|
5
|
+
scope2
|
6
|
+
end
|
7
|
+
|
8
|
+
def scope2
|
9
|
+
s2_var1 = 456
|
10
|
+
s2_var2 = "scope2"
|
11
|
+
0.upto(5) do |i|
|
12
|
+
j = i * 10
|
13
|
+
scope3
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def scope3
|
18
|
+
s3_var1 = 789
|
19
|
+
s3_var2 = "scope3"
|
20
|
+
puts eval("s3_var1", Debugger.current_context.frame_binding(0))
|
21
|
+
puts eval("i", Debugger.current_context.frame_binding(1))
|
22
|
+
puts eval("j", Debugger.current_context.frame_binding(1))
|
23
|
+
puts eval("s2_var1", Debugger.current_context.frame_binding(2))
|
24
|
+
puts eval("s1_var1", Debugger.current_context.frame_binding(3))
|
25
|
+
puts eval("s0_var1", Debugger.current_context.frame_binding(4))
|
26
|
+
end
|
27
|
+
|
28
|
+
s0_var1 = 1357;
|
29
|
+
scope1(111, 222)
|
data/test/tdebug.rb
ADDED
@@ -0,0 +1,248 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- Ruby -*-
|
3
|
+
# This is a hacked down copy of rdebug which can be used for testing
|
4
|
+
# FIXME: use the real rdebug script - DRY.
|
5
|
+
|
6
|
+
require 'stringio'
|
7
|
+
require 'rubygems'
|
8
|
+
require 'optparse'
|
9
|
+
require "ostruct"
|
10
|
+
|
11
|
+
TOP_SRC_DIR = File.join(File.dirname(__FILE__), "..") unless
|
12
|
+
defined?(TOP_SRC_DIR)
|
13
|
+
|
14
|
+
$:.unshift File.join(TOP_SRC_DIR, "ext")
|
15
|
+
$:.unshift File.join(TOP_SRC_DIR, "lib")
|
16
|
+
$:.unshift File.join(TOP_SRC_DIR, "cli")
|
17
|
+
|
18
|
+
def debug_program(options)
|
19
|
+
# Make sure Ruby script syntax checks okay.
|
20
|
+
# Otherwise we get a load message that looks like rdebug has
|
21
|
+
# a problem.
|
22
|
+
output = `ruby -c "#{Debugger::PROG_SCRIPT}" 2>&1`
|
23
|
+
if $?.exitstatus != 0 and RUBY_PLATFORM !~ /mswin/
|
24
|
+
puts output
|
25
|
+
exit $?.exitstatus
|
26
|
+
end
|
27
|
+
print "\032\032starting\n" if Debugger.annotate and Debugger.annotate > 2
|
28
|
+
unless options.no_rewrite_program
|
29
|
+
# Set $0 so things like __FILE == $0 work.
|
30
|
+
# A more reliable way to do this is to put $0 = __FILE__ *after*
|
31
|
+
# loading the script to be debugged. For this, adding a debug hook
|
32
|
+
# for the first time and then switching to the debug hook that's
|
33
|
+
# normally used would be helpful. Doing this would also help other
|
34
|
+
# first-time initializations such as reloading debugger state
|
35
|
+
# after a restart.
|
36
|
+
|
37
|
+
# However This is just a little more than I want to take on right
|
38
|
+
# now, so I think I'll stick with the slightly hacky approach.
|
39
|
+
$RDEBUG_0 = $0
|
40
|
+
|
41
|
+
# cygwin does some sort of funky truncation on $0 ./abcdef => ./ab
|
42
|
+
# probably something to do with 3-letter extension truncation.
|
43
|
+
# The hacky workaround is to do slice assignment. Ugh.
|
44
|
+
d0 = if '.' == File.dirname(Debugger::PROG_SCRIPT) and
|
45
|
+
Debugger::PROG_SCRIPT[0..0] != '.'
|
46
|
+
File.join('.', Debugger::PROG_SCRIPT)
|
47
|
+
else
|
48
|
+
Debugger::PROG_SCRIPT
|
49
|
+
end
|
50
|
+
if $0.frozen?
|
51
|
+
$0 = d0
|
52
|
+
else
|
53
|
+
$0[0..-1] = d0
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Record where we are we can know if the call stack has been
|
58
|
+
# truncated or not.
|
59
|
+
Debugger.start_sentinal=caller(0)[1]
|
60
|
+
|
61
|
+
bt = Debugger.debug_load(Debugger::PROG_SCRIPT, !options.nostop, false)
|
62
|
+
if bt
|
63
|
+
if options.post_mortem
|
64
|
+
Debugger.handle_post_mortem(bt)
|
65
|
+
else
|
66
|
+
print bt.backtrace.map{|l| "\t#{l}"}.join("\n"), "\n"
|
67
|
+
print "Uncaught exception: #{bt}\n"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
options = OpenStruct.new(
|
73
|
+
'annotate' => false,
|
74
|
+
'emacs' => false,
|
75
|
+
'no-quit' => false,
|
76
|
+
'no-stop' => false,
|
77
|
+
'nx' => false,
|
78
|
+
'post_mortem' => false,
|
79
|
+
'script' => nil,
|
80
|
+
'tracing' => false,
|
81
|
+
'verbose_long'=> false,
|
82
|
+
'wait' => false
|
83
|
+
)
|
84
|
+
|
85
|
+
require "ruby-debug"
|
86
|
+
|
87
|
+
program = File.basename($0)
|
88
|
+
opts = OptionParser.new do |opts|
|
89
|
+
opts.banner = <<EOB
|
90
|
+
#{program} #{Debugger::VERSION}
|
91
|
+
Usage: #{program} [options] <script.rb> -- <script.rb parameters>
|
92
|
+
EOB
|
93
|
+
opts.separator ""
|
94
|
+
opts.separator "Options:"
|
95
|
+
opts.on("-A", "--annotate LEVEL", Integer, "Set annotation level") do |s|
|
96
|
+
Debugger.annotate = s
|
97
|
+
end
|
98
|
+
opts.on("-d", "--debug", "Set $DEBUG=true") {$DEBUG = true}
|
99
|
+
opts.on("--emacs-basic", "Activates basic Emacs mode") do
|
100
|
+
ENV['EMACS'] = '1'
|
101
|
+
options.emacs = true
|
102
|
+
end
|
103
|
+
opts.on("-m", "--post-mortem", "Activate post-mortem mode") do
|
104
|
+
options.post_mortem = true
|
105
|
+
end
|
106
|
+
opts.on("--no-control", "Do not automatically start control thread") do
|
107
|
+
options.control = false
|
108
|
+
end
|
109
|
+
opts.on("--no-quit", "Do not quit when script finishes") do
|
110
|
+
options.noquit = true
|
111
|
+
end
|
112
|
+
opts.on("--no-stop", "Do not stop when script is loaded") do
|
113
|
+
options.nostop = true
|
114
|
+
end
|
115
|
+
opts.on("-nx", "Not run debugger initialization files (e.g. .rdebugrc") do
|
116
|
+
options.nx = true
|
117
|
+
end
|
118
|
+
opts.on("-I", "--include PATH", String, "Add PATH to $LOAD_PATH") do |path|
|
119
|
+
$LOAD_PATH.unshift(path)
|
120
|
+
end
|
121
|
+
opts.on("-r", "--require SCRIPT", String,
|
122
|
+
"Require the library, before executing your script") do |name|
|
123
|
+
if name == 'debug'
|
124
|
+
puts "ruby-debug is not compatible with Ruby's 'debug' library. This option is ignored."
|
125
|
+
else
|
126
|
+
require name
|
127
|
+
end
|
128
|
+
end
|
129
|
+
opts.on("--script FILE", String, "Name of the script file to run") do |s|
|
130
|
+
options.script = s
|
131
|
+
unless File.exists?(options.script)
|
132
|
+
puts "Script file '#{options.script}' is not found"
|
133
|
+
exit
|
134
|
+
end
|
135
|
+
end
|
136
|
+
opts.on("-x", "--trace", "Turn on line tracing") {options.tracing = true}
|
137
|
+
ENV['EMACS'] = nil unless options.emacs
|
138
|
+
opts.separator ""
|
139
|
+
opts.separator "Common options:"
|
140
|
+
opts.on_tail("--help", "Show this message") do
|
141
|
+
puts opts
|
142
|
+
exit
|
143
|
+
end
|
144
|
+
opts.on_tail("--version",
|
145
|
+
"Print the version") do
|
146
|
+
puts "ruby-debug #{Debugger::VERSION}"
|
147
|
+
exit
|
148
|
+
end
|
149
|
+
opts.on("--verbose", "Turn on verbose mode") do
|
150
|
+
$VERBOSE = true
|
151
|
+
options.verbose_long = true
|
152
|
+
end
|
153
|
+
opts.on_tail("-v",
|
154
|
+
"Print version number, then turn on verbose mode") do
|
155
|
+
puts "ruby-debug #{Debugger::VERSION}"
|
156
|
+
$VERBOSE = true
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
begin
|
161
|
+
if not defined? Debugger::ARGV
|
162
|
+
Debugger::ARGV = ARGV.clone
|
163
|
+
end
|
164
|
+
rdebug_path = File.expand_path($0)
|
165
|
+
if RUBY_PLATFORM =~ /mswin/
|
166
|
+
rdebug_path += '.cmd' unless rdebug_path =~ /\.cmd$/i
|
167
|
+
end
|
168
|
+
Debugger::RDEBUG_SCRIPT = rdebug_path
|
169
|
+
Debugger::RDEBUG_FILE = __FILE__
|
170
|
+
Debugger::INITIAL_DIR = Dir.pwd
|
171
|
+
opts.parse! ARGV
|
172
|
+
rescue StandardError => e
|
173
|
+
puts opts
|
174
|
+
puts
|
175
|
+
puts e.message
|
176
|
+
exit(-1)
|
177
|
+
end
|
178
|
+
|
179
|
+
if ARGV.empty?
|
180
|
+
exit if $VERBOSE and not options.verbose_long
|
181
|
+
puts opts
|
182
|
+
puts
|
183
|
+
puts 'Must specify a script to run'
|
184
|
+
exit(-1)
|
185
|
+
end
|
186
|
+
|
187
|
+
# save script name
|
188
|
+
Debugger::PROG_SCRIPT = ARGV.shift
|
189
|
+
|
190
|
+
# install interruption handler
|
191
|
+
trap('INT') { Debugger.interrupt_last }
|
192
|
+
|
193
|
+
# set options
|
194
|
+
Debugger.wait_connection = false
|
195
|
+
|
196
|
+
# Add Debugger trace hook.
|
197
|
+
Debugger.start
|
198
|
+
|
199
|
+
# start control thread
|
200
|
+
Debugger.start_control(options.host, options.cport) if options.control
|
201
|
+
|
202
|
+
# activate post-mortem
|
203
|
+
Debugger.post_mortem if options.post_mortem
|
204
|
+
|
205
|
+
# Set up an interface to read commands from a debugger script file.
|
206
|
+
if options.script
|
207
|
+
Debugger.interface = Debugger::ScriptInterface.new(options.script,
|
208
|
+
STDOUT, true)
|
209
|
+
end
|
210
|
+
options.nostop = true if options.tracing
|
211
|
+
Debugger.tracing = options.tracing
|
212
|
+
|
213
|
+
# Make sure Ruby script syntax checks okay.
|
214
|
+
# Otherwise we get a load message that looks like rdebug has
|
215
|
+
# a problem.
|
216
|
+
output = `ruby -c #{Debugger::PROG_SCRIPT} 2>&1`
|
217
|
+
if $?.exitstatus != 0 and RUBY_PLATFORM !~ /mswin/
|
218
|
+
puts output
|
219
|
+
exit $?.exitstatus
|
220
|
+
end
|
221
|
+
|
222
|
+
# load initrc script (e.g. .rdebugrc)
|
223
|
+
Debugger.run_init_script(StringIO.new) unless options.nx
|
224
|
+
|
225
|
+
# run startup script if specified
|
226
|
+
if options.script
|
227
|
+
Debugger.run_script(options.script)
|
228
|
+
end
|
229
|
+
# activate post-mortem
|
230
|
+
Debugger.post_mortem if options.post_mortem
|
231
|
+
options.stop = false if options.tracing
|
232
|
+
Debugger.tracing = options.tracing
|
233
|
+
|
234
|
+
if options.noquit
|
235
|
+
if Debugger.started?
|
236
|
+
until Debugger.stop do end
|
237
|
+
end
|
238
|
+
debug_program(options)
|
239
|
+
print "The program finished.\n" unless
|
240
|
+
Debugger.annotate.to_i > 1 # annotate has its own way
|
241
|
+
interface = Debugger::LocalInterface.new
|
242
|
+
# Not sure if ControlCommandProcessor is really the right
|
243
|
+
# thing to use. CommandProcessor requires a state.
|
244
|
+
processor = Debugger::ControlCommandProcessor.new(interface)
|
245
|
+
processor.process_commands
|
246
|
+
else
|
247
|
+
debug_program(options)
|
248
|
+
end
|