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