"Hot" Debug and Swap in Common LISP

Viewed 529

One of the features that are unique to Common Lisp that is frequently mentioned is that of the "hot" debug. That is, it is the ability to debug, edit and recompile the production code without stopping or taking the latter off line.

While I see this mentioned all the time, I have yet to see a tutorial on how to do it.

How does one do it in, say, Emacs? Are there some simple examples? Is the feature truly as magical as it seems?

2 Answers

The typical way to do this is to enable SWANK in the application that you want to debug. That way you can use M-x slime-connect from Emacs to connect to the running server. From there, you can do anything you can do with a normal SLIME session. You can even set up the way file names re resolved so that when you use M-. to jump to the source of a function, it will be opened on the remote machine using Tramp.

I think the reason you haven't seen a tutorial on it is because it's a natural thing to do, and there really isn't much of a difference between doing local debugging and working on a remote system.

There is a video of a lecture I did once where I demonstrated some of this, so there definitely are videos out there. However, I think linking to external videos is frowned upon on Stackoverflow.

Some notes I took for myself. I largely agree we should have a tutorial out there. In the CL Cookbook ?

(edit: there's now a more complete example here)

Reading http://readevalprint.tumblr.com/post/101841449553/its-alive-the-path-from-library-to-web-app

Another option is hot swapping all the changes. For this purpose my hunchentoot server also starts a swank server like this:

(defun start-app (&optional (port 8080))
  (handler-case (swank:create-server :dont-close t)
    (error ()))
    …

Swank is, of course, the server-side component of SLIME. It runs on a port that is not accessible remotely and can only be connected to locally or via SSH tunnel. I use the latter to connect SLIME on my PC to Swank running on my server, which allows me to apply various fixes without restarting, either from the REPL or by using C-c C-c to recompile some function.

Connect to a remote Slime server:

  • Install a Common Lisp implementation on the server. (E.g. sbcl, clisp, etc...)
  • Install quicklisp on the server.
  • Load SWANK with (ql:quickload :swank)
  • Start the server with (swank:create-server). The default port is 4005. [On your local machine] Create a SSH tunnel with ssh -L4005:127.0.0.1:4005 [remote machine]
  • Connect to the running remote swank server with M-x slime-connect.
  • The host should be 127.0.0.1 and the port 4005.

(reading an old SO doc page, impossible to link to now).

Related