[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: |
Alan Grover |
Subject: |
Re: Getting scheme error informations when running scheme code from C |
Date: |
Sat, 10 Sep 2005 10:33:30 -0400 |
User-agent: |
Mozilla Thunderbird 1.0.2 (X11/20050317) |
My comments are for Guile version 1.6.4.
To get a backtrace, you want something that does the same thing as the
--debug option. However:
"Using the debugging evaluator will give you better error messages but
it will slow down execution."
So, you don't want it in production-code.
I believe this will turn on the debug-evaluator at run-time (so the
documentation implies):
(debug-enable 'debug)
Hope that causes a stack-trace for you. See "Configuration, Features and
Runtime Options" in the documentation, subsection "Debugger Options".
Have you considered using "catch" to catch errors (or "lazy-catch")? You
could wrap your scheme code in a "catch", or use scm_catch. Section "How
to Handle Errors in C Code" has some hints. Lazy-catch lets you capture
the stack.
I don't see a mechanism for adding a "catch" for primitive-load. The
empty documentation for "REPL Hooks" is suggestive. So, use scm_catch,
or "eval" something like:
(catch #t
(lambda () (primitive-load ...))
(lambda (key . args) (deal with error here)))
(of course, you could add a function that does this to the top-level and
just call it.)
You may also find the section "Debugging Infrastructure" interesting. It
talks about decoding the stack, and limiting the backtrace.
Lazy-catch will let you examine the stack as it exists at the time of
the throw/exception. You could dump the stack with "display-backtrace"
or programatically try to find the relevant stack-frame (an interesting
problem since tail calls may-not generate a frame). See section
"Examining the Stack".
Christian Mauduit wrote:
> ...
> Here's my
> problem: when there's an error in scheme code, Guile terminates my
> program immediately and gives me an error message which is often not
> precise enough for proper debugging. Here's an example, with code
> excerpts (full code on http://ufoot.hd.free.fr/snapshot/pub/ , project
> liquidwar6).
>
> When I run scheme code from C code, placing on purpose an error in the
> scheme code (I add a "(car ())" line in some random place) and call it with:
> ---------8<------------------------------------------------
> scm_c_primitive_load (script);
> ---------8<------------------------------------------------
> with script a char * pointing to "src/script/liquidwar6.scm"
>
> I get the following output:
> ---------8<------------------------------------------------
> liquidwar6: registering C functions for Guile
> liquidwar6: loading "src/script/liquidwar6.scm"
> ERROR: missing or extra expression
> ---------8<------------------------------------------------
> The lines with liquidwar6: are output from my C program, using C log
> functions. The line with "ERROR" is an output from Guile, which
> terminates the program. As a side note the fact that it terminates the
> program is a bit annoying, since I would like to "trap" this message.
> Indeed a windows user will never read console output, and if I want
> proper bug reports from players, I'd better display this message in a popup.
>
> Then this message is a little "light" for proper debugging. When I'll
> have 10000 lines of scheme code, it will be impossible to track bugs
> without informations like line number for instance.
>
> Point is if I call "load" are "primitive-load" from the Guile
> interpreter I get much more information:
>
> ---------8<------------------------------------------------
> guile> (load "src/script/liquidwar6.scm")
> src/script/loop.scm:20:1: While evaluating arguments to car in
> expression (car ()):
> src/script/loop.scm:20:1: missing or extra expression
> ABORT: (misc-error)
>
> Type "(backtrace)" to get more information or "(debug)" to enter the
> debugger.
> guile>
> ---------8<------------------------------------------------
>
> ---------8<------------------------------------------------
> guile> (primitive-load "src/script/liquidwar6.scm")
> src/script/loop.scm:20:1: While evaluating arguments to car in
> expression (car ()):
> src/script/loop.scm:20:1: missing or extra expression
> ABORT: (misc-error)
> guile>
> ---------8<------------------------------------------------
>
> This would be very fine: filename, line number, code excerpt, these are
> the very informations I need.
>
> Anyone would have an idea on how to:
> 1) trap, redirecet or place a hook on the Guile "error handler" (if such
> a handler exists?) and get these errors in C, and then decide what to do
> with it.
> 2) actually get precise error informations (file, line, source, error
> description) the way the interactive Guile interpreter does.
>
> I read the Guile manual, but:
> http://www.gnu.org/software/guile/docs/guile-ref/Debugging-Features.html
> and:
> http://www.gnu.org/software/guile/docs/guile-ref/Hooks.html
> did not solve my problem. At least I couldn't find a solution reading them.
>
> Any clue?
>
> Thanks in advance,
>
> Christian.
>