]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/debug.el
Emulate POSIX_SIGNALS on MS-Windows.
[gnu-emacs] / lisp / emacs-lisp / debug.el
index 11909cf44c0f330bbc9db6d7a6ab060c6de67d8c..b8ff3c03ee9e9e9dd7b362eba37075e63236ac2e 100644 (file)
@@ -1,17 +1,17 @@
 ;;; debug.el --- debuggers and related commands for Emacs
 
-;; Copyright (C) 1985, 1986, 1994, 2001, 2003, 2005
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1986, 1994, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: lisp, tools, maint
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,9 +19,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
   :group 'debug)
 
 (defcustom debugger-mode-hook nil
-  "*Hooks run when `debugger-mode' is turned on."
+  "Hooks run when `debugger-mode' is turned on."
   :type 'hook
   :group 'debugger
   :version "20.3")
 
 (defcustom debugger-batch-max-lines 40
-  "*Maximum lines to show in debugger buffer in a noninteractive Emacs.
+  "Maximum lines to show in debugger buffer in a noninteractive Emacs.
 When the debugger is entered and Emacs is running in batch mode,
 if the backtrace text has more than this many lines,
 the middle is discarded, and just the beginning and end are displayed."
@@ -121,8 +119,7 @@ first will be printed into the backtrace buffer."
     (let (debugger-value
          (debug-on-error nil)
          (debug-on-quit nil)
-         (debugger-buffer (let ((default-major-mode 'fundamental-mode))
-                            (get-buffer-create "*Backtrace*")))
+         (debugger-buffer (get-buffer-create "*Backtrace*"))
          (debugger-old-buffer (current-buffer))
          (debugger-step-after-exit nil)
           (debugger-will-be-back nil)
@@ -150,7 +147,8 @@ first will be printed into the backtrace buffer."
          (debugger-outer-standard-input standard-input)
          (debugger-outer-standard-output standard-output)
          (debugger-outer-inhibit-redisplay inhibit-redisplay)
-         (debugger-outer-cursor-in-echo-area cursor-in-echo-area))
+         (debugger-outer-cursor-in-echo-area cursor-in-echo-area)
+         (debugger-with-timeout-suspend (with-timeout-suspend)))
       ;; Set this instead of binding it, so that `q'
       ;; will not restore it.
       (setq overriding-terminal-local-map nil)
@@ -201,7 +199,7 @@ first will be printed into the backtrace buffer."
                    (insert "...\n"))
                  (goto-char (point-min))
                  (message "%s" (buffer-string))
-                 (kill-emacs))
+                 (kill-emacs -1))
                (message "")
                (let ((standard-output nil)
                      (buffer-read-only t))
@@ -231,10 +229,12 @@ first will be printed into the backtrace buffer."
                     ;; would need to be de-iconified anyway immediately
                     ;; after when we re-enter the debugger, so iconifying it
                     ;; here would cause flashing.
-                    ;; Use quit-window rather than bury-buffer to quieten
-                    ;; Drew Adams.  --Stef
-                    (quit-window))))
+                    ;; Drew Adams is not happy with this: he wants to frame
+                    ;; to be left at the top-level, still working on how
+                    ;; best to do that.
+                    (bury-buffer))))
            (kill-buffer debugger-buffer))
+         (with-timeout-unsuspend debugger-with-timeout-suspend)
          (set-match-data debugger-outer-match-data)))
       ;; Put into effect the modified values of these variables
       ;; in case the user set them with the `e' command.
@@ -266,7 +266,8 @@ first will be printed into the backtrace buffer."
 That buffer should be current already."
   (setq buffer-read-only nil)
   (erase-buffer)
-  (set-buffer-multibyte nil)
+  (set-buffer-multibyte t)             ;Why was it nil ?  -stef
+  (setq buffer-undo-list t)
   (let ((standard-output (current-buffer))
        (print-escape-newlines t)
        (print-level 8)
@@ -328,8 +329,7 @@ That buffer should be current already."
 (defun debugger-make-xrefs (&optional buffer)
   "Attach cross-references to function names in the `*Backtrace*' buffer."
   (interactive "b")
-  (save-excursion
-    (set-buffer (or buffer (current-buffer)))
+  (with-current-buffer (or buffer (current-buffer))
     (setq buffer (current-buffer))
     (let ((inhibit-read-only t)
          (old-end (point-min)) (new-end (point-min)))
@@ -351,9 +351,10 @@ That buffer should be current already."
                  (forward-line -1)
                  (setq new-start (point)))
                (if (not (zerop
-                         (compare-buffer-substrings
-                          (current-buffer) old-start old-end
-                          buffer new-start new-end)))
+                          (let ((case-fold-search nil))
+                            (compare-buffer-substrings
+                             (current-buffer) old-start old-end
+                             buffer new-start new-end))))
                    (setq all-match nil))))
            ;; Now new-end is the position of the start of the
            ;; unchanged part in the current buffer, and old-end is
@@ -581,7 +582,8 @@ Applies to the frame whose line point is on in the backtrace."
   (debugger-env-macro (eval-expression exp)))
 \f
 (defvar debugger-mode-map
-  (let ((map (make-keymap)))
+  (let ((map (make-keymap))
+       (menu-map (make-sparse-keymap)))
     (set-keymap-parent map button-buffer-map)
     (suppress-keymap map)
     (define-key map "-" 'negative-argument)
@@ -599,10 +601,78 @@ Applies to the frame whose line point is on in the backtrace."
     (define-key map "R" 'debugger-record-expression)
     (define-key map "\C-m" 'debug-help-follow)
     (define-key map [mouse-2] 'push-button)
+    (define-key map [menu-bar debugger] (cons "Debugger" menu-map))
+    (define-key menu-map [deb-top]
+      '(menu-item "Quit" top-level
+                 :help "Quit debugging and return to top level"))
+    (define-key menu-map [deb-s0] '("--"))
+    (define-key menu-map [deb-descr]
+      '(menu-item "Describe Debugger Mode" describe-mode
+                 :help "Display documentation for debugger-mode"))
+    (define-key menu-map [deb-hfol]
+      '(menu-item "Help Follow" debug-help-follow
+                 :help "Follow cross-reference"))
+    (define-key menu-map [deb-nxt]
+      '(menu-item "Next Line" next-line
+                 :help "Move cursor down"))
+    (define-key menu-map [deb-s1] '("--"))
+    (define-key menu-map [deb-lfunc]
+      '(menu-item "List debug on entry functions" debugger-list-functions
+                 :help "Display a list of all the functions now set to debug on entry"))
+    (define-key menu-map [deb-fclear]
+      '(menu-item "Cancel debug frame" debugger-frame-clear
+                 :help "Do not enter debugger when this frame exits"))
+    (define-key menu-map [deb-frame]
+      '(menu-item "Debug frame" debugger-frame
+                 :help "Request entry to debugger when this frame exits"))
+    (define-key menu-map [deb-s2] '("--"))
+    (define-key menu-map [deb-ret]
+      '(menu-item "Return value..." debugger-return-value
+                 :help "Continue, specifying value to return."))
+    (define-key menu-map [deb-rec]
+      '(menu-item "Display and Record Expression" debugger-record-expression
+                 :help "Display a variable's value and record it in `*Backtrace-record*' buffer"))
+    (define-key menu-map [deb-eval]
+      '(menu-item "Eval Expression..." debugger-eval-expression
+                 :help "Eval an expression, in an environment like that outside the debugger"))
+    (define-key menu-map [deb-jump]
+      '(menu-item "Jump" debugger-jump
+                 :help "Continue to exit from this frame, with all debug-on-entry suspended"))
+    (define-key menu-map [deb-cont]
+      '(menu-item "Continue" debugger-continue
+                 :help "Continue, evaluating this expression without stopping"))
+    (define-key menu-map [deb-step]
+      '(menu-item "Step through" debugger-step-through
+                 :help "Proceed, stepping through subexpressions of this expression"))
     map))
+
+(put 'debugger-mode 'mode-class 'special)
+
+(defun debugger-mode ()
+  "Mode for backtrace buffers, selected in debugger.
+\\<debugger-mode-map>
+A line starts with `*' if exiting that frame will call the debugger.
+Type \\[debugger-frame] or \\[debugger-frame-clear] to set or remove the `*'.
+
+When in debugger due to frame being exited,
+use the \\[debugger-return-value] command to override the value
+being returned from that frame.
+
+Use \\[debug-on-entry] and \\[cancel-debug-on-entry] to control
+which functions will enter the debugger when called.
+
+Complete list of commands:
+\\{debugger-mode-map}"
+  (kill-all-local-variables)
+  (setq major-mode 'debugger-mode)
+  (setq mode-name "Debugger")
+  (setq truncate-lines t)
+  (set-syntax-table emacs-lisp-mode-syntax-table)
+  (use-local-map debugger-mode-map)
+  (run-mode-hooks 'debugger-mode-hook))
 \f
 (defcustom debugger-record-buffer "*Debugger-record*"
-  "*Buffer name for expression values, for \\[debugger-record-expression]."
+  "Buffer name for expression values, for \\[debugger-record-expression]."
   :type 'string
   :group 'debugger
   :version "20.3")
@@ -626,12 +696,17 @@ Applies to the frame whose line point is on in the backtrace."
             (buffer-substring (line-beginning-position 0)
                               (line-end-position 0)))))
 
+(declare-function help-xref-interned "help-mode" (symbol))
+
 (defun debug-help-follow (&optional pos)
   "Follow cross-reference at POS, defaulting to point.
 
 For the cross-reference format, see `help-make-xrefs'."
   (interactive "d")
   (require 'help-mode)
+  ;; Ideally we'd just do (call-interactively 'help-follow) except that this
+  ;; assumes we're already in a *Help* buffer and reuses it, so it ends up
+  ;; incorrectly "reusing" the *Backtrace* buffer to show the help info.
   (unless pos
     (setq pos (point)))
   (unless (push-button pos)
@@ -644,33 +719,7 @@ For the cross-reference format, see `help-make-xrefs'."
                                (progn (skip-syntax-forward "w_")
                                       (point)))))))
       (when (or (boundp sym) (fboundp sym) (facep sym))
-       (switch-to-buffer-other-window (generate-new-buffer "*Help*"))
-       (help-do-xref pos #'help-xref-interned (list sym))))))
-
-(put 'debugger-mode 'mode-class 'special)
-
-(defun debugger-mode ()
-  "Mode for backtrace buffers, selected in debugger.
-\\<debugger-mode-map>
-A line starts with `*' if exiting that frame will call the debugger.
-Type \\[debugger-frame] or \\[debugger-frame-clear] to set or remove the `*'.
-
-When in debugger due to frame being exited,
-use the \\[debugger-return-value] command to override the value
-being returned from that frame.
-
-Use \\[debug-on-entry] and \\[cancel-debug-on-entry] to control
-which functions will enter the debugger when called.
-
-Complete list of commands:
-\\{debugger-mode-map}"
-  (kill-all-local-variables)
-  (setq major-mode 'debugger-mode)
-  (setq mode-name "Debugger")
-  (setq truncate-lines t)
-  (set-syntax-table emacs-lisp-mode-syntax-table)
-  (use-local-map debugger-mode-map)
-  (run-mode-hooks 'debugger-mode-hook))
+        (help-xref-interned sym)))))
 \f
 ;; When you change this, you may also need to change the number of
 ;; frames that the debugger skips.
@@ -707,7 +756,7 @@ Redefining FUNCTION also cancels it."
    (let ((fn (function-called-at-point)) val)
      (when (debugger-special-form-p fn)
        (setq fn nil))
-     (setq val (completing-read 
+     (setq val (completing-read
                (if fn
                    (format "Debug on entry to function (default %s): " fn)
                  "Debug on entry to function: ")
@@ -752,7 +801,7 @@ To specify a nil argument interactively, exit with an empty minibuffer."
   (interactive
    (list (let ((name
                (completing-read
-                "Cancel debug on entry to function (default: all functions): "
+                "Cancel debug on entry to function (default all functions): "
                 (mapcar 'symbol-name debug-function-list) nil t)))
           (when name
             (unless (string= name "")
@@ -823,7 +872,8 @@ To specify a nil argument interactively, exit with an empty minibuffer."
   "Display a list of all the functions now set to debug on entry."
   (interactive)
   (require 'help-mode)
-  (help-setup-xref '(debugger-list-functions) (interactive-p))
+  (help-setup-xref '(debugger-list-functions)
+                  (called-interactively-p 'interactive))
   (with-output-to-temp-buffer (help-buffer)
     (with-current-buffer standard-output
       (if (null debug-function-list)