annotate lisp/prim/debug.el @ 70:131b0175ea99 r20-0b30

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