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