debugger 1.2.4 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. data/.gitignore +14 -0
  2. data/.travis.yml +0 -1
  3. data/CHANGELOG.md +9 -0
  4. data/Gemfile +3 -0
  5. data/README.md +2 -0
  6. data/Rakefile +3 -55
  7. data/debugger.gemspec +2 -0
  8. data/lib/debugger/version.rb +1 -1
  9. data/lib/ruby-debug-base.rb +3 -1
  10. data/lib/ruby-debug/commands/irb.rb +1 -1
  11. data/lib/ruby-debug/commands/jump.rb +1 -1
  12. data/lib/ruby-debug/commands/method.rb +1 -1
  13. data/lib/ruby-debug/commands/show.rb +1 -1
  14. data/lib/ruby-debug/commands/trace.rb +2 -2
  15. data/lib/ruby-debug/commands/variables.rb +3 -3
  16. data/test/breakpoints_test.rb +365 -0
  17. data/test/conditions_test.rb +76 -0
  18. data/test/continue_test.rb +28 -0
  19. data/test/display_test.rb +141 -0
  20. data/test/edit_test.rb +55 -0
  21. data/test/eval_test.rb +92 -0
  22. data/test/examples/breakpoint1.rb +15 -0
  23. data/test/examples/breakpoint2.rb +7 -0
  24. data/test/examples/conditions.rb +4 -0
  25. data/test/examples/continue.rb +4 -0
  26. data/test/examples/display.rb +5 -0
  27. data/test/examples/edit.rb +3 -0
  28. data/test/examples/edit2.rb +3 -0
  29. data/test/examples/eval.rb +4 -0
  30. data/test/examples/finish.rb +20 -0
  31. data/test/examples/frame.rb +31 -0
  32. data/test/examples/help.rb +2 -0
  33. data/test/examples/info.rb +48 -0
  34. data/test/examples/info2.rb +3 -0
  35. data/test/examples/irb.rb +6 -0
  36. data/test/examples/jump.rb +14 -0
  37. data/test/examples/kill.rb +2 -0
  38. data/test/examples/list.rb +12 -0
  39. data/test/examples/method.rb +15 -0
  40. data/test/examples/post_mortem.rb +19 -0
  41. data/test/examples/quit.rb +2 -0
  42. data/test/examples/reload.rb +6 -0
  43. data/test/examples/restart.rb +6 -0
  44. data/test/examples/save.rb +3 -0
  45. data/test/examples/set.rb +3 -0
  46. data/test/examples/set_annotate.rb +12 -0
  47. data/test/examples/settings.rb +1 -0
  48. data/test/examples/show.rb +2 -0
  49. data/test/examples/source.rb +3 -0
  50. data/test/examples/stepping.rb +21 -0
  51. data/test/examples/thread.rb +32 -0
  52. data/test/examples/tmate.rb +10 -0
  53. data/test/examples/trace.rb +7 -0
  54. data/test/examples/trace_threads.rb +20 -0
  55. data/test/examples/variables.rb +26 -0
  56. data/test/finish_test.rb +48 -0
  57. data/test/frame_test.rb +140 -0
  58. data/test/help_test.rb +50 -0
  59. data/test/info_test.rb +325 -0
  60. data/test/irb_test.rb +81 -0
  61. data/test/jump_test.rb +70 -0
  62. data/test/kill_test.rb +47 -0
  63. data/test/list_test.rb +145 -0
  64. data/test/method_test.rb +70 -0
  65. data/test/post_mortem_test.rb +25 -0
  66. data/test/quit_test.rb +55 -0
  67. data/test/reload_test.rb +43 -0
  68. data/test/restart_test.rb +143 -0
  69. data/test/save_test.rb +92 -0
  70. data/test/set_test.rb +163 -0
  71. data/test/show_test.rb +292 -0
  72. data/test/source_test.rb +44 -0
  73. data/test/stepping_test.rb +118 -0
  74. data/test/support/breakpoint.rb +12 -0
  75. data/test/support/context.rb +14 -0
  76. data/test/support/matchers.rb +67 -0
  77. data/test/support/mocha_extensions.rb +71 -0
  78. data/test/support/processor.rb +7 -0
  79. data/test/support/test_dsl.rb +205 -0
  80. data/test/support/test_interface.rb +66 -0
  81. data/test/test_helper.rb +8 -0
  82. data/test/thread_test.rb +122 -0
  83. data/test/tmate_test.rb +43 -0
  84. data/test/trace_test.rb +154 -0
  85. data/test/variables_test.rb +114 -0
  86. metadata +107 -158
  87. data/test/base/base.rb +0 -71
  88. data/test/base/binding.rb +0 -24
  89. data/test/base/catchpoint.rb +0 -22
  90. data/test/base/load.rb +0 -36
  91. data/test/bp_loop_issue.rb +0 -3
  92. data/test/classes.rb +0 -11
  93. data/test/config.yaml +0 -8
  94. data/test/data/annotate.cmd +0 -29
  95. data/test/data/annotate.right +0 -139
  96. data/test/data/break_bad.cmd +0 -18
  97. data/test/data/break_bad.right +0 -28
  98. data/test/data/break_loop_bug.cmd +0 -5
  99. data/test/data/break_loop_bug.right +0 -15
  100. data/test/data/breakpoints.cmd +0 -38
  101. data/test/data/breakpoints.right +0 -98
  102. data/test/data/catch.cmd +0 -20
  103. data/test/data/catch.right +0 -49
  104. data/test/data/catch2.cmd +0 -19
  105. data/test/data/catch2.right +0 -65
  106. data/test/data/catch3.cmd +0 -11
  107. data/test/data/catch3.right +0 -37
  108. data/test/data/condition.cmd +0 -28
  109. data/test/data/condition.right +0 -65
  110. data/test/data/ctrl.cmd +0 -23
  111. data/test/data/ctrl.right +0 -70
  112. data/test/data/display.cmd +0 -24
  113. data/test/data/display.right +0 -44
  114. data/test/data/dollar-0.right +0 -2
  115. data/test/data/dollar-0a.right +0 -2
  116. data/test/data/dollar-0b.right +0 -2
  117. data/test/data/edit.cmd +0 -12
  118. data/test/data/edit.right +0 -19
  119. data/test/data/emacs_basic.cmd +0 -43
  120. data/test/data/emacs_basic.right +0 -106
  121. data/test/data/enable.cmd +0 -20
  122. data/test/data/enable.right +0 -36
  123. data/test/data/finish.cmd +0 -16
  124. data/test/data/finish.right +0 -31
  125. data/test/data/frame.cmd +0 -26
  126. data/test/data/frame.right +0 -55
  127. data/test/data/help.cmd +0 -20
  128. data/test/data/help.right +0 -21
  129. data/test/data/history.right +0 -7
  130. data/test/data/info-thread.cmd +0 -13
  131. data/test/data/info-thread.right +0 -37
  132. data/test/data/info-var-bug2.cmd +0 -5
  133. data/test/data/info-var-bug2.right +0 -10
  134. data/test/data/info-var.cmd +0 -23
  135. data/test/data/info-var.right +0 -52
  136. data/test/data/info.cmd +0 -21
  137. data/test/data/info.right +0 -65
  138. data/test/data/jump.cmd +0 -16
  139. data/test/data/jump.right +0 -56
  140. data/test/data/jump2.cmd +0 -16
  141. data/test/data/jump2.right +0 -44
  142. data/test/data/linetrace.cmd +0 -6
  143. data/test/data/linetrace.right +0 -23
  144. data/test/data/list.cmd +0 -19
  145. data/test/data/list.right +0 -127
  146. data/test/data/method.cmd +0 -10
  147. data/test/data/method.right +0 -21
  148. data/test/data/methodsig.cmd +0 -10
  149. data/test/data/methodsig.right +0 -20
  150. data/test/data/next.cmd +0 -22
  151. data/test/data/next.right +0 -61
  152. data/test/data/noquit.right +0 -1
  153. data/test/data/output.cmd +0 -6
  154. data/test/data/output.right +0 -31
  155. data/test/data/pm-bug.cmd +0 -7
  156. data/test/data/pm-bug.right +0 -12
  157. data/test/data/post-mortem-next.cmd +0 -8
  158. data/test/data/post-mortem-next.right +0 -14
  159. data/test/data/post-mortem-osx.right +0 -31
  160. data/test/data/post-mortem.cmd +0 -13
  161. data/test/data/post-mortem.right +0 -32
  162. data/test/data/quit.cmd +0 -6
  163. data/test/data/quit.right +0 -0
  164. data/test/data/raise.cmd +0 -11
  165. data/test/data/raise.right +0 -23
  166. data/test/data/save.cmd +0 -34
  167. data/test/data/save.right +0 -59
  168. data/test/data/scope-var.cmd +0 -42
  169. data/test/data/scope-var.right +0 -587
  170. data/test/data/setshow.cmd +0 -56
  171. data/test/data/setshow.right +0 -98
  172. data/test/data/source.cmd +0 -5
  173. data/test/data/source.right +0 -15
  174. data/test/data/stepping.cmd +0 -21
  175. data/test/data/stepping.right +0 -50
  176. data/test/data/test-init-cygwin.right +0 -7
  177. data/test/data/test-init-osx.right +0 -4
  178. data/test/data/test-init.right +0 -5
  179. data/test/data/trace.right +0 -14
  180. data/test/dollar-0.rb +0 -5
  181. data/test/gcd-dbg-nox.rb +0 -30
  182. data/test/gcd-dbg.rb +0 -29
  183. data/test/gcd.rb +0 -18
  184. data/test/helper.rb +0 -142
  185. data/test/info-var-bug.rb +0 -47
  186. data/test/info-var-bug2.rb +0 -2
  187. data/test/jump.rb +0 -14
  188. data/test/jump2.rb +0 -27
  189. data/test/lib/commands/catchpoint_test.rb +0 -28
  190. data/test/lib/commands/unit/regexp.rb +0 -38
  191. data/test/next.rb +0 -18
  192. data/test/null.rb +0 -1
  193. data/test/output.rb +0 -2
  194. data/test/pm-base.rb +0 -17
  195. data/test/pm-bug.rb +0 -3
  196. data/test/pm-catch.rb +0 -12
  197. data/test/pm-catch2.rb +0 -27
  198. data/test/pm-catch3.rb +0 -47
  199. data/test/pm.rb +0 -11
  200. data/test/raise.rb +0 -3
  201. data/test/rdebug-save.1 +0 -7
  202. data/test/runall +0 -12
  203. data/test/scope-var.rb +0 -29
  204. data/test/tdebug.rb +0 -246
  205. data/test/test-annotate.rb +0 -24
  206. data/test/test-break-bad.rb +0 -36
  207. data/test/test-breakpoints.rb +0 -24
  208. data/test/test-catch.rb +0 -24
  209. data/test/test-catch2.rb +0 -24
  210. data/test/test-catch3.rb +0 -24
  211. data/test/test-condition.rb +0 -24
  212. data/test/test-ctrl.rb +0 -51
  213. data/test/test-display.rb +0 -25
  214. data/test/test-dollar-0.rb +0 -39
  215. data/test/test-edit.rb +0 -25
  216. data/test/test-emacs-basic.rb +0 -25
  217. data/test/test-enable.rb +0 -24
  218. data/test/test-finish.rb +0 -33
  219. data/test/test-frame.rb +0 -33
  220. data/test/test-help.rb +0 -54
  221. data/test/test-hist.rb +0 -65
  222. data/test/test-info-thread.rb +0 -31
  223. data/test/test-info-var.rb +0 -46
  224. data/test/test-info.rb +0 -25
  225. data/test/test-init.rb +0 -43
  226. data/test/test-jump.rb +0 -34
  227. data/test/test-list.rb +0 -24
  228. data/test/test-method.rb +0 -33
  229. data/test/test-next.rb +0 -24
  230. data/test/test-output.rb +0 -25
  231. data/test/test-quit.rb +0 -29
  232. data/test/test-raise.rb +0 -24
  233. data/test/test-remote.rb +0 -14
  234. data/test/test-save.rb +0 -30
  235. data/test/test-scope-var.rb +0 -24
  236. data/test/test-setshow.rb +0 -24
  237. data/test/test-source.rb +0 -24
  238. data/test/test-stepping.rb +0 -25
  239. data/test/test-trace.rb +0 -46
  240. data/test/thread1.rb +0 -25
  241. 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
