Nikodemus Siivola | 9 Nov 2004 14:18
Picon
Picon

Re: Access to backtraces

On Tue, 9 Nov 2004, Edi Weitz wrote:

> I have the following code in TBNL[1] which is used to print backtraces
> to the logfile and/or send them to the browser.
>
>  #+:sbcl
>  (defun get-backtrace (error)
>    (declare (ignore error))
>    (with-output-to-string (s)
>      (let ((sb-debug:*debug-print-level* nil)
>            (sb-debug:*debug-print-length* nil))
>        (sb-debug:backtrace most-positive-fixnum s))))
>
> Friedrich Dominicus told me that this won't work with newer SBCL
> versions. How do I change it to make it work again and how do I
> conditionalize it to do the right thing depending on the SBCL version?

In newer SBCL versions sb-debug:*debug-print-foo* variables have been 
replaced with sb-ext:*debug-print-variable-alist* -- you can check for 
existence of that symbol with FIND-SYMBOL and act accordingly, eg:

  (let ((*debug-print-variable-alist*
         (list* '(*print-level* . nil) '(*print-length* . nil)
                *debug-print-variable-alist*)))
       ...)

However, you might be better served by sb-debug:backtrace-as-list and
something like

  (defun print-backtrace (stream &optional (from 'print-backtrace))
(Continue reading)

Edi Weitz | 9 Nov 2004 15:15
Picon
Favicon

Re: Access to backtraces

On Tue, 9 Nov 2004 15:18:53 +0200 (EET), Nikodemus Siivola <tsiivola <at> cc.hut.fi> wrote:

> In newer SBCL versions sb-debug:*debug-print-foo* variables have
> been replaced with sb-ext:*debug-print-variable-alist* -- you can
> check for existence of that symbol with FIND-SYMBOL and act
> accordingly, eg:
>
>   (let ((*debug-print-variable-alist*
>          (list* '(*print-level* . nil) '(*print-length* . nil)
>                 *debug-print-variable-alist*)))
>        ...)

Thanks, I'll add something like this.

> However, you might be better served by sb-debug:backtrace-as-list
> and something like
>
>   (defun print-backtrace (stream &optional (from 'print-backtrace))
>     (let* ((stack (sb-debug:backtrace-as-list))
>            (top (or (position from stack :key #'car) -1))
>            (count -1))
>       (with-standard-io-syntax
>        (dolist (frame (nthcdr (1+ top) stack))
>           (format stream "~D: ~A~%" (incf count) frame)))))
>
> ...as this should work equally well in both older and newer SBCL's,
> and is a bit more customizable to boot.

Yeah, but it doesn't look as nice... :)

(Continue reading)


Gmane