21336
|
1 ;;; gud.el --- Grand Unified Debugger mode for running GDB and other debuggers
|
810
|
2
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
3 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
|
4818
|
4 ;; Maintainer: FSF
|
810
|
5 ;; Keywords: unix, tools
|
|
6
|
30736
48d749ce74e4
(gud-filter): Use `with-current-buffer' instead of save-excursion when
Miles Bader <miles@gnu.org>
diff
changeset
|
7 ;; Copyright (C) 1992, 93, 94, 95, 96, 1998, 2000 Free Software Foundation, Inc.
|
460
|
8
|
|
9 ;; This file is part of GNU Emacs.
|
|
10
|
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
12 ;; it under the terms of the GNU General Public License as published by
|
868
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
460
|
14 ;; any later version.
|
|
15
|
|
16 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 ;; GNU General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
14169
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
24 ;; Boston, MA 02111-1307, USA.
|
460
|
25
|
810
|
26 ;;; Commentary:
|
|
27
|
460
|
28 ;; The ancestral gdb.el was by W. Schelter <wfs@rascal.ics.utexas.edu>
|
22159
|
29 ;; It was later rewritten by rms. Some ideas were due to Masanobu.
|
810
|
30 ;; Grand Unification (sdb/dbx support) by Eric S. Raymond <esr@thyrsus.com>
|
460
|
31 ;; The overloading code was then rewritten by Barry Warsaw <bwarsaw@cen.com>,
|
3738
|
32 ;; who also hacked the mode to use comint.el. Shane Hartman <shane@spr.com>
|
6531
|
33 ;; added support for xdb (HPUX debugger). Rick Sladkey <jrs@world.std.com>
|
7165
|
34 ;; wrote the GDB command completion code. Dave Love <d.love@dl.ac.uk>
|
10217
|
35 ;; added the IRIX kluge, re-implemented the Mips-ish variant and added
|
22159
|
36 ;; a menu. Brian D. Carlstrom <bdc@ai.mit.edu> combined the IRIX kluge with
|
21336
|
37 ;; the gud-xdb-directories hack producing gud-dbx-directories. Derek L. Davies
|
|
38 ;; <ddavies@world.std.com> added support for jdb (Java debugger.)
|
460
|
39
|
810
|
40 ;;; Code:
|
|
41
|
460
|
42 (require 'comint)
|
923
|
43 (require 'etags)
|
460
|
44
|
|
45 ;; ======================================================================
|
2581
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
46 ;; GUD commands must be visible in C buffers visited by GUD
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
47
|
17663
|
48 (defgroup gud nil
|
22159
|
49 "Grand Unified Debugger mode for gdb and other debuggers under Emacs.
|
22173
|
50 Supported debuggers include gdb, sdb, dbx, xdb, perldb, pdb (Python), and jdb."
|
17663
|
51 :group 'unix
|
|
52 :group 'tools)
|
|
53
|
|
54
|
|
55 (defcustom gud-key-prefix "\C-x\C-a"
|
|
56 "Prefix of all GUD commands valid in C buffers."
|
|
57 :type 'string
|
|
58 :group 'gud)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
59
|
2581
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
60 (global-set-key (concat gud-key-prefix "\C-l") 'gud-refresh)
|
7741
|
61 (define-key ctl-x-map " " 'gud-break) ;; backward compatibility hack
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
62
|
9190
|
63 (defvar gud-marker-filter nil)
|
|
64 (put 'gud-marker-filter 'permanent-local t)
|
|
65 (defvar gud-find-file nil)
|
|
66 (put 'gud-find-file 'permanent-local t)
|
460
|
67
|
9190
|
68 (defun gud-marker-filter (&rest args)
|
|
69 (apply gud-marker-filter args))
|
460
|
70
|
9190
|
71 (defun gud-find-file (file)
|
|
72 ;; Don't get confused by double slashes in the name that comes from GDB.
|
|
73 (while (string-match "//+" file)
|
|
74 (setq file (replace-match "/" t t file)))
|
|
75 (funcall gud-find-file file))
|
10448
|
76
|
|
77 ;; Keymap definitions for menu bar entries common to all debuggers and
|
|
78 ;; slots for debugger-dependent ones in sensible places. (Defined here
|
|
79 ;; before use.)
|
|
80 (defvar gud-menu-map (make-sparse-keymap "Gud") nil)
|
|
81 (define-key gud-menu-map [refresh] '("Refresh" . gud-refresh))
|
12032
|
82 (define-key gud-menu-map [remove] '("Remove Breakpoint" . gud-remove))
|
10448
|
83 (define-key gud-menu-map [tbreak] nil) ; gdb, sdb and xdb
|
12032
|
84 (define-key gud-menu-map [break] '("Set Breakpoint" . gud-break))
|
10448
|
85 (define-key gud-menu-map [up] nil) ; gdb, dbx, and xdb
|
|
86 (define-key gud-menu-map [down] nil) ; gdb, dbx, and xdb
|
12032
|
87 (define-key gud-menu-map [print] '("Print Expression" . gud-print))
|
10448
|
88 (define-key gud-menu-map [finish] nil) ; gdb or xdb
|
12032
|
89 (define-key gud-menu-map [stepi] '("Step Instruction" . gud-stepi))
|
|
90 (define-key gud-menu-map [step] '("Step Line" . gud-step))
|
|
91 (define-key gud-menu-map [next] '("Next Line" . gud-next))
|
10448
|
92 (define-key gud-menu-map [cont] '("Continue" . gud-cont))
|
4729
|
93
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
94 ;; ======================================================================
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
95 ;; command definition
|
460
|
96
|
|
97 ;; This macro is used below to define some basic debugger interface commands.
|
810
|
98 ;; Of course you may use `gud-def' with any other debugger command, including
|
1255
|
99 ;; user defined ones.
|
|
100
|
|
101 ;; A macro call like (gud-def FUNC NAME KEY DOC) expands to a form
|
|
102 ;; which defines FUNC to send the command NAME to the debugger, gives
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
103 ;; it the docstring DOC, and binds that function to KEY in the GUD
|
2581
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
104 ;; major mode. The function is also bound in the global keymap with the
|
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
105 ;; GUD prefix.
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
106
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
107 (defmacro gud-def (func cmd key &optional doc)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
108 "Define FUNC to be a command sending STR and bound to KEY, with
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
109 optional doc string DOC. Certain %-escapes in the string arguments
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
110 are interpreted specially if present. These are:
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
111
|
22159
|
112 %f name (without directory) of current source file.
|
24736
|
113 %F name (without directory or extension) of current source file.
|
22159
|
114 %d directory of current source file.
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
115 %l number of current source line
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
116 %e text of the C lvalue or function-call expression surrounding point.
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
117 %a text of the hexadecimal address surrounding point
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
118 %p prefix argument to the command (if any) as a number
|
460
|
119
|
2581
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
120 The `current' source file is the file of the current buffer (if
|
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
121 we're in a C file) or the source file current at the last break or
|
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
122 step (if we're in the GUD buffer).
|
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
123 The `current' line is that of the current buffer (if we're in a
|
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
124 source file) or the source line number at the last break or step (if
|
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
125 we're in the GUD buffer)."
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
126 (list 'progn
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
127 (list 'defun func '(arg)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
128 (or doc "")
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
129 '(interactive "p")
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
130 (list 'gud-call cmd 'arg))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
131 (if key
|
2960
|
132 (list 'define-key
|
|
133 '(current-local-map)
|
|
134 (concat "\C-c" key)
|
|
135 (list 'quote func)))
|
|
136 (if key
|
|
137 (list 'global-set-key
|
3343
|
138 (list 'concat 'gud-key-prefix key)
|
2960
|
139 (list 'quote func)))))
|
460
|
140
|
22159
|
141 ;; Where gud-display-frame should put the debugging arrow; a cons of
|
|
142 ;; (filename . line-number). This is set by the marker-filter, which scans
|
|
143 ;; the debugger's output for indications of the current program counter.
|
1275
|
144 (defvar gud-last-frame nil)
|
|
145
|
3646
|
146 ;; Used by gud-refresh, which should cause gud-display-frame to redisplay
|
|
147 ;; the last frame, even if it's been called before and gud-last-frame has
|
|
148 ;; been set to nil.
|
4335
|
149 (defvar gud-last-last-frame nil)
|
3646
|
150
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
151 ;; All debugger-specific information is collected here.
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
152 ;; Here's how it works, in case you ever need to add a debugger to the mode.
|
460
|
153 ;;
|
|
154 ;; Each entry must define the following at startup:
|
|
155 ;;
|
|
156 ;;<name>
|
|
157 ;; comint-prompt-regexp
|
4092
|
158 ;; gud-<name>-massage-args
|
460
|
159 ;; gud-<name>-marker-filter
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
160 ;; gud-<name>-find-file
|
460
|
161 ;;
|
4092
|
162 ;; The job of the massage-args method is to modify the given list of
|
|
163 ;; debugger arguments before running the debugger.
|
477
|
164 ;;
|
|
165 ;; The job of the marker-filter method is to detect file/line markers in
|
|
166 ;; strings and set the global gud-last-frame to indicate what display
|
|
167 ;; action (if any) should be triggered by the marker. Note that only
|
3591
|
168 ;; whatever the method *returns* is displayed in the buffer; thus, you
|
477
|
169 ;; can filter the debugger's output, interpreting some and passing on
|
|
170 ;; the rest.
|
|
171 ;;
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
172 ;; The job of the find-file method is to visit and return the buffer indicated
|
477
|
173 ;; by the car of gud-tag-frame. This may be a file name, a tag name, or
|
10217
|
174 ;; something else. It would be good if it also copied the Gud menubar entry.
|
4729
|
175
|
460
|
176 ;; ======================================================================
|
20756
|
177 ;; speedbar support functions and variables.
|
22734
|
178 (eval-when-compile (require 'speedbar))
|
|
179
|
20756
|
180 (defvar gud-last-speedbar-buffer nil
|
|
181 "The last GUD buffer used.")
|
|
182
|
|
183 (defvar gud-last-speedbar-stackframe nil
|
|
184 "Description of the currently displayed GUD stack.
|
|
185 t means that there is no stack, and we are in display-file mode.")
|
|
186
|
22734
|
187 (defvar gud-speedbar-key-map nil
|
|
188 "Keymap used when in the buffers display mode.")
|
|
189
|
|
190 (defun gud-install-speedbar-variables ()
|
|
191 "Install those variables used by speedbar to enhance gud/gdb."
|
|
192 (if gud-speedbar-key-map
|
|
193 nil
|
|
194 (setq gud-speedbar-key-map (speedbar-make-specialized-keymap))
|
|
195
|
|
196 (define-key gud-speedbar-key-map "j" 'speedbar-edit-line)
|
|
197 (define-key gud-speedbar-key-map "e" 'speedbar-edit-line)
|
|
198 (define-key gud-speedbar-key-map "\C-m" 'speedbar-edit-line)))
|
|
199
|
20756
|
200 (defvar gud-speedbar-menu-items
|
|
201 ;; Note to self. Add expand, and turn off items when not available.
|
|
202 '(["Jump to stack frame" speedbar-edit-line t])
|
|
203 "Additional menu items to add the the speedbar frame.")
|
|
204
|
22734
|
205 ;; Make sure our special speedbar mode is loaded
|
|
206 (if (featurep 'speedbar)
|
|
207 (gud-install-speedbar-variables)
|
|
208 (add-hook 'speedbar-load-hook 'gud-install-speedbar-variables))
|
|
209
|
20756
|
210 (defun gud-speedbar-buttons (buffer)
|
|
211 "Create a speedbar display based on the current state of GUD.
|
|
212 If the GUD BUFFER is not running a supported debugger, then turn
|
|
213 off the specialized speedbar mode."
|
|
214 (if (and (save-excursion (goto-char (point-min))
|
|
215 (looking-at "Current Stack"))
|
|
216 (equal gud-last-last-frame gud-last-speedbar-stackframe))
|
|
217 nil
|
|
218 (setq gud-last-speedbar-buffer buffer)
|
|
219 (let* ((ff (save-excursion (set-buffer buffer) gud-find-file))
|
|
220 ;;(lf (save-excursion (set-buffer buffer) gud-last-last-frame))
|
|
221 (frames
|
|
222 (cond ((eq ff 'gud-gdb-find-file)
|
|
223 (gud-gdb-get-stackframe buffer)
|
|
224 )
|
|
225 ;; Add more debuggers here!
|
|
226 (t
|
|
227 (speedbar-remove-localized-speedbar-support buffer)
|
|
228 nil))))
|
|
229 (erase-buffer)
|
|
230 (if (not frames)
|
|
231 (insert "No Stack frames\n")
|
|
232 (insert "Current Stack:\n"))
|
|
233 (while frames
|
|
234 (insert (nth 1 (car frames)) ":\n")
|
|
235 (if (= (length (car frames)) 2)
|
|
236 (progn
|
|
237 ; (speedbar-insert-button "[?]"
|
|
238 ; 'speedbar-button-face
|
|
239 ; nil nil nil t)
|
|
240 (speedbar-insert-button (car (car frames))
|
|
241 'speedbar-directory-face
|
|
242 nil nil nil t))
|
|
243 ; (speedbar-insert-button "[+]"
|
|
244 ; 'speedbar-button-face
|
|
245 ; 'speedbar-highlight-face
|
|
246 ; 'gud-gdb-get-scope-data
|
|
247 ; (car frames) t)
|
|
248 (speedbar-insert-button (car (car frames))
|
|
249 'speedbar-file-face
|
|
250 'speedbar-highlight-face
|
|
251 (cond ((eq ff 'gud-gdb-find-file)
|
|
252 'gud-gdb-goto-stackframe)
|
|
253 (t (error "Should never be here.")))
|
|
254 (car frames) t))
|
|
255 (setq frames (cdr frames)))
|
|
256 ; (let ((selected-frame
|
|
257 ; (cond ((eq ff 'gud-gdb-find-file)
|
|
258 ; (gud-gdb-selected-frame-info buffer))
|
|
259 ; (t (error "Should never be here."))))))
|
|
260 )
|
|
261 (setq gud-last-speedbar-stackframe gud-last-last-frame)))
|
|
262
|
|
263
|
|
264 ;; ======================================================================
|
460
|
265 ;; gdb functions
|
|
266
|
3930
|
267 ;;; History of argument lists passed to gdb.
|
|
268 (defvar gud-gdb-history nil)
|
|
269
|
4092
|
270 (defun gud-gdb-massage-args (file args)
|
10876
|
271 (cons "-fullname" args))
|
460
|
272
|
11960
|
273 (defvar gud-gdb-marker-regexp
|
16843
|
274 ;; This used to use path-separator instead of ":";
|
|
275 ;; however, we found that on both Windows 32 and MSDOS
|
|
276 ;; a colon is correct here.
|
19682
9bf29ac182b4
(gud-gdb-marker-regexp): Allow for drive letter and colon.
Geoff Voelker <voelker@cs.washington.edu>
diff
changeset
|
277 (concat "\032\032\\(.:?[^" ":" "\n]*\\)" ":"
|
16843
|
278 "\\([0-9]*\\)" ":" ".*\n"))
|
11960
|
279
|
4346
|
280 ;; There's no guarantee that Emacs will hand the filter the entire
|
|
281 ;; marker at once; it could be broken up across several strings. We
|
|
282 ;; might even receive a big chunk with several markers in it. If we
|
|
283 ;; receive a chunk of text which looks like it might contain the
|
|
284 ;; beginning of a marker, we save it here between calls to the
|
|
285 ;; filter.
|
7165
|
286 (defvar gud-marker-acc "")
|
7317
|
287 (make-variable-buffer-local 'gud-marker-acc)
|
4346
|
288
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
289 (defun gud-gdb-marker-filter (string)
|
10042
|
290 (setq gud-marker-acc (concat gud-marker-acc string))
|
|
291 (let ((output ""))
|
4346
|
292
|
10042
|
293 ;; Process all the complete markers in this chunk.
|
11960
|
294 (while (string-match gud-gdb-marker-regexp gud-marker-acc)
|
10042
|
295 (setq
|
4346
|
296
|
10042
|
297 ;; Extract the frame position from the marker.
|
|
298 gud-last-frame
|
|
299 (cons (substring gud-marker-acc (match-beginning 1) (match-end 1))
|
|
300 (string-to-int (substring gud-marker-acc
|
|
301 (match-beginning 2)
|
|
302 (match-end 2))))
|
4346
|
303
|
10042
|
304 ;; Append any text before the marker to the output we're going
|
|
305 ;; to return - we don't include the marker in this text.
|
|
306 output (concat output
|
|
307 (substring gud-marker-acc 0 (match-beginning 0)))
|
4346
|
308
|
10042
|
309 ;; Set the accumulator to the remaining text.
|
|
310 gud-marker-acc (substring gud-marker-acc (match-end 0))))
|
4346
|
311
|
10042
|
312 ;; Does the remaining text look like it might end with the
|
|
313 ;; beginning of another marker? If it does, then keep it in
|
|
314 ;; gud-marker-acc until we receive the rest of it. Since we
|
|
315 ;; know the full marker regexp above failed, it's pretty simple to
|
|
316 ;; test for marker starts.
|
|
317 (if (string-match "\032.*\\'" gud-marker-acc)
|
|
318 (progn
|
|
319 ;; Everything before the potential marker start can be output.
|
|
320 (setq output (concat output (substring gud-marker-acc
|
|
321 0 (match-beginning 0))))
|
4346
|
322
|
10042
|
323 ;; Everything after, we save, to combine with later input.
|
|
324 (setq gud-marker-acc
|
|
325 (substring gud-marker-acc (match-beginning 0))))
|
4346
|
326
|
10042
|
327 (setq output (concat output gud-marker-acc)
|
|
328 gud-marker-acc ""))
|
4346
|
329
|
10042
|
330 output))
|
460
|
331
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
332 (defun gud-gdb-find-file (f)
|
10448
|
333 (save-excursion
|
28731
|
334 (let ((buf (find-file-noselect f 'nowarn)))
|
10448
|
335 (set-buffer buf)
|
12002
|
336 (gud-make-debug-menu)
|
10448
|
337 (local-set-key [menu-bar debug tbreak]
|
12032
|
338 '("Temporary Breakpoint" . gud-tbreak))
|
|
339 (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish))
|
|
340 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
|
|
341 (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
|
10448
|
342 buf)))
|
460
|
343
|
6238
|
344 (defvar gdb-minibuffer-local-map nil
|
|
345 "Keymap for minibuffer prompting of gdb startup command.")
|
|
346 (if gdb-minibuffer-local-map
|
|
347 ()
|
|
348 (setq gdb-minibuffer-local-map (copy-keymap minibuffer-local-map))
|
|
349 (define-key
|
|
350 gdb-minibuffer-local-map "\C-i" 'comint-dynamic-complete-filename))
|
|
351
|
477
|
352 ;;;###autoload
|
4092
|
353 (defun gdb (command-line)
|
460
|
354 "Run gdb on program FILE in buffer *gud-FILE*.
|
|
355 The directory containing FILE becomes the initial working directory
|
|
356 and source-file directory for your debugger."
|
3930
|
357 (interactive
|
15819
|
358 (list (read-from-minibuffer "Run gdb (like this): "
|
|
359 (if (consp gud-gdb-history)
|
|
360 (car gud-gdb-history)
|
|
361 "gdb ")
|
|
362 gdb-minibuffer-local-map nil
|
25601
|
363 'gud-gdb-history)))
|
460
|
364
|
9190
|
365 (gud-common-init command-line 'gud-gdb-massage-args
|
|
366 'gud-gdb-marker-filter 'gud-gdb-find-file)
|
2581
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
367
|
2960
|
368 (gud-def gud-break "break %f:%l" "\C-b" "Set breakpoint at current line.")
|
10203
|
369 (gud-def gud-tbreak "tbreak %f:%l" "\C-t" "Set temporary breakpoint at current line.")
|
10518
|
370 (gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line")
|
2960
|
371 (gud-def gud-step "step %p" "\C-s" "Step one source line with display.")
|
|
372 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
|
|
373 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).")
|
|
374 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
|
|
375 (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
376 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
377 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
|
2960
|
378 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
|
460
|
379
|
6531
|
380 (local-set-key "\C-i" 'gud-gdb-complete-command)
|
12032
|
381 (local-set-key [menu-bar debug tbreak] '("Temporary Breakpoint" . gud-tbreak))
|
|
382 (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish))
|
|
383 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
|
|
384 (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
|
460
|
385 (setq comint-prompt-regexp "^(.*gdb[+]?) *")
|
6997
|
386 (setq paragraph-start comint-prompt-regexp)
|
460
|
387 (run-hooks 'gdb-mode-hook)
|
|
388 )
|
|
389
|
6531
|
390 ;; One of the nice features of GDB is its impressive support for
|
|
391 ;; context-sensitive command completion. We preserve that feature
|
|
392 ;; in the GUD buffer by using a GDB command designed just for Emacs.
|
|
393
|
|
394 ;; The completion process filter indicates when it is finished.
|
|
395 (defvar gud-gdb-complete-in-progress)
|
|
396
|
|
397 ;; Since output may arrive in fragments we accumulate partials strings here.
|
|
398 (defvar gud-gdb-complete-string)
|
|
399
|
|
400 ;; We need to know how much of the completion to chop off.
|
|
401 (defvar gud-gdb-complete-break)
|
|
402
|
|
403 ;; The completion list is constructed by the process filter.
|
|
404 (defvar gud-gdb-complete-list)
|
|
405
|
6535
|
406 (defvar gud-comint-buffer nil)
|
|
407
|
6531
|
408 (defun gud-gdb-complete-command ()
|
|
409 "Perform completion on the GDB command preceding point.
|
|
410 This is implemented using the GDB `complete' command which isn't
|
|
411 available with older versions of GDB."
|
|
412 (interactive)
|
|
413 (let* ((end (point))
|
30643
|
414 (command (buffer-substring (comint-line-beginning-position) end))
|
6531
|
415 command-word)
|
|
416 ;; Find the word break. This match will always succeed.
|
|
417 (string-match "\\(\\`\\| \\)\\([^ ]*\\)\\'" command)
|
|
418 (setq gud-gdb-complete-break (match-beginning 2)
|
|
419 command-word (substring command gud-gdb-complete-break))
|
9190
|
420 ;; Temporarily install our filter function.
|
|
421 (let ((gud-marker-filter 'gud-gdb-complete-filter))
|
|
422 ;; Issue the command to GDB.
|
|
423 (gud-basic-call (concat "complete " command))
|
|
424 (setq gud-gdb-complete-in-progress t
|
|
425 gud-gdb-complete-string nil
|
|
426 gud-gdb-complete-list nil)
|
|
427 ;; Slurp the output.
|
|
428 (while gud-gdb-complete-in-progress
|
|
429 (accept-process-output (get-buffer-process gud-comint-buffer))))
|
6531
|
430 ;; Protect against old versions of GDB.
|
|
431 (and gud-gdb-complete-list
|
|
432 (string-match "^Undefined command: \"complete\""
|
|
433 (car gud-gdb-complete-list))
|
|
434 (error "This version of GDB doesn't support the `complete' command."))
|
|
435 ;; Sort the list like readline.
|
|
436 (setq gud-gdb-complete-list
|
|
437 (sort gud-gdb-complete-list (function string-lessp)))
|
|
438 ;; Remove duplicates.
|
|
439 (let ((first gud-gdb-complete-list)
|
|
440 (second (cdr gud-gdb-complete-list)))
|
|
441 (while second
|
|
442 (if (string-equal (car first) (car second))
|
|
443 (setcdr first (setq second (cdr second)))
|
|
444 (setq first second
|
|
445 second (cdr second)))))
|
9816
433b0117220b
(gud-gdb-complete-command): Add a trailing single quote to partially quoted
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
446 ;; Add a trailing single quote if there is a unique completion
|
433b0117220b
(gud-gdb-complete-command): Add a trailing single quote to partially quoted
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
447 ;; and it contains an odd number of unquoted single quotes.
|
433b0117220b
(gud-gdb-complete-command): Add a trailing single quote to partially quoted
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
448 (and (= (length gud-gdb-complete-list) 1)
|
433b0117220b
(gud-gdb-complete-command): Add a trailing single quote to partially quoted
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
449 (let ((str (car gud-gdb-complete-list))
|
433b0117220b
(gud-gdb-complete-command): Add a trailing single quote to partially quoted
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
450 (pos 0)
|
433b0117220b
(gud-gdb-complete-command): Add a trailing single quote to partially quoted
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
451 (count 0))
|
433b0117220b
(gud-gdb-complete-command): Add a trailing single quote to partially quoted
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
452 (while (string-match "\\([^'\\]\\|\\\\'\\)*'" str pos)
|
433b0117220b
(gud-gdb-complete-command): Add a trailing single quote to partially quoted
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
453 (setq count (1+ count)
|
433b0117220b
(gud-gdb-complete-command): Add a trailing single quote to partially quoted
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
454 pos (match-end 0)))
|
433b0117220b
(gud-gdb-complete-command): Add a trailing single quote to partially quoted
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
455 (and (= (mod count 2) 1)
|
433b0117220b
(gud-gdb-complete-command): Add a trailing single quote to partially quoted
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
456 (setq gud-gdb-complete-list (list (concat str "'"))))))
|
6531
|
457 ;; Let comint handle the rest.
|
|
458 (comint-dynamic-simple-complete command-word gud-gdb-complete-list)))
|
22159
|
459
|
6531
|
460 ;; The completion process filter is installed temporarily to slurp the
|
|
461 ;; output of GDB up to the next prompt and build the completion list.
|
|
462 (defun gud-gdb-complete-filter (string)
|
|
463 (setq string (concat gud-gdb-complete-string string))
|
|
464 (while (string-match "\n" string)
|
|
465 (setq gud-gdb-complete-list
|
|
466 (cons (substring string gud-gdb-complete-break (match-beginning 0))
|
|
467 gud-gdb-complete-list))
|
|
468 (setq string (substring string (match-end 0))))
|
|
469 (if (string-match comint-prompt-regexp string)
|
|
470 (progn
|
|
471 (setq gud-gdb-complete-in-progress nil)
|
|
472 string)
|
|
473 (progn
|
|
474 (setq gud-gdb-complete-string string)
|
|
475 "")))
|
|
476
|
20756
|
477 ;; gdb speedbar functions
|
|
478
|
|
479 (defun gud-gdb-goto-stackframe (text token indent)
|
|
480 "Goto the stackframe described by TEXT, TOKEN, and INDENT."
|
|
481 (speedbar-with-attached-buffer
|
|
482 (gud-basic-call (concat "frame " (nth 1 token)))
|
|
483 (sit-for 1)))
|
|
484
|
|
485 (defvar gud-gdb-fetched-stack-frame nil
|
|
486 "Stack frames we are fetching from GDB.")
|
|
487
|
|
488 (defvar gud-gdb-fetched-stack-frame-list nil
|
|
489 "List of stack frames we are fetching from GDB.")
|
|
490
|
|
491 ;(defun gud-gdb-get-scope-data (text token indent)
|
|
492 ; ;; checkdoc-params: (indent)
|
|
493 ; "Fetch data associated with a stack frame, and expand/contract it.
|
|
494 ;Data to do this is retrieved from TEXT and TOKEN."
|
|
495 ; (let ((args nil) (scope nil))
|
|
496 ; (gud-gdb-run-command-fetch-lines "info args")
|
|
497 ;
|
|
498 ; (gud-gdb-run-command-fetch-lines "info local")
|
|
499 ;
|
|
500 ; ))
|
|
501
|
|
502 (defun gud-gdb-get-stackframe (buffer)
|
|
503 "Extract the current stack frame out of the GUD GDB BUFFER."
|
|
504 (let ((newlst nil)
|
|
505 (gud-gdb-fetched-stack-frame-list nil))
|
|
506 (gud-gdb-run-command-fetch-lines "backtrace" buffer)
|
22734
|
507 (if (and (car gud-gdb-fetched-stack-frame-list)
|
|
508 (string-match "No stack" (car gud-gdb-fetched-stack-frame-list)))
|
20756
|
509 ;; Go into some other mode???
|
|
510 nil
|
|
511 (while gud-gdb-fetched-stack-frame-list
|
|
512 (let ((e (car gud-gdb-fetched-stack-frame-list))
|
|
513 (name nil) (num nil))
|
|
514 (if (not (or
|
22734
|
515 (string-match "^#\\([0-9]+\\) +[0-9a-fx]+ in \\([:0-9a-zA-Z_]+\\) (" e)
|
|
516 (string-match "^#\\([0-9]+\\) +\\([:0-9a-zA-Z_]+\\) (" e)))
|
20756
|
517 (if (not (string-match
|
|
518 "at \\([-0-9a-zA-Z_.]+\\):\\([0-9]+\\)$" e))
|
|
519 nil
|
|
520 (setcar newlst
|
|
521 (list (nth 0 (car newlst))
|
|
522 (nth 1 (car newlst))
|
|
523 (match-string 1 e)
|
|
524 (match-string 2 e))))
|
|
525 (setq num (match-string 1 e)
|
|
526 name (match-string 2 e))
|
|
527 (setq newlst
|
|
528 (cons
|
|
529 (if (string-match
|
|
530 "at \\([-0-9a-zA-Z_.]+\\):\\([0-9]+\\)$" e)
|
|
531 (list name num (match-string 1 e)
|
|
532 (match-string 2 e))
|
|
533 (list name num))
|
|
534 newlst))))
|
|
535 (setq gud-gdb-fetched-stack-frame-list
|
|
536 (cdr gud-gdb-fetched-stack-frame-list)))
|
|
537 (nreverse newlst))))
|
|
538
|
|
539 ;(defun gud-gdb-selected-frame-info (buffer)
|
|
540 ; "Learn GDB information for the currently selected stack frame in BUFFER."
|
|
541 ; )
|
|
542
|
|
543 (defun gud-gdb-run-command-fetch-lines (command buffer)
|
|
544 "Run COMMAND, and return when `gud-gdb-fetched-stack-frame-list' is full.
|
|
545 BUFFER is the GUD buffer in which to run the command."
|
|
546 (save-excursion
|
|
547 (set-buffer buffer)
|
|
548 (if (save-excursion
|
|
549 (goto-char (point-max))
|
|
550 (beginning-of-line)
|
|
551 (not (looking-at comint-prompt-regexp)))
|
|
552 nil
|
|
553 ;; Much of this copied from GDB complete, but I'm grabbing the stack
|
|
554 ;; frame instead.
|
|
555 (let ((gud-marker-filter 'gud-gdb-speedbar-stack-filter))
|
|
556 ;; Issue the command to GDB.
|
|
557 (gud-basic-call command)
|
|
558 (setq gud-gdb-complete-in-progress t ;; use this flag for our purposes.
|
|
559 gud-gdb-complete-string nil
|
|
560 gud-gdb-complete-list nil)
|
|
561 ;; Slurp the output.
|
|
562 (while gud-gdb-complete-in-progress
|
|
563 (accept-process-output (get-buffer-process gud-comint-buffer)))
|
|
564 (setq gud-gdb-fetched-stack-frame nil
|
|
565 gud-gdb-fetched-stack-frame-list
|
|
566 (nreverse gud-gdb-fetched-stack-frame-list))))))
|
22159
|
567
|
20756
|
568 (defun gud-gdb-speedbar-stack-filter (string)
|
|
569 ;; checkdoc-params: (string)
|
|
570 "Filter used to read in the current GDB stack."
|
|
571 (setq string (concat gud-gdb-fetched-stack-frame string))
|
|
572 (while (string-match "\n" string)
|
|
573 (setq gud-gdb-fetched-stack-frame-list
|
|
574 (cons (substring string 0 (match-beginning 0))
|
|
575 gud-gdb-fetched-stack-frame-list))
|
|
576 (setq string (substring string (match-end 0))))
|
|
577 (if (string-match comint-prompt-regexp string)
|
|
578 (progn
|
|
579 (setq gud-gdb-complete-in-progress nil)
|
|
580 string)
|
|
581 (progn
|
|
582 (setq gud-gdb-complete-string string)
|
|
583 "")))
|
|
584
|
4729
|
585
|
460
|
586 ;; ======================================================================
|
|
587 ;; sdb functions
|
|
588
|
3930
|
589 ;;; History of argument lists passed to sdb.
|
|
590 (defvar gud-sdb-history nil)
|
|
591
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
592 (defvar gud-sdb-needs-tags (not (file-exists-p "/var"))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
593 "If nil, we're on a System V Release 4 and don't need the tags hack.")
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
594
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
595 (defvar gud-sdb-lastfile nil)
|
460
|
596
|
10876
|
597 (defun gud-sdb-massage-args (file args) args)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
598
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
599 (defun gud-sdb-marker-filter (string)
|
10319
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
600 (setq gud-marker-acc
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
601 (if gud-marker-acc (concat gud-marker-acc string) string))
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
602 (let (start)
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
603 ;; Process all complete markers in this chunk
|
22159
|
604 (while
|
|
605 (cond
|
10319
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
606 ;; System V Release 3.2 uses this format
|
13797
|
607 ((string-match "\\(^\\|\n\\)\\*?\\(0x\\w* in \\)?\\([^:\n]*\\):\\([0-9]*\\):.*\n"
|
10319
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
608 gud-marker-acc start)
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
609 (setq gud-last-frame
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
610 (cons
|
13797
|
611 (substring gud-marker-acc (match-beginning 3) (match-end 3))
|
22159
|
612 (string-to-int
|
13797
|
613 (substring gud-marker-acc (match-beginning 4) (match-end 4))))))
|
10319
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
614 ;; System V Release 4.0 quite often clumps two lines together
|
22159
|
615 ((string-match "^\\(BREAKPOINT\\|STEPPED\\) process [0-9]+ function [^ ]+ in \\(.+\\)\n\\([0-9]+\\):"
|
10319
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
616 gud-marker-acc start)
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
617 (setq gud-sdb-lastfile
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
618 (substring gud-marker-acc (match-beginning 2) (match-end 2)))
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
619 (setq gud-last-frame
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
620 (cons
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
621 gud-sdb-lastfile
|
22159
|
622 (string-to-int
|
10319
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
623 (substring gud-marker-acc (match-beginning 3) (match-end 3))))))
|
22159
|
624 ;; System V Release 4.0
|
10319
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
625 ((string-match "^\\(BREAKPOINT\\|STEPPED\\) process [0-9]+ function [^ ]+ in \\(.+\\)\n"
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
626 gud-marker-acc start)
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
627 (setq gud-sdb-lastfile
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
628 (substring gud-marker-acc (match-beginning 2) (match-end 2))))
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
629 ((and gud-sdb-lastfile (string-match "^\\([0-9]+\\):"
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
630 gud-marker-acc start))
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
631 (setq gud-last-frame
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
632 (cons
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
633 gud-sdb-lastfile
|
22159
|
634 (string-to-int
|
10319
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
635 (substring gud-marker-acc (match-beginning 1) (match-end 1))))))
|
22159
|
636 (t
|
10319
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
637 (setq gud-sdb-lastfile nil)))
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
638 (setq start (match-end 0)))
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
639
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
640 ;; Search for the last incomplete line in this chunk
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
641 (while (string-match "\n" gud-marker-acc start)
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
642 (setq start (match-end 0)))
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
643
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
644 ;; If we have an incomplete line, store it in gud-marker-acc.
|
13797
|
645 (setq gud-marker-acc (substring gud-marker-acc (or start 0))))
|
460
|
646 string)
|
|
647
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
648 (defun gud-sdb-find-file (f)
|
10448
|
649 (save-excursion
|
|
650 (let ((buf (if gud-sdb-needs-tags
|
|
651 (find-tag-noselect f)
|
|
652 (find-file-noselect f))))
|
|
653 (set-buffer buf)
|
12002
|
654 (gud-make-debug-menu)
|
12032
|
655 (local-set-key [menu-bar debug tbreak] '("Temporary Breakpoint" . gud-tbreak))
|
10448
|
656 buf)))
|
460
|
657
|
477
|
658 ;;;###autoload
|
4092
|
659 (defun sdb (command-line)
|
460
|
660 "Run sdb on program FILE in buffer *gud-FILE*.
|
|
661 The directory containing FILE becomes the initial working directory
|
|
662 and source-file directory for your debugger."
|
3930
|
663 (interactive
|
4092
|
664 (list (read-from-minibuffer "Run sdb (like this): "
|
3930
|
665 (if (consp gud-sdb-history)
|
|
666 (car gud-sdb-history)
|
4092
|
667 "sdb ")
|
3930
|
668 nil nil
|
25601
|
669 'gud-sdb-history)))
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
670 (if (and gud-sdb-needs-tags
|
7461
|
671 (not (and (boundp 'tags-file-name)
|
|
672 (stringp tags-file-name)
|
|
673 (file-exists-p tags-file-name))))
|
460
|
674 (error "The sdb support requires a valid tags table to work."))
|
|
675
|
9190
|
676 (gud-common-init command-line 'gud-sdb-massage-args
|
|
677 'gud-sdb-marker-filter 'gud-sdb-find-file)
|
2581
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
678
|
2960
|
679 (gud-def gud-break "%l b" "\C-b" "Set breakpoint at current line.")
|
|
680 (gud-def gud-tbreak "%l c" "\C-t" "Set temporary breakpoint at current line.")
|
|
681 (gud-def gud-remove "%l d" "\C-d" "Remove breakpoint at current line")
|
|
682 (gud-def gud-step "s %p" "\C-s" "Step one source line with display.")
|
|
683 (gud-def gud-stepi "i %p" "\C-i" "Step one instruction with display.")
|
|
684 (gud-def gud-next "S %p" "\C-n" "Step one line (skip functions).")
|
|
685 (gud-def gud-cont "c" "\C-r" "Continue with display.")
|
|
686 (gud-def gud-print "%e/" "\C-p" "Evaluate C expression at point.")
|
460
|
687
|
1255
|
688 (setq comint-prompt-regexp "\\(^\\|\n\\)\\*")
|
6997
|
689 (setq paragraph-start comint-prompt-regexp)
|
10217
|
690 (local-set-key [menu-bar debug tbreak]
|
12032
|
691 '("Temporary Breakpoint" . gud-tbreak))
|
460
|
692 (run-hooks 'sdb-mode-hook)
|
|
693 )
|
4729
|
694
|
460
|
695 ;; ======================================================================
|
|
696 ;; dbx functions
|
|
697
|
3930
|
698 ;;; History of argument lists passed to dbx.
|
|
699 (defvar gud-dbx-history nil)
|
|
700
|
17663
|
701 (defcustom gud-dbx-directories nil
|
13288
|
702 "*A list of directories that dbx should search for source code.
|
|
703 If nil, only source files in the program directory
|
|
704 will be known to dbx.
|
|
705
|
|
706 The file names should be absolute, or relative to the directory
|
17663
|
707 containing the executable being debugged."
|
|
708 :type '(choice (const :tag "Current Directory" nil)
|
|
709 (repeat :value ("")
|
|
710 directory))
|
|
711 :group 'gud)
|
13288
|
712
|
|
713 (defun gud-dbx-massage-args (file args)
|
|
714 (nconc (let ((directories gud-dbx-directories)
|
|
715 (result nil))
|
|
716 (while directories
|
|
717 (setq result (cons (car directories) (cons "-I" result)))
|
|
718 (setq directories (cdr directories)))
|
|
719 (nreverse result))
|
|
720 args))
|
|
721
|
|
722 (defun gud-dbx-file-name (f)
|
|
723 "Transform a relative file name to an absolute file name, for dbx."
|
|
724 (let ((result nil))
|
|
725 (if (file-exists-p f)
|
|
726 (setq result (expand-file-name f))
|
|
727 (let ((directories gud-dbx-directories))
|
|
728 (while directories
|
|
729 (let ((path (concat (car directories) "/" f)))
|
|
730 (if (file-exists-p path)
|
|
731 (setq result (expand-file-name path)
|
|
732 directories nil)))
|
|
733 (setq directories (cdr directories)))))
|
|
734 result))
|
460
|
735
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
736 (defun gud-dbx-marker-filter (string)
|
10319
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
737 (setq gud-marker-acc (if gud-marker-acc (concat gud-marker-acc string) string))
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
738
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
739 (let (start)
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
740 ;; Process all complete markers in this chunk.
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
741 (while (or (string-match
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
742 "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\""
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
743 gud-marker-acc start)
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
744 (string-match
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
745 "signal .* in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\""
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
746 gud-marker-acc start))
|
460
|
747 (setq gud-last-frame
|
|
748 (cons
|
10319
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
749 (substring gud-marker-acc (match-beginning 2) (match-end 2))
|
22159
|
750 (string-to-int
|
10319
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
751 (substring gud-marker-acc (match-beginning 1) (match-end 1))))
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
752 start (match-end 0)))
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
753
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
754 ;; Search for the last incomplete line in this chunk
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
755 (while (string-match "\n" gud-marker-acc start)
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
756 (setq start (match-end 0)))
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
757
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
758 ;; If the incomplete line APPEARS to begin with another marker, keep it
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
759 ;; in the accumulator. Otherwise, clear the accumulator to avoid an
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
760 ;; unnecessary concat during the next call.
|
22159
|
761 (setq gud-marker-acc
|
10319
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
762 (if (string-match "\\(stopped\\|signal\\)" gud-marker-acc start)
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
763 (substring gud-marker-acc (match-beginning 0))
|
bf67e2fdd393
(gud-dbx-marker-filter): Use gud-marker-acc like gud-gdb-marker-filter.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
764 nil)))
|
460
|
765 string)
|
|
766
|
7165
|
767 ;; Functions for Mips-style dbx. Given the option `-emacs', documented in
|
|
768 ;; OSF1, not necessarily elsewhere, it produces markers similar to gdb's.
|
|
769 (defvar gud-mips-p
|
|
770 (or (string-match "^mips-[^-]*-ultrix" system-configuration)
|
|
771 ;; We haven't tested gud on this system:
|
|
772 (string-match "^mips-[^-]*-riscos" system-configuration)
|
|
773 ;; It's documented on OSF/1.3
|
8172
|
774 (string-match "^mips-[^-]*-osf1" system-configuration)
|
20425
|
775 (string-match "^alpha[^-]*-[^-]*-osf" system-configuration))
|
7165
|
776 "Non-nil to assume the MIPS/OSF dbx conventions (argument `-emacs').")
|
5264
|
777
|
|
778 (defun gud-mipsdbx-massage-args (file args)
|
10876
|
779 (cons "-emacs" args))
|
5264
|
780
|
7165
|
781 ;; This is just like the gdb one except for the regexps since we need to cope
|
|
782 ;; with an optional breakpoint number in [] before the ^Z^Z
|
5264
|
783 (defun gud-mipsdbx-marker-filter (string)
|
10042
|
784 (setq gud-marker-acc (concat gud-marker-acc string))
|
|
785 (let ((output ""))
|
|
786
|
|
787 ;; Process all the complete markers in this chunk.
|
|
788 (while (string-match
|
|
789 ;; This is like th gdb marker but with an optional
|
|
790 ;; leading break point number like `[1] '
|
|
791 "[][ 0-9]*\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
|
|
792 gud-marker-acc)
|
|
793 (setq
|
5264
|
794
|
10042
|
795 ;; Extract the frame position from the marker.
|
|
796 gud-last-frame
|
|
797 (cons (substring gud-marker-acc (match-beginning 1) (match-end 1))
|
|
798 (string-to-int (substring gud-marker-acc
|
|
799 (match-beginning 2)
|
|
800 (match-end 2))))
|
5264
|
801
|
10042
|
802 ;; Append any text before the marker to the output we're going
|
|
803 ;; to return - we don't include the marker in this text.
|
|
804 output (concat output
|
|
805 (substring gud-marker-acc 0 (match-beginning 0)))
|
5264
|
806
|
10042
|
807 ;; Set the accumulator to the remaining text.
|
|
808 gud-marker-acc (substring gud-marker-acc (match-end 0))))
|
5264
|
809
|
10042
|
810 ;; Does the remaining text look like it might end with the
|
|
811 ;; beginning of another marker? If it does, then keep it in
|
|
812 ;; gud-marker-acc until we receive the rest of it. Since we
|
|
813 ;; know the full marker regexp above failed, it's pretty simple to
|
|
814 ;; test for marker starts.
|
|
815 (if (string-match "[][ 0-9]*\032.*\\'" gud-marker-acc)
|
|
816 (progn
|
|
817 ;; Everything before the potential marker start can be output.
|
|
818 (setq output (concat output (substring gud-marker-acc
|
|
819 0 (match-beginning 0))))
|
7165
|
820
|
10042
|
821 ;; Everything after, we save, to combine with later input.
|
|
822 (setq gud-marker-acc
|
|
823 (substring gud-marker-acc (match-beginning 0))))
|
7165
|
824
|
10042
|
825 (setq output (concat output gud-marker-acc)
|
|
826 gud-marker-acc ""))
|
5264
|
827
|
10042
|
828 output))
|
5264
|
829
|
7165
|
830 ;; The dbx in IRIX is a pain. It doesn't print the file name when
|
|
831 ;; stopping at a breakpoint (but you do get it from the `up' and
|
|
832 ;; `down' commands...). The only way to extract the information seems
|
|
833 ;; to be with a `file' command, although the current line number is
|
|
834 ;; available in $curline. Thus we have to look for output which
|
|
835 ;; appears to indicate a breakpoint. Then we prod the dbx sub-process
|
|
836 ;; to output the information we want with a combination of the
|
|
837 ;; `printf' and `file' commands as a pseudo marker which we can
|
|
838 ;; recognise next time through the marker-filter. This would be like
|
|
839 ;; the gdb marker but you can't get the file name without a newline...
|
|
840 ;; Note that gud-remove won't work since Irix dbx expects a breakpoint
|
|
841 ;; number rather than a line number etc. Maybe this could be made to
|
|
842 ;; work by listing all the breakpoints and picking the one(s) with the
|
|
843 ;; correct line number, but life's too short.
|
|
844 ;; d.love@dl.ac.uk (Dave Love) can be blamed for this
|
|
845
|
15624
|
846 (defvar gud-irix-p
|
|
847 (and (string-match "^mips-[^-]*-irix" system-configuration)
|
|
848 (not (string-match "irix[6-9]\\.[1-9]" system-configuration)))
|
7165
|
849 "Non-nil to assume the interface appropriate for IRIX dbx.
|
15624
|
850 This works in IRIX 4, 5 and 6, but `gud-dbx-use-stopformat-p' provides
|
|
851 a better solution in 6.1 upwards.")
|
|
852 (defvar gud-dbx-use-stopformat-p
|
|
853 (string-match "irix[6-9]\\.[1-9]" system-configuration)
|
|
854 "Non-nil to use the dbx feature present at least from Irix 6.1
|
|
855 whereby $stopformat=1 produces an output format compatiable with
|
|
856 `gud-dbx-marker-filter'.")
|
10203
|
857 ;; [Irix dbx seems to be a moving target. The dbx output changed
|
|
858 ;; subtly sometime between OS v4.0.5 and v5.2 so that, for instance,
|
|
859 ;; the output from `up' is no longer spotted by gud (and it's probably
|
|
860 ;; not distinctive enough to try to match it -- use C-<, C->
|
|
861 ;; exclusively) . For 5.3 and 6.0, the $curline variable changed to
|
|
862 ;; `long long'(why?!), so the printf stuff needed changing. The line
|
15624
|
863 ;; number was cast to `long' as a compromise between the new `long
|
|
864 ;; long' and the original `int'. This is reported not to work in 6.2,
|
|
865 ;; so it's changed back to int -- don't make your sources too long.
|
|
866 ;; From Irix6.1 (but not 6.0?) dbx supports an undocumented feature
|
|
867 ;; whereby `set $stopformat=1' reportedly produces output compatible
|
|
868 ;; with `gud-dbx-marker-filter', which we prefer.
|
|
869
|
|
870 ;; The process filter is also somewhat
|
10203
|
871 ;; unreliable, sometimes not spotting the markers; I don't know
|
|
872 ;; whether there's anything that can be done about that. It would be
|
|
873 ;; much better if SGI could be persuaded to (re?)instate the MIPS
|
|
874 ;; -emacs flag for gdb-like output (which ought to be possible as most
|
|
875 ;; of the communication I've had over it has been from sgi.com).]
|
7165
|
876
|
|
877 ;; this filter is influenced by the xdb one rather than the gdb one
|
|
878 (defun gud-irixdbx-marker-filter (string)
|
10042
|
879 (let (result (case-fold-search nil))
|
|
880 (if (or (string-match comint-prompt-regexp string)
|
|
881 (string-match ".*\012" string))
|
|
882 (setq result (concat gud-marker-acc string)
|
|
883 gud-marker-acc "")
|
|
884 (setq gud-marker-acc (concat gud-marker-acc string)))
|
|
885 (if result
|
|
886 (cond
|
|
887 ;; look for breakpoint or signal indication e.g.:
|
|
888 ;; [2] Process 1267 (pplot) stopped at [params:338 ,0x400ec0]
|
|
889 ;; Process 1281 (pplot) stopped at [params:339 ,0x400ec8]
|
|
890 ;; Process 1270 (pplot) Floating point exception [._read._read:16 ,0x452188]
|
|
891 ((string-match
|
22159
|
892 "^\\(\\[[0-9]+] \\)?Process +[0-9]+ ([^)]*) [^[]+\\[[^]\n]*]\n"
|
10042
|
893 result)
|
|
894 ;; prod dbx into printing out the line number and file
|
|
895 ;; name in a form we can grok as below
|
|
896 (process-send-string (get-buffer-process gud-comint-buffer)
|
15624
|
897 "printf \"\032\032%1d:\",(int)$curline;file\n"))
|
10042
|
898 ;; look for result of, say, "up" e.g.:
|
|
899 ;; .pplot.pplot(0x800) ["src/pplot.f":261, 0x400c7c]
|
|
900 ;; (this will also catch one of the lines printed by "where")
|
|
901 ((string-match
|
|
902 "^[^ ][^[]*\\[\"\\([^\"]+\\)\":\\([0-9]+\\), [^]]+]\n"
|
|
903 result)
|
|
904 (let ((file (substring result (match-beginning 1)
|
|
905 (match-end 1))))
|
|
906 (if (file-exists-p file)
|
|
907 (setq gud-last-frame
|
|
908 (cons
|
|
909 (substring
|
|
910 result (match-beginning 1) (match-end 1))
|
22159
|
911 (string-to-int
|
10042
|
912 (substring
|
|
913 result (match-beginning 2) (match-end 2)))))))
|
|
914 result)
|
|
915 ((string-match ; kluged-up marker as above
|
|
916 "\032\032\\([0-9]*\\):\\(.*\\)\n" result)
|
13288
|
917 (let ((file (gud-dbx-file-name
|
|
918 (substring result (match-beginning 2) (match-end 2)))))
|
|
919 (if (and file (file-exists-p file))
|
10042
|
920 (setq gud-last-frame
|
|
921 (cons
|
|
922 file
|
22159
|
923 (string-to-int
|
10042
|
924 (substring
|
|
925 result (match-beginning 1) (match-end 1)))))))
|
|
926 (setq result (substring result 0 (match-beginning 0))))))
|
|
927 (or result "")))
|
7165
|
928
|
18098
|
929 (defvar gud-dgux-p (string-match "-dgux" system-configuration)
|
|
930 "Non-nil means to assume the interface approriate for DG/UX dbx.
|
|
931 This was tested using R4.11.")
|
|
932
|
|
933 ;; There are a couple of differences between DG's dbx output and normal
|
|
934 ;; dbx output which make it nontrivial to integrate this into the
|
|
935 ;; standard dbx-marker-filter (mainly, there are a different number of
|
|
936 ;; backreferences). The markers look like:
|
|
937 ;;
|
|
938 ;; (0) Stopped at line 10, routine main(argc=1, argv=0xeffff0e0), file t.c
|
|
939 ;;
|
|
940 ;; from breakpoints (the `(0)' there isn't constant, it's the breakpoint
|
|
941 ;; number), and
|
|
942 ;;
|
|
943 ;; Stopped at line 13, routine main(argc=1, argv=0xeffff0e0), file t.c
|
|
944 ;;
|
|
945 ;; from signals and
|
|
946 ;;
|
|
947 ;; Frame 21, line 974, routine command_loop(), file keyboard.c
|
|
948 ;;
|
|
949 ;; from up/down/where.
|
|
950
|
|
951 (defun gud-dguxdbx-marker-filter (string)
|
|
952 (setq gud-marker-acc (if gud-marker-acc
|
|
953 (concat gud-marker-acc string)
|
|
954 string))
|
|
955 (let ((re (concat "^\\(\\(([0-9]+) \\)?Stopped at\\|Frame [0-9]+,\\)"
|
|
956 " line \\([0-9]+\\), routine .*, file \\([^ \t\n]+\\)"))
|
|
957 start)
|
|
958 ;; Process all complete markers in this chunk.
|
|
959 (while (string-match re gud-marker-acc start)
|
|
960 (setq gud-last-frame
|
|
961 (cons
|
|
962 (substring gud-marker-acc (match-beginning 4) (match-end 4))
|
|
963 (string-to-int (substring gud-marker-acc
|
|
964 (match-beginning 3) (match-end 3))))
|
|
965 start (match-end 0)))
|
|
966
|
|
967 ;; Search for the last incomplete line in this chunk
|
|
968 (while (string-match "\n" gud-marker-acc start)
|
|
969 (setq start (match-end 0)))
|
|
970
|
|
971 ;; If the incomplete line APPEARS to begin with another marker, keep it
|
|
972 ;; in the accumulator. Otherwise, clear the accumulator to avoid an
|
|
973 ;; unnecessary concat during the next call.
|
22159
|
974 (setq gud-marker-acc
|
18098
|
975 (if (string-match "Stopped\\|Frame" gud-marker-acc start)
|
|
976 (substring gud-marker-acc (match-beginning 0))
|
|
977 nil)))
|
|
978 string)
|
|
979
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
980 (defun gud-dbx-find-file (f)
|
10448
|
981 (save-excursion
|
13288
|
982 (let ((realf (gud-dbx-file-name f)))
|
|
983 (if realf
|
13659
|
984 (let ((buf (find-file-noselect realf)))
|
13288
|
985 (set-buffer buf)
|
|
986 (gud-make-debug-menu)
|
|
987 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
|
|
988 (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
|
|
989 buf)
|
|
990 nil))))
|
460
|
991
|
477
|
992 ;;;###autoload
|
4092
|
993 (defun dbx (command-line)
|
460
|
994 "Run dbx on program FILE in buffer *gud-FILE*.
|
|
995 The directory containing FILE becomes the initial working directory
|
|
996 and source-file directory for your debugger."
|
3930
|
997 (interactive
|
4092
|
998 (list (read-from-minibuffer "Run dbx (like this): "
|
3930
|
999 (if (consp gud-dbx-history)
|
|
1000 (car gud-dbx-history)
|
4092
|
1001 "dbx ")
|
3930
|
1002 nil nil
|
25601
|
1003 'gud-dbx-history)))
|
5264
|
1004
|
9190
|
1005 (cond
|
|
1006 (gud-mips-p
|
|
1007 (gud-common-init command-line 'gud-mipsdbx-massage-args
|
|
1008 'gud-mipsdbx-marker-filter 'gud-dbx-find-file))
|
|
1009 (gud-irix-p
|
|
1010 (gud-common-init command-line 'gud-dbx-massage-args
|
|
1011 'gud-irixdbx-marker-filter 'gud-dbx-find-file))
|
18098
|
1012 (gud-dgux-p
|
|
1013 (gud-common-init command-line 'gud-dbx-massage-args
|
|
1014 'gud-dguxdbx-marker-filter 'gud-dbx-find-file))
|
9190
|
1015 (t
|
|
1016 (gud-common-init command-line 'gud-dbx-massage-args
|
|
1017 'gud-dbx-marker-filter 'gud-dbx-find-file)))
|
2581
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
1018
|
5264
|
1019 (cond
|
7165
|
1020 (gud-mips-p
|
10203
|
1021 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
|
|
1022 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
|
5264
|
1023 (gud-def gud-break "stop at \"%f\":%l"
|
|
1024 "\C-b" "Set breakpoint at current line.")
|
|
1025 (gud-def gud-finish "return" "\C-f" "Finish executing current function."))
|
7165
|
1026 (gud-irix-p
|
|
1027 (gud-def gud-break "stop at \"%d%f\":%l"
|
|
1028 "\C-b" "Set breakpoint at current line.")
|
|
1029 (gud-def gud-finish "return" "\C-f" "Finish executing current function.")
|
15624
|
1030 (gud-def gud-up "up %p; printf \"\032\032%1d:\",(int)$curline;file\n"
|
10203
|
1031 "<" "Up (numeric arg) stack frames.")
|
15624
|
1032 (gud-def gud-down "down %p; printf \"\032\032%1d:\",(int)$curline;file\n"
|
10203
|
1033 ">" "Down (numeric arg) stack frames.")
|
7165
|
1034 ;; Make dbx give out the source location info that we need.
|
|
1035 (process-send-string (get-buffer-process gud-comint-buffer)
|
15624
|
1036 "printf \"\032\032%1d:\",(int)$curline;file\n"))
|
|
1037 (gud-dbx-use-stopformat-p
|
22159
|
1038 (process-send-string (get-buffer-process gud-comint-buffer)
|
15624
|
1039 "set $stopformat=1\n"))
|
5264
|
1040 (t
|
10203
|
1041 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
|
|
1042 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
|
5264
|
1043 (gud-def gud-break "file \"%d%f\"\nstop at %l"
|
|
1044 "\C-b" "Set breakpoint at current line.")))
|
|
1045
|
2960
|
1046 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
|
|
1047 (gud-def gud-step "step %p" "\C-s" "Step one line with display.")
|
|
1048 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
|
|
1049 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).")
|
|
1050 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
|
|
1051 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
|
868
|
1052
|
5264
|
1053 (setq comint-prompt-regexp "^[^)\n]*dbx) *")
|
6997
|
1054 (setq paragraph-start comint-prompt-regexp)
|
12032
|
1055 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
|
|
1056 (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
|
460
|
1057 (run-hooks 'dbx-mode-hook)
|
|
1058 )
|
4729
|
1059
|
3738
|
1060 ;; ======================================================================
|
|
1061 ;; xdb (HP PARISC debugger) functions
|
|
1062
|
3930
|
1063 ;;; History of argument lists passed to xdb.
|
|
1064 (defvar gud-xdb-history nil)
|
|
1065
|
17663
|
1066 (defcustom gud-xdb-directories nil
|
3745
|
1067 "*A list of directories that xdb should search for source code.
|
|
1068 If nil, only source files in the program directory
|
|
1069 will be known to xdb.
|
|
1070
|
|
1071 The file names should be absolute, or relative to the directory
|
17663
|
1072 containing the executable being debugged."
|
|
1073 :type '(choice (const :tag "Current Directory" nil)
|
|
1074 (repeat :value ("")
|
|
1075 directory))
|
|
1076 :group 'gud)
|
3745
|
1077
|
4092
|
1078 (defun gud-xdb-massage-args (file args)
|
|
1079 (nconc (let ((directories gud-xdb-directories)
|
|
1080 (result nil))
|
|
1081 (while directories
|
|
1082 (setq result (cons (car directories) (cons "-d" result)))
|
|
1083 (setq directories (cdr directories)))
|
10876
|
1084 (nreverse result))
|
4092
|
1085 args))
|
3738
|
1086
|
|
1087 (defun gud-xdb-file-name (f)
|
|
1088 "Transform a relative pathname to a full pathname in xdb mode"
|
|
1089 (let ((result nil))
|
|
1090 (if (file-exists-p f)
|
|
1091 (setq result (expand-file-name f))
|
3745
|
1092 (let ((directories gud-xdb-directories))
|
|
1093 (while directories
|
|
1094 (let ((path (concat (car directories) "/" f)))
|
3738
|
1095 (if (file-exists-p path)
|
|
1096 (setq result (expand-file-name path)
|
3745
|
1097 directories nil)))
|
|
1098 (setq directories (cdr directories)))))
|
3738
|
1099 result))
|
|
1100
|
|
1101 ;; xdb does not print the lines all at once, so we have to accumulate them
|
|
1102 (defun gud-xdb-marker-filter (string)
|
|
1103 (let (result)
|
|
1104 (if (or (string-match comint-prompt-regexp string)
|
|
1105 (string-match ".*\012" string))
|
7165
|
1106 (setq result (concat gud-marker-acc string)
|
|
1107 gud-marker-acc "")
|
|
1108 (setq gud-marker-acc (concat gud-marker-acc string)))
|
3738
|
1109 (if result
|
12743
|
1110 (if (or (string-match "\\([^\n \t:]+\\): [^:]+: \\([0-9]+\\)[: ]"
|
|
1111 result)
|
3738
|
1112 (string-match "[^: \t]+:[ \t]+\\([^:]+\\): [^:]+: \\([0-9]+\\):"
|
|
1113 result))
|
12743
|
1114 (let ((line (string-to-int
|
3738
|
1115 (substring result (match-beginning 2) (match-end 2))))
|
|
1116 (file (gud-xdb-file-name
|
|
1117 (substring result (match-beginning 1) (match-end 1)))))
|
|
1118 (if file
|
|
1119 (setq gud-last-frame (cons file line))))))
|
22159
|
1120 (or result "")))
|
|
1121
|
3738
|
1122 (defun gud-xdb-find-file (f)
|
10448
|
1123 (save-excursion
|
|
1124 (let ((realf (gud-xdb-file-name f)))
|
|
1125 (if realf
|
|
1126 (let ((buf (find-file-noselect realf)))
|
|
1127 (set-buffer buf)
|
12002
|
1128 (gud-make-debug-menu)
|
10448
|
1129 (local-set-key [menu-bar debug tbreak]
|
12032
|
1130 '("Temporary Breakpoint" . gud-tbreak))
|
10448
|
1131 (local-set-key [menu-bar debug finish]
|
12032
|
1132 '("Finish Function" . gud-finish))
|
|
1133 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
|
|
1134 (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
|
10448
|
1135 buf)
|
|
1136 nil))))
|
3738
|
1137
|
|
1138 ;;;###autoload
|
4092
|
1139 (defun xdb (command-line)
|
3738
|
1140 "Run xdb on program FILE in buffer *gud-FILE*.
|
|
1141 The directory containing FILE becomes the initial working directory
|
|
1142 and source-file directory for your debugger.
|
|
1143
|
3745
|
1144 You can set the variable 'gud-xdb-directories' to a list of program source
|
3738
|
1145 directories if your program contains sources from more than one directory."
|
3930
|
1146 (interactive
|
4092
|
1147 (list (read-from-minibuffer "Run xdb (like this): "
|
3930
|
1148 (if (consp gud-xdb-history)
|
|
1149 (car gud-xdb-history)
|
4092
|
1150 "xdb ")
|
3930
|
1151 nil nil
|
25601
|
1152 'gud-xdb-history)))
|
3738
|
1153
|
9190
|
1154 (gud-common-init command-line 'gud-xdb-massage-args
|
|
1155 'gud-xdb-marker-filter 'gud-xdb-find-file)
|
3738
|
1156
|
|
1157 (gud-def gud-break "b %f:%l" "\C-b" "Set breakpoint at current line.")
|
|
1158 (gud-def gud-tbreak "b %f:%l\\t" "\C-t"
|
|
1159 "Set temporary breakpoint at current line.")
|
|
1160 (gud-def gud-remove "db" "\C-d" "Remove breakpoint at current line")
|
|
1161 (gud-def gud-step "s %p" "\C-s" "Step one line with display.")
|
|
1162 (gud-def gud-next "S %p" "\C-n" "Step one line (skip functions).")
|
|
1163 (gud-def gud-cont "c" "\C-r" "Continue with display.")
|
|
1164 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
|
|
1165 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
|
|
1166 (gud-def gud-finish "bu\\t" "\C-f" "Finish executing current function.")
|
|
1167 (gud-def gud-print "p %e" "\C-p" "Evaluate C expression at point.")
|
|
1168
|
|
1169 (setq comint-prompt-regexp "^>")
|
6997
|
1170 (setq paragraph-start comint-prompt-regexp)
|
12032
|
1171 (local-set-key [menu-bar debug tbreak] '("Temporary Breakpoint" . gud-tbreak))
|
|
1172 (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish))
|
|
1173 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
|
|
1174 (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
|
3738
|
1175 (run-hooks 'xdb-mode-hook))
|
4729
|
1176
|
|
1177 ;; ======================================================================
|
|
1178 ;; perldb functions
|
|
1179
|
|
1180 ;;; History of argument lists passed to perldb.
|
|
1181 (defvar gud-perldb-history nil)
|
|
1182
|
26351
|
1183 ;; Convert a command line as would be typed normally to run a script
|
|
1184 ;; into one that invokes an Emacs-enabled debugging session.
|
|
1185 ;; "-d" in inserted as the first switch, and "-emacs" is inserted where
|
|
1186 ;; it will be $ARGV[0] (see perl5db.pl).
|
4729
|
1187 (defun gud-perldb-massage-args (file args)
|
26351
|
1188 (let* ((new-args '("-d"))
|
|
1189 (seen-e nil)
|
|
1190 (shift (lambda ()
|
|
1191 (setq new-args (cons (car args) new-args))
|
|
1192 (setq args (cdr args)))))
|
26294
|
1193
|
26351
|
1194 ;; Pass all switches and -e scripts through.
|
26294
|
1195 (while (and args
|
26351
|
1196 (string-match "^-" (car args))
|
|
1197 (not (equal "-" (car args)))
|
|
1198 (not (equal "--" (car args))))
|
|
1199 (when (equal "-e" (car args))
|
|
1200 ;; -e goes with the next arg, so shift one extra.
|
|
1201 (or (funcall shift)
|
|
1202 ;; -e as the last arg is an error in Perl.
|
|
1203 (error "No code specified for -e."))
|
|
1204 (setq seen-e t))
|
|
1205 (funcall shift))
|
26294
|
1206
|
26351
|
1207 (when (not seen-e)
|
|
1208 (if (or (not args)
|
|
1209 (string-match "^-" (car args)))
|
|
1210 (error "Can't use stdin as the script to debug."))
|
|
1211 ;; This is the program name.
|
|
1212 (funcall shift))
|
|
1213
|
|
1214 ;; If -e specified, make sure there is a -- so -emacs is not taken
|
|
1215 ;; as -e macs.
|
|
1216 (if (and args (equal "--" (car args)))
|
|
1217 (funcall shift)
|
|
1218 (and seen-e (setq new-args (cons "--" new-args))))
|
26294
|
1219
|
|
1220 (setq new-args (cons "-emacs" new-args))
|
26351
|
1221 (while args
|
|
1222 (funcall shift))
|
26294
|
1223
|
26351
|
1224 (nreverse new-args)))
|
4729
|
1225
|
|
1226 ;; There's no guarantee that Emacs will hand the filter the entire
|
|
1227 ;; marker at once; it could be broken up across several strings. We
|
|
1228 ;; might even receive a big chunk with several markers in it. If we
|
|
1229 ;; receive a chunk of text which looks like it might contain the
|
|
1230 ;; beginning of a marker, we save it here between calls to the
|
|
1231 ;; filter.
|
|
1232 (defun gud-perldb-marker-filter (string)
|
10042
|
1233 (setq gud-marker-acc (concat gud-marker-acc string))
|
|
1234 (let ((output ""))
|
4729
|
1235
|
10042
|
1236 ;; Process all the complete markers in this chunk.
|
16327
|
1237 (while (string-match "\032\032\\(\\([a-zA-Z]:\\)?[^:\n]*\\):\\([0-9]*\\):.*\n"
|
10042
|
1238 gud-marker-acc)
|
|
1239 (setq
|
4729
|
1240
|
10042
|
1241 ;; Extract the frame position from the marker.
|
|
1242 gud-last-frame
|
|
1243 (cons (substring gud-marker-acc (match-beginning 1) (match-end 1))
|
|
1244 (string-to-int (substring gud-marker-acc
|
16327
|
1245 (match-beginning 3)
|
|
1246 (match-end 3))))
|
4729
|
1247
|
10042
|
1248 ;; Append any text before the marker to the output we're going
|
|
1249 ;; to return - we don't include the marker in this text.
|
|
1250 output (concat output
|
|
1251 (substring gud-marker-acc 0 (match-beginning 0)))
|
4729
|
1252
|
10042
|
1253 ;; Set the accumulator to the remaining text.
|
|
1254 gud-marker-acc (substring gud-marker-acc (match-end 0))))
|
4729
|
1255
|
10042
|
1256 ;; Does the remaining text look like it might end with the
|
|
1257 ;; beginning of another marker? If it does, then keep it in
|
|
1258 ;; gud-marker-acc until we receive the rest of it. Since we
|
|
1259 ;; know the full marker regexp above failed, it's pretty simple to
|
|
1260 ;; test for marker starts.
|
|
1261 (if (string-match "\032.*\\'" gud-marker-acc)
|
|
1262 (progn
|
|
1263 ;; Everything before the potential marker start can be output.
|
|
1264 (setq output (concat output (substring gud-marker-acc
|
|
1265 0 (match-beginning 0))))
|
4729
|
1266
|
10042
|
1267 ;; Everything after, we save, to combine with later input.
|
|
1268 (setq gud-marker-acc
|
|
1269 (substring gud-marker-acc (match-beginning 0))))
|
4729
|
1270
|
10042
|
1271 (setq output (concat output gud-marker-acc)
|
|
1272 gud-marker-acc ""))
|
4729
|
1273
|
10042
|
1274 output))
|
4729
|
1275
|
|
1276 (defun gud-perldb-find-file (f)
|
10448
|
1277 (save-excursion
|
|
1278 (let ((buf (find-file-noselect f)))
|
|
1279 (set-buffer buf)
|
12004
|
1280 (gud-make-debug-menu)
|
10448
|
1281 buf)))
|
4729
|
1282
|
21336
|
1283 (defcustom gud-perldb-command-name "perl"
|
17663
|
1284 "File name for executing Perl."
|
|
1285 :type 'string
|
|
1286 :group 'gud)
|
15755
|
1287
|
4729
|
1288 ;;;###autoload
|
|
1289 (defun perldb (command-line)
|
|
1290 "Run perldb on program FILE in buffer *gud-FILE*.
|
|
1291 The directory containing FILE becomes the initial working directory
|
|
1292 and source-file directory for your debugger."
|
|
1293 (interactive
|
|
1294 (list (read-from-minibuffer "Run perldb (like this): "
|
|
1295 (if (consp gud-perldb-history)
|
|
1296 (car gud-perldb-history)
|
21336
|
1297 (concat gud-perldb-command-name
|
16362
|
1298 " "
|
|
1299 (or (buffer-file-name)
|
19890
|
1300 "-e 0")
|
|
1301 " "))
|
4729
|
1302 nil nil
|
25601
|
1303 'gud-perldb-history)))
|
4729
|
1304
|
9190
|
1305 (gud-common-init command-line 'gud-perldb-massage-args
|
|
1306 'gud-perldb-marker-filter 'gud-perldb-find-file)
|
4729
|
1307
|
4732
|
1308 (gud-def gud-break "b %l" "\C-b" "Set breakpoint at current line.")
|
|
1309 (gud-def gud-remove "d %l" "\C-d" "Remove breakpoint at current line")
|
|
1310 (gud-def gud-step "s" "\C-s" "Step one source line with display.")
|
|
1311 (gud-def gud-next "n" "\C-n" "Step one line (skip functions).")
|
|
1312 (gud-def gud-cont "c" "\C-r" "Continue with display.")
|
|
1313 ; (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
|
|
1314 ; (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
|
|
1315 ; (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
|
|
1316 (gud-def gud-print "%e" "\C-p" "Evaluate perl expression at point.")
|
4729
|
1317
|
16327
|
1318 (setq comint-prompt-regexp "^ DB<+[0-9]+>+ ")
|
6997
|
1319 (setq paragraph-start comint-prompt-regexp)
|
4732
|
1320 (run-hooks 'perldb-mode-hook)
|
4729
|
1321 )
|
21336
|
1322
|
|
1323 ;; ======================================================================
|
22173
|
1324 ;; pdb (Python debugger) functions
|
|
1325
|
|
1326 ;;; History of argument lists passed to pdb.
|
|
1327 (defvar gud-pdb-history nil)
|
|
1328
|
|
1329 (defun gud-pdb-massage-args (file args)
|
|
1330 args)
|
|
1331
|
|
1332 ;; Last group is for return value, e.g. "> test.py(2)foo()->None"
|
|
1333 ;; Either file or function name may be omitted: "> <string>(0)?()"
|
|
1334 (defvar gud-pdb-marker-regexp
|
|
1335 "^> \\([-a-zA-Z0-9_/.]*\\|<string>\\)(\\([0-9]+\\))\\([a-zA-Z0-9_]*\\|\\?\\)()\\(->[^\n]*\\)?\n")
|
|
1336 (defvar gud-pdb-marker-regexp-file-group 1)
|
|
1337 (defvar gud-pdb-marker-regexp-line-group 2)
|
|
1338 (defvar gud-pdb-marker-regexp-fnname-group 3)
|
|
1339
|
|
1340 (defvar gud-pdb-marker-regexp-start "^> ")
|
|
1341
|
|
1342 ;; There's no guarantee that Emacs will hand the filter the entire
|
|
1343 ;; marker at once; it could be broken up across several strings. We
|
|
1344 ;; might even receive a big chunk with several markers in it. If we
|
|
1345 ;; receive a chunk of text which looks like it might contain the
|
|
1346 ;; beginning of a marker, we save it here between calls to the
|
|
1347 ;; filter.
|
|
1348 (defun gud-pdb-marker-filter (string)
|
|
1349 (setq gud-marker-acc (concat gud-marker-acc string))
|
|
1350 (let ((output ""))
|
|
1351
|
|
1352 ;; Process all the complete markers in this chunk.
|
|
1353 (while (string-match gud-pdb-marker-regexp gud-marker-acc)
|
|
1354 (setq
|
|
1355
|
|
1356 ;; Extract the frame position from the marker.
|
|
1357 gud-last-frame
|
|
1358 (let ((file (match-string gud-pdb-marker-regexp-file-group
|
|
1359 gud-marker-acc))
|
|
1360 (line (string-to-int
|
|
1361 (match-string gud-pdb-marker-regexp-line-group
|
|
1362 gud-marker-acc))))
|
|
1363 (if (string-equal file "<string>")
|
|
1364 gud-last-frame
|
|
1365 (cons file line)))
|
|
1366
|
|
1367 ;; Output everything instead of the below
|
|
1368 output (concat output (substring gud-marker-acc 0 (match-end 0)))
|
|
1369 ;; ;; Append any text before the marker to the output we're going
|
|
1370 ;; ;; to return - we don't include the marker in this text.
|
|
1371 ;; output (concat output
|
|
1372 ;; (substring gud-marker-acc 0 (match-beginning 0)))
|
|
1373
|
|
1374 ;; Set the accumulator to the remaining text.
|
|
1375 gud-marker-acc (substring gud-marker-acc (match-end 0))))
|
|
1376
|
|
1377 ;; Does the remaining text look like it might end with the
|
|
1378 ;; beginning of another marker? If it does, then keep it in
|
|
1379 ;; gud-marker-acc until we receive the rest of it. Since we
|
|
1380 ;; know the full marker regexp above failed, it's pretty simple to
|
|
1381 ;; test for marker starts.
|
|
1382 (if (string-match gud-pdb-marker-regexp-start gud-marker-acc)
|
|
1383 (progn
|
|
1384 ;; Everything before the potential marker start can be output.
|
|
1385 (setq output (concat output (substring gud-marker-acc
|
|
1386 0 (match-beginning 0))))
|
|
1387
|
|
1388 ;; Everything after, we save, to combine with later input.
|
|
1389 (setq gud-marker-acc
|
|
1390 (substring gud-marker-acc (match-beginning 0))))
|
|
1391
|
|
1392 (setq output (concat output gud-marker-acc)
|
|
1393 gud-marker-acc ""))
|
|
1394
|
|
1395 output))
|
|
1396
|
|
1397 (defun gud-pdb-find-file (f)
|
|
1398 (save-excursion
|
|
1399 (let ((buf (find-file-noselect f)))
|
|
1400 (set-buffer buf)
|
|
1401 (gud-make-debug-menu)
|
|
1402 ;; (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish))
|
|
1403 ;; (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
|
|
1404 ;; (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
|
|
1405 buf)))
|
|
1406
|
|
1407 (defvar pdb-minibuffer-local-map nil
|
|
1408 "Keymap for minibuffer prompting of pdb startup command.")
|
|
1409 (if pdb-minibuffer-local-map
|
|
1410 ()
|
|
1411 (setq pdb-minibuffer-local-map (copy-keymap minibuffer-local-map))
|
|
1412 (define-key
|
|
1413 pdb-minibuffer-local-map "\C-i" 'comint-dynamic-complete-filename))
|
|
1414
|
|
1415 (defcustom gud-pdb-command-name "pdb"
|
|
1416 "File name for executing the Python debugger.
|
|
1417 This should be an executable on your path, or an absolute file name."
|
|
1418 :type 'string
|
|
1419 :group 'gud)
|
|
1420
|
|
1421 ;;;###autoload
|
|
1422 (defun pdb (command-line)
|
|
1423 "Run pdb on program FILE in buffer `*gud-FILE*'.
|
|
1424 The directory containing FILE becomes the initial working directory
|
|
1425 and source-file directory for your debugger."
|
|
1426 (interactive
|
|
1427 (list (read-from-minibuffer "Run pdb (like this): "
|
|
1428 (if (consp gud-pdb-history)
|
|
1429 (car gud-pdb-history)
|
|
1430 (concat gud-pdb-command-name " "))
|
|
1431 pdb-minibuffer-local-map nil
|
25601
|
1432 'gud-pdb-history)))
|
22173
|
1433
|
|
1434 (gud-common-init command-line 'gud-pdb-massage-args
|
|
1435 'gud-pdb-marker-filter 'gud-pdb-find-file)
|
|
1436
|
|
1437 (gud-def gud-break "break %l" "\C-b" "Set breakpoint at current line.")
|
|
1438 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
|
|
1439 (gud-def gud-step "step" "\C-s" "Step one source line with display.")
|
|
1440 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
|
|
1441 (gud-def gud-cont "continue" "\C-r" "Continue with display.")
|
|
1442 (gud-def gud-finish "return" "\C-f" "Finish executing current function.")
|
|
1443 (gud-def gud-up "up" "<" "Up one stack frame.")
|
|
1444 (gud-def gud-down "down" ">" "Down one stack frame.")
|
|
1445 (gud-def gud-print "p %e" "\C-p" "Evaluate Python expression at point.")
|
|
1446 ;; Is this right?
|
|
1447 (gud-def gud-statement "! %e" "\C-e" "Execute Python statement at point.")
|
|
1448
|
|
1449 (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish))
|
|
1450 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
|
|
1451 (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
|
|
1452 ;; (setq comint-prompt-regexp "^(.*pdb[+]?) *")
|
|
1453 (setq comint-prompt-regexp "^(Pdb) *")
|
|
1454 (setq paragraph-start comint-prompt-regexp)
|
|
1455 (run-hooks 'pdb-mode-hook))
|
|
1456
|
|
1457 ;; ======================================================================
|
21336
|
1458 ;;
|
|
1459 ;; JDB support.
|
|
1460 ;;
|
|
1461 ;; AUTHOR: Derek Davies <ddavies@world.std.com>
|
|
1462 ;;
|
|
1463 ;; CREATED: Sun Feb 22 10:46:38 1998 Derek Davies.
|
|
1464 ;;
|
|
1465 ;; INVOCATION NOTES:
|
|
1466 ;;
|
|
1467 ;; You invoke jdb-mode with:
|
|
1468 ;;
|
|
1469 ;; M-x jdb <enter>
|
|
1470 ;;
|
|
1471 ;; It responds with:
|
|
1472 ;;
|
22159
|
1473 ;; Run jdb (like this): jdb
|
21336
|
1474 ;;
|
|
1475 ;; type any jdb switches followed by the name of the class you'd like to debug.
|
|
1476 ;; Supply a fully qualfied classname (these do not have the ".class" extension)
|
|
1477 ;; for the name of the class to debug (e.g. "COM.the-kind.ddavies.CoolClass").
|
|
1478 ;; See the known problems section below for restrictions when specifying jdb
|
|
1479 ;; command line switches (search forward for '-classpath').
|
|
1480 ;;
|
|
1481 ;; You should see something like the following:
|
|
1482 ;;
|
|
1483 ;; Current directory is ~/src/java/hello/
|
|
1484 ;; Initializing jdb...
|
|
1485 ;; 0xed2f6628:class(hello)
|
|
1486 ;; >
|
|
1487 ;;
|
|
1488 ;; To set an initial breakpoint try:
|
|
1489 ;;
|
|
1490 ;; > stop in hello.main
|
|
1491 ;; Breakpoint set in hello.main
|
|
1492 ;; >
|
|
1493 ;;
|
|
1494 ;; To execute the program type:
|
|
1495 ;;
|
|
1496 ;; > run
|
22159
|
1497 ;; run hello
|
21336
|
1498 ;;
|
|
1499 ;; Breakpoint hit: running ...
|
|
1500 ;; hello.main (hello:12)
|
|
1501 ;;
|
|
1502 ;; Type M-n to step over the current line and M-s to step into it. That,
|
|
1503 ;; along with the JDB 'help' command should get you started. The 'quit'
|
21437
|
1504 ;; JDB command will get out out of the debugger. There is some truly
|
|
1505 ;; pathetic JDB documentation available at:
|
|
1506 ;;
|
|
1507 ;; http://java.sun.com/products/jdk/1.1/debugging/
|
21336
|
1508 ;;
|
|
1509 ;; KNOWN PROBLEMS AND FIXME's:
|
|
1510 ;;
|
21437
|
1511 ;; Not sure what happens with inner classes ... haven't tried them.
|
21336
|
1512 ;;
|
|
1513 ;; Does not grok UNICODE id's. Only ASCII id's are supported.
|
|
1514 ;;
|
|
1515 ;; You must not put whitespace between "-classpath" and the path to
|
|
1516 ;; search for java classes even though it is required when invoking jdb
|
|
1517 ;; from the command line. See gud-jdb-massage-args for details.
|
|
1518 ;;
|
21437
|
1519 ;; If any of the source files in the directories listed in
|
|
1520 ;; gud-jdb-directories won't parse you'll have problems. Make sure
|
|
1521 ;; every file ending in ".java" in these directories parses without error.
|
|
1522 ;;
|
|
1523 ;; All the .java files in the directories in gud-jdb-directories are
|
|
1524 ;; syntactically analyzed each time gud jdb is invoked. It would be
|
|
1525 ;; nice to keep as much information as possible between runs. It would
|
|
1526 ;; be really nice to analyze the files only as neccessary (when the
|
|
1527 ;; source needs to be displayed.) I'm not sure to what extent the former
|
|
1528 ;; can be accomplished and I'm not sure the latter can be done at all
|
|
1529 ;; since I don't know of any general way to tell which .class files are
|
|
1530 ;; defined by which .java file without analyzing all the .java files.
|
|
1531 ;; If anyone knows why JavaSoft didn't put the source file names in
|
|
1532 ;; debuggable .class files please clue me in so I find something else
|
|
1533 ;; to be spiteful and bitter about.
|
|
1534 ;;
|
21336
|
1535 ;; ======================================================================
|
|
1536 ;; gud jdb variables and functions
|
|
1537
|
|
1538 ;; History of argument lists passed to jdb.
|
|
1539 (defvar gud-jdb-history nil)
|
|
1540
|
|
1541 ;; List of Java source file directories.
|
|
1542 (defvar gud-jdb-directories (list ".")
|
22159
|
1543 "*A list of directories that gud jdb should search for source code.
|
28992
|
1544 The file names should be absolute, or relative to the current
|
|
1545 directory.
|
|
1546
|
|
1547 The set of .java files residing in the directories listed are
|
|
1548 syntactically analyzed to determine the classes they define and the
|
|
1549 packages in which these classes belong. In this way gud jdb maps the
|
|
1550 package-qualified class names output by the jdb debugger to the source
|
|
1551 file from which the class originated. This allows gud mode to keep
|
|
1552 the source code display in sync with the debugging session.")
|
21336
|
1553
|
|
1554 ;; List of the java source files for this debugging session.
|
|
1555 (defvar gud-jdb-source-files nil)
|
|
1556
|
22215
|
1557 ;; Association list of fully qualified class names (package + class name) and
|
|
1558 ;; their source files.
|
|
1559 (defvar gud-jdb-class-source-alist nil)
|
|
1560
|
|
1561 ;; This is used to hold a source file during analysis.
|
|
1562 (defvar gud-jdb-analysis-buffer nil)
|
|
1563
|
21336
|
1564 ;; Return a list of java source files. PATH gives the directories in
|
|
1565 ;; which to search for files with extension EXTN. Normally EXTN is
|
|
1566 ;; given as the regular expression "\\.java$" .
|
|
1567 (defun gud-jdb-build-source-files-list (path extn)
|
28590
|
1568 (apply 'nconc (mapcar (lambda (d)
|
28614
|
1569 (when (file-directory-p d)
|
28590
|
1570 (directory-files d t extn nil)) path))))
|
21336
|
1571
|
21437
|
1572 ;; Move point past whitespace.
|
|
1573 (defun gud-jdb-skip-whitespace ()
|
|
1574 (skip-chars-forward " \n\r\t\014"))
|
|
1575
|
|
1576 ;; Move point past a "// <eol>" type of comment.
|
|
1577 (defun gud-jdb-skip-single-line-comment ()
|
|
1578 (end-of-line))
|
|
1579
|
|
1580 ;; Move point past a "/* */" or "/** */" type of comment.
|
|
1581 (defun gud-jdb-skip-traditional-or-documentation-comment ()
|
|
1582 (forward-char 2)
|
|
1583 (catch 'break
|
22159
|
1584 (while (not (eobp))
|
|
1585 (if (eq (following-char) ?*)
|
|
1586 (progn
|
|
1587 (forward-char)
|
|
1588 (if (not (eobp))
|
|
1589 (if (eq (following-char) ?/)
|
|
1590 (progn
|
|
1591 (forward-char)
|
|
1592 (throw 'break nil)))))
|
|
1593 (forward-char)))))
|
|
1594
|
21437
|
1595 ;; Move point past any number of consecutive whitespace chars and/or comments.
|
|
1596 (defun gud-jdb-skip-whitespace-and-comments ()
|
|
1597 (gud-jdb-skip-whitespace)
|
|
1598 (catch 'done
|
22159
|
1599 (while t
|
|
1600 (cond
|
|
1601 ((looking-at "//")
|
|
1602 (gud-jdb-skip-single-line-comment)
|
|
1603 (gud-jdb-skip-whitespace))
|
|
1604 ((looking-at "/\\*")
|
|
1605 (gud-jdb-skip-traditional-or-documentation-comment)
|
|
1606 (gud-jdb-skip-whitespace))
|
|
1607 (t (throw 'done nil))))))
|
21437
|
1608
|
|
1609 ;; Move point past things that are id-like. The intent is to skip regular
|
|
1610 ;; id's, such as class or interface names as well as package and interface
|
|
1611 ;; names.
|
|
1612 (defun gud-jdb-skip-id-ish-thing ()
|
|
1613 (skip-chars-forward "^ /\n\r\t\014,;{"))
|
|
1614
|
|
1615 ;; Move point past a string literal.
|
|
1616 (defun gud-jdb-skip-string-literal ()
|
|
1617 (forward-char)
|
24736
|
1618 (while (not (cond
|
|
1619 ((eq (following-char) ?\\)
|
|
1620 (forward-char))
|
|
1621 ((eq (following-char) ?\042))))
|
22159
|
1622 (forward-char))
|
21437
|
1623 (forward-char))
|
|
1624
|
|
1625 ;; Move point past a character literal.
|
|
1626 (defun gud-jdb-skip-character-literal ()
|
|
1627 (forward-char)
|
|
1628 (while
|
22159
|
1629 (progn
|
|
1630 (if (eq (following-char) ?\\)
|
|
1631 (forward-char 2))
|
|
1632 (not (eq (following-char) ?\')))
|
|
1633 (forward-char))
|
21437
|
1634 (forward-char))
|
22159
|
1635
|
21437
|
1636 ;; Move point past the following block. There may be (legal) cruft before
|
|
1637 ;; the block's opening brace. There must be a block or it's the end of life
|
|
1638 ;; in petticoat junction.
|
|
1639 (defun gud-jdb-skip-block ()
|
22159
|
1640
|
21437
|
1641 ;; Find the begining of the block.
|
|
1642 (while
|
22159
|
1643 (not (eq (following-char) ?{))
|
21437
|
1644
|
22159
|
1645 ;; Skip any constructs that can harbor literal block delimiter
|
|
1646 ;; characters and/or the delimiters for the constructs themselves.
|
|
1647 (cond
|
|
1648 ((looking-at "//")
|
|
1649 (gud-jdb-skip-single-line-comment))
|
|
1650 ((looking-at "/\\*")
|
|
1651 (gud-jdb-skip-traditional-or-documentation-comment))
|
|
1652 ((eq (following-char) ?\042)
|
|
1653 (gud-jdb-skip-string-literal))
|
|
1654 ((eq (following-char) ?\')
|
|
1655 (gud-jdb-skip-character-literal))
|
|
1656 (t (forward-char))))
|
|
1657
|
21437
|
1658 ;; Now at the begining of the block.
|
|
1659 (forward-char)
|
|
1660
|
|
1661 ;; Skip over the body of the block as well as the final brace.
|
|
1662 (let ((open-level 1))
|
22159
|
1663 (while (not (eq open-level 0))
|
|
1664 (cond
|
|
1665 ((looking-at "//")
|
|
1666 (gud-jdb-skip-single-line-comment))
|
|
1667 ((looking-at "/\\*")
|
|
1668 (gud-jdb-skip-traditional-or-documentation-comment))
|
|
1669 ((eq (following-char) ?\042)
|
|
1670 (gud-jdb-skip-string-literal))
|
|
1671 ((eq (following-char) ?\')
|
|
1672 (gud-jdb-skip-character-literal))
|
|
1673 ((eq (following-char) ?{)
|
|
1674 (setq open-level (+ open-level 1))
|
|
1675 (forward-char))
|
|
1676 ((eq (following-char) ?})
|
|
1677 (setq open-level (- open-level 1))
|
|
1678 (forward-char))
|
|
1679 (t (forward-char))))))
|
21437
|
1680
|
|
1681 ;; Find the package and class definitions in Java source file FILE. Assumes
|
|
1682 ;; that FILE contains a legal Java program. BUF is a scratch buffer used
|
|
1683 ;; to hold the source during analysis.
|
|
1684 (defun gud-jdb-analyze-source (buf file)
|
|
1685 (let ((l nil))
|
22159
|
1686 (set-buffer buf)
|
|
1687 (insert-file-contents file nil nil nil t)
|
|
1688 (goto-char 0)
|
|
1689 (catch 'abort
|
|
1690 (let ((p ""))
|
|
1691 (while (progn
|
|
1692 (gud-jdb-skip-whitespace)
|
|
1693 (not (eobp)))
|
|
1694 (cond
|
|
1695
|
|
1696 ;; Any number of semi's following a block is legal. Move point
|
|
1697 ;; past them. Note that comments and whitespace may be
|
|
1698 ;; interspersed as well.
|
|
1699 ((eq (following-char) ?\073)
|
|
1700 (forward-char))
|
21437
|
1701
|
22159
|
1702 ;; Move point past a single line comment.
|
|
1703 ((looking-at "//")
|
|
1704 (gud-jdb-skip-single-line-comment))
|
|
1705
|
|
1706 ;; Move point past a traditional or documentation comment.
|
|
1707 ((looking-at "/\\*")
|
|
1708 (gud-jdb-skip-traditional-or-documentation-comment))
|
21437
|
1709
|
22159
|
1710 ;; Move point past a package statement, but save the PackageName.
|
|
1711 ((looking-at "package")
|
|
1712 (forward-char 7)
|
|
1713 (gud-jdb-skip-whitespace-and-comments)
|
|
1714 (let ((s (point)))
|
|
1715 (gud-jdb-skip-id-ish-thing)
|
|
1716 (setq p (concat (buffer-substring s (point)) "."))
|
|
1717 (gud-jdb-skip-whitespace-and-comments)
|
|
1718 (if (eq (following-char) ?\073)
|
|
1719 (forward-char))))
|
21437
|
1720
|
22159
|
1721 ;; Move point past an import statement.
|
|
1722 ((looking-at "import")
|
|
1723 (forward-char 6)
|
|
1724 (gud-jdb-skip-whitespace-and-comments)
|
|
1725 (gud-jdb-skip-id-ish-thing)
|
|
1726 (gud-jdb-skip-whitespace-and-comments)
|
|
1727 (if (eq (following-char) ?\073)
|
|
1728 (forward-char)))
|
|
1729
|
|
1730 ;; Move point past the various kinds of ClassModifiers.
|
|
1731 ((looking-at "public")
|
|
1732 (forward-char 6))
|
|
1733 ((looking-at "abstract")
|
|
1734 (forward-char 8))
|
|
1735 ((looking-at "final")
|
|
1736 (forward-char 5))
|
21437
|
1737
|
22159
|
1738 ;; Move point past a ClassDeclaraction, but save the class
|
|
1739 ;; Identifier.
|
|
1740 ((looking-at "class")
|
|
1741 (forward-char 5)
|
|
1742 (gud-jdb-skip-whitespace-and-comments)
|
|
1743 (let ((s (point)))
|
|
1744 (gud-jdb-skip-id-ish-thing)
|
|
1745 (setq
|
|
1746 l (nconc l (list (concat p (buffer-substring s (point)))))))
|
|
1747 (gud-jdb-skip-block))
|
21437
|
1748
|
22159
|
1749 ;; Move point past an interface statement.
|
|
1750 ((looking-at "interface")
|
|
1751 (forward-char 9)
|
|
1752 (gud-jdb-skip-block))
|
|
1753
|
|
1754 ;; Anything else means the input is invalid.
|
|
1755 (t
|
|
1756 (message (format "Error parsing file %s." file))
|
|
1757 (throw 'abort nil))))))
|
|
1758 l))
|
21437
|
1759
|
|
1760 (defun gud-jdb-build-class-source-alist-for-file (file)
|
|
1761 (mapcar
|
|
1762 (lambda (c)
|
22159
|
1763 (cons c file))
|
21437
|
1764 (gud-jdb-analyze-source gud-jdb-analysis-buffer file)))
|
21336
|
1765
|
|
1766 ;; Return an alist of fully qualified classes and the source files
|
|
1767 ;; holding their definitions. SOURCES holds a list of all the source
|
|
1768 ;; files to examine.
|
|
1769 (defun gud-jdb-build-class-source-alist (sources)
|
27833
|
1770 (setq gud-jdb-analysis-buffer (get-buffer-create " *gud-jdb-scratch*"))
|
21437
|
1771 (prog1
|
22159
|
1772 (apply
|
|
1773 'nconc
|
|
1774 (mapcar
|
|
1775 'gud-jdb-build-class-source-alist-for-file
|
|
1776 sources))
|
|
1777 (kill-buffer gud-jdb-analysis-buffer)
|
|
1778 (setq gud-jdb-analysis-buffer nil)))
|
21336
|
1779
|
|
1780 ;; Change what was given in the minibuffer to something that can be used to
|
|
1781 ;; invoke the debugger.
|
|
1782 (defun gud-jdb-massage-args (file args)
|
|
1783 ;; The jdb executable must have whitespace between "-classpath" and
|
22159
|
1784 ;; its value while gud-common-init expects all switch values to
|
21336
|
1785 ;; follow the switch keyword without intervening whitespace. We
|
|
1786 ;; require that when the user enters the "-classpath" switch in the
|
|
1787 ;; EMACS minibuffer that they do so without the intervening
|
|
1788 ;; whitespace. This function adds it back (it's called after
|
|
1789 ;; gud-common-init). There are more switches like this (for
|
|
1790 ;; instance "-host" and "-password") but I don't care about them
|
|
1791 ;; yet.
|
|
1792 (if args
|
22159
|
1793 (let (massaged-args user-error)
|
|
1794
|
|
1795 (while
|
|
1796 (and args
|
|
1797 (not (string-match "-classpath\\(.+\\)" (car args)))
|
|
1798 (not (setq user-error
|
|
1799 (string-match "-classpath$" (car args)))))
|
|
1800 (setq massaged-args (append massaged-args (list (car args))))
|
|
1801 (setq args (cdr args)))
|
21336
|
1802
|
22159
|
1803 ;; By this point the current directory is all screwed up. Maybe we
|
|
1804 ;; could fix things and re-invoke gud-common-init, but for now I think
|
|
1805 ;; issueing the error is good enough.
|
|
1806 (if user-error
|
|
1807 (progn
|
|
1808 (kill-buffer (current-buffer))
|
24388
|
1809 (error "Error: Omit whitespace between '-classpath' and its value")))
|
22159
|
1810
|
|
1811 (if args
|
|
1812 (setq massaged-args
|
|
1813 (append
|
|
1814 massaged-args
|
|
1815 (list "-classpath")
|
|
1816 (list
|
|
1817 (substring
|
|
1818 (car args)
|
|
1819 (match-beginning 1) (match-end 1)))
|
|
1820 (cdr args)))
|
|
1821 massaged-args))))
|
21336
|
1822
|
|
1823 ;; Search for an association with P, a fully qualified class name, in
|
|
1824 ;; gud-jdb-class-source-alist. The asssociation gives the fully
|
|
1825 ;; qualified file name of the source file which produced the class.
|
|
1826 (defun gud-jdb-find-source-file (p)
|
|
1827 (cdr (assoc p gud-jdb-class-source-alist)))
|
|
1828
|
|
1829 ;; See comentary for other debugger's marker filters - there you will find
|
|
1830 ;; important notes about STRING.
|
|
1831 (defun gud-jdb-marker-filter (string)
|
|
1832
|
|
1833 ;; Build up the accumulator.
|
|
1834 (setq gud-marker-acc
|
22159
|
1835 (if gud-marker-acc
|
|
1836 (concat gud-marker-acc string)
|
|
1837 string))
|
21336
|
1838
|
|
1839 ;; We process STRING from left to right. Each time through the following
|
|
1840 ;; loop we process at most one marker. The start variable keeps track of
|
|
1841 ;; where we are in the input string through the iterations of this loop.
|
|
1842 (let (start file-found)
|
|
1843
|
22159
|
1844 ;; Process each complete marker in the input. There may be an incomplete
|
|
1845 ;; marker at the end of the input string. Incomplete markers are left
|
|
1846 ;; in the accumulator for processing the next time the function is called.
|
|
1847 (while
|
21336
|
1848
|
22159
|
1849 ;; Do we see a marker?
|
|
1850 (string-match
|
|
1851 ;; jdb puts out a string of the following form when it
|
|
1852 ;; hits a breakpoint:
|
|
1853 ;;
|
|
1854 ;; <fully-qualified-class><method> (<class>:<line-number>)
|
|
1855 ;;
|
|
1856 ;; <fully-qualified-class>'s are composed of Java ID's
|
|
1857 ;; separated by periods. <method> and <class> are
|
|
1858 ;; also Java ID's. <method> begins with a period and
|
|
1859 ;; may contain less-than and greater-than (constructors,
|
|
1860 ;; for instance, are called <init> in the symbol table.)
|
|
1861 ;; Java ID's begin with a letter followed by letters
|
|
1862 ;; and/or digits. The set of letters includes underscore
|
|
1863 ;; and dollar sign.
|
|
1864 ;;
|
|
1865 ;; The first group matches <fully-qualified-class>,
|
|
1866 ;; the second group matches <class> and the third group
|
|
1867 ;; matches <line-number>. We don't care about using
|
|
1868 ;; <method> so we don't "group" it.
|
|
1869 ;;
|
|
1870 ;; FIXME: Java ID's are UNICODE strings, this matches ASCII
|
|
1871 ;; ID's only.
|
|
1872 "\\([a-zA-Z0-9.$_]+\\)\\.[a-zA-Z0-9$_<>]+ (\\([a-zA-Z0-9$_]+\\):\\([0-9]+\\))"
|
|
1873 gud-marker-acc start)
|
|
1874
|
|
1875 ;; Figure out the line on which to position the debugging arrow.
|
|
1876 ;; Return the info as a cons of the form:
|
|
1877 ;;
|
|
1878 ;; (<file-name> . <line-number>) .
|
|
1879 (if (setq
|
|
1880 file-found
|
|
1881 (gud-jdb-find-source-file
|
|
1882 (substring gud-marker-acc
|
|
1883 (match-beginning 1)
|
|
1884 (match-end 1))))
|
|
1885 (setq gud-last-frame
|
|
1886 (cons
|
|
1887 file-found
|
|
1888 (string-to-int
|
|
1889 (substring gud-marker-acc
|
|
1890 (match-beginning 3)
|
|
1891 (match-end 3)))))
|
|
1892 (message "Could not find source file."))
|
|
1893
|
|
1894 ;; Set start after the last character of STRING that we've looked at
|
|
1895 ;; and loop to look for another marker.
|
|
1896 (setq start (match-end 0))))
|
21336
|
1897
|
|
1898 ;; We don't filter any debugger output so just return what we were given.
|
|
1899 string)
|
|
1900
|
|
1901 (defun gud-jdb-find-file (f)
|
|
1902 (and (file-readable-p f)
|
22159
|
1903 (find-file-noselect f)))
|
21336
|
1904
|
|
1905 (defvar gud-jdb-command-name "jdb" "Command that executes the Java debugger.")
|
|
1906
|
|
1907 ;;;###autoload
|
|
1908 (defun jdb (command-line)
|
22159
|
1909 "Run jdb with command line COMMAND-LINE in a buffer. The buffer is named
|
|
1910 \"*gud*\" if no initial class is given or \"*gud-<initial-class-basename>*\"
|
|
1911 if there is. If the \"-classpath\" switch is given, omit all whitespace
|
21336
|
1912 between it and it's value."
|
|
1913 (interactive
|
|
1914 (list (read-from-minibuffer "Run jdb (like this): "
|
22159
|
1915 (if (consp gud-jdb-history)
|
21336
|
1916 (car gud-jdb-history)
|
|
1917 (concat gud-jdb-command-name " "))
|
22159
|
1918 nil nil
|
25601
|
1919 'gud-jdb-history)))
|
21336
|
1920
|
|
1921 (gud-common-init command-line 'gud-jdb-massage-args
|
|
1922 'gud-jdb-marker-filter 'gud-jdb-find-file)
|
|
1923
|
24736
|
1924 (gud-def gud-break "stop at %F:%l" "\C-b" "Set breakpoint at current line.")
|
21336
|
1925 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
|
|
1926 (gud-def gud-step "step" "\C-s" "Step one source line with display.")
|
|
1927 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
|
|
1928 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
|
|
1929
|
24302
|
1930 (setq comint-prompt-regexp "^> \\|^.+\\[[0-9]+\\] ")
|
21336
|
1931 (setq paragraph-start comint-prompt-regexp)
|
|
1932 (run-hooks 'jdb-mode-hook)
|
|
1933
|
|
1934 ;; Create and bind the class/source association list as well as the source
|
|
1935 ;; file list.
|
|
1936 (setq
|
|
1937 gud-jdb-class-source-alist
|
|
1938 (gud-jdb-build-class-source-alist
|
22159
|
1939 (setq
|
|
1940 gud-jdb-source-files
|
|
1941 (gud-jdb-build-source-files-list gud-jdb-directories "\\.java$")))))
|
21336
|
1942
|
3738
|
1943
|
460
|
1944 ;;
|
|
1945 ;; End of debugger-specific information
|
477
|
1946 ;;
|
460
|
1947
|
4729
|
1948
|
1256
|
1949 ;;; When we send a command to the debugger via gud-call, it's annoying
|
|
1950 ;;; to see the command and the new prompt inserted into the debugger's
|
|
1951 ;;; buffer; we have other ways of knowing the command has completed.
|
|
1952 ;;;
|
|
1953 ;;; If the buffer looks like this:
|
|
1954 ;;; --------------------
|
|
1955 ;;; (gdb) set args foo bar
|
|
1956 ;;; (gdb) -!-
|
|
1957 ;;; --------------------
|
|
1958 ;;; (the -!- marks the location of point), and we type `C-x SPC' in a
|
|
1959 ;;; source file to set a breakpoint, we want the buffer to end up like
|
|
1960 ;;; this:
|
|
1961 ;;; --------------------
|
|
1962 ;;; (gdb) set args foo bar
|
|
1963 ;;; Breakpoint 1 at 0x92: file make-docfile.c, line 49.
|
|
1964 ;;; (gdb) -!-
|
|
1965 ;;; --------------------
|
|
1966 ;;; Essentially, the old prompt is deleted, and the command's output
|
|
1967 ;;; and the new prompt take its place.
|
|
1968 ;;;
|
|
1969 ;;; Not echoing the command is easy enough; you send it directly using
|
|
1970 ;;; process-send-string, and it never enters the buffer. However,
|
|
1971 ;;; getting rid of the old prompt is trickier; you don't want to do it
|
|
1972 ;;; when you send the command, since that will result in an annoying
|
|
1973 ;;; flicker as the prompt is deleted, redisplay occurs while Emacs
|
|
1974 ;;; waits for a response from the debugger, and the new prompt is
|
|
1975 ;;; inserted. Instead, we'll wait until we actually get some output
|
|
1976 ;;; from the subprocess before we delete the prompt. If the command
|
|
1977 ;;; produced no output other than a new prompt, that prompt will most
|
|
1978 ;;; likely be in the first chunk of output received, so we will delete
|
|
1979 ;;; the prompt and then replace it with an identical one. If the
|
|
1980 ;;; command produces output, the prompt is moving anyway, so the
|
|
1981 ;;; flicker won't be annoying.
|
|
1982 ;;;
|
|
1983 ;;; So - when we want to delete the prompt upon receipt of the next
|
|
1984 ;;; chunk of debugger output, we position gud-delete-prompt-marker at
|
|
1985 ;;; the start of the prompt; the process filter will notice this, and
|
|
1986 ;;; delete all text between it and the process output marker. If
|
|
1987 ;;; gud-delete-prompt-marker points nowhere, we leave the current
|
|
1988 ;;; prompt alone.
|
|
1989 (defvar gud-delete-prompt-marker nil)
|
|
1990
|
460
|
1991
|
17658
|
1992 (put 'gud-mode 'mode-class 'special)
|
|
1993
|
460
|
1994 (defun gud-mode ()
|
|
1995 "Major mode for interacting with an inferior debugger process.
|
868
|
1996
|
3738
|
1997 You start it up with one of the commands M-x gdb, M-x sdb, M-x dbx,
|
14934
|
1998 M-x perldb, or M-x xdb. Each entry point finishes by executing a
|
|
1999 hook; `gdb-mode-hook', `sdb-mode-hook', `dbx-mode-hook',
|
|
2000 `perldb-mode-hook', or `xdb-mode-hook' respectively.
|
868
|
2001
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2002 After startup, the following commands are available in both the GUD
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2003 interaction buffer and any source buffer GUD visits due to a breakpoint stop
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2004 or step operation:
|
460
|
2005
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2006 \\[gud-break] sets a breakpoint at the current file and line. In the
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2007 GUD buffer, the current file and line are those of the last breakpoint or
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2008 step. In a source buffer, they are the buffer's file and current line.
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2009
|
2532
17a6b6d079cf
(gud-mode): Created C-c synonym bindings in the GUD buffer's local map.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2010 \\[gud-remove] removes breakpoints on the current file and line.
|
17a6b6d079cf
(gud-mode): Created C-c synonym bindings in the GUD buffer's local map.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2011
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2012 \\[gud-refresh] displays in the source window the last line referred to
|
868
|
2013 in the gud buffer.
|
460
|
2014
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2015 \\[gud-step], \\[gud-next], and \\[gud-stepi] do a step-one-line,
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2016 step-one-line (not entering function calls), and step-one-instruction
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2017 and then update the source window with the current file and position.
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2018 \\[gud-cont] continues execution.
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2019
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2020 \\[gud-print] tries to find the largest C lvalue or function-call expression
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2021 around point, and sends it to the debugger for value display.
|
460
|
2022
|
3738
|
2023 The above commands are common to all supported debuggers except xdb which
|
|
2024 does not support stepping instructions.
|
868
|
2025
|
3738
|
2026 Under gdb, sdb and xdb, \\[gud-tbreak] behaves exactly like \\[gud-break],
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2027 except that the breakpoint is temporary; that is, it is removed when
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2028 execution stops on it.
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2029
|
3738
|
2030 Under gdb, dbx, and xdb, \\[gud-up] pops up through an enclosing stack
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2031 frame. \\[gud-down] drops back down through one.
|
868
|
2032
|
3738
|
2033 If you are using gdb or xdb, \\[gud-finish] runs execution to the return from
|
868
|
2034 the current function and stops.
|
|
2035
|
3551
|
2036 All the keystrokes above are accessible in the GUD buffer
|
|
2037 with the prefix C-c, and in all buffers through the prefix C-x C-a.
|
2532
17a6b6d079cf
(gud-mode): Created C-c synonym bindings in the GUD buffer's local map.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2038
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2039 All pre-defined functions for which the concept make sense repeat
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2040 themselves the appropriate number of times if you give a prefix
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2041 argument.
|
868
|
2042
|
3551
|
2043 You may use the `gud-def' macro in the initialization hook to define other
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2044 commands.
|
868
|
2045
|
|
2046 Other commands for interacting with the debugger process are inherited from
|
|
2047 comint mode, which see."
|
460
|
2048 (interactive)
|
|
2049 (comint-mode)
|
|
2050 (setq major-mode 'gud-mode)
|
|
2051 (setq mode-name "Debugger")
|
7074
|
2052 (setq mode-line-process '(":%s"))
|
12002
|
2053 (use-local-map comint-mode-map)
|
|
2054 (gud-make-debug-menu)
|
5997
|
2055 (define-key (current-local-map) "\C-c\C-l" 'gud-refresh)
|
460
|
2056 (make-local-variable 'gud-last-frame)
|
|
2057 (setq gud-last-frame nil)
|
|
2058 (make-local-variable 'comint-prompt-regexp)
|
16327
|
2059 ;; Don't put repeated commands in command history many times.
|
|
2060 (make-local-variable 'comint-input-ignoredups)
|
|
2061 (setq comint-input-ignoredups t)
|
6997
|
2062 (make-local-variable 'paragraph-start)
|
1256
|
2063 (make-local-variable 'gud-delete-prompt-marker)
|
|
2064 (setq gud-delete-prompt-marker (make-marker))
|
9190
|
2065 (run-hooks 'gud-mode-hook))
|
460
|
2066
|
4092
|
2067 ;; Chop STRING into words separated by SPC or TAB and return a list of them.
|
|
2068 (defun gud-chop-words (string)
|
|
2069 (let ((i 0) (beg 0)
|
|
2070 (len (length string))
|
|
2071 (words nil))
|
|
2072 (while (< i len)
|
|
2073 (if (memq (aref string i) '(?\t ? ))
|
|
2074 (progn
|
|
2075 (setq words (cons (substring string beg i) words)
|
|
2076 beg (1+ i))
|
|
2077 (while (and (< beg len) (memq (aref string beg) '(?\t ? )))
|
|
2078 (setq beg (1+ beg)))
|
|
2079 (setq i (1+ beg)))
|
|
2080 (setq i (1+ i))))
|
|
2081 (if (< beg len)
|
|
2082 (setq words (cons (substring string beg) words)))
|
|
2083 (nreverse words)))
|
|
2084
|
23735
|
2085 ;; Cause our buffers to be displayed, by default,
|
|
2086 ;; in the selected window.
|
|
2087 ;;;###autoload (add-hook 'same-window-regexps "\\*gud-.*\\*\\(\\|<[0-9]+>\\)")
|
|
2088
|
4092
|
2089 ;; Perform initializations common to all debuggers.
|
9190
|
2090 ;; The first arg is the specified command line,
|
|
2091 ;; which starts with the program to debug.
|
|
2092 ;; The other three args specify the values to use
|
|
2093 ;; for local variables in the debugger buffer.
|
|
2094 (defun gud-common-init (command-line massage-args marker-filter find-file)
|
4092
|
2095 (let* ((words (gud-chop-words command-line))
|
|
2096 (program (car words))
|
10876
|
2097 ;; Extract the file name from WORDS
|
|
2098 ;; and put t in its place.
|
|
2099 ;; Later on we will put the modified file name arg back there.
|
4092
|
2100 (file-word (let ((w (cdr words)))
|
|
2101 (while (and w (= ?- (aref (car w) 0)))
|
|
2102 (setq w (cdr w)))
|
11930
|
2103 (and w
|
|
2104 (prog1 (car w)
|
|
2105 (setcar w t)))))
|
9743
|
2106 (file-subst
|
|
2107 (and file-word (substitute-in-file-name file-word)))
|
10876
|
2108 (args (cdr words))
|
9743
|
2109 ;; If a directory was specified, expand the file name.
|
|
2110 ;; Otherwise, don't expand it, so GDB can use the PATH.
|
|
2111 ;; A file name without directory is literally valid
|
|
2112 ;; only if the file exists in ., and in that case,
|
|
2113 ;; omitting the expansion here has no visible effect.
|
5508
|
2114 (file (and file-word
|
9743
|
2115 (if (file-name-directory file-subst)
|
|
2116 (expand-file-name file-subst)
|
|
2117 file-subst)))
|
11930
|
2118 (filepart (and file-word (concat "-" (file-name-nondirectory file)))))
|
23735
|
2119 (pop-to-buffer (concat "*gud" filepart "*"))
|
9743
|
2120 ;; Set default-directory to the file's directory.
|
|
2121 (and file-word
|
|
2122 ;; Don't set default-directory if no directory was specified.
|
|
2123 ;; In that case, either the file is found in the current directory,
|
|
2124 ;; in which case this setq is a no-op,
|
|
2125 ;; or it is found by searching PATH,
|
|
2126 ;; in which case we don't know what directory it was found in.
|
|
2127 (file-name-directory file)
|
|
2128 (setq default-directory (file-name-directory file)))
|
9190
|
2129 (or (bolp) (newline))
|
|
2130 (insert "Current directory is " default-directory "\n")
|
10876
|
2131 ;; Put the substituted and expanded file name back in its place.
|
|
2132 (let ((w args))
|
|
2133 (while (and w (not (eq (car w) t)))
|
|
2134 (setq w (cdr w)))
|
11930
|
2135 (if w
|
|
2136 (setcar w file)))
|
|
2137 (apply 'make-comint (concat "gud" filepart) program nil
|
12116
1df1abcd466f
(gud-common-init): Call the MASSAGE-ARGS function even if FILE is nil.
Roland McGrath <roland@gnu.org>
diff
changeset
|
2138 (funcall massage-args file args)))
|
9190
|
2139 ;; Since comint clobbered the mode, we don't set it until now.
|
460
|
2140 (gud-mode)
|
9190
|
2141 (make-local-variable 'gud-marker-filter)
|
|
2142 (setq gud-marker-filter marker-filter)
|
|
2143 (make-local-variable 'gud-find-file)
|
|
2144 (setq gud-find-file find-file)
|
|
2145
|
460
|
2146 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter)
|
|
2147 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel)
|
|
2148 (gud-set-buffer)
|
|
2149 )
|
|
2150
|
|
2151 (defun gud-set-buffer ()
|
|
2152 (cond ((eq major-mode 'gud-mode)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2153 (setq gud-comint-buffer (current-buffer)))))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2154
|
13003
4711396531e8
(gud-filter): Save up text that arrives while processing previous text.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2155 (defvar gud-filter-defer-flag nil
|
4711396531e8
(gud-filter): Save up text that arrives while processing previous text.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2156 "Non-nil means don't process anything from the debugger right now.
|
4711396531e8
(gud-filter): Save up text that arrives while processing previous text.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2157 It is saved for when this flag is not set.")
|
4711396531e8
(gud-filter): Save up text that arrives while processing previous text.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2158
|
4711396531e8
(gud-filter): Save up text that arrives while processing previous text.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2159 (defvar gud-filter-pending-text nil
|
4711396531e8
(gud-filter): Save up text that arrives while processing previous text.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2160 "Non-nil means this is text that has been saved for later in `gud-filter'.")
|
4711396531e8
(gud-filter): Save up text that arrives while processing previous text.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2161
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2162 ;; These functions are responsible for inserting output from your debugger
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2163 ;; into the buffer. The hard work is done by the method that is
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2164 ;; the value of gud-marker-filter.
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2165
|
460
|
2166 (defun gud-filter (proc string)
|
|
2167 ;; Here's where the actual buffer insertion is done
|
13190
|
2168 (let (output process-window)
|
9519
|
2169 (if (buffer-name (process-buffer proc))
|
13003
4711396531e8
(gud-filter): Save up text that arrives while processing previous text.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2170 (if gud-filter-defer-flag
|
4711396531e8
(gud-filter): Save up text that arrives while processing previous text.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2171 ;; If we can't process any text now,
|
4711396531e8
(gud-filter): Save up text that arrives while processing previous text.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2172 ;; save it for later.
|
4711396531e8
(gud-filter): Save up text that arrives while processing previous text.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2173 (setq gud-filter-pending-text
|
4711396531e8
(gud-filter): Save up text that arrives while processing previous text.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2174 (concat (or gud-filter-pending-text "") string))
|
15185
|
2175
|
|
2176 ;; If we have to ask a question during the processing,
|
|
2177 ;; defer any additional text that comes from the debugger
|
|
2178 ;; during that time.
|
|
2179 (let ((gud-filter-defer-flag t))
|
|
2180 ;; Process now any text we previously saved up.
|
|
2181 (if gud-filter-pending-text
|
|
2182 (setq string (concat gud-filter-pending-text string)
|
|
2183 gud-filter-pending-text nil))
|
30736
48d749ce74e4
(gud-filter): Use `with-current-buffer' instead of save-excursion when
Miles Bader <miles@gnu.org>
diff
changeset
|
2184
|
48d749ce74e4
(gud-filter): Use `with-current-buffer' instead of save-excursion when
Miles Bader <miles@gnu.org>
diff
changeset
|
2185 (with-current-buffer (process-buffer proc)
|
13003
4711396531e8
(gud-filter): Save up text that arrives while processing previous text.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2186 ;; If we have been so requested, delete the debugger prompt.
|
30959
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2187 (save-restriction
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2188 (widen)
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2189 (if (marker-buffer gud-delete-prompt-marker)
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2190 (progn
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2191 (delete-region (process-mark proc)
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2192 gud-delete-prompt-marker)
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2193 (set-marker gud-delete-prompt-marker nil)))
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2194 ;; Save the process output, checking for source file markers.
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2195 (setq output (gud-marker-filter string))
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2196 ;; Check for a filename-and-line number.
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2197 ;; Don't display the specified file
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2198 ;; unless (1) point is at or after the position where output appears
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2199 ;; and (2) this buffer is on the screen.
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2200 (setq process-window
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2201 (and gud-last-frame
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2202 (>= (point) (process-mark proc))
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2203 (get-buffer-window (current-buffer)))))
|
15185
|
2204
|
|
2205 ;; Let the comint filter do the actual insertion.
|
|
2206 ;; That lets us inherit various comint features.
|
22446
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2207 (comint-output-filter proc output))
|
13190
|
2208
|
22446
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2209 ;; Put the arrow on the source line.
|
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2210 ;; This must be outside of the save-excursion
|
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2211 ;; in case the source file is our current buffer.
|
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2212 (if process-window
|
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2213 (save-selected-window
|
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2214 (select-window process-window)
|
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2215 (gud-display-frame))
|
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2216 ;; We have to be in the proper buffer, (process-buffer proc),
|
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2217 ;; but not in a save-excursion, because that would restore point.
|
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2218 (let ((old-buf (current-buffer)))
|
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2219 (set-buffer (process-buffer proc))
|
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2220 (unwind-protect
|
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2221 (gud-display-frame)
|
5988c3c973db
(gud-filter): extend scope of binding of gud-filter-defer-flag.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2222 (set-buffer old-buf)))))
|
13190
|
2223
|
15185
|
2224 ;; If we deferred text that arrived during this processing,
|
|
2225 ;; handle it now.
|
|
2226 (if gud-filter-pending-text
|
|
2227 (gud-filter proc ""))))))
|
460
|
2228
|
|
2229 (defun gud-sentinel (proc msg)
|
|
2230 (cond ((null (buffer-name (process-buffer proc)))
|
|
2231 ;; buffer killed
|
|
2232 ;; Stop displaying an arrow in a source file.
|
|
2233 (setq overlay-arrow-position nil)
|
|
2234 (set-process-buffer proc nil))
|
|
2235 ((memq (process-status proc) '(signal exit))
|
|
2236 ;; Stop displaying an arrow in a source file.
|
|
2237 (setq overlay-arrow-position nil)
|
|
2238 (let* ((obuf (current-buffer)))
|
|
2239 ;; save-excursion isn't the right thing if
|
|
2240 ;; process-buffer is current-buffer
|
|
2241 (unwind-protect
|
|
2242 (progn
|
|
2243 ;; Write something in *compilation* and hack its mode line,
|
|
2244 (set-buffer (process-buffer proc))
|
20296
|
2245 ;; Fix the mode line.
|
|
2246 (setq mode-line-process
|
|
2247 (concat ":"
|
|
2248 (symbol-name (process-status proc))))
|
11583
|
2249 (force-mode-line-update)
|
460
|
2250 (if (eobp)
|
|
2251 (insert ?\n mode-name " " msg)
|
|
2252 (save-excursion
|
|
2253 (goto-char (point-max))
|
|
2254 (insert ?\n mode-name " " msg)))
|
|
2255 ;; If buffer and mode line will show that the process
|
|
2256 ;; is dead, we can delete it now. Otherwise it
|
|
2257 ;; will stay around until M-x list-processes.
|
|
2258 (delete-process proc))
|
|
2259 ;; Restore old buffer, but don't restore old point
|
|
2260 ;; if obuf is the gud buffer.
|
|
2261 (set-buffer obuf))))))
|
|
2262
|
|
2263 (defun gud-display-frame ()
|
|
2264 "Find and obey the last filename-and-line marker from the debugger.
|
|
2265 Obeying it means displaying in another window the specified file and line."
|
|
2266 (interactive)
|
|
2267 (if gud-last-frame
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2268 (progn
|
460
|
2269 (gud-set-buffer)
|
|
2270 (gud-display-line (car gud-last-frame) (cdr gud-last-frame))
|
3646
|
2271 (setq gud-last-last-frame gud-last-frame
|
|
2272 gud-last-frame nil))))
|
460
|
2273
|
|
2274 ;; Make sure the file named TRUE-FILE is in a buffer that appears on the screen
|
|
2275 ;; and that its line LINE is visible.
|
|
2276 ;; Put the overlay-arrow on the line LINE in that buffer.
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2277 ;; Most of the trickiness in here comes from wanting to preserve the current
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2278 ;; region-restriction if that's possible. We use an explicit display-buffer
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2279 ;; to get around the fact that this is called inside a save-excursion.
|
460
|
2280
|
|
2281 (defun gud-display-line (true-file line)
|
7910
|
2282 (let* ((last-nonmenu-event t) ; Prevent use of dialog box for questions.
|
15127
654bc3990b4d
(gud-display-line): Switch to gud buffer before calling gud-find-file.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2283 (buffer
|
654bc3990b4d
(gud-display-line): Switch to gud buffer before calling gud-find-file.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2284 (save-excursion
|
654bc3990b4d
(gud-display-line): Switch to gud buffer before calling gud-find-file.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2285 (or (eq (current-buffer) gud-comint-buffer)
|
654bc3990b4d
(gud-display-line): Switch to gud buffer before calling gud-find-file.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2286 (set-buffer gud-comint-buffer))
|
654bc3990b4d
(gud-display-line): Switch to gud buffer before calling gud-find-file.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2287 (gud-find-file true-file)))
|
16250
|
2288 (window (and buffer (or (get-buffer-window buffer)
|
|
2289 (display-buffer buffer))))
|
460
|
2290 (pos))
|
15796
|
2291 (if buffer
|
|
2292 (progn
|
|
2293 (save-excursion
|
|
2294 (set-buffer buffer)
|
|
2295 (save-restriction
|
|
2296 (widen)
|
|
2297 (goto-line line)
|
|
2298 (setq pos (point))
|
|
2299 (setq overlay-arrow-string "=>")
|
|
2300 (or overlay-arrow-position
|
|
2301 (setq overlay-arrow-position (make-marker)))
|
|
2302 (set-marker overlay-arrow-position (point) (current-buffer)))
|
|
2303 (cond ((or (< pos (point-min)) (> pos (point-max)))
|
|
2304 (widen)
|
|
2305 (goto-char pos))))
|
|
2306 (set-window-point window overlay-arrow-position)))))
|
1256
|
2307
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2308 ;;; The gud-call function must do the right thing whether its invoking
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2309 ;;; keystroke is from the GUD buffer itself (via major-mode binding)
|
2581
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2310 ;;; or a C buffer. In the former case, we want to supply data from
|
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2311 ;;; gud-last-frame. Here's how we do it:
|
460
|
2312
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2313 (defun gud-format-command (str arg)
|
5264
|
2314 (let ((insource (not (eq (current-buffer) gud-comint-buffer)))
|
|
2315 (frame (or gud-last-frame gud-last-last-frame))
|
|
2316 result)
|
|
2317 (while (and str (string-match "\\([^%]*\\)%\\([adeflp]\\)" str))
|
|
2318 (let ((key (string-to-char (substring str (match-beginning 2))))
|
|
2319 subst)
|
|
2320 (cond
|
|
2321 ((eq key ?f)
|
|
2322 (setq subst (file-name-nondirectory (if insource
|
|
2323 (buffer-file-name)
|
|
2324 (car frame)))))
|
24736
|
2325 ((eq key ?F)
|
|
2326 (setq subst (file-name-sans-extension
|
|
2327 (file-name-nondirectory (if insource
|
|
2328 (buffer-file-name)
|
|
2329 (car frame))))))
|
5264
|
2330 ((eq key ?d)
|
|
2331 (setq subst (file-name-directory (if insource
|
4344
|
2332 (buffer-file-name)
|
5264
|
2333 (car frame)))))
|
|
2334 ((eq key ?l)
|
|
2335 (setq subst (if insource
|
|
2336 (save-excursion
|
|
2337 (beginning-of-line)
|
27833
|
2338 (save-restriction
|
|
2339 (widen)
|
|
2340 (int-to-string (1+ (count-lines 1 (point))))))
|
5264
|
2341 (cdr frame))))
|
|
2342 ((eq key ?e)
|
16185
|
2343 (setq subst (gud-find-c-expr)))
|
5264
|
2344 ((eq key ?a)
|
|
2345 (setq subst (gud-read-address)))
|
|
2346 ((eq key ?p)
|
27833
|
2347 (setq subst (if arg (int-to-string arg)))))
|
|
2348 (setq result (concat result (match-string 1 str) subst)))
|
5264
|
2349 (setq str (substring str (match-end 2))))
|
|
2350 ;; There might be text left in STR when the loop ends.
|
|
2351 (concat result str)))
|
460
|
2352
|
1255
|
2353 (defun gud-read-address ()
|
460
|
2354 "Return a string containing the core-address found in the buffer at point."
|
|
2355 (save-excursion
|
1255
|
2356 (let ((pt (point)) found begin)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2357 (setq found (if (search-backward "0x" (- pt 7) t) (point)))
|
1255
|
2358 (cond
|
|
2359 (found (forward-char 2)
|
|
2360 (buffer-substring found
|
|
2361 (progn (re-search-forward "[^0-9a-f]")
|
|
2362 (forward-char -1)
|
|
2363 (point))))
|
22159
|
2364 (t (setq begin (progn (re-search-backward "[^0-9]")
|
1255
|
2365 (forward-char 1)
|
|
2366 (point)))
|
|
2367 (forward-char 1)
|
|
2368 (re-search-forward "[^0-9]")
|
|
2369 (forward-char -1)
|
|
2370 (buffer-substring begin (point)))))))
|
460
|
2371
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2372 (defun gud-call (fmt &optional arg)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2373 (let ((msg (gud-format-command fmt arg)))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2374 (message "Command: %s" msg)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2375 (sit-for 0)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2376 (gud-basic-call msg)))
|
460
|
2377
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2378 (defun gud-basic-call (command)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2379 "Invoke the debugger COMMAND displaying source in other window."
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2380 (interactive)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2381 (gud-set-buffer)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2382 (let ((command (concat command "\n"))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2383 (proc (get-buffer-process gud-comint-buffer)))
|
10095
|
2384 (or proc (error "Current buffer has no process"))
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2385 ;; Arrange for the current prompt to get deleted.
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2386 (save-excursion
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2387 (set-buffer gud-comint-buffer)
|
30959
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2388 (save-restriction
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2389 (widen)
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2390 (goto-char (process-mark proc))
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2391 (forward-line 0)
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2392 (if (looking-at comint-prompt-regexp)
|
d55632c1102b
(gud-basic-call): Temporarily widen gud comint buffer while checking for
Miles Bader <miles@gnu.org>
diff
changeset
|
2393 (set-marker gud-delete-prompt-marker (point)))))
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2394 (process-send-string proc command)))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2395
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2396 (defun gud-refresh (&optional arg)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2397 "Fix up a possibly garbled display, and redraw the arrow."
|
460
|
2398 (interactive "P")
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2399 (recenter arg)
|
3646
|
2400 (or gud-last-frame (setq gud-last-frame gud-last-last-frame))
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2401 (gud-display-frame))
|
3551
|
2402
|
16405
|
2403
|
|
2404 (defun gud-new-keymap (map)
|
|
2405 "Return a new keymap which inherits from MAP and has name `Gud'."
|
|
2406 (nconc (make-sparse-keymap "Gud") map))
|
|
2407
|
|
2408 (defun gud-make-debug-menu ()
|
|
2409 "Make sure the current local map has a [menu-bar debug] submap.
|
|
2410 If it doesn't, replace it with a new map that inherits it,
|
|
2411 and create such a submap in that new map."
|
25601
|
2412 (use-local-map (gud-new-keymap (current-local-map)))
|
|
2413 (define-key (current-local-map) [menu-bar]
|
|
2414 (gud-new-keymap (lookup-key (current-local-map) [menu-bar])))
|
|
2415 (define-key (current-local-map) [menu-bar debug]
|
|
2416 (cons "Gud" (gud-new-keymap gud-menu-map))))
|
16405
|
2417
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2418 ;;; Code for parsing expressions out of C code. The single entry point is
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2419 ;;; find-c-expr, which tries to return an lvalue expression from around point.
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2420 ;;;
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2421 ;;; The rest of this file is a hacked version of gdbsrc.el by
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2422 ;;; Debby Ayers <ayers@asc.slb.com>,
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2423 ;;; Rich Schaefer <schaefer@asc.slb.com> Schlumberger, Austin, Tx.
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2424
|
16185
|
2425 (defun gud-find-c-expr ()
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2426 "Returns the C expr that surrounds point."
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2427 (interactive)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2428 (save-excursion
|
16185
|
2429 (let (p expr test-expr)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2430 (setq p (point))
|
16185
|
2431 (setq expr (gud-innermost-expr))
|
|
2432 (setq test-expr (gud-prev-expr))
|
|
2433 (while (and test-expr (gud-expr-compound test-expr expr))
|
|
2434 (let ((prev-expr expr))
|
|
2435 (setq expr (cons (car test-expr) (cdr expr)))
|
|
2436 (goto-char (car expr))
|
|
2437 (setq test-expr (gud-prev-expr))
|
|
2438 ;; If we just pasted on the condition of an if or while,
|
|
2439 ;; throw it away again.
|
|
2440 (if (member (buffer-substring (car test-expr) (cdr test-expr))
|
|
2441 '("if" "while" "for"))
|
|
2442 (setq test-expr nil
|
|
2443 expr prev-expr))))
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2444 (goto-char p)
|
16185
|
2445 (setq test-expr (gud-next-expr))
|
|
2446 (while (gud-expr-compound expr test-expr)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2447 (setq expr (cons (car expr) (cdr test-expr)))
|
16185
|
2448 (setq test-expr (gud-next-expr))
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2449 )
|
3551
|
2450 (buffer-substring (car expr) (cdr expr)))))
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2451
|
16185
|
2452 (defun gud-innermost-expr ()
|
|
2453 "Returns the smallest expr that point is in; move point to beginning of it.
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2454 The expr is represented as a cons cell, where the car specifies the point in
|
22159
|
2455 the current buffer that marks the beginning of the expr and the cdr specifies
|
3551
|
2456 the character after the end of the expr."
|
16185
|
2457 (let ((p (point)) begin end)
|
|
2458 (gud-backward-sexp)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2459 (setq begin (point))
|
16185
|
2460 (gud-forward-sexp)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2461 (setq end (point))
|
22159
|
2462 (if (>= p end)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2463 (progn
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2464 (setq begin p)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2465 (goto-char p)
|
16185
|
2466 (gud-forward-sexp)
|
|
2467 (setq end (point)))
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2468 )
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2469 (goto-char begin)
|
3551
|
2470 (cons begin end)))
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2471
|
16185
|
2472 (defun gud-backward-sexp ()
|
3551
|
2473 "Version of `backward-sexp' that catches errors."
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2474 (condition-case nil
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2475 (backward-sexp)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2476 (error t)))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2477
|
16185
|
2478 (defun gud-forward-sexp ()
|
3551
|
2479 "Version of `forward-sexp' that catches errors."
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2480 (condition-case nil
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2481 (forward-sexp)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2482 (error t)))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2483
|
16185
|
2484 (defun gud-prev-expr ()
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2485 "Returns the previous expr, point is set to beginning of that expr.
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2486 The expr is represented as a cons cell, where the car specifies the point in
|
22159
|
2487 the current buffer that marks the beginning of the expr and the cdr specifies
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2488 the character after the end of the expr"
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2489 (let ((begin) (end))
|
16185
|
2490 (gud-backward-sexp)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2491 (setq begin (point))
|
16185
|
2492 (gud-forward-sexp)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2493 (setq end (point))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2494 (goto-char begin)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2495 (cons begin end)))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2496
|
16185
|
2497 (defun gud-next-expr ()
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2498 "Returns the following expr, point is set to beginning of that expr.
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2499 The expr is represented as a cons cell, where the car specifies the point in
|
22159
|
2500 the current buffer that marks the beginning of the expr and the cdr specifies
|
3551
|
2501 the character after the end of the expr."
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2502 (let ((begin) (end))
|
16185
|
2503 (gud-forward-sexp)
|
|
2504 (gud-forward-sexp)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2505 (setq end (point))
|
16185
|
2506 (gud-backward-sexp)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2507 (setq begin (point))
|
3551
|
2508 (cons begin end)))
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2509
|
16185
|
2510 (defun gud-expr-compound-sep (span-start span-end)
|
|
2511 "Scan from SPAN-START to SPAN-END for punctuation characters.
|
|
2512 If `->' is found, return `?.'. If `.' is found, return `?.'.
|
|
2513 If any other punctuation is found, return `??'.
|
|
2514 If no punctuation is found, return `? '."
|
|
2515 (let ((result ?\ )
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2516 (syntax))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2517 (while (< span-start span-end)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2518 (setq syntax (char-syntax (char-after span-start)))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2519 (cond
|
16185
|
2520 ((= syntax ?\ ) t)
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2521 ((= syntax ?.) (setq syntax (char-after span-start))
|
22159
|
2522 (cond
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2523 ((= syntax ?.) (setq result ?.))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2524 ((and (= syntax ?-) (= (char-after (+ span-start 1)) ?>))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2525 (setq result ?.)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2526 (setq span-start (+ span-start 1)))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2527 (t (setq span-start span-end)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2528 (setq result ??)))))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2529 (setq span-start (+ span-start 1)))
|
3551
|
2530 result))
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2531
|
16185
|
2532 (defun gud-expr-compound (first second)
|
|
2533 "Non-nil if concatenating FIRST and SECOND makes a single C expression.
|
22159
|
2534 The two exprs are represented as a cons cells, where the car
|
|
2535 specifies the point in the current buffer that marks the beginning of the
|
3551
|
2536 expr and the cdr specifies the character after the end of the expr.
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2537 Link exprs of the form:
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2538 Expr -> Expr
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2539 Expr . Expr
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2540 Expr (Expr)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2541 Expr [Expr]
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2542 (Expr) Expr
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2543 [Expr] Expr"
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2544 (let ((span-start (cdr first))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2545 (span-end (car second))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2546 (syntax))
|
16185
|
2547 (setq syntax (gud-expr-compound-sep span-start span-end))
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2548 (cond
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2549 ((= (car first) (car second)) nil)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2550 ((= (cdr first) (cdr second)) nil)
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2551 ((= syntax ?.) t)
|
16185
|
2552 ((= syntax ?\ )
|
2489
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2553 (setq span-start (char-after (- span-start 1)))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2554 (setq span-end (char-after span-end))
|
b626f5b9a0df
Massive changes, amounting nearly to a rewrite. The new features
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2555 (cond
|
16185
|
2556 ((= span-start ?)) t)
|
|
2557 ((= span-start ?]) t)
|
|
2558 ((= span-end ?() t)
|
|
2559 ((= span-end ?[) t)
|
|
2560 (t nil)))
|
3551
|
2561 (t nil))))
|
2581
839d67a1dc58
Set no-byte-compile local variable t to work around a byte-compiler bug.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
2562
|
4016
|
2563 (provide 'gud)
|
|
2564
|
810
|
2565 ;;; gud.el ends here
|