From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.devel,gmane.lisp.guile.user Subject: Re: PLEASE: debugging embedded guile code Date: 28 Apr 2003 20:21:47 +0100 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: References: <20030225093608.6a8935f8.dsmith@altustech.com> <3EAAB691.6AD935B5@veritas.com> <3EAAE877.7140ECB6@veritas.com> <3EAC5266.23DEEB7F@veritas.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1051557851 14843 80.91.224.249 (28 Apr 2003 19:24:11 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 28 Apr 2003 19:24:11 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Apr 28 21:24:09 2003 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 19AEES-0003r6-00 for ; Mon, 28 Apr 2003 21:24:09 +0200 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 19AEEr-00085X-02 for guile-devel@m.gmane.org; Mon, 28 Apr 2003 15:24:33 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 19AEEY-00082p-00 for guile-devel@gnu.org; Mon, 28 Apr 2003 15:24:14 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 19AEDs-0007P3-00 for guile-devel@gnu.org; Mon, 28 Apr 2003 15:23:33 -0400 Original-Received: from mail.uklinux.net ([80.84.72.21] helo=s1.uklinux.net) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19AEDp-0007N0-00; Mon, 28 Apr 2003 15:23:29 -0400 Original-Received: from laruns.ossau.uklinux.net (bts-0591.dialup.zetnet.co.uk [194.247.50.79]) by s1.uklinux.net (8.11.6p2/8.11.6) with ESMTP id h3SJNPW06115; Mon, 28 Apr 2003 20:23:25 +0100 Original-Received: from laruns.ossau.uklinux.net.ossau.uklinux.net (localhost [127.0.0.1])ESMTP id BADFEDC4D4; Mon, 28 Apr 2003 20:21:48 +0100 (BST) Original-To: Bruce Korb In-Reply-To: <3EAC5266.23DEEB7F@veritas.com> Original-Lines: 96 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 Original-cc: guile-user@gnu.org X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2229 gmane.lisp.guile.user:1862 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2229 >>>>> "Bruce" == Bruce Korb writes: Bruce> I guess I'm really lazy. I'm interested in playing with my project Bruce> and I'm completely _un_interested in figuring out the inner workings Bruce> of Guile error handling. But I have a problem. Sometimes my clients Bruce> provide my project with a scheme script that is many lines long. Bruce> I merrily hand the whole string off to gh_eval_str() to deal with. Bruce> Somewhere in that string, Guile becomes confused and says, "this is Bruce> confusing" and calls exit(3C). My client emails me and says, "Your Bruce> program said it was confused but won't tell me where or why." Well, Bruce> I do print out where the Scheme script starts, but not where in the Bruce> script the confusion was. It's adequate for me because I generally Bruce> keep my Scheme scripts to under a half dozen lines. It's a problem. Bruce> So, what I would really like: Bruce> Explicit, unambiguous directions on exactly how to get the Guile library Bruce> to print out the same error messages it does when running as part Bruce> of the "guile" independent program. [...] 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. 2. The handler needs to call display-error, which is the function that displays all the useful information. 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 "") (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... guile> (eval-client-input "(define foo bar)") :1:1: In expression (define foo bar): :1:1: Unbound variable: bar #f guile> (eval-client-input "(let ((x 1)) (* x x unknown))") :1:14: While evaluating arguments to * in expression (* x x ...): :1:14: Unbound variable: unknown #f guile> (eval-client-input "\ ... (for-each (lambda (x) ... (display (* x x)) ... (newline)) ... number-list) ... ") :1:1: While evaluating arguments to for-each in expression (for-each (lambda # # ...) number-list): :1:1: Unbound variable: number-list #f guile> (eval-client-input "\ ... (for-each (lambda (x) ... (display (* x x)) ... (newline)) ... (cdr number-list)) ... ") :4:11: While evaluating arguments to cdr in expression (cdr number-list): :4:11: Unbound variable: number-list #f 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. Does this help? Neil _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel