On Tue, 9 Nov 2004, Edi Weitz wrote:
> I have the following code in TBNL which is used to print backtraces
> to the logfile and/or send them to the browser.
> (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:
(list* '(*print-level* . nil) '(*print-length* . nil)
However, you might be better served by sb-debug:backtrace-as-list and
(defun print-backtrace (stream &optional (from 'print-backtrace))
(let* ((stack (sb-debug:backtrace-as-list))
(top (or (position from stack :key #'car) -1))
(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.
-- Nikodemus Schemer: "Buddha is small, clean, and serious."
Lispnik: "Buddha is big, has hairy armpits, and laughs."