guile-devel
[Top][All Lists]
Advanced

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

Re: PLEASE: debugging embedded guile code


From: Bruce Korb
Subject: Re: PLEASE: debugging embedded guile code
Date: Mon, 28 Apr 2003 13:06:51 -0700

Neil Jerram wrote:
> 
> Does this help?

Yes.  A lot.  I think I know why I didn't think of it before, though.  :-)

> OK, I understand.  There are three parts to the answer that I think
> you need.
> 
> 1. You want an evaluator with a catch handler,
>    e.g. gh_eval_str_with_catch, instead of plain gh_eval_str, which
>    just exits.

I knew that, but didn't have a good idea about how to make it work.

> 2. The handler needs to call display-error, which is the function that
>    displays all the useful information.

OK.

> 3. In order for display-error to show maximum useful information, the
>    port that the source code came from must have a name.
>    Unfortunately the current default is that string ports are unnamed.
> 
> If I were you, I'd do as much of this as possible in Scheme, e.g.:
> 
> (use-modules (ice-9 stack-catch))
> 
> (define (eval-client-input str)
>   (stack-catch #t
>     (lambda ()
>       (call-with-input-string str
>         (lambda (p)
>           (set-port-filename! p "<string port>")
>           (list (primitive-eval (read p))))))
>     (lambda (key . args)
>       ;; [1]
>       (apply display-error (fluid-ref the-last-stack)
>                            (current-error-port)
>                            args)
>       (set! stack-saved? #f)
>       #f)))

except instead of "<string port>" I'd supply the name of the
file I was reading to get the Scheme code.  Right near [1]
I would want to add the starting line number to the evaluator's
notion of what the current line number is.  If I'm on line 100
of my clients input text, it would be nice for the display-error
code to display a line number 99 higher than otherwise.  I'd
do this by using some of my own functions:

> (define (eval-client-input str)
>   (stack-catch #t
>     (lambda ()
>       (call-with-input-string str
>         (lambda (p)
>           (set-port-filename! p (tpl-file))
>           (SET-PORT-FILELINE! p (string->number (tpl-file-line "%2$d")))
>           (list (primitive-eval (read p))))))
>     (lambda (key . args)
>       ;; [1]
>       (apply display-error (fluid-ref the-last-stack)
>                            (current-error-port)
>                            args)
>       (set! stack-saved? #f)
>       #f)))

> Basic testing...  [[elided]]

> You can call `eval-client-input' from C using scm_c_lookup and
> scm_call_1.
> 
> Note - the code above assumes that `args' has the right structure (see
> doc for display-error), which is true for all the exceptions generated
> by Guile itself.  If you want to handle exceptions generated by your
> own or your client's code, you need to add code at [1] to identify
> non-core exceptions and turn their throw args into suitable parameters
> for display-error.

I think I'd want to test for a client error list massaging procedure
and invoke that if present.  The only places I throw errors, I call
scm_wrong_type_arg directly.  I would guess it would have args set up okay. :)




reply via email to

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