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