Hi,
I am working on delivery of my app. I case it runs into an unexpected error I'd like to log these errors to a file. No Problem so
far. It would be better if I could write a backtrace as well.
Is there a standard way of creating a backtrace under program control?
If not can you give any hints?
Andreas
"Andreas Thiele" <······@nospam.com> writes:
> Is there a standard way of creating a backtrace under program control?
No.
> If not can you give any hints?
Have a look at the sources of swank (slime) to see how you can
programmatically collect the backtrace in the various implementations
it supports.
--
__Pascal Bourguignon__ http://www.informatimago.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d? s++:++ a+ C+++ UL++++ P--- L+++ E+++ W++ N+++ o-- K- w---
O- M++ V PS PE++ Y++ PGP t+ 5+ X++ R !tv b+++ DI++++ D++
G e+++ h+ r-- z?
------END GEEK CODE BLOCK------
On Thu, 04 Jan 2007 12:43:04 +0100, Andreas Thiele wrote:
> Hi,
>
> I am working on delivery of my app. I case it runs into an unexpected error I'd like to log these errors to a file. No Problem so
> far. It would be better if I could write a backtrace as well.
>
> Is there a standard way of creating a backtrace under program control?
> If not can you give any hints?
SBCL has `(sb-debug:backtrace-as-list)' etc.
--
Lars Rune Nøstdal
http://nostdal.org/
"Andreas Thiele" <······@nospam.com> writes:
> Hi,
>
> I am working on delivery of my app. I case it runs into an unexpected error I'd like to log these errors to a file. No Problem so
> far. It would be better if I could write a backtrace as well.
>
> Is there a standard way of creating a backtrace under program control?
> If not can you give any hints?
>
I also do that. Using swank you can have portability. Take a look at
the source code of ucw (thanks to Marco Baringer). I usually use:
(defun run ()
(handler-case
(your-main-entry-point-function)
(error (condition) (send-backtrace condition (collect-backtrace condition)))))
(defstruct backtrace-frame
index
description
locals
source-location)
(defun collect-backtrace (condition)
(let ((swank::*swank-debugger-condition* condition)
(swank::*buffer-package* *package*))
(swank::call-with-debugging-environment
(lambda ()
(loop
for (index desc) in (swank:backtrace 1 500) ; get the first 500 frames
collect (make-backtrace-frame :index index
:description desc
:source-location (if (numberp index)
(swank:frame-source-location-for-emacs index)
index)
:locals (swank-backend::frame-locals index)))))))
(defun send-backtrace (condition backtrace)
(with-output-to-string (s)
(dolist (frame backtrace)
(format t "--- FRAME ~D~%" (backtrace-frame-index frame))
(write-line (backtrace-frame-description frame) t)
(write-line "--- Locals:" t)
(dolist (local (backtrace-frame-locals frame))
(format t "~S ==> ~S~%" (getf local :name) (getf local :value)))
(write-line "--- Source:" t)
(format t "~S~%" (backtrace-frame-source-location frame)))
s))