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