Mercurial > emacs
annotate lisp/emacs-lisp/debug.el @ 10590:9f68d8d6357b
(menu-bar-update-yank-menu): If string is too long,
show start and end, with ... between them.
(yank-menu-length): Default value 20.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 30 Jan 1995 00:37:22 +0000 |
parents | 0bd8034a4f54 |
children | 48f895a471a2 |
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 | |
6926
027b7de8a571
(debug, debugger-eval-expression): Preserve match-data.
Karl Heuer <kwzh@gnu.org>
parents:
6567
diff
changeset
|
33 (defvar 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
|
34 (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
|
35 (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
|
36 (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
|
37 (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
|
38 (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
|
39 (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
|
40 (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
|
41 (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
|
42 (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
|
43 (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
|
44 (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
|
45 (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
|
46 |
473 | 47 ;;;###autoload |
48 (setq debugger 'debug) | |
49 ;;;###autoload | |
50 (defun debug (&rest debugger-args) | |
6048
ff40882c5578
(debug, debug-on-entry): Doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
5585
diff
changeset
|
51 "Enter debugger. To return, type \\<debugger-mode-map>`\\[debugger-continue]'. |
473 | 52 Arguments are mainly for use when this is called from the internals |
53 of the evaluator. | |
54 | |
55 You may call with no args, or you may pass nil as the first arg and | |
56 any other args you like. In that case, the list of args after the | |
57 first will be printed into the backtrace buffer." | |
58 (message "Entering debugger...") | |
59 (let (debugger-value | |
60 (debug-on-error nil) | |
61 (debug-on-quit nil) | |
62 (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
|
63 (get-buffer-create "*Backtrace*"))) |
473 | 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. |
6926
027b7de8a571
(debug, debugger-eval-expression): Preserve match-data.
Karl Heuer <kwzh@gnu.org>
parents:
6567
diff
changeset
|
70 (debugger-outer-match-data (match-data)) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
71 (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
|
72 (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
|
73 (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
|
74 (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
|
75 (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
|
76 (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
|
77 (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
|
78 (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
|
79 (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
|
80 (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
|
81 (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
|
82 (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
|
83 ;; 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
|
84 (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
|
85 (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
|
86 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
|
87 last-event-frame |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
88 (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
|
89 (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
|
90 (unwind-protect |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
91 (save-excursion |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
92 (save-window-excursion |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
93 (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
|
94 (erase-buffer) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
95 (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
|
96 (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
|
97 (print-length 50)) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
98 (backtrace)) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
99 (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
|
100 (debugger-mode) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
101 (delete-region (point) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
102 (progn |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
103 (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
|
104 (forward-line 1) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
105 (point))) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
106 (debugger-reenable) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
107 (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
|
108 (insert "Entering:\n") |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
109 (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
|
110 (progn |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
111 (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
|
112 (delete-char 1) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
113 (insert ?*) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
114 (beginning-of-line)))) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
115 ((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
|
116 (insert "Return value: ") |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
117 (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
|
118 (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
|
119 (insert ?\n) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
120 (delete-char 1) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
121 (insert ? ) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
122 (beginning-of-line)) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
123 ((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
|
124 (insert "Signalling: ") |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
125 (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
|
126 (insert ?\n)) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
127 ((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
|
128 (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
|
129 (t |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
130 (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
|
131 (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
|
132 (current-buffer)) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
133 (insert ?\n))) |
473 | 134 (message "") |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
135 (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
|
136 (standard-output nil) |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
137 (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
|
138 (message "") |
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
139 (recursive-edit)))) |
6567
baf8fe0c51e3
(debug): Behave sensibly if pop-up-frames is set.
Karl Heuer <kwzh@gnu.org>
parents:
6468
diff
changeset
|
140 ;; 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
|
141 ;; 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
|
142 (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
|
143 ;; 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
|
144 ;; 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
|
145 ;; 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
|
146 ;; 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
|
147 (save-excursion |
baf8fe0c51e3
(debug): Behave sensibly if pop-up-frames is set.
Karl Heuer <kwzh@gnu.org>
parents:
6468
diff
changeset
|
148 (set-buffer debugger-buffer) |
baf8fe0c51e3
(debug): Behave sensibly if pop-up-frames is set.
Karl Heuer <kwzh@gnu.org>
parents:
6468
diff
changeset
|
149 (erase-buffer) |
baf8fe0c51e3
(debug): Behave sensibly if pop-up-frames is set.
Karl Heuer <kwzh@gnu.org>
parents:
6468
diff
changeset
|
150 (fundamental-mode)) |
baf8fe0c51e3
(debug): Behave sensibly if pop-up-frames is set.
Karl Heuer <kwzh@gnu.org>
parents:
6468
diff
changeset
|
151 (kill-buffer debugger-buffer)) |
6926
027b7de8a571
(debug, debugger-eval-expression): Preserve match-data.
Karl Heuer <kwzh@gnu.org>
parents:
6567
diff
changeset
|
152 (store-match-data debugger-outer-match-data))) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
153 ;; 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
|
154 ;; 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
|
155 (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
|
156 (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
|
157 (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
|
158 (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
|
159 (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
|
160 (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
|
161 (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
|
162 (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
|
163 (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
|
164 (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
|
165 (setq standard-output debugger-outer-standard-output) |
5545 | 166 (setq cursor-in-echo-area debugger-outer-cursor-in-echo-area) |
473 | 167 (setq debug-on-next-call debugger-step-after-exit) |
168 debugger-value)) | |
169 | |
170 (defun debugger-step-through () | |
171 "Proceed, stepping through subexpressions of this expression. | |
172 Enter another debugger on next entry to eval, apply or funcall." | |
173 (interactive) | |
174 (setq debugger-step-after-exit t) | |
175 (message "Proceeding, will debug on next eval or call.") | |
176 (exit-recursive-edit)) | |
177 | |
178 (defun debugger-continue () | |
179 "Continue, evaluating this expression without stopping." | |
180 (interactive) | |
181 (message "Continuing.") | |
182 (exit-recursive-edit)) | |
183 | |
184 (defun debugger-return-value (val) | |
185 "Continue, specifying value to return. | |
186 This is only useful when the value returned from the debugger | |
187 will be used, such as in a debug on exit from a frame." | |
188 (interactive "XReturn value (evaluated): ") | |
189 (setq debugger-value val) | |
190 (princ "Returning " t) | |
191 (prin1 debugger-value) | |
192 (exit-recursive-edit)) | |
193 | |
194 (defun debugger-jump () | |
195 "Continue to exit from this frame, with all debug-on-entry suspended." | |
196 (interactive) | |
197 ;; Compensate for the two extra stack frames for debugger-jump. | |
198 (let ((debugger-frame-offset (+ debugger-frame-offset 2))) | |
199 (debugger-frame)) | |
200 ;; Turn off all debug-on-entry functions | |
201 ;; but leave them in the list. | |
202 (let ((list debug-function-list)) | |
203 (while list | |
204 (fset (car list) | |
205 (debug-on-entry-1 (car list) (symbol-function (car list)) nil)) | |
206 (setq list (cdr list)))) | |
207 (message "Continuing through this frame") | |
208 (exit-recursive-edit)) | |
209 | |
210 (defun debugger-reenable () | |
211 "Turn all debug-on-entry functions back on." | |
212 (let ((list debug-function-list)) | |
213 (while list | |
214 (or (consp (symbol-function (car list))) | |
215 (debug-convert-byte-code (car list))) | |
216 (fset (car list) | |
217 (debug-on-entry-1 (car list) (symbol-function (car list)) t)) | |
218 (setq list (cdr list))))) | |
219 | |
220 (defun debugger-frame-number () | |
221 "Return number of frames in backtrace before the one point points at." | |
222 (save-excursion | |
223 (beginning-of-line) | |
224 (let ((opoint (point)) | |
225 (count 0)) | |
226 (goto-char (point-min)) | |
227 (if (or (equal (buffer-substring (point) (+ (point) 6)) | |
228 "Signal") | |
229 (equal (buffer-substring (point) (+ (point) 6)) | |
230 "Return")) | |
231 (progn | |
232 (search-forward ":") | |
233 (forward-sexp 1))) | |
234 (forward-line 1) | |
235 (while (progn | |
236 (forward-char 2) | |
237 (if (= (following-char) ?\() | |
238 (forward-sexp 1) | |
239 (forward-sexp 2)) | |
240 (forward-line 1) | |
241 (<= (point) opoint)) | |
242 (setq count (1+ count))) | |
243 count))) | |
244 | |
245 ;; Chosen empirically to account for all the frames | |
246 ;; that will exist when debugger-frame is called | |
247 ;; within the first one that appears in the backtrace buffer. | |
248 ;; Assumes debugger-frame is called from a key; | |
249 ;; will be wrong if it is called with Meta-x. | |
250 (defconst debugger-frame-offset 8 "") | |
251 | |
252 (defun debugger-frame () | |
253 "Request entry to debugger when this frame exits. | |
254 Applies to the frame whose line point is on in the backtrace." | |
255 (interactive) | |
256 (beginning-of-line) | |
257 (let ((level (debugger-frame-number))) | |
258 (backtrace-debug (+ level debugger-frame-offset) t)) | |
259 (if (= (following-char) ? ) | |
260 (let ((buffer-read-only nil)) | |
261 (delete-char 1) | |
262 (insert ?*))) | |
263 (beginning-of-line)) | |
264 | |
265 (defun debugger-frame-clear () | |
266 "Do not enter to debugger when this frame exits. | |
267 Applies to the frame whose line point is on in the backtrace." | |
268 (interactive) | |
269 (beginning-of-line) | |
270 (let ((level (debugger-frame-number))) | |
271 (backtrace-debug (+ level debugger-frame-offset) nil)) | |
272 (if (= (following-char) ?*) | |
273 (let ((buffer-read-only nil)) | |
274 (delete-char 1) | |
275 (insert ? ))) | |
276 (beginning-of-line)) | |
277 | |
278 (defun debugger-eval-expression (exp) | |
6468
b0c731997544
(debugger-eval-expression): Use a history list.
Richard M. Stallman <rms@gnu.org>
parents:
6048
diff
changeset
|
279 "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
|
280 (interactive |
b0c731997544
(debugger-eval-expression): Use a history list.
Richard M. Stallman <rms@gnu.org>
parents:
6048
diff
changeset
|
281 (list (read-from-minibuffer "Eval: " |
b0c731997544
(debugger-eval-expression): Use a history list.
Richard M. Stallman <rms@gnu.org>
parents:
6048
diff
changeset
|
282 nil read-expression-map t |
b0c731997544
(debugger-eval-expression): Use a history list.
Richard M. Stallman <rms@gnu.org>
parents:
6048
diff
changeset
|
283 'read-expression-history))) |
473 | 284 (save-excursion |
285 (if (null (buffer-name debugger-old-buffer)) | |
286 ;; old buffer deleted | |
287 (setq debugger-old-buffer (current-buffer))) | |
288 (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
|
289 (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
|
290 (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
|
291 (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
|
292 (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
|
293 (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
|
294 (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
|
295 (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
|
296 (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
|
297 (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
|
298 (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
|
299 (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
|
300 (cursor-in-echo-area debugger-outer-cursor-in-echo-area)) |
6926
027b7de8a571
(debug, debugger-eval-expression): Preserve match-data.
Karl Heuer <kwzh@gnu.org>
parents:
6567
diff
changeset
|
301 (store-match-data debugger-outer-match-data) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
302 (prog1 (eval-expression exp) |
6926
027b7de8a571
(debug, debugger-eval-expression): Preserve match-data.
Karl Heuer <kwzh@gnu.org>
parents:
6567
diff
changeset
|
303 (setq debugger-outer-match-data (match-data)) |
5544
ab9c9a611b5a
(debug): Bind a bunch of vars, like last-command, to
Richard M. Stallman <rms@gnu.org>
parents:
5430
diff
changeset
|
304 (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
|
305 (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
|
306 (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
|
307 (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
|
308 (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
|
309 (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
|
310 (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
|
311 (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
|
312 (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
|
313 (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
|
314 (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
|
315 (setq debugger-outer-cursor-in-echo-area cursor-in-echo-area))))) |
473 | 316 |
317 (defvar debugger-mode-map nil) | |
318 (if debugger-mode-map | |
319 nil | |
320 (let ((loop ? )) | |
321 (setq debugger-mode-map (make-keymap)) | |
322 (suppress-keymap debugger-mode-map) | |
323 (define-key debugger-mode-map "-" 'negative-argument) | |
324 (define-key debugger-mode-map "b" 'debugger-frame) | |
325 (define-key debugger-mode-map "c" 'debugger-continue) | |
326 (define-key debugger-mode-map "j" 'debugger-jump) | |
327 (define-key debugger-mode-map "r" 'debugger-return-value) | |
328 (define-key debugger-mode-map "u" 'debugger-frame-clear) | |
329 (define-key debugger-mode-map "d" 'debugger-step-through) | |
330 (define-key debugger-mode-map "l" 'debugger-list-functions) | |
331 (define-key debugger-mode-map "h" 'describe-mode) | |
332 (define-key debugger-mode-map "q" 'top-level) | |
333 (define-key debugger-mode-map "e" 'debugger-eval-expression) | |
334 (define-key debugger-mode-map " " 'next-line))) | |
335 | |
336 (put 'debugger-mode 'mode-class 'special) | |
337 | |
338 (defun debugger-mode () | |
339 "Mode for backtrace buffers, selected in debugger. | |
340 \\<debugger-mode-map> | |
341 A line starts with `*' if exiting that frame will call the debugger. | |
342 Type \\[debugger-frame] or \\[debugger-frame-clear] to set or remove the `*'. | |
343 | |
344 When in debugger due to frame being exited, | |
345 use the \\[debugger-return-value] command to override the value | |
346 being returned from that frame. | |
347 | |
348 Use \\[debug-on-entry] and \\[cancel-debug-on-entry] to control | |
349 which functions will enter the debugger when called. | |
350 | |
351 Complete list of commands: | |
352 \\{debugger-mode-map}" | |
353 (kill-all-local-variables) | |
354 (setq major-mode 'debugger-mode) | |
355 (setq mode-name "Debugger") | |
356 (setq truncate-lines t) | |
357 (set-syntax-table emacs-lisp-mode-syntax-table) | |
358 (use-local-map debugger-mode-map)) | |
359 | |
360 ;;;###autoload | |
361 (defun debug-on-entry (function) | |
362 "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
|
363 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
|
364 This works by modifying the definition of FUNCTION, |
473 | 365 which must be written in Lisp, not predefined. |
366 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
|
367 Redefining FUNCTION also cancels it." |
473 | 368 (interactive "aDebug on entry (to function): ") |
369 (debugger-reenable) | |
370 (if (subrp (symbol-function function)) | |
371 (error "Function %s is a primitive" function)) | |
372 (or (consp (symbol-function function)) | |
373 (debug-convert-byte-code function)) | |
374 (or (consp (symbol-function function)) | |
375 (error "Definition of %s is not a list" function)) | |
376 (fset function (debug-on-entry-1 function (symbol-function function) t)) | |
377 (or (memq function debug-function-list) | |
378 (setq debug-function-list (cons function debug-function-list))) | |
379 function) | |
380 | |
381 ;;;###autoload | |
382 (defun cancel-debug-on-entry (&optional function) | |
383 "Undo effect of \\[debug-on-entry] on FUNCTION. | |
384 If argument is nil or an empty string, cancel for all functions." | |
477 | 385 (interactive |
386 (list (let ((name | |
387 (completing-read "Cancel debug on entry (to function): " | |
388 ;; Make an "alist" of the functions | |
389 ;; that now have debug on entry. | |
390 (mapcar 'list | |
391 (mapcar 'symbol-name | |
392 debug-function-list)) | |
393 nil t nil))) | |
394 (if name (intern name))))) | |
473 | 395 (debugger-reenable) |
396 (if (and function (not (string= function ""))) | |
397 (progn | |
398 (fset function | |
399 (debug-on-entry-1 function (symbol-function function) nil)) | |
400 (setq debug-function-list (delq function debug-function-list)) | |
401 function) | |
402 (message "Cancelling debug-on-entry for all functions") | |
403 (mapcar 'cancel-debug-on-entry debug-function-list))) | |
404 | |
405 (defun debug-convert-byte-code (function) | |
406 (let ((defn (symbol-function function))) | |
407 (if (not (consp defn)) | |
408 ;; Assume a compiled code object. | |
409 (let* ((contents (append defn nil)) | |
410 (body | |
411 (list (list 'byte-code (nth 1 contents) | |
412 (nth 2 contents) (nth 3 contents))))) | |
413 (if (nthcdr 5 contents) | |
414 (setq body (cons (list 'interactive (nth 5 contents)) body))) | |
415 (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
|
416 ;; 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
|
417 ;; 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
|
418 ;; 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
|
419 (setq body (cons (documentation function) body))) |
473 | 420 (fset function (cons 'lambda (cons (car contents) body))))))) |
421 | |
422 (defun debug-on-entry-1 (function defn flag) | |
423 (if (subrp defn) | |
424 (error "%s is a built-in function" function) | |
425 (if (eq (car defn) 'macro) | |
426 (debug-on-entry-1 function (cdr defn) flag) | |
427 (or (eq (car defn) 'lambda) | |
428 (error "%s not user-defined Lisp function" function)) | |
429 (let (tail prec) | |
430 (if (stringp (car (nthcdr 2 defn))) | |
431 (setq tail (nthcdr 3 defn) | |
432 prec (list (car defn) (car (cdr defn)) | |
433 (car (cdr (cdr defn))))) | |
434 (setq tail (nthcdr 2 defn) | |
435 prec (list (car defn) (car (cdr defn))))) | |
436 (if (eq flag (equal (car tail) '(debug 'debug))) | |
437 defn | |
438 (if flag | |
439 (nconc prec (cons '(debug 'debug) tail)) | |
440 (nconc prec (cdr tail)))))))) | |
441 | |
442 (defun debugger-list-functions () | |
443 "Display a list of all the functions now set to debug on entry." | |
444 (interactive) | |
445 (with-output-to-temp-buffer "*Help*" | |
446 (if (null debug-function-list) | |
447 (princ "No debug-on-entry functions now\n") | |
448 (princ "Functions set to debug on entry:\n\n") | |
449 (let ((list debug-function-list)) | |
450 (while list | |
451 (prin1 (car list)) | |
452 (terpri) | |
453 (setq list (cdr list)))) | |
454 (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
|
455 (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
|
456 (save-excursion |
b1455d954e44
(debugger-list-functions): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents:
6926
diff
changeset
|
457 (set-buffer standard-output) |
b1455d954e44
(debugger-list-functions): Set help-mode in *Help* buffer.
Karl Heuer <kwzh@gnu.org>
parents:
6926
diff
changeset
|
458 (help-mode)))) |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
477
diff
changeset
|
459 |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
477
diff
changeset
|
460 ;;; debug.el ends here |