Lisphacker.com

Some SBCL/Win32 hacking

Interest has been expressed in stdcall callbacks for SBCL/Win32, and I happen to have a little code to do that, so I offered to put my hack online.

hello world screenshot

The files linked below are an updated version of the source which produced the screenshot above. They were tested with SBCL 0.9.15.

We have here some hacking of the running system to add stdcall callbacks, a handful of alien type definitions, constants, and functions for various Win32 APIs, and a sample application that ties it all together.

In order to see it all in action, unpack the tarballs, load the two .asd files, (require :hello-win32), and then (hello-win32:do-it-to-it).

The two tarballs are lisp-winapi.tgz, which contains the callback hacking and API definitions, and hello-win32.tgz, which contains the sample application.

Single-stepping in SBCL/x86

The SBCL debugger, at present, can only single-step code which has been compiled with some phenominally high DEBUG setting which makes the compiler slow and the resulting code slow.

This works based on having the compiler insert extra code to handle stepping for each form.

Now, the x86 has a control flag which causes an exception after executing each instruction. It exists specifically to support single-stepping in debuggers.

The basic idea behind this hack is that we can set this flag in the context record supplied to a signal handler (in this case, SIGINT) and return, causing execution to resume where it left off, run one instruction, and then SIGTRAP.

This is a proof-of-concept, which means that it demonstrates the technique, but is missing all the bells and whistles, and may not be suitable for production use. Usage instructions (and this warning again) can be found at the top of the file.

So, without further ado, here's a single-step hack for SBCL/x86/Linux.