From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Dale P. Smith" Newsgroups: gmane.lisp.guile.user,gmane.lisp.guile.devel Subject: Re: PLEASE: debugging embedded guile code Date: Tue, 25 Feb 2003 09:36:07 -0500 Organization: Altus Technologies Corporation Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: <20030225093608.6a8935f8.dsmith@altustech.com> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1046183856 4581 80.91.224.249 (25 Feb 2003 14:37:36 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 25 Feb 2003 14:37:36 +0000 (UTC) Cc: guile-user@gnu.org Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18ngD2-0001BE-00 for ; Tue, 25 Feb 2003 15:37:28 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18ngCt-0004ib-04 for guile-user@m.gmane.org; Tue, 25 Feb 2003 09:37:19 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18ngCS-0004Yx-00 for guile-user@gnu.org; Tue, 25 Feb 2003 09:36:52 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18ngCL-0004E1-00 for guile-user@gnu.org; Tue, 25 Feb 2003 09:36:47 -0500 Original-Received: from borg.altus.cc ([208.40.56.34]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18ngC6-0003mw-00; Tue, 25 Feb 2003 09:36:30 -0500 Original-Received: from sparky (dsmith@sparky [192.168.10.14]) by borg.altus.cc (8.10.2/8.10.2) with SMTP id h1PEaCq00435; Tue, 25 Feb 2003 09:36:12 -0500 Original-To: Joris van der Hoeven In-Reply-To: X-Mailer: Sylpheed version 0.8.10claws13 (GTK+ 1.2.10; i386-debian-linux-gnu) Original-cc: guile-devel@gnu.org X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: General Guile related discussions List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.user:1691 gmane.lisp.guile.devel:1967 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:1967 On Tue, 25 Feb 2003 15:19:54 +0100 (MET) Joris van der Hoeven 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