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 19:40:41 -0400 Message-ID: <43236EF9.5050400@mail.msen.com> References: <4322DE2C.60801@ufoot.org> <4322EEBA.1090202@mail.msen.com> <432351D1.8010102@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 1126397220 11205 80.91.229.2 (11 Sep 2005 00:07:00 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 11 Sep 2005 00:07:00 +0000 (UTC) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Sep 11 02:06:52 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EEFME-00038x-JC for guile-user@m.gmane.org; Sun, 11 Sep 2005 02:06:06 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EEFMD-00013U-4Y for guile-user@m.gmane.org; Sat, 10 Sep 2005 20:06:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EEFJ3-0008Uo-PF for guile-user@gnu.org; Sat, 10 Sep 2005 20:02:50 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EEFJ1-0008U1-SP for guile-user@gnu.org; Sat, 10 Sep 2005 20:02:48 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EEFJ1-0008EI-7e for guile-user@gnu.org; Sat, 10 Sep 2005 20:02:47 -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 1EEExx-0000rv-Ar for guile-user@gnu.org; Sat, 10 Sep 2005 19:41:01 -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 j8ANegW0091916 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sat, 10 Sep 2005 19:40:43 -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: <432351D1.8010102@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:4736 Archived-At: Christian Mauduit wrote: > ... > Well, using lazy-catch and a handler with the line: > > (display-backtrace (make-stack #t) some-user-string-output-port) > > actually got me very close from solving my problem completely. The only > point is that the stack I obtain contains many useless things (such as > the actual functions I'm using within the error handler, which are > useless...) so I get a garbaged output. I guess there's some way to get > rid of this by passing cryptic arguments to make-stack. BTW trying to > handle the object returned by make-stack and produce a string output "by > hand" from it sounded awfully hairy to me. Wee. If we assume that the catch'ing lambda is always the same, then the stack-frames related to it should be stable. So, you should be able to discard the bottom n frames every time: For example: (lazy-catch #t (lambda () (+ 1 (hubert))) (lambda (key . args) (let ((s (make-stack #t))) (display (list key args)) (newline) (display-backtrace s (current-output-port) (- (stack-length s) 1) (- (stack-length s) 3))) (newline) (display "throw on") (newline) (throw 'bob))) Always truncates the stack at the "(hubert)" call (i.e. trims off the lazy-catch). Note the need to subtract 1 from stack-length for the "first" argument of display-backtrace. The documentation is not clear: the "first" argument is "how far back" to start (i.e. 1 would mean "1 before bottom"), "depth" is number of frames to display. Since I know I want to discard the last 3 (by examination), I subtracted 3 from the stack-length. Capture the stack as the first thing in the catch-lambda, then the "trim" is stable as you elaborate the body. Note that changing the debugger option 'frames will possibly change the depth. Probably some other debug/runtime things will disturb it too. It does look like you could auto-magically "do the right thing" with args to make-stack. Then you could use "display-error". I don't know how to provide the right args to make-stack, however. I had already decoded the frame for my own purposes (a logging function), so here's the code above plus it outputs the decoded frame info (I don't claim this is bullet proof!): (lazy-catch #t (lambda () (+ 1 (hubert))) (lambda (key . args) (let* ( (s (make-stack #t)) (bottom-frames-to-trim 3) (frame-of-interest (stack-ref s bottom-frames-to-trim)) (source-me (frame-source frame-of-interest)) (fname (and source-me (source-property source-me 'filename))) (procedure (frame-procedure (frame-of-interest)) (source-line (and source-me (1+ (source-property source-me 'line)))) ) (display (list key args)) (newline) (display-backtrace s (current-output-port) (- (stack-length s) 1) (- (stack-length s) bottom-frames-to-trim)) (newline) (display ; the decoded frame (list "file" fname "line" source-line "argument-of" procedure "source" (if (memoized? source-me) (unmemoize source-me) source-me))) (newline) (display "throw on") (newline) (throw 'bob)))) Remove the parens from "(hubert)" to see a more interesting "argument-of" value. > > If I get an elegant solution to my problem, I'll try to package it and > make a short text on the question, by searching the web I found out that > I'm not the only one to wish to handle his errors himself, but the > tutorial does not seem to be written yet 8-) > > Have a nice day and thanks for your help, > > Christian. > _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user