1 ;;; gud.el --- Grand Unified Debugger mode for running GDB and other debuggers
3 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
5 ;; Keywords: unix, tools
7 ;; Copyright (C) 1992,93,94,95,96,1998,2000,2002 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; The ancestral gdb.el was by W. Schelter <wfs@rascal.ics.utexas.edu>
29 ;; It was later rewritten by rms. Some ideas were due to Masanobu.
30 ;; Grand Unification (sdb/dbx support) by Eric S. Raymond <esr@thyrsus.com>
31 ;; The overloading code was then rewritten by Barry Warsaw <bwarsaw@cen.com>,
32 ;; who also hacked the mode to use comint.el. Shane Hartman <shane@spr.com>
33 ;; added support for xdb (HPUX debugger). Rick Sladkey <jrs@world.std.com>
34 ;; wrote the GDB command completion code. Dave Love <d.love@dl.ac.uk>
35 ;; added the IRIX kluge, re-implemented the Mips-ish variant and added
36 ;; a menu. Brian D. Carlstrom <bdc@ai.mit.edu> combined the IRIX kluge with
37 ;; the gud-xdb-directories hack producing gud-dbx-directories. Derek L. Davies
38 ;; <ddavies@world.std.com> added support for jdb (Java debugger.)
45 ;; ======================================================================
46 ;; GUD commands must be visible in C buffers visited by GUD
49 "Grand Unified Debugger mode for gdb and other debuggers under Emacs.
50 Supported debuggers include gdb, sdb, dbx, xdb, perldb, pdb (Python), and jdb."
55 (defcustom gud-key-prefix
"\C-x\C-a"
56 "Prefix of all GUD commands valid in C buffers."
60 (global-set-key (concat gud-key-prefix
"\C-l") 'gud-refresh
)
61 (define-key ctl-x-map
" " 'gud-break
) ;; backward compatibility hack
63 (defvar gud-marker-filter nil
)
64 (put 'gud-marker-filter
'permanent-local t
)
65 (defvar gud-find-file nil
)
66 (put 'gud-find-file
'permanent-local t
)
68 (defun gud-marker-filter (&rest args
)
69 (apply gud-marker-filter args
))
71 (defvar gud-minor-mode nil
)
72 (put 'gud-minor-mode
'permanent-local t
)
74 (defun gud-symbol (sym &optional soft minor-mode
)
75 "Return the symbol used for SYM in MINOR-MODE.
76 MINOR-MODE defaults to `gud-minor-mode.
77 The symbol returned is `gud-<MINOR-MODE>-<SYM>'.
78 If SOFT is non-nil, returns nil if the symbol doesn't already exist."
79 (unless (or minor-mode gud-minor-mode
) (error "Gud internal error"))
80 (funcall (if soft
'intern-soft
'intern
)
81 (format "gud-%s-%s" (or minor-mode gud-minor-mode
) sym
)))
83 (defun gud-val (sym &optional minor-mode
)
84 "Return the value of `gud-symbol' SYM. Default to nil."
85 (let ((sym (gud-symbol sym t minor-mode
)))
86 (if (boundp sym
) (symbol-value sym
))))
88 (defun gud-find-file (file)
89 ;; Don't get confused by double slashes in the name that comes from GDB.
90 (while (string-match "//+" file
)
91 (setq file
(replace-match "/" t t file
)))
92 (let ((minor-mode gud-minor-mode
)
93 (buf (funcall gud-find-file file
)))
95 ;; Copy `gud-minor-mode' to the found buffer to turn on the menu.
96 (with-current-buffer buf
97 (set (make-local-variable 'gud-minor-mode
) minor-mode
))
100 (easy-mmode-defmap gud-menu-map
101 '(([refresh] "Refresh" . gud-refresh)
102 ([remove] "Remove Breakpoint" . gud-remove)
103 ([tbreak] menu-item "Temporary Breakpoint" gud-tbreak
104 :enable (memq gud-minor-mode '(gdb sdb xdb)))
105 ([break] "Set Breakpoint" . gud-break)
106 ([up] menu-item "Up Stack" gud-up
107 :enable (memq gud-minor-mode '(gdb dbx xdb jdb)))
108 ([down] menu-item "Down Stack" gud-down
109 :enable (memq gud-minor-mode '(gdb dbx xdb jdb)))
110 ([print] "Print Expression" . gud-print)
111 ([finish] menu-item "Finish Function" gud-finish
112 :enable (memq gud-minor-mode '(gdb xdb jdb)))
113 ([stepi] "Step Instruction" . gud-stepi)
114 ([step] "Step Line" . gud-step)
115 ([next] "Next Line" . gud-next)
116 ([cont] "Continue" . gud-cont))
117 "Menu for `gud-mode'."
120 (easy-mmode-defmap gud-minor-mode-map
121 `(([menu-bar debug] . ("Gud" . ,gud-menu-map)))
122 "Map used in visited files.")
124 (let ((m (assq 'gud-minor-mode minor-mode-map-alist)))
125 (if m (setcdr m gud-minor-mode-map)
126 (push (cons 'gud-minor-mode gud-minor-mode-map) minor-mode-map-alist)))
129 ;; Will inherit from comint-mode via define-derived-mode.
131 "`gud-mode' keymap.")
133 ;; ======================================================================
134 ;; command definition
136 ;; This macro is used below to define some basic debugger interface commands.
137 ;; Of course you may use `gud-def' with any other debugger command, including
138 ;; user defined ones.
140 ;; A macro call like (gud-def FUNC NAME KEY DOC) expands to a form
141 ;; which defines FUNC to send the command NAME to the debugger, gives
142 ;; it the docstring DOC, and binds that function to KEY in the GUD
143 ;; major mode. The function is also bound in the global keymap with the
146 (defmacro gud-def (func cmd key &optional doc)
147 "Define FUNC to be a command sending STR and bound to KEY, with
148 optional doc string DOC. Certain %-escapes in the string arguments
149 are interpreted specially if present. These are:
151 %f name (without directory) of current source file.
152 %F name (without directory or extension) of current source file.
153 %d directory of current source file.
154 %l number of current source line
155 %e text of the C lvalue or function-call expression surrounding point.
156 %a text of the hexadecimal address surrounding point
157 %p prefix argument to the command (if any) as a number
159 The `current' source file is the file of the current buffer (if
160 we're in a C file) or the source file current at the last break or
161 step (if we're in the GUD buffer).
162 The `current' line is that of the current buffer (if we're in a
163 source file) or the source line number at the last break or step (if
164 we're in the GUD buffer)."
166 (list 'defun func '(arg)
169 (list 'gud-call cmd 'arg))
176 (list 'global-set-key
177 (list 'concat 'gud-key-prefix key)
178 (list 'quote func)))))
180 ;; Where gud-display-frame should put the debugging arrow; a cons of
181 ;; (filename . line-number). This is set by the marker-filter, which scans
182 ;; the debugger's output for indications of the current program counter.
183 (defvar gud-last-frame nil)
185 ;; Used by gud-refresh, which should cause gud-display-frame to redisplay
186 ;; the last frame, even if it's been called before and gud-last-frame has
188 (defvar gud-last-last-frame nil)
190 ;; All debugger-specific information is collected here.
191 ;; Here's how it works, in case you ever need to add a debugger to the mode.
193 ;; Each entry must define the following at startup:
196 ;; comint-prompt-regexp
197 ;; gud-<name>-massage-args
198 ;; gud-<name>-marker-filter
199 ;; gud-<name>-find-file
201 ;; The job of the massage-args method is to modify the given list of
202 ;; debugger arguments before running the debugger.
204 ;; The job of the marker-filter method is to detect file/line markers in
205 ;; strings and set the global gud-last-frame to indicate what display
206 ;; action (if any) should be triggered by the marker. Note that only
207 ;; whatever the method *returns* is displayed in the buffer; thus, you
208 ;; can filter the debugger's output, interpreting some and passing on
211 ;; The job of the find-file method is to visit and return the buffer indicated
212 ;; by the car of gud-tag-frame. This may be a file name, a tag name, or
215 ;; ======================================================================
216 ;; speedbar support functions and variables.
217 (eval-when-compile (require 'speedbar)) ;For speedbar-with-attached-buffer.
219 (defvar gud-last-speedbar-buffer nil
220 "The last GUD buffer used.")
222 (defvar gud-last-speedbar-stackframe nil
223 "Description of the currently displayed GUD stack.
224 t means that there is no stack, and we are in display-file mode.")
226 (defvar gud-speedbar-key-map nil
227 "Keymap used when in the buffers display mode.")
229 (defun gud-install-speedbar-variables ()
230 "Install those variables used by speedbar to enhance gud/gdb."
231 (if gud-speedbar-key-map
233 (setq gud-speedbar-key-map (speedbar-make-specialized-keymap))
235 (define-key gud-speedbar-key-map "j" 'speedbar-edit-line)
236 (define-key gud-speedbar-key-map "e" 'speedbar-edit-line)
237 (define-key gud-speedbar-key-map "\C-m" 'speedbar-edit-line)))
239 (defvar gud-speedbar-menu-items
240 ;; Note to self. Add expand, and turn off items when not available.
241 '(["Jump to stack frame" speedbar-edit-line t])
242 "Additional menu items to add to the speedbar frame.")
244 ;; Make sure our special speedbar mode is loaded
245 (if (featurep 'speedbar)
246 (gud-install-speedbar-variables)
247 (add-hook 'speedbar-load-hook 'gud-install-speedbar-variables))
249 (defun gud-speedbar-buttons (buffer)
250 "Create a speedbar display based on the current state of GUD.
251 If the GUD BUFFER is not running a supported debugger, then turn
252 off the specialized speedbar mode."
253 (if (and (save-excursion (goto-char (point-min))
254 (looking-at "Current Stack"))
255 (equal gud-last-last-frame gud-last-speedbar-stackframe))
257 (setq gud-last-speedbar-buffer buffer)
258 (let* ((ff (save-excursion (set-buffer buffer) gud-find-file))
259 ;;(lf (save-excursion (set-buffer buffer) gud-last-last-frame))
261 (cond ((eq ff 'gud-gdb-find-file)
262 (gud-gdb-get-stackframe buffer)
264 ;; Add more debuggers here!
266 (speedbar-remove-localized-speedbar-support buffer)
270 (insert "No Stack frames\n")
271 (insert "Current Stack:\n"))
273 (insert (nth 1 (car frames)) ":\n")
274 (if (= (length (car frames)) 2)
276 ; (speedbar-insert-button "[?]"
277 ; 'speedbar-button-face
279 (speedbar-insert-button (car (car frames))
280 'speedbar-directory-face
282 ; (speedbar-insert-button "[+]"
283 ; 'speedbar-button-face
284 ; 'speedbar-highlight-face
285 ; 'gud-gdb-get-scope-data
287 (speedbar-insert-button (car (car frames))
289 'speedbar-highlight-face
290 (cond ((eq ff 'gud-gdb-find-file)
291 'gud-gdb-goto-stackframe)
292 (t (error "Should never be here")))
294 (setq frames (cdr frames)))
295 ; (let ((selected-frame
296 ; (cond ((eq ff 'gud-gdb-find-file)
297 ; (gud-gdb-selected-frame-info buffer))
298 ; (t (error "Should never be here"))))))
300 (setq gud-last-speedbar-stackframe gud-last-last-frame)))
303 ;; ======================================================================
306 ;; History of argument lists passed to gdb.
307 (defvar gud-gdb-history nil)
309 (defcustom gud-gdb-command-name "gdb --fullname"
310 "Default command to execute an executable under the GDB debugger."
314 (defvar gud-gdb-marker-regexp
315 ;; This used to use path-separator instead of ":";
316 ;; however, we found that on both Windows 32 and MSDOS
317 ;; a colon is correct here.
318 (concat "\032\032\\(.:?[^" ":" "\n]*\\)" ":"
319 "\\([0-9]*\\)" ":" ".*\n"))
321 ;; There's no guarantee that Emacs will hand the filter the entire
322 ;; marker at once; it could be broken up across several strings. We
323 ;; might even receive a big chunk with several markers in it. If we
324 ;; receive a chunk of text which looks like it might contain the
325 ;; beginning of a marker, we save it here between calls to the
327 (defvar gud-marker-acc "")
328 (make-variable-buffer-local 'gud-marker-acc)
330 (defun gud-gdb-marker-filter (string)
331 (setq gud-marker-acc (concat gud-marker-acc string))
334 ;; Process all the complete markers in this chunk.
335 (while (string-match gud-gdb-marker-regexp gud-marker-acc)
338 ;; Extract the frame position from the marker.
340 (cons (substring gud-marker-acc (match-beginning 1) (match-end 1))
341 (string-to-int (substring gud-marker-acc
345 ;; Append any text before the marker to the output we're going
346 ;; to return - we don't include the marker in this text.
347 output (concat output
348 (substring gud-marker-acc 0 (match-beginning 0)))
350 ;; Set the accumulator to the remaining text.
351 gud-marker-acc (substring gud-marker-acc (match-end 0))))
353 ;; Does the remaining text look like it might end with the
354 ;; beginning of another marker? If it does, then keep it in
355 ;; gud-marker-acc until we receive the rest of it. Since we
356 ;; know the full marker regexp above failed, it's pretty simple to
357 ;; test for marker starts.
358 (if (string-match "\032.*\\'" gud-marker-acc)
360 ;; Everything before the potential marker start can be output.
361 (setq output (concat output (substring gud-marker-acc
362 0 (match-beginning 0))))
364 ;; Everything after, we save, to combine with later input.
366 (substring gud-marker-acc (match-beginning 0))))
368 (setq output (concat output gud-marker-acc)
373 (defun gud-gdb-find-file (f)
374 (find-file-noselect f 'nowarn))
376 (easy-mmode-defmap gud-minibuffer-local-map
377 '(("\C-i" . comint-dynamic-complete-filename))
378 "Keymap for minibuffer prompting of gud startup command."
379 :inherit minibuffer-local-map)
381 (defun gud-query-cmdline (minor-mode &optional init)
382 (let* ((hist-sym (gud-symbol 'history nil minor-mode))
383 (cmd-name (gud-val 'command-name minor-mode)))
384 (unless (boundp hist-sym) (set hist-sym nil))
385 (read-from-minibuffer
386 (format "Run %s (like this): " minor-mode)
387 (or (car-safe (symbol-value hist-sym))
388 (concat (or cmd-name (symbol-name minor-mode))
392 (dolist (f (directory-files default-directory) file)
393 (if (and (file-executable-p f)
394 (not (file-directory-p f))
396 (file-newer-than-file-p f file)))
398 gud-minibuffer-local-map nil
402 (defun gdb (command-line)
403 "Run gdb on program FILE in buffer *gud-FILE*.
404 The directory containing FILE becomes the initial working directory
405 and source-file directory for your debugger."
406 (interactive (list (gud-query-cmdline 'gdb)))
408 (gud-common-init command-line
409 #'(lambda (file args)
410 `("-cd" ,(expand-file-name default-directory) . ,args))
411 'gud-gdb-marker-filter 'gud-gdb-find-file)
412 (set (make-local-variable 'gud-minor-mode) 'gdb)
414 (gud-def gud-break "break %f:%l" "\C-b" "Set breakpoint at current line.")
415 (gud-def gud-tbreak "tbreak %f:%l" "\C-t" "Set temporary breakpoint at current line.")
416 (gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line")
417 (gud-def gud-step "step %p" "\C-s" "Step one source line with display.")
418 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
419 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).")
420 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
421 (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
422 (gud-def gud-jump "tbreak %f:%l\njump %f:%l" "\C-j" "Relocate execution address to line at point in source buffer.")
424 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
425 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
426 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
428 (local-set-key "\C-i" 'gud-gdb-complete-command)
429 (local-set-key [menu-bar debug tbreak] '("Temporary Breakpoint" . gud-tbreak))
430 (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish))
431 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
432 (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
433 (setq comint-prompt-regexp "^(.*gdb[+]?) *")
434 (setq paragraph-start comint-prompt-regexp)
435 (run-hooks 'gdb-mode-hook)
438 ;; One of the nice features of GDB is its impressive support for
439 ;; context-sensitive command completion. We preserve that feature
440 ;; in the GUD buffer by using a GDB command designed just for Emacs.
442 ;; The completion process filter indicates when it is finished.
443 (defvar gud-gdb-complete-in-progress)
445 ;; Since output may arrive in fragments we accumulate partials strings here.
446 (defvar gud-gdb-complete-string)
448 ;; We need to know how much of the completion to chop off.
449 (defvar gud-gdb-complete-break)
451 ;; The completion list is constructed by the process filter.
452 (defvar gud-gdb-complete-list)
454 (defvar gud-comint-buffer nil)
456 (defun gud-gdb-complete-command ()
457 "Perform completion on the GDB command preceding point.
458 This is implemented using the GDB `complete' command which isn't
459 available with older versions of GDB."
462 (command (buffer-substring (comint-line-beginning-position) end))
464 ;; Find the word break. This match will always succeed.
465 (string-match "\\(\\`\\| \\)\\([^ ]*\\)\\'" command)
466 (setq gud-gdb-complete-break (match-beginning 2)
467 command-word (substring command gud-gdb-complete-break))
468 ;; Temporarily install our filter function.
469 (let ((gud-marker-filter 'gud-gdb-complete-filter))
470 ;; Issue the command to GDB.
471 (gud-basic-call (concat "complete " command))
472 (setq gud-gdb-complete-in-progress t
473 gud-gdb-complete-string nil
474 gud-gdb-complete-list nil)
476 (while gud-gdb-complete-in-progress
477 (accept-process-output (get-buffer-process gud-comint-buffer))))
478 ;; Protect against old versions of GDB.
479 (and gud-gdb-complete-list
480 (string-match "^Undefined command: \"complete\""
481 (car gud-gdb-complete-list))
482 (error "This version of GDB doesn't support the `complete' command"))
483 ;; Sort the list like readline.
484 (setq gud-gdb-complete-list
485 (sort gud-gdb-complete-list (function string-lessp)))
486 ;; Remove duplicates.
487 (let ((first gud-gdb-complete-list)
488 (second (cdr gud-gdb-complete-list)))
490 (if (string-equal (car first) (car second))
491 (setcdr first (setq second (cdr second)))
493 second (cdr second)))))
494 ;; Add a trailing single quote if there is a unique completion
495 ;; and it contains an odd number of unquoted single quotes.
496 (and (= (length gud-gdb-complete-list) 1)
497 (let ((str (car gud-gdb-complete-list))
500 (while (string-match "\\([^'\\]\\|\\\\'\\)*'" str pos)
501 (setq count (1+ count)
503 (and (= (mod count 2) 1)
504 (setq gud-gdb-complete-list (list (concat str "'"))))))
505 ;; Let comint handle the rest.
506 (comint-dynamic-simple-complete command-word gud-gdb-complete-list)))
508 ;; The completion process filter is installed temporarily to slurp the
509 ;; output of GDB up to the next prompt and build the completion list.
510 (defun gud-gdb-complete-filter (string)
511 (setq string (concat gud-gdb-complete-string string))
512 (while (string-match "\n" string)
513 (setq gud-gdb-complete-list
514 (cons (substring string gud-gdb-complete-break (match-beginning 0))
515 gud-gdb-complete-list))
516 (setq string (substring string (match-end 0))))
517 (if (string-match comint-prompt-regexp string)
519 (setq gud-gdb-complete-in-progress nil)
522 (setq gud-gdb-complete-string string)
525 ;; gdb speedbar functions
527 (defun gud-gdb-goto-stackframe (text token indent)
528 "Goto the stackframe described by TEXT, TOKEN, and INDENT."
529 (speedbar-with-attached-buffer
530 (gud-basic-call (concat "frame " (nth 1 token)))
533 (defvar gud-gdb-fetched-stack-frame nil
534 "Stack frames we are fetching from GDB.")
536 (defvar gud-gdb-fetched-stack-frame-list nil
537 "List of stack frames we are fetching from GDB.")
539 ;(defun gud-gdb-get-scope-data (text token indent)
540 ; ;; checkdoc-params: (indent)
541 ; "Fetch data associated with a stack frame, and expand/contract it.
542 ;Data to do this is retrieved from TEXT and TOKEN."
543 ; (let ((args nil) (scope nil))
544 ; (gud-gdb-run-command-fetch-lines "info args")
546 ; (gud-gdb-run-command-fetch-lines "info local")
550 (defun gud-gdb-get-stackframe (buffer)
551 "Extract the current stack frame out of the GUD GDB BUFFER."
553 (gud-gdb-fetched-stack-frame-list nil))
554 (gud-gdb-run-command-fetch-lines "backtrace" buffer)
555 (if (and (car gud-gdb-fetched-stack-frame-list)
556 (string-match "No stack" (car gud-gdb-fetched-stack-frame-list)))
557 ;; Go into some other mode???
559 (while gud-gdb-fetched-stack-frame-list
560 (let ((e (car gud-gdb-fetched-stack-frame-list))
561 (name nil) (num nil))
563 (string-match "^#\\([0-9]+\\) +[0-9a-fx]+ in \\([:0-9a-zA-Z_]+\\) (" e)
564 (string-match "^#\\([0-9]+\\) +\\([:0-9a-zA-Z_]+\\) (" e)))
565 (if (not (string-match
566 "at \\([-0-9a-zA-Z_.]+\\):\\([0-9]+\\)$" e))
569 (list (nth 0 (car newlst))
572 (match-string 2 e))))
573 (setq num (match-string 1 e)
574 name (match-string 2 e))
578 "at \\([-0-9a-zA-Z_.]+\\):\\([0-9]+\\)$" e)
579 (list name num (match-string 1 e)
583 (setq gud-gdb-fetched-stack-frame-list
584 (cdr gud-gdb-fetched-stack-frame-list)))
587 ;(defun gud-gdb-selected-frame-info (buffer)
588 ; "Learn GDB information for the currently selected stack frame in BUFFER."
591 (defun gud-gdb-run-command-fetch-lines (command buffer)
592 "Run COMMAND, and return when `gud-gdb-fetched-stack-frame-list' is full.
593 BUFFER is the GUD buffer in which to run the command."
597 (goto-char (point-max))
599 (not (looking-at comint-prompt-regexp)))
601 ;; Much of this copied from GDB complete, but I'm grabbing the stack
603 (let ((gud-marker-filter 'gud-gdb-speedbar-stack-filter))
604 ;; Issue the command to GDB.
605 (gud-basic-call command)
606 (setq gud-gdb-complete-in-progress t ;; use this flag for our purposes.
607 gud-gdb-complete-string nil
608 gud-gdb-complete-list nil)
610 (while gud-gdb-complete-in-progress
611 (accept-process-output (get-buffer-process gud-comint-buffer)))
612 (setq gud-gdb-fetched-stack-frame nil
613 gud-gdb-fetched-stack-frame-list
614 (nreverse gud-gdb-fetched-stack-frame-list))))))
616 (defun gud-gdb-speedbar-stack-filter (string)
617 ;; checkdoc-params: (string)
618 "Filter used to read in the current GDB stack."
619 (setq string (concat gud-gdb-fetched-stack-frame string))
620 (while (string-match "\n" string)
621 (setq gud-gdb-fetched-stack-frame-list
622 (cons (substring string 0 (match-beginning 0))
623 gud-gdb-fetched-stack-frame-list))
624 (setq string (substring string (match-end 0))))
625 (if (string-match comint-prompt-regexp string)
627 (setq gud-gdb-complete-in-progress nil)
630 (setq gud-gdb-complete-string string)
634 ;; ======================================================================
637 ;; History of argument lists passed to sdb.
638 (defvar gud-sdb-history nil)
640 (defvar gud-sdb-needs-tags (not (file-exists-p "/var"))
641 "If nil, we're on a System V Release 4 and don't need the tags hack.")
643 (defvar gud-sdb-lastfile nil)
645 (defun gud-sdb-marker-filter (string)
647 (if gud-marker-acc (concat gud-marker-acc string) string))
649 ;; Process all complete markers in this chunk
652 ;; System V Release 3.2 uses this format
653 ((string-match "\\(^\\|\n\\)\\*?\\(0x\\w* in \\)?\\([^:\n]*\\):\\([0-9]*\\):.*\n"
654 gud-marker-acc start)
657 (substring gud-marker-acc (match-beginning 3) (match-end 3))
659 (substring gud-marker-acc (match-beginning 4) (match-end 4))))))
660 ;; System V Release 4.0 quite often clumps two lines together
661 ((string-match "^\\(BREAKPOINT\\|STEPPED\\) process [0-9]+ function [^ ]+ in \\(.+\\)\n\\([0-9]+\\):"
662 gud-marker-acc start)
663 (setq gud-sdb-lastfile
664 (substring gud-marker-acc (match-beginning 2) (match-end 2)))
669 (substring gud-marker-acc (match-beginning 3) (match-end 3))))))
670 ;; System V Release 4.0
671 ((string-match "^\\(BREAKPOINT\\|STEPPED\\) process [0-9]+ function [^ ]+ in \\(.+\\)\n"
672 gud-marker-acc start)
673 (setq gud-sdb-lastfile
674 (substring gud-marker-acc (match-beginning 2) (match-end 2))))
675 ((and gud-sdb-lastfile (string-match "^\\([0-9]+\\):"
676 gud-marker-acc start))
681 (substring gud-marker-acc (match-beginning 1) (match-end 1))))))
683 (setq gud-sdb-lastfile nil)))
684 (setq start (match-end 0)))
686 ;; Search for the last incomplete line in this chunk
687 (while (string-match "\n" gud-marker-acc start)
688 (setq start (match-end 0)))
690 ;; If we have an incomplete line, store it in gud-marker-acc.
691 (setq gud-marker-acc (substring gud-marker-acc (or start 0))))
694 (defun gud-sdb-find-file (f)
695 (if gud-sdb-needs-tags (find-tag-noselect f) (find-file-noselect f)))
698 (defun sdb (command-line)
699 "Run sdb on program FILE in buffer *gud-FILE*.
700 The directory containing FILE becomes the initial working directory
701 and source-file directory for your debugger."
702 (interactive (list (gud-query-cmdline 'sdb)))
704 (if (and gud-sdb-needs-tags
705 (not (and (boundp 'tags-file-name)
706 (stringp tags-file-name)
707 (file-exists-p tags-file-name))))
708 (error "The sdb support requires a valid tags table to work"))
710 (gud-common-init command-line nil
711 'gud-sdb-marker-filter 'gud-sdb-find-file)
712 (set (make-local-variable 'gud-minor-mode) 'sdb)
714 (gud-def gud-break "%l b" "\C-b" "Set breakpoint at current line.")
715 (gud-def gud-tbreak "%l c" "\C-t" "Set temporary breakpoint at current line.")
716 (gud-def gud-remove "%l d" "\C-d" "Remove breakpoint at current line")
717 (gud-def gud-step "s %p" "\C-s" "Step one source line with display.")
718 (gud-def gud-stepi "i %p" "\C-i" "Step one instruction with display.")
719 (gud-def gud-next "S %p" "\C-n" "Step one line (skip functions).")
720 (gud-def gud-cont "c" "\C-r" "Continue with display.")
721 (gud-def gud-print "%e/" "\C-p" "Evaluate C expression at point.")
723 (setq comint-prompt-regexp "\\(^\\|\n\\)\\*")
724 (setq paragraph-start comint-prompt-regexp)
725 (local-set-key [menu-bar debug tbreak]
726 '("Temporary Breakpoint" . gud-tbreak))
727 (run-hooks 'sdb-mode-hook)
730 ;; ======================================================================
733 ;; History of argument lists passed to dbx.
734 (defvar gud-dbx-history nil)
736 (defcustom gud-dbx-directories nil
737 "*A list of directories that dbx should search for source code.
738 If nil, only source files in the program directory
739 will be known to dbx.
741 The file names should be absolute, or relative to the directory
742 containing the executable being debugged."
743 :type '(choice (const :tag "Current Directory" nil)
748 (defun gud-dbx-massage-args (file args)
749 (nconc (let ((directories gud-dbx-directories)
752 (setq result (cons (car directories) (cons "-I" result)))
753 (setq directories (cdr directories)))
757 (defun gud-dbx-file-name (f)
758 "Transform a relative file name to an absolute file name, for dbx."
760 (if (file-exists-p f)
761 (setq result (expand-file-name f))
762 (let ((directories gud-dbx-directories))
764 (let ((path (concat (car directories) "/" f)))
765 (if (file-exists-p path)
766 (setq result (expand-file-name path)
768 (setq directories (cdr directories)))))
771 (defun gud-dbx-marker-filter (string)
772 (setq gud-marker-acc (if gud-marker-acc (concat gud-marker-acc string) string))
775 ;; Process all complete markers in this chunk.
776 (while (or (string-match
777 "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\""
778 gud-marker-acc start)
780 "signal .* in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\""
781 gud-marker-acc start))
784 (substring gud-marker-acc (match-beginning 2) (match-end 2))
786 (substring gud-marker-acc (match-beginning 1) (match-end 1))))
787 start (match-end 0)))
789 ;; Search for the last incomplete line in this chunk
790 (while (string-match "\n" gud-marker-acc start)
791 (setq start (match-end 0)))
793 ;; If the incomplete line APPEARS to begin with another marker, keep it
794 ;; in the accumulator. Otherwise, clear the accumulator to avoid an
795 ;; unnecessary concat during the next call.
797 (if (string-match "\\(stopped\\|signal\\)" gud-marker-acc start)
798 (substring gud-marker-acc (match-beginning 0))
802 ;; Functions for Mips-style dbx. Given the option `-emacs', documented in
803 ;; OSF1, not necessarily elsewhere, it produces markers similar to gdb's.
805 (or (string-match "^mips-[^-]*-ultrix" system-configuration)
806 ;; We haven't tested gud on this system:
807 (string-match "^mips-[^-]*-riscos" system-configuration)
808 ;; It's documented on OSF/1.3
809 (string-match "^mips-[^-]*-osf1" system-configuration)
810 (string-match "^alpha[^-]*-[^-]*-osf" system-configuration))
811 "Non-nil to assume the MIPS/OSF dbx conventions (argument `-emacs').")
813 (defun gud-mipsdbx-massage-args (file args)
814 (cons "-emacs" args))
816 ;; This is just like the gdb one except for the regexps since we need to cope
817 ;; with an optional breakpoint number in [] before the ^Z^Z
818 (defun gud-mipsdbx-marker-filter (string)
819 (setq gud-marker-acc (concat gud-marker-acc string))
822 ;; Process all the complete markers in this chunk.
824 ;; This is like th gdb marker but with an optional
825 ;; leading break point number like `[1] '
826 "[][ 0-9]*\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
830 ;; Extract the frame position from the marker.
832 (cons (substring gud-marker-acc (match-beginning 1) (match-end 1))
833 (string-to-int (substring gud-marker-acc
837 ;; Append any text before the marker to the output we're going
838 ;; to return - we don't include the marker in this text.
839 output (concat output
840 (substring gud-marker-acc 0 (match-beginning 0)))
842 ;; Set the accumulator to the remaining text.
843 gud-marker-acc (substring gud-marker-acc (match-end 0))))
845 ;; Does the remaining text look like it might end with the
846 ;; beginning of another marker? If it does, then keep it in
847 ;; gud-marker-acc until we receive the rest of it. Since we
848 ;; know the full marker regexp above failed, it's pretty simple to
849 ;; test for marker starts.
850 (if (string-match "[][ 0-9]*\032.*\\'" gud-marker-acc)
852 ;; Everything before the potential marker start can be output.
853 (setq output (concat output (substring gud-marker-acc
854 0 (match-beginning 0))))
856 ;; Everything after, we save, to combine with later input.
858 (substring gud-marker-acc (match-beginning 0))))
860 (setq output (concat output gud-marker-acc)
865 ;; The dbx in IRIX is a pain. It doesn't print the file name when
866 ;; stopping at a breakpoint (but you do get it from the `up' and
867 ;; `down' commands...). The only way to extract the information seems
868 ;; to be with a `file' command, although the current line number is
869 ;; available in $curline. Thus we have to look for output which
870 ;; appears to indicate a breakpoint. Then we prod the dbx sub-process
871 ;; to output the information we want with a combination of the
872 ;; `printf' and `file' commands as a pseudo marker which we can
873 ;; recognise next time through the marker-filter. This would be like
874 ;; the gdb marker but you can't get the file name without a newline...
875 ;; Note that gud-remove won't work since Irix dbx expects a breakpoint
876 ;; number rather than a line number etc. Maybe this could be made to
877 ;; work by listing all the breakpoints and picking the one(s) with the
878 ;; correct line number, but life's too short.
879 ;; d.love@dl.ac.uk (Dave Love) can be blamed for this
882 (and (string-match "^mips-[^-]*-irix" system-configuration)
883 (not (string-match "irix[6-9]\\.[1-9]" system-configuration)))
884 "Non-nil to assume the interface appropriate for IRIX dbx.
885 This works in IRIX 4, 5 and 6, but `gud-dbx-use-stopformat-p' provides
886 a better solution in 6.1 upwards.")
887 (defvar gud-dbx-use-stopformat-p
888 (string-match "irix[6-9]\\.[1-9]" system-configuration)
889 "Non-nil to use the dbx feature present at least from Irix 6.1
890 whereby $stopformat=1 produces an output format compatiable with
891 `gud-dbx-marker-filter'.")
892 ;; [Irix dbx seems to be a moving target. The dbx output changed
893 ;; subtly sometime between OS v4.0.5 and v5.2 so that, for instance,
894 ;; the output from `up' is no longer spotted by gud (and it's probably
895 ;; not distinctive enough to try to match it -- use C-<, C->
896 ;; exclusively) . For 5.3 and 6.0, the $curline variable changed to
897 ;; `long long'(why?!), so the printf stuff needed changing. The line
898 ;; number was cast to `long' as a compromise between the new `long
899 ;; long' and the original `int'. This is reported not to work in 6.2,
900 ;; so it's changed back to int -- don't make your sources too long.
901 ;; From Irix6.1 (but not 6.0?) dbx supports an undocumented feature
902 ;; whereby `set $stopformat=1' reportedly produces output compatible
903 ;; with `gud-dbx-marker-filter', which we prefer.
905 ;; The process filter is also somewhat
906 ;; unreliable, sometimes not spotting the markers; I don't know
907 ;; whether there's anything that can be done about that. It would be
908 ;; much better if SGI could be persuaded to (re?)instate the MIPS
909 ;; -emacs flag for gdb-like output (which ought to be possible as most
910 ;; of the communication I've had over it has been from sgi.com).]
912 ;; this filter is influenced by the xdb one rather than the gdb one
913 (defun gud-irixdbx-marker-filter (string)
914 (let (result (case-fold-search nil))
915 (if (or (string-match comint-prompt-regexp string)
916 (string-match ".*\012" string))
917 (setq result (concat gud-marker-acc string)
919 (setq gud-marker-acc (concat gud-marker-acc string)))
922 ;; look for breakpoint or signal indication e.g.:
923 ;; [2] Process 1267 (pplot) stopped at [params:338 ,0x400ec0]
924 ;; Process 1281 (pplot) stopped at [params:339 ,0x400ec8]
925 ;; Process 1270 (pplot) Floating point exception [._read._read:16 ,0x452188]
927 "^\\(\\[[0-9]+] \\)?Process +[0-9]+ ([^)]*) [^[]+\\[[^]\n]*]\n"
929 ;; prod dbx into printing out the line number and file
930 ;; name in a form we can grok as below
931 (process-send-string (get-buffer-process gud-comint-buffer)
932 "printf \"\032\032%1d:\",(int)$curline;file\n"))
933 ;; look for result of, say, "up" e.g.:
934 ;; .pplot.pplot(0x800) ["src/pplot.f":261, 0x400c7c]
935 ;; (this will also catch one of the lines printed by "where")
937 "^[^ ][^[]*\\[\"\\([^\"]+\\)\":\\([0-9]+\\), [^]]+]\n"
939 (let ((file (substring result (match-beginning 1)
941 (if (file-exists-p file)
945 result (match-beginning 1) (match-end 1))
948 result (match-beginning 2) (match-end 2)))))))
950 ((string-match ; kluged-up marker as above
951 "\032\032\\([0-9]*\\):\\(.*\\)\n" result)
952 (let ((file (gud-dbx-file-name
953 (substring result (match-beginning 2) (match-end 2)))))
954 (if (and file (file-exists-p file))
960 result (match-beginning 1) (match-end 1)))))))
961 (setq result (substring result 0 (match-beginning 0))))))
964 (defvar gud-dgux-p (string-match "-dgux" system-configuration)
965 "Non-nil means to assume the interface approriate for DG/UX dbx.
966 This was tested using R4.11.")
968 ;; There are a couple of differences between DG's dbx output and normal
969 ;; dbx output which make it nontrivial to integrate this into the
970 ;; standard dbx-marker-filter (mainly, there are a different number of
971 ;; backreferences). The markers look like:
973 ;; (0) Stopped at line 10, routine main(argc=1, argv=0xeffff0e0), file t.c
975 ;; from breakpoints (the `(0)' there isn't constant, it's the breakpoint
978 ;; Stopped at line 13, routine main(argc=1, argv=0xeffff0e0), file t.c
982 ;; Frame 21, line 974, routine command_loop(), file keyboard.c
984 ;; from up/down/where.
986 (defun gud-dguxdbx-marker-filter (string)
987 (setq gud-marker-acc (if gud-marker-acc
988 (concat gud-marker-acc string)
990 (let ((re (concat "^\\(\\(([0-9]+) \\)?Stopped at\\|Frame [0-9]+,\\)"
991 " line \\([0-9]+\\), routine .*, file \\([^ \t\n]+\\)"))
993 ;; Process all complete markers in this chunk.
994 (while (string-match re gud-marker-acc start)
997 (substring gud-marker-acc (match-beginning 4) (match-end 4))
998 (string-to-int (substring gud-marker-acc
999 (match-beginning 3) (match-end 3))))
1000 start (match-end 0)))
1002 ;; Search for the last incomplete line in this chunk
1003 (while (string-match "\n" gud-marker-acc start)
1004 (setq start (match-end 0)))
1006 ;; If the incomplete line APPEARS to begin with another marker, keep it
1007 ;; in the accumulator. Otherwise, clear the accumulator to avoid an
1008 ;; unnecessary concat during the next call.
1009 (setq gud-marker-acc
1010 (if (string-match "Stopped\\|Frame" gud-marker-acc start)
1011 (substring gud-marker-acc (match-beginning 0))
1015 (defun gud-dbx-find-file (f)
1017 (let ((realf (gud-dbx-file-name f)))
1019 (find-file-noselect realf)))))
1022 (defun dbx (command-line)
1023 "Run dbx on program FILE in buffer *gud-FILE*.
1024 The directory containing FILE becomes the initial working directory
1025 and source-file directory for your debugger."
1026 (interactive (list (gud-query-cmdline 'dbx)))
1030 (gud-common-init command-line 'gud-mipsdbx-massage-args
1031 'gud-mipsdbx-marker-filter 'gud-dbx-find-file))
1033 (gud-common-init command-line 'gud-dbx-massage-args
1034 'gud-irixdbx-marker-filter 'gud-dbx-find-file))
1036 (gud-common-init command-line 'gud-dbx-massage-args
1037 'gud-dguxdbx-marker-filter 'gud-dbx-find-file))
1039 (gud-common-init command-line 'gud-dbx-massage-args
1040 'gud-dbx-marker-filter 'gud-dbx-find-file)))
1042 (set (make-local-variable 'gud-minor-mode) 'dbx)
1046 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
1047 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
1048 (gud-def gud-break "stop at \"%f\":%l"
1049 "\C-b" "Set breakpoint at current line.")
1050 (gud-def gud-finish "return" "\C-f" "Finish executing current function."))
1052 (gud-def gud-break "stop at \"%d%f\":%l"
1053 "\C-b" "Set breakpoint at current line.")
1054 (gud-def gud-finish "return" "\C-f" "Finish executing current function.")
1055 (gud-def gud-up "up %p; printf \"\032\032%1d:\",(int)$curline;file\n"
1056 "<" "Up (numeric arg) stack frames.")
1057 (gud-def gud-down "down %p; printf \"\032\032%1d:\",(int)$curline;file\n"
1058 ">" "Down (numeric arg) stack frames.")
1059 ;; Make dbx give out the source location info that we need.
1060 (process-send-string (get-buffer-process gud-comint-buffer)
1061 "printf \"\032\032%1d:\",(int)$curline;file\n"))
1063 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
1064 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
1065 (gud-def gud-break "file \"%d%f\"\nstop at %l"
1066 "\C-b" "Set breakpoint at current line.")
1067 (if gud-dbx-use-stopformat-p
1068 (process-send-string (get-buffer-process gud-comint-buffer)
1069 "set $stopformat=1\n"))))
1071 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
1072 (gud-def gud-step "step %p" "\C-s" "Step one line with display.")
1073 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
1074 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).")
1075 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
1076 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
1078 (setq comint-prompt-regexp "^[^)\n]*dbx) *")
1079 (setq paragraph-start comint-prompt-regexp)
1080 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
1081 (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
1082 (run-hooks 'dbx-mode-hook)
1085 ;; ======================================================================
1086 ;; xdb (HP PARISC debugger) functions
1088 ;; History of argument lists passed to xdb.
1089 (defvar gud-xdb-history nil)
1091 (defcustom gud-xdb-directories nil
1092 "*A list of directories that xdb should search for source code.
1093 If nil, only source files in the program directory
1094 will be known to xdb.
1096 The file names should be absolute, or relative to the directory
1097 containing the executable being debugged."
1098 :type '(choice (const :tag "Current Directory" nil)
1103 (defun gud-xdb-massage-args (file args)
1104 (nconc (let ((directories gud-xdb-directories)
1107 (setq result (cons (car directories) (cons "-d" result)))
1108 (setq directories (cdr directories)))
1112 (defun gud-xdb-file-name (f)
1113 "Transform a relative pathname to a full pathname in xdb mode"
1115 (if (file-exists-p f)
1116 (setq result (expand-file-name f))
1117 (let ((directories gud-xdb-directories))
1119 (let ((path (concat (car directories) "/" f)))
1120 (if (file-exists-p path)
1121 (setq result (expand-file-name path)
1123 (setq directories (cdr directories)))))
1126 ;; xdb does not print the lines all at once, so we have to accumulate them
1127 (defun gud-xdb-marker-filter (string)
1129 (if (or (string-match comint-prompt-regexp string)
1130 (string-match ".*\012" string))
1131 (setq result (concat gud-marker-acc string)
1133 (setq gud-marker-acc (concat gud-marker-acc string)))
1135 (if (or (string-match "\\([^\n \t:]+\\): [^:]+: \\([0-9]+\\)[: ]"
1137 (string-match "[^: \t]+:[ \t]+\\([^:]+\\): [^:]+: \\([0-9]+\\):"
1139 (let ((line (string-to-int (match-string 2 result)))
1140 (file (gud-xdb-file-name (match-string 1 result))))
1142 (setq gud-last-frame (cons file line))))))
1145 (defun gud-xdb-find-file (f)
1147 (let ((realf (gud-xdb-file-name f)))
1149 (find-file-noselect realf)))))
1152 (defun xdb (command-line)
1153 "Run xdb on program FILE in buffer *gud-FILE*.
1154 The directory containing FILE becomes the initial working directory
1155 and source-file directory for your debugger.
1157 You can set the variable 'gud-xdb-directories' to a list of program source
1158 directories if your program contains sources from more than one directory."
1159 (interactive (list (gud-query-cmdline 'xdb)))
1161 (gud-common-init command-line 'gud-xdb-massage-args
1162 'gud-xdb-marker-filter 'gud-xdb-find-file)
1163 (set (make-local-variable 'gud-minor-mode) 'xdb)
1165 (gud-def gud-break "b %f:%l" "\C-b" "Set breakpoint at current line.")
1166 (gud-def gud-tbreak "b %f:%l\\t" "\C-t"
1167 "Set temporary breakpoint at current line.")
1168 (gud-def gud-remove "db" "\C-d" "Remove breakpoint at current line")
1169 (gud-def gud-step "s %p" "\C-s" "Step one line with display.")
1170 (gud-def gud-next "S %p" "\C-n" "Step one line (skip functions).")
1171 (gud-def gud-cont "c" "\C-r" "Continue with display.")
1172 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
1173 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
1174 (gud-def gud-finish "bu\\t" "\C-f" "Finish executing current function.")
1175 (gud-def gud-print "p %e" "\C-p" "Evaluate C expression at point.")
1177 (setq comint-prompt-regexp "^>")
1178 (setq paragraph-start comint-prompt-regexp)
1179 (local-set-key [menu-bar debug tbreak] '("Temporary Breakpoint" . gud-tbreak))
1180 (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish))
1181 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
1182 (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
1183 (run-hooks 'xdb-mode-hook))
1185 ;; ======================================================================
1188 ;; History of argument lists passed to perldb.
1189 (defvar gud-perldb-history nil)
1191 (defun gud-perldb-massage-args (file args)
1192 "Convert a command line as would be typed normally to run perldb
1193 into one that invokes an Emacs-enabled debugging session.
1194 \"-emacs\" is inserted where it will be $ARGV[0] (see perl5db.pl)."
1195 ;; FIXME: what if the command is `make perldb' and doesn't accept those extra
1197 (let* ((new-args nil)
1199 (shift (lambda () (push (pop args) new-args))))
1201 ;; Pass all switches and -e scripts through.
1203 (string-match "^-" (car args))
1204 (not (equal "-" (car args)))
1205 (not (equal "--" (car args))))
1206 (when (equal "-e" (car args))
1207 ;; -e goes with the next arg, so shift one extra.
1209 ;; -e as the last arg is an error in Perl.
1210 (error "No code specified for -e"))
1216 (string-match "^-" (car args)))
1217 (error "Can't use stdin as the script to debug"))
1218 ;; This is the program name.
1221 ;; If -e specified, make sure there is a -- so -emacs is not taken
1223 (if (and args (equal "--" (car args)))
1225 (and seen-e (push "--" new-args)))
1227 (push "-emacs" new-args)
1231 (nreverse new-args)))
1233 ;; There's no guarantee that Emacs will hand the filter the entire
1234 ;; marker at once; it could be broken up across several strings. We
1235 ;; might even receive a big chunk with several markers in it. If we
1236 ;; receive a chunk of text which looks like it might contain the
1237 ;; beginning of a marker, we save it here between calls to the
1239 (defun gud-perldb-marker-filter (string)
1240 (setq gud-marker-acc (concat gud-marker-acc string))
1243 ;; Process all the complete markers in this chunk.
1244 (while (string-match "\032\032\\(\\([a-zA-Z]:\\)?[^:\n]*\\):\\([0-9]*\\):.*\n"
1248 ;; Extract the frame position from the marker.
1250 (cons (substring gud-marker-acc (match-beginning 1) (match-end 1))
1251 (string-to-int (substring gud-marker-acc
1255 ;; Append any text before the marker to the output we're going
1256 ;; to return - we don't include the marker in this text.
1257 output (concat output
1258 (substring gud-marker-acc 0 (match-beginning 0)))
1260 ;; Set the accumulator to the remaining text.
1261 gud-marker-acc (substring gud-marker-acc (match-end 0))))
1263 ;; Does the remaining text look like it might end with the
1264 ;; beginning of another marker? If it does, then keep it in
1265 ;; gud-marker-acc until we receive the rest of it. Since we
1266 ;; know the full marker regexp above failed, it's pretty simple to
1267 ;; test for marker starts.
1268 (if (string-match "\032.*\\'" gud-marker-acc)
1270 ;; Everything before the potential marker start can be output.
1271 (setq output (concat output (substring gud-marker-acc
1272 0 (match-beginning 0))))
1274 ;; Everything after, we save, to combine with later input.
1275 (setq gud-marker-acc
1276 (substring gud-marker-acc (match-beginning 0))))
1278 (setq output (concat output gud-marker-acc)
1283 (defun gud-perldb-find-file (f)
1284 (find-file-noselect f))
1286 (defcustom gud-perldb-command-name "perl -d"
1287 "Default command to execute a Perl script under debugger."
1292 (defun perldb (command-line)
1293 "Run perldb on program FILE in buffer *gud-FILE*.
1294 The directory containing FILE becomes the initial working directory
1295 and source-file directory for your debugger."
1297 (list (gud-query-cmdline 'perldb
1298 (concat (or (buffer-file-name) "-e 0") " "))))
1300 (gud-common-init command-line 'gud-perldb-massage-args
1301 'gud-perldb-marker-filter 'gud-perldb-find-file)
1302 (set (make-local-variable 'gud-minor-mode) 'perldb)
1304 (gud-def gud-break "b %l" "\C-b" "Set breakpoint at current line.")
1305 (gud-def gud-remove "d %l" "\C-d" "Remove breakpoint at current line")
1306 (gud-def gud-step "s" "\C-s" "Step one source line with display.")
1307 (gud-def gud-next "n" "\C-n" "Step one line (skip functions).")
1308 (gud-def gud-cont "c" "\C-r" "Continue with display.")
1309 ; (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
1310 ; (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
1311 ; (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
1312 (gud-def gud-print "%e" "\C-p" "Evaluate perl expression at point.")
1314 (setq comint-prompt-regexp "^ DB<+[0-9]+>+ ")
1315 (setq paragraph-start comint-prompt-regexp)
1316 (run-hooks 'perldb-mode-hook))
1318 ;; ======================================================================
1319 ;; pdb (Python debugger) functions
1321 ;; History of argument lists passed to pdb.
1322 (defvar gud-pdb-history nil)
1324 ;; Last group is for return value, e.g. "> test.py(2)foo()->None"
1325 ;; Either file or function name may be omitted: "> <string>(0)?()"
1326 (defvar gud-pdb-marker-regexp
1327 "^> \\([-a-zA-Z0-9_/.:\\]*\\|<string>\\)(\\([0-9]+\\))\\([a-zA-Z0-9_]*\\|\\?\\)()\\(->[^\n]*\\)?\n")
1328 (defvar gud-pdb-marker-regexp-file-group 1)
1329 (defvar gud-pdb-marker-regexp-line-group 2)
1330 (defvar gud-pdb-marker-regexp-fnname-group 3)
1332 (defvar gud-pdb-marker-regexp-start "^> ")
1334 ;; There's no guarantee that Emacs will hand the filter the entire
1335 ;; marker at once; it could be broken up across several strings. We
1336 ;; might even receive a big chunk with several markers in it. If we
1337 ;; receive a chunk of text which looks like it might contain the
1338 ;; beginning of a marker, we save it here between calls to the
1340 (defun gud-pdb-marker-filter (string)
1341 (setq gud-marker-acc (concat gud-marker-acc string))
1344 ;; Process all the complete markers in this chunk.
1345 (while (string-match gud-pdb-marker-regexp gud-marker-acc)
1348 ;; Extract the frame position from the marker.
1350 (let ((file (match-string gud-pdb-marker-regexp-file-group
1352 (line (string-to-int
1353 (match-string gud-pdb-marker-regexp-line-group
1355 (if (string-equal file "<string>")
1359 ;; Output everything instead of the below
1360 output (concat output (substring gud-marker-acc 0 (match-end 0)))
1361 ;; ;; Append any text before the marker to the output we're going
1362 ;; ;; to return - we don't include the marker in this text.
1363 ;; output (concat output
1364 ;; (substring gud-marker-acc 0 (match-beginning 0)))
1366 ;; Set the accumulator to the remaining text.
1367 gud-marker-acc (substring gud-marker-acc (match-end 0))))
1369 ;; Does the remaining text look like it might end with the
1370 ;; beginning of another marker? If it does, then keep it in
1371 ;; gud-marker-acc until we receive the rest of it. Since we
1372 ;; know the full marker regexp above failed, it's pretty simple to
1373 ;; test for marker starts.
1374 (if (string-match gud-pdb-marker-regexp-start gud-marker-acc)
1376 ;; Everything before the potential marker start can be output.
1377 (setq output (concat output (substring gud-marker-acc
1378 0 (match-beginning 0))))
1380 ;; Everything after, we save, to combine with later input.
1381 (setq gud-marker-acc
1382 (substring gud-marker-acc (match-beginning 0))))
1384 (setq output (concat output gud-marker-acc)
1389 (defun gud-pdb-find-file (f)
1390 (find-file-noselect f))
1392 (defcustom gud-pdb-command-name "pdb"
1393 "File name for executing the Python debugger.
1394 This should be an executable on your path, or an absolute file name."
1399 (defun pdb (command-line)
1400 "Run pdb on program FILE in buffer `*gud-FILE*'.
1401 The directory containing FILE becomes the initial working directory
1402 and source-file directory for your debugger."
1404 (list (gud-query-cmdline 'pdb)))
1406 (gud-common-init command-line nil
1407 'gud-pdb-marker-filter 'gud-pdb-find-file)
1408 (set (make-local-variable 'gud-minor-mode) 'pdb)
1410 (gud-def gud-break "break %l" "\C-b" "Set breakpoint at current line.")
1411 (gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line")
1412 (gud-def gud-step "step" "\C-s" "Step one source line with display.")
1413 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
1414 (gud-def gud-cont "continue" "\C-r" "Continue with display.")
1415 (gud-def gud-finish "return" "\C-f" "Finish executing current function.")
1416 (gud-def gud-up "up" "<" "Up one stack frame.")
1417 (gud-def gud-down "down" ">" "Down one stack frame.")
1418 (gud-def gud-print "p %e" "\C-p" "Evaluate Python expression at point.")
1420 (gud-def gud-statement "! %e" "\C-e" "Execute Python statement at point.")
1422 (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish))
1423 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
1424 (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
1425 ;; (setq comint-prompt-regexp "^(.*pdb[+]?) *")
1426 (setq comint-prompt-regexp "^(Pdb) *")
1427 (setq paragraph-start comint-prompt-regexp)
1428 (run-hooks 'pdb-mode-hook))
1430 ;; ======================================================================
1434 ;; AUTHOR: Derek Davies <ddavies@world.std.com>
1435 ;; Zoltan Kemenczy <zoltan@ieee.org;zkemenczy@rim.net>
1437 ;; CREATED: Sun Feb 22 10:46:38 1998 Derek Davies.
1438 ;; UPDATED: Nov 11, 2001 Zoltan Kemenczy
1440 ;; INVOCATION NOTES:
1442 ;; You invoke jdb-mode with:
1446 ;; It responds with:
1448 ;; Run jdb (like this): jdb
1450 ;; type any jdb switches followed by the name of the class you'd like to debug.
1451 ;; Supply a fully qualfied classname (these do not have the ".class" extension)
1452 ;; for the name of the class to debug (e.g. "COM.the-kind.ddavies.CoolClass").
1453 ;; See the known problems section below for restrictions when specifying jdb
1454 ;; command line switches (search forward for '-classpath').
1456 ;; You should see something like the following:
1458 ;; Current directory is ~/src/java/hello/
1459 ;; Initializing jdb...
1460 ;; 0xed2f6628:class(hello)
1463 ;; To set an initial breakpoint try:
1465 ;; > stop in hello.main
1466 ;; Breakpoint set in hello.main
1469 ;; To execute the program type:
1474 ;; Breakpoint hit: running ...
1475 ;; hello.main (hello:12)
1477 ;; Type M-n to step over the current line and M-s to step into it. That,
1478 ;; along with the JDB 'help' command should get you started. The 'quit'
1479 ;; JDB command will get out out of the debugger. There is some truly
1480 ;; pathetic JDB documentation available at:
1482 ;; http://java.sun.com/products/jdk/1.1/debugging/
1484 ;; KNOWN PROBLEMS AND FIXME's:
1486 ;; Not sure what happens with inner classes ... haven't tried them.
1488 ;; Does not grok UNICODE id's. Only ASCII id's are supported.
1490 ;; You must not put whitespace between "-classpath" and the path to
1491 ;; search for java classes even though it is required when invoking jdb
1492 ;; from the command line. See gud-jdb-massage-args for details.
1493 ;; The same applies for "-sourcepath".
1495 ;; Note: The following applies only if `gud-jdb-use-classpath' is nil;
1496 ;; refer to the documentation of `gud-jdb-use-classpath' and
1497 ;; `gud-jdb-classpath',`gud-jdb-sourcepath' variables for information
1498 ;; on using the classpath for locating java source files.
1500 ;; If any of the source files in the directories listed in
1501 ;; gud-jdb-directories won't parse you'll have problems. Make sure
1502 ;; every file ending in ".java" in these directories parses without error.
1504 ;; All the .java files in the directories in gud-jdb-directories are
1505 ;; syntactically analyzed each time gud jdb is invoked. It would be
1506 ;; nice to keep as much information as possible between runs. It would
1507 ;; be really nice to analyze the files only as neccessary (when the
1508 ;; source needs to be displayed.) I'm not sure to what extent the former
1509 ;; can be accomplished and I'm not sure the latter can be done at all
1510 ;; since I don't know of any general way to tell which .class files are
1511 ;; defined by which .java file without analyzing all the .java files.
1512 ;; If anyone knows why JavaSoft didn't put the source file names in
1513 ;; debuggable .class files please clue me in so I find something else
1514 ;; to be spiteful and bitter about.
1516 ;; ======================================================================
1517 ;; gud jdb variables and functions
1519 (defcustom gud-jdb-command-name "jdb"
1520 "Command that executes the Java debugger."
1524 (defcustom gud-jdb-use-classpath t
1525 "If non-nil, search for Java source files in classpath directories.
1526 The list of directories to search is the value of `gud-jdb-classpath'.
1527 The file pathname is obtained by converting the fully qualified
1528 class information output by jdb to a relative pathname and appending
1529 it to `gud-jdb-classpath' element by element until a match is found.
1531 This method has a significant jdb startup time reduction advantage
1532 since it does not require the scanning of all `gud-jdb-directories'
1533 and parsing all Java files for class information.
1535 Set to nil to use `gud-jdb-directories' to scan java sources for
1536 class information on jdb startup (original method)."
1540 (defvar gud-jdb-classpath nil
1541 "Java/jdb classpath directories list.
1542 If `gud-jdb-use-classpath' is non-nil, gud-jdb derives the `gud-jdb-classpath'
1543 list automatically using the following methods in sequence
1544 \(with subsequent successful steps overriding the results of previous
1547 1) Read the CLASSPATH environment variable,
1548 2) Read any \"-classpath\" argument used to run jdb,
1549 or detected in jdb output (e.g. if jdb is run by a script
1550 that echoes the actual jdb command before starting jdb)
1551 3) Send a \"classpath\" command to jdb and scan jdb output for
1552 classpath information if jdb is invoked with an \"-attach\" (to
1553 an already running VM) argument (This case typically does not
1554 have a \"-classpath\" command line argument - that is provided
1555 to the VM when it is started).
1557 Note that method 3 cannot be used with oldjdb (or Java 1 jdb) since
1558 those debuggers do not support the classpath command. Use 1) or 2).")
1560 (defvar gud-jdb-sourcepath nil
1561 "Directory list provided by an (optional) \"-sourcepath\" option to jdb.
1562 This list is prepended to `gud-jdb-classpath' to form the complete
1563 list of directories searched for source files.")
1565 (defvar gud-marker-acc-max-length 4000
1566 "Maximum number of debugger output characters to keep.
1567 This variable limits the size of `gud-marker-acc' which holds
1568 the most recent debugger output history while searching for
1569 source file information.")
1571 (defvar gud-jdb-history nil
1572 "History of argument lists passed to jdb.")
1575 ;; List of Java source file directories.
1576 (defvar gud-jdb-directories (list ".")
1577 "*A list of directories that gud jdb should search for source code.
1578 The file names should be absolute, or relative to the current
1581 The set of .java files residing in the directories listed are
1582 syntactically analyzed to determine the classes they define and the
1583 packages in which these classes belong. In this way gud jdb maps the
1584 package-qualified class names output by the jdb debugger to the source
1585 file from which the class originated. This allows gud mode to keep
1586 the source code display in sync with the debugging session.")
1588 (defvar gud-jdb-source-files nil
1589 "List of the java source files for this debugging session.")
1591 ;; Association list of fully qualified class names (package + class name)
1592 ;; and their source files.
1593 (defvar gud-jdb-class-source-alist nil
1594 "Association list of fully qualified class names and source files.")
1596 ;; This is used to hold a source file during analysis.
1597 (defvar gud-jdb-analysis-buffer nil)
1599 (defvar gud-jdb-classpath-string nil
1600 "Holds temporary classpath values.")
1602 (defun gud-jdb-build-source-files-list (path extn)
1603 "Return a list of java source files (absolute paths).
1604 PATH gives the directories in which to search for files with
1605 extension EXTN. Normally EXTN is given as the regular expression
1607 (apply 'nconc (mapcar (lambda (d)
1608 (when (file-directory-p d)
1609 (directory-files d t extn nil)))
1612 ;; Move point past whitespace.
1613 (defun gud-jdb-skip-whitespace ()
1614 (skip-chars-forward " \n\r\t\014"))
1616 ;; Move point past a "// <eol>" type of comment.
1617 (defun gud-jdb-skip-single-line-comment ()
1620 ;; Move point past a "/* */" or "/** */" type of comment.
1621 (defun gud-jdb-skip-traditional-or-documentation-comment ()
1625 (if (eq (following-char) ?*)
1629 (if (eq (following-char) ?/)
1632 (throw 'break nil)))))
1635 ;; Move point past any number of consecutive whitespace chars and/or comments.
1636 (defun gud-jdb-skip-whitespace-and-comments ()
1637 (gud-jdb-skip-whitespace)
1642 (gud-jdb-skip-single-line-comment)
1643 (gud-jdb-skip-whitespace))
1644 ((looking-at "/\\*")
1645 (gud-jdb-skip-traditional-or-documentation-comment)
1646 (gud-jdb-skip-whitespace))
1647 (t (throw 'done nil))))))
1649 ;; Move point past things that are id-like. The intent is to skip regular
1650 ;; id's, such as class or interface names as well as package and interface
1652 (defun gud-jdb-skip-id-ish-thing ()
1653 (skip-chars-forward "^ /\n\r\t\014,;{"))
1655 ;; Move point past a string literal.
1656 (defun gud-jdb-skip-string-literal ()
1659 ((eq (following-char) ?\\)
1661 ((eq (following-char) ?\042))))
1665 ;; Move point past a character literal.
1666 (defun gud-jdb-skip-character-literal ()
1670 (if (eq (following-char) ?\\)
1672 (not (eq (following-char) ?\')))
1676 ;; Move point past the following block. There may be (legal) cruft before
1677 ;; the block's opening brace. There must be a block or it's the end of life
1678 ;; in petticoat junction.
1679 (defun gud-jdb-skip-block ()
1681 ;; Find the begining of the block.
1683 (not (eq (following-char) ?{))
1685 ;; Skip any constructs that can harbor literal block delimiter
1686 ;; characters and/or the delimiters for the constructs themselves.
1689 (gud-jdb-skip-single-line-comment))
1690 ((looking-at "/\\*")
1691 (gud-jdb-skip-traditional-or-documentation-comment))
1692 ((eq (following-char) ?\042)
1693 (gud-jdb-skip-string-literal))
1694 ((eq (following-char) ?\')
1695 (gud-jdb-skip-character-literal))
1696 (t (forward-char))))
1698 ;; Now at the begining of the block.
1701 ;; Skip over the body of the block as well as the final brace.
1702 (let ((open-level 1))
1703 (while (not (eq open-level 0))
1706 (gud-jdb-skip-single-line-comment))
1707 ((looking-at "/\\*")
1708 (gud-jdb-skip-traditional-or-documentation-comment))
1709 ((eq (following-char) ?\042)
1710 (gud-jdb-skip-string-literal))
1711 ((eq (following-char) ?\')
1712 (gud-jdb-skip-character-literal))
1713 ((eq (following-char) ?{)
1714 (setq open-level (+ open-level 1))
1716 ((eq (following-char) ?})
1717 (setq open-level (- open-level 1))
1719 (t (forward-char))))))
1721 ;; Find the package and class definitions in Java source file FILE. Assumes
1722 ;; that FILE contains a legal Java program. BUF is a scratch buffer used
1723 ;; to hold the source during analysis.
1724 (defun gud-jdb-analyze-source (buf file)
1727 (insert-file-contents file nil nil nil t)
1732 (gud-jdb-skip-whitespace)
1736 ;; Any number of semi's following a block is legal. Move point
1737 ;; past them. Note that comments and whitespace may be
1738 ;; interspersed as well.
1739 ((eq (following-char) ?\073)
1742 ;; Move point past a single line comment.
1744 (gud-jdb-skip-single-line-comment))
1746 ;; Move point past a traditional or documentation comment.
1747 ((looking-at "/\\*")
1748 (gud-jdb-skip-traditional-or-documentation-comment))
1750 ;; Move point past a package statement, but save the PackageName.
1751 ((looking-at "package")
1753 (gud-jdb-skip-whitespace-and-comments)
1755 (gud-jdb-skip-id-ish-thing)
1756 (setq p (concat (buffer-substring s (point)) "."))
1757 (gud-jdb-skip-whitespace-and-comments)
1758 (if (eq (following-char) ?\073)
1761 ;; Move point past an import statement.
1762 ((looking-at "import")
1764 (gud-jdb-skip-whitespace-and-comments)
1765 (gud-jdb-skip-id-ish-thing)
1766 (gud-jdb-skip-whitespace-and-comments)
1767 (if (eq (following-char) ?\073)
1770 ;; Move point past the various kinds of ClassModifiers.
1771 ((looking-at "public")
1773 ((looking-at "abstract")
1775 ((looking-at "final")
1778 ;; Move point past a ClassDeclaraction, but save the class
1780 ((looking-at "class")
1782 (gud-jdb-skip-whitespace-and-comments)
1784 (gud-jdb-skip-id-ish-thing)
1786 l (nconc l (list (concat p (buffer-substring s (point)))))))
1787 (gud-jdb-skip-block))
1789 ;; Move point past an interface statement.
1790 ((looking-at "interface")
1792 (gud-jdb-skip-block))
1794 ;; Anything else means the input is invalid.
1796 (message (format "Error parsing file %s." file))
1797 (throw 'abort nil))))))
1800 (defun gud-jdb-build-class-source-alist-for-file (file)
1804 (gud-jdb-analyze-source gud-jdb-analysis-buffer file)))
1806 ;; Return an alist of fully qualified classes and the source files
1807 ;; holding their definitions. SOURCES holds a list of all the source
1808 ;; files to examine.
1809 (defun gud-jdb-build-class-source-alist (sources)
1810 (setq gud-jdb-analysis-buffer (get-buffer-create " *gud-jdb-scratch*"))
1815 'gud-jdb-build-class-source-alist-for-file
1817 (kill-buffer gud-jdb-analysis-buffer)
1818 (setq gud-jdb-analysis-buffer nil)))
1820 ;; Change what was given in the minibuffer to something that can be used to
1821 ;; invoke the debugger.
1822 (defun gud-jdb-massage-args (file args)
1823 ;; The jdb executable must have whitespace between "-classpath" and
1824 ;; its value while gud-common-init expects all switch values to
1825 ;; follow the switch keyword without intervening whitespace. We
1826 ;; require that when the user enters the "-classpath" switch in the
1827 ;; EMACS minibuffer that they do so without the intervening
1828 ;; whitespace. This function adds it back (it's called after
1829 ;; gud-common-init). There are more switches like this (for
1830 ;; instance "-host" and "-password") but I don't care about them
1833 (let (massaged-args user-error)
1835 (while (and args (not user-error))
1837 ((setq user-error (string-match "-classpath$" (car args))))
1838 ((setq user-error (string-match "-sourcepath$" (car args))))
1839 ((string-match "-classpath\\(.+\\)" (car args))
1841 (append massaged-args
1844 (setq gud-jdb-classpath-string
1847 (match-beginning 1) (match-end 1)))))))
1848 ((string-match "-sourcepath\\(.+\\)" (car args))
1850 (append massaged-args
1851 (list "-sourcepath")
1853 (setq gud-jdb-sourcepath
1856 (match-beginning 1) (match-end 1)))))))
1857 (t (setq massaged-args (append massaged-args (list (car args))))))
1858 (setq args (cdr args)))
1860 ;; By this point the current directory is all screwed up. Maybe we
1861 ;; could fix things and re-invoke gud-common-init, but for now I think
1862 ;; issueing the error is good enough.
1865 (kill-buffer (current-buffer))
1866 (error "Error: Omit whitespace between '-classpath or -sourcepath' and its value")))
1869 ;; Search for an association with P, a fully qualified class name, in
1870 ;; gud-jdb-class-source-alist. The asssociation gives the fully
1871 ;; qualified file name of the source file which produced the class.
1872 (defun gud-jdb-find-source-file (p)
1873 (cdr (assoc p gud-jdb-class-source-alist)))
1875 ;; Note: Reset to this value every time a prompt is seen
1876 (defvar gud-jdb-lowest-stack-level 999)
1878 (defun gud-jdb-find-source-using-classpath (p)
1879 "Find source file corresponding to fully qualified class p.
1880 Convert p from jdb's output, converted to a pathname
1881 relative to a classpath directory."
1884 (;; Replace dots with slashes and append ".java" to generate file
1885 ;; name relative to classpath
1888 (mapconcat (lambda (x) x)
1890 ;; Eliminate any subclass references in the class
1891 ;; name string. These start with a "$"
1893 (if (string-match "$.*" x)
1894 (replace-match "" t t x) p))
1898 (cplist (append gud-jdb-sourcepath gud-jdb-classpath))
1901 (not (setq found-file
1903 (concat (car cplist) "/" filename)))))
1904 (setq cplist (cdr cplist)))
1905 (if found-file (concat (car cplist) "/" filename)))))
1907 (defun gud-jdb-find-source (string)
1908 "Alias for function used to locate source files.
1909 Set to `gud-jdb-find-source-using-classpath' or `gud-jdb-find-source-file'
1910 during jdb initialization depending on the value of
1911 `gud-jdb-use-classpath'."
1914 (defun gud-jdb-parse-classpath-string (string)
1915 "Parse the classpath list and convert each item to an absolute pathname."
1916 (mapcar (lambda (s) (if (string-match "[/\\]$" s)
1917 (replace-match "" nil nil s) s))
1918 (mapcar 'file-truename
1921 (concat "[ \t\n\r,\"" path-separator "]+")))))
1923 ;; See comentary for other debugger's marker filters - there you will find
1924 ;; important notes about STRING.
1925 (defun gud-jdb-marker-filter (string)
1927 ;; Build up the accumulator.
1928 (setq gud-marker-acc
1930 (concat gud-marker-acc string)
1933 ;; Look for classpath information until gud-jdb-classpath-string is found
1934 ;; (interactive, multiple settings of classpath from jdb
1935 ;; not supported/followed)
1936 (if (and gud-jdb-use-classpath
1937 (not gud-jdb-classpath-string)
1938 (or (string-match "classpath:[ \t[]+\\([^]]+\\)" gud-marker-acc)
1939 (string-match "-classpath[ \t\"]+\\([^ \"]+\\)" gud-marker-acc)))
1940 (setq gud-jdb-classpath
1941 (gud-jdb-parse-classpath-string
1942 (setq gud-jdb-classpath-string
1943 (substring gud-marker-acc
1944 (match-beginning 1) (match-end 1))))))
1946 ;; We process STRING from left to right. Each time through the
1947 ;; following loop we process at most one marker. After we've found a
1948 ;; marker, delete gud-marker-acc up to and including the match
1950 ;; Process each complete marker in the input.
1953 ;; Do we see a marker?
1955 ;; jdb puts out a string of the following form when it
1956 ;; hits a breakpoint:
1958 ;; <fully-qualified-class><method> (<class>:<line-number>)
1960 ;; <fully-qualified-class>'s are composed of Java ID's
1961 ;; separated by periods. <method> and <class> are
1962 ;; also Java ID's. <method> begins with a period and
1963 ;; may contain less-than and greater-than (constructors,
1964 ;; for instance, are called <init> in the symbol table.)
1965 ;; Java ID's begin with a letter followed by letters
1966 ;; and/or digits. The set of letters includes underscore
1969 ;; The first group matches <fully-qualified-class>,
1970 ;; the second group matches <class> and the third group
1971 ;; matches <line-number>. We don't care about using
1972 ;; <method> so we don't "group" it.
1974 ;; FIXME: Java ID's are UNICODE strings, this matches ASCII
1976 "\\(\[[0-9]+\] \\)*\\([a-zA-Z0-9.$_]+\\)\\.[a-zA-Z0-9$_<>(),]+ \
1977 \\(([a-zA-Z0-9.$_]+:\\|line=\\)\\([0-9]+\\)"
1980 ;; A good marker is one that:
1981 ;; 1) does not have a "[n] " prefix (not part of a stack backtrace)
1982 ;; 2) does have an "[n] " prefix and n is the lowest prefix seen
1983 ;; since the last prompt
1984 ;; Figure out the line on which to position the debugging arrow.
1985 ;; Return the info as a cons of the form:
1987 ;; (<file-name> . <line-number>) .
1988 (if (if (match-beginning 1)
1990 (setq n (string-to-int (substring
1992 (1+ (match-beginning 1))
1993 (- (match-end 1) 2))))
1994 (if (< n gud-jdb-lowest-stack-level)
1995 (progn (setq gud-jdb-lowest-stack-level n) t)))
1997 (if (setq file-found
1998 (gud-jdb-find-source
1999 (substring gud-marker-acc
2002 (setq gud-last-frame
2005 (substring gud-marker-acc
2008 (message "Could not find source file.")))
2010 ;; Set the accumulator to the remaining text.
2011 (setq gud-marker-acc (substring gud-marker-acc (match-end 0))))
2013 (if (string-match comint-prompt-regexp gud-marker-acc)
2014 (setq gud-jdb-lowest-stack-level 999)))
2016 ;; Do not allow gud-marker-acc to grow without bound. If the source
2017 ;; file information is not within the last 3/4
2018 ;; gud-marker-acc-max-length characters, well,...
2019 (if (> (length gud-marker-acc) gud-marker-acc-max-length)
2020 (setq gud-marker-acc
2021 (substring gud-marker-acc
2022 (- (/ (* gud-marker-acc-max-length 3) 4)))))
2024 ;; We don't filter any debugger output so just return what we were given.
2027 (defun gud-jdb-find-file (f)
2028 (and (file-readable-p f)
2029 (find-file-noselect f)))
2032 (defun jdb (command-line)
2033 "Run jdb with command line COMMAND-LINE in a buffer.
2034 The buffer is named \"*gud*\" if no initial class is given or
2035 \"*gud-<initial-class-basename>*\" if there is. If the \"-classpath\"
2036 switch is given, omit all whitespace between it and its value.
2038 See `gud-jdb-use-classpath' and `gud-jdb-classpath' documentation for
2039 information on how jdb accesses source files. Alternatively (if
2040 `gud-jdb-use-classpath' is nil), see `gud-jdb-directories' for the
2041 original source file access method.
2043 For general information about commands available to control jdb from
2044 gud, see `gud-mode'."
2046 (list (gud-query-cmdline 'jdb)))
2047 (setq gud-jdb-classpath nil)
2048 (setq gud-jdb-sourcepath nil)
2050 ;; Set gud-jdb-classpath from the CLASSPATH environment variable,
2051 ;; if CLASSPATH is set.
2052 (setq gud-jdb-classpath-string (getenv "CLASSPATH"))
2053 (if gud-jdb-classpath-string
2054 (setq gud-jdb-classpath
2055 (gud-jdb-parse-classpath-string gud-jdb-classpath-string)))
2056 (setq gud-jdb-classpath-string nil) ; prepare for next
2058 (gud-common-init command-line 'gud-jdb-massage-args
2059 'gud-jdb-marker-filter 'gud-jdb-find-file)
2060 (set (make-local-variable 'gud-minor-mode) 'jdb)
2062 ;; If a -classpath option was provided, set gud-jdb-classpath
2063 (if gud-jdb-classpath-string
2064 (setq gud-jdb-classpath
2065 (gud-jdb-parse-classpath-string gud-jdb-classpath-string)))
2066 (setq gud-jdb-classpath-string nil) ; prepare for next
2067 ;; If a -sourcepath option was provided, parse it
2068 (if gud-jdb-sourcepath
2069 (setq gud-jdb-sourcepath
2070 (gud-jdb-parse-classpath-string gud-jdb-sourcepath)))
2072 (gud-def gud-break "stop at %c:%l" "\C-b" "Set breakpoint at current line.")
2073 (gud-def gud-remove "clear %c:%l" "\C-d" "Remove breakpoint at current line")
2074 (gud-def gud-step "step" "\C-s" "Step one source line with display.")
2075 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
2076 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
2077 (gud-def gud-finish "step up" "\C-f" "Continue until current method returns.")
2078 (gud-def gud-up "up\C-Mwhere" "<" "Up one stack frame.")
2079 (gud-def gud-down "down\C-Mwhere" ">" "Up one stack frame.")
2080 (local-set-key [menu-bar debug finish] '("Finish Function" . gud-finish))
2081 (local-set-key [menu-bar debug up] '("Up Stack" . gud-up))
2082 (local-set-key [menu-bar debug down] '("Down Stack" . gud-down))
2084 (setq comint-prompt-regexp "^> \\|^[^ ]+\\[[0-9]+\\] ")
2085 (setq paragraph-start comint-prompt-regexp)
2086 (run-hooks 'jdb-mode-hook)
2088 (if gud-jdb-use-classpath
2089 ;; Get the classpath information from the debugger
2091 (if (string-match "-attach" command-line)
2092 (gud-call "classpath"))
2093 (fset 'gud-jdb-find-source
2094 'gud-jdb-find-source-using-classpath))
2096 ;; Else create and bind the class/source association list as well
2097 ;; as the source file list.
2098 (setq gud-jdb-class-source-alist
2099 (gud-jdb-build-class-source-alist
2100 (setq gud-jdb-source-files
2101 (gud-jdb-build-source-files-list gud-jdb-directories
2103 (fset 'gud-jdb-find-source 'gud-jdb-find-source-file)))
2107 ;; End of debugger-specific information
2111 ;; When we send a command to the debugger via gud-call, it's annoying
2112 ;; to see the command and the new prompt inserted into the debugger's
2113 ;; buffer; we have other ways of knowing the command has completed.
2115 ;; If the buffer looks like this:
2116 ;; --------------------
2117 ;; (gdb) set args foo bar
2119 ;; --------------------
2120 ;; (the -!- marks the location of point), and we type `C-x SPC' in a
2121 ;; source file to set a breakpoint, we want the buffer to end up like
2123 ;; --------------------
2124 ;; (gdb) set args foo bar
2125 ;; Breakpoint 1 at 0x92: file make-docfile.c, line 49.
2127 ;; --------------------
2128 ;; Essentially, the old prompt is deleted, and the command's output
2129 ;; and the new prompt take its place.
2131 ;; Not echoing the command is easy enough; you send it directly using
2132 ;; process-send-string, and it never enters the buffer. However,
2133 ;; getting rid of the old prompt is trickier; you don't want to do it
2134 ;; when you send the command, since that will result in an annoying
2135 ;; flicker as the prompt is deleted, redisplay occurs while Emacs
2136 ;; waits for a response from the debugger, and the new prompt is
2137 ;; inserted. Instead, we'll wait until we actually get some output
2138 ;; from the subprocess before we delete the prompt. If the command
2139 ;; produced no output other than a new prompt, that prompt will most
2140 ;; likely be in the first chunk of output received, so we will delete
2141 ;; the prompt and then replace it with an identical one. If the
2142 ;; command produces output, the prompt is moving anyway, so the
2143 ;; flicker won't be annoying.
2145 ;; So - when we want to delete the prompt upon receipt of the next
2146 ;; chunk of debugger output, we position gud-delete-prompt-marker at
2147 ;; the start of the prompt; the process filter will notice this, and
2148 ;; delete all text between it and the process output marker. If
2149 ;; gud-delete-prompt-marker points nowhere, we leave the current
2151 (defvar gud-delete-prompt-marker nil)
2154 (put 'gud-mode 'mode-class 'special)
2156 (define-derived-mode gud-mode comint-mode "Debugger"
2157 "Major mode for interacting with an inferior debugger process.
2159 You start it up with one of the commands M-x gdb, M-x sdb, M-x dbx,
2160 M-x perldb, M-x xdb, or M-x jdb. Each entry point finishes by executing a
2161 hook; `gdb-mode-hook', `sdb-mode-hook', `dbx-mode-hook',
2162 `perldb-mode-hook', `xdb-mode-hook', or `jdb-mode-hook' respectively.
2164 After startup, the following commands are available in both the GUD
2165 interaction buffer and any source buffer GUD visits due to a breakpoint stop
2168 \\[gud-break] sets a breakpoint at the current file and line. In the
2169 GUD buffer, the current file and line are those of the last breakpoint or
2170 step. In a source buffer, they are the buffer's file and current line.
2172 \\[gud-remove] removes breakpoints on the current file and line.
2174 \\[gud-refresh] displays in the source window the last line referred to
2177 \\[gud-step], \\[gud-next], and \\[gud-stepi] do a step-one-line,
2178 step-one-line (not entering function calls), and step-one-instruction
2179 and then update the source window with the current file and position.
2180 \\[gud-cont] continues execution.
2182 \\[gud-print] tries to find the largest C lvalue or function-call expression
2183 around point, and sends it to the debugger for value display.
2185 The above commands are common to all supported debuggers except xdb which
2186 does not support stepping instructions.
2188 Under gdb, sdb and xdb, \\[gud-tbreak] behaves exactly like \\[gud-break],
2189 except that the breakpoint is temporary; that is, it is removed when
2190 execution stops on it.
2192 Under gdb, dbx, and xdb, \\[gud-up] pops up through an enclosing stack
2193 frame. \\[gud-down] drops back down through one.
2195 If you are using gdb or xdb, \\[gud-finish] runs execution to the return from
2196 the current function and stops.
2198 All the keystrokes above are accessible in the GUD buffer
2199 with the prefix C-c, and in all buffers through the prefix C-x C-a.
2201 All pre-defined functions for which the concept make sense repeat
2202 themselves the appropriate number of times if you give a prefix
2205 You may use the `gud-def' macro in the initialization hook to define other
2208 Other commands for interacting with the debugger process are inherited from
2209 comint mode, which see."
2210 (setq mode-line-process '(":%s"))
2211 (define-key (current-local-map) "\C-c\C-l" 'gud-refresh)
2212 (set (make-local-variable 'gud-last-frame) nil)
2213 (make-local-variable 'comint-prompt-regexp)
2214 ;; Don't put repeated commands in command history many times.
2215 (set (make-local-variable 'comint-input-ignoredups) t)
2216 (make-local-variable 'paragraph-start)
2217 (set (make-local-variable 'gud-delete-prompt-marker) (make-marker)))
2219 ;; Cause our buffers to be displayed, by default,
2220 ;; in the selected window.
2221 ;;;###autoload (add-hook 'same-window-regexps "\\*gud-.*\\*\\(\\|<[0-9]+>\\)")
2223 (defcustom gud-chdir-before-run t
2224 "Non-nil if GUD should `cd' to the debugged executable."
2228 ;; Perform initializations common to all debuggers.
2229 ;; The first arg is the specified command line,
2230 ;; which starts with the program to debug.
2231 ;; The other three args specify the values to use
2232 ;; for local variables in the debugger buffer.
2233 (defun gud-common-init (command-line massage-args marker-filter &optional find-file)
2234 (let* ((words (split-string command-line))
2235 (program (car words))
2236 ;; Extract the file name from WORDS
2237 ;; and put t in its place.
2238 ;; Later on we will put the modified file name arg back there.
2239 (file-word (let ((w (cdr words)))
2240 (while (and w (= ?- (aref (car w) 0)))
2246 (and file-word (substitute-in-file-name file-word)))
2248 ;; If a directory was specified, expand the file name.
2249 ;; Otherwise, don't expand it, so GDB can use the PATH.
2250 ;; A file name without directory is literally valid
2251 ;; only if the file exists in ., and in that case,
2252 ;; omitting the expansion here has no visible effect.
2253 (file (and file-word
2254 (if (file-name-directory file-subst)
2255 (expand-file-name file-subst)
2257 (filepart (and file-word (concat "-" (file-name-nondirectory file)))))
2258 (pop-to-buffer (concat "*gud" filepart "*"))
2259 ;; Set default-directory to the file's directory.
2261 gud-chdir-before-run
2262 ;; Don't set default-directory if no directory was specified.
2263 ;; In that case, either the file is found in the current directory,
2264 ;; in which case this setq is a no-op,
2265 ;; or it is found by searching PATH,
2266 ;; in which case we don't know what directory it was found in.
2267 (file-name-directory file)
2268 (setq default-directory (file-name-directory file)))
2269 (or (bolp) (newline))
2270 (insert "Current directory is " default-directory "\n")
2271 ;; Put the substituted and expanded file name back in its place.
2273 (while (and w (not (eq (car w) t)))
2277 (apply 'make-comint (concat "gud" filepart) program nil
2278 (if massage-args (funcall massage-args file args) args)))
2279 ;; Since comint clobbered the mode, we don't set it until now.
2281 (make-local-variable 'gud-marker-filter)
2282 (setq gud-marker-filter marker-filter)
2283 (if find-file (set (make-local-variable 'gud-find-file) find-file))
2285 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter)
2286 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel)
2289 (defun gud-set-buffer ()
2290 (when (eq major-mode 'gud-mode)
2291 (setq gud-comint-buffer (current-buffer))))
2293 (defvar gud-filter-defer-flag nil
2294 "Non-nil means don't process anything from the debugger right now.
2295 It is saved for when this flag is not set.")
2297 (defvar gud-filter-pending-text nil
2298 "Non-nil means this is text that has been saved for later in `gud-filter'.")
2300 ;; These functions are responsible for inserting output from your debugger
2301 ;; into the buffer. The hard work is done by the method that is
2302 ;; the value of gud-marker-filter.
2304 (defun gud-filter (proc string)
2305 ;; Here's where the actual buffer insertion is done
2306 (let (output process-window)
2307 (if (buffer-name (process-buffer proc))
2308 (if gud-filter-defer-flag
2309 ;; If we can't process any text now,
2310 ;; save it for later.
2311 (setq gud-filter-pending-text
2312 (concat (or gud-filter-pending-text "") string))
2314 ;; If we have to ask a question during the processing,
2315 ;; defer any additional text that comes from the debugger
2316 ;; during that time.
2317 (let ((gud-filter-defer-flag t))
2318 ;; Process now any text we previously saved up.
2319 (if gud-filter-pending-text
2320 (setq string (concat gud-filter-pending-text string)
2321 gud-filter-pending-text nil))
2323 (with-current-buffer (process-buffer proc)
2324 ;; If we have been so requested, delete the debugger prompt.
2327 (if (marker-buffer gud-delete-prompt-marker)
2329 (delete-region (process-mark proc)
2330 gud-delete-prompt-marker)
2331 (set-marker gud-delete-prompt-marker nil)))
2332 ;; Save the process output, checking for source file markers.
2333 (setq output (gud-marker-filter string))
2334 ;; Check for a filename-and-line number.
2335 ;; Don't display the specified file
2336 ;; unless (1) point is at or after the position where output appears
2337 ;; and (2) this buffer is on the screen.
2338 (setq process-window
2340 (>= (point) (process-mark proc))
2341 (get-buffer-window (current-buffer)))))
2343 ;; Let the comint filter do the actual insertion.
2344 ;; That lets us inherit various comint features.
2345 (comint-output-filter proc output))
2347 ;; Put the arrow on the source line.
2348 ;; This must be outside of the save-excursion
2349 ;; in case the source file is our current buffer.
2351 (save-selected-window
2352 (select-window process-window)
2353 (gud-display-frame))
2354 ;; We have to be in the proper buffer, (process-buffer proc),
2355 ;; but not in a save-excursion, because that would restore point.
2356 (let ((old-buf (current-buffer)))
2357 (set-buffer (process-buffer proc))
2360 (set-buffer old-buf)))))
2362 ;; If we deferred text that arrived during this processing,
2364 (if gud-filter-pending-text
2365 (gud-filter proc ""))))))
2367 (defun gud-sentinel (proc msg)
2368 (cond ((null (buffer-name (process-buffer proc)))
2370 ;; Stop displaying an arrow in a source file.
2371 (setq overlay-arrow-position nil)
2372 (set-process-buffer proc nil))
2373 ((memq (process-status proc) '(signal exit))
2374 ;; Stop displaying an arrow in a source file.
2375 (setq overlay-arrow-position nil)
2376 (let* ((obuf (current-buffer)))
2377 ;; save-excursion isn't the right thing if
2378 ;; process-buffer is current-buffer
2381 ;; Write something in *compilation* and hack its mode line,
2382 (set-buffer (process-buffer proc))
2383 ;; Fix the mode line.
2384 (setq mode-line-process
2386 (symbol-name (process-status proc))))
2387 (force-mode-line-update)
2389 (insert ?\n mode-name " " msg)
2391 (goto-char (point-max))
2392 (insert ?\n mode-name " " msg)))
2393 ;; If buffer and mode line will show that the process
2394 ;; is dead, we can delete it now. Otherwise it
2395 ;; will stay around until M-x list-processes.
2396 (delete-process proc))
2397 ;; Restore old buffer, but don't restore old point
2398 ;; if obuf is the gud buffer.
2399 (set-buffer obuf))))))
2401 (defun gud-display-frame ()
2402 "Find and obey the last filename-and-line marker from the debugger.
2403 Obeying it means displaying in another window the specified file and line."
2408 (gud-display-line (car gud-last-frame) (cdr gud-last-frame))
2409 (setq gud-last-last-frame gud-last-frame
2410 gud-last-frame nil))))
2412 ;; Make sure the file named TRUE-FILE is in a buffer that appears on the screen
2413 ;; and that its line LINE is visible.
2414 ;; Put the overlay-arrow on the line LINE in that buffer.
2415 ;; Most of the trickiness in here comes from wanting to preserve the current
2416 ;; region-restriction if that's possible. We use an explicit display-buffer
2417 ;; to get around the fact that this is called inside a save-excursion.
2419 (defun gud-display-line (true-file line)
2420 (let* ((last-nonmenu-event t) ; Prevent use of dialog box for questions.
2423 (or (eq (current-buffer) gud-comint-buffer)
2424 (set-buffer gud-comint-buffer))
2425 (gud-find-file true-file)))
2426 (window (and buffer (or (get-buffer-window buffer)
2427 (display-buffer buffer))))
2437 (setq overlay-arrow-string "=>")
2438 (or overlay-arrow-position
2439 (setq overlay-arrow-position (make-marker)))
2440 (set-marker overlay-arrow-position (point) (current-buffer)))
2441 (cond ((or (< pos (point-min)) (> pos (point-max)))
2444 (set-window-point window overlay-arrow-position)))))
2446 ;; The gud-call function must do the right thing whether its invoking
2447 ;; keystroke is from the GUD buffer itself (via major-mode binding)
2448 ;; or a C buffer. In the former case, we want to supply data from
2449 ;; gud-last-frame. Here's how we do it:
2451 (defun gud-format-command (str arg)
2452 (let ((insource (not (eq (current-buffer) gud-comint-buffer)))
2453 (frame (or gud-last-frame gud-last-last-frame))
2455 (while (and str (string-match "\\([^%]*\\)%\\([adeflpc]\\)" str))
2456 (let ((key (string-to-char (substring str (match-beginning 2))))
2460 (setq subst (file-name-nondirectory (if insource
2464 (setq subst (file-name-sans-extension
2465 (file-name-nondirectory (if insource
2469 (setq subst (file-name-directory (if insource
2473 (setq subst (int-to-string
2477 (+ (count-lines (point-min) (point))
2481 (setq subst (gud-find-c-expr)))
2483 (setq subst (gud-read-address)))
2485 (setq subst (gud-find-class (if insource
2489 (setq subst (if arg (int-to-string arg)))))
2490 (setq result (concat result (match-string 1 str) subst)))
2491 (setq str (substring str (match-end 2))))
2492 ;; There might be text left in STR when the loop ends.
2493 (concat result str)))
2495 (defun gud-read-address ()
2496 "Return a string containing the core-address found in the buffer at point."
2498 (let ((pt (point)) found begin)
2499 (setq found (if (search-backward "0x" (- pt 7) t) (point)))
2501 (found (forward-char 2)
2502 (buffer-substring found
2503 (progn (re-search-forward "[^0-9a-f]")
2506 (t (setq begin (progn (re-search-backward "[^0-9]")
2510 (re-search-forward "[^0-9]")
2512 (buffer-substring begin (point)))))))
2514 (defun gud-call (fmt &optional arg)
2515 (let ((msg (gud-format-command fmt arg)))
2516 (message "Command: %s" msg)
2518 (gud-basic-call msg)))
2520 (defun gud-basic-call (command)
2521 "Invoke the debugger COMMAND displaying source in other window."
2524 (let ((command (concat command "\n"))
2525 (proc (get-buffer-process gud-comint-buffer)))
2526 (or proc (error "Current buffer has no process"))
2527 ;; Arrange for the current prompt to get deleted.
2529 (set-buffer gud-comint-buffer)
2532 (goto-char (process-mark proc))
2534 (if (looking-at comint-prompt-regexp)
2535 (set-marker gud-delete-prompt-marker (point)))))
2536 (process-send-string proc command)))
2538 (defun gud-refresh (&optional arg)
2539 "Fix up a possibly garbled display, and redraw the arrow."
2541 (or gud-last-frame (setq gud-last-frame gud-last-last-frame))
2545 ;; Code for parsing expressions out of C code. The single entry point is
2546 ;; find-c-expr, which tries to return an lvalue expression from around point.
2548 ;; The rest of this file is a hacked version of gdbsrc.el by
2549 ;; Debby Ayers <ayers@asc.slb.com>,
2550 ;; Rich Schaefer <schaefer@asc.slb.com> Schlumberger, Austin, Tx.
2552 (defun gud-find-c-expr ()
2553 "Returns the C expr that surrounds point."
2556 (let (p expr test-expr)
2558 (setq expr (gud-innermost-expr))
2559 (setq test-expr (gud-prev-expr))
2560 (while (and test-expr (gud-expr-compound test-expr expr))
2561 (let ((prev-expr expr))
2562 (setq expr (cons (car test-expr) (cdr expr)))
2563 (goto-char (car expr))
2564 (setq test-expr (gud-prev-expr))
2565 ;; If we just pasted on the condition of an if or while,
2566 ;; throw it away again.
2567 (if (member (buffer-substring (car test-expr) (cdr test-expr))
2568 '("if" "while" "for"))
2572 (setq test-expr (gud-next-expr))
2573 (while (gud-expr-compound expr test-expr)
2574 (setq expr (cons (car expr) (cdr test-expr)))
2575 (setq test-expr (gud-next-expr)))
2576 (buffer-substring (car expr) (cdr expr)))))
2578 (defun gud-innermost-expr ()
2579 "Returns the smallest expr that point is in; move point to beginning of it.
2580 The expr is represented as a cons cell, where the car specifies the point in
2581 the current buffer that marks the beginning of the expr and the cdr specifies
2582 the character after the end of the expr."
2583 (let ((p (point)) begin end)
2585 (setq begin (point))
2598 (defun gud-backward-sexp ()
2599 "Version of `backward-sexp' that catches errors."
2604 (defun gud-forward-sexp ()
2605 "Version of `forward-sexp' that catches errors."
2610 (defun gud-prev-expr ()
2611 "Returns the previous expr, point is set to beginning of that expr.
2612 The expr is represented as a cons cell, where the car specifies the point in
2613 the current buffer that marks the beginning of the expr and the cdr specifies
2614 the character after the end of the expr"
2615 (let ((begin) (end))
2617 (setq begin (point))
2623 (defun gud-next-expr ()
2624 "Returns the following expr, point is set to beginning of that expr.
2625 The expr is represented as a cons cell, where the car specifies the point in
2626 the current buffer that marks the beginning of the expr and the cdr specifies
2627 the character after the end of the expr."
2628 (let ((begin) (end))
2633 (setq begin (point))
2636 (defun gud-expr-compound-sep (span-start span-end)
2637 "Scan from SPAN-START to SPAN-END for punctuation characters.
2638 If `->' is found, return `?.'. If `.' is found, return `?.'.
2639 If any other punctuation is found, return `??'.
2640 If no punctuation is found, return `? '."
2643 (while (< span-start span-end)
2644 (setq syntax (char-syntax (char-after span-start)))
2647 ((= syntax ?.) (setq syntax (char-after span-start))
2649 ((= syntax ?.) (setq result ?.))
2650 ((and (= syntax ?-) (= (char-after (+ span-start 1)) ?>))
2652 (setq span-start (+ span-start 1)))
2653 (t (setq span-start span-end)
2654 (setq result ??)))))
2655 (setq span-start (+ span-start 1)))
2658 (defun gud-expr-compound (first second)
2659 "Non-nil if concatenating FIRST and SECOND makes a single C expression.
2660 The two exprs are represented as a cons cells, where the car
2661 specifies the point in the current buffer that marks the beginning of the
2662 expr and the cdr specifies the character after the end of the expr.
2663 Link exprs of the form:
2670 (let ((span-start (cdr first))
2671 (span-end (car second))
2673 (setq syntax (gud-expr-compound-sep span-start span-end))
2675 ((= (car first) (car second)) nil)
2676 ((= (cdr first) (cdr second)) nil)
2679 (setq span-start (char-after (- span-start 1)))
2680 (setq span-end (char-after span-end))
2682 ((= span-start ?)) t)
2683 ((= span-start ?]) t)
2689 (defun gud-find-class (f)
2690 "Find fully qualified class corresponding to file F.
2691 This function uses the `gud-jdb-classpath' (and optional
2692 `gud-jdb-sourcepath') list(s) to derive a file
2693 pathname relative to its classpath directory. The values in
2694 `gud-jdb-classpath' are assumed to have been converted to absolute
2695 pathname standards using file-truename."
2696 ;; Convert f to a standard representation and remove suffix
2697 (if (and gud-jdb-use-classpath (or gud-jdb-classpath gud-jdb-sourcepath))
2699 (let ((cplist (append gud-jdb-sourcepath gud-jdb-classpath))
2701 (setq f (file-name-sans-extension (file-truename f)))
2702 ;; Search through classpath list for an entry that is
2704 (while (and cplist (not class-found))
2705 (if (string-match (car cplist) f)
2707 (mapconcat (lambda(x) x)
2709 (substring f (+ (match-end 0) 1))
2711 (setq cplist (cdr cplist)))
2712 (if (not class-found)
2713 (message "gud-find-class: class for file %s not found!" f))
2715 ;; Not using classpath - try class/source association list
2716 (let ((class-found (rassoc f gud-jdb-class-source-alist)))
2719 (message "gud-find-class: class for file %s not found in gud-jdb-class-source-alist!" f)
2724 ;;; gud.el ends here