debugger2 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +3 -0
- data/AUTHORS +10 -0
- data/CHANGELOG.md +65 -0
- data/CONTRIBUTING.md +1 -0
- data/Gemfile +3 -0
- data/LICENSE +23 -0
- data/OLDER_CHANGELOG +334 -0
- data/OLD_CHANGELOG +5655 -0
- data/OLD_README +122 -0
- data/README.md +108 -0
- data/Rakefile +78 -0
- data/bin/rdebug +397 -0
- data/debugger2.gemspec +29 -0
- data/doc/.cvsignore +42 -0
- data/doc/Makefile.am +63 -0
- data/doc/emacs-notes.txt +38 -0
- data/doc/hanoi.rb +35 -0
- data/doc/primes.rb +28 -0
- data/doc/rdebug-emacs.texi +1030 -0
- data/doc/ruby-debug.texi +3791 -0
- data/doc/test-tri2.rb +18 -0
- data/doc/tri3.rb +8 -0
- data/doc/triangle.rb +12 -0
- data/emacs/Makefile.am +130 -0
- data/emacs/rdebug-annotate.el +385 -0
- data/emacs/rdebug-breaks.el +407 -0
- data/emacs/rdebug-cmd.el +92 -0
- data/emacs/rdebug-core.el +502 -0
- data/emacs/rdebug-dbg.el +62 -0
- data/emacs/rdebug-error.el +79 -0
- data/emacs/rdebug-fns.el +111 -0
- data/emacs/rdebug-frames.el +230 -0
- data/emacs/rdebug-gud.el +242 -0
- data/emacs/rdebug-help.el +104 -0
- data/emacs/rdebug-info.el +83 -0
- data/emacs/rdebug-layouts.el +180 -0
- data/emacs/rdebug-locring.el +118 -0
- data/emacs/rdebug-output.el +106 -0
- data/emacs/rdebug-regexp.el +118 -0
- data/emacs/rdebug-secondary.el +260 -0
- data/emacs/rdebug-shortkey.el +175 -0
- data/emacs/rdebug-source.el +568 -0
- data/emacs/rdebug-track.el +392 -0
- data/emacs/rdebug-varbuf.el +150 -0
- data/emacs/rdebug-vars.el +125 -0
- data/emacs/rdebug-watch.el +132 -0
- data/emacs/rdebug.el +326 -0
- data/emacs/test/elk-test.el +242 -0
- data/emacs/test/test-annotate.el +103 -0
- data/emacs/test/test-cmd.el +116 -0
- data/emacs/test/test-core.el +104 -0
- data/emacs/test/test-fns.el +65 -0
- data/emacs/test/test-frames.el +62 -0
- data/emacs/test/test-gud.el +35 -0
- data/emacs/test/test-indent.el +58 -0
- data/emacs/test/test-regexp.el +144 -0
- data/emacs/test/test-shortkey.el +61 -0
- data/ext/ruby_debug/breakpoint.c +630 -0
- data/ext/ruby_debug/extconf.rb +11 -0
- data/ext/ruby_debug/ruby_debug.c +2203 -0
- data/ext/ruby_debug/ruby_debug.h +151 -0
- data/lib/debugger.rb +5 -0
- data/lib/debugger/version.rb +5 -0
- data/lib/debugger2.rb +6 -0
- data/lib/ruby-debug-base.rb +307 -0
- data/lib/ruby-debug.rb +176 -0
- data/lib/ruby-debug/command.rb +227 -0
- data/lib/ruby-debug/commands/breakpoints.rb +153 -0
- data/lib/ruby-debug/commands/catchpoint.rb +55 -0
- data/lib/ruby-debug/commands/condition.rb +49 -0
- data/lib/ruby-debug/commands/continue.rb +38 -0
- data/lib/ruby-debug/commands/control.rb +107 -0
- data/lib/ruby-debug/commands/display.rb +120 -0
- data/lib/ruby-debug/commands/edit.rb +48 -0
- data/lib/ruby-debug/commands/enable.rb +202 -0
- data/lib/ruby-debug/commands/eval.rb +176 -0
- data/lib/ruby-debug/commands/finish.rb +42 -0
- data/lib/ruby-debug/commands/frame.rb +301 -0
- data/lib/ruby-debug/commands/help.rb +56 -0
- data/lib/ruby-debug/commands/info.rb +467 -0
- data/lib/ruby-debug/commands/irb.rb +123 -0
- data/lib/ruby-debug/commands/jump.rb +66 -0
- data/lib/ruby-debug/commands/kill.rb +51 -0
- data/lib/ruby-debug/commands/list.rb +94 -0
- data/lib/ruby-debug/commands/method.rb +84 -0
- data/lib/ruby-debug/commands/quit.rb +39 -0
- data/lib/ruby-debug/commands/reload.rb +40 -0
- data/lib/ruby-debug/commands/save.rb +90 -0
- data/lib/ruby-debug/commands/set.rb +223 -0
- data/lib/ruby-debug/commands/show.rb +247 -0
- data/lib/ruby-debug/commands/skip.rb +35 -0
- data/lib/ruby-debug/commands/source.rb +36 -0
- data/lib/ruby-debug/commands/stepping.rb +81 -0
- data/lib/ruby-debug/commands/threads.rb +189 -0
- data/lib/ruby-debug/commands/tmate.rb +36 -0
- data/lib/ruby-debug/commands/trace.rb +57 -0
- data/lib/ruby-debug/commands/variables.rb +199 -0
- data/lib/ruby-debug/debugger.rb +5 -0
- data/lib/ruby-debug/helper.rb +69 -0
- data/lib/ruby-debug/interface.rb +232 -0
- data/lib/ruby-debug/processor.rb +474 -0
- data/man/rdebug.1 +241 -0
- data/old_scripts/Makefile.am +14 -0
- data/old_scripts/README.md +2 -0
- data/old_scripts/autogen.sh +4 -0
- data/old_scripts/configure.ac +12 -0
- data/old_scripts/rdbg.rb +33 -0
- data/old_scripts/runner.sh +7 -0
- data/old_scripts/svn2cl_usermap +3 -0
- data/test/.cvsignore +1 -0
- data/test/breakpoints_test.rb +366 -0
- data/test/conditions_test.rb +77 -0
- data/test/continue_test.rb +28 -0
- data/test/display_test.rb +143 -0
- data/test/edit_test.rb +55 -0
- data/test/eval_test.rb +94 -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 +49 -0
- data/test/frame_test.rb +140 -0
- data/test/help_test.rb +51 -0
- data/test/info_test.rb +326 -0
- data/test/irb_test.rb +82 -0
- data/test/jump_test.rb +70 -0
- data/test/kill_test.rb +49 -0
- data/test/list_test.rb +147 -0
- data/test/method_test.rb +72 -0
- data/test/post_mortem_test.rb +25 -0
- data/test/quit_test.rb +56 -0
- data/test/reload_test.rb +47 -0
- data/test/restart_test.rb +145 -0
- data/test/save_test.rb +94 -0
- data/test/set_test.rb +183 -0
- data/test/show_test.rb +294 -0
- data/test/source_test.rb +46 -0
- data/test/stepping_test.rb +122 -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 +206 -0
- data/test/support/test_interface.rb +66 -0
- data/test/test_helper.rb +9 -0
- data/test/thread_test.rb +124 -0
- data/test/tmate_test.rb +45 -0
- data/test/trace_test.rb +156 -0
- data/test/variables_test.rb +116 -0
- metadata +319 -0
@@ -0,0 +1,502 @@
|
|
1
|
+
;;; rdebug-core.el --- Core parts of the Ruby debugger user
|
2
|
+
;;; interface. It pulls in other parts of the debugger.
|
3
|
+
|
4
|
+
;; Copyright (C) 2006, 2007, 2008 Rocky Bernstein (rocky@gnu.org)
|
5
|
+
;; Copyright (C) 2007, 2008 Anders Lindgren
|
6
|
+
|
7
|
+
;; $Id: rdebug-core.el 909 2009-03-11 18:57:08Z 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
|
+
;; See the manual and the file `rdebug.el' for more information.
|
27
|
+
|
28
|
+
;; This file implements the core of the debugger.
|
29
|
+
|
30
|
+
;;; Code:
|
31
|
+
|
32
|
+
;; -------------------------------------------------------------------
|
33
|
+
;; Consistency checks.
|
34
|
+
;;
|
35
|
+
|
36
|
+
(if (< emacs-major-version 22)
|
37
|
+
(error
|
38
|
+
"This version of rdebug.el needs at least Emacs 22 or greater - you have version %d"
|
39
|
+
emacs-major-version))
|
40
|
+
|
41
|
+
|
42
|
+
;; -------------------------------------------------------------------
|
43
|
+
;; Dependencies.
|
44
|
+
;;
|
45
|
+
|
46
|
+
(require 'gud)
|
47
|
+
(require 'cl)
|
48
|
+
|
49
|
+
(require 'rdebug)
|
50
|
+
(require 'rdebug-annotate)
|
51
|
+
(require 'rdebug-dbg)
|
52
|
+
(require 'rdebug-cmd)
|
53
|
+
(require 'rdebug-layouts)
|
54
|
+
(require 'rdebug-source)
|
55
|
+
(require 'rdebug-regexp)
|
56
|
+
(require 'rdebug-vars)
|
57
|
+
|
58
|
+
(defun rdebug-get-script-name (args)
|
59
|
+
"Parse command line ARGS.
|
60
|
+
|
61
|
+
A list containing the script name, and whether the annotate
|
62
|
+
option was set is returned.
|
63
|
+
|
64
|
+
Initially annotate should be set to nil. Argument ARGS contains
|
65
|
+
a tokenized list of the command line."
|
66
|
+
;; Parse the following:
|
67
|
+
;;
|
68
|
+
;; [ruby ruby-options] rdebug rdebug-options script-name script-options
|
69
|
+
(and args
|
70
|
+
(let ((name nil)
|
71
|
+
(annotate-p nil))
|
72
|
+
;; Strip of optional "ruby" or "ruby182" etc.
|
73
|
+
(when (string-match "^ruby[0-9]*$"
|
74
|
+
(file-name-sans-extension
|
75
|
+
(file-name-nondirectory (car args))))
|
76
|
+
(pop args)
|
77
|
+
(while (and args
|
78
|
+
(string-match "^-" (car args)))
|
79
|
+
(if (member (car args) '("-e" "-r" "-I" "-C" "-F" "-K"))
|
80
|
+
(pop args))
|
81
|
+
(pop args)))
|
82
|
+
;; Remove "rdebug" from "rdebug --rdebug-options script
|
83
|
+
;; --script-options"
|
84
|
+
(pop args)
|
85
|
+
;; Skip to the first non-option argument.
|
86
|
+
(while (and args
|
87
|
+
(not name))
|
88
|
+
(let ((arg (pop args)))
|
89
|
+
(cond
|
90
|
+
;; Annotation or emacs option with level number.
|
91
|
+
((or (member arg '("--annotate" "-A"))
|
92
|
+
(equal arg "--emacs"))
|
93
|
+
(setq annotate-p t)
|
94
|
+
(pop args))
|
95
|
+
;; Combined annotation and level option.
|
96
|
+
((string-match "^--annotate=[0-9]" arg)
|
97
|
+
(setq annotate-p t))
|
98
|
+
;; Options with arguments.
|
99
|
+
((member arg '("-h" "--host" "-p" "--port"
|
100
|
+
"-I" "--include" "-r" "--require"))
|
101
|
+
(pop args))
|
102
|
+
((string-match "^-" arg)
|
103
|
+
nil)
|
104
|
+
(t
|
105
|
+
(setq name arg)))))
|
106
|
+
(and name
|
107
|
+
(list name annotate-p)))))
|
108
|
+
|
109
|
+
;; -------------------------------------------------------------------
|
110
|
+
;; Window configuration state support.
|
111
|
+
;;
|
112
|
+
|
113
|
+
(defun rdebug-set-window-configuration-state (state &optional dont-restore)
|
114
|
+
"Change window configuration state.
|
115
|
+
|
116
|
+
Two states are supported, `original' and `debugger'.
|
117
|
+
|
118
|
+
When `dont-restore' is non-nil, the old window layout is not
|
119
|
+
restored. This is used when a new layout is being drawn, for
|
120
|
+
example when the debugger starts."
|
121
|
+
(rdebug-debug-message "Setting state to %s (was %s)"
|
122
|
+
state rdebug-window-configuration-state)
|
123
|
+
(when (not (eq state rdebug-window-configuration-state))
|
124
|
+
;; Save the previous state.
|
125
|
+
(cond ((not (eq rdebug-window-configuration-state 'original))
|
126
|
+
(setq rdebug-debugger-window-configuration
|
127
|
+
(current-window-configuration)))
|
128
|
+
((eq rdebug-window-configuration-state 'original)
|
129
|
+
(setq rdebug-original-window-configuration
|
130
|
+
(current-window-configuration))))
|
131
|
+
(unless dont-restore
|
132
|
+
;; Switch to the saved state,
|
133
|
+
(cond
|
134
|
+
((not (eq state 'original))
|
135
|
+
(if rdebug-debugger-window-configuration
|
136
|
+
(set-window-configuration rdebug-debugger-window-configuration)))
|
137
|
+
((eq state 'original)
|
138
|
+
(if rdebug-original-window-configuration
|
139
|
+
(set-window-configuration rdebug-original-window-configuration)))))
|
140
|
+
(setq rdebug-window-configuration-state state)))
|
141
|
+
|
142
|
+
|
143
|
+
;; have to bind rdebug-file-queue before installing the kill-emacs-hook
|
144
|
+
(defvar rdebug-file-queue nil
|
145
|
+
"Queue of Makefile temp files awaiting execution.
|
146
|
+
Currently-active file is at the head of the list.")
|
147
|
+
|
148
|
+
(defun rdebug-goto-traceback-line (pt)
|
149
|
+
"Display the location PT in a source file of the Ruby traceback line."
|
150
|
+
(interactive "d")
|
151
|
+
(save-excursion
|
152
|
+
(goto-char pt)
|
153
|
+
(let ((s (buffer-substring (line-beginning-position) (line-end-position)))
|
154
|
+
(gud-comint-buffer (current-buffer)))
|
155
|
+
(when (string-match rdebug-traceback-line-re s)
|
156
|
+
(rdebug-display-line
|
157
|
+
(substring s (match-beginning 1) (match-end 1))
|
158
|
+
(string-to-number (substring s (match-beginning 2) (match-end 2))))
|
159
|
+
))))
|
160
|
+
|
161
|
+
(defun rdebug-goto-dollarbang-traceback-line (pt)
|
162
|
+
"Display the location PT in a source file of the Ruby $! traceback line."
|
163
|
+
(interactive "d")
|
164
|
+
(save-excursion
|
165
|
+
(goto-char pt)
|
166
|
+
(let ((s (buffer-substring (line-beginning-position) (line-end-position)))
|
167
|
+
(gud-comint-buffer (current-buffer)))
|
168
|
+
(when (string-match rdebug-dollarbang-traceback-line-re s)
|
169
|
+
(rdebug-display-line
|
170
|
+
(substring s (match-beginning 1) (match-end 1))
|
171
|
+
(string-to-number (substring s (match-beginning 2) (match-end 2))))
|
172
|
+
))))
|
173
|
+
|
174
|
+
;; -------------------------------------------------------------------
|
175
|
+
;; Secondary buffers.
|
176
|
+
;;
|
177
|
+
|
178
|
+
(require 'rdebug-secondary)
|
179
|
+
(require 'rdebug-breaks)
|
180
|
+
(require 'rdebug-frames)
|
181
|
+
(require 'rdebug-help)
|
182
|
+
(require 'rdebug-output)
|
183
|
+
(require 'rdebug-varbuf)
|
184
|
+
(require 'rdebug-watch)
|
185
|
+
|
186
|
+
|
187
|
+
;; -------------------------------------------------------------------
|
188
|
+
;; Windows.
|
189
|
+
;;
|
190
|
+
|
191
|
+
(defun rdebug-setup-windows (&optional erase)
|
192
|
+
"Create the debugger user interface window layout.
|
193
|
+
|
194
|
+
If ERASE is non-nil, the content of the windows are erased
|
195
|
+
\(this does not apply to accumulative windows).
|
196
|
+
|
197
|
+
This function displays the source file (or, in some cases, a
|
198
|
+
buffer list) and creates the window layout. The variable
|
199
|
+
`rdebug-window-layout-function' controls the function that is
|
200
|
+
used to perform the actual layout.
|
201
|
+
|
202
|
+
This is only used when `rdebug-many-windows' is non-nil."
|
203
|
+
(rdebug-debug-enter "rdebug-setup-windows"
|
204
|
+
(rdebug-set-window-configuration-state 'debugger t)
|
205
|
+
(pop-to-buffer gud-comint-buffer)
|
206
|
+
(maphash
|
207
|
+
(lambda (name func)
|
208
|
+
(if erase
|
209
|
+
(let ((buf (rdebug-get-existing-buffer name gud-target-name)))
|
210
|
+
(if buf
|
211
|
+
(with-current-buffer buf
|
212
|
+
(let ((inhibit-read-only t))
|
213
|
+
(erase-buffer))))))
|
214
|
+
(rdebug-process-annotation name ""))
|
215
|
+
rdebug-annotation-setup-map)
|
216
|
+
(let ((buf
|
217
|
+
(cond (gud-last-last-frame
|
218
|
+
(gud-find-file (car gud-last-last-frame)))
|
219
|
+
(gud-target-name
|
220
|
+
(gud-find-file gud-target-name)))))
|
221
|
+
;; Put a buffer in window if we can't find a source file.
|
222
|
+
(unless buf (setq buf (get-buffer-create "*scratch*")))
|
223
|
+
(funcall rdebug-window-layout-function buf gud-target-name))))
|
224
|
+
|
225
|
+
|
226
|
+
(defun rdebug-setup-windows-initially ()
|
227
|
+
"Like `rdebug-setup-windows', but erase the content of accumulative windows.
|
228
|
+
This is called when the debugger starts."
|
229
|
+
(rdebug-setup-windows t))
|
230
|
+
|
231
|
+
|
232
|
+
(defun rdebug-restore-debugger-window-layout ()
|
233
|
+
"Restore the initial ruby debugger window layout."
|
234
|
+
(interactive)
|
235
|
+
(when rdebug-many-windows
|
236
|
+
(rdebug-setup-windows)))
|
237
|
+
|
238
|
+
(defun rdebug-display-debugger-window-configuration ()
|
239
|
+
"Switch from the \"original\" to the \"debugger\" window layout.
|
240
|
+
|
241
|
+
The rdebug debugger remembers, and can switch between, two window layouts:
|
242
|
+
* original -- the window layout when the debugger was started.
|
243
|
+
* debugger -- the window layout of the debugger, plus all changes made
|
244
|
+
since the debugger started.
|
245
|
+
|
246
|
+
The check-marks in the \"Window Layout\" menu indicates the
|
247
|
+
active window layout.
|
248
|
+
|
249
|
+
The function `rdebug-display-original-window-configuration'
|
250
|
+
switch to the \"original\" window configuration.
|
251
|
+
|
252
|
+
The function `rdebug-restore-debugger-window-layout' restores the
|
253
|
+
window layout to the state it was when the debugger started."
|
254
|
+
(interactive)
|
255
|
+
(rdebug-set-window-configuration-state 'debugger)
|
256
|
+
(message
|
257
|
+
"Type `M-x rdebug-display-original-window-configuration RET' to restore."))
|
258
|
+
|
259
|
+
|
260
|
+
;;This function is called upon quitting the debugger and
|
261
|
+
;;`rdebug-many-windows' is not nil. See also
|
262
|
+
;;`rdebug-display-debugger-window-configuration'."
|
263
|
+
|
264
|
+
(defun rdebug-display-original-window-configuration ()
|
265
|
+
"Switch from the \"debugger\" to the \"original\" window layout.
|
266
|
+
|
267
|
+
The rdebug debugger remembers, and can switch between, two window layouts:
|
268
|
+
* original -- the window layout when the debugger was started.
|
269
|
+
* debugger -- the window layout of the debugger, plus all changes made
|
270
|
+
since the debugger started.
|
271
|
+
|
272
|
+
The check-marks in the \"Window Layout\" menu indicates the
|
273
|
+
active window layout.
|
274
|
+
|
275
|
+
The function `rdebug-display-debugger-window-configuration'
|
276
|
+
switch to the \"debugger\" window configuration."
|
277
|
+
(interactive)
|
278
|
+
(rdebug-set-window-configuration-state 'original)
|
279
|
+
(message
|
280
|
+
"Type `M-x rdebug-display-debugger-window-configuration RET' to restore."))
|
281
|
+
|
282
|
+
|
283
|
+
;; -------------------------------------------------------------------
|
284
|
+
;; The `rdebug' command and support functions.
|
285
|
+
;;
|
286
|
+
|
287
|
+
(defun rdebug-process-sentinel (process event)
|
288
|
+
"Restore the original window configuration when the debugger process exits."
|
289
|
+
(rdebug-debug-enter "rdebug-process-sentinel"
|
290
|
+
(rdebug-debug-message "status=%S event=%S state=%S"
|
291
|
+
(process-status process)
|
292
|
+
event
|
293
|
+
rdebug-window-configuration-state)
|
294
|
+
(gud-sentinel process event)
|
295
|
+
;; This will "flush" the last annotation. Especially "output"
|
296
|
+
;; (a.k.a. "starting") annotations don't have an end markers, if
|
297
|
+
;; the last command printed something.
|
298
|
+
(if (string= event "finished\n")
|
299
|
+
(gud-rdebug-marker-filter "\032\032\n"))
|
300
|
+
;; When the debugger process exited, when the comint buffer has no
|
301
|
+
;; buffer process (nil). When the debugger processes is replaced
|
302
|
+
;; with another process we should not restore the window
|
303
|
+
;; configuration.
|
304
|
+
(when (and (or (eq rdebug-restore-original-window-configuration t)
|
305
|
+
(and (eq rdebug-restore-original-window-configuration :many)
|
306
|
+
rdebug-many-windows))
|
307
|
+
(or (rdebug-dead-process-p)
|
308
|
+
(eq process (get-buffer-process gud-comint-buffer)))
|
309
|
+
(eq rdebug-window-configuration-state 'debugger)
|
310
|
+
(not (eq (process-status process) 'run)))
|
311
|
+
(rdebug-internal-short-key-mode-off)
|
312
|
+
(rdebug-set-window-configuration-state 'original)
|
313
|
+
(rdebug-reset-keymaps))))
|
314
|
+
|
315
|
+
|
316
|
+
;; Perform initializations common to all debuggers.
|
317
|
+
;; The first arg is the specified command line,
|
318
|
+
;; which starts with the program to debug.
|
319
|
+
;; The other three args specify the values to use
|
320
|
+
;; for local variables in the debugger buffer.
|
321
|
+
(defun rdebug-common-init (rdebug-buffer-name rdebug-cmd-buffer target-name
|
322
|
+
program args
|
323
|
+
marker-filter
|
324
|
+
&optional find-file)
|
325
|
+
"Perform initializations common to all debuggers.
|
326
|
+
|
327
|
+
RDEBUG-BUFFER-NAME is the specified command line, which starts
|
328
|
+
with the program to debug. PROGRAM, ARGS and MARKER-FILTER
|
329
|
+
specify the values to use for local variables in the debugger
|
330
|
+
buffer."
|
331
|
+
(if rdebug-cmd-buffer
|
332
|
+
(progn
|
333
|
+
(pop-to-buffer rdebug-cmd-buffer)
|
334
|
+
(when (and rdebug-cmd-buffer (get-buffer-process rdebug-cmd-buffer))
|
335
|
+
(error "This program is already being debugged"))
|
336
|
+
(apply 'make-comint rdebug-buffer-name program nil args)
|
337
|
+
(or (bolp) (newline)))
|
338
|
+
(pop-to-buffer (setq rdebug-cmd-buffer
|
339
|
+
(apply 'make-comint rdebug-buffer-name program nil
|
340
|
+
args))))
|
341
|
+
|
342
|
+
;; Since comint clobbered the mode, we don't set it until now.
|
343
|
+
(gud-mode)
|
344
|
+
(set (make-local-variable 'gud-target-name) target-name)
|
345
|
+
(set (make-local-variable 'gud-marker-filter) marker-filter)
|
346
|
+
(set (make-local-variable 'gud-minor-mode) 'rdebug)
|
347
|
+
(set (make-local-variable 'gud-last-frame) nil)
|
348
|
+
(set (make-local-variable 'gud-last-last-frame) nil)
|
349
|
+
|
350
|
+
(let ((buffer-process (get-buffer-process (current-buffer))))
|
351
|
+
(if buffer-process
|
352
|
+
(progn
|
353
|
+
(set-process-filter buffer-process 'gud-filter)
|
354
|
+
(set-process-sentinel buffer-process 'gud-sentinel))))
|
355
|
+
(gud-set-buffer))
|
356
|
+
|
357
|
+
;;;###autoload
|
358
|
+
(defun rdebug (command-line)
|
359
|
+
"Invoke the rdebug Ruby debugger and start the Emacs user interface.
|
360
|
+
|
361
|
+
String COMMAND-LINE specifies how to run rdebug.
|
362
|
+
|
363
|
+
By default, the \"standard\" user window layout looks like the following:
|
364
|
+
|
365
|
+
+----------------------------------------------------------------------+
|
366
|
+
| Toolbar |
|
367
|
+
+-----------------------------------+----------------------------------+
|
368
|
+
| Debugger shell | Variables buffer |
|
369
|
+
+-----------------------------------+----------------------------------+
|
370
|
+
| | |
|
371
|
+
| Source buffer | Output buffer |
|
372
|
+
| | |
|
373
|
+
+-----------------------------------+----------------------------------+
|
374
|
+
| Stack Frame buffer | Breakpoints buffer |
|
375
|
+
+-----------------------------------+----------------------------------+
|
376
|
+
|
377
|
+
The variable `rdebug-window-layout-function' can be
|
378
|
+
customized so that another layout is used. In addition to a
|
379
|
+
number of predefined layouts it's possible to define a function
|
380
|
+
to perform a custom layout.
|
381
|
+
|
382
|
+
If `rdebug-many-windows' is nil, only a traditional debugger
|
383
|
+
shell and source window is opened.
|
384
|
+
|
385
|
+
The directory containing the debugged script becomes the initial
|
386
|
+
working directory and source-file directory for your debugger.
|
387
|
+
|
388
|
+
The custom variable `gud-rdebug-command-name' sets the command
|
389
|
+
and options used to invoke rdebug."
|
390
|
+
(interactive
|
391
|
+
(let ((init (buffer-file-name)))
|
392
|
+
(setq init (and init
|
393
|
+
(file-name-nondirectory init)))
|
394
|
+
(list (gud-query-cmdline 'rdebug init))))
|
395
|
+
(rdebug-debug-enter "rdebug"
|
396
|
+
(rdebug-set-window-configuration-state 'debugger t)
|
397
|
+
;; Parse the command line and pick out the script name and whether
|
398
|
+
;; --annotate has been set.
|
399
|
+
(let* ((words (with-no-warnings
|
400
|
+
(split-string-and-unquote command-line)))
|
401
|
+
(script-name-annotate-p (rdebug-get-script-name
|
402
|
+
(gud-rdebug-massage-args "1" words)))
|
403
|
+
(target-name (file-name-nondirectory (car script-name-annotate-p)))
|
404
|
+
(annotate-p (cadr script-name-annotate-p))
|
405
|
+
(cmd-buffer-name (format "rdebug-cmd-%s" target-name))
|
406
|
+
(rdebug-cmd-buffer-name (format "*%s*" cmd-buffer-name))
|
407
|
+
(rdebug-cmd-buffer (get-buffer rdebug-cmd-buffer-name))
|
408
|
+
(program (car words))
|
409
|
+
(args (cdr words))
|
410
|
+
(gud-chdir-before-run nil))
|
411
|
+
|
412
|
+
;; `gud-rdebug-massage-args' needs whole `command-line'.
|
413
|
+
;; command-line is refered through dynamic scope.
|
414
|
+
(rdebug-common-init cmd-buffer-name rdebug-cmd-buffer target-name
|
415
|
+
program args
|
416
|
+
'gud-rdebug-marker-filter
|
417
|
+
'gud-rdebug-find-file)
|
418
|
+
(setq comint-process-echoes t)
|
419
|
+
|
420
|
+
(setq rdebug-inferior-status "running")
|
421
|
+
|
422
|
+
(rdebug-command-initialization)
|
423
|
+
|
424
|
+
;; Setup exit callback so that the original frame configuration
|
425
|
+
;; can be restored.
|
426
|
+
(let ((process (get-buffer-process gud-comint-buffer)))
|
427
|
+
(when process
|
428
|
+
(unless (equal rdebug-line-width 120)
|
429
|
+
(gud-call (format "set width %d" rdebug-line-width)))
|
430
|
+
(set-process-sentinel process
|
431
|
+
'rdebug-process-sentinel)))
|
432
|
+
|
433
|
+
|
434
|
+
;; Add the buffer-displaying commands to the Gud buffer,
|
435
|
+
;; FIXME: combine with code in rdebug-track.el; make common
|
436
|
+
;; command buffer mode map.
|
437
|
+
(let ((prefix-map (make-sparse-keymap)))
|
438
|
+
(define-key (current-local-map) gud-key-prefix prefix-map)
|
439
|
+
(define-key prefix-map "t" 'rdebug-goto-traceback-line)
|
440
|
+
(define-key prefix-map "!" 'rdebug-goto-dollarbang-traceback-line)
|
441
|
+
(rdebug-populate-secondary-buffer-map-plain prefix-map))
|
442
|
+
|
443
|
+
(rdebug-populate-common-keys (current-local-map))
|
444
|
+
(rdebug-populate-debugger-menu (current-local-map))
|
445
|
+
|
446
|
+
(setq comint-prompt-regexp (concat "^" rdebug-input-prompt-regexp))
|
447
|
+
(setq paragraph-start comint-prompt-regexp)
|
448
|
+
|
449
|
+
(setcdr (assq 'rdebug-debugger-support-minor-mode minor-mode-map-alist)
|
450
|
+
rdebug-debugger-support-minor-mode-map-when-active)
|
451
|
+
(when rdebug-many-windows
|
452
|
+
(rdebug-setup-windows-initially))
|
453
|
+
|
454
|
+
(run-hooks 'rdebug-mode-hook))))
|
455
|
+
|
456
|
+
|
457
|
+
(defadvice gud-reset (before rdebug-reset)
|
458
|
+
"Rdebug cleanup - remove debugger's internal buffers (frame, breakpoints, etc.)."
|
459
|
+
(rdebug-breakpoint-remove-all-icons)
|
460
|
+
(dolist (buffer (buffer-list))
|
461
|
+
(when (string-match "\\*rdebug-[a-z]+\\*" (buffer-name buffer))
|
462
|
+
(let ((w (get-buffer-window buffer)))
|
463
|
+
(when w
|
464
|
+
(delete-window w)))
|
465
|
+
(kill-buffer buffer))))
|
466
|
+
(ad-activate 'gud-reset)
|
467
|
+
|
468
|
+
(defun rdebug-reset ()
|
469
|
+
"Rdebug cleanup - remove debugger's internal buffers (frame, breakpoints, etc.)."
|
470
|
+
(interactive)
|
471
|
+
(rdebug-breakpoint-remove-all-icons)
|
472
|
+
(dolist (buffer (buffer-list))
|
473
|
+
(when (string-match "\\*rdebug-[a-z]+\\*" (buffer-name buffer))
|
474
|
+
(let ((w (get-buffer-window buffer)))
|
475
|
+
(when w
|
476
|
+
(delete-window w)))
|
477
|
+
(kill-buffer buffer))))
|
478
|
+
|
479
|
+
(defun rdebug-reset-keymaps()
|
480
|
+
"This unbinds the special debugger keys of the source buffers."
|
481
|
+
(interactive)
|
482
|
+
(setcdr (assq 'rdebug-debugger-support-minor-mode minor-mode-map-alist)
|
483
|
+
rdebug-debugger-support-minor-mode-map-when-deactive))
|
484
|
+
|
485
|
+
|
486
|
+
(defun rdebug-customize ()
|
487
|
+
"Use `customize' to edit the settings of the `rdebug' debugger."
|
488
|
+
(interactive)
|
489
|
+
(customize-group 'rdebug))
|
490
|
+
|
491
|
+
|
492
|
+
;; -------------------------------------------------------------------
|
493
|
+
;; The end.
|
494
|
+
;;
|
495
|
+
|
496
|
+
(provide 'rdebug-core)
|
497
|
+
|
498
|
+
;;; Local variables:
|
499
|
+
;;; eval:(put 'rdebug-debug-enter 'lisp-indent-hook 1)
|
500
|
+
;;; End:
|
501
|
+
|
502
|
+
;;; rdebug-core.el ends here
|