debugger 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
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,18 @@
1
+ #!/usr/bin/env ruby
2
+ require "test/unit"
3
+ require "tri2.rb"
4
+ require "rubygems"
5
+ require "ruby-debug"
6
+ Debugger.start
7
+
8
+ class TestTri < Test::Unit::TestCase
9
+ def test_basic
10
+ debugger
11
+ solutions = []
12
+ 0.upto(5) do |i|
13
+ solutions << triangle(i)
14
+ end
15
+ assert_equal([0, 1, 3, 6, 10, 15], solutions,
16
+ "Testing the first 5 triangle numbers")
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ def triangle(n)
3
+ (0..n).inject do |sum, i|
4
+ sum +=i
5
+ end
6
+ end
7
+ puts triangle(3)
8
+
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # Compute the n'th triangle number - the hard way
3
+ # triangle(n) == (n * (n+1)) / 2
4
+ def triangle(n)
5
+ tri = 0
6
+ 0.upto(n) do |i|
7
+ tri += i
8
+ end
9
+ return tri
10
+ end
11
+
12
+ puts triangle(3)
@@ -0,0 +1,130 @@
1
+ # Copyright (C) 2007, 2008 Rocky Bernstein rocky@gnu.org
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify it under
4
+ # the terms of the GNU General Public License as published by the Free
5
+ # Software Foundation; either version 2, or (at your option) any later
6
+ # version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful, but WITHOUT ANY
9
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11
+ # for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with Bash; see the file COPYING. If not, write to the Free Software
15
+ # Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
16
+ #$Id: Makefile.am,v 1.10 2007/04/13 00:59:33 rockyb Exp $
17
+
18
+ lisp_files = rdebug.el \
19
+ rdebug-annotate.el \
20
+ rdebug-breaks.el \
21
+ rdebug-cmd.el \
22
+ rdebug-core.el \
23
+ rdebug-dbg.el \
24
+ rdebug-error.el \
25
+ rdebug-fns.el \
26
+ rdebug-frames.el \
27
+ rdebug-gud.el \
28
+ rdebug-help.el \
29
+ rdebug-info.el \
30
+ rdebug-layouts.el \
31
+ rdebug-locring.el \
32
+ rdebug-output.el \
33
+ rdebug-regexp.el \
34
+ rdebug-secondary.el\
35
+ rdebug-shortkey.el \
36
+ rdebug-source.el \
37
+ rdebug-track.el \
38
+ rdebug-varbuf.el \
39
+ rdebug-vars.el \
40
+ rdebug-watch.el
41
+ check_DATA = test/elk-test.el \
42
+ test/test-annotate.el \
43
+ test/test-cmd.el \
44
+ test/test-core.el \
45
+ test/test-fns.el \
46
+ test/test-gud.el \
47
+ test/test-indent.el \
48
+ test/test-regexp.el \
49
+ test/test-shortkey.el
50
+
51
+ EXTRA_DIST = $(lisp_files) $(check_DATA)
52
+ ELCFILES = rdebug.elc \
53
+ rdebug-annotate.elc \
54
+ rdebug-breaks.elc \
55
+ rdebug-cmd.elc \
56
+ rdebug-core.elc \
57
+ rdebug-dbg.elc \
58
+ rdebug-error.elc \
59
+ rdebug-fns.elc \
60
+ rdebug-gud.elc \
61
+ rdebug-frames.elc \
62
+ rdebug-help.elc \
63
+ rdebug-info.elc \
64
+ rdebug-layouts.elc \
65
+ rdebug-locring.elc \
66
+ rdebug-output.elc \
67
+ rdebug-regexp.elc \
68
+ rdebug-secondary.elc \
69
+ rdebug-shortkey.elc \
70
+ rdebug-source.elc \
71
+ rdebug-track.elc \
72
+ rdebug-varbuf.elc \
73
+ rdebug-vars.elc \
74
+ rdebug-watch.elc
75
+ if INSTALL_EMACS_LISP
76
+ lisp_LISP = $(lisp_files)
77
+ CHECK_FILES = \
78
+ check-annotate \
79
+ check-cmd \
80
+ check-core \
81
+ check-fns \
82
+ check-frames \
83
+ check-gud \
84
+ check-indent \
85
+ check-regexp \
86
+ check-shortkey
87
+
88
+ check: $(CHECK_FILES)
89
+
90
+ check-annotate: rdebug-annotate.el
91
+ (cd $(srcdir)/test && \
92
+ $(EMACS) -batch -q -l test-annotate.el )
93
+
94
+ check-cmd: rdebug-gud.el
95
+ (cd $(srcdir)/test && \
96
+ $(EMACS) -batch -q -l test-cmd.el )
97
+
98
+ check-core: rdebug-core.el
99
+ (cd $(srcdir)/test && \
100
+ $(EMACS) -batch -q -l test-core.el )
101
+
102
+ check-fns: rdebug-fns.el
103
+ (cd $(srcdir)/test && \
104
+ $(EMACS) -batch -q -l test-fns.el )
105
+
106
+ check-frames: rdebug-frames.el
107
+ (cd $(srcdir)/test && \
108
+ $(EMACS) -batch -q -l test-frames.el )
109
+
110
+ check-gud: rdebug-gud.el
111
+ (cd $(srcdir)/test && \
112
+ $(EMACS) -batch -q -l test-gud.el )
113
+
114
+ check-indent: $(lisp_files)
115
+ (cd $(srcdir)/test && \
116
+ $(EMACS) -batch -q -l test-indent.el )
117
+
118
+ check-regexp: rdebug-regexp.el
119
+ (cd $(srcdir)/test && \
120
+ $(EMACS) -batch -q -l test-regexp.el )
121
+
122
+ check-shortkey: rdebug-shortkey.el
123
+ (cd $(srcdir)/test && \
124
+ $(EMACS) -batch -q -l test-shortkey.el )
125
+ endif
126
+
127
+ PHONY = $(CHECK_FILES)
128
+
129
+ test: check
130
+
@@ -0,0 +1,385 @@
1
+ ;;; rdebug-annotate.el --- Ruby debugger output filtering - which
2
+ ;;; includes annotation handling.
3
+
4
+ ;; Copyright (C) 2008 Rocky Bernstein (rocky@gnu.org)
5
+ ;; Copyright (C) 2008 Anders Lindgren
6
+
7
+ ;; $Id: rdebug-annotate.el 786 2008-04-02 00:50:27Z rockyb $
8
+
9
+ ;; This program is free software; you can redistribute it and/or modify
10
+ ;; it under the terms of the GNU General Public License as published by
11
+ ;; the Free Software Foundation; either version 2, or (at your option)
12
+ ;; any later version.
13
+
14
+ ;; This program is distributed in the hope that it will be useful,
15
+ ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ ;; GNU General Public License for more details.
18
+
19
+ ;; You should have received a copy of the GNU General Public License
20
+ ;; along with GNU Emacs; see the file COPYING. If not, write to the
21
+ ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22
+ ;; Boston, MA 02111-1307, USA.
23
+
24
+ ;;; Commentary:
25
+
26
+ ;; This file contains code dealing with filter of debugger output a large
27
+ ;; part of which may contain annotations.
28
+
29
+ ;;; Code:
30
+
31
+ (require 'gud)
32
+ (require 'gdb-ui)
33
+ (require 'rdebug-dbg)
34
+ (require 'rdebug-error)
35
+ (require 'rdebug-fns)
36
+ (require 'rdebug-info)
37
+ (require 'rdebug-layouts)
38
+ (require 'rdebug-locring)
39
+ (require 'rdebug-regexp)
40
+ (require 'rdebug-shortkey)
41
+ (require 'rdebug-source)
42
+ (require 'rdebug-vars)
43
+
44
+ (defvar rdebug-non-annotated-text-kind nil
45
+ "Represent what non-annotated text is.
46
+
47
+ This can be:
48
+ * nil -- plain shell output
49
+ * :output -- output from the command being debugged
50
+ * :info -- text for the \"info\" secondary window.
51
+ * :message -- message the text to the echo area.
52
+ * :cmd -- a command + result, which might go into the \"info\" window.
53
+
54
+ See the function `rdebug-cmd-process' for details on :cmd.")
55
+
56
+ (defvar rdebug-annotation-setup-map
57
+ (progn
58
+ (define-hash-table-test 'str-hash 'string= 'sxhash)
59
+ (let ((map (make-hash-table :test 'str-hash)))
60
+ (puthash "breakpoints" 'rdebug-setup-breakpoints-buffer map)
61
+ ;;(puthash "error" 'rdebug-setup-error-buffer map)
62
+ (puthash "frame" 'rdebug-setup-frame-buffer map)
63
+ (puthash "variables" 'rdebug-setup-variables-buffer map)
64
+ (puthash "watch" 'rdebug-setup-watch-buffer map)
65
+ (puthash "output" 'rdebug-setup-output-buffer map)
66
+ (puthash "info" 'rdebug-setup-info-buffer map)
67
+ (puthash "help" 'rdebug-setup-secondary-window-help-buffer map)
68
+ map)))
69
+
70
+ (defun rdebug-temp-show (text)
71
+ "Arrange to show string as in sort of temporary way. Perhaps like a tooltip"
72
+ (tooltip-show text))
73
+
74
+ (defun rdebug-marker-filter-next-item (string)
75
+ "The next item for the rdebug marker filter to process.
76
+
77
+ Return (item . rest) or nil."
78
+ (rdebug-debug-message "ACC: %S" string)
79
+ (cond
80
+ ;; Empty line, we're done.
81
+ ((equal (length string) 0)
82
+ nil)
83
+ ;; A single ^Z, this could become a new annotation, so lets stop here.
84
+ ((string= string "\032")
85
+ nil)
86
+ ;; A half-baked annotation, lets stop here.
87
+ ((and (string-match "^\032\032" string)
88
+ (not (string-match "\n" string)))
89
+ nil)
90
+ (t
91
+ (let ((split-point
92
+ (cond ((string-match "\032\032" string)
93
+ (let ((beg (match-beginning 0)))
94
+ (if (equal beg 0)
95
+ (if (string-match "^\032\032" string 2)
96
+ (match-beginning 0)
97
+ (length string))
98
+ beg)))
99
+ ((eq (elt string (- (length string) 1)) ?\32)
100
+ -1)
101
+ (t
102
+ (length string)))))
103
+ (cons (substring string 0 split-point) (substring string split-point))))))
104
+
105
+ ;; There's no guarantee that Emacs will hand the filter the entire
106
+ ;; marker at once; it could be broken up across several strings. We
107
+ ;; might even receive a big chunk with several markers in it. If we
108
+ ;; receive a chunk of text which looks like it might contain the
109
+ ;; beginning of a marker, we save it here between calls to the
110
+ ;; filter.
111
+ (defun gud-rdebug-marker-filter (string)
112
+ "Filter function for process output of the rdebug Ruby debugger."
113
+ (rdebug-debug-enter "gud-rdebug-marker-filter:"
114
+ (rdebug-debug-message "GOT: %S" string)
115
+ (if rdebug-non-annotated-text-kind
116
+ (rdebug-debug-message " Text is %S" rdebug-non-annotated-text-kind))
117
+ (setq gud-marker-acc (concat gud-marker-acc string))
118
+ (rdebug-debug-message "TOT: %S" gud-marker-acc)
119
+ (let ((shell-output "") ; Output to debugger shell window.
120
+ (done nil)
121
+ item)
122
+ ;; The following loop peels of one "item" at a time. An item is
123
+ ;; a un-annotated section or an annotation. (This is taken care
124
+ ;; of by the `rdebug-marker-filter-next-item' function.)
125
+ ;;
126
+ ;; An Annotation can be a one-liner (where anything following
127
+ ;; the annotation is treated as un-annotated text) or a full
128
+ ;; annotation (which stretches to the next annotation).
129
+ ;;
130
+ ;; The concept of one-liners (no phun intended) is to allow
131
+ ;; continuous output, a "starting" annotation simply sets up the
132
+ ;; environment for sending lines to the output window, any text
133
+ ;; following it right now, or in later chunks of data, is
134
+ ;; redirected to the output window.
135
+ (while (and (not done)
136
+ (let ((pair (rdebug-marker-filter-next-item gud-marker-acc)))
137
+ (rdebug-debug-message "Next item: %S" pair)
138
+ (and pair
139
+ (progn
140
+ (setq item (car pair))
141
+ (setq gud-marker-acc (cdr pair))
142
+ t))))
143
+ ;; Note: Regexp:s are greedy, i.e. the char parts wins over
144
+ ;; the .* part.
145
+ (if (not (string-match "^\032\032\\([-a-z]*\\).*\n" item))
146
+ ;; Non-annotated text (or the content of one-liners) goes
147
+ ;; straight into the debugger shell window, or to the
148
+ ;; output window.
149
+ (cond ((and (eq rdebug-non-annotated-text-kind :output)
150
+ rdebug-use-separate-io-buffer)
151
+ (rdebug-process-annotation "starting" item))
152
+ ((eq rdebug-non-annotated-text-kind :info)
153
+ (rdebug-process-annotation "info" item))
154
+ (t
155
+ (if (eq rdebug-non-annotated-text-kind :cmd)
156
+ (rdebug-cmd-process item))
157
+ (setq shell-output (concat shell-output item))))
158
+ ;; Handle annotation.
159
+ (let* ((line-end (match-end 0))
160
+ (name (match-string 1 item))
161
+ ;; "prompt" is needed to handle "quit" in the shell correctly.
162
+ (one-liner
163
+ (member name
164
+ '("" "exited" "source" "prompt" "starting")))
165
+ (next-annotation (string-match "\032\032"
166
+ gud-marker-acc)))
167
+ ;; For one-liners, shuffle some text back to the accumulator.
168
+ (when one-liner
169
+ (setq gud-marker-acc (concat (substring item line-end)
170
+ gud-marker-acc))
171
+ (setq item (substring item 0 line-end)))
172
+ (if (or next-annotation
173
+ one-liner)
174
+ ;; ok, annotation complete, process it and remove it
175
+ (let* ((contents (substring item line-end))
176
+ (old-kind rdebug-non-annotated-text-kind))
177
+ (rdebug-debug-message "Name: %S Content: %S Kind: %S"
178
+ name contents
179
+ rdebug-non-annotated-text-kind)
180
+
181
+ ;; This is a global state flag, this allows us to
182
+ ;; redirect any further text to the output buffer.
183
+ (set
184
+ (make-local-variable 'rdebug-non-annotated-text-kind)
185
+ (cond ((string= name "starting")
186
+ :output)
187
+ ((string= name "prompt")
188
+ (rdebug-cmd-clear)
189
+ :cmd)
190
+ ((string= name "exited")
191
+ ;; Create a fake command whose output we
192
+ ;; handle in the cmd system. (We might not
193
+ ;; receive all of the message at once, we we
194
+ ;; need some kind of accumukator, which the
195
+ ;; cmd system provides.)
196
+ (setq rdebug-inferior-status "exited")
197
+ (rdebug-cmd-clear)
198
+ (setq rdebug-call-queue
199
+ (cons '("***exited***" :message)
200
+ rdebug-call-queue))
201
+ :cmd)
202
+ (t nil)))
203
+
204
+ (when (and (eq old-kind :cmd)
205
+ (not (eq rdebug-non-annotated-text-kind :cmd)))
206
+ (rdebug-debug-message
207
+ "New kind: %S" rdebug-non-annotated-text-kind)
208
+ (rdebug-cmd-done))
209
+
210
+ ;; Process the annotation.
211
+ (cond ((string= name "starting")
212
+ (setq rdebug-inferior-status "running"))
213
+ ((string= name "stopped")
214
+ (setq rdebug-inferior-status "stopped"))
215
+ ((string= name "exited")
216
+ (setq rdebug-inferior-status "exited"))
217
+ ((string= name "pre-prompt")
218
+ ;; Strip of the trailing \n (this is probably
219
+ ;; a bug in processor.rb).
220
+ (if (string= (substring contents -1) "\n")
221
+ (setq contents (substring contents 0 -1)))
222
+ (if (string-match "post-mortem" contents)
223
+ (setq rdebug-inferior-status "crashed"))
224
+ (setq shell-output (concat shell-output contents)))
225
+ ((string= name "source")
226
+ (if (string-match gud-rdebug-marker-regexp item)
227
+ ;; Extract the frame position from the marker.
228
+ (setq gud-last-frame
229
+ (cons (match-string 1 item)
230
+ (string-to-number
231
+ (match-string 2 item))))))
232
+ (t (rdebug-process-annotation name contents))))
233
+ ;; This is not a one-liner, and we haven't seen the next
234
+ ;; annotation, so we have to treat this as a partial
235
+ ;; annotation. Save it and hope that the we can process
236
+ ;; it the next time we're called.
237
+ (setq gud-marker-acc (concat item gud-marker-acc))
238
+ (setq done t)))))
239
+
240
+ (when gud-last-frame
241
+ ;; Display the source file where we want it, gud will only pick
242
+ ;; an arbitrary window.
243
+ (rdebug-pick-source-window)
244
+ (rdebug-set-frame-arrow (gud-find-file (car gud-last-frame)))
245
+ (if (equal 0 rdebug-frames-current-frame-number)
246
+ (rdebug-locring-add gud-last-frame
247
+ rdebug-source-location-ring)))
248
+ (rdebug-short-key-mode-maybe-activate)
249
+
250
+ (unless (string= shell-output "")
251
+ (rdebug-debug-message "Output: %S" shell-output))
252
+ (rdebug-debug-message "REM: %S" gud-marker-acc)
253
+
254
+ shell-output)))
255
+
256
+ (defun rdebug-process-annotation (name contents)
257
+ "Called after `gud-rdebug-marker-filter' found a complete
258
+ `name' annotation with string `contents'. Send it to the right
259
+ place for processing."
260
+ (rdebug-debug-enter (format "rdebug-process-annotation %s" name)
261
+ ;; Ruby-debug uses the name "starting" for process output (just like
262
+ ;; GDB). However, it's better to present the buffer as "output" to
263
+ ;; the user. Ditto for "display" and "watch".
264
+ (cond ((string= name "starting")
265
+ (setq name "output"))
266
+ ((string= name "display")
267
+ (setq name "watch"))
268
+ ((string= name "stack")
269
+ (setq name "frame"))
270
+ ((string= name "error-begin")
271
+ (setq name "error")))
272
+ ;; New "info"
273
+ (if (string= name "exited")
274
+ (setq name "info"))
275
+ (if (string= name "error")
276
+ (rdebug-errmsg contents))
277
+ (let ((setup-func (gethash name rdebug-annotation-setup-map)))
278
+ (when setup-func
279
+ (let ((buf (rdebug-get-buffer name gud-target-name))
280
+ ;; Buffer local, doesn't survive the buffer change.
281
+ (comint-buffer gud-comint-buffer))
282
+ (with-current-buffer buf
283
+ (setq buffer-read-only t)
284
+ (let ((inhibit-read-only t))
285
+ (set (make-local-variable 'rdebug-current-line-number)
286
+ (line-number-at-pos))
287
+ (set (make-local-variable 'gud-last-frame) gud-last-frame)
288
+ (if rdebug-accumulative-buffer
289
+ (goto-char (point-max))
290
+ (erase-buffer))
291
+ (insert contents)
292
+ (funcall setup-func buf comint-buffer))))))
293
+ (cond ((and (string= name "info")
294
+ (not (string= contents "")))
295
+ (save-selected-window
296
+ (rdebug-display-info-buffer))))))
297
+
298
+
299
+ ;; ------------------------------------------------------------
300
+ ;; Mode line displayer.
301
+ ;;
302
+
303
+ ;; The variable rdebug-mode-line-process uses this to generate the
304
+ ;; actual string to display.
305
+ (defun rdebug-display-inferior-status ()
306
+ "Return a (propertized) string, or nil, to be displayed in the mode line."
307
+ (if (and gud-comint-buffer
308
+ (buffer-name gud-comint-buffer)
309
+ (get-buffer-process gud-comint-buffer)
310
+ rdebug-inferior-status)
311
+ (let ((s rdebug-inferior-status))
312
+ (cond ((string= rdebug-inferior-status "running")
313
+ (setq s (propertize s 'face font-lock-type-face)))
314
+ (t
315
+ (setq s (propertize s 'face font-lock-warning-face))))
316
+ (concat ":" s))
317
+ ;; No process, don't display anything.
318
+ nil))
319
+
320
+ ;; ------------------------------------------------------------
321
+ ;; Command output parser.
322
+ ;;
323
+
324
+ (defvar rdebug-cmd-acc ""
325
+ "The accumulated output of the current command.
326
+
327
+ Note, on some systems the external process echoes the command,
328
+ which is included in the output.")
329
+
330
+ ;; Called when a new command starts.
331
+ (defun rdebug-cmd-clear ()
332
+ "Called when the Rdebug filter find the start of a new commands."
333
+ (rdebug-debug-enter "rdebug-cmd-clear"
334
+ (setq rdebug-cmd-acc "")))
335
+
336
+ ;; Called with command output, this can be called any number of times.
337
+ (defun rdebug-cmd-process (s)
338
+ "Called when the Rdebug filter find the command output.
339
+ This may be called any number of times."
340
+ (rdebug-debug-enter (format "rdebug-cmd-process %S" s)
341
+ (setq rdebug-cmd-acc (concat rdebug-cmd-acc s))))
342
+
343
+ ;; Called when command has finished.
344
+ (defun rdebug-cmd-done ()
345
+ "Called when the Rdebug filter find the end of a commands."
346
+ (rdebug-debug-enter "rdebug-cmd-done"
347
+ ;; car-safe is used since rdebug-call-queue can be empty.
348
+ (let ((entry (car-safe rdebug-call-queue))
349
+ (text rdebug-cmd-acc))
350
+ (when entry
351
+ (rdebug-debug-message "Entry: %S Acc:%S" rdebug-call-queue rdebug-cmd-acc)
352
+ (setq rdebug-call-queue (cdr rdebug-call-queue))
353
+ (let ((saved-cmd (car entry))
354
+ (options (cdr entry)))
355
+ ;; In cast the external process echoed the actual command,
356
+ ;; remove it.
357
+ (when (and (>= (length text)
358
+ (length saved-cmd))
359
+ (string= saved-cmd (substring text 0 (length saved-cmd))))
360
+ (setq text (substring text (+ 1 (length saved-cmd)))))
361
+ (rdebug-debug-message "Text: %S" text)
362
+ ;; Optionally display the result.
363
+ (if (memq :tooltip options)
364
+ (rdebug-temp-show text))
365
+ (if (memq :info options)
366
+ (rdebug-process-annotation "info" text))
367
+ (when (memq :message options)
368
+ ;; Remove trailing newlines (chomp).
369
+ (while (and (> (length text) 0)
370
+ (eq (elt text (- (length text) 1)) ?\n))
371
+ (setq text (substring text 0 -1)))
372
+ (message text)))))))
373
+
374
+
375
+ ;; -------------------------------------------------------------------
376
+ ;; The end.
377
+ ;;
378
+
379
+ (provide 'rdebug-annotate)
380
+
381
+ ;;; Local variables:
382
+ ;;; eval:(put 'rdebug-debug-enter 'lisp-indent-hook 1)
383
+ ;;; End:
384
+
385
+ ;;; rdebug-annotate.el ends here