@@ -1,2 +0,0 @@
1
- s = '<%= PRODUCT[:name] %>'
2
- y = 0
data/test/jump.rb DELETED
@@ -1,14 +0,0 @@
1
- def foo
2
- j = 0
3
- [1,2,3,4,5].each { |i|
4
- j = i
5
- [10,11,12].each { |k|
6
- j = j + k
7
- puts j
8
- }
9
- }
10
- puts j
11
- end
12
-
13
- foo
14
- puts "done"
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
@@ -1,18 +0,0 @@
1
- def foo
2
- a = 1
3
- puts "Stop here"
4
- b = 2
5
- end
6
-
7
- a = 1
8
- if a == 1
9
- a += 2
10
- puts a
11
- end
12
- foo
13
- b = 2
14
- b += 2
15
- puts "one"
16
- c = 4
17
- puts "two"
18
-
data/test/null.rb DELETED
@@ -1 +0,0 @@
1
- # Nothing here. Move along.
data/test/output.rb DELETED
@@ -1,2 +0,0 @@
1
- puts "one"
2
- puts "two"
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
@@ -1,3 +0,0 @@
1
- a = 1
2
- @x = 2
3
- raise
data/test/pm-catch.rb DELETED
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Test Debugger.catchpoint and post-mortem handling
3
- def zero_div
4
- x = 5
5
- 1/0
6
- x = 6
7
- end
8
- x = 2
9
- puts zero_div
10
- raise RuntimeError
11
- x = 3
12
-
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
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Test Debugger.catchpoint and post-mortem handling
3
- def zero_div
4
- x = 5
5
- 1/0
6
- end
7
- x = 2
8
- zero_div
9
- raise RuntimeError
10
- x = 3
11
-
data/test/raise.rb DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- raise "abc"
data/test/rdebug-save.1 DELETED
@@ -1,7 +0,0 @@
1
- break gcd.rb:10
2
- break gcd.rb:12 if a > b
3
- set autoeval on
4
- set basename off
5
- set debuggertesting off
6
- set autolist off
7
- set autoirb off
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