annotate lisp/prim/debug.el @ 171:929b76928fce r20-3b12

Import from CVS: tag r20-3b12
author cvs
date Mon, 13 Aug 2007 09:47:52 +0200
parents 3bb7ccffb0c0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; debug.el --- debuggers and related commands for XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 72
diff changeset
3 ;; Copyright (C) 1985-6, 1993-4, 1997 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keyword: lisp, tools
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
23 ;; 02111-1307, USA.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
24
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
25 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
27 ;;; Commentary:
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
28
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 72
diff changeset
29 ;; NB: There are lots of formatting changes in the XEmacs version. -slb
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 72
diff changeset
30
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 72
diff changeset
31 ;; 06/11/1997 - Converted to use char-after instead of broken
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 72
diff changeset
32 ;; following-char. -slb
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
33
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
34 ;; This is a major mode documented in the Emacs manual.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (defvar debug-function-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 "List of functions currently set for debug on entry.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (defvar debugger-step-after-exit nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 "Non-nil means \"single-step\" after the debugger exits.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defvar debugger-value nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 "This is the value for the debugger to return, when it returns.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defvar debugger-old-buffer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 "This is the buffer that was current when the debugger was entered.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;#### This is terminally random an nigh-unmaintainable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;#### (need progv in elisp...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (defvar debugger-outer-match-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (defvar debugger-outer-load-read-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (defvar debugger-outer-overriding-local-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; FSFmacs (defvar debugger-outer-track-mouse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defvar debugger-outer-last-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (defvar debugger-outer-this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (defvar debugger-outer-unread-command-event)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
59 ;; FSF: (defvar debugger-outer-unread-command-char)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
60 (defvar debugger-outer-unread-command-events)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defvar debugger-outer-last-input-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defvar debugger-outer-last-input-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (defvar debugger-outer-last-input-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (defvar debugger-outer-last-command-event)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
65 ;; (defvar debugger-outer-last-nonmenu-event)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
66 ;; (defvar debugger-outer-last-event-frame)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (defvar debugger-outer-last-command-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (defvar debugger-outer-standard-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (defvar debugger-outer-standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defvar debugger-outer-cursor-in-echo-area)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;;don't ###autoload, loadup.el does something smarter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (setq debugger 'debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (defvar debugger-step-after-exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (defvar debugger-old-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (defvar debugger-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defun debug (&rest debugger-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 "Enter debugger. To return, type \\<debugger-mode-map>`\\[debugger-continue]'.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
82 Arguments are mainly for use when this is called from the internals
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
83 of the evaluator.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
84
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
85 You may call with no args, or you may pass nil as the first arg and
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
86 any other args you like. In that case, the list of args after the
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
87 first will be printed into the backtrace buffer."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; XEmacs: it doesn't work to enter the debugger non-interactively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; so just print out a backtrace and exit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (if (noninteractive) (apply 'early-error-handler debugger-args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (message "Entering debugger...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (let (debugger-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (debug-on-error nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (debug-on-quit nil)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
96 (debug-on-signal nil) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (debugger-buffer (let ((default-major-mode 'fundamental-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (get-buffer-create "*Backtrace*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; #### I18N3 set the debugger-buffer to output-translating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (debugger-old-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (debugger-step-after-exit nil)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
102 ;; Don't keep reading from an executing kbd macro!
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
103 (executing-macro nil)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
104 ;; Save the outer values of these vars for the `e' command
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;; before we replace the values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (debugger-outer-match-data (match-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (debugger-outer-load-read-function load-read-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (debugger-outer-overriding-local-map overriding-local-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;; FSFmacs (debugger-outer-track-mouse track-mouse)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
110 (debugger-outer-last-command last-command)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
111 (debugger-outer-this-command this-command)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
112 (debugger-outer-unread-command-event unread-command-event)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
113 (debugger-outer-unread-command-events unread-command-events)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
114 (debugger-outer-last-input-event last-input-event)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
115 (debugger-outer-last-input-char last-input-char)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
116 (debugger-outer-last-input-time last-input-time)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
117 (debugger-outer-last-command-event last-command-event)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
118 (debugger-outer-last-command-char last-command-char)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
119 (debugger-outer-standard-input standard-input)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
120 (debugger-outer-standard-output standard-output)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
121 (debugger-outer-cursor-in-echo-area cursor-in-echo-area))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;; Don't let these magic variables affect the debugger itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (unwind-protect ;XEmacs change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (let ((last-command nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (this-command nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (unread-command-event nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (last-input-event (allocate-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (last-input-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (last-input-time nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (last-command-event (allocate-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (last-command-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 overriding-local-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 load-read-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (standard-input t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (standard-output t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (cursor-in-echo-area nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (pop-to-buffer debugger-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (let ((standard-output (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (print-escape-newlines t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (print-length 50))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (backtrace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (debugger-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (delete-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (progn
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
149 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (re-search-forward "\n[* ] debug(")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (point)))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
153 (debugger-reenable)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; lambda is for debug-on-call when a function call is next.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;; debug is for debug-on-entry function called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (cond ((memq (car debugger-args) '(lambda debug))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (insert "Entering:\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (if (eq (car debugger-args) 'debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;; Skip the frames for backtrace-debug, byte-code,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;; and debug.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (backtrace-debug 3 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (insert ?*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (beginning-of-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;; Exiting a function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ((eq (car debugger-args) 'exit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (insert "Return value: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (setq debugger-value (nth 1 debugger-args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (prin1 debugger-value (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (insert ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (insert ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;; Debugger entered for an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ((eq (car debugger-args) 'error)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
177 (insert "Signaling: ")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (prin1 (nth 1 debugger-args) (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (insert ?\n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; debug-on-call, when the next thing is an eval.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ((eq (car debugger-args) t)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
182 (insert "Beginning evaluation of function call form:\n"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ;; User calls debug directly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (prin1 (if (eq (car debugger-args) 'nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (cdr debugger-args) debugger-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (insert ?\n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (let ((inhibit-trace t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (standard-output nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (buffer-read-only t))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
193 (message "")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (recursive-edit)))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
195 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 debugger-value))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
197 ;; Kill or at least neuter the backtrace buffer, so that users
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
198 ;; don't try to execute debugger commands in an invalid context.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (if (get-buffer-window debugger-buffer 'visible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;; Still visible despite the save-window-excursion? Maybe it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;; it's in a pop-up frame. It would be annoying to delete and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; recreate it every time the debugger stops, so instead we'll
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; erase it but leave it visible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (set-buffer debugger-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (fundamental-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (kill-buffer debugger-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (store-match-data debugger-outer-match-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ;; Put into effect the modified values of these variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;; in case the user set them with the `e' command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (setq load-read-function debugger-outer-load-read-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (setq overriding-local-map debugger-outer-overriding-local-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ;; FSFmacs (setq track-mouse debugger-outer-track-mouse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (setq last-command debugger-outer-last-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (setq this-command debugger-outer-this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (setq unread-command-event debugger-outer-unread-command-event)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
218 (setq unread-command-event debugger-outer-unread-command-events)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (setq last-input-event debugger-outer-last-input-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (setq last-input-char debugger-outer-last-input-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (setq last-input-time debugger-outer-last-input-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (setq last-command-event debugger-outer-last-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (setq last-command-char debugger-outer-last-command-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (setq standard-input debugger-outer-standard-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (setq standard-output debugger-outer-standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (setq cursor-in-echo-area debugger-outer-cursor-in-echo-area)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (setq debug-on-next-call debugger-step-after-exit) ;do this last!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
230 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (defun debugger-exit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (let ((debug-on-error nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (debug-on-signal nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; Tell signal to keep searching for handlers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (throw 'debugger t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ;; Called from an old version of Emacs, perhaps?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (no-catch (exit-recursive-edit))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (defun debugger-step-through ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 "Proceed, stepping through subexpressions of this expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 Enter another debugger on next entry to eval, apply or funcall."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (setq debugger-step-after-exit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (message "Proceeding, will debug on next eval or call.")
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
247 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (debugger-exit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (defun debugger-continue ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 "Continue, evaluating this expression without stopping."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (message "Continuing.")
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
254 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (debugger-exit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (defun debugger-return-value (val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 "Continue, specifying value to return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 This is only useful when the value returned from the debugger
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 will be used, such as in a debug on exit from a frame."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (interactive "XReturn value (evaluated): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (setq debugger-value val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (princ "Returning " t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (prin1 debugger-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (exit-recursive-edit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
267 ;; XEmacs: [Moved block]
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;; Chosen empirically to account for all the frames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;; that will exist when debugger-frame is called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;; within the first one that appears in the backtrace buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;; Assumes debugger-frame is called from a key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ;; will be wrong if it is called with Meta-x.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (defconst debugger-frame-offset 8 "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (defun debugger-jump ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 "Continue to exit from this frame, with all debug-on-entry suspended."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;; Compensate for the two extra stack frames for debugger-jump.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (let ((debugger-frame-offset (+ debugger-frame-offset 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (debugger-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;; Turn off all debug-on-entry functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ;; but leave them in the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (let ((list debug-function-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (fset (car list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (debug-on-entry-1 (car list) (symbol-function (car list)) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (setq list (cdr list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (message "Continuing through this frame")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (debugger-exit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (defun debugger-reenable ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 "Turn all debug-on-entry functions back on."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (let ((list debug-function-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (or (consp (symbol-function (car list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (debug-convert-byte-code (car list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (fset (car list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (debug-on-entry-1 (car list) (symbol-function (car list)) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (setq list (cdr list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (defun debugger-frame-number ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 "Return number of frames in backtrace before the one point points at."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (goto-char (point-min))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
308 ;; XEmacs:#### I18N3 will not localize properly!
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (if (or (equal (buffer-substring (point) (+ (point) 6))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (gettext "Signal"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (equal (buffer-substring (point) (+ (point) 6))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (gettext "Return")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (search-forward ":")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (forward-sexp 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (forward-char 2)
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 72
diff changeset
319 (if (eq (char-after (point)) ?\()
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (forward-sexp 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (<= (point) opoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (setq count (1+ count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (defun debugger-frame ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 "Request entry to debugger when this frame exits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 Applies to the frame whose line point is on in the backtrace."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (let ((level (debugger-frame-number)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (backtrace-debug (+ level debugger-frame-offset) t))
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 72
diff changeset
334 (if (eq (char-after (point)) ? )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (insert ?*)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (defun debugger-frame-clear ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 "Do not enter to debugger when this frame exits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 Applies to the frame whose line point is on in the backtrace."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (let ((level (debugger-frame-number)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (backtrace-debug (+ level debugger-frame-offset) nil))
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 72
diff changeset
347 (if (eq (char-after (point)) ?*)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (insert ? )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (defun debugger-eval-expression (debugger-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 "Eval an expression, in an environment like that outside the debugger."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (list (read-from-minibuffer "Eval: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 nil read-expression-map t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 'read-expression-history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (if (null (buffer-name debugger-old-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 ;; old buffer deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (setq debugger-old-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (set-buffer debugger-old-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (let ((last-command debugger-outer-last-command)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
365 (this-command debugger-outer-this-command)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
366 (unread-command-event debugger-outer-unread-command-event)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
367 (unread-command-event debugger-outer-unread-command-events)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
368 (last-input-event debugger-outer-last-input-event)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
369 (last-input-char debugger-outer-last-input-char)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
370 (last-input-time debugger-outer-last-input-time)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
371 (last-command-event debugger-outer-last-command-event)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
372 (last-command-char debugger-outer-last-command-char)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
373 (standard-input debugger-outer-standard-input)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
374 (standard-output debugger-outer-standard-output)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (cursor-in-echo-area debugger-outer-cursor-in-echo-area)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (overriding-local-map debugger-outer-overriding-local-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (load-read-function debugger-outer-load-read-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (store-match-data debugger-outer-match-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (prog1 (eval-expression debugger-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (setq debugger-outer-match-data (match-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 debugger-outer-load-read-function load-read-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 debugger-outer-overriding-local-map overriding-local-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 debugger-outer-last-command last-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 debugger-outer-this-command this-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 debugger-outer-unread-command-event unread-command-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 debugger-outer-last-input-event last-input-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 debugger-outer-last-input-char last-input-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 debugger-outer-last-input-time last-input-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 debugger-outer-last-command-event last-command-event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 debugger-outer-last-command-char last-command-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 debugger-outer-standard-input standard-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 debugger-outer-standard-output standard-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 debugger-outer-cursor-in-echo-area cursor-in-echo-area)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
395 (defvar debugger-mode-map nil)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
396 (if debugger-mode-map
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
397 nil
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
398 (let ((loop ? ))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
399 (setq debugger-mode-map (make-keymap))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
400 (suppress-keymap debugger-mode-map)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
401 (define-key debugger-mode-map "-" 'negative-argument)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
402 (define-key debugger-mode-map "b" 'debugger-frame)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
403 (define-key debugger-mode-map "c" 'debugger-continue)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
404 (define-key debugger-mode-map "j" 'debugger-jump)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
405 (define-key debugger-mode-map "r" 'debugger-return-value)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
406 (define-key debugger-mode-map "u" 'debugger-frame-clear)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
407 (define-key debugger-mode-map "d" 'debugger-step-through)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
408 (define-key debugger-mode-map "l" 'debugger-list-functions)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
409 (define-key debugger-mode-map "h" 'describe-mode)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
410 (define-key debugger-mode-map "q" 'top-level)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
411 (define-key debugger-mode-map "e" 'debugger-eval-expression)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
412 (define-key debugger-mode-map " " 'next-line)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (put 'debugger-mode 'mode-class 'special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (defun debugger-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 "Mode for backtrace buffers, selected in debugger.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 \\<debugger-mode-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 A line starts with `*' if exiting that frame will call the debugger.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 Type \\[debugger-frame] or \\[debugger-frame-clear] to set or remove the `*'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 When in debugger due to frame being exited,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 use the \\[debugger-return-value] command to override the value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 being returned from that frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 Use \\[debug-on-entry] and \\[cancel-debug-on-entry] to control
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 which functions will enter the debugger when called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 Complete list of commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 \\{debugger-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (setq major-mode 'debugger-mode)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
433 (setq mode-name (gettext "Debugger")) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (setq truncate-lines t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (set-syntax-table emacs-lisp-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (use-local-map debugger-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (defun debug-on-entry (function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 "Request FUNCTION to invoke debugger each time it is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 If you tell the debugger to continue, FUNCTION's execution proceeds.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 This works by modifying the definition of FUNCTION,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 which must be written in Lisp, not predefined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 Use \\[cancel-debug-on-entry] to cancel the effect of this command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 Redefining FUNCTION also cancels it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (interactive "aDebug on entry (to function): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (debugger-reenable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (if (subrp (symbol-function function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (error "Function %s is a primitive" function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (or (consp (symbol-function function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (debug-convert-byte-code function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (or (consp (symbol-function function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (error "Definition of %s is not a list" function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (fset function (debug-on-entry-1 function (symbol-function function) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (or (memq function debug-function-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (setq debug-function-list (cons function debug-function-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (defun cancel-debug-on-entry (&optional function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 "Undo effect of \\[debug-on-entry] on FUNCTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 If argument is nil or an empty string, cancel for all functions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (list (let ((name
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
465 (completing-read "Cancel debug on entry (to function): "
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
466 ;; Make an "alist" of the functions
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 ;; that now have debug on entry.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
468 (mapcar 'list
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
469 (mapcar 'symbol-name
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
470 debug-function-list))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 nil t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (if name (intern name)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (debugger-reenable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (if (and function (not (string= function "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (fset function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (debug-on-entry-1 function (symbol-function function) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (setq debug-function-list (delq function debug-function-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (message "Cancelling debug-on-entry for all functions")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (mapcar 'cancel-debug-on-entry debug-function-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (defun debug-convert-byte-code (function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (let ((defn (symbol-function function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (if (not (consp defn))
171
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 159
diff changeset
486 ;; Assume a compiled-function object.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 159
diff changeset
487 (let* ((body
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 159
diff changeset
488 (list (list 'byte-code
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 159
diff changeset
489 (compiled-function-instructions defn)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 159
diff changeset
490 (compiled-function-constants defn)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 159
diff changeset
491 (compiled-function-stack-depth defn)))))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 159
diff changeset
492 (if (compiled-function-interactive defn)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 159
diff changeset
493 (setq body (cons (compiled-function-interactive defn) body)))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 159
diff changeset
494 (if (compiled-function-doc-string defn)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 ;; Use `documentation' here, to get the actual string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 ;; in case the compiled function has a reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 ;; to the .elc file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (setq body (cons (documentation function) body)))
171
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 159
diff changeset
499 (fset function (cons 'lambda (cons
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 159
diff changeset
500 (compiled-function-arglist defn)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 159
diff changeset
501 body)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (defun debug-on-entry-1 (function defn flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (if (subrp defn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (error "%s is a built-in function" function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (if (eq (car defn) 'macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (debug-on-entry-1 function (cdr defn) flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (or (eq (car defn) 'lambda)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (error "%s not user-defined Lisp function" function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (let (tail prec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (if (stringp (car (nthcdr 2 defn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (setq tail (nthcdr 3 defn)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
513 prec (list (car defn) (car (cdr defn))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
514 (car (cdr (cdr defn)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (setq tail (nthcdr 2 defn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 prec (list (car defn) (car (cdr defn)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (if (eq flag (equal (car tail) '(debug 'debug)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 defn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (if flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (nconc prec (cons '(debug 'debug) tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (nconc prec (cdr tail))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (defun debugger-list-functions ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 "Display a list of all the functions now set to debug on entry."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (with-output-to-temp-buffer "*Help*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (if (null debug-function-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (princ "No debug-on-entry functions now\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (princ "Functions set to debug on entry:\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (let ((list debug-function-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (prin1 (car list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (setq list (cdr list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (princ "Note: if you have redefined a function, then it may no longer\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (princ "be set to debug on entry, even if it is in the list."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (help-mode))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 ;;; debug.el ends here