From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Grover Newsgroups: gmane.lisp.guile.user Subject: Re: Getting scheme error informations when running scheme code from C Date: Sat, 10 Sep 2005 10:33:30 -0400 Message-ID: <4322EEBA.1090202@mail.msen.com> References: <4322DE2C.60801@ufoot.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1126363387 788 80.91.229.2 (10 Sep 2005 14:43:07 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 10 Sep 2005 14:43:07 +0000 (UTC) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Sep 10 16:42:56 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EE6ZA-0003lX-ST for guile-user@m.gmane.org; Sat, 10 Sep 2005 16:42:53 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EE6ZA-00066l-3d for guile-user@m.gmane.org; Sat, 10 Sep 2005 10:42:52 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EE6Ya-0005u2-OT for guile-user@gnu.org; Sat, 10 Sep 2005 10:42:17 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EE6YQ-0005pE-Um for guile-user@gnu.org; Sat, 10 Sep 2005 10:42:12 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EE6YP-0005hh-7i for guile-user@gnu.org; Sat, 10 Sep 2005 10:42:05 -0400 Original-Received: from [148.59.80.48] (helo=ww8.msen.com) by monty-python.gnu.org with esmtp (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.34) id 1EE6QL-000386-OB for guile-user@gnu.org; Sat, 10 Sep 2005 10:33:45 -0400 X-Sent-To: Original-Received: from [192.168.1.220] (pool-151-196-115-140.balt.east.verizon.net [151.196.115.140]) (authenticated bits=0) by ww8.msen.com (8.13.4/8.13.4) with ESMTP id j8AEXVhq089614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sat, 10 Sep 2005 10:33:31 -0400 (EDT) (envelope-from awgrover@mail.msen.com) User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en Original-To: guile-user@gnu.org In-Reply-To: <4322DE2C.60801@ufoot.org> X-Milter: Spamilter (Reciever: ww8.msen.com; Sender-ip: 151.196.115.140; Sender-helo: [192.168.1.220]; ) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:4733 Archived-At: 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. > _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user