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

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

Work in progress.

File size: 2.0 KB
Line 
1;;; debug.lisp
2;;;
3;;; Copyright (C) 2003 Peter Graves
4;;; $Id: debug.lisp,v 1.11 2003-12-14 17:16:04 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*)
23
24(defvar *debug-condition* nil)
25
26(in-package "SYSTEM")
27
28(defun debug-loop ()
29  (let ((tpl::*break-level* (1+ tpl::*break-level*)))
30  (fresh-line *debug-io*)
31  (%format *debug-io* "Type :CONTINUE to return from break or :RESET to return to top level.~%")
32    (loop
33      (catch 'debug-loop-catcher
34        (handler-case
35            (tpl::repl)
36          (error (c) (%format t "Error: ~S.~%" c) (break) (throw 'debug-loop-catcher nil)))))))
37
38(defun invoke-debugger (condition)
39  (when *debugger-hook*
40    (let ((hook-function *debugger-hook*)
41          (*debugger-hook* nil))
42      (funcall hook-function condition hook-function)))
43  (setf *debug-condition* condition)
44  (when condition
45    (fresh-line *debug-io*)
46    (%format *debug-io* "Debugger invoked on condition of type ~A:~%" (type-of condition))
47    (%format *debug-io* "  ~A~%" condition))
48  (catch 'tpl::continue-catcher
49    (clear-input)
50    (debug-loop)))
51
52(defun break (&optional format-control &rest format-arguments)
53  (fresh-line *debug-io*)
54  (%format *debug-io* "BREAK called.~%")
55  (if format-control
56      (apply #'%format *debug-io* format-control format-arguments))
57  (invoke-debugger nil))
Note: See TracBrowser for help on using the repository browser.