home *** CD-ROM | disk | FTP | other *** search
- ; debug.l - Copyright (c) 1984 by David Morein.
- ;
- ; this file contains miscellaneous debugger support routines.
- ;
- ; note - this is an initialization file, see the manual for more info.
- ;
- (pdq /sys/cmd)
- ;
- ;global functions:
- ;
- (global
- 'debugq
- 'debug
- 'debugset
- 'baktrace
- 'showstack
- 'trace
- 'untrace
- 'reset)
- ;
- ;
- ; local variables:
- (setq *tracelevel* 0)
- ;
- ; debugq - same as debug except that it quotes its argument.
- ;
- (def debugq (nlambda (e)
- (debug e)))
- ;
- ; debug - evaluates an argument in a debugging environment
- ;
- (defun debug (e &aux olderrlbl result)
- (progn
- (setq olderrlbl (status error_label)) ;save entry value ierrlbl
- (status error_label nil) ;disable internal error label
- (setq result (eval e)) ;evaluate e
- (status error_label olderrlbl) ;restore internal error label
- result)) ;return the result
- ;
- ; debugset - sets up a debugging environment.
- ;
- (def debugset (nlambda (x)
- (cond
- (x
- (progn ;x non-NIL => disable debugging
- (status error_label nil) ;reset error label
- (status smash_hook t) ;turn on macro displacement
- t)) ;return t
- (t
- (progn ;x NIL => enable debugging
- (status error_label 'errset) ;set error label
- (status smash_hook nil) ;turn off macro displacement
- t))))) ;return t
- ;
- ;
- ; baktrace - outputs an abbreviated back-trace of the stack,
- ; showing only function names.
- ;
- (defun baktrace (&optional n)
- (cond
- (n (bt_print_list (firstn n (cdddr (cdddr (cdddr (baktrce 0)))))))
- (t (bt_print_list (cdddr (cdddr (cdddr (baktrce 0))))))))
- ;
- ;
- ; bt_print_list - outputs a list for baktrace
- ;
- (defun bt_print_list (l)
- (cond
- ((null l) t)
- (t
- (progn
- (cond
- ((atom (car l)) (print (car l)))
- (t (print (caar l))))
- (terpri)
- (bt_print_list (cdr l))))))
- ;
- ;
- ; showstack - outputs a complete back trace.
- ; if n is specified, then only n frames
- ; are printed; otherwise, the entire
- ; stack is printed.
- ;
- (defun showstack (&optional n)
- (cond
- (n (shstk_print_list (firstn n (cdddr (cdddr (cdddr (baktrce 0)))))))
- (t (shstk_print_list (cdddr (cdddr (cdddr (baktrce 0))))))))
- ;
- ;
- (def trace (nlambda (&rest fnlist)
- (mapcar '*trace1 fnlist)))
- ;
- ;
- (defun *trace1 (tfn &aux lambda-exp)
- (cond ;check that tfn is not already being traced
- ((get 'trace tfn) nil) ;if tfn being traced, return NIL
- (t ;otherwise ...
- (cond ;check that tfn is bound as a function
- ((not (fboundp tfn)) nil) ;if not, return NIL
- (t ;otherwise ...
- (progn
- ;
- ; save tfn's old definition on TRACE's property list, and alter
- ; tnf's function definition cell.
- ;
- (setq lambda-exp (symbol-function tfn))
- (putprop 'trace lambda-exp tfn)
- ;
- ; if no error is generated during the call to trace-alter,
- ; return T; otherwise, return NIL:
- ;
- (cond
- ((errset (putd tfn (trace-alter tfn))) t)
- (t nil)))))) ))
- ;
- ;
- ; trace-alter - produces a new function definition for traced symbols
- ;
- ; for some function foo, we want trace-alter to expand it to:
- ;
- ; (progn
- ; (princ "entering ")
- ; (unprint 'foo)
- ; (unprinc " ")
- ; (unprint actuals)
- ; (terpri)
- ; (setq *trace_result (funcall (get 'trace 'traced_function) actuals))
- ; (princ "exiting ")
- ; (unprint 'foo)
- ; (unprinc " ")
- ; (unprint *trace_result)
- ; (terpri)
- ; *trace_result)
- ;
- (defun trace-alter (tfn &aux *trace_result l-exp discipline parameters)
- (progn
- (setq l-exp (symbol-function tfn))
- (setq discipline (car l-exp))
- (setq parameters
- (cond
- ((or
- (eql discipline 'lambda)
- (eql discipline 'nlambda))
- (cadr l-exp))
- (t
- (err "***> TRACE-ALTER: untraceable function discipline."))))
- (list discipline parameters
- (list 'progn
- ;
- ; output "entering <fn-name> <actual parameter list>"
- ;
- (list 'indent_princ '*tracelevel* (list "entering "))
- (list 'unprint (list quote tfn))
- (list 'unprinc " ")
- (list
- 'unprint
- (cond
- ((or (eql discipline 'lambda) (eql discipline 'nlambda))
- (list 'tr-evlist (list 'quote parameters)))
- (t
- (err "***> TRACE: bad discipline."))))
- (list 'terpri)
- (list 'setq '*tracelevel* (list '+ '*tracelevel* 1))
- (list
- 'setq '*trace_result
- (list 'apply
- (list
- 'get
- (list quote 'trace)
- (list quote tfn))
- (list 'evlist (list 'quote parameters))))
- (list 'setq '*tracelevel* (list '- '*tracelevel* 1))
- (list 'indent_princ '*tracelevel* (list "exiting "))
- (list 'unprint (list quote tfn))
- (list 'unprinc " ")
- (list 'unprint '*trace_result)
- (list 'terpri)
- '*trace_result))))
- ;
- ; untrace - untraces a list of functions
- ;
- (def untrace (nlambda (&rest fnlist)
- (mapcar '*untrace1 fnlist)))
- ;
- ; *untrace1 - untraces a single function
- ;
- (defun *untrace1 (fn)
- (cond ;check that fn is being traced.
- ((get 'trace fn)
- (progn ;fn is being traced.
- (putd fn (get 'trace fn)) ;restore original fn def.
- (remprop 'trace fn) ;remove marker on TRACE's plist
- t)) ;return T
- (t nil))) ;return NIL, fn not traced.
- ;
- ;
- ; tr-evlist - evaluates a list for TRACE. The tricky thing that
- ; this function does (and the reason that we couldn't use EVLIST
- ; in TRACE), is that it properly handles lambda-list keywords
- ; like &AUX.
- ;
- (defun tr-evlist (tr-list)
- (cond
- ((eq (car tr-list) '&aux) 'nil)
- ((eq (car tr-list) '&rest) (cdr tr-list))
- ((null tr-list) 'nil)
- (t (cons (eval (car tr-list)) (tr-evlist (cdr tr-list)))))))
- ;
- ; indent_print - indents a new line & prints an object
- ;
- (defun indent_print (indent object)
- (progn
- (space_to_col (* indent 2))
- (unprint object)))
- ;
- ; indent_princ - indents a new line & prints an object
- ;
- (defun indent_princ (indent object)
- (progn
- (space_to_col (* indent 2))
- (unprinc object)))
- ;
- ;
- ; shstk_print_list - prints out a list of frames for showstack
- ;
- (defun shstk_print_list (l)
- (cond
- ((atom l) t)
- (t
- (progn
- (pp (car l))
- (terpri)
- (terpri)
- (princ "<--------------- frame --------------->")
- (terpri)
- (shstk_print_list (cdr l))))))
- ;
- ;
- ; reset - throws control back to toplevel
- ;
- (def reset (nlambda (&optional (e nil))
- (progn
- (status break_level 0)
- (debugset nil)
- (throw '?*toplevel*? e))))
- ;
- ;
- (popd) ;return to entry directory
- ;
- ;**************************** end of debug.l ****************************
-