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