*** empty log message ***
[bpt/emacs.git] / lisp / progmodes / gud.el
CommitLineData
0f9c2d46
JB
1;;; gud.el --- Grand Unified Debugger mode for running GDB and other debuggers
2
3;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
4;; Maintainer: FSF
5;; Keywords: unix, tools
6
f9878c26 7;; Copyright (C) 1992,93,94,95,96,1998,2000,02,03,04 Free Software Foundation, Inc.
0f9c2d46
JB
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
13;; the Free Software Foundation; either version 2, or (at your option)
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
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.
25
26;;; Commentary:
27
be820e8d
NR
28;; The ancestral gdb.el was by W. Schelter <wfs@rascal.ics.utexas.edu> It was
29;; later rewritten by rms. Some ideas were due to Masanobu. Grand
30;; Unification (sdb/dbx support) by Eric S. Raymond <esr@thyrsus.com> Barry
31;; Warsaw <bwarsaw@cen.com> hacked the mode to use comint.el. Shane Hartman
32;; <shane@spr.com> added support for xdb (HPUX debugger). Rick Sladkey
33;; <jrs@world.std.com> wrote the GDB command completion code. Dave Love
34;; <d.love@dl.ac.uk> added the IRIX kluge, re-implemented the Mips-ish variant
35;; and added a menu. Brian D. Carlstrom <bdc@ai.mit.edu> combined the IRIX
36;; kluge with the gud-xdb-directories hack producing gud-dbx-directories.
37;; Derek L. Davies <ddavies@world.std.com> added support for jdb (Java
38;; debugger.)
0f9c2d46
JB
39
40;;; Code:
41
ce38ddb8
NR
42(eval-when-compile (require 'cl)) ; for case macro
43
0f9c2d46
JB
44(require 'comint)
45(require 'etags)
46
47;; ======================================================================
48;; GUD commands must be visible in C buffers visited by GUD
49
50(defgroup gud nil
51 "Grand Unified Debugger mode for gdb and other debuggers under Emacs.
52Supported debuggers include gdb, sdb, dbx, xdb, perldb, pdb (Python), jdb, and bash."
53 :group 'unix
54 :group 'tools)
55
56
57(defcustom gud-key-prefix "\C-x\C-a"
58 "Prefix of all GUD commands valid in C buffers."
59 :type 'string
60 :group 'gud)
61
62(global-set-key (concat gud-key-prefix "\C-l") 'gud-refresh)
63(define-key ctl-x-map " " 'gud-break) ;; backward compatibility hack
64
65(defvar gud-marker-filter nil)
66(put 'gud-marker-filter 'permanent-local t)
67(defvar gud-find-file nil)
68(put 'gud-find-file 'permanent-local t)
69
70(defun gud-marker-filter (&rest args)
71 (apply gud-marker-filter args))
72
73(defvar gud-minor-mode nil)
74(put 'gud-minor-mode 'permanent-local t)
75
76(defvar gud-keep-buffer nil)
77
78(defun gud-symbol (sym &optional soft minor-mode)
79 "Return the symbol used for SYM in MINOR-MODE.
80MINOR-MODE defaults to `gud-minor-mode.
81The symbol returned is `gud-<MINOR-MODE>-<SYM>'.
82If SOFT is non-nil, returns nil if the symbol doesn't already exist."
83 (unless (or minor-mode gud-minor-mode) (error "Gud internal error"))
84 (funcall (if soft 'intern-soft 'intern)
85 (format "gud-%s-%s" (or minor-mode gud-minor-mode) sym)))
86
87(defun gud-val (sym &optional minor-mode)
88 "Return the value of `gud-symbol' SYM. Default to nil."
89 (let ((sym (gud-symbol sym t minor-mode)))
90 (if (boundp sym) (symbol-value sym))))
91
92(defvar gud-running nil
93 "Non-nil if debuggee is running.
f6579c71 94Used to grey out relevant togolbar icons.")
0f9c2d46 95
f6579c71 96;; Use existing Info buffer, if possible.
ed941a3c
NR
97(defun gud-goto-info ()
98 "Go to relevant Emacs info node."
99 (interactive)
f6579c71
NR
100 (let ((same-window-regexps same-window-regexps)
101 (display-buffer-reuse-frames t))
102 (catch 'info-found
103 (walk-windows
104 '(lambda (window)
105 (if (eq (window-buffer window) (get-buffer "*info*"))
106 (progn
107 (setq same-window-regexps nil)
108 (throw 'info-found nil))))
109 nil 0)
f6579c71
NR
110 (select-frame (make-frame)))
111 (if (memq gud-minor-mode '(gdbmi gdba))
be820e8d
NR
112 (info "(emacs)GDB Graphical Interface")
113 (info "(emacs)Debuggers"))))
ed941a3c 114
0f9c2d46 115(easy-mmode-defmap gud-menu-map
4e518230 116 '(([help] "Info" . gud-goto-info)
ce38ddb8 117 ([tooltips] menu-item "Toggle GUD tooltips" gud-tooltip-mode
12b47dbf
NR
118 :enable (and (not emacs-basic-display)
119 (display-graphic-p)
120 (fboundp 'x-show-tip))
ce38ddb8 121 :button (:toggle . gud-tooltip-mode))
adbb5567 122 ([refresh] "Refresh" . gud-refresh)
0f9c2d46 123 ([run] menu-item "Run" gud-run
129adb6f
NR
124 :enable (and (not gud-running)
125 (memq gud-minor-mode '(gdbmi gdba gdb dbx jdb))))
1dd52b82 126 ([until] menu-item "Continue to selection" gud-until
129adb6f
NR
127 :enable (and (not gud-running)
128 (memq gud-minor-mode '(gdbmi gdba gdb perldb))))
0f9c2d46 129 ([remove] menu-item "Remove Breakpoint" gud-remove
129adb6f 130 :enable (not gud-running))
0f9c2d46 131 ([tbreak] menu-item "Temporary Breakpoint" gud-tbreak
129adb6f 132 :enable (memq gud-minor-mode '(gdbmi gdba gdb sdb xdb bashdb)))
0f9c2d46 133 ([break] menu-item "Set Breakpoint" gud-break
129adb6f 134 :enable (not gud-running))
0f9c2d46 135 ([up] menu-item "Up Stack" gud-up
129adb6f
NR
136 :enable (and (not gud-running)
137 (memq gud-minor-mode
138 '(gdbmi gdba gdb dbx xdb jdb pdb bashdb))))
0f9c2d46 139 ([down] menu-item "Down Stack" gud-down
129adb6f
NR
140 :enable (and (not gud-running)
141 (memq gud-minor-mode
142 '(gdbmi gdba gdb dbx xdb jdb pdb bashdb))))
0f9c2d46
JB
143 ([print] menu-item "Print Expression" gud-print
144 :enable (not gud-running))
187c0c40 145 ([watch] menu-item "Watch Expression" gud-watch
129adb6f
NR
146 :enable (and (not gud-running)
147 (memq gud-minor-mode '(gdbmi gdba))))
0f9c2d46
JB
148 ([finish] menu-item "Finish Function" gud-finish
149 :enable (and (not gud-running)
150 (memq gud-minor-mode
129adb6f 151 '(gdbmi gdba gdb xdb jdb pdb bashdb))))
0f9c2d46
JB
152 ([stepi] menu-item "Step Instruction" gud-stepi
153 :enable (and (not gud-running)
129adb6f 154 (memq gud-minor-mode '(gdbmi gdba gdb dbx))))
0f9c2d46
JB
155 ([nexti] menu-item "Next Instruction" gud-nexti
156 :enable (and (not gud-running)
129adb6f 157 (memq gud-minor-mode '(gdbmi gdba gdb dbx))))
0f9c2d46
JB
158 ([step] menu-item "Step Line" gud-step
159 :enable (not gud-running))
160 ([next] menu-item "Next Line" gud-next
161 :enable (not gud-running))
162 ([cont] menu-item "Continue" gud-cont
163 :enable (not gud-running)))
164 "Menu for `gud-mode'."
165 :name "Gud")
166
167(easy-mmode-defmap gud-minor-mode-map
168 `(([menu-bar debug] . ("Gud" . ,gud-menu-map)))
169 "Map used in visited files.")
170
171(let ((m (assq 'gud-minor-mode minor-mode-map-alist)))
172 (if m (setcdr m gud-minor-mode-map)
173 (push (cons 'gud-minor-mode gud-minor-mode-map) minor-mode-map-alist)))
174
175(defvar gud-mode-map
176 ;; Will inherit from comint-mode via define-derived-mode.
177 (make-sparse-keymap)
178 "`gud-mode' keymap.")
179
180(defvar gud-tool-bar-map
181 (if (display-graphic-p)
182 (let ((map (make-sparse-keymap)))
183 (dolist (x '((gud-break . "gud-break")
184 (gud-remove . "gud-remove")
185 (gud-print . "gud-print")
187c0c40 186 (gud-watch . "gud-watch")
0f9c2d46
JB
187 (gud-run . "gud-run")
188 (gud-until . "gud-until")
189 (gud-cont . "gud-cont")
74c942de
EZ
190 ;; gud-s, gud-si etc. instead of gud-step,
191 ;; gud-stepi, to avoid file-name clashes on DOS
192 ;; 8+3 filesystems.
193 (gud-step . "gud-s")
194 (gud-next . "gud-n")
0f9c2d46 195 (gud-finish . "gud-finish")
74c942de
EZ
196 (gud-stepi . "gud-si")
197 (gud-nexti . "gud-ni")
0f9c2d46 198 (gud-up . "gud-up")
adbb5567 199 (gud-down . "gud-down")
ed941a3c 200 (gud-goto-info . "info"))
0f9c2d46
JB
201 map)
202 (tool-bar-local-item-from-menu
203 (car x) (cdr x) map gud-minor-mode-map)))))
204
205(defun gud-file-name (f)
206 "Transform a relative file name to an absolute file name.
207Uses `gud-<MINOR-MODE>-directories' to find the source files."
208 (if (file-exists-p f) (expand-file-name f)
209 (let ((directories (gud-val 'directories))
210 (result nil))
211 (while directories
212 (let ((path (expand-file-name f (car directories))))
213 (if (file-exists-p path)
214 (setq result path
215 directories nil)))
216 (setq directories (cdr directories)))
217 result)))
218
219(defun gud-find-file (file)
220 ;; Don't get confused by double slashes in the name that comes from GDB.
221 (while (string-match "//+" file)
222 (setq file (replace-match "/" t t file)))
223 (let ((minor-mode gud-minor-mode)
224 (buf (funcall (or gud-find-file 'gud-file-name) file)))
225 (when (stringp buf)
226 (setq buf (and (file-readable-p buf) (find-file-noselect buf 'nowarn))))
227 (when buf
228 ;; Copy `gud-minor-mode' to the found buffer to turn on the menu.
229 (with-current-buffer buf
230 (set (make-local-variable 'gud-minor-mode) minor-mode)
231 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
ce38ddb8
NR
232 (when (and gud-tooltip-mode
233 (memq gud-minor-mode '(gdbmi gdba)))
0d2794e3
NR
234 (make-local-variable 'gdb-define-alist)
235 (unless gdb-define-alist (gdb-create-define-alist))
236 (add-hook 'after-save-hook 'gdb-create-define-alist nil t))
0f9c2d46
JB
237 (make-local-variable 'gud-keep-buffer))
238 buf)))
239\f
240;; ======================================================================
241;; command definition
242
243;; This macro is used below to define some basic debugger interface commands.
244;; Of course you may use `gud-def' with any other debugger command, including
245;; user defined ones.
246
247;; A macro call like (gud-def FUNC NAME KEY DOC) expands to a form
248;; which defines FUNC to send the command NAME to the debugger, gives
249;; it the docstring DOC, and binds that function to KEY in the GUD
250;; major mode. The function is also bound in the global keymap with the
251;; GUD prefix.
252
253(defmacro gud-def (func cmd key &optional doc)
254 "Define FUNC to be a command sending STR and bound to KEY, with
255optional doc string DOC. Certain %-escapes in the string arguments
256are interpreted specially if present. These are:
257
258 %f name (without directory) of current source file.
259 %F name (without directory or extension) of current source file.
260 %d directory of current source file.
261 %l number of current source line
262 %e text of the C lvalue or function-call expression surrounding point.
263 %a text of the hexadecimal address surrounding point
264 %p prefix argument to the command (if any) as a number
265
266 The `current' source file is the file of the current buffer (if
267we're in a C file) or the source file current at the last break or
268step (if we're in the GUD buffer).
269 The `current' line is that of the current buffer (if we're in a
270source file) or the source line number at the last break or step (if
271we're in the GUD buffer)."
272 `(progn
273 (defun ,func (arg)
274 ,@(if doc (list doc))
275 (interactive "p")
276 ,(if (stringp cmd)
277 `(gud-call ,cmd arg)
278 cmd))
279 ,(if key `(local-set-key ,(concat "\C-c" key) ',func))
280 ,(if key `(global-set-key (vconcat gud-key-prefix ,key) ',func))))
281
282;; Where gud-display-frame should put the debugging arrow; a cons of
283;; (filename . line-number). This is set by the marker-filter, which scans
284;; the debugger's output for indications of the current program counter.
285(defvar gud-last-frame nil)
286
287;; Used by gud-refresh, which should cause gud-display-frame to redisplay
288;; the last frame, even if it's been called before and gud-last-frame has
289;; been set to nil.
290(defvar gud-last-last-frame nil)
291
292;; All debugger-specific information is collected here.
293;; Here's how it works, in case you ever need to add a debugger to the mode.
294;;
295;; Each entry must define the following at startup:
296;;
297;;<name>
298;; comint-prompt-regexp
299;; gud-<name>-massage-args
300;; gud-<name>-marker-filter
301;; gud-<name>-find-file
302;;
303;; The job of the massage-args method is to modify the given list of
304;; debugger arguments before running the debugger.
305;;
306;; The job of the marker-filter method is to detect file/line markers in
307;; strings and set the global gud-last-frame to indicate what display
308;; action (if any) should be triggered by the marker. Note that only
309;; whatever the method *returns* is displayed in the buffer; thus, you
310;; can filter the debugger's output, interpreting some and passing on
311;; the rest.
312;;
313;; The job of the find-file method is to visit and return the buffer indicated
314;; by the car of gud-tag-frame. This may be a file name, a tag name, or
315;; something else.
316\f
317;; ======================================================================
318;; speedbar support functions and variables.
319(eval-when-compile (require 'speedbar)) ;For speedbar-with-attached-buffer.
320
321(defvar gud-last-speedbar-buffer nil
322 "The last GUD buffer used.")
323
324(defvar gud-last-speedbar-stackframe nil
325 "Description of the currently displayed GUD stack.
326t means that there is no stack, and we are in display-file mode.")
327
328(defvar gud-speedbar-key-map nil
329 "Keymap used when in the buffers display mode.")
330
331(defun gud-install-speedbar-variables ()
332 "Install those variables used by speedbar to enhance gud/gdb."
333 (if gud-speedbar-key-map
334 nil
335 (setq gud-speedbar-key-map (speedbar-make-specialized-keymap))
336
337 (define-key gud-speedbar-key-map "j" 'speedbar-edit-line)
338 (define-key gud-speedbar-key-map "e" 'speedbar-edit-line)
4ff07782
NR
339 (define-key gud-speedbar-key-map "\C-m" 'speedbar-edit-line)
340 (define-key gud-speedbar-key-map "D" 'gdb-var-delete)))
341
0f9c2d46
JB
342
343(defvar gud-speedbar-menu-items
344 ;; Note to self. Add expand, and turn off items when not available.
be820e8d 345 '(["Jump to stack frame" speedbar-edit-line
129adb6f
NR
346 (with-current-buffer gud-comint-buffer
347 (not (memq gud-minor-mode '(gdbmi gdba))))]
be820e8d 348 ["Edit value" speedbar-edit-line
129adb6f
NR
349 (with-current-buffer gud-comint-buffer
350 (not (memq gud-minor-mode '(gdbmi gdba))))]
be820e8d 351 ["Delete expression" gdb-var-delete
129adb6f
NR
352 (with-current-buffer gud-comint-buffer
353 (not (memq gud-minor-mode '(gdbmi gdba))))])
0f9c2d46
JB
354 "Additional menu items to add to the speedbar frame.")
355
356;; Make sure our special speedbar mode is loaded
357(if (featurep 'speedbar)
358 (gud-install-speedbar-variables)
359 (add-hook 'speedbar-load-hook 'gud-install-speedbar-variables))
360
361(defun gud-speedbar-buttons (buffer)
362 "Create a speedbar display based on the current state of GUD.
363If the GUD BUFFER is not running a supported debugger, then turn
364off the specialized speedbar mode."
187c0c40 365 (let ((minor-mode (with-current-buffer buffer gud-minor-mode)))
d7af3230 366 (cond
129adb6f 367 ((memq minor-mode '(gdbmi gdba))
187c0c40 368 (when (or gdb-var-changed
d7af3230 369 (not (save-excursion
187c0c40
NR
370 (goto-char (point-min))
371 (let ((case-fold-search t))
372 (looking-at "Watch Expressions:")))))
79148a5b 373 (erase-buffer)
187c0c40
NR
374 (insert "Watch Expressions:\n")
375 (let ((var-list gdb-var-list))
376 (while var-list
377 (let* ((depth 0) (start 0) (char ?+)
378 (var (car var-list)) (varnum (nth 1 var)))
379 (while (string-match "\\." varnum start)
380 (setq depth (1+ depth)
381 start (1+ (match-beginning 0))))
382 (if (equal (nth 2 var) "0")
383 (speedbar-make-tag-line 'bracket ?? nil nil
79148a5b
NR
384 (concat (car var) "\t" (nth 4 var))
385 'gdb-edit-value
d7af3230
NR
386 nil
387 (if (and (nth 5 var)
79148a5b
NR
388 gdb-show-changed-values)
389 'font-lock-warning-face
390 nil) depth)
187c0c40
NR
391 (if (and (cadr var-list)
392 (string-match varnum (cadr (cadr var-list))))
393 (setq char ?-))
394 (speedbar-make-tag-line 'bracket char
395 'gdb-speedbar-expand-node varnum
79148a5b 396 (concat (car var) "\t" (nth 3 var))
4ff07782 397 nil nil nil depth)))
187c0c40
NR
398 (setq var-list (cdr var-list))))
399 (setq gdb-var-changed nil)))
d7af3230 400 (t (if (and (save-excursion
187c0c40
NR
401 (goto-char (point-min))
402 (looking-at "Current Stack"))
403 (equal gud-last-last-frame gud-last-speedbar-stackframe))
404 nil
405 (setq gud-last-speedbar-buffer buffer)
406 (let ((gud-frame-list
407 (cond ((eq minor-mode 'gdb)
408 (gud-gdb-get-stackframe buffer))
409 ;; Add more debuggers here!
410 (t (speedbar-remove-localized-speedbar-support buffer)
411 nil))))
412 (erase-buffer)
413 (if (not gud-frame-list)
414 (insert "No Stack frames\n")
415 (insert "Current Stack:\n"))
416 (dolist (frame gud-frame-list)
417 (insert (nth 1 frame) ":\n")
418 (if (= (length frame) 2)
419 (progn
420; (speedbar-insert-button "[?]"
421; 'speedbar-button-face
422; nil nil nil t)
423 (speedbar-insert-button (car frame)
424 'speedbar-directory-face
425 nil nil nil t))
426; (speedbar-insert-button "[+]"
0f9c2d46 427; 'speedbar-button-face
187c0c40
NR
428; 'speedbar-highlight-face
429; 'gud-gdb-get-scope-data
430; frame t)
431 (speedbar-insert-button (car frame)
432 'speedbar-file-face
433 'speedbar-highlight-face
129adb6f 434 (cond ((memq minor-mode '(gdbmi gdba gdb))
187c0c40
NR
435 'gud-gdb-goto-stackframe)
436 (t (error "Should never be here")))
437 frame t)))
438; (let ((selected-frame
439; (cond ((eq ff 'gud-gdb-find-file)
440; (gud-gdb-selected-frame-info buffer))
441; (t (error "Should never be here"))))))
442 )
443 (setq gud-last-speedbar-stackframe gud-last-last-frame))))))
0f9c2d46
JB
444
445\f
446;; ======================================================================
447;; gdb functions
448
449;; History of argument lists passed to gdb.
450(defvar gud-gdb-history nil)
451
d7af3230 452(defcustom gud-gdb-command-name "gdb --annotate=3"
0f9c2d46
JB
453 "Default command to execute an executable under the GDB debugger."
454 :type 'string
455 :group 'gud)
456
457(defvar gud-gdb-marker-regexp
458 ;; This used to use path-separator instead of ":";
459 ;; however, we found that on both Windows 32 and MSDOS
460 ;; a colon is correct here.
461 (concat "\032\032\\(.:?[^" ":" "\n]*\\)" ":"
462 "\\([0-9]*\\)" ":" ".*\n"))
463
464;; There's no guarantee that Emacs will hand the filter the entire
465;; marker at once; it could be broken up across several strings. We
466;; might even receive a big chunk with several markers in it. If we
467;; receive a chunk of text which looks like it might contain the
468;; beginning of a marker, we save it here between calls to the
469;; filter.
470(defvar gud-marker-acc "")
471(make-variable-buffer-local 'gud-marker-acc)
472
473(defun gud-gdb-marker-filter (string)
474 (setq gud-marker-acc (concat gud-marker-acc string))
475 (let ((output ""))
476
477 ;; Process all the complete markers in this chunk.
478 (while (string-match gud-gdb-marker-regexp gud-marker-acc)
479 (setq
480
481 ;; Extract the frame position from the marker.
482 gud-last-frame (cons (match-string 1 gud-marker-acc)
0d2794e3 483 (string-to-number (match-string 2 gud-marker-acc)))
0f9c2d46
JB
484
485 ;; Append any text before the marker to the output we're going
486 ;; to return - we don't include the marker in this text.
487 output (concat output
488 (substring gud-marker-acc 0 (match-beginning 0)))
489
490 ;; Set the accumulator to the remaining text.
491 gud-marker-acc (substring gud-marker-acc (match-end 0))))
492
4ff07782
NR
493 ;; Check for annotations and change gud-minor-mode to 'gdba if
494 ;; they are found.
d7af3230
NR
495 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
496 (when (string-equal (match-string 1 gud-marker-acc) "prompt")
497 (require 'gdb-ui)
498 (gdb-prompt nil))
4ff07782 499
d7af3230
NR
500 (setq
501 ;; Append any text before the marker to the output we're going
502 ;; to return - we don't include the marker in this text.
503 output (concat output
504 (substring gud-marker-acc 0 (match-beginning 0)))
505
506 ;; Set the accumulator to the remaining text.
507 gud-marker-acc (substring gud-marker-acc (match-end 0))))
508
0f9c2d46
JB
509 ;; Does the remaining text look like it might end with the
510 ;; beginning of another marker? If it does, then keep it in
511 ;; gud-marker-acc until we receive the rest of it. Since we
512 ;; know the full marker regexp above failed, it's pretty simple to
513 ;; test for marker starts.
034de736 514 (if (string-match "\n\\(\032.*\\)?\\'" gud-marker-acc)
0f9c2d46
JB
515 (progn
516 ;; Everything before the potential marker start can be output.
517 (setq output (concat output (substring gud-marker-acc
518 0 (match-beginning 0))))
519
520 ;; Everything after, we save, to combine with later input.
521 (setq gud-marker-acc
522 (substring gud-marker-acc (match-beginning 0))))
523
524 (setq output (concat output gud-marker-acc)
525 gud-marker-acc ""))
526
527 output))
528
529(easy-mmode-defmap gud-minibuffer-local-map
530 '(("\C-i" . comint-dynamic-complete-filename))
531 "Keymap for minibuffer prompting of gud startup command."
532 :inherit minibuffer-local-map)
533
534(defun gud-query-cmdline (minor-mode &optional init)
535 (let* ((hist-sym (gud-symbol 'history nil minor-mode))
536 (cmd-name (gud-val 'command-name minor-mode)))
537 (unless (boundp hist-sym) (set hist-sym nil))
538 (read-from-minibuffer
539 (format "Run %s (like this): " minor-mode)
540 (or (car-safe (symbol-value hist-sym))
541 (concat (or cmd-name (symbol-name minor-mode))
542 " "
543 (or init
544 (let ((file nil))
545 (dolist (f (directory-files default-directory) file)
546 (if (and (file-executable-p f)
547 (not (file-directory-p f))
548 (or (not file)
549 (file-newer-than-file-p f file)))
550 (setq file f)))))))
551 gud-minibuffer-local-map nil
552 hist-sym)))
553
9f1d9ee4 554(defvar gdb-first-prompt t)
d7af3230 555
63cc3b09
NR
556(defvar gud-filter-pending-text nil
557 "Non-nil means this is text that has been saved for later in `gud-filter'.")
558
0f9c2d46
JB
559;;;###autoload
560(defun gdb (command-line)
561 "Run gdb on program FILE in buffer *gud-FILE*.
562The directory containing FILE becomes the initial working directory
563and source-file directory for your debugger."
564 (interactive (list (gud-query-cmdline 'gdb)))
565
566 (gud-common-init command-line nil 'gud-gdb-marker-filter)
567 (set (make-local-variable 'gud-minor-mode) 'gdb)
568
569 (gud-def gud-break "break %f:%l" "\C-b" "Set breakpoint at current line.")
570 (gud-def gud-tbreak "tbreak %f:%l" "\C-t" "Set temporary breakpoint at current line.")
571 (gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line")
572 (gud-def gud-step "step %p" "\C-s" "Step one source line with display.")
573 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
574 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).")
575 (gud-def gud-nexti "nexti %p" nil "Step one instruction (skip functions).")
576 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
577 (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
578 (gud-def gud-jump "tbreak %f:%l\njump %f:%l" "\C-j" "Relocate execution address to line at point in source buffer.")
579
580 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
581 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
582 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
583 (gud-def gud-until "until %l" "\C-u" "Continue to current line.")
584 (gud-def gud-run "run" nil "Run the program.")
585
586 (local-set-key "\C-i" 'gud-gdb-complete-command)
587 (setq comint-prompt-regexp "^(.*gdb[+]?) *")
588 (setq paragraph-start comint-prompt-regexp)
9f1d9ee4 589 (setq gdb-first-prompt t)
63cc3b09 590 (setq gud-filter-pending-text nil)
d7af3230 591 (run-hooks 'gdb-mode-hook))
0f9c2d46
JB
592
593;; One of the nice features of GDB is its impressive support for
594;; context-sensitive command completion. We preserve that feature
595;; in the GUD buffer by using a GDB command designed just for Emacs.
596
597;; The completion process filter indicates when it is finished.
598(defvar gud-gdb-fetch-lines-in-progress)
599
600;; Since output may arrive in fragments we accumulate partials strings here.
601(defvar gud-gdb-fetch-lines-string)
602
603;; We need to know how much of the completion to chop off.
604(defvar gud-gdb-fetch-lines-break)
605
606;; The completion list is constructed by the process filter.
607(defvar gud-gdb-fetched-lines)
608
609(defvar gud-comint-buffer nil)
610
611(defun gud-gdb-complete-command ()
612 "Perform completion on the GDB command preceding point.
613This is implemented using the GDB `complete' command which isn't
614available with older versions of GDB."
615 (interactive)
616 (let* ((end (point))
617 (command (buffer-substring (comint-line-beginning-position) end))
618 (command-word
619 ;; Find the word break. This match will always succeed.
620 (and (string-match "\\(\\`\\| \\)\\([^ ]*\\)\\'" command)
621 (substring command (match-beginning 2))))
622 (complete-list
623 (gud-gdb-run-command-fetch-lines (concat "complete " command)
624 (current-buffer)
625 ;; From string-match above.
626 (match-beginning 2))))
627 ;; Protect against old versions of GDB.
628 (and complete-list
629 (string-match "^Undefined command: \"complete\"" (car complete-list))
630 (error "This version of GDB doesn't support the `complete' command"))
631 ;; Sort the list like readline.
632 (setq complete-list (sort complete-list (function string-lessp)))
633 ;; Remove duplicates.
634 (let ((first complete-list)
635 (second (cdr complete-list)))
636 (while second
637 (if (string-equal (car first) (car second))
638 (setcdr first (setq second (cdr second)))
639 (setq first second
640 second (cdr second)))))
641 ;; Add a trailing single quote if there is a unique completion
642 ;; and it contains an odd number of unquoted single quotes.
643 (and (= (length complete-list) 1)
644 (let ((str (car complete-list))
645 (pos 0)
646 (count 0))
647 (while (string-match "\\([^'\\]\\|\\\\'\\)*'" str pos)
648 (setq count (1+ count)
649 pos (match-end 0)))
650 (and (= (mod count 2) 1)
651 (setq complete-list (list (concat str "'"))))))
652 ;; Let comint handle the rest.
653 (comint-dynamic-simple-complete command-word complete-list)))
654
655;; The completion process filter is installed temporarily to slurp the
656;; output of GDB up to the next prompt and build the completion list.
657(defun gud-gdb-fetch-lines-filter (string filter)
658 "Filter used to read the list of lines output by a command.
659STRING is the output to filter.
660It is passed through FILTER before we look at it."
661 (setq string (funcall filter string))
662 (setq string (concat gud-gdb-fetch-lines-string string))
663 (while (string-match "\n" string)
664 (push (substring string gud-gdb-fetch-lines-break (match-beginning 0))
665 gud-gdb-fetched-lines)
666 (setq string (substring string (match-end 0))))
667 (if (string-match comint-prompt-regexp string)
668 (progn
669 (setq gud-gdb-fetch-lines-in-progress nil)
670 string)
671 (progn
672 (setq gud-gdb-fetch-lines-string string)
673 "")))
674
675;; gdb speedbar functions
676
677(defun gud-gdb-goto-stackframe (text token indent)
678 "Goto the stackframe described by TEXT, TOKEN, and INDENT."
679 (speedbar-with-attached-buffer
680 (gud-basic-call (concat "server frame " (nth 1 token)))
681 (sit-for 1)))
682
683(defvar gud-gdb-fetched-stack-frame nil
684 "Stack frames we are fetching from GDB.")
685
686;(defun gud-gdb-get-scope-data (text token indent)
687; ;; checkdoc-params: (indent)
688; "Fetch data associated with a stack frame, and expand/contract it.
689;Data to do this is retrieved from TEXT and TOKEN."
690; (let ((args nil) (scope nil))
691; (gud-gdb-run-command-fetch-lines "info args")
692;
693; (gud-gdb-run-command-fetch-lines "info local")
694;
695; ))
696
697(defun gud-gdb-get-stackframe (buffer)
698 "Extract the current stack frame out of the GUD GDB BUFFER."
699 (let ((newlst nil)
700 (fetched-stack-frame-list
701 (gud-gdb-run-command-fetch-lines "server backtrace" buffer)))
702 (if (and (car fetched-stack-frame-list)
703 (string-match "No stack" (car fetched-stack-frame-list)))
704 ;; Go into some other mode???
705 nil
706 (dolist (e fetched-stack-frame-list)
707 (let ((name nil) (num nil))
708 (if (not (or
709 (string-match "^#\\([0-9]+\\) +[0-9a-fx]+ in \\([:0-9a-zA-Z_]+\\) (" e)
710 (string-match "^#\\([0-9]+\\) +\\([:0-9a-zA-Z_]+\\) (" e)))
711 (if (not (string-match
712 "at \\([-0-9a-zA-Z_.]+\\):\\([0-9]+\\)$" e))
713 nil
714 (setcar newlst
715 (list (nth 0 (car newlst))
716 (nth 1 (car newlst))
717 (match-string 1 e)
718 (match-string 2 e))))
719 (setq num (match-string 1 e)
720 name (match-string 2 e))
721 (setq newlst
722 (cons
723 (if (string-match
724 "at \\([-0-9a-zA-Z_.]+\\):\\([0-9]+\\)$" e)
725 (list name num (match-string 1 e)
726 (match-string 2 e))
727 (list name num))
728 newlst)))))
729 (nreverse newlst))))
730
731;(defun gud-gdb-selected-frame-info (buffer)
732; "Learn GDB information for the currently selected stack frame in BUFFER."
733; )
734
735(defun gud-gdb-run-command-fetch-lines (command buffer &optional skip)
736 "Run COMMAND, and return the list of lines it outputs.
737BUFFER is the GUD buffer in which to run the command.
738SKIP is the number of chars to skip on each lines, it defaults to 0."
739 (with-current-buffer buffer
740 (if (save-excursion
741 (goto-char (point-max))
742 (forward-line 0)
743 (not (looking-at comint-prompt-regexp)))
744 nil
745 ;; Much of this copied from GDB complete, but I'm grabbing the stack
746 ;; frame instead.
747 (let ((gud-gdb-fetch-lines-in-progress t)
748 (gud-gdb-fetched-lines nil)
749 (gud-gdb-fetch-lines-string nil)
750 (gud-gdb-fetch-lines-break (or skip 0))
751 (gud-marker-filter
752 `(lambda (string) (gud-gdb-fetch-lines-filter string ',gud-marker-filter))))
753 ;; Issue the command to GDB.
754 (gud-basic-call command)
755 ;; Slurp the output.
756 (while gud-gdb-fetch-lines-in-progress
757 (accept-process-output (get-buffer-process buffer)))
758 (nreverse gud-gdb-fetched-lines)))))
759
760\f
761;; ======================================================================
762;; sdb functions
763
764;; History of argument lists passed to sdb.
765(defvar gud-sdb-history nil)
766
767(defvar gud-sdb-needs-tags (not (file-exists-p "/var"))
768 "If nil, we're on a System V Release 4 and don't need the tags hack.")
769
770(defvar gud-sdb-lastfile nil)
771
772(defun gud-sdb-marker-filter (string)
773 (setq gud-marker-acc
774 (if gud-marker-acc (concat gud-marker-acc string) string))
775 (let (start)
776 ;; Process all complete markers in this chunk
777 (while
778 (cond
779 ;; System V Release 3.2 uses this format
780 ((string-match "\\(^\\|\n\\)\\*?\\(0x\\w* in \\)?\\([^:\n]*\\):\\([0-9]*\\):.*\n"
781 gud-marker-acc start)
782 (setq gud-last-frame
783 (cons (match-string 3 gud-marker-acc)
0d2794e3 784 (string-to-number (match-string 4 gud-marker-acc)))))
0f9c2d46
JB
785 ;; System V Release 4.0 quite often clumps two lines together
786 ((string-match "^\\(BREAKPOINT\\|STEPPED\\) process [0-9]+ function [^ ]+ in \\(.+\\)\n\\([0-9]+\\):"
787 gud-marker-acc start)
788 (setq gud-sdb-lastfile (match-string 2 gud-marker-acc))
789 (setq gud-last-frame
790 (cons gud-sdb-lastfile
0d2794e3 791 (string-to-number (match-string 3 gud-marker-acc)))))
0f9c2d46
JB
792 ;; System V Release 4.0
793 ((string-match "^\\(BREAKPOINT\\|STEPPED\\) process [0-9]+ function [^ ]+ in \\(.+\\)\n"
794 gud-marker-acc start)
795 (setq gud-sdb-lastfile (match-string 2 gud-marker-acc)))
796 ((and gud-sdb-lastfile (string-match "^\\([0-9]+\\):"
797 gud-marker-acc start))
798 (setq gud-last-frame
799 (cons gud-sdb-lastfile
0d2794e3 800 (string-to-number (match-string 1 gud-marker-acc)))))
0f9c2d46
JB
801 (t
802 (setq gud-sdb-lastfile nil)))
803 (setq start (match-end 0)))
804
805 ;; Search for the last incomplete line in this chunk
806 (while (string-match "\n" gud-marker-acc start)
807 (setq start (match-end 0)))
808
809 ;; If we have an incomplete line, store it in gud-marker-acc.
810 (setq gud-marker-acc (substring gud-marker-acc (or start 0))))
811 string)
812
813(defun gud-sdb-find-file (f)
814 (if gud-sdb-needs-tags (find-tag-noselect f) (find-file-noselect f)))
815
816;;;###autoload
817(defun sdb (command-line)
818 "Run sdb on program FILE in buffer *gud-FILE*.
819The directory containing FILE becomes the initial working directory
820and source-file directory for your debugger."
821 (interactive (list (gud-query-cmdline 'sdb)))
822
823 (if (and gud-sdb-needs-tags
824 (not (and (boundp 'tags-file-name)
825 (stringp tags-file-name)
826 (file-exists-p tags-file-name))))
827 (error "The sdb support requires a valid tags table to work"))
828
829 (gud-common-init command-line nil 'gud-sdb-marker-filter 'gud-sdb-find-file)
830 (set (make-local-variable 'gud-minor-mode) 'sdb)
831
832 (gud-def gud-break "%l b" "\C-b" "Set breakpoint at current line.")
833 (gud-def gud-tbreak "%l c" "\C-t" "Set temporary breakpoint at current line.")
834 (gud-def gud-remove "%l d" "\C-d" "Remove breakpoint at current line")
835 (gud-def gud-step "s %p" "\C-s" "Step one source line with display.")
836 (gud-def gud-stepi "i %p" "\C-i" "Step one instruction with display.")
837 (gud-def gud-next "S %p" "\C-n" "Step one line (skip functions).")
838 (gud-def gud-cont "c" "\C-r" "Continue with display.")
839 (gud-def gud-print "%e/" "\C-p" "Evaluate C expression at point.")
840
841 (setq comint-prompt-regexp "\\(^\\|\n\\)\\*")
842 (setq paragraph-start comint-prompt-regexp)
843 (run-hooks 'sdb-mode-hook)
844 )
845\f
846;; ======================================================================
847;; dbx functions
848
849;; History of argument lists passed to dbx.
850(defvar gud-dbx-history nil)
851
852(defcustom gud-dbx-directories nil
853 "*A list of directories that dbx should search for source code.
854If nil, only source files in the program directory
855will be known to dbx.
856
857The file names should be absolute, or relative to the directory
858containing the executable being debugged."
859 :type '(choice (const :tag "Current Directory" nil)
860 (repeat :value ("")
861 directory))
862 :group 'gud)
863
864(defun gud-dbx-massage-args (file args)
865 (nconc (let ((directories gud-dbx-directories)
866 (result nil))
867 (while directories
868 (setq result (cons (car directories) (cons "-I" result)))
869 (setq directories (cdr directories)))
870 (nreverse result))
871 args))
872
873(defun gud-dbx-marker-filter (string)
874 (setq gud-marker-acc (if gud-marker-acc (concat gud-marker-acc string) string))
875
876 (let (start)
877 ;; Process all complete markers in this chunk.
878 (while (or (string-match
879 "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\""
880 gud-marker-acc start)
881 (string-match
882 "signal .* in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\""
883 gud-marker-acc start))
884 (setq gud-last-frame
885 (cons (match-string 2 gud-marker-acc)
0d2794e3 886 (string-to-number (match-string 1 gud-marker-acc)))
0f9c2d46
JB
887 start (match-end 0)))
888
889 ;; Search for the last incomplete line in this chunk
890 (while (string-match "\n" gud-marker-acc start)
891 (setq start (match-end 0)))
892
893 ;; If the incomplete line APPEARS to begin with another marker, keep it
894 ;; in the accumulator. Otherwise, clear the accumulator to avoid an
895 ;; unnecessary concat during the next call.
896 (setq gud-marker-acc
897 (if (string-match "\\(stopped\\|signal\\)" gud-marker-acc start)
898 (substring gud-marker-acc (match-beginning 0))
899 nil)))
900 string)
901
902;; Functions for Mips-style dbx. Given the option `-emacs', documented in
903;; OSF1, not necessarily elsewhere, it produces markers similar to gdb's.
904(defvar gud-mips-p
905 (or (string-match "^mips-[^-]*-ultrix" system-configuration)
906 ;; We haven't tested gud on this system:
907 (string-match "^mips-[^-]*-riscos" system-configuration)
908 ;; It's documented on OSF/1.3
909 (string-match "^mips-[^-]*-osf1" system-configuration)
910 (string-match "^alpha[^-]*-[^-]*-osf" system-configuration))
911 "Non-nil to assume the MIPS/OSF dbx conventions (argument `-emacs').")
912
913(defvar gud-dbx-command-name
914 (concat "dbx" (if gud-mips-p " -emacs")))
915
916;; This is just like the gdb one except for the regexps since we need to cope
917;; with an optional breakpoint number in [] before the ^Z^Z
918(defun gud-mipsdbx-marker-filter (string)
919 (setq gud-marker-acc (concat gud-marker-acc string))
920 (let ((output ""))
921
922 ;; Process all the complete markers in this chunk.
923 (while (string-match
924 ;; This is like th gdb marker but with an optional
925 ;; leading break point number like `[1] '
926 "[][ 0-9]*\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
927 gud-marker-acc)
928 (setq
929
930 ;; Extract the frame position from the marker.
931 gud-last-frame
932 (cons (match-string 1 gud-marker-acc)
0d2794e3 933 (string-to-number (match-string 2 gud-marker-acc)))
0f9c2d46
JB
934
935 ;; Append any text before the marker to the output we're going
936 ;; to return - we don't include the marker in this text.
937 output (concat output
938 (substring gud-marker-acc 0 (match-beginning 0)))
939
940 ;; Set the accumulator to the remaining text.
941 gud-marker-acc (substring gud-marker-acc (match-end 0))))
942
943 ;; Does the remaining text look like it might end with the
944 ;; beginning of another marker? If it does, then keep it in
945 ;; gud-marker-acc until we receive the rest of it. Since we
946 ;; know the full marker regexp above failed, it's pretty simple to
947 ;; test for marker starts.
948 (if (string-match "[][ 0-9]*\032.*\\'" gud-marker-acc)
949 (progn
950 ;; Everything before the potential marker start can be output.
951 (setq output (concat output (substring gud-marker-acc
952 0 (match-beginning 0))))
953
954 ;; Everything after, we save, to combine with later input.
955 (setq gud-marker-acc
956 (substring gud-marker-acc (match-beginning 0))))
957
958 (setq output (concat output gud-marker-acc)
959 gud-marker-acc ""))
960
961 output))
962
963;; The dbx in IRIX is a pain. It doesn't print the file name when
964;; stopping at a breakpoint (but you do get it from the `up' and
965;; `down' commands...). The only way to extract the information seems
966;; to be with a `file' command, although the current line number is
967;; available in $curline. Thus we have to look for output which
968;; appears to indicate a breakpoint. Then we prod the dbx sub-process
969;; to output the information we want with a combination of the
970;; `printf' and `file' commands as a pseudo marker which we can
971;; recognise next time through the marker-filter. This would be like
972;; the gdb marker but you can't get the file name without a newline...
973;; Note that gud-remove won't work since Irix dbx expects a breakpoint
974;; number rather than a line number etc. Maybe this could be made to
975;; work by listing all the breakpoints and picking the one(s) with the
976;; correct line number, but life's too short.
977;; d.love@dl.ac.uk (Dave Love) can be blamed for this
978
979(defvar gud-irix-p
980 (and (string-match "^mips-[^-]*-irix" system-configuration)
981 (not (string-match "irix[6-9]\\.[1-9]" system-configuration)))
982 "Non-nil to assume the interface appropriate for IRIX dbx.
983This works in IRIX 4, 5 and 6, but `gud-dbx-use-stopformat-p' provides
984a better solution in 6.1 upwards.")
985(defvar gud-dbx-use-stopformat-p
986 (string-match "irix[6-9]\\.[1-9]" system-configuration)
987 "Non-nil to use the dbx feature present at least from Irix 6.1
988 whereby $stopformat=1 produces an output format compatiable with
989 `gud-dbx-marker-filter'.")
990;; [Irix dbx seems to be a moving target. The dbx output changed
991;; subtly sometime between OS v4.0.5 and v5.2 so that, for instance,
992;; the output from `up' is no longer spotted by gud (and it's probably
993;; not distinctive enough to try to match it -- use C-<, C->
994;; exclusively) . For 5.3 and 6.0, the $curline variable changed to
995;; `long long'(why?!), so the printf stuff needed changing. The line
996;; number was cast to `long' as a compromise between the new `long
997;; long' and the original `int'. This is reported not to work in 6.2,
998;; so it's changed back to int -- don't make your sources too long.
999;; From Irix6.1 (but not 6.0?) dbx supports an undocumented feature
1000;; whereby `set $stopformat=1' reportedly produces output compatible
1001;; with `gud-dbx-marker-filter', which we prefer.
1002
1003;; The process filter is also somewhat
1004;; unreliable, sometimes not spotting the markers; I don't know
1005;; whether there's anything that can be done about that. It would be
1006;; much better if SGI could be persuaded to (re?)instate the MIPS
1007;; -emacs flag for gdb-like output (which ought to be possible as most
1008;; of the communication I've had over it has been from sgi.com).]
1009
1010;; this filter is influenced by the xdb one rather than the gdb one
1011(defun gud-irixdbx-marker-filter (string)
1012 (let (result (case-fold-search nil))
1013 (if (or (string-match comint-prompt-regexp string)
1014 (string-match ".*\012" string))
1015 (setq result (concat gud-marker-acc string)
1016 gud-marker-acc "")
1017 (setq gud-marker-acc (concat gud-marker-acc string)))
1018 (if result
1019 (cond
1020 ;; look for breakpoint or signal indication e.g.:
1021 ;; [2] Process 1267 (pplot) stopped at [params:338 ,0x400ec0]
1022 ;; Process 1281 (pplot) stopped at [params:339 ,0x400ec8]
1023 ;; Process 1270 (pplot) Floating point exception [._read._read:16 ,0x452188]
1024 ((string-match
1025 "^\\(\\[[0-9]+] \\)?Process +[0-9]+ ([^)]*) [^[]+\\[[^]\n]*]\n"
1026 result)
1027 ;; prod dbx into printing out the line number and file
1028 ;; name in a form we can grok as below
1029 (process-send-string (get-buffer-process gud-comint-buffer)
1030 "printf \"\032\032%1d:\",(int)$curline;file\n"))
1031 ;; look for result of, say, "up" e.g.:
1032 ;; .pplot.pplot(0x800) ["src/pplot.f":261, 0x400c7c]
1033 ;; (this will also catch one of the lines printed by "where")
1034 ((string-match
1035 "^[^ ][^[]*\\[\"\\([^\"]+\\)\":\\([0-9]+\\), [^]]+]\n"
1036 result)
1037 (let ((file (match-string 1 result)))
1038 (if (file-exists-p file)
1039 (setq gud-last-frame
1040 (cons (match-string 1 result)
0d2794e3 1041 (string-to-number (match-string 2 result))))))
0f9c2d46
JB
1042 result)
1043 ((string-match ; kluged-up marker as above
1044 "\032\032\\([0-9]*\\):\\(.*\\)\n" result)
1045 (let ((file (gud-file-name (match-string 2 result))))
1046 (if (and file (file-exists-p file))
1047 (setq gud-last-frame
1048 (cons file
0d2794e3 1049 (string-to-number (match-string 1 result))))))
0f9c2d46
JB
1050 (setq result (substring result 0 (match-beginning 0))))))
1051 (or result "")))
1052
1053(defvar gud-dgux-p (string-match "-dgux" system-configuration)
1054 "Non-nil means to assume the interface approriate for DG/UX dbx.
1055This was tested using R4.11.")
1056
1057;; There are a couple of differences between DG's dbx output and normal
1058;; dbx output which make it nontrivial to integrate this into the
1059;; standard dbx-marker-filter (mainly, there are a different number of
1060;; backreferences). The markers look like:
1061;;
1062;; (0) Stopped at line 10, routine main(argc=1, argv=0xeffff0e0), file t.c
1063;;
1064;; from breakpoints (the `(0)' there isn't constant, it's the breakpoint
1065;; number), and
1066;;
1067;; Stopped at line 13, routine main(argc=1, argv=0xeffff0e0), file t.c
1068;;
1069;; from signals and
1070;;
1071;; Frame 21, line 974, routine command_loop(), file keyboard.c
1072;;
1073;; from up/down/where.
1074
1075(defun gud-dguxdbx-marker-filter (string)
1076 (setq gud-marker-acc (if gud-marker-acc
1077 (concat gud-marker-acc string)
1078 string))
1079 (let ((re (concat "^\\(\\(([0-9]+) \\)?Stopped at\\|Frame [0-9]+,\\)"
1080 " line \\([0-9]+\\), routine .*, file \\([^ \t\n]+\\)"))
1081 start)
1082 ;; Process all complete markers in this chunk.
1083 (while (string-match re gud-marker-acc start)
1084 (setq gud-last-frame
1085 (cons (match-string 4 gud-marker-acc)
0d2794e3 1086 (string-to-number (match-string 3 gud-marker-acc)))
0f9c2d46
JB
1087 start (match-end 0)))
1088
1089 ;; Search for the last incomplete line in this chunk
1090 (while (string-match "\n" gud-marker-acc start)
1091 (setq start (match-end 0)))
1092
1093 ;; If the incomplete line APPEARS to begin with another marker, keep it
1094 ;; in the accumulator. Otherwise, clear the accumulator to avoid an
1095 ;; unnecessary concat during the next call.
1096 (setq gud-marker-acc
1097 (if (string-match "Stopped\\|Frame" gud-marker-acc start)
1098 (substring gud-marker-acc (match-beginning 0))
1099 nil)))
1100 string)
1101
1102;;;###autoload
1103(defun dbx (command-line)
1104 "Run dbx on program FILE in buffer *gud-FILE*.
1105The directory containing FILE becomes the initial working directory
1106and source-file directory for your debugger."
1107 (interactive (list (gud-query-cmdline 'dbx)))
1108
1109 (cond
1110 (gud-mips-p
1111 (gud-common-init command-line nil 'gud-mipsdbx-marker-filter))
1112 (gud-irix-p
1113 (gud-common-init command-line 'gud-dbx-massage-args
1114 'gud-irixdbx-marker-filter))
1115 (gud-dgux-p
1116 (gud-common-init command-line 'gud-dbx-massage-args
1117 'gud-dguxdbx-marker-filter))
1118 (t
1119 (gud-common-init command-line 'gud-dbx-massage-args
1120 'gud-dbx-marker-filter)))
1121
1122 (set (make-local-variable 'gud-minor-mode) 'dbx)
1123
1124 (cond
1125 (gud-mips-p
1126 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
1127 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
1128 (gud-def gud-break "stop at \"%f\":%l"
1129 "\C-b" "Set breakpoint at current line.")
1130 (gud-def gud-finish "return" "\C-f" "Finish executing current function."))
1131 (gud-irix-p
1132 (gud-def gud-break "stop at \"%d%f\":%l"
1133 "\C-b" "Set breakpoint at current line.")
1134 (gud-def gud-finish "return" "\C-f" "Finish executing current function.")
1135 (gud-def gud-up "up %p; printf \"\032\032%1d:\",(int)$curline;file\n"
1136 "<" "Up (numeric arg) stack frames.")
1137 (gud-def gud-down "down %p; printf \"\032\032%1d:\",(int)$curline;file\n"
1138 ">" "Down (numeric arg) stack frames.")
1139 ;; Make dbx give out the source location info that we need.
1140 (process-send-string (get-buffer-process gud-comint-buffer)
1141 "printf \"\032\032%1d:\",(int)$curline;file\n"))
1142 (t
1143 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
1144 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
1145 (gud-def gud-break "file \"%d%f\"\nstop at %l"
1146 "\C-b" "Set breakpoint at current line.")
1147 (if gud-dbx-use-stopformat-p
1148 (process-send-string (get-buffer-process gud-comint-buffer)
1149 "set $stopformat=1\n"))))
1150
1151 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
1152 (gud-def gud-step "step %p" "\C-s" "Step one line with display.")
1153 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
1154 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).")
deaef289 1155 (gud-def gud-nexti "nexti %p" nil "Step one instruction (skip functions).")
0f9c2d46
JB
1156 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
1157 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
deaef289 1158 (gud-def gud-run "run" nil "Run the program.")
0f9c2d46
JB
1159
1160 (setq comint-prompt-regexp "^[^)\n]*dbx) *")
1161 (setq paragraph-start comint-prompt-regexp)
1162 (run-hooks 'dbx-mode-hook)
1163 )
1164\f
1165;; ======================================================================
1166;; xdb (HP PARISC debugger) functions
1167
1168;; History of argument lists passed to xdb.
1169(defvar gud-xdb-history nil)
1170
1171(defcustom gud-xdb-directories nil
1172 "*A list of directories that xdb should search for source code.
1173If nil, only source files in the program directory
1174will be known to xdb.
1175
1176The file names should be absolute, or relative to the directory
1177containing the executable being debugged."
1178 :type '(choice (const :tag "Current Directory" nil)
1179 (repeat :value ("")
1180 directory))
1181 :group 'gud)
1182
1183(defun gud-xdb-massage-args (file args)
1184 (nconc (let ((directories gud-xdb-directories)
1185 (result nil))
1186 (while directories
1187 (setq result (cons (car directories) (cons "-d" result)))
1188 (setq directories (cdr directories)))
1189 (nreverse result))
1190 args))
1191
1192;; xdb does not print the lines all at once, so we have to accumulate them
1193(defun gud-xdb-marker-filter (string)
1194 (let (result)
1195 (if (or (string-match comint-prompt-regexp string)
1196 (string-match ".*\012" string))
1197 (setq result (concat gud-marker-acc string)
1198 gud-marker-acc "")
1199 (setq gud-marker-acc (concat gud-marker-acc string)))
1200 (if result
1201 (if (or (string-match "\\([^\n \t:]+\\): [^:]+: \\([0-9]+\\)[: ]"
1202 result)
1203 (string-match "[^: \t]+:[ \t]+\\([^:]+\\): [^:]+: \\([0-9]+\\):"
1204 result))
0d2794e3 1205 (let ((line (string-to-number (match-string 2 result)))
0f9c2d46
JB
1206 (file (gud-file-name (match-string 1 result))))
1207 (if file
1208 (setq gud-last-frame (cons file line))))))
1209 (or result "")))
1210
1211;;;###autoload
1212(defun xdb (command-line)
1213 "Run xdb on program FILE in buffer *gud-FILE*.
1214The directory containing FILE becomes the initial working directory
1215and source-file directory for your debugger.
1216
1217You can set the variable 'gud-xdb-directories' to a list of program source
1218directories if your program contains sources from more than one directory."
1219 (interactive (list (gud-query-cmdline 'xdb)))
1220
1221 (gud-common-init command-line 'gud-xdb-massage-args
1222 'gud-xdb-marker-filter)
1223 (set (make-local-variable 'gud-minor-mode) 'xdb)
1224
1225 (gud-def gud-break "b %f:%l" "\C-b" "Set breakpoint at current line.")
1226 (gud-def gud-tbreak "b %f:%l\\t" "\C-t"
1227 "Set temporary breakpoint at current line.")
1228 (gud-def gud-remove "db" "\C-d" "Remove breakpoint at current line")
1229 (gud-def gud-step "s %p" "\C-s" "Step one line with display.")
1230 (gud-def gud-next "S %p" "\C-n" "Step one line (skip functions).")
1231 (gud-def gud-cont "c" "\C-r" "Continue with display.")
1232 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
1233 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
1234 (gud-def gud-finish "bu\\t" "\C-f" "Finish executing current function.")
1235 (gud-def gud-print "p %e" "\C-p" "Evaluate C expression at point.")
1236
1237 (setq comint-prompt-regexp "^>")
1238 (setq paragraph-start comint-prompt-regexp)
1239 (run-hooks 'xdb-mode-hook))
1240\f
1241;; ======================================================================
1242;; perldb functions
1243
1244;; History of argument lists passed to perldb.
1245(defvar gud-perldb-history nil)
1246
1247(defun gud-perldb-massage-args (file args)
1248 "Convert a command line as would be typed normally to run perldb
1249into one that invokes an Emacs-enabled debugging session.
1250\"-emacs\" is inserted where it will be $ARGV[0] (see perl5db.pl)."
1251 ;; FIXME: what if the command is `make perldb' and doesn't accept those extra
1252 ;; arguments ?
1253 (let* ((new-args nil)
1254 (seen-e nil)
1255 (shift (lambda () (push (pop args) new-args))))
1256
1257 ;; Pass all switches and -e scripts through.
1258 (while (and args
1259 (string-match "^-" (car args))
1260 (not (equal "-" (car args)))
1261 (not (equal "--" (car args))))
1262 (when (equal "-e" (car args))
1263 ;; -e goes with the next arg, so shift one extra.
1264 (or (funcall shift)
1265 ;; -e as the last arg is an error in Perl.
1266 (error "No code specified for -e"))
1267 (setq seen-e t))
1268 (funcall shift))
1269
1270 (unless seen-e
1271 (if (or (not args)
1272 (string-match "^-" (car args)))
1273 (error "Can't use stdin as the script to debug"))
1274 ;; This is the program name.
1275 (funcall shift))
1276
1277 ;; If -e specified, make sure there is a -- so -emacs is not taken
1278 ;; as -e macs.
1279 (if (and args (equal "--" (car args)))
1280 (funcall shift)
1281 (and seen-e (push "--" new-args)))
1282
1283 (push "-emacs" new-args)
1284 (while args
1285 (funcall shift))
1286
1287 (nreverse new-args)))
1288
1289;; There's no guarantee that Emacs will hand the filter the entire
1290;; marker at once; it could be broken up across several strings. We
1291;; might even receive a big chunk with several markers in it. If we
1292;; receive a chunk of text which looks like it might contain the
1293;; beginning of a marker, we save it here between calls to the
1294;; filter.
1295(defun gud-perldb-marker-filter (string)
1296 (setq gud-marker-acc (concat gud-marker-acc string))
1297 (let ((output ""))
1298
1299 ;; Process all the complete markers in this chunk.
1300 (while (string-match "\032\032\\(\\([a-zA-Z]:\\)?[^:\n]*\\):\\([0-9]*\\):.*\n"
1301 gud-marker-acc)
1302 (setq
1303
1304 ;; Extract the frame position from the marker.
1305 gud-last-frame
1306 (cons (match-string 1 gud-marker-acc)
0d2794e3 1307 (string-to-number (match-string 3 gud-marker-acc)))
0f9c2d46
JB
1308
1309 ;; Append any text before the marker to the output we're going
1310 ;; to return - we don't include the marker in this text.
1311 output (concat output
1312 (substring gud-marker-acc 0 (match-beginning 0)))
1313
1314 ;; Set the accumulator to the remaining text.
1315 gud-marker-acc (substring gud-marker-acc (match-end 0))))
1316
1317 ;; Does the remaining text look like it might end with the
1318 ;; beginning of another marker? If it does, then keep it in
1319 ;; gud-marker-acc until we receive the rest of it. Since we
1320 ;; know the full marker regexp above failed, it's pretty simple to
1321 ;; test for marker starts.
1322 (if (string-match "\032.*\\'" gud-marker-acc)
1323 (progn
1324 ;; Everything before the potential marker start can be output.
1325 (setq output (concat output (substring gud-marker-acc
1326 0 (match-beginning 0))))
1327
1328 ;; Everything after, we save, to combine with later input.
1329 (setq gud-marker-acc
1330 (substring gud-marker-acc (match-beginning 0))))
1331
1332 (setq output (concat output gud-marker-acc)
1333 gud-marker-acc ""))
1334
1335 output))
1336
1337(defcustom gud-perldb-command-name "perl -d"
1338 "Default command to execute a Perl script under debugger."
1339 :type 'string
1340 :group 'gud)
1341
1342;;;###autoload
1343(defun perldb (command-line)
1344 "Run perldb on program FILE in buffer *gud-FILE*.
1345The directory containing FILE becomes the initial working directory
1346and source-file directory for your debugger."
1347 (interactive
1348 (list (gud-query-cmdline 'perldb
1349 (concat (or (buffer-file-name) "-e 0") " "))))
1350
1351 (gud-common-init command-line 'gud-perldb-massage-args
1352 'gud-perldb-marker-filter)
1353 (set (make-local-variable 'gud-minor-mode) 'perldb)
1354
1355 (gud-def gud-break "b %l" "\C-b" "Set breakpoint at current line.")
1dd52b82 1356 (gud-def gud-remove "B %l" "\C-d" "Remove breakpoint at current line")
0f9c2d46
JB
1357 (gud-def gud-step "s" "\C-s" "Step one source line with display.")
1358 (gud-def gud-next "n" "\C-n" "Step one line (skip functions).")
1359 (gud-def gud-cont "c" "\C-r" "Continue with display.")
1360; (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
1361; (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
1362; (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
8a7bc7b8 1363 (gud-def gud-print "p %e" "\C-p" "Evaluate perl expression at point.")
1dd52b82
NR
1364 (gud-def gud-until "c %l" "\C-u" "Continue to current line.")
1365
0f9c2d46
JB
1366
1367 (setq comint-prompt-regexp "^ DB<+[0-9]+>+ ")
1368 (setq paragraph-start comint-prompt-regexp)
1369 (run-hooks 'perldb-mode-hook))
1370\f
1371;; ======================================================================
1372;; pdb (Python debugger) functions
1373
1374;; History of argument lists passed to pdb.
1375(defvar gud-pdb-history nil)
1376
1377;; Last group is for return value, e.g. "> test.py(2)foo()->None"
1378;; Either file or function name may be omitted: "> <string>(0)?()"
1379(defvar gud-pdb-marker-regexp
1380 "^> \\([-a-zA-Z0-9_/.:\\]*\\|<string>\\)(\\([0-9]+\\))\\([a-zA-Z0-9_]*\\|\\?\\)()\\(->[^\n]*\\)?\n")
1381(defvar gud-pdb-marker-regexp-file-group 1)
1382(defvar gud-pdb-marker-regexp-line-group 2)
1383(defvar gud-pdb-marker-regexp-fnname-group 3)
1384
1385(defvar gud-pdb-marker-regexp-start "^> ")
1386
1387;; There's no guarantee that Emacs will hand the filter the entire
1388;; marker at once; it could be broken up across several strings. We
1389;; might even receive a big chunk with several markers in it. If we
1390;; receive a chunk of text which looks like it might contain the
1391;; beginning of a marker, we save it here between calls to the
1392;; filter.
1393(defun gud-pdb-marker-filter (string)
1394 (setq gud-marker-acc (concat gud-marker-acc string))
1395 (let ((output ""))
1396
1397 ;; Process all the complete markers in this chunk.
1398 (while (string-match gud-pdb-marker-regexp gud-marker-acc)
1399 (setq
1400
1401 ;; Extract the frame position from the marker.
1402 gud-last-frame
1403 (let ((file (match-string gud-pdb-marker-regexp-file-group
1404 gud-marker-acc))
0d2794e3 1405 (line (string-to-number
0f9c2d46
JB
1406 (match-string gud-pdb-marker-regexp-line-group
1407 gud-marker-acc))))
1408 (if (string-equal file "<string>")
1409 gud-last-frame
1410 (cons file line)))
1411
1412 ;; Output everything instead of the below
1413 output (concat output (substring gud-marker-acc 0 (match-end 0)))
1414;; ;; Append any text before the marker to the output we're going
1415;; ;; to return - we don't include the marker in this text.
1416;; output (concat output
1417;; (substring gud-marker-acc 0 (match-beginning 0)))
1418
1419 ;; Set the accumulator to the remaining text.
1420 gud-marker-acc (substring gud-marker-acc (match-end 0))))
1421
1422 ;; Does the remaining text look like it might end with the
1423 ;; beginning of another marker? If it does, then keep it in
1424 ;; gud-marker-acc until we receive the rest of it. Since we
1425 ;; know the full marker regexp above failed, it's pretty simple to
1426 ;; test for marker starts.
1427 (if (string-match gud-pdb-marker-regexp-start gud-marker-acc)
1428 (progn
1429 ;; Everything before the potential marker start can be output.
1430 (setq output (concat output (substring gud-marker-acc
1431 0 (match-beginning 0))))
1432
1433 ;; Everything after, we save, to combine with later input.
1434 (setq gud-marker-acc
1435 (substring gud-marker-acc (match-beginning 0))))
1436
1437 (setq output (concat output gud-marker-acc)
1438 gud-marker-acc ""))
1439
1440 output))
1441
6f120f70 1442(defcustom gud-pdb-command-name "pdb"
0f9c2d46
JB
1443 "File name for executing the Python debugger.
1444This should be an executable on your path, or an absolute file name."
1445 :type 'string
1446 :group 'gud)
1447
1448;;;###autoload
1449(defun pdb (command-line)
1450 "Run pdb on program FILE in buffer `*gud-FILE*'.
1451The directory containing FILE becomes the initial working directory
1452and source-file directory for your debugger."
1453 (interactive
1454 (list (gud-query-cmdline 'pdb)))
1455
1456 (gud-common-init command-line nil 'gud-pdb-marker-filter)
1457 (set (make-local-variable 'gud-minor-mode) 'pdb)
1458
1459 (gud-def gud-break "break %l" "\C-b" "Set breakpoint at current line.")
1460 (gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line")
1461 (gud-def gud-step "step" "\C-s" "Step one source line with display.")
1462 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
1463 (gud-def gud-cont "continue" "\C-r" "Continue with display.")
1464 (gud-def gud-finish "return" "\C-f" "Finish executing current function.")
1465 (gud-def gud-up "up" "<" "Up one stack frame.")
1466 (gud-def gud-down "down" ">" "Down one stack frame.")
1467 (gud-def gud-print "p %e" "\C-p" "Evaluate Python expression at point.")
1468 ;; Is this right?
1469 (gud-def gud-statement "! %e" "\C-e" "Execute Python statement at point.")
1470
1471 ;; (setq comint-prompt-regexp "^(.*pdb[+]?) *")
1472 (setq comint-prompt-regexp "^(Pdb) *")
1473 (setq paragraph-start comint-prompt-regexp)
1474 (run-hooks 'pdb-mode-hook))
1475\f
1476;; ======================================================================
1477;;
1478;; JDB support.
1479;;
1480;; AUTHOR: Derek Davies <ddavies@world.std.com>
1481;; Zoltan Kemenczy <zoltan@ieee.org;zkemenczy@rim.net>
1482;;
1483;; CREATED: Sun Feb 22 10:46:38 1998 Derek Davies.
1484;; UPDATED: Nov 11, 2001 Zoltan Kemenczy
1485;; Dec 10, 2002 Zoltan Kemenczy - added nested class support
1486;;
1487;; INVOCATION NOTES:
1488;;
1489;; You invoke jdb-mode with:
1490;;
1491;; M-x jdb <enter>
1492;;
1493;; It responds with:
1494;;
1495;; Run jdb (like this): jdb
1496;;
1497;; type any jdb switches followed by the name of the class you'd like to debug.
1498;; Supply a fully qualfied classname (these do not have the ".class" extension)
1499;; for the name of the class to debug (e.g. "COM.the-kind.ddavies.CoolClass").
1500;; See the known problems section below for restrictions when specifying jdb
1501;; command line switches (search forward for '-classpath').
1502;;
1503;; You should see something like the following:
1504;;
1505;; Current directory is ~/src/java/hello/
1506;; Initializing jdb...
1507;; 0xed2f6628:class(hello)
1508;; >
1509;;
1510;; To set an initial breakpoint try:
1511;;
1512;; > stop in hello.main
1513;; Breakpoint set in hello.main
1514;; >
1515;;
1516;; To execute the program type:
1517;;
1518;; > run
1519;; run hello
1520;;
1521;; Breakpoint hit: running ...
1522;; hello.main (hello:12)
1523;;
1524;; Type M-n to step over the current line and M-s to step into it. That,
1525;; along with the JDB 'help' command should get you started. The 'quit'
1526;; JDB command will get out out of the debugger. There is some truly
1527;; pathetic JDB documentation available at:
1528;;
1529;; http://java.sun.com/products/jdk/1.1/debugging/
1530;;
1531;; KNOWN PROBLEMS AND FIXME's:
1532;;
1533;; Not sure what happens with inner classes ... haven't tried them.
1534;;
1535;; Does not grok UNICODE id's. Only ASCII id's are supported.
1536;;
1537;; You must not put whitespace between "-classpath" and the path to
1538;; search for java classes even though it is required when invoking jdb
1539;; from the command line. See gud-jdb-massage-args for details.
1540;; The same applies for "-sourcepath".
1541;;
1542;; Note: The following applies only if `gud-jdb-use-classpath' is nil;
1543;; refer to the documentation of `gud-jdb-use-classpath' and
1544;; `gud-jdb-classpath',`gud-jdb-sourcepath' variables for information
1545;; on using the classpath for locating java source files.
1546;;
1547;; If any of the source files in the directories listed in
1548;; gud-jdb-directories won't parse you'll have problems. Make sure
1549;; every file ending in ".java" in these directories parses without error.
1550;;
1551;; All the .java files in the directories in gud-jdb-directories are
1552;; syntactically analyzed each time gud jdb is invoked. It would be
1553;; nice to keep as much information as possible between runs. It would
1554;; be really nice to analyze the files only as neccessary (when the
1555;; source needs to be displayed.) I'm not sure to what extent the former
1556;; can be accomplished and I'm not sure the latter can be done at all
1557;; since I don't know of any general way to tell which .class files are
1558;; defined by which .java file without analyzing all the .java files.
1559;; If anyone knows why JavaSoft didn't put the source file names in
1560;; debuggable .class files please clue me in so I find something else
1561;; to be spiteful and bitter about.
1562;;
1563;; ======================================================================
1564;; gud jdb variables and functions
1565
1566(defcustom gud-jdb-command-name "jdb"
1567 "Command that executes the Java debugger."
1568 :type 'string
1569 :group 'gud)
1570
1571(defcustom gud-jdb-use-classpath t
1572 "If non-nil, search for Java source files in classpath directories.
1573The list of directories to search is the value of `gud-jdb-classpath'.
1574The file pathname is obtained by converting the fully qualified
1575class information output by jdb to a relative pathname and appending
1576it to `gud-jdb-classpath' element by element until a match is found.
1577
1578This method has a significant jdb startup time reduction advantage
1579since it does not require the scanning of all `gud-jdb-directories'
1580and parsing all Java files for class information.
1581
1582Set to nil to use `gud-jdb-directories' to scan java sources for
1583class information on jdb startup (original method)."
1584 :type 'boolean
1585 :group 'gud)
1586
1587(defvar gud-jdb-classpath nil
1588 "Java/jdb classpath directories list.
1589If `gud-jdb-use-classpath' is non-nil, gud-jdb derives the `gud-jdb-classpath'
1590list automatically using the following methods in sequence
1591\(with subsequent successful steps overriding the results of previous
1592steps):
1593
15941) Read the CLASSPATH environment variable,
15952) Read any \"-classpath\" argument used to run jdb,
1596 or detected in jdb output (e.g. if jdb is run by a script
1597 that echoes the actual jdb command before starting jdb)
15983) Send a \"classpath\" command to jdb and scan jdb output for
1599 classpath information if jdb is invoked with an \"-attach\" (to
1600 an already running VM) argument (This case typically does not
1601 have a \"-classpath\" command line argument - that is provided
1602 to the VM when it is started).
1603
1604Note that method 3 cannot be used with oldjdb (or Java 1 jdb) since
1605those debuggers do not support the classpath command. Use 1) or 2).")
1606
1607(defvar gud-jdb-sourcepath nil
1608 "Directory list provided by an (optional) \"-sourcepath\" option to jdb.
1609This list is prepended to `gud-jdb-classpath' to form the complete
1610list of directories searched for source files.")
1611
1612(defvar gud-marker-acc-max-length 4000
1613 "Maximum number of debugger output characters to keep.
1614This variable limits the size of `gud-marker-acc' which holds
1615the most recent debugger output history while searching for
1616source file information.")
1617
1618(defvar gud-jdb-history nil
1619"History of argument lists passed to jdb.")
1620
1621
1622;; List of Java source file directories.
1623(defvar gud-jdb-directories (list ".")
1624 "*A list of directories that gud jdb should search for source code.
1625The file names should be absolute, or relative to the current
1626directory.
1627
1628The set of .java files residing in the directories listed are
1629syntactically analyzed to determine the classes they define and the
1630packages in which these classes belong. In this way gud jdb maps the
1631package-qualified class names output by the jdb debugger to the source
1632file from which the class originated. This allows gud mode to keep
1633the source code display in sync with the debugging session.")
1634
1635(defvar gud-jdb-source-files nil
1636"List of the java source files for this debugging session.")
1637
1638;; Association list of fully qualified class names (package + class name)
1639;; and their source files.
1640(defvar gud-jdb-class-source-alist nil
1641"Association list of fully qualified class names and source files.")
1642
1643;; This is used to hold a source file during analysis.
1644(defvar gud-jdb-analysis-buffer nil)
1645
1646(defvar gud-jdb-classpath-string nil
1647"Holds temporary classpath values.")
1648
1649(defun gud-jdb-build-source-files-list (path extn)
1650"Return a list of java source files (absolute paths).
1651PATH gives the directories in which to search for files with
1652extension EXTN. Normally EXTN is given as the regular expression
1653 \"\\.java$\" ."
1654 (apply 'nconc (mapcar (lambda (d)
1655 (when (file-directory-p d)
1656 (directory-files d t extn nil)))
1657 path)))
1658
1659;; Move point past whitespace.
1660(defun gud-jdb-skip-whitespace ()
1661 (skip-chars-forward " \n\r\t\014"))
1662
1663;; Move point past a "// <eol>" type of comment.
1664(defun gud-jdb-skip-single-line-comment ()
1665 (end-of-line))
1666
1667;; Move point past a "/* */" or "/** */" type of comment.
1668(defun gud-jdb-skip-traditional-or-documentation-comment ()
1669 (forward-char 2)
1670 (catch 'break
1671 (while (not (eobp))
1672 (if (eq (following-char) ?*)
1673 (progn
1674 (forward-char)
1675 (if (not (eobp))
1676 (if (eq (following-char) ?/)
1677 (progn
1678 (forward-char)
1679 (throw 'break nil)))))
1680 (forward-char)))))
1681
1682;; Move point past any number of consecutive whitespace chars and/or comments.
1683(defun gud-jdb-skip-whitespace-and-comments ()
1684 (gud-jdb-skip-whitespace)
1685 (catch 'done
1686 (while t
1687 (cond
1688 ((looking-at "//")
1689 (gud-jdb-skip-single-line-comment)
1690 (gud-jdb-skip-whitespace))
1691 ((looking-at "/\\*")
1692 (gud-jdb-skip-traditional-or-documentation-comment)
1693 (gud-jdb-skip-whitespace))
1694 (t (throw 'done nil))))))
1695
1696;; Move point past things that are id-like. The intent is to skip regular
1697;; id's, such as class or interface names as well as package and interface
1698;; names.
1699(defun gud-jdb-skip-id-ish-thing ()
1700 (skip-chars-forward "^ /\n\r\t\014,;{"))
1701
1702;; Move point past a string literal.
1703(defun gud-jdb-skip-string-literal ()
1704 (forward-char)
1705 (while (not (cond
1706 ((eq (following-char) ?\\)
1707 (forward-char))
1708 ((eq (following-char) ?\042))))
1709 (forward-char))
1710 (forward-char))
1711
1712;; Move point past a character literal.
1713(defun gud-jdb-skip-character-literal ()
1714 (forward-char)
1715 (while
1716 (progn
1717 (if (eq (following-char) ?\\)
1718 (forward-char 2))
1719 (not (eq (following-char) ?\')))
1720 (forward-char))
1721 (forward-char))
1722
1723;; Move point past the following block. There may be (legal) cruft before
1724;; the block's opening brace. There must be a block or it's the end of life
1725;; in petticoat junction.
1726(defun gud-jdb-skip-block ()
1727
1728 ;; Find the begining of the block.
1729 (while
1730 (not (eq (following-char) ?{))
1731
1732 ;; Skip any constructs that can harbor literal block delimiter
1733 ;; characters and/or the delimiters for the constructs themselves.
1734 (cond
1735 ((looking-at "//")
1736 (gud-jdb-skip-single-line-comment))
1737 ((looking-at "/\\*")
1738 (gud-jdb-skip-traditional-or-documentation-comment))
1739 ((eq (following-char) ?\042)
1740 (gud-jdb-skip-string-literal))
1741 ((eq (following-char) ?\')
1742 (gud-jdb-skip-character-literal))
1743 (t (forward-char))))
1744
1745 ;; Now at the begining of the block.
1746 (forward-char)
1747
1748 ;; Skip over the body of the block as well as the final brace.
1749 (let ((open-level 1))
1750 (while (not (eq open-level 0))
1751 (cond
1752 ((looking-at "//")
1753 (gud-jdb-skip-single-line-comment))
1754 ((looking-at "/\\*")
1755 (gud-jdb-skip-traditional-or-documentation-comment))
1756 ((eq (following-char) ?\042)
1757 (gud-jdb-skip-string-literal))
1758 ((eq (following-char) ?\')
1759 (gud-jdb-skip-character-literal))
1760 ((eq (following-char) ?{)
1761 (setq open-level (+ open-level 1))
1762 (forward-char))
1763 ((eq (following-char) ?})
1764 (setq open-level (- open-level 1))
1765 (forward-char))
1766 (t (forward-char))))))
1767
1768;; Find the package and class definitions in Java source file FILE. Assumes
1769;; that FILE contains a legal Java program. BUF is a scratch buffer used
1770;; to hold the source during analysis.
1771(defun gud-jdb-analyze-source (buf file)
1772 (let ((l nil))
1773 (set-buffer buf)
1774 (insert-file-contents file nil nil nil t)
1775 (goto-char 0)
1776 (catch 'abort
1777 (let ((p ""))
1778 (while (progn
1779 (gud-jdb-skip-whitespace)
1780 (not (eobp)))
1781 (cond
1782
1783 ;; Any number of semi's following a block is legal. Move point
1784 ;; past them. Note that comments and whitespace may be
1785 ;; interspersed as well.
1786 ((eq (following-char) ?\073)
1787 (forward-char))
1788
1789 ;; Move point past a single line comment.
1790 ((looking-at "//")
1791 (gud-jdb-skip-single-line-comment))
1792
1793 ;; Move point past a traditional or documentation comment.
1794 ((looking-at "/\\*")
1795 (gud-jdb-skip-traditional-or-documentation-comment))
1796
1797 ;; Move point past a package statement, but save the PackageName.
1798 ((looking-at "package")
1799 (forward-char 7)
1800 (gud-jdb-skip-whitespace-and-comments)
1801 (let ((s (point)))
1802 (gud-jdb-skip-id-ish-thing)
1803 (setq p (concat (buffer-substring s (point)) "."))
1804 (gud-jdb-skip-whitespace-and-comments)
1805 (if (eq (following-char) ?\073)
1806 (forward-char))))
1807
1808 ;; Move point past an import statement.
1809 ((looking-at "import")
1810 (forward-char 6)
1811 (gud-jdb-skip-whitespace-and-comments)
1812 (gud-jdb-skip-id-ish-thing)
1813 (gud-jdb-skip-whitespace-and-comments)
1814 (if (eq (following-char) ?\073)
1815 (forward-char)))
1816
1817 ;; Move point past the various kinds of ClassModifiers.
1818 ((looking-at "public")
1819 (forward-char 6))
1820 ((looking-at "abstract")
1821 (forward-char 8))
1822 ((looking-at "final")
1823 (forward-char 5))
1824
1825 ;; Move point past a ClassDeclaraction, but save the class
1826 ;; Identifier.
1827 ((looking-at "class")
1828 (forward-char 5)
1829 (gud-jdb-skip-whitespace-and-comments)
1830 (let ((s (point)))
1831 (gud-jdb-skip-id-ish-thing)
1832 (setq
1833 l (nconc l (list (concat p (buffer-substring s (point)))))))
1834 (gud-jdb-skip-block))
1835
1836 ;; Move point past an interface statement.
1837 ((looking-at "interface")
1838 (forward-char 9)
1839 (gud-jdb-skip-block))
1840
1841 ;; Anything else means the input is invalid.
1842 (t
1843 (message (format "Error parsing file %s." file))
1844 (throw 'abort nil))))))
1845 l))
1846
1847(defun gud-jdb-build-class-source-alist-for-file (file)
1848 (mapcar
1849 (lambda (c)
1850 (cons c file))
1851 (gud-jdb-analyze-source gud-jdb-analysis-buffer file)))
1852
1853;; Return an alist of fully qualified classes and the source files
1854;; holding their definitions. SOURCES holds a list of all the source
1855;; files to examine.
1856(defun gud-jdb-build-class-source-alist (sources)
1857 (setq gud-jdb-analysis-buffer (get-buffer-create " *gud-jdb-scratch*"))
1858 (prog1
1859 (apply
1860 'nconc
1861 (mapcar
1862 'gud-jdb-build-class-source-alist-for-file
1863 sources))
1864 (kill-buffer gud-jdb-analysis-buffer)
1865 (setq gud-jdb-analysis-buffer nil)))
1866
1867;; Change what was given in the minibuffer to something that can be used to
1868;; invoke the debugger.
1869(defun gud-jdb-massage-args (file args)
1870 ;; The jdb executable must have whitespace between "-classpath" and
1871 ;; its value while gud-common-init expects all switch values to
1872 ;; follow the switch keyword without intervening whitespace. We
1873 ;; require that when the user enters the "-classpath" switch in the
1874 ;; EMACS minibuffer that they do so without the intervening
1875 ;; whitespace. This function adds it back (it's called after
1876 ;; gud-common-init). There are more switches like this (for
1877 ;; instance "-host" and "-password") but I don't care about them
1878 ;; yet.
1879 (if args
1880 (let (massaged-args user-error)
1881
1882 (while (and args (not user-error))
1883 (cond
1884 ((setq user-error (string-match "-classpath$" (car args))))
1885 ((setq user-error (string-match "-sourcepath$" (car args))))
1886 ((string-match "-classpath\\(.+\\)" (car args))
1887 (setq massaged-args
1888 (append massaged-args
1889 (list "-classpath"
1890 (setq gud-jdb-classpath-string
1891 (match-string 1 (car args)))))))
1892 ((string-match "-sourcepath\\(.+\\)" (car args))
1893 (setq massaged-args
1894 (append massaged-args
1895 (list "-sourcepath"
1896 (setq gud-jdb-sourcepath
1897 (match-string 1 (car args)))))))
1898 (t (setq massaged-args (append massaged-args (list (car args))))))
1899 (setq args (cdr args)))
1900
1901 ;; By this point the current directory is all screwed up. Maybe we
1902 ;; could fix things and re-invoke gud-common-init, but for now I think
1903 ;; issueing the error is good enough.
1904 (if user-error
1905 (progn
1906 (kill-buffer (current-buffer))
1907 (error "Error: Omit whitespace between '-classpath or -sourcepath' and its value")))
1908 massaged-args)))
1909
1910;; Search for an association with P, a fully qualified class name, in
1911;; gud-jdb-class-source-alist. The asssociation gives the fully
1912;; qualified file name of the source file which produced the class.
1913(defun gud-jdb-find-source-file (p)
1914 (cdr (assoc p gud-jdb-class-source-alist)))
1915
1916;; Note: Reset to this value every time a prompt is seen
1917(defvar gud-jdb-lowest-stack-level 999)
1918
1919(defun gud-jdb-find-source-using-classpath (p)
1920"Find source file corresponding to fully qualified class p.
1921Convert p from jdb's output, converted to a pathname
1922relative to a classpath directory."
1923 (save-match-data
1924 (let
1925 (;; Replace dots with slashes and append ".java" to generate file
1926 ;; name relative to classpath
1927 (filename
1928 (concat
1929 (mapconcat 'identity
1930 (split-string
1931 ;; Eliminate any subclass references in the class
1932 ;; name string. These start with a "$"
1933 ((lambda (x)
1934 (if (string-match "$.*" x)
1935 (replace-match "" t t x) p))
1936 p)
1937 "\\.") "/")
1938 ".java"))
1939 (cplist (append gud-jdb-sourcepath gud-jdb-classpath))
1940 found-file)
1941 (while (and cplist
1942 (not (setq found-file
1943 (file-readable-p
1944 (concat (car cplist) "/" filename)))))
1945 (setq cplist (cdr cplist)))
1946 (if found-file (concat (car cplist) "/" filename)))))
1947
1948(defun gud-jdb-find-source (string)
1949"Alias for function used to locate source files.
1950Set to `gud-jdb-find-source-using-classpath' or `gud-jdb-find-source-file'
1951during jdb initialization depending on the value of
1952`gud-jdb-use-classpath'."
1953nil)
1954
1955(defun gud-jdb-parse-classpath-string (string)
1956"Parse the classpath list and convert each item to an absolute pathname."
1957 (mapcar (lambda (s) (if (string-match "[/\\]$" s)
1958 (replace-match "" nil nil s) s))
1959 (mapcar 'file-truename
1960 (split-string
1961 string
1962 (concat "[ \t\n\r,\"" path-separator "]+")))))
1963
1964;; See comentary for other debugger's marker filters - there you will find
1965;; important notes about STRING.
1966(defun gud-jdb-marker-filter (string)
1967
1968 ;; Build up the accumulator.
1969 (setq gud-marker-acc
1970 (if gud-marker-acc
1971 (concat gud-marker-acc string)
1972 string))
1973
1974 ;; Look for classpath information until gud-jdb-classpath-string is found
1975 ;; (interactive, multiple settings of classpath from jdb
1976 ;; not supported/followed)
1977 (if (and gud-jdb-use-classpath
1978 (not gud-jdb-classpath-string)
1979 (or (string-match "classpath:[ \t[]+\\([^]]+\\)" gud-marker-acc)
1980 (string-match "-classpath[ \t\"]+\\([^ \"]+\\)" gud-marker-acc)))
1981 (setq gud-jdb-classpath
1982 (gud-jdb-parse-classpath-string
1983 (setq gud-jdb-classpath-string
1984 (match-string 1 gud-marker-acc)))))
1985
1986 ;; We process STRING from left to right. Each time through the
1987 ;; following loop we process at most one marker. After we've found a
1988 ;; marker, delete gud-marker-acc up to and including the match
1989 (let (file-found)
1990 ;; Process each complete marker in the input.
1991 (while
1992
1993 ;; Do we see a marker?
1994 (string-match
1995 ;; jdb puts out a string of the following form when it
1996 ;; hits a breakpoint:
1997 ;;
1998 ;; <fully-qualified-class><method> (<class>:<line-number>)
1999 ;;
2000 ;; <fully-qualified-class>'s are composed of Java ID's
2001 ;; separated by periods. <method> and <class> are
2002 ;; also Java ID's. <method> begins with a period and
2003 ;; may contain less-than and greater-than (constructors,
2004 ;; for instance, are called <init> in the symbol table.)
2005 ;; Java ID's begin with a letter followed by letters
2006 ;; and/or digits. The set of letters includes underscore
2007 ;; and dollar sign.
2008 ;;
2009 ;; The first group matches <fully-qualified-class>,
2010 ;; the second group matches <class> and the third group
2011 ;; matches <line-number>. We don't care about using
2012 ;; <method> so we don't "group" it.
2013 ;;
2014 ;; FIXME: Java ID's are UNICODE strings, this matches ASCII
2015 ;; ID's only.
2016 ;;
a0c3f8bc
NR
2017 ;; The ".," in the last square-bracket are necessary because
2018 ;; of Sun's total disrespect for backwards compatibility in
0f9c2d46 2019 ;; reported line numbers from jdb - starting in 1.4.0 they
a0c3f8bc
NR
2020 ;; print line numbers using LOCALE, inserting a comma or a
2021 ;; period at the thousands positions (how ingenious!).
0f9c2d46
JB
2022
2023 "\\(\[[0-9]+\] \\)*\\([a-zA-Z0-9.$_]+\\)\\.[a-zA-Z0-9$_<>(),]+ \
a0c3f8bc 2024\\(([a-zA-Z0-9.$_]+:\\|line=\\)\\([0-9.,]+\\)"
0f9c2d46
JB
2025 gud-marker-acc)
2026
2027 ;; A good marker is one that:
2028 ;; 1) does not have a "[n] " prefix (not part of a stack backtrace)
2029 ;; 2) does have an "[n] " prefix and n is the lowest prefix seen
2030 ;; since the last prompt
2031 ;; Figure out the line on which to position the debugging arrow.
2032 ;; Return the info as a cons of the form:
2033 ;;
2034 ;; (<file-name> . <line-number>) .
2035 (if (if (match-beginning 1)
2036 (let (n)
0d2794e3 2037 (setq n (string-to-number (substring
0f9c2d46
JB
2038 gud-marker-acc
2039 (1+ (match-beginning 1))
2040 (- (match-end 1) 2))))
2041 (if (< n gud-jdb-lowest-stack-level)
2042 (progn (setq gud-jdb-lowest-stack-level n) t)))
2043 t)
2044 (if (setq file-found
2045 (gud-jdb-find-source (match-string 2 gud-marker-acc)))
2046 (setq gud-last-frame
2047 (cons file-found
0d2794e3 2048 (string-to-number
0f9c2d46
JB
2049 (let
2050 ((numstr (match-string 4 gud-marker-acc)))
a0c3f8bc 2051 (if (string-match "[.,]" numstr)
0f9c2d46
JB
2052 (replace-match "" nil nil numstr)
2053 numstr)))))
2054 (message "Could not find source file.")))
2055
2056 ;; Set the accumulator to the remaining text.
2057 (setq gud-marker-acc (substring gud-marker-acc (match-end 0))))
2058
2059 (if (string-match comint-prompt-regexp gud-marker-acc)
2060 (setq gud-jdb-lowest-stack-level 999)))
2061
2062 ;; Do not allow gud-marker-acc to grow without bound. If the source
2063 ;; file information is not within the last 3/4
2064 ;; gud-marker-acc-max-length characters, well,...
2065 (if (> (length gud-marker-acc) gud-marker-acc-max-length)
2066 (setq gud-marker-acc
2067 (substring gud-marker-acc
2068 (- (/ (* gud-marker-acc-max-length 3) 4)))))
2069
2070 ;; We don't filter any debugger output so just return what we were given.
2071 string)
2072
2073(defvar gud-jdb-command-name "jdb" "Command that executes the Java debugger.")
2074
2075;;;###autoload
2076(defun jdb (command-line)
2077 "Run jdb with command line COMMAND-LINE in a buffer.
2078The buffer is named \"*gud*\" if no initial class is given or
2079\"*gud-<initial-class-basename>*\" if there is. If the \"-classpath\"
2080switch is given, omit all whitespace between it and its value.
2081
2082See `gud-jdb-use-classpath' and `gud-jdb-classpath' documentation for
2083information on how jdb accesses source files. Alternatively (if
2084`gud-jdb-use-classpath' is nil), see `gud-jdb-directories' for the
2085original source file access method.
2086
2087For general information about commands available to control jdb from
2088gud, see `gud-mode'."
2089 (interactive
2090 (list (gud-query-cmdline 'jdb)))
2091 (setq gud-jdb-classpath nil)
2092 (setq gud-jdb-sourcepath nil)
2093
2094 ;; Set gud-jdb-classpath from the CLASSPATH environment variable,
2095 ;; if CLASSPATH is set.
2096 (setq gud-jdb-classpath-string (getenv "CLASSPATH"))
2097 (if gud-jdb-classpath-string
2098 (setq gud-jdb-classpath
2099 (gud-jdb-parse-classpath-string gud-jdb-classpath-string)))
2100 (setq gud-jdb-classpath-string nil) ; prepare for next
2101
2102 (gud-common-init command-line 'gud-jdb-massage-args
2103 'gud-jdb-marker-filter)
2104 (set (make-local-variable 'gud-minor-mode) 'jdb)
2105
2106 ;; If a -classpath option was provided, set gud-jdb-classpath
2107 (if gud-jdb-classpath-string
2108 (setq gud-jdb-classpath
2109 (gud-jdb-parse-classpath-string gud-jdb-classpath-string)))
2110 (setq gud-jdb-classpath-string nil) ; prepare for next
2111 ;; If a -sourcepath option was provided, parse it
2112 (if gud-jdb-sourcepath
2113 (setq gud-jdb-sourcepath
2114 (gud-jdb-parse-classpath-string gud-jdb-sourcepath)))
2115
2116 (gud-def gud-break "stop at %c:%l" "\C-b" "Set breakpoint at current line.")
2117 (gud-def gud-remove "clear %c:%l" "\C-d" "Remove breakpoint at current line")
2118 (gud-def gud-step "step" "\C-s" "Step one source line with display.")
2119 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
2120 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
2121 (gud-def gud-finish "step up" "\C-f" "Continue until current method returns.")
2122 (gud-def gud-up "up\C-Mwhere" "<" "Up one stack frame.")
2123 (gud-def gud-down "down\C-Mwhere" ">" "Up one stack frame.")
2124 (gud-def gud-run "run" nil "Run the program.") ;if VM start using jdb
2125
2126 (setq comint-prompt-regexp "^> \\|^[^ ]+\\[[0-9]+\\] ")
2127 (setq paragraph-start comint-prompt-regexp)
2128 (run-hooks 'jdb-mode-hook)
2129
2130 (if gud-jdb-use-classpath
2131 ;; Get the classpath information from the debugger
2132 (progn
2133 (if (string-match "-attach" command-line)
2134 (gud-call "classpath"))
2135 (fset 'gud-jdb-find-source
2136 'gud-jdb-find-source-using-classpath))
2137
2138 ;; Else create and bind the class/source association list as well
2139 ;; as the source file list.
2140 (setq gud-jdb-class-source-alist
2141 (gud-jdb-build-class-source-alist
2142 (setq gud-jdb-source-files
2143 (gud-jdb-build-source-files-list gud-jdb-directories
2144 "\\.java$"))))
2145 (fset 'gud-jdb-find-source 'gud-jdb-find-source-file)))
2146\f
2147
2148;; ======================================================================
2149;;
2150;; BASHDB support. See http://bashdb.sourceforge.net
2151;;
2152;; AUTHOR: Rocky Bernstein <rocky@panix.com>
2153;;
2154;; CREATED: Sun Nov 10 10:46:38 2002 Rocky Bernstein.
2155;;
2156;; INVOCATION NOTES:
2157;;
2158;; You invoke bashdb-mode with:
2159;;
2160;; M-x bashdb <enter>
2161;;
2162;; It responds with:
2163;;
2164;; Run bashdb (like this): bash
2165;;
2166
2167;; History of argument lists passed to bashdb.
2168(defvar gud-bashdb-history nil)
2169
2170;; Convert a command line as would be typed normally to run a script
2171;; into one that invokes an Emacs-enabled debugging session.
2172;; "--debugger" in inserted as the first switch.
2173
2174;; There's no guarantee that Emacs will hand the filter the entire
2175;; marker at once; it could be broken up across several strings. We
2176;; might even receive a big chunk with several markers in it. If we
2177;; receive a chunk of text which looks like it might contain the
2178;; beginning of a marker, we save it here between calls to the
2179;; filter.
2180(defun gud-bashdb-marker-filter (string)
2181 (setq gud-marker-acc (concat gud-marker-acc string))
2182 (let ((output ""))
2183
2184 ;; Process all the complete markers in this chunk.
2185 ;; Format of line looks like this:
2186 ;; (/etc/init.d/ntp.init:16):
2187 ;; but we also allow DOS drive letters
2188 ;; (d:/etc/init.d/ntp.init:16):
2189 (while (string-match "\\(^\\|\n\\)(\\(\\([a-zA-Z]:\\)?[^:\n]*\\):\\([0-9]*\\)):.*\n"
2190 gud-marker-acc)
2191 (setq
2192
2193 ;; Extract the frame position from the marker.
2194 gud-last-frame
2195 (cons (match-string 2 gud-marker-acc)
0d2794e3 2196 (string-to-number (match-string 4 gud-marker-acc)))
0f9c2d46
JB
2197
2198 ;; Append any text before the marker to the output we're going
2199 ;; to return - we don't include the marker in this text.
2200 output (concat output
2201 (substring gud-marker-acc 0 (match-beginning 0)))
2202
2203 ;; Set the accumulator to the remaining text.
2204 gud-marker-acc (substring gud-marker-acc (match-end 0))))
2205
2206 ;; Does the remaining text look like it might end with the
2207 ;; beginning of another marker? If it does, then keep it in
2208 ;; gud-marker-acc until we receive the rest of it. Since we
2209 ;; know the full marker regexp above failed, it's pretty simple to
2210 ;; test for marker starts.
2211 (if (string-match "\032.*\\'" gud-marker-acc)
2212 (progn
2213 ;; Everything before the potential marker start can be output.
2214 (setq output (concat output (substring gud-marker-acc
2215 0 (match-beginning 0))))
2216
2217 ;; Everything after, we save, to combine with later input.
2218 (setq gud-marker-acc
2219 (substring gud-marker-acc (match-beginning 0))))
2220
2221 (setq output (concat output gud-marker-acc)
2222 gud-marker-acc ""))
2223
2224 output))
2225
2226(defcustom gud-bashdb-command-name "bash --debugger"
2227 "File name for executing bash debugger."
2228 :type 'string
2229 :group 'gud)
2230
2231;;;###autoload
2232(defun bashdb (command-line)
2233 "Run bashdb on program FILE in buffer *gud-FILE*.
2234The directory containing FILE becomes the initial working directory
2235and source-file directory for your debugger."
2236 (interactive
2237 (list (read-from-minibuffer "Run bashdb (like this): "
2238 (if (consp gud-bashdb-history)
2239 (car gud-bashdb-history)
2240 (concat gud-bashdb-command-name
2241 " "))
2242 gud-minibuffer-local-map nil
2243 '(gud-bashdb-history . 1))))
2244
2245 (gud-common-init command-line nil 'gud-bashdb-marker-filter)
2246
2247 (set (make-local-variable 'gud-minor-mode) 'bashdb)
2248
2249 (gud-def gud-break "break %l" "\C-b" "Set breakpoint at current line.")
2250 (gud-def gud-tbreak "tbreak %l" "\C-t" "Set temporary breakpoint at current line.")
2251 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
2252 (gud-def gud-step "step" "\C-s" "Step one source line with display.")
2253 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
2254 (gud-def gud-cont "continue" "\C-r" "Continue with display.")
2255 (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
2256 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
2257 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
2258 (gud-def gud-print "x %e" "\C-p" "Evaluate BASH expression at point.")
2259
2260 ;; Is this right?
2261 (gud-def gud-statement "eval %e" "\C-e" "Execute BASH statement at point.")
2262
2263 (setq comint-prompt-regexp "^bashdb<+(*[0-9]+)*>+ ")
2264 (setq paragraph-start comint-prompt-regexp)
2265 (run-hooks 'bashdb-mode-hook)
2266 )
2267
2268;;
2269;; End of debugger-specific information
2270;;
2271
2272\f
2273;; When we send a command to the debugger via gud-call, it's annoying
2274;; to see the command and the new prompt inserted into the debugger's
2275;; buffer; we have other ways of knowing the command has completed.
2276;;
2277;; If the buffer looks like this:
2278;; --------------------
2279;; (gdb) set args foo bar
2280;; (gdb) -!-
2281;; --------------------
2282;; (the -!- marks the location of point), and we type `C-x SPC' in a
2283;; source file to set a breakpoint, we want the buffer to end up like
2284;; this:
2285;; --------------------
2286;; (gdb) set args foo bar
2287;; Breakpoint 1 at 0x92: file make-docfile.c, line 49.
2288;; (gdb) -!-
2289;; --------------------
2290;; Essentially, the old prompt is deleted, and the command's output
2291;; and the new prompt take its place.
2292;;
2293;; Not echoing the command is easy enough; you send it directly using
2294;; process-send-string, and it never enters the buffer. However,
2295;; getting rid of the old prompt is trickier; you don't want to do it
2296;; when you send the command, since that will result in an annoying
2297;; flicker as the prompt is deleted, redisplay occurs while Emacs
2298;; waits for a response from the debugger, and the new prompt is
2299;; inserted. Instead, we'll wait until we actually get some output
2300;; from the subprocess before we delete the prompt. If the command
2301;; produced no output other than a new prompt, that prompt will most
2302;; likely be in the first chunk of output received, so we will delete
2303;; the prompt and then replace it with an identical one. If the
2304;; command produces output, the prompt is moving anyway, so the
2305;; flicker won't be annoying.
2306;;
2307;; So - when we want to delete the prompt upon receipt of the next
2308;; chunk of debugger output, we position gud-delete-prompt-marker at
2309;; the start of the prompt; the process filter will notice this, and
2310;; delete all text between it and the process output marker. If
2311;; gud-delete-prompt-marker points nowhere, we leave the current
2312;; prompt alone.
2313(defvar gud-delete-prompt-marker nil)
2314
2315\f
2316(put 'gud-mode 'mode-class 'special)
2317
2318(define-derived-mode gud-mode comint-mode "Debugger"
2319 "Major mode for interacting with an inferior debugger process.
2320
2321 You start it up with one of the commands M-x gdb, M-x sdb, M-x dbx,
2322M-x perldb, M-x xdb, or M-x jdb. Each entry point finishes by executing a
2323hook; `gdb-mode-hook', `sdb-mode-hook', `dbx-mode-hook',
2324`perldb-mode-hook', `xdb-mode-hook', or `jdb-mode-hook' respectively.
2325
2326After startup, the following commands are available in both the GUD
2327interaction buffer and any source buffer GUD visits due to a breakpoint stop
2328or step operation:
2329
2330\\[gud-break] sets a breakpoint at the current file and line. In the
2331GUD buffer, the current file and line are those of the last breakpoint or
2332step. In a source buffer, they are the buffer's file and current line.
2333
2334\\[gud-remove] removes breakpoints on the current file and line.
2335
2336\\[gud-refresh] displays in the source window the last line referred to
2337in the gud buffer.
2338
2339\\[gud-step], \\[gud-next], and \\[gud-stepi] do a step-one-line,
2340step-one-line (not entering function calls), and step-one-instruction
2341and then update the source window with the current file and position.
2342\\[gud-cont] continues execution.
2343
2344\\[gud-print] tries to find the largest C lvalue or function-call expression
2345around point, and sends it to the debugger for value display.
2346
2347The above commands are common to all supported debuggers except xdb which
2348does not support stepping instructions.
2349
2350Under gdb, sdb and xdb, \\[gud-tbreak] behaves exactly like \\[gud-break],
2351except that the breakpoint is temporary; that is, it is removed when
2352execution stops on it.
2353
2354Under gdb, dbx, and xdb, \\[gud-up] pops up through an enclosing stack
2355frame. \\[gud-down] drops back down through one.
2356
2357If you are using gdb or xdb, \\[gud-finish] runs execution to the return from
2358the current function and stops.
2359
2360All the keystrokes above are accessible in the GUD buffer
2361with the prefix C-c, and in all buffers through the prefix C-x C-a.
2362
2363All pre-defined functions for which the concept make sense repeat
2364themselves the appropriate number of times if you give a prefix
2365argument.
2366
2367You may use the `gud-def' macro in the initialization hook to define other
2368commands.
2369
2370Other commands for interacting with the debugger process are inherited from
2371comint mode, which see."
2372 (setq mode-line-process '(":%s"))
2373 (define-key (current-local-map) "\C-c\C-l" 'gud-refresh)
2374 (set (make-local-variable 'gud-last-frame) nil)
2375 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
2376 (make-local-variable 'comint-prompt-regexp)
2377 ;; Don't put repeated commands in command history many times.
2378 (set (make-local-variable 'comint-input-ignoredups) t)
2379 (make-local-variable 'paragraph-start)
68b872d2
NR
2380 (set (make-local-variable 'gud-delete-prompt-marker) (make-marker))
2381 (add-hook 'kill-buffer-hook 'gud-kill-buffer-hook nil t))
0f9c2d46
JB
2382
2383;; Cause our buffers to be displayed, by default,
2384;; in the selected window.
2385;;;###autoload (add-hook 'same-window-regexps "\\*gud-.*\\*\\(\\|<[0-9]+>\\)")
2386
2387(defcustom gud-chdir-before-run t
2388 "Non-nil if GUD should `cd' to the debugged executable."
2389 :group 'gud
2390 :type 'boolean)
2391
2392(defvar gud-target-name "--unknown--"
2393 "The apparent name of the program being debugged in a gud buffer.")
2394
2395;; Perform initializations common to all debuggers.
2396;; The first arg is the specified command line,
2397;; which starts with the program to debug.
2398;; The other three args specify the values to use
2399;; for local variables in the debugger buffer.
2400(defun gud-common-init (command-line massage-args marker-filter
2401 &optional find-file)
2402 (let* ((words (split-string command-line))
2403 (program (car words))
2404 (dir default-directory)
2405 ;; Extract the file name from WORDS
2406 ;; and put t in its place.
2407 ;; Later on we will put the modified file name arg back there.
2408 (file-word (let ((w (cdr words)))
2409 (while (and w (= ?- (aref (car w) 0)))
2410 (setq w (cdr w)))
2411 (and w
2412 (prog1 (car w)
2413 (setcar w t)))))
2414 (file-subst
2415 (and file-word (substitute-in-file-name file-word)))
2416 (args (cdr words))
2417 ;; If a directory was specified, expand the file name.
2418 ;; Otherwise, don't expand it, so GDB can use the PATH.
2419 ;; A file name without directory is literally valid
2420 ;; only if the file exists in ., and in that case,
2421 ;; omitting the expansion here has no visible effect.
2422 (file (and file-word
2423 (if (file-name-directory file-subst)
2424 (expand-file-name file-subst)
2425 file-subst)))
5ab26292
NR
2426 (filepart (and file-word (concat "-" (file-name-nondirectory file))))
2427 (existing-buffer (get-buffer (concat "*gud" filepart "*"))))
0f9c2d46 2428 (pop-to-buffer (concat "*gud" filepart "*"))
f9878c26
MB
2429 (when (and existing-buffer (get-buffer-process existing-buffer))
2430 (error "This program is already running under gdb"))
0f9c2d46
JB
2431 ;; Set the dir, in case the buffer already existed with a different dir.
2432 (setq default-directory dir)
2433 ;; Set default-directory to the file's directory.
2434 (and file-word
2435 gud-chdir-before-run
2436 ;; Don't set default-directory if no directory was specified.
2437 ;; In that case, either the file is found in the current directory,
2438 ;; in which case this setq is a no-op,
2439 ;; or it is found by searching PATH,
2440 ;; in which case we don't know what directory it was found in.
2441 (file-name-directory file)
2442 (setq default-directory (file-name-directory file)))
2443 (or (bolp) (newline))
2444 (insert "Current directory is " default-directory "\n")
2445 ;; Put the substituted and expanded file name back in its place.
2446 (let ((w args))
2447 (while (and w (not (eq (car w) t)))
2448 (setq w (cdr w)))
2449 (if w
2450 (setcar w file)))
2451 (apply 'make-comint (concat "gud" filepart) program nil
2452 (if massage-args (funcall massage-args file args) args))
2453 ;; Since comint clobbered the mode, we don't set it until now.
2454 (gud-mode)
2455 (set (make-local-variable 'gud-target-name)
2456 (and file-word (file-name-nondirectory file))))
2457 (set (make-local-variable 'gud-marker-filter) marker-filter)
2458 (if find-file (set (make-local-variable 'gud-find-file) find-file))
2459 (setq gud-running nil)
2460 (setq gud-last-last-frame nil)
2461
2462 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter)
2463 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel)
2464 (gud-set-buffer))
2465
2466(defun gud-set-buffer ()
2467 (when (eq major-mode 'gud-mode)
2468 (setq gud-comint-buffer (current-buffer))))
2469
2470(defvar gud-filter-defer-flag nil
2471 "Non-nil means don't process anything from the debugger right now.
2472It is saved for when this flag is not set.")
2473
0f9c2d46
JB
2474;; These functions are responsible for inserting output from your debugger
2475;; into the buffer. The hard work is done by the method that is
2476;; the value of gud-marker-filter.
2477
2478(defun gud-filter (proc string)
2479 ;; Here's where the actual buffer insertion is done
2480 (let (output process-window)
2481 (if (buffer-name (process-buffer proc))
2482 (if gud-filter-defer-flag
2483 ;; If we can't process any text now,
2484 ;; save it for later.
2485 (setq gud-filter-pending-text
2486 (concat (or gud-filter-pending-text "") string))
2487
2488 ;; If we have to ask a question during the processing,
2489 ;; defer any additional text that comes from the debugger
2490 ;; during that time.
2491 (let ((gud-filter-defer-flag t))
2492 ;; Process now any text we previously saved up.
2493 (if gud-filter-pending-text
2494 (setq string (concat gud-filter-pending-text string)
2495 gud-filter-pending-text nil))
2496
2497 (with-current-buffer (process-buffer proc)
2498 ;; If we have been so requested, delete the debugger prompt.
2499 (save-restriction
2500 (widen)
2501 (if (marker-buffer gud-delete-prompt-marker)
2502 (progn
2503 (delete-region (process-mark proc)
2504 gud-delete-prompt-marker)
2505 (set-marker gud-delete-prompt-marker nil)))
2506 ;; Save the process output, checking for source file markers.
2507 (setq output (gud-marker-filter string))
2508 ;; Check for a filename-and-line number.
2509 ;; Don't display the specified file
2510 ;; unless (1) point is at or after the position where output appears
2511 ;; and (2) this buffer is on the screen.
2512 (setq process-window
2513 (and gud-last-frame
2514 (>= (point) (process-mark proc))
2515 (get-buffer-window (current-buffer)))))
2516
2517 ;; Let the comint filter do the actual insertion.
2518 ;; That lets us inherit various comint features.
2519 (comint-output-filter proc output))
2520
2521 ;; Put the arrow on the source line.
2522 ;; This must be outside of the save-excursion
2523 ;; in case the source file is our current buffer.
2524 (if process-window
2525 (save-selected-window
2526 (select-window process-window)
2527 (gud-display-frame))
2528 ;; We have to be in the proper buffer, (process-buffer proc),
2529 ;; but not in a save-excursion, because that would restore point.
2530 (let ((old-buf (current-buffer)))
2531 (set-buffer (process-buffer proc))
2532 (unwind-protect
2533 (gud-display-frame)
2534 (set-buffer old-buf)))))
2535
2536 ;; If we deferred text that arrived during this processing,
2537 ;; handle it now.
2538 (if gud-filter-pending-text
2539 (gud-filter proc ""))))))
2540
2541(defvar gud-minor-mode-type nil)
63cc3b09 2542(defvar gud-overlay-arrow-position nil)
63cc3b09 2543(add-to-list 'overlay-arrow-variable-list 'gud-overlay-arrow-position)
0f9c2d46
JB
2544
2545(defun gud-sentinel (proc msg)
2546 (cond ((null (buffer-name (process-buffer proc)))
2547 ;; buffer killed
2548 ;; Stop displaying an arrow in a source file.
63cc3b09 2549 (setq gud-overlay-arrow-position nil)
0f9c2d46 2550 (set-process-buffer proc nil)
129adb6f 2551 (if (memq gud-minor-mode-type '(gdbmi gdba))
0f9c2d46
JB
2552 (gdb-reset)
2553 (gud-reset)))
2554 ((memq (process-status proc) '(signal exit))
2555 ;; Stop displaying an arrow in a source file.
63cc3b09 2556 (setq gud-overlay-arrow-position nil)
0f9c2d46 2557 (with-current-buffer gud-comint-buffer
129adb6f 2558 (if (memq gud-minor-mode-type '(gdbmi gdba))
0f9c2d46
JB
2559 (gdb-reset)
2560 (gud-reset)))
2561 (let* ((obuf (current-buffer)))
2562 ;; save-excursion isn't the right thing if
2563 ;; process-buffer is current-buffer
2564 (unwind-protect
2565 (progn
2566 ;; Write something in *compilation* and hack its mode line,
2567 (set-buffer (process-buffer proc))
2568 ;; Fix the mode line.
2569 (setq mode-line-process
2570 (concat ":"
2571 (symbol-name (process-status proc))))
2572 (force-mode-line-update)
2573 (if (eobp)
2574 (insert ?\n mode-name " " msg)
2575 (save-excursion
2576 (goto-char (point-max))
2577 (insert ?\n mode-name " " msg)))
2578 ;; If buffer and mode line will show that the process
2579 ;; is dead, we can delete it now. Otherwise it
2580 ;; will stay around until M-x list-processes.
2581 (delete-process proc))
2582 ;; Restore old buffer, but don't restore old point
2583 ;; if obuf is the gud buffer.
2584 (set-buffer obuf))))))
2585
2586(defun gud-kill-buffer-hook ()
68b872d2
NR
2587 (setq gud-minor-mode-type gud-minor-mode)
2588 (condition-case nil
2589 (kill-process (get-buffer-process gud-comint-buffer))
2590 (error nil)))
0f9c2d46
JB
2591
2592(defun gud-reset ()
2593 (dolist (buffer (buffer-list))
27149c58
SM
2594 (unless (eq buffer gud-comint-buffer)
2595 (with-current-buffer buffer
2596 (when gud-minor-mode
2597 (setq gud-minor-mode nil)
2598 (kill-local-variable 'tool-bar-map))))))
0f9c2d46
JB
2599
2600(defun gud-display-frame ()
2601 "Find and obey the last filename-and-line marker from the debugger.
2602Obeying it means displaying in another window the specified file and line."
2603 (interactive)
2604 (when gud-last-frame
2605 (gud-set-buffer)
2606 (gud-display-line (car gud-last-frame) (cdr gud-last-frame))
2607 (setq gud-last-last-frame gud-last-frame
2608 gud-last-frame nil)))
2609
2610;; Make sure the file named TRUE-FILE is in a buffer that appears on the screen
2611;; and that its line LINE is visible.
2612;; Put the overlay-arrow on the line LINE in that buffer.
2613;; Most of the trickiness in here comes from wanting to preserve the current
2614;; region-restriction if that's possible. We use an explicit display-buffer
2615;; to get around the fact that this is called inside a save-excursion.
2616
2617(defun gud-display-line (true-file line)
2618 (let* ((last-nonmenu-event t) ; Prevent use of dialog box for questions.
2619 (buffer
2620 (with-current-buffer gud-comint-buffer
2621 (gud-find-file true-file)))
2622 (window (and buffer (or (get-buffer-window buffer)
1236e386 2623 (display-buffer buffer))))
0f9c2d46
JB
2624 (pos))
2625 (if buffer
2626 (progn
2627 (with-current-buffer buffer
37fdcfbc
NR
2628 (unless (or (verify-visited-file-modtime buffer) gud-keep-buffer)
2629 (if (yes-or-no-p
0f9c2d46
JB
2630 (format "File %s changed on disk. Reread from disk? "
2631 (buffer-name)))
2632 (revert-buffer t t)
37fdcfbc 2633 (setq gud-keep-buffer t)))
0f9c2d46
JB
2634 (save-restriction
2635 (widen)
2636 (goto-line line)
2637 (setq pos (point))
63cc3b09
NR
2638 (or gud-overlay-arrow-position
2639 (setq gud-overlay-arrow-position (make-marker)))
2640 (set-marker gud-overlay-arrow-position (point) (current-buffer)))
0f9c2d46 2641 (cond ((or (< pos (point-min)) (> pos (point-max)))
37fdcfbc
NR
2642 (widen)
2643 (goto-char pos))))
63cc3b09 2644 (if window (set-window-point window gud-overlay-arrow-position))))))
0f9c2d46
JB
2645
2646;; The gud-call function must do the right thing whether its invoking
2647;; keystroke is from the GUD buffer itself (via major-mode binding)
2648;; or a C buffer. In the former case, we want to supply data from
2649;; gud-last-frame. Here's how we do it:
2650
2651(defun gud-format-command (str arg)
2652 (let ((insource (not (eq (current-buffer) gud-comint-buffer)))
2653 (frame (or gud-last-frame gud-last-last-frame))
2654 result)
2655 (while (and str (string-match "\\([^%]*\\)%\\([adeflpc]\\)" str))
2656 (let ((key (string-to-char (match-string 2 str)))
2657 subst)
2658 (cond
2659 ((eq key ?f)
2660 (setq subst (file-name-nondirectory (if insource
2661 (buffer-file-name)
2662 (car frame)))))
2663 ((eq key ?F)
2664 (setq subst (file-name-sans-extension
2665 (file-name-nondirectory (if insource
2666 (buffer-file-name)
2667 (car frame))))))
2668 ((eq key ?d)
2669 (setq subst (file-name-directory (if insource
2670 (buffer-file-name)
2671 (car frame)))))
2672 ((eq key ?l)
2673 (setq subst (int-to-string
2674 (if insource
2675 (save-restriction
2676 (widen)
2677 (+ (count-lines (point-min) (point))
2678 (if (bolp) 1 0)))
2679 (cdr frame)))))
2680 ((eq key ?e)
deaef289 2681 (setq subst (gud-find-expr)))
0f9c2d46
JB
2682 ((eq key ?a)
2683 (setq subst (gud-read-address)))
2684 ((eq key ?c)
2685 (setq subst
2686 (gud-find-class
2687 (if insource
2688 (buffer-file-name)
2689 (car frame))
2690 (if insource
2691 (save-restriction
2692 (widen)
2693 (+ (count-lines (point-min) (point))
2694 (if (bolp) 1 0)))
2695 (cdr frame)))))
2696 ((eq key ?p)
2697 (setq subst (if arg (int-to-string arg)))))
2698 (setq result (concat result (match-string 1 str) subst)))
2699 (setq str (substring str (match-end 2))))
2700 ;; There might be text left in STR when the loop ends.
2701 (concat result str)))
2702
2703(defun gud-read-address ()
2704 "Return a string containing the core-address found in the buffer at point."
2705 (save-match-data
2706 (save-excursion
2707 (let ((pt (point)) found begin)
2708 (setq found (if (search-backward "0x" (- pt 7) t) (point)))
2709 (cond
2710 (found (forward-char 2)
2711 (buffer-substring found
2712 (progn (re-search-forward "[^0-9a-f]")
2713 (forward-char -1)
2714 (point))))
2715 (t (setq begin (progn (re-search-backward "[^0-9]")
2716 (forward-char 1)
2717 (point)))
2718 (forward-char 1)
2719 (re-search-forward "[^0-9]")
2720 (forward-char -1)
2721 (buffer-substring begin (point))))))))
2722
2723(defun gud-call (fmt &optional arg)
2724 (let ((msg (gud-format-command fmt arg)))
2725 (message "Command: %s" msg)
2726 (sit-for 0)
2727 (gud-basic-call msg)))
2728
2729(defun gud-basic-call (command)
2730 "Invoke the debugger COMMAND displaying source in other window."
2731 (interactive)
2732 (gud-set-buffer)
2733 (let ((proc (get-buffer-process gud-comint-buffer)))
2734 (or proc (error "Current buffer has no process"))
2735 ;; Arrange for the current prompt to get deleted.
2736 (save-excursion
2737 (set-buffer gud-comint-buffer)
2738 (save-restriction
2739 (widen)
2740 (goto-char (process-mark proc))
2741 (forward-line 0)
2742 (if (looking-at comint-prompt-regexp)
2743 (set-marker gud-delete-prompt-marker (point)))
129adb6f 2744 (if (memq gud-minor-mode '(gdbmi gdba))
0f9c2d46
JB
2745 (apply comint-input-sender (list proc command))
2746 (process-send-string proc (concat command "\n")))))))
2747
2748(defun gud-refresh (&optional arg)
2749 "Fix up a possibly garbled display, and redraw the arrow."
2750 (interactive "P")
2751 (or gud-last-frame (setq gud-last-frame gud-last-last-frame))
2752 (gud-display-frame)
2753 (recenter arg))
2754\f
deaef289
NR
2755;; Code for parsing expressions out of C or Fortran code. The single entry
2756;; point is gud-find-expr, which tries to return an lvalue expression from
2757;; around point.
2758
c3f6b2b4 2759(defvar gud-find-expr-function 'gud-find-c-expr)
deaef289
NR
2760
2761(defun gud-find-expr (&rest args)
c3f6b2b4 2762 (apply gud-find-expr-function args))
deaef289
NR
2763
2764;; The next eight functions are hacked from gdbsrc.el by
0f9c2d46
JB
2765;; Debby Ayers <ayers@asc.slb.com>,
2766;; Rich Schaefer <schaefer@asc.slb.com> Schlumberger, Austin, Tx.
2767
2768(defun gud-find-c-expr ()
deaef289 2769 "Returns the expr that surrounds point."
0f9c2d46
JB
2770 (interactive)
2771 (save-excursion
deaef289
NR
2772 (let ((p (point))
2773 (expr (gud-innermost-expr))
2774 (test-expr (gud-prev-expr)))
0f9c2d46
JB
2775 (while (and test-expr (gud-expr-compound test-expr expr))
2776 (let ((prev-expr expr))
2777 (setq expr (cons (car test-expr) (cdr expr)))
2778 (goto-char (car expr))
2779 (setq test-expr (gud-prev-expr))
2780 ;; If we just pasted on the condition of an if or while,
2781 ;; throw it away again.
2782 (if (member (buffer-substring (car test-expr) (cdr test-expr))
2783 '("if" "while" "for"))
2784 (setq test-expr nil
2785 expr prev-expr))))
2786 (goto-char p)
2787 (setq test-expr (gud-next-expr))
2788 (while (gud-expr-compound expr test-expr)
2789 (setq expr (cons (car expr) (cdr test-expr)))
2790 (setq test-expr (gud-next-expr)))
2791 (buffer-substring (car expr) (cdr expr)))))
2792
2793(defun gud-innermost-expr ()
2794 "Returns the smallest expr that point is in; move point to beginning of it.
2795The expr is represented as a cons cell, where the car specifies the point in
2796the current buffer that marks the beginning of the expr and the cdr specifies
2797the character after the end of the expr."
2798 (let ((p (point)) begin end)
2799 (gud-backward-sexp)
2800 (setq begin (point))
2801 (gud-forward-sexp)
2802 (setq end (point))
2803 (if (>= p end)
2804 (progn
2805 (setq begin p)
2806 (goto-char p)
2807 (gud-forward-sexp)
2808 (setq end (point)))
2809 )
2810 (goto-char begin)
2811 (cons begin end)))
2812
2813(defun gud-backward-sexp ()
2814 "Version of `backward-sexp' that catches errors."
2815 (condition-case nil
2816 (backward-sexp)
2817 (error t)))
2818
2819(defun gud-forward-sexp ()
2820 "Version of `forward-sexp' that catches errors."
2821 (condition-case nil
2822 (forward-sexp)
2823 (error t)))
2824
2825(defun gud-prev-expr ()
2826 "Returns the previous expr, point is set to beginning of that expr.
2827The expr is represented as a cons cell, where the car specifies the point in
2828the current buffer that marks the beginning of the expr and the cdr specifies
2829the character after the end of the expr"
2830 (let ((begin) (end))
2831 (gud-backward-sexp)
2832 (setq begin (point))
2833 (gud-forward-sexp)
2834 (setq end (point))
2835 (goto-char begin)
2836 (cons begin end)))
2837
2838(defun gud-next-expr ()
2839 "Returns the following expr, point is set to beginning of that expr.
2840The expr is represented as a cons cell, where the car specifies the point in
2841the current buffer that marks the beginning of the expr and the cdr specifies
2842the character after the end of the expr."
2843 (let ((begin) (end))
2844 (gud-forward-sexp)
2845 (gud-forward-sexp)
2846 (setq end (point))
2847 (gud-backward-sexp)
2848 (setq begin (point))
2849 (cons begin end)))
2850
2851(defun gud-expr-compound-sep (span-start span-end)
2852 "Scan from SPAN-START to SPAN-END for punctuation characters.
2853If `->' is found, return `?.'. If `.' is found, return `?.'.
2854If any other punctuation is found, return `??'.
2855If no punctuation is found, return `? '."
2856 (let ((result ?\ )
2857 (syntax))
2858 (while (< span-start span-end)
2859 (setq syntax (char-syntax (char-after span-start)))
2860 (cond
2861 ((= syntax ?\ ) t)
2862 ((= syntax ?.) (setq syntax (char-after span-start))
2863 (cond
2864 ((= syntax ?.) (setq result ?.))
2865 ((and (= syntax ?-) (= (char-after (+ span-start 1)) ?>))
2866 (setq result ?.)
2867 (setq span-start (+ span-start 1)))
2868 (t (setq span-start span-end)
2869 (setq result ??)))))
2870 (setq span-start (+ span-start 1)))
2871 result))
2872
2873(defun gud-expr-compound (first second)
2874 "Non-nil if concatenating FIRST and SECOND makes a single C expression.
2875The two exprs are represented as a cons cells, where the car
2876specifies the point in the current buffer that marks the beginning of the
2877expr and the cdr specifies the character after the end of the expr.
2878Link exprs of the form:
2879 Expr -> Expr
2880 Expr . Expr
2881 Expr (Expr)
2882 Expr [Expr]
2883 (Expr) Expr
2884 [Expr] Expr"
2885 (let ((span-start (cdr first))
2886 (span-end (car second))
2887 (syntax))
2888 (setq syntax (gud-expr-compound-sep span-start span-end))
2889 (cond
2890 ((= (car first) (car second)) nil)
2891 ((= (cdr first) (cdr second)) nil)
2892 ((= syntax ?.) t)
2893 ((= syntax ?\ )
deaef289
NR
2894 (setq span-start (char-after (- span-start 1)))
2895 (setq span-end (char-after span-end))
2896 (cond
2897 ((= span-start ?)) t)
2898 ((= span-start ?]) t)
2899 ((= span-end ?() t)
2900 ((= span-end ?[) t)
2901 (t nil)))
0f9c2d46
JB
2902 (t nil))))
2903
2904(defun gud-find-class (f line)
2905 "Find fully qualified class in file F at line LINE.
2906This function uses the `gud-jdb-classpath' (and optional
2907`gud-jdb-sourcepath') list(s) to derive a file
2908pathname relative to its classpath directory. The values in
2909`gud-jdb-classpath' are assumed to have been converted to absolute
2910pathname standards using file-truename.
2911If F is visited by a buffer and its mode is CC-mode(Java),
2912syntactic information of LINE is used to find the enclosing (nested)
2913class string which is appended to the top level
2914class of the file (using s to separate nested class ids)."
2915 ;; Convert f to a standard representation and remove suffix
2916 (if (and gud-jdb-use-classpath (or gud-jdb-classpath gud-jdb-sourcepath))
2917 (save-match-data
2918 (let ((cplist (append gud-jdb-sourcepath gud-jdb-classpath))
2919 (fbuffer (get-file-buffer f))
339a559e 2920 syntax-symbol syntax-point class-found)
0f9c2d46 2921 (setq f (file-name-sans-extension (file-truename f)))
339a559e
NR
2922 ;; Syntax-symbol returns the symbol of the *first* element
2923 ;; in the syntactical analysis result list, syntax-point
2924 ;; returns the buffer position of same
2925 (fset 'syntax-symbol (lambda (x) (c-langelem-sym (car x))))
2926 (fset 'syntax-point (lambda (x) (c-langelem-pos (car x))))
0f9c2d46
JB
2927 ;; Search through classpath list for an entry that is
2928 ;; contained in f
2929 (while (and cplist (not class-found))
2930 (if (string-match (car cplist) f)
2931 (setq class-found
2932 (mapconcat 'identity
2933 (split-string
2934 (substring f (+ (match-end 0) 1))
2935 "/") ".")))
2936 (setq cplist (cdr cplist)))
2937 ;; if f is visited by a java(cc-mode) buffer, walk up the
2938 ;; syntactic information chain and collect any 'inclass
2939 ;; symbols until 'topmost-intro is reached to find out if
2940 ;; point is within a nested class
2941 (if (and fbuffer (equal (symbol-file 'java-mode) "cc-mode"))
2942 (save-excursion
2943 (set-buffer fbuffer)
2944 (let ((nclass) (syntax))
2945 ;; While the c-syntactic information does not start
2946 ;; with the 'topmost-intro symbol, there may be
2947 ;; nested classes...
2948 (while (not (eq 'topmost-intro
339a559e 2949 (syntax-symbol (c-guess-basic-syntax))))
0f9c2d46
JB
2950 ;; Check if the current position c-syntactic
2951 ;; analysis has 'inclass
2952 (setq syntax (c-guess-basic-syntax))
2953 (while
339a559e 2954 (and (not (eq 'inclass (syntax-symbol syntax)))
0f9c2d46
JB
2955 (cdr syntax))
2956 (setq syntax (cdr syntax)))
339a559e 2957 (if (eq 'inclass (syntax-symbol syntax))
0f9c2d46 2958 (progn
339a559e 2959 (goto-char (syntax-point syntax))
0f9c2d46
JB
2960 ;; Now we're at the beginning of a class
2961 ;; definition. Find class name
2962 (looking-at
2963 "[A-Za-z0-9 \t\n]*?class[ \t\n]+\\([^ \t\n]+\\)")
2964 (setq nclass
2965 (append (list (match-string-no-properties 1))
2966 nclass)))
2967 (setq syntax (c-guess-basic-syntax))
339a559e 2968 (while (and (not (syntax-point syntax)) (cdr syntax))
0f9c2d46 2969 (setq syntax (cdr syntax)))
339a559e 2970 (goto-char (syntax-point syntax))
0f9c2d46
JB
2971 ))
2972 (string-match (concat (car nclass) "$") class-found)
2973 (setq class-found
2974 (replace-match (mapconcat 'identity nclass "$")
2975 t t class-found)))))
2976 (if (not class-found)
2977 (message "gud-find-class: class for file %s not found!" f))
2978 class-found))
2979 ;; Not using classpath - try class/source association list
2980 (let ((class-found (rassoc f gud-jdb-class-source-alist)))
2981 (if class-found
2982 (car class-found)
2983 (message "gud-find-class: class for file %s not found in gud-jdb-class-source-alist!" f)
2984 nil))))
2985
0d2794e3 2986\f
0f9c2d46
JB
2987;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2988;;; GDB script mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2989;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2990
2991(defvar gdb-script-mode-syntax-table
2992 (let ((st (make-syntax-table)))
2993 (modify-syntax-entry ?' "\"" st)
2994 (modify-syntax-entry ?# "<" st)
2995 (modify-syntax-entry ?\n ">" st)
2996 st))
2997
2998(defvar gdb-script-font-lock-keywords
c5209376
MY
2999 '(("^define\\s-+\\(\\(\\w\\|\\s_\\)+\\)" (1 font-lock-function-name-face))
3000 ("\\$\\(\\w+\\)" (1 font-lock-variable-name-face))
0f9c2d46
JB
3001 ("^\\s-*\\([a-z]+\\)" (1 font-lock-keyword-face))))
3002
3003(defvar gdb-script-font-lock-syntactic-keywords
3004 '(("^document\\s-.*\\(\n\\)" (1 "< b"))
3005 ;; It would be best to change the \n in front, but it's more difficult.
3006 ("^en\\(d\\)\\>" (1 "> b"))))
3007
3008(defun gdb-script-font-lock-syntactic-face (state)
3009 (cond
3010 ((nth 3 state) font-lock-string-face)
3011 ((nth 7 state) font-lock-doc-face)
3012 (t font-lock-comment-face)))
3013
3014(defvar gdb-script-basic-indent 2)
3015
3016(defun gdb-script-skip-to-head ()
3017 "We're just in front of an `end' and we need to go to its head."
3018 (while (and (re-search-backward "^\\s-*\\(\\(end\\)\\|define\\|document\\|if\\|while\\)\\>" nil 'move)
3019 (match-end 2))
3020 (gdb-script-skip-to-head)))
3021
3022(defun gdb-script-calculate-indentation ()
3023 (cond
3024 ((looking-at "end\\>")
3025 (gdb-script-skip-to-head)
3026 (current-indentation))
3027 ((looking-at "else\\>")
3028 (while (and (re-search-backward "^\\s-*\\(if\\|\\(end\\)\\)\\>" nil 'move)
3029 (match-end 2))
3030 (gdb-script-skip-to-head))
3031 (current-indentation))
3032 (t
3033 (forward-comment (- (point-max)))
3034 (forward-line 0)
3035 (skip-chars-forward " \t")
3036 (+ (current-indentation)
3037 (if (looking-at "\\(if\\|while\\|define\\|else\\)\\>")
3038 gdb-script-basic-indent 0)))))
3039
3040(defun gdb-script-indent-line ()
3041 "Indent current line of GDB script."
3042 (interactive)
3043 (if (and (eq (get-text-property (point) 'face) font-lock-doc-face)
3044 (save-excursion
3045 (forward-line 0)
3046 (skip-chars-forward " \t")
3047 (not (looking-at "end\\>"))))
3048 'noindent
3049 (let* ((savep (point))
3050 (indent (condition-case nil
3051 (save-excursion
3052 (forward-line 0)
3053 (skip-chars-forward " \t")
3054 (if (>= (point) savep) (setq savep nil))
3055 (max (gdb-script-calculate-indentation) 0))
3056 (error 0))))
3057 (if savep
3058 (save-excursion (indent-line-to indent))
3059 (indent-line-to indent)))))
3060
e375517f
MY
3061;; Derived from cfengine.el.
3062(defun gdb-script-beginning-of-defun ()
3063 "`beginning-of-defun' function for Gdb script mode.
3064Treats actions as defuns."
3065 (unless (<= (current-column) (current-indentation))
3066 (end-of-line))
3067 (if (re-search-backward "^define \\|^document " nil t)
3068 (beginning-of-line)
3069 (goto-char (point-min)))
3070 t)
3071
3072;; Derived from cfengine.el.
3073(defun gdb-script-end-of-defun ()
3074 "`end-of-defun' function for Gdb script mode.
3075Treats actions as defuns."
3076 (end-of-line)
3077 (if (re-search-forward "^end" nil t)
3078 (beginning-of-line)
3079 (goto-char (point-max)))
3080 t)
3081
0f9c2d46
JB
3082;;;###autoload
3083(add-to-list 'auto-mode-alist '("/\\.gdbinit" . gdb-script-mode))
3084
3085;;;###autoload
3086(define-derived-mode gdb-script-mode nil "GDB-Script"
3087 "Major mode for editing GDB scripts"
3088 (set (make-local-variable 'comment-start) "#")
3089 (set (make-local-variable 'comment-start-skip) "#+\\s-*")
3090 (set (make-local-variable 'outline-regexp) "[ \t]")
3091 (set (make-local-variable 'imenu-generic-expression)
3092 '((nil "^define[ \t]+\\(\\w+\\)" 1)))
3093 (set (make-local-variable 'indent-line-function) 'gdb-script-indent-line)
e375517f
MY
3094 (set (make-local-variable 'beginning-of-defun-function)
3095 #'gdb-script-beginning-of-defun)
3096 (set (make-local-variable 'end-of-defun-function)
3097 #'gdb-script-end-of-defun)
0f9c2d46
JB
3098 (set (make-local-variable 'font-lock-defaults)
3099 '(gdb-script-font-lock-keywords nil nil ((?_ . "w")) nil
3100 (font-lock-syntactic-keywords
3101 . gdb-script-font-lock-syntactic-keywords)
3102 (font-lock-syntactic-face-function
3103 . gdb-script-font-lock-syntactic-face))))
3104
ce38ddb8
NR
3105\f
3106;;; tooltips for GUD
3107
3108;;; Customizable settings
3109(defcustom gud-tooltip-modes '(gud-mode c-mode c++-mode fortran-mode)
3110 "List of modes for which to enable GUD tips."
3111 :type 'sexp
3112 :tag "GUD modes"
3113 :group 'tooltip)
3114
3115(defcustom gud-tooltip-display
3116 '((eq (tooltip-event-buffer gud-tooltip-event)
3117 (marker-buffer gud-overlay-arrow-position)))
3118 "List of forms determining where GUD tooltips are displayed.
3119
3120Forms in the list are combined with AND. The default is to display
3121only tooltips in the buffer containing the overlay arrow."
3122 :type 'sexp
3123 :tag "GUD buffers predicate"
3124 :group 'tooltip)
3125
3126(defcustom gud-tooltip-echo-area nil
3127 "Use the echo area instead of frames for GUD tooltips."
3128 :type 'boolean
3129 :tag "Use echo area"
3130 :group 'tooltip)
3131
3132(define-obsolete-variable-alias 'tooltip-gud-modes
3133 'gud-tooltip-modes "22.1")
3134(define-obsolete-variable-alias 'tooltip-gud-display
3135 'gud-tooltip-display "22.1")
3136(define-obsolete-variable-alias 'tooltip-use-echo-area
3137 'gud-tooltip-echo-area "22.1")
3138
3139;;; Reacting on mouse movements
3140
3141(defun gud-tooltip-change-major-mode ()
3142 "Function added to `change-major-mode-hook' when tooltip mode is on."
3143 (add-hook 'post-command-hook 'gud-tooltip-activate-mouse-motions-if-enabled))
3144
3145(defun gud-tooltip-activate-mouse-motions-if-enabled ()
3146 "Reconsider for all buffers whether mouse motion events are desired."
3147 (remove-hook 'post-command-hook
3148 'gud-tooltip-activate-mouse-motions-if-enabled)
3149 (dolist (buffer (buffer-list))
3150 (save-excursion
3151 (set-buffer buffer)
3152 (if (and gud-tooltip-mode
3153 (memq major-mode gud-tooltip-modes))
3154 (gud-tooltip-activate-mouse-motions t)
3155 (gud-tooltip-activate-mouse-motions nil)))))
3156
3157(defvar gud-tooltip-mouse-motions-active nil
3158 "Locally t in a buffer if tooltip processing of mouse motion is enabled.")
3159
3160(defun gud-tooltip-activate-mouse-motions (activatep)
3161 "Activate/deactivate mouse motion events for the current buffer.
3162ACTIVATEP non-nil means activate mouse motion events."
3163 (if activatep
3164 (progn
3165 (make-local-variable 'gud-tooltip-mouse-motions-active)
3166 (setq gud-tooltip-mouse-motions-active t)
3167 (make-local-variable 'track-mouse)
3168 (setq track-mouse t))
3169 (when gud-tooltip-mouse-motions-active
3170 (kill-local-variable 'gud-tooltip-mouse-motions-active)
3171 (kill-local-variable 'track-mouse))))
3172
3173(defun gud-tooltip-mouse-motion (event)
3174 "Command handler for mouse movement events in `global-map'."
3175 (interactive "e")
3176 (tooltip-hide)
3177 (when (car (mouse-pixel-position))
3178 (setq tooltip-last-mouse-motion-event (copy-sequence event))
3179 (tooltip-start-delayed-tip)))
3180
3181;;; Tips for `gud'
3182
3183(defvar gud-tooltip-original-filter nil
3184 "Process filter to restore after GUD output has been received.")
3185
3186(defvar gud-tooltip-dereference nil
3187 "Non-nil means print expressions with a `*' in front of them.
3188For C this would dereference a pointer expression.")
3189
3190(defvar gud-tooltip-event nil
3191 "The mouse movement event that led to a tooltip display.
3192This event can be examined by forms in GUD-TOOLTIP-DISPLAY.")
3193
be820e8d 3194(defun toggle-gud-tooltip-dereference ()
ce38ddb8
NR
3195 "Toggle whether tooltips should show `* expr' or `expr'."
3196 (interactive)
3197 (setq gud-tooltip-dereference (not gud-tooltip-dereference))
3198 (when (interactive-p)
3199 (message "Dereferencing is now %s."
3200 (if gud-tooltip-dereference "on" "off"))))
3201
3202(define-obsolete-function-alias 'tooltip-gud-toggle-dereference
be820e8d 3203 'toggle-gud-tooltip-dereference "22.1")
ce38ddb8
NR
3204
3205(define-minor-mode gud-tooltip-mode
3206 "Toggle the display of GUD tooltips."
3207 :global t
3208 :group 'gud
df94fa1e 3209 (require 'tooltip)
ce38ddb8
NR
3210 (if gud-tooltip-mode
3211 (progn
3212 (add-hook 'change-major-mode-hook 'gud-tooltip-change-major-mode)
3213 (add-hook 'pre-command-hook 'tooltip-hide)
3214 (add-hook 'tooltip-hook 'gud-tooltip-tips)
3215 (define-key global-map [mouse-movement] 'gud-tooltip-mouse-motion))
3216 (unless tooltip-mode (remove-hook 'pre-command-hook 'tooltip-hide)
2b9688f6 3217 (remove-hook 'change-major-mode-hook 'gud-tooltip-change-major-mode)
ce38ddb8
NR
3218 (remove-hook 'tooltip-hook 'gud-tooltip-tips)
3219 (define-key global-map [mouse-movement] 'ignore)))
3220 (gud-tooltip-activate-mouse-motions-if-enabled)
3221 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
3222 (if gud-tooltip-mode
3223 (progn
3224 (dolist (buffer (buffer-list))
3225 (unless (eq buffer gud-comint-buffer)
3226 (with-current-buffer buffer
3227 (when (and (memq gud-minor-mode '(gdbmi gdba))
3228 (not (string-match "\\`\\*.+\\*\\'"
3229 (buffer-name))))
3230 (make-local-variable 'gdb-define-alist)
3231 (gdb-create-define-alist)
3232 (add-hook 'after-save-hook
3233 'gdb-create-define-alist nil t))))))
3234 (kill-local-variable 'gdb-define-alist)
3235 (remove-hook 'after-save-hook 'gdb-create-define-alist t))))
3236
3237; This will only display data that comes in one chunk.
3238; Larger arrays (say 400 elements) are displayed in
3239; the tootip incompletely and spill over into the gud buffer.
3240; Switching the process-filter creates timing problems and
3241; it may be difficult to do better. Using annotations as in
3242; gdb-ui.el gets round this problem.
3243(defun gud-tooltip-process-output (process output)
3244 "Process debugger output and show it in a tooltip window."
3245 (set-process-filter process gud-tooltip-original-filter)
3246 (tooltip-show (tooltip-strip-prompt process output)
3247 gud-tooltip-echo-area))
3248
3249(defun gud-tooltip-print-command (expr)
3250 "Return a suitable command to print the expression EXPR.
3251If GUD-TOOLTIP-DEREFERENCE is t, also prepend a `*' to EXPR."
3252 (when gud-tooltip-dereference
3253 (setq expr (concat "*" expr)))
3254 (case gud-minor-mode
2b9688f6 3255 (gdba (concat "server print " expr))
df94fa1e 3256 ((dbx gdbmi) (concat "print " expr))
ce38ddb8
NR
3257 (xdb (concat "p " expr))
3258 (sdb (concat expr "/"))
3259 (perldb expr)))
3260
3261(defun gud-tooltip-tips (event)
3262 "Show tip for identifier or selection under the mouse.
3263The mouse must either point at an identifier or inside a selected
3264region for the tip window to be shown. If gud-tooltip-dereference is t,
3265add a `*' in front of the printed expression. In the case of a C program
3266controlled by GDB, show the associated #define directives when program is
3267not executing.
3268
3269This function must return nil if it doesn't handle EVENT."
3270 (let (process)
3271 (when (and (eventp event)
3272 gud-tooltip-mode
3273 (boundp 'gud-comint-buffer)
3274 gud-comint-buffer
3275 (buffer-name gud-comint-buffer); gud-comint-buffer might be killed
3276 (setq process (get-buffer-process gud-comint-buffer))
3277 (posn-point (event-end event))
3278 (or (and (eq gud-minor-mode 'gdba) (not gdb-active-process))
3279 (progn (setq gud-tooltip-event event)
3280 (eval (cons 'and gud-tooltip-display)))))
3281 (let ((expr (tooltip-expr-to-print event)))
3282 (when expr
3283 (if (and (eq gud-minor-mode 'gdba)
3284 (not gdb-active-process))
3285 (progn
3286 (with-current-buffer
3287 (window-buffer (let ((mouse (mouse-position)))
3288 (window-at (cadr mouse)
3289 (cddr mouse))))
3290 (let ((define-elt (assoc expr gdb-define-alist)))
3291 (unless (null define-elt)
3292 (tooltip-show (cdr define-elt))
3293 expr))))
3294 (let ((cmd (gud-tooltip-print-command expr)))
2b9688f6
NR
3295 (when (and gud-tooltip-mode (eq gud-minor-mode 'gdb))
3296 (gud-tooltip-mode -1)
3297 (message-box "Using GUD tooltips in this mode is unsafe\n\
3298so they have been disabled."))
ce38ddb8 3299 (unless (null cmd) ; CMD can be nil if unknown debugger
df94fa1e
NR
3300 (if (memq gud-minor-mode '(gdba gdbmi))
3301 (if gdb-macro-info
3302 (gdb-enqueue-input
3303 (list (concat
3304 gdb-server-prefix "macro expand " expr "\n")
3305 `(lambda () (gdb-tooltip-print-1 ,expr))))
3306 (gdb-enqueue-input
3307 (list (concat cmd "\n") 'gdb-tooltip-print)))
ce38ddb8
NR
3308 (setq gud-tooltip-original-filter (process-filter process))
3309 (set-process-filter process 'gud-tooltip-process-output)
3310 (gud-basic-call cmd))
3311 expr))))))))
3312
0f9c2d46
JB
3313(provide 'gud)
3314
ab5796a9 3315;;; arch-tag: 6d990948-df65-461a-be39-1c7fb83ac4c4
0f9c2d46 3316;;; gud.el ends here