source: trunk/j/src/org/armedbear/lisp/debug.lisp @ 5162

Last change on this file since 5162 was 5162, checked in by piso, 18 years ago

TPL::*BREAK-LEVEL* => EXT:*DEBUG-LEVEL*

File size: 2.0 KB
Line 
1;;; debug.lisp
2;;;
3;;; Copyright (C) 2003 Peter Graves
4;;; $Id: debug.lisp,v 1.12 2003-12-16 14:37:57 piso Exp $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20(in-package "EXTENSIONS")
21
22(export '(*debug-condition* *debug-level*))
23
24(defvar *debug-condition* nil)
25
26(defvar *debug-level* 0)
27
28(in-package "SYSTEM")
29
30(defun debug-loop ()
31  (let ((*debug-level* (1+ *debug-level*)))
32  (fresh-line *debug-io*)
33  (%format *debug-io* "Type :CONTINUE to return from break or :RESET to return to top level.~%")
34    (loop
35      (catch 'debug-loop-catcher
36        (handler-case
37            (tpl::repl)
38          (error (c) (%format t "Error: ~S.~%" c) (break) (throw 'debug-loop-catcher nil)))))))
39
40(defun invoke-debugger (condition)
41  (when *debugger-hook*
42    (let ((hook-function *debugger-hook*)
43          (*debugger-hook* nil))
44      (funcall hook-function condition hook-function)))
45  (setf *debug-condition* condition)
46  (when condition
47    (fresh-line *debug-io*)
48    (%format *debug-io* "Debugger invoked on condition of type ~A:~%" (type-of condition))
49    (%format *debug-io* "  ~A~%" condition))
50  (catch 'tpl::continue-catcher
51    (clear-input)
52    (debug-loop)))
53
54(defun break (&optional format-control &rest format-arguments)
55  (fresh-line *debug-io*)
56  (%format *debug-io* "BREAK called.~%")
57  (if format-control
58      (apply #'%format *debug-io* format-control format-arguments))
59  (invoke-debugger nil))
Note: See TracBrowser for help on using the repository browser.