From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Bruce Korb Newsgroups: gmane.lisp.guile.user,gmane.lisp.guile.devel Subject: Re: PLEASE: debugging embedded guile code Date: Mon, 28 Apr 2003 13:06:51 -0700 Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: <3EAD89DB.9B0A1367@veritas.com> References: <20030225093608.6a8935f8.dsmith@altustech.com> <3EAAB691.6AD935B5@veritas.com> <3EAAE877.7140ECB6@veritas.com> Reply-To: bkorb@veritas.com 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 1051560537 27800 80.91.224.249 (28 Apr 2003 20:08:57 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 28 Apr 2003 20:08:57 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Apr 28 22:08:55 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 19AEvn-0007E3-00 for ; Mon, 28 Apr 2003 22:08:55 +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 19AEwa-0005q1-06 for guile-user@m.gmane.org; Mon, 28 Apr 2003 16:09:44 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 19AEvH-0005G1-00 for guile-user@gnu.org; Mon, 28 Apr 2003 16:08:23 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 19AEua-0004o0-00 for guile-user@gnu.org; Mon, 28 Apr 2003 16:07:42 -0400 Original-Received: from bay-bridge.veritas.com ([143.127.3.10] helo=mtvmime03.VERITAS.COM) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19AEtt-0004aR-00; Mon, 28 Apr 2003 16:06:57 -0400 Original-Received: from megami (unverified) by mtvmime03.VERITAS.COM ; Mon, 28 Apr 2003 13:07:12 -0700 Original-Received: from veritas.com(ellen.veritas.com[10.180.88.137]) (4052 bytes) by megami via sendmail with P:esmtp/R:smart_host/T:smtp (sender: ) id for ; Mon, 28 Apr 2003 13:06:56 -0700 (PDT) (Smail-3.2.0.101 1997-Dec-17 #15 built 2001-Aug-30) X-Mailer: Mozilla 4.8 [en] (X11; U; SunOS 5.8 sun4u) X-Accept-Language: en Original-To: Neil Jerram Original-cc: guile-user@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:1863 gmane.lisp.guile.devel:2230 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2230 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 "") > (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 "" 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. :) _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user