From: "Dale P. Smith" <dsmith@altustech.com>
Cc: guile-user@gnu.org
Subject: Re: PLEASE: debugging embedded guile code
Date: Tue, 25 Feb 2003 09:36:07 -0500 [thread overview]
Message-ID: <20030225093608.6a8935f8.dsmith@altustech.com> (raw)
In-Reply-To: <Pine.GSO.3.96.1030225150844.3895A-100000@anh>
On Tue, 25 Feb 2003 15:19:54 +0100 (MET)
Joris van der Hoeven <TeXmacs@math.u-psud.fr> wrote:
>
> Hi,
>
> I am sorry to bother you again with the same question
> as a few weeks ago, but I think that it is a crucial point
> if you want Guile to be used as an extension language.
>
> When I run Guile interactively, and my code contains an error,
> then I get a nice error message with the location (file name,
> line number, column) of the error. I would like to have
> something similar for errors which occur in embedded Guile code.
>
> So: what should I do in order to enable debugging support
> for embedded Guile code? How can I retrieve the location of
> a possible error when calling guile code from the main program?
>
> Now these questions certainly do have an answer, because it is
> possible to debug interactive programs. However, I have been
> unable to retrieve this information from the sources after
> one day of study :^((( Maybe someone can tell me at least
> who wrote the interactive Guile shell?
The answer is lazy-catch.
Normally, you would handle exceptions with catch, but by the time catch
gets the exception, all the context of the error is lost. So you need
to catch the error with lazy-catch instead, which still has the error
context. Lazy-catch is not allowed to return, you must re-throw or
abort, so you must also catch the throw from lazy-catch.
Here is how I did it in mod-guile:
SCM
mg_lazy_handler(void *data, SCM tag, SCM throw_args)
{
SCM eport = scm_current_error_port();
/* header only tag. Just return */
if (SCM_EQ_P(header_only_key, tag))
scm_ithrow(tag, throw_args, 1);
/* Error report */
scm_putc('[', eport);
scm_puts(ap_get_time(), eport);
scm_puts("] mod_guile:", eport);
if (!SCM_DEVAL_P)
scm_puts(" (enable debugging evaluator for backtrace output)", eport);
scm_putc('\n', eport);
scm_handle_by_message_noexit(data, tag, throw_args);
scm_force_output(eport);
scm_ithrow(tag, throw_args, 1);
return SCM_UNSPECIFIED; /* never returns */
}
SCM
mg_empty_handler(void *data, SCM tag, SCM args)
{
/* header only tag. Just return */
if (SCM_EQ_P(header_only_key, tag))
return SCM_UNSPECIFIED;
/* This (non SCM_UNSPECIFIED) return causes the handler to return an
error back to apache */
return SCM_BOOL_F;
}
static SCM
mg_lazy_eval_file(char *file)
{
return scm_internal_lazy_catch(SCM_BOOL_T,
(scm_t_catch_body) scm_c_primitive_load, file,
(scm_t_catch_handler) mg_lazy_handler, file);
}
static SCM
mg_eval_file(char *file)
{
return scm_internal_catch(SCM_BOOL_T,
(scm_t_catch_body) mg_lazy_eval_file, file,
(scm_t_catch_handler) mg_empty_handler, file);
}
--
Dale P. Smith
Senior Systems Consultant, | Treasurer,
Altus Technologies Corporation | Cleveland Linux Users Group
dsmith@altustech.com | http://cleveland.lug.net
440-746-9000 x239 |
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
next prev parent reply other threads:[~2003-02-25 14:36 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Pine.GSO.3.96.1030209200016.26546A-100000@anh>
2003-02-25 14:19 ` PLEASE: debugging embedded guile code Joris van der Hoeven
2003-02-25 14:36 ` Dale P. Smith [this message]
2003-04-26 14:51 ` Neil Jerram
2003-04-26 16:40 ` Bruce Korb
2003-04-26 19:12 ` Neil Jerram
2003-04-26 20:13 ` Bruce Korb
2003-04-27 20:49 ` Neil Jerram
2003-04-27 21:57 ` Bruce Korb
2003-04-28 15:54 ` Paul Jarc
2003-04-28 16:07 ` Bruce Korb
2003-04-28 19:21 ` Neil Jerram
2003-04-28 20:06 ` Bruce Korb
2003-04-28 20:58 ` Neil Jerram
2003-05-16 17:19 ` Bruce Korb
2003-05-16 19:23 ` Neil Jerram
2003-05-16 20:27 ` Bruce Korb
2003-05-16 21:21 ` Rob Browning
2003-05-16 21:56 ` Bruce Korb
2003-05-17 0:31 ` Bruce Korb
2003-05-17 2:33 ` Bruce Korb
2003-05-19 15:00 ` Paul Jarc
2003-04-28 13:52 ` Mikael Djurfeldt
2003-04-28 19:26 ` Neil Jerram
2003-04-30 0:13 ` SRFI 34 Neil Jerram
2003-05-17 0:45 ` Marius Vollmer
2003-05-17 9:39 ` Neil Jerram
2003-05-17 20:36 ` Marius Vollmer
2004-03-07 18:34 ` Neil Jerram
2003-04-26 14:45 ` PLEASE: debugging embedded guile code Neil Jerram
[not found] <Pine.GSO.4.33.0304261706460.1619-100000@sunanh>
2003-04-26 15:34 ` Neil Jerram
2003-04-26 15:40 ` Joris van der Hoeven
2003-04-26 19:30 ` Neil Jerram
2003-04-27 8:40 ` Joris van der Hoeven
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=20030225093608.6a8935f8.dsmith@altustech.com \
--to=dsmith@altustech.com \
--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).