Debugging Lisp Part 2: Inspecting

This is part 2 of Debugging Lisp. If you haven’t read part 1 on dynamic recompilation, you can find it here. For the next post in the series on redefining classes, click here.

In this post I am going to discuss another tool used for debugging Common Lisp – the Slime Inspector. The Slime inspector makes it possible to manipulate objects directly from the repl. You can do many different things with it, including clicking on objects to look at their contents and being able to copy and paste objects in order to reuse them in future function calls.1 Let’s say you have the following point class:

(defclass point ()
  ((x :accessor point-x :initarg :x :initform 0)
   (y :accessor point-y :initarg :y :initform 0)))

If you were to make an instance of the above class:

(make-instance 'point :x 10 :y 20)

You can then right click on it and click on the “inspect” option, or just use the Emacs shortcut “C-c C-v TAB” to peek inside the object: (5)


This will show you the current values of all of the instance variables of the object. Not only can you look at the object’s instance variables, you can modify them as well. Note that the power comes from being able to do all of this from within the debugger at runtime. (7)


To make sure that the value of that object was actually changed, you can copy and paste the point object and then call the point-x function on it. (5)


One more really cool tool that hooks into the Inspector is the Slime Trace Dialog. The Slime Trace Dialog is like ordinary trace, but it also allows for inspection on the objects that were passed to or returned from the traced functions. For example, let’s say you are writing a tail call optimized function, sum, that sums all of the numbers in a list.

(defun sum (xs &optional (acc 0))
  (if (null xs)
      (sum (cdr xs) (+ (car xs) acc))))

(sum '(1 2 3))
=> 6

You can toggle the use the Slime Trace Dialog to trace sum by typing the shortcut “C-c M-t” and then typing in the name of function, “sum”. After tracing it and running the code, you can press “C-c T” to enter the interactive Trace Dialog buffer. From there you can press “G” to refresh it and obtain the most recent trace. (4)


The trace will look like the output from ordinary trace, except it will have some addition goodies. As I said above you can inspect all of the arguments and return values. You can also hide/show branches of the trace tree in order to make it easier to find what you are looking for. (8)


The Slime Trace Dialog is invaluable when you have code which is passing lots of objects around and you aren’t exactly sure what the value of each variable in each object is. You can just use the Slime Trace Dialog and have it keep track of all of the information for you.

All in all, the Slime Inspector is another amazing part of the Common Lisp debugging tool set. It comes in handy when the program crashes and you are unaware of the current state of the program. When combined with the rest of the features for debugging Common Lisp, the Slime Inspector is just incredible.

  1. Technically these aren’t features of the Inspector, they are features of “Presentations”. The Inspector is just the part that lets you look inside of the objects.

8 thoughts on “Debugging Lisp Part 2: Inspecting

  1. Superb article. Very informative.

    I have used inspector before, but I didn’t knew that you could use the trace dialog together with the inspector like this. More people should know about the presentations & debugging feature of SLIME.

    Thank you for writing this series of posts. Looking forward to the next entry!

  2. In the latest slime (2.14) a left mouse click does what you might expect in the inspector. Previously a middle (or mouse wheel) click was necessary to drill down into a field/property.

  3. A great post to start the day with! I have one related question though. If I have a running lisp image on a remote machine, what provision(s) should I have in place to connect to it so that I will be able to apply the magical tricks describe above? Run swank in it? Or are there other standard ways to connect to running lisp images.

  4. Hi thanks for this nice tutorial, I have a problem When I follow this I get the following error:

    CL-USER> (make-instance ‘point :x 10 :y 20)
    CL-USER> (point-x #)
    ; Evaluation aborted on #.

Leave a Reply

Your email address will not be published. Required fields are marked *