9 Nov 2004 14:18
Re: Access to backtraces
Nikodemus Siivola <tsiivola <at> cc.hut.fi>
2004-11-09 13:18:53 GMT
2004-11-09 13:18:53 GMT
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))
(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.
Cheers,
-- Nikodemus Schemer: "Buddha is small, clean, and serious."
Lispnik: "Buddha is big, has hairy armpits, and laughs."
-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
RSS Feed