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