debugger 1.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. data/AUTHORS +10 -0
  2. data/CHANGES +334 -0
  3. data/ChangeLog +5655 -0
  4. data/INSTALL.SVN +154 -0
  5. data/LICENSE +23 -0
  6. data/Makefile.am +14 -0
  7. data/OLD_README +122 -0
  8. data/README.md +10 -0
  9. data/Rakefile +266 -0
  10. data/autogen.sh +4 -0
  11. data/bin/rdebug +398 -0
  12. data/cli/ruby-debug.rb +173 -0
  13. data/cli/ruby-debug/command.rb +228 -0
  14. data/cli/ruby-debug/commands/breakpoints.rb +153 -0
  15. data/cli/ruby-debug/commands/catchpoint.rb +55 -0
  16. data/cli/ruby-debug/commands/condition.rb +49 -0
  17. data/cli/ruby-debug/commands/continue.rb +38 -0
  18. data/cli/ruby-debug/commands/control.rb +107 -0
  19. data/cli/ruby-debug/commands/display.rb +120 -0
  20. data/cli/ruby-debug/commands/edit.rb +48 -0
  21. data/cli/ruby-debug/commands/enable.rb +202 -0
  22. data/cli/ruby-debug/commands/eval.rb +176 -0
  23. data/cli/ruby-debug/commands/finish.rb +42 -0
  24. data/cli/ruby-debug/commands/frame.rb +301 -0
  25. data/cli/ruby-debug/commands/help.rb +56 -0
  26. data/cli/ruby-debug/commands/info.rb +467 -0
  27. data/cli/ruby-debug/commands/irb.rb +123 -0
  28. data/cli/ruby-debug/commands/jump.rb +66 -0
  29. data/cli/ruby-debug/commands/kill.rb +51 -0
  30. data/cli/ruby-debug/commands/list.rb +94 -0
  31. data/cli/ruby-debug/commands/method.rb +84 -0
  32. data/cli/ruby-debug/commands/quit.rb +39 -0
  33. data/cli/ruby-debug/commands/reload.rb +40 -0
  34. data/cli/ruby-debug/commands/save.rb +90 -0
  35. data/cli/ruby-debug/commands/set.rb +221 -0
  36. data/cli/ruby-debug/commands/show.rb +247 -0
  37. data/cli/ruby-debug/commands/skip.rb +35 -0
  38. data/cli/ruby-debug/commands/source.rb +36 -0
  39. data/cli/ruby-debug/commands/stepping.rb +81 -0
  40. data/cli/ruby-debug/commands/threads.rb +189 -0
  41. data/cli/ruby-debug/commands/tmate.rb +36 -0
  42. data/cli/ruby-debug/commands/trace.rb +57 -0
  43. data/cli/ruby-debug/commands/variables.rb +199 -0
  44. data/cli/ruby-debug/debugger.rb +5 -0
  45. data/cli/ruby-debug/helper.rb +69 -0
  46. data/cli/ruby-debug/interface.rb +232 -0
  47. data/cli/ruby-debug/processor.rb +474 -0
  48. data/configure.ac +12 -0
  49. data/debugger.gemspec +24 -0
  50. data/doc/.cvsignore +42 -0
  51. data/doc/Makefile.am +63 -0
  52. data/doc/emacs-notes.txt +38 -0
  53. data/doc/hanoi.rb +35 -0
  54. data/doc/primes.rb +28 -0
  55. data/doc/rdebug-emacs.texi +1030 -0
  56. data/doc/rdebug.1 +241 -0
  57. data/doc/ruby-debug.texi +3791 -0
  58. data/doc/test-tri2.rb +18 -0
  59. data/doc/tri3.rb +8 -0
  60. data/doc/triangle.rb +12 -0
  61. data/emacs/Makefile.am +130 -0
  62. data/emacs/rdebug-annotate.el +385 -0
  63. data/emacs/rdebug-breaks.el +407 -0
  64. data/emacs/rdebug-cmd.el +92 -0
  65. data/emacs/rdebug-core.el +502 -0
  66. data/emacs/rdebug-dbg.el +62 -0
  67. data/emacs/rdebug-error.el +79 -0
  68. data/emacs/rdebug-fns.el +111 -0
  69. data/emacs/rdebug-frames.el +230 -0
  70. data/emacs/rdebug-gud.el +242 -0
  71. data/emacs/rdebug-help.el +104 -0
  72. data/emacs/rdebug-info.el +83 -0
  73. data/emacs/rdebug-layouts.el +180 -0
  74. data/emacs/rdebug-locring.el +118 -0
  75. data/emacs/rdebug-output.el +106 -0
  76. data/emacs/rdebug-regexp.el +118 -0
  77. data/emacs/rdebug-secondary.el +260 -0
  78. data/emacs/rdebug-shortkey.el +175 -0
  79. data/emacs/rdebug-source.el +568 -0
  80. data/emacs/rdebug-track.el +392 -0
  81. data/emacs/rdebug-varbuf.el +150 -0
  82. data/emacs/rdebug-vars.el +125 -0
  83. data/emacs/rdebug-watch.el +132 -0
  84. data/emacs/rdebug.el +326 -0
  85. data/emacs/test/elk-test.el +242 -0
  86. data/emacs/test/test-annotate.el +103 -0
  87. data/emacs/test/test-cmd.el +116 -0
  88. data/emacs/test/test-core.el +104 -0
  89. data/emacs/test/test-fns.el +65 -0
  90. data/emacs/test/test-frames.el +62 -0
  91. data/emacs/test/test-gud.el +35 -0
  92. data/emacs/test/test-indent.el +58 -0
  93. data/emacs/test/test-regexp.el +144 -0
  94. data/emacs/test/test-shortkey.el +61 -0
  95. data/ext/ruby_debug/breakpoint.c +586 -0
  96. data/ext/ruby_debug/extconf.rb +49 -0
  97. data/ext/ruby_debug/ruby_debug.c +2624 -0
  98. data/ext/ruby_debug/ruby_debug.h +148 -0
  99. data/lib/ChangeLog +1065 -0
  100. data/lib/debugger.rb +7 -0
  101. data/lib/debugger/version.rb +3 -0
  102. data/lib/ruby-debug-base.rb +304 -0
  103. data/rdbg.rb +33 -0
  104. data/runner.sh +7 -0
  105. data/svn2cl_usermap +3 -0
  106. data/test/.cvsignore +1 -0
  107. data/test/base/base.rb +74 -0
  108. data/test/base/binding.rb +31 -0
  109. data/test/base/catchpoint.rb +26 -0
  110. data/test/base/load.rb +40 -0
  111. data/test/bp_loop_issue.rb +3 -0
  112. data/test/classes.rb +11 -0
  113. data/test/cli/commands/catchpoint_test.rb +36 -0
  114. data/test/cli/commands/unit/regexp.rb +42 -0
  115. data/test/config.yaml +8 -0
  116. data/test/data/annotate.cmd +29 -0
  117. data/test/data/annotate.right +139 -0
  118. data/test/data/break_bad.cmd +18 -0
  119. data/test/data/break_bad.right +28 -0
  120. data/test/data/break_loop_bug.cmd +5 -0
  121. data/test/data/break_loop_bug.right +15 -0
  122. data/test/data/breakpoints.cmd +38 -0
  123. data/test/data/breakpoints.right +98 -0
  124. data/test/data/catch.cmd +20 -0
  125. data/test/data/catch.right +49 -0
  126. data/test/data/catch2.cmd +19 -0
  127. data/test/data/catch2.right +65 -0
  128. data/test/data/catch3.cmd +11 -0
  129. data/test/data/catch3.right +37 -0
  130. data/test/data/condition.cmd +28 -0
  131. data/test/data/condition.right +65 -0
  132. data/test/data/ctrl.cmd +23 -0
  133. data/test/data/ctrl.right +70 -0
  134. data/test/data/display.cmd +24 -0
  135. data/test/data/display.right +44 -0
  136. data/test/data/dollar-0.right +2 -0
  137. data/test/data/dollar-0a.right +2 -0
  138. data/test/data/dollar-0b.right +2 -0
  139. data/test/data/edit.cmd +12 -0
  140. data/test/data/edit.right +19 -0
  141. data/test/data/emacs_basic.cmd +43 -0
  142. data/test/data/emacs_basic.right +106 -0
  143. data/test/data/enable.cmd +20 -0
  144. data/test/data/enable.right +36 -0
  145. data/test/data/finish.cmd +16 -0
  146. data/test/data/finish.right +31 -0
  147. data/test/data/frame.cmd +26 -0
  148. data/test/data/frame.right +55 -0
  149. data/test/data/help.cmd +20 -0
  150. data/test/data/help.right +21 -0
  151. data/test/data/history.right +7 -0
  152. data/test/data/info-thread.cmd +13 -0
  153. data/test/data/info-thread.right +37 -0
  154. data/test/data/info-var-bug2.cmd +5 -0
  155. data/test/data/info-var-bug2.right +10 -0
  156. data/test/data/info-var.cmd +23 -0
  157. data/test/data/info-var.right +52 -0
  158. data/test/data/info.cmd +21 -0
  159. data/test/data/info.right +65 -0
  160. data/test/data/jump.cmd +16 -0
  161. data/test/data/jump.right +56 -0
  162. data/test/data/jump2.cmd +16 -0
  163. data/test/data/jump2.right +44 -0
  164. data/test/data/linetrace.cmd +6 -0
  165. data/test/data/linetrace.right +23 -0
  166. data/test/data/list.cmd +19 -0
  167. data/test/data/list.right +127 -0
  168. data/test/data/method.cmd +10 -0
  169. data/test/data/method.right +21 -0
  170. data/test/data/methodsig.cmd +10 -0
  171. data/test/data/methodsig.right +20 -0
  172. data/test/data/next.cmd +22 -0
  173. data/test/data/next.right +61 -0
  174. data/test/data/noquit.right +1 -0
  175. data/test/data/output.cmd +6 -0
  176. data/test/data/output.right +31 -0
  177. data/test/data/pm-bug.cmd +7 -0
  178. data/test/data/pm-bug.right +12 -0
  179. data/test/data/post-mortem-next.cmd +8 -0
  180. data/test/data/post-mortem-next.right +14 -0
  181. data/test/data/post-mortem-osx.right +31 -0
  182. data/test/data/post-mortem.cmd +13 -0
  183. data/test/data/post-mortem.right +32 -0
  184. data/test/data/quit.cmd +6 -0
  185. data/test/data/quit.right +0 -0
  186. data/test/data/raise.cmd +11 -0
  187. data/test/data/raise.right +23 -0
  188. data/test/data/save.cmd +34 -0
  189. data/test/data/save.right +59 -0
  190. data/test/data/scope-var.cmd +42 -0
  191. data/test/data/scope-var.right +587 -0
  192. data/test/data/setshow.cmd +56 -0
  193. data/test/data/setshow.right +98 -0
  194. data/test/data/source.cmd +5 -0
  195. data/test/data/source.right +15 -0
  196. data/test/data/stepping.cmd +21 -0
  197. data/test/data/stepping.right +50 -0
  198. data/test/data/test-init-cygwin.right +7 -0
  199. data/test/data/test-init-osx.right +4 -0
  200. data/test/data/test-init.right +5 -0
  201. data/test/data/trace.right +14 -0
  202. data/test/dollar-0.rb +5 -0
  203. data/test/gcd-dbg-nox.rb +31 -0
  204. data/test/gcd-dbg.rb +30 -0
  205. data/test/gcd.rb +18 -0
  206. data/test/helper.rb +144 -0
  207. data/test/info-var-bug.rb +47 -0
  208. data/test/info-var-bug2.rb +2 -0
  209. data/test/jump.rb +14 -0
  210. data/test/jump2.rb +27 -0
  211. data/test/next.rb +18 -0
  212. data/test/null.rb +1 -0
  213. data/test/output.rb +2 -0
  214. data/test/pm-base.rb +22 -0
  215. data/test/pm-bug.rb +3 -0
  216. data/test/pm-catch.rb +12 -0
  217. data/test/pm-catch2.rb +27 -0
  218. data/test/pm-catch3.rb +47 -0
  219. data/test/pm.rb +11 -0
  220. data/test/raise.rb +3 -0
  221. data/test/rdebug-save.1 +7 -0
  222. data/test/runall +12 -0
  223. data/test/scope-var.rb +29 -0
  224. data/test/tdebug.rb +248 -0
  225. data/test/test-annotate.rb +25 -0
  226. data/test/test-break-bad.rb +37 -0
  227. data/test/test-breakpoints.rb +25 -0
  228. data/test/test-catch.rb +25 -0
  229. data/test/test-catch2.rb +25 -0
  230. data/test/test-catch3.rb +25 -0
  231. data/test/test-condition.rb +25 -0
  232. data/test/test-ctrl.rb +55 -0
  233. data/test/test-display.rb +26 -0
  234. data/test/test-dollar-0.rb +40 -0
  235. data/test/test-edit.rb +26 -0
  236. data/test/test-emacs-basic.rb +26 -0
  237. data/test/test-enable.rb +25 -0
  238. data/test/test-finish.rb +34 -0
  239. data/test/test-frame.rb +34 -0
  240. data/test/test-help.rb +60 -0
  241. data/test/test-hist.rb +68 -0
  242. data/test/test-info-thread.rb +32 -0
  243. data/test/test-info-var.rb +47 -0
  244. data/test/test-info.rb +26 -0
  245. data/test/test-init.rb +44 -0
  246. data/test/test-jump.rb +35 -0
  247. data/test/test-list.rb +25 -0
  248. data/test/test-method.rb +34 -0
  249. data/test/test-next.rb +25 -0
  250. data/test/test-output.rb +26 -0
  251. data/test/test-quit.rb +30 -0
  252. data/test/test-raise.rb +25 -0
  253. data/test/test-save.rb +31 -0
  254. data/test/test-scope-var.rb +25 -0
  255. data/test/test-setshow.rb +25 -0
  256. data/test/test-source.rb +25 -0
  257. data/test/test-stepping.rb +26 -0
  258. data/test/test-trace.rb +47 -0
  259. data/test/thread1.rb +26 -0
  260. data/test/trunc-call.rb +31 -0
  261. metadata +364 -0
