Debugging lisp is not as straightforward as one might think at first. Being a live environment I thought it would be a joy, like in smalltalk, racket, or elisp, which provides a quite decent tracer and stepper. Smalltalk is another world, but I'm already getting used to it so it doesn't surprise me that much.
We all heard stories about lisp machines (genera), and eventually read some article or seen some talk about how awesome it's lisp to debug.. but for me it was not so straightforward.
I'm using SBCL for all my experimentation in CL, so the examples here are going to be all sbcl related. First of all, some reasons on why there's not an easy mapping between your debugger on the language next door and lisp when debugging:
- Lisp normally compiles the source code to native code. Doing so, it runs lots of optimizations on your source, so the code executed has no direct mapping to your written code.
- Lisp is not line oriented, so the order of execution of code is not so easily mappable to the typical next-line, next-line... debugging.
- On the other side, you have 'trace' that lets you track all executions of a function, with params, and so. It's not so live, but with all the instrumentation that sbcl and slime provide, you can track down a fair amount of bugs just with trace.
To instrument a method to be debuggable more easily, my advice is to add this declarations.
(declare (optimize (speed 0) (space 1) (compilation-speed 0) (debug
That'll keep sbcl out from doing optimizations that can make variables 'disappear' in runtime.
A little more info in:
and obviously, in your nearest implementation manual http://www.sbcl.org/manual/Debugger.html