home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / modes / dbx-fixed.el < prev    next >
Encoding:
Text File  |  1989-06-18  |  8.6 KB  |  235 lines

  1. ;To: unix-emacs@bbn.com
  2. ;Date: 5 Mar 89 02:00:06 GMT
  3. ;From: Robert Lupton <ucsd!nosc!humu!uhccux!lupton@ames.ARPA>
  4. ;Subject: Dbx mode
  5. ;
  6. ;Dbx.el in 18.52 doesn't understand the use command, so if your source
  7. ;is spread over several directories the trace feature doesn't work. Here
  8. ;is a function dbx-use that can either be called instead of using `use',
  9. ;or can be called to tell dbx-mode about a use command (e.g. if you have
  10. ;an alias to do the work).
  11. ;
  12. ;The diffs were longer than the file, so here it all is. It includes
  13. ;a version of the simple fix to do with process names that I posted a few
  14. ;weeks ago, and superseded it.
  15. ;
  16. ;            Robert Lupton
  17. ;
  18. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  19. ;; Run dbx under Emacs
  20. ;; Copyright (C) 1988 Free Software Foundation, Inc.
  21. ;; Main author Masanobu UMEDA (umerin@flab.fujitsu.junet)
  22.  
  23. ;; This file is part of GNU Emacs.
  24.  
  25. ;; GNU Emacs is distributed in the hope that it will be useful,
  26. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  27. ;; accepts responsibility to anyone for the consequences of using it
  28. ;; or for whether it serves any particular purpose or works at all,
  29. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  30. ;; License for full details.
  31.  
  32. ;; Everyone is granted permission to copy, modify and redistribute
  33. ;; GNU Emacs, but only under the conditions described in the
  34. ;; GNU Emacs General Public License.   A copy of this license is
  35. ;; supposed to have been given to you along with GNU Emacs so you
  36. ;; can know your rights and responsibilities.  It should be in a
  37. ;; file named COPYING.  Among other things, the copyright notice
  38. ;; and this notice must be preserved on all copies.
  39. ;
  40. ; Added dbx-use to follow `use' commands. RHL March 1989
  41.  
  42. (require 'shell)
  43.  
  44. (defvar dbx-trace-flag nil
  45.   "Dbx trace switch.")
  46.  
  47. (defvar dbx-process nil
  48.   "Dbx process name.")
  49.  
  50. (defvar dbx-dir-list nil
  51.   "List of directories searched by dbx-where, set by dbx-use")
  52.  
  53. (defvar dbx-break-point
  54.   "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\""
  55.   "Regexp of pattern that dbx writes at break point.")
  56.  
  57. (defvar inferior-dbx-mode-map nil)
  58. (if inferior-dbx-mode-map
  59.     nil
  60.   (setq inferior-dbx-mode-map (copy-keymap shell-mode-map))
  61.   (define-key inferior-dbx-mode-map "\C-cu" 'dbx-use)
  62.   (define-key inferior-dbx-mode-map "\C-cw" 'dbx-where)
  63.   (define-key inferior-dbx-mode-map "\C-c\C-t" 'dbx-trace-mode)
  64.   (define-key ctl-x-map "\C-@" 'dbx-stop-at))
  65.  
  66. (defun inferior-dbx-mode ()
  67.   "Major mode for interacting with an inferior Dbx process.
  68.  
  69. The following commands are available:
  70. \\{inferior-dbx-mode-map}
  71.  
  72. Entry to this mode calls the value of dbx-mode-hook with no arguments,
  73. if that value is non-nil.  Likewise with the value of shell-mode-hook.
  74. dbx-mode-hook is called after shell-mode-hook.
  75.  
  76. You can display the debugging program in other window and point out
  77. where you are looking at using the command \\[dbx-where].
  78.  
  79. \\[dbx-trace-mode] toggles dbx-trace mode. In dbx-trace mode,
  80. debugging program is automatically traced using output from dbx.
  81.  
  82. The command \\[dbx-stop-at] sets break point at current line of the
  83. program in the buffer. Major mode name of the buffer must be in
  84. dbx-language-mode-list.
  85.  
  86. You should use the command `dbx-use' (in the mini-buffer, or \\[dbx-use])
  87. rather than `use' so dbx-mode can find your source directories. (Using
  88. use, then dbx-use with no directories specified also works).
  89.  
  90. Commands:
  91.  
  92. Return at end of buffer sends line as input.
  93. Return not at end copies rest of line to end and sends it.
  94. \\[shell-send-eof] sends end-of-file as input.
  95. \\[kill-shell-input] and \\[backward-kill-word] are kill commands, imitating normal Unix input editing.
  96. \\[interrupt-shell-subjob] interrupts the shell or its current subjob if any.
  97. \\[stop-shell-subjob] stops, likewise. \\[quit-shell-subjob] sends quit signal, likewise.
  98. \\[dbx-use] tells dbx mode about any use commands you have issued
  99. \\[dbx-where] displays debugging program in other window and
  100.  points out where you are looking at.
  101. \\[dbx-trace-mode] toggles dbx-trace mode.
  102. \\[dbx-stop-at] sets break point at current line."
  103.   (interactive)
  104.   (kill-all-local-variables)
  105.   (setq major-mode 'inferior-dbx-mode)
  106.   (setq mode-name "Inferior Dbx")
  107.   (setq mode-line-process '(": %s"))
  108.   (use-local-map inferior-dbx-mode-map)
  109.   (make-local-variable 'last-input-start)
  110.   (setq last-input-start (make-marker))
  111.   (make-local-variable 'last-input-end)
  112.   (setq last-input-end (make-marker))
  113.   (make-local-variable 'dbx-trace-flag)
  114.   (setq dbx-trace-flag nil)
  115.   (make-variable-buffer-local 'shell-prompt-pattern)
  116.   (setq shell-prompt-pattern "^[^)]*dbx) *") ;Set dbx prompt pattern
  117.   (or (assq 'dbx-trace-flag minor-mode-alist)
  118.       (setq minor-mode-alist
  119.         (cons '(dbx-trace-flag " Trace") minor-mode-alist)))
  120.   (run-hooks 'shell-mode-hook 'dbx-mode-hook))
  121.  
  122. (defun run-dbx (path)
  123.   "Run inferior Dbx process on PROGRAM, with I/O via buffer *dbx-PROGRAM*."
  124.   (interactive "fProgram to debug: ")
  125.   (setq path (expand-file-name path))
  126.   (let ((file (file-name-nondirectory path)))
  127.     (switch-to-buffer (concat "*dbx-" file "*"))
  128.     (setq default-directory (file-name-directory path))
  129.     (switch-to-buffer (make-shell (concat "dbx-" file) "dbx" nil file)))
  130.   (setq dbx-process (get-buffer-process (current-buffer)))
  131.   (setq dbx-dir-list (list "."))
  132.   (set-process-filter dbx-process 'dbx-filter)
  133.   (inferior-dbx-mode))
  134.  
  135. (defun dbx-trace-mode (arg)
  136.   "Toggle dbx-trace mode.
  137. With arg, turn dbx-trace mode on iff arg is positive.
  138. In dbx-trace mode, user program is automatically traced."
  139.   (interactive "P")
  140.   (if (not (eql major-mode 'inferior-dbx-mode))
  141.       (error "Dbx-trace mode is effective in inferior-dbx mode only."))
  142.   (setq dbx-trace-flag
  143.     (if (null arg)
  144.         (not dbx-trace-flag)
  145.       (> (prefix-numeric-value arg) 0)))
  146.   ;; Force mode line redisplay
  147.   (set-buffer-modified-p (buffer-modified-p)))
  148.  
  149. (defun dbx-filter (process string)
  150.   "Trace debugging program automatically if dbx-trace-flag is not nil."
  151.   (save-excursion
  152.     (set-buffer (process-buffer process))
  153.     (goto-char (point-max))
  154.     (let ((beg (point)))
  155.       (insert string)
  156.       (if dbx-trace-flag        ;Trace mode is on?
  157.       (dbx-where beg t)))
  158.     (if (process-mark process)
  159.     (set-marker (process-mark process) (point-max))))
  160.   (if (eq (process-buffer process)
  161.       (current-buffer))
  162.       (goto-char (point-max)))
  163.   )
  164.  
  165. (defun dbx-where (&optional begin quiet)
  166.   "Display dbx'ed program in other window and point out where you are looking at.
  167. BEGIN bounds the search. If QUIET, just return nil (no error) if fail."
  168.   (interactive)
  169.   (let (file line)
  170.     (save-excursion
  171.       (if (re-search-backward dbx-break-point begin quiet)
  172.       (progn
  173.         (setq line (buffer-substring (match-beginning 1) (match-end 1)))
  174.         (setq file (buffer-substring (match-beginning 2) (match-end 2)))
  175.         )))
  176.     (if (and file line)            ;Find break point?
  177.     (progn
  178. ; Look for the file in each of the dbx-dir-list directories
  179.       (let ((dir dbx-dir-list))
  180.         (while (and dir (not (file-readable-p
  181.             (expand-file-name (concat (car dir) "/" file) nil))))
  182.           (setq dir (cdr dir))
  183.           )
  184.         (if (not dir)
  185.         (error (format "Can't find file %s" file)))
  186.         (setq file (expand-file-name (concat (car dir) "/" file) nil)))
  187.       (find-file-other-window file)
  188.       (goto-line (string-to-int line)) ;Jump to the line
  189.       (beginning-of-line)
  190.       (setq overlay-arrow-string "=>")
  191.       (or overlay-arrow-position 
  192.           (setq overlay-arrow-position (make-marker)))
  193.       (set-marker overlay-arrow-position (point) (current-buffer))
  194.       (other-window 1))        ;Return to dbx
  195.       )))
  196.  
  197. (defun dbx-stop-at ()
  198.   "Set break point at current line."
  199.   (interactive)
  200.   (let ((file-name (file-name-nondirectory buffer-file-name))
  201.     (line (save-restriction
  202.         (widen)
  203.         (1+ (count-lines 1 (point))))))
  204.     (send-string dbx-process
  205.          (concat "stop at \"" file-name "\":" line "\n"))))
  206.  
  207. (defun dbx-use (dirs)
  208.   "Run dbx's `use' command and parse the output to make a list of
  209. directories for the use of dbx-where. If no directories are specified,
  210. get the current list and parse that"
  211.   (interactive "suse: ")
  212.   (setq dbx-dir-list nil)
  213.   (save-window-excursion
  214.     (if (string-match "[^ \t]" dirs)
  215.     (progn
  216.       (send-string dbx-process (concat "use " dirs "\n"))
  217.       (delete-region (save-excursion (beginning-of-line) (dot)) (dot))))
  218.     (send-string dbx-process "use\n")
  219.     (accept-process-output dbx-process)
  220.     (switch-to-buffer (process-buffer dbx-process))
  221.     (end-of-buffer)
  222.     (previous-line 1)
  223.     (beginning-of-line)
  224.     (if (looking-at shell-prompt-pattern)
  225.     (goto-char (match-end 0)))
  226.     (while (looking-at "[ \t]*[^ \t\n]+")
  227.       (progn 
  228.       (setq dbx-dir-list
  229.         (append dbx-dir-list (list (buffer-substring
  230.                     (match-beginning 0) (match-end 0)))))
  231.       (goto-char (match-end 0))
  232.       (skip-chars-forward " \t"))))
  233.       (end-of-buffer))
  234.  
  235.