
* lisp/allout.el (allout-abbreviate-flattened-numbering) (allout-mode-deactivate-hook): * lisp/ansi-color.el (ansi-color-unfontify-region): * lisp/auth-source.el (auth-source-hide-passwords) (auth-source-user-or-password) (auth-source-forget-user-or-password): * lisp/cedet/data-debug.el (data-debug-map): * lisp/cedet/semantic/grammar.el (semantic-grammar-syntax-table) (semantic-grammar-map): * lisp/chistory.el (command-history-map): * lisp/comint.el (comint-dynamic-complete) (comint-dynamic-complete-as-filename) (comint-dynamic-simple-complete): * lisp/dired-x.el (read-filename-at-point) (dired-x-submit-report): * lisp/dos-fns.el (register-name-alist, make-register) (register-value, set-register-value, intdos, mode25, mode4350): * lisp/emacs-lisp/bytecomp.el (byte-compile-disable-print-circle): * lisp/emacs-lisp/chart.el (chart-map): * lisp/emacs-lisp/package.el (package-menu-view-commentary): * lisp/emacs-lock.el (toggle-emacs-lock, emacs-lock-from-exiting): * lisp/erc/erc.el (erc-complete-word): * lisp/eshell/em-cmpl.el (eshell-cmpl-suffix-list): * lisp/eshell/esh-util.el (eshell-for): * lisp/files.el (inhibit-first-line-modes-regexps) (inhibit-first-line-modes-suffixes): * lisp/gnus/gnus-msg.el (gnus-outgoing-message-group) (gnus-debug-files, gnus-debug-exclude-variables): * lisp/gnus/gnus-registry.el (gnus-registry-user-format-function-M): * lisp/gnus/gnus.el (gnus-local-domain, gnus-carpal): * lisp/gnus/nnimap.el (nnimap-split-rule): * lisp/iimage.el (turn-on-iimage-mode): * lisp/image.el (image-extension-data, image-library-alist): * lisp/mail/emacsbug.el (report-emacs-bug-pretest-address): * lisp/mail/mail-utils.el (rmail-dont-reply-to): * lisp/mail/mailalias.el (mail-complete-function) (mail-completion-at-point-function): * lisp/mail/rmail.el (rmail-dont-reply-to-names) (rmail-default-dont-reply-to-names): * lisp/mail/sendmail.el (mail-mailer-swallows-blank-line) (mail-sent-via): * lisp/menu-bar.el (menu-bar-kill-ring-save): * lisp/minibuffer.el (completion-annotate-function) (minibuffer-local-filename-must-match-map): * lisp/msb.el (msb-after-load-hooks): * lisp/obsolete/eieio-compat.el (eieio-defmethod) (eieio-defgeneric): * lisp/obsolete/info-edit.el (Info-edit-map): * lisp/obsolete/starttls.el (starttls-any-program-available): * lisp/progmodes/cfengine.el (cfengine-mode-abbrevs): * lisp/progmodes/cwarn.el (turn-on-cwarn-mode): * lisp/progmodes/make-mode.el (makefile-complete): * lisp/progmodes/meta-mode.el (meta-complete-symbol) (meta-mode-map): * lisp/progmodes/pascal.el (pascal-toggle-completions) (pascal-last-completions, pascal-show-completions): * lisp/progmodes/prolog.el (prolog-char-quote-workaround): * lisp/progmodes/which-func.el (which-func-mode): [FUNCTION] * lisp/simple.el (count-lines-region, minibuffer-completing-symbol): * lisp/speedbar.el (speedbar-syntax-table, speedbar-key-map): * lisp/strokes.el (strokes-report-bug): * lisp/subr.el (condition-case-no-debug): * lisp/term/ns-win.el (ns-alternatives-map) (ns-store-cut-buffer-internal): * lisp/term/w32-win.el (w32-default-color-map): * lisp/term/x-win.el (x-cut-buffer-or-selection-value): * lisp/textmodes/bibtex.el (bibtex-complete) (bibtex-entry-field-alist): * lisp/textmodes/reftex-index.el (reftex-index-map) (reftex-index-phrases-map): * lisp/textmodes/reftex-sel.el (reftex-select-label-map) (reftex-select-bib-map): * lisp/textmodes/reftex-toc.el (reftex-toc-map): * lisp/textmodes/rst.el (rst-block-face, rst-external-face) (rst-definition-face, rst-directive-face, rst-comment-face) (rst-emphasis1-face, rst-emphasis2-face, rst-literal-face) (rst-reference-face): * lisp/vc/vc-hooks.el (vc-toggle-read-only): * lisp/view.el (view-return-to-alist) (view-return-to-alist-update): Remove many functions and variables obsolete since 24.1. * lisp/textmodes/bibtex.el (bibtex-entry-alist): Don't use above removed variable 'bibtex-entry-field-alist'. * lisp/cedet/data-debug.el (data-debug-edebug-expr) (data-debug-eval-expression): * lisp/emacs-lisp/trace.el (trace--read-args): * lisp/files-x.el (read-file-local-variable-value): * lisp/simple.el (read--expression): Don't use above removed variable 'minibuffer-completing-symbol'. * lisp/textmodes/rst.el (rst-font-lock-keywords): Don't use above removed variables. * src/w32fns.c (Fw32_default_color_map): Delete obsolete function. (syms_of_w32fns): Delete defsubr for above defun. * src/keyboard.c (syms_of_keyboard) <Vdeferred_action_list> <Vdeferred_action_function>: Delete DEFVARs. <Qdeferred_action_function>: Delete DEFSYM. (syms_of_keyboard_for_pdumper): Adjust for above change. (command_loop_1): Don't run deferred-action-function hook. * lisp/subr.el (deferred-action-list, deferred-action-function): Delete obsoletion statements. * lisp/emacs-lisp/ert-x.el (ert-simulate-command): Don't run 'deferred-action-list' hook. * doc/lispref/hooks.texi (Standard Hooks): Delete 'deferred-action-function'. * lisp/emacs-lisp/lisp.el (field-complete): * lisp/eshell/em-cmpl.el (eshell-cmpl-initialize): * lisp/gnus/gnus-msg.el (gnus-inews-insert-gcc): * lisp/gnus/nnmail.el (nnmail-fancy-expiry-target): * lisp/mail/mail-utils.el (mail-dont-reply-to): * lisp/mail/sendmail.el (sendmail-send-it): * lisp/mail/smtpmail.el (smtpmail-send-it): * lisp/minibuffer.el (minibuffer-completion-help): * lisp/progmodes/python.el: Don't use above removed items. * lisp/emacs-lisp/eieio-core.el: * lisp/mail/mailalias.el (mail-complete-alist): Doc fixes; don't refer to above removed items. ; * etc/NEWS: List removed items.
337 lines
12 KiB
EmacsLisp
337 lines
12 KiB
EmacsLisp
;;; trace.el --- tracing facility for Emacs Lisp functions -*- lexical-binding: t -*-
|
|
|
|
;; Copyright (C) 1993, 1998, 2000-2022 Free Software Foundation, Inc.
|
|
|
|
;; Author: Hans Chalupsky <hans@cs.buffalo.edu>
|
|
;; Maintainer: emacs-devel@gnu.org
|
|
;; Created: 15 Dec 1992
|
|
;; Keywords: tools, lisp
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; 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 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
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
;; LCD Archive Entry:
|
|
;; trace|Hans Chalupsky|hans@cs.buffalo.edu|
|
|
;; Tracing facility for Emacs Lisp functions|
|
|
;; 1993/05/18 00:41:16|2.0|~/packages/trace.el.Z|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; Introduction:
|
|
;; =============
|
|
;; A simple trace package that utilizes nadvice.el. It generates trace
|
|
;; information in a Lisp-style fashion and inserts it into a trace output
|
|
;; buffer. Tracing can be done in the background (or silently) so that
|
|
;; generation of trace output won't interfere with what you are currently
|
|
;; doing.
|
|
|
|
;; Restrictions:
|
|
;; =============
|
|
;; - Traced subrs when called interactively will always show nil as the
|
|
;; value of their arguments.
|
|
;; - Only functions/macros/subrs that are called via their function cell will
|
|
;; generate trace output, hence, you won't get trace output for:
|
|
;; + Subrs called directly from other subrs/C-code
|
|
;; + Compiled calls to subrs that have special byte-codes associated
|
|
;; with them (e.g., car, cdr, ...)
|
|
;; + Macros that were expanded during compilation
|
|
;; - All the restrictions that apply to nadvice.el
|
|
|
|
;; Usage:
|
|
;; ======
|
|
;; - To trace a function say `M-x trace-function', which will ask you for the
|
|
;; name of the function/subr/macro to trace.
|
|
;; - If you want to trace a function that switches buffers or does other
|
|
;; display oriented stuff use `M-x trace-function-background', which will
|
|
;; generate the trace output silently in the background without popping
|
|
;; up windows and doing other irritating stuff.
|
|
;; - To untrace a function say `M-x untrace-function'.
|
|
;; - To untrace all currently traced functions say `M-x untrace-all'.
|
|
|
|
;; Examples:
|
|
;; =========
|
|
;;
|
|
;; (defun fact (n)
|
|
;; (if (= n 0) 1
|
|
;; (* n (fact (1- n)))))
|
|
;; fact
|
|
;;
|
|
;; (trace-function 'fact)
|
|
;; fact
|
|
;;
|
|
;; Now, evaluating this...
|
|
;;
|
|
;; (fact 4)
|
|
;; 24
|
|
;;
|
|
;; ...will generate the following in *trace-buffer*:
|
|
;;
|
|
;; 1 -> fact: n=4
|
|
;; | 2 -> fact: n=3
|
|
;; | | 3 -> fact: n=2
|
|
;; | | | 4 -> fact: n=1
|
|
;; | | | | 5 -> fact: n=0
|
|
;; | | | | 5 <- fact: 1
|
|
;; | | | 4 <- fact: 1
|
|
;; | | 3 <- fact: 2
|
|
;; | 2 <- fact: 6
|
|
;; 1 <- fact: 24
|
|
;;
|
|
;;
|
|
;; (defun ack (x y z)
|
|
;; (if (= x 0)
|
|
;; (+ y z)
|
|
;; (if (and (<= x 2) (= z 0))
|
|
;; (1- x)
|
|
;; (if (and (> x 2) (= z 0))
|
|
;; y
|
|
;; (ack (1- x) y (ack x y (1- z)))))))
|
|
;; ack
|
|
;;
|
|
;; (trace-function 'ack)
|
|
;; ack
|
|
;;
|
|
;; Try this for some interesting trace output:
|
|
;;
|
|
;; (ack 3 3 1)
|
|
;; 27
|
|
;;
|
|
;;
|
|
;; The following does something similar to the functionality of the package
|
|
;; log-message.el by Robert Potter, which is giving you a chance to look at
|
|
;; messages that might have whizzed by too quickly (you won't see subr
|
|
;; generated messages though):
|
|
;;
|
|
;; (trace-function-background 'message "*Message Log*")
|
|
|
|
|
|
;;; Change Log:
|
|
|
|
;; Revision 2.0 1993/05/18 00:41:16 hans
|
|
;; * Adapted for advice.el 2.0; it now also works
|
|
;; for GNU Emacs-19 and Lemacs
|
|
;; * Separate function `trace-function-background'
|
|
;; * Separate pieces of advice for foreground and background tracing
|
|
;; * Less insane handling of interactive trace buffer specification
|
|
;; * String arguments and values are now printed properly
|
|
;;
|
|
;; Revision 1.1 1992/12/15 22:45:15 hans
|
|
;; * Created, first public release
|
|
|
|
|
|
;;; Code:
|
|
|
|
(defgroup trace nil
|
|
"Tracing facility for Emacs Lisp functions."
|
|
:prefix "trace-"
|
|
:group 'lisp)
|
|
|
|
;;;###autoload
|
|
(defcustom trace-buffer "*trace-output*"
|
|
"Trace output will by default go to that buffer."
|
|
:type 'string)
|
|
|
|
;; Current level of traced function invocation:
|
|
(defvar trace-level 0)
|
|
|
|
;; Semi-cryptic name used for a piece of trace advice:
|
|
(defvar trace-advice-name 'trace-function\ )
|
|
|
|
;; Used to separate new trace output from previous traced runs:
|
|
(defvar trace-separator (format "%s\n" (make-string 70 ?=)))
|
|
|
|
(defvar inhibit-trace nil
|
|
"If non-nil, all tracing is temporarily inhibited.")
|
|
|
|
;;;###autoload
|
|
(defun trace-values (&rest values)
|
|
"Helper function to get internal values.
|
|
You can call this function to add internal values in the trace buffer."
|
|
(unless inhibit-trace
|
|
(with-current-buffer (get-buffer-create trace-buffer)
|
|
(goto-char (point-max))
|
|
(insert
|
|
(trace-entry-message
|
|
'trace-values trace-level values "")))))
|
|
|
|
(defun trace-entry-message (function level args context)
|
|
"Generate a string that describes that FUNCTION has been entered.
|
|
LEVEL is the trace level, ARGS is the list of arguments passed to FUNCTION,
|
|
and CONTEXT is a string describing the dynamic context (e.g. values of
|
|
some global variables)."
|
|
(let ((print-circle t)
|
|
(print-escape-newlines t))
|
|
(format "%s%s%d -> %S%s\n"
|
|
(mapconcat #'char-to-string (make-string (max 0 (1- level)) ?|) " ")
|
|
(if (> level 1) " " "")
|
|
level
|
|
;; FIXME: Make it so we can click the function name to jump to its
|
|
;; definition and/or untrace it.
|
|
(cons function args)
|
|
context)))
|
|
|
|
(defun trace-exit-message (function level value context)
|
|
"Generate a string that describes that FUNCTION has exited.
|
|
LEVEL is the trace level, VALUE value returned by FUNCTION,
|
|
and CONTEXT is a string describing the dynamic context (e.g. values of
|
|
some global variables)."
|
|
(let ((print-circle t)
|
|
(print-escape-newlines t))
|
|
(format "%s%s%d <- %s: %S%s\n"
|
|
(mapconcat 'char-to-string (make-string (1- level) ?|) " ")
|
|
(if (> level 1) " " "")
|
|
level
|
|
function
|
|
;; Do this so we'll see strings:
|
|
value
|
|
context)))
|
|
|
|
(defvar trace--timer nil)
|
|
|
|
(defun trace--display-buffer (buf)
|
|
(unless (or trace--timer
|
|
(get-buffer-window buf 'visible))
|
|
(setq trace--timer
|
|
;; Postpone the display to some later time, in case we
|
|
;; can't actually do it now.
|
|
(run-with-timer 0 nil
|
|
(lambda ()
|
|
(setq trace--timer nil)
|
|
(display-buffer buf nil 0))))))
|
|
|
|
|
|
(defun trace-make-advice (function buffer background context)
|
|
"Build the piece of advice to be added to trace FUNCTION.
|
|
FUNCTION is the name of the traced function.
|
|
BUFFER is the buffer where the trace should be printed.
|
|
BACKGROUND if nil means to display BUFFER.
|
|
CONTEXT if non-nil should be a function that returns extra info that should
|
|
be printed along with the arguments in the trace."
|
|
(lambda (body &rest args)
|
|
(let ((trace-level (1+ trace-level))
|
|
(trace-buffer (get-buffer-create buffer))
|
|
(deactivate-mark nil) ;Protect deactivate-mark.
|
|
(ctx (funcall context)))
|
|
(unless inhibit-trace
|
|
(with-current-buffer trace-buffer
|
|
(setq-local window-point-insertion-type t)
|
|
(unless background (trace--display-buffer trace-buffer))
|
|
(goto-char (point-max))
|
|
;; Insert a separator from previous trace output:
|
|
(if (= trace-level 1) (insert trace-separator))
|
|
(insert
|
|
(trace-entry-message
|
|
function trace-level args ctx))))
|
|
(let ((result))
|
|
(unwind-protect
|
|
(setq result (list (apply body args)))
|
|
(unless inhibit-trace
|
|
(let ((ctx (funcall context)))
|
|
(with-current-buffer trace-buffer
|
|
(unless background (trace--display-buffer trace-buffer))
|
|
(goto-char (point-max))
|
|
(insert
|
|
(trace-exit-message
|
|
function
|
|
trace-level
|
|
(if result (car result) '\!non-local\ exit\!)
|
|
ctx))))))
|
|
(car result)))))
|
|
|
|
(defun trace-function-internal (function buffer background context)
|
|
"Add trace advice for FUNCTION."
|
|
(advice-add
|
|
function :around
|
|
(trace-make-advice function (or buffer trace-buffer) background
|
|
(or context (lambda () "")))
|
|
`((name . ,trace-advice-name) (depth . -100))))
|
|
|
|
(defun trace-is-traced (function)
|
|
(advice-member-p trace-advice-name function))
|
|
|
|
(defun trace--read-args (prompt)
|
|
"Read a function name, prompting with string PROMPT.
|
|
If `current-prefix-arg' is non-nil, also read a buffer and a \"context\"
|
|
\(Lisp expression). Return (FUNCTION BUFFER FUNCTION-CONTEXT)."
|
|
(cons
|
|
(let ((default (function-called-at-point)))
|
|
(intern (completing-read (format-prompt prompt default)
|
|
obarray 'fboundp t nil nil
|
|
(if default (symbol-name default)))))
|
|
(when current-prefix-arg
|
|
(list
|
|
(read-buffer "Output to buffer" trace-buffer)
|
|
(let ((exp
|
|
(read-from-minibuffer "Context expression: "
|
|
nil read-expression-map t
|
|
'read-expression-history)))
|
|
(lambda ()
|
|
(let ((print-circle t)
|
|
(print-escape-newlines t))
|
|
(concat " [" (prin1-to-string (eval exp t)) "]"))))))))
|
|
|
|
;;;###autoload
|
|
(defun trace-function-foreground (function &optional buffer context)
|
|
"Trace calls to function FUNCTION.
|
|
With a prefix argument, also prompt for the trace buffer (default
|
|
`trace-buffer'), and a Lisp expression CONTEXT. When called from
|
|
Lisp, CONTEXT should be a function of no arguments which returns
|
|
a value to insert into BUFFER during the trace.
|
|
|
|
Tracing a function causes every call to that function to insert
|
|
into BUFFER Lisp-style trace messages that display the function's
|
|
arguments and return values. It also evaluates CONTEXT, if that is
|
|
non-nil, and inserts its value too. For example, you can use this
|
|
to track the current buffer, or position of point.
|
|
|
|
This function creates BUFFER if it does not exist. This buffer will
|
|
popup whenever FUNCTION is called. Do not use this function to trace
|
|
functions that switch buffers, or do any other display-oriented
|
|
stuff - use `trace-function-background' instead.
|
|
|
|
To stop tracing a function, use `untrace-function' or `untrace-all'."
|
|
(interactive (trace--read-args "Trace function"))
|
|
(trace-function-internal function buffer nil context))
|
|
|
|
;;;###autoload
|
|
(defun trace-function-background (function &optional buffer context)
|
|
"Trace calls to function FUNCTION, quietly.
|
|
This is like `trace-function-foreground', but without popping up
|
|
the output buffer or changing the window configuration."
|
|
(interactive (trace--read-args "Trace function in background"))
|
|
(trace-function-internal function buffer t context))
|
|
|
|
;;;###autoload
|
|
(defalias 'trace-function 'trace-function-foreground)
|
|
|
|
(defun untrace-function (function)
|
|
"Untraces FUNCTION and possibly activates all remaining advice.
|
|
Activation is performed with `ad-update', hence remaining advice will get
|
|
activated only if the advice of FUNCTION is currently active. If FUNCTION
|
|
was not traced this is a noop."
|
|
(interactive
|
|
(list (intern (completing-read "Untrace function: "
|
|
obarray #'trace-is-traced t))))
|
|
(advice-remove function trace-advice-name))
|
|
|
|
(defun untrace-all ()
|
|
"Untraces all currently traced functions."
|
|
(interactive)
|
|
(mapatoms #'untrace-function))
|
|
|
|
(provide 'trace)
|
|
|
|
;;; trace.el ends here
|