1997-05-16 09:14:45 +00:00
|
|
|
|
;;;; Copyright (C) 1996, 1997 Free Software Foundation
|
1996-08-23 04:54:35 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
;;;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
;;;; the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
|
;;;; any later version.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
;;;; GNU General Public License for more details.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
|
;;;; along with this software; see the file COPYING. If not, write to
|
* COPYING, boot-9.scm, debug.scm, emacs.scm, expect.scm, gtcl.scm,
gwish.scm, hcons.scm, lineio.scm, mapping.scm, nonblocking.scm,
oldprint.scm, poe.scm, r4rs.scm, source.scm, tags.scm, test.scm,
threads.scm: New address for FSF.
1997-05-26 22:26:48 +00:00
|
|
|
|
;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
|
|
;;;; Boston, MA 02111-1307 USA
|
1996-08-23 04:54:35 +00:00
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; The author can be reached at djurfeldt@nada.kth.se
|
|
|
|
|
|
;;;; Mikael Djurfeldt, SANS/NADA KTH, 10044 STOCKHOLM, SWEDEN
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
1997-06-24 16:26:27 +00:00
|
|
|
|
(define-module (ice-9 debug))
|
1996-08-23 04:54:35 +00:00
|
|
|
|
|
1997-08-24 03:32:43 +00:00
|
|
|
|
|
|
|
|
|
|
;;; {Misc}
|
|
|
|
|
|
;;;
|
|
|
|
|
|
(define-public (frame-number->index n)
|
|
|
|
|
|
(if (memq 'backwards (debug-options))
|
|
|
|
|
|
n
|
1998-06-13 18:08:25 +00:00
|
|
|
|
(- (stack-length (fluid-ref the-last-stack)) n 1)))
|
1997-08-24 03:32:43 +00:00
|
|
|
|
|
1996-10-14 03:28:35 +00:00
|
|
|
|
|
* * debug.scm: *Warning* This feature is a bit premature. I add
it anyway because 1. it is very useful, and, 2. you can start
making it less premature by complaining to me and by modifying
the source! :-)
(trace): Given one or more procedure objects, trace each one.
Given no arguments, show all traced procedures.
(untrace): Given one or more procedure objects, untrace each one.
Given no arguments, untrace all traced procedures. The tracing in
Guile have an advantage to most other systems: We don't create new
procedure objects, but mark the procedure objects themselves.
This means that also anonymous and internal procedures can be
traced.
* boot-9.scm (error-catching-loop): Added handling of apply-frame
and exit-frame exceptions.
* * boot-9.scm (assert-repl-prompt, the-prompt-string): Removed.
(set-repl-prompt!): Setter for repl prompt.
(scm-style-repl): If prompt is #f, don't prompt; if prompt is a
string, display it; if prompt is a thunk, call it and display its
result; otherwise display "> ".
(Change suggested by Roland Orre <orre@nada.kth.se>.)
1997-02-28 23:11:22 +00:00
|
|
|
|
;;; {Trace}
|
|
|
|
|
|
;;;
|
1997-03-01 14:26:57 +00:00
|
|
|
|
;;; This code is just an experimental prototype (e. g., it is not
|
|
|
|
|
|
;;; thread safe), but since it's at the same time useful, it's
|
|
|
|
|
|
;;; included anyway.
|
|
|
|
|
|
;;;
|
* * debug.scm: *Warning* This feature is a bit premature. I add
it anyway because 1. it is very useful, and, 2. you can start
making it less premature by complaining to me and by modifying
the source! :-)
(trace): Given one or more procedure objects, trace each one.
Given no arguments, show all traced procedures.
(untrace): Given one or more procedure objects, untrace each one.
Given no arguments, untrace all traced procedures. The tracing in
Guile have an advantage to most other systems: We don't create new
procedure objects, but mark the procedure objects themselves.
This means that also anonymous and internal procedures can be
traced.
* boot-9.scm (error-catching-loop): Added handling of apply-frame
and exit-frame exceptions.
* * boot-9.scm (assert-repl-prompt, the-prompt-string): Removed.
(set-repl-prompt!): Setter for repl prompt.
(scm-style-repl): If prompt is #f, don't prompt; if prompt is a
string, display it; if prompt is a thunk, call it and display its
result; otherwise display "> ".
(Change suggested by Roland Orre <orre@nada.kth.se>.)
1997-02-28 23:11:22 +00:00
|
|
|
|
(define traced-procedures '())
|
|
|
|
|
|
|
|
|
|
|
|
(define-public (trace . args)
|
|
|
|
|
|
(if (null? args)
|
|
|
|
|
|
(nameify traced-procedures)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(for-each (lambda (proc)
|
1997-03-01 14:53:27 +00:00
|
|
|
|
(if (not (procedure? proc))
|
|
|
|
|
|
(error "trace: Wrong type argument:" proc))
|
* * debug.scm: *Warning* This feature is a bit premature. I add
it anyway because 1. it is very useful, and, 2. you can start
making it less premature by complaining to me and by modifying
the source! :-)
(trace): Given one or more procedure objects, trace each one.
Given no arguments, show all traced procedures.
(untrace): Given one or more procedure objects, untrace each one.
Given no arguments, untrace all traced procedures. The tracing in
Guile have an advantage to most other systems: We don't create new
procedure objects, but mark the procedure objects themselves.
This means that also anonymous and internal procedures can be
traced.
* boot-9.scm (error-catching-loop): Added handling of apply-frame
and exit-frame exceptions.
* * boot-9.scm (assert-repl-prompt, the-prompt-string): Removed.
(set-repl-prompt!): Setter for repl prompt.
(scm-style-repl): If prompt is #f, don't prompt; if prompt is a
string, display it; if prompt is a thunk, call it and display its
result; otherwise display "> ".
(Change suggested by Roland Orre <orre@nada.kth.se>.)
1997-02-28 23:11:22 +00:00
|
|
|
|
(set-procedure-property! proc 'trace #t)
|
|
|
|
|
|
(if (not (memq proc traced-procedures))
|
|
|
|
|
|
(set! traced-procedures
|
|
|
|
|
|
(cons proc traced-procedures))))
|
|
|
|
|
|
args)
|
|
|
|
|
|
(set! apply-frame-handler trace-entry)
|
|
|
|
|
|
(set! exit-frame-handler trace-exit)
|
|
|
|
|
|
(set! trace-level 0)
|
|
|
|
|
|
(debug-enable 'trace)
|
|
|
|
|
|
(nameify args))))
|
|
|
|
|
|
|
|
|
|
|
|
(define-public (untrace . args)
|
|
|
|
|
|
(if (and (null? args)
|
|
|
|
|
|
(not (null? traced-procedures)))
|
|
|
|
|
|
(apply untrace traced-procedures)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(for-each (lambda (proc)
|
|
|
|
|
|
(set-procedure-property! proc 'trace #f)
|
|
|
|
|
|
(set! traced-procedures (delq! proc traced-procedures)))
|
|
|
|
|
|
args)
|
|
|
|
|
|
(if (null? traced-procedures)
|
|
|
|
|
|
(debug-disable 'trace))
|
|
|
|
|
|
(nameify args))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (nameify ls)
|
|
|
|
|
|
(map (lambda (proc)
|
|
|
|
|
|
(let ((name (procedure-name proc)))
|
|
|
|
|
|
(or name proc)))
|
|
|
|
|
|
ls))
|
|
|
|
|
|
|
|
|
|
|
|
(define trace-level 0)
|
1997-03-01 01:34:23 +00:00
|
|
|
|
(add-hook! abort-hook (lambda () (set! trace-level 0)))
|
* * debug.scm: *Warning* This feature is a bit premature. I add
it anyway because 1. it is very useful, and, 2. you can start
making it less premature by complaining to me and by modifying
the source! :-)
(trace): Given one or more procedure objects, trace each one.
Given no arguments, show all traced procedures.
(untrace): Given one or more procedure objects, untrace each one.
Given no arguments, untrace all traced procedures. The tracing in
Guile have an advantage to most other systems: We don't create new
procedure objects, but mark the procedure objects themselves.
This means that also anonymous and internal procedures can be
traced.
* boot-9.scm (error-catching-loop): Added handling of apply-frame
and exit-frame exceptions.
* * boot-9.scm (assert-repl-prompt, the-prompt-string): Removed.
(set-repl-prompt!): Setter for repl prompt.
(scm-style-repl): If prompt is #f, don't prompt; if prompt is a
string, display it; if prompt is a thunk, call it and display its
result; otherwise display "> ".
(Change suggested by Roland Orre <orre@nada.kth.se>.)
1997-02-28 23:11:22 +00:00
|
|
|
|
|
|
|
|
|
|
(define (trace-entry key cont tail)
|
1997-03-01 14:26:57 +00:00
|
|
|
|
(if (eq? (stack-id cont) 'repl-stack)
|
|
|
|
|
|
(let ((cep (current-error-port))
|
|
|
|
|
|
(frame (last-stack-frame cont)))
|
|
|
|
|
|
(if (not tail)
|
|
|
|
|
|
(set! trace-level (+ trace-level 1)))
|
|
|
|
|
|
(let indent ((n trace-level))
|
|
|
|
|
|
(cond ((> n 1) (display "| " cep) (indent (- n 1)))))
|
1997-03-08 02:29:45 +00:00
|
|
|
|
(display-application frame cep)))
|
1997-03-01 14:26:57 +00:00
|
|
|
|
(debug-enable 'trace)
|
|
|
|
|
|
;; It's not necessary to call the continuation since
|
|
|
|
|
|
;; execution will continue if the handler returns
|
|
|
|
|
|
;(cont #f)
|
|
|
|
|
|
)
|
* * debug.scm: *Warning* This feature is a bit premature. I add
it anyway because 1. it is very useful, and, 2. you can start
making it less premature by complaining to me and by modifying
the source! :-)
(trace): Given one or more procedure objects, trace each one.
Given no arguments, show all traced procedures.
(untrace): Given one or more procedure objects, untrace each one.
Given no arguments, untrace all traced procedures. The tracing in
Guile have an advantage to most other systems: We don't create new
procedure objects, but mark the procedure objects themselves.
This means that also anonymous and internal procedures can be
traced.
* boot-9.scm (error-catching-loop): Added handling of apply-frame
and exit-frame exceptions.
* * boot-9.scm (assert-repl-prompt, the-prompt-string): Removed.
(set-repl-prompt!): Setter for repl prompt.
(scm-style-repl): If prompt is #f, don't prompt; if prompt is a
string, display it; if prompt is a thunk, call it and display its
result; otherwise display "> ".
(Change suggested by Roland Orre <orre@nada.kth.se>.)
1997-02-28 23:11:22 +00:00
|
|
|
|
|
|
|
|
|
|
(define (trace-exit key cont retval)
|
1997-03-01 14:26:57 +00:00
|
|
|
|
(if (eq? (stack-id cont) 'repl-stack)
|
|
|
|
|
|
(let ((cep (current-error-port)))
|
|
|
|
|
|
(set! trace-level (- trace-level 1))
|
|
|
|
|
|
(let indent ((n trace-level))
|
|
|
|
|
|
(cond ((> n 0) (display "| " cep) (indent (- n 1)))))
|
|
|
|
|
|
(write retval cep)
|
|
|
|
|
|
(newline cep)))
|
|
|
|
|
|
(debug-enable 'trace))
|
* * debug.scm: *Warning* This feature is a bit premature. I add
it anyway because 1. it is very useful, and, 2. you can start
making it less premature by complaining to me and by modifying
the source! :-)
(trace): Given one or more procedure objects, trace each one.
Given no arguments, show all traced procedures.
(untrace): Given one or more procedure objects, untrace each one.
Given no arguments, untrace all traced procedures. The tracing in
Guile have an advantage to most other systems: We don't create new
procedure objects, but mark the procedure objects themselves.
This means that also anonymous and internal procedures can be
traced.
* boot-9.scm (error-catching-loop): Added handling of apply-frame
and exit-frame exceptions.
* * boot-9.scm (assert-repl-prompt, the-prompt-string): Removed.
(set-repl-prompt!): Setter for repl prompt.
(scm-style-repl): If prompt is #f, don't prompt; if prompt is a
string, display it; if prompt is a thunk, call it and display its
result; otherwise display "> ".
(Change suggested by Roland Orre <orre@nada.kth.se>.)
1997-02-28 23:11:22 +00:00
|
|
|
|
|
1997-03-01 14:26:57 +00:00
|
|
|
|
|
|
|
|
|
|
;;; A fix to get the error handling working together with the module system.
|
|
|
|
|
|
;;;
|
|
|
|
|
|
(variable-set! (builtin-variable 'debug-options) debug-options)
|
|
|
|
|
|
|
* * debug.scm: *Warning* This feature is a bit premature. I add
it anyway because 1. it is very useful, and, 2. you can start
making it less premature by complaining to me and by modifying
the source! :-)
(trace): Given one or more procedure objects, trace each one.
Given no arguments, show all traced procedures.
(untrace): Given one or more procedure objects, untrace each one.
Given no arguments, untrace all traced procedures. The tracing in
Guile have an advantage to most other systems: We don't create new
procedure objects, but mark the procedure objects themselves.
This means that also anonymous and internal procedures can be
traced.
* boot-9.scm (error-catching-loop): Added handling of apply-frame
and exit-frame exceptions.
* * boot-9.scm (assert-repl-prompt, the-prompt-string): Removed.
(set-repl-prompt!): Setter for repl prompt.
(scm-style-repl): If prompt is #f, don't prompt; if prompt is a
string, display it; if prompt is a thunk, call it and display its
result; otherwise display "> ".
(Change suggested by Roland Orre <orre@nada.kth.se>.)
1997-02-28 23:11:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
1996-11-02 20:51:37 +00:00
|
|
|
|
(debug-enable 'debug)
|
|
|
|
|
|
(read-enable 'positions)
|