Lisp HUG Maillist Archive

Creating backtrace under program control?

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


Re: Creating backtrace under program control?

On Thu, 4 Jan 2007 12:58:20 +0100, "Andreas Thiele" <andreas@atp-media.de> wrote:

> 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.

The source code for this function

  http://weitz.de/hunchentoot/#get-backtrace

should show you how this can be done.

Cheers,
Edi.


Re: Creating backtrace under program control?

Andreas Thiele wrote:

> does LispWorks offer facilities to generate a backtrace under program
> control?

Have a look at MP:MAP-PROCESS-BACKTRACE.  I think there's also something
that gives a more detailed backtrace, but I can't find it right now.

Arthur


Re: Creating backtrace under program control?


On 04 Jan 2007, at 12:58, 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
>

I am using the following:

(defun current-backtrace-to-string ()
   "Produce a string representation of the current stack of the  
current process"
   #+lispworks
   (with-output-to-string (out)
     (mp:map-process-backtrace mp:*current-process*
                               #'(lambda (x) (format out "~a~%" x))))
   #-lispworks
   "no-backtrace")

but this somehow only works on LWM and not on LWL, but I still need  
to file a bugreport for it (isolating the code in a testcase is a a  
lot of work ;-)
mp:map-process-backtrace is the only function that is publicly  
documented by LW, but it doesn't produce much detail.

Sven


Re: Creating backtrace under program control?

Unable to parse email body. Email id is 6303

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))))))

Updated at: 2020-12-10 08:46 UTC