[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting scheme error informations when running scheme code from C

From: Neil Jerram
Subject: Re: Getting scheme error informations when running scheme code from C
Date: Sun, 11 Sep 2005 00:50:51 +0100
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Christian Mauduit <address@hidden> writes:

> mmm, OK I see, indeed using:
> (debug-enable 'debug)
> (debug-enable 'backtrace)
> gave me much more detailed output, thanks for the tip.

FWIW, I use this at the start of my Scheme script (which is also
loaded by a C program - very similar overall structure to yours):

(debug-set! stack 100000)
(if #t
      (read-enable 'positions)
      (debug-enable 'debug)
      (debug-enable 'backtrace)
      (debug-set! frames 8)
      (debug-set! depth 50)))

> Well, using lazy-catch and a handler with the line:
> (display-backtrace (make-stack #t) some-user-string-output-port)
> actually got me very close from solving my problem completely. The only
> point is that the stack I obtain contains many useless things (such as
> the actual functions I'm using within the error handler, which are
> useless...) so I get a garbaged output. I guess there's some way to get
> rid of this by passing cryptic arguments to make-stack.

Not that cryptic; you just pass either an integer or a procedure.  If
you always have 5 frames of your own error handling, for example, then
you just need to say (make-stack #t 5).  The procedure approach
usually looks something like this:

  (define (lazy-catch-handler key . args)
    (let ((stack (make-stack #t lazy-catch-handler)))
      ;; do whatever you want with stack, such as
      ;; saving it off or calling display-backtrace
    (apply throw key args))
  (lazy-catch #t

In this case the lazy-catch-handler arg to make-stack means "throw
away all the innermost frames up to and including the
lazy-catch-handler frame".

> BTW trying to
> handle the object returned by make-stack and produce a string output "by
> hand" from it sounded awfully hairy to me. Wee.

Why awfully hairy?  A stack is just a list of frames, and there are
procedures available for getting all the interesting information about
each frame ... how would you improve this?

> If I get an elegant solution to my problem, I'll try to package it and
> make a short text on the question, by searching the web I found out that
> I'm not the only one to wish to handle his errors himself, but the
> tutorial does not seem to be written yet 8-)

Writing a tutorial for this area would indeed be very helpful!

Finally, you might like to know that my guile-debugging package
includes a kind of Emacs display-backtrace front end.  In other words,
when an error occurs, the stack is popped up in Emacs, and Emacs will
pop up the source code for each frame, and so on.  Although the raw
backtrace information is the same (as if you just do a
display-backtrace to some port), I've found this front end to be
effective in allowing me to analyze backtraces very quickly.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]