chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Debugging -- truncating the call-history report?


From: Kon Lovett
Subject: Re: [Chicken-users] Debugging -- truncating the call-history report?
Date: Fri, 26 May 2006 08:46:13 -0700

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On May 25, 2006, at 4:35 PM, Graham Fawcett wrote:

First, let me ask the short question: when an uncaught exception
occurs, is there a way to prevent exception-handler code from
appearing in the call-history report?

Although the error-traceback output in recent versions of Chicken
is helpful, the output can still be rather dense, and finding the
offending statement in the source code can be quite difficult. To
help find an elusive bug in some of my code, I came up with this
macro, to annotate sections of code and include the annotation
before the traceback:

(define-macro (section section-name . body)
 `(handle-exceptions
   exn
   (begin
     (print (format
             "-------- unhandled error in section '~A'"
             ',section-name))
     (abort exn))
   ,@body))

For example,

(section "main"
        (let ((x 0))
          ; do something here...
          (section "divide by x"
                   (print (/ 1 x)))))

when run, will generate a division-by-zero error, but before the
traceback it will print

-------- unhandled error in section 'divide by x'
-------- unhandled error in section 'main'
Error: (/) division by zero

helping to zero in on the bug. Great, except the call-history now
looks less like this:

       <eval>          (print (/ 1 x))
       <eval>          (/ 1 x) <--

and more like this (trimmed for readability):

       <eval>          (with-exception-handler (lambda (exn)
       <eval>          (##sys#call-with-values (lambda () (le
       <eval>          ((call-with-current-continuation (lamb
       <eval>          (call-with-current-continuation (lambd
       <eval>          (with-exception-handler (lambda (exn)
       <eval>          (##sys#call-with-values (lambda () (pr
       <eval>          (print (/ 1 x))
****    <eval>          (/ 1 x)
       <eval>          (g2 (lambda () (begin (print (format "
       <eval>          (print (format "-------- unhandled err
       <eval>          (format "-------- unhandled error in s
       <eval>          (abort exn)
       <eval>          (g0 (lambda () (begin (print (format "
       <eval>          (print (format "-------- unhandled err
       <eval>          (format "-------- unhandled error in s
       <eval>          (abort exn)     <--

where the asterisks mark the actual problem statement. If
sections are nested deeply, then the problem may not appear in
the 16 lines of traceback at all.

Maybe there's a better way of doing what I'm trying to
accomplish. But failing that, it would be nice to have a
procedure like (stop-adding-stuff-to-the-traceback), so that the
exception-handler statements would not be included in the call
history. Is there a way to do this?

Don't think there is a direct way to do what you want.

You can access the call stack w/ 'get-call-chain' & parse it yourself. Good.

SRFI-12 doesn't allow replacing the 'current-exception-handler' except in a dynamic context. And even if it did the repl substitutes its' own. Bad.

So, I guess dig into the ##sys#error-handler, ##sys#current-exception- handler, ##sys#repl-*-hook stuff (look in library.scm & eval.scm).

Not what you wanted to hear.

Sorry,
Kon


Thanks,
Graham

P.S. I've also found this useful:

(define-macro (define-proc signature . body)
 (let ((proc-name (car signature)))
   `(define ,signature
      (section ,proc-name
                     ,@body))))

as a way of defining procedures with built-in sections for
error-reporting.


_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)

iD8DBQFEdyLFJJNoeGe+5O4RAhiRAJ9Yat7Uo1co/u9tdmsmTu+VXpE2XgCfWSZV
LW4uI17VoymqkD3FJILNPFc=
=h0az
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]