On of the many things that didn't quite get into the Common Lisp standard was how to get a Lisp to output its call stack when something has gone wrong. As such, each Lisp has developed its own notion of what to display, how to display it, and what sort of arguments can be used to customize it.
trivial-backtrace is a simple solution to generating a backtrace portably. As of 16 May 2012, it supports Allegro Common Lisp, LispWorks, ECL, MCL, SCL, SBCL and CMUCL. Its interface consists of three functions and one variable:
You can probably already guess what they do, but they are described in more detail below.
Send a backtrace for the error
The keywords arguments are:
if-exists - what to do if output designates a pathname and the pathname already exists. Defaults to :append.
verbose - if true, then a message about the backtrace is sent to *terminal-io*. Defaults to
output is nil, the returns the backtrace output as a string. Otherwise, returns nil.
Send a backtrace of the current error to stream.
Stream is assumed to be an open writable file stream or a string-output-stream. Note that
print-backtrace-to-stream will print a backtrace for whatever the Lisp deems to be the current error.
streamusing the pretty printer.
The default format to use when printing dates and times.
This code is borrowed from the
format-date function in metatilities-base.
A git repository is available using
git clone http://common-lisp.net/project/trivial-backtrace/trivial-backtrace.git
The darcs repository is still around but is not being updated. The command to get it is below:
;;; WARNING: out of date darcs get http://common-lisp.net/project/trivial-backtrace/
There's also a handy gzipped tar file.