From: ckonstanski
Subject: Common Lisp: printing the backtrace as well as the error message
Date: 
Message-ID: <1157937558.008589.227850@i3g2000cwc.googlegroups.com>
I am writing a webapp in SBCL.  In a webapp, you do not ever want to
enter the debugger.  Instead, you want a full error dump to appear in
your logs, and the user should get sent to a nice error page.

Using the following FORMAT, I can get the error message.  But I would
also like to print the entire backtrace.

(format t "Error while rendering page: ~A" error)

The question I have is, how do I print the backtrace of an error?

From: Pascal Bourguignon
Subject: Re: Common Lisp: printing the backtrace as well as the error message
Date: 
Message-ID: <87wt8buon5.fsf@thalassa.informatimago.com>
"ckonstanski" <···········@pippiandcarlos.com> writes:

> I am writing a webapp in SBCL.  In a webapp, you do not ever want to
> enter the debugger.  Instead, you want a full error dump to appear in
> your logs, and the user should get sent to a nice error page.
>
> Using the following FORMAT, I can get the error message.  But I would
> also like to print the entire backtrace.
>
> (format t "Error while rendering page: ~A" error)
>
> The question I have is, how do I print the backtrace of an error?

Have a look at the sources of araneida or ucw. 
They output the backtrace on a web page.

Also: (apropos :backtrace) can help.
For example:

#+sbcl (SB-DEBUG:BACKTRACE-AS-LIST)
#+clisp (with-output-to-string (s) (system::print-backtrace :out s))

Not mentionning the documentation of your implementation...

-- 
__Pascal_Bourguignon__               _  Software patents are endangering
()  ASCII ribbon against html email (o_ the computer industry all around
/\  1962:DO20I=1.100                //\ the world http://lpf.ai.mit.edu/
    2001:my($f)=`fortune`;          V_/   http://petition.eurolinux.org/
From: Rob Warnock
Subject: Re: Common Lisp: printing the backtrace as well as the error message
Date: 
Message-ID: <2KednbBCJJKLT5nYnZ2dnUVZ_v2dnZ2d@speakeasy.net>
Pascal Bourguignon  <···@informatimago.com> wrote:
+---------------
| Also: (apropos :backtrace) can help.
| For example:
| #+sbcl (SB-DEBUG:BACKTRACE-AS-LIST)
| #+clisp (with-output-to-string (s) (system::print-backtrace :out s))
+---------------

Or in CMUCL, one of these:

  #+cmu (debug:backtrace)
  #+cmu (with-output-to-string (s) (debug:backtrace 100 s)

The full signature is:

  debug:backtrace (&optional (count most-positive-fixnum)
			     (*standard-output* *debug-io*))


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Thomas A. Russ
Subject: Re: Common Lisp: printing the backtrace as well as the error message
Date: 
Message-ID: <ymik64a8l1a.fsf@sevak.isi.edu>
Pascal Bourguignon <···@informatimago.com> writes:

> "ckonstanski" <···········@pippiandcarlos.com> writes:
> 
> > The question I have is, how do I print the backtrace of an error?
> 
> Have a look at the sources of araneida or ucw. 
> They output the backtrace on a web page.
> 
> Also: (apropos :backtrace) can help.
> For example:
> 
> #+sbcl (SB-DEBUG:BACKTRACE-AS-LIST)
> #+clisp (with-output-to-string (s) (system::print-backtrace :out s))

Expanding on this, this is one area where different implementations have
their own methods.  In some of our code, we identified the following
implementation-dependent methods:

(cl:defun %%print-exception-context (condition stream)
  ;; System dependent printing of error context
  (cl:declare (cl:ignore condition))
  (cl:let ((cl:*debug-io* stream))
    #+:EXCL (tpl::zoom-print-stack-1 stream 20)
    #+:MCL  (ccl:print-call-history)
    #+:CMU  (debug:backtrace)
    #+:SBCL (sb-debug:backtrace)
    ))

I now get to add the CLISP version.  :)



-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Raffael Cavallaro
Subject: Re: Common Lisp: printing the backtrace as well as the error message
Date: 
Message-ID: <2006091114140443658-raffaelcavallaro@pasdespamsilvousplaitmaccom>
On 2006-09-11 11:45:05 -0400, ···@sevak.isi.edu (Thomas A. Russ) said:

> Expanding on this, this is one area where different implementations have
> their own methods.  In some of our code, we identified the following
> implementation-dependent methods:
> 
> (cl:defun %%print-exception-context (condition stream)
>   ;; System dependent printing of error context
>   (cl:declare (cl:ignore condition))
>   (cl:let ((cl:*debug-io* stream))
>     #+:EXCL (tpl::zoom-print-stack-1 stream 20)
>     #+:MCL  (ccl:print-call-history)
>     #+:CMU  (debug:backtrace)
>     #+:SBCL (sb-debug:backtrace)
>     ))
> 
> I now get to add the CLISP version.  :)

and lispworks:

 #+:LISPWORKS (dbg:output-backtrace :stream stream)
From: Thomas A. Russ
Subject: Re: Common Lisp: printing the backtrace as well as the error message
Date: 
Message-ID: <ymi8xkq80fj.fsf@sevak.isi.edu>
Raffael Cavallaro <················@pas-d'espam-s'il-vous-plait-mac.com> writes:

> On 2006-09-11 11:45:05 -0400, ···@sevak.isi.edu (Thomas A. Russ) said:
> 

> > (cl:defun %%print-exception-context (condition stream)
> >   ;; System dependent printing of error context
> >   (cl:declare (cl:ignore condition))
> >   (cl:let ((cl:*debug-io* stream))
> >     #+:EXCL (tpl::zoom-print-stack-1 stream 20)
> >     #+:MCL  (ccl:print-call-history)
> >     #+:CMU  (debug:backtrace)
> >     #+:SBCL (sb-debug:backtrace)
> >     ))
> > I now get to add the CLISP version.  :)
> 
> 
> and lispworks:
> 
>  #+:LISPWORKS (dbg:output-backtrace :stream stream)

Oh goody, another one!

-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Jock Cooper
Subject: Re: Common Lisp: printing the backtrace as well as the error message
Date: 
Message-ID: <m3lkoprjzg.fsf@jcooper02.sagepub.com>
Raffael Cavallaro <················@pas-d'espam-s'il-vous-plait-mac.com> writes:

> On 2006-09-11 11:45:05 -0400, ···@sevak.isi.edu (Thomas A. Russ) said:
> 
> > Expanding on this, this is one area where different implementations have
> > their own methods.  In some of our code, we identified the following
> > implementation-dependent methods:
> > (cl:defun %%print-exception-context (condition stream)
> >   ;; System dependent printing of error context
> >   (cl:declare (cl:ignore condition))
> >   (cl:let ((cl:*debug-io* stream))
> >     #+:EXCL (tpl::zoom-print-stack-1 stream 20)
> >     #+:MCL  (ccl:print-call-history)
> >     #+:CMU  (debug:backtrace)
> >     #+:SBCL (sb-debug:backtrace)
> >     ))
> > I now get to add the CLISP version.  :)
> 
> and lispworks:
> 
>  #+:LISPWORKS (dbg:output-backtrace :stream stream)


#+acl (let ((*terminal-io* stream))
        (tpl:do-command "zoom" :from-read-eval-print-loop nil :count t :all t)
        *terminal-io*)