chicken-users
[Top][All Lists]
Advanced

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

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


From: Graham Fawcett
Subject: [Chicken-users] Debugging -- truncating the call-history report?
Date: Thu, 25 May 2006 19:35:52 -0400

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?

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.




reply via email to

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