• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/emacs-93/emacs/lisp/progmodes/

Lines Matching +defs:gud +defs:gdb +defs:command +defs:name

0 ;;; gud.el --- Grand Unified Debugger mode for running GDB and other debuggers
29 ;; The ancestral gdb.el was by W. Schelter <wfs@rascal.ics.utexas.edu> It was
34 ;; <jrs@world.std.com> wrote the GDB command completion code. Dave Love
37 ;; kluge with the gud-xdb-directories hack producing gud-dbx-directories.
47 (defvar gdb-active-process)
48 (defvar gdb-define-alist)
49 (defvar gdb-macro-info)
50 (defvar gdb-server-prefix)
51 (defvar gdb-show-changed-values)
52 (defvar gdb-var-list)
53 (defvar gdb-speedbar-auto-raise)
59 (defgroup gud nil
60 "Grand Unified Debugger mode for gdb and other debuggers under Emacs.
61 Supported debuggers include gdb, sdb, dbx, xdb, perldb, pdb (Python), jdb."
66 (defcustom gud-key-prefix "\C-x\C-a"
69 :group 'gud)
71 (global-set-key (concat gud-key-prefix "\C-l") 'gud-refresh)
72 (define-key ctl-x-map " " 'gud-break) ;; backward compatibility hack
74 (defvar gud-marker-filter nil)
75 (put 'gud-marker-filter 'permanent-local t)
76 (defvar gud-find-file nil)
77 (put 'gud-find-file 'permanent-local t)
79 (defun gud-marker-filter (&rest args)
80 (apply gud-marker-filter args))
82 (defvar gud-minor-mode nil)
83 (put 'gud-minor-mode 'permanent-local t)
85 (defvar gud-comint-buffer nil)
87 (defvar gud-keep-buffer nil)
89 (defun gud-symbol (sym &optional soft minor-mode)
91 MINOR-MODE defaults to `gud-minor-mode.
92 The symbol returned is `gud-<MINOR-MODE>-<SYM>'.
94 (unless (or minor-mode gud-minor-mode) (error "Gud internal error"))
96 (format "gud-%s-%s" (or minor-mode gud-minor-mode) sym)))
98 (defun gud-val (sym &optional minor-mode)
99 "Return the value of `gud-symbol' SYM. Default to nil."
100 (let ((sym (gud-symbol sym t minor-mode)))
103 (defvar gud-running nil
108 (defun gud-goto-info ()
122 (if (memq gud-minor-mode '(gdbmi gdba))
126 (defun gud-tool-bar-item-visible-no-fringe ()
128 (and (memq gud-minor-mode '(gdbmi gdba))
131 (defun gud-stop-subjob ()
133 (with-current-buffer gud-comint-buffer
134 (if (string-equal gud-target-name "emacs")
138 (easy-mmode-defmap gud-menu-map
139 '(([help] "Info" . gud-goto-info)
140 ([tooltips] menu-item "Toggle GUD tooltips" gud-tooltip-mode
144 :visible (memq gud-minor-mode
146 :button (:toggle . gud-tooltip-mode))
147 ([refresh] "Refresh" . gud-refresh)
148 ([run] menu-item "Run" gud-run
149 :enable (not gud-running)
150 :visible (memq gud-minor-mode '(gdbmi gdb dbx jdb)))
151 ([go] menu-item (if gdb-active-process "Continue" "Run") gud-go
152 :visible (and (not gud-running)
153 (eq gud-minor-mode 'gdba)))
154 ([stop] menu-item "Stop" gud-stop-subjob
155 :visible (or (not (memq gud-minor-mode '(gdba pdb)))
156 (and gud-running
157 (eq gud-minor-mode 'gdba))))
158 ([until] menu-item "Continue to selection" gud-until
159 :enable (not gud-running)
160 :visible (and (memq gud-minor-mode '(gdbmi gdba gdb perldb))
161 (gud-tool-bar-item-visible-no-fringe)))
162 ([remove] menu-item "Remove Breakpoint" gud-remove
163 :enable (not gud-running)
164 :visible (gud-tool-bar-item-visible-no-fringe))
165 ([tbreak] menu-item "Temporary Breakpoint" gud-tbreak
166 :enable (not gud-running)
167 :visible (memq gud-minor-mode
168 '(gdbmi gdba gdb sdb xdb)))
169 ([break] menu-item "Set Breakpoint" gud-break
170 :enable (not gud-running)
171 :visible (gud-tool-bar-item-visible-no-fringe))
172 ([up] menu-item "Up Stack" gud-up
173 :enable (not gud-running)
174 :visible (memq gud-minor-mode
175 '(gdbmi gdba gdb dbx xdb jdb pdb)))
176 ([down] menu-item "Down Stack" gud-down
177 :enable (not gud-running)
178 :visible (memq gud-minor-mode
179 '(gdbmi gdba gdb dbx xdb jdb pdb)))
180 ([pp] menu-item "Print S-expression" gud-pp
181 :enable (and (not gud-running)
182 gdb-active-process)
185 'gud-target-name gud-comint-buffer) "emacs")
186 (eq gud-minor-mode 'gdba)))
187 ([print*] menu-item "Print Dereference" gud-pstar
188 :enable (not gud-running)
189 :visible (memq gud-minor-mode '(gdbmi gdba gdb)))
190 ([print] menu-item "Print Expression" gud-print
191 :enable (not gud-running))
192 ([watch] menu-item "Watch Expression" gud-watch
193 :enable (not gud-running)
194 :visible (memq gud-minor-mode '(gdbmi gdba)))
195 ([finish] menu-item "Finish Function" gud-finish
196 :enable (not gud-running)
197 :visible (memq gud-minor-mode
198 '(gdbmi gdba gdb xdb jdb pdb)))
199 ([stepi] menu-item "Step Instruction" gud-stepi
200 :enable (not gud-running)
201 :visible (memq gud-minor-mode '(gdbmi gdba gdb dbx)))
202 ([nexti] menu-item "Next Instruction" gud-nexti
203 :enable (not gud-running)
204 :visible (memq gud-minor-mode '(gdbmi gdba gdb dbx)))
205 ([step] menu-item "Step Line" gud-step
206 :enable (not gud-running))
207 ([next] menu-item "Next Line" gud-next
208 :enable (not gud-running))
209 ([cont] menu-item "Continue" gud-cont
210 :enable (not gud-running)
211 :visible (not (eq gud-minor-mode 'gdba))))
212 "Menu for `gud-mode'."
213 :name "Gud")
215 (easy-mmode-defmap gud-minor-mode-map
217 `(([menu-bar debug] . ("Gud" . ,gud-menu-map)))
222 . (,(propertize "down" 'face 'font-lock-doc-face) . gud-down))
224 . (,(propertize "up" 'face 'font-lock-doc-face) . gud-up))
226 . (,(propertize "finish" 'face 'font-lock-doc-face) . gud-finish))
228 . (,(propertize "step" 'face 'font-lock-doc-face) . gud-step))
230 . (,(propertize "next" 'face 'font-lock-doc-face) . gud-next))
232 ,(propertize "until" 'face 'font-lock-doc-face) gud-until
233 :visible (memq gud-minor-mode '(gdbmi gdba gdb perldb)))
235 ,(propertize "cont" 'face 'font-lock-doc-face) gud-cont
236 :visible (not (eq gud-minor-mode 'gdba)))
238 ,(propertize "run" 'face 'font-lock-doc-face) gud-run
239 :visible (memq gud-minor-mode '(gdbmi gdb dbx jdb)))
241 ,(propertize " go " 'face 'font-lock-doc-face) gud-go
242 :visible (and (not gud-running)
243 (eq gud-minor-mode 'gdba)))
245 ,(propertize "stop" 'face 'font-lock-doc-face) gud-stop-subjob
246 :visible (or gud-running
247 (not (eq gud-minor-mode 'gdba))))
249 . (,(propertize "print" 'face 'font-lock-doc-face) . gud-print))
257 (let ((m (assq 'gud-minor-mode minor-mode-map-alist)))
258 (if m (setcdr m gud-minor-mode-map)
259 (push (cons 'gud-minor-mode gud-minor-mode-map) minor-mode-map-alist)))
261 (defvar gud-mode-map
264 "`gud-mode' keymap.")
266 (defvar gud-tool-bar-map
269 (dolist (x '((gud-break . "gud/break")
270 (gud-remove . "gud/remove")
271 (gud-print . "gud/print")
272 (gud-pstar . "gud/pstar")
273 (gud-pp . "gud/pp")
274 (gud-watch . "gud/watch")
275 (gud-run . "gud/run")
276 (gud-go . "gud/go")
277 (gud-stop-subjob . "gud/stop")
278 (gud-cont . "gud/cont")
279 (gud-until . "gud/until")
280 (gud-next . "gud/next")
281 (gud-step . "gud/step")
282 (gud-finish . "gud/finish")
283 (gud-nexti . "gud/nexti")
284 (gud-stepi . "gud/stepi")
285 (gud-up . "gud/up")
286 (gud-down . "gud/down")
287 (gud-goto-info . "info"))
290 (car x) (cdr x) map gud-minor-mode-map)))))
292 (defun gud-file-name (f)
293 "Transform a relative file name to an absolute file name.
294 Uses `gud-<MINOR-MODE>-directories' to find the source files."
295 (if (file-exists-p f) (expand-file-name f)
296 (let ((directories (gud-val 'directories))
299 (let ((path (expand-file-name f (car directories))))
306 (defun gud-find-file (file)
307 ;; Don't get confused by double slashes in the name that comes from GDB.
310 (let ((minor-mode gud-minor-mode)
311 (buf (funcall (or gud-find-file 'gud-file-name) file)))
315 ;; Copy `gud-minor-mode' to the found buffer to turn on the menu.
317 (set (make-local-variable 'gud-minor-mode) minor-mode)
318 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
319 (when (and gud-tooltip-mode
320 (memq gud-minor-mode '(gdbmi gdba)))
321 (make-local-variable 'gdb-define-alist)
322 (unless gdb-define-alist (gdb-create-define-alist))
323 (add-hook 'after-save-hook 'gdb-create-define-alist nil t))
324 (make-local-variable 'gud-keep-buffer))
329 ;; command definition
332 ;; Of course you may use `gud-def' with any other debugger command, including
335 ;; A macro call like (gud-def FUNC NAME KEY DOC) expands to a form
336 ;; which defines FUNC to send the command NAME to the debugger, gives
341 (defmacro gud-def (func cmd key &optional doc)
342 "Define FUNC to be a command sending STR and bound to KEY, with
352 %p -- Prefix argument to the command (if any) as a number.
353 %c -- Fully qualified class name derived from the expression
367 `(gud-call ,cmd arg)
370 ,(if key `(global-set-key (vconcat gud-key-prefix ,key) ',func))))
372 ;; Where gud-display-frame should put the debugging arrow; a cons of
375 (defvar gud-last-frame nil)
377 ;; Used by gud-refresh, which should cause gud-display-frame to redisplay
378 ;; the last frame, even if it's been called before and gud-last-frame has
380 (defvar gud-last-last-frame nil)
387 ;;<name>
389 ;; gud-<name>-massage-args
390 ;; gud-<name>-marker-filter
391 ;; gud-<name>-find-file
397 ;; strings and set the global gud-last-frame to indicate what display
404 ;; by the car of gud-tag-frame. This may be a file name, a tag name, or
412 (defvar gud-last-speedbar-stackframe nil
416 (defvar gud-speedbar-key-map nil
419 (defun gud-speedbar-item-info ()
421 (let ((var (nth (- (line-number-at-pos (point)) 2) gdb-var-list)))
426 (defun gud-install-speedbar-variables ()
427 "Install those variables used by speedbar to enhance gud/gdb."
428 (if gud-speedbar-key-map
430 (setq gud-speedbar-key-map (speedbar-make-specialized-keymap))
432 (define-key gud-speedbar-key-map "j" 'speedbar-edit-line)
433 (define-key gud-speedbar-key-map "e" 'speedbar-edit-line)
434 (define-key gud-speedbar-key-map "\C-m" 'speedbar-edit-line)
435 (define-key gud-speedbar-key-map " " 'speedbar-toggle-line-expansion)
436 (define-key gud-speedbar-key-map "D" 'gdb-var-delete)
437 (define-key gud-speedbar-key-map "p" 'gud-pp))
439 (speedbar-add-expansion-list '("GUD" gud-speedbar-menu-items
440 gud-speedbar-key-map
441 gud-expansion-speedbar-buttons))
445 '("GUD" (speedbar-item-info . gud-speedbar-item-info)
448 (defvar gud-speedbar-menu-items
450 :visible (not (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
453 :visible (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
455 ["Delete expression" gdb-var-delete
456 :visible (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
458 ["Auto raise frame" gdb-speedbar-auto-raise
459 :style toggle :selected gdb-speedbar-auto-raise
460 :visible (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
466 (gud-install-speedbar-variables)
467 (add-hook 'speedbar-load-hook 'gud-install-speedbar-variables))
469 (defun gud-expansion-speedbar-buttons (directory zero)
472 (gud-speedbar-buttons gud-comint-buffer))
474 (defun gud-speedbar-buttons (buffer)
479 (when (and gud-comint-buffer
480 ;; gud-comint-buffer might be killed
481 (buffer-name gud-comint-buffer))
482 (let* ((minor-mode (with-current-buffer buffer gud-minor-mode))
490 (if gdb-speedbar-auto-raise
492 (let ((var-list gdb-var-list) parent)
499 0 (length expr) 'face font-lock-variable-name-face expr)
513 nil 'gdb-edit-value)
515 (if gdb-show-changed-values
531 'gdb-speedbar-expand-node varnum
534 nil 'gdb-edit-value)
536 (if gdb-show-changed-values
545 'gdb-speedbar-expand-node varnum
548 (if (and (or parent status) gdb-show-changed-values)
555 (equal gud-last-last-frame gud-last-speedbar-stackframe))
556 (let ((gud-frame-list
557 (cond ((eq minor-mode 'gdb)
558 (gud-gdb-get-stackframe buffer))
563 (if (not gud-frame-list)
566 (dolist (frame gud-frame-list)
577 (cond ((memq minor-mode '(gdbmi gdba gdb))
578 'gud-gdb-goto-stackframe)
581 (setq gud-last-speedbar-stackframe gud-last-last-frame))))
588 ;; gdb functions
590 ;; History of argument lists passed to gdb.
591 (defvar gud-gdb-history nil)
593 (defcustom gud-gdb-command-name "gdb --annotate=3"
594 "Default command to execute an executable under the GDB debugger."
596 :group 'gud)
598 (defvar gud-gdb-marker-regexp
611 (defvar gud-marker-acc "")
612 (make-variable-buffer-local 'gud-marker-acc)
614 (defun gud-gdb-marker-filter (string)
615 (setq gud-marker-acc (concat gud-marker-acc string))
619 (while (string-match gud-gdb-marker-regexp gud-marker-acc)
623 gud-last-frame (cons (match-string 1 gud-marker-acc)
624 (string-to-number (match-string 2 gud-marker-acc)))
629 (substring gud-marker-acc 0 (match-beginning 0)))
632 gud-marker-acc (substring gud-marker-acc (match-end 0))))
634 ;; Check for annotations and change gud-minor-mode to 'gdba if
636 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
637 (let ((match (match-string 1 gud-marker-acc)))
640 (if (string-equal match "stopped") (setq gdb-active-process t))
642 ;; Using annotations, switch to gud-gdba-marker-filter.
644 (require 'gdb-ui)
645 (gdb-prompt nil))
651 (substring gud-marker-acc 0 (match-beginning 0)))
655 gud-marker-acc (substring gud-marker-acc (match-end 0)))
659 (put-text-property 0 (length gud-marker-acc)
661 gud-marker-acc))))
665 ;; gud-marker-acc until we receive the rest of it. Since we
668 (if (string-match "\n\\(\032.*\\)?\\'" gud-marker-acc)
671 (setq output (concat output (substring gud-marker-acc
675 (setq gud-marker-acc
676 (substring gud-marker-acc (match-beginning 0))))
678 (setq output (concat output gud-marker-acc)
679 gud-marker-acc ""))
683 (easy-mmode-defmap gud-minibuffer-local-map
685 "Keymap for minibuffer prompting of gud startup command."
688 (defun gud-query-cmdline (minor-mode &optional init)
689 (let* ((hist-sym (gud-symbol 'history nil minor-mode))
690 (cmd-name (gud-val 'command-name minor-mode)))
695 (concat (or cmd-name (symbol-name minor-mode))
705 gud-minibuffer-local-map nil
708 (defvar gdb-first-prompt t)
710 (defvar gud-filter-pending-text nil
711 "Non-nil means this is text that has been saved for later in `gud-filter'.")
714 (defun gdb (command-line)
715 "Run gdb on program FILE in buffer *gud-FILE*.
718 default this command starts GDB using a graphical interface. See
721 To run GDB in text command mode, replace the GDB \"--annotate=3\"
724 `gud-gdb-command-name' for all future sessions. You need to use
725 text command mode to debug multiple programs within one Emacs
727 (interactive (list (gud-query-cmdline 'gdb)))
729 (when (and gud-comint-buffer
730 (buffer-name gud-comint-buffer)
731 (get-buffer-process gud-comint-buffer)
732 (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba)))
733 (gdb-restore-windows)
735 "Multiple debugging requires restarting in text command mode"))
737 (gud-common-init command-line nil 'gud-gdb-marker-filter)
738 (set (make-local-variable 'gud-minor-mode) 'gdb)
740 (gud-def gud-break "break %f:%l" "\C-b" "Set breakpoint at current line.")
741 (gud-def gud-tbreak "tbreak %f:%l" "\C-t"
743 (gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line")
744 (gud-def gud-step "step %p" "\C-s" "Step one source line with display.")
745 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
746 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).")
747 (gud-def gud-nexti "nexti %p" nil "Step one instruction (skip functions).")
748 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
749 (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
750 (gud-def gud-jump
751 (progn (gud-call "tbreak %f:%l") (gud-call "jump %f:%l"))
754 (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
755 (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
756 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
757 (gud-def gud-pstar "print* %e" nil
761 (gud-def gud-pv "pv1 %e" "\C-v" "Print the value of the lisp variable.")
763 (gud-def gud-until "until %l" "\C-u" "Continue to current line.")
764 (gud-def gud-run "run" nil "Run the program.")
766 (local-set-key "\C-i" 'gud-gdb-complete-command)
767 (setq comint-prompt-regexp "^(.*gdb[+]?) *")
769 (setq gdb-first-prompt t)
770 (setq gud-filter-pending-text nil)
771 (run-hooks 'gdb-mode-hook))
774 ;; context-sensitive command completion. We preserve that feature
775 ;; in the GUD buffer by using a GDB command designed just for Emacs.
778 (defvar gud-gdb-fetch-lines-in-progress)
781 (defvar gud-gdb-fetch-lines-string)
784 (defvar gud-gdb-fetch-lines-break)
787 (defvar gud-gdb-fetched-lines)
789 (defun gud-gdb-complete-command (&optional command a b)
790 "Perform completion on the GDB command preceding point.
791 This is implemented using the GDB `complete' command which isn't
794 (if command
795 ;; Used by gud-watch in mini-buffer.
796 (setq command (concat "p " command))
799 (setq command (buffer-substring (comint-line-beginning-position) end))))
800 (let* ((command-word
802 (and (string-match "\\(\\`\\| \\)\\([^ ]*\\)\\'" command)
803 (substring command (match-beginning 2))))
805 (gud-gdb-run-command-fetch-lines (concat "complete " command)
811 (string-match "^Undefined command: \"complete\"" (car complete-list))
812 (error "This version of GDB doesn't support the `complete' command"))
835 (comint-dynamic-simple-complete command-word complete-list)))
839 (defun gud-gdb-fetch-lines-filter (string filter)
840 "Filter used to read the list of lines output by a command.
844 (setq string (concat gud-gdb-fetch-lines-string string))
846 (push (substring string gud-gdb-fetch-lines-break (match-beginning 0))
847 gud-gdb-fetched-lines)
851 (setq gud-gdb-fetch-lines-in-progress nil)
854 (setq gud-gdb-fetch-lines-string string)
857 ;; gdb speedbar functions
859 (defun gud-gdb-goto-stackframe (text token indent)
862 (gud-basic-call (concat "server frame " (nth 1 token)))
865 (defvar gud-gdb-fetched-stack-frame nil
868 ;(defun gud-gdb-get-scope-data (text token indent)
873 ; (gud-gdb-run-command-fetch-lines "info args")
875 ; (gud-gdb-run-command-fetch-lines "info local")
879 (defun gud-gdb-get-stackframe (buffer)
883 (gud-gdb-run-command-fetch-lines "server backtrace" buffer)))
889 (let ((name nil) (num nil))
902 name (match-string 2 e))
907 (list name num (match-string 1 e)
909 (list name num))
913 ;(defun gud-gdb-selected-frame-info (buffer)
917 (defun gud-gdb-run-command-fetch-lines (command buffer &optional skip)
921 (with-current-buffer gud-comint-buffer
922 (if (and (eq gud-comint-buffer buffer)
930 (let ((gud-gdb-fetch-lines-in-progress t)
931 (gud-gdb-fetched-lines nil)
932 (gud-gdb-fetch-lines-string nil)
933 (gud-gdb-fetch-lines-break (or skip 0))
934 (gud-marker-filter
936 (gud-gdb-fetch-lines-filter string ',gud-marker-filter))))
937 ;; Issue the command to GDB.
938 (gud-basic-call command)
940 (while gud-gdb-fetch-lines-in-progress
941 (accept-process-output (get-buffer-process gud-comint-buffer)))
942 (nreverse gud-gdb-fetched-lines)))))
950 (defvar gud-sdb-history nil)
952 (defvar gud-sdb-needs-tags (not (file-exists-p "/var"))
955 (defvar gud-sdb-lastfile nil)
957 (defun gud-sdb-marker-filter (string)
958 (setq gud-marker-acc
959 (if gud-marker-acc (concat gud-marker-acc string) string))
966 gud-marker-acc start)
967 (setq gud-last-frame
968 (cons (match-string 3 gud-marker-acc)
969 (string-to-number (match-string 4 gud-marker-acc)))))
972 gud-marker-acc start)
973 (setq gud-sdb-lastfile (match-string 2 gud-marker-acc))
974 (setq gud-last-frame
975 (cons gud-sdb-lastfile
976 (string-to-number (match-string 3 gud-marker-acc)))))
979 gud-marker-acc start)
980 (setq gud-sdb-lastfile (match-string 2 gud-marker-acc)))
981 ((and gud-sdb-lastfile (string-match "^\\([0-9]+\\):"
982 gud-marker-acc start))
983 (setq gud-last-frame
984 (cons gud-sdb-lastfile
985 (string-to-number (match-string 1 gud-marker-acc)))))
987 (setq gud-sdb-lastfile nil)))
991 (while (string-match "\n" gud-marker-acc start)
994 ;; If we have an incomplete line, store it in gud-marker-acc.
995 (setq gud-marker-acc (substring gud-marker-acc (or start 0))))
998 (defun gud-sdb-find-file (f)
999 (if gud-sdb-needs-tags (find-tag-noselect f) (find-file-noselect f)))
1002 (defun sdb (command-line)
1003 "Run sdb on program FILE in buffer *gud-FILE*.
1006 (interactive (list (gud-query-cmdline 'sdb)))
1008 (if gud-sdb-needs-tags (require 'etags))
1009 (if (and gud-sdb-needs-tags
1010 (not (and (boundp 'tags-file-name)
1011 (stringp tags-file-name)
1012 (file-exists-p tags-file-name))))
1015 (gud-common-init command-line nil 'gud-sdb-marker-filter 'gud-sdb-find-file)
1016 (set (make-local-variable 'gud-minor-mode) 'sdb)
1018 (gud-def gud-break "%l b" "\C-b" "Set breakpoint at current line.")
1019 (gud-def gud-tbreak "%l c" "\C-t" "Set temporary breakpoint at current line.")
1020 (gud-def gud-remove "%l d" "\C-d" "Remove breakpoint at current line")
1021 (gud-def gud-step "s %p" "\C-s" "Step one source line with display.")
1022 (gud-def gud-stepi "i %p" "\C-i" "Step one instruction with display.")
1023 (gud-def gud-next "S %p" "\C-n" "Step one line (skip functions).")
1024 (gud-def gud-cont "c" "\C-r" "Continue with display.")
1025 (gud-def gud-print "%e/" "\C-p" "Evaluate C expression at point.")
1037 (defvar gud-dbx-history nil)
1039 (defcustom gud-dbx-directories nil
1049 :group 'gud)
1051 (defun gud-dbx-massage-args (file args)
1052 (nconc (let ((directories gud-dbx-directories)
1060 (defun gud-dbx-marker-filter (string)
1061 (setq gud-marker-acc (if gud-marker-acc (concat gud-marker-acc string) string))
1067 gud-marker-acc start)
1070 gud-marker-acc start))
1071 (setq gud-last-frame
1072 (cons (match-string 2 gud-marker-acc)
1073 (string-to-number (match-string 1 gud-marker-acc)))
1077 (while (string-match "\n" gud-marker-acc start)
1083 (setq gud-marker-acc
1084 (if (string-match "\\(stopped\\|signal\\)" gud-marker-acc start)
1085 (substring gud-marker-acc (match-beginning 0))
1090 ;; OSF1, not necessarily elsewhere, it produces markers similar to gdb's.
1091 (defvar gud-mips-p
1093 ;; We haven't tested gud on this system:
1100 (defvar gud-dbx-command-name
1101 (concat "dbx" (if gud-mips-p " -emacs")))
1103 ;; This is just like the gdb one except for the regexps since we need to cope
1105 (defun gud-mipsdbx-marker-filter (string)
1106 (setq gud-marker-acc (concat gud-marker-acc string))
1111 ;; This is like th gdb marker but with an optional
1114 gud-marker-acc)
1118 gud-last-frame
1119 (cons (match-string 1 gud-marker-acc)
1120 (string-to-number (match-string 2 gud-marker-acc)))
1125 (substring gud-marker-acc 0 (match-beginning 0)))
1128 gud-marker-acc (substring gud-marker-acc (match-end 0))))
1132 ;; gud-marker-acc until we receive the rest of it. Since we
1135 (if (string-match "[][ 0-9]*\032.*\\'" gud-marker-acc)
1138 (setq output (concat output (substring gud-marker-acc
1142 (setq gud-marker-acc
1143 (substring gud-marker-acc (match-beginning 0))))
1145 (setq output (concat output gud-marker-acc)
1146 gud-marker-acc ""))
1150 ;; The dbx in IRIX is a pain. It doesn't print the file name when
1153 ;; to be with a `file' command, although the current line number is
1159 ;; the gdb marker but you can't get the file name without a newline...
1160 ;; Note that gud-remove won't work since Irix dbx expects a breakpoint
1166 (defvar gud-irix-p
1170 This works in IRIX 4, 5 and 6, but `gud-dbx-use-stopformat-p' provides
1172 (defvar gud-dbx-use-stopformat-p
1176 `gud-dbx-marker-filter'.")
1179 ;; the output from `up' is no longer spotted by gud (and it's probably
1188 ;; with `gud-dbx-marker-filter', which we prefer.
1194 ;; -emacs flag for gdb-like output (which ought to be possible as most
1197 ;; this filter is influenced by the xdb one rather than the gdb one
1198 (defun gud-irixdbx-marker-filter (string)
1202 (setq result (concat gud-marker-acc string)
1203 gud-marker-acc "")
1204 (setq gud-marker-acc (concat gud-marker-acc string)))
1215 ;; name in a form we can grok as below
1216 (process-send-string (get-buffer-process gud-comint-buffer)
1226 (setq gud-last-frame
1232 (let ((file (gud-file-name (match-string 2 result))))
1234 (setq gud-last-frame
1240 (defvar gud-dgux-p (string-match "-dgux" system-configuration)
1262 (defun gud-dguxdbx-marker-filter (string)
1263 (setq gud-marker-acc (if gud-marker-acc
1264 (concat gud-marker-acc string)
1270 (while (string-match re gud-marker-acc start)
1271 (setq gud-last-frame
1272 (cons (match-string 4 gud-marker-acc)
1273 (string-to-number (match-string 3 gud-marker-acc)))
1277 (while (string-match "\n" gud-marker-acc start)
1283 (setq gud-marker-acc
1284 (if (string-match "Stopped\\|Frame" gud-marker-acc start)
1285 (substring gud-marker-acc (match-beginning 0))
1290 (defun dbx (command-line)
1291 "Run dbx on program FILE in buffer *gud-FILE*.
1294 (interactive (list (gud-query-cmdline 'dbx)))
1297 (gud-mips-p
1298 (gud-common-init command-line nil 'gud-mipsdbx-marker-filter))
1299 (gud-irix-p
1300 (gud-common-init command-line 'gud-dbx-massage-args
1301 'gud-irixdbx-marker-filter))
1302 (gud-dgux-p
1303 (gud-common-init command-line 'gud-dbx-massage-args
1304 'gud-dguxdbx-marker-filter))
1306 (gud-common-init command-line 'gud-dbx-massage-args
1307 'gud-dbx-marker-filter)))
1309 (set (make-local-variable 'gud-minor-mode) 'dbx)
1312 (gud-mips-p
1313 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
1314 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
1315 (gud-def gud-break "stop at \"%f\":%l"
1317 (gud-def gud-finish "return" "\C-f" "Finish executing current function."))
1318 (gud-irix-p
1319 (gud-def gud-break "stop at \"%d%f\":%l"
1321 (gud-def gud-finish "return" "\C-f" "Finish executing current function.")
1322 (gud-def gud-up "up %p; printf \"\032\032%1d:\",(int)$curline;file\n"
1324 (gud-def gud-down "down %p; printf \"\032\032%1d:\",(int)$curline;file\n"
1327 (process-send-string (get-buffer-process gud-comint-buffer)
1330 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
1331 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
1332 (gud-def gud-break "file \"%d%f\"\nstop at %l"
1334 (if gud-dbx-use-stopformat-p
1335 (process-send-string (get-buffer-process gud-comint-buffer)
1338 (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
1339 (gud-def gud-step "step %p" "\C-s" "Step one line with display.")
1340 (gud-def gud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
1341 (gud-def gud-next "next %p" "\C-n" "Step one line (skip functions).")
1342 (gud-def gud-nexti "nexti %p" nil "Step one instruction (skip functions).")
1343 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
1344 (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
1345 (gud-def gud-run "run" nil "Run the program.")
1357 (defvar gud-xdb-history nil)
1359 (defcustom gud-xdb-directories nil
1369 :group 'gud)
1371 (defun gud-xdb-massage-args (file args)
1372 (nconc (let ((directories gud-xdb-directories)
1381 (defun gud-xdb-marker-filter (string)
1385 (setq result (concat gud-marker-acc string)
1386 gud-marker-acc "")
1387 (setq gud-marker-acc (concat gud-marker-acc string)))
1394 (file (gud-file-name (match-string 1 result))))
1396 (setq gud-last-frame (cons file line))))))
1400 (defun xdb (command-line)
1401 "Run xdb on program FILE in buffer *gud-FILE*.
1405 You can set the variable `gud-xdb-directories' to a list of program source
1407 (interactive (list (gud-query-cmdline 'xdb)))
1409 (gud-common-init command-line 'gud-xdb-massage-args
1410 'gud-xdb-marker-filter)
1411 (set (make-local-variable 'gud-minor-mode) 'xdb)
1413 (gud-def gud-break "b %f:%l" "\C-b" "Set breakpoint at current line.")
1414 (gud-def gud-tbreak "b %f:%l\\t" "\C-t"
1416 (gud-def gud-remove "db" "\C-d" "Remove breakpoint at current line")
1417 (gud-def gud-step "s %p" "\C-s" "Step one line with display.")
1418 (gud-def gud-next "S %p" "\C-n" "Step one line (skip functions).")
1419 (gud-def gud-cont "c" "\C-r" "Continue with display.")
1420 (gud-def gud-up "up %p" "<" "Up (numeric arg) stack frames.")
1421 (gud-def gud-down "down %p" ">" "Down (numeric arg) stack frames.")
1422 (gud-def gud-finish "bu\\t" "\C-f" "Finish executing current function.")
1423 (gud-def gud-print "p %e" "\C-p" "Evaluate C expression at point.")
1434 (defvar gud-perldb-history nil)
1436 (defun gud-perldb-massage-args (file args)
1437 "Convert a command line as would be typed normally to run perldb
1440 ;; FIXME: what if the command is `make perldb' and doesn't accept those extra
1463 ;; This is the program name.
1484 (defun gud-perldb-marker-filter (string)
1485 (setq gud-marker-acc (concat gud-marker-acc string))
1490 gud-marker-acc)
1494 gud-last-frame
1495 (cons (match-string 1 gud-marker-acc)
1496 (string-to-number (match-string 3 gud-marker-acc)))
1501 (substring gud-marker-acc 0 (match-beginning 0)))
1504 gud-marker-acc (substring gud-marker-acc (match-end 0))))
1508 ;; gud-marker-acc until we receive the rest of it. Since we
1511 (if (string-match "\032.*\\'" gud-marker-acc)
1514 (setq output (concat output (substring gud-marker-acc
1518 (setq gud-marker-acc
1519 (substring gud-marker-acc (match-beginning 0))))
1521 (setq output (concat output gud-marker-acc)
1522 gud-marker-acc ""))
1526 (defcustom gud-perldb-command-name "perl -d"
1527 "Default command to execute a Perl script under debugger."
1529 :group 'gud)
1532 (defun perldb (command-line)
1533 "Run perldb on program FILE in buffer *gud-FILE*.
1537 (list (gud-query-cmdline 'perldb
1538 (concat (or (buffer-file-name) "-e 0") " "))))
1540 (gud-common-init command-line 'gud-perldb-massage-args
1541 'gud-perldb-marker-filter)
1542 (set (make-local-variable 'gud-minor-mode) 'perldb)
1544 (gud-def gud-break "b %l" "\C-b" "Set breakpoint at current line.")
1545 (gud-def gud-remove "B %l" "\C-d" "Remove breakpoint at current line")
1546 (gud-def gud-step "s" "\C-s" "Step one source line with display.")
1547 (gud-def gud-next "n" "\C-n" "Step one line (skip functions).")
1548 (gud-def gud-cont "c" "\C-r" "Continue with display.")
1549 ; (gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
1550 ; (gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
1551 ; (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
1552 (gud-def gud-print "p %e" "\C-p" "Evaluate perl expression at point.")
1553 (gud-def gud-until "c %l" "\C-u" "Continue to current line.")
1565 (defvar gud-pdb-history nil)
1568 ;; Either file or function name may be omitted: "> <string>(0)?()"
1569 (defvar gud-pdb-marker-regexp
1571 (defvar gud-pdb-marker-regexp-file-group 1)
1572 (defvar gud-pdb-marker-regexp-line-group 2)
1573 (defvar gud-pdb-marker-regexp-fnname-group 3)
1575 (defvar gud-pdb-marker-regexp-start "^> ")
1583 (defun gud-pdb-marker-filter (string)
1584 (setq gud-marker-acc (concat gud-marker-acc string))
1588 (while (string-match gud-pdb-marker-regexp gud-marker-acc)
1592 gud-last-frame
1593 (let ((file (match-string gud-pdb-marker-regexp-file-group
1594 gud-marker-acc))
1596 (match-string gud-pdb-marker-regexp-line-group
1597 gud-marker-acc))))
1599 gud-last-frame
1603 output (concat output (substring gud-marker-acc 0 (match-end 0)))
1607 ;; (substring gud-marker-acc 0 (match-beginning 0)))
1610 gud-marker-acc (substring gud-marker-acc (match-end 0))))
1614 ;; gud-marker-acc until we receive the rest of it. Since we
1617 (if (string-match gud-pdb-marker-regexp-start gud-marker-acc)
1620 (setq output (concat output (substring gud-marker-acc
1624 (setq gud-marker-acc
1625 (substring gud-marker-acc (match-beginning 0))))
1627 (setq output (concat output gud-marker-acc)
1628 gud-marker-acc ""))
1632 (defcustom gud-pdb-command-name "pdb"
1633 "File name for executing the Python debugger.
1634 This should be an executable on your path, or an absolute file name."
1636 :group 'gud)
1639 (defun pdb (command-line)
1640 "Run pdb on program FILE in buffer `*gud-FILE*'.
1644 (list (gud-query-cmdline 'pdb)))
1646 (gud-common-init command-line nil 'gud-pdb-marker-filter)
1647 (set (make-local-variable 'gud-minor-mode) 'pdb)
1649 (gud-def gud-break "break %l" "\C-b" "Set breakpoint at current line.")
1650 (gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line")
1651 (gud-def gud-step "step" "\C-s" "Step one source line with display.")
1652 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
1653 (gud-def gud-cont "continue" "\C-r" "Continue with display.")
1654 (gud-def gud-finish "return" "\C-f" "Finish executing current function.")
1655 (gud-def gud-up "up" "<" "Up one stack frame.")
1656 (gud-def gud-down "down" ">" "Down one stack frame.")
1657 (gud-def gud-print "p %e" "\C-p" "Evaluate Python expression at point.")
1659 (gud-def gud-statement "! %e" "\C-e" "Execute Python statement at point.")
1688 ;; type any jdb switches followed by the name of the class you'd like to debug.
1690 ;; for the name of the class to debug (e.g. "COM.the-kind.ddavies.CoolClass").
1692 ;; command line switches (search forward for '-classpath').
1716 ;; along with the JDB 'help' command should get you started. The 'quit'
1717 ;; JDB command will get out out of the debugger. There is some truly
1730 ;; from the command line. See gud-jdb-massage-args for details.
1733 ;; Note: The following applies only if `gud-jdb-use-classpath' is nil;
1734 ;; refer to the documentation of `gud-jdb-use-classpath' and
1735 ;; `gud-jdb-classpath',`gud-jdb-sourcepath' variables for information
1739 ;; gud-jdb-directories won't parse you'll have problems. Make sure
1742 ;; All the .java files in the directories in gud-jdb-directories are
1743 ;; syntactically analyzed each time gud jdb is invoked. It would be
1755 ;; gud jdb variables and functions
1757 (defcustom gud-jdb-command-name "jdb"
1760 :group 'gud)
1762 (defcustom gud-jdb-use-classpath t
1764 The list of directories to search is the value of `gud-jdb-classpath'.
1767 it to `gud-jdb-classpath' element by element until a match is found.
1770 since it does not require the scanning of all `gud-jdb-directories'
1773 Set to nil to use `gud-jdb-directories' to scan java sources for
1776 :group 'gud)
1778 (defvar gud-jdb-classpath nil
1780 If `gud-jdb-use-classpath' is non-nil, gud-jdb derives the `gud-jdb-classpath'
1788 that echoes the actual jdb command before starting jdb)
1789 3) Send a \"classpath\" command to jdb and scan jdb output for
1792 have a \"-classpath\" command line argument - that is provided
1796 those debuggers do not support the classpath command. Use 1) or 2).")
1798 (defvar gud-jdb-sourcepath nil
1800 This list is prepended to `gud-jdb-classpath' to form the complete
1803 (defvar gud-marker-acc-max-length 4000
1805 This variable limits the size of `gud-marker-acc' which holds
1809 (defvar gud-jdb-history nil
1814 (defvar gud-jdb-directories (list ".")
1815 "*A list of directories that gud jdb should search for source code.
1821 packages in which these classes belong. In this way gud jdb maps the
1823 file from which the class originated. This allows gud mode to keep
1826 (defvar gud-jdb-source-files nil
1829 ;; Association list of fully qualified class names (package + class name)
1831 (defvar gud-jdb-class-source-alist nil
1835 (defvar gud-jdb-analysis-buffer nil)
1837 (defvar gud-jdb-classpath-string nil
1840 (defun gud-jdb-build-source-files-list (path extn)
1851 (defun gud-jdb-skip-whitespace ()
1855 (defun gud-jdb-skip-single-line-comment ()
1859 (defun gud-jdb-skip-traditional-or-documentation-comment ()
1874 (defun gud-jdb-skip-whitespace-and-comments ()
1875 (gud-jdb-skip-whitespace)
1880 (gud-jdb-skip-single-line-comment)
1881 (gud-jdb-skip-whitespace))
1883 (gud-jdb-skip-traditional-or-documentation-comment)
1884 (gud-jdb-skip-whitespace))
1890 (defun gud-jdb-skip-id-ish-thing ()
1894 (defun gud-jdb-skip-string-literal ()
1904 (defun gud-jdb-skip-character-literal ()
1917 (defun gud-jdb-skip-block ()
1927 (gud-jdb-skip-single-line-comment))
1929 (gud-jdb-skip-traditional-or-documentation-comment))
1931 (gud-jdb-skip-string-literal))
1933 (gud-jdb-skip-character-literal))
1944 (gud-jdb-skip-single-line-comment))
1946 (gud-jdb-skip-traditional-or-documentation-comment))
1948 (gud-jdb-skip-string-literal))
1950 (gud-jdb-skip-character-literal))
1962 (defun gud-jdb-analyze-source (buf file)
1970 (gud-jdb-skip-whitespace)
1982 (gud-jdb-skip-single-line-comment))
1986 (gud-jdb-skip-traditional-or-documentation-comment))
1991 (gud-jdb-skip-whitespace-and-comments)
1993 (gud-jdb-skip-id-ish-thing)
1995 (gud-jdb-skip-whitespace-and-comments)
2002 (gud-jdb-skip-whitespace-and-comments)
2003 (gud-jdb-skip-id-ish-thing)
2004 (gud-jdb-skip-whitespace-and-comments)
2020 (gud-jdb-skip-whitespace-and-comments)
2022 (gud-jdb-skip-id-ish-thing)
2025 (gud-jdb-skip-block))
2030 (gud-jdb-skip-block))
2038 (defun gud-jdb-build-class-source-alist-for-file (file)
2042 (gud-jdb-analyze-source gud-jdb-analysis-buffer file)))
2047 (defun gud-jdb-build-class-source-alist (sources)
2048 (setq gud-jdb-analysis-buffer (get-buffer-create " *gud-jdb-scratch*"))
2053 'gud-jdb-build-class-source-alist-for-file
2055 (kill-buffer gud-jdb-analysis-buffer)
2056 (setq gud-jdb-analysis-buffer nil)))
2060 (defun gud-jdb-massage-args (file args)
2062 ;; its value while gud-common-init expects all switch values to
2067 ;; gud-common-init). There are more switches like this (for
2081 (setq gud-jdb-classpath-string
2087 (setq gud-jdb-sourcepath
2093 ;; could fix things and re-invoke gud-common-init, but for now I think
2101 ;; Search for an association with P, a fully qualified class name, in
2102 ;; gud-jdb-class-source-alist. The asssociation gives the fully
2103 ;; qualified file name of the source file which produced the class.
2104 (defun gud-jdb-find-source-file (p)
2105 (cdr (assoc p gud-jdb-class-source-alist)))
2108 (defvar gud-jdb-lowest-stack-level 999)
2110 (defun gud-jdb-find-source-using-classpath (p)
2117 ;; name relative to classpath
2123 ;; name string. These start with a "$"
2130 (cplist (append gud-jdb-sourcepath gud-jdb-classpath))
2139 (defun gud-jdb-find-source (string)
2141 Set to `gud-jdb-find-source-using-classpath' or `gud-jdb-find-source-file'
2143 `gud-jdb-use-classpath'."
2146 (defun gud-jdb-parse-classpath-string (string)
2157 (defun gud-jdb-marker-filter (string)
2160 (setq gud-marker-acc
2161 (if gud-marker-acc
2162 (concat gud-marker-acc string)
2165 ;; Look for classpath information until gud-jdb-classpath-string is found
2168 (if (and gud-jdb-use-classpath
2169 (not gud-jdb-classpath-string)
2170 (or (string-match "classpath:[ \t[]+\\([^]]+\\)" gud-marker-acc)
2171 (string-match "-classpath[ \t\"]+\\([^ \"]+\\)" gud-marker-acc)))
2172 (setq gud-jdb-classpath
2173 (gud-jdb-parse-classpath-string
2174 (setq gud-jdb-classpath-string
2175 (match-string 1 gud-marker-acc)))))
2179 ;; marker, delete gud-marker-acc up to and including the match
2216 gud-marker-acc)
2225 ;; (<file-name> . <line-number>) .
2229 gud-marker-acc
2232 (if (< n gud-jdb-lowest-stack-level)
2233 (progn (setq gud-jdb-lowest-stack-level n) t)))
2236 (gud-jdb-find-source (match-string 2 gud-marker-acc)))
2237 (setq gud-last-frame
2241 ((numstr (match-string 4 gud-marker-acc)))
2248 (setq gud-marker-acc (substring gud-marker-acc (match-end 0))))
2250 (if (string-match comint-prompt-regexp gud-marker-acc)
2251 (setq gud-jdb-lowest-stack-level 999)))
2253 ;; Do not allow gud-marker-acc to grow without bound. If the source
2255 ;; gud-marker-acc-max-length characters, well,...
2256 (if (> (length gud-marker-acc) gud-marker-acc-max-length)
2257 (setq gud-marker-acc
2258 (substring gud-marker-acc
2259 (- (/ (* gud-marker-acc-max-length 3) 4)))))
2264 (defvar gud-jdb-command-name "jdb" "Command that executes the Java debugger.")
2267 (defun jdb (command-line)
2268 "Run jdb with command line COMMAND-LINE in a buffer.
2269 The buffer is named \"*gud*\" if no initial class is given or
2270 \"*gud-<initial-class-basename>*\" if there is. If the \"-classpath\"
2273 See `gud-jdb-use-classpath' and `gud-jdb-classpath' documentation for
2275 `gud-jdb-use-classpath' is nil), see `gud-jdb-directories' for the
2279 gud, see `gud-mode'."
2281 (list (gud-query-cmdline 'jdb)))
2282 (setq gud-jdb-classpath nil)
2283 (setq gud-jdb-sourcepath nil)
2285 ;; Set gud-jdb-classpath from the CLASSPATH environment variable,
2287 (setq gud-jdb-classpath-string (getenv "CLASSPATH"))
2288 (if gud-jdb-classpath-string
2289 (setq gud-jdb-classpath
2290 (gud-jdb-parse-classpath-string gud-jdb-classpath-string)))
2291 (setq gud-jdb-classpath-string nil) ; prepare for next
2293 (gud-common-init command-line 'gud-jdb-massage-args
2294 'gud-jdb-marker-filter)
2295 (set (make-local-variable 'gud-minor-mode) 'jdb)
2297 ;; If a -classpath option was provided, set gud-jdb-classpath
2298 (if gud-jdb-classpath-string
2299 (setq gud-jdb-classpath
2300 (gud-jdb-parse-classpath-string gud-jdb-classpath-string)))
2301 (setq gud-jdb-classpath-string nil) ; prepare for next
2303 (if gud-jdb-sourcepath
2304 (setq gud-jdb-sourcepath
2305 (gud-jdb-parse-classpath-string gud-jdb-sourcepath)))
2307 (gud-def gud-break "stop at %c:%l" "\C-b" "Set breakpoint at current line.")
2308 (gud-def gud-remove "clear %c:%l" "\C-d" "Remove breakpoint at current line")
2309 (gud-def gud-step "step" "\C-s" "Step one source line with display.")
2310 (gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
2311 (gud-def gud-cont "cont" "\C-r" "Continue with display.")
2312 (gud-def gud-finish "step up" "\C-f" "Continue until current method returns.")
2313 (gud-def gud-up "up\C-Mwhere" "<" "Up one stack frame.")
2314 (gud-def gud-down "down\C-Mwhere" ">" "Up one stack frame.")
2315 (gud-def gud-run "run" nil "Run the program.") ;if VM start using jdb
2316 (gud-def gud-print "print %e" "\C-p" "Evaluate Java expression at point.")
2323 (if gud-jdb-use-classpath
2326 (if (string-match "-attach" command-line)
2327 (gud-call "classpath"))
2328 (fset 'gud-jdb-find-source
2329 'gud-jdb-find-source-using-classpath))
2333 (setq gud-jdb-class-source-alist
2334 (gud-jdb-build-class-source-alist
2335 (setq gud-jdb-source-files
2336 (gud-jdb-build-source-files-list gud-jdb-directories
2338 (fset 'gud-jdb-find-source 'gud-jdb-find-source-file)))
2346 ;; When we send a command to the debugger via gud-call, it's annoying
2347 ;; to see the command and the new prompt inserted into the debugger's
2348 ;; buffer; we have other ways of knowing the command has completed.
2352 ;; (gdb) set args foo bar
2353 ;; (gdb) -!-
2359 ;; (gdb) set args foo bar
2361 ;; (gdb) -!-
2363 ;; Essentially, the old prompt is deleted, and the command's output
2366 ;; Not echoing the command is easy enough; you send it directly using
2369 ;; when you send the command, since that will result in an annoying
2373 ;; from the subprocess before we delete the prompt. If the command
2377 ;; command produces output, the prompt is moving anyway, so the
2381 ;; chunk of debugger output, we position gud-delete-prompt-marker at
2384 ;; gud-delete-prompt-marker points nowhere, we leave the current
2386 (defvar gud-delete-prompt-marker nil)
2390 (put 'gud-mode 'mode-class 'special)
2392 (define-derived-mode gud-mode comint-mode "Debugger"
2395 You start it up with one of the commands M-x gdb, M-x sdb, M-x dbx,
2397 hook; `gdb-mode-hook', `sdb-mode-hook', `dbx-mode-hook',
2404 \\[gud-break] sets a breakpoint at the current file and line. In the
2408 \\[gud-remove] removes breakpoints on the current file and line.
2410 \\[gud-refresh] displays in the source window the last line referred to
2411 in the gud buffer.
2413 \\[gud-step], \\[gud-next], and \\[gud-stepi] do a step-one-line,
2416 \\[gud-cont] continues execution.
2418 \\[gud-print] tries to find the largest C lvalue or function-call expression
2424 Under gdb, sdb and xdb, \\[gud-tbreak] behaves exactly like \\[gud-break],
2428 Under gdb, dbx, and xdb, \\[gud-up] pops up through an enclosing stack
2429 frame. \\[gud-down] drops back down through one.
2431 If you are using gdb or xdb, \\[gud-finish] runs execution to the return from
2441 You may use the `gud-def' macro in the initialization hook to define other
2447 (define-key (current-local-map) "\C-c\C-l" 'gud-refresh)
2448 (set (make-local-variable 'gud-last-frame) nil)
2449 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
2451 ;; Don't put repeated commands in command history many times.
2454 (set (make-local-variable 'gud-delete-prompt-marker) (make-marker))
2455 (add-hook 'kill-buffer-hook 'gud-kill-buffer-hook nil t))
2459 ;;;###autoload (add-hook 'same-window-regexps "\\*gud-.*\\*\\(\\|<[0-9]+>\\)")
2461 (defcustom gud-chdir-before-run t
2463 :group 'gud
2466 (defvar gud-target-name "--unknown--"
2467 "The apparent name of the program being debugged in a gud buffer.")
2470 ;; The first arg is the specified command line,
2474 (defun gud-common-init (command-line massage-args marker-filter
2476 (let* ((words (split-string command-line))
2479 ;; Extract the file name from WORDS
2481 ;; Later on we will put the modified file name arg back there.
2489 (and file-word (substitute-in-file-name file-word)))
2491 ;; If a directory was specified, expand the file name.
2493 ;; A file name without directory is literally valid
2497 (if (file-name-directory file-subst)
2498 (expand-file-name file-subst)
2500 (filepart (and file-word (concat "-" (file-name-nondirectory file))))
2501 (existing-buffer (get-buffer (concat "*gud" filepart "*"))))
2502 (pop-to-buffer (concat "*gud" filepart "*"))
2509 gud-chdir-before-run
2515 (file-name-directory file)
2516 (setq default-directory (file-name-directory file)))
2519 ;; Put the substituted and expanded file name back in its place.
2525 (apply 'make-comint (concat "gud" filepart) program nil
2528 (gud-mode)
2529 (set (make-local-variable 'gud-target-name)
2530 (and file-word (file-name-nondirectory file))))
2531 (set (make-local-variable 'gud-marker-filter) marker-filter)
2532 (if find-file (set (make-local-variable 'gud-find-file) find-file))
2533 (setq gud-running nil)
2534 (setq gud-last-last-frame nil)
2536 (set-process-filter (get-buffer-process (current-buffer)) 'gud-filter)
2537 (set-process-sentinel (get-buffer-process (current-buffer)) 'gud-sentinel)
2538 (gud-set-buffer))
2540 (defun gud-set-buffer ()
2541 (when (eq major-mode 'gud-mode)
2542 (setq gud-comint-buffer (current-buffer))))
2544 (defvar gud-filter-defer-flag nil
2550 ;; the value of gud-marker-filter.
2552 (defun gud-filter (proc string)
2555 (if (buffer-name (process-buffer proc))
2556 (if gud-filter-defer-flag
2559 (setq gud-filter-pending-text
2560 (concat (or gud-filter-pending-text "") string))
2565 (let ((gud-filter-defer-flag t))
2567 (if gud-filter-pending-text
2568 (setq string (concat gud-filter-pending-text string)
2569 gud-filter-pending-text nil))
2575 (if (marker-buffer gud-delete-prompt-marker)
2578 gud-delete-prompt-marker)
2580 (set-marker gud-delete-prompt-marker nil)))
2582 (setq output (gud-marker-filter string))
2588 (and gud-last-frame
2601 (gud-display-frame))
2605 (gud-display-frame))))
2609 (if gud-filter-pending-text
2610 (gud-filter proc ""))))))
2612 (defvar gud-minor-mode-type nil)
2613 (defvar gud-overlay-arrow-position nil)
2614 (add-to-list 'overlay-arrow-variable-list 'gud-overlay-arrow-position)
2616 (defun gud-sentinel (proc msg)
2617 (cond ((null (buffer-name (process-buffer proc)))
2620 (setq gud-overlay-arrow-position nil)
2623 (string-equal speedbar-initial-expansion-list-name "GUD"))
2625 speedbar-previously-used-expansion-list-name))
2626 (if (memq gud-minor-mode-type '(gdbmi gdba))
2627 (gdb-reset)
2628 (gud-reset)))
2631 (setq gud-overlay-arrow-position nil)
2632 (if (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
2634 (gdb-reset)
2635 (gud-reset))
2646 (symbol-name (process-status proc))))
2649 (insert ?\n mode-name " " msg)
2652 (insert ?\n mode-name " " msg)))
2658 ;; if obuf is the gud buffer.
2661 (defun gud-kill-buffer-hook ()
2662 (setq gud-minor-mode-type gud-minor-mode)
2667 (defun gud-reset ()
2669 (unless (eq buffer gud-comint-buffer)
2671 (when gud-minor-mode
2672 (setq gud-minor-mode nil)
2675 (defun gud-display-frame ()
2679 (when gud-last-frame
2680 (gud-set-buffer)
2681 (gud-display-line (car gud-last-frame) (cdr gud-last-frame))
2682 (setq gud-last-last-frame gud-last-frame
2683 gud-last-frame nil)))
2692 (defun gud-display-line (true-file line)
2695 (with-current-buffer gud-comint-buffer
2696 (gud-find-file true-file)))
2698 (if (memq gud-minor-mode '(gdbmi gdba))
2699 (unless (gdb-display-source-buffer buffer)
2700 (gdb-display-buffer buffer nil)))
2706 (unless (or (verify-visited-file-modtime buffer) gud-keep-buffer)
2709 (buffer-name)))
2711 (setq gud-keep-buffer t)))
2716 (or gud-overlay-arrow-position
2717 (setq gud-overlay-arrow-position (make-marker)))
2718 (set-marker gud-overlay-arrow-position (point) (current-buffer))
2731 (set-window-point window gud-overlay-arrow-position)
2732 (if (memq gud-minor-mode '(gdbmi gdba))
2733 (setq gdb-source-window window)))))))
2735 ;; The gud-call function must do the right thing whether its invoking
2738 ;; gud-last-frame. Here's how we do it:
2740 (defun gud-format-command (str arg)
2741 (let ((insource (not (eq (current-buffer) gud-comint-buffer)))
2742 (frame (or gud-last-frame gud-last-last-frame))
2751 (setq subst (file-name-nondirectory (if insource
2752 (buffer-file-name)
2755 (setq subst (file-name-sans-extension
2756 (file-name-nondirectory (if insource
2757 (buffer-file-name)
2760 (setq subst (file-name-directory (if insource
2761 (buffer-file-name)
2772 (setq subst (gud-find-expr)))
2774 (setq subst (gud-read-address)))
2777 (gud-find-class
2779 (buffer-file-name)
2794 (defun gud-read-address ()
2814 (defun gud-call (fmt &optional arg)
2815 (let ((msg (gud-format-command fmt arg)))
2818 (gud-basic-call msg)))
2820 (defun gud-basic-call (command)
2823 (gud-set-buffer)
2824 (let ((proc (get-buffer-process gud-comint-buffer)))
2828 (set-buffer gud-comint-buffer)
2831 (if (marker-position gud-delete-prompt-marker)
2833 (goto-char gud-delete-prompt-marker)
2837 (set-marker gud-delete-prompt-marker (point)))
2838 (if (memq gud-minor-mode '(gdbmi gdba))
2839 (apply comint-input-sender (list proc command))
2840 (process-send-string proc (concat command "\n")))))))
2842 (defun gud-refresh (&optional arg)
2845 (or gud-last-frame (setq gud-last-frame gud-last-last-frame))
2846 (gud-display-frame)
2851 ;; point is gud-find-expr, which tries to return an lvalue expression from
2854 (defvar gud-find-expr-function 'gud-find-c-expr)
2856 (defun gud-find-expr (&rest args)
2859 (apply gud-find-expr-function args))))
2863 (with-current-buffer gud-comint-buffer
2865 (goto-char (process-mark (get-buffer-process gud-comint-buffer)))
2868 (set-marker gud-delete-prompt-marker (point))
2869 (set-marker-insertion-type gud-delete-prompt-marker t))
2870 (unless (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
2879 (defun gud-find-c-expr ()
2884 (expr (gud-innermost-expr))
2885 (test-expr (gud-prev-expr)))
2886 (while (and test-expr (gud-expr-compound test-expr expr))
2890 (setq test-expr (gud-prev-expr))
2898 (setq test-expr (gud-next-expr))
2899 (while (gud-expr-compound expr test-expr)
2901 (setq test-expr (gud-next-expr)))
2904 (defun gud-innermost-expr ()
2910 (gud-backward-sexp)
2912 (gud-forward-sexp)
2918 (gud-forward-sexp)
2924 (defun gud-backward-sexp ()
2930 (defun gud-forward-sexp ()
2936 (defun gud-prev-expr ()
2942 (gud-backward-sexp)
2944 (gud-forward-sexp)
2949 (defun gud-next-expr ()
2955 (gud-forward-sexp)
2956 (gud-forward-sexp)
2958 (gud-backward-sexp)
2962 (defun gud-expr-compound-sep (span-start span-end)
2984 (defun gud-expr-compound (first second)
2999 (setq syntax (gud-expr-compound-sep span-start span-end))
3015 (defun gud-find-class (f line)
3017 This function uses the `gud-jdb-classpath' (and optional
3018 `gud-jdb-sourcepath') list(s) to derive a file
3020 `gud-jdb-classpath' are assumed to have been converted to absolute
3027 (if (and gud-jdb-use-classpath (or gud-jdb-classpath gud-jdb-sourcepath))
3029 (let ((cplist (append gud-jdb-sourcepath gud-jdb-classpath))
3032 (setq f (file-name-sans-extension (file-truename f)))
3072 ;; definition. Find class name
3088 (message "gud-find-class: class for file %s not found!" f))
3091 (let ((class-found (rassoc f gud-jdb-class-source-alist)))
3094 (message "gud-find-class: class for file %s not found in gud-jdb-class-source-alist!" f)
3103 (defvar gdb-script-mode-syntax-table
3110 (defvar gdb-script-font-lock-keywords
3111 '(("^define\\s-+\\(\\(\\w\\|\\s_\\)+\\)" (1 font-lock-function-name-face))
3112 ("\\$\\(\\w+\\)" (1 font-lock-variable-name-face))
3115 (defvar gdb-script-font-lock-syntactic-keywords
3135 (defun gdb-script-font-lock-syntactic-face (state)
3141 (defvar gdb-script-basic-indent 2)
3143 (defun gdb-script-skip-to-head ()
3147 (gdb-script-skip-to-head)))
3149 (defun gdb-script-calculate-indentation ()
3152 (gdb-script-skip-to-head)
3157 (gdb-script-skip-to-head))
3165 gdb-script-basic-indent 0)))))
3167 (defun gdb-script-indent-line ()
3182 (max (gdb-script-calculate-indentation) 0))
3189 (defun gdb-script-beginning-of-defun ()
3200 (defun gdb-script-end-of-defun ()
3210 (add-to-list 'auto-mode-alist '("/\\.gdbinit" . gdb-script-mode))
3213 (define-derived-mode gdb-script-mode nil "GDB-Script"
3220 (set (make-local-variable 'indent-line-function) 'gdb-script-indent-line)
3222 #'gdb-script-beginning-of-defun)
3224 #'gdb-script-end-of-defun)
3226 '(gdb-script-font-lock-keywords nil nil ((?_ . "w")) nil
3228 . gdb-script-font-lock-syntactic-keywords)
3230 . gdb-script-font-lock-syntactic-face))))
3238 (define-minor-mode gud-tooltip-mode
3241 :group 'gud
3244 (if gud-tooltip-mode
3246 (add-hook 'change-major-mode-hook 'gud-tooltip-change-major-mode)
3247 (add-hook 'pre-command-hook 'tooltip-hide)
3248 (add-hook 'tooltip-hook 'gud-tooltip-tips)
3249 (define-key global-map [mouse-movement] 'gud-tooltip-mouse-motion))
3250 (unless tooltip-mode (remove-hook 'pre-command-hook 'tooltip-hide)
3251 (remove-hook 'change-major-mode-hook 'gud-tooltip-change-major-mode)
3252 (remove-hook 'tooltip-hook 'gud-tooltip-tips)
3254 (gud-tooltip-activate-mouse-motions-if-enabled)
3255 (if (and gud-comint-buffer
3256 (buffer-name gud-comint-buffer); gud-comint-buffer might be killed
3257 (memq (buffer-local-value 'gud-minor-mode gud-comint-buffer)
3259 (if gud-tooltip-mode
3262 (unless (eq buffer gud-comint-buffer)
3264 (when (and (memq gud-minor-mode '(gdbmi gdba))
3266 (buffer-name))))
3267 (make-local-variable 'gdb-define-alist)
3268 (gdb-create-define-alist)
3270 'gdb-create-define-alist nil t))))))
3271 (kill-local-variable 'gdb-define-alist)
3272 (remove-hook 'after-save-hook 'gdb-create-define-alist t))))
3274 (defcustom gud-tooltip-modes '(gud-mode c-mode c++-mode fortran-mode
3278 :group 'gud
3281 (defcustom gud-tooltip-display
3282 '((eq (tooltip-event-buffer gud-tooltip-event)
3283 (marker-buffer gud-overlay-arrow-position)))
3289 :group 'gud
3292 (defcustom gud-tooltip-echo-area nil
3295 :group 'gud
3298 (define-obsolete-variable-alias 'tooltip-gud-modes
3299 'gud-tooltip-modes "22.1")
3300 (define-obsolete-variable-alias 'tooltip-gud-display
3301 'gud-tooltip-display "22.1")
3305 (defun gud-tooltip-change-major-mode ()
3307 (add-hook 'post-command-hook 'gud-tooltip-activate-mouse-motions-if-enabled))
3309 (defun gud-tooltip-activate-mouse-motions-if-enabled ()
3311 (remove-hook 'post-command-hook
3312 'gud-tooltip-activate-mouse-motions-if-enabled)
3316 (if (and gud-tooltip-mode
3317 (memq major-mode gud-tooltip-modes))
3318 (gud-tooltip-activate-mouse-motions t)
3319 (gud-tooltip-activate-mouse-motions nil)))))
3321 (defvar gud-tooltip-mouse-motions-active nil
3325 ;; problem in buffers having a pre-command-hook or such installed,
3330 (defun gud-tooltip-activate-mouse-motions (activatep)
3335 (make-local-variable 'gud-tooltip-mouse-motions-active)
3336 (setq gud-tooltip-mouse-motions-active t)
3339 (when gud-tooltip-mouse-motions-active
3340 (kill-local-variable 'gud-tooltip-mouse-motions-active)
3343 (defun gud-tooltip-mouse-motion (event)
3351 ;;; Tips for `gud'
3353 (defvar gud-tooltip-original-filter nil
3356 (defvar gud-tooltip-dereference nil
3360 (defvar gud-tooltip-event nil
3364 (defun gud-tooltip-dereference (&optional arg)
3368 (setq gud-tooltip-dereference
3370 (not gud-tooltip-dereference)
3373 (if gud-tooltip-dereference "on" "off")))
3375 (define-obsolete-function-alias 'tooltip-gud-toggle-dereference
3376 'gud-tooltip-dereference "22.1")
3380 ; the tooltip incompletely and spill over into the gud buffer.
3383 ; gdb-ui.el gets round this problem.
3384 (defun gud-tooltip-process-output (process output)
3386 (set-process-filter process gud-tooltip-original-filter)
3388 (or gud-tooltip-echo-area tooltip-use-echo-area)))
3390 (defun gud-tooltip-print-command (expr)
3391 "Return a suitable command to print the expression EXPR."
3392 (case gud-minor-mode
3398 (defun gud-tooltip-tips (event)
3401 region for the tip window to be shown. If gud-tooltip-dereference is t,
3409 gud-tooltip-mode
3410 gud-comint-buffer
3411 (buffer-name gud-comint-buffer); might be killed
3412 (setq process (get-buffer-process gud-comint-buffer))
3414 (or (and (eq gud-minor-mode 'gdba) (not gdb-active-process))
3415 (progn (setq gud-tooltip-event event)
3416 (eval (cons 'and gud-tooltip-display)))))
3419 (if (and (eq gud-minor-mode 'gdba)
3420 (not gdb-active-process))
3426 (let ((define-elt (assoc expr gdb-define-alist)))
3430 (or gud-tooltip-echo-area tooltip-use-echo-area))
3432 (when gud-tooltip-dereference
3434 (let ((cmd (gud-tooltip-print-command expr)))
3435 (when (and gud-tooltip-mode (eq gud-minor-mode 'gdb))
3436 (gud-tooltip-mode -1)
3440 (if (memq gud-minor-mode '(gdba gdbmi))
3441 (if gdb-macro-info
3442 (gdb-enqueue-input
3444 gdb-server-prefix "macro expand " expr "\n")
3445 `(lambda () (gdb-tooltip-print-1 ,expr))))
3446 (gdb-enqueue-input
3448 `(lambda () (gdb-tooltip-print ,expr)))))
3449 (setq gud-tooltip-original-filter (process-filter process))
3450 (set-process-filter process 'gud-tooltip-process-output)
3451 (gud-basic-call cmd))
3454 (provide 'gud)
3457 ;;; gud.el ends here