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