diff options
| author | Lute Kamstra | 2005-03-29 13:59:41 +0000 |
|---|---|---|
| committer | Lute Kamstra | 2005-03-29 13:59:41 +0000 |
| commit | d70299080162eab4a35d4048e6df26f23a048683 (patch) | |
| tree | 42ddbf03e4a09ff4ba3b8e46bbba6f66eb29f9c2 | |
| parent | d3cd33652b82b3fc6cbc7dadb51860947f099303 (diff) | |
| download | emacs-d70299080162eab4a35d4048e6df26f23a048683.tar.gz emacs-d70299080162eab4a35d4048e6df26f23a048683.zip | |
(debug-on-entry): Handle autoloaded functions and compiled macros.
(debug-convert-byte-code): Handle macros too.
(debug-on-entry-1): Don't signal an error when trying to clear a
function that is not set to debug on entry.
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/emacs-lisp/debug.el | 100 |
2 files changed, 65 insertions, 43 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f04f93a8b34..54629d63992 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2005-03-29 Lute Kamstra <lute@gnu.org> | ||
| 2 | |||
| 3 | * emacs-lisp/debug.el (debug-on-entry): Handle autoloaded | ||
| 4 | functions and compiled macros. | ||
| 5 | (debug-convert-byte-code): Handle macros too. | ||
| 6 | (debug-on-entry-1): Don't signal an error when trying to clear a | ||
| 7 | function that is not set to debug on entry. | ||
| 8 | |||
| 1 | 2005-03-29 Jay Belanger <belanger@truman.edu> | 9 | 2005-03-29 Jay Belanger <belanger@truman.edu> |
| 2 | 10 | ||
| 3 | * calc/calc-lang.el: Add functions to math-function-table | 11 | * calc/calc-lang.el: Add functions to math-function-table |
diff --git a/lisp/emacs-lisp/debug.el b/lisp/emacs-lisp/debug.el index 1e45439658c..2149cba8720 100644 --- a/lisp/emacs-lisp/debug.el +++ b/lisp/emacs-lisp/debug.el | |||
| @@ -632,24 +632,31 @@ which must be written in Lisp, not predefined. | |||
| 632 | Use \\[cancel-debug-on-entry] to cancel the effect of this command. | 632 | Use \\[cancel-debug-on-entry] to cancel the effect of this command. |
| 633 | Redefining FUNCTION also cancels it." | 633 | Redefining FUNCTION also cancels it." |
| 634 | (interactive "aDebug on entry (to function): ") | 634 | (interactive "aDebug on entry (to function): ") |
| 635 | ;; Handle a function that has been aliased to some other function. | 635 | (when (and (subrp (symbol-function function)) |
| 636 | (if (and (subrp (symbol-function function)) | 636 | (eq (cdr (subr-arity (symbol-function function))) 'unevalled)) |
| 637 | (eq (cdr (subr-arity (symbol-function function))) 'unevalled)) | 637 | (error "Function %s is a special form" function)) |
| 638 | (error "Function %s is a special form" function)) | 638 | (if (or (symbolp (symbol-function function)) |
| 639 | (if (or (symbolp (symbol-function function)) | ||
| 640 | (subrp (symbol-function function))) | 639 | (subrp (symbol-function function))) |
| 641 | ;; Create a wrapper in which we can then add the necessary debug call. | 640 | ;; The function is built-in or aliased to another function. |
| 641 | ;; Create a wrapper in which we can add the debug call. | ||
| 642 | (fset function `(lambda (&rest debug-on-entry-args) | 642 | (fset function `(lambda (&rest debug-on-entry-args) |
| 643 | ,(interactive-form (symbol-function function)) | 643 | ,(interactive-form (symbol-function function)) |
| 644 | (apply ',(symbol-function function) | 644 | (apply ',(symbol-function function) |
| 645 | debug-on-entry-args)))) | 645 | debug-on-entry-args))) |
| 646 | (or (consp (symbol-function function)) | 646 | (when (eq (car-safe (symbol-function function)) 'autoload) |
| 647 | (debug-convert-byte-code function)) | 647 | ;; The function is autoloaded. Load its real definition. |
| 648 | (or (consp (symbol-function function)) | 648 | (load (cadr (symbol-function function)) nil noninteractive nil t)) |
| 649 | (error "Definition of %s is not a list" function)) | 649 | (when (or (not (consp (symbol-function function))) |
| 650 | (and (eq (car (symbol-function function)) 'macro) | ||
| 651 | (not (consp (cdr (symbol-function function)))))) | ||
| 652 | ;; The function is byte-compiled. Create a wrapper in which | ||
| 653 | ;; we can add the debug call. | ||
| 654 | (debug-convert-byte-code function))) | ||
| 655 | (unless (consp (symbol-function function)) | ||
| 656 | (error "Definition of %s is not a list" function)) | ||
| 650 | (fset function (debug-on-entry-1 function t)) | 657 | (fset function (debug-on-entry-1 function t)) |
| 651 | (or (memq function debug-function-list) | 658 | (unless (memq function debug-function-list) |
| 652 | (push function debug-function-list)) | 659 | (push function debug-function-list)) |
| 653 | function) | 660 | function) |
| 654 | 661 | ||
| 655 | ;;;###autoload | 662 | ;;;###autoload |
| @@ -664,45 +671,52 @@ If argument is nil or an empty string, cancel for all functions." | |||
| 664 | (if name (intern name))))) | 671 | (if name (intern name))))) |
| 665 | (if (and function (not (string= function ""))) | 672 | (if (and function (not (string= function ""))) |
| 666 | (progn | 673 | (progn |
| 667 | (let ((f (debug-on-entry-1 function nil))) | 674 | (let ((defn (debug-on-entry-1 function nil))) |
| 668 | (condition-case nil | 675 | (condition-case nil |
| 669 | (if (and (equal (nth 1 f) '(&rest debug-on-entry-args)) | 676 | (when (and (equal (nth 1 defn) '(&rest debug-on-entry-args)) |
| 670 | (eq (car (nth 3 f)) 'apply)) | 677 | (eq (car (nth 3 defn)) 'apply)) |
| 671 | ;; `f' is a wrapper introduced in debug-on-entry. | 678 | ;; `defn' is a wrapper introduced in debug-on-entry. |
| 672 | ;; Get rid of it since we don't need it any more. | 679 | ;; Get rid of it since we don't need it any more. |
| 673 | (setq f (nth 1 (nth 1 (nth 3 f))))) | 680 | (setq defn (nth 1 (nth 1 (nth 3 defn))))) |
| 674 | (error nil)) | 681 | (error nil)) |
| 675 | (fset function f)) | 682 | (fset function defn)) |
| 676 | (setq debug-function-list (delq function debug-function-list)) | 683 | (setq debug-function-list (delq function debug-function-list)) |
| 677 | function) | 684 | function) |
| 678 | (message "Cancelling debug-on-entry for all functions") | 685 | (message "Cancelling debug-on-entry for all functions") |
| 679 | (mapcar 'cancel-debug-on-entry debug-function-list))) | 686 | (mapcar 'cancel-debug-on-entry debug-function-list))) |
| 680 | 687 | ||
| 681 | (defun debug-convert-byte-code (function) | 688 | (defun debug-convert-byte-code (function) |
| 682 | (let ((defn (symbol-function function))) | 689 | (let* ((defn (symbol-function function)) |
| 683 | (if (not (consp defn)) | 690 | (macro (eq (car-safe defn) 'macro))) |
| 684 | ;; Assume a compiled code object. | 691 | (when macro (setq defn (cdr defn))) |
| 685 | (let* ((contents (append defn nil)) | 692 | (unless (consp defn) |
| 686 | (body | 693 | ;; Assume a compiled code object. |
| 687 | (list (list 'byte-code (nth 1 contents) | 694 | (let* ((contents (append defn nil)) |
| 688 | (nth 2 contents) (nth 3 contents))))) | 695 | (body |
| 689 | (if (nthcdr 5 contents) | 696 | (list (list 'byte-code (nth 1 contents) |
| 690 | (setq body (cons (list 'interactive (nth 5 contents)) body))) | 697 | (nth 2 contents) (nth 3 contents))))) |
| 691 | (if (nth 4 contents) | 698 | (if (nthcdr 5 contents) |
| 692 | ;; Use `documentation' here, to get the actual string, | 699 | (setq body (cons (list 'interactive (nth 5 contents)) body))) |
| 693 | ;; in case the compiled function has a reference | 700 | (if (nth 4 contents) |
| 694 | ;; to the .elc file. | 701 | ;; Use `documentation' here, to get the actual string, |
| 695 | (setq body (cons (documentation function) body))) | 702 | ;; in case the compiled function has a reference |
| 696 | (fset function (cons 'lambda (cons (car contents) body))))))) | 703 | ;; to the .elc file. |
| 704 | (setq body (cons (documentation function) body))) | ||
| 705 | (setq defn (cons 'lambda (cons (car contents) body)))) | ||
| 706 | (when macro (setq defn (cons 'macro defn))) | ||
| 707 | (fset function defn)))) | ||
| 697 | 708 | ||
| 698 | (defun debug-on-entry-1 (function flag) | 709 | (defun debug-on-entry-1 (function flag) |
| 699 | (let* ((defn (symbol-function function)) | 710 | (let* ((defn (symbol-function function)) |
| 700 | (tail defn)) | 711 | (tail defn)) |
| 701 | (if (subrp tail) | 712 | (when (eq (car-safe tail) 'macro) |
| 702 | (error "%s is a built-in function" function) | 713 | (setq tail (cdr tail))) |
| 703 | (if (eq (car tail) 'macro) (setq tail (cdr tail))) | 714 | (if (not (eq (car-safe tail) 'lambda)) |
| 704 | (if (eq (car tail) 'lambda) (setq tail (cdr tail)) | 715 | ;; Only signal an error when we try to set debug-on-entry. |
| 705 | (error "%s not user-defined Lisp function" function)) | 716 | ;; When we try to clear debug-on-entry, we are now done. |
| 717 | (when flag | ||
| 718 | (error "%s is not a user-defined Lisp function" function)) | ||
| 719 | (setq tail (cdr tail)) | ||
| 706 | ;; Skip the docstring. | 720 | ;; Skip the docstring. |
| 707 | (when (and (stringp (cadr tail)) (cddr tail)) | 721 | (when (and (stringp (cadr tail)) (cddr tail)) |
| 708 | (setq tail (cdr tail))) | 722 | (setq tail (cdr tail))) |
| @@ -713,8 +727,8 @@ If argument is nil or an empty string, cancel for all functions." | |||
| 713 | ;; Add/remove debug statement as needed. | 727 | ;; Add/remove debug statement as needed. |
| 714 | (if flag | 728 | (if flag |
| 715 | (setcdr tail (cons '(implement-debug-on-entry) (cdr tail))) | 729 | (setcdr tail (cons '(implement-debug-on-entry) (cdr tail))) |
| 716 | (setcdr tail (cddr tail)))) | 730 | (setcdr tail (cddr tail))))) |
| 717 | defn))) | 731 | defn)) |
| 718 | 732 | ||
| 719 | (defun debugger-list-functions () | 733 | (defun debugger-list-functions () |
| 720 | "Display a list of all the functions now set to debug on entry." | 734 | "Display a list of all the functions now set to debug on entry." |