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