unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Neil Jerram <neil@ossau.uklinux.net>
Cc: guile-user@gnu.org
Subject: Re: Getting scheme error informations when running scheme code from C
Date: Sun, 11 Sep 2005 00:50:51 +0100	[thread overview]
Message-ID: <87fysceb38.fsf@ossau.uklinux.net> (raw)
In-Reply-To: <432351D1.8010102@ufoot.org> (Christian Mauduit's message of "Sat, 10 Sep 2005 23:36:17 +0200")

Christian Mauduit <ufoot@ufoot.org> 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
    (begin
      (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
              thunk
              lazy-catch-handler)

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.

Regards,
        Neil



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


  parent reply	other threads:[~2005-09-10 23:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-10 13:22 Getting scheme error informations when running scheme code from C Christian Mauduit
2005-09-10 14:33 ` Alan Grover
2005-09-10 21:36   ` Christian Mauduit
2005-09-10 23:40     ` Alan Grover
2005-09-11 20:19       ` Christian Mauduit
2005-09-11 21:12         ` Stephen Compall
2005-09-10 23:50     ` Neil Jerram [this message]
2005-09-12 12:11       ` Ludovic Courtès
2005-09-12 18:49         ` Neil Jerram

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fysceb38.fsf@ossau.uklinux.net \
    --to=neil@ossau.uklinux.net \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).