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