annotate lisp/comint/dbx.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children b82b59fe008d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; dbx.el --- run dbx under Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1988 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Main author Masanobu UMEDA (umerin@flab.fujitsu.junet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Keywords: c, unix, tools, debugging
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 (require 'comint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 (defvar dbx-trace-flag nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 "Dbx trace switch.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (defvar dbx-process nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 "The process in which dbx is running.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (defvar dbx-break-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 "Regexp of pattern that dbx writes at break point.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defvar inferior-dbx-mode-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (if inferior-dbx-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (setq inferior-dbx-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (set-keymap-name inferior-dbx-mode-map 'inferior-dbx-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (set-keymap-parent inferior-dbx-mode-map comint-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (define-key inferior-dbx-mode-map "\C-c\C-w" 'dbx-where)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (define-key inferior-dbx-mode-map "\C-c\C-t" 'dbx-trace-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (define-key ctl-x-map " " 'dbx-stop-at))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defun inferior-dbx-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 "Major mode for interacting with an inferior dbx process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 The following commands are available:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 \\{inferior-dbx-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 Entry to this mode calls the value of dbx-mode-hook with no arguments,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 if that value is non-nil. Likewise with the value of comint-mode-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 dbx-mode-hook is called after comint-mode-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 You can display the debugging program in other window and point out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 where you are looking at using the command \\[dbx-where].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 \\[dbx-trace-mode] toggles dbx-trace mode. In dbx-trace mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 debugging program is automatically traced using output from dbx.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 The command \\[dbx-stop-at] sets break point at current line of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 program in the buffer. Major mode name of the buffer must be in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 dbx-language-mode-list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 Return at end of buffer sends line as input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 Return not at end copies line, sans any dbx prompt, to end and sends it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 \\[shell-send-eof] sends end-of-file as input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 \\[comint-kill-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 \\[comint-interrupt-subjob] interrupts the shell or its current subjob if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 \\[comint-stop-subjob] stops, likewise. \\[comint-quit-subjob] sends quit signal, likewise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 \\[dbx-where] displays debugging program in other window and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 points out where you are looking at.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 \\[dbx-trace-mode] toggles dbx-trace mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 \\[dbx-stop-at] sets break point at current line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (comint-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (use-local-map inferior-dbx-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (setq major-mode 'inferior-dbx-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 mode-name "Inferior dbx"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 comint-prompt-regexp "^[^)]*dbx) *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (make-local-variable 'dbx-trace-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (or (assq 'dbx-trace-flag minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (cons '(dbx-trace-flag " Trace") minor-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (run-hooks 'dbx-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (defun run-dbx (path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 "Run inferior dbx process on PROGRAM, with I/O via buffer *dbx-PROGRAM*."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (interactive "fProgram to debug: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (setq path (expand-file-name path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (let ((file (file-name-nondirectory path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (switch-to-buffer (concat "*dbx-" file "*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (setq default-directory (file-name-directory path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (switch-to-buffer (make-comint (concat "dbx-" file) "dbx" nil file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (setq dbx-process (get-buffer-process (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (set-process-filter dbx-process 'dbx-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (inferior-dbx-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defun dbx-trace-mode (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "Toggle dbx-trace mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 With arg, turn dbx-trace mode on iff arg is positive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 In dbx-trace mode, user program is automatically traced."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (if (not (eql major-mode 'inferior-dbx-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (error "dbx-trace mode is effective in inferior-dbx mode only."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (setq dbx-trace-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (not dbx-trace-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (> (prefix-numeric-value arg) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; Force mode line redisplay
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (set-buffer-modified-p (buffer-modified-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defun dbx-filter (process string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "Trace debugging program automatically if dbx-trace-flag is not nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (set-buffer (process-buffer process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (let ((beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (insert-before-markers string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (if dbx-trace-flag ;Trace mode is on?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (dbx-where beg t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (if (process-mark process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (set-marker (process-mark process) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (if (eq (process-buffer process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (defun dbx-where (&optional begin quiet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 "Display dbx'ed program in other window and point out where you are looking.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 BEGIN bounds the search. If QUIET, just return nil (no error) if fail."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (let (file line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (if (re-search-backward dbx-break-point begin quiet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (setq line (buffer-substring (match-beginning 1) (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (setq file (buffer-substring (match-beginning 2) (match-end 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (if (and file line) ;Find break point?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (find-file-other-window (expand-file-name file nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (goto-line (string-to-int line)) ;Jump to the line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (setq overlay-arrow-string "=>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (or overlay-arrow-position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (setq overlay-arrow-position (make-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (set-marker overlay-arrow-position (point) (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (other-window 1)) ;Return to dbx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (defun dbx-stop-at ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 "Set break point at current line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (let ((file-name (file-name-nondirectory buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (line (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (1+ (count-lines 1 (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (process-send-string dbx-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (concat "stop at \"" file-name "\":" line "\n"))))