martes, 15 de mayo de 2012

Lisp debugging, step by step. Step 1

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

That'll keep sbcl out from doing optimizations that can make variables 'disappear' in runtime.

A little more info in:

http://www.rhinocerus.net/forum/lang-lisp/583943-sbcl-line-line-debugging-tracing.html


and obviously, in your nearest implementation manual http://www.sbcl.org/manual/Debugger.html

No hay comentarios: