annotate lisp/comint/dbx.el @ 70:131b0175ea99 r20-0b30

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