debugger 1.2.4 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -0
- data/.travis.yml +0 -1
- data/CHANGELOG.md +9 -0
- data/Gemfile +3 -0
- data/README.md +2 -0
- data/Rakefile +3 -55
- data/debugger.gemspec +2 -0
- data/lib/debugger/version.rb +1 -1
- data/lib/ruby-debug-base.rb +3 -1
- data/lib/ruby-debug/commands/irb.rb +1 -1
- data/lib/ruby-debug/commands/jump.rb +1 -1
- data/lib/ruby-debug/commands/method.rb +1 -1
- data/lib/ruby-debug/commands/show.rb +1 -1
- data/lib/ruby-debug/commands/trace.rb +2 -2
- data/lib/ruby-debug/commands/variables.rb +3 -3
- data/test/breakpoints_test.rb +365 -0
- data/test/conditions_test.rb +76 -0
- data/test/continue_test.rb +28 -0
- data/test/display_test.rb +141 -0
- data/test/edit_test.rb +55 -0
- data/test/eval_test.rb +92 -0
- data/test/examples/breakpoint1.rb +15 -0
- data/test/examples/breakpoint2.rb +7 -0
- data/test/examples/conditions.rb +4 -0
- data/test/examples/continue.rb +4 -0
- data/test/examples/display.rb +5 -0
- data/test/examples/edit.rb +3 -0
- data/test/examples/edit2.rb +3 -0
- data/test/examples/eval.rb +4 -0
- data/test/examples/finish.rb +20 -0
- data/test/examples/frame.rb +31 -0
- data/test/examples/help.rb +2 -0
- data/test/examples/info.rb +48 -0
- data/test/examples/info2.rb +3 -0
- data/test/examples/irb.rb +6 -0
- data/test/examples/jump.rb +14 -0
- data/test/examples/kill.rb +2 -0
- data/test/examples/list.rb +12 -0
- data/test/examples/method.rb +15 -0
- data/test/examples/post_mortem.rb +19 -0
- data/test/examples/quit.rb +2 -0
- data/test/examples/reload.rb +6 -0
- data/test/examples/restart.rb +6 -0
- data/test/examples/save.rb +3 -0
- data/test/examples/set.rb +3 -0
- data/test/examples/set_annotate.rb +12 -0
- data/test/examples/settings.rb +1 -0
- data/test/examples/show.rb +2 -0
- data/test/examples/source.rb +3 -0
- data/test/examples/stepping.rb +21 -0
- data/test/examples/thread.rb +32 -0
- data/test/examples/tmate.rb +10 -0
- data/test/examples/trace.rb +7 -0
- data/test/examples/trace_threads.rb +20 -0
- data/test/examples/variables.rb +26 -0
- data/test/finish_test.rb +48 -0
- data/test/frame_test.rb +140 -0
- data/test/help_test.rb +50 -0
- data/test/info_test.rb +325 -0
- data/test/irb_test.rb +81 -0
- data/test/jump_test.rb +70 -0
- data/test/kill_test.rb +47 -0
- data/test/list_test.rb +145 -0
- data/test/method_test.rb +70 -0
- data/test/post_mortem_test.rb +25 -0
- data/test/quit_test.rb +55 -0
- data/test/reload_test.rb +43 -0
- data/test/restart_test.rb +143 -0
- data/test/save_test.rb +92 -0
- data/test/set_test.rb +163 -0
- data/test/show_test.rb +292 -0
- data/test/source_test.rb +44 -0
- data/test/stepping_test.rb +118 -0
- data/test/support/breakpoint.rb +12 -0
- data/test/support/context.rb +14 -0
- data/test/support/matchers.rb +67 -0
- data/test/support/mocha_extensions.rb +71 -0
- data/test/support/processor.rb +7 -0
- data/test/support/test_dsl.rb +205 -0
- data/test/support/test_interface.rb +66 -0
- data/test/test_helper.rb +8 -0
- data/test/thread_test.rb +122 -0
- data/test/tmate_test.rb +43 -0
- data/test/trace_test.rb +154 -0
- data/test/variables_test.rb +114 -0
- metadata +107 -158
- data/test/base/base.rb +0 -71
- data/test/base/binding.rb +0 -24
- data/test/base/catchpoint.rb +0 -22
- data/test/base/load.rb +0 -36
- data/test/bp_loop_issue.rb +0 -3
- data/test/classes.rb +0 -11
- data/test/config.yaml +0 -8
- data/test/data/annotate.cmd +0 -29
- data/test/data/annotate.right +0 -139
- data/test/data/break_bad.cmd +0 -18
- data/test/data/break_bad.right +0 -28
- data/test/data/break_loop_bug.cmd +0 -5
- data/test/data/break_loop_bug.right +0 -15
- data/test/data/breakpoints.cmd +0 -38
- data/test/data/breakpoints.right +0 -98
- data/test/data/catch.cmd +0 -20
- data/test/data/catch.right +0 -49
- data/test/data/catch2.cmd +0 -19
- data/test/data/catch2.right +0 -65
- data/test/data/catch3.cmd +0 -11
- data/test/data/catch3.right +0 -37
- data/test/data/condition.cmd +0 -28
- data/test/data/condition.right +0 -65
- data/test/data/ctrl.cmd +0 -23
- data/test/data/ctrl.right +0 -70
- data/test/data/display.cmd +0 -24
- data/test/data/display.right +0 -44
- data/test/data/dollar-0.right +0 -2
- data/test/data/dollar-0a.right +0 -2
- data/test/data/dollar-0b.right +0 -2
- data/test/data/edit.cmd +0 -12
- data/test/data/edit.right +0 -19
- data/test/data/emacs_basic.cmd +0 -43
- data/test/data/emacs_basic.right +0 -106
- data/test/data/enable.cmd +0 -20
- data/test/data/enable.right +0 -36
- data/test/data/finish.cmd +0 -16
- data/test/data/finish.right +0 -31
- data/test/data/frame.cmd +0 -26
- data/test/data/frame.right +0 -55
- data/test/data/help.cmd +0 -20
- data/test/data/help.right +0 -21
- data/test/data/history.right +0 -7
- data/test/data/info-thread.cmd +0 -13
- data/test/data/info-thread.right +0 -37
- data/test/data/info-var-bug2.cmd +0 -5
- data/test/data/info-var-bug2.right +0 -10
- data/test/data/info-var.cmd +0 -23
- data/test/data/info-var.right +0 -52
- data/test/data/info.cmd +0 -21
- data/test/data/info.right +0 -65
- data/test/data/jump.cmd +0 -16
- data/test/data/jump.right +0 -56
- data/test/data/jump2.cmd +0 -16
- data/test/data/jump2.right +0 -44
- data/test/data/linetrace.cmd +0 -6
- data/test/data/linetrace.right +0 -23
- data/test/data/list.cmd +0 -19
- data/test/data/list.right +0 -127
- data/test/data/method.cmd +0 -10
- data/test/data/method.right +0 -21
- data/test/data/methodsig.cmd +0 -10
- data/test/data/methodsig.right +0 -20
- data/test/data/next.cmd +0 -22
- data/test/data/next.right +0 -61
- data/test/data/noquit.right +0 -1
- data/test/data/output.cmd +0 -6
- data/test/data/output.right +0 -31
- data/test/data/pm-bug.cmd +0 -7
- data/test/data/pm-bug.right +0 -12
- data/test/data/post-mortem-next.cmd +0 -8
- data/test/data/post-mortem-next.right +0 -14
- data/test/data/post-mortem-osx.right +0 -31
- data/test/data/post-mortem.cmd +0 -13
- data/test/data/post-mortem.right +0 -32
- data/test/data/quit.cmd +0 -6
- data/test/data/quit.right +0 -0
- data/test/data/raise.cmd +0 -11
- data/test/data/raise.right +0 -23
- data/test/data/save.cmd +0 -34
- data/test/data/save.right +0 -59
- data/test/data/scope-var.cmd +0 -42
- data/test/data/scope-var.right +0 -587
- data/test/data/setshow.cmd +0 -56
- data/test/data/setshow.right +0 -98
- data/test/data/source.cmd +0 -5
- data/test/data/source.right +0 -15
- data/test/data/stepping.cmd +0 -21
- data/test/data/stepping.right +0 -50
- data/test/data/test-init-cygwin.right +0 -7
- data/test/data/test-init-osx.right +0 -4
- data/test/data/test-init.right +0 -5
- data/test/data/trace.right +0 -14
- data/test/dollar-0.rb +0 -5
- data/test/gcd-dbg-nox.rb +0 -30
- data/test/gcd-dbg.rb +0 -29
- data/test/gcd.rb +0 -18
- data/test/helper.rb +0 -142
- data/test/info-var-bug.rb +0 -47
- data/test/info-var-bug2.rb +0 -2
- data/test/jump.rb +0 -14
- data/test/jump2.rb +0 -27
- data/test/lib/commands/catchpoint_test.rb +0 -28
- data/test/lib/commands/unit/regexp.rb +0 -38
- data/test/next.rb +0 -18
- data/test/null.rb +0 -1
- data/test/output.rb +0 -2
- data/test/pm-base.rb +0 -17
- data/test/pm-bug.rb +0 -3
- data/test/pm-catch.rb +0 -12
- data/test/pm-catch2.rb +0 -27
- data/test/pm-catch3.rb +0 -47
- data/test/pm.rb +0 -11
- data/test/raise.rb +0 -3
- data/test/rdebug-save.1 +0 -7
- data/test/runall +0 -12
- data/test/scope-var.rb +0 -29
- data/test/tdebug.rb +0 -246
- data/test/test-annotate.rb +0 -24
- data/test/test-break-bad.rb +0 -36
- data/test/test-breakpoints.rb +0 -24
- data/test/test-catch.rb +0 -24
- data/test/test-catch2.rb +0 -24
- data/test/test-catch3.rb +0 -24
- data/test/test-condition.rb +0 -24
- data/test/test-ctrl.rb +0 -51
- data/test/test-display.rb +0 -25
- data/test/test-dollar-0.rb +0 -39
- data/test/test-edit.rb +0 -25
- data/test/test-emacs-basic.rb +0 -25
- data/test/test-enable.rb +0 -24
- data/test/test-finish.rb +0 -33
- data/test/test-frame.rb +0 -33
- data/test/test-help.rb +0 -54
- data/test/test-hist.rb +0 -65
- data/test/test-info-thread.rb +0 -31
- data/test/test-info-var.rb +0 -46
- data/test/test-info.rb +0 -25
- data/test/test-init.rb +0 -43
- data/test/test-jump.rb +0 -34
- data/test/test-list.rb +0 -24
- data/test/test-method.rb +0 -33
- data/test/test-next.rb +0 -24
- data/test/test-output.rb +0 -25
- data/test/test-quit.rb +0 -29
- data/test/test-raise.rb +0 -24
- data/test/test-remote.rb +0 -14
- data/test/test-save.rb +0 -30
- data/test/test-scope-var.rb +0 -24
- data/test/test-setshow.rb +0 -24
- data/test/test-source.rb +0 -24
- data/test/test-stepping.rb +0 -25
- data/test/test-trace.rb +0 -46
- data/test/thread1.rb +0 -25
- data/test/trunc-call.rb +0 -30
data/test/info-var-bug.rb
DELETED
@@ -1,47 +0,0 @@
|
|
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/info-var-bug2.rb
DELETED
data/test/jump.rb
DELETED
data/test/jump2.rb
DELETED
@@ -1,27 +0,0 @@
|
|
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"
|
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'ruby-debug'
|
5
|
-
|
6
|
-
class TestCatchCommand < Test::Unit::TestCase
|
7
|
-
|
8
|
-
class MockState
|
9
|
-
attr_accessor :message
|
10
|
-
def context; end
|
11
|
-
def confirm(msg); true end
|
12
|
-
def print(*args)
|
13
|
-
@message = *args
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# regression test for bug #20156
|
18
|
-
def test_catch_does_not_blow_up
|
19
|
-
state = MockState.new
|
20
|
-
catch_cmd = Debugger::CatchCommand.new(state)
|
21
|
-
assert(catch_cmd.match('catch off'))
|
22
|
-
catch(:debug_error) do
|
23
|
-
catch_cmd.execute
|
24
|
-
end
|
25
|
-
assert_equal(nil, state.message)
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
|
3
|
-
|
4
|
-
class TestCommandREs < Test::Unit::TestCase
|
5
|
-
require 'ruby-debug/command'
|
6
|
-
require 'ruby-debug/commands/frame'
|
7
|
-
include Debugger
|
8
|
-
|
9
|
-
def test_quit
|
10
|
-
c = QuitCommand.new(nil)
|
11
|
-
assert c.regexp.match('quit')
|
12
|
-
assert c.regexp.match('q')
|
13
|
-
assert c.regexp.match('quit!')
|
14
|
-
assert c.regexp.match('q!')
|
15
|
-
assert c.regexp.match('quit unconditionally')
|
16
|
-
assert c.regexp.match('exit')
|
17
|
-
assert c.regexp.match('exit!')
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_up
|
21
|
-
c = UpCommand.new(nil)
|
22
|
-
assert c.regexp.match('up')
|
23
|
-
assert c.regexp.match('up 2')
|
24
|
-
assert c.regexp.match('up 2+5')
|
25
|
-
assert c.regexp.match('u')
|
26
|
-
assert c.regexp.match('u 2')
|
27
|
-
assert_equal nil, c.regexp.match('ufoo')
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_down
|
31
|
-
c = DownCommand.new(nil)
|
32
|
-
assert c.regexp.match('down')
|
33
|
-
assert c.regexp.match('down 2')
|
34
|
-
assert_equal(nil, c.regexp.match('d 2'))
|
35
|
-
assert_equal(nil, c.regexp.match('d'))
|
36
|
-
assert_equal(nil, c.regexp.match('dow'))
|
37
|
-
end
|
38
|
-
end
|
data/test/next.rb
DELETED
data/test/null.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# Nothing here. Move along.
|
data/test/output.rb
DELETED
data/test/pm-base.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Test post-mortem handling using only ruby-debug-base.
|
3
|
-
require 'ruby-debug-base'
|
4
|
-
|
5
|
-
class CommandProcessor
|
6
|
-
def at_line(context, file, line)
|
7
|
-
puts 'file: %s, line: %s' % [ File.basename(file), line ]
|
8
|
-
exit!
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
Debugger.start(:post_mortem => true)
|
13
|
-
Debugger.handler = CommandProcessor.new
|
14
|
-
def zero_div
|
15
|
-
1/0
|
16
|
-
end
|
17
|
-
zero_div
|
data/test/pm-bug.rb
DELETED
data/test/pm-catch.rb
DELETED
data/test/pm-catch2.rb
DELETED
@@ -1,27 +0,0 @@
|
|
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
DELETED
@@ -1,47 +0,0 @@
|
|
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
DELETED
data/test/raise.rb
DELETED
data/test/rdebug-save.1
DELETED
data/test/runall
DELETED
@@ -1,12 +0,0 @@
|
|
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
DELETED
@@ -1,29 +0,0 @@
|
|
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
DELETED
@@ -1,246 +0,0 @@
|
|
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 'optparse'
|
8
|
-
require "ostruct"
|
9
|
-
|
10
|
-
TOP_SRC_DIR = File.join(File.dirname(__FILE__), "..") unless
|
11
|
-
defined?(TOP_SRC_DIR)
|
12
|
-
|
13
|
-
$:.unshift File.join(TOP_SRC_DIR, "ext")
|
14
|
-
$:.unshift File.join(TOP_SRC_DIR, "lib")
|
15
|
-
|
16
|
-
def debug_program(options)
|
17
|
-
# Make sure Ruby script syntax checks okay.
|
18
|
-
# Otherwise we get a load message that looks like rdebug has
|
19
|
-
# a problem.
|
20
|
-
output = `ruby -c "#{Debugger::PROG_SCRIPT}" 2>&1`
|
21
|
-
if $?.exitstatus != 0 and RUBY_PLATFORM !~ /mswin/
|
22
|
-
puts output
|
23
|
-
exit $?.exitstatus
|
24
|
-
end
|
25
|
-
print "\032\032starting\n" if Debugger.annotate and Debugger.annotate > 2
|
26
|
-
unless options.no_rewrite_program
|
27
|
-
# Set $0 so things like __FILE == $0 work.
|
28
|
-
# A more reliable way to do this is to put $0 = __FILE__ *after*
|
29
|
-
# loading the script to be debugged. For this, adding a debug hook
|
30
|
-
# for the first time and then switching to the debug hook that's
|
31
|
-
# normally used would be helpful. Doing this would also help other
|
32
|
-
# first-time initializations such as reloading debugger state
|
33
|
-
# after a restart.
|
34
|
-
|
35
|
-
# However This is just a little more than I want to take on right
|
36
|
-
# now, so I think I'll stick with the slightly hacky approach.
|
37
|
-
$RDEBUG_0 = $0
|
38
|
-
|
39
|
-
# cygwin does some sort of funky truncation on $0 ./abcdef => ./ab
|
40
|
-
# probably something to do with 3-letter extension truncation.
|
41
|
-
# The hacky workaround is to do slice assignment. Ugh.
|
42
|
-
d0 = if '.' == File.dirname(Debugger::PROG_SCRIPT) and
|
43
|
-
Debugger::PROG_SCRIPT[0..0] != '.'
|
44
|
-
File.join('.', Debugger::PROG_SCRIPT)
|
45
|
-
else
|
46
|
-
Debugger::PROG_SCRIPT
|
47
|
-
end
|
48
|
-
if $0.frozen?
|
49
|
-
$0 = d0
|
50
|
-
else
|
51
|
-
$0[0..-1] = d0
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# Record where we are we can know if the call stack has been
|
56
|
-
# truncated or not.
|
57
|
-
Debugger.start_sentinal=caller(0)[1]
|
58
|
-
|
59
|
-
bt = Debugger.debug_load(Debugger::PROG_SCRIPT, !options.nostop, false)
|
60
|
-
if bt
|
61
|
-
if options.post_mortem
|
62
|
-
Debugger.handle_post_mortem(bt)
|
63
|
-
else
|
64
|
-
print bt.backtrace.map{|l| "\t#{l}"}.join("\n"), "\n"
|
65
|
-
print "Uncaught exception: #{bt}\n"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
options = OpenStruct.new(
|
71
|
-
'annotate' => false,
|
72
|
-
'emacs' => false,
|
73
|
-
'no-quit' => false,
|
74
|
-
'no-stop' => false,
|
75
|
-
'nx' => false,
|
76
|
-
'post_mortem' => false,
|
77
|
-
'script' => nil,
|
78
|
-
'tracing' => false,
|
79
|
-
'verbose_long'=> false,
|
80
|
-
'wait' => false
|
81
|
-
)
|
82
|
-
|
83
|
-
require "ruby-debug"
|
84
|
-
|
85
|
-
program = File.basename($0)
|
86
|
-
opts = OptionParser.new do |opts|
|
87
|
-
opts.banner = <<EOB
|
88
|
-
#{program} #{Debugger::VERSION}
|
89
|
-
Usage: #{program} [options] <script.rb> -- <script.rb parameters>
|
90
|
-
EOB
|
91
|
-
opts.separator ""
|
92
|
-
opts.separator "Options:"
|
93
|
-
opts.on("-A", "--annotate LEVEL", Integer, "Set annotation level") do |s|
|
94
|
-
Debugger.annotate = s
|
95
|
-
end
|
96
|
-
opts.on("-d", "--debug", "Set $DEBUG=true") {$DEBUG = true}
|
97
|
-
opts.on("--emacs-basic", "Activates basic Emacs mode") do
|
98
|
-
ENV['EMACS'] = '1'
|
99
|
-
options.emacs = true
|
100
|
-
end
|
101
|
-
opts.on("-m", "--post-mortem", "Activate post-mortem mode") do
|
102
|
-
options.post_mortem = true
|
103
|
-
end
|
104
|
-
opts.on("--no-control", "Do not automatically start control thread") do
|
105
|
-
options.control = false
|
106
|
-
end
|
107
|
-
opts.on("--no-quit", "Do not quit when script finishes") do
|
108
|
-
options.noquit = true
|
109
|
-
end
|
110
|
-
opts.on("--no-stop", "Do not stop when script is loaded") do
|
111
|
-
options.nostop = true
|
112
|
-
end
|
113
|
-
opts.on("-nx", "Not run debugger initialization files (e.g. .rdebugrc") do
|
114
|
-
options.nx = true
|
115
|
-
end
|
116
|
-
opts.on("-I", "--include PATH", String, "Add PATH to $LOAD_PATH") do |path|
|
117
|
-
$LOAD_PATH.unshift(path)
|
118
|
-
end
|
119
|
-
opts.on("-r", "--require SCRIPT", String,
|
120
|
-
"Require the library, before executing your script") do |name|
|
121
|
-
if name == 'debug'
|
122
|
-
puts "ruby-debug is not compatible with Ruby's 'debug' library. This option is ignored."
|
123
|
-
else
|
124
|
-
require name
|
125
|
-
end
|
126
|
-
end
|
127
|
-
opts.on("--script FILE", String, "Name of the script file to run") do |s|
|
128
|
-
options.script = s
|
129
|
-
unless File.exists?(options.script)
|
130
|
-
puts "Script file '#{options.script}' is not found"
|
131
|
-
exit
|
132
|
-
end
|
133
|
-
end
|
134
|
-
opts.on("-x", "--trace", "Turn on line tracing") {options.tracing = true}
|
135
|
-
ENV['EMACS'] = nil unless options.emacs
|
136
|
-
opts.separator ""
|
137
|
-
opts.separator "Common options:"
|
138
|
-
opts.on_tail("--help", "Show this message") do
|
139
|
-
puts opts
|
140
|
-
exit
|
141
|
-
end
|
142
|
-
opts.on_tail("--version",
|
143
|
-
"Print the version") do
|
144
|
-
puts "ruby-debug #{Debugger::VERSION}"
|
145
|
-
exit
|
146
|
-
end
|
147
|
-
opts.on("--verbose", "Turn on verbose mode") do
|
148
|
-
$VERBOSE = true
|
149
|
-
options.verbose_long = true
|
150
|
-
end
|
151
|
-
opts.on_tail("-v",
|
152
|
-
"Print version number, then turn on verbose mode") do
|
153
|
-
puts "ruby-debug #{Debugger::VERSION}"
|
154
|
-
$VERBOSE = true
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
begin
|
159
|
-
if not defined? Debugger::ARGV
|
160
|
-
Debugger::ARGV = ARGV.clone
|
161
|
-
end
|
162
|
-
rdebug_path = File.expand_path($0)
|
163
|
-
if RUBY_PLATFORM =~ /mswin/
|
164
|
-
rdebug_path += '.cmd' unless rdebug_path =~ /\.cmd$/i
|
165
|
-
end
|
166
|
-
Debugger::RDEBUG_SCRIPT = rdebug_path
|
167
|
-
Debugger::RDEBUG_FILE = __FILE__
|
168
|
-
Debugger::INITIAL_DIR = Dir.pwd
|
169
|
-
opts.parse! ARGV
|
170
|
-
rescue StandardError => e
|
171
|
-
puts opts
|
172
|
-
puts
|
173
|
-
puts e.message
|
174
|
-
exit(-1)
|
175
|
-
end
|
176
|
-
|
177
|
-
if ARGV.empty?
|
178
|
-
exit if $VERBOSE and not options.verbose_long
|
179
|
-
puts opts
|
180
|
-
puts
|
181
|
-
puts 'Must specify a script to run'
|
182
|
-
exit(-1)
|
183
|
-
end
|
184
|
-
|
185
|
-
# save script name
|
186
|
-
Debugger::PROG_SCRIPT = ARGV.shift
|
187
|
-
|
188
|
-
# install interruption handler
|
189
|
-
trap('INT') { Debugger.interrupt_last }
|
190
|
-
|
191
|
-
# set options
|
192
|
-
Debugger.wait_connection = false
|
193
|
-
|
194
|
-
# Add Debugger trace hook.
|
195
|
-
Debugger.start
|
196
|
-
|
197
|
-
# start control thread
|
198
|
-
Debugger.start_control(options.host, options.cport) if options.control
|
199
|
-
|
200
|
-
# activate post-mortem
|
201
|
-
Debugger.post_mortem if options.post_mortem
|
202
|
-
|
203
|
-
# Set up an interface to read commands from a debugger script file.
|
204
|
-
if options.script
|
205
|
-
Debugger.interface = Debugger::ScriptInterface.new(options.script,
|
206
|
-
STDOUT, true)
|
207
|
-
end
|
208
|
-
options.nostop = true if options.tracing
|
209
|
-
Debugger.tracing = options.tracing
|
210
|
-
|
211
|
-
# Make sure Ruby script syntax checks okay.
|
212
|
-
# Otherwise we get a load message that looks like rdebug has
|
213
|
-
# a problem.
|
214
|
-
output = `ruby -c #{Debugger::PROG_SCRIPT} 2>&1`
|
215
|
-
if $?.exitstatus != 0 and RUBY_PLATFORM !~ /mswin/
|
216
|
-
puts output
|
217
|
-
exit $?.exitstatus
|
218
|
-
end
|
219
|
-
|
220
|
-
# load initrc script (e.g. .rdebugrc)
|
221
|
-
Debugger.run_init_script(StringIO.new) unless options.nx
|
222
|
-
|
223
|
-
# run startup script if specified
|
224
|
-
if options.script
|
225
|
-
Debugger.run_script(options.script)
|
226
|
-
end
|
227
|
-
# activate post-mortem
|
228
|
-
Debugger.post_mortem if options.post_mortem
|
229
|
-
options.stop = false if options.tracing
|
230
|
-
Debugger.tracing = options.tracing
|
231
|
-
|
232
|
-
if options.noquit
|
233
|
-
if Debugger.started?
|
234
|
-
until Debugger.stop do end
|
235
|
-
end
|
236
|
-
debug_program(options)
|
237
|
-
print "The program finished.\n" unless
|
238
|
-
Debugger.annotate.to_i > 1 # annotate has its own way
|
239
|
-
interface = Debugger::LocalInterface.new
|
240
|
-
# Not sure if ControlCommandProcessor is really the right
|
241
|
-
# thing to use. CommandProcessor requires a state.
|
242
|
-
processor = Debugger::ControlCommandProcessor.new(interface)
|
243
|
-
processor.process_commands
|
244
|
-
else
|
245
|
-
debug_program(options)
|
246
|
-
end
|