annotate lisp/comint/dbx.el @ 58:8b0bdfdf0cf0 r19-16-pre4

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