Annotation of 43BSDReno/contrib/emacs-18.55/lisp/dbx.el, revision 1.1.1.1

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 distributed in the hope that it will be useful,
                      8: ;; but WITHOUT ANY WARRANTY.  No author or distributor
                      9: ;; accepts responsibility to anyone for the consequences of using it
                     10: ;; or for whether it serves any particular purpose or works at all,
                     11: ;; unless he says so in writing.  Refer to the GNU Emacs General Public
                     12: ;; License for full details.
                     13: 
                     14: ;; Everyone is granted permission to copy, modify and redistribute
                     15: ;; GNU Emacs, but only under the conditions described in the
                     16: ;; GNU Emacs General Public License.   A copy of this license is
                     17: ;; supposed to have been given to you along with GNU Emacs so you
                     18: ;; can know your rights and responsibilities.  It should be in a
                     19: ;; file named COPYING.  Among other things, the copyright notice
                     20: ;; and this notice must be preserved on all copies.
                     21: 
                     22: (require 'shell)
                     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 (copy-keymap shell-mode-map))
                     38:   (define-key inferior-dbx-mode-map "\C-cw" 'dbx-where)
                     39:   (define-key inferior-dbx-mode-map "\C-c\C-t" 'dbx-trace-mode)
                     40:   (define-key ctl-x-map "\C-@" 'dbx-stop-at))
                     41: 
                     42: (defun inferior-dbx-mode ()
                     43:   "Major mode for interacting with an inferior Dbx process.
                     44: 
                     45: The following commands are available:
                     46: \\{inferior-dbx-mode-map}
                     47: 
                     48: Entry to this mode calls the value of dbx-mode-hook with no arguments,
                     49: if that value is non-nil.  Likewise with the value of shell-mode-hook.
                     50: dbx-mode-hook is called after shell-mode-hook.
                     51: 
                     52: You can display the debugging program in other window and point out
                     53: where you are looking at using the command \\[dbx-where].
                     54: 
                     55: \\[dbx-trace-mode] toggles dbx-trace mode. In dbx-trace mode,
                     56: debugging program is automatically traced using output from dbx.
                     57: 
                     58: The command \\[dbx-stop-at] sets break point at current line of the
                     59: program in the buffer. Major mode name of the buffer must be in
                     60: dbx-language-mode-list.
                     61: 
                     62: Commands:
                     63: 
                     64: Return at end of buffer sends line as input.
                     65: Return not at end copies rest of line to end and sends it.
                     66: \\[shell-send-eof] sends end-of-file as input.
                     67: \\[kill-shell-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing.
                     68: \\[interrupt-shell-subjob] interrupts the shell or its current subjob if any.
                     69: \\[stop-shell-subjob] stops, likewise. \\[quit-shell-subjob] sends quit signal, likewise.
                     70: \\[dbx-where] displays debugging program in other window and
                     71:  points out where you are looking at.
                     72: \\[dbx-trace-mode] toggles dbx-trace mode.
                     73: \\[dbx-stop-at] sets break point at current line."
                     74:   (interactive)
                     75:   (kill-all-local-variables)
                     76:   (setq major-mode 'inferior-dbx-mode)
                     77:   (setq mode-name "Inferior Dbx")
                     78:   (setq mode-line-process '(": %s"))
                     79:   (use-local-map inferior-dbx-mode-map)
                     80:   (make-local-variable 'last-input-start)
                     81:   (setq last-input-start (make-marker))
                     82:   (make-local-variable 'last-input-end)
                     83:   (setq last-input-end (make-marker))
                     84:   (make-local-variable 'dbx-trace-flag)
                     85:   (setq dbx-trace-flag nil)
                     86:   (make-variable-buffer-local 'shell-prompt-pattern)
                     87:   (setq shell-prompt-pattern "^[^)]*dbx) *") ;Set dbx prompt pattern
                     88:   (or (assq 'dbx-trace-flag minor-mode-alist)
                     89:       (setq minor-mode-alist
                     90:            (cons '(dbx-trace-flag " Trace") minor-mode-alist)))
                     91:   (run-hooks 'shell-mode-hook 'dbx-mode-hook))
                     92: 
                     93: (defun run-dbx (path)
                     94:   "Run an inferior Dbx process, input and output via buffer *dbx*."
                     95:   (interactive "fProgram to debug: ")
                     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"))))

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.