9

I'm trying understand how to interpret the output of, and use, the Lisp debugger.

I've got a pretty simple Backtrace for the evaluation of my function, but I cann't seem to work out how to use it to find out in which Lisp 'form' in my function the exception occurred.

I'd appreciate any clues as to what I should be doing, to find where in my code the error originated.

Also - why does the second frame display as "no debug information available for frame"?

I've attached a screen shot with the debugger, and repl (I've also included my function below - I know it's very wrong - but I'm just interested in learning to use the debugger properly). In addition, I hit 'v' on the first frame to go to the source, but this resulted in the error below the repl. (EDIT - the missing source code issue is fixed by downloading & copying it to the correct path)

alt text

(horrible function - no comments please!)

(defun myquicksort2 (lst)
  (if (eql 1 (length lst))
      lst
      (let ((mid (middle lst)))
    (do ((i 0 (+ i 1)))
        ((>= i mid) (append (myquicksort2 (subseq lst 0 mid))
                  (myquicksort2 (subseq lst mid (length lst)))))
      (if (> (ltval i lst) (nth 100 lst))
          (let ((tmp (ltval i lst)))
        (setf (nth i lst) (gtval i lst))
        (setf (nth (- (- (length lst) i) 1) lst)  tmp)))))))

(defun ltval (i lst)
  (nth i lst))

(defun gtval (i lst)
  (nth (- (- (length lst) i) 1) lst))

(defun middle (lst)
  (round (/ (length lst) 2)))
Joel
  • 29,538
  • 35
  • 110
  • 138
  • 1
    One should mention that there is no 'the Lisp debugger'. Lisp is a large family of languages and implementations. Most implementations have different debuggers. An IDE like SLIME for Emacs adds to that a debugger interface that runs on top of the supported Lisps. – Rainer Joswig Jan 10 '11 at 13:38
  • Have you set your optimize flags for maximum debugging info? Try evaluating this in the repl before compiling everything: (declaim (optimize (speed 0) (safety 3) (debug 3) (size 0))) – Beef Jan 10 '11 at 15:55
  • @Beef - yes, I have tried this already. – Joel Jan 11 '11 at 08:32
  • @Joel: I don't know what your OS is (people really should supply this information), but Debian has a package called `sbcl-source`, which is intended for exactly this purpose - backtraces etc. Your OS might have one too. The Debian one installs in `/usr/share/sbcl-source/src`, which is exactly where your debugger is looking. :-) – Faheem Mitha May 18 '12 at 18:01

1 Answers1

4

The error is with > and you have only one > in your source, so that's where the problem is.

edit Built-in CL functions are highly prone to optimization in SBCL, so although the function call in your code is to CL:<, the code that's actually called (and which shows up in the debugger) is from an optimized, specific, SBCL-internal routine. This is less of an issue for user-defined functions, where you will be much more likely to get a useful frame.

Xach
  • 11,774
  • 37
  • 38
  • 2
    How come I couldn't use 'v' in the debugger to take me to the source where the function occurs? I really want to learn how to use the debugger (more so than fixing the error itself!). – Joel Jan 09 '11 at 17:57
  • @Xach - With regards to point you make in you first edit - is there a way to disable this 'aggressive optimization' - for more user friendly debug output? I have already set (sb-ext:restrict-compiler-policy 'debug 3) for max debug support in compiled code. – Joel Jan 09 '11 at 18:01
  • Since the error is in an internal routine, you need to install SBCL's source in a way that SBCL can find it again. One easy way is to build SBCL and install it from source. – Xach Jan 09 '11 at 18:09
  • I don't know if there's a way to disable that kind of optimization. – Xach Jan 09 '11 at 18:10
  • Is there anyway to tell where in MY source the error originated? If I had lots of function calls to > it would be pretty hard to trace. Also any clues as to why the Backtrace says "no debug information available for frame" for the second frame? – Joel Jan 09 '11 at 18:48
  • Not sure. I haven't seen what you've seen very often. I wouldn't worry about it unless you run into it chronically. – Xach Jan 09 '11 at 20:29
  • Ah - ok! Because it was the first thing I ran into I was a little worried it going to be like that all the way! Having progressed a little I can see a bit more light... – Joel Jan 09 '11 at 21:06