1 ;;; debug.el --- debuggers and related commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1994, 2001, 2003 Free Software Foundation, Inc.
6 ;; Keywords: lisp, tools, maint
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This is a major mode documented in the Emacs manual.
33 (defgroup debugger nil
34 "Debuggers and related commands for Emacs."
38 (defcustom debugger-mode-hook nil
39 "*Hooks run when `debugger-mode' is turned on."
44 (defcustom debugger-batch-max-lines
40
45 "*Maximum lines to show in debugger buffer in a noninteractive Emacs.
46 When the debugger is entered and Emacs is running in batch mode,
47 if the backtrace text has more than this many lines,
48 the middle is discarded, and just the beginning and end are displayed."
53 (defcustom debug-function-list nil
54 "List of functions currently set for debug on entry."
55 :type
'(repeat function
)
58 (defcustom debugger-step-after-exit nil
59 "Non-nil means \"single-step\" after the debugger exits."
63 (defvar debugger-value nil
64 "This is the value for the debugger to return, when it returns.")
66 (defvar debugger-old-buffer nil
67 "This is the buffer that was current when the debugger was entered.")
69 (defvar debugger-previous-backtrace nil
70 "The contents of the previous backtrace (including text properties).
71 This is to optimize `debugger-make-xrefs'.")
73 (defvar debugger-outer-match-data
)
74 (defvar debugger-outer-load-read-function
)
75 (defvar debugger-outer-overriding-local-map
)
76 (defvar debugger-outer-overriding-terminal-local-map
)
77 (defvar debugger-outer-track-mouse
)
78 (defvar debugger-outer-last-command
)
79 (defvar debugger-outer-this-command
)
80 ;; unread-command-char is obsolete,
81 ;; but we still save and restore it
82 ;; in case some user program still tries to set it.
83 (defvar debugger-outer-unread-command-char
)
84 (defvar debugger-outer-unread-command-events
)
85 (defvar debugger-outer-unread-post-input-method-events
)
86 (defvar debugger-outer-last-input-event
)
87 (defvar debugger-outer-last-command-event
)
88 (defvar debugger-outer-last-nonmenu-event
)
89 (defvar debugger-outer-last-event-frame
)
90 (defvar debugger-outer-standard-input
)
91 (defvar debugger-outer-standard-output
)
92 (defvar debugger-outer-inhibit-redisplay
)
93 (defvar debugger-outer-cursor-in-echo-area
)
96 (setq debugger
'debug
)
98 (defun debug (&rest debugger-args
)
99 "Enter debugger. To return, type \\<debugger-mode-map>`\\[debugger-continue]'.
100 Arguments are mainly for use when this is called from the internals
103 You may call with no args, or you may pass nil as the first arg and
104 any other args you like. In that case, the list of args after the
105 first will be printed into the backtrace buffer."
107 (if inhibit-redisplay
108 ;; Don't really try to enter debugger within an eval from redisplay.
110 (unless noninteractive
111 (message "Entering debugger..."))
115 (debugger-buffer (let ((default-major-mode 'fundamental-mode
))
116 (get-buffer-create "*Backtrace*")))
117 (debugger-old-buffer (current-buffer))
118 (debugger-step-after-exit nil
)
119 ;; Don't keep reading from an executing kbd macro!
120 (executing-kbd-macro nil
)
121 ;; Save the outer values of these vars for the `e' command
122 ;; before we replace the values.
123 (debugger-outer-match-data (match-data))
124 (debugger-outer-load-read-function load-read-function
)
125 (debugger-outer-overriding-local-map overriding-local-map
)
126 (debugger-outer-overriding-terminal-local-map
127 overriding-terminal-local-map
)
128 (debugger-outer-track-mouse track-mouse
)
129 (debugger-outer-last-command last-command
)
130 (debugger-outer-this-command this-command
)
131 (debugger-outer-unread-command-char unread-command-char
)
132 (debugger-outer-unread-command-events unread-command-events
)
133 (debugger-outer-unread-post-input-method-events
134 unread-post-input-method-events
)
135 (debugger-outer-last-input-event last-input-event
)
136 (debugger-outer-last-command-event last-command-event
)
137 (debugger-outer-last-nonmenu-event last-nonmenu-event
)
138 (debugger-outer-last-event-frame last-event-frame
)
139 (debugger-outer-standard-input standard-input
)
140 (debugger-outer-standard-output standard-output
)
141 (debugger-outer-inhibit-redisplay inhibit-redisplay
)
142 (debugger-outer-cursor-in-echo-area cursor-in-echo-area
))
143 ;; Set this instead of binding it, so that `q'
144 ;; will not restore it.
145 (setq overriding-terminal-local-map nil
)
146 ;; Don't let these magic variables affect the debugger itself.
147 (let ((last-command nil
) this-command track-mouse
148 (unread-command-char -
1) unread-command-events
149 unread-post-input-method-events
150 last-input-event last-command-event last-nonmenu-event
154 ;; If we are inside a minibuffer, allow nesting
155 ;; so that we don't get an error from the `e' command.
156 (enable-recursive-minibuffers
157 (or enable-recursive-minibuffers
(> (minibuffer-depth) 0)))
158 (standard-input t
) (standard-output t
)
160 (cursor-in-echo-area nil
))
163 (save-window-excursion
164 (pop-to-buffer debugger-buffer
)
166 (debugger-setup-buffer debugger-args
)
168 ;; If the backtrace is long, save the beginning
169 ;; and the end, but discard the middle.
170 (when (> (count-lines (point-min) (point-max))
171 debugger-batch-max-lines
)
172 (goto-char (point-min))
173 (forward-line (/ 2 debugger-batch-max-lines
))
174 (let ((middlestart (point)))
175 (goto-char (point-max))
176 (forward-line (- (/ 2 debugger-batch-max-lines
)
177 debugger-batch-max-lines
))
178 (delete-region middlestart
(point)))
180 (goto-char (point-min))
181 (message "%s" (buffer-string))
183 (if (eq (car debugger-args
) 'debug
)
184 ;; Skip the frames for backtrace-debug, byte-code, and debug.
185 (backtrace-debug 3 t
))
188 (let ((inhibit-trace t
)
189 (standard-output nil
)
190 (buffer-read-only t
))
192 ;; Make sure we unbind buffer-read-only in the right buffer.
195 ;; Kill or at least neuter the backtrace buffer, so that users
196 ;; don't try to execute debugger commands in an invalid context.
197 (if (get-buffer-window debugger-buffer
'visible
)
198 ;; Still visible despite the save-window-excursion? Maybe it
199 ;; it's in a pop-up frame. It would be annoying to delete and
200 ;; recreate it every time the debugger stops, so instead we'll
201 ;; erase it but leave it visible.
203 (set-buffer debugger-buffer
)
206 (kill-buffer debugger-buffer
))
207 (set-match-data debugger-outer-match-data
)))
208 ;; Put into effect the modified values of these variables
209 ;; in case the user set them with the `e' command.
210 (setq load-read-function debugger-outer-load-read-function
)
211 (setq overriding-local-map debugger-outer-overriding-local-map
)
212 (setq overriding-terminal-local-map
213 debugger-outer-overriding-terminal-local-map
)
214 (setq track-mouse debugger-outer-track-mouse
)
215 (setq last-command debugger-outer-last-command
)
216 (setq this-command debugger-outer-this-command
)
217 (setq unread-command-char debugger-outer-unread-command-char
)
218 (setq unread-command-events debugger-outer-unread-command-events
)
219 (setq unread-post-input-method-events
220 debugger-outer-unread-post-input-method-events
)
221 (setq last-input-event debugger-outer-last-input-event
)
222 (setq last-command-event debugger-outer-last-command-event
)
223 (setq last-nonmenu-event debugger-outer-last-nonmenu-event
)
224 (setq last-event-frame debugger-outer-last-event-frame
)
225 (setq standard-input debugger-outer-standard-input
)
226 (setq standard-output debugger-outer-standard-output
)
227 (setq inhibit-redisplay debugger-outer-inhibit-redisplay
)
228 (setq cursor-in-echo-area debugger-outer-cursor-in-echo-area
)
229 (setq debug-on-next-call debugger-step-after-exit
)
232 (defun debugger-setup-buffer (debugger-args)
233 "Initialize the `*Backtrace*' buffer for entry to the debugger.
234 That buffer should be current already."
235 (setq buffer-read-only nil
)
237 (set-buffer-multibyte nil
)
238 (let ((standard-output (current-buffer))
239 (print-escape-newlines t
)
243 (goto-char (point-min))
244 (delete-region (point)
246 (search-forward "\n debug(")
249 (insert "Debugger entered")
250 ;; lambda is for debug-on-call when a function call is next.
251 ;; debug is for debug-on-entry function called.
252 (cond ((memq (car debugger-args
) '(lambda debug
))
253 (insert "--entering a function:\n")
254 (if (eq (car debugger-args
) 'debug
)
258 (beginning-of-line))))
259 ;; Exiting a function.
260 ((eq (car debugger-args
) 'exit
)
261 (insert "--returning value: ")
262 (setq debugger-value
(nth 1 debugger-args
))
263 (prin1 debugger-value
(current-buffer))
268 ;; Debugger entered for an error.
269 ((eq (car debugger-args
) 'error
)
270 (insert "--Lisp error: ")
271 (prin1 (nth 1 debugger-args
) (current-buffer))
273 ;; debug-on-call, when the next thing is an eval.
274 ((eq (car debugger-args
) t
)
275 (insert "--beginning evaluation of function call form:\n"))
276 ;; User calls debug directly.
279 (prin1 (if (eq (car debugger-args
) 'nil
)
280 (cdr debugger-args
) debugger-args
)
283 ;; After any frame that uses eval-buffer,
284 ;; insert a line that states the buffer position it's reading at.
286 (while (re-search-forward "^ eval-buffer(" nil t
)
288 (insert (format "\n ;;; Reading at buffer position %d"
289 (with-current-buffer (nth 2 (backtrace-frame (debugger-frame-number)))
291 (debugger-make-xrefs))
293 (defun debugger-make-xrefs (&optional buffer
)
294 "Attach cross-references to symbol names in the `*Backtrace*' buffer."
297 (set-buffer (or buffer
(current-buffer)))
298 (setq buffer
(current-buffer))
299 (let ((buffer-read-only nil
)
300 (old-end (point-min)) (new-end (point-min)))
301 ;; If we saved an old backtrace, find the common part
302 ;; between the new and the old.
303 ;; Compare line by line, starting from the end,
304 ;; because that's the part that is likely to be unchanged.
305 (if debugger-previous-backtrace
306 (let (old-start new-start
(all-match t
))
307 (goto-char (point-max))
309 (insert debugger-previous-backtrace
)
310 (while (and all-match
(not (bobp)))
311 (setq old-end
(point))
313 (setq old-start
(point))
314 (with-current-buffer buffer
315 (setq new-end
(point))
317 (setq new-start
(point)))
319 (compare-buffer-substrings
320 (current-buffer) old-start old-end
321 buffer new-start new-end
)))
322 (setq all-match nil
))))
323 ;; Now new-end is the position of the start of the
324 ;; unchanged part in the current buffer, and old-end is
325 ;; the position of that same text in the saved old
326 ;; backtrace. But we must subtract (point-min) since strings are
327 ;; indexed in origin 0.
329 ;; Replace the unchanged part of the backtrace
330 ;; with the text from debugger-previous-backtrace,
331 ;; since that already has the proper xrefs.
332 ;; With this optimization, we only need to scan
333 ;; the changed part of the backtrace.
334 (delete-region new-end
(point-max))
335 (goto-char (point-max))
336 (insert (substring debugger-previous-backtrace
337 (- old-end
(point-min))))
338 ;; Make the unchanged part of the backtrace inaccessible
339 ;; so it won't be scanned.
340 (narrow-to-region (point-min) new-end
)))
342 ;; Scan the new part of the backtrace, inserting xrefs.
343 (goto-char (point-min))
345 (skip-syntax-forward "^w_")
348 (end (progn (skip-syntax-forward "w_") (point)))
349 (sym (intern-soft (buffer-substring-no-properties
351 (file (and sym
(symbol-file sym
))))
354 ;; help-xref-button needs to operate on something matched
355 ;; by a regexp, so set that up for it.
356 (re-search-forward "\\(\\(\\sw\\|\\s_\\)+\\)")
357 (help-xref-button 1 'help-function-def sym file
)))
360 (setq debugger-previous-backtrace
(buffer-string))))
362 (defun debugger-step-through ()
363 "Proceed, stepping through subexpressions of this expression.
364 Enter another debugger on next entry to eval, apply or funcall."
366 (setq debugger-step-after-exit t
)
367 (message "Proceeding, will debug on next eval or call.")
368 (exit-recursive-edit))
370 (defun debugger-continue ()
371 "Continue, evaluating this expression without stopping."
373 (unless debugger-may-continue
374 (error "Cannot continue"))
375 (message "Continuing.")
376 (exit-recursive-edit))
378 (defun debugger-return-value (val)
379 "Continue, specifying value to return.
380 This is only useful when the value returned from the debugger
381 will be used, such as in a debug on exit from a frame."
382 (interactive "XReturn value (evaluated): ")
383 (setq debugger-value val
)
384 (princ "Returning " t
)
385 (prin1 debugger-value
)
386 (exit-recursive-edit))
388 (defun debugger-jump ()
389 "Continue to exit from this frame, with all debug-on-entry suspended."
392 ;; Turn off all debug-on-entry functions
393 ;; but leave them in the list.
394 (let ((list debug-function-list
))
397 (debug-on-entry-1 (car list
) (symbol-function (car list
)) nil
))
398 (setq list
(cdr list
))))
399 (message "Continuing through this frame")
400 (exit-recursive-edit))
402 (defun debugger-reenable ()
403 "Turn all debug-on-entry functions back on."
404 (let ((list debug-function-list
))
406 (or (consp (symbol-function (car list
)))
407 (debug-convert-byte-code (car list
)))
409 (debug-on-entry-1 (car list
) (symbol-function (car list
)) t
))
410 (setq list
(cdr list
)))))
412 (defun debugger-frame-number ()
413 "Return number of frames in backtrace before the one point points at."
416 (let ((opoint (point))
418 (while (not (eq (cadr (backtrace-frame count
)) 'debug
))
419 (setq count
(1+ count
)))
420 (goto-char (point-min))
421 (if (or (equal (buffer-substring (point) (+ (point) 6))
423 (equal (buffer-substring (point) (+ (point) 6))
431 (if (= (following-char) ?\
()
436 (if (looking-at " *;;;")
438 (setq count
(1+ count
)))
441 (defun debugger-frame ()
442 "Request entry to debugger when this frame exits.
443 Applies to the frame whose line point is on in the backtrace."
447 (if (looking-at " *;;;\\|[a-z]")
448 (error "This line is not a function call")))
450 (backtrace-debug (debugger-frame-number) t
)
451 (if (= (following-char) ?
)
452 (let ((buffer-read-only nil
))
457 (defun debugger-frame-clear ()
458 "Do not enter debugger when this frame exits.
459 Applies to the frame whose line point is on in the backtrace."
463 (if (looking-at " *;;;\\|[a-z]")
464 (error "This line is not a function call")))
466 (backtrace-debug (debugger-frame-number) nil
)
467 (if (= (following-char) ?
*)
468 (let ((buffer-read-only nil
))
475 (put 'debugger-env-macro
'lisp-indent-function
0)
476 (defmacro debugger-env-macro
(&rest body
)
477 "Run BODY in original environment."
479 (if (null (buffer-name debugger-old-buffer
))
480 ;; old buffer deleted
481 (setq debugger-old-buffer
(current-buffer)))
482 (set-buffer debugger-old-buffer
)
483 (let ((load-read-function debugger-outer-load-read-function
)
484 (overriding-terminal-local-map
485 debugger-outer-overriding-terminal-local-map
)
486 (overriding-local-map debugger-outer-overriding-local-map
)
487 (track-mouse debugger-outer-track-mouse
)
488 (last-command debugger-outer-last-command
)
489 (this-command debugger-outer-this-command
)
490 (unread-command-char debugger-outer-unread-command-char
)
491 (unread-command-events debugger-outer-unread-command-events
)
492 (unread-post-input-method-events
493 debugger-outer-unread-post-input-method-events
)
494 (last-input-event debugger-outer-last-input-event
)
495 (last-command-event debugger-outer-last-command-event
)
496 (last-nonmenu-event debugger-outer-last-nonmenu-event
)
497 (last-event-frame debugger-outer-last-event-frame
)
498 (standard-input debugger-outer-standard-input
)
499 (standard-output debugger-outer-standard-output
)
500 (inhibit-redisplay debugger-outer-inhibit-redisplay
)
501 (cursor-in-echo-area debugger-outer-cursor-in-echo-area
))
502 (set-match-data debugger-outer-match-data
)
503 (prog1 (progn ,@body
)
504 (setq debugger-outer-match-data
(match-data))
505 (setq debugger-outer-load-read-function load-read-function
)
506 (setq debugger-outer-overriding-terminal-local-map
507 overriding-terminal-local-map
)
508 (setq debugger-outer-overriding-local-map overriding-local-map
)
509 (setq debugger-outer-track-mouse track-mouse
)
510 (setq debugger-outer-last-command last-command
)
511 (setq debugger-outer-this-command this-command
)
512 (setq debugger-outer-unread-command-char unread-command-char
)
513 (setq debugger-outer-unread-command-events unread-command-events
)
514 (setq debugger-outer-unread-post-input-method-events
515 unread-post-input-method-events
)
516 (setq debugger-outer-last-input-event last-input-event
)
517 (setq debugger-outer-last-command-event last-command-event
)
518 (setq debugger-outer-last-nonmenu-event last-nonmenu-event
)
519 (setq debugger-outer-last-event-frame last-event-frame
)
520 (setq debugger-outer-standard-input standard-input
)
521 (setq debugger-outer-standard-output standard-output
)
522 (setq debugger-outer-inhibit-redisplay inhibit-redisplay
)
523 (setq debugger-outer-cursor-in-echo-area cursor-in-echo-area
)
526 (defun debugger-eval-expression (exp)
527 "Eval an expression, in an environment like that outside the debugger."
529 (list (read-from-minibuffer "Eval: "
530 nil read-expression-map t
531 'read-expression-history
)))
532 (debugger-env-macro (eval-expression exp
)))
534 (defvar debugger-mode-map nil
)
535 (unless debugger-mode-map
537 (setq debugger-mode-map
(make-keymap))
538 (set-keymap-parent debugger-mode-map button-buffer-map
)
539 (suppress-keymap debugger-mode-map
)
540 (define-key debugger-mode-map
"-" 'negative-argument
)
541 (define-key debugger-mode-map
"b" 'debugger-frame
)
542 (define-key debugger-mode-map
"c" 'debugger-continue
)
543 (define-key debugger-mode-map
"j" 'debugger-jump
)
544 (define-key debugger-mode-map
"r" 'debugger-return-value
)
545 (define-key debugger-mode-map
"u" 'debugger-frame-clear
)
546 (define-key debugger-mode-map
"d" 'debugger-step-through
)
547 (define-key debugger-mode-map
"l" 'debugger-list-functions
)
548 (define-key debugger-mode-map
"h" 'describe-mode
)
549 (define-key debugger-mode-map
"q" 'top-level
)
550 (define-key debugger-mode-map
"e" 'debugger-eval-expression
)
551 (define-key debugger-mode-map
" " 'next-line
)
552 (define-key debugger-mode-map
"R" 'debugger-record-expression
)
553 (define-key debugger-mode-map
"\C-m" 'help-follow
)
554 (define-key debugger-mode-map
[mouse-2
] 'push-button
)
558 (defcustom debugger-record-buffer
"*Debugger-record*"
559 "*Buffer name for expression values, for \\[debugger-record-expression]."
564 (defun debugger-record-expression (exp)
565 "Display a variable's value and record it in `*Backtrace-record*' buffer."
567 (list (read-from-minibuffer
570 read-expression-map t
571 'read-expression-history
)))
572 (let* ((buffer (get-buffer-create debugger-record-buffer
))
573 (standard-output buffer
))
574 (princ (format "Debugger Eval (%s): " exp
))
575 (princ (debugger-eval-expression exp
))
578 (with-current-buffer (get-buffer debugger-record-buffer
)
582 (buffer-substring (point) (progn (end-of-line) (point)))))))
584 (put 'debugger-mode
'mode-class
'special
)
586 (defun debugger-mode ()
587 "Mode for backtrace buffers, selected in debugger.
588 \\<debugger-mode-map>
589 A line starts with `*' if exiting that frame will call the debugger.
590 Type \\[debugger-frame] or \\[debugger-frame-clear] to set or remove the `*'.
592 When in debugger due to frame being exited,
593 use the \\[debugger-return-value] command to override the value
594 being returned from that frame.
596 Use \\[debug-on-entry] and \\[cancel-debug-on-entry] to control
597 which functions will enter the debugger when called.
599 Complete list of commands:
600 \\{debugger-mode-map}"
601 (kill-all-local-variables)
602 (setq major-mode
'debugger-mode
)
603 (setq mode-name
"Debugger")
604 (setq truncate-lines t
)
605 (set-syntax-table emacs-lisp-mode-syntax-table
)
606 (use-local-map debugger-mode-map
)
607 (run-hooks 'debugger-mode-hook
))
610 (defun debug-on-entry (function)
611 "Request FUNCTION to invoke debugger each time it is called.
612 If you tell the debugger to continue, FUNCTION's execution proceeds.
613 This works by modifying the definition of FUNCTION,
614 which must be written in Lisp, not predefined.
615 Use \\[cancel-debug-on-entry] to cancel the effect of this command.
616 Redefining FUNCTION also cancels it."
617 (interactive "aDebug on entry (to function): ")
619 ;; Handle a function that has been aliased to some other function.
620 (if (and (subrp (symbol-function function
))
621 (eq (cdr (subr-arity (symbol-function function
))) 'unevalled
))
622 (error "Function %s is a special form" function
))
623 (if (or (symbolp (symbol-function function
))
624 (subrp (symbol-function function
)))
625 ;; Create a wrapper in which we can then add the necessary debug call.
626 (fset function
`(lambda (&rest debug-on-entry-args
)
627 ,(interactive-form (symbol-function function
))
628 (apply ',(symbol-function function
)
629 debug-on-entry-args
))))
630 (or (consp (symbol-function function
))
631 (debug-convert-byte-code function
))
632 (or (consp (symbol-function function
))
633 (error "Definition of %s is not a list" function
))
634 (fset function
(debug-on-entry-1 function
(symbol-function function
) t
))
635 (or (memq function debug-function-list
)
636 (push function debug-function-list
))
640 (defun cancel-debug-on-entry (&optional function
)
641 "Undo effect of \\[debug-on-entry] on FUNCTION.
642 If argument is nil or an empty string, cancel for all functions."
645 (completing-read "Cancel debug on entry (to function): "
646 (mapcar 'symbol-name debug-function-list
)
648 (if name
(intern name
)))))
650 (if (and function
(not (string= function
"")))
652 (let ((f (debug-on-entry-1 function
(symbol-function function
) nil
)))
654 (if (and (equal (nth 1 f
) '(&rest debug-on-entry-args
))
655 (eq (car (nth 3 f
)) 'apply
))
656 ;; `f' is a wrapper introduced in debug-on-entry.
657 ;; Get rid of it since we don't need it any more.
658 (setq f
(nth 1 (nth 1 (nth 3 f
)))))
661 (setq debug-function-list
(delq function debug-function-list
))
663 (message "Cancelling debug-on-entry for all functions")
664 (mapcar 'cancel-debug-on-entry debug-function-list
)))
666 (defun debug-convert-byte-code (function)
667 (let ((defn (symbol-function function
)))
668 (if (not (consp defn
))
669 ;; Assume a compiled code object.
670 (let* ((contents (append defn nil
))
672 (list (list 'byte-code
(nth 1 contents
)
673 (nth 2 contents
) (nth 3 contents
)))))
674 (if (nthcdr 5 contents
)
675 (setq body
(cons (list 'interactive
(nth 5 contents
)) body
)))
677 ;; Use `documentation' here, to get the actual string,
678 ;; in case the compiled function has a reference
680 (setq body
(cons (documentation function
) body
)))
681 (fset function
(cons 'lambda
(cons (car contents
) body
)))))))
683 (defun debug-on-entry-1 (function defn flag
)
685 (error "%s is a built-in function" function
)
686 (if (eq (car defn
) 'macro
)
687 (debug-on-entry-1 function
(cdr defn
) flag
)
688 (or (eq (car defn
) 'lambda
)
689 (error "%s not user-defined Lisp function" function
))
690 (let ((tail (cddr defn
)))
691 ;; Skip the docstring.
692 (if (stringp (car tail
)) (setq tail
(cdr tail
)))
693 ;; Skip the interactive form.
694 (if (eq 'interactive
(car-safe (car tail
))) (setq tail
(cdr tail
)))
695 (unless (eq flag
(equal (car tail
) '(debug 'debug
)))
696 ;; Add/remove debug statement as needed.
698 (progn (setcar tail
(cadr tail
))
699 (setcdr tail
(cddr tail
)))
700 (setcdr tail
(cons (car tail
) (cdr tail
)))
701 (setcar tail
'(debug 'debug
))))
704 (defun debugger-list-functions ()
705 "Display a list of all the functions now set to debug on entry."
707 (with-output-to-temp-buffer "*Help*"
708 (if (null debug-function-list
)
709 (princ "No debug-on-entry functions now\n")
710 (princ "Functions set to debug on entry:\n\n")
711 (let ((list debug-function-list
))
715 (setq list
(cdr list
))))
716 (princ "Note: if you have redefined a function, then it may no longer\n")
717 (princ "be set to debug on entry, even if it is in the list."))
719 (set-buffer standard-output
)
724 ;;; debug.el ends here