Changeset 4190


Ignore:
Timestamp:
10/04/03 10:53:35 (19 years ago)
Author:
piso
Message:

Work in progress.

Location:
trunk/j/src/org/armedbear/lisp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/debug.lisp

    r4157 r4190  
    22;;;
    33;;; Copyright (C) 2003 Peter Graves
    4 ;;; $Id: debug.lisp,v 1.4 2003-10-01 13:59:23 piso Exp $
     4;;; $Id: debug.lisp,v 1.5 2003-10-04 10:53:35 piso Exp $
    55;;;
    66;;; This program is free software; you can redistribute it and/or
     
    2020(in-package "SYSTEM")
    2121
    22 (defun debug-prompt (stream)
    23   (format stream "~%> "))
     22(defun debug-loop ()
     23  (let ((tpl::*break-level* (1+ tpl::*break-level*)))
     24  (fresh-line *debug-io*)
     25  (format *debug-io* "Type :CONTINUE to return from break or :RESET to return to top level.~%")
     26    (loop
     27      (catch 'debug-loop-catcher
     28        (handler-case
     29            (tpl::repl)
     30          (error (c) (format t "Error: ~S.~%" c) (break) (throw 'debug-loop-catcher nil)))))))
    2431
    2532(defun invoke-debugger (condition)
     
    2835          (*debugger-hook* nil))
    2936      (funcall hook-function condition hook-function)))
    30   (catch 'continue
    31     (debugger-loop)))
    32 
    33 (defun debugger-loop ()
    34   (fresh-line *debug-io*)
    35   (format *debug-io* "Type :continue to continue...")
    36   (loop
    37     (catch 'debug-loop-catcher
    38       (handler-bind ((error (lambda (condition)
    39                               (format *debug-io* "~%Error: ~S.~%" condition)
    40                               (throw 'debug-loop-catcher nil))))
    41         (debug-prompt *debug-io*)
    42         (finish-output *debug-io*)
    43         (let* ((exp (read *debug-io*)))
    44           (when (memq exp '(:co :continue))
    45             (return-from debugger-loop))
    46           (let* ((values (multiple-value-list (eval exp)))
    47                  (*standard-output* *debug-io*))
    48             (fresh-line)
    49             (if values (prin1 (car values)))
    50             (dolist (x (cdr values))
    51               (fresh-line)
    52               (prin1 x))))))))
     37  (catch 'tpl::continue-catcher
     38    (debug-loop)))
    5339
    5440(defun break (&optional format-control &rest format-arguments)
    5541  (fresh-line *debug-io*)
    56   (format *debug-io* "break called~%")
     42  (format *debug-io* "BREAK called.~%")
    5743  (invoke-debugger nil))
  • trunk/j/src/org/armedbear/lisp/top-level.lisp

    r4079 r4190  
    22;;;
    33;;; Copyright (C) 2003 Peter Graves
    4 ;;; $Id: top-level.lisp,v 1.2 2003-09-26 19:19:14 piso Exp $
     4;;; $Id: top-level.lisp,v 1.3 2003-10-04 10:53:26 piso Exp $
    55;;;
    66;;; This program is free software; you can redistribute it and/or
     
    2222(in-package "EXTENSIONS")
    2323
    24 (export '(*saved-backtrace* bt))
     24(export '(*saved-backtrace*))
    2525
    2626(defvar *saved-backtrace* nil)
    2727
    28 (defun bt (&optional count)
    29   (let ((count (if (fixnump count) count 7))
    30         (n 0))
    31     (dolist (frame *saved-backtrace*)
    32       (format t "  ~D: ~A~%" n frame)
    33       (incf n)
    34       (when (>= n count)
    35         (return))))
    36   (values))
    37 
    3828(in-package "TOP-LEVEL")
     29
     30(defvar *break-level* 0)
    3931
    4032(defparameter *command-char* #\:)
     
    5143(defun repl-prompt-fun (stream)
    5244  (fresh-line stream)
     45  (when (> *break-level* 0)
     46    (format stream "[~D] " *break-level*))
    5347  (write-string (prompt-package-name) stream)
    5448  (write-string "(" stream)
     
    8377    (push (subseq string 0 end) res)))
    8478
     79(defun backtrace-command (&optional count)
     80  (let ((count (if (fixnump count) count 7))
     81        (n 0))
     82    (dolist (frame *saved-backtrace*)
     83      (format t "  ~D: ~A~%" n frame)
     84      (incf n)
     85      (when (>= n count)
     86        (return))))
     87  (values))
     88
     89(defun continue-command ()
     90  (if (> *break-level* 0)
     91      (throw 'continue-catcher nil)))
     92
     93(defun reset-command ()
     94  (throw 'top-level-catcher nil))
     95
    8596(defun process-cmd (form)
    8697  (when (and (stringp form) (> (length form) 1) (eql (char form 0) *command-char*))
     
    92103        (when (zerop (length args))
    93104          (setf args nil)))
    94       (cond ((string= cmd "ld")
     105      (cond ((string-equal cmd "ld")
    95106             (let ((files (if args (tokenize args) *last-files-loaded*)))
    96107               (setf *last-files-loaded* files)
     
    98109                 (load file)))
    99110             )
    100             ((string= cmd "de")
     111            ((string-equal cmd "de")
    101112             (let ((obj (eval (read-from-string args))))
    102113               (describe obj)))
    103             ((string= cmd "ap")
     114            ((string-equal cmd "ap")
    104115             (apropos args))
    105             ((string= cmd "pwd")
     116            ((string-equal cmd "pwd")
    106117             (format t "~A~%" *default-pathname-defaults*))
    107             ((string= cmd "cd")
     118            ((string-equal cmd "cd")
    108119             (cond ((or (null args) (string= args "~"))
    109120                    (setf args (namestring (user-homedir-pathname))))
     
    118129                     (format *standard-output* "~A" (namestring *default-pathname-defaults*)))
    119130                   (format *standard-output* "Error: no such directory (~S).~%" args))))
    120             ((string= cmd "bt")
    121              (let ((count (or (and args (ignore-errors (parse-integer args))) 7)))
    122                (bt count)))
    123             ((string= cmd "pa")
     131            ((string-equal cmd "bt")
     132             (let ((count (or (and args (ignore-errors (parse-integer args))) most-positive-fixnum)))
     133               (backtrace-command count)))
     134            ((string-equal cmd "pa")
    124135             (cond ((null args)
    125136                    (format *standard-output* "The ~A package is current.~%"
     
    133144                          (setf *package* pkg)
    134145                          (format *standard-output* "Unknown package ~A.~%" args))))))
    135             ((string= cmd "ex")
     146            ((or (string-equal cmd "cont") (string-equal cmd "continue"))
     147             (continue-command))
     148            ((or (string-equal cmd "res") (string-equal cmd "reset"))
     149             (reset-command))
     150            ((string-equal cmd "ex")
    136151             (format t "Bye!~%")
    137152             (exit))
     
    169184  (values-list /))
    170185
    171 (defun repl-fun ()
     186(defun repl ()
    172187  (loop
    173188    (funcall *repl-prompt-fun* *standard-output*)
     
    181196        (prin1 result)))))
    182197
    183 (defvar *in-top-level-loop* nil)
    184 
    185198(defun top-level-loop ()
    186   (setf *in-top-level-loop* t)
    187   (loop
    188     (catch 'top-level
     199  (loop
     200    (catch 'top-level-catcher
    189201      (handler-case
    190           (repl-fun)
    191         (error (c) (format t "Error: ~S.~%" c) (break) (throw 'top-level nil))))))
     202          (repl)
     203        (stream-error (c) (return-from top-level-loop))
     204        (error (c) (format t "Error: ~S.~%" c) (break) (throw 'top-level-catcher nil))))))
Note: See TracChangeset for help on using the changeset viewer.