diff options
| author | Gerd Moellmann | 1999-11-03 13:43:19 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 1999-11-03 13:43:19 +0000 |
| commit | 63ca439e7f892acd6be15edbf56c418ea6654039 (patch) | |
| tree | 04813467abd4a74b40070c9ee253c0b48bea4ca1 | |
| parent | dadec482301e636433a178cf19e5227ec7314313 (diff) | |
| download | emacs-63ca439e7f892acd6be15edbf56c418ea6654039.tar.gz emacs-63ca439e7f892acd6be15edbf56c418ea6654039.zip | |
(debug): If noninteractive, display the
backtrace using `message', then exit Emacs.
(debugger-batch-max-lines): New variable.
(debugger-setup-buffer): New subroutine, broken out of `debug'.
Change the messages put at the start, to say that the debugger
was entered.
| -rw-r--r-- | lisp/emacs-lisp/debug.el | 145 |
1 files changed, 89 insertions, 56 deletions
diff --git a/lisp/emacs-lisp/debug.el b/lisp/emacs-lisp/debug.el index 41cb6c66425..db85b24a0f6 100644 --- a/lisp/emacs-lisp/debug.el +++ b/lisp/emacs-lisp/debug.el | |||
| @@ -39,6 +39,14 @@ | |||
| 39 | :group 'debugger | 39 | :group 'debugger |
| 40 | :version "20.3") | 40 | :version "20.3") |
| 41 | 41 | ||
| 42 | (defcustom debugger-batch-max-lines 40 | ||
| 43 | "*Maximum lines to show in debugger buffer in a noninteractive Emacs. | ||
| 44 | When the debugger is entered and Emacs is running in batch mode, | ||
| 45 | if the backtrace text has more than this many lines, | ||
| 46 | the middle is discarded, and just the beginning and end are displayed." | ||
| 47 | :type 'integer | ||
| 48 | :group 'debugger | ||
| 49 | :version "21.1") | ||
| 42 | 50 | ||
| 43 | (defcustom debug-function-list nil | 51 | (defcustom debug-function-list nil |
| 44 | "List of functions currently set for debug on entry." | 52 | "List of functions currently set for debug on entry." |
| @@ -87,7 +95,8 @@ You may call with no args, or you may pass nil as the first arg and | |||
| 87 | any other args you like. In that case, the list of args after the | 95 | any other args you like. In that case, the list of args after the |
| 88 | first will be printed into the backtrace buffer." | 96 | first will be printed into the backtrace buffer." |
| 89 | (interactive) | 97 | (interactive) |
| 90 | (message "Entering debugger...") | 98 | (unless noninteractive |
| 99 | (message "Entering debugger...")) | ||
| 91 | (let (debugger-value | 100 | (let (debugger-value |
| 92 | (debug-on-error nil) | 101 | (debug-on-error nil) |
| 93 | (debug-on-quit nil) | 102 | (debug-on-quit nil) |
| @@ -141,56 +150,28 @@ first will be printed into the backtrace buffer." | |||
| 141 | (save-excursion | 150 | (save-excursion |
| 142 | (save-window-excursion | 151 | (save-window-excursion |
| 143 | (pop-to-buffer debugger-buffer) | 152 | (pop-to-buffer debugger-buffer) |
| 144 | (setq buffer-read-only nil) | ||
| 145 | (erase-buffer) | ||
| 146 | (set-buffer-multibyte nil) | ||
| 147 | (let ((standard-output (current-buffer)) | ||
| 148 | (print-escape-newlines t) | ||
| 149 | (print-length 50)) | ||
| 150 | (backtrace)) | ||
| 151 | (goto-char (point-min)) | ||
| 152 | (debugger-mode) | 153 | (debugger-mode) |
| 153 | (delete-region (point) | 154 | (debugger-setup-buffer debugger-args) |
| 154 | (progn | 155 | (when noninteractive |
| 155 | (search-forward "\n debug(") | 156 | ;; If the backtrace is long, save the beginning |
| 156 | (forward-line 1) | 157 | ;; and the end, but discard the middle. |
| 157 | (point))) | 158 | (when (> (count-lines (point-min) (point-max)) |
| 159 | debugger-batch-max-lines) | ||
| 160 | (goto-char (point-min)) | ||
| 161 | (forward-line (/ 2 debugger-batch-max-lines)) | ||
| 162 | (let ((middlestart (point))) | ||
| 163 | (goto-char (point-max)) | ||
| 164 | (forward-line (- (/ 2 debugger-batch-max-lines) | ||
| 165 | debugger-batch-max-lines)) | ||
| 166 | (delete-region middlestart (point))) | ||
| 167 | (insert "...\n")) | ||
| 168 | (goto-char (point-min)) | ||
| 169 | (message (buffer-string)) | ||
| 170 | (kill-emacs)) | ||
| 171 | (if (eq (car debugger-args) 'debug) | ||
| 172 | ;; Skip the frames for backtrace-debug, byte-code, and debug. | ||
| 173 | (backtrace-debug 3 t)) | ||
| 158 | (debugger-reenable) | 174 | (debugger-reenable) |
| 159 | ;; lambda is for debug-on-call when a function call is next. | ||
| 160 | ;; debug is for debug-on-entry function called. | ||
| 161 | (cond ((memq (car debugger-args) '(lambda debug)) | ||
| 162 | (insert "Entering:\n") | ||
| 163 | (if (eq (car debugger-args) 'debug) | ||
| 164 | (progn | ||
| 165 | ;; Skip the frames for backtrace-debug, byte-code, | ||
| 166 | ;; and debug. | ||
| 167 | (backtrace-debug 3 t) | ||
| 168 | (delete-char 1) | ||
| 169 | (insert ?*) | ||
| 170 | (beginning-of-line)))) | ||
| 171 | ;; Exiting a function. | ||
| 172 | ((eq (car debugger-args) 'exit) | ||
| 173 | (insert "Return value: ") | ||
| 174 | (setq debugger-value (nth 1 debugger-args)) | ||
| 175 | (prin1 debugger-value (current-buffer)) | ||
| 176 | (insert ?\n) | ||
| 177 | (delete-char 1) | ||
| 178 | (insert ? ) | ||
| 179 | (beginning-of-line)) | ||
| 180 | ;; Debugger entered for an error. | ||
| 181 | ((eq (car debugger-args) 'error) | ||
| 182 | (insert "Signaling: ") | ||
| 183 | (prin1 (nth 1 debugger-args) (current-buffer)) | ||
| 184 | (insert ?\n)) | ||
| 185 | ;; debug-on-call, when the next thing is an eval. | ||
| 186 | ((eq (car debugger-args) t) | ||
| 187 | (insert "Beginning evaluation of function call form:\n")) | ||
| 188 | ;; User calls debug directly. | ||
| 189 | (t | ||
| 190 | (prin1 (if (eq (car debugger-args) 'nil) | ||
| 191 | (cdr debugger-args) debugger-args) | ||
| 192 | (current-buffer)) | ||
| 193 | (insert ?\n))) | ||
| 194 | (message "") | 175 | (message "") |
| 195 | (let ((inhibit-trace t) | 176 | (let ((inhibit-trace t) |
| 196 | (standard-output nil) | 177 | (standard-output nil) |
| @@ -236,6 +217,58 @@ first will be printed into the backtrace buffer." | |||
| 236 | (setq debug-on-next-call debugger-step-after-exit) | 217 | (setq debug-on-next-call debugger-step-after-exit) |
| 237 | debugger-value)) | 218 | debugger-value)) |
| 238 | 219 | ||
| 220 | (defun debugger-setup-buffer (debugger-args) | ||
| 221 | "Initialize the `*Backtrace*' buffer for entry to the debugger. | ||
| 222 | That buffer should be current already." | ||
| 223 | (setq buffer-read-only nil) | ||
| 224 | (erase-buffer) | ||
| 225 | (set-buffer-multibyte nil) | ||
| 226 | (let ((standard-output (current-buffer)) | ||
| 227 | (print-escape-newlines t) | ||
| 228 | (print-level 8) | ||
| 229 | (print-length 50)) | ||
| 230 | (backtrace)) | ||
| 231 | (goto-char (point-min)) | ||
| 232 | (delete-region (point) | ||
| 233 | (progn | ||
| 234 | (search-forward "\n debug(") | ||
| 235 | (forward-line 1) | ||
| 236 | (point))) | ||
| 237 | (insert "Debugger entered") | ||
| 238 | ;; lambda is for debug-on-call when a function call is next. | ||
| 239 | ;; debug is for debug-on-entry function called. | ||
| 240 | (cond ((memq (car debugger-args) '(lambda debug)) | ||
| 241 | (insert "--entering a function:\n") | ||
| 242 | (if (eq (car debugger-args) 'debug) | ||
| 243 | (progn | ||
| 244 | (delete-char 1) | ||
| 245 | (insert ?*) | ||
| 246 | (beginning-of-line)))) | ||
| 247 | ;; Exiting a function. | ||
| 248 | ((eq (car debugger-args) 'exit) | ||
| 249 | (insert "--returning value: ") | ||
| 250 | (setq debugger-value (nth 1 debugger-args)) | ||
| 251 | (prin1 debugger-value (current-buffer)) | ||
| 252 | (insert ?\n) | ||
| 253 | (delete-char 1) | ||
| 254 | (insert ? ) | ||
| 255 | (beginning-of-line)) | ||
| 256 | ;; Debugger entered for an error. | ||
| 257 | ((eq (car debugger-args) 'error) | ||
| 258 | (insert "--Lisp error: ") | ||
| 259 | (prin1 (nth 1 debugger-args) (current-buffer)) | ||
| 260 | (insert ?\n)) | ||
| 261 | ;; debug-on-call, when the next thing is an eval. | ||
| 262 | ((eq (car debugger-args) t) | ||
| 263 | (insert "--beginning evaluation of function call form:\n")) | ||
| 264 | ;; User calls debug directly. | ||
| 265 | (t | ||
| 266 | (insert ": ") | ||
| 267 | (prin1 (if (eq (car debugger-args) 'nil) | ||
| 268 | (cdr debugger-args) debugger-args) | ||
| 269 | (current-buffer)) | ||
| 270 | (insert ?\n)))) | ||
| 271 | |||
| 239 | (defun debugger-step-through () | 272 | (defun debugger-step-through () |
| 240 | "Proceed, stepping through subexpressions of this expression. | 273 | "Proceed, stepping through subexpressions of this expression. |
| 241 | Enter another debugger on next entry to eval, apply or funcall." | 274 | Enter another debugger on next entry to eval, apply or funcall." |
| @@ -260,6 +293,13 @@ will be used, such as in a debug on exit from a frame." | |||
| 260 | (prin1 debugger-value) | 293 | (prin1 debugger-value) |
| 261 | (exit-recursive-edit)) | 294 | (exit-recursive-edit)) |
| 262 | 295 | ||
| 296 | ;; Chosen empirically to account for all the frames | ||
| 297 | ;; that will exist when debugger-frame is called | ||
| 298 | ;; within the first one that appears in the backtrace buffer. | ||
| 299 | ;; Assumes debugger-frame is called from a key; | ||
| 300 | ;; will be wrong if it is called with Meta-x. | ||
| 301 | (defconst debugger-frame-offset 8 "") | ||
| 302 | |||
| 263 | (defun debugger-jump () | 303 | (defun debugger-jump () |
| 264 | "Continue to exit from this frame, with all debug-on-entry suspended." | 304 | "Continue to exit from this frame, with all debug-on-entry suspended." |
| 265 | (interactive) | 305 | (interactive) |
| @@ -311,13 +351,6 @@ will be used, such as in a debug on exit from a frame." | |||
| 311 | (setq count (1+ count))) | 351 | (setq count (1+ count))) |
| 312 | count))) | 352 | count))) |
| 313 | 353 | ||
| 314 | ;; Chosen empirically to account for all the frames | ||
| 315 | ;; that will exist when debugger-frame is called | ||
| 316 | ;; within the first one that appears in the backtrace buffer. | ||
| 317 | ;; Assumes debugger-frame is called from a key; | ||
| 318 | ;; will be wrong if it is called with Meta-x. | ||
| 319 | (defconst debugger-frame-offset 8 "") | ||
| 320 | |||
| 321 | (defun debugger-frame () | 354 | (defun debugger-frame () |
| 322 | "Request entry to debugger when this frame exits. | 355 | "Request entry to debugger when this frame exits. |
| 323 | Applies to the frame whose line point is on in the backtrace." | 356 | Applies to the frame whose line point is on in the backtrace." |