annotate lisp/prim/debug.el @ 5:49b78a777eb4

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