aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2011-08-22 17:16:46 -0400
committerStefan Monnier2011-08-22 17:16:46 -0400
commit4eb613489b98093e31f2a81765a4b644fdb90fb2 (patch)
treee40d34f715a95acb70637dc5c55f9771a288dcec
parentdac347dd4a459bbbd7274f106797201e6e420701 (diff)
downloademacs-4eb613489b98093e31f2a81765a4b644fdb90fb2.tar.gz
emacs-4eb613489b98093e31f2a81765a4b644fdb90fb2.zip
* lisp/emacs-lisp/debug.el (debug-arglist): New function.
(debug-convert-byte-code): Use it. Handle lexical byte-codes. (debug-on-entry-1): Handle interpreted closures. Fixes: debbugs:9120
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/emacs-lisp/debug.el34
2 files changed, 27 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 4c7306174d6..4efa1de8e43 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12011-08-22 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * emacs-lisp/debug.el (debug-arglist): New function.
4 (debug-convert-byte-code): Use it. Handle lexical byte-codes.
5 (debug-on-entry-1): Handle interpreted closures (bug#9120).
6
12011-08-22 Juri Linkov <juri@jurta.org> 72011-08-22 Juri Linkov <juri@jurta.org>
2 8
3 * progmodes/compile.el (compilation-mode-font-lock-keywords): 9 * progmodes/compile.el (compilation-mode-font-lock-keywords):
diff --git a/lisp/emacs-lisp/debug.el b/lisp/emacs-lisp/debug.el
index 157749500e7..8276030ccf8 100644
--- a/lisp/emacs-lisp/debug.el
+++ b/lisp/emacs-lisp/debug.el
@@ -778,6 +778,7 @@ Redefining FUNCTION also cancels it."
778 (not (debugger-special-form-p symbol)))) 778 (not (debugger-special-form-p symbol))))
779 t nil nil (symbol-name fn))) 779 t nil nil (symbol-name fn)))
780 (list (if (equal val "") fn (intern val))))) 780 (list (if (equal val "") fn (intern val)))))
781 ;; FIXME: Use advice.el.
781 (when (debugger-special-form-p function) 782 (when (debugger-special-form-p function)
782 (error "Function %s is a special form" function)) 783 (error "Function %s is a special form" function))
783 (if (or (symbolp (symbol-function function)) 784 (if (or (symbolp (symbol-function function))
@@ -835,24 +836,30 @@ To specify a nil argument interactively, exit with an empty minibuffer."
835 (message "Cancelling debug-on-entry for all functions") 836 (message "Cancelling debug-on-entry for all functions")
836 (mapcar 'cancel-debug-on-entry debug-function-list))) 837 (mapcar 'cancel-debug-on-entry debug-function-list)))
837 838
839(defun debug-arglist (definition)
840 ;; FIXME: copied from ad-arglist.
841 "Return the argument list of DEFINITION."
842 (require 'help-fns)
843 (help-function-arglist definition 'preserve-names))
844
838(defun debug-convert-byte-code (function) 845(defun debug-convert-byte-code (function)
839 (let* ((defn (symbol-function function)) 846 (let* ((defn (symbol-function function))
840 (macro (eq (car-safe defn) 'macro))) 847 (macro (eq (car-safe defn) 'macro)))
841 (when macro (setq defn (cdr defn))) 848 (when macro (setq defn (cdr defn)))
842 (unless (consp defn) 849 (when (byte-code-function-p defn)
843 ;; Assume a compiled code object. 850 (let* ((args (debug-arglist defn))
844 (let* ((contents (append defn nil))
845 (body 851 (body
846 (list (list 'byte-code (nth 1 contents) 852 `((,(if (memq '&rest args) #'apply #'funcall)
847 (nth 2 contents) (nth 3 contents))))) 853 ,defn
848 (if (nthcdr 5 contents) 854 ,@(remq '&rest (remq '&optional args))))))
849 (setq body (cons (list 'interactive (nth 5 contents)) body))) 855 (if (> (length defn) 5)
850 (if (nth 4 contents) 856 (push `(interactive ,(aref defn 5)) body))
857 (if (aref defn 4)
851 ;; Use `documentation' here, to get the actual string, 858 ;; Use `documentation' here, to get the actual string,
852 ;; in case the compiled function has a reference 859 ;; in case the compiled function has a reference
853 ;; to the .elc file. 860 ;; to the .elc file.
854 (setq body (cons (documentation function) body))) 861 (setq body (cons (documentation function) body)))
855 (setq defn (cons 'lambda (cons (car contents) body)))) 862 (setq defn `(closure (t) ,args ,@body)))
856 (when macro (setq defn (cons 'macro defn))) 863 (when macro (setq defn (cons 'macro defn)))
857 (fset function defn)))) 864 (fset function defn))))
858 865
@@ -861,11 +868,12 @@ To specify a nil argument interactively, exit with an empty minibuffer."
861 (tail defn)) 868 (tail defn))
862 (when (eq (car-safe tail) 'macro) 869 (when (eq (car-safe tail) 'macro)
863 (setq tail (cdr tail))) 870 (setq tail (cdr tail)))
864 (if (not (eq (car-safe tail) 'lambda)) 871 (if (not (memq (car-safe tail) '(closure lambda)))
865 ;; Only signal an error when we try to set debug-on-entry. 872 ;; Only signal an error when we try to set debug-on-entry.
866 ;; When we try to clear debug-on-entry, we are now done. 873 ;; When we try to clear debug-on-entry, we are now done.
867 (when flag 874 (when flag
868 (error "%s is not a user-defined Lisp function" function)) 875 (error "%s is not a user-defined Lisp function" function))
876 (if (eq (car tail) 'closure) (setq tail (cdr tail)))
869 (setq tail (cdr tail)) 877 (setq tail (cdr tail))
870 ;; Skip the docstring. 878 ;; Skip the docstring.
871 (when (and (stringp (cadr tail)) (cddr tail)) 879 (when (and (stringp (cadr tail)) (cddr tail))
@@ -875,9 +883,9 @@ To specify a nil argument interactively, exit with an empty minibuffer."
875 (setq tail (cdr tail))) 883 (setq tail (cdr tail)))
876 (unless (eq flag (equal (cadr tail) '(implement-debug-on-entry))) 884 (unless (eq flag (equal (cadr tail) '(implement-debug-on-entry)))
877 ;; Add/remove debug statement as needed. 885 ;; Add/remove debug statement as needed.
878 (if flag 886 (setcdr tail (if flag
879 (setcdr tail (cons '(implement-debug-on-entry) (cdr tail))) 887 (cons '(implement-debug-on-entry) (cdr tail))
880 (setcdr tail (cddr tail))))) 888 (cddr tail)))))
881 defn)) 889 defn))
882 890
883(defun debugger-list-functions () 891(defun debugger-list-functions ()