Mercurial > emacs
annotate lisp/emacs-lisp/debug.el @ 25325:fbe05e67b94d
Check for termcap.h.
author | Dave Love <fx@gnu.org> |
---|---|
date | Wed, 18 Aug 1999 13:22:47 +0000 |
parents | 00ef85c8a0ff |
children | 8523249aaee3 |
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 | |
14169 | 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. | |
473 | 24 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
25 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
26 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
27 ;; 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
|
28 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
29 ;;; Code: |
473 | 30 |
21365 | 31 (defgroup debugger nil |
32 "Debuggers and related commands for Emacs." | |
33 :prefix "debugger-" | |
34 :group 'debug) | |
35 | |
36 (defcustom debugger-mode-hook nil | |
37 "*Hooks run when `debugger-mode' is turned on." | |
38 :type 'hook | |
21669
9861518505cb
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21365
diff
changeset
|
39 :group 'debugger |
9861518505cb
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21365
diff
changeset
|
40 :version "20.3") |
20403
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
41 |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
42 |
21365 | 43 (defcustom debug-function-list nil |
44 "List of functions currently set for debug on entry." | |
45 :type '(repeat function) | |
46 :group 'debugger) | |
473 | 47 |
21365 | 48 (defcustom debugger-step-after-exit nil |
49 "Non-nil means \"single-step\" after the debugger exits." | |
50 :type 'boolean | |
51 :group 'debugger) | |
10731
65e10f44e765
(debugger-step-after-exit): Variable declared.
Richard M. Stallman <rms@gnu.org>
parents:
10728
diff
changeset
|
52 |
65e10f44e765
(debugger-step-after-exit): Variable declared.
Richard M. Stallman <rms@gnu.org>
parents:
10728
diff
changeset
|
53 (defvar debugger-value nil |
65e10f44e765
(debugger-step-after-exit): Variable declared.
Richard M. Stallman <rms@gnu.org>
parents:
10728
diff
changeset
|
54 "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
|
55 |
65e10f44e765
(debugger-step-after-exit): Variable declared.
Richard M. Stallman <rms@gnu.org>
parents:
10728
diff
changeset
|
56 (defvar debugger-old-buffer nil |
65e10f44e765
(debugger-step-after-exit): Variable declared.
Richard M. Stallman <rms@gnu.org>
parents:
10728
diff
changeset
|
57 "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
|
58 |
6926
027b7de8a571
(debug, debugger-eval-expression): Preserve match-data.
Karl Heuer <kwzh@gnu.org>
parents:
6567
diff
changeset
|
59 (defvar debugger-outer-match-data) |
11062
302f676eeca0
(debugger-outer-load-read-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10731
diff
changeset
|
60 (defvar debugger-outer-load-read-function) |
302f676eeca0
(debugger-outer-load-read-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10731
diff
changeset
|
61 (defvar debugger-outer-overriding-local-map) |
18166
84c0a412aa71
(debug, debugger-eval-expression):
Richard M. Stallman <rms@gnu.org>
parents:
17262
diff
changeset
|
62 (defvar debugger-outer-overriding-terminal-local-map) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
63 (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
|
64 (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
|
65 (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
|
66 (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
|
67 (defvar debugger-outer-unread-command-events) |
22921
48b85e4a4dd3
(debugger-outer-unread-post-input-method-events): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22114
diff
changeset
|
68 (defvar debugger-outer-unread-post-input-method-events) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
69 (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
|
70 (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
|
71 (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
|
72 (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
|
73 (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
|
74 (defvar debugger-outer-standard-output) |
24741
00ef85c8a0ff
(debugger-outer-inhibit-redisplay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24524
diff
changeset
|
75 (defvar debugger-outer-inhibit-redisplay) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
76 (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
|
77 |
473 | 78 ;;;###autoload |
79 (setq debugger 'debug) | |
80 ;;;###autoload | |
81 (defun debug (&rest debugger-args) | |
6048
ff40882c5578
(debug, debug-on-entry): Doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
5585
diff
changeset
|
82 "Enter debugger. To return, type \\<debugger-mode-map>`\\[debugger-continue]'. |
473 | 83 Arguments are mainly for use when this is called from the internals |
84 of the evaluator. | |
85 | |
86 You may call with no args, or you may pass nil as the first arg and | |
87 any other args you like. In that case, the list of args after the | |
88 first will be printed into the backtrace buffer." | |
11069
ee94cf4fd05a
(debug): Now interactive.
Richard M. Stallman <rms@gnu.org>
parents:
11062
diff
changeset
|
89 (interactive) |
473 | 90 (message "Entering debugger...") |
91 (let (debugger-value | |
92 (debug-on-error nil) | |
93 (debug-on-quit nil) | |
94 (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
|
95 (get-buffer-create "*Backtrace*"))) |
473 | 96 (debugger-old-buffer (current-buffer)) |
97 (debugger-step-after-exit nil) | |
98 ;; Don't keep reading from an executing kbd macro! | |
15302
c23c9712ef5c
Use executing-kbd-macro, not executing-macro.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
99 (executing-kbd-macro nil) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
100 ;; 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
|
101 ;; before we replace the values. |
6926
027b7de8a571
(debug, debugger-eval-expression): Preserve match-data.
Karl Heuer <kwzh@gnu.org>
parents:
6567
diff
changeset
|
102 (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
|
103 (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
|
104 (debugger-outer-overriding-local-map overriding-local-map) |
18166
84c0a412aa71
(debug, debugger-eval-expression):
Richard M. Stallman <rms@gnu.org>
parents:
17262
diff
changeset
|
105 (debugger-outer-overriding-terminal-local-map |
84c0a412aa71
(debug, debugger-eval-expression):
Richard M. Stallman <rms@gnu.org>
parents:
17262
diff
changeset
|
106 overriding-terminal-local-map) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
107 (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
|
108 (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
|
109 (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
|
110 (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
|
111 (debugger-outer-unread-command-events unread-command-events) |
22921
48b85e4a4dd3
(debugger-outer-unread-post-input-method-events): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22114
diff
changeset
|
112 (debugger-outer-unread-post-input-method-events |
48b85e4a4dd3
(debugger-outer-unread-post-input-method-events): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22114
diff
changeset
|
113 unread-post-input-method-events) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
114 (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
|
115 (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
|
116 (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
|
117 (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
|
118 (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
|
119 (debugger-outer-standard-output standard-output) |
24741
00ef85c8a0ff
(debugger-outer-inhibit-redisplay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24524
diff
changeset
|
120 (debugger-outer-inhibit-redisplay inhibit-redisplay) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
121 (debugger-outer-cursor-in-echo-area cursor-in-echo-area)) |
18190
bca8e581535a
(debug): Set overriding-terminal-local-map to nil,
Richard M. Stallman <rms@gnu.org>
parents:
18166
diff
changeset
|
122 ;; Set this instead of binding it, so that `q' |
bca8e581535a
(debug): Set overriding-terminal-local-map to nil,
Richard M. Stallman <rms@gnu.org>
parents:
18166
diff
changeset
|
123 ;; will not restore it. |
bca8e581535a
(debug): Set overriding-terminal-local-map to nil,
Richard M. Stallman <rms@gnu.org>
parents:
18166
diff
changeset
|
124 (setq overriding-terminal-local-map nil) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
125 ;; 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
|
126 (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
|
127 (unread-command-char -1) unread-command-events |
22921
48b85e4a4dd3
(debugger-outer-unread-post-input-method-events): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22114
diff
changeset
|
128 unread-post-input-method-events |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
129 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
|
130 last-event-frame |
11062
302f676eeca0
(debugger-outer-load-read-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10731
diff
changeset
|
131 overriding-local-map |
302f676eeca0
(debugger-outer-load-read-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
10731
diff
changeset
|
132 load-read-function |
19889
3e6802bae367
(debug): Allow recursive minibuffers if we're in a minibuffer already.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
133 ;; If we are inside a minibuffer, allow nesting |
3e6802bae367
(debug): Allow recursive minibuffers if we're in a minibuffer already.
Richard M. Stallman <rms@gnu.org>
parents:
18383
diff
changeset
|
134 ;; so that we don't get an error from the `e' command. |
23988
571d2c4f3edf
(debug): Leave recursive minibuffer enabled
Andreas Schwab <schwab@suse.de>
parents:
22921
diff
changeset
|
135 (enable-recursive-minibuffers |
571d2c4f3edf
(debug): Leave recursive minibuffer enabled
Andreas Schwab <schwab@suse.de>
parents:
22921
diff
changeset
|
136 (or enable-recursive-minibuffers (> (minibuffer-depth) 0))) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
137 (standard-input t) (standard-output t) |
24741
00ef85c8a0ff
(debugger-outer-inhibit-redisplay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24524
diff
changeset
|
138 inhibit-redisplay |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
139 (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
|
140 (unwind-protect |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
141 (save-excursion |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
142 (save-window-excursion |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
143 (pop-to-buffer debugger-buffer) |
24524
d46353824322
(debug): Make *Backtrace* buffer writable.
Andreas Schwab <schwab@suse.de>
parents:
23988
diff
changeset
|
144 (setq buffer-read-only nil) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
145 (erase-buffer) |
20885
9bd868e76aa5
(debugger-mode): Don't set enable-multibyte-characters here.
Richard M. Stallman <rms@gnu.org>
parents:
20404
diff
changeset
|
146 (set-buffer-multibyte nil) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
147 (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
|
148 (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
|
149 (print-length 50)) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
150 (backtrace)) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
151 (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
|
152 (debugger-mode) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
153 (delete-region (point) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
154 (progn |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
155 (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
|
156 (forward-line 1) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
157 (point))) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
158 (debugger-reenable) |
10728
48f895a471a2
(debug): Fix arg to backtrace-debug for debug-on-entry.
Richard M. Stallman <rms@gnu.org>
parents:
10571
diff
changeset
|
159 ;; 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
|
160 ;; 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
|
161 (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
|
162 (insert "Entering:\n") |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
163 (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
|
164 (progn |
10728
48f895a471a2
(debug): Fix arg to backtrace-debug for debug-on-entry.
Richard M. Stallman <rms@gnu.org>
parents:
10571
diff
changeset
|
165 ;; 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
|
166 ;; and debug. |
48f895a471a2
(debug): Fix arg to backtrace-debug for debug-on-entry.
Richard M. Stallman <rms@gnu.org>
parents:
10571
diff
changeset
|
167 (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
|
168 (delete-char 1) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
169 (insert ?*) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
170 (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
|
171 ;; 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
|
172 ((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
|
173 (insert "Return value: ") |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
174 (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
|
175 (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
|
176 (insert ?\n) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
177 (delete-char 1) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
178 (insert ? ) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
179 (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
|
180 ;; 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
|
181 ((eq (car debugger-args) 'error) |
13955 | 182 (insert "Signaling: ") |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
183 (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
|
184 (insert ?\n)) |
10728
48f895a471a2
(debug): Fix arg to backtrace-debug for debug-on-entry.
Richard M. Stallman <rms@gnu.org>
parents:
10571
diff
changeset
|
185 ;; 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
|
186 ((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
|
187 (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
|
188 ;; 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
|
189 (t |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
190 (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
|
191 (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
|
192 (current-buffer)) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
193 (insert ?\n))) |
473 | 194 (message "") |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
195 (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
|
196 (standard-output nil) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
197 (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
|
198 (message "") |
17262
76bfab081263
(debug): Use save-excursion inside the binding of buffer-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
17003
diff
changeset
|
199 ;; Make sure we unbind buffer-read-only in the right buffer. |
76bfab081263
(debug): Use save-excursion inside the binding of buffer-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
17003
diff
changeset
|
200 (save-excursion |
76bfab081263
(debug): Use save-excursion inside the binding of buffer-read-only.
Richard M. Stallman <rms@gnu.org>
parents:
17003
diff
changeset
|
201 (recursive-edit))))) |
6567
baf8fe0c51e3
(debug): Behave sensibly if pop-up-frames is set.
Karl Heuer <kwzh@gnu.org>
parents:
6468
diff
changeset
|
202 ;; 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
|
203 ;; 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
|
204 (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
|
205 ;; 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
|
206 ;; 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
|
207 ;; 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
|
208 ;; 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
|
209 (save-excursion |
baf8fe0c51e3
(debug): Behave sensibly if pop-up-frames is set.
Karl Heuer <kwzh@gnu.org>
parents:
6468
diff
changeset
|
210 (set-buffer debugger-buffer) |
baf8fe0c51e3
(debug): Behave sensibly if pop-up-frames is set.
Karl Heuer <kwzh@gnu.org>
parents:
6468
diff
changeset
|
211 (erase-buffer) |
baf8fe0c51e3
(debug): Behave sensibly if pop-up-frames is set.
Karl Heuer <kwzh@gnu.org>
parents:
6468
diff
changeset
|
212 (fundamental-mode)) |
baf8fe0c51e3
(debug): Behave sensibly if pop-up-frames is set.
Karl Heuer <kwzh@gnu.org>
parents:
6468
diff
changeset
|
213 (kill-buffer debugger-buffer)) |
21161
37f271ee9f6f
(debug, debugger-env-macro): store-match-data => set-match-data.
Richard M. Stallman <rms@gnu.org>
parents:
20885
diff
changeset
|
214 (set-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
|
215 ;; 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
|
216 ;; 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
|
217 (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
|
218 (setq overriding-local-map debugger-outer-overriding-local-map) |
18166
84c0a412aa71
(debug, debugger-eval-expression):
Richard M. Stallman <rms@gnu.org>
parents:
17262
diff
changeset
|
219 (setq overriding-terminal-local-map |
84c0a412aa71
(debug, debugger-eval-expression):
Richard M. Stallman <rms@gnu.org>
parents:
17262
diff
changeset
|
220 debugger-outer-overriding-terminal-local-map) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
221 (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
|
222 (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
|
223 (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
|
224 (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
|
225 (setq unread-command-events debugger-outer-unread-command-events) |
22921
48b85e4a4dd3
(debugger-outer-unread-post-input-method-events): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22114
diff
changeset
|
226 (setq unread-post-input-method-events |
48b85e4a4dd3
(debugger-outer-unread-post-input-method-events): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22114
diff
changeset
|
227 debugger-outer-unread-post-input-method-events) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
228 (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
|
229 (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
|
230 (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
|
231 (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
|
232 (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
|
233 (setq standard-output debugger-outer-standard-output) |
24741
00ef85c8a0ff
(debugger-outer-inhibit-redisplay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24524
diff
changeset
|
234 (setq inhibit-redisplay debugger-outer-inhibit-redisplay) |
5545 | 235 (setq cursor-in-echo-area debugger-outer-cursor-in-echo-area) |
473 | 236 (setq debug-on-next-call debugger-step-after-exit) |
237 debugger-value)) | |
238 | |
239 (defun debugger-step-through () | |
240 "Proceed, stepping through subexpressions of this expression. | |
241 Enter another debugger on next entry to eval, apply or funcall." | |
242 (interactive) | |
243 (setq debugger-step-after-exit t) | |
244 (message "Proceeding, will debug on next eval or call.") | |
245 (exit-recursive-edit)) | |
246 | |
247 (defun debugger-continue () | |
248 "Continue, evaluating this expression without stopping." | |
249 (interactive) | |
250 (message "Continuing.") | |
251 (exit-recursive-edit)) | |
252 | |
253 (defun debugger-return-value (val) | |
254 "Continue, specifying value to return. | |
255 This is only useful when the value returned from the debugger | |
256 will be used, such as in a debug on exit from a frame." | |
257 (interactive "XReturn value (evaluated): ") | |
258 (setq debugger-value val) | |
259 (princ "Returning " t) | |
260 (prin1 debugger-value) | |
261 (exit-recursive-edit)) | |
262 | |
263 (defun debugger-jump () | |
264 "Continue to exit from this frame, with all debug-on-entry suspended." | |
265 (interactive) | |
266 ;; Compensate for the two extra stack frames for debugger-jump. | |
267 (let ((debugger-frame-offset (+ debugger-frame-offset 2))) | |
268 (debugger-frame)) | |
269 ;; Turn off all debug-on-entry functions | |
270 ;; but leave them in the list. | |
271 (let ((list debug-function-list)) | |
272 (while list | |
273 (fset (car list) | |
274 (debug-on-entry-1 (car list) (symbol-function (car list)) nil)) | |
275 (setq list (cdr list)))) | |
276 (message "Continuing through this frame") | |
277 (exit-recursive-edit)) | |
278 | |
279 (defun debugger-reenable () | |
280 "Turn all debug-on-entry functions back on." | |
281 (let ((list debug-function-list)) | |
282 (while list | |
283 (or (consp (symbol-function (car list))) | |
284 (debug-convert-byte-code (car list))) | |
285 (fset (car list) | |
286 (debug-on-entry-1 (car list) (symbol-function (car list)) t)) | |
287 (setq list (cdr list))))) | |
288 | |
289 (defun debugger-frame-number () | |
290 "Return number of frames in backtrace before the one point points at." | |
291 (save-excursion | |
292 (beginning-of-line) | |
293 (let ((opoint (point)) | |
294 (count 0)) | |
295 (goto-char (point-min)) | |
296 (if (or (equal (buffer-substring (point) (+ (point) 6)) | |
297 "Signal") | |
298 (equal (buffer-substring (point) (+ (point) 6)) | |
299 "Return")) | |
300 (progn | |
301 (search-forward ":") | |
302 (forward-sexp 1))) | |
303 (forward-line 1) | |
304 (while (progn | |
305 (forward-char 2) | |
306 (if (= (following-char) ?\() | |
307 (forward-sexp 1) | |
308 (forward-sexp 2)) | |
309 (forward-line 1) | |
310 (<= (point) opoint)) | |
311 (setq count (1+ count))) | |
312 count))) | |
313 | |
314 ;; Chosen empirically to account for all the frames | |
315 ;; that will exist when debugger-frame is called | |
316 ;; within the first one that appears in the backtrace buffer. | |
317 ;; Assumes debugger-frame is called from a key; | |
318 ;; will be wrong if it is called with Meta-x. | |
319 (defconst debugger-frame-offset 8 "") | |
320 | |
321 (defun debugger-frame () | |
322 "Request entry to debugger when this frame exits. | |
323 Applies to the frame whose line point is on in the backtrace." | |
324 (interactive) | |
325 (beginning-of-line) | |
326 (let ((level (debugger-frame-number))) | |
327 (backtrace-debug (+ level debugger-frame-offset) t)) | |
328 (if (= (following-char) ? ) | |
329 (let ((buffer-read-only nil)) | |
330 (delete-char 1) | |
331 (insert ?*))) | |
332 (beginning-of-line)) | |
333 | |
334 (defun debugger-frame-clear () | |
22114
0fbcff056c0f
(debugger-frame-clear): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
21669
diff
changeset
|
335 "Do not enter debugger when this frame exits. |
473 | 336 Applies to the frame whose line point is on in the backtrace." |
337 (interactive) | |
338 (beginning-of-line) | |
339 (let ((level (debugger-frame-number))) | |
340 (backtrace-debug (+ level debugger-frame-offset) nil)) | |
341 (if (= (following-char) ?*) | |
342 (let ((buffer-read-only nil)) | |
343 (delete-char 1) | |
344 (insert ? ))) | |
345 (beginning-of-line)) | |
346 | |
20403
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
347 |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
348 |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
349 (put 'debugger-env-macro 'lisp-indent-function 0) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
350 (defmacro debugger-env-macro (&rest body) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
351 "Run BODY in original environment." |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
352 (` |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
353 (save-excursion |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
354 (if (null (buffer-name debugger-old-buffer)) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
355 ;; old buffer deleted |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
356 (setq debugger-old-buffer (current-buffer))) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
357 (set-buffer debugger-old-buffer) |
24741
00ef85c8a0ff
(debugger-outer-inhibit-redisplay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24524
diff
changeset
|
358 (let ((load-read-function debugger-outer-load-read-function) |
00ef85c8a0ff
(debugger-outer-inhibit-redisplay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24524
diff
changeset
|
359 (overriding-terminal-local-map |
00ef85c8a0ff
(debugger-outer-inhibit-redisplay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24524
diff
changeset
|
360 debugger-outer-overriding-terminal-local-map) |
00ef85c8a0ff
(debugger-outer-inhibit-redisplay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24524
diff
changeset
|
361 (overriding-local-map debugger-outer-overriding-local-map) |
00ef85c8a0ff
(debugger-outer-inhibit-redisplay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24524
diff
changeset
|
362 (track-mouse debugger-outer-track-mouse) |
20403
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
363 (last-command debugger-outer-last-command) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
364 (this-command debugger-outer-this-command) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
365 (unread-command-char debugger-outer-unread-command-char) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
366 (unread-command-events debugger-outer-unread-command-events) |
22921
48b85e4a4dd3
(debugger-outer-unread-post-input-method-events): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22114
diff
changeset
|
367 (unread-post-input-method-events |
48b85e4a4dd3
(debugger-outer-unread-post-input-method-events): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22114
diff
changeset
|
368 debugger-outer-unread-post-input-method-events) |
20403
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
369 (last-input-event debugger-outer-last-input-event) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
370 (last-command-event debugger-outer-last-command-event) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
371 (last-nonmenu-event debugger-outer-last-nonmenu-event) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
372 (last-event-frame debugger-outer-last-event-frame) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
373 (standard-input debugger-outer-standard-input) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
374 (standard-output debugger-outer-standard-output) |
24741
00ef85c8a0ff
(debugger-outer-inhibit-redisplay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24524
diff
changeset
|
375 (inhibit-redisplay debugger-outer-inhibit-redisplay) |
00ef85c8a0ff
(debugger-outer-inhibit-redisplay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24524
diff
changeset
|
376 (cursor-in-echo-area debugger-outer-cursor-in-echo-area)) |
21161
37f271ee9f6f
(debug, debugger-env-macro): store-match-data => set-match-data.
Richard M. Stallman <rms@gnu.org>
parents:
20885
diff
changeset
|
377 (set-match-data debugger-outer-match-data) |
20403
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
378 (prog1 (progn (,@ body)) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
379 (setq debugger-outer-match-data (match-data)) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
380 (setq debugger-outer-load-read-function load-read-function) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
381 (setq debugger-outer-overriding-terminal-local-map |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
382 overriding-terminal-local-map) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
383 (setq debugger-outer-overriding-local-map overriding-local-map) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
384 (setq debugger-outer-track-mouse track-mouse) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
385 (setq debugger-outer-last-command last-command) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
386 (setq debugger-outer-this-command this-command) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
387 (setq debugger-outer-unread-command-char unread-command-char) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
388 (setq debugger-outer-unread-command-events unread-command-events) |
22921
48b85e4a4dd3
(debugger-outer-unread-post-input-method-events): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22114
diff
changeset
|
389 (setq debugger-outer-unread-post-input-method-events |
48b85e4a4dd3
(debugger-outer-unread-post-input-method-events): New variable.
Kenichi Handa <handa@m17n.org>
parents:
22114
diff
changeset
|
390 unread-post-input-method-events) |
20403
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
391 (setq debugger-outer-last-input-event last-input-event) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
392 (setq debugger-outer-last-command-event last-command-event) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
393 (setq debugger-outer-last-nonmenu-event last-nonmenu-event) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
394 (setq debugger-outer-last-event-frame last-event-frame) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
395 (setq debugger-outer-standard-input standard-input) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
396 (setq debugger-outer-standard-output standard-output) |
24741
00ef85c8a0ff
(debugger-outer-inhibit-redisplay): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
24524
diff
changeset
|
397 (setq debugger-outer-inhibit-redisplay inhibit-redisplay) |
20403
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
398 (setq debugger-outer-cursor-in-echo-area cursor-in-echo-area) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
399 ))))) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
400 |
473 | 401 (defun debugger-eval-expression (exp) |
6468
b0c731997544
(debugger-eval-expression): Use a history list.
Richard M. Stallman <rms@gnu.org>
parents:
6048
diff
changeset
|
402 "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
|
403 (interactive |
b0c731997544
(debugger-eval-expression): Use a history list.
Richard M. Stallman <rms@gnu.org>
parents:
6048
diff
changeset
|
404 (list (read-from-minibuffer "Eval: " |
b0c731997544
(debugger-eval-expression): Use a history list.
Richard M. Stallman <rms@gnu.org>
parents:
6048
diff
changeset
|
405 nil read-expression-map t |
b0c731997544
(debugger-eval-expression): Use a history list.
Richard M. Stallman <rms@gnu.org>
parents:
6048
diff
changeset
|
406 'read-expression-history))) |
20403
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
407 (debugger-env-macro (eval-expression exp))) |
473 | 408 |
409 (defvar debugger-mode-map nil) | |
410 (if debugger-mode-map | |
411 nil | |
412 (let ((loop ? )) | |
413 (setq debugger-mode-map (make-keymap)) | |
414 (suppress-keymap debugger-mode-map) | |
415 (define-key debugger-mode-map "-" 'negative-argument) | |
416 (define-key debugger-mode-map "b" 'debugger-frame) | |
417 (define-key debugger-mode-map "c" 'debugger-continue) | |
418 (define-key debugger-mode-map "j" 'debugger-jump) | |
419 (define-key debugger-mode-map "r" 'debugger-return-value) | |
420 (define-key debugger-mode-map "u" 'debugger-frame-clear) | |
421 (define-key debugger-mode-map "d" 'debugger-step-through) | |
422 (define-key debugger-mode-map "l" 'debugger-list-functions) | |
423 (define-key debugger-mode-map "h" 'describe-mode) | |
424 (define-key debugger-mode-map "q" 'top-level) | |
425 (define-key debugger-mode-map "e" 'debugger-eval-expression) | |
20403
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
426 (define-key debugger-mode-map " " 'next-line) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
427 (define-key debugger-mode-map "R" 'debugger-record-expression) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
428 )) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
429 |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
430 |
21365 | 431 (defcustom debugger-record-buffer "*Debugger-record*" |
432 "*Buffer name for expression values, for \\[debugger-record-expression]." | |
433 :type 'string | |
21669
9861518505cb
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21365
diff
changeset
|
434 :group 'debugger |
9861518505cb
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21365
diff
changeset
|
435 :version "20.3") |
20403
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
436 |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
437 (defun debugger-record-expression (exp) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
438 "Display a variable's value and record it in `*Backtrace-record*' buffer." |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
439 (interactive |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
440 (list (read-from-minibuffer |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
441 "Record Eval: " |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
442 nil |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
443 read-expression-map t |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
444 'read-expression-history))) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
445 (let* ((buffer (get-buffer-create debugger-record-buffer)) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
446 (standard-output buffer)) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
447 (princ (format "Debugger Eval (%s): " exp)) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
448 (princ (debugger-eval-expression exp)) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
449 (terpri)) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
450 |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
451 (with-current-buffer (get-buffer debugger-record-buffer) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
452 (save-excursion |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
453 (forward-line -1) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
454 (message |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
455 (buffer-substring (point) (progn (end-of-line) (point))))))) |
473 | 456 |
457 (put 'debugger-mode 'mode-class 'special) | |
458 | |
459 (defun debugger-mode () | |
460 "Mode for backtrace buffers, selected in debugger. | |
461 \\<debugger-mode-map> | |
462 A line starts with `*' if exiting that frame will call the debugger. | |
463 Type \\[debugger-frame] or \\[debugger-frame-clear] to set or remove the `*'. | |
464 | |
465 When in debugger due to frame being exited, | |
466 use the \\[debugger-return-value] command to override the value | |
467 being returned from that frame. | |
468 | |
469 Use \\[debug-on-entry] and \\[cancel-debug-on-entry] to control | |
470 which functions will enter the debugger when called. | |
471 | |
472 Complete list of commands: | |
473 \\{debugger-mode-map}" | |
20403
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
474 (kill-all-local-variables) |
473 | 475 (setq major-mode 'debugger-mode) |
476 (setq mode-name "Debugger") | |
477 (setq truncate-lines t) | |
478 (set-syntax-table emacs-lisp-mode-syntax-table) | |
20403
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
479 (use-local-map debugger-mode-map) |
698119867c21
(debugger-mode-hook): New user variable.
Karl Heuer <kwzh@gnu.org>
parents:
19889
diff
changeset
|
480 (run-hooks 'debugger-mode-hook)) |
473 | 481 |
482 ;;;###autoload | |
483 (defun debug-on-entry (function) | |
484 "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
|
485 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
|
486 This works by modifying the definition of FUNCTION, |
473 | 487 which must be written in Lisp, not predefined. |
488 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
|
489 Redefining FUNCTION also cancels it." |
473 | 490 (interactive "aDebug on entry (to function): ") |
491 (debugger-reenable) | |
20404
7cce7f974c78
(debug-on-entry): If definition is a symbol,
Karl Heuer <kwzh@gnu.org>
parents:
20403
diff
changeset
|
492 ;; Handle a function that has been aliased to some other function. |
7cce7f974c78
(debug-on-entry): If definition is a symbol,
Karl Heuer <kwzh@gnu.org>
parents:
20403
diff
changeset
|
493 (if (symbolp (symbol-function function)) |
7cce7f974c78
(debug-on-entry): If definition is a symbol,
Karl Heuer <kwzh@gnu.org>
parents:
20403
diff
changeset
|
494 (fset function `(lambda (&rest debug-on-entry-args) |
7cce7f974c78
(debug-on-entry): If definition is a symbol,
Karl Heuer <kwzh@gnu.org>
parents:
20403
diff
changeset
|
495 (apply ',(symbol-function function) |
7cce7f974c78
(debug-on-entry): If definition is a symbol,
Karl Heuer <kwzh@gnu.org>
parents:
20403
diff
changeset
|
496 debug-on-entry-args)))) |
473 | 497 (if (subrp (symbol-function function)) |
498 (error "Function %s is a primitive" function)) | |
499 (or (consp (symbol-function function)) | |
500 (debug-convert-byte-code function)) | |
501 (or (consp (symbol-function function)) | |
502 (error "Definition of %s is not a list" function)) | |
503 (fset function (debug-on-entry-1 function (symbol-function function) t)) | |
504 (or (memq function debug-function-list) | |
505 (setq debug-function-list (cons function debug-function-list))) | |
506 function) | |
507 | |
508 ;;;###autoload | |
509 (defun cancel-debug-on-entry (&optional function) | |
510 "Undo effect of \\[debug-on-entry] on FUNCTION. | |
511 If argument is nil or an empty string, cancel for all functions." | |
477 | 512 (interactive |
513 (list (let ((name | |
514 (completing-read "Cancel debug on entry (to function): " | |
515 ;; Make an "alist" of the functions | |
516 ;; that now have debug on entry. | |
517 (mapcar 'list | |
518 (mapcar 'symbol-name | |
519 debug-function-list)) | |
520 nil t nil))) | |
521 (if name (intern name))))) | |
473 | 522 (debugger-reenable) |
523 (if (and function (not (string= function ""))) | |
524 (progn | |
525 (fset function | |
526 (debug-on-entry-1 function (symbol-function function) nil)) | |
527 (setq debug-function-list (delq function debug-function-list)) | |
528 function) | |
529 (message "Cancelling debug-on-entry for all functions") | |
530 (mapcar 'cancel-debug-on-entry debug-function-list))) | |
531 | |
532 (defun debug-convert-byte-code (function) | |
533 (let ((defn (symbol-function function))) | |
534 (if (not (consp defn)) | |
535 ;; Assume a compiled code object. | |
536 (let* ((contents (append defn nil)) | |
537 (body | |
538 (list (list 'byte-code (nth 1 contents) | |
539 (nth 2 contents) (nth 3 contents))))) | |
540 (if (nthcdr 5 contents) | |
541 (setq body (cons (list 'interactive (nth 5 contents)) body))) | |
542 (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
|
543 ;; 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
|
544 ;; 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
|
545 ;; 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
|
546 (setq body (cons (documentation function) body))) |
473 | 547 (fset function (cons 'lambda (cons (car contents) body))))))) |
548 | |
549 (defun debug-on-entry-1 (function defn flag) | |
550 (if (subrp defn) | |
551 (error "%s is a built-in function" function) | |
552 (if (eq (car defn) 'macro) | |
553 (debug-on-entry-1 function (cdr defn) flag) | |
554 (or (eq (car defn) 'lambda) | |
555 (error "%s not user-defined Lisp function" function)) | |
556 (let (tail prec) | |
557 (if (stringp (car (nthcdr 2 defn))) | |
558 (setq tail (nthcdr 3 defn) | |
559 prec (list (car defn) (car (cdr defn)) | |
560 (car (cdr (cdr defn))))) | |
561 (setq tail (nthcdr 2 defn) | |
562 prec (list (car defn) (car (cdr defn))))) | |
563 (if (eq flag (equal (car tail) '(debug 'debug))) | |
564 defn | |
565 (if flag | |
566 (nconc prec (cons '(debug 'debug) tail)) | |
567 (nconc prec (cdr tail)))))))) | |
568 | |
569 (defun debugger-list-functions () | |
570 "Display a list of all the functions now set to debug on entry." | |
571 (interactive) | |
572 (with-output-to-temp-buffer "*Help*" | |
573 (if (null debug-function-list) | |
574 (princ "No debug-on-entry functions now\n") | |
575 (princ "Functions set to debug on entry:\n\n") | |
576 (let ((list debug-function-list)) | |
577 (while list | |
578 (prin1 (car list)) | |
579 (terpri) | |
580 (setq list (cdr list)))) | |
581 (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
|
582 (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
|
583 (save-excursion |
b1455d954e44
(debugger-list-functions): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents:
6926
diff
changeset
|
584 (set-buffer standard-output) |
b1455d954e44
(debugger-list-functions): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents:
6926
diff
changeset
|
585 (help-mode)))) |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
477
diff
changeset
|
586 |
18383 | 587 (provide 'debug) |
588 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
477
diff
changeset
|
589 ;;; debug.el ends here |