Re: Creating backtrace under program control?
On Jan 4, 2007, at 6:58 AM, Andreas Thiele wrote:
Hi,
does LispWorks offer facilities to generate a backtrace under program
control?
(I didn't find any hint in the docu)
I'd like my delivered app to catch all errors and write good information
into a file.
Andreas
Andreas,
The code below is what we use in our client's product to produce backtraces. The feature :no-debugger, whose name has been changed to protect the client's identity, is present when we deliver the application at level 5 (i.e., when the debugger is removed).
At level 5, we deliver with the option
:keep-function-name :minimal
which leaves enough information in the application to make backtraces readable.
- Gary Palter
Principal Software Engineer
Clozure Associates
Cell: 617-947-0536
_______________________________________________________________________________
(defun bug-form (condition)
(flet ((all-processes-backtrace ()
(let ((first-process? t)
(skip? nil)
(first-frame? t))
(with-output-to-string (stream)
(flet ((doit (item)
(cond ((typep item 'mp:process)
(cond ((eql item mp:*current-process*)
(setf skip? t))
(t
(when (shiftf first-process? nil)
(format stream "~%Other Processes:"))
(setf skip? nil
first-frame? t)
(format stream "~2% Process: ~A~% "
(mp:process-name item)))))
(skip?)
(t
(unless (shiftf first-frame? nil)
(write-string " <- " stream))
(format stream "~S" item)))))
(mp:map-all-processes-backtrace #'doit))))))
(let ((*default-character-element-type* 'simple-char))
#+no-debugger
(format nil "DESCRIPTION: ~A~2%SOFTWARE VERSION: ~A~2%Backtrace:~%~A~2%~A"
condition
(software-version)
(with-output-to-string (stream)
(dbg::simple-output-backtrace :stream stream))
(with-output-to-string (*standard-output*)
(room t)))
#-no-debugger
(let* ((backtrace (with-output-to-string (stream)
(dbg:output-backtrace :bug-form :stream stream)))
(form (with-output-to-string (*debug-io*)
(dbg:bug-report-form t
(format nil "~A" condition)
:impact "Broken" :urgency "ASAP")))
(position (search +use-bb+ form :test #'char-equal)))
(when position
(setf form (concatenate-strings (subseq form 0 position)
(string #\Newline)
backtrace
(subseq form (+ position (length +use-bb+))))))
(concatenate-strings (subseq form (+ (length "------------------------------") 2))
(all-processes-backtrace)
(string #\Newline))))))