1 ;;; debug.el --- debuggers and related commands for Emacs
3 ;; Copyright (C) 1985, 1986, 1994, 2001, 2003, 2005
4 ;; Free Software Foundation, Inc.
7 ;; Keywords: lisp, tools, maint
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; This is a major mode documented in the Emacs Lisp manual.
34 (defgroup debugger nil
35 "Debuggers and related commands for Emacs."
39 (defcustom debugger-mode-hook nil
40 "*Hooks run when `debugger-mode' is turned on."
45 (defcustom debugger-batch-max-lines
40
46 "*Maximum lines to show in debugger buffer in a noninteractive Emacs.
47 When the debugger is entered and Emacs is running in batch mode,
48 if the backtrace text has more than this many lines,
49 the middle is discarded, and just the beginning and end are displayed."
54 (defvar debug-function-list nil
55 "List of functions currently set for debug on entry.")
57 (defvar debugger-step-after-exit nil
58 "Non-nil means \"single-step\" after the debugger exits.")
60 (defvar debugger-value nil
61 "This is the value for the debugger to return, when it returns.")
63 (defvar debugger-old-buffer nil
64 "This is the buffer that was current when the debugger was entered.")
66 (defvar debugger-previous-backtrace nil
67 "The contents of the previous backtrace (including text properties).
68 This is to optimize `debugger-make-xrefs'.")
70 (defvar debugger-outer-match-data
)
71 (defvar debugger-outer-load-read-function
)
72 (defvar debugger-outer-overriding-local-map
)
73 (defvar debugger-outer-overriding-terminal-local-map
)
74 (defvar debugger-outer-track-mouse
)
75 (defvar debugger-outer-last-command
)
76 (defvar debugger-outer-this-command
)
77 ;; unread-command-char is obsolete,
78 ;; but we still save and restore it
79 ;; in case some user program still tries to set it.
80 (defvar debugger-outer-unread-command-char
)
81 (defvar debugger-outer-unread-command-events
)
82 (defvar debugger-outer-unread-post-input-method-events
)
83 (defvar debugger-outer-last-input-event
)
84 (defvar debugger-outer-last-command-event
)
85 (defvar debugger-outer-last-nonmenu-event
)
86 (defvar debugger-outer-last-event-frame
)
87 (defvar debugger-outer-standard-input
)
88 (defvar debugger-outer-standard-output
)
89 (defvar debugger-outer-inhibit-redisplay
)
90 (defvar debugger-outer-cursor-in-echo-area
)
92 (defvar inhibit-debug-on-entry nil
93 "Non-nil means that debug-on-entry is disabled.")
95 (defvar debugger-jumping-flag nil
96 "Non-nil means that debug-on-entry is disabled.
97 This variable is used by `debugger-jump', `debugger-step-through',
98 and `debugger-reenable' to temporarily disable debug-on-entry.")
101 (setq debugger
'debug
)
103 (defun debug (&rest debugger-args
)
104 "Enter debugger. To return, type \\<debugger-mode-map>`\\[debugger-continue]'.
105 Arguments are mainly for use when this is called from the internals
108 You may call with no args, or you may pass nil as the first arg and
109 any other args you like. In that case, the list of args after the
110 first will be printed into the backtrace buffer."
112 (if inhibit-redisplay
113 ;; Don't really try to enter debugger within an eval from redisplay.
115 (unless noninteractive
116 (message "Entering debugger..."))
120 (debugger-buffer (let ((default-major-mode 'fundamental-mode
))
121 (get-buffer-create "*Backtrace*")))
122 (debugger-old-buffer (current-buffer))
123 (debugger-step-after-exit nil
)
124 ;; Don't keep reading from an executing kbd macro!
125 (executing-kbd-macro nil
)
126 ;; Save the outer values of these vars for the `e' command
127 ;; before we replace the values.
128 (debugger-outer-match-data (match-data))
129 (debugger-outer-load-read-function load-read-function
)
130 (debugger-outer-overriding-local-map overriding-local-map
)
131 (debugger-outer-overriding-terminal-local-map
132 overriding-terminal-local-map
)
133 (debugger-outer-track-mouse track-mouse
)
134 (debugger-outer-last-command last-command
)
135 (debugger-outer-this-command this-command
)
136 (debugger-outer-unread-command-char
137 (with-no-warnings unread-command-char
))
138 (debugger-outer-unread-command-events unread-command-events
)
139 (debugger-outer-unread-post-input-method-events
140 unread-post-input-method-events
)
141 (debugger-outer-last-input-event last-input-event
)
142 (debugger-outer-last-command-event last-command-event
)
143 (debugger-outer-last-nonmenu-event last-nonmenu-event
)
144 (debugger-outer-last-event-frame last-event-frame
)
145 (debugger-outer-standard-input standard-input
)
146 (debugger-outer-standard-output standard-output
)
147 (debugger-outer-inhibit-redisplay inhibit-redisplay
)
148 (debugger-outer-cursor-in-echo-area cursor-in-echo-area
))
149 ;; Set this instead of binding it, so that `q'
150 ;; will not restore it.
151 (setq overriding-terminal-local-map nil
)
152 ;; Don't let these magic variables affect the debugger itself.
153 (let ((last-command nil
) this-command track-mouse
155 (inhibit-debug-on-entry t
)
156 unread-command-events
157 unread-post-input-method-events
158 last-input-event last-command-event last-nonmenu-event
162 ;; If we are inside a minibuffer, allow nesting
163 ;; so that we don't get an error from the `e' command.
164 (enable-recursive-minibuffers
165 (or enable-recursive-minibuffers
(> (minibuffer-depth) 0)))
166 (standard-input t
) (standard-output t
)
168 (cursor-in-echo-area nil
))
171 (save-window-excursion
173 (setq unread-command-char -
1))
174 (when (eq (car debugger-args
) 'debug
)
175 ;; Skip the frames for backtrace-debug, byte-code,
176 ;; and implement-debug-on-entry.
177 (backtrace-debug 4 t
)
178 ;; Place an extra debug-on-exit for macro's.
179 (when (eq 'lambda
(car-safe (cadr (backtrace-frame 4))))
180 (backtrace-debug 5 t
)))
181 (pop-to-buffer debugger-buffer
)
183 (debugger-setup-buffer debugger-args
)
185 ;; If the backtrace is long, save the beginning
186 ;; and the end, but discard the middle.
187 (when (> (count-lines (point-min) (point-max))
188 debugger-batch-max-lines
)
189 (goto-char (point-min))
190 (forward-line (/ 2 debugger-batch-max-lines
))
191 (let ((middlestart (point)))
192 (goto-char (point-max))
193 (forward-line (- (/ 2 debugger-batch-max-lines
)
194 debugger-batch-max-lines
))
195 (delete-region middlestart
(point)))
197 (goto-char (point-min))
198 (message "%s" (buffer-string))
201 (let ((standard-output nil
)
202 (buffer-read-only t
))
204 ;; Make sure we unbind buffer-read-only in the right buffer.
207 ;; Kill or at least neuter the backtrace buffer, so that users
208 ;; don't try to execute debugger commands in an invalid context.
209 (if (get-buffer-window debugger-buffer
0)
210 ;; Still visible despite the save-window-excursion? Maybe it
211 ;; it's in a pop-up frame. It would be annoying to delete and
212 ;; recreate it every time the debugger stops, so instead we'll
213 ;; erase it and hide it but keep it alive.
214 (with-current-buffer debugger-buffer
217 (with-selected-window (get-buffer-window debugger-buffer
0)
219 (kill-buffer debugger-buffer
))
220 (set-match-data debugger-outer-match-data
)))
221 ;; Put into effect the modified values of these variables
222 ;; in case the user set them with the `e' command.
223 (setq load-read-function debugger-outer-load-read-function
)
224 (setq overriding-local-map debugger-outer-overriding-local-map
)
225 (setq overriding-terminal-local-map
226 debugger-outer-overriding-terminal-local-map
)
227 (setq track-mouse debugger-outer-track-mouse
)
228 (setq last-command debugger-outer-last-command
)
229 (setq this-command debugger-outer-this-command
)
231 (setq unread-command-char debugger-outer-unread-command-char
))
232 (setq unread-command-events debugger-outer-unread-command-events
)
233 (setq unread-post-input-method-events
234 debugger-outer-unread-post-input-method-events
)
235 (setq last-input-event debugger-outer-last-input-event
)
236 (setq last-command-event debugger-outer-last-command-event
)
237 (setq last-nonmenu-event debugger-outer-last-nonmenu-event
)
238 (setq last-event-frame debugger-outer-last-event-frame
)
239 (setq standard-input debugger-outer-standard-input
)
240 (setq standard-output debugger-outer-standard-output
)
241 (setq inhibit-redisplay debugger-outer-inhibit-redisplay
)
242 (setq cursor-in-echo-area debugger-outer-cursor-in-echo-area
)
243 (setq debug-on-next-call debugger-step-after-exit
)
246 (defun debugger-setup-buffer (debugger-args)
247 "Initialize the `*Backtrace*' buffer for entry to the debugger.
248 That buffer should be current already."
249 (setq buffer-read-only nil
)
251 (set-buffer-multibyte nil
)
252 (let ((standard-output (current-buffer))
253 (print-escape-newlines t
)
257 (goto-char (point-min))
258 (delete-region (point)
260 (search-forward "\n debug(")
261 (forward-line (if (eq (car debugger-args
) 'debug
)
262 2 ; Remove implement-debug-on-entry frame.
265 (insert "Debugger entered")
266 ;; lambda is for debug-on-call when a function call is next.
267 ;; debug is for debug-on-entry function called.
268 (cond ((memq (car debugger-args
) '(lambda debug
))
269 (insert "--entering a function:\n"))
270 ;; Exiting a function.
271 ((eq (car debugger-args
) 'exit
)
272 (insert "--returning value: ")
273 (setq debugger-value
(nth 1 debugger-args
))
274 (prin1 debugger-value
(current-buffer))
279 ;; Debugger entered for an error.
280 ((eq (car debugger-args
) 'error
)
281 (insert "--Lisp error: ")
282 (prin1 (nth 1 debugger-args
) (current-buffer))
284 ;; debug-on-call, when the next thing is an eval.
285 ((eq (car debugger-args
) t
)
286 (insert "--beginning evaluation of function call form:\n"))
287 ;; User calls debug directly.
290 (prin1 (if (eq (car debugger-args
) 'nil
)
291 (cdr debugger-args
) debugger-args
)
294 ;; After any frame that uses eval-buffer,
295 ;; insert a line that states the buffer position it's reading at.
297 (while (re-search-forward "^ eval-buffer(" nil t
)
299 (insert (format "\n ;;; Reading at buffer position %d"
300 (with-current-buffer (nth 2 (backtrace-frame (debugger-frame-number)))
302 (debugger-make-xrefs))
304 (defun debugger-make-xrefs (&optional buffer
)
305 "Attach cross-references to function names in the `*Backtrace*' buffer."
308 (set-buffer (or buffer
(current-buffer)))
309 (setq buffer
(current-buffer))
310 (let ((buffer-read-only nil
)
311 (old-end (point-min)) (new-end (point-min)))
312 ;; If we saved an old backtrace, find the common part
313 ;; between the new and the old.
314 ;; Compare line by line, starting from the end,
315 ;; because that's the part that is likely to be unchanged.
316 (if debugger-previous-backtrace
317 (let (old-start new-start
(all-match t
))
318 (goto-char (point-max))
320 (insert debugger-previous-backtrace
)
321 (while (and all-match
(not (bobp)))
322 (setq old-end
(point))
324 (setq old-start
(point))
325 (with-current-buffer buffer
326 (setq new-end
(point))
328 (setq new-start
(point)))
330 (compare-buffer-substrings
331 (current-buffer) old-start old-end
332 buffer new-start new-end
)))
333 (setq all-match nil
))))
334 ;; Now new-end is the position of the start of the
335 ;; unchanged part in the current buffer, and old-end is
336 ;; the position of that same text in the saved old
337 ;; backtrace. But we must subtract (point-min) since strings are
338 ;; indexed in origin 0.
340 ;; Replace the unchanged part of the backtrace
341 ;; with the text from debugger-previous-backtrace,
342 ;; since that already has the proper xrefs.
343 ;; With this optimization, we only need to scan
344 ;; the changed part of the backtrace.
345 (delete-region new-end
(point-max))
346 (goto-char (point-max))
347 (insert (substring debugger-previous-backtrace
348 (- old-end
(point-min))))
349 ;; Make the unchanged part of the backtrace inaccessible
350 ;; so it won't be scanned.
351 (narrow-to-region (point-min) new-end
)))
353 ;; Scan the new part of the backtrace, inserting xrefs.
354 (goto-char (point-min))
356 (goto-char (+ (point) 2))
357 (skip-syntax-forward "^w_")
360 (end (progn (skip-syntax-forward "w_") (point)))
361 (sym (intern-soft (buffer-substring-no-properties
363 (file (and sym
(symbol-file sym
'defun
))))
366 ;; help-xref-button needs to operate on something matched
367 ;; by a regexp, so set that up for it.
368 (re-search-forward "\\(\\sw\\|\\s_\\)+")
369 (help-xref-button 0 'help-function-def sym file
)))
372 (setq debugger-previous-backtrace
(buffer-string))))
374 (defun debugger-step-through ()
375 "Proceed, stepping through subexpressions of this expression.
376 Enter another debugger on next entry to eval, apply or funcall."
378 (setq debugger-step-after-exit t
)
379 (setq debugger-jumping-flag t
)
380 (add-hook 'post-command-hook
'debugger-reenable
)
381 (message "Proceeding, will debug on next eval or call.")
382 (exit-recursive-edit))
384 (defun debugger-continue ()
385 "Continue, evaluating this expression without stopping."
387 (unless debugger-may-continue
388 (error "Cannot continue"))
389 (message "Continuing.")
390 (exit-recursive-edit))
392 (defun debugger-return-value (val)
393 "Continue, specifying value to return.
394 This is only useful when the value returned from the debugger
395 will be used, such as in a debug on exit from a frame."
396 (interactive "XReturn value (evaluated): ")
397 (setq debugger-value val
)
398 (princ "Returning " t
)
399 (prin1 debugger-value
)
400 (exit-recursive-edit))
402 (defun debugger-jump ()
403 "Continue to exit from this frame, with all debug-on-entry suspended."
406 (setq debugger-jumping-flag t
)
407 (add-hook 'post-command-hook
'debugger-reenable
)
408 (message "Continuing through this frame")
409 (exit-recursive-edit))
411 (defun debugger-reenable ()
412 "Turn all debug-on-entry functions back on.
413 This function is put on `post-command-hook' by `debugger-jump' and
414 removes itself from that hook."
415 (setq debugger-jumping-flag nil
)
416 (remove-hook 'post-command-hook
'debugger-reenable
))
418 (defun debugger-frame-number ()
419 "Return number of frames in backtrace before the one point points at."
422 (let ((opoint (point))
424 (while (not (eq (cadr (backtrace-frame count
)) 'debug
))
425 (setq count
(1+ count
)))
426 ;; Skip implement-debug-on-entry frame.
427 (when (eq 'implement-debug-on-entry
(cadr (backtrace-frame (1+ count
))))
428 (setq count
(1+ count
)))
429 (goto-char (point-min))
430 (when (looking-at "Debugger entered--\\(Lisp error\\|returning value\\):")
431 (goto-char (match-end 0))
436 (if (= (following-char) ?\
()
441 (if (looking-at " *;;;")
443 (setq count
(1+ count
)))
446 (defun debugger-frame ()
447 "Request entry to debugger when this frame exits.
448 Applies to the frame whose line point is on in the backtrace."
452 (if (looking-at " *;;;\\|[a-z]")
453 (error "This line is not a function call")))
455 (backtrace-debug (debugger-frame-number) t
)
456 (if (= (following-char) ?
)
457 (let ((buffer-read-only nil
))
462 (defun debugger-frame-clear ()
463 "Do not enter debugger when this frame exits.
464 Applies to the frame whose line point is on in the backtrace."
468 (if (looking-at " *;;;\\|[a-z]")
469 (error "This line is not a function call")))
471 (backtrace-debug (debugger-frame-number) nil
)
472 (if (= (following-char) ?
*)
473 (let ((buffer-read-only nil
))
478 (put 'debugger-env-macro
'lisp-indent-function
0)
479 (defmacro debugger-env-macro
(&rest body
)
480 "Run BODY in original environment."
482 (if (null (buffer-name debugger-old-buffer
))
483 ;; old buffer deleted
484 (setq debugger-old-buffer
(current-buffer)))
485 (set-buffer debugger-old-buffer
)
486 (let ((load-read-function debugger-outer-load-read-function
)
487 (overriding-terminal-local-map
488 debugger-outer-overriding-terminal-local-map
)
489 (overriding-local-map debugger-outer-overriding-local-map
)
490 (track-mouse debugger-outer-track-mouse
)
491 (last-command debugger-outer-last-command
)
492 (this-command debugger-outer-this-command
)
493 (unread-command-events debugger-outer-unread-command-events
)
494 (unread-post-input-method-events
495 debugger-outer-unread-post-input-method-events
)
496 (last-input-event debugger-outer-last-input-event
)
497 (last-command-event debugger-outer-last-command-event
)
498 (last-nonmenu-event debugger-outer-last-nonmenu-event
)
499 (last-event-frame debugger-outer-last-event-frame
)
500 (standard-input debugger-outer-standard-input
)
501 (standard-output debugger-outer-standard-output
)
502 (inhibit-redisplay debugger-outer-inhibit-redisplay
)
503 (cursor-in-echo-area debugger-outer-cursor-in-echo-area
))
504 (set-match-data debugger-outer-match-data
)
506 (let ((save-ucc (with-no-warnings unread-command-char
)))
510 (setq unread-command-char debugger-outer-unread-command-char
))
511 (prog1 (progn ,@body
)
513 (setq debugger-outer-unread-command-char unread-command-char
))))
515 (setq unread-command-char save-ucc
))))
516 (setq debugger-outer-match-data
(match-data))
517 (setq debugger-outer-load-read-function load-read-function
)
518 (setq debugger-outer-overriding-terminal-local-map
519 overriding-terminal-local-map
)
520 (setq debugger-outer-overriding-local-map overriding-local-map
)
521 (setq debugger-outer-track-mouse track-mouse
)
522 (setq debugger-outer-last-command last-command
)
523 (setq debugger-outer-this-command this-command
)
524 (setq debugger-outer-unread-command-events unread-command-events
)
525 (setq debugger-outer-unread-post-input-method-events
526 unread-post-input-method-events
)
527 (setq debugger-outer-last-input-event last-input-event
)
528 (setq debugger-outer-last-command-event last-command-event
)
529 (setq debugger-outer-last-nonmenu-event last-nonmenu-event
)
530 (setq debugger-outer-last-event-frame last-event-frame
)
531 (setq debugger-outer-standard-input standard-input
)
532 (setq debugger-outer-standard-output standard-output
)
533 (setq debugger-outer-inhibit-redisplay inhibit-redisplay
)
534 (setq debugger-outer-cursor-in-echo-area cursor-in-echo-area
)
537 (defun debugger-eval-expression (exp)
538 "Eval an expression, in an environment like that outside the debugger."
540 (list (read-from-minibuffer "Eval: "
541 nil read-expression-map t
542 'read-expression-history
)))
543 (debugger-env-macro (eval-expression exp
)))
545 (defvar debugger-mode-map
546 (let ((map (make-keymap)))
547 (set-keymap-parent map button-buffer-map
)
548 (suppress-keymap map
)
549 (define-key map
"-" 'negative-argument
)
550 (define-key map
"b" 'debugger-frame
)
551 (define-key map
"c" 'debugger-continue
)
552 (define-key map
"j" 'debugger-jump
)
553 (define-key map
"r" 'debugger-return-value
)
554 (define-key map
"u" 'debugger-frame-clear
)
555 (define-key map
"d" 'debugger-step-through
)
556 (define-key map
"l" 'debugger-list-functions
)
557 (define-key map
"h" 'describe-mode
)
558 (define-key map
"q" 'top-level
)
559 (define-key map
"e" 'debugger-eval-expression
)
560 (define-key map
" " 'next-line
)
561 (define-key map
"R" 'debugger-record-expression
)
562 (define-key map
"\C-m" 'help-follow
)
563 (define-key map
[mouse-2
] 'push-button
)
566 (defcustom debugger-record-buffer
"*Debugger-record*"
567 "*Buffer name for expression values, for \\[debugger-record-expression]."
572 (defun debugger-record-expression (exp)
573 "Display a variable's value and record it in `*Backtrace-record*' buffer."
575 (list (read-from-minibuffer
578 read-expression-map t
579 'read-expression-history
)))
580 (let* ((buffer (get-buffer-create debugger-record-buffer
))
581 (standard-output buffer
))
582 (princ (format "Debugger Eval (%s): " exp
))
583 (princ (debugger-eval-expression exp
))
586 (with-current-buffer (get-buffer debugger-record-buffer
)
590 (buffer-substring (point) (progn (end-of-line) (point)))))))
592 (put 'debugger-mode
'mode-class
'special
)
594 (defun debugger-mode ()
595 "Mode for backtrace buffers, selected in debugger.
596 \\<debugger-mode-map>
597 A line starts with `*' if exiting that frame will call the debugger.
598 Type \\[debugger-frame] or \\[debugger-frame-clear] to set or remove the `*'.
600 When in debugger due to frame being exited,
601 use the \\[debugger-return-value] command to override the value
602 being returned from that frame.
604 Use \\[debug-on-entry] and \\[cancel-debug-on-entry] to control
605 which functions will enter the debugger when called.
607 Complete list of commands:
608 \\{debugger-mode-map}"
609 (kill-all-local-variables)
610 (setq major-mode
'debugger-mode
)
611 (setq mode-name
"Debugger")
612 (setq truncate-lines t
)
613 (set-syntax-table emacs-lisp-mode-syntax-table
)
614 (use-local-map debugger-mode-map
)
615 (run-mode-hooks 'debugger-mode-hook
))
617 ;; When you change this, you may also need to change the number of
618 ;; frames that the debugger skips.
619 (defun implement-debug-on-entry ()
620 "Conditionally call the debugger.
621 A call to this function is inserted by `debug-on-entry' to cause
622 functions to break on entry."
623 (if (or inhibit-debug-on-entry debugger-jumping-flag
)
625 (funcall debugger
'debug
)))
628 (defun debug-on-entry (function)
629 "Request FUNCTION to invoke debugger each time it is called.
630 If you tell the debugger to continue, FUNCTION's execution proceeds.
631 This works by modifying the definition of FUNCTION,
632 which must be written in Lisp, not predefined.
633 Use \\[cancel-debug-on-entry] to cancel the effect of this command.
634 Redefining FUNCTION also cancels it."
635 (interactive "aDebug on entry (to function): ")
636 ;; Handle a function that has been aliased to some other function.
637 (if (and (subrp (symbol-function function
))
638 (eq (cdr (subr-arity (symbol-function function
))) 'unevalled
))
639 (error "Function %s is a special form" function
))
640 (if (or (symbolp (symbol-function function
))
641 (subrp (symbol-function function
)))
642 ;; Create a wrapper in which we can then add the necessary debug call.
643 (fset function
`(lambda (&rest debug-on-entry-args
)
644 ,(interactive-form (symbol-function function
))
645 (apply ',(symbol-function function
)
646 debug-on-entry-args
))))
647 (or (consp (symbol-function function
))
648 (debug-convert-byte-code function
))
649 (or (consp (symbol-function function
))
650 (error "Definition of %s is not a list" function
))
651 (fset function
(debug-on-entry-1 function t
))
652 (or (memq function debug-function-list
)
653 (push function debug-function-list
))
657 (defun cancel-debug-on-entry (&optional function
)
658 "Undo effect of \\[debug-on-entry] on FUNCTION.
659 If argument is nil or an empty string, cancel for all functions."
662 (completing-read "Cancel debug on entry (to function): "
663 (mapcar 'symbol-name debug-function-list
)
665 (if name
(intern name
)))))
666 (if (and function
(not (string= function
"")))
668 (let ((f (debug-on-entry-1 function nil
)))
670 (if (and (equal (nth 1 f
) '(&rest debug-on-entry-args
))
671 (eq (car (nth 3 f
)) 'apply
))
672 ;; `f' is a wrapper introduced in debug-on-entry.
673 ;; Get rid of it since we don't need it any more.
674 (setq f
(nth 1 (nth 1 (nth 3 f
)))))
677 (setq debug-function-list
(delq function debug-function-list
))
679 (message "Cancelling debug-on-entry for all functions")
680 (mapcar 'cancel-debug-on-entry debug-function-list
)))
682 (defun debug-convert-byte-code (function)
683 (let ((defn (symbol-function function
)))
684 (if (not (consp defn
))
685 ;; Assume a compiled code object.
686 (let* ((contents (append defn nil
))
688 (list (list 'byte-code
(nth 1 contents
)
689 (nth 2 contents
) (nth 3 contents
)))))
690 (if (nthcdr 5 contents
)
691 (setq body
(cons (list 'interactive
(nth 5 contents
)) body
)))
693 ;; Use `documentation' here, to get the actual string,
694 ;; in case the compiled function has a reference
696 (setq body
(cons (documentation function
) body
)))
697 (fset function
(cons 'lambda
(cons (car contents
) body
)))))))
699 (defun debug-on-entry-1 (function flag
)
700 (let* ((defn (symbol-function function
))
703 (error "%s is a built-in function" function
)
704 (if (eq (car tail
) 'macro
) (setq tail
(cdr tail
)))
705 (if (eq (car tail
) 'lambda
) (setq tail
(cdr tail
))
706 (error "%s not user-defined Lisp function" function
))
707 ;; Skip the docstring.
708 (when (and (stringp (cadr tail
)) (cddr tail
))
709 (setq tail
(cdr tail
)))
710 ;; Skip the interactive form.
711 (when (eq 'interactive
(car-safe (cadr tail
)))
712 (setq tail
(cdr tail
)))
713 (unless (eq flag
(equal (cadr tail
) '(implement-debug-on-entry)))
714 ;; Add/remove debug statement as needed.
716 (setcdr tail
(cons '(implement-debug-on-entry) (cdr tail
)))
717 (setcdr tail
(cddr tail
))))
720 (defun debugger-list-functions ()
721 "Display a list of all the functions now set to debug on entry."
724 (help-setup-xref '(debugger-list-functions) (interactive-p))
725 (with-output-to-temp-buffer (help-buffer)
726 (with-current-buffer standard-output
727 (if (null debug-function-list
)
728 (princ "No debug-on-entry functions now\n")
729 (princ "Functions set to debug on entry:\n\n")
730 (dolist (fun debug-function-list
)
731 (make-text-button (point) (progn (prin1 fun
) (point))
733 'help-args
(list fun
))
736 (princ "Note: if you have redefined a function, then it may no longer\n")
737 (princ "be set to debug on entry, even if it is in the list.")))))
741 ;; arch-tag: b6ec7047-f801-4103-9c63-d69322db9d3b
742 ;;; debug.el ends here