Commit | Line | Data |
---|---|---|
c0274f38 ER |
1 | ;;; debug.el --- debuggers and related commands for Emacs |
2 | ||
14769773 | 3 | ;; Copyright (C) 1985, 1986, 1994 Free Software Foundation, Inc. |
9750e079 | 4 | |
e5167999 | 5 | ;; Maintainer: FSF |
e9571d2a | 6 | ;; Keywords: lisp, tools, maint |
e5167999 | 7 | |
0231f2dc JB |
8 | ;; This file is part of GNU Emacs. |
9 | ||
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 | |
e5167999 | 12 | ;; the Free Software Foundation; either version 2, or (at your option) |
0231f2dc JB |
13 | ;; any later version. |
14 | ||
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. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
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. | |
0231f2dc | 24 | |
e41b2db1 ER |
25 | ;;; Commentary: |
26 | ||
27 | ;; This is a major mode documented in the Emacs manual. | |
28 | ||
e5167999 | 29 | ;;; Code: |
0231f2dc JB |
30 | |
31 | (defvar debug-function-list nil | |
32 | "List of functions currently set for debug on entry.") | |
33 | ||
2eeeb0d2 RS |
34 | (defvar debugger-step-after-exit nil |
35 | "Non-nil means \"single-step\" after the debugger exits.") | |
36 | ||
37 | (defvar debugger-value nil | |
38 | "This is the value for the debugger to return, when it returns.") | |
39 | ||
40 | (defvar debugger-old-buffer nil | |
41 | "This is the buffer that was current when the debugger was entered.") | |
42 | ||
cf1c8cd9 | 43 | (defvar debugger-outer-match-data) |
80ddb8ed RS |
44 | (defvar debugger-outer-load-read-function) |
45 | (defvar debugger-outer-overriding-local-map) | |
29e2b496 | 46 | (defvar debugger-outer-overriding-terminal-local-map) |
35cf010d RS |
47 | (defvar debugger-outer-track-mouse) |
48 | (defvar debugger-outer-last-command) | |
49 | (defvar debugger-outer-this-command) | |
50 | (defvar debugger-outer-unread-command-char) | |
51 | (defvar debugger-outer-unread-command-events) | |
52 | (defvar debugger-outer-last-input-event) | |
53 | (defvar debugger-outer-last-command-event) | |
54 | (defvar debugger-outer-last-nonmenu-event) | |
55 | (defvar debugger-outer-last-event-frame) | |
56 | (defvar debugger-outer-standard-input) | |
57 | (defvar debugger-outer-standard-output) | |
58 | (defvar debugger-outer-cursor-in-echo-area) | |
59 | ||
0231f2dc JB |
60 | ;;;###autoload |
61 | (setq debugger 'debug) | |
62 | ;;;###autoload | |
63 | (defun debug (&rest debugger-args) | |
2512acba | 64 | "Enter debugger. To return, type \\<debugger-mode-map>`\\[debugger-continue]'. |
0231f2dc JB |
65 | Arguments are mainly for use when this is called from the internals |
66 | of the evaluator. | |
67 | ||
68 | You may call with no args, or you may pass nil as the first arg and | |
69 | any other args you like. In that case, the list of args after the | |
70 | first will be printed into the backtrace buffer." | |
73e78cf1 | 71 | (interactive) |
0231f2dc JB |
72 | (message "Entering debugger...") |
73 | (let (debugger-value | |
0231f2dc JB |
74 | (debug-on-error nil) |
75 | (debug-on-quit nil) | |
76 | (debugger-buffer (let ((default-major-mode 'fundamental-mode)) | |
36363ac1 | 77 | (get-buffer-create "*Backtrace*"))) |
0231f2dc JB |
78 | (debugger-old-buffer (current-buffer)) |
79 | (debugger-step-after-exit nil) | |
80 | ;; Don't keep reading from an executing kbd macro! | |
efcf38c7 | 81 | (executing-kbd-macro nil) |
35cf010d RS |
82 | ;; Save the outer values of these vars for the `e' command |
83 | ;; before we replace the values. | |
cf1c8cd9 | 84 | (debugger-outer-match-data (match-data)) |
80ddb8ed RS |
85 | (debugger-outer-load-read-function load-read-function) |
86 | (debugger-outer-overriding-local-map overriding-local-map) | |
29e2b496 RS |
87 | (debugger-outer-overriding-terminal-local-map |
88 | overriding-terminal-local-map) | |
35cf010d RS |
89 | (debugger-outer-track-mouse track-mouse) |
90 | (debugger-outer-last-command last-command) | |
91 | (debugger-outer-this-command this-command) | |
92 | (debugger-outer-unread-command-char unread-command-char) | |
93 | (debugger-outer-unread-command-events unread-command-events) | |
94 | (debugger-outer-last-input-event last-input-event) | |
95 | (debugger-outer-last-command-event last-command-event) | |
96 | (debugger-outer-last-nonmenu-event last-nonmenu-event) | |
97 | (debugger-outer-last-event-frame last-event-frame) | |
98 | (debugger-outer-standard-input standard-input) | |
99 | (debugger-outer-standard-output standard-output) | |
100 | (debugger-outer-cursor-in-echo-area cursor-in-echo-area)) | |
101 | ;; Don't let these magic variables affect the debugger itself. | |
102 | (let ((last-command nil) this-command track-mouse | |
b2ecc630 | 103 | (unread-command-char -1) unread-command-events |
35cf010d RS |
104 | last-input-event last-command-event last-nonmenu-event |
105 | last-event-frame | |
80ddb8ed | 106 | overriding-local-map |
29e2b496 | 107 | overriding-terminal-local-map |
80ddb8ed | 108 | load-read-function |
35cf010d RS |
109 | (standard-input t) (standard-output t) |
110 | (cursor-in-echo-area nil)) | |
111 | (unwind-protect | |
112 | (save-excursion | |
113 | (save-window-excursion | |
114 | (pop-to-buffer debugger-buffer) | |
115 | (erase-buffer) | |
116 | (let ((standard-output (current-buffer)) | |
117 | (print-escape-newlines t) | |
118 | (print-length 50)) | |
119 | (backtrace)) | |
120 | (goto-char (point-min)) | |
121 | (debugger-mode) | |
122 | (delete-region (point) | |
123 | (progn | |
124 | (search-forward "\n debug(") | |
125 | (forward-line 1) | |
126 | (point))) | |
127 | (debugger-reenable) | |
f4249c6f RS |
128 | ;; lambda is for debug-on-call when a function call is next. |
129 | ;; debug is for debug-on-entry function called. | |
35cf010d RS |
130 | (cond ((memq (car debugger-args) '(lambda debug)) |
131 | (insert "Entering:\n") | |
132 | (if (eq (car debugger-args) 'debug) | |
133 | (progn | |
f4249c6f RS |
134 | ;; Skip the frames for backtrace-debug, byte-code, |
135 | ;; and debug. | |
136 | (backtrace-debug 3 t) | |
35cf010d RS |
137 | (delete-char 1) |
138 | (insert ?*) | |
139 | (beginning-of-line)))) | |
f4249c6f | 140 | ;; Exiting a function. |
35cf010d RS |
141 | ((eq (car debugger-args) 'exit) |
142 | (insert "Return value: ") | |
143 | (setq debugger-value (nth 1 debugger-args)) | |
144 | (prin1 debugger-value (current-buffer)) | |
145 | (insert ?\n) | |
146 | (delete-char 1) | |
147 | (insert ? ) | |
148 | (beginning-of-line)) | |
f4249c6f | 149 | ;; Debugger entered for an error. |
35cf010d | 150 | ((eq (car debugger-args) 'error) |
3aa2f02e | 151 | (insert "Signaling: ") |
35cf010d RS |
152 | (prin1 (nth 1 debugger-args) (current-buffer)) |
153 | (insert ?\n)) | |
f4249c6f | 154 | ;; debug-on-call, when the next thing is an eval. |
35cf010d RS |
155 | ((eq (car debugger-args) t) |
156 | (insert "Beginning evaluation of function call form:\n")) | |
f4249c6f | 157 | ;; User calls debug directly. |
35cf010d RS |
158 | (t |
159 | (prin1 (if (eq (car debugger-args) 'nil) | |
160 | (cdr debugger-args) debugger-args) | |
161 | (current-buffer)) | |
162 | (insert ?\n))) | |
0231f2dc | 163 | (message "") |
35cf010d RS |
164 | (let ((inhibit-trace t) |
165 | (standard-output nil) | |
166 | (buffer-read-only t)) | |
167 | (message "") | |
614710af RS |
168 | ;; Make sure we unbind buffer-read-only in the right buffer. |
169 | (save-excursion | |
170 | (recursive-edit))))) | |
36363ac1 KH |
171 | ;; Kill or at least neuter the backtrace buffer, so that users |
172 | ;; don't try to execute debugger commands in an invalid context. | |
173 | (if (get-buffer-window debugger-buffer 'visible) | |
174 | ;; Still visible despite the save-window-excursion? Maybe it | |
175 | ;; it's in a pop-up frame. It would be annoying to delete and | |
176 | ;; recreate it every time the debugger stops, so instead we'll | |
177 | ;; erase it but leave it visible. | |
178 | (save-excursion | |
179 | (set-buffer debugger-buffer) | |
180 | (erase-buffer) | |
181 | (fundamental-mode)) | |
182 | (kill-buffer debugger-buffer)) | |
cf1c8cd9 | 183 | (store-match-data debugger-outer-match-data))) |
35cf010d RS |
184 | ;; Put into effect the modified values of these variables |
185 | ;; in case the user set them with the `e' command. | |
80ddb8ed RS |
186 | (setq load-read-function debugger-outer-load-read-function) |
187 | (setq overriding-local-map debugger-outer-overriding-local-map) | |
29e2b496 RS |
188 | (setq overriding-terminal-local-map |
189 | debugger-outer-overriding-terminal-local-map) | |
35cf010d RS |
190 | (setq track-mouse debugger-outer-track-mouse) |
191 | (setq last-command debugger-outer-last-command) | |
192 | (setq this-command debugger-outer-this-command) | |
193 | (setq unread-command-char debugger-outer-unread-command-char) | |
194 | (setq unread-command-events debugger-outer-unread-command-events) | |
195 | (setq last-input-event debugger-outer-last-input-event) | |
196 | (setq last-command-event debugger-outer-last-command-event) | |
197 | (setq last-nonmenu-event debugger-outer-last-nonmenu-event) | |
198 | (setq last-event-frame debugger-outer-last-event-frame) | |
199 | (setq standard-input debugger-outer-standard-input) | |
200 | (setq standard-output debugger-outer-standard-output) | |
14769773 | 201 | (setq cursor-in-echo-area debugger-outer-cursor-in-echo-area) |
0231f2dc JB |
202 | (setq debug-on-next-call debugger-step-after-exit) |
203 | debugger-value)) | |
204 | \f | |
205 | (defun debugger-step-through () | |
206 | "Proceed, stepping through subexpressions of this expression. | |
207 | Enter another debugger on next entry to eval, apply or funcall." | |
208 | (interactive) | |
209 | (setq debugger-step-after-exit t) | |
210 | (message "Proceeding, will debug on next eval or call.") | |
211 | (exit-recursive-edit)) | |
212 | ||
213 | (defun debugger-continue () | |
214 | "Continue, evaluating this expression without stopping." | |
215 | (interactive) | |
216 | (message "Continuing.") | |
217 | (exit-recursive-edit)) | |
218 | ||
219 | (defun debugger-return-value (val) | |
220 | "Continue, specifying value to return. | |
221 | This is only useful when the value returned from the debugger | |
222 | will be used, such as in a debug on exit from a frame." | |
223 | (interactive "XReturn value (evaluated): ") | |
224 | (setq debugger-value val) | |
225 | (princ "Returning " t) | |
226 | (prin1 debugger-value) | |
227 | (exit-recursive-edit)) | |
228 | ||
229 | (defun debugger-jump () | |
230 | "Continue to exit from this frame, with all debug-on-entry suspended." | |
231 | (interactive) | |
232 | ;; Compensate for the two extra stack frames for debugger-jump. | |
233 | (let ((debugger-frame-offset (+ debugger-frame-offset 2))) | |
234 | (debugger-frame)) | |
235 | ;; Turn off all debug-on-entry functions | |
236 | ;; but leave them in the list. | |
237 | (let ((list debug-function-list)) | |
238 | (while list | |
239 | (fset (car list) | |
240 | (debug-on-entry-1 (car list) (symbol-function (car list)) nil)) | |
241 | (setq list (cdr list)))) | |
242 | (message "Continuing through this frame") | |
243 | (exit-recursive-edit)) | |
244 | ||
245 | (defun debugger-reenable () | |
246 | "Turn all debug-on-entry functions back on." | |
247 | (let ((list debug-function-list)) | |
248 | (while list | |
249 | (or (consp (symbol-function (car list))) | |
250 | (debug-convert-byte-code (car list))) | |
251 | (fset (car list) | |
252 | (debug-on-entry-1 (car list) (symbol-function (car list)) t)) | |
253 | (setq list (cdr list))))) | |
254 | ||
255 | (defun debugger-frame-number () | |
256 | "Return number of frames in backtrace before the one point points at." | |
257 | (save-excursion | |
258 | (beginning-of-line) | |
259 | (let ((opoint (point)) | |
260 | (count 0)) | |
261 | (goto-char (point-min)) | |
262 | (if (or (equal (buffer-substring (point) (+ (point) 6)) | |
263 | "Signal") | |
264 | (equal (buffer-substring (point) (+ (point) 6)) | |
265 | "Return")) | |
266 | (progn | |
267 | (search-forward ":") | |
268 | (forward-sexp 1))) | |
269 | (forward-line 1) | |
270 | (while (progn | |
271 | (forward-char 2) | |
272 | (if (= (following-char) ?\() | |
273 | (forward-sexp 1) | |
274 | (forward-sexp 2)) | |
275 | (forward-line 1) | |
276 | (<= (point) opoint)) | |
277 | (setq count (1+ count))) | |
278 | count))) | |
279 | ||
280 | ;; Chosen empirically to account for all the frames | |
281 | ;; that will exist when debugger-frame is called | |
282 | ;; within the first one that appears in the backtrace buffer. | |
283 | ;; Assumes debugger-frame is called from a key; | |
284 | ;; will be wrong if it is called with Meta-x. | |
285 | (defconst debugger-frame-offset 8 "") | |
286 | ||
287 | (defun debugger-frame () | |
288 | "Request entry to debugger when this frame exits. | |
289 | Applies to the frame whose line point is on in the backtrace." | |
290 | (interactive) | |
291 | (beginning-of-line) | |
292 | (let ((level (debugger-frame-number))) | |
293 | (backtrace-debug (+ level debugger-frame-offset) t)) | |
294 | (if (= (following-char) ? ) | |
295 | (let ((buffer-read-only nil)) | |
296 | (delete-char 1) | |
297 | (insert ?*))) | |
298 | (beginning-of-line)) | |
299 | ||
300 | (defun debugger-frame-clear () | |
301 | "Do not enter to debugger when this frame exits. | |
302 | Applies to the frame whose line point is on in the backtrace." | |
303 | (interactive) | |
304 | (beginning-of-line) | |
305 | (let ((level (debugger-frame-number))) | |
306 | (backtrace-debug (+ level debugger-frame-offset) nil)) | |
307 | (if (= (following-char) ?*) | |
308 | (let ((buffer-read-only nil)) | |
309 | (delete-char 1) | |
310 | (insert ? ))) | |
311 | (beginning-of-line)) | |
312 | ||
313 | (defun debugger-eval-expression (exp) | |
8782c06b RS |
314 | "Eval an expression, in an environment like that outside the debugger." |
315 | (interactive | |
316 | (list (read-from-minibuffer "Eval: " | |
317 | nil read-expression-map t | |
318 | 'read-expression-history))) | |
0231f2dc JB |
319 | (save-excursion |
320 | (if (null (buffer-name debugger-old-buffer)) | |
321 | ;; old buffer deleted | |
322 | (setq debugger-old-buffer (current-buffer))) | |
323 | (set-buffer debugger-old-buffer) | |
35cf010d RS |
324 | (let ((track-mouse debugger-outer-track-mouse) |
325 | (last-command debugger-outer-last-command) | |
326 | (this-command debugger-outer-this-command) | |
327 | (unread-command-char debugger-outer-unread-command-char) | |
328 | (unread-command-events debugger-outer-unread-command-events) | |
329 | (last-input-event debugger-outer-last-input-event) | |
330 | (last-command-event debugger-outer-last-command-event) | |
331 | (last-nonmenu-event debugger-outer-last-nonmenu-event) | |
332 | (last-event-frame debugger-outer-last-event-frame) | |
333 | (standard-input debugger-outer-standard-input) | |
334 | (standard-output debugger-outer-standard-output) | |
80ddb8ed RS |
335 | (cursor-in-echo-area debugger-outer-cursor-in-echo-area) |
336 | (overriding-local-map debugger-outer-overriding-local-map) | |
29e2b496 RS |
337 | (overriding-terminal-local-map |
338 | debugger-outer-overriding-terminal-local-map) | |
80ddb8ed | 339 | (load-read-function debugger-outer-load-read-function)) |
cf1c8cd9 | 340 | (store-match-data debugger-outer-match-data) |
35cf010d | 341 | (prog1 (eval-expression exp) |
cf1c8cd9 | 342 | (setq debugger-outer-match-data (match-data)) |
80ddb8ed RS |
343 | (setq debugger-outer-load-read-function load-read-function) |
344 | (setq debugger-outer-overriding-local-map overriding-local-map) | |
29e2b496 RS |
345 | (setq debugger-outer-overriding-terminal-local-map |
346 | overriding-terminal-local-map) | |
35cf010d RS |
347 | (setq debugger-outer-track-mouse track-mouse) |
348 | (setq debugger-outer-last-command last-command) | |
349 | (setq debugger-outer-this-command this-command) | |
350 | (setq debugger-outer-unread-command-char unread-command-char) | |
351 | (setq debugger-outer-unread-command-events unread-command-events) | |
352 | (setq debugger-outer-last-input-event last-input-event) | |
353 | (setq debugger-outer-last-command-event last-command-event) | |
354 | (setq debugger-outer-last-nonmenu-event last-nonmenu-event) | |
355 | (setq debugger-outer-last-event-frame last-event-frame) | |
356 | (setq debugger-outer-standard-input standard-input) | |
357 | (setq debugger-outer-standard-output standard-output) | |
358 | (setq debugger-outer-cursor-in-echo-area cursor-in-echo-area))))) | |
0231f2dc JB |
359 | \f |
360 | (defvar debugger-mode-map nil) | |
361 | (if debugger-mode-map | |
362 | nil | |
363 | (let ((loop ? )) | |
364 | (setq debugger-mode-map (make-keymap)) | |
365 | (suppress-keymap debugger-mode-map) | |
366 | (define-key debugger-mode-map "-" 'negative-argument) | |
367 | (define-key debugger-mode-map "b" 'debugger-frame) | |
368 | (define-key debugger-mode-map "c" 'debugger-continue) | |
369 | (define-key debugger-mode-map "j" 'debugger-jump) | |
370 | (define-key debugger-mode-map "r" 'debugger-return-value) | |
371 | (define-key debugger-mode-map "u" 'debugger-frame-clear) | |
372 | (define-key debugger-mode-map "d" 'debugger-step-through) | |
373 | (define-key debugger-mode-map "l" 'debugger-list-functions) | |
374 | (define-key debugger-mode-map "h" 'describe-mode) | |
375 | (define-key debugger-mode-map "q" 'top-level) | |
376 | (define-key debugger-mode-map "e" 'debugger-eval-expression) | |
377 | (define-key debugger-mode-map " " 'next-line))) | |
378 | ||
379 | (put 'debugger-mode 'mode-class 'special) | |
380 | ||
381 | (defun debugger-mode () | |
382 | "Mode for backtrace buffers, selected in debugger. | |
383 | \\<debugger-mode-map> | |
384 | A line starts with `*' if exiting that frame will call the debugger. | |
385 | Type \\[debugger-frame] or \\[debugger-frame-clear] to set or remove the `*'. | |
386 | ||
387 | When in debugger due to frame being exited, | |
388 | use the \\[debugger-return-value] command to override the value | |
389 | being returned from that frame. | |
390 | ||
391 | Use \\[debug-on-entry] and \\[cancel-debug-on-entry] to control | |
392 | which functions will enter the debugger when called. | |
393 | ||
394 | Complete list of commands: | |
395 | \\{debugger-mode-map}" | |
396 | (kill-all-local-variables) | |
397 | (setq major-mode 'debugger-mode) | |
398 | (setq mode-name "Debugger") | |
399 | (setq truncate-lines t) | |
400 | (set-syntax-table emacs-lisp-mode-syntax-table) | |
9a06295d KH |
401 | ;; Since we must handle bytecode... |
402 | (setq enable-multibyte-characters nil) | |
0231f2dc JB |
403 | (use-local-map debugger-mode-map)) |
404 | \f | |
405 | ;;;###autoload | |
406 | (defun debug-on-entry (function) | |
407 | "Request FUNCTION to invoke debugger each time it is called. | |
2512acba RS |
408 | If you tell the debugger to continue, FUNCTION's execution proceeds. |
409 | This works by modifying the definition of FUNCTION, | |
0231f2dc JB |
410 | which must be written in Lisp, not predefined. |
411 | Use \\[cancel-debug-on-entry] to cancel the effect of this command. | |
2512acba | 412 | Redefining FUNCTION also cancels it." |
0231f2dc JB |
413 | (interactive "aDebug on entry (to function): ") |
414 | (debugger-reenable) | |
415 | (if (subrp (symbol-function function)) | |
416 | (error "Function %s is a primitive" function)) | |
417 | (or (consp (symbol-function function)) | |
418 | (debug-convert-byte-code function)) | |
419 | (or (consp (symbol-function function)) | |
420 | (error "Definition of %s is not a list" function)) | |
421 | (fset function (debug-on-entry-1 function (symbol-function function) t)) | |
422 | (or (memq function debug-function-list) | |
423 | (setq debug-function-list (cons function debug-function-list))) | |
424 | function) | |
425 | ||
426 | ;;;###autoload | |
427 | (defun cancel-debug-on-entry (&optional function) | |
428 | "Undo effect of \\[debug-on-entry] on FUNCTION. | |
429 | If argument is nil or an empty string, cancel for all functions." | |
10a4c11f JB |
430 | (interactive |
431 | (list (let ((name | |
432 | (completing-read "Cancel debug on entry (to function): " | |
433 | ;; Make an "alist" of the functions | |
434 | ;; that now have debug on entry. | |
435 | (mapcar 'list | |
436 | (mapcar 'symbol-name | |
437 | debug-function-list)) | |
438 | nil t nil))) | |
439 | (if name (intern name))))) | |
0231f2dc JB |
440 | (debugger-reenable) |
441 | (if (and function (not (string= function ""))) | |
442 | (progn | |
443 | (fset function | |
444 | (debug-on-entry-1 function (symbol-function function) nil)) | |
445 | (setq debug-function-list (delq function debug-function-list)) | |
446 | function) | |
447 | (message "Cancelling debug-on-entry for all functions") | |
448 | (mapcar 'cancel-debug-on-entry debug-function-list))) | |
449 | ||
450 | (defun debug-convert-byte-code (function) | |
451 | (let ((defn (symbol-function function))) | |
452 | (if (not (consp defn)) | |
453 | ;; Assume a compiled code object. | |
454 | (let* ((contents (append defn nil)) | |
455 | (body | |
456 | (list (list 'byte-code (nth 1 contents) | |
457 | (nth 2 contents) (nth 3 contents))))) | |
458 | (if (nthcdr 5 contents) | |
459 | (setq body (cons (list 'interactive (nth 5 contents)) body))) | |
460 | (if (nth 4 contents) | |
c8c76dd3 RS |
461 | ;; Use `documentation' here, to get the actual string, |
462 | ;; in case the compiled function has a reference | |
463 | ;; to the .elc file. | |
464 | (setq body (cons (documentation function) body))) | |
0231f2dc JB |
465 | (fset function (cons 'lambda (cons (car contents) body))))))) |
466 | ||
467 | (defun debug-on-entry-1 (function defn flag) | |
468 | (if (subrp defn) | |
469 | (error "%s is a built-in function" function) | |
470 | (if (eq (car defn) 'macro) | |
471 | (debug-on-entry-1 function (cdr defn) flag) | |
472 | (or (eq (car defn) 'lambda) | |
473 | (error "%s not user-defined Lisp function" function)) | |
474 | (let (tail prec) | |
475 | (if (stringp (car (nthcdr 2 defn))) | |
476 | (setq tail (nthcdr 3 defn) | |
477 | prec (list (car defn) (car (cdr defn)) | |
478 | (car (cdr (cdr defn))))) | |
479 | (setq tail (nthcdr 2 defn) | |
480 | prec (list (car defn) (car (cdr defn))))) | |
481 | (if (eq flag (equal (car tail) '(debug 'debug))) | |
482 | defn | |
483 | (if flag | |
484 | (nconc prec (cons '(debug 'debug) tail)) | |
485 | (nconc prec (cdr tail)))))))) | |
486 | ||
487 | (defun debugger-list-functions () | |
488 | "Display a list of all the functions now set to debug on entry." | |
489 | (interactive) | |
490 | (with-output-to-temp-buffer "*Help*" | |
491 | (if (null debug-function-list) | |
492 | (princ "No debug-on-entry functions now\n") | |
493 | (princ "Functions set to debug on entry:\n\n") | |
494 | (let ((list debug-function-list)) | |
495 | (while list | |
496 | (prin1 (car list)) | |
497 | (terpri) | |
498 | (setq list (cdr list)))) | |
499 | (princ "Note: if you have redefined a function, then it may no longer\n") | |
89961ff8 KH |
500 | (princ "be set to debug on entry, even if it is in the list.")) |
501 | (save-excursion | |
502 | (set-buffer standard-output) | |
503 | (help-mode)))) | |
c0274f38 ER |
504 | |
505 | ;;; debug.el ends here |