@@ -0,0 +1,56 @@
1
+ # This tests the functioning of some set/show debugger commands
2
+ set debuggertesting on
3
+ ### *******************************
4
+ ### *** Set/show commands ***
5
+ ### *******************************
6
+ ########################################
7
+ ### test args and baseneme...
8
+ ########################################
9
+ set args this is a test
10
+ show args
11
+ show basename
12
+ set basename foo
13
+ show base
14
+ set basename off
15
+ show basename
16
+ set basename 0
17
+ show basename
18
+ set basename 1
19
+ show basename
20
+ ########################################
21
+ ### test listsize tests...
22
+ ########################################
23
+ show listsize
24
+ show listsi
25
+ set listsize abc
26
+ set listsize -20
27
+ ########################################
28
+ ### test linetrace...
29
+ ########################################
30
+ set linetrace on
31
+ show linetrace
32
+ set linetrace off
33
+ show linetrace
34
+ ########################################
35
+ ### show history
36
+ ########################################
37
+ set history
38
+ set history size 10
39
+ show history size
40
+ set history save off
41
+ show history save
42
+ set history save 1
43
+ show history save
44
+ #### Test 'autoeval'...
45
+ set autoeval on
46
+ puts 'printed via autoeval'
47
+ set autoeval off
48
+ puts 'autoeval should not run this'
49
+ #### Test 'callstyle'...
50
+ set callstyle
51
+ set callstyle short
52
+ set callstyle last
53
+ set callstyle tracked
54
+ set callstyle foo
55
+
56
+
@@ -0,0 +1,98 @@
1
+ gcd.rb:4
2
+ def gcd(a, b)
3
+ # # This tests the functioning of some set/show debugger commands
4
+ # set debuggertesting on
5
+ Currently testing the debugger is on.
6
+ # ### *******************************
7
+ # ### *** Set/show commands ***
8
+ # ### *******************************
9
+ # ########################################
10
+ # ### test args and baseneme...
11
+ # ########################################
12
+ # set args this is a test
13
+ Argument list to give program being debugged when it is started is "this is a test".
14
+ # show args
15
+ Argument list to give program being debugged when it is started is "this is a test".
16
+ # show basename
17
+ basename is on.
18
+ # set basename foo
19
+ Expecting 'on', 1, 'off', or 0. Got: foo.
20
+ # show base
21
+ basename is on.
22
+ # set basename off
23
+ basename is off.
24
+ # show basename
25
+ basename is off.
26
+ # set basename 0
27
+ basename is off.
28
+ # show basename
29
+ basename is off.
30
+ # set basename 1
31
+ basename is on.
32
+ # show basename
33
+ basename is on.
34
+ # ########################################
35
+ # ### test listsize tests...
36
+ # ########################################
37
+ # show listsize
38
+ Number of source lines to list by default is 10.
39
+ # show listsi
40
+ Number of source lines to list by default is 10.
41
+ # set listsize abc
42
+ Set listsize argument 'abc' needs to be a number.
43
+ # set listsize -20
44
+ Set listsize argument '-20' needs to at least 1.
45
+ # ########################################
46
+ # ### test linetrace...
47
+ # ########################################
48
+ # set linetrace on
49
+ line tracing is on.
50
+ # show linetrace
51
+ line tracing is on.
52
+ # set linetrace off
53
+ line tracing is off.
54
+ # show linetrace
55
+ line tracing is off.
56
+ # ########################################
57
+ # ### show history
58
+ # ########################################
59
+ # set history
60
+ Need two parameters for 'set history'; got 0.
61
+ # set history size 10
62
+ Debugger history size is 10
63
+ # show history size
64
+ Debugger history size is 10
65
+ # set history save off
66
+ Saving of history save is off.
67
+ # show history save
68
+ Saving of history save is off.
69
+ # set history save 1
70
+ Saving of history save is on.
71
+ # show history save
72
+ Saving of history save is on.
73
+ # #### Test 'autoeval'...
74
+ # set autoeval on
75
+ autoeval is on.
76
+ # puts 'printed via autoeval'
77
+ printed via autoeval
78
+ nil
79
+ # set autoeval off
80
+ autoeval is off.
81
+ # puts 'autoeval should not run this'
82
+ *** Unknown command: "puts 'autoeval should not run this'". Try "help".
83
+ # #### Test 'callstyle'...
84
+ # set callstyle
85
+ Invalid call style . Should be one of: 'short' or 'last'.
86
+ Frame call-display style is last.
87
+ # set callstyle short
88
+ Frame call-display style is short.
89
+ # set callstyle last
90
+ Frame call-display style is last.
91
+ # set callstyle tracked
92
+ Invalid call style tracked. Should be one of: 'short' or 'last'.
93
+ Frame call-display style is last.
94
+ # set callstyle foo
95
+ Invalid call style foo. Should be one of: 'short' or 'last'.
96
+ Frame call-display style is last.
97
+ #
98
+ #
@@ -0,0 +1,5 @@
1
+ # Test the source command
2
+ # rdebug-save has breakpoint commands
3
+ set debuggertesting on
4
+ source ./rdebug-save.1
5
+ quit
@@ -0,0 +1,15 @@
1
+ gcd.rb:4
2
+ def gcd(a, b)
3
+ # # Test the source command
4
+ # # rdebug-save has breakpoint commands
5
+ # set debuggertesting on
6
+ Currently testing the debugger is on.
7
+ # source ./rdebug-save.1
8
+ Breakpoint 1 file gcd.rb, line 10
9
+ Breakpoint 2 file gcd.rb, line 12
10
+ autoeval is on.
11
+ basename is off.
12
+ Currently testing the debugger is on.
13
+ autolist is off.
14
+ autoirb is off.
15
+ # quit
@@ -0,0 +1,21 @@
1
+ # ***************************************************
2
+ # This tests step, next, finish and continue
3
+ # ***************************************************
4
+ set debuggertesting on
5
+ set callstyle last
6
+ next
7
+ where
8
+ step a
9
+ set forcestep on
10
+ step- ; step-
11
+ set forcestep off
12
+ where
13
+ next
14
+ step+
15
+ where
16
+ step 3
17
+ step+
18
+ where
19
+ next+
20
+ # finish
21
+ quit
@@ -0,0 +1,50 @@
1
+ gcd.rb:4
2
+ def gcd(a, b)
3
+ # # ***************************************************
4
+ # # This tests step, next, finish and continue
5
+ # # ***************************************************
6
+ # set debuggertesting on
7
+ Currently testing the debugger is on.
8
+ # set callstyle last
9
+ Frame call-display style is last.
10
+ # next
11
+ gcd.rb:18
12
+ gcd(3,5)
13
+ # where
14
+ --> #0 at line gcd.rb:18
15
+ # step a
16
+ Step argument 'a' needs to be a number.
17
+ # set forcestep on
18
+ force-stepping is on.
19
+ # step- ; step-
20
+ gcd.rb:6
21
+ if a > b
22
+ # set forcestep off
23
+ force-stepping is off.
24
+ # where
25
+ --> #0 Object.gcd(a#Fixnum, b#Fixnum) at line gcd.rb:6
26
+ #1 at line gcd.rb:18
27
+ # next
28
+ gcd.rb:10
29
+ return nil if a <= 0
30
+ # step+
31
+ gcd.rb:12
32
+ if a == 1 or b-a == 0
33
+ # where
34
+ --> #0 Object.gcd(a#Fixnum, b#Fixnum) at line gcd.rb:12
35
+ #1 at line gcd.rb:18
36
+ # step 3
37
+ gcd.rb:10
38
+ return nil if a <= 0
39
+ # step+
40
+ gcd.rb:12
41
+ if a == 1 or b-a == 0
42
+ # where
43
+ --> #0 Object.gcd(a#Fixnum, b#Fixnum) at line gcd.rb:12
44
+ #1 Object.gcd(a#Fixnum, b#Fixnum) at line gcd.rb:15
45
+ #2 at line gcd.rb:18
46
+ # next+
47
+ gcd.rb:15
48
+ gcd(b-a, a)
49
+ # # finish
50
+ # quit
@@ -0,0 +1,7 @@
1
+ gcd-dbg.rb:18
2
+ if a > b
3
+ (rdb:1) p Debugger::PROG_SCRIPT
4
+ "./gcd-dbg.rb"
5
+ (rdb:1) show args
6
+ Argument list to give program being debugged when it is started is "5".
7
+ (rdb:1) quit unconditionally
@@ -0,0 +1,4 @@
1
+ gcd-dbg.rb:18
2
+ if a > b
3
+ "./gcd-dbg.rb"
4
+ Argument list to give program being debugged when it is started is "5".
@@ -0,0 +1,5 @@
1
+ gcd-dbg.rb:18
2
+ if a > b
3
+ (rdb:1) "./gcd-dbg.rb"
4
+ (rdb:1) Argument list to give program being debugged when it is started is "5".
5
+ (rdb:1)
@@ -0,0 +1,14 @@
1
+ Tracing(1):./gcd.rb:4 def gcd(a, b)
2
+ Tracing(1):./gcd.rb:18 gcd(3,5)
3
+ Tracing(1):./gcd.rb:6 if a > b
4
+ Tracing(1):./gcd.rb:10 return nil if a <= 0
5
+ Tracing(1):./gcd.rb:12 if a == 1 or b-a == 0
6
+ Tracing(1):./gcd.rb:15 gcd(b-a, a)
7
+ Tracing(1):./gcd.rb:6 if a > b
8
+ Tracing(1):./gcd.rb:10 return nil if a <= 0
9
+ Tracing(1):./gcd.rb:12 if a == 1 or b-a == 0
10
+ Tracing(1):./gcd.rb:15 gcd(b-a, a)
11
+ Tracing(1):./gcd.rb:6 if a > b
12
+ Tracing(1):./gcd.rb:10 return nil if a <= 0
13
+ Tracing(1):./gcd.rb:12 if a == 1 or b-a == 0
14
+ Tracing(1):./gcd.rb:13 return a
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # A test to see that rdebug set's $0 properly.
3
+ puts $0
4
+ puts __FILE__
5
+
@@ -0,0 +1,31 @@
1
+ # This program is *NOT* supposed to be executable, but called
2
+ # via ruby (in order to test that restart provides a funky $:).
3
+ # This program is used to test that 'restart' works when we didn't call
4
+ # the debugger initially.
5
+
6
+ TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__), '..')) unless
7
+ defined?(TOP_SRC_DIR)
8
+
9
+ $:.unshift File.join(TOP_SRC_DIR, 'ext')
10
+ $:.unshift File.join(TOP_SRC_DIR, 'lib')
11
+ $:.unshift File.join(TOP_SRC_DIR, 'cli')
12
+ require 'ruby-debug'
13
+ Debugger.init
14
+
15
+ # GCD. We assume positive numbers
16
+ def gcd(a, b)
17
+ # Make: a <= b
18
+ debugger
19
+ if a > b
20
+ a, b = [b, a]
21
+ end
22
+
23
+ return nil if a <= 0
24
+
25
+ if a == 1 or b-a == 0
26
+ return a
27
+ end
28
+ return gcd(b-a, a)
29
+ end
30
+
31
+ gcd(3,5)
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ # This program is used to test that 'restart' works when we didn't call
3
+ # the debugger initially.
4
+
5
+ TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__), "..")) unless
6
+ defined?(TOP_SRC_DIR)
7
+
8
+ $:.unshift File.join(TOP_SRC_DIR, "ext")
9
+ $:.unshift File.join(TOP_SRC_DIR, "lib")
10
+ $:.unshift File.join(TOP_SRC_DIR, "cli")
11
+ require 'ruby-debug'
12
+
13
+
14
+ # GCD. We assume positive numbers
15
+ def gcd(a, b)
16
+ # Make: a <= b
17
+ debugger
18
+ if a > b
19
+ a, b = [b, a]
20
+ end
21
+
22
+ return nil if a <= 0
23
+
24
+ if a == 1 or b-a == 0
25
+ return a
26
+ end
27
+ return gcd(b-a, a)
28
+ end
29
+
30
+ gcd(3,5)
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # GCD. We assume positive numbers
4
+ def gcd(a, b)
5
+ # Make: a <= b
6
+ if a > b
7
+ a, b = [b, a]
8
+ end
9
+
10
+ return nil if a <= 0
11
+
12
+ if a == 1 or b-a == 0
13
+ return a
14
+ end
15
+ gcd(b-a, a)
16
+ end
17
+
18
+ gcd(3,5)
@@ -0,0 +1,144 @@
1
+ # Some common routines used in testing.
2
+
3
+ require 'fileutils'
4
+ require 'yaml'
5
+ # require 'diff/lcs'
6
+ # require 'diff/lcs/hunk'
7
+
8
+ # begin require 'rubygems' rescue LoadError end
9
+ # require 'ruby-debug'; Debugger.start
10
+
11
+ module TestHelper
12
+
13
+ # FIXME: turn args into a hash.
14
+ def run_debugger(testname, args='', outfile=nil, filter=nil, old_code=false,
15
+ debug_pgm='tdebug.rb')
16
+ rightfile = File.join('data', "#{testname}.right")
17
+
18
+ outfile = "#{testname}.out" unless outfile
19
+
20
+ if File.exists?(outfile)
21
+ FileUtils.rm(outfile)
22
+ end
23
+
24
+ ENV['RDEBUG'] = debug_pgm
25
+
26
+ if old_code
27
+ cmd = "/bin/sh #{File.join('..', 'runner.sh')} #{args} >#{outfile}"
28
+ else
29
+ cmd = "#{"#{load_ruby} #{load_params} "}../rdbg.rb #{args} > #{outfile}"
30
+ end
31
+ puts "'#{cmd}'" if $DEBUG
32
+ output = `#{cmd}`
33
+
34
+ curr_path = Dir.pwd
35
+ got_lines = File.read(outfile).split(/\n/).map{|s| s.sub(curr_path, '.') }
36
+ correct_lines = File.read(rightfile).split(/\n/)
37
+ filter.call(got_lines, correct_lines) if filter
38
+ if cheap_diff(got_lines, correct_lines)
39
+ FileUtils.rm(outfile)
40
+ return true
41
+ end
42
+ return false
43
+ end
44
+
45
+ def cheap_diff(got_lines, correct_lines)
46
+ if $DEBUG
47
+ got_lines.each_with_index do |line, i|
48
+ printf "%3d %s\n", i+1, line
49
+ end
50
+ end
51
+ correct_lines.each_with_index do |line, i|
52
+ correct_lines[i].chomp!
53
+ if got_lines[i] != correct_lines[i]
54
+ puts "difference found at line #{i+1}"
55
+ puts "got : #{got_lines[i]}"
56
+ puts "need: #{correct_lines[i]}"
57
+ return false
58
+ end
59
+ end
60
+ if correct_lines.size != got_lines.size
61
+ puts("difference in number of lines: " +
62
+ "#{correct_lines.size} vs. #{got_lines.size}")
63
+ return false
64
+ end
65
+ return true
66
+ end
67
+
68
+ # FIXME: using this causes the same test to get run several times
69
+ # and some tests fail probably because of a lack of environment isolation.
70
+ # Many tests follow a basic pattern: run the debugger with a given
71
+ # debugger script and compare output produced. The following creates
72
+ # this kind of test.
73
+ def add_test(base_name, src_dir, script_name=nil, cmd=nil, test_name=nil)
74
+ puts "+++ Adding #{base_name} ++++" if $DEBUG
75
+ test_name = base_name unless test_name
76
+ script_name = File.join('data', test_name + '.cmd') unless script_name
77
+ cmd = 'gcd.rb 3 5' unless cmd
78
+ eval <<-EOF
79
+ def test_#{test_name}
80
+ Dir.chdir(\"#{src_dir}\") do
81
+ assert_equal(true,
82
+ run_debugger(\"#{base_name}\",
83
+ \"--script #{script_name} -- #{cmd}\"))
84
+ end
85
+ end
86
+ EOF
87
+ end
88
+ module_function :add_test
89
+
90
+ # Adapted from the Ruby Cookbook, Section 6.10: Comparing two files.
91
+ # def diff_as_string(rightfile, checkfile, format=:unified, context_lines=3)
92
+ # right_data = File.read(rightfile)
93
+ # check_data = File.read(checkfile)
94
+ # output = ''
95
+ # diffs = Diff::LCS.diff(right_data, check_data)
96
+ # return output if diffs.empty?
97
+ # oldhunk = hunk = nil
98
+ # file_length_difference = 0
99
+ # diffs.each do |piece|
100
+ # begin
101
+ # hunk = Diff::LCS::Hunk.new(right_data, check_data, piece,
102
+ # context_lines, file_length_difference)
103
+ # next unless oldhunk
104
+ #
105
+ # # Hunks may overlap, which is why we need to be careful when our
106
+ # # diff includes lines of context. Otherwise, we might print
107
+ # # redundant lines.
108
+ # if (context_lines > 0) and hunk.overlaps?(oldhunk)
109
+ # hunk.unshift(oldhunk)
110
+ # else
111
+ # output << oldhunk.diff(format)
112
+ # end
113
+ # ensure
114
+ # oldhunk = hunk
115
+ # output << '\n'
116
+ # end
117
+ # end
118
+
119
+ # # Handle the last remaining hunk
120
+ # output << oldhunk.diff(format) << '\n'
121
+ # end
122
+
123
+ # Loads key from the _config_._yaml_ file.
124
+ def config_load(key, may_be_nil=false, default_value='')
125
+ conf = File.join('config.private.yaml') # try private first
126
+ conf = File.join('config.yaml') unless File.exists?(conf)
127
+ value = YAML.load_file(conf)[key]
128
+ assert_not_nil(value, "#{key} is set in config.yaml") unless may_be_nil
129
+ value || default_value
130
+ end
131
+ module_function :config_load
132
+
133
+ def load_ruby
134
+ config_load('ruby', true)
135
+ end
136
+ module_function :load_ruby
137
+
138
+ def load_params
139
+ config_load('ruby_params', true)
140
+ end
141
+ module_function :load_params
142
+
143
+ end
144
+